From 39229a3311305deaa6f01882f20c87227947f4a2 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Thu, 22 Jun 2006 20:52:12 +0000 Subject: [PATCH] wp_get_current_commenter() git-svn-id: https://develop.svn.wordpress.org/trunk@3902 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-content/themes/classic/comments-popup.php | 5 +-- wp-content/themes/default/comments-popup.php | 5 +-- wp-includes/comment-template.php | 28 +++---------- wp-includes/comment.php | 41 ++++++++++++++++++++ wp-includes/default-filters.php | 1 + wp-settings.php | 2 + 6 files changed, 54 insertions(+), 28 deletions(-) diff --git a/wp-content/themes/classic/comments-popup.php b/wp-content/themes/classic/comments-popup.php index 7a209a2129..49ffe3c020 100644 --- a/wp-content/themes/classic/comments-popup.php +++ b/wp-content/themes/classic/comments-popup.php @@ -29,9 +29,8 @@ foreach ($posts as $post) { start_wp(); post_password) && $_COOKIE['wp-postpass_'. COOKIEHASH] != $commentstatus->post_password) { // and it doesn't match the cookie diff --git a/wp-content/themes/default/comments-popup.php b/wp-content/themes/default/comments-popup.php index f22b8610c4..3cd58a6628 100644 --- a/wp-content/themes/default/comments-popup.php +++ b/wp-content/themes/default/comments-popup.php @@ -29,9 +29,8 @@ foreach ($posts as $post) { start_wp(); post_password) && $_COOKIE['wp-postpass_'. COOKIEHASH] != $post->post_password) { // and it doesn't match the cookie diff --git a/wp-includes/comment-template.php b/wp-includes/comment-template.php index 6355a96248..c5d5b8f2cc 100644 --- a/wp-includes/comment-template.php +++ b/wp-includes/comment-template.php @@ -273,26 +273,12 @@ function pings_open() { function comments_template( $file = '/comments.php' ) { global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity; - if ( is_single() || is_page() || $withcomments ) : - $req = get_settings('require_name_email'); - $comment_author = ''; - if ( isset($_COOKIE['comment_author_'.COOKIEHASH]) ) { - $comment_author = apply_filters('pre_comment_author_name', $_COOKIE['comment_author_'.COOKIEHASH]); - $comment_author = stripslashes($comment_author); - $comment_author = wp_specialchars($comment_author, true); - } - $comment_author_email = ''; - if ( isset($_COOKIE['comment_author_email_'.COOKIEHASH]) ) { - $comment_author_email = apply_filters('pre_comment_author_email', $_COOKIE['comment_author_email_'.COOKIEHASH]); - $comment_author_email = stripslashes($comment_author_email); - $comment_author_email = wp_specialchars($comment_author_email, true); - } - $comment_author_url = ''; - if ( isset($_COOKIE['comment_author_url_'.COOKIEHASH]) ) { - $comment_author_url = apply_filters('pre_comment_author_url', $_COOKIE['comment_author_url_'.COOKIEHASH]); - $comment_author_url = stripslashes($comment_author_url); - $comment_author_url = wp_specialchars($comment_author_url, true); - } + if ( ! (is_single() || is_page() || $withcomments) ) + return; + + $req = get_settings('require_name_email'); + $commenter = wp_get_current_commenter(); + extract($commenter); // TODO: Use API instead of SELECTs. if ( empty($comment_author) ) { @@ -309,8 +295,6 @@ function comments_template( $file = '/comments.php' ) { require( $include ); else require( ABSPATH . 'wp-content/themes/default/comments.php'); - - endif; } function comments_popup_script($width=400, $height=400, $file='') { diff --git a/wp-includes/comment.php b/wp-includes/comment.php index ee28fe7e74..404a8f9384 100644 --- a/wp-includes/comment.php +++ b/wp-includes/comment.php @@ -146,6 +146,29 @@ function get_lastcommentmodified($timezone = 'server') { return $lastcommentmodified; } +function sanitize_comment_cookies() { + if ( isset($_COOKIE['comment_author_'.COOKIEHASH]) ) { + $comment_author = apply_filters('pre_comment_author_name', $_COOKIE['comment_author_'.COOKIEHASH]); + $comment_author = stripslashes($comment_author); + $comment_author = wp_specialchars($comment_author, true); + $_COOKIE['comment_author_'.COOKIEHASH] = $comment_author; + } + + if ( isset($_COOKIE['comment_author_email_'.COOKIEHASH]) ) { + $comment_author_email = apply_filters('pre_comment_author_email', $_COOKIE['comment_author_email_'.COOKIEHASH]); + $comment_author_email = stripslashes($comment_author_email); + $comment_author_email = wp_specialchars($comment_author_email, true); + $_COOKIE['comment_author_email_'.COOKIEHASH] = $comment_author_email; + } + + if ( isset($_COOKIE['comment_author_url_'.COOKIEHASH]) ) { + $comment_author_url = apply_filters('pre_comment_author_url', $_COOKIE['comment_author_url_'.COOKIEHASH]); + $comment_author_url = stripslashes($comment_author_url); + $comment_author_url = wp_specialchars($comment_author_url, true); + $_COOKIE['comment_author_url_'.COOKIEHASH] = $comment_author_url; + } +} + function wp_allow_comment($commentdata) { global $wpdb; extract($commentdata); @@ -275,6 +298,24 @@ function wp_get_comment_status($comment_id) { } } +function wp_get_current_commenter() { + // Cookies should already be sanitized. + + $comment_author = ''; + if ( isset($_COOKIE['comment_author_'.COOKIEHASH]) ) + $comment_author = $_COOKIE['comment_author_'.COOKIEHASH]; + + $comment_author_email = ''; + if ( isset($_COOKIE['comment_author_email_'.COOKIEHASH]) ) + $comment_author_email = $_COOKIE['comment_author_email_'.COOKIEHASH]; + + $comment_author_url = ''; + if ( isset($_COOKIE['comment_author_url_'.COOKIEHASH]) ) + $comment_author_url = $_COOKIE['comment_author_url_'.COOKIEHASH]; + + return compact('comment_author', 'comment_author_email', 'comment_author_url'); +} + function wp_insert_comment($commentdata) { global $wpdb; extract($commentdata); diff --git a/wp-includes/default-filters.php b/wp-includes/default-filters.php index 8500a0ca86..d596500330 100644 --- a/wp-includes/default-filters.php +++ b/wp-includes/default-filters.php @@ -127,4 +127,5 @@ add_action('do_feed_rss2', 'do_feed_rss2', 10, 1); add_action('do_feed_atom', 'do_feed_atom', 10, 1); add_action('do_pings', 'do_all_pings', 10, 1); add_action('do_robots', 'do_robots'); +add_action('sanitize_comment_cookies', 'sanitize_comment_cookies'); ?> diff --git a/wp-settings.php b/wp-settings.php index 7d19a7abaa..c21a3950c3 100644 --- a/wp-settings.php +++ b/wp-settings.php @@ -204,6 +204,8 @@ $_POST = add_magic_quotes($_POST ); $_COOKIE = add_magic_quotes($_COOKIE); $_SERVER = add_magic_quotes($_SERVER); +do_action('sanitize_comment_cookies'); + $wp_query = new WP_Query(); $wp_rewrite = new WP_Rewrite(); $wp = new WP();