Changeset 3845 for trunk/wp-includes/bookmark-template.php
- Timestamp:
- 06/05/2006 02:12:59 AM (19 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/bookmark-template.php
r3809 r3845 281 281 } 282 282 283 function get_bookmarks($args = '') {284 global $wpdb;285 286 if ( is_array($args) )287 $r = &$args;288 else289 parse_str($args, $r);290 291 $defaults = array('orderby' => 'name', 'order' => 'ASC', 'limit' => -1, 'category' => '',292 'category_name' => '', 'hide_invisible' => 1, 'show_updated' => 0, 'include' => '', 'exclude' => '');293 $r = array_merge($defaults, $r);294 extract($r);295 296 $inclusions = '';297 if ( !empty($include) ) {298 $exclude = ''; //ignore exclude, category, and category_name params if using include299 $category = '';300 $category_name = '';301 $inclinks = preg_split('/[\s,]+/',$include);302 if ( count($inclinks) ) {303 foreach ( $inclinks as $inclink ) {304 if (empty($inclusions))305 $inclusions = ' AND ( link_id = ' . intval($inclink) . ' ';306 else307 $inclusions .= ' OR link_id = ' . intval($inclink) . ' ';308 }309 }310 }311 if (!empty($inclusions))312 $inclusions .= ')';313 314 $exclusions = '';315 if ( !empty($exclude) ) {316 $exlinks = preg_split('/[\s,]+/',$exclude);317 if ( count($exlinks) ) {318 foreach ( $exlinks as $exlink ) {319 if (empty($exclusions))320 $exclusions = ' AND ( link_id <> ' . intval($exlink) . ' ';321 else322 $exclusions .= ' AND link_id <> ' . intval($exlink) . ' ';323 }324 }325 }326 if (!empty($exclusions))327 $exclusions .= ')';328 329 if ( ! empty($category_name) ) {330 if ( $cat_id = $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE cat_name='$category_name' LIMIT 1") )331 $category = $cat_id;332 }333 334 $category_query = '';335 $join = '';336 if ( !empty($category) ) {337 $incategories = preg_split('/[\s,]+/',$category);338 if ( count($incategories) ) {339 foreach ( $incategories as $incat ) {340 if (empty($category_query))341 $category_query = ' AND ( category_id = ' . intval($incat) . ' ';342 else343 $category_query .= ' OR category_id = ' . intval($incat) . ' ';344 }345 }346 }347 if (!empty($category_query)) {348 $category_query .= ')';349 $join = " LEFT JOIN $wpdb->link2cat ON ($wpdb->links.link_id = $wpdb->link2cat.link_id) ";350 }351 352 if (get_settings('links_recently_updated_time')) {353 $recently_updated_test = ", IF (DATE_ADD(link_updated, INTERVAL " . get_settings('links_recently_updated_time') . " MINUTE) >= NOW(), 1,0) as recently_updated ";354 } else {355 $recently_updated_test = '';356 }357 358 if ($show_updated) {359 $get_updated = ", UNIX_TIMESTAMP(link_updated) AS link_updated_f ";360 }361 362 $orderby = strtolower($orderby);363 $length = '';364 switch ($orderby) {365 case 'length':366 $length = ", CHAR_LENGTH(link_name) AS length";367 break;368 case 'rand':369 $orderby = 'rand()';370 break;371 default:372 $orderby = "link_" . $orderby;373 }374 375 if ( 'link_id' == $orderby )376 $orderby = "$wpdb->links.link_id";377 378 $visible = '';379 if ( $hide_invisible )380 $visible = "AND link_visible = 'Y'";381 382 $query = "SELECT * $length $recently_updated_test $get_updated FROM $wpdb->links $join WHERE 1=1 $visible $category_query";383 $query .= " $exclusions $inclusions";384 $query .= " ORDER BY $orderby $order";385 if ($limit != -1)386 $query .= " LIMIT $limit";387 388 $results = $wpdb->get_results($query);389 return apply_filters('get_bookmarks', $results, $r);390 }391 283 ?>
Note: See TracChangeset
for help on using the changeset viewer.