]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/pluggable.php
Wordpress 2.3.2
[autoinstalls/wordpress.git] / wp-includes / pluggable.php
1 <?php
2
3         /* These functions can be replaced via plugins.  They are loaded after
4          plugins are loaded. */
5
6 if ( !function_exists('set_current_user') ) :
7 function set_current_user($id, $name = '') {
8         return wp_set_current_user($id, $name);
9 }
10 endif;
11
12 if ( !function_exists('wp_set_current_user') ) :
13 function wp_set_current_user($id, $name = '') {
14         global $current_user;
15
16         if ( isset($current_user) && ($id == $current_user->ID) )
17                 return $current_user;
18
19         $current_user = new WP_User($id, $name);
20
21         setup_userdata($current_user->ID);
22
23         do_action('set_current_user');
24
25         return $current_user;
26 }
27 endif;
28
29 if ( !function_exists('wp_get_current_user') ) :
30 function wp_get_current_user() {
31         global $current_user;
32
33         get_currentuserinfo();
34
35         return $current_user;
36 }
37 endif;
38
39 if ( !function_exists('get_currentuserinfo') ) :
40 function get_currentuserinfo() {
41         global $current_user;
42
43         if ( defined('XMLRPC_REQUEST') && XMLRPC_REQUEST )
44                 return false;
45
46         if ( ! empty($current_user) )
47                 return;
48
49         if ( empty($_COOKIE[USER_COOKIE]) || empty($_COOKIE[PASS_COOKIE]) ||
50                 !wp_login($_COOKIE[USER_COOKIE], $_COOKIE[PASS_COOKIE], true) ) {
51                 wp_set_current_user(0);
52                 return false;
53         }
54
55         $user_login = $_COOKIE[USER_COOKIE];
56         wp_set_current_user(0, $user_login);
57 }
58 endif;
59
60 if ( !function_exists('get_userdata') ) :
61 function get_userdata( $user_id ) {
62         global $wpdb;
63         $user_id = (int) $user_id;
64         if ( $user_id == 0 )
65                 return false;
66
67         $user = wp_cache_get($user_id, 'users');
68
69         if ( $user )
70                 return $user;
71
72         if ( !$user = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE ID = '$user_id' LIMIT 1") )
73                 return false;
74
75         $show = $wpdb->hide_errors();
76         $metavalues = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->usermeta WHERE user_id = '$user_id'");
77         $wpdb->show_errors($show);
78
79         if ($metavalues) {
80                 foreach ( $metavalues as $meta ) {
81                         $value = maybe_unserialize($meta->meta_value);
82                         $user->{$meta->meta_key} = $value;
83
84                         // We need to set user_level from meta, not row
85                         if ( $wpdb->prefix . 'user_level' == $meta->meta_key )
86                                 $user->user_level = $meta->meta_value;
87                 } // end foreach
88         } //end if
89
90         // For backwards compat.
91         if ( isset($user->first_name) )
92                 $user->user_firstname = $user->first_name;
93         if ( isset($user->last_name) )
94                 $user->user_lastname = $user->last_name;
95         if ( isset($user->description) )
96                 $user->user_description = $user->description;
97
98         wp_cache_add($user_id, $user, 'users');
99         wp_cache_add($user->user_login, $user_id, 'userlogins');
100         return $user;
101 }
102 endif;
103
104 if ( !function_exists('update_user_cache') ) :
105 function update_user_cache() {
106         return true;
107 }
108 endif;
109
110 if ( !function_exists('get_userdatabylogin') ) :
111 function get_userdatabylogin($user_login) {
112         global $wpdb;
113         $user_login = sanitize_user( $user_login );
114
115         if ( empty( $user_login ) )
116                 return false;
117
118         $user_id = wp_cache_get($user_login, 'userlogins');
119         $userdata = wp_cache_get($user_id, 'users');
120
121         if ( $userdata )
122                 return $userdata;
123
124         $user_login = $wpdb->escape($user_login);
125
126         if ( !$user_ID = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_login = '$user_login'") )
127                 return false;
128
129         $user = get_userdata($user_ID);
130         return $user;
131 }
132 endif;
133
134 if ( !function_exists( 'wp_mail' ) ) :
135 function wp_mail( $to, $subject, $message, $headers = '' ) {
136         // Compact the input, apply the filters, and extract them back out
137         extract( apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers' ) ) );
138
139         global $phpmailer;
140
141         // (Re)create it, if it's gone missing
142         if ( !is_object( $phpmailer ) || !is_a( $phpmailer, 'PHPMailer' ) ) {
143                 require_once ABSPATH . WPINC . '/class-phpmailer.php';
144                 require_once ABSPATH . WPINC . '/class-smtp.php';
145                 $phpmailer = new PHPMailer();
146         }
147
148         // Headers
149         if ( empty( $headers ) ) {
150                 $headers = array();
151         } elseif ( !is_array( $headers ) ) {
152                 // Explode the headers out, so this function can take both
153                 // string headers and an array of headers.
154                 $tempheaders = (array) explode( "\n", $headers );
155                 $headers = array();
156
157                 // If it's actually got contents
158                 if ( !empty( $tempheaders ) ) {
159                         // Iterate through the raw headers
160                         foreach ( $tempheaders as $header ) {
161                                 if ( strpos($header, ':') === false )
162                                         continue;
163                                 // Explode them out
164                                 list( $name, $content ) = explode( ':', trim( $header ), 2 );
165
166                                 // Cleanup crew
167                                 $name = trim( $name );
168                                 $content = trim( $content );
169
170                                 // Mainly for legacy -- process a From: header if it's there
171                                 if ( 'from' == strtolower($name) ) {
172                                         if ( strpos($content, '<' ) !== false ) {
173                                                 // So... making my life hard again?
174                                                 $from_name = substr( $content, 0, strpos( $content, '<' ) - 1 );
175                                                 $from_name = str_replace( '"', '', $from_name );
176                                                 $from_name = trim( $from_name );
177
178                                                 $from_email = substr( $content, strpos( $content, '<' ) + 1 );
179                                                 $from_email = str_replace( '>', '', $from_email );
180                                                 $from_email = trim( $from_email );
181                                         } else {
182                                                 $from_name = trim( $content );
183                                         }
184                                 } elseif ( 'content-type' == strtolower($name) ) {
185                                         if ( strpos( $content,';' ) !== false ) {
186                                                 list( $type, $charset ) = explode( ';', $content );
187                                                 $content_type = trim( $type );
188                                                 $charset = trim( str_replace( array( 'charset=', '"' ), '', $charset ) );
189                                         } else {
190                                                 $content_type = trim( $content );
191                                         }
192                                 } else {
193                                         // Add it to our grand headers array
194                                         $headers[trim( $name )] = trim( $content );
195                                 }
196                         }
197                 }
198         }
199
200         // Empty out the values that may be set
201         $phpmailer->ClearAddresses();
202         $phpmailer->ClearAllRecipients();
203         $phpmailer->ClearAttachments();
204         $phpmailer->ClearBCCs();
205         $phpmailer->ClearCCs();
206         $phpmailer->ClearCustomHeaders();
207         $phpmailer->ClearReplyTos();
208
209         // From email and name
210         // If we don't have a name from the input headers
211         if ( !isset( $from_name ) ) {
212                 $from_name = 'WordPress';
213         }
214
215         // If we don't have an email from the input headers
216         if ( !isset( $from_email ) ) {
217                 // Get the site domain and get rid of www.
218                 $sitename = strtolower( $_SERVER['SERVER_NAME'] );
219                 if ( substr( $sitename, 0, 4 ) == 'www.' ) {
220                         $sitename = substr( $sitename, 4 );
221                 }
222
223                 $from_email = 'wordpress@' . $sitename;
224         }
225
226         // Set the from name and email
227         $phpmailer->From = apply_filters( 'wp_mail_from', $from_email );
228         $phpmailer->Sender = apply_filters( 'wp_mail_from', $from_email );
229         $phpmailer->FromName = apply_filters( 'wp_mail_from_name', $from_name );
230
231         // Set destination address
232         $phpmailer->AddAddress( $to );
233
234         // Set mail's subject and body
235         $phpmailer->Subject = $subject;
236         $phpmailer->Body = $message;
237
238         // Set to use PHP's mail()
239         $phpmailer->IsMail();
240
241         // Set Content-Type and charset
242         // If we don't have a content-type from the input headers
243         if ( !isset( $content_type ) ) {
244                 $content_type = 'text/plain';
245         }
246
247         $content_type = apply_filters( 'wp_mail_content_type', $content_type );
248
249         // Set whether it's plaintext or not, depending on $content_type
250         if ( $content_type == 'text/html' ) {
251                 $phpmailer->IsHTML( true );
252         } else {
253                 $phpmailer->IsHTML( false );
254         }
255
256         // If we don't have a charset from the input headers
257         if ( !isset( $charset ) ) {
258                 $charset = get_bloginfo( 'charset' );
259         }
260
261         // Set the content-type and charset
262         $phpmailer->CharSet = apply_filters( 'wp_mail_charset', $charset );
263
264         // Set custom headers
265         if ( !empty( $headers ) ) {
266                 foreach ( $headers as $name => $content ) {
267                         $phpmailer->AddCustomHeader( sprintf( '%1$s: %2$s', $name, $content ) );
268                 }
269         }
270
271         do_action_ref_array( 'phpmailer_init', array( &$phpmailer ) );
272
273         // Send!
274         $result = @$phpmailer->Send();
275
276         return $result;
277 }
278 endif;
279
280 if ( !function_exists('wp_login') ) :
281 function wp_login($username, $password, $already_md5 = false) {
282         global $wpdb, $error;
283
284         $username = sanitize_user($username);
285
286         if ( '' == $username )
287                 return false;
288
289         if ( '' == $password ) {
290                 $error = __('<strong>ERROR</strong>: The password field is empty.');
291                 return false;
292         }
293
294         $login = get_userdatabylogin($username);
295         //$login = $wpdb->get_row("SELECT ID, user_login, user_pass FROM $wpdb->users WHERE user_login = '$username'");
296
297         if (!$login) {
298                 $error = __('<strong>ERROR</strong>: Invalid username.');
299                 return false;
300         } else {
301                 // If the password is already_md5, it has been double hashed.
302                 // Otherwise, it is plain text.
303                 if ( ($already_md5 && md5($login->user_pass) == $password) || ($login->user_login == $username && $login->user_pass == md5($password)) ) {
304                         return true;
305                 } else {
306                         $error = __('<strong>ERROR</strong>: Incorrect password.');
307                         $pwd = '';
308                         return false;
309                 }
310         }
311 }
312 endif;
313
314 if ( !function_exists('is_user_logged_in') ) :
315 function is_user_logged_in() {
316         $user = wp_get_current_user();
317
318         if ( $user->id == 0 )
319                 return false;
320
321         return true;
322 }
323 endif;
324
325 if ( !function_exists('auth_redirect') ) :
326 function auth_redirect() {
327         // Checks if a user is logged in, if not redirects them to the login page
328         if ( (!empty($_COOKIE[USER_COOKIE]) &&
329                                 !wp_login($_COOKIE[USER_COOKIE], $_COOKIE[PASS_COOKIE], true)) ||
330                          (empty($_COOKIE[USER_COOKIE])) ) {
331                 nocache_headers();
332
333                 wp_redirect(get_option('siteurl') . '/wp-login.php?redirect_to=' . urlencode($_SERVER['REQUEST_URI']));
334                 exit();
335         }
336 }
337 endif;
338
339 if ( !function_exists('check_admin_referer') ) :
340 function check_admin_referer($action = -1) {
341         $adminurl = strtolower(get_option('siteurl')).'/wp-admin';
342         $referer = strtolower(wp_get_referer());
343         if ( !wp_verify_nonce($_REQUEST['_wpnonce'], $action) &&
344                 !(-1 == $action && strpos($referer, $adminurl) !== false)) {
345                 wp_nonce_ays($action);
346                 die();
347         }
348         do_action('check_admin_referer', $action);
349 }endif;
350
351 if ( !function_exists('check_ajax_referer') ) :
352 function check_ajax_referer() {
353         $current_name = '';
354         if ( ( $current = wp_get_current_user() ) && $current->ID )
355                 $current_name = $current->data->user_login;
356         if ( !$current_name )
357                 die('-1');
358
359         $cookie = explode('; ', urldecode(empty($_POST['cookie']) ? $_GET['cookie'] : $_POST['cookie'])); // AJAX scripts must pass cookie=document.cookie
360         foreach ( $cookie as $tasty ) {
361                 if ( false !== strpos($tasty, USER_COOKIE) )
362                         $user = substr(strstr($tasty, '='), 1);
363                 if ( false !== strpos($tasty, PASS_COOKIE) )
364                         $pass = substr(strstr($tasty, '='), 1);
365         }
366
367         if ( $current_name != $user || !wp_login( $user, $pass, true ) )
368                 die('-1');
369         do_action('check_ajax_referer');
370 }
371 endif;
372
373 // Cookie safe redirect.  Works around IIS Set-Cookie bug.
374 // http://support.microsoft.com/kb/q176113/
375 if ( !function_exists('wp_redirect') ) :
376 function wp_redirect($location, $status = 302) {
377         global $is_IIS;
378
379         $location = apply_filters('wp_redirect', $location, $status);
380
381         if ( !$location ) // allows the wp_redirect filter to cancel a redirect
382                 return false;
383
384         $location = wp_sanitize_redirect($location);
385
386         if ( $is_IIS ) {
387                 header("Refresh: 0;url=$location");
388         } else {
389                 if ( php_sapi_name() != 'cgi-fcgi' )
390                         status_header($status); // This causes problems on IIS and some FastCGI setups
391                 header("Location: $location");
392         }
393 }
394 endif;
395
396 if ( !function_exists('wp_sanitize_redirect') ) :
397 /**
398  * sanitizes a URL for use in a redirect
399  * @return string redirect-sanitized URL
400  **/
401 function wp_sanitize_redirect($location) {
402         $location = preg_replace('|[^a-z0-9-~+_.?#=&;,/:%]|i', '', $location);
403         $location = wp_kses_no_null($location);
404
405         // remove %0d and %0a from location
406         $strip = array('%0d', '%0a');
407         $found = true;
408         while($found) {
409                 $found = false;
410                 foreach($strip as $val) {
411                         while(strpos($location, $val) !== false) {
412                                 $found = true;
413                                 $location = str_replace($val, '', $location);
414                         }
415                 }
416         }
417         return $location;
418 }
419 endif;
420
421 if ( !function_exists('wp_safe_redirect') ) :
422 /**
423  * performs a safe (local) redirect, using wp_redirect()
424  * @return void
425  **/
426 function wp_safe_redirect($location, $status = 302) {
427
428         // Need to look at the URL the way it will end up in wp_redirect()
429         $location = wp_sanitize_redirect($location);
430
431         // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
432         if ( substr($location, 0, 2) == '//' )
433                 $location = 'http:' . $location;
434
435         $lp  = parse_url($location);
436         $wpp = parse_url(get_option('home'));
437
438         $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), $lp['host']);
439
440         if ( isset($lp['host']) && ( !in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host'])) )
441                 $location = get_option('siteurl') . '/wp-admin/';
442
443         wp_redirect($location, $status);
444 }
445 endif;
446
447 if ( !function_exists('wp_get_cookie_login') ):
448 function wp_get_cookie_login() {
449         if ( empty($_COOKIE[USER_COOKIE]) || empty($_COOKIE[PASS_COOKIE]) )
450                 return false;
451
452         return array('login' => $_COOKIE[USER_COOKIE],  'password' => $_COOKIE[PASS_COOKIE]);
453 }
454
455 endif;
456
457 if ( !function_exists('wp_setcookie') ) :
458 function wp_setcookie($username, $password, $already_md5 = false, $home = '', $siteurl = '', $remember = false) {
459         if ( !$already_md5 )
460                 $password = md5( md5($password) ); // Double hash the password in the cookie.
461
462         if ( empty($home) )
463                 $cookiepath = COOKIEPATH;
464         else
465                 $cookiepath = preg_replace('|https?://[^/]+|i', '', $home . '/' );
466
467         if ( empty($siteurl) ) {
468                 $sitecookiepath = SITECOOKIEPATH;
469                 $cookiehash = COOKIEHASH;
470         } else {
471                 $sitecookiepath = preg_replace('|https?://[^/]+|i', '', $siteurl . '/' );
472                 $cookiehash = md5($siteurl);
473         }
474
475         if ( $remember )
476                 $expire = time() + 31536000;
477         else
478                 $expire = 0;
479
480         setcookie(USER_COOKIE, $username, $expire, $cookiepath, COOKIE_DOMAIN);
481         setcookie(PASS_COOKIE, $password, $expire, $cookiepath, COOKIE_DOMAIN);
482
483         if ( $cookiepath != $sitecookiepath ) {
484                 setcookie(USER_COOKIE, $username, $expire, $sitecookiepath, COOKIE_DOMAIN);
485                 setcookie(PASS_COOKIE, $password, $expire, $sitecookiepath, COOKIE_DOMAIN);
486         }
487 }
488 endif;
489
490 if ( !function_exists('wp_clearcookie') ) :
491 function wp_clearcookie() {
492         setcookie(USER_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN);
493         setcookie(PASS_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN);
494         setcookie(USER_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN);
495         setcookie(PASS_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN);
496 }
497 endif;
498
499 if ( ! function_exists('wp_notify_postauthor') ) :
500 function wp_notify_postauthor($comment_id, $comment_type='') {
501         global $wpdb;
502
503         $comment = get_comment($comment_id);
504         $post    = get_post($comment->comment_post_ID);
505         $user    = get_userdata( $post->post_author );
506
507         if ('' == $user->user_email) return false; // If there's no email to send the comment to
508
509         $comment_author_domain = @gethostbyaddr($comment->comment_author_IP);
510
511         $blogname = get_option('blogname');
512
513         if ( empty( $comment_type ) ) $comment_type = 'comment';
514
515         if ('comment' == $comment_type) {
516                 $notify_message  = sprintf( __('New comment on your post #%1$s "%2$s"'), $comment->comment_post_ID, $post->post_title ) . "\r\n";
517                 $notify_message .= sprintf( __('Author : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
518                 $notify_message .= sprintf( __('E-mail : %s'), $comment->comment_author_email ) . "\r\n";
519                 $notify_message .= sprintf( __('URL    : %s'), $comment->comment_author_url ) . "\r\n";
520                 $notify_message .= sprintf( __('Whois  : http://ws.arin.net/cgi-bin/whois.pl?queryinput=%s'), $comment->comment_author_IP ) . "\r\n";
521                 $notify_message .= __('Comment: ') . "\r\n" . $comment->comment_content . "\r\n\r\n";
522                 $notify_message .= __('You can see all comments on this post here: ') . "\r\n";
523                 $subject = sprintf( __('[%1$s] Comment: "%2$s"'), $blogname, $post->post_title );
524         } elseif ('trackback' == $comment_type) {
525                 $notify_message  = sprintf( __('New trackback on your post #%1$s "%2$s"'), $comment->comment_post_ID, $post->post_title ) . "\r\n";
526                 $notify_message .= sprintf( __('Website: %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
527                 $notify_message .= sprintf( __('URL    : %s'), $comment->comment_author_url ) . "\r\n";
528                 $notify_message .= __('Excerpt: ') . "\r\n" . $comment->comment_content . "\r\n\r\n";
529                 $notify_message .= __('You can see all trackbacks on this post here: ') . "\r\n";
530                 $subject = sprintf( __('[%1$s] Trackback: "%2$s"'), $blogname, $post->post_title );
531         } elseif ('pingback' == $comment_type) {
532                 $notify_message  = sprintf( __('New pingback on your post #%1$s "%2$s"'), $comment->comment_post_ID, $post->post_title ) . "\r\n";
533                 $notify_message .= sprintf( __('Website: %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
534                 $notify_message .= sprintf( __('URL    : %s'), $comment->comment_author_url ) . "\r\n";
535                 $notify_message .= __('Excerpt: ') . "\r\n" . sprintf('[...] %s [...]', $comment->comment_content ) . "\r\n\r\n";
536                 $notify_message .= __('You can see all pingbacks on this post here: ') . "\r\n";
537                 $subject = sprintf( __('[%1$s] Pingback: "%2$s"'), $blogname, $post->post_title );
538         }
539         $notify_message .= get_permalink($comment->comment_post_ID) . "#comments\r\n\r\n";
540         $notify_message .= sprintf( __('Delete it: %s'), get_option('siteurl')."/wp-admin/comment.php?action=cdc&c=$comment_id" ) . "\r\n";
541         $notify_message .= sprintf( __('Spam it: %s'), get_option('siteurl')."/wp-admin/comment.php?action=cdc&dt=spam&c=$comment_id" ) . "\r\n";
542
543         $wp_email = 'wordpress@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME']));
544
545         if ( '' == $comment->comment_author ) {
546                 $from = "From: \"$blogname\" <$wp_email>";
547                 if ( '' != $comment->comment_author_email )
548                         $reply_to = "Reply-To: $comment->comment_author_email";
549         } else {
550                 $from = "From: \"$comment->comment_author\" <$wp_email>";
551                 if ( '' != $comment->comment_author_email )
552                         $reply_to = "Reply-To: \"$comment->comment_author_email\" <$comment->comment_author_email>";
553         }
554
555         $message_headers = "$from\n"
556                 . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
557
558         if ( isset($reply_to) )
559                 $message_headers .= $reply_to . "\n";
560
561         $notify_message = apply_filters('comment_notification_text', $notify_message, $comment_id);
562         $subject = apply_filters('comment_notification_subject', $subject, $comment_id);
563         $message_headers = apply_filters('comment_notification_headers', $message_headers, $comment_id);
564
565         @wp_mail($user->user_email, $subject, $notify_message, $message_headers);
566
567         return true;
568 }
569 endif;
570
571 /* wp_notify_moderator
572    notifies the moderator of the blog (usually the admin)
573    about a new comment that waits for approval
574    always returns true
575  */
576 if ( !function_exists('wp_notify_moderator') ) :
577 function wp_notify_moderator($comment_id) {
578         global $wpdb;
579
580         if( get_option( "moderation_notify" ) == 0 )
581                 return true;
582
583         $comment = $wpdb->get_row("SELECT * FROM $wpdb->comments WHERE comment_ID='$comment_id' LIMIT 1");
584         $post = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID='$comment->comment_post_ID' LIMIT 1");
585
586         $comment_author_domain = @gethostbyaddr($comment->comment_author_IP);
587         $comments_waiting = $wpdb->get_var("SELECT count(comment_ID) FROM $wpdb->comments WHERE comment_approved = '0'");
588
589         $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";
590         $notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n";
591         $notify_message .= sprintf( __('Author : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
592         $notify_message .= sprintf( __('E-mail : %s'), $comment->comment_author_email ) . "\r\n";
593         $notify_message .= sprintf( __('URL    : %s'), $comment->comment_author_url ) . "\r\n";
594         $notify_message .= sprintf( __('Whois  : http://ws.arin.net/cgi-bin/whois.pl?queryinput=%s'), $comment->comment_author_IP ) . "\r\n";
595         $notify_message .= __('Comment: ') . "\r\n" . $comment->comment_content . "\r\n\r\n";
596         $notify_message .= sprintf( __('Approve it: %s'),  get_option('siteurl')."/wp-admin/comment.php?action=mac&c=$comment_id" ) . "\r\n";
597         $notify_message .= sprintf( __('Delete it: %s'), get_option('siteurl')."/wp-admin/comment.php?action=cdc&c=$comment_id" ) . "\r\n";
598         $notify_message .= sprintf( __('Spam it: %s'), get_option('siteurl')."/wp-admin/comment.php?action=cdc&dt=spam&c=$comment_id" ) . "\r\n";
599         $notify_message .= sprintf( __('Currently %s comments are waiting for approval. Please visit the moderation panel:'), $comments_waiting ) . "\r\n";
600         $notify_message .= get_option('siteurl') . "/wp-admin/moderation.php\r\n";
601
602         $subject = sprintf( __('[%1$s] Please moderate: "%2$s"'), get_option('blogname'), $post->post_title );
603         $admin_email = get_option('admin_email');
604
605         $notify_message = apply_filters('comment_moderation_text', $notify_message, $comment_id);
606         $subject = apply_filters('comment_moderation_subject', $subject, $comment_id);
607
608         @wp_mail($admin_email, $subject, $notify_message);
609
610         return true;
611 }
612 endif;
613
614 if ( !function_exists('wp_new_user_notification') ) :
615 function wp_new_user_notification($user_id, $plaintext_pass = '') {
616         $user = new WP_User($user_id);
617
618         $user_login = stripslashes($user->user_login);
619         $user_email = stripslashes($user->user_email);
620
621         $message  = sprintf(__('New user registration on your blog %s:'), get_option('blogname')) . "\r\n\r\n";
622         $message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n";
623         $message .= sprintf(__('E-mail: %s'), $user_email) . "\r\n";
624
625         @wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration'), get_option('blogname')), $message);
626
627         if ( empty($plaintext_pass) )
628                 return;
629
630         $message  = sprintf(__('Username: %s'), $user_login) . "\r\n";
631         $message .= sprintf(__('Password: %s'), $plaintext_pass) . "\r\n";
632         $message .= get_option('siteurl') . "/wp-login.php\r\n";
633
634         wp_mail($user_email, sprintf(__('[%s] Your username and password'), get_option('blogname')), $message);
635
636 }
637 endif;
638
639 if ( !function_exists('wp_verify_nonce') ) :
640 function wp_verify_nonce($nonce, $action = -1) {
641         $user = wp_get_current_user();
642         $uid = (int) $user->id;
643
644         $i = ceil(time() / 43200);
645
646         //Allow for expanding range, but only do one check if we can
647         if( substr(wp_hash($i . $action . $uid), -12, 10) == $nonce || substr(wp_hash(($i - 1) . $action . $uid), -12, 10) == $nonce )
648                 return true;
649         return false;
650 }
651 endif;
652
653 if ( !function_exists('wp_create_nonce') ) :
654 function wp_create_nonce($action = -1) {
655         $user = wp_get_current_user();
656         $uid = (int) $user->id;
657
658         $i = ceil(time() / 43200);
659
660         return substr(wp_hash($i . $action . $uid), -12, 10);
661 }
662 endif;
663
664 if ( !function_exists('wp_salt') ) :
665 function wp_salt() {
666         $salt = get_option('secret');
667         if ( empty($salt) )
668                 $salt = DB_PASSWORD . DB_USER . DB_NAME . DB_HOST . ABSPATH;
669
670         return $salt;
671 }
672 endif;
673
674 if ( !function_exists('wp_hash') ) :
675 function wp_hash($data) {
676         $salt = wp_salt();
677
678         if ( function_exists('hash_hmac') ) {
679                 return hash_hmac('md5', $data, $salt);
680         } else {
681                 return md5($data . $salt);
682         }
683 }
684 endif;
685
686 ?>