Changeset 5510
- Timestamp:
- 05/22/2007 05:12:38 AM (17 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/admin-db.php
r5272 r5510 283 283 284 284 function tag_exists($tag_name) { 285 global $wpdb; 286 if (! $tag_nicename = sanitize_title($tag_name)) 287 return 0; 288 289 return (int) $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE category_nicename = '$tag_nicename' AND ( type & " . TAXONOMY_TAG . " != 0 )"); 285 return is_term($tag_name, 'post_tag'); 290 286 } 291 287 … … 293 289 if ( $id = tag_exists($tag_name) ) 294 290 return $id; 295 $tag_array = array('cat_name' => $tag_name, 'type' => TAXONOMY_TAG); 296 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 } 291 292 $tag_id = add_term($tag_name, 'post_tag'); 306 293 } 307 294 -
trunk/wp-admin/admin-functions.php
r5404 r5510 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->name; 677 674 $tags_to_edit = join( ', ', $tag_names ); 678 675 $tags_to_edit = attribute_escape( $tags_to_edit ); -
trunk/wp-admin/upgrade-schema.php
r5303 r5510 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 name varchar(55) NOT NULL default '', 16 slug varchar(200) NOT NULL default '', 17 term_group bigint(10) NOT NULL default 0, 18 PRIMARY KEY (term_id), 19 UNIQUE KEY slug (slug) 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 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) 27 36 ) $charset_collate; 28 37 CREATE TABLE $wpdb->comments ( … … 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, … … 86 88 PRIMARY KEY (option_id,blog_id,option_name), 87 89 KEY option_name (option_name) 88 ) $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 90 ) $charset_collate; 97 91 CREATE TABLE $wpdb->postmeta ( -
trunk/wp-includes/post.php
r5459 r5510 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 … … 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 -
trunk/wp-includes/version.php
r5303 r5510 4 4 5 5 $wp_version = '2.3-alpha'; 6 $wp_db_version = 5 200;6 $wp_db_version = 5495; 7 7 8 8 ?> -
trunk/wp-includes/wp-db.php
r5458 r5510 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; -
trunk/wp-settings.php
r5491 r5510 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') ) … … 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) {
Note: See TracChangeset
for help on using the changeset viewer.