Changeset 8620 for branches/crazyhorse/wp-includes/category.php
- Timestamp:
- 08/11/2008 10:52:43 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/crazyhorse/wp-includes/category.php
r8103 r8620 15 15 */ 16 16 function get_all_category_ids() { 17 if ( ! $cat_ids = wp_cache_get( 'all_category_ids', 'category') ) {18 $cat_ids = get_terms( 'category', 'fields=ids&get=all');19 wp_cache_add( 'all_category_ids', $cat_ids, 'category');17 if ( ! $cat_ids = wp_cache_get( 'all_category_ids', 'category' ) ) { 18 $cat_ids = get_terms( 'category', 'fields=ids&get=all' ); 19 wp_cache_add( 'all_category_ids', $cat_ids, 'category' ); 20 20 } 21 21 … … 37 37 * @return array List of categories. 38 38 */ 39 function &get_categories( $args = '') {40 $defaults = array( 'type' => 'category');41 $args = wp_parse_args( $args, $defaults);39 function &get_categories( $args = '' ) { 40 $defaults = array( 'type' => 'category' ); 41 $args = wp_parse_args( $args, $defaults ); 42 42 43 43 $taxonomy = 'category'; 44 44 if ( 'link' == $args['type'] ) 45 45 $taxonomy = 'link_category'; 46 $categories = get_terms($taxonomy, $args);47 48 foreach ( array_keys( $categories) as $k )49 _make_cat_compat( $categories[$k]);46 $categories = (array) get_terms( $taxonomy, $args ); 47 48 foreach ( array_keys( $categories ) as $k ) 49 _make_cat_compat( $categories[$k] ); 50 50 51 51 return $categories; … … 74 74 * @return mixed Category data in type defined by $output parameter. 75 75 */ 76 function &get_category( $category, $output = OBJECT, $filter = 'raw') {77 $category = get_term( $category, 'category', $output, $filter);76 function &get_category( $category, $output = OBJECT, $filter = 'raw' ) { 77 $category = get_term( $category, 'category', $output, $filter ); 78 78 if ( is_wp_error( $category ) ) 79 79 return $category; 80 80 81 _make_cat_compat( $category);81 _make_cat_compat( $category ); 82 82 83 83 return $category; … … 103 103 * @return null|object|array Null on failure. Type is based on $output value. 104 104 */ 105 function get_category_by_path( $category_path, $full_match = true, $output = OBJECT) {106 $category_path = rawurlencode( urldecode($category_path));107 $category_path = str_replace( '%2F', '/', $category_path);108 $category_path = str_replace( '%20', ' ', $category_path);109 $category_paths = '/' . trim( $category_path, '/');110 $leaf_path = sanitize_title( basename($category_paths));111 $category_paths = explode( '/', $category_paths);105 function get_category_by_path( $category_path, $full_match = true, $output = OBJECT ) { 106 $category_path = rawurlencode( urldecode( $category_path ) ); 107 $category_path = str_replace( '%2F', '/', $category_path ); 108 $category_path = str_replace( '%20', ' ', $category_path ); 109 $category_paths = '/' . trim( $category_path, '/' ); 110 $leaf_path = sanitize_title( basename( $category_paths ) ); 111 $category_paths = explode( '/', $category_paths ); 112 112 $full_path = ''; 113 113 foreach ( (array) $category_paths as $pathdir ) 114 $full_path .= ( $pathdir != '' ? '/' : '' ) . sanitize_title( $pathdir);115 116 $categories = get_terms( 'category', "get=all&slug=$leaf_path");117 118 if ( empty( $categories) )114 $full_path .= ( $pathdir != '' ? '/' : '' ) . sanitize_title( $pathdir ); 115 116 $categories = get_terms( 'category', "get=all&slug=$leaf_path" ); 117 118 if ( empty( $categories ) ) 119 119 return null; 120 120 121 foreach ( $categories as $category) {121 foreach ( $categories as $category ) { 122 122 $path = '/' . $leaf_path; 123 123 $curcategory = $category; 124 while ( ( $curcategory->parent != 0) && ($curcategory->parent != $curcategory->term_id) ) {125 $curcategory = get_term( $curcategory->parent, 'category');124 while ( ( $curcategory->parent != 0 ) && ( $curcategory->parent != $curcategory->term_id ) ) { 125 $curcategory = get_term( $curcategory->parent, 'category' ); 126 126 if ( is_wp_error( $curcategory ) ) 127 127 return $curcategory; … … 130 130 131 131 if ( $path == $full_path ) 132 return get_category( $category->term_id, $output);132 return get_category( $category->term_id, $output ); 133 133 } 134 134 135 135 // If full matching is not required, return the first cat that matches the leaf. 136 136 if ( ! $full_match ) 137 return get_category( $categories[0]->term_id, $output);137 return get_category( $categories[0]->term_id, $output ); 138 138 139 139 return null; … … 149 149 */ 150 150 function get_category_by_slug( $slug ) { 151 $category = get_term_by( 'slug', $slug, 'category');151 $category = get_term_by( 'slug', $slug, 'category' ); 152 152 if ( $category ) 153 _make_cat_compat( $category);153 _make_cat_compat( $category ); 154 154 155 155 return $category; … … 165 165 * @return int 0, if failure and ID of category on success. 166 166 */ 167 function get_cat_ID( $cat_name='General') {168 $cat = get_term_by( 'name', $cat_name, 'category');169 if ( $cat)167 function get_cat_ID( $cat_name='General' ) { 168 $cat = get_term_by( 'name', $cat_name, 'category' ); 169 if ( $cat ) 170 170 return $cat->term_id; 171 171 return 0; … … 183 183 * @return string category name 184 184 */ 185 function get_catname( $cat_ID) {186 return get_cat_name( $cat_ID);185 function get_catname( $cat_ID ) { 186 return get_cat_name( $cat_ID ); 187 187 } 188 188 … … 196 196 * @return string Category name 197 197 */ 198 function get_cat_name( $cat_id) {198 function get_cat_name( $cat_id ) { 199 199 $cat_id = (int) $cat_id; 200 $category = &get_category( $cat_id);200 $category = &get_category( $cat_id ); 201 201 return $category->name; 202 202 } … … 215 215 * @return bool Whether $cat2 is child of $cat1 216 216 */ 217 function cat_is_ancestor_of( $cat1, $cat2) {218 if ( is_int( $cat1) )219 $cat1 = & get_category($cat1);220 if ( is_int( $cat2) )221 $cat2 = & get_category($cat2);217 function cat_is_ancestor_of( $cat1, $cat2 ) { 218 if ( is_int( $cat1 ) ) 219 $cat1 = &get_category( $cat1 ); 220 if ( is_int( $cat2 ) ) 221 $cat2 = &get_category( $cat2 ); 222 222 223 223 if ( !$cat1->term_id || !$cat2->parent ) … … 227 227 return true; 228 228 229 return cat_is_ancestor_of( $cat1, get_category($cat2->parent));229 return cat_is_ancestor_of( $cat1, get_category( $cat2->parent ) ); 230 230 } 231 231 … … 241 241 * @return object|array Same type as $category with sanitized data for safe use. 242 242 */ 243 function sanitize_category( $category, $context = 'display') {244 return sanitize_term( $category, 'category', $context);243 function sanitize_category( $category, $context = 'display' ) { 244 return sanitize_term( $category, 'category', $context ); 245 245 } 246 246 … … 258 258 * @return mixed Same type as $value after $value has been sanitized. 259 259 */ 260 function sanitize_category_field( $field, $value, $cat_id, $context) {261 return sanitize_term_field( $field, $value, $cat_id, 'category', $context);260 function sanitize_category_field( $field, $value, $cat_id, $context ) { 261 return sanitize_term_field( $field, $value, $cat_id, 'category', $context ); 262 262 } 263 263 … … 275 275 * @return array List of tags. 276 276 */ 277 function &get_tags( $args = '') {278 $tags = get_terms( 'post_tag', $args);279 280 if ( empty( $tags) )277 function &get_tags( $args = '' ) { 278 $tags = get_terms( 'post_tag', $args ); 279 280 if ( empty( $tags ) ) 281 281 return array(); 282 282 283 $tags = apply_filters( 'get_tags', $tags, $args);283 $tags = apply_filters( 'get_tags', $tags, $args ); 284 284 return $tags; 285 285 } … … 305 305 * @return object|array Return type based on $output value. 306 306 */ 307 function &get_tag( $tag, $output = OBJECT, $filter = 'raw') {308 return get_term( $tag, 'post_tag', $output, $filter);307 function &get_tag( $tag, $output = OBJECT, $filter = 'raw' ) { 308 return get_term( $tag, 'post_tag', $output, $filter ); 309 309 } 310 310 … … 337 337 * @param int $id Category ID 338 338 */ 339 function clean_category_cache( $id) {340 clean_term_cache( $id, 'category');339 function clean_category_cache( $id ) { 340 clean_term_cache( $id, 'category' ); 341 341 } 342 342 … … 361 361 * @param array|object $category Category Row object or array 362 362 */ 363 function _make_cat_compat( &$category ) {364 if ( is_object( $category) ) {363 function _make_cat_compat( &$category ) { 364 if ( is_object( $category ) ) { 365 365 $category->cat_ID = &$category->term_id; 366 366 $category->category_count = &$category->count; … … 369 369 $category->category_nicename = &$category->slug; 370 370 $category->category_parent = &$category->parent; 371 } else if ( is_array($category) && isset($category['term_id']) ) {371 } elseif ( is_array( $category ) && isset( $category['term_id'] ) ) { 372 372 $category['cat_ID'] = &$category['term_id']; 373 373 $category['category_count'] = &$category['count'];
Note: See TracChangeset
for help on using the changeset viewer.