]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/author-template.php
Wordpress 2.5.1-scripts
[autoinstalls/wordpress.git] / wp-includes / author-template.php
1 <?php
2 /**
3  * Author Template functions for use in themes.
4  *
5  * @package WordPress
6  * @subpackage Template
7  */
8
9 /**
10  * get_the_author() - Get the author of the current post in the Loop.
11  *
12  * @since 1.5
13  * @uses $authordata The current author's DB object.
14  * @uses apply_filters() Calls 'the_author' hook on the author display name.
15  *
16  * @param string $deprecated Deprecated.
17  * @return string The author's display name.
18  */
19 function get_the_author($deprecated = '') {
20         global $authordata;
21         return apply_filters('the_author', $authordata->display_name);
22 }
23
24 /**
25  * the_author() - Echo the name of the author of the current post in the Loop.
26  *
27  * The behavior of this function is based off of old functionality predating get_the_author().
28  * This function is not deprecated, but is designed to echo the value from get_the_author()
29  * and as an result of any old theme that might still use the old behavior will also
30  * pass the value from get_the_author().
31  *
32  * The normal, expected behavior of this function is to echo the author and not return it.
33  * However, backwards compatiability has to be maintained.
34  *
35  * @since 0.71
36  * @see get_the_author()
37  *
38  * @param string $deprecated Deprecated.
39  * @param string $deprecated_echo Echo the string or return it. Deprecated, use get_the_author().
40  * @return string The author's display name, from get_the_author().
41  */
42 function the_author($deprecated = '', $deprecated_echo = true) {
43         if ( $deprecated_echo )
44                 echo get_the_author();
45         return get_the_author();
46 }
47
48 /**
49  * get_the_author_description() - Get the description of the author of the current post in the Loop.
50  *
51  * @since 1.5
52  * @uses $authordata The current author's DB object.
53  * @return string The author's description.
54  */
55 function get_the_author_description() {
56         global $authordata;
57         return $authordata->description;
58 }
59
60 /**
61  * the_author_description() - Echo the description of the author of the current post in the Loop.
62  *
63  * @since 1.0.0
64  * @see get_the_author_description()
65  */
66 function the_author_description() {
67         echo get_the_author_description();
68 }
69
70 /**
71  * get_the_author_login() - Get the login name of the author of the current post in the Loop.
72  *
73  * @since 1.5
74  * @uses $authordata The current author's DB object.
75  * @return string The author's login name (username).
76  */
77 function get_the_author_login() {
78         global $authordata;
79         return $authordata->user_login;
80 }
81
82 /**
83  * the_author_login() - Echo the login name of the author of the current post in the Loop.
84  *
85  * @since 0.71
86  * @see get_the_author_login()
87  */
88 function the_author_login() {
89         echo get_the_author_login();
90 }
91
92 /**
93  * get_the_author_firstname() - Get the first name of the author of the current post in the Loop.
94  *
95  * @since 1.5
96  * @uses $authordata The current author's DB object.
97  * @return string The author's first name.
98  */
99 function get_the_author_firstname() {
100         global $authordata;
101         return $authordata->first_name;
102 }
103
104 /**
105  * the_author_firstname() - Echo the first name of the author of the current post in the Loop.
106  *
107  * @since 0.71
108  * @uses get_the_author_firstname()
109  */
110 function the_author_firstname() {
111         echo get_the_author_firstname();
112 }
113
114 /**
115  * get_the_author_lastname() - Get the last name of the author of the current post in the Loop.
116  *
117  * @since 1.5
118  * @uses $authordata The current author's DB object.
119  * @return string The author's last name.
120  */
121 function get_the_author_lastname() {
122         global $authordata;
123         return $authordata->last_name;
124 }
125
126 /**
127  * the_author_lastname() - Echo the last name of the author of the current post in the Loop.
128  *
129  * @since 0.71
130  * @uses get_the_author_lastname()
131  */
132 function the_author_lastname() {
133         echo get_the_author_lastname();
134 }
135
136 /**
137  * get_the_author_nickname() - Get the nickname of the author of the current post in the Loop.
138  *
139  * @since 1.5
140  * @uses $authordata The current author's DB object.
141  * @return string The author's nickname.
142  */
143 function get_the_author_nickname() {
144         global $authordata;
145         return $authordata->nickname;
146 }
147
148 /**
149  * the_author_nickname() - Echo the nickname of the author of the current post in the Loop.
150  *
151  * @since 0.71
152  * @uses get_the_author_nickname()
153  */
154 function the_author_nickname() {
155         echo get_the_author_nickname();
156 }
157
158 /**
159  * get_the_author_ID() - Get the ID of the author of the current post in the Loop.
160  *
161  * @since 1.5
162  * @uses $authordata The current author's DB object.
163  * @return int The author's ID.
164  */
165 function get_the_author_ID() {
166         global $authordata;
167         return (int) $authordata->ID;
168 }
169
170 /**
171  * the_author_ID() - Echo the ID of the author of the current post in the Loop.
172  *
173  * @since 0.71
174  * @uses get_the_author_ID()
175  */
176 function the_author_ID() {
177         echo get_the_author_id();
178 }
179
180 /**
181  * get_the_author_email() - Get the email of the author of the current post in the Loop.
182  *
183  * @since 1.5
184  * @uses $authordata The current author's DB object.
185  * @return string The author's username.
186  */
187 function get_the_author_email() {
188         global $authordata;
189         return $authordata->user_email;
190 }
191
192 /**
193  * the_author_email() - Echo the email of the author of the current post in the Loop.
194  *
195  * @since 0.71
196  * @uses get_the_author_email()
197  */
198 function the_author_email() {
199         echo apply_filters('the_author_email', get_the_author_email() );
200 }
201
202 /**
203  * get_the_author_url() - Get the URL to the home page of the author of the current post in the Loop.
204  *
205  * @since 1.5
206  * @uses $authordata The current author's DB object.
207  * @return string The URL to the author's page.
208  */
209 function get_the_author_url() {
210         global $authordata;
211
212         if ( 'http://' == $authordata->user_url )
213                 return '';
214
215         return $authordata->user_url;
216 }
217
218 /**
219  * the_author_url() - Echo the URL to the home page of the author of the current post in the Loop.
220  *
221  * @since 0.71
222  * @uses get_the_author_url()
223  */
224 function the_author_url() {
225         echo get_the_author_url();
226 }
227
228 /**
229  * the_author_link() - If the author has a home page set, echo an HTML link, otherwise just echo the author's name.
230  *
231  * @since 2.1
232  * @uses get_the_author_url()
233  * @uses the_author()
234  */
235 function the_author_link() {
236         if (get_the_author_url()) {
237                 echo '<a href="' . get_the_author_url() . '" title="' . sprintf(__("Visit %s's website"), get_the_author()) . '" rel="external">' . get_the_author() . '</a>';
238         } else {
239                 the_author();
240         }
241 }
242
243 /**
244  * get_the_author_icq() - Get the ICQ number of the author of the current post in the Loop.
245  *
246  * @since 1.5
247  * @uses $authordata The current author's DB object.
248  * @return string The author's ICQ number.
249  */
250 function get_the_author_icq() {
251         global $authordata;
252         return $authordata->icq;
253 }
254
255 /**
256  * the_author_icq() - Echo the ICQ number of the author of the current post in the Loop.
257  *
258  * @since 0.71
259  * @see get_the_author_icq()
260  */
261 function the_author_icq() {
262         echo get_the_author_icq();
263 }
264
265 /**
266  * get_the_author_aim() - Get the AIM name of the author of the current post in the Loop.
267  *
268  * @since 1.5
269  * @uses $authordata The current author's DB object.
270  * @return string The author's AIM name.
271  */
272 function get_the_author_aim() {
273         global $authordata;
274         return str_replace(' ', '+', $authordata->aim);
275 }
276
277 /**
278  * the_author_aim() - Echo the AIM name of the author of the current post in the Loop.
279  *
280  * @since 0.71
281  * @see get_the_author_aim()
282  */
283 function the_author_aim() {
284         echo get_the_author_aim();
285 }
286
287 /**
288  * get_the_author_yim() - Get the Yahoo! IM name of the author of the current post in the Loop.
289  *
290  * @since 1.5
291  * @uses $authordata The current author's DB object.
292  * @return string The author's Yahoo! IM name.
293  */
294 function get_the_author_yim() {
295         global $authordata;
296         return $authordata->yim;
297 }
298
299 /**
300  * the_author_yim() - Echo the Yahoo! IM name of the author of the current post in the Loop.
301  *
302  * @since 0.71
303  * @see get_the_author_yim()
304  */
305 function the_author_yim() {
306         echo get_the_author_yim();
307 }
308
309 /**
310  * get_the_author_msn() - Get the MSN address of the author of the current post in the Loop.
311  *
312  * @since 1.5
313  * @uses $authordata The current author's DB object.
314  * @return string The author's MSN address.
315  */
316 function get_the_author_msn() {
317         global $authordata;
318         return $authordata->msn;
319 }
320
321 /**
322  * the_author_msn() - Echo the MSN address of the author of the current post in the Loop.
323  *
324  * @since 0.71
325  * @see get_the_author_msn()
326  */
327 function the_author_msn() {
328         echo get_the_author_msn();
329 }
330
331 /**
332  * get_the_author_posts() - Get the number of posts by the author of the current post in the Loop.
333  *
334  * @since 1.5
335  * @uses $post The current post in the Loop's DB object.
336  * @uses get_usernumposts()
337  * @return int The number of posts by the author.
338  */
339 function get_the_author_posts() {
340         global $post;
341         return get_usernumposts($post->post_author);
342 }
343
344 /**
345  * the_author_posts() - Echo the number of posts by the author of the current post in the Loop.
346  *
347  * @since 0.71
348  * @uses get_the_author_posts() Echos returned value from function.
349  */
350 function the_author_posts() {
351         echo get_the_author_posts();
352 }
353
354 /**
355  * the_author_posts_link() - Echo an HTML link to the author page of the author of the current post in the Loop.
356  *
357  * Does just echo get_author_posts_url() function, like the others do. The reason for this,
358  * is that another function is used to help in printing the link to the author's posts.
359  *
360  * @since 1.2
361  * @uses $authordata The current author's DB object.
362  * @uses get_author_posts_url()
363  * @uses get_the_author()
364  * @param string $deprecated Deprecated.
365  */
366 function the_author_posts_link($deprecated = '') {
367         global $authordata;
368         printf(
369                 '<a href="%1$s" title="%2$s">%3$s</a>',
370                 get_author_posts_url( $authordata->ID, $authordata->user_nicename ),
371                 sprintf( __( 'Posts by %s' ), attribute_escape( get_the_author() ) ),
372                 get_the_author()
373         );
374 }
375
376 /**
377  * get_author_posts_url() - Get the URL to the author page of the author of the current post in the Loop.
378  *
379  * @since 2.1
380  * @uses $wp_rewrite WP_Rewrite
381  * @return string The URL to the author's page.
382  */
383 function get_author_posts_url($author_id, $author_nicename = '') {
384         global $wp_rewrite;
385         $auth_ID = (int) $author_id;
386         $link = $wp_rewrite->get_author_permastruct();
387
388         if ( empty($link) ) {
389                 $file = get_option('home') . '/';
390                 $link = $file . '?author=' . $auth_ID;
391         } else {
392                 if ( '' == $author_nicename ) {
393                         $user = get_userdata($author_id);
394                         if ( !empty($user->user_nicename) )
395                                 $author_nicename = $user->user_nicename;
396                 }
397                 $link = str_replace('%author%', $author_nicename, $link);
398                 $link = get_option('home') . trailingslashit($link);
399         }
400
401         $link = apply_filters('author_link', $link, $author_id, $author_nicename);
402
403         return $link;
404 }
405
406 /**
407  * get_author_name() - Get the specified author's preferred display name.
408  *
409  * @since 1.0.0
410  * @param int $auth_id The ID of the author.
411  * @return string The author's display name.
412  */
413 function get_author_name( $auth_id ) {
414         $authordata = get_userdata( $auth_id );
415         return $authordata->display_name;
416 }
417
418 /**
419  * wp_list_authors() - List all the authors of the blog, with several options available.
420  *
421  * optioncount (boolean) (false): Show the count in parenthesis next to the author's name.
422  * exclude_admin (boolean) (true): Exclude the 'admin' user that is installed by default.
423  * show_fullname (boolean) (false): Show their full names.
424  * hide_empty (boolean) (true): Don't show authors without any posts.
425  * feed (string) (''): If isn't empty, show links to author's feeds.
426  * feed_image (string) (''): If isn't empty, use this image to link to feeds.
427  * echo (boolean) (true): Set to false to return the output, instead of echoing.
428  *
429  * @since 1.2
430  * @param array $args The argument array.
431  * @return null|string The output, if echo is set to false.
432  */
433 function wp_list_authors($args = '') {
434         global $wpdb;
435
436         $defaults = array(
437                 'optioncount' => false, 'exclude_admin' => true,
438                 'show_fullname' => false, 'hide_empty' => true,
439                 'feed' => '', 'feed_image' => '', 'feed_type' => '', 'echo' => true
440         );
441
442         $r = wp_parse_args( $args, $defaults );
443         extract($r, EXTR_SKIP);
444
445         $return = '';
446
447         /** @todo Move select to get_authors(). */
448         $authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users " . ($exclude_admin ? "WHERE user_login <> 'admin' " : '') . "ORDER BY display_name");
449
450         $author_count = array();
451         foreach ((array) $wpdb->get_results("SELECT DISTINCT post_author, COUNT(ID) AS count FROM $wpdb->posts WHERE post_type = 'post' AND " . get_private_posts_cap_sql( 'post' ) . " GROUP BY post_author") as $row) {
452                 $author_count[$row->post_author] = $row->count;
453         }
454
455         foreach ( (array) $authors as $author ) {
456                 $author = get_userdata( $author->ID );
457                 $posts = (isset($author_count[$author->ID])) ? $author_count[$author->ID] : 0;
458                 $name = $author->display_name;
459
460                 if ( $show_fullname && ($author->first_name != '' && $author->last_name != '') )
461                         $name = "$author->first_name $author->last_name";
462
463                 if ( !($posts == 0 && $hide_empty) )
464                         $return .= '<li>';
465                 if ( $posts == 0 ) {
466                         if ( !$hide_empty )
467                                 $link = $name;
468                 } else {
469                         $link = '<a href="' . get_author_posts_url($author->ID, $author->user_nicename) . '" title="' . sprintf(__("Posts by %s"), attribute_escape($author->display_name)) . '">' . $name . '</a>';
470
471                         if ( (! empty($feed_image)) || (! empty($feed)) ) {
472                                 $link .= ' ';
473                                 if (empty($feed_image))
474                                         $link .= '(';
475                                 $link .= '<a href="' . get_author_rss_link(0, $author->ID, $author->user_nicename) . '"';
476
477                                 if ( !empty($feed) ) {
478                                         $title = ' title="' . $feed . '"';
479                                         $alt = ' alt="' . $feed . '"';
480                                         $name = $feed;
481                                         $link .= $title;
482                                 }
483
484                                 $link .= '>';
485
486                                 if ( !empty($feed_image) )
487                                         $link .= "<img src=\"$feed_image\" style=\"border: none;\"$alt$title" . ' />';
488                                 else
489                                         $link .= $name;
490
491                                 $link .= '</a>';
492
493                                 if ( empty($feed_image) )
494                                         $link .= ')';
495                         }
496
497                         if ( $optioncount )
498                                 $link .= ' ('. $posts . ')';
499
500                 }
501
502                 if ( !($posts == 0 && $hide_empty) )
503                         $return .= $link . '</li>';
504         }
505         if ( !$echo )
506                 return $return;
507         echo $return;
508 }
509
510 ?>