4 * Deprecated global variables.
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;
18 * Deprecated functions come here to die.
22 function get_postdata($postid) {
23 $post = &get_post($postid);
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
46 // Use the new post loop.
48 global $wp_query, $post;
50 // Since the old style loop is being used, advance the query iterator here.
51 $wp_query->next_post();
53 setup_postdata($post);
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;
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 ) {
74 echo get_the_category_by_ID($currentcat);
76 $previouscat = $currentcat;
80 // Use previous_post_link().
81 function previous_post($format='%', $previous='previous post: ', $title='yes', $in_same_cat='no', $limitprev=1, $excluded_categories='') {
83 if ( empty($in_same_cat) || 'no' == $in_same_cat )
88 $post = get_previous_post($in_same_cat, $excluded_categories);
93 $string = '<a href="'.get_permalink($post->ID).'">'.$previous;
94 if ( 'yes' == $title )
95 $string .= apply_filters('the_title', $post->post_title, $post);
97 $format = str_replace('%', $string, $format);
101 // Use next_post_link().
102 function next_post($format='%', $next='next post: ', $title='yes', $in_same_cat='no', $limitnext=1, $excluded_categories='') {
104 if ( empty($in_same_cat) || 'no' == $in_same_cat )
105 $in_same_cat = false;
109 $post = get_next_post($in_same_cat, $excluded_categories);
114 $string = '<a href="'.get_permalink($post->ID).'">'.$next;
115 if ( 'yes' == $title )
116 $string .= apply_filters('the_title', $post->post_title, $nextpost);
118 $format = str_replace('%', $string, $format);
123 // Use current_user_can() for these.
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);
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);
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);
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) ) {
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);
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));
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));
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);
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);
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 )
192 /** function get_linksbyname()
193 ** Gets the links associated with category 'cat_name'.
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
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
212 ** show_updated (default 0) - whether to show last updated timestamp
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) {
220 $cat = get_term_by('name', $cat_name, 'link_category');
222 $cat_id = $cat->term_id;
224 get_links($cat_id, $before, $after, $between, $show_images, $orderby,
225 $show_description, $show_rating, $limit, $show_updated);
228 /** function wp_get_linksbyname()
229 ** Gets the links associated with the named category.
231 ** category (no default) - The category to use.
233 function wp_get_linksbyname($category, $args = '') {
236 $cat = get_term_by('name', $cat_name, 'link_category');
239 $cat_id = $cat->term_id;
241 $args = add_query_arg('category', $cat_id, $args);
245 /** function get_linkobjectsbyname()
246 ** Gets an array of link objects associated with category 'cat_name'.
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
255 ** limit (default -1) - Limit to X entries. If not specified, all entries
259 ** $links = get_linkobjectsbyname('fred');
260 ** foreach ($links as $link) {
261 ** echo '<li>'.$link->link_name.'</li>';
264 function get_linkobjectsbyname($cat_name = "noname" , $orderby = 'name', $limit = -1) {
267 $cat = get_term_by('name', $cat_name, 'link_category');
269 $cat_id = $cat->term_id;
271 return get_linkobjects($cat_id, $orderby, $limit);
274 /** function get_linkobjects()
275 ** Gets an array of link objects associated with category n.
277 ** category (default -1) - The category to use. If no category supplied
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
284 ** limit (default -1) - Limit to X entries. If not specified, all entries
288 ** $links = get_linkobjects(1);
290 ** foreach ($links as $link) {
291 ** echo '<li>'.$link->link_name.'<br />'.$link->link_description.'</li>';
309 // Deprecate in favor of get_linkz().
310 function get_linkobjects($category = 0, $orderby = 'name', $limit = 0) {
313 $links = get_bookmarks("category=$category&orderby=$orderby&limit=$limit");
315 $links_array = array();
316 foreach ($links as $link) {
317 $links_array[] = $link;
323 /** function get_linksbyname_withrating()
324 ** Gets the links associated with category 'cat_name' and display rating stars/chars.
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
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
342 ** show_updated (default 0) - whether to show last updated timestamp
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) {
349 get_linksbyname($cat_name, $before, $after, $between, $show_images,
350 $orderby, $show_description, true, $limit, $show_updated);
353 /** function get_links_withrating()
354 ** Gets the links associated with category n and display rating stars/chars.
356 ** category (default -1) - The category to use. If no category supplied
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
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
372 ** show_updated (default 0) - whether to show last updated timestamp
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) {
379 get_links($category, $before, $after, $between, $show_images, $orderby,
380 $show_description, true, $limit, $show_updated);
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
388 function get_autotoggle($id = 0) {
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);
399 function wp_list_cats($args = '') {
400 $r = wp_parse_args( $args );
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';
417 return wp_list_categories($r);
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) {
424 $show_option_all = '';
426 $show_option_all = $all;
428 $show_option_none = '';
430 $show_option_none = __('None');
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);
438 // Use wp_print_scripts() or WP_Scripts.
439 function tinymce_include() {
440 wp_print_script('wp_tiny_mce');
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);
448 function wp_get_post_cats($blogid = '1', $post_ID = 0) {
449 return wp_get_post_categories($post_ID);
452 function wp_set_post_cats($blogid = '1', $post_ID = 0, $post_categories = array()) {
453 return wp_set_post_categories($post_ID, $post_categories);
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);
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);
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);
478 function get_settings($option) {
479 return get_option($option);
482 // Use the_permalink().
483 function permalink_link() {
487 // Use the_permalink_rss()
488 function permalink_single_rss($file = '') {
492 /** function wp_get_links()
493 ** Gets the links associated with category n.
495 ** category (no default) - The category to use.
499 function wp_get_links($args = '') {
502 if ( strpos( $args, '=' ) === false ) {
504 $args = add_query_arg( 'category', $cat_id, $args );
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,
516 $r = wp_parse_args( $args, $defaults );
517 extract( $r, EXTR_SKIP );
519 return get_links($category, $before, $after, $between, $show_images, $orderby, $show_description, $show_rating, $limit, $show_updated, $echo);
520 } // end wp_get_links
522 /** function get_links()
523 ** Gets the links associated with category n.
525 ** category (default -1) - The category to use. If no category supplied
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
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
542 ** show_updated (default 0) - whether to show last updated timestamp
543 ** echo (default true) - whether to echo the results, or return them instead
545 function get_links($category = -1,
551 $show_description = true,
552 $show_rating = false,
560 if ( substr($orderby, 0, 1) == '_' ) {
562 $orderby = substr($orderby, 1);
565 if ( $category == -1 ) //get_bookmarks uses '' to signify all categories
568 $results = get_bookmarks("category=$category&orderby=$orderby&order=$order&show_updated=$show_updated&limit=$limit");
575 foreach ( (array) $results as $row ) {
576 if ( !isset($row->recently_updated) )
577 $row->recently_updated = false;
579 if ( $show_updated && $row->recently_updated )
580 $output .= get_option('links_recently_updated_prepend');
582 if ( !empty($row->link_url) )
583 $the_link = clean_url($row->link_url);
584 $rel = $row->link_rel;
586 $rel = ' rel="' . $rel . '"';
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'));
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)) . ')';
597 $title = ' title="' . $title . '"';
599 $alt = ' alt="' . $name . '"';
601 $target = $row->link_target;
603 $target = ' target="' . $target . '"';
605 $output .= '<a href="' . $the_link . '"' . $rel . $title . $target. '>';
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 />";
618 if ( $show_updated && $row->recently_updated )
619 $output .= get_option('links_recently_updated_append');
621 if ( $show_description && '' != $desc )
622 $output .= $between . $desc;
625 $output .= $between . get_linkrating($row);
628 $output .= "$after\n";
637 * function get_links_list()
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.
646 * order (default 'name') - Sort link categories by 'name' or 'id'
647 * hide_if_empty (default true) - Supress listing empty link categories
649 function get_links_list($order = 'name', $hide_if_empty = 'obsolete') {
650 $order = strtolower($order);
652 // Handle link category sorting
654 if ( '_' == substr($order,0,1) ) {
656 $order = substr($order,1);
659 if ( !isset($direction) )
662 $cats = get_categories("type=link&orderby=$order&order=$direction&hierarchical=0");
664 // Display each category
666 foreach ( (array) $cats as $cat ) {
667 // Handle each category.
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);
674 // Close the last category
675 echo "\n\t</ul>\n</li>\n";
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
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
691 function links_popup_script($text = 'Links', $width=400, $height=400, $file='links.all.php', $count = true) {
693 $counts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->links");
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;
699 $javascript .= " ($counts)";
701 $javascript .= "</a>\n\n";
706 function get_linkrating($link) {
707 return sanitize_bookmark_field('link_rating', $link->link_rating, $link->link_id, 'display');
710 /** function get_linkcatname()
711 ** Gets the name of category n.
712 ** Parameters: id (default 0) - The category to get. If no category supplied
715 function get_linkcatname($id = 0) {
721 $cats = wp_get_link_cats($id);
723 if ( empty($cats) || ! is_array($cats) )
726 $cat_id = (int) $cats[0]; // Take the first cat.
728 $cat = get_category($cat_id);