Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 104 lines (79 sloc) 3.17 kb
b43564c *** empty log message ***
saxmatt authored
1 <?php
0990789 Fix for cookie paths being set correctly when using a different home …
saxmatt authored
2 require( dirname(__FILE__) . '/wp-config.php' );
b43564c *** empty log message ***
saxmatt authored
3
4 function add_magic_quotes($array) {
5 foreach ($array as $k => $v) {
6 if (is_array($v)) {
7 $array[$k] = add_magic_quotes($v);
8 } else {
9 $array[$k] = addslashes($v);
10 }
11 }
12 return $array;
13 }
14
15 if (!get_magic_quotes_gpc()) {
10c6b7e Changed to superglobals, and eliminated $use_cache (since we always do).
saxmatt authored
16 $_POST = add_magic_quotes($_POST);
17 $_COOKIE = add_magic_quotes($_COOKIE);
b43564c *** empty log message ***
saxmatt authored
18 }
19
10c6b7e Changed to superglobals, and eliminated $use_cache (since we always do).
saxmatt authored
20 $author = trim(strip_tags($_POST['author']));
68c12a4 Some general comment code cleanup.
saxmatt authored
21
10c6b7e Changed to superglobals, and eliminated $use_cache (since we always do).
saxmatt authored
22 $email = trim(strip_tags($_POST['email']));
68c12a4 Some general comment code cleanup.
saxmatt authored
23 if (strlen($email) < 6)
24 $email = '';
25
10c6b7e Changed to superglobals, and eliminated $use_cache (since we always do).
saxmatt authored
26 $url = trim(strip_tags($_POST['url']));
68c12a4 Some general comment code cleanup.
saxmatt authored
27 $url = ((!stristr($url, '://')) && ($url != '')) ? 'http://'.$url : $url;
28 if (strlen($url) < 7)
29 $url = '';
30
10c6b7e Changed to superglobals, and eliminated $use_cache (since we always do).
saxmatt authored
31 $comment = trim($_POST['comment']);
32 $comment_post_ID = intval($_POST['comment_post_ID']);
33 $user_ip = $_SERVER['REMOTE_ADDR'];
b43564c *** empty log message ***
saxmatt authored
34
0990789 Fix for cookie paths being set correctly when using a different home …
saxmatt authored
35 if ( 'closed' == $wpdb->get_var("SELECT comment_status FROM $tableposts WHERE ID = '$comment_post_ID'") )
36 die( __('Sorry, comments are closed for this item.') );
37
38 if ( get_settings('require_name_email') && ('' == $email || '' == $author) )
39 die( __('Error: please fill the required fields (name, email).') );
40
41 if ( '' == $comment )
42 die( __('Error: please type a comment.') );
8f10709 Check for comment status.
saxmatt authored
43
b43564c *** empty log message ***
saxmatt authored
44
caeaf47 now commenting in localtime+gmt
michelvaldrighi authored
45 $now = current_time('mysql');
46 $now_gmt = current_time('mysql', 1);
84435bf big leap to GMT dates
michelvaldrighi authored
47
b43564c *** empty log message ***
saxmatt authored
48
49 $comment = balanceTags($comment, 1);
50 $comment = format_to_post($comment);
0990789 Fix for cookie paths being set correctly when using a different home …
saxmatt authored
51 $comment = apply_filters('post_comment_text', $comment);
b43564c *** empty log message ***
saxmatt authored
52
0990789 Fix for cookie paths being set correctly when using a different home …
saxmatt authored
53 // Simple flood-protection
d37d520 ezSQL mods.
saxmatt authored
54 $lasttime = $wpdb->get_var("SELECT comment_date FROM $tablecomments WHERE comment_author_IP = '$user_ip' ORDER BY comment_date DESC LIMIT 1");
55 if (!empty($lasttime)) {
56 $time_lastcomment= mysql2date('U', $lasttime);
0990789 Fix for cookie paths being set correctly when using a different home …
saxmatt authored
57 $time_newcomment= mysql2date('U', $now);
a14dc22 Decrease flood time threshhold.
saxmatt authored
58 if (($time_newcomment - $time_lastcomment) < 10)
0990789 Fix for cookie paths being set correctly when using a different home …
saxmatt authored
59 die( __('Sorry, you can only post a new comment once every 10 seconds. Slow down cowboy.') );
b43564c *** empty log message ***
saxmatt authored
60 }
8f10709 Check for comment status.
saxmatt authored
61
0313700 Fixed bug. We now notify on comment (if options say so)
mikelittle authored
62
0990789 Fix for cookie paths being set correctly when using a different home …
saxmatt authored
63 // If we've made it this far, let's post.
adbca5d New comment moderation code, for trackbacks and comments.
saxmatt authored
64
0990789 Fix for cookie paths being set correctly when using a different home …
saxmatt authored
65 if(check_comment($author, $email, $url, $comment, $user_ip)) {
66 $approved = 1;
67 } else {
68 $approved = 0;
69 }
b43564c *** empty log message ***
saxmatt authored
70
0990789 Fix for cookie paths being set correctly when using a different home …
saxmatt authored
71 $wpdb->query("INSERT INTO $tablecomments
72 (comment_post_ID, comment_author, comment_author_email, comment_author_url, comment_author_IP, comment_date, comment_date_gmt, comment_content, comment_approved)
73 VALUES
74 ('$comment_post_ID', '$author', '$email', '$url', '$user_ip', '$now', '$now_gmt', '$comment', '$approved')
75 ");
b43564c *** empty log message ***
saxmatt authored
76
0990789 Fix for cookie paths being set correctly when using a different home …
saxmatt authored
77 $comment_ID = $wpdb->get_var('SELECT last_insert_id()');
b43564c *** empty log message ***
saxmatt authored
78
0990789 Fix for cookie paths being set correctly when using a different home …
saxmatt authored
79 if (!$approved) {
80 wp_notify_moderator($comment_ID);
81 }
0c1e385 Additional plugin API hooks, extending moderation scheme to more full…
saxmatt authored
82
0990789 Fix for cookie paths being set correctly when using a different home …
saxmatt authored
83 if ((get_settings('comments_notify')) && ($approved)) {
84 wp_notify_postauthor($comment_ID, 'comment');
85 }
88a6405 Email fixes, formatting changes.
saxmatt authored
86
0990789 Fix for cookie paths being set correctly when using a different home …
saxmatt authored
87 do_action('comment_post', $comment_ID);
88a6405 Email fixes, formatting changes.
saxmatt authored
88
0990789 Fix for cookie paths being set correctly when using a different home …
saxmatt authored
89 setcookie('comment_author_' . $cookiehash, $author, time() + 30000000, COOKIEPATH);
90 setcookie('comment_author_email_' . $cookiehash, $email, time() + 30000000, COOKIEPATH);
91 setcookie('comment_author_url_' . $cookiehash, $url, time() + 30000000, COOKIEPATH);
facb7af Fixed whitespace error, cleaned some formatting. Improved grammer on …
saxmatt authored
92
0990789 Fix for cookie paths being set correctly when using a different home …
saxmatt authored
93 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
94 header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
95 header('Cache-Control: no-cache, must-revalidate');
96 header('Pragma: no-cache');
97 $location = (empty($_POST['redirect_to'])) ? $_SERVER["HTTP_REFERER"] : $_POST['redirect_to'];
98 if ($is_IIS) {
99 header("Refresh: 0;url=$location");
b43564c *** empty log message ***
saxmatt authored
100 } else {
0990789 Fix for cookie paths being set correctly when using a different home …
saxmatt authored
101 header("Location: $location");
b43564c *** empty log message ***
saxmatt authored
102 }
103
0f866d5 Cleaning up comment moderation and the comment code in general. More …
saxmatt authored
104 ?>
Something went wrong with that request. Please try again.