Plugin Directory

Changeset 1585466


Ignore:
Timestamp:
01/31/2017 02:24:01 AM (9 years ago)
Author:
itmatio
Message:

fix statistics shortcake, fix job text search

Location:
interserve-data-feed/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • interserve-data-feed/trunk/Base.php

    r1585453 r1585466  
    158158    public function addCanonicalLink()
    159159    {
     160        return '';
    160161    }
    161162}
  • interserve-data-feed/trunk/Context.php

    r1585453 r1585466  
    139139    /**
    140140     * @param        $term
    141      * @return string wordpress taxonomy termID
     141     * @return array wordpress taxonomy termID
    142142     */
    143143    public function getTaxonomyTermIDs($term)
     
    211211     *        duration => array( term_ids ))
    212212     * where known. term_ids are wordpress taxonomy term ids
    213      * @return array
    214213     */
    215214    public function calculateFromPost()
  • interserve-data-feed/trunk/Data/Statistics.php

    r1585453 r1585466  
    1919class Statistics extends \ISData\Base
    2020{
     21    const JOB_COUNT = 'jobs';
     22    const STORY_COUNT = 'stories';
     23    const PROFESSION_COUNT = 'professions';
     24    const LOCATION_COUNT = 'locations';
     25
    2126    /**
    2227     * @const name of option passed to set_site_option()
     
    6873
    6974    /**
     75     * @param array $args
    7076     * @return string html
    7177     */
    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()
    73102    {
    74103        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    }
    75108
    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    }
    77119
    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 '';
    80144        }
    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;
    103159            }
    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>';
    113161        }
     162        $output .= '</dl>';
    114163        return $output;
    115164    }
     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    }
    116180}
  • interserve-data-feed/trunk/PostType/CustomPostType.php

    r1585453 r1585466  
    6969    {
    7070        $fileName = $prefix . $this->getWordpressName() . '.php';
    71 
    7271        // 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;
    7874    }
    7975
  • interserve-data-feed/trunk/PostType/Job.php

    r1585453 r1585466  
    193193    /**
    194194     * Get a list of posts exactly matching the context
    195      * @param array $context
    196      * @param int   $maxRecords
     195     * @param \ISData\Context $context
     196     * @param int             $maxRecords
    197197     * @return array of post objects
    198198     */
     
    220220        }
    221221        if ($context->hasSearchText()) {
    222             $pattern = $wpdb->escape(esc_like($context->getSearchText()));
     222            $pattern = $wpdb->_escape($wpdb->esc_like($context->getSearchText()));
    223223            $sql .= 'AND (post.post_title like "%' . $pattern . '%" or post.post_content like "%' . $pattern . '%") ';
    224224        }
     
    241241        $included = $context->getTaxonomyTermIDs($feed);
    242242        if (empty($included)) {
    243             return ''; // nothing to exclude
     243            return []; // nothing to exclude
    244244        }
    245245        $excluded   = [];
  • interserve-data-feed/trunk/readme.txt

    r1585453 r1585466  
    3838- [isdata_location_list] shows an unordered list of the location taxonomy, with counts
    3939- [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.
    4144- [isdata_child_pages] shows the pages that are children of this page
    4245
Note: See TracChangeset for help on using the changeset viewer.