Edit File by line
/home/barbar84/www/wp-inclu...
File: bookmark-template.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Bookmark Template Functions for usage in Themes
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage Template
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
/**
[8] Fix | Delete
* The formatted output of a list of bookmarks.
[9] Fix | Delete
*
[10] Fix | Delete
* The $bookmarks array must contain bookmark objects and will be iterated over
[11] Fix | Delete
* to retrieve the bookmark to be used in the output.
[12] Fix | Delete
*
[13] Fix | Delete
* The output is formatted as HTML with no way to change that format. However,
[14] Fix | Delete
* what is between, before, and after can be changed. The link itself will be
[15] Fix | Delete
* HTML.
[16] Fix | Delete
*
[17] Fix | Delete
* This function is used internally by wp_list_bookmarks() and should not be
[18] Fix | Delete
* used by themes.
[19] Fix | Delete
*
[20] Fix | Delete
* @since 2.1.0
[21] Fix | Delete
* @access private
[22] Fix | Delete
*
[23] Fix | Delete
* @param array $bookmarks List of bookmarks to traverse.
[24] Fix | Delete
* @param string|array $args {
[25] Fix | Delete
* Optional. Bookmarks arguments.
[26] Fix | Delete
*
[27] Fix | Delete
* @type int|bool $show_updated Whether to show the time the bookmark was last updated.
[28] Fix | Delete
* Accepts 1|true or 0|false. Default 0|false.
[29] Fix | Delete
* @type int|bool $show_description Whether to show the bookmark description. Accepts 1|true,
[30] Fix | Delete
* Accepts 1|true or 0|false. Default 0|false.
[31] Fix | Delete
* @type int|bool $show_images Whether to show the link image if available. Accepts 1|true
[32] Fix | Delete
* or 0|false. Default 1|true.
[33] Fix | Delete
* @type int|bool $show_name Whether to show link name if available. Accepts 1|true or
[34] Fix | Delete
* 0|false. Default 0|false.
[35] Fix | Delete
* @type string $before The HTML or text to prepend to each bookmark. Default `<li>`.
[36] Fix | Delete
* @type string $after The HTML or text to append to each bookmark. Default `</li>`.
[37] Fix | Delete
* @type string $link_before The HTML or text to prepend to each bookmark inside the anchor
[38] Fix | Delete
* tags. Default empty.
[39] Fix | Delete
* @type string $link_after The HTML or text to append to each bookmark inside the anchor
[40] Fix | Delete
* tags. Default empty.
[41] Fix | Delete
* @type string $between The string for use in between the link, description, and image.
[42] Fix | Delete
* Default "\n".
[43] Fix | Delete
* @type int|bool $show_rating Whether to show the link rating. Accepts 1|true or 0|false.
[44] Fix | Delete
* Default 0|false.
[45] Fix | Delete
*
[46] Fix | Delete
* }
[47] Fix | Delete
* @return string Formatted output in HTML
[48] Fix | Delete
*/
[49] Fix | Delete
function _walk_bookmarks( $bookmarks, $args = '' ) {
[50] Fix | Delete
$defaults = array(
[51] Fix | Delete
'show_updated' => 0,
[52] Fix | Delete
'show_description' => 0,
[53] Fix | Delete
'show_images' => 1,
[54] Fix | Delete
'show_name' => 0,
[55] Fix | Delete
'before' => '<li>',
[56] Fix | Delete
'after' => '</li>',
[57] Fix | Delete
'between' => "\n",
[58] Fix | Delete
'show_rating' => 0,
[59] Fix | Delete
'link_before' => '',
[60] Fix | Delete
'link_after' => '',
[61] Fix | Delete
);
[62] Fix | Delete
[63] Fix | Delete
$parsed_args = wp_parse_args( $args, $defaults );
[64] Fix | Delete
[65] Fix | Delete
$output = ''; // Blank string to start with.
[66] Fix | Delete
[67] Fix | Delete
foreach ( (array) $bookmarks as $bookmark ) {
[68] Fix | Delete
if ( ! isset( $bookmark->recently_updated ) ) {
[69] Fix | Delete
$bookmark->recently_updated = false;
[70] Fix | Delete
}
[71] Fix | Delete
$output .= $parsed_args['before'];
[72] Fix | Delete
if ( $parsed_args['show_updated'] && $bookmark->recently_updated ) {
[73] Fix | Delete
$output .= '<em>';
[74] Fix | Delete
}
[75] Fix | Delete
$the_link = '#';
[76] Fix | Delete
if ( ! empty( $bookmark->link_url ) ) {
[77] Fix | Delete
$the_link = esc_url( $bookmark->link_url );
[78] Fix | Delete
}
[79] Fix | Delete
$desc = esc_attr( sanitize_bookmark_field( 'link_description', $bookmark->link_description, $bookmark->link_id, 'display' ) );
[80] Fix | Delete
$name = esc_attr( sanitize_bookmark_field( 'link_name', $bookmark->link_name, $bookmark->link_id, 'display' ) );
[81] Fix | Delete
$title = $desc;
[82] Fix | Delete
[83] Fix | Delete
if ( $parsed_args['show_updated'] ) {
[84] Fix | Delete
if ( '00' !== substr( $bookmark->link_updated_f, 0, 2 ) ) {
[85] Fix | Delete
$title .= ' (';
[86] Fix | Delete
$title .= sprintf(
[87] Fix | Delete
/* translators: %s: Date and time of last update. */
[88] Fix | Delete
__( 'Last updated: %s' ),
[89] Fix | Delete
gmdate(
[90] Fix | Delete
get_option( 'links_updated_date_format' ),
[91] Fix | Delete
$bookmark->link_updated_f + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS )
[92] Fix | Delete
)
[93] Fix | Delete
);
[94] Fix | Delete
$title .= ')';
[95] Fix | Delete
}
[96] Fix | Delete
}
[97] Fix | Delete
$alt = ' alt="' . $name . ( $parsed_args['show_description'] ? ' ' . $title : '' ) . '"';
[98] Fix | Delete
[99] Fix | Delete
if ( '' !== $title ) {
[100] Fix | Delete
$title = ' title="' . $title . '"';
[101] Fix | Delete
}
[102] Fix | Delete
$rel = $bookmark->link_rel;
[103] Fix | Delete
if ( '' !== $rel ) {
[104] Fix | Delete
$rel = ' rel="' . esc_attr( $rel ) . '"';
[105] Fix | Delete
}
[106] Fix | Delete
$target = $bookmark->link_target;
[107] Fix | Delete
if ( '' !== $target ) {
[108] Fix | Delete
$target = ' target="' . $target . '"';
[109] Fix | Delete
}
[110] Fix | Delete
$output .= '<a href="' . $the_link . '"' . $rel . $title . $target . '>';
[111] Fix | Delete
[112] Fix | Delete
$output .= $parsed_args['link_before'];
[113] Fix | Delete
[114] Fix | Delete
if ( null != $bookmark->link_image && $parsed_args['show_images'] ) {
[115] Fix | Delete
if ( strpos( $bookmark->link_image, 'http' ) === 0 ) {
[116] Fix | Delete
$output .= "<img src=\"$bookmark->link_image\" $alt $title />";
[117] Fix | Delete
} else { // If it's a relative path.
[118] Fix | Delete
$output .= '<img src="' . get_option( 'siteurl' ) . "$bookmark->link_image\" $alt $title />";
[119] Fix | Delete
}
[120] Fix | Delete
if ( $parsed_args['show_name'] ) {
[121] Fix | Delete
$output .= " $name";
[122] Fix | Delete
}
[123] Fix | Delete
} else {
[124] Fix | Delete
$output .= $name;
[125] Fix | Delete
}
[126] Fix | Delete
[127] Fix | Delete
$output .= $parsed_args['link_after'];
[128] Fix | Delete
[129] Fix | Delete
$output .= '</a>';
[130] Fix | Delete
[131] Fix | Delete
if ( $parsed_args['show_updated'] && $bookmark->recently_updated ) {
[132] Fix | Delete
$output .= '</em>';
[133] Fix | Delete
}
[134] Fix | Delete
[135] Fix | Delete
if ( $parsed_args['show_description'] && '' !== $desc ) {
[136] Fix | Delete
$output .= $parsed_args['between'] . $desc;
[137] Fix | Delete
}
[138] Fix | Delete
[139] Fix | Delete
if ( $parsed_args['show_rating'] ) {
[140] Fix | Delete
$output .= $parsed_args['between'] . sanitize_bookmark_field(
[141] Fix | Delete
'link_rating',
[142] Fix | Delete
$bookmark->link_rating,
[143] Fix | Delete
$bookmark->link_id,
[144] Fix | Delete
'display'
[145] Fix | Delete
);
[146] Fix | Delete
}
[147] Fix | Delete
$output .= $parsed_args['after'] . "\n";
[148] Fix | Delete
} // End while.
[149] Fix | Delete
[150] Fix | Delete
return $output;
[151] Fix | Delete
}
[152] Fix | Delete
[153] Fix | Delete
/**
[154] Fix | Delete
* Retrieve or echo all of the bookmarks.
[155] Fix | Delete
*
[156] Fix | Delete
* List of default arguments are as follows:
[157] Fix | Delete
*
[158] Fix | Delete
* These options define how the Category name will appear before the category
[159] Fix | Delete
* links are displayed, if 'categorize' is 1. If 'categorize' is 0, then it will
[160] Fix | Delete
* display for only the 'title_li' string and only if 'title_li' is not empty.
[161] Fix | Delete
*
[162] Fix | Delete
* @since 2.1.0
[163] Fix | Delete
*
[164] Fix | Delete
* @see _walk_bookmarks()
[165] Fix | Delete
*
[166] Fix | Delete
* @param string|array $args {
[167] Fix | Delete
* Optional. String or array of arguments to list bookmarks.
[168] Fix | Delete
*
[169] Fix | Delete
* @type string $orderby How to order the links by. Accepts post fields. Default 'name'.
[170] Fix | Delete
* @type string $order Whether to order bookmarks in ascending or descending order.
[171] Fix | Delete
* Accepts 'ASC' (ascending) or 'DESC' (descending). Default 'ASC'.
[172] Fix | Delete
* @type int $limit Amount of bookmarks to display. Accepts 1+ or -1 for all.
[173] Fix | Delete
* Default -1.
[174] Fix | Delete
* @type string $category Comma-separated list of category IDs to include links from.
[175] Fix | Delete
* Default empty.
[176] Fix | Delete
* @type string $category_name Category to retrieve links for by name. Default empty.
[177] Fix | Delete
* @type int|bool $hide_invisible Whether to show or hide links marked as 'invisible'. Accepts
[178] Fix | Delete
* 1|true or 0|false. Default 1|true.
[179] Fix | Delete
* @type int|bool $show_updated Whether to display the time the bookmark was last updated.
[180] Fix | Delete
* Accepts 1|true or 0|false. Default 0|false.
[181] Fix | Delete
* @type int|bool $echo Whether to echo or return the formatted bookmarks. Accepts
[182] Fix | Delete
* 1|true (echo) or 0|false (return). Default 1|true.
[183] Fix | Delete
* @type int|bool $categorize Whether to show links listed by category or in a single column.
[184] Fix | Delete
* Accepts 1|true (by category) or 0|false (one column). Default 1|true.
[185] Fix | Delete
* @type int|bool $show_description Whether to show the bookmark descriptions. Accepts 1|true or 0|false.
[186] Fix | Delete
* Default 0|false.
[187] Fix | Delete
* @type string $title_li What to show before the links appear. Default 'Bookmarks'.
[188] Fix | Delete
* @type string $title_before The HTML or text to prepend to the $title_li string. Default '<h2>'.
[189] Fix | Delete
* @type string $title_after The HTML or text to append to the $title_li string. Default '</h2>'.
[190] Fix | Delete
* @type string|array $class The CSS class or an array of classes to use for the $title_li.
[191] Fix | Delete
* Default 'linkcat'.
[192] Fix | Delete
* @type string $category_before The HTML or text to prepend to $title_before if $categorize is true.
[193] Fix | Delete
* String must contain '%id' and '%class' to inherit the category ID and
[194] Fix | Delete
* the $class argument used for formatting in themes.
[195] Fix | Delete
* Default '<li id="%id" class="%class">'.
[196] Fix | Delete
* @type string $category_after The HTML or text to append to $title_after if $categorize is true.
[197] Fix | Delete
* Default '</li>'.
[198] Fix | Delete
* @type string $category_orderby How to order the bookmark category based on term scheme if $categorize
[199] Fix | Delete
* is true. Default 'name'.
[200] Fix | Delete
* @type string $category_order Whether to order categories in ascending or descending order if
[201] Fix | Delete
* $categorize is true. Accepts 'ASC' (ascending) or 'DESC' (descending).
[202] Fix | Delete
* Default 'ASC'.
[203] Fix | Delete
* }
[204] Fix | Delete
* @return void|string Void if 'echo' argument is true, HTML list of bookmarks if 'echo' is false.
[205] Fix | Delete
*/
[206] Fix | Delete
function wp_list_bookmarks( $args = '' ) {
[207] Fix | Delete
$defaults = array(
[208] Fix | Delete
'orderby' => 'name',
[209] Fix | Delete
'order' => 'ASC',
[210] Fix | Delete
'limit' => -1,
[211] Fix | Delete
'category' => '',
[212] Fix | Delete
'exclude_category' => '',
[213] Fix | Delete
'category_name' => '',
[214] Fix | Delete
'hide_invisible' => 1,
[215] Fix | Delete
'show_updated' => 0,
[216] Fix | Delete
'echo' => 1,
[217] Fix | Delete
'categorize' => 1,
[218] Fix | Delete
'title_li' => __( 'Bookmarks' ),
[219] Fix | Delete
'title_before' => '<h2>',
[220] Fix | Delete
'title_after' => '</h2>',
[221] Fix | Delete
'category_orderby' => 'name',
[222] Fix | Delete
'category_order' => 'ASC',
[223] Fix | Delete
'class' => 'linkcat',
[224] Fix | Delete
'category_before' => '<li id="%id" class="%class">',
[225] Fix | Delete
'category_after' => '</li>',
[226] Fix | Delete
);
[227] Fix | Delete
[228] Fix | Delete
$parsed_args = wp_parse_args( $args, $defaults );
[229] Fix | Delete
[230] Fix | Delete
$output = '';
[231] Fix | Delete
[232] Fix | Delete
if ( ! is_array( $parsed_args['class'] ) ) {
[233] Fix | Delete
$parsed_args['class'] = explode( ' ', $parsed_args['class'] );
[234] Fix | Delete
}
[235] Fix | Delete
$parsed_args['class'] = array_map( 'sanitize_html_class', $parsed_args['class'] );
[236] Fix | Delete
$parsed_args['class'] = trim( implode( ' ', $parsed_args['class'] ) );
[237] Fix | Delete
[238] Fix | Delete
if ( $parsed_args['categorize'] ) {
[239] Fix | Delete
$cats = get_terms(
[240] Fix | Delete
array(
[241] Fix | Delete
'taxonomy' => 'link_category',
[242] Fix | Delete
'name__like' => $parsed_args['category_name'],
[243] Fix | Delete
'include' => $parsed_args['category'],
[244] Fix | Delete
'exclude' => $parsed_args['exclude_category'],
[245] Fix | Delete
'orderby' => $parsed_args['category_orderby'],
[246] Fix | Delete
'order' => $parsed_args['category_order'],
[247] Fix | Delete
'hierarchical' => 0,
[248] Fix | Delete
)
[249] Fix | Delete
);
[250] Fix | Delete
if ( empty( $cats ) ) {
[251] Fix | Delete
$parsed_args['categorize'] = false;
[252] Fix | Delete
}
[253] Fix | Delete
}
[254] Fix | Delete
[255] Fix | Delete
if ( $parsed_args['categorize'] ) {
[256] Fix | Delete
// Split the bookmarks into ul's for each category.
[257] Fix | Delete
foreach ( (array) $cats as $cat ) {
[258] Fix | Delete
$params = array_merge( $parsed_args, array( 'category' => $cat->term_id ) );
[259] Fix | Delete
$bookmarks = get_bookmarks( $params );
[260] Fix | Delete
if ( empty( $bookmarks ) ) {
[261] Fix | Delete
continue;
[262] Fix | Delete
}
[263] Fix | Delete
$output .= str_replace(
[264] Fix | Delete
array( '%id', '%class' ),
[265] Fix | Delete
array( "linkcat-$cat->term_id", $parsed_args['class'] ),
[266] Fix | Delete
$parsed_args['category_before']
[267] Fix | Delete
);
[268] Fix | Delete
/**
[269] Fix | Delete
* Filters the category name.
[270] Fix | Delete
*
[271] Fix | Delete
* @since 2.2.0
[272] Fix | Delete
*
[273] Fix | Delete
* @param string $cat_name The category name.
[274] Fix | Delete
*/
[275] Fix | Delete
$catname = apply_filters( 'link_category', $cat->name );
[276] Fix | Delete
[277] Fix | Delete
$output .= $parsed_args['title_before'];
[278] Fix | Delete
$output .= $catname;
[279] Fix | Delete
$output .= $parsed_args['title_after'];
[280] Fix | Delete
$output .= "\n\t<ul class='xoxo blogroll'>\n";
[281] Fix | Delete
$output .= _walk_bookmarks( $bookmarks, $parsed_args );
[282] Fix | Delete
$output .= "\n\t</ul>\n";
[283] Fix | Delete
$output .= $parsed_args['category_after'] . "\n";
[284] Fix | Delete
}
[285] Fix | Delete
} else {
[286] Fix | Delete
// Output one single list using title_li for the title.
[287] Fix | Delete
$bookmarks = get_bookmarks( $parsed_args );
[288] Fix | Delete
[289] Fix | Delete
if ( ! empty( $bookmarks ) ) {
[290] Fix | Delete
if ( ! empty( $parsed_args['title_li'] ) ) {
[291] Fix | Delete
$output .= str_replace(
[292] Fix | Delete
array( '%id', '%class' ),
[293] Fix | Delete
array( 'linkcat-' . $parsed_args['category'], $parsed_args['class'] ),
[294] Fix | Delete
$parsed_args['category_before']
[295] Fix | Delete
);
[296] Fix | Delete
$output .= $parsed_args['title_before'];
[297] Fix | Delete
$output .= $parsed_args['title_li'];
[298] Fix | Delete
$output .= $parsed_args['title_after'];
[299] Fix | Delete
$output .= "\n\t<ul class='xoxo blogroll'>\n";
[300] Fix | Delete
$output .= _walk_bookmarks( $bookmarks, $parsed_args );
[301] Fix | Delete
$output .= "\n\t</ul>\n";
[302] Fix | Delete
$output .= $parsed_args['category_after'] . "\n";
[303] Fix | Delete
} else {
[304] Fix | Delete
$output .= _walk_bookmarks( $bookmarks, $parsed_args );
[305] Fix | Delete
}
[306] Fix | Delete
}
[307] Fix | Delete
}
[308] Fix | Delete
[309] Fix | Delete
/**
[310] Fix | Delete
* Filters the bookmarks list before it is echoed or returned.
[311] Fix | Delete
*
[312] Fix | Delete
* @since 2.5.0
[313] Fix | Delete
*
[314] Fix | Delete
* @param string $html The HTML list of bookmarks.
[315] Fix | Delete
*/
[316] Fix | Delete
$html = apply_filters( 'wp_list_bookmarks', $output );
[317] Fix | Delete
[318] Fix | Delete
if ( $parsed_args['echo'] ) {
[319] Fix | Delete
echo $html;
[320] Fix | Delete
} else {
[321] Fix | Delete
return $html;
[322] Fix | Delete
}
[323] Fix | Delete
}
[324] Fix | Delete
[325] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function