Changeset 6088 for trunk/wp-includes/bookmark-template.php
- Timestamp:
- 09/12/2007 01:01:48 AM (18 years ago)
- File:
-
- 1 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 = '' ) {
Note: See TracChangeset
for help on using the changeset viewer.