wp/wp-includes/bookmark-template.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
    26  * @param string|array $args {
    26  * @param string|array $args {
    27  *     Optional. Bookmarks arguments.
    27  *     Optional. Bookmarks arguments.
    28  *
    28  *
    29  *     @type int|bool $show_updated     Whether to show the time the bookmark was last updated.
    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.
    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,
    31  *     @type int|bool $show_description Whether to show the bookmark description. Accepts 1|true,
    32  *                                      Accepts 1|true or 0|false. Default 0|false.
    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
    33  *     @type int|bool $show_images      Whether to show the link image if available. Accepts 1|true
    34  *                                      or 0|false. Default 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
    35  *     @type int|bool $show_name        Whether to show link name if available. Accepts 1|true or
    36  *                                      0|false. Default 0|false.
    36  *                                      0|false. Default 0|false.
    48  * }
    48  * }
    49  * @return string Formatted output in HTML
    49  * @return string Formatted output in HTML
    50  */
    50  */
    51 function _walk_bookmarks( $bookmarks, $args = '' ) {
    51 function _walk_bookmarks( $bookmarks, $args = '' ) {
    52 	$defaults = array(
    52 	$defaults = array(
    53 		'show_updated' => 0, 'show_description' => 0,
    53 		'show_updated'     => 0,
    54 		'show_images' => 1, 'show_name' => 0,
    54 		'show_description' => 0,
    55 		'before' => '<li>', 'after' => '</li>', 'between' => "\n",
    55 		'show_images'      => 1,
    56 		'show_rating' => 0, 'link_before' => '', 'link_after' => ''
    56 		'show_name'        => 0,
       
    57 		'before'           => '<li>',
       
    58 		'after'            => '</li>',
       
    59 		'between'          => "\n",
       
    60 		'show_rating'      => 0,
       
    61 		'link_before'      => '',
       
    62 		'link_after'       => '',
    57 	);
    63 	);
    58 
    64 
    59 	$r = wp_parse_args( $args, $defaults );
    65 	$r = wp_parse_args( $args, $defaults );
    60 
    66 
    61 	$output = ''; // Blank string to start with.
    67 	$output = ''; // Blank string to start with.
    70 		}
    76 		}
    71 		$the_link = '#';
    77 		$the_link = '#';
    72 		if ( ! empty( $bookmark->link_url ) ) {
    78 		if ( ! empty( $bookmark->link_url ) ) {
    73 			$the_link = esc_url( $bookmark->link_url );
    79 			$the_link = esc_url( $bookmark->link_url );
    74 		}
    80 		}
    75 		$desc = esc_attr( sanitize_bookmark_field( 'link_description', $bookmark->link_description, $bookmark->link_id, 'display' ) );
    81 		$desc  = esc_attr( sanitize_bookmark_field( 'link_description', $bookmark->link_description, $bookmark->link_id, 'display' ) );
    76 		$name = esc_attr( sanitize_bookmark_field( 'link_name', $bookmark->link_name, $bookmark->link_id, 'display' ) );
    82 		$name  = esc_attr( sanitize_bookmark_field( 'link_name', $bookmark->link_name, $bookmark->link_id, 'display' ) );
    77  		$title = $desc;
    83 		$title = $desc;
    78 
    84 
    79 		if ( $r['show_updated'] ) {
    85 		if ( $r['show_updated'] ) {
    80 			if ( '00' != substr( $bookmark->link_updated_f, 0, 2 ) ) {
    86 			if ( '00' != substr( $bookmark->link_updated_f, 0, 2 ) ) {
    81 				$title .= ' (';
    87 				$title .= ' (';
    82 				$title .= sprintf(
    88 				$title .= sprintf(
    83 					__('Last updated: %s'),
    89 					__( 'Last updated: %s' ),
    84 					date(
    90 					date(
    85 						get_option( 'links_updated_date_format' ),
    91 						get_option( 'links_updated_date_format' ),
    86 						$bookmark->link_updated_f + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS )
    92 						$bookmark->link_updated_f + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS )
    87 					)
    93 					)
    88 				);
    94 				);
    94 		if ( '' != $title ) {
   100 		if ( '' != $title ) {
    95 			$title = ' title="' . $title . '"';
   101 			$title = ' title="' . $title . '"';
    96 		}
   102 		}
    97 		$rel = $bookmark->link_rel;
   103 		$rel = $bookmark->link_rel;
    98 		if ( '' != $rel ) {
   104 		if ( '' != $rel ) {
    99 			$rel = ' rel="' . esc_attr($rel) . '"';
   105 			$rel = ' rel="' . esc_attr( $rel ) . '"';
   100 		}
   106 		}
   101 		$target = $bookmark->link_target;
   107 		$target = $bookmark->link_target;
   102 		if ( '' != $target ) {
   108 		if ( '' != $target ) {
   103 			$target = ' target="' . $target . '"';
   109 			$target = ' target="' . $target . '"';
   104 		}
   110 		}
   108 
   114 
   109 		if ( $bookmark->link_image != null && $r['show_images'] ) {
   115 		if ( $bookmark->link_image != null && $r['show_images'] ) {
   110 			if ( strpos( $bookmark->link_image, 'http' ) === 0 ) {
   116 			if ( strpos( $bookmark->link_image, 'http' ) === 0 ) {
   111 				$output .= "<img src=\"$bookmark->link_image\" $alt $title />";
   117 				$output .= "<img src=\"$bookmark->link_image\" $alt $title />";
   112 			} else { // If it's a relative path
   118 			} else { // If it's a relative path
   113 				$output .= "<img src=\"" . get_option('siteurl') . "$bookmark->link_image\" $alt $title />";
   119 				$output .= '<img src="' . get_option( 'siteurl' ) . "$bookmark->link_image\" $alt $title />";
   114 			}
   120 			}
   115 			if ( $r['show_name'] ) {
   121 			if ( $r['show_name'] ) {
   116 				$output .= " $name";
   122 				$output .= " $name";
   117 			}
   123 			}
   118 		} else {
   124 		} else {
   197  * }
   203  * }
   198  * @return string|void Will only return if echo option is set to not echo. Default is not return anything.
   204  * @return string|void Will only return if echo option is set to not echo. Default is not return anything.
   199  */
   205  */
   200 function wp_list_bookmarks( $args = '' ) {
   206 function wp_list_bookmarks( $args = '' ) {
   201 	$defaults = array(
   207 	$defaults = array(
   202 		'orderby' => 'name', 'order' => 'ASC',
   208 		'orderby'          => 'name',
   203 		'limit' => -1, 'category' => '', 'exclude_category' => '',
   209 		'order'            => 'ASC',
   204 		'category_name' => '', 'hide_invisible' => 1,
   210 		'limit'            => -1,
   205 		'show_updated' => 0, 'echo' => 1,
   211 		'category'         => '',
   206 		'categorize' => 1, 'title_li' => __('Bookmarks'),
   212 		'exclude_category' => '',
   207 		'title_before' => '<h2>', 'title_after' => '</h2>',
   213 		'category_name'    => '',
   208 		'category_orderby' => 'name', 'category_order' => 'ASC',
   214 		'hide_invisible'   => 1,
   209 		'class' => 'linkcat', 'category_before' => '<li id="%id" class="%class">',
   215 		'show_updated'     => 0,
   210 		'category_after' => '</li>'
   216 		'echo'             => 1,
       
   217 		'categorize'       => 1,
       
   218 		'title_li'         => __( 'Bookmarks' ),
       
   219 		'title_before'     => '<h2>',
       
   220 		'title_after'      => '</h2>',
       
   221 		'category_orderby' => 'name',
       
   222 		'category_order'   => 'ASC',
       
   223 		'class'            => 'linkcat',
       
   224 		'category_before'  => '<li id="%id" class="%class">',
       
   225 		'category_after'   => '</li>',
   211 	);
   226 	);
   212 
   227 
   213 	$r = wp_parse_args( $args, $defaults );
   228 	$r = wp_parse_args( $args, $defaults );
   214 
   229 
   215 	$output = '';
   230 	$output = '';
   216 
   231 
   217 	if ( ! is_array( $r['class'] ) ) {
   232 	if ( ! is_array( $r['class'] ) ) {
   218 		$r['class'] = explode( ' ', $r['class'] );
   233 		$r['class'] = explode( ' ', $r['class'] );
   219 	}
   234 	}
   220  	$r['class'] = array_map( 'sanitize_html_class', $r['class'] );
   235 	$r['class'] = array_map( 'sanitize_html_class', $r['class'] );
   221  	$r['class'] = trim( join( ' ', $r['class'] ) );
   236 	$r['class'] = trim( join( ' ', $r['class'] ) );
   222 
   237 
   223 	if ( $r['categorize'] ) {
   238 	if ( $r['categorize'] ) {
   224 		$cats = get_terms( 'link_category', array(
   239 		$cats = get_terms(
   225 			'name__like' => $r['category_name'],
   240 			'link_category',
   226 			'include' => $r['category'],
   241 			array(
   227 			'exclude' => $r['exclude_category'],
   242 				'name__like'   => $r['category_name'],
   228 			'orderby' => $r['category_orderby'],
   243 				'include'      => $r['category'],
   229 			'order' => $r['category_order'],
   244 				'exclude'      => $r['exclude_category'],
   230 			'hierarchical' => 0
   245 				'orderby'      => $r['category_orderby'],
   231 		) );
   246 				'order'        => $r['category_order'],
       
   247 				'hierarchical' => 0,
       
   248 			)
       
   249 		);
   232 		if ( empty( $cats ) ) {
   250 		if ( empty( $cats ) ) {
   233 			$r['categorize'] = false;
   251 			$r['categorize'] = false;
   234 		}
   252 		}
   235 	}
   253 	}
   236 
   254 
   237 	if ( $r['categorize'] ) {
   255 	if ( $r['categorize'] ) {
   238 		// Split the bookmarks into ul's for each category
   256 		// Split the bookmarks into ul's for each category
   239 		foreach ( (array) $cats as $cat ) {
   257 		foreach ( (array) $cats as $cat ) {
   240 			$params = array_merge( $r, array( 'category' => $cat->term_id ) );
   258 			$params    = array_merge( $r, array( 'category' => $cat->term_id ) );
   241 			$bookmarks = get_bookmarks( $params );
   259 			$bookmarks = get_bookmarks( $params );
   242 			if ( empty( $bookmarks ) ) {
   260 			if ( empty( $bookmarks ) ) {
   243 				continue;
   261 				continue;
   244 			}
   262 			}
   245 			$output .= str_replace(
   263 			$output .= str_replace(
   246 				array( '%id', '%class' ),
   264 				array( '%id', '%class' ),
   247 				array( "linkcat-$cat->term_id", $r['class'] ),
   265 				array( "linkcat-$cat->term_id", $r['class'] ),
   248 				$r['category_before']
   266 				$r['category_before']
   249 			);
   267 			);
   250 			/**
   268 			/**
   251 			 * Filters the bookmarks category name.
   269 			 * Filters the category name.
   252 			 *
   270 			 *
   253 			 * @since 2.2.0
   271 			 * @since 2.2.0
   254 			 *
   272 			 *
   255 			 * @param string $cat_name The category name of bookmarks.
   273 			 * @param string $cat_name The category name.
   256 			 */
   274 			 */
   257 			$catname = apply_filters( 'link_category', $cat->name );
   275 			$catname = apply_filters( 'link_category', $cat->name );
   258 
   276 
   259 			$output .= $r['title_before'];
   277 			$output .= $r['title_before'];
   260 			$output .= $catname;
   278 			$output .= $catname;
   270 
   288 
   271 		if ( ! empty( $bookmarks ) ) {
   289 		if ( ! empty( $bookmarks ) ) {
   272 			if ( ! empty( $r['title_li'] ) ) {
   290 			if ( ! empty( $r['title_li'] ) ) {
   273 				$output .= str_replace(
   291 				$output .= str_replace(
   274 					array( '%id', '%class' ),
   292 					array( '%id', '%class' ),
   275 					array( "linkcat-" . $r['category'], $r['class'] ),
   293 					array( 'linkcat-' . $r['category'], $r['class'] ),
   276 					$r['category_before']
   294 					$r['category_before']
   277 				);
   295 				);
   278 				$output .= $r['title_before'];
   296 				$output .= $r['title_before'];
   279 				$output .= $r['title_li'];
   297 				$output .= $r['title_li'];
   280 				$output .= $r['title_after'];
   298 				$output .= $r['title_after'];