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