Ticket #4189: terms.diff
File terms.diff, 9.3 KB (added by , 17 years ago) |
---|
-
wp-includes/wp-db.php
34 34 var $optiongroups; 35 35 var $optiongroup_options; 36 36 var $postmeta; 37 var $terms; 38 var $term_taxonomy; 39 var $term_relationships; 37 40 38 41 var $charset; 39 42 var $collate; -
wp-includes/post.php
459 459 460 460 $post_id = (int) $post_id; 461 461 462 if ( !isset( $tag_cache[$blog_id][$post_id] ) ) 463 update_post_category_cache( $post_id ); // loads $tag_cache 464 465 return $tag_cache[$blog_id][$post_id]; 462 $tags = get_object_terms($post_id, 'post_tag'); 463 return $tags; 466 464 } 467 465 468 466 function wp_get_recent_posts($num = 10) { … … 792 790 793 791 if ( !$post_id ) 794 792 return false; 795 796 // prevent warnings for unintialized variables797 $tag_ids = array();798 793 799 794 if ( empty($tags) ) 800 795 $tags = array(); 801 796 $tags = (is_array($tags)) ? $tags : explode( ',', $tags ); 802 803 foreach ( $tags as $tag ) { 804 $tag = trim( $tag ); 805 if ( !$tag_slug = sanitize_title( $tag ) ) 806 continue; // discard 807 if ( !$tag_id = tag_exists( $tag ) ) 808 $tag_id = wp_create_tag( $tag ); 809 $tag_ids[] = $tag_id; 810 } 811 812 if ( empty($tag_ids) && ( !empty($tags) || $append ) ) 813 return false; 814 815 $tag_ids = array_unique( $tag_ids ); 816 817 // First the old tags 818 $old_tags = $wpdb->get_col(" 819 SELECT category_id 820 FROM $wpdb->post2cat 821 WHERE post_id = '$post_id' AND rel_type = 'tag'"); 822 823 if ( !$old_tags ) { 824 $old_tags = array(); 825 } else { 826 $old_tags = array_unique( $old_tags ); 827 } 828 829 // Delete any? 830 $delete_tags = array_diff( $old_tags, $tag_ids); 831 if ( $delete_tags && !$append ) { 832 foreach ( $delete_tags as $del ) { 833 $wpdb->query(" 834 DELETE FROM $wpdb->post2cat 835 WHERE category_id = '$del' 836 AND post_id = '$post_id' 837 AND rel_type = 'tag' 838 "); 839 } 840 } 841 842 // Add any? 843 $add_tags = array_diff( $tag_ids, $old_tags ); 844 if ( $add_tags ) { 845 foreach ( $add_tags as $new_tag ) { 846 $new_tag = (int) $new_tag; 847 if ( !empty($new_tag) ) 848 $wpdb->query(" 849 INSERT INTO $wpdb->post2cat (post_id, category_id, rel_type) 850 VALUES ('$post_id', '$new_tag', 'tag')"); 851 } 852 } 853 854 // Update category counts. 855 $all_affected_tags = array_unique( array_merge( $tag_ids, $old_tags ) ); 856 foreach ( $all_affected_tags as $tag_id ) { 857 $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 = '$tag_id' AND rel_type = 'tag'" ); 858 $wpdb->query( "UPDATE $wpdb->categories SET tag_count = '$count', type = type | " . TAXONOMY_TAG . " WHERE cat_ID = '$tag_id'" ); 859 if ( $count == 0 ) 860 $wpdb->query( "UPDATE $wpdb->categories SET type = type & ~". TAXONOMY_TAG . " WHERE cat_ID = '$tag_id'" ); 861 clean_category_cache( $tag_id ); 862 do_action( 'edit_category', $tag_id ); 863 do_action( 'edit_tag', $tag_id ); 864 } 797 add_term_relationship($tags, $post_id, 'post_tag'); 865 798 } 866 799 867 800 function wp_set_post_categories($post_ID = 0, $post_categories = array()) { -
wp-includes/version.php
3 3 // This holds the version number in a separate file so we can bump it without cluttering the SVN 4 4 5 5 $wp_version = '2.3-alpha'; 6 $wp_db_version = 5 200;6 $wp_db_version = 5495; 7 7 8 8 ?> -
wp-settings.php
116 116 $wpdb->options = $wpdb->prefix . 'options'; 117 117 $wpdb->postmeta = $wpdb->prefix . 'postmeta'; 118 118 $wpdb->usermeta = $wpdb->prefix . 'usermeta'; 119 $wpdb->terms = $wpdb->prefix . 'terms'; 120 $wpdb->term_taxonomy = $wpdb->prefix . 'term_taxonomy'; 121 $wpdb->term_relationships = $wpdb->prefix . 'term_relationships'; 119 122 120 123 if ( defined('CUSTOM_USER_TABLE') ) 121 124 $wpdb->users = CUSTOM_USER_TABLE; … … 168 171 require (ABSPATH . WPINC . '/version.php'); 169 172 require (ABSPATH . WPINC . '/deprecated.php'); 170 173 require (ABSPATH . WPINC . '/script-loader.php'); 174 require (ABSPATH . WPINC . '/taxonomy.php'); 171 175 172 176 if (strpos($_SERVER['PHP_SELF'], 'install.php') === false) { 173 177 // Used to guarantee unique hash cookies -
wp-admin/admin-functions.php
664 664 if ( !$post_id ) 665 665 return false; 666 666 667 $tags = $wpdb->get_results( " 668 SELECT category_id, cat_name 669 FROM $wpdb->categories, $wpdb->post2cat 670 WHERE $wpdb->post2cat.category_id = cat_ID AND $wpdb->post2cat.post_id = '$post_id' AND rel_type = 'tag' 671 " ); 667 $tags = wp_get_post_tags($post_id); 668 672 669 if ( !$tags ) 673 670 return false; 674 671 675 672 foreach ( $tags as $tag ) 676 $tag_names[] = $tag-> cat_name;673 $tag_names[] = $tag->term_name; 677 674 $tags_to_edit = join( ', ', $tag_names ); 678 675 $tags_to_edit = attribute_escape( $tags_to_edit ); 679 676 $tags_to_edit = apply_filters( 'tags_to_edit', $tags_to_edit ); -
wp-admin/admin-db.php
286 286 if (! $tag_nicename = sanitize_title($tag_name)) 287 287 return 0; 288 288 289 return (int) $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE category_nicename = '$tag_nicename' AND ( type & " . TAXONOMY_TAG . " != 0 )");289 return is_term($tag_name, 'post_tag'); 290 290 } 291 291 292 292 function wp_create_tag($tag_name) { 293 293 if ( $id = tag_exists($tag_name) ) 294 294 return $id; 295 $tag_array = array('cat_name' => $tag_name, 'type' => TAXONOMY_TAG);296 295 297 if ( $id = category_object_exists($tag_name) ) { 298 $category = get_category($id); 299 $tag_array['type'] = $category->type | $tag_array['type']; 300 $tag_array['cat_ID'] = $id; 301 $id = wp_update_category($tag_array); 302 return $id; 303 } else { 304 return wp_insert_category($tag_array); 305 } 296 $tag_id = add_term($tag_name, 'post_tag'); 306 297 } 307 298 308 299 function wp_delete_user($id, $reassign = 'novalue') { -
wp-admin/upgrade-schema.php
10 10 $charset_collate .= " COLLATE $wpdb->collate"; 11 11 } 12 12 13 $wp_queries="CREATE TABLE $wpdb->categories ( 14 cat_ID bigint(20) NOT NULL auto_increment, 15 cat_name varchar(55) NOT NULL default '', 16 category_nicename varchar(200) NOT NULL default '', 17 category_description longtext NOT NULL, 18 category_parent bigint(20) NOT NULL default '0', 19 category_count bigint(20) NOT NULL default '0', 20 link_count bigint(20) NOT NULL default '0', 21 tag_count bigint(20) NOT NULL default '0', 22 posts_private tinyint(1) NOT NULL default '0', 23 links_private tinyint(1) NOT NULL default '0', 24 type tinyint NOT NULL default '1', 25 PRIMARY KEY (cat_ID), 26 KEY category_nicename (category_nicename) 13 $wp_queries="CREATE TABLE $wpdb->terms ( 14 term_id bigint(20) NOT NULL auto_increment, 15 term_name varchar(55) NOT NULL default '', 16 term_slug varchar(200) NOT NULL default '', 17 term_group bigint(10) NOT NULL default 0, 18 PRIMARY KEY (term_id), 19 UNIQUE KEY term_slug (term_slug) 27 20 ) $charset_collate; 21 CREATE TABLE $wpdb->term_taxonomy ( 22 term_taxonomy_id bigint(20) NOT NULL auto_increment, 23 term_id bigint(20) NOT NULL default 0, 24 taxonomy varchar(32) NOT NULL default '', 25 term_description longtext NOT NULL, 26 parent bigint(20) NOT NULL default 0, 27 count bigint(20) NOT NULL default 0, 28 PRIMARY KEY (term_taxonomy_id), 29 UNIQUE KEY (term_id, taxonomy) 30 ) $charset_collate; 31 CREATE TABLE $wpdb->term_relationships ( 32 object_id bigint(20) NOT NULL default 0, 33 term_taxonomy_id bigint(20) NOT NULL default 0, 34 PRIMARY KEY (object_id), 35 KEY (term_taxonomy_id) 36 ) $charset_collate; 28 37 CREATE TABLE $wpdb->comments ( 29 38 comment_ID bigint(20) unsigned NOT NULL auto_increment, 30 39 comment_post_ID int(11) NOT NULL default '0', … … 45 54 KEY comment_approved (comment_approved), 46 55 KEY comment_post_ID (comment_post_ID) 47 56 ) $charset_collate; 48 CREATE TABLE $wpdb->link2cat (49 rel_id bigint(20) NOT NULL auto_increment,50 link_id bigint(20) NOT NULL default '0',51 category_id bigint(20) NOT NULL default '0',52 PRIMARY KEY (rel_id),53 KEY link_id (link_id,category_id)54 ) $charset_collate;55 57 CREATE TABLE $wpdb->links ( 56 58 link_id bigint(20) NOT NULL auto_increment, 57 59 link_url varchar(255) NOT NULL default '', … … 86 88 PRIMARY KEY (option_id,blog_id,option_name), 87 89 KEY option_name (option_name) 88 90 ) $charset_collate; 89 CREATE TABLE $wpdb->post2cat (90 rel_id bigint(20) NOT NULL auto_increment,91 post_id bigint(20) NOT NULL default '0',92 category_id bigint(20) NOT NULL default '0',93 rel_type varchar(64) NOT NULL default 'category',94 PRIMARY KEY (rel_id),95 KEY post_id (post_id,category_id)96 ) $charset_collate;97 91 CREATE TABLE $wpdb->postmeta ( 98 92 meta_id bigint(20) NOT NULL auto_increment, 99 93 post_id bigint(20) NOT NULL default '0', … … 404 398 } 405 399 } 406 400 407 ?> 408 No newline at end of file 401 ?>