17 * HTML. |
17 * HTML. |
18 * |
18 * |
19 * This function is used internally by wp_list_bookmarks() and should not be |
19 * This function is used internally by wp_list_bookmarks() and should not be |
20 * used by themes. |
20 * used by themes. |
21 * |
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 * 'show_name' - Default is 0 (integer). Whether to show link name if |
|
30 * available. |
|
31 * 'before' - Default is '<li>' (string). The html or text to prepend to each |
|
32 * bookmarks. |
|
33 * 'after' - Default is '</li>' (string). The html or text to append to each |
|
34 * bookmarks. |
|
35 * 'link_before' - Default is '' (string). The html or text to prepend to each |
|
36 * bookmarks inside the <a> tag. |
|
37 * 'link_after' - Default is '' (string). The html or text to append to each |
|
38 * bookmarks inside the <a> tag. |
|
39 * 'between' - Default is '\n' (string). The string for use in between the link, |
|
40 * description, and image. |
|
41 * 'show_rating' - Default is 0 (integer). Whether to show the link rating. |
|
42 * |
|
43 * @since 2.1.0 |
22 * @since 2.1.0 |
44 * @access private |
23 * @access private |
45 * |
24 * |
46 * @param array $bookmarks List of bookmarks to traverse |
25 * @param array $bookmarks List of bookmarks to traverse. |
47 * @param string|array $args Optional. Overwrite the defaults. |
26 * @param string|array $args { |
|
27 * Optional. Bookmarks arguments. |
|
28 * |
|
29 * @type int|bool $show_updated Whether to show the time the bookmark was last updated. |
|
30 * Accepts 1|true or 0|false. Default 0|false. |
|
31 * @type int|bool $show_description Whether to show the bookmakr description. Accepts 1|true, |
|
32 * Accepts 1|true or 0|false. Default 0|false. |
|
33 * @type int|bool $show_images Whether to show the link image if available. Accepts 1|true |
|
34 * or 0|false. Default 1|true. |
|
35 * @type int|bool $show_name Whether to show link name if available. Accepts 1|true or |
|
36 * 0|false. Default 0|false. |
|
37 * @type string $before The HTML or text to prepend to each bookmark. Default `<li>`. |
|
38 * @type string $after The HTML or text to append to each bookmark. Default `</li>`. |
|
39 * @type string $link_before The HTML or text to prepend to each bookmark inside the anchor |
|
40 * tags. Default empty. |
|
41 * @type string $link_after The HTML or text to append to each bookmark inside the anchor |
|
42 * tags. Default empty. |
|
43 * @type string $between The string for use in between the link, description, and image. |
|
44 * Default "\n". |
|
45 * @type int|bool $show_rating Whether to show the link rating. Accepts 1|true or 0|false. |
|
46 * Default 0|false. |
|
47 * |
|
48 * } |
48 * @return string Formatted output in HTML |
49 * @return string Formatted output in HTML |
49 */ |
50 */ |
50 function _walk_bookmarks($bookmarks, $args = '' ) { |
51 function _walk_bookmarks( $bookmarks, $args = '' ) { |
51 $defaults = array( |
52 $defaults = array( |
52 'show_updated' => 0, 'show_description' => 0, |
53 'show_updated' => 0, 'show_description' => 0, |
53 'show_images' => 1, 'show_name' => 0, |
54 'show_images' => 1, 'show_name' => 0, |
54 'before' => '<li>', 'after' => '</li>', 'between' => "\n", |
55 'before' => '<li>', 'after' => '</li>', 'between' => "\n", |
55 'show_rating' => 0, 'link_before' => '', 'link_after' => '' |
56 'show_rating' => 0, 'link_before' => '', 'link_after' => '' |
56 ); |
57 ); |
57 |
58 |
58 $r = wp_parse_args( $args, $defaults ); |
59 $r = wp_parse_args( $args, $defaults ); |
59 extract( $r, EXTR_SKIP ); |
|
60 |
60 |
61 $output = ''; // Blank string to start with. |
61 $output = ''; // Blank string to start with. |
62 |
62 |
63 foreach ( (array) $bookmarks as $bookmark ) { |
63 foreach ( (array) $bookmarks as $bookmark ) { |
64 if ( !isset($bookmark->recently_updated) ) |
64 if ( ! isset( $bookmark->recently_updated ) ) { |
65 $bookmark->recently_updated = false; |
65 $bookmark->recently_updated = false; |
66 $output .= $before; |
66 } |
67 if ( $show_updated && $bookmark->recently_updated ) |
67 $output .= $r['before']; |
68 $output .= get_option('links_recently_updated_prepend'); |
68 if ( $r['show_updated'] && $bookmark->recently_updated ) { |
69 |
69 $output .= '<em>'; |
|
70 } |
70 $the_link = '#'; |
71 $the_link = '#'; |
71 if ( !empty($bookmark->link_url) ) |
72 if ( ! empty( $bookmark->link_url ) ) { |
72 $the_link = esc_url($bookmark->link_url); |
73 $the_link = esc_url( $bookmark->link_url ); |
73 |
74 } |
74 $desc = esc_attr(sanitize_bookmark_field('link_description', $bookmark->link_description, $bookmark->link_id, 'display')); |
75 $desc = esc_attr( sanitize_bookmark_field( 'link_description', $bookmark->link_description, $bookmark->link_id, 'display' ) ); |
75 $name = esc_attr(sanitize_bookmark_field('link_name', $bookmark->link_name, $bookmark->link_id, 'display')); |
76 $name = esc_attr( sanitize_bookmark_field( 'link_name', $bookmark->link_name, $bookmark->link_id, 'display' ) ); |
76 $title = $desc; |
77 $title = $desc; |
77 |
78 |
78 if ( $show_updated ) |
79 if ( $r['show_updated'] ) { |
79 if ( '00' != substr($bookmark->link_updated_f, 0, 2) ) { |
80 if ( '00' != substr( $bookmark->link_updated_f, 0, 2 ) ) { |
80 $title .= ' ('; |
81 $title .= ' ('; |
81 $title .= sprintf(__('Last updated: %s'), date(get_option('links_updated_date_format'), $bookmark->link_updated_f + (get_option('gmt_offset') * HOUR_IN_SECONDS))); |
82 $title .= sprintf( |
|
83 __('Last updated: %s'), |
|
84 date( |
|
85 get_option( 'links_updated_date_format' ), |
|
86 $bookmark->link_updated_f + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) |
|
87 ) |
|
88 ); |
82 $title .= ')'; |
89 $title .= ')'; |
83 } |
90 } |
84 |
91 } |
85 $alt = ' alt="' . $name . ( $show_description ? ' ' . $title : '' ) . '"'; |
92 $alt = ' alt="' . $name . ( $r['show_description'] ? ' ' . $title : '' ) . '"'; |
86 |
93 |
87 if ( '' != $title ) |
94 if ( '' != $title ) { |
88 $title = ' title="' . $title . '"'; |
95 $title = ' title="' . $title . '"'; |
89 |
96 } |
90 $rel = $bookmark->link_rel; |
97 $rel = $bookmark->link_rel; |
91 if ( '' != $rel ) |
98 if ( '' != $rel ) { |
92 $rel = ' rel="' . esc_attr($rel) . '"'; |
99 $rel = ' rel="' . esc_attr($rel) . '"'; |
93 |
100 } |
94 $target = $bookmark->link_target; |
101 $target = $bookmark->link_target; |
95 if ( '' != $target ) |
102 if ( '' != $target ) { |
96 $target = ' target="' . $target . '"'; |
103 $target = ' target="' . $target . '"'; |
97 |
104 } |
98 $output .= '<a href="' . $the_link . '"' . $rel . $title . $target . '>'; |
105 $output .= '<a href="' . $the_link . '"' . $rel . $title . $target . '>'; |
99 |
106 |
100 $output .= $link_before; |
107 $output .= $r['link_before']; |
101 |
108 |
102 if ( $bookmark->link_image != null && $show_images ) { |
109 if ( $bookmark->link_image != null && $r['show_images'] ) { |
103 if ( strpos($bookmark->link_image, 'http') === 0 ) |
110 if ( strpos( $bookmark->link_image, 'http' ) === 0 ) { |
104 $output .= "<img src=\"$bookmark->link_image\" $alt $title />"; |
111 $output .= "<img src=\"$bookmark->link_image\" $alt $title />"; |
105 else // If it's a relative path |
112 } else { // If it's a relative path |
106 $output .= "<img src=\"" . get_option('siteurl') . "$bookmark->link_image\" $alt $title />"; |
113 $output .= "<img src=\"" . get_option('siteurl') . "$bookmark->link_image\" $alt $title />"; |
107 |
114 } |
108 if ( $show_name ) |
115 if ( $r['show_name'] ) { |
109 $output .= " $name"; |
116 $output .= " $name"; |
|
117 } |
110 } else { |
118 } else { |
111 $output .= $name; |
119 $output .= $name; |
112 } |
120 } |
113 |
121 |
114 $output .= $link_after; |
122 $output .= $r['link_after']; |
115 |
123 |
116 $output .= '</a>'; |
124 $output .= '</a>'; |
117 |
125 |
118 if ( $show_updated && $bookmark->recently_updated ) |
126 if ( $r['show_updated'] && $bookmark->recently_updated ) { |
119 $output .= get_option('links_recently_updated_append'); |
127 $output .= '</em>'; |
120 |
128 } |
121 if ( $show_description && '' != $desc ) |
129 |
122 $output .= $between . $desc; |
130 if ( $r['show_description'] && '' != $desc ) { |
123 |
131 $output .= $r['between'] . $desc; |
124 if ( $show_rating ) |
132 } |
125 $output .= $between . sanitize_bookmark_field('link_rating', $bookmark->link_rating, $bookmark->link_id, 'display'); |
133 |
126 |
134 if ( $r['show_rating'] ) { |
127 $output .= "$after\n"; |
135 $output .= $r['between'] . sanitize_bookmark_field( |
|
136 'link_rating', |
|
137 $bookmark->link_rating, |
|
138 $bookmark->link_id, |
|
139 'display' |
|
140 ); |
|
141 } |
|
142 $output .= $r['after'] . "\n"; |
128 } // end while |
143 } // end while |
129 |
144 |
130 return $output; |
145 return $output; |
131 } |
146 } |
132 |
147 |
133 /** |
148 /** |
134 * Retrieve or echo all of the bookmarks. |
149 * Retrieve or echo all of the bookmarks. |
135 * |
150 * |
136 * List of default arguments are as follows: |
151 * List of default arguments are as follows: |
137 * 'orderby' - Default is 'name' (string). How to order the links by. String is |
|
138 * based off of the bookmark scheme. |
|
139 * 'order' - Default is 'ASC' (string). Either 'ASC' or 'DESC'. Orders in either |
|
140 * ascending or descending order. |
|
141 * 'limit' - Default is -1 (integer) or show all. The amount of bookmarks to |
|
142 * display. |
|
143 * 'category' - Default is empty string (string). Include the links in what |
|
144 * category ID(s). |
|
145 * 'category_name' - Default is empty string (string). Get links by category |
|
146 * name. |
|
147 * 'hide_invisible' - Default is 1 (integer). Whether to show (default) or hide |
|
148 * links marked as 'invisible'. |
|
149 * 'show_updated' - Default is 0 (integer). Will show the time of when the |
|
150 * bookmark was last updated. |
|
151 * 'echo' - Default is 1 (integer). Whether to echo (default) or return the |
|
152 * formatted bookmarks. |
|
153 * 'categorize' - Default is 1 (integer). Whether to show links listed by |
|
154 * category (default) or show links in one column. |
|
155 * 'show_description' - Default is 0 (integer). Whether to show the description |
|
156 * of the bookmark. |
|
157 * |
152 * |
158 * These options define how the Category name will appear before the category |
153 * These options define how the Category name will appear before the category |
159 * links are displayed, if 'categorize' is 1. If 'categorize' is 0, then it will |
154 * links are displayed, if 'categorize' is 1. If 'categorize' is 0, then it will |
160 * display for only the 'title_li' string and only if 'title_li' is not empty. |
155 * display for only the 'title_li' string and only if 'title_li' is not empty. |
161 * 'title_li' - Default is 'Bookmarks' (translatable string). What to show |
|
162 * before the links appear. |
|
163 * 'title_before' - Default is '<h2>' (string). The HTML or text to show before |
|
164 * the 'title_li' string. |
|
165 * 'title_after' - Default is '</h2>' (string). The HTML or text to show after |
|
166 * the 'title_li' string. |
|
167 * 'class' - Default is 'linkcat' (string). The CSS class to use for the |
|
168 * 'title_li'. |
|
169 * |
|
170 * 'category_before' - Default is '<li id="%id" class="%class">'. String must |
|
171 * contain '%id' and '%class' to get |
|
172 * the id of the category and the 'class' argument. These are used for |
|
173 * formatting in themes. |
|
174 * Argument will be displayed before the 'title_before' argument. |
|
175 * 'category_after' - Default is '</li>' (string). The HTML or text that will |
|
176 * appear after the list of links. |
|
177 * |
|
178 * These are only used if 'categorize' is set to 1 or true. |
|
179 * 'category_orderby' - Default is 'name'. How to order the bookmark category |
|
180 * based on term scheme. |
|
181 * 'category_order' - Default is 'ASC'. Set the order by either ASC (ascending) |
|
182 * or DESC (descending). |
|
183 * |
|
184 * @see _walk_bookmarks() For other arguments that can be set in this function |
|
185 * and passed to _walk_bookmarks(). |
|
186 * @see get_bookmarks() For other arguments that can be set in this function and |
|
187 * passed to get_bookmarks(). |
|
188 * @link http://codex.wordpress.org/Template_Tags/wp_list_bookmarks |
|
189 * |
156 * |
190 * @since 2.1.0 |
157 * @since 2.1.0 |
191 * @uses _walk_bookmarks() Used to iterate over all of the bookmarks and return |
158 * |
192 * the html |
159 * @see _walk_bookmarks() |
193 * @uses get_terms() Gets all of the categories that are for links. |
160 * |
194 * |
161 * @param string|array $args { |
195 * @param string|array $args Optional. Overwrite the defaults of the function |
162 * Optional. String or array of arguments to list bookmarks. |
196 * @return string|null Will only return if echo option is set to not echo. |
163 * |
197 * Default is not return anything. |
164 * @type string $orderby How to order the links by. Accepts post fields. Default 'name'. |
|
165 * @type string $order Whether to order bookmarks in ascending or descending order. |
|
166 * Accepts 'ASC' (ascending) or 'DESC' (descending). Default 'ASC'. |
|
167 * @type int $limit Amount of bookmarks to display. Accepts 1+ or -1 for all. |
|
168 * Default -1. |
|
169 * @type string $category Comma-separated list of category ids to include links from. |
|
170 * Default empty. |
|
171 * @type string $category_name Category to retrieve links for by name. Default empty. |
|
172 * @type int|bool $hide_invisible Whether to show or hide links marked as 'invisible'. Accepts |
|
173 * 1|true or 0|false. Default 1|true. |
|
174 * @type int|bool $show_updated Whether to display the time the bookmark was last updated. |
|
175 * Accepts 1|true or 0|false. Default 0|false. |
|
176 * @type int|bool $echo Whether to echo or return the formatted bookmarks. Accepts |
|
177 * 1|true (echo) or 0|false (return). Default 1|true. |
|
178 * @type int|bool $categorize Whether to show links listed by category or in a single column. |
|
179 * Accepts 1|true (by category) or 0|false (one column). Default 1|true. |
|
180 * @type int|bool $show_description Whether to show the bookmark descriptions. Accepts 1|true or 0|false. |
|
181 * Default 0|false. |
|
182 * @type string $title_li What to show before the links appear. Default 'Bookmarks'. |
|
183 * @type string $title_before The HTML or text to prepend to the $title_li string. Default '<h2>'. |
|
184 * @type string $title_after The HTML or text to append to the $title_li string. Default '</h2>'. |
|
185 * @type string $class The CSS class to use for the $title_li. Default 'linkcat'. |
|
186 * @type string $category_before The HTML or text to prepend to $title_before if $categorize is true. |
|
187 * String must contain '%id' and '%class' to inherit the category ID and |
|
188 * the $class argument used for formatting in themes. |
|
189 * Default '<li id="%id" class="%class">'. |
|
190 * @type string $category_after The HTML or text to append to $title_after if $categorize is true. |
|
191 * Default '</li>'. |
|
192 * @type string $category_orderby How to order the bookmark category based on term scheme if $categorize |
|
193 * is true. Default 'name'. |
|
194 * @type string $category_order Whether to order categories in ascending or descending order if |
|
195 * $categorize is true. Accepts 'ASC' (ascending) or 'DESC' (descending). |
|
196 * Default 'ASC'. |
|
197 * } |
|
198 * @return string|null Will only return if echo option is set to not echo. Default is not return anything. |
198 */ |
199 */ |
199 function wp_list_bookmarks($args = '') { |
200 function wp_list_bookmarks( $args = '' ) { |
200 $defaults = array( |
201 $defaults = array( |
201 'orderby' => 'name', 'order' => 'ASC', |
202 'orderby' => 'name', 'order' => 'ASC', |
202 'limit' => -1, 'category' => '', 'exclude_category' => '', |
203 'limit' => -1, 'category' => '', 'exclude_category' => '', |
203 'category_name' => '', 'hide_invisible' => 1, |
204 'category_name' => '', 'hide_invisible' => 1, |
204 'show_updated' => 0, 'echo' => 1, |
205 'show_updated' => 0, 'echo' => 1, |
208 'class' => 'linkcat', 'category_before' => '<li id="%id" class="%class">', |
209 'class' => 'linkcat', 'category_before' => '<li id="%id" class="%class">', |
209 'category_after' => '</li>' |
210 'category_after' => '</li>' |
210 ); |
211 ); |
211 |
212 |
212 $r = wp_parse_args( $args, $defaults ); |
213 $r = wp_parse_args( $args, $defaults ); |
213 extract( $r, EXTR_SKIP ); |
|
214 |
214 |
215 $output = ''; |
215 $output = ''; |
216 |
216 |
217 if ( $categorize ) { |
217 if ( $r['categorize'] ) { |
218 $cats = get_terms( 'link_category', array( 'name__like' => $category_name, 'include' => $category, 'exclude' => $exclude_category, 'orderby' => $category_orderby, 'order' => $category_order, 'hierarchical' => 0 ) ); |
218 $cats = get_terms( 'link_category', array( |
219 if ( empty( $cats ) ) |
219 'name__like' => $r['category_name'], |
220 $categorize = false; |
220 'include' => $r['category'], |
|
221 'exclude' => $r['exclude_category'], |
|
222 'orderby' => $r['category_orderby'], |
|
223 'order' => $r['category_order'], |
|
224 'hierarchical' => 0 |
|
225 ) ); |
|
226 if ( empty( $cats ) ) { |
|
227 $r['categorize'] = false; |
|
228 } |
221 } |
229 } |
222 |
230 |
223 if ( $categorize ) { |
231 if ( $r['categorize'] ) { |
224 // Split the bookmarks into ul's for each category |
232 // Split the bookmarks into ul's for each category |
225 foreach ( (array) $cats as $cat ) { |
233 foreach ( (array) $cats as $cat ) { |
226 $params = array_merge($r, array('category'=>$cat->term_id)); |
234 $params = array_merge( $r, array( 'category' => $cat->term_id ) ); |
227 $bookmarks = get_bookmarks($params); |
235 $bookmarks = get_bookmarks( $params ); |
228 if ( empty($bookmarks) ) |
236 if ( empty( $bookmarks ) ) { |
229 continue; |
237 continue; |
230 $output .= str_replace(array('%id', '%class'), array("linkcat-$cat->term_id", $class), $category_before); |
238 } |
|
239 $output .= str_replace( |
|
240 array( '%id', '%class' ), |
|
241 array( "linkcat-$cat->term_id", $r['class'] ), |
|
242 $r['category_before'] |
|
243 ); |
231 /** |
244 /** |
232 * Filter the bookmarks category name. |
245 * Filter the bookmarks category name. |
233 * |
246 * |
234 * @since 2.2.0 |
247 * @since 2.2.0 |
235 * |
248 * |
236 * @param string $cat->name The category name of bookmarks. |
249 * @param string $cat_name The category name of bookmarks. |
237 */ |
250 */ |
238 $catname = apply_filters( 'link_category', $cat->name ); |
251 $catname = apply_filters( 'link_category', $cat->name ); |
239 |
252 |
240 $output .= "$title_before$catname$title_after\n\t<ul class='xoxo blogroll'>\n"; |
253 $output .= $r['title_before']; |
241 $output .= _walk_bookmarks($bookmarks, $r); |
254 $output .= $catname; |
242 $output .= "\n\t</ul>\n$category_after\n"; |
255 $output .= $r['title_after']; |
|
256 $output .= "\n\t<ul class='xoxo blogroll'>\n"; |
|
257 $output .= _walk_bookmarks( $bookmarks, $r ); |
|
258 $output .= "\n\t</ul>\n"; |
|
259 $output .= $r['category_after'] . "\n"; |
243 } |
260 } |
244 } else { |
261 } else { |
245 //output one single list using title_li for the title |
262 //output one single list using title_li for the title |
246 $bookmarks = get_bookmarks($r); |
263 $bookmarks = get_bookmarks( $r ); |
247 |
264 |
248 if ( !empty($bookmarks) ) { |
265 if ( ! empty( $bookmarks ) ) { |
249 if ( !empty( $title_li ) ){ |
266 if ( ! empty( $r['title_li'] ) ) { |
250 $output .= str_replace(array('%id', '%class'), array("linkcat-$category", $class), $category_before); |
267 $output .= str_replace( |
251 $output .= "$title_before$title_li$title_after\n\t<ul class='xoxo blogroll'>\n"; |
268 array( '%id', '%class' ), |
252 $output .= _walk_bookmarks($bookmarks, $r); |
269 array( "linkcat-" . $r['category'], $r['class'] ), |
253 $output .= "\n\t</ul>\n$category_after\n"; |
270 $r['category_before'] |
|
271 ); |
|
272 $output .= $r['title_before']; |
|
273 $output .= $r['title_li']; |
|
274 $output .= $r['title_after']; |
|
275 $output .= "\n\t<ul class='xoxo blogroll'>\n"; |
|
276 $output .= _walk_bookmarks( $bookmarks, $r ); |
|
277 $output .= "\n\t</ul>\n"; |
|
278 $output .= $r['category_after'] . "\n"; |
254 } else { |
279 } else { |
255 $output .= _walk_bookmarks($bookmarks, $r); |
280 $output .= _walk_bookmarks( $bookmarks, $r ); |
256 } |
281 } |
257 } |
282 } |
258 } |
283 } |
259 |
284 |
260 /** |
285 /** |
261 * Filter the bookmarks list before it is echoed or returned. |
286 * Filter the bookmarks list before it is echoed or returned. |
262 * |
287 * |
263 * @since 2.5.0 |
288 * @since 2.5.0 |
264 * |
289 * |
265 * @param string $output The HTML list of bookmarks. |
290 * @param string $html The HTML list of bookmarks. |
266 */ |
291 */ |
267 $output = apply_filters( 'wp_list_bookmarks', $output ); |
292 $html = apply_filters( 'wp_list_bookmarks', $output ); |
268 |
293 |
269 if ( !$echo ) |
294 if ( ! $r['echo'] ) { |
270 return $output; |
295 return $html; |
271 echo $output; |
296 } |
|
297 echo $html; |
272 } |
298 } |