From cf9f85dc8121a359d550ffa3b735fb48859eee88 Mon Sep 17 00:00:00 2001 From: donncha Date: Thu, 24 Apr 2008 11:45:39 +0000 Subject: Merged with WP 2.5, revision 7806 git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@1260 7be80a69-a1ef-0310-a953-fb0f7c49ff36 --- wp-admin/includes/template.php | 147 +++++++++++++++++++++-------------------- 1 file changed, 75 insertions(+), 72 deletions(-) (limited to 'wp-admin/includes/template.php') diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php index 3e67338..db80bf8 100644 --- a/wp-admin/includes/template.php +++ b/wp-admin/includes/template.php @@ -55,11 +55,12 @@ function _cat_row( $category, $level, $name_override = false ) { $output = " "; if ( absint(get_option( 'default_category' ) ) != $category->term_id ) { - $output .= ""; + $output .= ""; } else { $output .= " "; } - $output .= "$edit + $output .= " + $edit $category->description $posts_count\n\t\n"; @@ -86,11 +87,17 @@ function link_cat_row( $category ) { $category->count = number_format_i18n( $category->count ); $count = ( $category->count > 0 ) ? "$category->count" : $category->count; - $output = "" . - ' ' . - "$edit - $category->description - $count"; + $output = " + "; + if ( absint( get_option( 'default_link_category' ) ) != $category->term_id ) { + $output .= ""; + } else { + $output .= " "; + } + $output .= " + $edit + $category->description + $count"; return apply_filters( 'link_cat_row', $output ); } @@ -106,93 +113,83 @@ function selected( $selected, $current) { } // -// Nasty Category Stuff +// Category Checklists // -function sort_cats( $cat1, $cat2 ) { - if ( $cat1['checked'] || $cat2['checked'] ) - return ( $cat1['checked'] && !$cat2['checked'] ) ? -1 : 1; - else - return strcasecmp( $cat1['cat_name'], $cat2['cat_name'] ); +// Deprecated. Use wp_link_category_checklist +function dropdown_categories( $default = 0, $parent = 0, $popular_ids = array() ) { + global $post_ID; + wp_category_checklist($post_ID); } -function wp_set_checked_post_categories( $default = 0 ) { - global $post_ID, $checked_categories; +class Walker_Category_Checklist extends Walker { + var $tree_type = 'category'; + var $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); //TODO: decouple this - if ( empty($checked_categories) ) { - if ( $post_ID ) { - $checked_categories = wp_get_post_categories($post_ID); - - if ( count( $checked_categories ) == 0 ) { - // No selected categories, strange - $checked_categories[] = $default; - } - } else { - $checked_categories[] = $default; - } + function start_lvl(&$output, $depth, $args) { + $indent = str_repeat("\t", $depth); + $output .= "$indent\n"; + } - $cats = get_categories("parent=$parent&hide_empty=0&fields=ids"); + function start_el(&$output, $category, $depth, $args) { + extract($args); - $result = array(); - if ( is_array( $cats ) ) { - foreach ( $cats as $cat ) { - $result[$cat]['children'] = get_nested_categories( $default, $cat ); - $result[$cat]['cat_ID'] = $cat; - $result[$cat]['checked'] = in_array( $cat, $checked_categories ); - $result[$cat]['cat_name'] = get_the_category_by_ID( $cat ); - } - } + $class = in_array( $category->term_id, $popular_cats ) ? ' class="popular-category"' : ''; + $output .= "\n
  • " . ''; } - $result = apply_filters('get_nested_categories', $result); - usort( $result, 'sort_cats' ); - - return $result; + function end_el(&$output, $category, $depth, $args) { + $output .= "
  • \n"; + } } -function write_nested_categories( $categories ) { - foreach ( $categories as $category ) { - echo "\n", '
  • '; +function wp_category_checklist( $post_id = 0, $descendants_and_self = 0, $selected_cats = false ) { + $walker = new Walker_Category_Checklist; + $descendants_and_self = (int) $descendants_and_self; - if ( $category['children'] ) { - echo "\n"; - } - echo '
  • '; + $args = array(); + + if ( $post_id ) + $args['selected_cats'] = wp_get_post_categories($post_id); + else + $args['selected_cats'] = array(); + if ( is_array( $selected_cats ) ) + $args['selected_cats'] = $selected_cats; + $args['popular_cats'] = get_terms( 'category', array( 'fields' => 'ids', 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) ); + if ( $descendants_and_self ) { + $categories = get_categories( "child_of=$descendants_and_self&hierarchical=0&hide_empty=0" ); + $self = get_category( $descendants_and_self ); + array_unshift( $categories, $self ); + } else { + $categories = get_categories('get=all'); } -} -function dropdown_categories( $default = 0, $parent = 0 ) { - write_nested_categories( get_nested_categories( $default, $parent ) ); + $args = array($categories, 0, $args); + $output = call_user_func_array(array(&$walker, 'walk'), $args); + + echo $output; } function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10 ) { - $categories = get_terms( $taxonomy, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => $number ) ); + global $post_ID; + if ( $post_ID ) + $checked_categories = wp_get_post_categories($post_ID); + else + $checked_categories = array(); + $categories = get_terms( $taxonomy, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => $number, 'hierarchical' => false ) ); + $popular_ids = array(); foreach ( (array) $categories as $category ) { + $popular_ids[] = $category->term_id; $id = "popular-category-$category->term_id"; ?> -
  • +