root/trunk/wp-includes/bookmark-template.php

Revision 8742, 8.7 kB (checked in by westi, 1 week ago)

phpDoc corrections for wp-includes. See #7550 props santosj.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 <?php
2 /**
3  * Bookmark Template Functions for usage in Themes
4  *
5  * @package WordPress
6  * @subpackage Template
7  */
8
9 /**
10  * The formatted output of a list of bookmarks.
11  *
12  * The $bookmarks array must contain bookmark objects and will be iterated over
13  * to retrieve the bookmark to be used in the output.
14  *
15  * The output is formatted as HTML with no way to change that format. However,
16  * what is between, before, and after can be changed. The link itself will be
17  * HTML.
18  *
19  * This function is used internally by wp_list_bookmarks() and should not be
20  * used by themes.
21  *
22  * The defaults for overwriting are:
23  * 'show_updated' - Default is 0 (integer). Will show the time of when the
24  *        bookmark was last updated.
25  * 'show_description' - Default is 0 (integer). Whether to show the description
26  *        of the bookmark.
27  * 'show_images' - Default is 1 (integer). Whether to show link image if
28  *        available.
29  * 'before' - Default is '<li>' (string). The html or text to prepend to each
30  *        bookmarks.
31  * 'after' - Default is '</li>' (string). The html or text to append to each
32  *        bookmarks.
33  * 'between' - Default is '\n' (string). The string for use in between the link,
34  *        description, and image.
35  * 'show_rating' - Default is 0 (integer). Whether to show the link rating.
36  *
37  * @since 2.1.0
38  * @access private
39  * @usedby wp_list_bookmarks()
40  *
41  * @param array $bookmarks List of bookmarks to traverse
42  * @param string|array $args Optional. Overwrite the defaults.
43  * @return string Formatted output in HTML
44  */
45 function _walk_bookmarks($bookmarks, $args = '' ) {
46     $defaults = array(
47         'show_updated' => 0, 'show_description' => 0,
48         'show_images' => 1, 'before' => '<li>',
49         'after' => '</li>', 'between' => "\n",
50         'show_rating' => 0
51     );
52
53     $r = wp_parse_args( $args, $defaults );
54     extract( $r, EXTR_SKIP );
55
56     $output = ''; // Blank string to start with.
57
58     foreach ( (array) $bookmarks as $bookmark ) {
59         if ( !isset($bookmark->recently_updated) )
60             $bookmark->recently_updated = false;
61         $output .= $before;
62         if ( $show_updated && $bookmark->recently_updated )
63             $output .= get_option('links_recently_updated_prepend');
64
65         $the_link = '#';
66         if ( !empty($bookmark->link_url) )
67             $the_link = clean_url($bookmark->link_url);
68
69         $rel = $bookmark->link_rel;
70         if ( '' != $rel )
71             $rel = ' rel="' . $rel . '"';
72
73         $desc = attribute_escape(sanitize_bookmark_field('link_description', $bookmark->link_description, $bookmark->link_id, 'display'));
74         $name = attribute_escape(sanitize_bookmark_field('link_name', $bookmark->link_name, $bookmark->link_id, 'display'));
75          $title = $desc;
76
77         if ( $show_updated )
78             if ( '00' != substr($bookmark->link_updated_f, 0, 2) ) {
79                 $title .= ' (';
80                 $title .= sprintf(__('Last updated: %s'), date(get_option('links_updated_date_format'), $bookmark->link_updated_f + (get_option('gmt_offset') * 3600)));
81                 $title .= ')';
82             }
83
84         if ( '' != $title )
85             $title = ' title="' . $title . '"';
86
87         $alt = ' alt="' . $name . '"';
88
89         $target = $bookmark->link_target;
90         if ( '' != $target )
91             $target = ' target="' . $target . '"';
92
93         $output .= '<a href="' . $the_link . '"' . $rel . $title . $target. '>';
94
95         if ( $bookmark->link_image != null && $show_images ) {
96             if ( strpos($bookmark->link_image, 'http') !== false )
97                 $output .= "<img src=\"$bookmark->link_image\" $alt $title />";
98             else // If it's a relative path
99                 $output .= "<img src=\"" . get_option('siteurl') . "$bookmark->link_image\" $alt $title />";
100         } else {
101             $output .= $name;
102         }
103
104         $output .= '</a>';
105
106         if ( $show_updated && $bookmark->recently_updated )
107             $output .= get_option('links_recently_updated_append');
108
109         if ( $show_description && '' != $desc )
110             $output .= $between . $desc;
111
112         if ($show_rating) {
113             $output .= $between . get_linkrating($bookmark);
114         }
115
116         $output .= "$after\n";
117     } // end while
118
119     return $output;
120 }
121
122 /**
123  * Retrieve or echo all of the bookmarks.
124  *
125  * List of default arguments are as follows:
126  * 'orderby' - Default is 'name' (string). How to order the links by. String is
127  *        based off of the bookmark scheme.
128  * 'order' - Default is 'ASC' (string). Either 'ASC' or 'DESC'. Orders in either
129  *        ascending or descending order.
130  * 'limit' - Default is -1 (integer) or show all. The amount of bookmarks to
131  *        display.
132  * 'category' - Default is empty string (string). Include the links in what
133  *        category ID(s).
134  * 'category_name' - Default is empty string (string). Get links by category
135  *        name.
136  * 'hide_invisible' - Default is 1 (integer). Whether to show (default) or hide
137  *        links marked as 'invisible'.
138  * 'show_updated' - Default is 0 (integer). Will show the time of when the
139  *        bookmark was last updated.
140  * 'echo' - Default is 1 (integer). Whether to echo (default) or return the
141  *        formatted bookmarks.
142  * 'categorize' - Default is 1 (integer). Whether to show links listed by
143  *        category (default) or show links in one column.
144  *
145  * These options define how the Category name will appear before the category
146  * links are displayed, if 'categorize' is 1. If 'categorize' is 0, then it will
147  * display for only the 'title_li' string and only if 'title_li' is not empty.
148  * 'title_li' - Default is 'Bookmarks' (translatable string). What to show
149  *        before the links appear.
150  * 'title_before' - Default is '<h2>' (string). The HTML or text to show before
151  *        the 'title_li' string.
152  * 'title_after' - Default is '</h2>' (string). The HTML or text to show after
153  *        the 'title_li' string.
154  * 'class' - Default is 'linkcat' (string). The CSS class to use for the
155  *        'title_li'.
156  *
157  * 'category_before' - Default is '<li id="%id" class="%class">'. String must
158  *        contain '%id' and '%class' to get
159  * the id of the category and the 'class' argument. These are used for
160  *        formatting in themes.
161  * Argument will be displayed before the 'title_before' argument.
162  * 'category_after' - Default is '</li>' (string). The HTML or text that will
163  *        appear after the list of links.
164  *
165  * These are only used if 'categorize' is set to 1 or true.
166  * 'category_orderby' - Default is 'name'. How to order the bookmark category
167  *        based on term scheme.
168  * 'category_order' - Default is 'ASC'. Set the order by either ASC (ascending)
169  *        or DESC (descending).
170  *
171  * @see _walk_bookmarks() For other arguments that can be set in this function
172  *        and passed to _walk_bookmarks().
173  * @see get_bookmarks() For other arguments that can be set in this function and
174  *        passed to get_bookmarks().
175  * @link http://codex.wordpress.org/Template_Tags/wp_list_bookmarks
176  *
177  * @since 2.1.0
178  * @uses _list_bookmarks() Used to iterate over all of the bookmarks and return
179  *        the html
180  * @uses get_terms() Gets all of the categories that are for links.
181  *
182  * @param string|array $args Optional. Overwrite the defaults of the function
183  * @return string|null Will only return if echo option is set to not echo.
184  *        Default is not return anything.
185  */
186 function wp_list_bookmarks($args = '') {
187     $defaults = array(
188         'orderby' => 'name', 'order' => 'ASC',
189         'limit' => -1, 'category' => '', 'exclude_category' => '',
190         'category_name' => '', 'hide_invisible' => 1,
191         'show_updated' => 0, 'echo' => 1,
192         'categorize' => 1, 'title_li' => __('Bookmarks'),
193         'title_before' => '<h2>', 'title_after' => '</h2>',
194         'category_orderby' => 'name', 'category_order' => 'ASC',
195         'class' => 'linkcat', 'category_before' => '<li id="%id" class="%class">',
196         'category_after' => '</li>'
197     );
198
199     $r = wp_parse_args( $args, $defaults );
200     extract( $r, EXTR_SKIP );
201
202     $output = '';
203
204     if ( $categorize ) {
205         //Split the bookmarks into ul's for each category
206         $cats = get_terms('link_category', array('name__like' => $category_name, 'include' => $category, 'exclude' => $exclude_category, 'orderby' => $category_orderby, 'order' => $category_order, 'hierarchical' => 0));
207
208         foreach ( (array) $cats as $cat ) {
209             $params = array_merge($r, array('category'=>$cat->term_id));
210             $bookmarks = get_bookmarks($params);
211             if ( empty($bookmarks) )
212                 continue;
213             $output .= str_replace(array('%id', '%class'), array("linkcat-$cat->term_id", $class), $category_before);
214             $catname = apply_filters( "link_category", $cat->name );
215             $output .= "$title_before$catname$title_after\n\t<ul class='xoxo blogroll'>\n";
216             $output .= _walk_bookmarks($bookmarks, $r);
217             $output .= "\n\t</ul>\n$category_after\n";
218         }
219     } else {
220         //output one single list using title_li for the title
221         $bookmarks = get_bookmarks($r);
222
223         if ( !empty($bookmarks) ) {
224             if ( !empty( $title_li ) ){
225                 $output .= str_replace(array('%id', '%class'), array("linkcat-$category", $class), $category_before);
226                 $output .= "$title_before$title_li$title_after\n\t<ul class='xoxo blogroll'>\n";
227                 $output .= _walk_bookmarks($bookmarks, $r);
228                 $output .= "\n\t</ul>\n$category_after\n";
229             } else {
230                 $output .= _walk_bookmarks($bookmarks, $r);
231             }
232         }
233     }
234
235     $output = apply_filters( 'wp_list_bookmarks', $output );
236
237     if ( !$echo )
238         return $output;
239     echo $output;
240 }
241
242 ?>
Note: See TracBrowser for help on using the browser.