[ Index ]

WordPress Source Cross Reference

title

Body

[close]

/wp-includes/ -> bookmark.php (source)

   1  <?php
   2  
   3  function get_bookmark($bookmark_id, $output = OBJECT) {
   4      global $wpdb;
   5  
   6      $link = $wpdb->get_row("SELECT * FROM $wpdb->links WHERE link_id = '$bookmark_id'");
   7      $link->link_category = wp_get_link_cats($bookmark_id);
   8  
   9      if ( $output == OBJECT ) {
  10          return $link;
  11      } elseif ( $output == ARRAY_A ) {
  12          return get_object_vars($link);
  13      } elseif ( $output == ARRAY_N ) {
  14          return array_values(get_object_vars($link));
  15      } else {
  16          return $link;
  17      }
  18  }
  19  
  20  // Deprecate
  21  function get_link($bookmark_id, $output = OBJECT) {
  22      return get_bookmark($bookmark_id, $output);    
  23  }
  24  
  25  function get_bookmarks($args = '') {
  26      global $wpdb;
  27  
  28      if ( is_array($args) )
  29          $r = &$args;
  30      else
  31          parse_str($args, $r);
  32  
  33      $defaults = array('orderby' => 'name', 'order' => 'ASC', 'limit' => -1, 'category' => '',
  34          'category_name' => '', 'hide_invisible' => 1, 'show_updated' => 0, 'include' => '', 'exclude' => '');
  35      $r = array_merge($defaults, $r);
  36      extract($r);
  37  
  38      $inclusions = '';
  39      if ( !empty($include) ) {
  40      $exclude = '';  //ignore exclude, category, and category_name params if using include
  41      $category = '';
  42      $category_name = '';
  43          $inclinks = preg_split('/[\s,]+/',$include);
  44          if ( count($inclinks) ) {
  45              foreach ( $inclinks as $inclink ) {
  46                  if (empty($inclusions))
  47                      $inclusions = ' AND ( link_id = ' . intval($inclink) . ' ';
  48                  else
  49                      $inclusions .= ' OR link_id = ' . intval($inclink) . ' ';
  50              }
  51          }
  52      }
  53      if (!empty($inclusions)) 
  54          $inclusions .= ')';
  55  
  56      $exclusions = '';
  57      if ( !empty($exclude) ) {
  58          $exlinks = preg_split('/[\s,]+/',$exclude);
  59          if ( count($exlinks) ) {
  60              foreach ( $exlinks as $exlink ) {
  61                  if (empty($exclusions))
  62                      $exclusions = ' AND ( link_id <> ' . intval($exlink) . ' ';
  63                  else
  64                      $exclusions .= ' AND link_id <> ' . intval($exlink) . ' ';
  65              }
  66          }
  67      }
  68      if (!empty($exclusions)) 
  69          $exclusions .= ')';
  70          
  71      if ( ! empty($category_name) ) {
  72          if ( $cat_id = $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE cat_name='$category_name' LIMIT 1") )
  73              $category = $cat_id;
  74      }
  75  
  76      $category_query = '';
  77      $join = '';
  78      if ( !empty($category) ) {
  79          $incategories = preg_split('/[\s,]+/',$category);
  80          if ( count($incategories) ) {
  81              foreach ( $incategories as $incat ) {
  82                  if (empty($category_query))
  83                      $category_query = ' AND ( category_id = ' . intval($incat) . ' ';
  84                  else
  85                      $category_query .= ' OR category_id = ' . intval($incat) . ' ';
  86              }
  87          }
  88      }
  89      if (!empty($category_query)) {
  90          $category_query .= ')';    
  91          $join = " LEFT JOIN $wpdb->link2cat ON ($wpdb->links.link_id = $wpdb->link2cat.link_id) ";
  92      }
  93  
  94      if (get_settings('links_recently_updated_time')) {
  95          $recently_updated_test = ", IF (DATE_ADD(link_updated, INTERVAL " . get_settings('links_recently_updated_time') . " MINUTE) >= NOW(), 1,0) as recently_updated ";
  96      } else {
  97          $recently_updated_test = '';
  98      }
  99  
 100      if ($show_updated) {
 101          $get_updated = ", UNIX_TIMESTAMP(link_updated) AS link_updated_f ";
 102      }
 103  
 104      $orderby = strtolower($orderby);
 105      $length = '';
 106      switch ($orderby) {
 107          case 'length':
 108              $length = ", CHAR_LENGTH(link_name) AS length";
 109              break;
 110          case 'rand':
 111              $orderby = 'rand()';
 112              break;
 113          default:
 114              $orderby = "link_" . $orderby;
 115      }
 116  
 117      if ( 'link_id' == $orderby )
 118          $orderby = "$wpdb->links.link_id";
 119  
 120      $visible = '';
 121      if ( $hide_invisible )
 122          $visible = "AND link_visible = 'Y'";
 123  
 124      $query = "SELECT * $length $recently_updated_test $get_updated FROM $wpdb->links $join WHERE 1=1 $visible $category_query";
 125      $query .= " $exclusions $inclusions";
 126      $query .= " ORDER BY $orderby $order";
 127      if ($limit != -1)
 128          $query .= " LIMIT $limit";
 129  
 130      $results = $wpdb->get_results($query);
 131      return apply_filters('get_bookmarks', $results, $r);
 132  }
 133  
 134  ?>

Your comment here...

Name: Location:
Comments:


List: Classes | Functions | Variables | Constants | Tables

Generated: Sat Jul 15 11:57:04 2006 Courtesy of Taragana