Eliminate use of `extract()` in `get_bookmarks()`.
See #22400. Built from https://develop.svn.wordpress.org/trunk@28403 git-svn-id: http://core.svn.wordpress.org/trunk@28230 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
a4a5560b22
commit
12a5b389ab
|
@ -118,7 +118,7 @@ function get_bookmark_field( $field, $bookmark, $context = 'display' ) {
|
|||
* @param string|array $args List of arguments to overwrite the defaults
|
||||
* @return array List of bookmark row objects
|
||||
*/
|
||||
function get_bookmarks($args = '') {
|
||||
function get_bookmarks( $args = '' ) {
|
||||
global $wpdb;
|
||||
|
||||
$defaults = array(
|
||||
|
@ -130,11 +130,10 @@ function get_bookmarks($args = '') {
|
|||
);
|
||||
|
||||
$r = wp_parse_args( $args, $defaults );
|
||||
extract( $r, EXTR_SKIP );
|
||||
|
||||
$key = md5( serialize( $r ) );
|
||||
if ( $cache = wp_cache_get( 'get_bookmarks', 'bookmark' ) ) {
|
||||
if ( is_array($cache) && isset( $cache[ $key ] ) ) {
|
||||
if ( is_array( $cache ) && isset( $cache[ $key ] ) ) {
|
||||
$bookmarks = $cache[ $key ];
|
||||
/**
|
||||
* Filter the returned list of bookmarks.
|
||||
|
@ -155,45 +154,50 @@ function get_bookmarks($args = '') {
|
|||
}
|
||||
}
|
||||
|
||||
if ( !is_array($cache) )
|
||||
if ( ! is_array( $cache ) ) {
|
||||
$cache = array();
|
||||
}
|
||||
|
||||
$inclusions = '';
|
||||
if ( !empty($include) ) {
|
||||
$exclude = ''; //ignore exclude, category, and category_name params if using include
|
||||
$category = '';
|
||||
$category_name = '';
|
||||
$inclinks = preg_split('/[\s,]+/',$include);
|
||||
if ( count($inclinks) ) {
|
||||
if ( ! empty( $r['include'] ) ) {
|
||||
$r['exclude'] = ''; //ignore exclude, category, and category_name params if using include
|
||||
$r['category'] = '';
|
||||
$r['category_name'] = '';
|
||||
$inclinks = preg_split( '/[\s,]+/', $r['include'] );
|
||||
if ( count( $inclinks ) ) {
|
||||
foreach ( $inclinks as $inclink ) {
|
||||
if (empty($inclusions))
|
||||
$inclusions = ' AND ( link_id = ' . intval($inclink) . ' ';
|
||||
else
|
||||
$inclusions .= ' OR link_id = ' . intval($inclink) . ' ';
|
||||
if ( empty( $inclusions ) ) {
|
||||
$inclusions = ' AND ( link_id = ' . intval( $inclink ) . ' ';
|
||||
} else {
|
||||
$inclusions .= ' OR link_id = ' . intval( $inclink ) . ' ';
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($inclusions))
|
||||
}
|
||||
if (! empty( $inclusions ) ) {
|
||||
$inclusions .= ')';
|
||||
}
|
||||
|
||||
$exclusions = '';
|
||||
if ( !empty($exclude) ) {
|
||||
$exlinks = preg_split('/[\s,]+/',$exclude);
|
||||
if ( count($exlinks) ) {
|
||||
if ( ! empty( $r['exclude'] ) ) {
|
||||
$exlinks = preg_split( '/[\s,]+/', $r['exclude'] );
|
||||
if ( count( $exlinks ) ) {
|
||||
foreach ( $exlinks as $exlink ) {
|
||||
if (empty($exclusions))
|
||||
$exclusions = ' AND ( link_id <> ' . intval($exlink) . ' ';
|
||||
else
|
||||
$exclusions .= ' AND link_id <> ' . intval($exlink) . ' ';
|
||||
if ( empty( $exclusions ) ) {
|
||||
$exclusions = ' AND ( link_id <> ' . intval( $exlink ) . ' ';
|
||||
} else {
|
||||
$exclusions .= ' AND link_id <> ' . intval( $exlink ) . ' ';
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($exclusions))
|
||||
}
|
||||
if ( ! empty( $exclusions ) ) {
|
||||
$exclusions .= ')';
|
||||
}
|
||||
|
||||
if ( !empty($category_name) ) {
|
||||
if ( $category = get_term_by('name', $category_name, 'link_category') ) {
|
||||
$category = $category->term_id;
|
||||
if ( ! empty( $r['category_name'] ) ) {
|
||||
if ( $r['category'] = get_term_by('name', $r['category_name'], 'link_category') ) {
|
||||
$r['category'] = $r['category']->term_id;
|
||||
} else {
|
||||
$cache[ $key ] = array();
|
||||
wp_cache_set( 'get_bookmarks', $cache, 'bookmark' );
|
||||
|
@ -202,38 +206,40 @@ function get_bookmarks($args = '') {
|
|||
}
|
||||
}
|
||||
|
||||
if ( ! empty($search) ) {
|
||||
$search = esc_sql( like_escape( $search ) );
|
||||
$search = '';
|
||||
if ( ! empty( $r['search'] ) ) {
|
||||
$search = esc_sql( like_escape( $r['search'] ) );
|
||||
$search = " AND ( (link_url LIKE '%$search%') OR (link_name LIKE '%$search%') OR (link_description LIKE '%$search%') ) ";
|
||||
}
|
||||
|
||||
$category_query = '';
|
||||
$join = '';
|
||||
if ( !empty($category) ) {
|
||||
$incategories = preg_split('/[\s,]+/',$category);
|
||||
if ( ! empty( $r['category'] ) ) {
|
||||
$incategories = preg_split( '/[\s,]+/', $r['category'] );
|
||||
if ( count($incategories) ) {
|
||||
foreach ( $incategories as $incat ) {
|
||||
if (empty($category_query))
|
||||
$category_query = ' AND ( tt.term_id = ' . intval($incat) . ' ';
|
||||
else
|
||||
$category_query .= ' OR tt.term_id = ' . intval($incat) . ' ';
|
||||
if ( empty( $category_query ) ) {
|
||||
$category_query = ' AND ( tt.term_id = ' . intval( $incat ) . ' ';
|
||||
} else {
|
||||
$category_query .= ' OR tt.term_id = ' . intval( $incat ) . ' ';
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($category_query)) {
|
||||
}
|
||||
if ( ! empty( $category_query ) ) {
|
||||
$category_query .= ") AND taxonomy = 'link_category'";
|
||||
$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";
|
||||
}
|
||||
|
||||
if ( $show_updated ) {
|
||||
if ( $r['show_updated'] ) {
|
||||
$recently_updated_test = ", IF (DATE_ADD(link_updated, INTERVAL 120 MINUTE) >= NOW(), 1,0) as recently_updated ";
|
||||
} else {
|
||||
$recently_updated_test = '';
|
||||
}
|
||||
|
||||
$get_updated = ( $show_updated ) ? ', UNIX_TIMESTAMP(link_updated) AS link_updated_f ' : '';
|
||||
$get_updated = ( $r['show_updated'] ) ? ', UNIX_TIMESTAMP(link_updated) AS link_updated_f ' : '';
|
||||
|
||||
$orderby = strtolower($orderby);
|
||||
$orderby = strtolower( $r['orderby'] );
|
||||
$length = '';
|
||||
switch ( $orderby ) {
|
||||
case 'length':
|
||||
|
@ -247,35 +253,41 @@ function get_bookmarks($args = '') {
|
|||
break;
|
||||
default:
|
||||
$orderparams = array();
|
||||
foreach ( explode(',', $orderby) as $ordparam ) {
|
||||
$ordparam = trim($ordparam);
|
||||
$keys = array( 'link_id', 'link_name', 'link_url', 'link_visible', 'link_rating', 'link_owner', 'link_updated', 'link_notes' );
|
||||
if ( in_array( 'link_' . $ordparam, $keys ) )
|
||||
foreach ( explode( ',', $orderby ) as $ordparam ) {
|
||||
$ordparam = trim( $ordparam );
|
||||
|
||||
if ( in_array( 'link_' . $ordparam, $keys ) ) {
|
||||
$orderparams[] = 'link_' . $ordparam;
|
||||
elseif ( in_array( $ordparam, $keys ) )
|
||||
} elseif ( in_array( $ordparam, $keys ) ) {
|
||||
$orderparams[] = $ordparam;
|
||||
}
|
||||
$orderby = implode(',', $orderparams);
|
||||
}
|
||||
$orderby = implode( ',', $orderparams );
|
||||
}
|
||||
|
||||
if ( empty( $orderby ) )
|
||||
if ( empty( $orderby ) ) {
|
||||
$orderby = 'link_name';
|
||||
}
|
||||
|
||||
$order = strtoupper( $order );
|
||||
if ( '' !== $order && !in_array( $order, array( 'ASC', 'DESC' ) ) )
|
||||
$order = strtoupper( $r['order'] );
|
||||
if ( '' !== $order && ! in_array( $order, array( 'ASC', 'DESC' ) ) ) {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
$visible = '';
|
||||
if ( $hide_invisible )
|
||||
if ( $r['hide_invisible'] ) {
|
||||
$visible = "AND link_visible = 'Y'";
|
||||
}
|
||||
|
||||
$query = "SELECT * $length $recently_updated_test $get_updated FROM $wpdb->links $join WHERE 1=1 $visible $category_query";
|
||||
$query .= " $exclusions $inclusions $search";
|
||||
$query .= " ORDER BY $orderby $order";
|
||||
if ($limit != -1)
|
||||
$query .= " LIMIT $limit";
|
||||
if ( $r['limit'] != -1 ) {
|
||||
$query .= ' LIMIT ' . $r['limit'];
|
||||
}
|
||||
|
||||
$results = $wpdb->get_results($query);
|
||||
$results = $wpdb->get_results( $query );
|
||||
|
||||
$cache[ $key ] = $results;
|
||||
wp_cache_set( 'get_bookmarks', $cache, 'bookmark' );
|
||||
|
|
Loading…
Reference in New Issue