Changeset 1585466
- Timestamp:
- 01/31/2017 02:24:01 AM (9 years ago)
- Location:
- interserve-data-feed/trunk
- Files:
-
- 6 edited
-
Base.php (modified) (1 diff)
-
Context.php (modified) (2 diffs)
-
Data/Statistics.php (modified) (2 diffs)
-
PostType/CustomPostType.php (modified) (1 diff)
-
PostType/Job.php (modified) (3 diffs)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
interserve-data-feed/trunk/Base.php
r1585453 r1585466 158 158 public function addCanonicalLink() 159 159 { 160 return ''; 160 161 } 161 162 } -
interserve-data-feed/trunk/Context.php
r1585453 r1585466 139 139 /** 140 140 * @param $term 141 * @return stringwordpress taxonomy termID141 * @return array wordpress taxonomy termID 142 142 */ 143 143 public function getTaxonomyTermIDs($term) … … 211 211 * duration => array( term_ids )) 212 212 * where known. term_ids are wordpress taxonomy term ids 213 * @return array214 213 */ 215 214 public function calculateFromPost() -
interserve-data-feed/trunk/Data/Statistics.php
r1585453 r1585466 19 19 class Statistics extends \ISData\Base 20 20 { 21 const JOB_COUNT = 'jobs'; 22 const STORY_COUNT = 'stories'; 23 const PROFESSION_COUNT = 'professions'; 24 const LOCATION_COUNT = 'locations'; 25 21 26 /** 22 27 * @const name of option passed to set_site_option() … … 68 73 69 74 /** 75 * @param array $args 70 76 * @return string html 71 77 */ 72 public function renderShortcode($args = '') 78 public function renderShortcode($args = []) 79 { 80 $args = shortcode_atts(['name' => ''], $args); 81 $name = strtolower($args['name']); 82 switch ($name) { 83 case self::JOB_COUNT: 84 return $this->getJobCount(); 85 case self::LOCATION_COUNT: 86 return $this->getLocationCount(); 87 case self::STORY_COUNT: 88 return $this->getStoryCount(); 89 case self::PROFESSION_COUNT: 90 return $this->getProfessionCount(); 91 case '': 92 return $this->formatAll(); 93 default: 94 return $this->getNamed($name); 95 } 96 } 97 98 /** 99 * @return string 100 */ 101 private function getJobCount() 73 102 { 74 103 global $wpdb; // ick! wordpress global variable 104 $subQuery = 'SELECT count(ID) jobcount FROM ' . $wpdb->posts . ' WHERE post_type = "isdata_job"'; 105 $result = $wpdb->get_results($subQuery); 106 return $result[0]->jobcount; 107 } 75 108 76 $newdata = $this->getData(); 109 /** 110 * @return string 111 */ 112 private function getStoryCount() 113 { 114 global $wpdb; // ick! wordpress global variable 115 $subQuery = 'SELECT count(ID) storycount FROM ' . $wpdb->posts . ' WHERE post_type = "isdata_story"'; 116 $result = $wpdb->get_results($subQuery); 117 return $result[0]->storycount; 118 } 77 119 78 if (empty($newdata)) { 79 return '0'; 120 /** 121 * @return int 122 */ 123 private function getProfessionCount() 124 { 125 return count(get_terms('isdata_profession', ['hide_empty' => false])); 126 } 127 128 /** 129 * @return int 130 */ 131 private function getLocationCount() 132 { 133 return count(get_terms('isdata_location', ['hide_empty' => false])); 134 } 135 136 /** 137 * @return string html 138 */ 139 private function formatAll() 140 { 141 $data = $this->getData(); 142 if (empty($data)) { 143 return ''; 80 144 } 81 if ($args != '') { 82 if ($args['name'] == 'Job Count') { 83 $subQuery = 'SELECT count(ID) jobcount FROM ' . $wpdb->posts . ' WHERE post_type = "isdata_job"'; 84 $result = $wpdb->get_results($subQuery); 85 $output = $result[0]->jobcount; 86 } elseif ($args['name'] == 'Story Count') { 87 $subQuery = 'SELECT count(ID) storycount FROM ' . $wpdb->posts . ' WHERE post_type = "isdata_story"'; 88 $result = $wpdb->get_results($subQuery); 89 $output = $result[0]->storycount; 90 } elseif ($args['name'] == 'Profession Count') { 91 $terms = get_terms('isdata_profession', ['hide_empty' => false]); 92 $output = count($terms); 93 } elseif ($args['name'] == 'Location Count') { 94 $terms = get_terms('isdata_location', ['hide_empty' => false]); 95 $output = count($terms); 96 } else { 97 foreach ($newdata as $title => $value) { 98 if (strtolower($args['name']) == strtolower($title)) { 99 $output = esc_html($value); 100 break; 101 } 102 } 145 $builtin = [ 146 self::JOB_COUNT => $this->getJobCount(), 147 self::STORY_COUNT => $this->getStoryCount(), 148 self::LOCATION_COUNT => $this->getLocationCount(), 149 self::PROFESSION_COUNT => $this->getProfessionCount(), 150 ]; 151 foreach ($builtin as $title => $value) { 152 $data[ucwords($title)] = $value; 153 } 154 155 $output = '<dl class="isdata_statistics">'; 156 foreach ($data as $title => $value) { 157 if ($title == 'Updated') { 158 continue; 103 159 } 104 } else { 105 $output = '<dl class="isdata_statistics">'; 106 foreach ($newdata as $title => $value) { 107 if ($title == 'Updated') { 108 continue; 109 } 110 $output .= '<dt>' . esc_html($title) . '</dt><dd>' . esc_html($value) . '</dd>'; 111 } 112 $output .= '</dl>'; 160 $output .= '<dt>' . esc_html($title) . '</dt><dd>' . esc_html($value) . '</dd>'; 113 161 } 162 $output .= '</dl>'; 114 163 return $output; 115 164 } 165 166 /** 167 * @param string $name lowercased arg name from shortcode 168 * @return string 169 */ 170 private function getNamed($name) 171 { 172 $data = $this->getData(); 173 foreach ($data as $title => $value) { 174 if ($name == strtolower($title)) { 175 return esc_html($value); 176 } 177 } 178 return ''; 179 } 116 180 } -
interserve-data-feed/trunk/PostType/CustomPostType.php
r1585453 r1585466 69 69 { 70 70 $fileName = $prefix . $this->getWordpressName() . '.php'; 71 72 71 // if the file exists in the theme, use it: so we can override the plugin 73 if ($themeFile = locate_template([$fileName])) { 74 return $themeFile; 75 } 76 // otherwise use the file from the plugin 77 return ISDATA_PATH . $fileName; 72 $themeFile = locate_template([$fileName]); 73 return empty($themeFile) ? ISDATA_PATH . $fileName : $themeFile; 78 74 } 79 75 -
interserve-data-feed/trunk/PostType/Job.php
r1585453 r1585466 193 193 /** 194 194 * Get a list of posts exactly matching the context 195 * @param array$context196 * @param int $maxRecords195 * @param \ISData\Context $context 196 * @param int $maxRecords 197 197 * @return array of post objects 198 198 */ … … 220 220 } 221 221 if ($context->hasSearchText()) { 222 $pattern = $wpdb-> escape(esc_like($context->getSearchText()));222 $pattern = $wpdb->_escape($wpdb->esc_like($context->getSearchText())); 223 223 $sql .= 'AND (post.post_title like "%' . $pattern . '%" or post.post_content like "%' . $pattern . '%") '; 224 224 } … … 241 241 $included = $context->getTaxonomyTermIDs($feed); 242 242 if (empty($included)) { 243 return ''; // nothing to exclude243 return []; // nothing to exclude 244 244 } 245 245 $excluded = []; -
interserve-data-feed/trunk/readme.txt
r1585453 r1585466 38 38 - [isdata_location_list] shows an unordered list of the location taxonomy, with counts 39 39 - [isdata_duration_list] shows an unordered list of the duration taxonomy, with counts 40 - [isdata_statistics] shows a two column table of random stats about Interserve 40 - [isdata_statistics] shows a two column table of random stats about Interserve. 41 Use [isdata_statistics name="Updated"] to show the date and time the stats were last updated on data.interserve.org. 42 Use name="Jobs" to return just the number for the count of job openings. This works for any of the other numbers 43 reported by the bare tag. 41 44 - [isdata_child_pages] shows the pages that are children of this page 42 45
Note: See TracChangeset
for help on using the changeset viewer.