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