| [ Index ] |
|
Code source de WordPress 2.1.2 |
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 $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(); 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, 'userlogins'); 100 101 return $user; 102 } 103 endif; 104 105 if ( !function_exists('update_user_cache') ) : 106 function update_user_cache() { 107 return true; 108 } 109 endif; 110 111 if ( !function_exists('get_userdatabylogin') ) : 112 function get_userdatabylogin($user_login) { 113 global $wpdb; 114 $user_login = sanitize_user( $user_login ); 115 116 if ( empty( $user_login ) ) 117 return false; 118 119 $userdata = wp_cache_get($user_login, 'userlogins'); 120 if ( $userdata ) 121 return $userdata; 122 123 if ( !$user = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE user_login = '$user_login'") ) 124 return false; 125 126 $wpdb->hide_errors(); 127 $metavalues = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->usermeta WHERE user_id = '$user->ID'"); 128 $wpdb->show_errors(); 129 130 if ($metavalues) { 131 foreach ( $metavalues as $meta ) { 132 $value = maybe_unserialize($meta->meta_value); 133 $user->{$meta->meta_key} = $value; 134 135 // We need to set user_level from meta, not row 136 if ( $wpdb->prefix . 'user_level' == $meta->meta_key ) 137 $user->user_level = $meta->meta_value; 138 } 139 } 140 141 // For backwards compat. 142 if ( isset($user->first_name) ) 143 $user->user_firstname = $user->first_name; 144 if ( isset($user->last_name) ) 145 $user->user_lastname = $user->last_name; 146 if ( isset($user->description) ) 147 $user->user_description = $user->description; 148 149 wp_cache_add($user->ID, $user, 'users'); 150 wp_cache_add($user->user_login, $user, 'userlogins'); 151 152 return $user; 153 154 } 155 endif; 156 157 if ( !function_exists('wp_mail') ) : 158 function wp_mail($to, $subject, $message, $headers = '') { 159 if( $headers == '' ) { 160 $headers = "MIME-Version: 1.0\n" . 161 "From: wordpress@" . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME'])) . "\n" . 162 "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n"; 163 } 164 165 return @mail($to, $subject, $message, $headers); 166 } 167 endif; 168 169 if ( !function_exists('wp_login') ) : 170 function wp_login($username, $password, $already_md5 = false) { 171 global $wpdb, $error; 172 173 if ( '' == $username ) 174 return false; 175 176 if ( '' == $password ) { 177 $error = __('<strong>ERROR</strong>: The password field is empty.'); 178 return false; 179 } 180 181 $login = get_userdatabylogin($username); 182 //$login = $wpdb->get_row("SELECT ID, user_login, user_pass FROM $wpdb->users WHERE user_login = '$username'"); 183 184 if (!$login) { 185 $error = __('<strong>ERROR</strong>: Invalid username.'); 186 return false; 187 } else { 188 // If the password is already_md5, it has been double hashed. 189 // Otherwise, it is plain text. 190 if ( ($already_md5 && md5($login->user_pass) == $password) || ($login->user_login == $username && $login->user_pass == md5($password)) ) { 191 return true; 192 } else { 193 $error = __('<strong>ERROR</strong>: Incorrect password.'); 194 $pwd = ''; 195 return false; 196 } 197 } 198 } 199 endif; 200 201 if ( !function_exists('is_user_logged_in') ) : 202 function is_user_logged_in() { 203 $user = wp_get_current_user(); 204 205 if ( $user->id == 0 ) 206 return false; 207 208 return true; 209 } 210 endif; 211 212 if ( !function_exists('auth_redirect') ) : 213 function auth_redirect() { 214 // Checks if a user is logged in, if not redirects them to the login page 215 if ( (!empty($_COOKIE[USER_COOKIE]) && 216 !wp_login($_COOKIE[USER_COOKIE], $_COOKIE[PASS_COOKIE], true)) || 217 (empty($_COOKIE[USER_COOKIE])) ) { 218 nocache_headers(); 219 220 wp_redirect(get_option('siteurl') . '/wp-login.php?redirect_to=' . urlencode($_SERVER['REQUEST_URI'])); 221 exit(); 222 } 223 } 224 endif; 225 226 if ( !function_exists('check_admin_referer') ) : 227 function check_admin_referer($action = -1) { 228 $adminurl = strtolower(get_option('siteurl')).'/wp-admin'; 229 $referer = strtolower(wp_get_referer()); 230 if ( !wp_verify_nonce($_REQUEST['_wpnonce'], $action) && 231 !(-1 == $action && strstr($referer, $adminurl)) ) { 232 wp_nonce_ays($action); 233 die(); 234 } 235 do_action('check_admin_referer', $action); 236 }endif; 237 238 if ( !function_exists('check_ajax_referer') ) : 239 function check_ajax_referer() { 240 $cookie = explode('; ', urldecode(empty($_POST['cookie']) ? $_GET['cookie'] : $_POST['cookie'])); // AJAX scripts must pass cookie=document.cookie 241 foreach ( $cookie as $tasty ) { 242 if ( false !== strpos($tasty, USER_COOKIE) ) 243 $user = substr(strstr($tasty, '='), 1); 244 if ( false !== strpos($tasty, PASS_COOKIE) ) 245 $pass = substr(strstr($tasty, '='), 1); 246 } 247 if ( !wp_login( $user, $pass, true ) ) 248 die('-1'); 249 do_action('check_ajax_referer'); 250 } 251 endif; 252 253 // Cookie safe redirect. Works around IIS Set-Cookie bug. 254 // http://support.microsoft.com/kb/q176113/ 255 if ( !function_exists('wp_redirect') ) : 256 function wp_redirect($location, $status = 302) { 257 global $is_IIS; 258 259 $location = apply_filters('wp_redirect', $location, $status); 260 261 if ( !$location ) // allows the wp_redirect filter to cancel a redirect 262 return false; 263 264 $location = preg_replace('|[^a-z0-9-~+_.?#=&;,/:%]|i', '', $location); 265 $location = wp_kses_no_null($location); 266 267 $strip = array('%0d', '%0a'); 268 $location = str_replace($strip, '', $location); 269 270 if ( $is_IIS ) { 271 header("Refresh: 0;url=$location"); 272 } else { 273 if ( php_sapi_name() != 'cgi-fcgi' ) 274 status_header($status); // This causes problems on IIS and some FastCGI setups 275 header("Location: $location"); 276 } 277 } 278 endif; 279 280 if ( !function_exists('wp_get_cookie_login') ): 281 function wp_get_cookie_login() { 282 if ( empty($_COOKIE[USER_COOKIE]) || empty($_COOKIE[PASS_COOKIE]) ) 283 return false; 284 285 return array('login' => $_COOKIE[USER_COOKIE], 'password' => $_COOKIE[PASS_COOKIE]); 286 } 287 288 endif; 289 290 if ( !function_exists('wp_setcookie') ) : 291 function wp_setcookie($username, $password, $already_md5 = false, $home = '', $siteurl = '', $remember = false) { 292 if ( !$already_md5 ) 293 $password = md5( md5($password) ); // Double hash the password in the cookie. 294 295 if ( empty($home) ) 296 $cookiepath = COOKIEPATH; 297 else 298 $cookiepath = preg_replace('|https?://[^/]+|i', '', $home . '/' ); 299 300 if ( empty($siteurl) ) { 301 $sitecookiepath = SITECOOKIEPATH; 302 $cookiehash = COOKIEHASH; 303 } else { 304 $sitecookiepath = preg_replace('|https?://[^/]+|i', '', $siteurl . '/' ); 305 $cookiehash = md5($siteurl); 306 } 307 308 if ( $remember ) 309 $expire = time() + 31536000; 310 else 311 $expire = 0; 312 313 setcookie(USER_COOKIE, $username, $expire, $cookiepath, COOKIE_DOMAIN); 314 setcookie(PASS_COOKIE, $password, $expire, $cookiepath, COOKIE_DOMAIN); 315 316 if ( $cookiepath != $sitecookiepath ) { 317 setcookie(USER_COOKIE, $username, $expire, $sitecookiepath, COOKIE_DOMAIN); 318 setcookie(PASS_COOKIE, $password, $expire, $sitecookiepath, COOKIE_DOMAIN); 319 } 320 } 321 endif; 322 323 if ( !function_exists('wp_clearcookie') ) : 324 function wp_clearcookie() { 325 setcookie(USER_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN); 326 setcookie(PASS_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN); 327 setcookie(USER_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN); 328 setcookie(PASS_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN); 329 } 330 endif; 331 332 if ( ! function_exists('wp_notify_postauthor') ) : 333 function wp_notify_postauthor($comment_id, $comment_type='') { 334 global $wpdb; 335 336 $comment = get_comment($comment_id); 337 $post = get_post($comment->comment_post_ID); 338 $user = get_userdata( $post->post_author ); 339 340 if ('' == $user->user_email) return false; // If there's no email to send the comment to 341 342 $comment_author_domain = @gethostbyaddr($comment->comment_author_IP); 343 344 $blogname = get_option('blogname'); 345 346 if ( empty( $comment_type ) ) $comment_type = 'comment'; 347 348 if ('comment' == $comment_type) { 349 $notify_message = sprintf( __('New comment on your post #%1$s "%2$s"'), $comment->comment_post_ID, $post->post_title ) . "\r\n"; 350 $notify_message .= sprintf( __('Author : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; 351 $notify_message .= sprintf( __('E-mail : %s'), $comment->comment_author_email ) . "\r\n"; 352 $notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n"; 353 $notify_message .= sprintf( __('Whois : http://ws.arin.net/cgi-bin/whois.pl?queryinput=%s'), $comment->comment_author_IP ) . "\r\n"; 354 $notify_message .= __('Comment: ') . "\r\n" . $comment->comment_content . "\r\n\r\n"; 355 $notify_message .= __('You can see all comments on this post here: ') . "\r\n"; 356 $subject = sprintf( __('[%1$s] Comment: "%2$s"'), $blogname, $post->post_title ); 357 } elseif ('trackback' == $comment_type) { 358 $notify_message = sprintf( __('New trackback on your post #%1$s "%2$s"'), $comment->comment_post_ID, $post->post_title ) . "\r\n"; 359 $notify_message .= sprintf( __('Website: %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; 360 $notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n"; 361 $notify_message .= __('Excerpt: ') . "\r\n" . $comment->comment_content . "\r\n\r\n"; 362 $notify_message .= __('You can see all trackbacks on this post here: ') . "\r\n"; 363 $subject = sprintf( __('[%1$s] Trackback: "%2$s"'), $blogname, $post->post_title ); 364 } elseif ('pingback' == $comment_type) { 365 $notify_message = sprintf( __('New pingback on your post #%1$s "%2$s"'), $comment->comment_post_ID, $post->post_title ) . "\r\n"; 366 $notify_message .= sprintf( __('Website: %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; 367 $notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n"; 368 $notify_message .= __('Excerpt: ') . "\r\n" . sprintf('[...] %s [...]', $comment->comment_content ) . "\r\n\r\n"; 369 $notify_message .= __('You can see all pingbacks on this post here: ') . "\r\n"; 370 $subject = sprintf( __('[%1$s] Pingback: "%2$s"'), $blogname, $post->post_title ); 371 } 372 $notify_message .= get_permalink($comment->comment_post_ID) . "#comments\r\n\r\n"; 373 $notify_message .= sprintf( __('To delete this comment, visit: %s'), get_option('siteurl')."/wp-admin/comment.php?action=cdc&c=$comment_id" ) . "\r\n"; 374 $notify_message .= sprintf( __('To mark this comment as spam, visit: %s'), get_option('siteurl')."/wp-admin/comment.php?action=cdc&dt=spam&c=$comment_id" ) . "\r\n"; 375 376 $wp_email = 'wordpress@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME'])); 377 378 if ( '' == $comment->comment_author ) { 379 $from = "From: \"$blogname\" <$wp_email>"; 380 if ( '' != $comment->comment_author_email ) 381 $reply_to = "Reply-To: $comment->comment_author_email"; 382 } else { 383 $from = "From: \"$comment->comment_author\" <$wp_email>"; 384 if ( '' != $comment->comment_author_email ) 385 $reply_to = "Reply-To: \"$comment->comment_author_email\" <$comment->comment_author_email>"; 386 } 387 388 $message_headers = "MIME-Version: 1.0\n" 389 . "$from\n" 390 . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n"; 391 392 if ( isset($reply_to) ) 393 $message_headers .= $reply_to . "\n"; 394 395 $notify_message = apply_filters('comment_notification_text', $notify_message, $comment_id); 396 $subject = apply_filters('comment_notification_subject', $subject, $comment_id); 397 $message_headers = apply_filters('comment_notification_headers', $message_headers, $comment_id); 398 399 @wp_mail($user->user_email, $subject, $notify_message, $message_headers); 400 401 return true; 402 } 403 endif; 404 405 /* wp_notify_moderator 406 notifies the moderator of the blog (usually the admin) 407 about a new comment that waits for approval 408 always returns true 409 */ 410 if ( !function_exists('wp_notify_moderator') ) : 411 function wp_notify_moderator($comment_id) { 412 global $wpdb; 413 414 if( get_option( "moderation_notify" ) == 0 ) 415 return true; 416 417 $comment = $wpdb->get_row("SELECT * FROM $wpdb->comments WHERE comment_ID='$comment_id' LIMIT 1"); 418 $post = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID='$comment->comment_post_ID' LIMIT 1"); 419 420 $comment_author_domain = @gethostbyaddr($comment->comment_author_IP); 421 $comments_waiting = $wpdb->get_var("SELECT count(comment_ID) FROM $wpdb->comments WHERE comment_approved = '0'"); 422 423 $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"; 424 $notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n"; 425 $notify_message .= sprintf( __('Author : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; 426 $notify_message .= sprintf( __('E-mail : %s'), $comment->comment_author_email ) . "\r\n"; 427 $notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n"; 428 $notify_message .= sprintf( __('Whois : http://ws.arin.net/cgi-bin/whois.pl?queryinput=%s'), $comment->comment_author_IP ) . "\r\n"; 429 $notify_message .= __('Comment: ') . "\r\n" . $comment->comment_content . "\r\n\r\n"; 430 $notify_message .= sprintf( __('Approve it: %s'), get_option('siteurl')."/wp-admin/comment.php?action=mac&c=$comment_id" ) . "\r\n"; 431 $notify_message .= sprintf( __('Delete it: %s'), get_option('siteurl')."/wp-admin/comment.php?action=cdc&c=$comment_id" ) . "\r\n"; 432 $notify_message .= sprintf( __('Spam it: %s'), get_option('siteurl')."/wp-admin/comment.php?action=cdc&dt=spam&c=$comment_id" ) . "\r\n"; 433 $notify_message .= sprintf( __('Currently %s comments are waiting for approval. Please visit the moderation panel:'), $comments_waiting ) . "\r\n"; 434 $notify_message .= get_option('siteurl') . "/wp-admin/moderation.php\r\n"; 435 436 $subject = sprintf( __('[%1$s] Please moderate: "%2$s"'), get_option('blogname'), $post->post_title ); 437 $admin_email = get_option('admin_email'); 438 439 $notify_message = apply_filters('comment_moderation_text', $notify_message, $comment_id); 440 $subject = apply_filters('comment_moderation_subject', $subject, $comment_id); 441 442 @wp_mail($admin_email, $subject, $notify_message); 443 444 return true; 445 } 446 endif; 447 448 if ( !function_exists('wp_new_user_notification') ) : 449 function wp_new_user_notification($user_id, $plaintext_pass = '') { 450 $user = new WP_User($user_id); 451 452 $user_login = stripslashes($user->user_login); 453 $user_email = stripslashes($user->user_email); 454 455 $message = sprintf(__('New user registration on your blog %s:'), get_option('blogname')) . "\r\n\r\n"; 456 $message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n"; 457 $message .= sprintf(__('E-mail: %s'), $user_email) . "\r\n"; 458 459 @wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration'), get_option('blogname')), $message); 460 461 if ( empty($plaintext_pass) ) 462 return; 463 464 $message = sprintf(__('Username: %s'), $user_login) . "\r\n"; 465 $message .= sprintf(__('Password: %s'), $plaintext_pass) . "\r\n"; 466 $message .= get_option('siteurl') . "/wp-login.php\r\n"; 467 468 wp_mail($user_email, sprintf(__('[%s] Your username and password'), get_option('blogname')), $message); 469 470 } 471 endif; 472 473 if ( !function_exists('wp_verify_nonce') ) : 474 function wp_verify_nonce($nonce, $action = -1) { 475 $user = wp_get_current_user(); 476 $uid = $user->id; 477 478 $i = ceil(time() / 43200); 479 480 //Allow for expanding range, but only do one check if we can 481 if( substr(wp_hash($i . $action . $uid), -12, 10) == $nonce || substr(wp_hash(($i - 1) . $action . $uid), -12, 10) == $nonce ) 482 return true; 483 return false; 484 } 485 endif; 486 487 if ( !function_exists('wp_create_nonce') ) : 488 function wp_create_nonce($action = -1) { 489 $user = wp_get_current_user(); 490 $uid = $user->id; 491 492 $i = ceil(time() / 43200); 493 494 return substr(wp_hash($i . $action . $uid), -12, 10); 495 } 496 endif; 497 498 if ( !function_exists('wp_salt') ) : 499 function wp_salt() { 500 $salt = get_option('secret'); 501 if ( empty($salt) ) 502 $salt = DB_PASSWORD . DB_USER . DB_NAME . DB_HOST . ABSPATH; 503 504 return $salt; 505 } 506 endif; 507 508 if ( !function_exists('wp_hash') ) : 509 function wp_hash($data) { 510 $salt = wp_salt(); 511 512 if ( function_exists('hash_hmac') ) { 513 return hash_hmac('md5', $data, $salt); 514 } else { 515 return md5($data . $salt); 516 } 517 } 518 endif; 519 520 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Fri Mar 30 19:41:27 2007 | par Balluche grâce à PHPXref 0.7 |