WordPress.org

Make WordPress Core

Changeset 8575


Ignore:
Timestamp:
08/06/2008 09:06:14 PM (10 years ago)
Author:
markjaquith
Message:

Whitespacing/coding standards cleanup for category.php

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/category.php

    r8572 r8575  
    1515 */
    1616function 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' );
    2020    }
    2121
     
    3737 * @return array List of categories.
    3838 */
    39 function &get_categories($args = '') {
    40     $defaults = array('type' => 'category');
    41     $args = wp_parse_args($args, $defaults);
     39function &get_categories( $args = '' ) {
     40    $defaults = array( 'type' => 'category' );
     41    $args = wp_parse_args( $args, $defaults );
    4242
    4343    $taxonomy = 'category';
    4444    if ( 'link' == $args['type'] )
    4545        $taxonomy = 'link_category';
    46     $categories = (array) 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] );
    5050
    5151    return $categories;
     
    7474 * @return mixed Category data in type defined by $output parameter.
    7575 */
    76 function &get_category($category, $output = OBJECT, $filter = 'raw') {
    77     $category = get_term($category, 'category', $output, $filter);
     76function &get_category( $category, $output = OBJECT, $filter = 'raw' ) {
     77    $category = get_term( $category, 'category', $output, $filter );
    7878    if ( is_wp_error( $category ) )
    7979        return $category;
    8080
    81     _make_cat_compat($category);
     81    _make_cat_compat( $category );
    8282
    8383    return $category;
     
    103103 * @return null|object|array Null on failure. Type is based on $output value.
    104104 */
    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);
     105function 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 );
    112112    $full_path = '';
    113113    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 ) )
    119119        return null;
    120120
    121     foreach ($categories as $category) {
     121    foreach ( $categories as $category ) {
    122122        $path = '/' . $leaf_path;
    123123        $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' );
    126126            if ( is_wp_error( $curcategory ) )
    127127                return $curcategory;
     
    130130
    131131        if ( $path == $full_path )
    132             return get_category($category->term_id, $output);
     132            return get_category( $category->term_id, $output );
    133133    }
    134134
    135135    // If full matching is not required, return the first cat that matches the leaf.
    136136    if ( ! $full_match )
    137         return get_category($categories[0]->term_id, $output);
     137        return get_category( $categories[0]->term_id, $output );
    138138
    139139    return null;
     
    149149 */
    150150function get_category_by_slug( $slug  ) {
    151     $category = get_term_by('slug', $slug, 'category');
     151    $category = get_term_by( 'slug', $slug, 'category' );
    152152    if ( $category )
    153         _make_cat_compat($category);
     153        _make_cat_compat( $category );
    154154
    155155    return $category;
     
    165165 * @return int 0, if failure and ID of category on success.
    166166 */
    167 function get_cat_ID($cat_name='General') {
    168     $cat = get_term_by('name', $cat_name, 'category');
    169     if ($cat)
     167function get_cat_ID( $cat_name='General' ) {
     168    $cat = get_term_by( 'name', $cat_name, 'category' );
     169    if ( $cat )
    170170        return $cat->term_id;
    171171    return 0;
     
    183183 * @return string category name
    184184 */
    185 function get_catname($cat_ID) {
    186     return get_cat_name($cat_ID);
     185function get_catname( $cat_ID ) {
     186    return get_cat_name( $cat_ID );
    187187}
    188188
     
    196196 * @return string Category name
    197197 */
    198 function get_cat_name($cat_id) {
     198function get_cat_name( $cat_id ) {
    199199    $cat_id = (int) $cat_id;
    200     $category = &get_category($cat_id);
     200    $category = &get_category( $cat_id );
    201201    return $category->name;
    202202}
     
    215215 * @return bool Whether $cat2 is child of $cat1
    216216 */
    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);
     217function 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 );
    222222
    223223    if ( !$cat1->term_id || !$cat2->parent )
     
    227227        return true;
    228228
    229     return cat_is_ancestor_of($cat1, get_category($cat2->parent));
     229    return cat_is_ancestor_of( $cat1, get_category( $cat2->parent ) );
    230230}
    231231
     
    241241 * @return object|array Same type as $category with sanitized data for safe use.
    242242 */
    243 function sanitize_category($category, $context = 'display') {
    244     return sanitize_term($category, 'category', $context);
     243function sanitize_category( $category, $context = 'display' ) {
     244    return sanitize_term( $category, 'category', $context );
    245245}
    246246
     
    258258 * @return mixed Same type as $value after $value has been sanitized.
    259259 */
    260 function sanitize_category_field($field, $value, $cat_id, $context) {
    261     return sanitize_term_field($field, $value, $cat_id, 'category', $context);
     260function sanitize_category_field( $field, $value, $cat_id, $context ) {
     261    return sanitize_term_field( $field, $value, $cat_id, 'category', $context );
    262262}
    263263
     
    275275 * @return array List of tags.
    276276 */
    277 function &get_tags($args = '') {
    278     $tags = get_terms('post_tag', $args);
    279 
    280     if ( empty($tags) )
     277function &get_tags( $args = '' ) {
     278    $tags = get_terms( 'post_tag', $args );
     279
     280    if ( empty( $tags ) )
    281281        return array();
    282282
    283     $tags = apply_filters('get_tags', $tags, $args);
     283    $tags = apply_filters( 'get_tags', $tags, $args );
    284284    return $tags;
    285285}
     
    305305 * @return object|array Return type based on $output value.
    306306 */
    307 function &get_tag($tag, $output = OBJECT, $filter = 'raw') {
    308     return get_term($tag, 'post_tag', $output, $filter);
     307function &get_tag( $tag, $output = OBJECT, $filter = 'raw' ) {
     308    return get_term( $tag, 'post_tag', $output, $filter );
    309309}
    310310
     
    337337 * @param int $id Category ID
    338338 */
    339 function clean_category_cache($id) {
    340     clean_term_cache($id, 'category');
     339function clean_category_cache( $id ) {
     340    clean_term_cache( $id, 'category' );
    341341}
    342342
     
    361361 * @param array|object $category Category Row object or array
    362362 */
    363 function _make_cat_compat( &$category) {
    364     if ( is_object($category) ) {
     363function _make_cat_compat( &$category ) {
     364    if ( is_object( $category ) ) {
    365365        $category->cat_ID = &$category->term_id;
    366366        $category->category_count = &$category->count;
     
    369369        $category->category_nicename = &$category->slug;
    370370        $category->category_parent = &$category->parent;
    371     } else if ( is_array($category) && isset($category['term_id']) ) {
     371    } elseif ( is_array( $category ) && isset( $category['term_id'] ) ) {
    372372        $category['cat_ID'] = &$category['term_id'];
    373373        $category['category_count'] = &$category['count'];
Note: See TracChangeset for help on using the changeset viewer.