Changeset 1964 for trunk/wp-comments-post.php
- Timestamp:
- 12/16/2004 02:57:05 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-comments-post.php
r1854 r1964 2 2 require( dirname(__FILE__) . '/wp-config.php' ); 3 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()) { 16 $_POST = add_magic_quotes($_POST); 17 $_COOKIE = add_magic_quotes($_COOKIE); 18 $_SERVER = add_magic_quotes($_SERVER); 19 } 20 21 $author = trim(strip_tags($_POST['author'])); 22 23 $email = trim(strip_tags($_POST['email'])); 24 if (strlen($email) < 6) 25 $email = ''; 26 27 $url = trim(strip_tags($_POST['url'])); 28 $url = ((!stristr($url, '://')) && ($url != '')) ? 'http://'.$url : $url; 29 if (strlen($url) < 7) 30 $url = ''; 31 32 $user_agent = $_SERVER['HTTP_USER_AGENT']; 33 34 $comment = trim($_POST['comment']); 35 $comment_post_ID = intval($_POST['comment_post_ID']); 36 $user_ip = $_SERVER['REMOTE_ADDR']; 4 $comment_post_ID = (int) $_POST['comment_post_ID']; 37 5 38 6 $post_status = $wpdb->get_var("SELECT comment_status FROM $wpdb->posts WHERE ID = '$comment_post_ID'"); 39 7 40 8 if ( empty($post_status) ) { 41 // Post does not exist. Someone is trolling. Die silently.42 // (Perhaps offer pluggable rebukes? Long delays, etc.)43 die(); 44 } else if ( 'closed' == $post_status ) { 9 do_action('comment_id_not_found', $comment_post_ID); 10 exit; 11 } elseif ( 'closed' == $post_status ) { 12 do_action('comment_closed', $comment_post_ID); 45 13 die( __('Sorry, comments are closed for this item.') ); 46 14 } 15 16 $comment_author = $_POST['author']; 17 $comment_author_email = $_POST['email']; 18 $comment_author_url = $_POST['url']; 19 $comment_content = $_POST['comment']; 20 21 $comment_type = ''; 22 23 $user_ip = apply_filters('pre_comment_user_ip', $_SERVER['REMOTE_ADDR']); 47 24 48 25 if ( get_settings('require_name_email') && ('' == $email || '' == $author) ) … … 52 29 die( __('Error: please type a comment.') ); 53 30 31 $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type'); 54 32 55 $now = current_time('mysql'); 56 $now_gmt = current_time('mysql', 1); 57 58 $comment = format_to_post($comment); 59 $comment = apply_filters('post_comment_text', $comment); 60 61 // Simple flood-protection 62 $lasttime = $wpdb->get_var("SELECT comment_date FROM $wpdb->comments WHERE comment_author_IP = '$user_ip' ORDER BY comment_date DESC LIMIT 1"); 63 if (!empty($lasttime)) { 64 $time_lastcomment= mysql2date('U', $lasttime); 65 $time_newcomment= mysql2date('U', $now); 66 if (($time_newcomment - $time_lastcomment) < 10) 67 die( __('Sorry, you can only post a new comment once every 10 seconds. Slow down cowboy.') ); 68 } 69 70 71 // If we've made it this far, let's post. 72 73 if( check_comment($author, $email, $url, $comment, $user_ip, $user_agent) ) { 74 $approved = 1; 75 } else { 76 $approved = 0; 77 } 78 79 $wpdb->query("INSERT INTO $wpdb->comments 80 (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) 81 VALUES 82 ('$comment_post_ID', '$author', '$email', '$url', '$user_ip', '$now', '$now_gmt', '$comment', '$approved', '$user_agent') 83 "); 84 85 $comment_ID = $wpdb->insert_id; 86 87 do_action('comment_post', $comment_ID); 88 89 if (!$approved) { 90 wp_notify_moderator($comment_ID); 91 } 92 93 if ((get_settings('comments_notify')) && ($approved)) { 94 wp_notify_postauthor($comment_ID, 'comment'); 95 } 33 wp_new_comment($commentdata); 96 34 97 35 setcookie('comment_author_' . COOKIEHASH, stripslashes($author), time() + 30000000, COOKIEPATH); … … 99 37 setcookie('comment_author_url_' . COOKIEHASH, stripslashes($url), time() + 30000000, COOKIEPATH); 100 38 101 header('Expires: Mon, 26 Jul 199705:00:00 GMT');39 header('Expires: Mon, 11 Jan 1984 05:00:00 GMT'); 102 40 header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); 103 41 header('Cache-Control: no-cache, must-revalidate');
Note: See TracChangeset
for help on using the changeset viewer.