[ Index ]
 

Code source de WordPress 2.1.2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/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      $results = get_bookmarks("category=$category&orderby=$orderby&order=$order&show_updated=$show_updated&limit=$limit");
  85  
  86      if ( !$results )
  87          return;
  88  
  89      $output = '';
  90  
  91      foreach ( (array) $results as $row ) {
  92          if ( !isset($row->recently_updated) )
  93              $row->recently_updated = false;
  94          $output .= $before;
  95          if ( $show_updated && $row->recently_updated )
  96              $output .= get_option('links_recently_updated_prepend');
  97          $the_link = '#';
  98          if ( !empty($row->link_url) )
  99              $the_link = wp_specialchars($row->link_url);
 100          $rel = $row->link_rel;
 101          if ( '' != $rel )
 102              $rel = ' rel="' . $rel . '"';
 103  
 104          $desc = attribute_escape($row->link_description);
 105          $name = attribute_escape($row->link_name);
 106          $title = $desc;
 107  
 108          if ( $show_updated )
 109              if (substr($row->link_updated_f, 0, 2) != '00')
 110                  $title .= ' ('.__('Last updated') . ' ' . date(get_option('links_updated_date_format'), $row->link_updated_f + (get_option('gmt_offset') * 3600)) . ')';
 111  
 112          if ( '' != $title )
 113              $title = ' title="' . $title . '"';
 114  
 115          $alt = ' alt="' . $name . '"';
 116  
 117          $target = $row->link_target;
 118          if ( '' != $target )
 119              $target = ' target="' . $target . '"';
 120  
 121          $output .= '<a href="' . $the_link . '"' . $rel . $title . $target. '>';
 122  
 123          if ( $row->link_image != null && $show_images ) {
 124              if ( strpos($row->link_image, 'http') !== false )
 125                  $output .= "<img src=\"$row->link_image\" $alt $title />";
 126              else // If it's a relative path
 127                  $output .= "<img src=\"" . get_option('siteurl') . "$row->link_image\" $alt $title />";
 128          } else {
 129              $output .= $name;
 130          }
 131  
 132          $output .= '</a>';
 133  
 134          if ( $show_updated && $row->recently_updated )
 135              $output .= get_option('links_recently_updated_append');
 136  
 137          if ( $show_description && '' != $desc )
 138              $output .= $between . $desc;
 139  
 140          $output .= "$after\n";
 141      } // end while
 142  
 143      if ( !$echo )
 144          return $output;
 145      echo $output;
 146  }
 147  
 148  function get_linkrating($link) {
 149      return apply_filters('link_rating', $link->link_rating);
 150  }
 151  
 152  /** function get_linkcatname()
 153   ** Gets the name of category n.
 154   ** Parameters: id (default 0)  - The category to get. If no category supplied
 155   **                uses 0
 156   */
 157  function get_linkcatname($id = 0) {
 158      $id = (int) $id;
 159  
 160      if ( empty($id) )
 161          return '';
 162  
 163      $cats = wp_get_link_cats($id);
 164  
 165      if ( empty($cats) || ! is_array($cats) )
 166          return '';
 167  
 168      $cat_id = $cats[0]; // Take the first cat.
 169  
 170      $cat = get_category($cat_id);
 171      return $cat->cat_name;
 172  }
 173  
 174  /** function links_popup_script()
 175   ** This function contributed by Fullo -- http://sprite.csr.unibo.it/fullo/
 176   ** Show the link to the links popup and the number of links
 177   ** Parameters:
 178   **   text (default Links)  - the text of the link
 179   **   width (default 400)  - the width of the popup window
 180   **   height (default 400)  - the height of the popup window
 181   **   file (default linkspopup.php) - the page to open in the popup window
 182   **   count (default true) - the number of links in the db
 183   */
 184  function links_popup_script($text = 'Links', $width=400, $height=400, $file='links.all.php', $count = true) {
 185      if ( $count )
 186          $counts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->links");
 187  
 188      $javascript = "<a href=\"#\" onclick=\"javascript:window.open('$file?popup=1', '_blank', 'width=$width,height=$height,scrollbars=yes,status=no'); return false\">";
 189      $javascript .= $text;
 190  
 191      if ( $count )
 192          $javascript .= " ($counts)";
 193  
 194      $javascript .= "</a>\n\n";
 195          echo $javascript;
 196  }
 197  
 198  
 199  /*
 200   * function get_links_list()
 201   *
 202   * added by Dougal
 203   *
 204   * Output a list of all links, listed by category, using the
 205   * settings in $wpdb->linkcategories and output it as a nested
 206   * HTML unordered list.
 207   *
 208   * Parameters:
 209   *   order (default 'name')  - Sort link categories by 'name' or 'id'
 210   *   hide_if_empty (default true)  - Supress listing empty link categories
 211   */
 212  function get_links_list($order = 'name', $hide_if_empty = 'obsolete') {
 213      $order = strtolower($order);
 214  
 215      // Handle link category sorting
 216      $direction = 'ASC';
 217      if ( '_' == substr($order,0,1) ) {
 218          $direction = 'DESC';
 219          $order = substr($order,1);
 220      }
 221  
 222      if ( !isset($direction) )
 223          $direction = '';
 224  
 225      $cats = get_categories("type=link&orderby=$order&order=$direction&hierarchical=0");
 226  
 227      // Display each category
 228      if ( $cats ) {
 229          foreach ( (array) $cats as $cat ) {
 230              // Handle each category.
 231  
 232              // Display the category name
 233              echo '    <li id="linkcat-' . $cat->cat_ID . '" class="linkcat"><h2>' . $cat->cat_name . "</h2>\n\t<ul>\n";
 234              // Call get_links() with all the appropriate params
 235              get_links($cat->cat_ID, '<li>', "</li>", "\n", true, 'name', false);
 236  
 237              // Close the last category
 238              echo "\n\t</ul>\n</li>\n";
 239          }
 240      }
 241  }
 242  
 243  function _walk_bookmarks($bookmarks, $args = '' ) {
 244      if ( is_array($args) )
 245          $r = &$args;
 246      else
 247          parse_str($args, $r);
 248  
 249      $defaults = array('show_updated' => 0, 'show_description' => 0, 'show_images' => 1, 'before' => '<li>',
 250          'after' => '</li>', 'between' => "\n");
 251      $r = array_merge($defaults, $r);
 252      extract($r);
 253  
 254      foreach ( (array) $bookmarks as $bookmark ) {
 255          if ( !isset($bookmark->recently_updated) )
 256              $bookmark->recently_updated = false;
 257          $output .= $before;
 258          if ( $show_updated && $bookmark->recently_updated )
 259              $output .= get_option('links_recently_updated_prepend');
 260  
 261          $the_link = '#';
 262          if ( !empty($bookmark->link_url) )
 263              $the_link = wp_specialchars($bookmark->link_url);
 264  
 265          $rel = $bookmark->link_rel;
 266          if ( '' != $rel )
 267              $rel = ' rel="' . $rel . '"';
 268  
 269          $desc = attribute_escape($bookmark->link_description);
 270          $name = attribute_escape($bookmark->link_name);
 271          $title = $desc;
 272  
 273          if ( $show_updated )
 274              if ( '00' != substr($bookmark->link_updated_f, 0, 2) ) {
 275                  $title .= ' ';
 276                  $title .= sprintf(__('Last updated: %s'), date(get_option('links_updated_date_format'), $bookmark->link_updated_f + (get_option('gmt_offset') * 3600)));
 277                  $title .= ')';
 278              }
 279  
 280          if ( '' != $title )
 281              $title = ' title="' . $title . '"';
 282  
 283          $alt = ' alt="' . $name . '"';
 284  
 285          $target = $bookmark->link_target;
 286          if ( '' != $target )
 287              $target = ' target="' . $target . '"';
 288  
 289          $output .= '<a href="' . $the_link . '"' . $rel . $title . $target. '>';
 290  
 291          if ( $bookmark->link_image != null && $show_images ) {
 292              if ( strpos($bookmark->link_image, 'http') !== false )
 293                  $output .= "<img src=\"$bookmark->link_image\" $alt $title />";
 294              else // If it's a relative path
 295                  $output .= "<img src=\"" . get_option('siteurl') . "$bookmark->link_image\" $alt $title />";
 296          } else {
 297              $output .= $name;
 298          }
 299  
 300          $output .= '</a>';
 301  
 302          if ( $show_updated && $bookmark->recently_updated )
 303              $output .= get_option('links_recently_updated_append');
 304  
 305          if ( $show_description && '' != $desc )
 306              $output .= $between . $desc;
 307          $output .= "$after\n";
 308      } // end while
 309  
 310      return $output;
 311  }
 312  
 313  function wp_list_bookmarks($args = '') {
 314      if ( is_array($args) )
 315          $r = &$args;
 316      else
 317          parse_str($args, $r);
 318  
 319      $defaults = array('orderby' => 'name', 'order' => 'ASC', 'limit' => -1, 'category' => '',
 320          'category_name' => '', 'hide_invisible' => 1, 'show_updated' => 0, 'echo' => 1,
 321          'categorize' => 1, 'title_li' => __('Bookmarks'), 'title_before' => '<h2>', 'title_after' => '</h2>',
 322          'category_orderby' => 'name', 'category_order' => 'ASC', 'class' => 'linkcat',
 323          'category_before' => '<li id="%id" class="%class">', 'category_after' => '</li>');
 324      $r = array_merge($defaults, $r);
 325      extract($r);
 326  
 327      $output = '';
 328  
 329      if ( $categorize ) {
 330          //Split the bookmarks into ul's for each category
 331          $cats = get_categories("type=link&category_name=$category_name&include=$category&orderby=$category_orderby&order=$category_order&hierarchical=0");
 332  
 333          foreach ( (array) $cats as $cat ) {
 334              $bookmarks = get_bookmarks("limit=$limit&category={$cat->cat_ID}&show_updated=$show_updated&orderby=$orderby&order=$order&hide_invisible=$hide_invisible&show_updated=$show_updated");
 335              if ( empty($bookmarks) )
 336                  continue;
 337              $output .= str_replace(array('%id', '%class'), array("linkcat-$cat->cat_ID", $class), $category_before);
 338              $output .= "$title_before$cat->cat_name$title_after\n\t<ul>\n";
 339              $output .= _walk_bookmarks($bookmarks, $r);
 340              $output .= "\n\t</ul>\n$category_after\n";
 341          }
 342      } else {
 343          //output one single list using title_li for the title
 344          $bookmarks = get_bookmarks("limit=$limit&category=$category&show_updated=$show_updated&orderby=$orderby&order=$order&hide_invisible=$hide_invisible&show_updated=$show_updated");
 345          
 346          if ( !empty($bookmarks) ) {
 347              if ( !empty( $title_li ) ){
 348                  $output .= str_replace(array('%id', '%class'), array("linkcat-$category", $class), $category_before);
 349                  $output .= "$title_before$title_li$title_after\n\t<ul>\n";
 350                  $output .= _walk_bookmarks($bookmarks, $r);
 351                  $output .= "\n\t</ul>\n$category_after\n";
 352              } else {
 353                  $output .= _walk_bookmarks($bookmarks, $r);
 354              }
 355          }
 356      }
 357  
 358      if ( !$echo )
 359          return $output;
 360      echo $output;
 361  }
 362  
 363  ?>


Généré le : Fri Mar 30 19:41:27 2007 par Balluche grâce à PHPXref 0.7