| 8 | | if ( is_single() || is_page() || $withcomments ) : |
|---|
| 9 | | $req = get_settings('require_name_email'); |
|---|
| 10 | | $comment_author = ''; |
|---|
| 11 | | if ( isset($_COOKIE['comment_author_'.COOKIEHASH]) ) { |
|---|
| 12 | | $comment_author = apply_filters('pre_comment_author_name', $_COOKIE['comment_author_'.COOKIEHASH]); |
|---|
| 13 | | $comment_author = stripslashes($comment_author); |
|---|
| 14 | | $comment_author = wp_specialchars($comment_author, true); |
|---|
| 15 | | } |
|---|
| 16 | | $comment_author_email = ''; |
|---|
| 17 | | if ( isset($_COOKIE['comment_author_email_'.COOKIEHASH]) ) { |
|---|
| 18 | | $comment_author_email = apply_filters('pre_comment_author_email', $_COOKIE['comment_author_email_'.COOKIEHASH]); |
|---|
| 19 | | $comment_author_email = stripslashes($comment_author_email); |
|---|
| 20 | | $comment_author_email = wp_specialchars($comment_author_email, true); |
|---|
| 21 | | } |
|---|
| 22 | | $comment_author_url = ''; |
|---|
| 23 | | if ( isset($_COOKIE['comment_author_url_'.COOKIEHASH]) ) { |
|---|
| 24 | | $comment_author_url = apply_filters('pre_comment_author_url', $_COOKIE['comment_author_url_'.COOKIEHASH]); |
|---|
| 25 | | $comment_author_url = stripslashes($comment_author_url); |
|---|
| 26 | | $comment_author_url = wp_specialchars($comment_author_url, true); |
|---|
| 27 | | } |
|---|
| | 8 | if ( (count(explode('http:', $comment)) - 1) >= get_settings('comment_max_links') ) |
|---|
| | 9 | return false; // Check # of external links |
|---|
| 50 | | $commentdata['comment_post_ID'] = (int) $commentdata['comment_post_ID']; |
|---|
| 51 | | $commentdata['user_ID'] = (int) $commentdata['user_ID']; |
|---|
| | 25 | $pattern = "#$word#i"; |
|---|
| | 26 | if ( preg_match($pattern, $author) ) return false; |
|---|
| | 27 | if ( preg_match($pattern, $email) ) return false; |
|---|
| | 28 | if ( preg_match($pattern, $url) ) return false; |
|---|
| | 29 | if ( preg_match($pattern, $comment) ) return false; |
|---|
| | 30 | if ( preg_match($pattern, $user_ip) ) return false; |
|---|
| | 31 | if ( preg_match($pattern, $user_agent) ) return false; |
|---|
| | 32 | } |
|---|
| | 33 | } |
|---|
| 53 | | $commentdata['comment_author_IP'] = $_SERVER['REMOTE_ADDR']; |
|---|
| 54 | | $commentdata['comment_agent'] = $_SERVER['HTTP_USER_AGENT']; |
|---|
| 55 | | |
|---|
| 56 | | $commentdata['comment_date'] = current_time('mysql'); |
|---|
| 57 | | $commentdata['comment_date_gmt'] = current_time('mysql', 1); |
|---|
| 58 | | |
|---|
| 59 | | |
|---|
| 60 | | $commentdata = wp_filter_comment($commentdata); |
|---|
| 61 | | |
|---|
| 62 | | $commentdata['comment_approved'] = wp_allow_comment($commentdata); |
|---|
| 63 | | |
|---|
| 64 | | $comment_ID = wp_insert_comment($commentdata); |
|---|
| 65 | | |
|---|
| 66 | | do_action('comment_post', $comment_ID, $commentdata['comment_approved']); |
|---|
| 67 | | |
|---|
| 68 | | if ( 'spam' !== $commentdata['comment_approved'] ) { // If it's spam save it silently for later crunching |
|---|
| 69 | | if ( '0' == $commentdata['comment_approved'] ) |
|---|
| 70 | | wp_notify_moderator($comment_ID); |
|---|
| 71 | | |
|---|
| 72 | | $post = &get_post($commentdata['comment_post_ID']); // Don't notify if it's your own comment |
|---|
| 73 | | |
|---|
| 74 | | if ( get_settings('comments_notify') && $commentdata['comment_approved'] && $post->post_author != $commentdata['user_ID'] ) |
|---|
| 75 | | wp_notify_postauthor($comment_ID, $commentdata['comment_type']); |
|---|
| | 35 | // Comment whitelisting: |
|---|
| | 36 | if ( 1 == get_settings('comment_whitelist')) { |
|---|
| | 37 | if ( 'trackback' == $comment_type || 'pingback' == $comment_type ) { // check if domain is in blogroll |
|---|
| | 38 | $uri = parse_url($url); |
|---|
| | 39 | $domain = $uri['host']; |
|---|
| | 40 | $uri = parse_url( get_option('home') ); |
|---|
| | 41 | $home_domain = $uri['host']; |
|---|
| | 42 | if ( $wpdb->get_var("SELECT link_id FROM $wpdb->links WHERE link_url LIKE ('%$domain%') LIMIT 1") || $domain == $home_domain ) |
|---|
| | 43 | return true; |
|---|
| | 44 | else |
|---|
| | 45 | return false; |
|---|
| | 46 | } elseif( $author != '' && $email != '' ) { |
|---|
| | 47 | $ok_to_comment = $wpdb->get_var("SELECT comment_approved FROM $wpdb->comments WHERE comment_author = '$author' AND comment_author_email = '$email' and comment_approved = '1' LIMIT 1"); |
|---|
| | 48 | if ( ( 1 == $ok_to_comment ) && |
|---|
| | 49 | ( empty($mod_keys) || false === strpos( $email, $mod_keys) ) ) |
|---|
| | 50 | return true; |
|---|
| | 51 | else |
|---|
| | 52 | return false; |
|---|
| | 53 | } else { |
|---|
| | 54 | return false; |
|---|
| | 55 | } |
|---|
| 85 | | if ( ! isset($comment_author_IP) ) |
|---|
| 86 | | $comment_author_IP = $_SERVER['REMOTE_ADDR']; |
|---|
| 87 | | if ( ! isset($comment_date) ) |
|---|
| 88 | | $comment_date = current_time('mysql'); |
|---|
| 89 | | if ( ! isset($comment_date_gmt) ) |
|---|
| 90 | | $comment_date_gmt = gmdate('Y-m-d H:i:s', strtotime($comment_date) ); |
|---|
| 91 | | if ( ! isset($comment_parent) ) |
|---|
| 92 | | $comment_parent = 0; |
|---|
| 93 | | if ( ! isset($comment_approved) ) |
|---|
| 94 | | $comment_approved = 1; |
|---|
| 95 | | if ( ! isset($user_id) ) |
|---|
| 96 | | $user_id = 0; |
|---|
| | 66 | // Retrieves comment data given a comment ID or comment object. |
|---|
| | 67 | // Handles comment caching. |
|---|
| | 68 | function &get_comment(&$comment, $output = OBJECT) { |
|---|
| | 69 | global $comment_cache, $wpdb; |
|---|
| 98 | | $result = $wpdb->query("INSERT INTO $wpdb->comments |
|---|
| 99 | | (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, comment_type, comment_parent, user_id) |
|---|
| 100 | | VALUES |
|---|
| 101 | | ('$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', '$comment_type', '$comment_parent', '$user_id') |
|---|
| 102 | | "); |
|---|
| | 71 | if ( empty($comment) ) |
|---|
| | 72 | return null; |
|---|
| 113 | | function wp_filter_comment($commentdata) { |
|---|
| 114 | | $commentdata['user_id'] = apply_filters('pre_user_id', $commentdata['user_ID']); |
|---|
| 115 | | $commentdata['comment_agent'] = apply_filters('pre_comment_user_agent', $commentdata['comment_agent']); |
|---|
| 116 | | $commentdata['comment_author'] = apply_filters('pre_comment_author_name', $commentdata['comment_author']); |
|---|
| 117 | | $commentdata['comment_content'] = apply_filters('pre_comment_content', $commentdata['comment_content']); |
|---|
| 118 | | $commentdata['comment_author_IP'] = apply_filters('pre_comment_user_ip', $commentdata['comment_author_IP']); |
|---|
| 119 | | $commentdata['comment_author_url'] = apply_filters('pre_comment_author_url', $commentdata['comment_author_url']); |
|---|
| 120 | | $commentdata['comment_author_email'] = apply_filters('pre_comment_author_email', $commentdata['comment_author_email']); |
|---|
| 121 | | $commentdata['filtered'] = true; |
|---|
| 122 | | return $commentdata; |
|---|
| | 98 | // Deprecate in favor of get_comment()? |
|---|
| | 99 | function get_commentdata( $comment_ID, $no_cache = 0, $include_unapproved = false ) { // less flexible, but saves DB queries |
|---|
| | 100 | global $postc, $id, $commentdata, $wpdb; |
|---|
| | 101 | if ($no_cache) { |
|---|
| | 102 | $query = "SELECT * FROM $wpdb->comments WHERE comment_ID = '$comment_ID'"; |
|---|
| | 103 | if (false == $include_unapproved) { |
|---|
| | 104 | $query .= " AND comment_approved = '1'"; |
|---|
| | 105 | } |
|---|
| | 106 | $myrow = $wpdb->get_row($query, ARRAY_A); |
|---|
| | 107 | } else { |
|---|
| | 108 | $myrow['comment_ID'] = $postc->comment_ID; |
|---|
| | 109 | $myrow['comment_post_ID'] = $postc->comment_post_ID; |
|---|
| | 110 | $myrow['comment_author'] = $postc->comment_author; |
|---|
| | 111 | $myrow['comment_author_email'] = $postc->comment_author_email; |
|---|
| | 112 | $myrow['comment_author_url'] = $postc->comment_author_url; |
|---|
| | 113 | $myrow['comment_author_IP'] = $postc->comment_author_IP; |
|---|
| | 114 | $myrow['comment_date'] = $postc->comment_date; |
|---|
| | 115 | $myrow['comment_content'] = $postc->comment_content; |
|---|
| | 116 | $myrow['comment_karma'] = $postc->comment_karma; |
|---|
| | 117 | $myrow['comment_approved'] = $postc->comment_approved; |
|---|
| | 118 | $myrow['comment_type'] = $postc->comment_type; |
|---|
| | 119 | } |
|---|
| | 120 | return $myrow; |
|---|
| | 123 | function get_lastcommentmodified($timezone = 'server') { |
|---|
| | 124 | global $cache_lastcommentmodified, $pagenow, $wpdb; |
|---|
| | 125 | $add_seconds_blog = get_settings('gmt_offset') * 3600; |
|---|
| | 126 | $add_seconds_server = date('Z'); |
|---|
| | 127 | $now = current_time('mysql', 1); |
|---|
| | 128 | if ( !isset($cache_lastcommentmodified[$timezone]) ) { |
|---|
| | 129 | switch(strtolower($timezone)) { |
|---|
| | 130 | case 'gmt': |
|---|
| | 131 | $lastcommentmodified = $wpdb->get_var("SELECT comment_date_gmt FROM $wpdb->comments WHERE comment_date_gmt <= '$now' ORDER BY comment_date_gmt DESC LIMIT 1"); |
|---|
| | 132 | break; |
|---|
| | 133 | case 'blog': |
|---|
| | 134 | $lastcommentmodified = $wpdb->get_var("SELECT comment_date FROM $wpdb->comments WHERE comment_date_gmt <= '$now' ORDER BY comment_date_gmt DESC LIMIT 1"); |
|---|
| | 135 | break; |
|---|
| | 136 | case 'server': |
|---|
| | 137 | $lastcommentmodified = $wpdb->get_var("SELECT DATE_ADD(comment_date_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->comments WHERE comment_date_gmt <= '$now' ORDER BY comment_date_gmt DESC LIMIT 1"); |
|---|
| | 138 | break; |
|---|
| | 139 | } |
|---|
| | 140 | $cache_lastcommentmodified[$timezone] = $lastcommentmodified; |
|---|
| | 141 | } else { |
|---|
| | 142 | $lastcommentmodified = $cache_lastcommentmodified[$timezone]; |
|---|
| | 143 | } |
|---|
| | 144 | return $lastcommentmodified; |
|---|
| | 145 | } |
|---|
| | 146 | |
|---|
| 174 | | |
|---|
| 175 | | function wp_update_comment($commentarr) { |
|---|
| 176 | | global $wpdb; |
|---|
| 177 | | |
|---|
| 178 | | // First, get all of the original fields |
|---|
| 179 | | $comment = get_comment($commentarr['comment_ID'], ARRAY_A); |
|---|
| 180 | | |
|---|
| 181 | | // Escape data pulled from DB. |
|---|
| 182 | | foreach ($comment as $key => $value) |
|---|
| 183 | | $comment[$key] = $wpdb->escape($value); |
|---|
| 184 | | |
|---|
| 185 | | // Merge old and new fields with new fields overwriting old ones. |
|---|
| 186 | | $commentarr = array_merge($comment, $commentarr); |
|---|
| 187 | | |
|---|
| 188 | | $commentarr = wp_filter_comment( $commentarr ); |
|---|
| 189 | | |
|---|
| 190 | | // Now extract the merged array. |
|---|
| 191 | | extract($commentarr); |
|---|
| 192 | | |
|---|
| 193 | | $comment_content = apply_filters('comment_save_pre', $comment_content); |
|---|
| 194 | | |
|---|
| 195 | | $result = $wpdb->query( |
|---|
| 196 | | "UPDATE $wpdb->comments SET |
|---|
| 197 | | comment_content = '$comment_content', |
|---|
| 198 | | comment_author = '$comment_author', |
|---|
| 199 | | comment_author_email = '$comment_author_email', |
|---|
| 200 | | comment_approved = '$comment_approved', |
|---|
| 201 | | comment_author_url = '$comment_author_url', |
|---|
| 202 | | comment_date = '$comment_date' |
|---|
| 203 | | WHERE comment_ID = $comment_ID" ); |
|---|
| 204 | | |
|---|
| 205 | | $rval = $wpdb->rows_affected; |
|---|
| 206 | | |
|---|
| 207 | | $c = $wpdb->get_row( "SELECT count(*) as c FROM {$wpdb->comments} WHERE comment_post_ID = '$comment_post_ID' AND comment_approved = '1'" ); |
|---|
| 208 | | if( is_object( $c ) ) |
|---|
| 209 | | $wpdb->query( "UPDATE $wpdb->posts SET comment_count = '$c->c' WHERE ID = '$comment_post_ID'" ); |
|---|
| 210 | | |
|---|
| 211 | | do_action('edit_comment', $comment_ID); |
|---|
| 212 | | |
|---|
| 213 | | return $rval; |
|---|
| 214 | | } |
|---|
| 215 | | |
|---|
| 237 | | if ( !$post_id ) |
|---|
| 238 | | $post_id = $id; |
|---|
| 239 | | |
|---|
| 240 | | if ( !isset($comment_count_cache[$post_id]) ) |
|---|
| 241 | | $comment_count_cache[$id] = $wpdb->get_var("SELECT comment_count FROM $wpdb->posts WHERE ID = '$post_id'"); |
|---|
| 242 | | |
|---|
| 243 | | return apply_filters('get_comments_number', $comment_count_cache[$post_id]); |
|---|
| 244 | | } |
|---|
| 245 | | |
|---|
| 246 | | function comments_number( $zero = 'No Comments', $one = '1 Comment', $more = '% Comments', $number = '' ) { |
|---|
| 247 | | global $id, $comment; |
|---|
| 248 | | $number = get_comments_number( $id ); |
|---|
| 249 | | if ($number == 0) { |
|---|
| 250 | | $blah = $zero; |
|---|
| 251 | | } elseif ($number == 1) { |
|---|
| 252 | | $blah = $one; |
|---|
| 253 | | } elseif ($number > 1) { |
|---|
| 254 | | $blah = str_replace('%', $number, $more); |
|---|
| | 216 | $result = $wpdb->get_var("SELECT comment_approved FROM $wpdb->comments WHERE comment_ID='$comment_id' LIMIT 1"); |
|---|
| | 217 | if ($result == NULL) { |
|---|
| | 218 | return 'deleted'; |
|---|
| | 219 | } else if ($result == '1') { |
|---|
| | 220 | return 'approved'; |
|---|
| | 221 | } else if ($result == '0') { |
|---|
| | 222 | return 'unapproved'; |
|---|
| | 223 | } else if ($result == 'spam') { |
|---|
| | 224 | return 'spam'; |
|---|
| | 225 | } else { |
|---|
| | 226 | return false; |
|---|
| 263 | | function get_comment_link() { |
|---|
| 264 | | global $comment; |
|---|
| 265 | | return get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment->comment_ID; |
|---|
| 266 | | } |
|---|
| | 234 | if ( ! isset($comment_author_IP) ) |
|---|
| | 235 | $comment_author_IP = $_SERVER['REMOTE_ADDR']; |
|---|
| | 236 | if ( ! isset($comment_date) ) |
|---|
| | 237 | $comment_date = current_time('mysql'); |
|---|
| | 238 | if ( ! isset($comment_date_gmt) ) |
|---|
| | 239 | $comment_date_gmt = gmdate('Y-m-d H:i:s', strtotime($comment_date) ); |
|---|
| | 240 | if ( ! isset($comment_parent) ) |
|---|
| | 241 | $comment_parent = 0; |
|---|
| | 242 | if ( ! isset($comment_approved) ) |
|---|
| | 243 | $comment_approved = 1; |
|---|
| | 244 | if ( ! isset($user_id) ) |
|---|
| | 245 | $user_id = 0; |
|---|
| 268 | | function comments_link( $file = '', $echo = true ) { |
|---|
| 269 | | echo get_comments_link(); |
|---|
| 270 | | } |
|---|
| | 247 | $result = $wpdb->query("INSERT INTO $wpdb->comments |
|---|
| | 248 | (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, comment_type, comment_parent, user_id) |
|---|
| | 249 | VALUES |
|---|
| | 250 | ('$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', '$comment_type', '$comment_parent', '$user_id') |
|---|
| | 251 | "); |
|---|
| 275 | | if (empty ($file)) { |
|---|
| 276 | | $wpcommentspopupfile = ''; // Use the index. |
|---|
| 277 | | } else { |
|---|
| 278 | | $wpcommentspopupfile = $file; |
|---|
| 279 | | } |
|---|
| 280 | | |
|---|
| 281 | | $wpcommentsjavascript = 1; |
|---|
| 282 | | $javascript = "<script type='text/javascript'>\nfunction wpopen (macagna) {\n window.open(macagna, '_blank', 'width=$width,height=$height,scrollbars=yes,status=yes');\n}\n</script>\n"; |
|---|
| 283 | | echo $javascript; |
|---|
| 284 | | } |
|---|
| 285 | | |
|---|
| 286 | | function comments_popup_link($zero='No Comments', $one='1 Comment', $more='% Comments', $CSSclass='', $none='Comments Off') { |
|---|
| 287 | | global $id, $wpcommentspopupfile, $wpcommentsjavascript, $post, $wpdb; |
|---|
| 288 | | global $comment_count_cache; |
|---|
| 289 | | |
|---|
| 290 | | if (! is_single() && ! is_page()) { |
|---|
| 291 | | if ( !isset($comment_count_cache[$id]) ) |
|---|
| 292 | | $comment_count_cache[$id] = $wpdb->get_var("SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_post_ID = $id AND comment_approved = '1';"); |
|---|
| 293 | | |
|---|
| 294 | | $number = $comment_count_cache[$id]; |
|---|
| 295 | | |
|---|
| 296 | | if (0 == $number && 'closed' == $post->comment_status && 'closed' == $post->ping_status) { |
|---|
| 297 | | echo $none; |
|---|
| 298 | | return; |
|---|
| 299 | | } else { |
|---|
| 300 | | if (!empty($post->post_password)) { // if there's a password |
|---|
| 301 | | if ($_COOKIE['wp-postpass_'.COOKIEHASH] != $post->post_password) { // and it doesn't match the cookie |
|---|
| 302 | | echo(__('Enter your password to view comments')); |
|---|
| 303 | | return; |
|---|
| 304 | | } |
|---|
| 305 | | } |
|---|
| 306 | | echo '<a href="'; |
|---|
| 307 | | if ($wpcommentsjavascript) { |
|---|
| 308 | | if ( empty($wpcommentspopupfile) ) |
|---|
| 309 | | $home = get_settings('home'); |
|---|
| 310 | | else |
|---|
| 311 | | $home = get_settings('siteurl'); |
|---|
| 312 | | echo $home . '/' . $wpcommentspopupfile.'?comments_popup='.$id; |
|---|
| 313 | | echo '" onclick="wpopen(this.href); return false"'; |
|---|
| 314 | | } else { // if comments_popup_script() is not in the template, display simple comment link |
|---|
| 315 | | if ( 0 == $number ) |
|---|
| 316 | | echo get_permalink() . '#respond'; |
|---|
| 317 | | else |
|---|
| 318 | | comments_link(); |
|---|
| 319 | | echo '"'; |
|---|
| 320 | | } |
|---|
| 321 | | if (!empty($CSSclass)) { |
|---|
| 322 | | echo ' class="'.$CSSclass.'"'; |
|---|
| 323 | | } |
|---|
| 324 | | echo ' title="' . sprintf( __('Comment on %s'), $post->post_title ) .'">'; |
|---|
| 325 | | comments_number($zero, $one, $more, $number); |
|---|
| 326 | | echo '</a>'; |
|---|
| | 255 | if ( $comment_approved == 1) { |
|---|
| | 256 | $count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = '$comment_post_ID' AND comment_approved = '1'"); |
|---|
| | 257 | $wpdb->query( "UPDATE $wpdb->posts SET comment_count = $count WHERE ID = '$comment_post_ID'" ); |
|---|
| 331 | | function get_comment_ID() { |
|---|
| 332 | | global $comment; |
|---|
| 333 | | return apply_filters('get_comment_ID', $comment->comment_ID); |
|---|
| | 262 | function wp_filter_comment($commentdata) { |
|---|
| | 263 | $commentdata['user_id'] = apply_filters('pre_user_id', $commentdata['user_ID']); |
|---|
| | 264 | $commentdata['comment_agent'] = apply_filters('pre_comment_user_agent', $commentdata['comment_agent']); |
|---|
| | 265 | $commentdata['comment_author'] = apply_filters('pre_comment_author_name', $commentdata['comment_author']); |
|---|
| | 266 | $commentdata['comment_content'] = apply_filters('pre_comment_content', $commentdata['comment_content']); |
|---|
| | 267 | $commentdata['comment_author_IP'] = apply_filters('pre_comment_user_ip', $commentdata['comment_author_IP']); |
|---|
| | 268 | $commentdata['comment_author_url'] = apply_filters('pre_comment_author_url', $commentdata['comment_author_url']); |
|---|
| | 269 | $commentdata['comment_author_email'] = apply_filters('pre_comment_author_email', $commentdata['comment_author_email']); |
|---|
| | 270 | $commentdata['filtered'] = true; |
|---|
| | 271 | return $commentdata; |
|---|
| 411 | | function comment_author_email_link($linktext='', $before='', $after='') { |
|---|
| 412 | | global $comment; |
|---|
| 413 | | $email = apply_filters('comment_email', $comment->comment_author_email); |
|---|
| 414 | | if ((!empty($email)) && ($email != '@')) { |
|---|
| 415 | | $display = ($linktext != '') ? $linktext : $email; |
|---|
| 416 | | echo $before; |
|---|
| 417 | | echo "<a href='mailto:$email'>$display</a>"; |
|---|
| 418 | | echo $after; |
|---|
| 419 | | } |
|---|
| 420 | | } |
|---|
| | 311 | switch($comment_status) { |
|---|
| | 312 | case 'hold': |
|---|
| | 313 | $query = "UPDATE $wpdb->comments SET comment_approved='0' WHERE comment_ID='$comment_id' LIMIT 1"; |
|---|
| | 314 | break; |
|---|
| | 315 | case 'approve': |
|---|
| | 316 | $query = "UPDATE $wpdb->comments SET comment_approved='1' WHERE comment_ID='$comment_id' LIMIT 1"; |
|---|
| | 317 | break; |
|---|
| | 318 | case 'spam': |
|---|
| | 319 | $query = "UPDATE $wpdb->comments SET comment_approved='spam' WHERE comment_ID='$comment_id' LIMIT 1"; |
|---|
| | 320 | break; |
|---|
| | 321 | case 'delete': |
|---|
| | 322 | return wp_delete_comment($comment_id); |
|---|
| | 323 | break; |
|---|
| | 324 | default: |
|---|
| | 325 | return false; |
|---|
| | 326 | } |
|---|
| | 327 | |
|---|
| | 328 | if ($wpdb->query($query)) { |
|---|
| | 329 | do_action('wp_set_comment_status', $comment_id, $comment_status); |
|---|
| 422 | | function get_comment_author_url_link( $linktext = '', $before = '', $after = '' ) { |
|---|
| 423 | | global $comment; |
|---|
| 424 | | $url = get_comment_author_url(); |
|---|
| 425 | | $display = ($linktext != '') ? $linktext : $url; |
|---|
| 426 | | $return = "$before<a href='$url' rel='external'>$display</a>$after"; |
|---|
| 427 | | return apply_filters('get_comment_author_url_link', $return); |
|---|
| | 331 | $comment = get_comment($comment_id); |
|---|
| | 332 | $comment_post_ID = $comment->comment_post_ID; |
|---|
| | 333 | $c = $wpdb->get_row( "SELECT count(*) as c FROM {$wpdb->comments} WHERE comment_post_ID = '$comment_post_ID' AND comment_approved = '1'" ); |
|---|
| | 334 | if( is_object( $c ) ) |
|---|
| | 335 | $wpdb->query( "UPDATE $wpdb->posts SET comment_count = '$c->c' WHERE ID = '$comment_post_ID'" ); |
|---|
| | 336 | return true; |
|---|
| | 337 | } else { |
|---|
| | 338 | return false; |
|---|
| | 339 | } |
|---|
| 475 | | function get_comment_date( $d = '' ) { |
|---|
| 476 | | global $comment; |
|---|
| 477 | | if ( '' == $d ) |
|---|
| 478 | | $date = mysql2date( get_settings('date_format'), $comment->comment_date); |
|---|
| 479 | | else |
|---|
| 480 | | $date = mysql2date($d, $comment->comment_date); |
|---|
| 481 | | return apply_filters('get_comment_date', $date); |
|---|
| 482 | | } |
|---|
| | 362 | $result = $wpdb->query( |
|---|
| | 363 | "UPDATE $wpdb->comments SET |
|---|
| | 364 | comment_content = '$comment_content', |
|---|
| | 365 | comment_author = '$comment_author', |
|---|
| | 366 | comment_author_email = '$comment_author_email', |
|---|
| | 367 | comment_approved = '$comment_approved', |
|---|
| | 368 | comment_author_url = '$comment_author_url', |
|---|
| | 369 | comment_date = '$comment_date' |
|---|
| | 370 | WHERE comment_ID = $comment_ID" ); |
|---|
| 518 | | function trackback_rdf($timezone = 0) { |
|---|
| 519 | | global $id; |
|---|
| 520 | | if (!stristr($_SERVER['HTTP_USER_AGENT'], 'W3C_Validator')) { |
|---|
| 521 | | echo '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" |
|---|
| 522 | | xmlns:dc="http://purl.org/dc/elements/1.1/" |
|---|
| 523 | | xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/"> |
|---|
| 524 | | <rdf:Description rdf:about="'; |
|---|
| 525 | | the_permalink(); |
|---|
| 526 | | echo '"'."\n"; |
|---|
| 527 | | echo ' dc:identifier="'; |
|---|
| 528 | | the_permalink(); |
|---|
| 529 | | echo '"'."\n"; |
|---|
| 530 | | echo ' dc:title="'.str_replace('--', '--', wptexturize(strip_tags(get_the_title()))).'"'."\n"; |
|---|
| 531 | | echo ' trackback:ping="'.trackback_url(0).'"'." />\n"; |
|---|
| 532 | | echo '</rdf:RDF>'; |
|---|
| 533 | | } |
|---|
| 534 | | } |
|---|
| 535 | | |
|---|
| 536 | | function comments_open() { |
|---|
| 537 | | global $post; |
|---|
| 538 | | if ( 'open' == $post->comment_status ) |
|---|
| 539 | | return true; |
|---|
| 540 | | else |
|---|
| 541 | | return false; |
|---|
| 542 | | } |
|---|
| 543 | | |
|---|
| 544 | | function pings_open() { |
|---|
| 545 | | global $post; |
|---|
| 546 | | if ( 'open' == $post->ping_status ) |
|---|
| 547 | | return true; |
|---|
| 548 | | else |
|---|
| 549 | | return false; |
|---|
| 550 | | } |
|---|
| 551 | | |
|---|
| 552 | | // Non-template functions |
|---|
| 553 | | |
|---|
| 554 | | function get_lastcommentmodified($timezone = 'server') { |
|---|
| 555 | | global $cache_lastcommentmodified, $pagenow, $wpdb; |
|---|
| 556 | | $add_seconds_blog = get_settings('gmt_offset') * 3600; |
|---|
| 557 | | $add_seconds_server = date('Z'); |
|---|
| 558 | | $now = current_time('mysql', 1); |
|---|
| 559 | | if ( !isset($cache_lastcommentmodified[$timezone]) ) { |
|---|
| 560 | | switch(strtolower($timezone)) { |
|---|
| 561 | | case 'gmt': |
|---|
| 562 | | $lastcommentmodified = $wpdb->get_var("SELECT comment_date_gmt FROM $wpdb->comments WHERE comment_date_gmt <= '$now' ORDER BY comment_date_gmt DESC LIMIT 1"); |
|---|
| 563 | | break; |
|---|
| 564 | | case 'blog': |
|---|
| 565 | | $lastcommentmodified = $wpdb->get_var("SELECT comment_date FROM $wpdb->comments WHERE comment_date_gmt <= '$now' ORDER BY comment_date_gmt DESC LIMIT 1"); |
|---|
| 566 | | break; |
|---|
| 567 | | case 'server': |
|---|
| 568 | | $lastcommentmodified = $wpdb->get_var("SELECT DATE_ADD(comment_date_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->comments WHERE comment_date_gmt <= '$now' ORDER BY comment_date_gmt DESC LIMIT 1"); |
|---|
| 569 | | break; |
|---|
| 570 | | } |
|---|
| 571 | | $cache_lastcommentmodified[$timezone] = $lastcommentmodified; |
|---|
| 572 | | } else { |
|---|
| 573 | | $lastcommentmodified = $cache_lastcommentmodified[$timezone]; |
|---|
| 574 | | } |
|---|
| 575 | | return $lastcommentmodified; |
|---|
| 576 | | } |
|---|
| 577 | | |
|---|
| 578 | | function get_commentdata( $comment_ID, $no_cache = 0, $include_unapproved = false ) { // less flexible, but saves DB queries |
|---|
| 579 | | global $postc, $id, $commentdata, $wpdb; |
|---|
| 580 | | if ($no_cache) { |
|---|
| 581 | | $query = "SELECT * FROM $wpdb->comments WHERE comment_ID = '$comment_ID'"; |
|---|
| 582 | | if (false == $include_unapproved) { |
|---|
| 583 | | $query .= " AND comment_approved = '1'"; |
|---|
| 584 | | } |
|---|
| 585 | | $myrow = $wpdb->get_row($query, ARRAY_A); |
|---|
| 586 | | } else { |
|---|
| 587 | | $myrow['comment_ID'] = $postc->comment_ID; |
|---|
| 588 | | $myrow['comment_post_ID'] = $postc->comment_post_ID; |
|---|
| 589 | | $myrow['comment_author'] = $postc->comment_author; |
|---|
| 590 | | $myrow['comment_author_email'] = $postc->comment_author_email; |
|---|
| 591 | | $myrow['comment_author_url'] = $postc->comment_author_url; |
|---|
| 592 | | $myrow['comment_author_IP'] = $postc->comment_author_IP; |
|---|
| 593 | | $myrow['comment_date'] = $postc->comment_date; |
|---|
| 594 | | $myrow['comment_content'] = $postc->comment_content; |
|---|
| 595 | | $myrow['comment_karma'] = $postc->comment_karma; |
|---|
| 596 | | $myrow['comment_approved'] = $postc->comment_approved; |
|---|
| 597 | | $myrow['comment_type'] = $postc->comment_type; |
|---|
| 598 | | } |
|---|
| 599 | | return $myrow; |
|---|
| 600 | | } |
|---|
| 601 | | |
|---|
| 785 | | function wp_set_comment_status($comment_id, $comment_status) { |
|---|
| 786 | | global $wpdb; |
|---|
| 787 | | |
|---|
| 788 | | switch($comment_status) { |
|---|
| 789 | | case 'hold': |
|---|
| 790 | | $query = "UPDATE $wpdb->comments SET comment_approved='0' WHERE comment_ID='$comment_id' LIMIT 1"; |
|---|
| 791 | | break; |
|---|
| 792 | | case 'approve': |
|---|
| 793 | | $query = "UPDATE $wpdb->comments SET comment_approved='1' WHERE comment_ID='$comment_id' LIMIT 1"; |
|---|
| 794 | | break; |
|---|
| 795 | | case 'spam': |
|---|
| 796 | | $query = "UPDATE $wpdb->comments SET comment_approved='spam' WHERE comment_ID='$comment_id' LIMIT 1"; |
|---|
| 797 | | break; |
|---|
| 798 | | case 'delete': |
|---|
| 799 | | return wp_delete_comment($comment_id); |
|---|
| 800 | | break; |
|---|
| 801 | | default: |
|---|
| 802 | | return false; |
|---|
| 803 | | } |
|---|
| 804 | | |
|---|
| 805 | | if ($wpdb->query($query)) { |
|---|
| 806 | | do_action('wp_set_comment_status', $comment_id, $comment_status); |
|---|
| 807 | | |
|---|
| 808 | | $comment = get_comment($comment_id); |
|---|
| 809 | | $comment_post_ID = $comment->comment_post_ID; |
|---|
| 810 | | $c = $wpdb->get_row( "SELECT count(*) as c FROM {$wpdb->comments} WHERE comment_post_ID = '$comment_post_ID' AND comment_approved = '1'" ); |
|---|
| 811 | | if( is_object( $c ) ) |
|---|
| 812 | | $wpdb->query( "UPDATE $wpdb->posts SET comment_count = '$c->c' WHERE ID = '$comment_post_ID'" ); |
|---|
| 813 | | return true; |
|---|
| 814 | | } else { |
|---|
| 815 | | return false; |
|---|
| 816 | | } |
|---|
| 817 | | } |
|---|
| 818 | | |
|---|
| 819 | | function wp_get_comment_status($comment_id) { |
|---|
| 820 | | global $wpdb; |
|---|
| 821 | | |
|---|
| 822 | | $result = $wpdb->get_var("SELECT comment_approved FROM $wpdb->comments WHERE comment_ID='$comment_id' LIMIT 1"); |
|---|
| 823 | | if ($result == NULL) { |
|---|
| 824 | | return 'deleted'; |
|---|
| 825 | | } else if ($result == '1') { |
|---|
| 826 | | return 'approved'; |
|---|
| 827 | | } else if ($result == '0') { |
|---|
| 828 | | return 'unapproved'; |
|---|
| 829 | | } else if ($result == 'spam') { |
|---|
| 830 | | return 'spam'; |
|---|
| 831 | | } else { |
|---|
| 832 | | return false; |
|---|
| 833 | | } |
|---|
| 834 | | } |
|---|
| 835 | | |
|---|
| 836 | | function check_comment($author, $email, $url, $comment, $user_ip, $user_agent, $comment_type) { |
|---|
| 837 | | global $wpdb; |
|---|
| 838 | | |
|---|
| 839 | | if (1 == get_settings('comment_moderation')) return false; // If moderation is set to manual |
|---|
| 840 | | |
|---|
| 841 | | if ( (count(explode('http:', $comment)) - 1) >= get_settings('comment_max_links') ) |
|---|
| 842 | | return false; // Check # of external links |
|---|
| 843 | | |
|---|
| 844 | | $mod_keys = trim( get_settings('moderation_keys') ); |
|---|
| 845 | | if ( !empty($mod_keys) ) { |
|---|
| 846 | | $words = explode("\n", $mod_keys ); |
|---|
| 847 | | |
|---|
| 848 | | foreach ($words as $word) { |
|---|
| 849 | | $word = trim($word); |
|---|
| 850 | | |
|---|
| 851 | | // Skip empty lines |
|---|
| 852 | | if (empty($word)) { continue; } |
|---|
| 853 | | |
|---|
| 854 | | // Do some escaping magic so that '#' chars in the |
|---|
| 855 | | // spam words don't break things: |
|---|
| 856 | | $word = preg_quote($word, '#'); |
|---|
| 857 | | |
|---|
| 858 | | $pattern = "#$word#i"; |
|---|
| 859 | | if ( preg_match($pattern, $author) ) return false; |
|---|
| 860 | | if ( preg_match($pattern, $email) ) return false; |
|---|
| 861 | | if ( preg_match($pattern, $url) ) return false; |
|---|
| 862 | | if ( preg_match($pattern, $comment) ) return false; |
|---|
| 863 | | if ( preg_match($pattern, $user_ip) ) return false; |
|---|
| 864 | | if ( preg_match($pattern, $user_agent) ) return false; |
|---|
| 865 | | } |
|---|
| 866 | | } |
|---|
| 867 | | |
|---|
| 868 | | // Comment whitelisting: |
|---|
| 869 | | if ( 1 == get_settings('comment_whitelist')) { |
|---|
| 870 | | if ( 'trackback' == $comment_type || 'pingback' == $comment_type ) { // check if domain is in blogroll |
|---|
| 871 | | $uri = parse_url($url); |
|---|
| 872 | | $domain = $uri['host']; |
|---|
| 873 | | $uri = parse_url( get_option('home') ); |
|---|
| 874 | | $home_domain = $uri['host']; |
|---|
| 875 | | if ( $wpdb->get_var("SELECT link_id FROM $wpdb->links WHERE link_url LIKE ('%$domain%') LIMIT 1") || $domain == $home_domain ) |
|---|
| 876 | | return true; |
|---|
| 877 | | else |
|---|
| 878 | | return false; |
|---|
| 879 | | } elseif( $author != '' && $email != '' ) { |
|---|
| 880 | | |
|---|