Changeset 6088
- Timestamp:
- 09/12/2007 01:01:48 AM (18 years ago)
- Location:
- trunk/wp-includes
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/bookmark-template.php
r6026 r6088 1 1 <?php 2 3 /** function wp_get_links()4 ** Gets the links associated with category n.5 ** Parameters:6 ** category (no default) - The category to use.7 ** or:8 ** a query string9 **/10 function wp_get_links($args = '') {11 global $wpdb;12 13 if ( strpos( $args, '=' ) === false ) {14 $cat_id = $args;15 $args = add_query_arg( 'category', $cat_id, $args );16 }17 18 $defaults = array(19 'category' => -1, 'before' => '',20 'after' => '<br />', 'between' => ' ',21 'show_images' => true, 'orderby' => 'name',22 'show_description' => true, 'show_rating' => false,23 'limit' => -1, 'show_updated' => true,24 'echo' => true25 );26 27 $r = wp_parse_args( $args, $defaults );28 extract( $r, EXTR_SKIP );29 30 return get_links($category, $before, $after, $between, $show_images, $orderby, $show_description, $show_rating, $limit, $show_updated, $echo);31 } // end wp_get_links32 33 /** function get_links()34 ** Gets the links associated with category n.35 ** Parameters:36 ** category (default -1) - The category to use. If no category supplied37 ** uses all38 ** before (default '') - the html to output before the link39 ** after (default '<br />') - the html to output after the link40 ** between (default ' ') - the html to output between the link/image41 ** and its description. Not used if no image or show_images == true42 ** show_images (default true) - whether to show images (if defined).43 ** orderby (default 'id') - the order to output the links. E.g. 'id', 'name',44 ** 'url', 'description', or 'rating'. Or maybe owner. If you start the45 ** name with an underscore the order will be reversed.46 ** You can also specify 'rand' as the order which will return links in a47 ** random order.48 ** show_description (default true) - whether to show the description if49 ** show_images=false/not defined .50 ** show_rating (default false) - show rating stars/chars51 ** limit (default -1) - Limit to X entries. If not specified, all entries52 ** are shown.53 ** show_updated (default 0) - whether to show last updated timestamp54 ** echo (default true) - whether to echo the results, or return them instead55 */56 function get_links($category = -1,57 $before = '',58 $after = '<br />',59 $between = ' ',60 $show_images = true,61 $orderby = 'name',62 $show_description = true,63 $show_rating = false,64 $limit = -1,65 $show_updated = 1,66 $echo = true) {67 68 global $wpdb;69 70 $order = 'ASC';71 if ( substr($orderby, 0, 1) == '_' ) {72 $order = 'DESC';73 $orderby = substr($orderby, 1);74 }75 76 if ( $category == -1 ) //get_bookmarks uses '' to signify all categories77 $category = '';78 79 $results = get_bookmarks("category=$category&orderby=$orderby&order=$order&show_updated=$show_updated&limit=$limit");80 81 if ( !$results )82 return;83 84 $output = '';85 86 foreach ( (array) $results as $row ) {87 if ( !isset($row->recently_updated) )88 $row->recently_updated = false;89 $output .= $before;90 if ( $show_updated && $row->recently_updated )91 $output .= get_option('links_recently_updated_prepend');92 $the_link = '#';93 if ( !empty($row->link_url) )94 $the_link = clean_url($row->link_url);95 $rel = $row->link_rel;96 if ( '' != $rel )97 $rel = ' rel="' . $rel . '"';98 99 $desc = attribute_escape($row->link_description);100 $name = attribute_escape($row->link_name);101 $title = $desc;102 103 if ( $show_updated )104 if (substr($row->link_updated_f, 0, 2) != '00')105 $title .= ' ('.__('Last updated') . ' ' . date(get_option('links_updated_date_format'), $row->link_updated_f + (get_option('gmt_offset') * 3600)) . ')';106 107 if ( '' != $title )108 $title = ' title="' . $title . '"';109 110 $alt = ' alt="' . $name . '"';111 112 $target = $row->link_target;113 if ( '' != $target )114 $target = ' target="' . $target . '"';115 116 $output .= '<a href="' . $the_link . '"' . $rel . $title . $target. '>';117 118 if ( $row->link_image != null && $show_images ) {119 if ( strpos($row->link_image, 'http') !== false )120 $output .= "<img src=\"$row->link_image\" $alt $title />";121 else // If it's a relative path122 $output .= "<img src=\"" . get_option('siteurl') . "$row->link_image\" $alt $title />";123 } else {124 $output .= $name;125 }126 127 $output .= '</a>';128 129 if ( $show_updated && $row->recently_updated )130 $output .= get_option('links_recently_updated_append');131 132 if ( $show_description && '' != $desc )133 $output .= $between . $desc;134 135 if ($show_rating) {136 $output .= $between . get_linkrating($row);137 }138 139 $output .= "$after\n";140 } // end while141 142 if ( !$echo )143 return $output;144 echo $output;145 }146 147 function get_linkrating($link) {148 return apply_filters('link_rating', $link->link_rating);149 }150 151 /** function get_linkcatname()152 ** Gets the name of category n.153 ** Parameters: id (default 0) - The category to get. If no category supplied154 ** uses 0155 */156 function get_linkcatname($id = 0) {157 $id = (int) $id;158 159 if ( empty($id) )160 return '';161 162 $cats = wp_get_link_cats($id);163 164 if ( empty($cats) || ! is_array($cats) )165 return '';166 167 $cat_id = (int) $cats[0]; // Take the first cat.168 169 $cat = get_category($cat_id);170 return $cat->name;171 }172 173 /** function links_popup_script()174 ** This function contributed by Fullo -- http://sprite.csr.unibo.it/fullo/175 ** Show the link to the links popup and the number of links176 ** Parameters:177 ** text (default Links) - the text of the link178 ** width (default 400) - the width of the popup window179 ** height (default 400) - the height of the popup window180 ** file (default linkspopup.php) - the page to open in the popup window181 ** count (default true) - the number of links in the db182 */183 function links_popup_script($text = 'Links', $width=400, $height=400, $file='links.all.php', $count = true) {184 if ( $count )185 $counts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->links");186 187 $javascript = "<a href=\"#\" onclick=\"javascript:window.open('$file?popup=1', '_blank', 'width=$width,height=$height,scrollbars=yes,status=no'); return false\">";188 $javascript .= $text;189 190 if ( $count )191 $javascript .= " ($counts)";192 193 $javascript .= "</a>\n\n";194 echo $javascript;195 }196 197 198 /*199 * function get_links_list()200 *201 * added by Dougal202 *203 * Output a list of all links, listed by category, using the204 * settings in $wpdb->linkcategories and output it as a nested205 * HTML unordered list.206 *207 * Parameters:208 * order (default 'name') - Sort link categories by 'name' or 'id'209 * hide_if_empty (default true) - Supress listing empty link categories210 */211 function get_links_list($order = 'name', $hide_if_empty = 'obsolete') {212 $order = strtolower($order);213 214 // Handle link category sorting215 $direction = 'ASC';216 if ( '_' == substr($order,0,1) ) {217 $direction = 'DESC';218 $order = substr($order,1);219 }220 221 if ( !isset($direction) )222 $direction = '';223 224 $cats = get_categories("type=link&orderby=$order&order=$direction&hierarchical=0");225 226 // Display each category227 if ( $cats ) {228 foreach ( (array) $cats as $cat ) {229 // Handle each category.230 231 // Display the category name232 echo ' <li id="linkcat-' . $cat->term_id . '" class="linkcat"><h2>' . $cat->name . "</h2>\n\t<ul>\n";233 // Call get_links() with all the appropriate params234 get_links($cat->term_id, '<li>', "</li>", "\n", true, 'name', false);235 236 // Close the last category237 echo "\n\t</ul>\n</li>\n";238 }239 }240 }241 2 242 3 function _walk_bookmarks($bookmarks, $args = '' ) { -
trunk/wp-includes/deprecated.php
r5910 r6088 490 490 } 491 491 492 /** function wp_get_links() 493 ** Gets the links associated with category n. 494 ** Parameters: 495 ** category (no default) - The category to use. 496 ** or: 497 ** a query string 498 **/ 499 function wp_get_links($args = '') { 500 global $wpdb; 501 502 if ( strpos( $args, '=' ) === false ) { 503 $cat_id = $args; 504 $args = add_query_arg( 'category', $cat_id, $args ); 505 } 506 507 $defaults = array( 508 'category' => -1, 'before' => '', 509 'after' => '<br />', 'between' => ' ', 510 'show_images' => true, 'orderby' => 'name', 511 'show_description' => true, 'show_rating' => false, 512 'limit' => -1, 'show_updated' => true, 513 'echo' => true 514 ); 515 516 $r = wp_parse_args( $args, $defaults ); 517 extract( $r, EXTR_SKIP ); 518 519 return get_links($category, $before, $after, $between, $show_images, $orderby, $show_description, $show_rating, $limit, $show_updated, $echo); 520 } // end wp_get_links 521 522 /** function get_links() 523 ** Gets the links associated with category n. 524 ** Parameters: 525 ** category (default -1) - The category to use. If no category supplied 526 ** uses all 527 ** before (default '') - the html to output before the link 528 ** after (default '<br />') - the html to output after the link 529 ** between (default ' ') - the html to output between the link/image 530 ** and its description. Not used if no image or show_images == true 531 ** show_images (default true) - whether to show images (if defined). 532 ** orderby (default 'id') - the order to output the links. E.g. 'id', 'name', 533 ** 'url', 'description', or 'rating'. Or maybe owner. If you start the 534 ** name with an underscore the order will be reversed. 535 ** You can also specify 'rand' as the order which will return links in a 536 ** random order. 537 ** show_description (default true) - whether to show the description if 538 ** show_images=false/not defined . 539 ** show_rating (default false) - show rating stars/chars 540 ** limit (default -1) - Limit to X entries. If not specified, all entries 541 ** are shown. 542 ** show_updated (default 0) - whether to show last updated timestamp 543 ** echo (default true) - whether to echo the results, or return them instead 544 */ 545 function get_links($category = -1, 546 $before = '', 547 $after = '<br />', 548 $between = ' ', 549 $show_images = true, 550 $orderby = 'name', 551 $show_description = true, 552 $show_rating = false, 553 $limit = -1, 554 $show_updated = 1, 555 $echo = true) { 556 557 global $wpdb; 558 559 $order = 'ASC'; 560 if ( substr($orderby, 0, 1) == '_' ) { 561 $order = 'DESC'; 562 $orderby = substr($orderby, 1); 563 } 564 565 if ( $category == -1 ) //get_bookmarks uses '' to signify all categories 566 $category = ''; 567 568 $results = get_bookmarks("category=$category&orderby=$orderby&order=$order&show_updated=$show_updated&limit=$limit"); 569 570 if ( !$results ) 571 return; 572 573 $output = ''; 574 575 foreach ( (array) $results as $row ) { 576 if ( !isset($row->recently_updated) ) 577 $row->recently_updated = false; 578 $output .= $before; 579 if ( $show_updated && $row->recently_updated ) 580 $output .= get_option('links_recently_updated_prepend'); 581 $the_link = '#'; 582 if ( !empty($row->link_url) ) 583 $the_link = clean_url($row->link_url); 584 $rel = $row->link_rel; 585 if ( '' != $rel ) 586 $rel = ' rel="' . $rel . '"'; 587 588 $desc = attribute_escape($row->link_description); 589 $name = attribute_escape($row->link_name); 590 $title = $desc; 591 592 if ( $show_updated ) 593 if (substr($row->link_updated_f, 0, 2) != '00') 594 $title .= ' ('.__('Last updated') . ' ' . date(get_option('links_updated_date_format'), $row->link_updated_f + (get_option('gmt_offset') * 3600)) . ')'; 595 596 if ( '' != $title ) 597 $title = ' title="' . $title . '"'; 598 599 $alt = ' alt="' . $name . '"'; 600 601 $target = $row->link_target; 602 if ( '' != $target ) 603 $target = ' target="' . $target . '"'; 604 605 $output .= '<a href="' . $the_link . '"' . $rel . $title . $target. '>'; 606 607 if ( $row->link_image != null && $show_images ) { 608 if ( strpos($row->link_image, 'http') !== false ) 609 $output .= "<img src=\"$row->link_image\" $alt $title />"; 610 else // If it's a relative path 611 $output .= "<img src=\"" . get_option('siteurl') . "$row->link_image\" $alt $title />"; 612 } else { 613 $output .= $name; 614 } 615 616 $output .= '</a>'; 617 618 if ( $show_updated && $row->recently_updated ) 619 $output .= get_option('links_recently_updated_append'); 620 621 if ( $show_description && '' != $desc ) 622 $output .= $between . $desc; 623 624 if ($show_rating) { 625 $output .= $between . get_linkrating($row); 626 } 627 628 $output .= "$after\n"; 629 } // end while 630 631 if ( !$echo ) 632 return $output; 633 echo $output; 634 } 635 636 /* 637 * function get_links_list() 638 * 639 * added by Dougal 640 * 641 * Output a list of all links, listed by category, using the 642 * settings in $wpdb->linkcategories and output it as a nested 643 * HTML unordered list. 644 * 645 * Parameters: 646 * order (default 'name') - Sort link categories by 'name' or 'id' 647 * hide_if_empty (default true) - Supress listing empty link categories 648 */ 649 function get_links_list($order = 'name', $hide_if_empty = 'obsolete') { 650 $order = strtolower($order); 651 652 // Handle link category sorting 653 $direction = 'ASC'; 654 if ( '_' == substr($order,0,1) ) { 655 $direction = 'DESC'; 656 $order = substr($order,1); 657 } 658 659 if ( !isset($direction) ) 660 $direction = ''; 661 662 $cats = get_categories("type=link&orderby=$order&order=$direction&hierarchical=0"); 663 664 // Display each category 665 if ( $cats ) { 666 foreach ( (array) $cats as $cat ) { 667 // Handle each category. 668 669 // Display the category name 670 echo ' <li id="linkcat-' . $cat->term_id . '" class="linkcat"><h2>' . $cat->name . "</h2>\n\t<ul>\n"; 671 // Call get_links() with all the appropriate params 672 get_links($cat->term_id, '<li>', "</li>", "\n", true, 'name', false); 673 674 // Close the last category 675 echo "\n\t</ul>\n</li>\n"; 676 } 677 } 678 } 679 680 681 /** function links_popup_script() 682 ** This function contributed by Fullo -- http://sprite.csr.unibo.it/fullo/ 683 ** Show the link to the links popup and the number of links 684 ** Parameters: 685 ** text (default Links) - the text of the link 686 ** width (default 400) - the width of the popup window 687 ** height (default 400) - the height of the popup window 688 ** file (default linkspopup.php) - the page to open in the popup window 689 ** count (default true) - the number of links in the db 690 */ 691 function links_popup_script($text = 'Links', $width=400, $height=400, $file='links.all.php', $count = true) { 692 if ( $count ) 693 $counts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->links"); 694 695 $javascript = "<a href=\"#\" onclick=\"javascript:window.open('$file?popup=1', '_blank', 'width=$width,height=$height,scrollbars=yes,status=no'); return false\">"; 696 $javascript .= $text; 697 698 if ( $count ) 699 $javascript .= " ($counts)"; 700 701 $javascript .= "</a>\n\n"; 702 echo $javascript; 703 } 704 705 706 function get_linkrating($link) { 707 return apply_filters('link_rating', $link->link_rating); 708 } 709 710 /** function get_linkcatname() 711 ** Gets the name of category n. 712 ** Parameters: id (default 0) - The category to get. If no category supplied 713 ** uses 0 714 */ 715 function get_linkcatname($id = 0) { 716 $id = (int) $id; 717 718 if ( empty($id) ) 719 return ''; 720 721 $cats = wp_get_link_cats($id); 722 723 if ( empty($cats) || ! is_array($cats) ) 724 return ''; 725 726 $cat_id = (int) $cats[0]; // Take the first cat. 727 728 $cat = get_category($cat_id); 729 return $cat->name; 730 } 731 492 732 ?>
Note: See TracChangeset
for help on using the changeset viewer.