Make WordPress Core

Changeset 28403


Ignore:
Timestamp:
05/15/2014 01:57:24 AM (12 years ago)
Author:
wonderboymusic
Message:

Eliminate use of extract() in get_bookmarks().

See #22400.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/bookmark.php

    r28316 r28403  
    119119 * @return array List of bookmark row objects
    120120 */
    121 function get_bookmarks($args = '') {
     121function get_bookmarks( $args = '' ) {
    122122        global $wpdb;
    123123
     
    131131
    132132        $r = wp_parse_args( $args, $defaults );
    133         extract( $r, EXTR_SKIP );
    134133
    135134        $key = md5( serialize( $r ) );
    136135        if ( $cache = wp_cache_get( 'get_bookmarks', 'bookmark' ) ) {
    137                 if ( is_array($cache) && isset( $cache[ $key ] ) ) {
     136                if ( is_array( $cache ) && isset( $cache[ $key ] ) ) {
    138137                        $bookmarks = $cache[ $key ];
    139138                        /**
     
    156155        }
    157156
    158         if ( !is_array($cache) )
     157        if ( ! is_array( $cache ) ) {
    159158                $cache = array();
     159        }
    160160
    161161        $inclusions = '';
    162         if ( !empty($include) ) {
    163                 $exclude = '';  //ignore exclude, category, and category_name params if using include
    164                 $category = '';
    165                 $category_name = '';
    166                 $inclinks = preg_split('/[\s,]+/',$include);
    167                 if ( count($inclinks) ) {
     162        if ( ! empty( $r['include'] ) ) {
     163                $r['exclude'] = '';  //ignore exclude, category, and category_name params if using include
     164                $r['category'] = '';
     165                $r['category_name'] = '';
     166                $inclinks = preg_split( '/[\s,]+/', $r['include'] );
     167                if ( count( $inclinks ) ) {
    168168                        foreach ( $inclinks as $inclink ) {
    169                                 if (empty($inclusions))
    170                                         $inclusions = ' AND ( link_id = ' . intval($inclink) . ' ';
    171                                 else
    172                                         $inclusions .= ' OR link_id = ' . intval($inclink) . ' ';
     169                                if ( empty( $inclusions ) ) {
     170                                        $inclusions = ' AND ( link_id = ' . intval( $inclink ) . ' ';
     171                                } else {
     172                                        $inclusions .= ' OR link_id = ' . intval( $inclink ) . ' ';
     173                                }
    173174                        }
    174175                }
    175176        }
    176         if (!empty($inclusions))
     177        if (! empty( $inclusions ) ) {
    177178                $inclusions .= ')';
     179        }
    178180
    179181        $exclusions = '';
    180         if ( !empty($exclude) ) {
    181                 $exlinks = preg_split('/[\s,]+/',$exclude);
    182                 if ( count($exlinks) ) {
     182        if ( ! empty( $r['exclude'] ) ) {
     183                $exlinks = preg_split( '/[\s,]+/', $r['exclude'] );
     184                if ( count( $exlinks ) ) {
    183185                        foreach ( $exlinks as $exlink ) {
    184                                 if (empty($exclusions))
    185                                         $exclusions = ' AND ( link_id <> ' . intval($exlink) . ' ';
    186                                 else
    187                                         $exclusions .= ' AND link_id <> ' . intval($exlink) . ' ';
     186                                if ( empty( $exclusions ) ) {
     187                                        $exclusions = ' AND ( link_id <> ' . intval( $exlink ) . ' ';
     188                                } else {
     189                                        $exclusions .= ' AND link_id <> ' . intval( $exlink ) . ' ';
     190                                }
    188191                        }
    189192                }
    190193        }
    191         if (!empty($exclusions))
     194        if ( ! empty( $exclusions ) ) {
    192195                $exclusions .= ')';
    193 
    194         if ( !empty($category_name) ) {
    195                 if ( $category = get_term_by('name', $category_name, 'link_category') ) {
    196                         $category = $category->term_id;
     196        }
     197
     198        if ( ! empty( $r['category_name'] ) ) {
     199                if ( $r['category'] = get_term_by('name', $r['category_name'], 'link_category') ) {
     200                        $r['category'] = $r['category']->term_id;
    197201                } else {
    198202                        $cache[ $key ] = array();
     
    203207        }
    204208
    205         if ( ! empty($search) ) {
    206                 $search = esc_sql( like_escape( $search ) );
     209        $search = '';
     210        if ( ! empty( $r['search'] ) ) {
     211                $search = esc_sql( like_escape( $r['search'] ) );
    207212                $search = " AND ( (link_url LIKE '%$search%') OR (link_name LIKE '%$search%') OR (link_description LIKE '%$search%') ) ";
    208213        }
     
    210215        $category_query = '';
    211216        $join = '';
    212         if ( !empty($category) ) {
    213                 $incategories = preg_split('/[\s,]+/',$category);
     217        if ( ! empty( $r['category'] ) ) {
     218                $incategories = preg_split( '/[\s,]+/', $r['category'] );
    214219                if ( count($incategories) ) {
    215220                        foreach ( $incategories as $incat ) {
    216                                 if (empty($category_query))
    217                                         $category_query = ' AND ( tt.term_id = ' . intval($incat) . ' ';
    218                                 else
    219                                         $category_query .= ' OR tt.term_id = ' . intval($incat) . ' ';
     221                                if ( empty( $category_query ) ) {
     222                                        $category_query = ' AND ( tt.term_id = ' . intval( $incat ) . ' ';
     223                                } else {
     224                                        $category_query .= ' OR tt.term_id = ' . intval( $incat ) . ' ';
     225                                }
    220226                        }
    221227                }
    222228        }
    223         if (!empty($category_query)) {
     229        if ( ! empty( $category_query ) ) {
    224230                $category_query .= ") AND taxonomy = 'link_category'";
    225231                $join = " INNER JOIN $wpdb->term_relationships AS tr ON ($wpdb->links.link_id = tr.object_id) INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_taxonomy_id = tr.term_taxonomy_id";
    226232        }
    227233
    228         if ( $show_updated ) {
     234        if ( $r['show_updated'] ) {
    229235                $recently_updated_test = ", IF (DATE_ADD(link_updated, INTERVAL 120 MINUTE) >= NOW(), 1,0) as recently_updated ";
    230236        } else {
     
    232238        }
    233239
    234         $get_updated = ( $show_updated ) ? ', UNIX_TIMESTAMP(link_updated) AS link_updated_f ' : '';
    235 
    236         $orderby = strtolower($orderby);
     240        $get_updated = ( $r['show_updated'] ) ? ', UNIX_TIMESTAMP(link_updated) AS link_updated_f ' : '';
     241
     242        $orderby = strtolower( $r['orderby'] );
    237243        $length = '';
    238244        switch ( $orderby ) {
     
    248254                default:
    249255                        $orderparams = array();
    250                         foreach ( explode(',', $orderby) as $ordparam ) {
    251                                 $ordparam = trim($ordparam);
    252                                 $keys = array( 'link_id', 'link_name', 'link_url', 'link_visible', 'link_rating', 'link_owner', 'link_updated', 'link_notes' );
    253                                 if ( in_array( 'link_' . $ordparam, $keys ) )
     256                        $keys = array( 'link_id', 'link_name', 'link_url', 'link_visible', 'link_rating', 'link_owner', 'link_updated', 'link_notes' );
     257                        foreach ( explode( ',', $orderby ) as $ordparam ) {
     258                                $ordparam = trim( $ordparam );
     259
     260                                if ( in_array( 'link_' . $ordparam, $keys ) ) {
    254261                                        $orderparams[] = 'link_' . $ordparam;
    255                                 elseif ( in_array( $ordparam, $keys ) )
     262                                } elseif ( in_array( $ordparam, $keys ) ) {
    256263                                        $orderparams[] = $ordparam;
     264                                }
    257265                        }
    258                         $orderby = implode(',', $orderparams);
    259         }
    260 
    261         if ( empty( $orderby ) )
     266                        $orderby = implode( ',', $orderparams );
     267        }
     268
     269        if ( empty( $orderby ) ) {
    262270                $orderby = 'link_name';
    263 
    264         $order = strtoupper( $order );
    265         if ( '' !== $order && !in_array( $order, array( 'ASC', 'DESC' ) ) )
     271        }
     272
     273        $order = strtoupper( $r['order'] );
     274        if ( '' !== $order && ! in_array( $order, array( 'ASC', 'DESC' ) ) ) {
    266275                $order = 'ASC';
     276        }
    267277
    268278        $visible = '';
    269         if ( $hide_invisible )
     279        if ( $r['hide_invisible'] ) {
    270280                $visible = "AND link_visible = 'Y'";
     281        }
    271282
    272283        $query = "SELECT * $length $recently_updated_test $get_updated FROM $wpdb->links $join WHERE 1=1 $visible $category_query";
    273284        $query .= " $exclusions $inclusions $search";
    274285        $query .= " ORDER BY $orderby $order";
    275         if ($limit != -1)
    276                 $query .= " LIMIT $limit";
    277 
    278         $results = $wpdb->get_results($query);
     286        if ( $r['limit'] != -1 ) {
     287                $query .= ' LIMIT ' . $r['limit'];
     288        }
     289
     290        $results = $wpdb->get_results( $query );
    279291
    280292        $cache[ $key ] = $results;
     
    356368                // The 'link_category' filter is for the name of a link category, not an array of a link's link categories
    357369                return $value;
    358                
     370
    359371        case 'link_visible' : // bool stored as Y|N
    360372                $value = preg_replace('/[^YNyn]/', '', $value);
Note: See TracChangeset for help on using the changeset viewer.