equal
deleted
inserted
replaced
5 * @package WordPress |
5 * @package WordPress |
6 * @subpackage Bookmark |
6 * @subpackage Bookmark |
7 */ |
7 */ |
8 |
8 |
9 /** |
9 /** |
10 * Retrieve Bookmark data |
10 * Retrieves bookmark data. |
11 * |
11 * |
12 * @since 2.1.0 |
12 * @since 2.1.0 |
13 * |
13 * |
14 * @global wpdb $wpdb WordPress database abstraction object. |
14 * @global object $link Current link object. |
|
15 * @global wpdb $wpdb WordPress database abstraction object. |
15 * |
16 * |
16 * @param int|stdClass $bookmark |
17 * @param int|stdClass $bookmark |
17 * @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which |
18 * @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which |
18 * correspond to an stdClass object, an associative array, or a numeric array, |
19 * correspond to an stdClass object, an associative array, or a numeric array, |
19 * respectively. Default OBJECT. |
20 * respectively. Default OBJECT. |
31 } |
32 } |
32 } elseif ( is_object( $bookmark ) ) { |
33 } elseif ( is_object( $bookmark ) ) { |
33 wp_cache_add( $bookmark->link_id, $bookmark, 'bookmark' ); |
34 wp_cache_add( $bookmark->link_id, $bookmark, 'bookmark' ); |
34 $_bookmark = $bookmark; |
35 $_bookmark = $bookmark; |
35 } else { |
36 } else { |
36 if ( isset( $GLOBALS['link'] ) && ( $GLOBALS['link']->link_id == $bookmark ) ) { |
37 if ( isset( $GLOBALS['link'] ) && ( $GLOBALS['link']->link_id === $bookmark ) ) { |
37 $_bookmark = & $GLOBALS['link']; |
38 $_bookmark = & $GLOBALS['link']; |
38 } else { |
39 } else { |
39 $_bookmark = wp_cache_get( $bookmark, 'bookmark' ); |
40 $_bookmark = wp_cache_get( $bookmark, 'bookmark' ); |
40 if ( ! $_bookmark ) { |
41 if ( ! $_bookmark ) { |
41 $_bookmark = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->links WHERE link_id = %d LIMIT 1", $bookmark ) ); |
42 $_bookmark = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->links WHERE link_id = %d LIMIT 1", $bookmark ) ); |
63 return $_bookmark; |
64 return $_bookmark; |
64 } |
65 } |
65 } |
66 } |
66 |
67 |
67 /** |
68 /** |
68 * Retrieve single bookmark data item or field. |
69 * Retrieves single bookmark data item or field. |
69 * |
70 * |
70 * @since 2.3.0 |
71 * @since 2.3.0 |
71 * |
72 * |
72 * @param string $field The name of the data field to return. |
73 * @param string $field The name of the data field to return. |
73 * @param int $bookmark The bookmark ID to get field. |
74 * @param int $bookmark The bookmark ID to get field. |
74 * @param string $context Optional. The context of how the field will be used. |
75 * @param string $context Optional. The context of how the field will be used. Default 'display'. |
75 * @return string|WP_Error |
76 * @return string|WP_Error |
76 */ |
77 */ |
77 function get_bookmark_field( $field, $bookmark, $context = 'display' ) { |
78 function get_bookmark_field( $field, $bookmark, $context = 'display' ) { |
78 $bookmark = (int) $bookmark; |
79 $bookmark = (int) $bookmark; |
79 $bookmark = get_bookmark( $bookmark ); |
80 $bookmark = get_bookmark( $bookmark ); |
92 |
93 |
93 return sanitize_bookmark_field( $field, $bookmark->$field, $bookmark->link_id, $context ); |
94 return sanitize_bookmark_field( $field, $bookmark->$field, $bookmark->link_id, $context ); |
94 } |
95 } |
95 |
96 |
96 /** |
97 /** |
97 * Retrieves the list of bookmarks |
98 * Retrieves the list of bookmarks. |
98 * |
99 * |
99 * Attempts to retrieve from the cache first based on MD5 hash of arguments. If |
100 * Attempts to retrieve from the cache first based on MD5 hash of arguments. If |
100 * that fails, then the query will be built from the arguments and executed. The |
101 * that fails, then the query will be built from the arguments and executed. The |
101 * results will be stored to the cache. |
102 * results will be stored to the cache. |
102 * |
103 * |
304 } |
305 } |
305 |
306 |
306 $query = "SELECT * $length $recently_updated_test $get_updated FROM $wpdb->links $join WHERE 1=1 $visible $category_query"; |
307 $query = "SELECT * $length $recently_updated_test $get_updated FROM $wpdb->links $join WHERE 1=1 $visible $category_query"; |
307 $query .= " $exclusions $inclusions $search"; |
308 $query .= " $exclusions $inclusions $search"; |
308 $query .= " ORDER BY $orderby $order"; |
309 $query .= " ORDER BY $orderby $order"; |
309 if ( -1 != $parsed_args['limit'] ) { |
310 if ( -1 !== $parsed_args['limit'] ) { |
310 $query .= ' LIMIT ' . absint( $parsed_args['limit'] ); |
311 $query .= ' LIMIT ' . absint( $parsed_args['limit'] ); |
311 } |
312 } |
312 |
313 |
313 $results = $wpdb->get_results( $query ); |
314 $results = $wpdb->get_results( $query ); |
314 |
315 |
402 } |
403 } |
403 |
404 |
404 switch ( $field ) { |
405 switch ( $field ) { |
405 case 'link_category': // array( ints ) |
406 case 'link_category': // array( ints ) |
406 $value = array_map( 'absint', (array) $value ); |
407 $value = array_map( 'absint', (array) $value ); |
407 // We return here so that the categories aren't filtered. |
408 /* |
408 // The 'link_category' filter is for the name of a link category, not an array of a link's link categories. |
409 * We return here so that the categories aren't filtered. |
|
410 * The 'link_category' filter is for the name of a link category, not an array of a link's link categories. |
|
411 */ |
409 return $value; |
412 return $value; |
410 |
413 |
411 case 'link_visible': // bool stored as Y|N |
414 case 'link_visible': // bool stored as Y|N |
412 $value = preg_replace( '/[^YNyn]/', '', $value ); |
415 $value = preg_replace( '/[^YNyn]/', '', $value ); |
413 break; |
416 break; |