]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/deprecated.php
Wordpress 2.3.2
[autoinstalls/wordpress.git] / wp-includes / deprecated.php
1 <?php
2
3 /*
4  * Deprecated global variables.
5  */
6
7 $tableposts = $wpdb->posts;
8 $tableusers = $wpdb->users;
9 $tablecategories = $wpdb->categories;
10 $tablepost2cat = $wpdb->post2cat;
11 $tablecomments = $wpdb->comments;
12 $tablelinks = $wpdb->links;
13 $tablelinkcategories = 'linkcategories_is_gone';
14 $tableoptions = $wpdb->options;
15 $tablepostmeta = $wpdb->postmeta;
16
17 /*
18  * Deprecated functions come here to die.
19  */
20
21 // Use get_post().
22 function get_postdata($postid) {
23         $post = &get_post($postid);
24
25         $postdata = array (
26                 'ID' => $post->ID,
27                 'Author_ID' => $post->post_author,
28                 'Date' => $post->post_date,
29                 'Content' => $post->post_content,
30                 'Excerpt' => $post->post_excerpt,
31                 'Title' => $post->post_title,
32                 'Category' => $post->post_category,
33                 'post_status' => $post->post_status,
34                 'comment_status' => $post->comment_status,
35                 'ping_status' => $post->ping_status,
36                 'post_password' => $post->post_password,
37                 'to_ping' => $post->to_ping,
38                 'pinged' => $post->pinged,
39                 'post_type' => $post->post_type,
40                 'post_name' => $post->post_name
41         );
42
43         return $postdata;
44 }
45
46 // Use the new post loop.
47 function start_wp() {
48         global $wp_query, $post;
49
50         // Since the old style loop is being used, advance the query iterator here.
51         $wp_query->next_post();
52
53         setup_postdata($post);
54 }
55
56 function the_category_ID($echo = true) {
57         // Grab the first cat in the list.
58         $categories = get_the_category();
59         $cat = $categories[0]->term_id;
60
61         if ( $echo )
62                 echo $cat;
63
64         return $cat;
65 }
66
67 function the_category_head($before='', $after='') {
68         global $currentcat, $previouscat;
69         // Grab the first cat in the list.
70         $categories = get_the_category();
71         $currentcat = $categories[0]->category_id;
72         if ( $currentcat != $previouscat ) {
73                 echo $before;
74                 echo get_the_category_by_ID($currentcat);
75                 echo $after;
76                 $previouscat = $currentcat;
77         }
78 }
79
80 // Use previous_post_link().
81 function previous_post($format='%', $previous='previous post: ', $title='yes', $in_same_cat='no', $limitprev=1, $excluded_categories='') {
82
83         if ( empty($in_same_cat) || 'no' == $in_same_cat )
84                 $in_same_cat = false;
85         else
86                 $in_same_cat = true;
87
88         $post = get_previous_post($in_same_cat, $excluded_categories);
89
90         if ( !$post )
91                 return;
92
93         $string = '<a href="'.get_permalink($post->ID).'">'.$previous;
94         if ( 'yes' == $title )
95                 $string .= apply_filters('the_title', $post->post_title, $post);
96         $string .= '</a>';
97         $format = str_replace('%', $string, $format);
98         echo $format;
99 }
100
101 // Use next_post_link().
102 function next_post($format='%', $next='next post: ', $title='yes', $in_same_cat='no', $limitnext=1, $excluded_categories='') {
103
104         if ( empty($in_same_cat) || 'no' == $in_same_cat )
105                 $in_same_cat = false;
106         else
107                 $in_same_cat = true;
108
109         $post = get_next_post($in_same_cat, $excluded_categories);
110
111         if ( !$post     )
112                 return;
113
114         $string = '<a href="'.get_permalink($post->ID).'">'.$next;
115         if ( 'yes' == $title )
116                 $string .= apply_filters('the_title', $post->post_title, $nextpost);
117         $string .= '</a>';
118         $format = str_replace('%', $string, $format);
119         echo $format;
120 }
121
122 //
123 // Use current_user_can() for these.
124 //
125
126 /* returns true if $user_id can create a new post */
127 function user_can_create_post($user_id, $blog_id = 1, $category_id = 'None') {
128         $author_data = get_userdata($user_id);
129         return ($author_data->user_level > 1);
130 }
131
132 /* returns true if $user_id can create a new post */
133 function user_can_create_draft($user_id, $blog_id = 1, $category_id = 'None') {
134         $author_data = get_userdata($user_id);
135         return ($author_data->user_level >= 1);
136 }
137
138 /* returns true if $user_id can edit $post_id */
139 function user_can_edit_post($user_id, $post_id, $blog_id = 1) {
140         $author_data = get_userdata($user_id);
141         $post = get_post($post_id);
142         $post_author_data = get_userdata($post->post_author);
143
144         if ( (($user_id == $post_author_data->ID) && !($post->post_status == 'publish' &&  $author_data->user_level < 2))
145                          || ($author_data->user_level > $post_author_data->user_level)
146                          || ($author_data->user_level >= 10) ) {
147                 return true;
148         } else {
149                 return false;
150         }
151 }
152
153 /* returns true if $user_id can delete $post_id */
154 function user_can_delete_post($user_id, $post_id, $blog_id = 1) {
155         // right now if one can edit, one can delete
156         return user_can_edit_post($user_id, $post_id, $blog_id);
157 }
158
159 /* returns true if $user_id can set new posts' dates on $blog_id */
160 function user_can_set_post_date($user_id, $blog_id = 1, $category_id = 'None') {
161         $author_data = get_userdata($user_id);
162         return (($author_data->user_level > 4) && user_can_create_post($user_id, $blog_id, $category_id));
163 }
164
165 /* returns true if $user_id can edit $post_id's date */
166 function user_can_edit_post_date($user_id, $post_id, $blog_id = 1) {
167         $author_data = get_userdata($user_id);
168         return (($author_data->user_level > 4) && user_can_edit_post($user_id, $post_id, $blog_id));
169 }
170
171 /* returns true if $user_id can edit $post_id's comments */
172 function user_can_edit_post_comments($user_id, $post_id, $blog_id = 1) {
173         // right now if one can edit a post, one can edit comments made on it
174         return user_can_edit_post($user_id, $post_id, $blog_id);
175 }
176
177 /* returns true if $user_id can delete $post_id's comments */
178 function user_can_delete_post_comments($user_id, $post_id, $blog_id = 1) {
179         // right now if one can edit comments, one can delete comments
180         return user_can_edit_post_comments($user_id, $post_id, $blog_id);
181 }
182
183 function user_can_edit_user($user_id, $other_user) {
184         $user  = get_userdata($user_id);
185         $other = get_userdata($other_user);
186         if ( $user->user_level > $other->user_level || $user->user_level > 8 || $user->ID == $other->ID )
187                 return true;
188         else
189                 return false;
190 }
191
192 /** function get_linksbyname()
193  ** Gets the links associated with category 'cat_name'.
194  ** Parameters:
195  **   cat_name (default 'noname')  - The category name to use. If no
196  **     match is found uses all
197  **   before (default '')  - the html to output before the link
198  **   after (default '<br />')  - the html to output after the link
199  **   between (default ' ')  - the html to output between the link/image
200  **     and it's description. Not used if no image or show_images == true
201  **   show_images (default true) - whether to show images (if defined).
202  **   orderby (default 'id') - the order to output the links. E.g. 'id', 'name',
203  **     'url', 'description' or 'rating'. Or maybe owner. If you start the
204  **     name with an underscore the order will be reversed.
205  **     You can also specify 'rand' as the order which will return links in a
206  **     random order.
207  **   show_description (default true) - whether to show the description if
208  **     show_images=false/not defined
209  **   show_rating (default false) - show rating stars/chars
210  **   limit (default -1) - Limit to X entries. If not specified, all entries
211  **     are shown.
212  **   show_updated (default 0) - whether to show last updated timestamp
213  */
214 function get_linksbyname($cat_name = "noname", $before = '', $after = '<br />',
215                                                                                                  $between = " ", $show_images = true, $orderby = 'id',
216                                                                                                  $show_description = true, $show_rating = false,
217                                                                                                  $limit = -1, $show_updated = 0) {
218                 global $wpdb;
219                 $cat_id = -1;
220                 $cat = get_term_by('name', $cat_name, 'link_category');
221                 if ( $cat )
222                         $cat_id = $cat->term_id;
223
224                 get_links($cat_id, $before, $after, $between, $show_images, $orderby,
225                                                         $show_description, $show_rating, $limit, $show_updated);
226 }
227
228 /** function wp_get_linksbyname()
229  ** Gets the links associated with the named category.
230  ** Parameters:
231  **   category (no default)  - The category to use.
232  **/
233 function wp_get_linksbyname($category, $args = '') {
234         global $wpdb;
235
236         $cat = get_term_by('name', $cat_name, 'link_category');
237         if ( !$cat )
238                 return false;
239         $cat_id = $cat->term_id;
240
241         $args = add_query_arg('category', $cat_id, $args);
242         wp_get_links($args);
243 }
244
245 /** function get_linkobjectsbyname()
246  ** Gets an array of link objects associated with category 'cat_name'.
247  ** Parameters:
248  **   cat_name (default 'noname')  - The category name to use. If no
249  **     match is found uses all
250  **   orderby (default 'id') - the order to output the links. E.g. 'id', 'name',
251  **     'url', 'description', or 'rating'. Or maybe owner. If you start the
252  **     name with an underscore the order will be reversed.
253  **     You can also specify 'rand' as the order which will return links in a
254  **     random order.
255  **   limit (default -1) - Limit to X entries. If not specified, all entries
256  **     are shown.
257  **
258  ** Use this like:
259  ** $links = get_linkobjectsbyname('fred');
260  ** foreach ($links as $link) {
261  **   echo '<li>'.$link->link_name.'</li>';
262  ** }
263  **/
264 function get_linkobjectsbyname($cat_name = "noname" , $orderby = 'name', $limit = -1) {
265                 global $wpdb;
266                 $cat_id = -1;
267                 $cat = get_term_by('name', $cat_name, 'link_category');
268                 if ( $cat )
269                         $cat_id = $cat->term_id;
270
271                 return get_linkobjects($cat_id, $orderby, $limit);
272 }
273
274 /** function get_linkobjects()
275  ** Gets an array of link objects associated with category n.
276  ** Parameters:
277  **   category (default -1)  - The category to use. If no category supplied
278  **      uses all
279  **   orderby (default 'id') - the order to output the links. E.g. 'id', 'name',
280  **     'url', 'description', or 'rating'. Or maybe owner. If you start the
281  **     name with an underscore the order will be reversed.
282  **     You can also specify 'rand' as the order which will return links in a
283  **     random order.
284  **   limit (default -1) - Limit to X entries. If not specified, all entries
285  **     are shown.
286  **
287  ** Use this like:
288  ** $links = get_linkobjects(1);
289  ** if ($links) {
290  **   foreach ($links as $link) {
291  **     echo '<li>'.$link->link_name.'<br />'.$link->link_description.'</li>';
292  **   }
293  ** }
294  ** Fields are:
295  ** link_id
296  ** link_url
297  ** link_name
298  ** link_image
299  ** link_target
300  ** link_category
301  ** link_description
302  ** link_visible
303  ** link_owner
304  ** link_rating
305  ** link_updated
306  ** link_rel
307  ** link_notes
308  **/
309 // Deprecate in favor of get_linkz().
310 function get_linkobjects($category = 0, $orderby = 'name', $limit = 0) {
311                 global $wpdb;
312
313                 $links = get_bookmarks("category=$category&orderby=$orderby&limit=$limit");
314
315                 $links_array = array();
316                 foreach ($links as $link) {
317                         $links_array[] = $link;
318                 }
319
320                 return $links_array;
321 }
322
323 /** function get_linksbyname_withrating()
324  ** Gets the links associated with category 'cat_name' and display rating stars/chars.
325  ** Parameters:
326  **   cat_name (default 'noname')  - The category name to use. If no
327  **     match is found uses all
328  **   before (default '')  - the html to output before the link
329  **   after (default '<br />')  - the html to output after the link
330  **   between (default ' ')  - the html to output between the link/image
331  **     and it's description. Not used if no image or show_images == true
332  **   show_images (default true) - whether to show images (if defined).
333  **   orderby (default 'id') - the order to output the links. E.g. 'id', 'name',
334  **     'url' or 'description'. Or maybe owner. If you start the
335  **     name with an underscore the order will be reversed.
336  **     You can also specify 'rand' as the order which will return links in a
337  **     random order.
338  **   show_description (default true) - whether to show the description if
339  **     show_images=false/not defined
340  **   limit (default -1) - Limit to X entries. If not specified, all entries
341  **     are shown.
342  **   show_updated (default 0) - whether to show last updated timestamp
343  */
344 function get_linksbyname_withrating($cat_name = "noname", $before = '',
345                                                                                                                                                 $after = '<br />', $between = " ",
346                                                                                                                                                 $show_images = true, $orderby = 'id',
347                                                                                                                                                 $show_description = true, $limit = -1, $show_updated = 0) {
348
349                 get_linksbyname($cat_name, $before, $after, $between, $show_images,
350                                                                                 $orderby, $show_description, true, $limit, $show_updated);
351 }
352
353 /** function get_links_withrating()
354  ** Gets the links associated with category n and display rating stars/chars.
355  ** Parameters:
356  **   category (default -1)  - The category to use. If no category supplied
357  **      uses all
358  **   before (default '')  - the html to output before the link
359  **   after (default '<br />')  - the html to output after the link
360  **   between (default ' ')  - the html to output between the link/image
361  **     and it's description. Not used if no image or show_images == true
362  **   show_images (default true) - whether to show images (if defined).
363  **   orderby (default 'id') - the order to output the links. E.g. 'id', 'name',
364  **     'url' or 'description'. Or maybe owner. If you start the
365  **     name with an underscore the order will be reversed.
366  **     You can also specify 'rand' as the order which will return links in a
367  **     random order.
368  **   show_description (default true) - whether to show the description if
369  **    show_images=false/not defined .
370  **   limit (default -1) - Limit to X entries. If not specified, all entries
371  **     are shown.
372  **   show_updated (default 0) - whether to show last updated timestamp
373  */
374 function get_links_withrating($category = -1, $before = '', $after = '<br />',
375                                                                                                                         $between = " ", $show_images = true,
376                                                                                                                         $orderby = 'id', $show_description = true,
377                                                                                                                         $limit = -1, $show_updated = 0) {
378
379                 get_links($category, $before, $after, $between, $show_images, $orderby,
380                                                         $show_description, true, $limit, $show_updated);
381 }
382
383 /** function get_get_autotoggle()
384  ** Gets the auto_toggle setting of category n.
385  ** Parameters: id (default 0)  - The category to get. If no category supplied
386  **                uses 0
387  */
388 function get_autotoggle($id = 0) {
389         return 0;
390 }
391
392 // Use wp_list_cats().
393 function list_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_order = 'asc', $file = '', $list = true, $optiondates = 0, $optioncount = 0, $hide_empty = 1, $use_desc_for_title = 1, $children=FALSE, $child_of=0, $categories=0, $recurse=0, $feed = '', $feed_image = '', $exclude = '', $hierarchical=FALSE) {
394         $query = compact('optionall', 'all', 'sort_column', 'sort_order', 'file', 'list', 'optiondates', 'optioncount', 'hide_empty', 'use_desc_for_title', 'children',
395                 'child_of', 'categories', 'recurse', 'feed', 'feed_image', 'exclude', 'hierarchical');
396         return wp_list_cats($query);
397 }
398
399 function wp_list_cats($args = '') {
400         $r = wp_parse_args( $args );
401
402         // Map to new names.
403         if ( isset($r['optionall']) && isset($r['all']))
404                 $r['show_option_all'] = $r['all'];
405         if ( isset($r['sort_column']) )
406                 $r['orderby'] = $r['sort_column'];
407         if ( isset($r['sort_order']) )
408                 $r['order'] = $r['sort_order'];
409         if ( isset($r['optiondates']) )
410                 $r['show_last_update'] = $r['optiondates'];
411         if ( isset($r['optioncount']) )
412                 $r['show_count'] = $r['optioncount'];
413         if ( isset($r['list']) )
414                 $r['style'] = $r['list'] ? 'list' : 'break';
415         $r['title_li'] = '';
416
417         return wp_list_categories($r);
418 }
419
420 function dropdown_cats($optionall = 1, $all = 'All', $orderby = 'ID', $order = 'asc',
421                 $show_last_update = 0, $show_count = 0, $hide_empty = 1, $optionnone = FALSE,
422                 $selected = 0, $exclude = 0) {
423
424         $show_option_all = '';
425         if ( $optionall )
426                 $show_option_all = $all;
427
428         $show_option_none = '';
429         if ( $optionnone )
430                 $show_option_none = __('None');
431
432         $vars = compact('show_option_all', 'show_option_none', 'orderby', 'order',
433                                         'show_last_update', 'show_count', 'hide_empty', 'selected', 'exclude');
434         $query = add_query_arg($vars, '');
435         return wp_dropdown_categories($query);
436 }
437
438 // Use wp_print_scripts() or WP_Scripts.
439 function tinymce_include() {
440         wp_print_script('wp_tiny_mce');
441 }
442
443 function list_authors($optioncount = false, $exclude_admin = true, $show_fullname = false, $hide_empty = true, $feed = '', $feed_image = '') {
444         $args = compact('optioncount', 'exclude_admin', 'show_fullname', 'hide_empty', 'feed', 'feed_image');
445         return wp_list_authors($args);
446 }
447
448 function wp_get_post_cats($blogid = '1', $post_ID = 0) {
449         return wp_get_post_categories($post_ID);
450 }
451
452 function wp_set_post_cats($blogid = '1', $post_ID = 0, $post_categories = array()) {
453         return wp_set_post_categories($post_ID, $post_categories);
454 }
455
456 // Use wp_get_archives().
457 function get_archives($type='', $limit='', $format='html', $before = '', $after = '', $show_post_count = false) {
458         $args = compact('type', 'limit', 'format', 'before', 'after', 'show_post_count');
459         return wp_get_archives($args);
460 }
461
462 // Use get_author_posts_url().
463 function get_author_link($echo = false, $author_id, $author_nicename = '') {
464         $link = get_author_posts_url($author_id, $author_nicename);
465
466         if ( $echo )
467                 echo $link;
468         return $link;
469 }
470
471 // Use wp_link_pages().
472 function link_pages($before='<br />', $after='<br />', $next_or_number='number', $nextpagelink='next page', $previouspagelink='previous page', $pagelink='%', $more_file='') {
473         $args = compact('before', 'after', 'next_or_number', 'nextpagelink', 'previouspagelink', 'pagelink', 'more_file');
474         return wp_link_pages($args);
475 }
476
477 // Use get_option().
478 function get_settings($option) {
479         return get_option($option);
480 }
481
482 // Use the_permalink().
483 function permalink_link() {
484         the_permalink();
485 }
486
487 // Use the_permalink_rss()
488 function permalink_single_rss($file = '') {
489         the_permalink_rss();
490 }
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(sanitize_bookmark_field('link_description', $row->link_description, $row->link_id, 'display'));
589                 $name = attribute_escape(sanitize_bookmark_field('link_name', $row->link_name, $row->link_id, 'display'));
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>' . apply_filters('link_category', $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 sanitize_bookmark_field('link_rating', $link->link_rating, $link->link_id, 'display');
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
732 ?>