-
+ B235E332385EF92EA7DB8CC513FC9001BE5B800182725B8CC2C2CAFCC99944F89BEE7828A6EA84AC238FF79B7754E4D0B0FB866F2C06F0D4E13A58DD4C4872B1
mp-wp/wp-includes/bookmark-template.php
(0 . 0)(1 . 254)
71759 <?php
71760 /**
71761 * Bookmark Template Functions for usage in Themes
71762 *
71763 * @package WordPress
71764 * @subpackage Template
71765 */
71766
71767 /**
71768 * The formatted output of a list of bookmarks.
71769 *
71770 * The $bookmarks array must contain bookmark objects and will be iterated over
71771 * to retrieve the bookmark to be used in the output.
71772 *
71773 * The output is formatted as HTML with no way to change that format. However,
71774 * what is between, before, and after can be changed. The link itself will be
71775 * HTML.
71776 *
71777 * This function is used internally by wp_list_bookmarks() and should not be
71778 * used by themes.
71779 *
71780 * The defaults for overwriting are:
71781 * 'show_updated' - Default is 0 (integer). Will show the time of when the
71782 * bookmark was last updated.
71783 * 'show_description' - Default is 0 (integer). Whether to show the description
71784 * of the bookmark.
71785 * 'show_images' - Default is 1 (integer). Whether to show link image if
71786 * available.
71787 * 'show_name' - Default is 1 (integer). Whether to show link name if
71788 * available.
71789 * 'before' - Default is '<li>' (string). The html or text to prepend to each
71790 * bookmarks.
71791 * 'after' - Default is '</li>' (string). The html or text to append to each
71792 * bookmarks.
71793 * 'link_before' - Default is '' (string). The html or text to prepend to each
71794 * bookmarks inside the <a> tag.
71795 * 'link_after' - Default is '' (string). The html or text to append to each
71796 * bookmarks inside the <a> tag.
71797 * 'between' - Default is '\n' (string). The string for use in between the link,
71798 * description, and image.
71799 * 'show_rating' - Default is 0 (integer). Whether to show the link rating.
71800 *
71801 * @since 2.1.0
71802 * @access private
71803 * @usedby wp_list_bookmarks()
71804 *
71805 * @param array $bookmarks List of bookmarks to traverse
71806 * @param string|array $args Optional. Overwrite the defaults.
71807 * @return string Formatted output in HTML
71808 */
71809 function _walk_bookmarks($bookmarks, $args = '' ) {
71810 $defaults = array(
71811 'show_updated' => 0, 'show_description' => 0,
71812 'show_images' => 1, 'show_name' => 0,
71813 'before' => '<li>', 'after' => '</li>', 'between' => "\n",
71814 'show_rating' => 0, 'link_before' => '', 'link_after' => ''
71815 );
71816
71817 $r = wp_parse_args( $args, $defaults );
71818 extract( $r, EXTR_SKIP );
71819
71820 $output = ''; // Blank string to start with.
71821
71822 foreach ( (array) $bookmarks as $bookmark ) {
71823 if ( !isset($bookmark->recently_updated) )
71824 $bookmark->recently_updated = false;
71825 $output .= $before;
71826 if ( $show_updated && $bookmark->recently_updated )
71827 $output .= get_option('links_recently_updated_prepend');
71828
71829 $the_link = '#';
71830 if ( !empty($bookmark->link_url) )
71831 $the_link = clean_url($bookmark->link_url);
71832
71833 $rel = $bookmark->link_rel;
71834 if ( '' != $rel )
71835 $rel = ' rel="' . $rel . '"';
71836
71837 $desc = attribute_escape(sanitize_bookmark_field('link_description', $bookmark->link_description, $bookmark->link_id, 'display'));
71838 $name = attribute_escape(sanitize_bookmark_field('link_name', $bookmark->link_name, $bookmark->link_id, 'display'));
71839 $title = $desc;
71840
71841 if ( $show_updated )
71842 if ( '00' != substr($bookmark->link_updated_f, 0, 2) ) {
71843 $title .= ' (';
71844 $title .= sprintf(__('Last updated: %s'), date(get_option('links_updated_date_format'), $bookmark->link_updated_f + (get_option('gmt_offset') * 3600)));
71845 $title .= ')';
71846 }
71847
71848 if ( '' != $title )
71849 $title = ' title="' . $title . '"';
71850
71851 $alt = ' alt="' . $name . '"';
71852
71853 $target = $bookmark->link_target;
71854 if ( '' != $target )
71855 $target = ' target="' . $target . '"';
71856
71857 $output .= '<a href="' . $the_link . '"' . $rel . $title . $target. '>';
71858
71859 $output .= $link_before;
71860
71861 if ( $bookmark->link_image != null && $show_images ) {
71862 if ( strpos($bookmark->link_image, 'http') !== false )
71863 $output .= "<img src=\"$bookmark->link_image\" $alt $title />";
71864 else // If it's a relative path
71865 $output .= "<img src=\"" . get_option('siteurl') . "$bookmark->link_image\" $alt $title />";
71866
71867 if ($show_name) $output .= $name;
71868 } else {
71869 $output .= $name;
71870 }
71871
71872 $output .= $link_after;
71873
71874 $output .= '</a>';
71875
71876 if ( $show_updated && $bookmark->recently_updated )
71877 $output .= get_option('links_recently_updated_append');
71878
71879 if ( $show_description && '' != $desc )
71880 $output .= $between . $desc;
71881
71882 if ($show_rating) {
71883 $output .= $between . sanitize_bookmark_field('link_rating', $bookmark->link_rating, $bookmark->link_id, 'display');
71884 }
71885
71886 $output .= "$after\n";
71887 } // end while
71888
71889 return $output;
71890 }
71891
71892 /**
71893 * Retrieve or echo all of the bookmarks.
71894 *
71895 * List of default arguments are as follows:
71896 * 'orderby' - Default is 'name' (string). How to order the links by. String is
71897 * based off of the bookmark scheme.
71898 * 'order' - Default is 'ASC' (string). Either 'ASC' or 'DESC'. Orders in either
71899 * ascending or descending order.
71900 * 'limit' - Default is -1 (integer) or show all. The amount of bookmarks to
71901 * display.
71902 * 'category' - Default is empty string (string). Include the links in what
71903 * category ID(s).
71904 * 'category_name' - Default is empty string (string). Get links by category
71905 * name.
71906 * 'hide_invisible' - Default is 1 (integer). Whether to show (default) or hide
71907 * links marked as 'invisible'.
71908 * 'show_updated' - Default is 0 (integer). Will show the time of when the
71909 * bookmark was last updated.
71910 * 'echo' - Default is 1 (integer). Whether to echo (default) or return the
71911 * formatted bookmarks.
71912 * 'categorize' - Default is 1 (integer). Whether to show links listed by
71913 * category (default) or show links in one column.
71914 *
71915 * These options define how the Category name will appear before the category
71916 * links are displayed, if 'categorize' is 1. If 'categorize' is 0, then it will
71917 * display for only the 'title_li' string and only if 'title_li' is not empty.
71918 * 'title_li' - Default is 'Bookmarks' (translatable string). What to show
71919 * before the links appear.
71920 * 'title_before' - Default is '<h2>' (string). The HTML or text to show before
71921 * the 'title_li' string.
71922 * 'title_after' - Default is '</h2>' (string). The HTML or text to show after
71923 * the 'title_li' string.
71924 * 'class' - Default is 'linkcat' (string). The CSS class to use for the
71925 * 'title_li'.
71926 *
71927 * 'category_before' - Default is '<li id="%id" class="%class">'. String must
71928 * contain '%id' and '%class' to get
71929 * the id of the category and the 'class' argument. These are used for
71930 * formatting in themes.
71931 * Argument will be displayed before the 'title_before' argument.
71932 * 'category_after' - Default is '</li>' (string). The HTML or text that will
71933 * appear after the list of links.
71934 *
71935 * These are only used if 'categorize' is set to 1 or true.
71936 * 'category_orderby' - Default is 'name'. How to order the bookmark category
71937 * based on term scheme.
71938 * 'category_order' - Default is 'ASC'. Set the order by either ASC (ascending)
71939 * or DESC (descending).
71940 *
71941 * @see _walk_bookmarks() For other arguments that can be set in this function
71942 * and passed to _walk_bookmarks().
71943 * @see get_bookmarks() For other arguments that can be set in this function and
71944 * passed to get_bookmarks().
71945 * @link http://codex.wordpress.org/Template_Tags/wp_list_bookmarks
71946 *
71947 * @since 2.1.0
71948 * @uses _list_bookmarks() Used to iterate over all of the bookmarks and return
71949 * the html
71950 * @uses get_terms() Gets all of the categories that are for links.
71951 *
71952 * @param string|array $args Optional. Overwrite the defaults of the function
71953 * @return string|null Will only return if echo option is set to not echo.
71954 * Default is not return anything.
71955 */
71956 function wp_list_bookmarks($args = '') {
71957 $defaults = array(
71958 'orderby' => 'name', 'order' => 'ASC',
71959 'limit' => -1, 'category' => '', 'exclude_category' => '',
71960 'category_name' => '', 'hide_invisible' => 1,
71961 'show_updated' => 0, 'echo' => 1,
71962 'categorize' => 1, 'title_li' => __('Bookmarks'),
71963 'title_before' => '<h2>', 'title_after' => '</h2>',
71964 'category_orderby' => 'name', 'category_order' => 'ASC',
71965 'class' => 'linkcat', 'category_before' => '<li id="%id" class="%class">',
71966 'category_after' => '</li>'
71967 );
71968
71969 $r = wp_parse_args( $args, $defaults );
71970 extract( $r, EXTR_SKIP );
71971
71972 $output = '';
71973
71974 if ( $categorize ) {
71975 //Split the bookmarks into ul's for each category
71976 $cats = get_terms('link_category', array('name__like' => $category_name, 'include' => $category, 'exclude' => $exclude_category, 'orderby' => $category_orderby, 'order' => $category_order, 'hierarchical' => 0));
71977
71978 foreach ( (array) $cats as $cat ) {
71979 $params = array_merge($r, array('category'=>$cat->term_id));
71980 $bookmarks = get_bookmarks($params);
71981 if ( empty($bookmarks) )
71982 continue;
71983 $output .= str_replace(array('%id', '%class'), array("linkcat-$cat->term_id", $class), $category_before);
71984 $catname = apply_filters( "link_category", $cat->name );
71985 $output .= "$title_before$catname$title_after\n\t<ul class='xoxo blogroll'>\n";
71986 $output .= _walk_bookmarks($bookmarks, $r);
71987 $output .= "\n\t</ul>\n$category_after\n";
71988 }
71989 } else {
71990 //output one single list using title_li for the title
71991 $bookmarks = get_bookmarks($r);
71992
71993 if ( !empty($bookmarks) ) {
71994 if ( !empty( $title_li ) ){
71995 $output .= str_replace(array('%id', '%class'), array("linkcat-$category", $class), $category_before);
71996 $output .= "$title_before$title_li$title_after\n\t<ul class='xoxo blogroll'>\n";
71997 $output .= _walk_bookmarks($bookmarks, $r);
71998 $output .= "\n\t</ul>\n$category_after\n";
71999 } else {
72000 $output .= _walk_bookmarks($bookmarks, $r);
72001 }
72002 }
72003 }
72004
72005 $output = apply_filters( 'wp_list_bookmarks', $output );
72006
72007 if ( !$echo )
72008 return $output;
72009 echo $output;
72010 }
72011
72012 ?>