') - 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
** 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
** name with an underscore the order will be reversed.
** You can also specify 'rand' as the order which will return links in a
** random order.
** show_description (default true) - whether to show the description if
** show_images=false/not defined
** show_rating (default false) - show rating stars/chars
** limit (default -1) - Limit to X entries. If not specified, all entries
** are shown.
** show_updated (default 0) - whether to show last updated timestamp
*/
function get_linksbyname($cat_name = "noname", $before = '', $after = '
',
$between = " ", $show_images = true, $orderby = 'id',
$show_description = true, $show_rating = false,
$limit = -1, $show_updated = 0) {
global $wpdb;
$cat_id = -1;
$results = $wpdb->get_results("SELECT cat_id FROM $wpdb->linkcategories WHERE cat_name='$cat_name'");
if ($results) {
foreach ($results as $result) {
$cat_id = $result->cat_id;
}
}
get_links($cat_id, $before, $after, $between, $show_images, $orderby,
$show_description, $show_rating, $limit, $show_updated);
}
function bool_from_yn($yn) {
if ($yn == 'Y') return 1;
return 0;
}
/** function wp_get_linksbyname()
** Gets the links associated with the named category.
** Parameters:
** category (no default) - The category to use.
**/
function wp_get_linksbyname($category) {
global $wpdb;
$cat = $wpdb->get_row("SELECT cat_id, cat_name, auto_toggle, show_images, show_description, "
. " show_rating, show_updated, sort_order, sort_desc, text_before_link, text_after_link, "
. " text_after_all, list_limit FROM $wpdb->linkcategories WHERE cat_name='$category'");
if ($cat) {
if ($cat->sort_desc == 'Y') {
$cat->sort_order = '_'.$cat->sort_order;
}
get_links($cat->cat_id, $cat->text_before_link, $cat->text_after_all,
$cat->text_after_link, bool_from_yn($cat->show_images), $cat->sort_order,
bool_from_yn($cat->show_description), bool_from_yn($cat->show_rating),
$cat->list_limit, bool_from_yn($cat->show_updated));
}
} // end wp_get_linksbyname
/** function wp_get_links()
** Gets the links associated with category n.
** Parameters:
** category (no default) - The category to use.
**/
function wp_get_links($category) {
global $wpdb;
$cat = $wpdb->get_row("SELECT cat_id, cat_name, auto_toggle, show_images, show_description, "
. " show_rating, show_updated, sort_order, sort_desc, text_before_link, text_after_link, "
. " text_after_all, list_limit FROM $wpdb->linkcategories WHERE cat_id=$category");
if ($cat) {
if ($cat->sort_desc == 'Y') {
$cat->sort_order = '_'.$cat->sort_order;
}
get_links($cat->cat_id, $cat->text_before_link, $cat->text_after_all,
$cat->text_after_link, bool_from_yn($cat->show_images), $cat->sort_order,
bool_from_yn($cat->show_description), bool_from_yn($cat->show_rating),
$cat->list_limit, bool_from_yn($cat->show_updated));
}
} // end wp_get_links
/** function get_links()
** Gets the links associated with category n.
** Parameters:
** category (default -1) - The category to use. If no category supplied
** uses all
** before (default '') - the html to output before the link
** after (default '
') - 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
** 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
** name with an underscore the order will be reversed.
** You can also specify 'rand' as the order which will return links in a
** random order.
** show_description (default true) - whether to show the description if
** show_images=false/not defined .
** show_rating (default false) - show rating stars/chars
** limit (default -1) - Limit to X entries. If not specified, all entries
** are shown.
** show_updated (default 0) - whether to show last updated timestamp
*/
function get_links($category = -1, $before = '', $after = '
',
$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 = "";
if ($category != -1) {
$category_query = " AND link_category = $category ";
}
if (get_settings('links_recently_updated_time')) {
$recently_updated_test = ", IF (DATE_ADD(link_updated, INTERVAL ".get_settings('links_recently_updated_time')." MINUTE) >= NOW(), 1,0) as recently_updated ";
} else {
$recently_updated_test = '';
}
if ($show_updated) {
$get_updated = ", UNIX_TIMESTAMP(link_updated) AS link_updated_f ";
}
$orderby=strtolower($orderby);
if ($orderby == '')
$orderby = 'id';
if (substr($orderby,0,1) == '_') {
$direction = ' DESC';
$orderby = substr($orderby,1);
}
switch($orderby) {
case 'length':
$length = ",CHAR_LENGTH(link_name) AS length";
break;
case 'rand':
$orderby = 'rand()';
break;
default:
$orderby = " link_" . $orderby;
}
if (!isset($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;
/* The next 2 lines implement LIMIT TO processing */
if ($limit != -1)
$sql .= " LIMIT $limit";
//echo $sql;
$results = $wpdb->get_results($sql);
if (!$results) {
return;
}
foreach ($results as $row) {
if (!isset($row->recently_updated)) $row->recently_updated = false;
echo($before);
if ($show_updated && $row->recently_updated) {
echo get_settings('links_recently_updated_prepend');
}
$the_link = '#';
if (($row->link_url != null) && ($row->link_url != '')) {
$the_link = htmlspecialchars($row->link_url);
}
$rel = $row->link_rel;
if ($rel != '') {
$rel = " rel='$rel'";
}
$desc = htmlspecialchars($row->link_description, ENT_QUOTES);
$name = htmlspecialchars($row->link_name, ENT_QUOTES);
$title = $desc;
if ($show_updated) {
if (substr($row->link_updated_f,0,2) != '00') {
$title .= ' (Last updated ' . date(get_settings('links_updated_date_format'), $row->link_updated_f + (get_settings('gmt_offset') * 3600)) .')';
}
}
if ('' != $title) {
$title = " title='$title'";
}
$alt = " alt='$name'";
$target = $row->link_target;
if ('' != $target) {
$target = " target='$target'";
}
echo("');
if (($row->link_image != null) && $show_images) {
if (strstr($row->link_image, 'http'))
echo "";
else // If it's a relative path
echo "link_image' $alt $title />";
} else {
echo($name);
}
echo('');
if ($show_updated && $row->recently_updated) {
echo get_settings('links_recently_updated_append');
}
if ($show_description && ($desc != '')) {
echo($between.$desc);
}
echo("$after\n");
} // end while
}
/** function get_linkobjectsbyname()
** Gets an array of link objects associated with category 'cat_name'.
** Parameters:
** cat_name (default 'noname') - The category name to use. If no
** match is found uses all
** orderby (default 'id') - the order to output the links. E.g. 'id', 'name',
** 'url', 'description', or 'rating'. Or maybe owner. If you start the
** name with an underscore the order will be reversed.
** You can also specify 'rand' as the order which will return links in a
** random order.
** limit (default -1) - Limit to X entries. If not specified, all entries
** are shown.
**
** Use this like:
** $links = get_linkobjectsbyname('fred');
** foreach ($links as $link) {
** echo '