Changeset 581647
- Timestamp:
- 08/04/2012 07:44:12 AM (14 years ago)
- Location:
- category-icons-lite/tags/1.2
- Files:
-
- 3 edited
-
caticons-lite.class.php (modified) (25 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
r581219 r581647 14 14 private $sb_position = 'left'; 15 15 private $default_options = array ( 16 "caticonslite-sidebar-position" => "left", 17 "caticonslite-sidebar" => "checked", 18 "caticonslite-posttitle" => "checked" 16 'caticonslite-sidebar-position' => 'left', 17 'caticonslite-sidebar' => 'checked', 18 'caticonslite-posttitle' => 'checked', 19 'caticonslite-rss' => '' 19 20 ); 20 21 private $options = array(); 22 private $rss = false; 21 23 22 24 function __construct() { 23 25 $this->set_cat_icons(); 24 26 $options = get_option(CIL_OPTIONS); 25 if ( !is_array($options) || count($options) == 0) {27 if ( !is_array($options) || 0 == count($options) ) { 26 28 add_option(CIL_OPTIONS,$this->default_options); 27 29 $options = $this->default_options; … … 37 39 38 40 function reset_settings($options) { 39 if(!empty($options['reset'])) 40 return $this->default_options; 41 else 42 return $options; 41 if(!empty($options['reset'])) { 42 return $this->default_options; 43 } 44 else { 45 return $options; 46 } 43 47 } 44 48 45 49 function set_options() { 46 50 register_setting(CIL_GROUP, CIL_OPTIONS, array($this, 'reset_settings')); 47 }51 } 48 52 49 53 function is_checked($option,$suboption='') { 50 54 $resultat = ''; 51 55 $checked = ' checked="checked" '; 52 if ( empty($suboption) AND $this->options[$option] == "checked") {56 if ( empty($suboption) AND isset($this->options[$option]) AND 'checked' == $this->options[$option] ) { 53 57 $resultat = $checked; 54 58 } 55 59 if (!empty($suboption)) { 56 if ( $this->options[$option] == $suboption) {60 if ( isset($this->options[$option]) AND $this->options[$option] == $suboption) { 57 61 $resultat = $checked; 58 62 } … … 106 110 <p class="description">('.__('Sidebar').')</p></td> 107 111 </tr> 112 <tr valign="top"> 113 <th scope="row">'.__('RSS').'</th> 114 <td><label > 115 <input type="checkbox" value="checked" name="'.CIL_OPTIONS.'[caticonslite-rss]" '.$this->is_checked('caticonslite-rss').' /> 116 </label> 117 </td> 118 </tr> 108 119 </table> 109 120 <p> … … 120 131 function are_icons_sidebar() { 121 132 $result = false; 122 if ( $this->options['caticonslite-sidebar']=="checked") {133 if (isset($this->options['caticonslite-sidebar']) AND 'checked' == $this->options['caticonslite-sidebar']) { 123 134 $result = true; 124 135 } … … 132 143 function are_icons_post_title() { 133 144 $result = false; 134 if ( $this->options['caticonslite-posttitle']=="checked") {145 if (isset($this->options['caticonslite-posttitle']) AND 'checked' == $this->options['caticonslite-posttitle']) { 135 146 $result = true; 136 147 } … … 138 149 } 139 150 151 function is_rss() { 152 $result = false; 153 if (isset($this->options['caticonslite-rss']) AND 'checked' == $this->options['caticonslite-rss']) { 154 $result = true; 155 } 156 return $result; 157 } 158 /** 159 * If a RSS feed is created, 'raise the flag' 160 */ 161 function rss_flag() { 162 $this->rss = true; 163 } 164 165 /** 166 * Inject the icons into the feeds 167 * Working only with RSS2 and Atom. (And RDF, but only in Safari) 168 * @param string The content to process 169 * @return string The feed content 170 */ 171 function rss($content) { 172 if ( $this->rss AND isset($this->options['caticonslite-rss']) AND 'checked' == $this->options['caticonslite-rss'] ) // If the rss flag is raised, inject icons 173 $content = get_cat_icon_lite().'<br/>'.$content; 174 return $content; 175 } 176 140 177 /** 141 178 * Sets the display of the icons on the right or on the left of the sidebar category name 142 179 */ 143 180 function set_sidebar_icons_position($position='left') { 144 if ( $position=='left' OR $position=='right' OR $position=='center') {181 if ( 'left' == $position OR 'right' == $position OR 'center' == $position ) { 145 182 $this->sb_position = $position; 146 183 } … … 151 188 */ 152 189 function page_filter($text) {//if (is_category()) // use this if you want to display icons in front of the post title only in the category page, for example 153 if ($this->the_title == 1 && $this->permalink == 1) $text = $this->post_title($text); 154 if ($this->the_title == 0) $this->the_title = 1; 190 if ( 1 == $this->the_title AND 1 == $this->permalink ) { 191 $text = $this->post_title($text); 192 } 193 if ( 0 == $this->the_title ) { 194 $this->the_title = 1; 195 } 155 196 return $text; 156 197 } … … 161 202 function post_title($text) { 162 203 $image = ''; 163 if ( in_the_loop() && $GLOBALS['post']->post_title==$text) {// if in the loop & post title is the same than the one being processed204 if ( in_the_loop() AND $text == $GLOBALS['post']->post_title ) {// if in the loop & post title is the same than the one being processed 164 205 $this->reset_flags(); 165 206 $icon=$this->get_icon(); 166 if (!empty($icon)) $image = $this->html_tag($icon,$text); 207 if (!empty($icon)) { 208 $image = $this->html_tag($icon,$text); 209 } 167 210 } 168 211 return $image.$text; // if you want to display it after the title : return $text.$image; … … 170 213 171 214 /** 172 * Returns the html tagof the icon215 * Returns the html code of the icon 173 216 */ 174 217 function html_tag($url,$title='') { … … 177 220 $cat_name = esc_attr($cat_object->name); 178 221 $alt = $cat_name; 179 //$alt = 'caticonslite_bm_alt';180 222 $alt = apply_filters('caticonslite_alt', $alt); 181 //$title = esc_attr($title); 182 $title = $cat_name; 223 if (!empty($title)) { 224 $title = esc_attr($title); 225 } 226 else { 227 $title = $cat_name; 228 } 183 229 $title = apply_filters('caticonslite_title', $title); 184 if (!empty($url)) $html = "<img class='caticonslite_bm' alt=\"$alt\" src=\"".esc_url($url)."\" title=\"$title\" />"; 230 if (!empty($url)) { 231 $html = "<img class='caticonslite_bm' alt=\"$alt\" src=\"".esc_url($url)."\" title=\"$title\" />"; 232 } 185 233 $html = apply_filters('caticonslite_htmltag', $html); 186 234 return $html; 187 235 } 236 188 237 189 238 /** … … 193 242 global $wpdb; 194 243 $result = ''; 244 $cat_id = (int) $cat_id; 195 245 if ( 0 == $cat_id ) { 196 246 $catlist = get_the_category(get_the_ID()); … … 204 254 } 205 255 } 206 else 256 else { 207 257 $cat_id = (int) $catlist->term_id; 258 } 208 259 } 209 260 210 261 $cat_id = apply_filters('caticonslite_cat_id', $cat_id); 211 212 if ($cat_id > 0 AND isset($this->caticons_array[$cat_id]['url'])) { 262 if ($cat_id > 0 AND isset($this->caticons_array[$cat_id]['url'])) { 213 263 $result = $this->caticons_array[$cat_id]['url']; 214 } 215 264 } 216 265 return $result; 217 266 } … … 234 283 wp_cache_add( 'categoryiconslite_results', $results ); 235 284 } 236 if ( is_array($results) && count($results)>0) {285 if ( is_array($results) AND 0 < count($results) ) { 237 286 foreach($results as $result) { 238 287 $this->caticons_array[$result->cat_id] = array( 239 'icon_id' => $result->icon_id,240 'url' => esc_url($result->image_url),241 'slug' => $result->slug,242 'name' => $result->name243 );288 'icon_id' => $result->icon_id, 289 'url' => esc_url($result->image_url), 290 'slug' => $result->slug, 291 'name' => $result->name 292 ); 244 293 $this->slugs[$result->slug] = $result->cat_id; 245 294 } … … 258 307 */ 259 308 function list_cats( $output ) { 260 if (count($this->slugs)==0) return $output; 309 if ( 0 == count($this->slugs) ) { 310 return $output; 311 } 261 312 if (!empty($output)) { 262 313 $myarray = $this->url_extractor($output); … … 264 315 $cats = array(); 265 316 $array = preg_match('/.*?\\/.*?\\/.*?\\/\\?cat=(\\d+)/is', $child[0], $correspondances) ; 266 if ( $array == 1 && isset($correspondances[1]) && $correspondances[1] > 0) {317 if (1 == $array AND isset($correspondances[1]) AND 0 < $correspondances[1] ) { 267 318 $cats[] = $correspondances[1];// standard permalinks 268 319 } … … 290 341 $output = str_replace($cat_name.'<', $cat_name.$img.'<', $output); 291 342 break; 292 293 343 case 'center': // Icons only 294 344 $toto = preg_match('/(>.*)</i',$child[1],$result); … … 296 346 $output = str_replace($cat_name.'<','>'.$img.'<', $output); 297 347 break; 298 299 348 } 300 349 } … … 304 353 return $output; 305 354 } 306 307 355 308 356 /** 309 357 * Displays the category assigned to the image (icon) in the media library … … 311 359 function catagory_name($actions, $post) { 312 360 $cat_name = get_cat_name(get_post_meta($post->ID, $this->meta_key, true)); 313 if (!empty($cat_name)) echo '<i>'.esc_html(__('Category').' : '. $cat_name).'</i>'; 361 if ( !empty($cat_name) ) { 362 echo '<i>'.esc_html(__('Category').' : '. $cat_name).'</i>'; 363 } 314 364 return $actions; 315 365 } … … 374 424 $post_meta = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM {$wpdb->prefix}postmeta WHERE meta_key = '".esc_sql($this->meta_key)."' AND meta_value=$cat_id"));// search in postmeta table if the category exists 375 425 $post_id2 = get_post_meta($post_id,$this->meta_key,true); 376 if ( !is_null($post_meta) &&$post_id != $post_meta ) { // tests if the image is different than the one already assigned to the category and throws an error if it's the case, does nothing otherwise426 if ( !is_null($post_meta) AND $post_id != $post_meta ) { // tests if the image is different than the one already assigned to the category and throws an error if it's the case, does nothing otherwise 377 427 delete_post_meta($post_meta,$this->meta_key); 378 428 } … … 397 447 function categories_custom_column( $data, $column, $id) {//$empty, $columnName, $id 398 448 $row = ''; 399 if ( $column == 'caticonslite_icon') {449 if ( 'caticonslite_icon' == $column ) { 400 450 $icon = $this->get_icon($id); 401 451 $icon_img = ''; … … 445 495 function category_removed($term_id) { 446 496 global $wpdb; 447 if( $_POST['taxonomy'] == 'category') {497 if('category' == $_POST['taxonomy'] ) { 448 498 $query = "DELETE FROM {$wpdb->prefix}postmeta WHERE meta_key ='".esc_sql($this->meta_key)."' and meta_value = ".$term_id; 449 499 $results = $wpdb->get_results( $wpdb->prepare($query )); … … 512 562 */ 513 563 function caticons_media_filter( $query ) { 514 global $pagenow, $wp_query;515 if ( is_admin() && $pagenow=='upload.php' && isset( $_GET['caticons'] ) && $_GET['caticons'] == '1') {564 global $pagenow, $wp_query; 565 if ( is_admin() AND 'upload.php' == $pagenow AND isset( $_GET['caticons'] ) AND '1' == $_GET['caticons'] ) { 516 566 set_query_var( 'meta_key', $this->meta_key ) ; 517 567 } … … 523 573 function show_caticons_dropdown() { 524 574 global $post_type, $post_mime_type, $pagenow; 525 if ( $post_type=='attachment' AND ($post_mime_type=='image'OR !isset($post_mime_type))) {575 if ( 'attachment' == $post_type AND ( 'image' == $post_mime_type OR !isset($post_mime_type))) { 526 576 $caticons = isset( $_GET['caticons'] ) ? (int) $_GET['caticons'] : 0; 527 577 ?> … … 530 580 <option <?php selected( $caticons, 1 ); ?> value='1'>Category Icons</option> 531 581 </select> 532 533 582 <?php 534 583 } -
category-icons-lite/tags/1.2/caticonslite.php
r581219 r581647 26 26 if (function_exists('register_uninstall_hook')) register_uninstall_hook(__FILE__,'category_icons_lite_uninstall'); 27 27 28 $caticonslite_icons = $CategoryIconsLite->get_all();28 //$caticonslite_icons = $CategoryIconsLite->get_all(); 29 29 $post_titles_icon = $CategoryIconsLite->are_icons_post_title(); 30 30 $sidebar_icons = $CategoryIconsLite->are_icons_sidebar(); 31 $rss = $CategoryIconsLite->is_rss(); 32 33 if ($rss) {// RSS 34 add_action('rss2_head',array($CategoryIconsLite,'rss_flag')); 35 add_action('rdf_header',array($CategoryIconsLite,'rss_flag')); // only for Safari 36 add_action('atom_ns',array($CategoryIconsLite,'rss_flag')); 37 add_filter('the_excerpt_rss',array($CategoryIconsLite,'rss')); 38 add_filter('the_content',array($CategoryIconsLite,'rss')); 39 add_filter('the_content_rss',array($CategoryIconsLite,'rss')); 40 } 31 41 32 42 if ($sidebar_icons) { // if the option is checked, display the icon in the sidebar … … 74 84 } 75 85 } 86 87 if (!function_exists('get_cat_icon_lite')) { 88 89 function get_cat_icon_lite($cat_id=0) { 90 global $CategoryIconsLite; 91 //return caticonslite_html_tag(caticonslite_get_icon($cat_id)); 92 return $CategoryIconsLite->get_cat_icon($cat_id); 93 } 94 95 } 76 96 } 77 78 if (!function_exists('get_cat_icon_lite')) {79 80 function get_cat_icon_lite($cat_id=0) {81 return caticonslite_html_tag(caticonslite_get_icon($cat_id));82 }83 84 function caticonslite_html_tag($url,$title='') {85 $html = '';86 $alt = 'caticonslite_bm_alt';87 $alt = apply_filters('caticonslite_alt', $alt);88 if (!empty($title)) $title = esc_attr($title);89 $title = apply_filters('caticonslite_title', $title);90 if (!empty($url)) $html = "<img class='caticonslite_bm' alt=\"$alt\" src=\"".esc_url($url)."\" title=\"$title\" />";91 $html = apply_filters('caticonslite_htmltag', $html);92 return $html;93 }94 95 function caticonslite_get_icon($cat_id=0) {96 global $caticonslite_icons;97 $result = '';98 $cat_id = (int) $cat_id;99 if ( 0 == $cat_id ) {100 $catlist = get_the_category(get_the_ID());101 if (is_array($catlist)) {// If there are several categories,102 if (count($catlist) > 0) {103 $cat_id = (int) $catlist[0]->term_id; // I take only the first one104 $cat_id = apply_filters('caticonslite_cat_priority', $cat_id, $catlist);105 }106 else {107 return $result;108 }109 }110 else111 $cat_id = (int) $catlist->term_id;112 }113 114 $cat_id = apply_filters('caticonslite_cat_id', $cat_id);115 116 if ($cat_id > 0 AND isset($caticonslite_icons[$cat_id]['url'])) {117 $result = $caticonslite_icons[$cat_id]['url'];118 }119 120 return $result;121 }122 } -
category-icons-lite/tags/1.2/readme.txt
r581219 r581647 7 7 Stable tag: 1.2 8 8 9 The No. 1 plugin to assign icons to categories easily. 9 The No. 1 plugin to assign icons to categories easily. Category Icons allows you to associate a unique image with each of your WordPress categories. 10 10 11 11 == Description == 12 12 13 Assigns icons to categories with WordPress 3.1 or higher. This plugin : 13 This plugin allows you to associate a unique image with each of your WordPress categories in order to prettify your pages a bit. That will make your category pages look better than 90% of the category pages out there. 14 14 15 * automagically displays an icon in front of your post title (optional) 16 * automagically displays icons next to the category names in the sidebar (optional) 17 * offers 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. 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 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) 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. 18 20 * offers 4 filters for developers : caticonslite_htmltag, caticonslite_alt, caticonslite_title & caticonslite_widget. 19 21 * generates valid XHTML (and Strict XHTML) … … 49 51 If you like this plugin, or it has benefited you, [buy me a coffee](http://www.category-icons.com/support-the-plugin/). 50 52 51 == I've found a bug, how can I tell you about it so you'll fix it for me? ==52 53 Go to the [support page](http://wordpress.org/support/plugin/category-icons-lite). Make sure you let me know the following:54 55 * What version of WordPress you're using56 * What exactly is your issue57 * Provide a screenshot or a link to your website is better58 59 53 == Changelog == 60 54 61 55 = 1.2 = 62 56 * Now you can display icons only in the sidebar by selecting 'center' in the settings 57 * You can enable the display of category icons in the rss 63 58 64 59 = 1.1.4 =
Note: See TracChangeset
for help on using the changeset viewer.