]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/category-template.php
Wordpress 2.5.1
[autoinstalls/wordpress.git] / wp-includes / category-template.php
index cd8dbcb17ef8eef4b5893129fe297f4d939611dd..ba24302074acab8eedaa9e6523249839af177c5f 100644 (file)
@@ -66,7 +66,7 @@ function get_category_parents($id, $link = FALSE, $separator = '/', $nicename =
 }
 
 function get_the_category($id = false) {
-       global $post, $term_cache, $blog_id;
+       global $post;
 
        $id = (int) $id;
        if ( !$id )
@@ -109,9 +109,9 @@ function get_the_category_by_ID($cat_ID) {
        return $category->name;
 }
 
-function get_the_category_list($separator = '', $parents='') {
+function get_the_category_list($separator = '', $parents='', $post_id = false) {
        global $wp_rewrite;
-       $categories = get_the_category();
+       $categories = get_the_category($post_id);
        if (empty($categories))
                return apply_filters('the_category', __('Uncategorized'), $separator, $parents);
 
@@ -167,20 +167,39 @@ function get_the_category_list($separator = '', $parents='') {
        return apply_filters('the_category', $thelist, $separator, $parents);
 }
 
+/*
+ * in_category() - Checks whether the current post is within a particular category
+ *
+ * This function checks to see if the post is within the supplied category.  The categoy
+ * can be specified by number or name and will be checked as a name first to allow for categories with numeric names.
+ * Note: Prior to v2.5 of WordPress category names where not supported.
+ *
+ * @since 1.2.0
+ *
+ * @param int|string $category
+ * @return bool true if the post is in the supplied category
+*/
 function in_category( $category ) { // Check if the current post is in the given category
-       global $post, $blog_id;
+       global $post;
+
+       if ( empty($category) )
+               return false;
+
+       $cat_ID = get_cat_ID($category);
+       if ( $cat_ID )
+               $category = $cat_ID;
 
        $categories = get_object_term_cache($post->ID, 'category');
        if ( false === $categories )
                $categories = wp_get_object_terms($post->ID, 'category');
-       if(array_key_exists($category, $categories))
+       if ( array_key_exists($category, $categories) )
                return true;
        else
                return false;
 }
 
-function the_category($separator = '', $parents='') {
-       echo get_the_category_list($separator, $parents);
+function the_category($separator = '', $parents='', $post_id = false) {
+       echo get_the_category_list($separator, $parents, $post_id);
 }
 
 function category_description($category = 0) {
@@ -199,7 +218,8 @@ function wp_dropdown_categories($args = '') {
                'hide_empty' => 1, 'child_of' => 0,
                'exclude' => '', 'echo' => 1,
                'selected' => 0, 'hierarchical' => 0,
-               'name' => 'cat', 'class' => 'postform'
+               'name' => 'cat', 'class' => 'postform',
+               'depth' => 0, 'tab_index' => 0
        );
 
        $defaults['selected'] = ( is_category() ) ? get_query_var('cat') : 0;
@@ -208,11 +228,15 @@ function wp_dropdown_categories($args = '') {
        $r['include_last_update_time'] = $r['show_last_update'];
        extract( $r );
 
+       $tab_index_attribute = '';
+       if ( (int) $tab_index > 0 )
+               $tab_index_attribute = " tabindex=\"$tab_index\"";
+
        $categories = get_categories($r);
 
        $output = '';
        if ( ! empty($categories) ) {
-               $output = "<select name='$name' id='$name' class='$class'>\n";
+               $output = "<select name='$name' id='$name' class='$class' $tab_index_attribute>\n";
 
                if ( $show_option_all ) {
                        $show_option_all = apply_filters('list_cats', $show_option_all);
@@ -225,7 +249,7 @@ function wp_dropdown_categories($args = '') {
                }
 
                if ( $hierarchical )
-                       $depth = 0;  // Walk the full depth.
+                       $depth = $r['depth'];  // Walk the full depth.
                else
                        $depth = -1; // Flat.
 
@@ -247,10 +271,10 @@ function wp_list_categories($args = '') {
                'order' => 'ASC', 'show_last_update' => 0,
                'style' => 'list', 'show_count' => 0,
                'hide_empty' => 1, 'use_desc_for_title' => 1,
-               'child_of' => 0, 'feed' => '',
+               'child_of' => 0, 'feed' => '', 'feed_type' => '',
                'feed_image' => '', 'exclude' => '',
                'hierarchical' => true, 'title_li' => __('Categories'),
-               'echo' => 1
+               'echo' => 1, 'depth' => 0
        );
 
        $r = wp_parse_args( $args, $defaults );
@@ -289,7 +313,7 @@ function wp_list_categories($args = '') {
                        $r['current_category'] = $wp_query->get_queried_object_id();
 
                if ( $hierarchical )
-                       $depth = 0;  // Walk the full depth.
+                       $depth = $r['depth'];
                else
                        $depth = -1; // Flat.
 
@@ -321,10 +345,16 @@ function wp_tag_cloud( $args = '' ) {
                return;
 
        $return = wp_generate_tag_cloud( $tags, $args ); // Here's where those top tags get sorted according to $args
+
        if ( is_wp_error( $return ) )
                return false;
-       else 
-               echo apply_filters( 'wp_tag_cloud', $return, $args );
+
+       $return = apply_filters( 'wp_tag_cloud', $return, $args );
+
+       if ( 'array' == $args['format'] )
+               return $return;
+
+       echo $return;
 }
 
 // $tags = prefetched tag array ( get_tags() )
@@ -367,6 +397,13 @@ function wp_generate_tag_cloud( $tags, $args = '' ) {
 
        if ( 'DESC' == $order )
                $counts = array_reverse( $counts, true );
+       elseif ( 'RAND' == $order ) {
+               $keys = array_rand( $counts, count($counts) );
+               foreach ( $keys as $key )
+                       $temp[$key] = $counts[$key];
+               $counts = $temp;
+               unset($temp);
+       }
 
        $a = array();
 
@@ -376,7 +413,7 @@ function wp_generate_tag_cloud( $tags, $args = '' ) {
                $tag_id = $tag_ids[$tag];
                $tag_link = clean_url($tag_links[$tag]);
                $tag = str_replace(' ', '&nbsp;', wp_specialchars( $tag ));
-               $a[] = "<a href='$tag_link' class='tag-link-$tag_id' title='" . attribute_escape( sprintf( __('%d topics'), $count ) ) . "'$rel style='font-size: " .
+               $a[] = "<a href='$tag_link' class='tag-link-$tag_id' title='" . attribute_escape( sprintf( __ngettext('%d topic','%d topics',$count), $count ) ) . "'$rel style='font-size: " .
                        ( $smallest + ( ( $count - $min_count ) * $font_step ) )
                        . "$unit;'>$tag</a>";
        }
@@ -438,6 +475,18 @@ function get_tag_link( $tag_id ) {
 }
 
 function get_the_tags( $id = 0 ) {
+       return apply_filters( 'get_the_tags', get_the_terms($id, 'post_tag') );
+}
+
+function get_the_tag_list( $before = '', $sep = '', $after = '' ) {
+       return apply_filters( 'the_tags', get_the_term_list(0, 'post_tag', $before, $sep, $after) );
+}
+
+function the_tags( $before = 'Tags: ', $sep = ', ', $after = '' ) {
+       return the_terms( 0, 'post_tag', $before, $sep, $after );
+}
+
+function get_the_terms( $id = 0, $taxonomy ) {
        global $post;
 
        $id = (int) $id;
@@ -448,41 +497,39 @@ function get_the_tags( $id = 0 ) {
        if ( !$id )
                $id = (int) $post->ID;
 
-       $tags = get_object_term_cache($id, 'post_tag');
-       if ( false === $tags )
-               $tags = wp_get_object_terms($id, 'post_tag');
+       $terms = get_object_term_cache($id, $taxonomy);
+       if ( false === $terms )
+               $terms = wp_get_object_terms($id, $taxonomy);
 
-       $tags = apply_filters( 'get_the_tags', $tags );
-       if ( empty( $tags ) )
+       if ( empty( $terms ) )
                return false;
-       return $tags;
+
+       return $terms;
 }
 
-function get_the_tag_list( $before = '', $sep = '', $after = '' ) {
-       $tags = get_the_tags();
+function get_the_term_list( $id = 0, $taxonomy, $before = '', $sep = '', $after = '' ) {
+       $terms = get_the_terms($id, $taxonomy);
 
-       if ( empty( $tags ) )
+       if ( is_wp_error($terms) )
+               return $terms;
+
+       if ( empty( $terms ) )
                return false;
 
-       $tag_list = $before;
-       foreach ( $tags as $tag ) {
-               $link = get_tag_link($tag->term_id);
+       foreach ( $terms as $term ) {
+               $link = get_term_link($term, $taxonomy);
                if ( is_wp_error( $link ) )
                        return $link;
-               $tag_links[] = '<a href="' . $link . '" rel="tag">' . $tag->name . '</a>';
+               $term_links[] = '<a href="' . $link . '" rel="tag">' . $term->name . '</a>';
        }
 
-       $tag_links = join( $sep, $tag_links );
-       $tag_links = apply_filters( 'the_tags', $tag_links );
-       $tag_list .= $tag_links;
-
-       $tag_list .= $after;
+       $term_links = apply_filters( "term_links-$taxonomy", $term_links );
 
-       return $tag_list;
+       return $before . join($sep, $term_links) . $after;
 }
 
-function the_tags( $before = 'Tags: ', $sep = ', ', $after = '' ) {
-       $return = get_the_tag_list($before, $sep, $after);
+function the_terms( $id, $taxonomy, $before = '', $sep = '', $after = '' ) {
+       $return = get_the_term_list($id, $taxonomy, $before, $sep, $after);
        if ( is_wp_error( $return ) )
                return false;
        else