1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566
|
<?php
/** function get_linksbyname()
** Gets the links associated with category 'cat_name'.
** Parameters:
** cat_name (default 'noname') - The category name to use. If no
** match is found uses all
** 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
** 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 = '<br />',
$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, $args = '') {
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) {
return;
}
if (empty($args)) {
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));
} else {
$args = add_query_arg('category', $cat->cat_id, $args);
wp_get_links($args);
}
} // end wp_get_linksbyname
/** function wp_get_links()
** Gets the links associated with category n.
** Parameters:
** category (no default) - The category to use.
** or:
** a query string
**/
function wp_get_links($args = '') {
global $wpdb;
if (!empty($args) && false === strpos($args, '=')) {
// If args is not a query string, it's a category id.
$category = $args;
$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));
}
} else {
parse_str($args);
if (! isset($category)) $category = -1;
if (! isset($before)) $before = '';
if (! isset($after)) $after = '<br />';
if (! isset($between)) $between = ' ';
if (! isset($show_images)) $show_images = true;
if (! isset($orderby)) $orderby = 'name';
if (! isset($show_description)) $show_description = true;
if (! isset($show_rating)) $show_rating = false;
if (! isset($limit)) $limit = -1;
if (! isset($show_updated)) $show_updated = 1;
if (! isset($echo)) $echo = true;
return get_links($category, $before, $after, $between, $show_images, $orderby, $show_description, $show_rating, $limit, $show_updated, $echo);
}
} // 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 '<br />') - the html to output after the link
** between (default ' ') - the html to output between the link/image
** 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
** 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
** 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) {
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 . $direction;
/* The next 2 lines implement LIMIT TO processing */
if ($limit != -1)
$sql .= " LIMIT $limit";
$results = $wpdb->get_results($sql);
if (!$results) {
return;
}
$output = '';
foreach ($results as $row) {
if (!isset($row->recently_updated)) $row->recently_updated = false;
$output .= $before;
if ($show_updated && $row->recently_updated) {
$output .= get_settings('links_recently_updated_prepend');
}
$the_link = '#';
if (!empty($row->link_url))
$the_link = clean_url($row->link_url);
$rel = $row->link_rel;
if ($rel != '') {
$rel = ' rel="' . $rel . '"';
}
$desc = attribute_escape($row->link_description);
$name = attribute_escape($row->link_name);
$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 . '"';
}
$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 />";
else // If it's a relative path
$output .= "<img src=\"" . get_settings('siteurl') . "$row->link_image\" $alt $title />";
} else {
$output .= $name;
}
$output .= '</a>';
if ($show_updated && $row->recently_updated) {
$output .= get_settings('links_recently_updated_append');
}
if ($show_description && ($desc != '')) {
$output .= $between . $desc;
}
$output .= "$after\n";
} // end while
if ($echo) {
echo $output;
} else {
return $output;
}
}
/** 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 '<li>'.$link->link_name.'</li>';
** }
**/
function get_linkobjectsbyname($cat_name = "noname" , $orderby = 'name', $limit = -1) {
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;
}
}
return get_linkobjects($cat_id, $orderby, $limit);
}
/** function get_linkobjects()
** Gets an array of link objects associated with category n.
** Parameters:
** category (default -1) - The category to use. If no category supplied
** 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_linkobjects(1);
** if ($links) {
** foreach ($links as $link) {
** echo '<li>'.$link->link_name.'<br />'.$link->link_description.'</li>';
** }
** }
** Fields are:
** link_id
** link_url
** link_name
** link_image
** link_target
** link_category
** link_description
** link_visible
** link_owner
** link_rating
** link_updated
** link_rel
** link_notes
**/
function get_linkobjects($category = -1, $orderby = 'name', $limit = -1) {
global $wpdb;
$sql = "SELECT * FROM $wpdb->links WHERE link_visible = 'Y'";
if ($category != -1) {
$sql .= " AND link_category = $category ";
}
if ($orderby == '')
$orderby = 'id';
if (substr($orderby,0,1) == '_') {
$direction = ' DESC';
$orderby = substr($orderby,1);
}
if (strcasecmp('rand',$orderby) == 0) {
$orderby = 'rand()';
} else {
$orderby = " link_" . $orderby;
}
$sql .= ' ORDER BY ' . $orderby;
$sql .= $direction;
/* The next 2 lines implement LIMIT TO processing */
if ($limit != -1)
$sql .= " LIMIT $limit";
$results = $wpdb->get_results($sql);
if ($results) {
foreach ($results as $result) {
$result->link_url = $result->link_url;
$result->link_name = $result->link_name;
$result->link_description = $result->link_description;
$result->link_notes = $result->link_notes;
$newresults[] = $result;
}
}
return $newresults;
}
function get_linkrating($link) {
return apply_filters('link_rating', $link->link_rating);
}
/** function get_linksbyname_withrating()
** Gets the links associated with category 'cat_name' and display rating stars/chars.
** Parameters:
** cat_name (default 'noname') - The category name to use. If no
** match is found uses all
** 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
** show_images (default true) - whether to show images (if defined).
** orderby (default 'id') - the order to output the links. E.g. 'id', 'name',
** 'url' or 'description'. 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
** 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_withrating($cat_name = "noname", $before = '',
$after = '<br />', $between = " ",
$show_images = true, $orderby = 'id',
$show_description = true, $limit = -1, $show_updated = 0) {
get_linksbyname($cat_name, $before, $after, $between, $show_images,
$orderby, $show_description, true, $limit, $show_updated);
}
/** function get_links_withrating()
** Gets the links associated with category n and display rating stars/chars.
** 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 '<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
** show_images (default true) - whether to show images (if defined).
** orderby (default 'id') - the order to output the links. E.g. 'id', 'name',
** 'url' or 'description'. 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 .
** 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_withrating($category = -1, $before = '', $after = '<br />',
$between = " ", $show_images = true,
$orderby = 'id', $show_description = true,
$limit = -1, $show_updated = 0) {
get_links($category, $before, $after, $between, $show_images, $orderby,
$show_description, true, $limit, $show_updated);
}
/** function get_linkcatname()
** Gets the name of category n.
** Parameters: id (default 0) - The category to get. If no category supplied
** uses 0
*/
function get_linkcatname($id = 0) {
$id = (int) $id;
global $wpdb;
$cat_name = '';
if ( !empty($id) ) {
$cat_name = $wpdb->get_var("SELECT cat_name FROM $wpdb->linkcategories WHERE cat_id=$id");
}
return $cat_name;
}
/** function get_get_autotoggle()
** Gets the auto_toggle setting of category n.
** Parameters: id (default 0) - The category to get. If no category supplied
** uses 0
*/
function get_autotoggle($id = 0) {
global $wpdb;
$auto_toggle = $wpdb->get_var("SELECT auto_toggle FROM $wpdb->linkcategories WHERE cat_id=$id");
if ('' == $auto_toggle)
$auto_toggle = 'N';
return $auto_toggle;
}
/** function links_popup_script()
** This function contributed by Fullo -- http://sprite.csr.unibo.it/fullo/
** Show the link to the links popup and the number of links
** Parameters:
** text (default Links) - the text of the link
** width (default 400) - the width of the popup window
** height (default 400) - the height of the popup window
** file (default linkspopup.php) - the page to open in the popup window
** count (default true) - the number of links in the db
*/
function links_popup_script($text = 'Links', $width=400, $height=400,
$file='links.all.php', $count = true) {
if ($count == true) {
$counts = $wpdb->get_var("SELECT count(*) FROM $wpdb->links");
}
$javascript = "<a href=\"#\" " .
" onclick=\"javascript:window.open('$file?popup=1', '_blank', " .
"'width=$width,height=$height,scrollbars=yes,status=no'); " .
" return false\">";
$javascript .= $text;
if ($count == true) {
$javascript .= " ($counts)";
}
$javascript .="</a>\n\n";
echo $javascript;
}
/*
* function get_links_list()
*
* added by Dougal
*
* Output a list of all links, listed by category, using the
* settings in $wpdb->linkcategories and output it as a nested
* HTML unordered list.
*
* Parameters:
* order (default 'name') - Sort link categories by 'name' or 'id'
* hide_if_empty (default true) - Supress listing empty link categories
*/
function get_links_list($order = 'name', $hide_if_empty = 'obsolete') {
global $wpdb;
$order = strtolower($order);
// Handle link category sorting
if (substr($order,0,1) == '_') {
$direction = ' DESC';
$order = substr($order,1);
}
// if 'name' wasn't specified, assume 'id':
$cat_order = ('name' == $order) ? 'cat_name' : 'cat_id';
if (!isset($direction)) $direction = '';
// Fetch the link category data as an array of hashesa
$cats = $wpdb->get_results("
SELECT DISTINCT link_category, cat_name, show_images,
show_description, show_rating, show_updated, sort_order,
sort_desc, list_limit
FROM `$wpdb->links`
LEFT JOIN `$wpdb->linkcategories` ON (link_category = cat_id)
WHERE link_visible = 'Y'
AND list_limit <> 0
ORDER BY $cat_order $direction ", ARRAY_A);
// Display each category
if ($cats) {
foreach ($cats as $cat) {
// Handle each category.
// First, fix the sort_order info
$orderby = $cat['sort_order'];
$orderby = (bool_from_yn($cat['sort_desc'])?'_':'') . $orderby;
// Display the category name
echo ' <li id="linkcat-' . $cat['link_category'] . '"><h2>' . $cat['cat_name'] . "</h2>\n\t<ul>\n";
// Call get_links() with all the appropriate params
get_links($cat['link_category'],
'<li>',"</li>","\n",
bool_from_yn($cat['show_images']),
$orderby,
bool_from_yn($cat['show_description']),
bool_from_yn($cat['show_rating']),
$cat['list_limit'],
bool_from_yn($cat['show_updated']));
// Close the last category
echo "\n\t</ul>\n</li>\n";
}
}
}
?>
|