Plugin Directory

Changeset 583069


Ignore:
Timestamp:
08/08/2012 10:20:11 AM (14 years ago)
Author:
submarine
Message:

1.2 updated

Location:
category-icons-lite/tags/1.2
Files:
1 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • category-icons-lite/tags/1.2/caticons-lite.class.php

    r581997 r583069  
    11<?php
    22if ( !class_exists('CategoryIconsLite') ) {
    3     //include_once('caticon.class.php');
    43   
    5     define('CIL_OPTIONS','caticonslite_settings');
    6     define('CIL_GROUP','caticonslite-group');
    7        
    84    class CategoryIconsLite {
    95       
    106        private $meta_key = '_wp_attachment_category'; // hidden custom field
     7        private $settings = 'caticonslite_settings';
     8        private $group = 'caticonslite-group';
    119       
    1210        // Automagic variables
    1311        protected $permalink = 0;
    1412        protected $the_title = 0;
    15        
     13               
    1614        // Datas
    1715        private $caticons_array = array(); // cat_id => array(icon_id, icon_url, cat_slug, cat_name)
    18         private $slugs = array(); // slug => cat_id
    19         private $names = array(); // name => cat_id
    20         private $urls = array(); // url => cat name
    2116       
    2217        // Options
     
    2621            'caticonslite-sidebar'   => 'checked',
    2722            'caticonslite-posttitle' => 'checked',
    28             'caticonslite-rss' => ''
     23            'caticonslite-rss' => '',
     24            'caticonslite-maxicons' => '1'
    2925            );
    3026        private $options = array();
     
    3228        function __construct() {
    3329            $this->set_cat_icons();
    34             $options = get_option(CIL_OPTIONS);
     30            $options = get_option($this->settings);
    3531            if ( !is_array($options) || 0 == count($options) ) {
    36                 add_option(CIL_OPTIONS,$this->default_options);
     32                add_option($this->settings,$this->default_options);
    3733                $options = $this->default_options;
    3834            }
    3935            $this->options = $options;
    40             update_option(CIL_OPTIONS, $this->options);
     36            update_option($this->settings, $this->options);
    4137            $this->set_sidebar_icons_position($this->options['caticonslite-sidebar-position']);
    4238        }
     
    5652       
    5753        function set_options() {
    58             register_setting(CIL_GROUP, CIL_OPTIONS, array($this, 'reset_settings'));
     54            register_setting($this->group, $this->settings, array($this, 'reset_settings'));
    5955        }   
    60          
     56       
     57        function input_value($option_name='') {
     58          $result = 0;
     59          if (!empty($option_name) AND isset($this->options[$option_name]) AND $this->options[$option_name]>0 ) {
     60              $result = $this->options[$option_name];
     61          }
     62          return $result;
     63        }
     64       
    6165        function is_checked($option,$suboption='') {
    6266            $resultat = '';
     
    8488        function panel() {
    8589            echo '<div class="wrap"><h2>Category Icons Lite</h2><form action="options.php" method="post" id="caticonslite-form">';
    86             settings_fields(CIL_GROUP);
     90            settings_fields($this->group);
    8791            $html = '
    8892              <div class="metabox-holder" id="caticonslite-metabox">
     
    9599                          <th scope="row">'.__('Posts').'</th>
    96100                          <td><label >
    97                               <input type="checkbox" value="checked" name="'.CIL_OPTIONS.'[caticonslite-posttitle]" '.$this->is_checked('caticonslite-posttitle').' />
     101                              <input type="checkbox" value="checked" name="'.$this->settings.'[caticonslite-posttitle]" '.$this->is_checked('caticonslite-posttitle').' />
    98102                            </label>
    99103                          </td>
     
    102106                          <th scope="row">'.__('Sidebar').'</th>
    103107                          <td><label >
    104                               <input type="checkbox" value="checked" name="'.CIL_OPTIONS.'[caticonslite-sidebar]" '.$this->is_checked('caticonslite-sidebar').' />
     108                              <input type="checkbox" value="checked" name="'.$this->settings.'[caticonslite-sidebar]" '.$this->is_checked('caticonslite-sidebar').' />
    105109                            </label>
    106110                          </td>
     
    109113                          <th scope="row">'.__('Alignment').'</th>
    110114                          <td><label>
    111                               <input type="radio" value="left" name="'.CIL_OPTIONS.'[caticonslite-sidebar-position]" '.$this->is_checked('caticonslite-sidebar-position','left').' />
     115                              <input type="radio" value="left" name="'.$this->settings.'[caticonslite-sidebar-position]" '.$this->is_checked('caticonslite-sidebar-position','left').' />
    112116                              '. __('Left').'</label>
    113117                            <label >
    114                               <input type="radio" value="right" name="'.CIL_OPTIONS.'[caticonslite-sidebar-position]" '.$this->is_checked('caticonslite-sidebar-position','right').' />
     118                              <input type="radio" value="right" name="'.$this->settings.'[caticonslite-sidebar-position]" '.$this->is_checked('caticonslite-sidebar-position','right').' />
    115119                              '.__('Right').'</label>
    116                               <input type="radio" value="center" name="'.CIL_OPTIONS.'[caticonslite-sidebar-position]" '.$this->is_checked('caticonslite-sidebar-position','center').' />
     120                              <input type="radio" value="center" name="'.$this->settings.'[caticonslite-sidebar-position]" '.$this->is_checked('caticonslite-sidebar-position','center').' />
    117121                              '.__('Center').'</label>
    118122                            <p class="description">('.__('Sidebar').')</p></td>
     
    121125                          <th scope="row">'.__('RSS').'</th>
    122126                          <td><label >
    123                               <input type="checkbox" value="checked" name="'.CIL_OPTIONS.'[caticonslite-rss]" '.$this->is_checked('caticonslite-rss').' />
     127                              <input type="checkbox" value="checked" name="'.$this->settings.'[caticonslite-rss]" '.$this->is_checked('caticonslite-rss').' />
     128                            </label>
     129                          </td>
     130                        </tr>
     131                        <tr valign="top">
     132                          <th scope="row">'.__('Max Icons').'</th>
     133                          <td><label >
     134                              <input type="input" value="'.$this->input_value('caticonslite-maxicons').'" name="'.$this->settings.'[caticonslite-maxicons]" />
    124135                            </label>
    125136                          </td>
     
    127138                      </table>
    128139                      <p>
    129                         <input class="button-primary"  type="submit" name="caticonslite_submit" value="Save Options" />
    130                         <input  class="button-secondary" type="submit" name="caticonslite_settings[reset]" value="Reset Options"  />
     140                        <input class="button-primary"  type="submit" name="caticonslite_submit" value="'.__('Save').'" />
     141                        <input  class="button-secondary" type="submit" name="caticonslite_settings[reset]" value="'.__('Reset').'"  />
    131142                      </p>
    132143                    </div>
     
    137148        }
    138149       
     150       
     151       
    139152        function are_icons_sidebar() {
    140153            $result = false;
     
    164177            return $result;
    165178        }
    166                
     179
    167180        /**
    168181         * Inject the icons next to the category name in the RSS
     
    175188                if (is_array($cats)) {// several categories
    176189                    foreach($cats as $cat_name) {
    177                         $cat_id = $this->names[$cat_name];
    178                         $icon = $this->get_cat_icon($cat_id);
    179                         $the_list = str_replace('CDATA['.$cat_name.']', 'CDATA['.$icon.' '.$cat_name.']', $the_list);
     190                        $this->temp = 0;
     191                        $cat_id = $this->search_cat_id('name',$cat_name);
     192                        if (0 < $cat_id) {
     193                            $icon = $this->get_cat_icon($cat_id);
     194                            $the_list = str_replace('CDATA['.$cat_name.']', 'CDATA['.$icon.' '.$cat_name.']', $the_list);
     195                        }
    180196                    }
    181197                }
     
    227243            if ( in_the_loop() AND $text == $GLOBALS['post']->post_title ) {// if in the loop & post title is the same than the one being processed
    228244                $this->reset_flags();
    229                 $icon=$this->get_icon();
     245                /*$icon=$this->get_icon();
    230246                if (!empty($icon)) {
    231247                    $image = $this->html_tag($icon,$text);
    232248                }
     249                */
     250                $image = $this->get_cat_icon();
    233251            }
    234252            return $image.$text; // if you want to display it after the title : return $text.$image;
    235253        }
     254           
     255        function search_cat_id($param,$val) {
     256            $result = 0;
     257            foreach ($this->caticons_array as $k => $v) {
     258                if ($v[$param] == $val) {
     259                    return $k;
     260                }
     261            }
     262            return $result;
     263        }
    236264       
    237265        /**
     
    240268        function html_tag($url,$title='') {
    241269            $html = '';
    242             $cat_name = $this->urls[$url];
    243             if (empty($cat_name)) {
    244                 $cat_name = 'Category Icons Lite';
    245             }
    246             $alt = $cat_name;
    247             $alt = apply_filters('caticonslite_alt', $alt);
    248             if (!empty($title)) {
    249                 $title = esc_attr($title);
    250             }
    251             else {
    252                 $title = $cat_name;             
    253             }   
    254             $title = apply_filters('caticonslite_title', $title);
    255270            if (!empty($url)) {
    256                 $html = "<img class='caticonslite_bm' alt=\"$alt\" src=\"".esc_url($url)."\" title=\"$title\" />";
    257             }   
    258             $html = apply_filters('caticonslite_htmltag', $html);
     271                $cat_name = '';
     272                $cat_id = $this->search_cat_id('url',$url);
     273                if (0 < $cat_id) {
     274                    $cat_name = $this->caticons_array[$cat_id]['name'];
     275                }
     276                if (empty($cat_name)) {
     277                    $cat_name = 'Category Icons Lite';
     278                }
     279                $alt = $cat_name;
     280                $alt = apply_filters('caticonslite_alt', $alt);
     281                if (!empty($title)) {
     282                    $title = esc_attr($title);
     283                }
     284                else {
     285                    $title = $cat_name;             
     286                }   
     287                $title = apply_filters('caticonslite_title', $title);
     288                if (!empty($url)) {
     289                    $html = "<img class='caticonslite_bm' alt=\"$alt\" src=\"".esc_url($url)."\" title=\"$title\" />";
     290                }   
     291                $html = apply_filters('caticonslite_htmltag', $html);
     292            }
    259293            return $html;
    260294        }
     
    264298        * This function returns the icon url
    265299        */
    266         function get_icon($cat_id=0) {
     300        private function get_icon($cat_id=0) {
    267301            global $wpdb;
    268302            $result = '';
     
    271305                $catlist = get_the_category(get_the_ID());
    272306                if (is_array($catlist)) {// If there are several categories,
     307                    $cat_id = array();
     308                    $result = array();
    273309                    if (count($catlist) > 0) {
    274                         $cat_id = (int) $catlist[0]->term_id; // I take only the first one
    275                         $cat_id = apply_filters('caticonslite_cat_priority', $cat_id, $catlist);
     310                        $max = $this->options['caticonslite-maxicons'];
     311                        if (count($catlist)<$max) {
     312                            $max = count($catlist);
     313                        }
     314                        for ($i=0;$i<$max;$i++) {
     315                            $cat_id[] = (int) $catlist[$i]->term_id;
     316                        }
     317                        //$cat_id = apply_filters('caticonslite_cat_priority', $cat_id, $catlist);
    276318                    }   
    277319                    else {
     
    285327           
    286328            $cat_id = apply_filters('caticonslite_cat_id', $cat_id);
    287             if (0 < $cat_id AND isset($this->caticons_array[$cat_id]['url'])) {
    288                 $result = $this->caticons_array[$cat_id]['url'];
    289             }           
     329            if (is_array($cat_id)) {
     330                for ($i=0; $i<count($cat_id);$i++) { 
     331                     $index = $cat_id[$i];
     332                    if (0 < $index AND isset($this->caticons_array[$index]['url'])) {   
     333                        $result[] = $this->caticons_array[$index]['url'];
     334                       
     335                    }
     336                }
     337            }
     338            else {
     339                if (0 < $cat_id AND isset($this->caticons_array[$cat_id]['url'])) {
     340                    $result = $this->caticons_array[$cat_id]['url'];
     341                }
     342            }
    290343            return $result;
    291344        }
     
    301354            INNER JOIN {$wpdb->prefix}postmeta ON {$wpdb->prefix}postmeta.post_id = {$wpdb->prefix}posts.ID
    302355            INNER JOIN {$wpdb->prefix}terms ON {$wpdb->prefix}postmeta.meta_value = {$wpdb->prefix}terms.term_id
    303             WHERE meta_key = '".esc_sql($this->meta_key)."'";   
     356            WHERE meta_key = '".esc_sql($this->meta_key).'\''
    304357           
    305358            $results = wp_cache_get( 'categoryiconslite_results');
     
    316369                           'name' => $result->name
    317370                           );
    318                     $this->slugs[$result->slug] = $result->cat_id;
    319                     $this->names[$result->name] = $result->cat_id;
    320                     $this->urls[esc_url($result->image_url)] = $result->name;
    321                 }
    322             }
    323         }
    324        
    325         /**
    326         * Returns the category icon
     371                }
     372            }
     373        }
     374       
     375        /**
     376        * Returns the category icons
    327377        */
    328378        function get_cat_icon($cat_id=0) {
    329             return $this->html_tag($this->get_icon($cat_id));
     379            $result = '';
     380            $icons = $this->get_icon($cat_id);
     381            if (!empty($icons)) {
     382                if (is_array($icons)) {
     383                    foreach ($icons as $icon) {
     384                        $result .= $this->html_tag($icon);       
     385                    }
     386                }
     387                else {
     388                    $result = $this->html_tag($icon);
     389                }
     390            }
     391            return $result;
    330392        }
    331393       
     
    334396        */
    335397        function list_cats( $output ) {         
    336             if ( 0 == count($this->slugs) ) {
     398            //if ( 0 == count($this->slugs) ) {
     399            if ( 0 == count($this->caticons_array) ) {
    337400                return $output;
    338401            }   
     
    350413                       if (0 < $nb) {
    351414                           $name = $result[0];
    352                            $cats[] = $this->slugs[trim($name)];   
     415                           //$cats[] = $this->slugs[trim($name)];     
     416                           $cats[] = $this->search_cat_id('name',$name);
    353417                       }
    354418                    }
  • category-icons-lite/tags/1.2/caticonslite.php

    r581997 r583069  
    1212* This function removes all traces of the plugin in the postmeta table
    1313*/
     14
     15global $pagenow;
     16
    1417function category_icons_lite_uninstall() {
    1518    global $wpdb;
     
    8083            add_filter('deleted_term_taxonomy', array($CategoryIconsLite,'category_removed'));
    8184        }
     85       
    8286    }
    8387   
  • category-icons-lite/tags/1.2/readme.txt

    r581997 r583069  
    1515Everything is configurable from the settings menu, you can use it on your index (home) page, post pages, or even your sidebar ! You can do icons only, or text and icons. This wonderful plugin :
    1616
    17 * automagically displays an icon in front of your post title (optional : you can disable it)
    18 * automagically displays icons next to the category names in the sidebar (optional : you can disable it)
     17* automagically displays an icon in front of your post title (but you can disable it via the panel settings)
     18* automagically displays icons next to the category names in the sidebar (in the widget or in the template) (you can disable it too)
    1919* offers 2 template tags : designers & developers can [use template tag with this plugin](http://www.category-icons.com/2011/02/how-to-use-a-tag-to-display-icons-with-category-icons-lite/) to display category icons wherever you want.
    2020* offers 4 filters for developers : caticonslite_htmltag, caticonslite_alt, caticonslite_title & caticonslite_widget.
     
    5858* Now you can display icons only in the sidebar by selecting 'center' in the settings
    5959* You can enable the display of category icons in the rss
     60* The maximum number of icons to display can be defined
    6061
    6162= 1.1.4 =
Note: See TracChangeset for help on using the changeset viewer.