root/tags/1.5.1.3/wp-includes/pluggable-functions.php

Revision 2607, 11.9 kB (checked in by matt, 3 years ago)

Newline regression - http://mosquito.wordpress.org/view.php?id=263 - Hat tip: mlittle

  • Property svn:eol-style set to native
Line 
1 <?php
2
3     /* These functions can be replaced via plugins.  They are loaded after
4      plugins are loaded. */
5
6
7 if ( !function_exists('get_currentuserinfo') ) :
8 function get_currentuserinfo() {
9     global $user_login, $userdata, $user_level, $user_ID, $user_nickname, $user_email, $user_url, $user_pass_md5, $user_identity;
10     // *** retrieving user's data from cookies and db - no spoofing
11
12     if (isset($_COOKIE['wordpressuser_' . COOKIEHASH]))
13         $user_login = $_COOKIE['wordpressuser_' . COOKIEHASH];
14     $userdata = get_userdatabylogin($user_login);
15     $user_level = $userdata->user_level;
16     $user_ID = $userdata->ID;
17     $user_nickname = $userdata->user_nickname;
18     $user_email = $userdata->user_email;
19     $user_url = $userdata->user_url;
20     $user_pass_md5 = md5($userdata->user_pass);
21
22     $idmode = $userdata->user_idmode;
23     if ($idmode == 'nickname'$user_identity = $userdata->user_nickname;
24     if ($idmode == 'login')     $user_identity = $userdata->user_login;
25     if ($idmode == 'firstname') $user_identity = $userdata->user_firstname;
26     if ($idmode == 'lastname'$user_identity = $userdata->user_lastname;
27     if ($idmode == 'namefl')    $user_identity = $userdata->user_firstname.' '.$userdata->user_lastname;
28     if ($idmode == 'namelf')    $user_identity = $userdata->user_lastname.' '.$userdata->user_firstname;
29     if (!$idmode) $user_identity = $userdata->user_nickname;
30 }
31 endif;
32
33 if ( !function_exists('get_userdata') ) :
34 function get_userdata($userid) {
35     global $wpdb, $cache_userdata;
36     $userid = (int) $userid;
37     if ( empty($cache_userdata[$userid]) && $userid != 0) {
38         $cache_userdata[$userid] = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE ID = $userid");
39         $cache_userdata[$cache_userdata[$userid]->user_login] =& $cache_userdata[$userid];
40     }
41
42     return $cache_userdata[$userid];
43 }
44 endif;
45
46 if ( !function_exists('get_userdatabylogin') ) :
47 function get_userdatabylogin($user_login) {
48     global $cache_userdata, $wpdb;
49     if ( !empty($user_login) && empty($cache_userdata[$user_login]) ) {
50         $user = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE user_login = '$user_login'"); /* todo: get rid of this intermediate var */
51         $cache_userdata[$user->ID] = $user;
52         $cache_userdata[$user_login] =& $cache_userdata[$user->ID];
53     } else {
54         $user = $cache_userdata[$user_login];
55     }
56     return $user;
57 }
58 endif;
59
60 if ( !function_exists('wp_mail') ) :
61 function wp_mail($to, $subject, $message, $headers = '') {
62     if( $headers == '' ) {
63         $headers = "MIME-Version: 1.0\n" .
64             "From: " . get_settings('admin_email') . "\n" .
65             "Content-Type: text/plain; charset=\"" . get_settings('blog_charset') . "\"\n";
66     }
67
68     return @mail($to, $subject, $message, $headers);
69 }
70 endif;
71
72 if ( !function_exists('wp_login') ) :
73 function wp_login($username, $password, $already_md5 = false) {
74     global $wpdb, $error;
75
76     if ( !$username )
77         return false;
78
79     if ( !$password ) {
80         $error = __('<strong>Error</strong>: The password field is empty.');
81         return false;
82     }
83
84     $login = $wpdb->get_row("SELECT ID, user_login, user_pass FROM $wpdb->users WHERE user_login = '$username'");
85
86     if (!$login) {
87         $error = __('<strong>Error</strong>: Wrong username.');
88         return false;
89     } else {
90         // If the password is already_md5, it has been double hashed.
91         // Otherwise, it is plain text.
92         if ( ($already_md5 && $login->user_login == $username && md5($login->user_pass) == $password) || ($login->user_login == $username && $login->user_pass == md5($password)) ) {
93             return true;
94         } else {
95             $error = __('<strong>Error</strong>: Incorrect password.');
96             $pwd = '';
97             return false;
98         }
99     }
100 }
101 endif;
102
103 if ( !function_exists('auth_redirect') ) :
104 function auth_redirect() {
105     // Checks if a user is logged in, if not redirects them to the login page
106     if ( (!empty($_COOKIE['wordpressuser_' . COOKIEHASH]) &&
107                 !wp_login($_COOKIE['wordpressuser_' . COOKIEHASH], $_COOKIE['wordpresspass_' . COOKIEHASH], true)) ||
108              (empty($_COOKIE['wordpressuser_' . COOKIEHASH])) ) {
109         header('Expires: Wed, 11 Jan 1984 05:00:00 GMT');
110         header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
111         header('Cache-Control: no-cache, must-revalidate, max-age=0');
112         header('Pragma: no-cache');
113     
114         header('Location: ' . get_settings('siteurl') . '/wp-login.php?redirect_to=' . urlencode($_SERVER['REQUEST_URI']));
115         exit();
116     }
117 }
118 endif;
119
120 // Cookie safe redirect.  Works around IIS Set-Cookie bug.
121 // http://support.microsoft.com/kb/q176113/
122 if ( !function_exists('wp_redirect') ) :
123 function wp_redirect($location) {
124     global $is_IIS;
125
126     if ($is_IIS)
127         header("Refresh: 0;url=$location");
128     else
129         header("Location: $location");
130 }
131 endif;
132
133 if ( !function_exists('wp_setcookie') ) :
134 function wp_setcookie($username, $password, $already_md5 = false, $home = '', $siteurl = '') {
135     if ( !$already_md5 )
136         $password = md5( md5($password) ); // Double hash the password in the cookie.
137
138     if ( empty($home) )
139         $cookiepath = COOKIEPATH;
140     else
141         $cookiepath = preg_replace('|https?://[^/]+|i', '', $home . '/' );
142
143     if ( empty($siteurl) ) {
144         $sitecookiepath = SITECOOKIEPATH;
145         $cookiehash = COOKIEHASH;
146     } else {
147         $sitecookiepath = preg_replace('|https?://[^/]+|i', '', $siteurl . '/' );
148         $cookiehash = md5($siteurl);
149     }
150
151     setcookie('wordpressuser_'. $cookiehash, $username, time() + 31536000, $cookiepath);
152     setcookie('wordpresspass_'. $cookiehash, $password, time() + 31536000, $cookiepath);
153
154     if ( $cookiepath != $sitecookiepath ) {
155         setcookie('wordpressuser_'. $cookiehash, $username, time() + 31536000, $sitecookiepath);
156         setcookie('wordpresspass_'. $cookiehash, $password, time() + 31536000, $sitecookiepath);
157     }
158 }
159 endif;
160
161 if ( !function_exists('wp_clearcookie') ) :
162 function wp_clearcookie() {
163     setcookie('wordpressuser_' . COOKIEHASH, ' ', time() - 31536000, COOKIEPATH);
164     setcookie('wordpresspass_' . COOKIEHASH, ' ', time() - 31536000, COOKIEPATH);
165     setcookie('wordpressuser_' . COOKIEHASH, ' ', time() - 31536000, SITECOOKIEPATH);
166     setcookie('wordpresspass_' . COOKIEHASH, ' ', time() - 31536000, SITECOOKIEPATH);
167 }
168 endif;
169
170 if ( ! function_exists('wp_notify_postauthor') ) :
171 function wp_notify_postauthor($comment_id, $comment_type='') {
172     global $wpdb;
173     
174     $comment = $wpdb->get_row("SELECT * FROM $wpdb->comments WHERE comment_ID='$comment_id' LIMIT 1");
175     $post = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID='$comment->comment_post_ID' LIMIT 1");
176     $user = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE ID='$post->post_author' LIMIT 1");
177
178     if ('' == $user->user_email) return false; // If there's no email to send the comment to
179
180     $comment_author_domain = gethostbyaddr($comment->comment_author_IP);
181
182     $blogname = get_settings('blogname');
183     
184     if ( empty( $comment_type ) ) $comment_type = 'comment';
185     
186     if ('comment' == $comment_type) {
187         $notify_message  = sprintf( __('New comment on your post #%1$s "%2$s"'), $comment->comment_post_ID, $post->post_title ) . "\r\n";
188         $notify_message .= sprintf( __('Author : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
189         $notify_message .= sprintf( __('E-mail : %s'), $comment->comment_author_email ) . "\r\n";
190         $notify_message .= sprintf( __('URI    : %s'), $comment->comment_author_url ) . "\r\n";
191         $notify_message .= sprintf( __('Whois  : http://ws.arin.net/cgi-bin/whois.pl?queryinput=%s'), $comment->comment_author_IP ) . "\r\n";
192         $notify_message .= __('Comment: ') . "\r\n" . $comment->comment_content . "\r\n\r\n";
193         $notify_message .= __('You can see all comments on this post here: ') . "\r\n";
194         $subject = sprintf( __('[%1$s] Comment: "%2$s"'), $blogname, $post->post_title );
195     } elseif ('trackback' == $comment_type) {
196         $notify_message  = sprintf( __('New trackback on your post #%1$s "%2$s"'), $comment->comment_post_ID, $post->post_title ) . "\r\n";
197         $notify_message .= sprintf( __('Website: %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
198         $notify_message .= sprintf( __('URI    : %s'), $comment->comment_author_url ) . "\r\n";
199         $notify_message .= __('Excerpt: ') . "\r\n" . $comment->comment_content . "\r\n\r\n";
200         $notify_message .= __('You can see all trackbacks on this post here: ') . "\r\n";
201         $subject = sprintf( __('[%1$s] Trackback: "%2$s"'), $blogname, $post->post_title );
202     } elseif ('pingback' == $comment_type) {
203         $notify_message  = sprintf( __('New pingback on your post #%1$s "%2$s"'), $comment->comment_post_ID, $post->post_title ) . "\r\n";
204         $notify_message .= sprintf( __('Website: %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
205         $notify_message .= sprintf( __('URI    : %s'), $comment->comment_author_url ) . "\r\n";
206         $notify_message .= __('Excerpt: ') . "\r\n" . sprintf( __('[...] %s [...]'), $comment->comment_content ) . "\r\n\r\n";
207         $notify_message .= __('You can see all pingbacks on this post here: ') . "\r\n";
208         $subject = sprintf( __('[%1$s] Pingback: "%2$s"'), $blogname, $post->post_title );
209     }
210     $notify_message .= get_permalink($comment->comment_post_ID) . "#comments\r\n\r\n";
211     $notify_message .= sprintf( __('To delete this comment, visit: %s'), get_settings('siteurl').'/wp-admin/post.php?action=confirmdeletecomment&p='.$comment->comment_post_ID."&comment=$comment_id" ) . "\r\n";
212
213     if ('' == $comment->comment_author_email || '' == $comment->comment_author) {
214         $from = "From: \"$blogname\" <wordpress@" . $_SERVER['SERVER_NAME'] . '>';
215     } else {
216         $from = 'From: "' . $comment->comment_author . "\" <$comment->comment_author_email>";
217     }
218
219     $message_headers = "MIME-Version: 1.0\n"
220         . "$from\n"
221         . "Content-Type: text/plain; charset=\"" . get_settings('blog_charset') . "\"\n";
222
223     @wp_mail($user->user_email, $subject, $notify_message, $message_headers);
224   
225     return true;
226 }
227 endif;
228
229 /* wp_notify_moderator
230    notifies the moderator of the blog (usually the admin)
231    about a new comment that waits for approval
232    always returns true
233  */
234 if ( !function_exists('wp_notify_moderator') ) :
235 function wp_notify_moderator($comment_id) {
236     global $wpdb;
237
238     if( get_settings( "moderation_notify" ) == 0 )
239         return true;
240     
241     $comment = $wpdb->get_row("SELECT * FROM $wpdb->comments WHERE comment_ID='$comment_id' LIMIT 1");
242     $post = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID='$comment->comment_post_ID' LIMIT 1");
243     $user = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE ID='$post->post_author' LIMIT 1");
244
245     $comment_author_domain = gethostbyaddr($comment->comment_author_IP);
246     $comments_waiting = $wpdb->get_var("SELECT count(comment_ID) FROM $wpdb->comments WHERE comment_approved = '0'");
247
248     $notify_message  = sprintf( __('A new comment on the post #%1$s "%2$s" is waiting for your approval'), $post->ID, $post->post_title ) . "\r\n";
249     $notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n";
250     $notify_message .= sprintf( __('Author : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
251     $notify_message .= sprintf( __('E-mail : %s'), $comment->comment_author_email ) . "\r\n";
252     $notify_message .= sprintf( __('URI    : %s'), $comment->comment_author_url ) . "\r\n";
253     $notify_message .= sprintf( __('Whois  : http://ws.arin.net/cgi-bin/whois.pl?queryinput=%s'), $comment->comment_author_IP ) . "\r\n";
254     $notify_message .= __('Comment: ') . "\r\n" . $comment->comment_content . "\r\n\r\n";
255     $notify_message .= sprintf( __('To approve this comment, visit: %s'),  get_settings('siteurl').'/wp-admin/post.php?action=mailapprovecomment&p='.$comment->comment_post_ID."&comment=$comment_id" ) . "\r\n";
256     $notify_message .= sprintf( __('To delete this comment, visit: %s'), get_settings('siteurl').'/wp-admin/post.php?action=confirmdeletecomment&p='.$comment->comment_post_ID."&comment=$comment_id" ) . "\r\n";
257     $notify_message .= sprintf( __('Currently %s comments are waiting for approval. Please visit the moderation panel:'), $comments_waiting ) . "\r\n";
258     $notify_message .= get_settings('siteurl') . "/wp-admin/moderation.php\r\n";
259
260     $subject = sprintf( __('[%1$s] Please moderate: "%2$s"'), get_settings('blogname'), $post->post_title );
261     $admin_email = get_settings("admin_email");
262
263     @wp_mail($admin_email, $subject, $notify_message);
264     
265     return true;
266 }
267 endif;
268
269 ?>
Note: See TracBrowser for help on using the browser.