get_links() purtification. Props MaThIbUs. fixes #1244

git-svn-id: http://svn.automattic.com/wordpress/trunk@2795 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2005-08-20 01:46:18 +00:00
parent 5c6d00bbfc
commit e93dd02321
1 changed files with 113 additions and 116 deletions

View File

@ -125,7 +125,7 @@ function wp_get_links($args = '') {
** before (default '') - the html to output before the link
** after (default '<br />') - the html to output after the link
** between (default ' ') - the html to output between the link/image
** and it's description. Not used if no image or show_images == true
** and its description. Not used if no image or show_images == true
** show_images (default true) - whether to show images (if defined).
** orderby (default 'id') - the order to output the links. E.g. 'id', 'name',
** 'url', 'description', or 'rating'. Or maybe owner. If you start the
@ -138,16 +138,24 @@ function wp_get_links($args = '') {
** limit (default -1) - Limit to X entries. If not specified, all entries
** are shown.
** show_updated (default 0) - whether to show last updated timestamp
** echo (default true) - whether to echo the results, or return them instead
*/
function get_links($category = -1, $before = '', $after = '<br />',
$between = ' ', $show_images = true, $orderby = 'name',
$show_description = true, $show_rating = false,
$limit = -1, $show_updated = 1, $echo = true) {
function get_links($category = -1,
$before = '',
$after = '<br />',
$between = ' ',
$show_images = true,
$orderby = 'name',
$show_description = true,
$show_rating = false,
$limit = -1,
$show_updated = 1,
$echo = true) {
global $wpdb;
$direction = ' ASC';
$category_query = "";
$category_query = '';
if ($category != -1) {
$category_query = " AND link_category = $category ";
}
@ -180,48 +188,39 @@ function get_links($category = -1, $before = '', $after = '<br />',
}
if (!isset($length)) {
$length = "";
$length = '';
}
$sql = "SELECT link_url, link_name, link_image, link_target,
link_description, link_rating, link_rel $length $recently_updated_test $get_updated
FROM $wpdb->links
WHERE link_visible = 'Y' " .
$category_query;
$sql .= ' ORDER BY ' . $orderby;
$sql .= $direction;
$sql = "SELECT link_url, link_name, link_image, link_target, link_description, link_rating, link_rel $length $recently_updated_test $get_updated FROM $wpdb->links WHERE link_visible = 'Y' " . $category_query;
$sql .= ' ORDER BY ' . $orderby . $direction;
/* The next 2 lines implement LIMIT TO processing */
if ($limit != -1)
$sql .= " LIMIT $limit";
//echo $sql;
$results = $wpdb->get_results($sql);
if (!$results) {
return;
}
$output = "";
$output = '';
foreach ($results as $row) {
if (!isset($row->recently_updated)) $row->recently_updated = false;
$output .= ($before);
$output .= $before;
if ($show_updated && $row->recently_updated) {
$output .= get_settings('links_recently_updated_prepend');
}
$the_link = '#';
if (!empty($row->link_url))
$the_link = wp_specialchars($row->link_url);
$rel = $row->link_rel;
$rel = $row->link_rel;
if ($rel != '') {
$rel = " rel='$rel'";
$rel = ' rel="' . $rel . '"';
}
$desc = wp_specialchars($row->link_description, ENT_QUOTES);
$name = wp_specialchars($row->link_name, ENT_QUOTES);
$title = $desc;
if ($show_updated) {
@ -231,25 +230,23 @@ function get_links($category = -1, $before = '', $after = '<br />',
}
if ('' != $title) {
$title = " title='$title'";
$title = ' title="' . $title . '"';
}
$alt = " alt='$name'";
$alt = ' alt="' . $name . '"';
$target = $row->link_target;
if ('' != $target) {
$target = " target='$target'";
$target = ' target="' . $target . '"';
}
$output.= "<a href='$the_link'";
$output.= $rel . $title . $target;
$output.= '>';
$output .= '<a href="' . $the_link . '"' . $rel . $title . $target. '>';
if (($row->link_image != null) && $show_images) {
if (strstr($row->link_image, 'http'))
$output.= "<img src='$row->link_image' $alt $title />";
$output .= "<img src=\"$row->link_image\" $alt $title />";
else // If it's a relative path
$output.= "<img src='" . get_settings('siteurl') . "$row->link_image' $alt $title />";
$output .= "<img src=\"" . get_settings('siteurl') . "$row->link_image\" $alt $title />";
} else {
$output .= $name;
}