Changeset 583069
- Timestamp:
- 08/08/2012 10:20:11 AM (14 years ago)
- Location:
- category-icons-lite/tags/1.2
- Files:
-
- 1 deleted
- 3 edited
-
caticon.class.php (deleted)
-
caticons-lite.class.php (modified) (22 diffs)
-
caticonslite.php (modified) (2 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
category-icons-lite/tags/1.2/caticons-lite.class.php
r581997 r583069 1 1 <?php 2 2 if ( !class_exists('CategoryIconsLite') ) { 3 //include_once('caticon.class.php');4 3 5 define('CIL_OPTIONS','caticonslite_settings');6 define('CIL_GROUP','caticonslite-group');7 8 4 class CategoryIconsLite { 9 5 10 6 private $meta_key = '_wp_attachment_category'; // hidden custom field 7 private $settings = 'caticonslite_settings'; 8 private $group = 'caticonslite-group'; 11 9 12 10 // Automagic variables 13 11 protected $permalink = 0; 14 12 protected $the_title = 0; 15 13 16 14 // Datas 17 15 private $caticons_array = array(); // cat_id => array(icon_id, icon_url, cat_slug, cat_name) 18 private $slugs = array(); // slug => cat_id19 private $names = array(); // name => cat_id20 private $urls = array(); // url => cat name21 16 22 17 // Options … … 26 21 'caticonslite-sidebar' => 'checked', 27 22 'caticonslite-posttitle' => 'checked', 28 'caticonslite-rss' => '' 23 'caticonslite-rss' => '', 24 'caticonslite-maxicons' => '1' 29 25 ); 30 26 private $options = array(); … … 32 28 function __construct() { 33 29 $this->set_cat_icons(); 34 $options = get_option( CIL_OPTIONS);30 $options = get_option($this->settings); 35 31 if ( !is_array($options) || 0 == count($options) ) { 36 add_option( CIL_OPTIONS,$this->default_options);32 add_option($this->settings,$this->default_options); 37 33 $options = $this->default_options; 38 34 } 39 35 $this->options = $options; 40 update_option( CIL_OPTIONS, $this->options);36 update_option($this->settings, $this->options); 41 37 $this->set_sidebar_icons_position($this->options['caticonslite-sidebar-position']); 42 38 } … … 56 52 57 53 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')); 59 55 } 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 61 65 function is_checked($option,$suboption='') { 62 66 $resultat = ''; … … 84 88 function panel() { 85 89 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); 87 91 $html = ' 88 92 <div class="metabox-holder" id="caticonslite-metabox"> … … 95 99 <th scope="row">'.__('Posts').'</th> 96 100 <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').' /> 98 102 </label> 99 103 </td> … … 102 106 <th scope="row">'.__('Sidebar').'</th> 103 107 <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').' /> 105 109 </label> 106 110 </td> … … 109 113 <th scope="row">'.__('Alignment').'</th> 110 114 <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').' /> 112 116 '. __('Left').'</label> 113 117 <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').' /> 115 119 '.__('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').' /> 117 121 '.__('Center').'</label> 118 122 <p class="description">('.__('Sidebar').')</p></td> … … 121 125 <th scope="row">'.__('RSS').'</th> 122 126 <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]" /> 124 135 </label> 125 136 </td> … … 127 138 </table> 128 139 <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').'" /> 131 142 </p> 132 143 </div> … … 137 148 } 138 149 150 151 139 152 function are_icons_sidebar() { 140 153 $result = false; … … 164 177 return $result; 165 178 } 166 179 167 180 /** 168 181 * Inject the icons next to the category name in the RSS … … 175 188 if (is_array($cats)) {// several categories 176 189 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 } 180 196 } 181 197 } … … 227 243 if ( in_the_loop() AND $text == $GLOBALS['post']->post_title ) {// if in the loop & post title is the same than the one being processed 228 244 $this->reset_flags(); 229 $icon=$this->get_icon();245 /*$icon=$this->get_icon(); 230 246 if (!empty($icon)) { 231 247 $image = $this->html_tag($icon,$text); 232 248 } 249 */ 250 $image = $this->get_cat_icon(); 233 251 } 234 252 return $image.$text; // if you want to display it after the title : return $text.$image; 235 253 } 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 } 236 264 237 265 /** … … 240 268 function html_tag($url,$title='') { 241 269 $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);255 270 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 } 259 293 return $html; 260 294 } … … 264 298 * This function returns the icon url 265 299 */ 266 function get_icon($cat_id=0) {300 private function get_icon($cat_id=0) { 267 301 global $wpdb; 268 302 $result = ''; … … 271 305 $catlist = get_the_category(get_the_ID()); 272 306 if (is_array($catlist)) {// If there are several categories, 307 $cat_id = array(); 308 $result = array(); 273 309 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); 276 318 } 277 319 else { … … 285 327 286 328 $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 } 290 343 return $result; 291 344 } … … 301 354 INNER JOIN {$wpdb->prefix}postmeta ON {$wpdb->prefix}postmeta.post_id = {$wpdb->prefix}posts.ID 302 355 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).'\''; 304 357 305 358 $results = wp_cache_get( 'categoryiconslite_results'); … … 316 369 'name' => $result->name 317 370 ); 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 327 377 */ 328 378 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; 330 392 } 331 393 … … 334 396 */ 335 397 function list_cats( $output ) { 336 if ( 0 == count($this->slugs) ) { 398 //if ( 0 == count($this->slugs) ) { 399 if ( 0 == count($this->caticons_array) ) { 337 400 return $output; 338 401 } … … 350 413 if (0 < $nb) { 351 414 $name = $result[0]; 352 $cats[] = $this->slugs[trim($name)]; 415 //$cats[] = $this->slugs[trim($name)]; 416 $cats[] = $this->search_cat_id('name',$name); 353 417 } 354 418 } -
category-icons-lite/tags/1.2/caticonslite.php
r581997 r583069 12 12 * This function removes all traces of the plugin in the postmeta table 13 13 */ 14 15 global $pagenow; 16 14 17 function category_icons_lite_uninstall() { 15 18 global $wpdb; … … 80 83 add_filter('deleted_term_taxonomy', array($CategoryIconsLite,'category_removed')); 81 84 } 85 82 86 } 83 87 -
category-icons-lite/tags/1.2/readme.txt
r581997 r583069 15 15 Everything 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 : 16 16 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) 19 19 * 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. 20 20 * offers 4 filters for developers : caticonslite_htmltag, caticonslite_alt, caticonslite_title & caticonslite_widget. … … 58 58 * Now you can display icons only in the sidebar by selecting 'center' in the settings 59 59 * You can enable the display of category icons in the rss 60 * The maximum number of icons to display can be defined 60 61 61 62 = 1.1.4 =
Note: See TracChangeset
for help on using the changeset viewer.