root/tags/2.1.1/wp-includes/deprecated.php

Revision 4726, 17.6 kB (checked in by ryan, 2 years ago)

Add some back compat files and vars. Use is deprecated.

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