[ Index ]

WordPress Source Cross Reference

title

Body

[close]

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

   1  <?php
   2  
   3  /** function wp_get_links()
   4   ** Gets the links associated with category n.
   5   ** Parameters:
   6   **   category (no default)  - The category to use.
   7   ** or:
   8   **   a query string
   9   **/
  10  function wp_get_links($args = '') {
  11      global $wpdb;
  12  
  13      if ( empty($args) )
  14          return;
  15  
  16      if ( false === strpos($args, '=') ) {
  17          $cat_id = $args;
  18          $args = add_query_arg('category', $cat_id, $args);
  19      }
  20  
  21      parse_str($args);
  22  
  23      if (! isset($category))    $category = -1;
  24      if (! isset($before)) $before = '';
  25      if (! isset($after)) $after = '<br />';
  26      if (! isset($between))    $between = ' ';
  27      if (! isset($show_images)) $show_images = true;
  28      if (! isset($orderby)) $orderby = 'name';
  29      if (! isset($show_description)) $show_description = true;
  30      if (! isset($show_rating)) $show_rating = false;
  31      if (! isset($limit)) $limit = -1;
  32      if (! isset($show_updated)) $show_updated = 1;
  33      if (! isset($echo)) $echo = true;
  34  
  35      return get_links($category, $before, $after, $between, $show_images, $orderby, $show_description, $show_rating, $limit, $show_updated, $echo);
  36  } // end wp_get_links
  37  
  38  /** function get_links()
  39   ** Gets the links associated with category n.
  40   ** Parameters:
  41   **   category (default -1)  - The category to use. If no category supplied
  42   **      uses all
  43   **   before (default '')  - the html to output before the link
  44   **   after (default '<br />')  - the html to output after the link
  45   **   between (default ' ')  - the html to output between the link/image
  46   **     and its description. Not used if no image or show_images == true
  47   **   show_images (default true) - whether to show images (if defined).
  48   **   orderby (default 'id') - the order to output the links. E.g. 'id', 'name',
  49   **     'url', 'description', or 'rating'. Or maybe owner. If you start the
  50   **     name with an underscore the order will be reversed.
  51   **     You can also specify 'rand' as the order which will return links in a
  52   **     random order.
  53   **   show_description (default true) - whether to show the description if
  54   **    show_images=false/not defined .
  55   **   show_rating (default false) - show rating stars/chars
  56   **   limit (default -1) - Limit to X entries. If not specified, all entries
  57   **     are shown.
  58   **   show_updated (default 0) - whether to show last updated timestamp
  59   **   echo (default true) - whether to echo the results, or return them instead
  60   */
  61  function get_links($category = -1,
  62              $before = '',
  63              $after = '<br />',
  64              $between = ' ',
  65              $show_images = true,
  66              $orderby = 'name',
  67              $show_description = true,
  68              $show_rating = false,
  69              $limit = -1,
  70              $show_updated = 1,
  71              $echo = true) {
  72  
  73      global $wpdb;
  74  
  75      $order = 'ASC';
  76      if (substr($orderby, 0, 1) == '_') {
  77          $order = 'DESC';
  78          $orderby = substr($orderby, 1);
  79      }
  80      
  81      if ($category == -1) {  //get_bookmarks uses '' to signify all categories
  82          $category = '';
  83      }
  84  
  85      $results = get_bookmarks("category=$category&orderby=$orderby&order=$order&show_updated=$show_updated&limit=$limit");
  86  
  87      if (!$results) {
  88          return;
  89      }
  90  
  91  
  92      $output = '';
  93  
  94      foreach ($results as $row) {
  95          if (!isset($row->recently_updated)) $row->recently_updated = false;
  96              $output .= $before;
  97          if ($show_updated && $row->recently_updated) {
  98              $output .= get_settings('links_recently_updated_prepend');
  99          }
 100  
 101          $the_link = '#';
 102          if (!empty($row->link_url))
 103              $the_link = wp_specialchars($row->link_url);
 104  
 105          $rel = $row->link_rel;
 106          if ($rel != '') {
 107              $rel = ' rel="' . $rel . '"';
 108          }
 109  
 110          $desc = wp_specialchars($row->link_description, ENT_QUOTES);
 111          $name = wp_specialchars($row->link_name, ENT_QUOTES);
 112          $title = $desc;
 113  
 114          if ($show_updated) {
 115              if (substr($row->link_updated_f, 0, 2) != '00') {
 116                  $title .= ' (Last updated ' . date(get_settings('links_updated_date_format'), $row->link_updated_f + (get_settings('gmt_offset') * 3600)) . ')';
 117              }
 118          }
 119  
 120          if ('' != $title) {
 121              $title = ' title="' . $title . '"';
 122          }
 123  
 124          $alt = ' alt="' . $name . '"';
 125  
 126          $target = $row->link_target;
 127          if ('' != $target) {
 128              $target = ' target="' . $target . '"';
 129          }
 130  
 131          $output .= '<a href="' . $the_link . '"' . $rel . $title . $target. '>';
 132  
 133          if (($row->link_image != null) && $show_images) {
 134              if (strstr($row->link_image, 'http'))
 135                  $output .= "<img src=\"$row->link_image\" $alt $title />";
 136              else // If it's a relative path
 137                  $output .= "<img src=\"" . get_settings('siteurl') . "$row->link_image\" $alt $title />";
 138          } else {
 139              $output .= $name;
 140          }
 141  
 142          $output .= '</a>';
 143  
 144          if ($show_updated && $row->recently_updated) {
 145              $output .= get_settings('links_recently_updated_append');
 146          }
 147  
 148          if ($show_description && ($desc != '')) {
 149              $output .= $between . $desc;
 150          }
 151          $output .= "$after\n";
 152      } // end while
 153  
 154      if ($echo) {
 155          echo $output;
 156      } else {
 157          return $output;
 158      }
 159  }
 160  
 161  function get_linkrating($link) {
 162      return apply_filters('link_rating', $link->link_rating);
 163  }
 164  
 165  /** function get_linkcatname()
 166   ** Gets the name of category n.
 167   ** Parameters: id (default 0)  - The category to get. If no category supplied
 168   **                uses 0
 169   */
 170  function get_linkcatname($id = 0) {
 171      $id = (int) $id;
 172  
 173      if ( empty($id) )
 174          return '';
 175    
 176      $cats = wp_get_link_cats($id);
 177  
 178      if ( empty($cats) || ! is_array($cats) )
 179          return '';
 180  
 181      $cat_id = $cats[0]; // Take the first cat.
 182  
 183      $cat = get_category($cat_id);
 184      return $cat->cat_name;
 185  }
 186  
 187  /** function links_popup_script()
 188   ** This function contributed by Fullo -- http://sprite.csr.unibo.it/fullo/
 189   ** Show the link to the links popup and the number of links
 190   ** Parameters:
 191   **   text (default Links)  - the text of the link
 192   **   width (default 400)  - the width of the popup window
 193   **   height (default 400)  - the height of the popup window
 194   **   file (default linkspopup.php) - the page to open in the popup window
 195   **   count (default true) - the number of links in the db
 196   */
 197  function links_popup_script($text = 'Links', $width=400, $height=400,
 198                              $file='links.all.php', $count = true) {
 199     if ($count == true) {
 200        $counts = $wpdb->get_var("SELECT count(*) FROM $wpdb->links");
 201     }
 202  
 203     $javascript = "<a href=\"#\" " .
 204                   " onclick=\"javascript:window.open('$file?popup=1', '_blank', " .
 205                   "'width=$width,height=$height,scrollbars=yes,status=no'); " .
 206                   " return false\">";
 207     $javascript .= $text;
 208  
 209     if ($count == true) {
 210        $javascript .= " ($counts)";
 211     }
 212  
 213     $javascript .="</a>\n\n";
 214     echo $javascript;
 215  }
 216  
 217  
 218  /*
 219   * function get_links_list()
 220   *
 221   * added by Dougal
 222   *
 223   * Output a list of all links, listed by category, using the
 224   * settings in $wpdb->linkcategories and output it as a nested
 225   * HTML unordered list.
 226   *
 227   * Parameters:
 228   *   order (default 'name')  - Sort link categories by 'name' or 'id'
 229   *   hide_if_empty (default true)  - Supress listing empty link categories
 230   */
 231  function get_links_list($order = 'name', $hide_if_empty = 'obsolete') {
 232      $order = strtolower($order);
 233  
 234      // Handle link category sorting
 235      $direction = 'ASC';
 236      if (substr($order,0,1) == '_') {
 237          $direction = 'DESC';
 238          $order = substr($order,1);
 239      }
 240  
 241      if (!isset($direction)) $direction = '';
 242  
 243      $cats = get_categories("type=link&orderby=$order&order=$direction&hierarchical=0");
 244  
 245      // Display each category
 246      if ($cats) {
 247          foreach ($cats as $cat) {
 248              // Handle each category.
 249  
 250              // Display the category name
 251              echo '    <li id="linkcat-' . $cat->cat_ID . '"><h2>' . $cat->cat_name . "</h2>\n\t<ul>\n";
 252              // Call get_links() with all the appropriate params
 253              get_links($cat->cat_ID,
 254                  '<li>',"</li>","\n", true, 'name', false);
 255  
 256              // Close the last category
 257              echo "\n\t</ul>\n</li>\n";
 258          }
 259      }
 260  }
 261  
 262  function _walk_bookmarks($bookmarks, $args = '' ) {
 263      if ( is_array($args) )
 264          $r = &$args;
 265      else
 266          parse_str($args, $r);
 267  
 268      $defaults = array('show_updated' => 0, 'show_description' => 0, 'show_images' => 0, 'before' => '<li>',
 269          'after' => '</li>', 'between' => "\n");
 270      $r = array_merge($defaults, $r);
 271      extract($r);
 272  
 273      foreach ( (array) $bookmarks as $bookmark ) {
 274          if (!isset($bookmark->recently_updated)) $bookmark->recently_updated = false;
 275              $output .= $before;
 276          if ($show_updated && $bookmark->recently_updated) {
 277              $output .= get_settings('links_recently_updated_prepend');
 278          }
 279  
 280          $the_link = '#';
 281          if (!empty($bookmark->link_url))
 282              $the_link = wp_specialchars($bookmark->link_url);
 283  
 284          $rel = $bookmark->link_rel;
 285          if ($rel != '') {
 286              $rel = ' rel="' . $rel . '"';
 287          }
 288  
 289          $desc = wp_specialchars($bookmark->link_description, ENT_QUOTES);
 290          $name = wp_specialchars($bookmark->link_name, ENT_QUOTES);
 291          $title = $desc;
 292  
 293          if ($show_updated) {
 294              if (substr($bookmark->link_updated_f, 0, 2) != '00') {
 295                  $title .= ' (Last updated ' . date(get_settings('links_updated_date_format'), $bookmark->link_updated_f + (get_settings('gmt_offset') * 3600)) . ')';
 296              }
 297          }
 298  
 299          if ('' != $title) {
 300              $title = ' title="' . $title . '"';
 301          }
 302  
 303          $alt = ' alt="' . $name . '"';
 304  
 305          $target = $bookmark->link_target;
 306          if ('' != $target) {
 307              $target = ' target="' . $target . '"';
 308          }
 309  
 310          $output .= '<a href="' . $the_link . '"' . $rel . $title . $target. '>';
 311  
 312          if (($bookmark->link_image != null) && $show_images) {
 313              if (strstr($bookmark->link_image, 'http'))
 314                  $output .= "<img src=\"$bookmark->link_image\" $alt $title />";
 315              else // If it's a relative path
 316                  $output .= "<img src=\"" . get_settings('siteurl') . "$bookmark->link_image\" $alt $title />";
 317          } else {
 318              $output .= $name;
 319          }
 320  
 321          $output .= '</a>';
 322  
 323          if ($show_updated && $bookmark->recently_updated) {
 324              $output .= get_settings('links_recently_updated_append');
 325          }
 326  
 327          if ($show_description && ($desc != '')) {
 328              $output .= $between . $desc;
 329          }
 330          $output .= "$after\n";
 331      } // end while
 332  
 333      return $output;
 334  }
 335  
 336  function wp_list_bookmarks($args = '') {
 337      if ( is_array($args) )
 338          $r = &$args;
 339      else
 340          parse_str($args, $r);
 341  
 342      $defaults = array('orderby' => 'name', 'order' => 'ASC', 'limit' => -1, 'category' => 0,
 343          'category_name' => '', 'hide_invisible' => 1, 'show_updated' => 0, 'echo' => 1,
 344          'categorize' => 1, 'title_li' => __('Bookmarks'), 'title_before' => '<h2>', 'title_after' => '</h2>',
 345          'category_orderby' => 'name', 'category_order' => 'ASC');
 346      $r = array_merge($defaults, $r);
 347      extract($r);
 348      
 349      // TODO: The rest of it.
 350      // If $categorize, group links by category with the category name being the
 351      // title of each li, otherwise just list them with title_li as the li title. 
 352      // If $categorize and $category or $category_name, list links for the given category
 353      // with the category name as the title li.  If not $categorize, use title_li.
 354      // When using each category's name as a title li, use before and after args for specifying
 355      // any markup.  We don't want to hardcode h2.
 356  
 357      $output = '';
 358  
 359      if ( $categorize ) {
 360          $cats = get_categories("type=link&orderby=$category_orderby&order=$category_order&hierarchical=0");
 361          foreach ( (array) $cats as $cat ) {
 362              $r['category'] = $cat->cat_ID;
 363              $bookmarks = get_bookmarks($r);
 364              if ( empty($bookmarks) )
 365                  continue;
 366              $output .= "<li id=\"linkcat-$cat->cat_ID\">$title_before$cat->cat_name$title_after\n\t<ul>\n";
 367              $output .= _walk_bookmarks($bookmarks, $r);
 368              $output .= "\n\t</ul>\n</li>\n";
 369          }
 370      }
 371  
 372      if ($echo)
 373          echo $output;
 374  
 375      return $output;
 376  }
 377  
 378  ?>

Your comment here...

Name: Location:
Comments:


List: Classes | Functions | Variables | Constants | Tables

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