root/tags/2.1/wp-includes/author-template.php

Revision 4656, 5.6 kB (checked in by markjaquith, 2 years ago)

new function for escaping within attributes: attribute_escape()

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 <?php
2
3 function get_the_author($deprecated = '') {
4     global $authordata;
5     return apply_filters('the_author', $authordata->display_name);
6 }
7
8 // Using echo = false is deprecated.  Use get_the_author instead.
9 function the_author($deprecated = '', $deprecated_echo = true) {
10     if ( $deprecated_echo )
11         echo get_the_author();
12     return get_the_author();
13 }
14
15 function get_the_author_description() {
16     global $authordata;
17     return $authordata->description;
18 }
19 function the_author_description() {
20     echo get_the_author_description();
21 }
22
23 function get_the_author_login() {
24     global $authordata;
25     return $authordata->user_login;
26 }
27
28 function the_author_login() {
29     echo get_the_author_login();
30 }
31
32 function get_the_author_firstname() {
33     global $authordata;
34     return $authordata->first_name;
35 }
36 function the_author_firstname() {
37     echo get_the_author_firstname();
38 }
39
40 function get_the_author_lastname() {
41     global $authordata;
42     return $authordata->last_name;
43 }
44
45 function the_author_lastname() {
46     echo get_the_author_lastname();
47 }
48
49 function get_the_author_nickname() {
50     global $authordata;
51     return $authordata->nickname;
52 }
53
54 function the_author_nickname() {
55     echo get_the_author_nickname();
56 }
57
58 function get_the_author_ID() {
59     global $authordata;
60     return $authordata->ID;
61 }
62 function the_author_ID() {
63     echo get_the_author_id();
64 }
65
66 function get_the_author_email() {
67     global $authordata;
68     return $authordata->user_email;
69 }
70
71 function the_author_email() {
72     echo apply_filters('the_author_email', get_the_author_email() );
73 }
74
75 function get_the_author_url() {
76     global $authordata;
77     return $authordata->user_url;
78 }
79
80 function the_author_url() {
81     echo get_the_author_url();
82 }
83
84 function the_author_link() {
85     if (get_the_author_url()) {
86         echo '<a href="' . get_the_author_url() . '" title="' . sprintf(__("Visit %s's website"), get_the_author()) . '" rel="external">' . get_the_author() . '</a>';
87     } else {
88         the_author();
89     }
90 }
91
92 function get_the_author_icq() {
93     global $authordata;
94     return $authordata->icq;
95 }
96
97 function the_author_icq() {
98     echo get_the_author_icq();
99 }
100
101 function get_the_author_aim() {
102     global $authordata;
103     return str_replace(' ', '+', $authordata->aim);
104 }
105
106 function the_author_aim() {
107     echo get_the_author_aim();
108 }
109
110 function get_the_author_yim() {
111     global $authordata;
112     return $authordata->yim;
113 }
114
115 function the_author_yim() {
116     echo get_the_author_yim();
117 }
118
119 function get_the_author_msn() {
120     global $authordata;
121     return $authordata->msn;
122 }
123
124 function the_author_msn() {
125     echo get_the_author_msn();
126 }
127
128 function get_the_author_posts() {
129     global $post;
130     $posts = get_usernumposts($post->post_author);
131     return $posts;
132 }
133
134 function the_author_posts() {
135     echo get_the_author_posts();
136 }
137
138 /* the_author_posts_link() requires no get_, use get_author_posts_url() */
139 function the_author_posts_link($deprecated = '') {
140     global $authordata;
141
142     echo '<a href="' . get_author_posts_url($authordata->ID, $authordata->user_nicename) . '" title="' . sprintf(__("Posts by %s"), attribute_escape(get_the_author())) . '">' . get_the_author() . '</a>';
143 }
144
145 function get_author_posts_url($author_id, $author_nicename = '') {
146     global $wpdb, $wp_rewrite, $post, $cache_userdata;
147     $auth_ID = $author_id;
148     $link = $wp_rewrite->get_author_permastruct();
149
150     if ( empty($link) ) {
151         $file = get_option('home') . '/';
152         $link = $file . '?author=' . $auth_ID;
153     } else {
154         if ( '' == $author_nicename ) {
155             $user = get_userdata($author_id);
156             if ( !empty($user->user_nicename) )
157                 $author_nicename = $user->user_nicename;
158         }
159         $link = str_replace('%author%', $author_nicename, $link);
160         $link = get_option('home') . trailingslashit($link);
161     }
162
163     $link = apply_filters('author_link', $link, $author_id, $author_nicename);
164
165     return $link;
166 }
167
168 // Get author's preferred display name
169 function get_author_name( $auth_id ) {
170     $authordata = get_userdata( $auth_id );
171
172     return $authordata->display_name;
173 }
174
175 function wp_list_authors($args = '') {
176     if ( is_array($args) )
177         $r = &$args;
178     else
179         parse_str($args, $r);
180
181     $defaults = array('optioncount' => false, 'exclude_admin' => true, 'show_fullname' => false, 'hide_empty' => true,
182         'feed' => '', 'feed_image' => '');
183     $r = array_merge($defaults, $r);
184     extract($r);
185
186     global $wpdb;
187     // TODO:  Move select to get_authors().
188     $query = "SELECT ID, user_nicename from $wpdb->users " . ($exclude_admin ? "WHERE user_login <> 'admin' " : '') . "ORDER BY display_name";
189     $authors = $wpdb->get_results($query);
190
191     foreach ( (array) $authors as $author ) {
192         $author = get_userdata( $author->ID );
193         $posts = get_usernumposts($author->ID);
194         $name = $author->nickname;
195
196         if ( $show_fullname && ($author->first_name != '' && $author->last_name != '') )
197             $name = "$author->first_name $author->last_name";
198
199         if ( !($posts == 0 && $hide_empty) )
200             echo "<li>";
201         if ( $posts == 0 ) {
202             if ( !$hide_empty )
203                 $link = $name;
204         } else {
205             $link = '<a href="' . get_author_posts_url($author->ID, $author->user_nicename) . '" title="' . sprintf(__("Posts by %s"), attribute_escape($author->display_name)) . '">' . $name . '</a>';
206
207             if ( (! empty($feed_image)) || (! empty($feed)) ) {
208                 $link .= ' ';
209                 if (empty($feed_image))
210                     $link .= '(';
211                 $link .= '<a href="' . get_author_rss_link(0, $author->ID, $author->user_nicename) . '"';
212
213                 if ( !empty($feed) ) {
214                     $title = ' title="' . $feed . '"';
215                     $alt = ' alt="' . $feed . '"';
216                     $name = $feed;
217                     $link .= $title;
218                 }
219
220                 $link .= '>';
221
222                 if ( !empty($feed_image) )
223                     $link .= "<img src=\"$feed_image\" border=\"0\"$alt$title" . ' />';
224                 else
225                     $link .= $name;
226
227                 $link .= '</a>';
228
229                 if ( empty($feed_image) )
230                     $link .= ')';
231             }
232
233             if ( $optioncount )
234                 $link .= ' ('. $posts . ')';
235
236         }
237
238         if ( !($posts == 0 && $hide_empty) )
239             echo "$link</li>";
240     }
241 }
242
243 ?>
Note: See TracBrowser for help on using the browser.