Skip to content

Commit

Permalink
Comments refactoring and cleanup
Browse files Browse the repository at this point in the history
git-svn-id: http://core.svn.wordpress.org/trunk@1964 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
m committed Dec 16, 2004
1 parent 18cf85d commit 0a5b1bc
Show file tree
Hide file tree
Showing 15 changed files with 956 additions and 998 deletions.
17 changes: 0 additions & 17 deletions wp-admin/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,6 @@
$date_format = get_settings('date_format');
$time_format = get_settings('time_format');

function add_magic_quotes($array) {
foreach ($array as $k => $v) {
if (is_array($v)) {
$array[$k] = add_magic_quotes($v);
} else {
$array[$k] = addslashes($v);
}
}
return $array;
}

if (!get_magic_quotes_gpc()) {
$_GET = add_magic_quotes($_GET);
$_POST = add_magic_quotes($_POST);
$_COOKIE = add_magic_quotes($_COOKIE);
}

$wpvarstoreset = array('profile','redirect','redirect_url','a','popuptitle','popupurl','text', 'trackback', 'pingback');
for ($i=0; $i<count($wpvarstoreset); $i += 1) {
$wpvar = $wpvarstoreset[$i];
Expand Down
98 changes: 18 additions & 80 deletions wp-comments-post.php
Original file line number Diff line number Diff line change
@@ -1,104 +1,42 @@
<?php
require( dirname(__FILE__) . '/wp-config.php' );

function add_magic_quotes($array) {
foreach ($array as $k => $v) {
if (is_array($v)) {
$array[$k] = add_magic_quotes($v);
} else {
$array[$k] = addslashes($v);
}
}
return $array;
}

if (!get_magic_quotes_gpc()) {
$_POST = add_magic_quotes($_POST);
$_COOKIE = add_magic_quotes($_COOKIE);
$_SERVER = add_magic_quotes($_SERVER);
}

$author = trim(strip_tags($_POST['author']));

$email = trim(strip_tags($_POST['email']));
if (strlen($email) < 6)
$email = '';

$url = trim(strip_tags($_POST['url']));
$url = ((!stristr($url, '://')) && ($url != '')) ? 'http://'.$url : $url;
if (strlen($url) < 7)
$url = '';

$user_agent = $_SERVER['HTTP_USER_AGENT'];

$comment = trim($_POST['comment']);
$comment_post_ID = intval($_POST['comment_post_ID']);
$user_ip = $_SERVER['REMOTE_ADDR'];
$comment_post_ID = (int) $_POST['comment_post_ID'];

$post_status = $wpdb->get_var("SELECT comment_status FROM $wpdb->posts WHERE ID = '$comment_post_ID'");

if ( empty($post_status) ) {
// Post does not exist. Someone is trolling. Die silently.
// (Perhaps offer pluggable rebukes? Long delays, etc.)
die();
} else if ( 'closed' == $post_status ) {
do_action('comment_id_not_found', $comment_post_ID);
exit;
} elseif ( 'closed' == $post_status ) {
do_action('comment_closed', $comment_post_ID);
die( __('Sorry, comments are closed for this item.') );
}

$comment_author = $_POST['author'];
$comment_author_email = $_POST['email'];
$comment_author_url = $_POST['url'];
$comment_content = $_POST['comment'];

$comment_type = '';

$user_ip = apply_filters('pre_comment_user_ip', $_SERVER['REMOTE_ADDR']);

if ( get_settings('require_name_email') && ('' == $email || '' == $author) )
die( __('Error: please fill the required fields (name, email).') );

if ( '' == $comment )
die( __('Error: please type a comment.') );

$commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type');

$now = current_time('mysql');
$now_gmt = current_time('mysql', 1);

$comment = format_to_post($comment);
$comment = apply_filters('post_comment_text', $comment);

// Simple flood-protection
$lasttime = $wpdb->get_var("SELECT comment_date FROM $wpdb->comments WHERE comment_author_IP = '$user_ip' ORDER BY comment_date DESC LIMIT 1");
if (!empty($lasttime)) {
$time_lastcomment= mysql2date('U', $lasttime);
$time_newcomment= mysql2date('U', $now);
if (($time_newcomment - $time_lastcomment) < 10)
die( __('Sorry, you can only post a new comment once every 10 seconds. Slow down cowboy.') );
}


// If we've made it this far, let's post.

if( check_comment($author, $email, $url, $comment, $user_ip, $user_agent) ) {
$approved = 1;
} else {
$approved = 0;
}

$wpdb->query("INSERT INTO $wpdb->comments
(comment_post_ID, comment_author, comment_author_email, comment_author_url, comment_author_IP, comment_date, comment_date_gmt, comment_content, comment_approved, comment_agent)
VALUES
('$comment_post_ID', '$author', '$email', '$url', '$user_ip', '$now', '$now_gmt', '$comment', '$approved', '$user_agent')
");

$comment_ID = $wpdb->insert_id;

do_action('comment_post', $comment_ID);

if (!$approved) {
wp_notify_moderator($comment_ID);
}

if ((get_settings('comments_notify')) && ($approved)) {
wp_notify_postauthor($comment_ID, 'comment');
}
wp_new_comment($commentdata);

setcookie('comment_author_' . COOKIEHASH, stripslashes($author), time() + 30000000, COOKIEPATH);
setcookie('comment_author_email_' . COOKIEHASH, stripslashes($email), time() + 30000000, COOKIEPATH);
setcookie('comment_author_url_' . COOKIEHASH, stripslashes($url), time() + 30000000, COOKIEPATH);

header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Expires: Mon, 11 Jan 1984 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-cache, must-revalidate');
header('Pragma: no-cache');
Expand All @@ -111,4 +49,4 @@ function add_magic_quotes($array) {
header("Location: $location");
}

?>
?>
Loading

0 comments on commit 0a5b1bc

Please sign in to comment.