2005-04-20 05:37:23 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/* These functions can be replaced via plugins. They are loaded after
|
|
|
|
plugins are loaded. */
|
|
|
|
|
2006-01-13 20:19:09 +01:00
|
|
|
if ( !function_exists('set_current_user') ) :
|
|
|
|
function set_current_user($id, $name = '') {
|
2006-05-12 01:05:45 +02:00
|
|
|
return wp_set_current_user($id, $name);
|
|
|
|
}
|
|
|
|
endif;
|
2006-01-13 20:19:09 +01:00
|
|
|
|
2006-05-12 01:05:45 +02:00
|
|
|
if ( !function_exists('wp_set_current_user') ) :
|
|
|
|
function wp_set_current_user($id, $name = '') {
|
|
|
|
global $current_user;
|
2006-01-13 20:19:09 +01:00
|
|
|
|
2006-05-12 01:05:45 +02:00
|
|
|
if ( isset($current_user) && ($id == $current_user->ID) )
|
|
|
|
return $current_user;
|
2006-01-13 20:19:09 +01:00
|
|
|
|
2006-05-12 01:05:45 +02:00
|
|
|
$current_user = new WP_User($id, $name);
|
2006-01-13 20:19:09 +01:00
|
|
|
|
2006-05-12 01:05:45 +02:00
|
|
|
setup_userdata($current_user->ID);
|
2006-01-13 20:19:09 +01:00
|
|
|
|
|
|
|
do_action('set_current_user');
|
|
|
|
|
|
|
|
return $current_user;
|
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
2006-05-31 08:27:50 +02:00
|
|
|
if ( !function_exists('wp_get_current_user') ) :
|
2006-05-12 01:05:45 +02:00
|
|
|
function wp_get_current_user() {
|
|
|
|
global $current_user;
|
|
|
|
|
|
|
|
get_currentuserinfo();
|
|
|
|
|
|
|
|
return $current_user;
|
|
|
|
}
|
|
|
|
endif;
|
2005-04-20 05:37:23 +02:00
|
|
|
|
|
|
|
if ( !function_exists('get_currentuserinfo') ) :
|
|
|
|
function get_currentuserinfo() {
|
2006-05-12 01:05:45 +02:00
|
|
|
global $current_user;
|
2005-06-13 02:05:41 +02:00
|
|
|
|
2006-01-13 20:19:09 +01:00
|
|
|
if ( defined('XMLRPC_REQUEST') && XMLRPC_REQUEST )
|
|
|
|
return false;
|
|
|
|
|
2006-05-12 01:05:45 +02:00
|
|
|
if ( ! empty($current_user) )
|
|
|
|
return;
|
|
|
|
|
2005-12-13 19:18:07 +01:00
|
|
|
if ( empty($_COOKIE[USER_COOKIE]) || empty($_COOKIE[PASS_COOKIE]) ||
|
|
|
|
!wp_login($_COOKIE[USER_COOKIE], $_COOKIE[PASS_COOKIE], true) ) {
|
2006-05-12 01:05:45 +02:00
|
|
|
wp_set_current_user(0);
|
2005-06-13 02:05:41 +02:00
|
|
|
return false;
|
2005-12-13 04:46:40 +01:00
|
|
|
}
|
2006-05-12 01:05:45 +02:00
|
|
|
|
|
|
|
$user_login = $_COOKIE[USER_COOKIE];
|
|
|
|
wp_set_current_user(0, $user_login);
|
2005-04-20 05:37:23 +02:00
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
|
|
|
if ( !function_exists('get_userdata') ) :
|
2005-06-12 22:49:13 +02:00
|
|
|
function get_userdata( $user_id ) {
|
2005-11-07 22:56:03 +01:00
|
|
|
global $wpdb;
|
2005-06-12 22:49:13 +02:00
|
|
|
$user_id = (int) $user_id;
|
|
|
|
if ( $user_id == 0 )
|
|
|
|
return false;
|
2005-07-12 17:53:13 +02:00
|
|
|
|
2005-11-07 22:56:03 +01:00
|
|
|
$user = wp_cache_get($user_id, 'users');
|
|
|
|
|
|
|
|
if ( $user )
|
|
|
|
return $user;
|
2005-06-12 22:49:13 +02:00
|
|
|
|
2005-11-08 00:09:09 +01:00
|
|
|
if ( !$user = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE ID = '$user_id' LIMIT 1") )
|
2005-11-07 22:56:03 +01:00
|
|
|
return false;
|
2005-06-12 22:49:13 +02:00
|
|
|
|
2005-12-23 01:32:15 +01:00
|
|
|
$wpdb->hide_errors();
|
2005-06-12 22:49:13 +02:00
|
|
|
$metavalues = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->usermeta WHERE user_id = '$user_id'");
|
2005-12-23 01:32:15 +01:00
|
|
|
$wpdb->show_errors();
|
2005-06-12 22:49:13 +02:00
|
|
|
|
2005-11-11 01:55:31 +01:00
|
|
|
if ($metavalues) {
|
|
|
|
foreach ( $metavalues as $meta ) {
|
|
|
|
@ $value = unserialize($meta->meta_value);
|
|
|
|
if ($value === FALSE)
|
|
|
|
$value = $meta->meta_value;
|
|
|
|
$user->{$meta->meta_key} = $value;
|
|
|
|
|
|
|
|
// We need to set user_level from meta, not row
|
|
|
|
if ( $wpdb->prefix . 'user_level' == $meta->meta_key )
|
|
|
|
$user->user_level = $meta->meta_value;
|
|
|
|
} // end foreach
|
|
|
|
} //end if
|
2005-04-20 05:37:23 +02:00
|
|
|
|
2006-01-27 19:14:33 +01:00
|
|
|
// For backwards compat.
|
|
|
|
if ( isset($user->first_name) )
|
|
|
|
$user->user_firstname = $user->first_name;
|
|
|
|
if ( isset($user->last_name) )
|
|
|
|
$user->user_lastname = $user->last_name;
|
|
|
|
if ( isset($user->description) )
|
|
|
|
$user->user_description = $user->description;
|
|
|
|
|
2005-11-07 22:56:03 +01:00
|
|
|
wp_cache_add($user_id, $user, 'users');
|
2005-12-19 20:14:22 +01:00
|
|
|
wp_cache_add($user->user_login, $user, 'userlogins');
|
2005-11-07 22:56:03 +01:00
|
|
|
|
|
|
|
return $user;
|
2005-04-20 05:37:23 +02:00
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
2005-07-12 17:53:13 +02:00
|
|
|
if ( !function_exists('update_user_cache') ) :
|
|
|
|
function update_user_cache() {
|
2005-11-17 19:15:59 +01:00
|
|
|
return true;
|
2005-07-12 17:53:13 +02:00
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
2005-04-20 05:37:23 +02:00
|
|
|
if ( !function_exists('get_userdatabylogin') ) :
|
|
|
|
function get_userdatabylogin($user_login) {
|
2005-11-17 19:15:59 +01:00
|
|
|
global $wpdb;
|
2005-06-13 01:14:52 +02:00
|
|
|
$user_login = sanitize_user( $user_login );
|
2005-10-30 01:23:17 +02:00
|
|
|
|
2005-06-12 22:49:13 +02:00
|
|
|
if ( empty( $user_login ) )
|
|
|
|
return false;
|
2005-11-07 22:56:03 +01:00
|
|
|
|
2005-12-19 20:14:22 +01:00
|
|
|
$userdata = wp_cache_get($user_login, 'userlogins');
|
2005-11-07 22:56:03 +01:00
|
|
|
if ( $userdata )
|
|
|
|
return $userdata;
|
2005-06-12 22:49:13 +02:00
|
|
|
|
2005-10-30 01:23:17 +02:00
|
|
|
if ( !$user = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE user_login = '$user_login'") )
|
2005-11-17 19:15:59 +01:00
|
|
|
return false;
|
2005-10-30 01:23:17 +02:00
|
|
|
|
2005-12-23 01:32:15 +01:00
|
|
|
$wpdb->hide_errors();
|
2005-10-30 01:23:17 +02:00
|
|
|
$metavalues = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->usermeta WHERE user_id = '$user->ID'");
|
2005-12-23 01:32:15 +01:00
|
|
|
$wpdb->show_errors();
|
2005-10-30 01:23:17 +02:00
|
|
|
|
2005-11-17 19:15:59 +01:00
|
|
|
if ($metavalues) {
|
|
|
|
foreach ( $metavalues as $meta ) {
|
|
|
|
@ $value = unserialize($meta->meta_value);
|
|
|
|
if ($value === FALSE)
|
|
|
|
$value = $meta->meta_value;
|
|
|
|
$user->{$meta->meta_key} = $value;
|
2005-10-30 01:23:17 +02:00
|
|
|
|
2005-11-17 19:15:59 +01:00
|
|
|
// We need to set user_level from meta, not row
|
|
|
|
if ( $wpdb->prefix . 'user_level' == $meta->meta_key )
|
|
|
|
$user->user_level = $meta->meta_value;
|
|
|
|
}
|
2005-10-30 01:23:17 +02:00
|
|
|
}
|
|
|
|
|
2006-01-27 19:14:33 +01:00
|
|
|
// For backwards compat.
|
|
|
|
if ( isset($user->first_name) )
|
|
|
|
$user->user_firstname = $user->first_name;
|
|
|
|
if ( isset($user->last_name) )
|
|
|
|
$user->user_lastname = $user->last_name;
|
|
|
|
if ( isset($user->description) )
|
|
|
|
$user->user_description = $user->description;
|
|
|
|
|
2005-11-17 19:15:59 +01:00
|
|
|
wp_cache_add($user->ID, $user, 'users');
|
2005-12-19 20:14:22 +01:00
|
|
|
wp_cache_add($user->user_login, $user, 'userlogins');
|
2005-10-30 01:23:17 +02:00
|
|
|
|
2005-11-17 19:15:59 +01:00
|
|
|
return $user;
|
2005-10-30 01:23:17 +02:00
|
|
|
|
2005-04-20 05:37:23 +02:00
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
|
|
|
if ( !function_exists('wp_mail') ) :
|
|
|
|
function wp_mail($to, $subject, $message, $headers = '') {
|
|
|
|
if( $headers == '' ) {
|
2005-05-14 02:22:30 +02:00
|
|
|
$headers = "MIME-Version: 1.0\n" .
|
2005-11-25 23:57:26 +01:00
|
|
|
"From: wordpress@" . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME'])) . "\n" .
|
2005-05-14 02:22:30 +02:00
|
|
|
"Content-Type: text/plain; charset=\"" . get_settings('blog_charset') . "\"\n";
|
2005-04-20 05:37:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return @mail($to, $subject, $message, $headers);
|
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
|
|
|
if ( !function_exists('wp_login') ) :
|
|
|
|
function wp_login($username, $password, $already_md5 = false) {
|
|
|
|
global $wpdb, $error;
|
|
|
|
|
2005-11-17 01:51:34 +01:00
|
|
|
if ( '' == $username )
|
2005-04-20 05:37:23 +02:00
|
|
|
return false;
|
|
|
|
|
2005-11-17 01:51:34 +01:00
|
|
|
if ( '' == $password ) {
|
2005-04-20 05:37:23 +02:00
|
|
|
$error = __('<strong>Error</strong>: The password field is empty.');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2005-11-07 22:56:03 +01:00
|
|
|
$login = get_userdatabylogin($username);
|
|
|
|
//$login = $wpdb->get_row("SELECT ID, user_login, user_pass FROM $wpdb->users WHERE user_login = '$username'");
|
2005-04-20 05:37:23 +02:00
|
|
|
|
|
|
|
if (!$login) {
|
|
|
|
$error = __('<strong>Error</strong>: Wrong username.');
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
// If the password is already_md5, it has been double hashed.
|
|
|
|
// Otherwise, it is plain text.
|
2005-08-23 09:51:14 +02:00
|
|
|
if ( ($already_md5 && md5($login->user_pass) == $password) || ($login->user_login == $username && $login->user_pass == md5($password)) ) {
|
2005-04-20 05:37:23 +02:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
$error = __('<strong>Error</strong>: Incorrect password.');
|
|
|
|
$pwd = '';
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
2005-12-15 17:31:41 +01:00
|
|
|
if ( !function_exists('is_user_logged_in') ) :
|
|
|
|
function is_user_logged_in() {
|
2006-05-12 01:05:45 +02:00
|
|
|
$user = wp_get_current_user();
|
2005-12-15 17:31:41 +01:00
|
|
|
|
2006-05-12 01:05:45 +02:00
|
|
|
if ( $user->id == 0 )
|
2005-12-15 17:31:41 +01:00
|
|
|
return false;
|
2006-05-12 01:05:45 +02:00
|
|
|
|
2005-12-15 17:31:41 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
2005-04-20 05:37:23 +02:00
|
|
|
if ( !function_exists('auth_redirect') ) :
|
|
|
|
function auth_redirect() {
|
|
|
|
// Checks if a user is logged in, if not redirects them to the login page
|
2005-07-18 22:12:48 +02:00
|
|
|
if ( (!empty($_COOKIE[USER_COOKIE]) &&
|
|
|
|
!wp_login($_COOKIE[USER_COOKIE], $_COOKIE[PASS_COOKIE], true)) ||
|
|
|
|
(empty($_COOKIE[USER_COOKIE])) ) {
|
2005-06-09 02:17:43 +02:00
|
|
|
nocache_headers();
|
2005-04-20 05:37:23 +02:00
|
|
|
|
2006-06-28 01:10:02 +02:00
|
|
|
wp_redirect(get_settings('siteurl') . '/wp-login.php?redirect_to=' . urlencode($_SERVER['REQUEST_URI']));
|
2005-04-20 05:37:23 +02:00
|
|
|
exit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
2006-01-30 00:06:58 +01:00
|
|
|
if ( !function_exists('check_admin_referer') ) :
|
2006-05-12 01:05:45 +02:00
|
|
|
function check_admin_referer($action = -1) {
|
2006-01-30 00:06:58 +01:00
|
|
|
$adminurl = strtolower(get_settings('siteurl')).'/wp-admin';
|
2006-06-24 07:41:59 +02:00
|
|
|
$referer = strtolower(wp_get_referer());
|
2006-05-18 03:02:25 +02:00
|
|
|
if ( !wp_verify_nonce($_REQUEST['_wpnonce'], $action) &&
|
|
|
|
!(-1 == $action && strstr($referer, $adminurl)) ) {
|
2006-06-28 00:57:49 +02:00
|
|
|
wp_nonce_ays($action);
|
|
|
|
die();
|
2006-05-12 01:05:45 +02:00
|
|
|
}
|
2006-06-28 00:57:49 +02:00
|
|
|
do_action('check_admin_referer', $action);
|
|
|
|
}
|
|
|
|
endif;
|
2006-01-30 00:06:58 +01:00
|
|
|
|
2006-04-21 23:18:32 +02:00
|
|
|
if ( !function_exists('check_ajax_referer') ) :
|
|
|
|
function check_ajax_referer() {
|
2006-04-22 00:18:58 +02:00
|
|
|
$cookie = explode('; ', urldecode(empty($_POST['cookie']) ? $_GET['cookie'] : $_POST['cookie'])); // AJAX scripts must pass cookie=document.cookie
|
2006-04-21 23:18:32 +02:00
|
|
|
foreach ( $cookie as $tasty ) {
|
|
|
|
if ( false !== strpos($tasty, USER_COOKIE) )
|
|
|
|
$user = substr(strstr($tasty, '='), 1);
|
|
|
|
if ( false !== strpos($tasty, PASS_COOKIE) )
|
|
|
|
$pass = substr(strstr($tasty, '='), 1);
|
|
|
|
}
|
|
|
|
if ( wp_login( $user, $pass, true ) )
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
2005-04-20 05:37:23 +02:00
|
|
|
// Cookie safe redirect. Works around IIS Set-Cookie bug.
|
|
|
|
// http://support.microsoft.com/kb/q176113/
|
|
|
|
if ( !function_exists('wp_redirect') ) :
|
|
|
|
function wp_redirect($location) {
|
|
|
|
global $is_IIS;
|
|
|
|
|
2006-06-30 02:44:21 +02:00
|
|
|
$location = preg_replace('|[^a-z0-9-~+_.?#=&;,/:%]|i', '', $location);
|
|
|
|
|
|
|
|
$strip = array('%0d', '%0a');
|
|
|
|
$location = str_replace($strip, '', $location);
|
2005-11-13 05:38:56 +01:00
|
|
|
|
2005-04-20 05:37:23 +02:00
|
|
|
if ($is_IIS)
|
|
|
|
header("Refresh: 0;url=$location");
|
|
|
|
else
|
|
|
|
header("Location: $location");
|
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
2006-05-12 01:05:45 +02:00
|
|
|
if ( !function_exists('wp_get_cookie_login') ):
|
|
|
|
function wp_get_cookie_login() {
|
|
|
|
if ( empty($_COOKIE[USER_COOKIE]) || empty($_COOKIE[PASS_COOKIE]) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return array('login' => $_COOKIE[USER_COOKIE], 'password' => $_COOKIE[PASS_COOKIE]);
|
|
|
|
}
|
|
|
|
|
|
|
|
endif;
|
|
|
|
|
2005-04-20 05:37:23 +02:00
|
|
|
if ( !function_exists('wp_setcookie') ) :
|
2005-07-23 08:56:59 +02:00
|
|
|
function wp_setcookie($username, $password, $already_md5 = false, $home = '', $siteurl = '', $remember = false) {
|
2005-04-20 05:37:23 +02:00
|
|
|
if ( !$already_md5 )
|
|
|
|
$password = md5( md5($password) ); // Double hash the password in the cookie.
|
|
|
|
|
|
|
|
if ( empty($home) )
|
|
|
|
$cookiepath = COOKIEPATH;
|
|
|
|
else
|
|
|
|
$cookiepath = preg_replace('|https?://[^/]+|i', '', $home . '/' );
|
|
|
|
|
|
|
|
if ( empty($siteurl) ) {
|
|
|
|
$sitecookiepath = SITECOOKIEPATH;
|
|
|
|
$cookiehash = COOKIEHASH;
|
|
|
|
} else {
|
|
|
|
$sitecookiepath = preg_replace('|https?://[^/]+|i', '', $siteurl . '/' );
|
|
|
|
$cookiehash = md5($siteurl);
|
|
|
|
}
|
|
|
|
|
2005-07-23 08:56:59 +02:00
|
|
|
if ( $remember )
|
|
|
|
$expire = time() + 31536000;
|
|
|
|
else
|
|
|
|
$expire = 0;
|
|
|
|
|
|
|
|
setcookie(USER_COOKIE, $username, $expire, $cookiepath, COOKIE_DOMAIN);
|
|
|
|
setcookie(PASS_COOKIE, $password, $expire, $cookiepath, COOKIE_DOMAIN);
|
2005-04-20 05:37:23 +02:00
|
|
|
|
|
|
|
if ( $cookiepath != $sitecookiepath ) {
|
2005-07-23 08:56:59 +02:00
|
|
|
setcookie(USER_COOKIE, $username, $expire, $sitecookiepath, COOKIE_DOMAIN);
|
|
|
|
setcookie(PASS_COOKIE, $password, $expire, $sitecookiepath, COOKIE_DOMAIN);
|
2005-04-20 05:37:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
|
|
|
if ( !function_exists('wp_clearcookie') ) :
|
|
|
|
function wp_clearcookie() {
|
2005-07-18 21:55:24 +02:00
|
|
|
setcookie(USER_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN);
|
|
|
|
setcookie(PASS_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN);
|
|
|
|
setcookie(USER_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN);
|
|
|
|
setcookie(PASS_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN);
|
2005-04-20 05:37:23 +02:00
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
|
|
|
if ( ! function_exists('wp_notify_postauthor') ) :
|
|
|
|
function wp_notify_postauthor($comment_id, $comment_type='') {
|
|
|
|
global $wpdb;
|
|
|
|
|
2005-11-08 00:15:21 +01:00
|
|
|
$comment = get_comment($comment_id);
|
|
|
|
$post = get_post($comment->comment_post_ID);
|
2005-11-07 09:58:37 +01:00
|
|
|
$user = get_userdata( $post->post_author );
|
2005-04-20 05:37:23 +02:00
|
|
|
|
|
|
|
if ('' == $user->user_email) return false; // If there's no email to send the comment to
|
|
|
|
|
|
|
|
$comment_author_domain = gethostbyaddr($comment->comment_author_IP);
|
|
|
|
|
|
|
|
$blogname = get_settings('blogname');
|
|
|
|
|
|
|
|
if ( empty( $comment_type ) ) $comment_type = 'comment';
|
|
|
|
|
|
|
|
if ('comment' == $comment_type) {
|
|
|
|
$notify_message = sprintf( __('New comment on your post #%1$s "%2$s"'), $comment->comment_post_ID, $post->post_title ) . "\r\n";
|
|
|
|
$notify_message .= sprintf( __('Author : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
|
|
|
|
$notify_message .= sprintf( __('E-mail : %s'), $comment->comment_author_email ) . "\r\n";
|
|
|
|
$notify_message .= sprintf( __('URI : %s'), $comment->comment_author_url ) . "\r\n";
|
|
|
|
$notify_message .= sprintf( __('Whois : http://ws.arin.net/cgi-bin/whois.pl?queryinput=%s'), $comment->comment_author_IP ) . "\r\n";
|
|
|
|
$notify_message .= __('Comment: ') . "\r\n" . $comment->comment_content . "\r\n\r\n";
|
|
|
|
$notify_message .= __('You can see all comments on this post here: ') . "\r\n";
|
|
|
|
$subject = sprintf( __('[%1$s] Comment: "%2$s"'), $blogname, $post->post_title );
|
|
|
|
} elseif ('trackback' == $comment_type) {
|
|
|
|
$notify_message = sprintf( __('New trackback on your post #%1$s "%2$s"'), $comment->comment_post_ID, $post->post_title ) . "\r\n";
|
|
|
|
$notify_message .= sprintf( __('Website: %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
|
|
|
|
$notify_message .= sprintf( __('URI : %s'), $comment->comment_author_url ) . "\r\n";
|
|
|
|
$notify_message .= __('Excerpt: ') . "\r\n" . $comment->comment_content . "\r\n\r\n";
|
|
|
|
$notify_message .= __('You can see all trackbacks on this post here: ') . "\r\n";
|
|
|
|
$subject = sprintf( __('[%1$s] Trackback: "%2$s"'), $blogname, $post->post_title );
|
|
|
|
} elseif ('pingback' == $comment_type) {
|
|
|
|
$notify_message = sprintf( __('New pingback on your post #%1$s "%2$s"'), $comment->comment_post_ID, $post->post_title ) . "\r\n";
|
|
|
|
$notify_message .= sprintf( __('Website: %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
|
|
|
|
$notify_message .= sprintf( __('URI : %s'), $comment->comment_author_url ) . "\r\n";
|
2005-12-02 23:37:02 +01:00
|
|
|
$notify_message .= __('Excerpt: ') . "\r\n" . sprintf('[...] %s [...]', $comment->comment_content ) . "\r\n\r\n";
|
2005-04-20 05:37:23 +02:00
|
|
|
$notify_message .= __('You can see all pingbacks on this post here: ') . "\r\n";
|
|
|
|
$subject = sprintf( __('[%1$s] Pingback: "%2$s"'), $blogname, $post->post_title );
|
|
|
|
}
|
|
|
|
$notify_message .= get_permalink($comment->comment_post_ID) . "#comments\r\n\r\n";
|
|
|
|
$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";
|
|
|
|
|
2005-11-25 23:57:26 +01:00
|
|
|
$wp_email = 'wordpress@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME']));
|
2005-11-11 01:07:39 +01:00
|
|
|
|
|
|
|
if ( '' == $comment->comment_author ) {
|
2005-11-25 23:57:26 +01:00
|
|
|
$from = "From: \"$blogname\" <$wp_email>";
|
2005-11-11 01:07:39 +01:00
|
|
|
if ( '' != $comment->comment_author_email )
|
|
|
|
$reply_to = "Reply-To: $comment->comment_author_email";
|
|
|
|
} else {
|
2005-11-25 23:57:26 +01:00
|
|
|
$from = "From: \"$comment->comment_author\" <$wp_email>";
|
2005-11-11 01:07:39 +01:00
|
|
|
if ( '' != $comment->comment_author_email )
|
|
|
|
$reply_to = "Reply-To: \"$comment->comment_author_email\" <$comment->comment_author_email>";
|
|
|
|
}
|
2005-04-20 05:37:23 +02:00
|
|
|
|
2005-05-14 02:22:30 +02:00
|
|
|
$message_headers = "MIME-Version: 1.0\n"
|
|
|
|
. "$from\n"
|
|
|
|
. "Content-Type: text/plain; charset=\"" . get_settings('blog_charset') . "\"\n";
|
2005-04-20 05:37:23 +02:00
|
|
|
|
2005-11-11 03:00:06 +01:00
|
|
|
if ( isset($reply_to) )
|
|
|
|
$message_headers .= $reply_to . "\n";
|
|
|
|
|
2006-01-18 19:49:28 +01:00
|
|
|
$notify_message = apply_filters('comment_notification_text', $notify_message, $comment_id);
|
|
|
|
$subject = apply_filters('comment_notification_subject', $subject, $comment_id);
|
|
|
|
$message_headers = apply_filters('comment_notification_headers', $message_headers, $comment_id);
|
2005-08-31 01:17:42 +02:00
|
|
|
|
2005-04-20 05:37:23 +02:00
|
|
|
@wp_mail($user->user_email, $subject, $notify_message, $message_headers);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
|
|
|
/* wp_notify_moderator
|
|
|
|
notifies the moderator of the blog (usually the admin)
|
|
|
|
about a new comment that waits for approval
|
|
|
|
always returns true
|
|
|
|
*/
|
|
|
|
if ( !function_exists('wp_notify_moderator') ) :
|
|
|
|
function wp_notify_moderator($comment_id) {
|
|
|
|
global $wpdb;
|
|
|
|
|
|
|
|
if( get_settings( "moderation_notify" ) == 0 )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
$comment = $wpdb->get_row("SELECT * FROM $wpdb->comments WHERE comment_ID='$comment_id' LIMIT 1");
|
|
|
|
$post = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID='$comment->comment_post_ID' LIMIT 1");
|
|
|
|
|
|
|
|
$comment_author_domain = gethostbyaddr($comment->comment_author_IP);
|
|
|
|
$comments_waiting = $wpdb->get_var("SELECT count(comment_ID) FROM $wpdb->comments WHERE comment_approved = '0'");
|
|
|
|
|
|
|
|
$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";
|
|
|
|
$notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n";
|
|
|
|
$notify_message .= sprintf( __('Author : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
|
|
|
|
$notify_message .= sprintf( __('E-mail : %s'), $comment->comment_author_email ) . "\r\n";
|
|
|
|
$notify_message .= sprintf( __('URI : %s'), $comment->comment_author_url ) . "\r\n";
|
|
|
|
$notify_message .= sprintf( __('Whois : http://ws.arin.net/cgi-bin/whois.pl?queryinput=%s'), $comment->comment_author_IP ) . "\r\n";
|
|
|
|
$notify_message .= __('Comment: ') . "\r\n" . $comment->comment_content . "\r\n\r\n";
|
|
|
|
$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";
|
|
|
|
$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";
|
|
|
|
$notify_message .= sprintf( __('Currently %s comments are waiting for approval. Please visit the moderation panel:'), $comments_waiting ) . "\r\n";
|
|
|
|
$notify_message .= get_settings('siteurl') . "/wp-admin/moderation.php\r\n";
|
|
|
|
|
|
|
|
$subject = sprintf( __('[%1$s] Please moderate: "%2$s"'), get_settings('blogname'), $post->post_title );
|
2005-08-31 01:17:42 +02:00
|
|
|
$admin_email = get_settings('admin_email');
|
|
|
|
|
2006-01-18 19:49:28 +01:00
|
|
|
$notify_message = apply_filters('comment_moderation_text', $notify_message, $comment_id);
|
|
|
|
$subject = apply_filters('comment_moderation_subject', $subject, $comment_id);
|
2005-04-20 05:37:23 +02:00
|
|
|
|
|
|
|
@wp_mail($admin_email, $subject, $notify_message);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
2005-09-14 02:03:02 +02:00
|
|
|
if ( !function_exists('wp_new_user_notification') ) :
|
|
|
|
function wp_new_user_notification($user_id, $plaintext_pass = '') {
|
|
|
|
$user = new WP_User($user_id);
|
|
|
|
|
2005-11-16 03:54:23 +01:00
|
|
|
$user_login = stripslashes($user->user_login);
|
|
|
|
$user_email = stripslashes($user->user_email);
|
2005-09-14 02:03:02 +02:00
|
|
|
|
|
|
|
$message = sprintf(__('New user registration on your blog %s:'), get_settings('blogname')) . "\r\n\r\n";
|
|
|
|
$message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n";
|
|
|
|
$message .= sprintf(__('E-mail: %s'), $user_email) . "\r\n";
|
|
|
|
|
|
|
|
@wp_mail(get_settings('admin_email'), sprintf(__('[%s] New User Registration'), get_settings('blogname')), $message);
|
|
|
|
|
|
|
|
if ( empty($plaintext_pass) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
$message = sprintf(__('Username: %s'), $user_login) . "\r\n";
|
|
|
|
$message .= sprintf(__('Password: %s'), $plaintext_pass) . "\r\n";
|
|
|
|
$message .= get_settings('siteurl') . "/wp-login.php\r\n";
|
|
|
|
|
|
|
|
wp_mail($user_email, sprintf(__('[%s] Your username and password'), get_settings('blogname')), $message);
|
|
|
|
|
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
2006-05-12 01:05:45 +02:00
|
|
|
if ( !function_exists('wp_verify_nonce') ) :
|
|
|
|
function wp_verify_nonce($nonce, $action = -1) {
|
|
|
|
$user = wp_get_current_user();
|
|
|
|
$uid = $user->id;
|
|
|
|
|
|
|
|
$i = ceil(time() / 43200);
|
|
|
|
|
|
|
|
//Allow for expanding range, but only do one check if we can
|
2006-05-31 07:01:09 +02:00
|
|
|
if( substr(wp_hash($i . $action . $uid), -12, 10) == $nonce || substr(wp_hash(($i - 1) . $action . $uid), -12, 10) == $nonce )
|
2006-05-12 01:05:45 +02:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
|
|
|
if ( !function_exists('wp_create_nonce') ) :
|
|
|
|
function wp_create_nonce($action = -1) {
|
|
|
|
$user = wp_get_current_user();
|
|
|
|
$uid = $user->id;
|
|
|
|
|
|
|
|
$i = ceil(time() / 43200);
|
|
|
|
|
2006-05-31 07:01:09 +02:00
|
|
|
return substr(wp_hash($i . $action . $uid), -12, 10);
|
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
|
|
|
if ( !function_exists('wp_salt') ) :
|
|
|
|
function wp_salt() {
|
|
|
|
$salt = get_option('secret');
|
|
|
|
if ( empty($salt) )
|
|
|
|
$salt = DB_PASSWORD . DB_USER . DB_NAME . DB_HOST . ABSPATH;
|
|
|
|
|
|
|
|
return $salt;
|
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
|
|
|
if ( !function_exists('wp_hash') ) :
|
|
|
|
function wp_hash($data) {
|
|
|
|
$salt = wp_salt();
|
|
|
|
|
|
|
|
if ( function_exists('hash_hmac') ) {
|
|
|
|
return hash_hmac('md5', $data, $salt);
|
|
|
|
} else {
|
|
|
|
return md5($data . $salt);
|
|
|
|
}
|
2006-05-12 01:05:45 +02:00
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
2005-07-12 17:53:13 +02:00
|
|
|
?>
|