Changeset 5110
- Timestamp:
- 03/26/2007 07:28:29 AM (18 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/admin-functions.php
r5089 r5110 648 648 function return_categories_list( $parent = 0 ) { 649 649 global $wpdb; 650 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" );650 return $wpdb->get_col( "SELECT cat_ID FROM $wpdb->categories WHERE category_parent = $parent AND ( ( link_count = 0 AND tag_count = 0 ) OR category_count != 0 OR ( link_count = 0 AND category_count = 0 AND tag_count = 0 ) ) ORDER BY category_count DESC" ); 651 651 } 652 652 … … 658 658 } 659 659 660 function get_tags_to_edit( $post_id ) { 661 global $wpdb; 662 663 $post_id = (int) $post_id; 664 if ( !$post_id ) 665 return false; 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 " ); 672 if ( !$tags ) 673 return false; 674 675 foreach ( $tags as $tag ) 676 $tag_names[] = $tag->cat_name; 677 $tags_to_edit = join( ', ', $tag_names ); 678 $tags_to_edit = attribute_escape( $tags_to_edit ); 679 $tags_to_edit = apply_filters( 'tags_to_edit', $tags_to_edit ); 680 return $tags_to_edit; 681 } 682 660 683 function get_nested_categories( $default = 0, $parent = 0 ) { 661 684 global $post_ID, $link_id, $mode, $wpdb; … … 665 688 SELECT category_id 666 689 FROM $wpdb->categories, $wpdb->post2cat 667 WHERE $wpdb->post2cat.category_id = cat_ID AND $wpdb->post2cat.post_id = '$post_ID' 690 WHERE $wpdb->post2cat.category_id = cat_ID AND $wpdb->post2cat.post_id = '$post_ID' AND rel_type = 'category' 668 691 " ); 669 692 … … 722 745 function return_link_categories_list( $parent = 0 ) { 723 746 global $wpdb; 724 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" );747 return $wpdb->get_col( "SELECT cat_ID FROM $wpdb->categories WHERE category_parent = $parent AND ( ( category_count = 0 AND tag_count = 0 ) OR link_count != 0 OR ( link_count = 0 AND category_count = 0 AND tag_count = 0 ) ) ORDER BY link_count DESC" ); 725 748 } 726 749 -
trunk/wp-admin/edit-form-advanced.php
r5056 r5110 153 153 <?php echo $form_prevstatus ?> 154 154 155 <div class="tagdiv"><p>Enter tags (keywords) that you feel describe this post separated by commas: (ex: dogs, san francisco, cats.)<br /> 156 <input type="text" name="tags_input" id="tags_input" size="30" tabindex="3" value="<?php echo get_tags_to_edit( $post_ID ); ?>" /> 157 </p></div> 155 158 156 159 <p class="submit"> -
trunk/wp-admin/upgrade-schema.php
r4953 r5110 19 19 category_count bigint(20) NOT NULL default '0', 20 20 link_count bigint(20) NOT NULL default '0', 21 tag_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', … … 89 90 post_id bigint(20) NOT NULL default '0', 90 91 category_id bigint(20) NOT NULL default '0', 92 rel_type varchar(64) NOT NULL default 'category', 91 93 PRIMARY KEY (rel_id), 92 94 KEY post_id (post_id,category_id) -
trunk/wp-admin/wp-admin.css
r5103 r5110 559 559 } 560 560 561 #titlediv input, #guiddiv input {561 #titlediv input, #guiddiv input, #tags_input { 562 562 margin: 0; 563 563 width: 100%; -
trunk/wp-includes/post.php
r5090 r5110 518 518 $comment_status = apply_filters('comment_status_pre', $comment_status); 519 519 $ping_status = apply_filters('ping_status_pre', $ping_status); 520 $tags_input = apply_filters('tags_input_pre', $tags_input); 520 521 } 521 522 … … 652 653 } 653 654 654 wp_set_post_categories($post_ID, $post_category); 655 wp_set_post_categories( $post_ID, $post_category ); 656 wp_set_post_tags( $post_ID, $tags_input ); 655 657 656 658 if ( 'page' == $post_type ) { … … 770 772 } 771 773 774 function wp_set_post_tags( $post_id = 0, $tags = '' ) { 775 global $wpdb; 776 777 $post_id = (int) $post_id; 778 779 if ( !$post_id ) 780 return false; 781 782 $tags = explode( ',', $tags ); 783 foreach ( $tags as $tag ) { 784 $tag = trim( $tag ); 785 if ( !$tag_slug = sanitize_title( $tag ) ) 786 continue; // discard 787 if ( !$tag_id = category_exists( $tag ) ) 788 $tag_id = wp_create_category( $tag ); 789 $tag_ids[] = $tag_id; 790 } 791 792 $tag_ids = array_unique( $tag_ids ); 793 794 // First the old tags 795 $old_tags = $wpdb->get_col(" 796 SELECT category_id 797 FROM $wpdb->post2cat 798 WHERE post_id = '$post_id' AND rel_type = 'tag'"); 799 800 if ( !$old_tags ) { 801 $old_tags = array(); 802 } else { 803 $old_tags = array_unique( $old_tags ); 804 } 805 806 // Delete any? 807 $delete_tags = array_diff( $old_tags, $tag_ids); 808 if ( $delete_tags ) { 809 foreach ( $delete_tags as $del ) { 810 $wpdb->query(" 811 DELETE FROM $wpdb->post2cat 812 WHERE category_id = '$del' 813 AND post_id = '$post_id' 814 AND rel_type = 'tag' 815 "); 816 } 817 } 818 819 // Add any? 820 $add_tags = array_diff( $tag_ids, $old_tags ); 821 if ( $add_tags ) { 822 foreach ( $add_tags as $new_tag ) { 823 $new_tag = (int) $new_tag; 824 if ( !empty($new_tag) ) 825 $wpdb->query(" 826 INSERT INTO $wpdb->post2cat (post_id, category_id, rel_type) 827 VALUES ('$post_id', '$new_tag', 'tag')"); 828 } 829 } 830 831 // Update category counts. 832 $all_affected_tags = array_unique( array_merge( $tag_ids, $old_tags ) ); 833 foreach ( $all_affected_tags as $tag_id ) { 834 $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'" ); 835 $wpdb->query( "UPDATE $wpdb->categories SET tag_count = '$count' WHERE cat_ID = '$tag_id'" ); 836 if ( $count == 0 ) 837 $wpdb->query( "UPDATE $wpdb->categories SET tag_count = '-1' WHERE cat_ID = '$tag_id'" ); 838 clean_category_cache( $tag_id ); 839 do_action( 'edit_category', $tag_id ); 840 do_action( 'edit_tag', $tag_id ); 841 } 842 } 843 772 844 function wp_set_post_categories($post_ID = 0, $post_categories = array()) { 773 845 global $wpdb; … … 784 856 SELECT category_id 785 857 FROM $wpdb->post2cat 786 WHERE post_id = '$post_ID' ");858 WHERE post_id = '$post_ID' AND rel_type = 'category'"); 787 859 788 860 if (!$old_categories) { … … 821 893 $all_affected_cats = array_unique(array_merge($post_categories, $old_categories)); 822 894 foreach ( $all_affected_cats as $cat_id ) { 823 $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' ");895 $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' AND rel_type = 'category'"); 824 896 $wpdb->query("UPDATE $wpdb->categories SET category_count = '$count' WHERE cat_ID = '$cat_id'"); 825 897 clean_category_cache($cat_id); -
trunk/wp-includes/version.php
r4860 r5110 4 4 5 5 $wp_version = '2.2-bleeding'; 6 $wp_db_version = 486 0;6 $wp_db_version = 4865; 7 7 8 8 ?>
Note: See TracChangeset
for help on using the changeset viewer.