Changeset 5529
- Timestamp:
- 05/23/2007 06:07:53 PM (17 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/admin-functions.php
r5528 r5529 679 679 680 680 function get_nested_categories( $default = 0, $parent = 0 ) { 681 global $post_ID, $ link_id, $mode, $wpdb;681 global $post_ID, $mode, $wpdb; 682 682 683 683 if ( $post_ID ) { 684 $checked_categories = $wpdb->get_col( " 685 SELECT category_id 686 FROM $wpdb->categories, $wpdb->post2cat 687 WHERE $wpdb->post2cat.category_id = cat_ID AND $wpdb->post2cat.post_id = '$post_ID' AND rel_type = 'category' 688 " ); 684 $checked_categories = wp_get_post_categories($post_ID); 689 685 690 686 if ( count( $checked_categories ) == 0 ) { … … 692 688 $checked_categories[] = $default; 693 689 } 694 } else if ( $link_id ) {695 $checked_categories = $wpdb->get_col( "696 SELECT category_id697 FROM $wpdb->categories, $wpdb->link2cat698 WHERE $wpdb->link2cat.category_id = cat_ID AND $wpdb->link2cat.link_id = '$link_id'699 " );700 701 if ( count( $checked_categories ) == 0 ) {702 // No selected categories, strange703 $checked_categories[] = $default;704 }705 690 } else { 706 691 $checked_categories[] = $default; 707 692 } 708 693 709 $cats = return_categories_list( $parent);694 $cats = get_categories("child_of=$parent&hide_empty=0&get=ids"); 710 695 $result = array (); 711 696 712 697 if ( is_array( $cats ) ) { 713 698 foreach ( $cats as $cat) { 714 $result[$cat]['children'] = get_nested_categories( $default, $cat);699 //$result[$cat]['children'] = get_nested_categories( $default, $cat); 715 700 $result[$cat]['cat_ID'] = $cat; 716 701 $result[$cat]['checked'] = in_array( $cat, $checked_categories ); … … 755 740 } 756 741 757 $categories = get_terms('link_category', 'orderby=count ');742 $categories = get_terms('link_category', 'orderby=count&hide_empty=0'); 758 743 759 744 if ( empty($categories) ) … … 773 758 $categories = get_categories( 'hide_empty=0' ); 774 759 775 $children = _get_ category_hierarchy();760 $children = _get_term_hierarchy('category'); 776 761 777 762 if ( $categories ) { … … 960 945 if ( $categories ) { 961 946 foreach ( $categories as $category ) { 962 if ( $currentcat != $category-> cat_ID && $parent == $category->category_parent) {947 if ( $currentcat != $category->term_id && $parent == $category->parent) { 963 948 $pad = str_repeat( '– ', $level ); 964 $category-> cat_name = wp_specialchars( $category->cat_name );965 echo "\n\t<option value='$category-> cat_ID'";966 if ( $currentparent == $category-> cat_ID)949 $category->name = wp_specialchars( $category->name ); 950 echo "\n\t<option value='$category->term_id'"; 951 if ( $currentparent == $category->term_id ) 967 952 echo " selected='selected'"; 968 echo ">$pad$category-> cat_name</option>";969 wp_dropdown_cats( $currentcat, $currentparent, $category-> cat_ID, $level +1, $categories );953 echo ">$pad$category->name</option>"; 954 wp_dropdown_cats( $currentcat, $currentparent, $category->term_id, $level +1, $categories ); 970 955 } 971 956 } -
trunk/wp-admin/edit-category-form.php
r4941 r5529 22 22 <?php echo $form ?> 23 23 <input type="hidden" name="action" value="<?php echo $action ?>" /> 24 <input type="hidden" name="cat_ID" value="<?php echo $category-> cat_ID?>" />24 <input type="hidden" name="cat_ID" value="<?php echo $category->term_id ?>" /> 25 25 <?php wp_nonce_field($nonce_action); ?> 26 26 <table class="editform" width="100%" cellspacing="2" cellpadding="5"> 27 27 <tr> 28 28 <th width="33%" scope="row" valign="top"><label for="cat_name"><?php _e('Category name:') ?></label></th> 29 <td width="67%"><input name="cat_name" id="cat_name" type="text" value="<?php echo attribute_escape($category-> cat_name); ?>" size="40" /></td>29 <td width="67%"><input name="cat_name" id="cat_name" type="text" value="<?php echo attribute_escape($category->name); ?>" size="40" /></td> 30 30 </tr> 31 31 <tr> 32 32 <th scope="row" valign="top"><label for="category_nicename"><?php _e('Category slug:') ?></label></th> 33 <td><input name="category_nicename" id="category_nicename" type="text" value="<?php echo attribute_escape($category-> category_nicename); ?>" size="40" /></td>33 <td><input name="category_nicename" id="category_nicename" type="text" value="<?php echo attribute_escape($category->slug); ?>" size="40" /></td> 34 34 </tr> 35 35 <tr> 36 36 <th scope="row" valign="top"><label for="category_parent"><?php _e('Category parent:') ?></label></th> 37 37 <td> 38 <?php wp_dropdown_categories('hide_empty=0&name=category_parent&orderby=name&selected=' . $category-> category_parent . '&hierarchical=1&show_option_none=' . __('None')); ?>38 <?php wp_dropdown_categories('hide_empty=0&name=category_parent&orderby=name&selected=' . $category->parent . '&hierarchical=1&show_option_none=' . __('None')); ?> 39 39 </td> 40 40 </tr> 41 41 <tr> 42 42 <th scope="row" valign="top"><label for="category_description"><?php _e('Description: (optional)') ?></label></th> 43 <td><textarea name="category_description" id="category_description" rows="5" cols="50" style="width: 97%;"><?php echo wp_specialchars($category-> category_description); ?></textarea></td>43 <td><textarea name="category_description" id="category_description" rows="5" cols="50" style="width: 97%;"><?php echo wp_specialchars($category->description); ?></textarea></td> 44 44 </tr> 45 45 </table> -
trunk/wp-includes/category-template.php
r5521 r5529 13 13 14 14 $category = get_category($cat_id); 15 if ( $category-> category_parent == $id ) {16 $chain .= $before.$category-> cat_ID.$after;17 $chain .= get_category_children($category-> cat_ID, $before, $after);15 if ( $category->parent == $id ) { 16 $chain .= $before.$category->term_id.$after; 17 $chain .= get_category_children($category->term_id, $before, $after); 18 18 } 19 19 } … … 30 30 } else { 31 31 $category = &get_category($category_id); 32 $category_nicename = $category-> category_nicename;33 34 if ( $parent = $category-> category_parent )32 $category_nicename = $category->slug; 33 34 if ( $parent = $category->parent ) 35 35 $category_nicename = get_category_parents($parent, false, '/', true) . $category_nicename; 36 36 … … 46 46 47 47 if ( $nicename ) 48 $name = $parent-> category_nicename;48 $name = $parent->slug; 49 49 else 50 50 $name = $parent->cat_name; 51 51 52 if ( $parent-> category_parent && ($parent->category_parent != $parent->cat_ID) )53 $chain .= get_category_parents($parent-> category_parent, $link, $separator, $nicename);52 if ( $parent->parent && ($parent->parent != $parent->term_id) ) 53 $chain .= get_category_parents($parent->parent, $link, $separator, $nicename); 54 54 55 55 if ( $link ) 56 $chain .= '<a href="' . get_category_link($parent-> cat_ID) . '" title="' . sprintf(__("View all posts in %s"), $parent->cat_name) . '">'.$name.'</a>' . $separator;56 $chain .= '<a href="' . get_category_link($parent->term_id) . '" title="' . sprintf(__("View all posts in %s"), $parent->cat_name) . '">'.$name.'</a>' . $separator; 57 57 else 58 58 $chain .= $name.$separator; … … 61 61 62 62 function get_the_category($id = false) { 63 global $post, $category_cache, $blog_id;63 global $post, $category_cache, $blog_id; 64 64 65 65 $id = (int) $id; … … 67 67 $id = (int) $post->ID; 68 68 69 if ( !isset($category_cache[$blog_id][$id]) ) 70 update_post_category_cache($id); 71 72 $categories = $category_cache[$blog_id][$id]; 69 $categories = get_object_terms($id, 'category'); 73 70 74 71 if ( !empty($categories) ) … … 87 84 $cat_ID = (int) $cat_ID; 88 85 $category = &get_category($cat_ID); 89 return $category-> cat_name;86 return $category->name; 90 87 } 91 88 … … 105 102 switch ( strtolower($parents) ) { 106 103 case 'multiple': 107 if ($category-> category_parent)108 $thelist .= get_category_parents($category-> category_parent, TRUE);109 $thelist .= '<a href="' . get_category_link($category-> cat_ID) . '" title="' . sprintf(__("View all posts in %s"), $category->cat_name) . '" ' . $rel . '>' . $category->cat_name.'</a></li>';104 if ($category->parent) 105 $thelist .= get_category_parents($category->parent, TRUE); 106 $thelist .= '<a href="' . get_category_link($category->term_id) . '" title="' . sprintf(__("View all posts in %s"), $category->name) . '" ' . $rel . '>' . $category->name.'</a></li>'; 110 107 break; 111 108 case 'single': 112 $thelist .= '<a href="' . get_category_link($category-> cat_ID) . '" title="' . sprintf(__("View all posts in %s"), $category->cat_name) . '" ' . $rel . '>';113 if ($category-> category_parent)114 $thelist .= get_category_parents($category-> category_parent, FALSE);115 $thelist .= $category-> cat_name.'</a></li>';109 $thelist .= '<a href="' . get_category_link($category->term_id) . '" title="' . sprintf(__("View all posts in %s"), $category->name) . '" ' . $rel . '>'; 110 if ($category->parent) 111 $thelist .= get_category_parents($category->parent, FALSE); 112 $thelist .= $category->name.'</a></li>'; 116 113 break; 117 114 case '': 118 115 default: 119 $thelist .= '<a href="' . get_category_link($category-> cat_ID) . '" title="' . sprintf(__("View all posts in %s"), $category->cat_name) . '" ' . $rel . '>' . $category->cat_name.'</a></li>';116 $thelist .= '<a href="' . get_category_link($category->term_id) . '" title="' . sprintf(__("View all posts in %s"), $category->name) . '" ' . $rel . '>' . $category->cat_name.'</a></li>'; 120 117 } 121 118 } … … 128 125 switch ( strtolower($parents) ) { 129 126 case 'multiple': 130 if ( $category-> category_parent )131 $thelist .= get_category_parents($category-> category_parent, TRUE);132 $thelist .= '<a href="' . get_category_link($category-> cat_ID) . '" title="' . sprintf(__("View all posts in %s"), $category->cat_name) . '" ' . $rel . '>' . $category->cat_name.'</a>';127 if ( $category->parent ) 128 $thelist .= get_category_parents($category->parent, TRUE); 129 $thelist .= '<a href="' . get_category_link($category->term_id) . '" title="' . sprintf(__("View all posts in %s"), $category->name) . '" ' . $rel . '>' . $category->cat_name.'</a>'; 133 130 break; 134 131 case 'single': 135 $thelist .= '<a href="' . get_category_link($category-> cat_ID) . '" title="' . sprintf(__("View all posts in %s"), $category->cat_name) . '" ' . $rel . '>';136 if ( $category-> category_parent )137 $thelist .= get_category_parents($category-> category_parent, FALSE);132 $thelist .= '<a href="' . get_category_link($category->term_id) . '" title="' . sprintf(__("View all posts in %s"), $category->name) . '" ' . $rel . '>'; 133 if ( $category->parent ) 134 $thelist .= get_category_parents($category->parent, FALSE); 138 135 $thelist .= "$category->cat_name</a>"; 139 136 break; 140 137 case '': 141 138 default: 142 $thelist .= '<a href="' . get_category_link($category-> cat_ID) . '" title="' . sprintf(__("View all posts in %s"), $category->cat_name) . '" ' . $rel . '>' . $category->cat_name.'</a>';139 $thelist .= '<a href="' . get_category_link($category->term_id) . '" title="' . sprintf(__("View all posts in %s"), $category->name) . '" ' . $rel . '>' . $category->name.'</a>'; 143 140 } 144 141 ++$i; … … 166 163 $category = $cat; 167 164 $category = & get_category($category); 168 return apply_filters('category_description', $category-> category_description, $category->cat_ID);165 return apply_filters('category_description', $category->description, $category->term_id); 169 166 } 170 167 -
trunk/wp-includes/category.php
r5528 r5529 103 103 } 104 104 105 //106 // Private107 //108 109 function &_get_cat_children($category_id, $categories) {110 if ( empty($categories) )111 return array();112 113 $category_list = array();114 $has_children = _get_category_hierarchy();115 116 if ( ( 0 != $category_id ) && ! isset($has_children[$category_id]) )117 return array();118 119 foreach ( $categories as $category ) {120 if ( $category->cat_ID == $category_id )121 continue;122 123 if ( $category->category_parent == $category_id ) {124 $category_list[] = $category;125 126 if ( !isset($has_children[$category->cat_ID]) )127 continue;128 129 if ( $children = _get_cat_children($category->cat_ID, $categories) )130 $category_list = array_merge($category_list, $children);131 }132 }133 134 return $category_list;135 }136 137 // Recalculates link or post counts by including items from child categories138 // Assumes all relevant children are already in the $categories argument139 function _pad_category_counts($type, &$categories) {140 global $wpdb;141 142 // Set up some useful arrays143 foreach ( $categories as $key => $cat ) {144 $cats[$cat->cat_ID] = & $categories[$key];145 $cat_IDs[] = $cat->cat_ID;146 }147 148 // Get the relevant post2cat or link2cat records and stick them in a lookup table149 if ( $type == 'post' ) {150 $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'");151 foreach ( $results as $row )152 ++$cat_items[$row->category_id][$row->post_id];153 } else {154 $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'");155 foreach ( $results as $row )156 ++$cat_items[$row->category_id][$row->link_id];157 }158 159 // Touch every ancestor's lookup row for each post in each category160 foreach ( $cat_IDs as $cat_ID ) {161 $child = $cat_ID;162 while ( $parent = $cats[$child]->category_parent ) {163 if ( !empty($cat_items[$cat_ID]) )164 foreach ( $cat_items[$cat_ID] as $item_id => $touches )165 ++$cat_items[$parent][$item_id];166 $child = $parent;167 }168 }169 170 // Transfer the touched cells171 foreach ( (array) $cat_items as $id => $items )172 if ( isset($cats[$id]) )173 $cats[$id]->{'link' == $type ? 'link_count' : 'category_count'} = count($items);174 }175 176 function _get_category_hierarchy() {177 return _get_term_hierarchy('category');178 }179 180 105 // Tags 181 106 -
trunk/wp-includes/post.php
r5515 r5529 448 448 $post_id = (int) $post_id; 449 449 450 $cats = &get_the_category($post_id); 451 $cat_ids = array(); 452 foreach ( $cats as $cat ) 453 $cat_ids[] = (int) $cat->cat_ID; 454 return array_unique($cat_ids); 450 $cats = get_object_terms($post_id, 'category', 'get=ids'); 451 return $cats; 455 452 } 456 453 … … 806 803 $post_categories = array(get_option('default_category')); 807 804 805 $post_categories = array_map('intval', $post_categories); 808 806 $post_categories = array_unique($post_categories); 809 807 810 // First the old categories 811 $old_categories = $wpdb->get_col(" 812 SELECT category_id 813 FROM $wpdb->post2cat 814 WHERE post_id = '$post_ID' AND rel_type = 'category'"); 815 816 if (!$old_categories) { 817 $old_categories = array(); 818 } else { 819 $old_categories = array_unique($old_categories); 820 } 821 822 // Delete any? 823 $delete_cats = array_diff($old_categories,$post_categories); 824 825 if ($delete_cats) { 826 foreach ($delete_cats as $del) { 827 $wpdb->query(" 828 DELETE FROM $wpdb->post2cat 829 WHERE category_id = '$del' 830 AND post_id = '$post_ID' AND rel_type = 'category' 831 "); 832 } 833 } 834 835 // Add any? 836 $add_cats = array_diff($post_categories, $old_categories); 837 838 if ($add_cats) { 839 foreach ($add_cats as $new_cat) { 840 $new_cat = (int) $new_cat; 841 if ( !empty($new_cat) ) 842 $wpdb->query(" 843 INSERT INTO $wpdb->post2cat (post_id, category_id) 844 VALUES ('$post_ID', '$new_cat')"); 845 } 846 } 847 848 // Update category counts. 849 $all_affected_cats = array_unique(array_merge($post_categories, $old_categories)); 850 foreach ( $all_affected_cats as $cat_id ) { 851 $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'"); 852 $wpdb->query("UPDATE $wpdb->categories SET category_count = '$count', type = type | " . TAXONOMY_CATEGORY . " WHERE cat_ID = '$cat_id'"); 853 clean_category_cache($cat_id); 854 do_action('edit_category', $cat_id); 855 } 808 return wp_set_object_terms($post_ID, $post_categories, 'category'); 856 809 } // wp_set_post_categories() 857 810 -
trunk/wp-includes/taxonomy.php
r5528 r5529 225 225 $in_taxonomies = "'" . implode("', '", $taxonomies) . "'"; 226 226 $old_terms = $wpdb->get_col("SELECT tr.term_taxonomy_id FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ($in_taxonomies) AND tr.object_id = '$object_id'"); 227 if ( empty($old_terms) ) 228 $old_terms = array(); 227 229 } 228 230 … … 263 265 global $wpdb; 264 266 $taxonomies = ($single_taxonomy = !is_array($taxonomy)) ? array($taxonomy) : $taxonomy; 267 // TODO cast to int 265 268 $object_ids = ($single_object = !is_array($object_id)) ? array($object_id) : $object_id; 266 269
Note: See TracChangeset
for help on using the changeset viewer.