[ Index ]

PHP Cross Reference of zeList

title

Body

[close]

/includes/ -> duplicate.php (source)

   1  <?php
   2  
   3  /**
   4   * Duplicated version of wp_list_bookmarks... only the _walk function is modified
   5   *
   6   * List of default arguments are as follows:
   7   * 'orderby' - Default is 'name' (string). How to order the links by. String is
   8   *        based off of the bookmark scheme.
   9   * 'order' - Default is 'ASC' (string). Either 'ASC' or 'DESC'. Orders in either
  10   *        ascending or descending order.
  11   * 'limit' - Default is -1 (integer) or show all. The amount of bookmarks to
  12   *        display.
  13   * 'category' - Default is empty string (string). Include the links in what
  14   *        category ID(s).
  15   * 'category_name' - Default is empty string (string). Get links by category
  16   *        name.
  17   * 'hide_invisible' - Default is 1 (integer). Whether to show (default) or hide
  18   *        links marked as 'invisible'.
  19   * 'show_updated' - Default is 0 (integer). Will show the time of when the
  20   *        bookmark was last updated.
  21   * 'echo' - Default is 1 (integer). Whether to echo (default) or return the
  22   *        formatted bookmarks.
  23   * 'categorize' - Default is 1 (integer). Whether to show links listed by
  24   *        category (default) or show links in one column.
  25   *
  26   * These options define how the Category name will appear before the category
  27   * links are displayed, if 'categorize' is 1. If 'categorize' is 0, then it will
  28   * display for only the 'title_li' string and only if 'title_li' is not empty.
  29   * 'title_li' - Default is 'Bookmarks' (translatable string). What to show
  30   *        before the links appear.
  31   * 'title_before' - Default is '<h2>' (string). The HTML or text to show before
  32   *        the 'title_li' string.
  33   * 'title_after' - Default is '</h2>' (string). The HTML or text to show after
  34   *        the 'title_li' string.
  35   * 'class' - Default is 'linkcat' (string). The CSS class to use for the
  36   *        'title_li'.
  37   *
  38   * 'category_before' - Default is '<li id="%id" class="%class">'. String must
  39   *        contain '%id' and '%class' to get
  40   * the id of the category and the 'class' argument. These are used for
  41   *        formatting in themes.
  42   * Argument will be displayed before the 'title_before' argument.
  43   * 'category_after' - Default is '</li>' (string). The HTML or text that will
  44   *        appear after the list of links.
  45   *
  46   * These are only used if 'categorize' is set to 1 or true.
  47   * 'category_orderby' - Default is 'name'. How to order the bookmark category
  48   *        based on term scheme.
  49   * 'category_order' - Default is 'ASC'. Set the order by either ASC (ascending)
  50   *        or DESC (descending).
  51   *
  52   * @see _hack_walk_bookmarks() For other arguments that can be set in this function
  53   *        and passed to _walk_bookmarks().
  54   * @see get_bookmarks() For other arguments that can be set in this function and
  55   *        passed to get_bookmarks().
  56   * @link http://codex.wordpress.org/Template_Tags/wp_list_bookmarks
  57   *
  58   * @since 2.1.0
  59   * @uses _list_bookmarks() Used to iterate over all of the bookmarks and return
  60   *        the html
  61   * @uses get_terms() Gets all of the categories that are for links.
  62   *
  63   * @param string|array $args Optional. Overwrite the defaults of the function
  64   * @return string|null Will only return if echo option is set to not echo.
  65   *        Default is not return anything.
  66   */
  67  function zelist_list_bookmarks($args = '') {
  68      $defaults = array(
  69          'orderby' => 'name', 'order' => 'ASC',
  70          'limit' => -1, 'category' => '', 'exclude_category' => '',
  71          'category_name' => '', 'hide_invisible' => 1,
  72          'show_updated' => 0, 'echo' => 1,
  73          'categorize' => 1, 'title_li' => __('Bookmarks'),
  74          'title_before' => '<h2>', 'title_after' => '</h2>',
  75          'category_orderby' => 'name', 'category_order' => 'ASC',
  76          'class' => 'linkcat', 'category_before' => '<li id="%id" class="%class">',
  77          'category_after' => '</li>', 'true_link' => 0,
  78      );
  79  
  80      $r = wp_parse_args( $args, $defaults );
  81      extract( $r, EXTR_SKIP );
  82  
  83      $output = '';
  84  
  85      if ( $categorize ) {
  86          //Split the bookmarks into ul's for each category
  87          $cats = get_terms('link_category', array('name__like' => $category_name, 'include' => $category, 'exclude' => $exclude_category, 'orderby' => $category_orderby, 'order' => $category_order, 'hierarchical' => 0));
  88  
  89          foreach ( (array) $cats as $cat ) {
  90              $params = array_merge($r, array('category'=>$cat->term_id));
  91              $bookmarks = get_bookmarks($params);
  92              if ( empty($bookmarks) )
  93                  continue;
  94              $output .= str_replace(array('%id', '%class'), array("linkcat-$cat->term_id", $class), $category_before);
  95              $catname = apply_filters( "link_category", $cat->name );
  96              $output .= "$title_before$catname$title_after\n\t<ul class='xoxo blogroll'>\n";
  97              $output .= _hack_walk_bookmarks($bookmarks, $r);
  98              $output .= "\n\t</ul>\n$category_after\n";
  99          }
 100      } else {
 101          //output one single list using title_li for the title
 102          $bookmarks = get_bookmarks($r);
 103  
 104          if ( !empty($bookmarks) ) {
 105              if ( !empty( $title_li ) ){
 106                  $output .= str_replace(array('%id', '%class'), array("linkcat-$category", $class), $category_before);
 107                  $output .= "$title_before$title_li$title_after\n\t<ul class='xoxo blogroll'>\n";
 108                  $output .= _hack_walk_bookmarks($bookmarks, $r);
 109                  $output .= "\n\t</ul>\n$category_after\n";
 110              } else {
 111                  $output .= _hack_walk_bookmarks($bookmarks, $r);
 112              }
 113          }
 114      }
 115  
 116      $output = apply_filters( 'wp_list_bookmarks', $output );
 117  
 118      if ( !$echo )
 119          return $output;
 120      echo $output;
 121  }
 122  
 123  /**
 124   * Thanks to WordPress limited usage of hooks, this function is duplicated with 2 lines changed. The formatted output of a list of bookmarks.
 125   *
 126   * The $bookmarks array must contain bookmark objects and will be iterated over
 127   * to retrieve the bookmark to be used in the output.
 128   *
 129   * The output is formatted as HTML with no way to change that format. However,
 130   * what is between, before, and after can be changed. The link itself will be
 131   * HTML.
 132   *
 133   * This function is used internally by wp_list_bookmarks() and should not be
 134   * used by themes.
 135   *
 136   * The defaults for overwriting are:
 137   * 'show_updated' - Default is 0 (integer). Will show the time of when the
 138   *        bookmark was last updated.
 139   * 'show_description' - Default is 0 (integer). Whether to show the description
 140   *        of the bookmark.
 141   * 'show_images' - Default is 1 (integer). Whether to show link image if
 142   *        available.
 143   * 'show_name' - Default is 0 (integer). Whether to show link name if
 144   *        available.
 145   * 'before' - Default is '<li>' (string). The html or text to prepend to each
 146   *        bookmarks.
 147   * 'after' - Default is '</li>' (string). The html or text to append to each
 148   *        bookmarks.
 149   * 'link_before' - Default is '' (string). The html or text to prepend to each
 150   *        bookmarks inside the <a> tag.
 151   * 'link_after' - Default is '' (string). The html or text to append to each
 152   *        bookmarks inside the <a> tag.
 153   * 'between' - Default is '\n' (string). The string for use in between the link,
 154   *        description, and image.
 155   * 'show_rating' - Default is 0 (integer). Whether to show the link rating.
 156   *
 157   * @since 2.1.0
 158   * @access private
 159   * @usedby wp_list_bookmarks()
 160   *
 161   * @param array $bookmarks List of bookmarks to traverse
 162   * @param string|array $args Optional. Overwrite the defaults.
 163   * @return string Formatted output in HTML
 164   */
 165  function _hack_walk_bookmarks($bookmarks, $args = '' ) {
 166      $defaults = array(
 167          'show_updated' => 0, 'show_description' => 0,
 168          'show_images' => 1, 'show_name' => 0,
 169          'before' => '<li>', 'after' => '</li>', 'between' => "\n",
 170          'show_rating' => 0, 'link_before' => '', 'link_after' => '',
 171          'true_link' => 0,
 172  
 173      );
 174  
 175      $r = wp_parse_args( $args, $defaults );
 176      extract( $r, EXTR_SKIP );
 177  
 178      $output = ''; // Blank string to start with.
 179  
 180      foreach ( (array) $bookmarks as $bookmark ) {
 181          if ( !isset($bookmark->recently_updated) )
 182              $bookmark->recently_updated = false;
 183          $output .= $before;
 184          if ( $show_updated && $bookmark->recently_updated )
 185              $output .= get_option('links_recently_updated_prepend');
 186  
 187          $the_link = '#';
 188          if ( $true_link && !empty($bookmark->link_url) )
 189              $the_link = clean_url($bookmark->link_url);
 190          else
 191              $the_link = get_link_permalink($bookmark->link_id);
 192          //echo "\n<br />true link $true_link : $the_link";
 193  
 194          $rel = $bookmark->link_rel;
 195          if ( '' != $rel )
 196              $rel = ' rel="' . $rel . '"';
 197  
 198          $desc = attribute_escape(sanitize_bookmark_field('link_description', $bookmark->link_description, $bookmark->link_id, 'display'));
 199          $name = attribute_escape(sanitize_bookmark_field('link_name', $bookmark->link_name, $bookmark->link_id, 'display'));
 200           $title = $desc;
 201  
 202          if ( $show_updated )
 203              if ( '00' != substr($bookmark->link_updated_f, 0, 2) ) {
 204                  $title .= ' (';
 205                  $title .= sprintf(__('Last updated: %s'), date(get_option('links_updated_date_format'), $bookmark->link_updated_f + (get_option('gmt_offset') * 3600)));
 206                  $title .= ')';
 207              }
 208  
 209          if ( '' != $title )
 210              $title = ' title="' . $title . '"';
 211  
 212          $alt = ' alt="' . $name . '"';
 213  
 214          $target = $bookmark->link_target;
 215          if ( '' != $target )
 216              $target = ' target="' . $target . '"';
 217  
 218          $output .= '<a href="' . $the_link . '"' . $rel . $title . $target. '>';
 219  
 220          $output .= $link_before;
 221  
 222          if ( $bookmark->link_image != null && $show_images ) {
 223              if ( strpos($bookmark->link_image, 'http') !== false )
 224                  $output .= "<img src=\"$bookmark->link_image\" $alt $title />";
 225              else // If it's a relative path
 226                  $output .= "<img src=\"" . get_option('siteurl') . "$bookmark->link_image\" $alt $title />";
 227  
 228              if ($show_name) $output .= $name;
 229          } else {
 230              $output .= $name;
 231          }
 232  
 233          $output .= $link_after;
 234  
 235          $output .= '</a>';
 236  
 237          if ( $show_updated && $bookmark->recently_updated )
 238              $output .= get_option('links_recently_updated_append');
 239  
 240          if ( $show_description && '' != $desc )
 241              $output .= $between . $desc;
 242  
 243          if ($show_rating) {
 244              $output .= $between . sanitize_bookmark_field('link_rating', $bookmark->link_rating, $bookmark->link_id, 'display');
 245          }
 246  
 247          $output .= "$after\n";
 248      } // end while
 249  
 250      return $output;
 251  }
 252  
 253  
 254  /**
 255   * Count number of links and is user has permissions to view.
 256   *
 257   * This function provides an efficient method of finding the amount of post's
 258   * type a blog has. Another method is to count the amount of items in
 259   * get_posts(), but that method has a lot of overhead with doing so. Therefore,
 260   * when developing for 2.5+, use this function instead.
 261   *
 262   * The $perm parameter checks for 'readable' value and if the user can read
 263   * private posts, it will display that for the user that is signed in.
 264   *
 265   * @since 2.5.0
 266   * @link http://codex.wordpress.org/Template_Tags/wp_count_posts
 267   *
 268   * @param string $type Optional. Post type to retrieve count
 269   * @param string $perm Optional. 'readable' or empty.
 270   * @return object Number of posts for each status
 271   */
 272  function wp_count_links( ) {
 273      global $wpdb;
 274      $user = wp_get_current_user();
 275      $cache_key = 'link_counts';
 276      $query = "SELECT link_status, COUNT( * ) AS num_links FROM {$wpdb->links} WHERE 1=1 ";
 277  
 278      if ( !current_user_can("manage_links") ) {
 279          $cache_key .= '_' . $user->ID;
 280          //$query .= " AND (link_status != 'private' OR ( link_owner = '$user->ID' AND link_status = 'private' ))";
 281      }
 282      $query .= ' GROUP BY link_status';
 283  
 284      $count = wp_cache_get($cache_key, 'counts');
 285      if ( false !== $count )
 286      return $count;
 287  
 288      $count = $wpdb->get_results( $wpdb->prepare( $query ), ARRAY_A );
 289  
 290      $stats = array( );
 291      $stats['total'] = 0;
 292      foreach( (array) $count as $row_num => $row ) {
 293          $stats[$row['link_status']] = $row['num_links'];
 294          $stats['total'] += $row['num_links'];
 295      }
 296  
 297      $stats['link_rss'] = $wpdb->get_var("SELECT COUNT(DISTINCT(link_id)) FROM $wpdb->links WHERE link_rss <> ''");
 298      $stats['wrong_description'] = $wpdb->get_var($wpdb->prepare("SELECT COUNT(DISTINCT(link_id)) FROM $wpdb->links WHERE LENGTH(link_description) < %s OR LENGTH(link_description) > %s",get_option('zelist_description_min_length'),get_option('zelist_description_max_length')));
 299  
 300      $stats = (object) $stats;
 301      wp_cache_set($cache_key, $stats, 'counts');
 302      return $stats;
 303  }
 304  
 305  /**
 306   * Retrieves all link tags.
 307   *
 308   * @since 2.3.0
 309   * @see get_terms() For list of arguments to pass.
 310   * @uses apply_filters() Calls 'get_tags' hook on array of tags and with $args.
 311   *
 312   * @param string|array $args Tag arguments to use when retrieving tags.
 313   * @return array List of tags.
 314   */
 315  function &get_links_tags( $args = '' ) {
 316      $tags = get_terms( 'link_tag', $args );
 317  
 318      if ( empty( $tags ) ) {
 319          $return = array();
 320          return $return;
 321      }
 322  
 323      $tags = apply_filters( 'get_links_tags', $tags, $args );
 324      return $tags;
 325  }
 326  
 327   /**
 328   * {@internal Missing Short Description}}
 329   *
 330   * @since unknown
 331   *
 332   * @param unknown_type $q
 333   * @return unknown
 334   */
 335  function wp_edit_links_query( $q = false ) {
 336      if ( false === $q )
 337      $q = $_GET;
 338      $q['m']   = isset($q['m']) ? (int) $q['m'] : 0;
 339      $q['cat'] = isset($q['cat']) ? (int) $q['cat'] : 0;
 340      $link_stati  = array(    //    array( adj, noun )
 341      'publish' => array(__('Published'), __('Published links'), __ngettext_noop('Published <span class="count">(%s)</span>', 'Published <span class="count">(%s)</span>')),
 342      'deny' => array(__('Denied'), __('Denied links'), __ngettext_noop('Denied <span class="count">(%s)</span>', 'Denied <span class="count">(%s)</span>',1,'zelist')),
 343      'pending' => array(__('Pending Review'), __('Pending links'), __ngettext_noop('Pending Validation <span class="count">(%s)</span>', 'Pending Review <span class="count">(%s)</span>')),
 344      'dead' => array(__('Dead','zelist'), __('Dead','zelist'), __ngettext_noop('Dead <span class="count">(%s)</span>', 'Dead <span class="count">(%s)</span>',1,'zelist')),
 345      );
 346  
 347      $link_stati = apply_filters('link_stati', $link_stati);
 348      $avail_link_stati = get_available_link_statuses('link');
 349  
 350      $link_status_q = '';
 351      if ( isset($q['link_status']) && in_array( $q['link_status'], array_keys($link_stati) ) ) {
 352          $link_status_q = '&link_status=' . $q['link_status'];
 353          $link_status_q .= '&perm=readable';
 354      }
 355  
 356      if ( isset($q['link_status']) && 'pending' === $q['link_status'] ) {
 357          $order = 'ASC';
 358          $orderby = 'modified';
 359      } elseif ( isset($q['link_status']) && 'draft' === $q['link_status'] ) {
 360          $order = 'DESC';
 361          $orderby = 'modified';
 362      } else {
 363          $order = 'DESC';
 364          $orderby = 'date';
 365      }
 366      return array($link_stati, $avail_link_stati);
 367  }
 368  
 369  /**
 370   * Returns availables ( = with 1 link or more) statuses for links
 371   *
 372   * @since unknown
 373   *
 374   * @param unknown_type $type
 375   * @return unknown
 376   */
 377  function get_available_link_statuses($type = 'link') {
 378      $stati = wp_count_links($type);
 379      return array_keys(get_object_vars($stati));
 380  }
 381  
 382  /*
 383  
 384   function the_link_category($separator = '' ,$parents = '', $link_id = false) {
 385   return get_the_link_category_list($separator,$parents, $link_id);
 386   }
 387  
 388   function wp_create_link_tag($tag_name) {
 389   if($id = link_tag_exists($tag_name))
 390   return $id;
 391   return wp_insert_term($tag_name,'link_tag');
 392   }
 393  */
 394  
 395  
 396  /**
 397   * Display or retrieve page title for link_tag post archive.
 398   *
 399   * Useful for link_tag template files for displaying the link_tag page title. It has less
 400   * overhead than {@link wp_title()}, because of its limited implementation.
 401   *
 402   * It does not support placing the separator after the title, but by leaving the
 403   * prefix parameter empty, you can set the title separator manually. The prefix
 404   * does not automatically place a space between the prefix, so if there should
 405   * be a space, the parameter value will need to have it at the end.
 406   *
 407   * @since 2.3.0
 408   *
 409   * @param string $prefix Optional. What to display before the title.
 410   * @param bool $display Optional, default is true. Whether to display or retrieve title.
 411   * @return string|null Title when retrieving, null when displaying or failure.
 412   */
 413  function single_link_tag_title($prefix = '', $display = true ) {
 414      if ( !is_link_tag() )
 415          return;
 416  
 417      $link_tag_id = intval( get_zelist_query_var('link_tag_id') );
 418  
 419      if ( !empty($link_tag_id) ) {
 420          $my_link_tag = &get_term($link_tag_id, 'link_tag', OBJECT, 'display');
 421          if ( is_wp_error( $my_link_tag ) )
 422              return false;
 423          $my_link_tag_name = apply_filters('single_link_tag_title', $my_link_tag->name);
 424          if ( !empty($my_link_tag_name) ) {
 425              if ( $display )
 426                  echo $prefix . $my_link_tag_name;
 427              else
 428                  return $my_link_tag_name;
 429          }
 430      }
 431  }
 432  
 433  /**
 434   * {@internal Missing Short Description}}
 435   *
 436   * @since unknown
 437   *
 438   * @param unknown_type $cat_name
 439   * @return unknown
 440   */
 441  function link_category_exists($cat_name) {
 442      $id = is_term($cat_name, 'link_category');
 443      if ( is_array($id) )
 444          $id = $id['term_id'];
 445      return $id;
 446  }
 447  


Generated: Sat May 30 23:51:06 2009 Cross-referenced by PHPXref 0.7