Ticket #3723: tags.diff
File tags.diff, 9.2 KB (added by , 18 years ago) |
---|
-
wp-includes/category.php
23 23 'hide_empty' => true, 'include_last_update_time' => false, 'hierarchical' => 1, 'exclude' => '', 'include' => '', 24 24 'number' => '', 'pad_counts' => false); 25 25 $r = array_merge($defaults, $r); 26 if ( 'count' == $r['orderby'] ) 27 $r['orderby'] = 'category_count'; 28 else 26 if ( 'count' == $r['orderby'] ) { 27 if ( 'link' == $type ) 28 $r['orderby'] = 'link_count'; 29 else if ( 'post' == $type ) 30 $r['orderby'] = 'category_count'; 31 else 32 $r['orderby'] = 'tagged_count'; 33 } else 29 34 $r['orderby'] = "cat_" . $r['orderby']; // restricts order by to cat_ID and cat_name fields 30 35 $r['number'] = (int) $r['number']; 36 if ( 'tag' == $type ) 37 $r['hierarchical'] = 0; 31 38 extract($r); 32 39 33 40 $key = md5( serialize( $r ) ); … … 75 82 if ( $hide_empty && !$hierarchical ) { 76 83 if ( 'link' == $type ) 77 84 $where .= ' AND link_count > 0'; 85 else if ( 'post' == $type ) 86 $where .= ' AND category_count > 0'; 78 87 else 79 $where .= ' AND category_count > 0';88 $where .= ' AND tagged_count > 0'; 80 89 } 81 90 82 91 if ( !empty($number) ) … … 276 285 $results = $wpdb->get_results("SELECT post_id, category_id FROM $wpdb->post2cat LEFT JOIN $wpdb->posts ON post_id = ID WHERE category_id IN (".join(',', $cat_IDs).") AND post_type = 'post' AND post_status = 'publish'"); 277 286 foreach ( $results as $row ) 278 287 ++$cat_items[$row->category_id][$row->post_id]; 279 } else {288 } else if ( $type == 'link' ) { 280 289 $results = $wpdb->get_results("SELECT $wpdb->link2cat.link_id, category_id FROM $wpdb->link2cat LEFT JOIN $wpdb->links USING (link_id) WHERE category_id IN (".join(',', $cat_IDs).") AND link_visible = 'Y'"); 281 290 foreach ( $results as $row ) 282 291 ++$cat_items[$row->category_id][$row->link_id]; 292 } else { 293 $results = $wpdb->get_results("SELECT post_id, category_id FROM $wpdb->post2tag LEFT JOIN $wpdb->posts ON post_id = ID WHERE category_id IN (".join(',', $cat_IDs).") AND post_type = 'post' AND post_status = 'publish'"); 294 foreach ( $results as $row ) 295 ++$cat_items[$row->category_id][$row->post_id]; 283 296 } 284 297 285 298 // Touch every ancestor's lookup row for each post in each category … … 293 306 } 294 307 } 295 308 296 // Transfer the touched cells 309 // Transfer the touched cells // TAGFIX 297 310 foreach ( (array) $cat_items as $id => $items ) 298 311 if ( isset($cats[$id]) ) 299 312 $cats[$id]->{'link' == $type ? 'link_count' : 'category_count'} = count($items); -
wp-includes/post.php
453 453 return array_unique($cat_ids); 454 454 } 455 455 456 function wp_get_post_tags($post_id = 0) { 457 $cats = &get_the_tags($post_id); 458 $cat_ids = array(); 459 foreach ( $cats as $cat ) 460 $cat_ids[] = (int) $cat->cat_ID; 461 return array_unique($cat_ids); 462 } 463 456 464 function wp_get_recent_posts($num = 10) { 457 465 global $wpdb; 458 466 … … 761 769 return wp_update_post(array('post_status' => 'publish', 'ID' => $post_id, 'no_filter' => true)); 762 770 } 763 771 764 function wp_set_post_categories($post_ID = 0, $post_categories = array()) {772 function _set_post_categories($type = 'cat', $post_ID = 0, $post_categories = array()) { 765 773 global $wpdb; 766 // If $post_categories isn't already an array, make it one:767 if (!is_array($post_categories) || 0 == count($post_categories) || empty($post_categories))768 $post_categories = array(get_option('default_category'));769 774 770 775 $post_categories = array_unique($post_categories); 771 776 777 if ( 'cat' == $type ) { 778 $table = 'post2cat'; 779 $counter = 'category_count'; 780 } else { 781 $table = 'post2tag'; 782 $counter = 'tagged_count'; 783 } 784 772 785 // First the old categories 773 786 $old_categories = $wpdb->get_col(" 774 787 SELECT category_id 775 FROM $wpdb-> post2cat788 FROM $wpdb->$table 776 789 WHERE post_id = $post_ID"); 777 790 778 791 if (!$old_categories) { … … 787 800 if ($delete_cats) { 788 801 foreach ($delete_cats as $del) { 789 802 $wpdb->query(" 790 DELETE FROM $wpdb-> post2cat803 DELETE FROM $wpdb->$table 791 804 WHERE category_id = $del 792 805 AND post_id = $post_ID 793 806 "); … … 801 814 foreach ($add_cats as $new_cat) { 802 815 if ( !empty($new_cat) ) 803 816 $wpdb->query(" 804 INSERT INTO $wpdb-> post2cat(post_id, category_id)817 INSERT INTO $wpdb->$table (post_id, category_id) 805 818 VALUES ($post_ID, $new_cat)"); 806 819 } 807 820 } … … 809 822 // Update category counts. 810 823 $all_affected_cats = array_unique(array_merge($post_categories, $old_categories)); 811 824 foreach ( $all_affected_cats as $cat_id ) { 812 $count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb-> post2cat, $wpdb->posts WHERE $wpdb->posts.ID=$wpdb->post2cat.post_id AND post_status = 'publish' AND post_type = 'post' AND category_id = '$cat_id'");813 $wpdb->query("UPDATE $wpdb->categories SET category_count= '$count' WHERE cat_ID = '$cat_id'");825 $count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->$table, $wpdb->posts WHERE $wpdb->posts.ID=$wpdb->$table.post_id AND post_status = 'publish' AND post_type = 'post' AND category_id = '$cat_id'"); 826 $wpdb->query("UPDATE $wpdb->categories SET $counter = '$count' WHERE cat_ID = '$cat_id'"); 814 827 clean_category_cache($cat_id); 815 828 do_action('edit_category', $cat_id); 816 829 } 817 } // wp_set_post_categories()830 } 818 831 832 function wp_set_post_categories($post_ID = 0, $post_categories = array()) { 833 // If $post_categories isn't already an array, make it one: 834 if (!is_array($post_categories) || 0 == count($post_categories) || empty($post_categories)) 835 $post_categories = array(get_option('default_category')); 836 837 return _set_post_categories($post_ID, $post_categories); 838 } 839 840 function wp_set_post_tags($post_ID = 0, $post_tags = array()) { 841 global $wpdb; 842 // If $post_categories isn't already an array, make it one: 843 if (!is_array($post_tags) || 0 == count($post_tags) || empty($post_tags)) 844 $post_tags = array(); 845 846 return _set_post_categories($post_ID, $post_tags); 847 } 848 819 849 // 820 850 // Trackback and ping functions 821 851 // -
wp-admin/admin-functions.php
635 635 636 636 function return_categories_list( $parent = 0 ) { 637 637 global $wpdb; 638 return $wpdb->get_col( "SELECT cat_ID FROM $wpdb->categories WHERE category_parent = $parent AND ( link_count = 0 OR category_count != 0 OR ( link_count = 0 AND category_count = 0 ) ) ORDER BY category_count DESC" );638 return $wpdb->get_col( "SELECT cat_ID FROM $wpdb->categories WHERE category_parent = $parent AND ( link_count = 0 OR category_count != 0 OR tagged_count = 0 OR ( link_count = 0 AND category_count = 0 AND tagged_count = 0 ) ) ORDER BY category_count DESC" ); 639 639 } 640 640 641 641 function sort_cats( $cat1, $cat2 ) { … … 709 709 710 710 function return_link_categories_list( $parent = 0 ) { 711 711 global $wpdb; 712 return $wpdb->get_col( "SELECT cat_ID FROM $wpdb->categories WHERE category_parent = $parent AND ( category_count = 0 OR link_count != 0 OR ( link_count = 0 AND category_count = 0 ) ) ORDER BY link_count DESC" );712 return $wpdb->get_col( "SELECT cat_ID FROM $wpdb->categories WHERE category_parent = $parent AND ( category_count = 0 OR link_count != 0 OR tagged_count = 0 OR ( link_count = 0 AND category_count = 0 AND tagged_count = 0 ) ) ORDER BY link_count DESC" ); 713 713 } 714 714 715 715 function get_nested_link_categories( $default = 0, $parent = 0 ) { -
wp-admin/admin-db.php
248 248 return $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE category_nicename = '$category_nicename'"); 249 249 } 250 250 251 function wp_create_tag($tag_name) { 252 return wp_create_tag($tag_name); 253 } 254 255 function wp_create_tags($tags, $post_id = '') { 256 $cat_ids = array (); 257 foreach ($tags as $tag) { 258 if ($id = tag_exists($tag)) 259 $tag_ids[] = $id; 260 else 261 if ($id = wp_create_tag($tag)) 262 $tag_ids[] = $id; 263 } 264 265 if ($post_id) 266 wp_set_post_tags($post_id, $tag_ids); 267 268 return $tag_ids; 269 } 270 271 function tag_exists($tag_name) { 272 return category_exists($tag_name); 273 } 274 251 275 function wp_delete_user($id, $reassign = 'novalue') { 252 276 global $wpdb; 253 277 -
wp-admin/upgrade-schema.php
18 18 category_parent bigint(20) NOT NULL default '0', 19 19 category_count bigint(20) NOT NULL default '0', 20 20 link_count bigint(20) NOT NULL default '0', 21 tagged_count bigint(20) NOT NULL default '0', 21 22 posts_private tinyint(1) NOT NULL default '0', 22 23 links_private tinyint(1) NOT NULL default '0', 23 24 PRIMARY KEY (cat_ID), … … 91 92 PRIMARY KEY (rel_id), 92 93 KEY post_id (post_id,category_id) 93 94 ) $charset_collate; 95 CREATE TABLE $wpdb->post2tag ( 96 rel_id bigint(20) NOT NULL auto_increment, 97 post_id bigint(20) NOT NULL default '0', 98 tag_id bigint(20) NOT NULL default '0', 99 PRIMARY KEY (rel_id), 100 KEY post_id (post_id,tag_id) 101 ) $charset_collate; 94 102 CREATE TABLE $wpdb->postmeta ( 95 103 meta_id bigint(20) NOT NULL auto_increment, 96 104 post_id bigint(20) NOT NULL default '0',