Changeset 4626 for trunk/wp-includes/comment.php
- Timestamp:
- 12/07/2006 03:57:23 AM (19 years ago)
- File:
-
- 1 edited
-
trunk/wp-includes/comment.php (modified) (36 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/comment.php
r4495 r4626 4 4 global $wpdb; 5 5 6 if (1 == get_option('comment_moderation')) return false; // If moderation is set to manual 6 if ( 1 == get_option('comment_moderation') ) 7 return false; // If moderation is set to manual 7 8 8 9 if ( preg_match_all("|(href\t*?=\t*?['\"]?)?(https?:)?//|i", $comment, $out) >= get_option('comment_max_links') ) 9 10 return false; // Check # of external links 10 11 11 $mod_keys = trim( get_option('moderation_keys'));12 $mod_keys = trim(get_option('moderation_keys')); 12 13 if ( !empty($mod_keys) ) { 13 14 $words = explode("\n", $mod_keys ); … … 17 18 18 19 // Skip empty lines 19 if (empty($word)) { continue; } 20 if ( empty($word) ) 21 continue; 20 22 21 23 // Do some escaping magic so that '#' chars in the … … 44 46 else 45 47 return false; 46 } elseif ( $author != '' && $email != '' ) {48 } elseif ( $author != '' && $email != '' ) { 47 49 $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 50 if ( ( 1 == $ok_to_comment ) && … … 55 57 } 56 58 } 57 58 59 return true; 59 60 } 61 60 62 61 63 function get_approved_comments($post_id) { … … 65 67 return $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$post_id' AND comment_approved = '1' ORDER BY comment_date"); 66 68 } 69 67 70 68 71 // Retrieves comment data given a comment ID or comment object. … … 98 101 } 99 102 103 100 104 // Deprecate in favor of get_comment()? 101 105 function get_commentdata( $comment_ID, $no_cache = 0, $include_unapproved = false ) { // less flexible, but saves DB queries 102 106 global $postc, $id, $commentdata, $wpdb; 103 if ( $no_cache) {107 if ( $no_cache ) { 104 108 $query = "SELECT * FROM $wpdb->comments WHERE comment_ID = '$comment_ID'"; 105 if (false == $include_unapproved) { 106 $query .= " AND comment_approved = '1'"; 107 } 108 $myrow = $wpdb->get_row($query, ARRAY_A); 109 if ( false == $include_unapproved ) 110 $query .= " AND comment_approved = '1'"; 111 $myrow = $wpdb->get_row($query, ARRAY_A); 109 112 } else { 110 $myrow['comment_ID'] = $postc->comment_ID;111 $myrow['comment_post_ID'] = $postc->comment_post_ID;112 $myrow['comment_author'] = $postc->comment_author;113 $myrow['comment_ID'] = $postc->comment_ID; 114 $myrow['comment_post_ID'] = $postc->comment_post_ID; 115 $myrow['comment_author'] = $postc->comment_author; 113 116 $myrow['comment_author_email'] = $postc->comment_author_email; 114 $myrow['comment_author_url'] = $postc->comment_author_url;115 $myrow['comment_author_IP'] = $postc->comment_author_IP;116 $myrow['comment_date'] = $postc->comment_date;117 $myrow['comment_content'] = $postc->comment_content;118 $myrow['comment_karma'] = $postc->comment_karma;119 $myrow['comment_approved'] = $postc->comment_approved;120 $myrow['comment_type'] = $postc->comment_type;117 $myrow['comment_author_url'] = $postc->comment_author_url; 118 $myrow['comment_author_IP'] = $postc->comment_author_IP; 119 $myrow['comment_date'] = $postc->comment_date; 120 $myrow['comment_content'] = $postc->comment_content; 121 $myrow['comment_karma'] = $postc->comment_karma; 122 $myrow['comment_approved'] = $postc->comment_approved; 123 $myrow['comment_type'] = $postc->comment_type; 121 124 } 122 125 return $myrow; 123 126 } 127 124 128 125 129 function get_lastcommentmodified($timezone = 'server') { … … 129 133 $now = current_time('mysql', 1); 130 134 if ( !isset($cache_lastcommentmodified[$timezone]) ) { 131 switch (strtolower($timezone)) {135 switch ( strtolower($timezone)) { 132 136 case 'gmt': 133 137 $lastcommentmodified = $wpdb->get_var("SELECT comment_date_gmt FROM $wpdb->comments WHERE comment_date_gmt <= '$now' ORDER BY comment_date_gmt DESC LIMIT 1"); … … 147 151 } 148 152 153 149 154 function sanitize_comment_cookies() { 150 155 if ( isset($_COOKIE['comment_author_'.COOKIEHASH]) ) { … … 169 174 } 170 175 } 176 171 177 172 178 function wp_allow_comment($commentdata) { … … 199 205 } 200 206 201 // The author and the admins get respect.202 207 if ( $userdata && ( $user_id == $post_author || $user->has_cap('level_9') ) ) { 208 // The author and the admins get respect. 203 209 $approved = 1; 204 } 205 206 // Everyone else's comments will be checked. 207 else { 210 } else { 211 // Everyone else's comments will be checked. 208 212 if ( check_comment($comment_author, $comment_author_email, $comment_author_url, $comment_content, $comment_author_IP, $comment_agent, $comment_type) ) 209 213 $approved = 1; … … 218 222 } 219 223 224 220 225 function wp_blacklist_check($author, $email, $url, $comment, $user_ip, $user_agent) { 221 226 global $wpdb; … … 224 229 225 230 if ( preg_match_all('/&#(\d+);/', $comment . $author . $url, $chars) ) { 226 foreach ( $chars[1] as $char) {231 foreach ( (array) $chars[1] as $char ) { 227 232 // If it's an encoded char in the normal ASCII set, reject 228 233 if ( 38 == $char ) 229 234 continue; // Unless it's & 230 if ( $char < 128)235 if ( $char < 128 ) 231 236 return true; 232 237 } … … 234 239 235 240 $mod_keys = trim( get_option('blacklist_keys') ); 236 if ( '' == $mod_keys )241 if ( '' == $mod_keys ) 237 242 return false; // If moderation keys are empty 238 243 $words = explode("\n", $mod_keys ); 239 244 240 foreach ( $words as $word) {245 foreach ( (array) $words as $word ) { 241 246 $word = trim($word); 242 247 … … 249 254 250 255 $pattern = "#$word#i"; 251 if ( preg_match($pattern, $author ) ) return true; 252 if ( preg_match($pattern, $email ) ) return true; 253 if ( preg_match($pattern, $url ) ) return true; 254 if ( preg_match($pattern, $comment ) ) return true; 255 if ( preg_match($pattern, $user_ip ) ) return true; 256 if ( preg_match($pattern, $user_agent) ) return true; 257 } 258 256 if ( 257 preg_match($pattern, $author) 258 || preg_match($pattern, $email) 259 || preg_match($pattern, $url) 260 || preg_match($pattern, $comment) 261 || preg_match($pattern, $user_ip) 262 || preg_match($pattern, $user_agent) 263 ) 264 return true; 265 } 259 266 return false; 260 267 } 268 261 269 262 270 function wp_delete_comment($comment_id) { … … 277 285 } 278 286 287 279 288 function wp_get_comment_status($comment_id) { 280 289 global $wpdb; 281 290 282 291 $result = $wpdb->get_var("SELECT comment_approved FROM $wpdb->comments WHERE comment_ID='$comment_id' LIMIT 1"); 283 if ($result == NULL) { 292 293 if ( $result == NULL ) 284 294 return 'deleted'; 285 } else if ($result == '1') {295 elseif ( $result == '1' ) 286 296 return 'approved'; 287 } else if ($result == '0') {297 elseif ( $result == '0' ) 288 298 return 'unapproved'; 289 } else if ($result == 'spam') {299 elseif ( $result == 'spam' ) 290 300 return 'spam'; 291 } else {301 else 292 302 return false; 293 }294 } 303 } 304 295 305 296 306 function wp_get_current_commenter() { … … 311 321 return compact('comment_author', 'comment_author_email', 'comment_author_url'); 312 322 } 323 313 324 314 325 function wp_insert_comment($commentdata) { … … 343 354 } 344 355 356 345 357 function wp_filter_comment($commentdata) { 346 358 $commentdata['user_id'] = apply_filters('pre_user_id', $commentdata['user_ID']); … … 355 367 } 356 368 369 357 370 function wp_throttle_comment_flood($block, $time_lastcomment, $time_newcomment) { 358 371 if ( $block ) // a plugin has already blocked... we'll let that decision stand … … 363 376 } 364 377 378 365 379 function wp_new_comment( $commentdata ) { 366 380 $commentdata = apply_filters('preprocess_comment', $commentdata); … … 374 388 $commentdata['comment_date'] = current_time('mysql'); 375 389 $commentdata['comment_date_gmt'] = current_time('mysql', 1); 376 377 390 378 391 $commentdata = wp_filter_comment($commentdata); … … 397 410 } 398 411 412 399 413 function wp_set_comment_status($comment_id, $comment_status) { 400 global $wpdb;401 402 switch($comment_status) {414 global $wpdb; 415 416 switch ( $comment_status ) { 403 417 case 'hold': 404 418 $query = "UPDATE $wpdb->comments SET comment_approved='0' WHERE comment_ID='$comment_id' LIMIT 1"; 405 break;419 break; 406 420 case 'approve': 407 421 $query = "UPDATE $wpdb->comments SET comment_approved='1' WHERE comment_ID='$comment_id' LIMIT 1"; 408 break;422 break; 409 423 case 'spam': 410 424 $query = "UPDATE $wpdb->comments SET comment_approved='spam' WHERE comment_ID='$comment_id' LIMIT 1"; 411 break;425 break; 412 426 case 'delete': 413 427 return wp_delete_comment($comment_id); 414 break;428 break; 415 429 default: 416 430 return false; 417 }418 419 if ($wpdb->query($query)) {431 } 432 433 if ( $wpdb->query($query) ) { 420 434 do_action('wp_set_comment_status', $comment_id, $comment_status); 421 435 422 436 $comment = get_comment($comment_id); 423 437 $comment_post_ID = $comment->comment_post_ID; 424 $c = $wpdb->get_row( "SELECT count(*) as c FROM {$wpdb->comments} WHERE comment_post_ID = '$comment_post_ID' AND comment_approved = '1'");425 if ( is_object( $c) )426 $wpdb->query( "UPDATE $wpdb->posts SET comment_count = '$c->c' WHERE ID = '$comment_post_ID'");438 $c = $wpdb->get_row("SELECT count(*) as c FROM {$wpdb->comments} WHERE comment_post_ID = '$comment_post_ID' AND comment_approved = '1'"); 439 if ( is_object($c) ) 440 $wpdb->query("UPDATE $wpdb->posts SET comment_count = '$c->c' WHERE ID = '$comment_post_ID'"); 427 441 return true; 428 } else {442 } else { 429 443 return false; 430 } 431 } 444 } 445 } 446 432 447 433 448 function wp_update_comment($commentarr) { … … 438 453 439 454 // Escape data pulled from DB. 440 foreach ( $comment as $key => $value)455 foreach ( (array) $comment as $key => $value ) 441 456 $comment[$key] = $wpdb->escape($value); 442 457 … … 453 468 $result = $wpdb->query( 454 469 "UPDATE $wpdb->comments SET 455 comment_content = '$comment_content',456 comment_author = '$comment_author',470 comment_content = '$comment_content', 471 comment_author = '$comment_author', 457 472 comment_author_email = '$comment_author_email', 458 comment_approved = '$comment_approved',459 comment_author_url = '$comment_author_url',460 comment_date = '$comment_date'473 comment_approved = '$comment_approved', 474 comment_author_url = '$comment_author_url', 475 comment_date = '$comment_date' 461 476 WHERE comment_ID = $comment_ID" ); 462 477 463 478 $rval = $wpdb->rows_affected; 464 465 479 wp_update_comment_count($comment_post_ID); 466 467 480 do_action('edit_comment', $comment_ID); 468 469 481 return $rval; 470 482 } 483 471 484 472 485 function wp_update_comment_count($post_id) { … … 481 494 } 482 495 496 483 497 // 484 498 // Ping and trackback functions. … … 498 512 extract(parse_url($url)); 499 513 500 if (!isset($host)) { 501 // Not an URL. This should never happen. 514 if ( !isset($host) ) // Not an URL. This should never happen. 502 515 return false; 503 } 504 505 $path = (!isset($path)) ? '/' : $path; 506 $path .= (isset($query)) ? '?'.$query : ''; 507 $port = (isset($port)) ? $port : 80; 516 517 $path = ( !isset($path) ) ? '/' : $path; 518 $path .= ( isset($query) ) ? '?' . $query : ''; 519 $port = ( isset($port) ) ? $port : 80; 508 520 509 521 // Try to connect to the server at $host 510 522 $fp = @fsockopen($host, $port, $errno, $errstr, 2); 511 if (!$fp) { 512 // Couldn't open a connection to $host; 523 if ( !$fp ) // Couldn't open a connection to $host 513 524 return false; 514 }515 525 516 526 // Send the GET request 517 527 $request = "GET $path HTTP/1.1\r\nHost: $host\r\nUser-Agent: WordPress/$wp_version \r\n\r\n"; 518 //ob_end_flush();528 // ob_end_flush(); 519 529 fputs($fp, $request); 520 530 521 531 // Let's check for an X-Pingback header first 522 while ( !feof($fp)) {532 while ( !feof($fp) ) { 523 533 $line = fgets($fp, 512); 524 if ( trim($line) == '') {534 if ( trim($line) == '' ) 525 535 break; 526 }527 536 $headers .= trim($line)."\n"; 528 537 $x_pingback_header_offset = strpos(strtolower($headers), $x_pingback_str); 529 if ( $x_pingback_header_offset) {538 if ( $x_pingback_header_offset ) { 530 539 // We got it! 531 540 preg_match('#x-pingback: (.+)#is', $headers, $matches); … … 533 542 return $pingback_server_url; 534 543 } 535 if (strpos(strtolower($headers), 'content-type: ')) {544 if ( strpos(strtolower($headers), 'content-type: ') ) { 536 545 preg_match('#content-type: (.+)#is', $headers, $matches); 537 546 $content_type = trim($matches[1]); … … 539 548 } 540 549 541 if (preg_match('#(image|audio|video|model)/#is', $content_type)) { 542 // Not an (x)html, sgml, or xml page, no use going further 550 if ( preg_match('#(image|audio|video|model)/#is', $content_type) ) // Not an (x)html, sgml, or xml page, no use going further 543 551 return false; 544 } 545 546 while (!feof($fp)) { 552 553 while ( !feof($fp) ) { 547 554 $line = fgets($fp, 1024); 548 555 $contents .= trim($line); 549 556 $pingback_link_offset_dquote = strpos($contents, $pingback_str_dquote); 550 557 $pingback_link_offset_squote = strpos($contents, $pingback_str_squote); 551 if ( $pingback_link_offset_dquote || $pingback_link_offset_squote) {558 if ( $pingback_link_offset_dquote || $pingback_link_offset_squote ) { 552 559 $quote = ($pingback_link_offset_dquote) ? '"' : '\''; 553 560 $pingback_link_offset = ($quote=='"') ? $pingback_link_offset_dquote : $pingback_link_offset_squote; … … 558 565 $pingback_server_url = substr($contents, $pingback_href_start, $pingback_server_url_len); 559 566 // We may find rel="pingback" but an incomplete pingback URL 560 if ($pingback_server_url_len > 0) { 561 // We got it! 567 if ( $pingback_server_url_len > 0 ) // We got it! 562 568 return $pingback_server_url; 563 }564 569 } 565 570 $byte_count += strlen($line); 566 if ( $byte_count > $timeout_bytes) {571 if ( $byte_count > $timeout_bytes ) { 567 572 // It's no use going further, there probably isn't any pingback 568 573 // server to find in this file. (Prevents loading large files.) … … 574 579 return false; 575 580 } 581 576 582 577 583 function do_all_pings() { … … 593 599 $trackbacks = $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE CHAR_LENGTH(TRIM(to_ping)) > 7 AND post_status = 'publish'"); 594 600 if ( is_array($trackbacks) ) { 595 foreach ( $trackbacks as $trackback ) {601 foreach ( $trackbacks as $trackback ) 596 602 do_trackbacks($trackback->ID); 597 }598 603 } 599 604 … … 613 618 } 614 619 615 if ( empty($post->post_excerpt))620 if ( empty($post->post_excerpt) ) 616 621 $excerpt = apply_filters('the_content', $post->post_content); 617 622 else … … 627 632 $post_title = strip_tags($post_title); 628 633 629 if ($to_ping) : foreach ($to_ping as $tb_ping) : 630 $tb_ping = trim($tb_ping); 631 if ( !in_array($tb_ping, $pinged) ) { 632 trackback($tb_ping, $post_title, $excerpt, $post_id); 633 $pinged[] = $tb_ping; 634 } else { 635 $wpdb->query("UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, '$tb_ping', '')) WHERE ID = '$post_id'"); 636 } 637 endforeach; endif; 638 } 634 if ( $to_ping ) { 635 foreach ( (array) $to_ping as $tb_ping ) { 636 $tb_ping = trim($tb_ping); 637 if ( !in_array($tb_ping, $pinged) ) { 638 trackback($tb_ping, $post_title, $excerpt, $post_id); 639 $pinged[] = $tb_ping; 640 } else { 641 $wpdb->query("UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, '$tb_ping', '')) WHERE ID = '$post_id'"); 642 } 643 } 644 } 645 } 646 639 647 640 648 function generic_ping($post_id = 0) { … … 644 652 if ( '' != $services ) { 645 653 $services = explode("\n", $services); 646 foreach ( $services as $service) {654 foreach ( (array) $services as $service ) 647 655 weblog_ping($service); 648 }649 656 } 650 657 651 658 return $post_id; 652 659 } 660 653 661 654 662 function pingback($content, $post_ID) { 655 663 global $wp_version, $wpdb; 656 include_once (ABSPATH . WPINC . '/class-IXR.php');664 include_once(ABSPATH . WPINC . '/class-IXR.php'); 657 665 658 666 // original code by Mort (http://mort.mine.nu:8080) 659 667 $log = debug_fopen(ABSPATH . '/pingback.log', 'a'); 660 668 $post_links = array(); 661 debug_fwrite($log, 'BEGIN ' .date('YmdHis', time())."\n");669 debug_fwrite($log, 'BEGIN ' . date('YmdHis', time()) . "\n"); 662 670 663 671 $pung = get_pung($post_ID); … … 688 696 // We don't wanna ping first and second types, even if they have a valid <link/> 689 697 690 foreach ($post_links_temp[0] as $link_test) :698 foreach ( $post_links_temp[0] as $link_test ) : 691 699 if ( !in_array($link_test, $pung) && (url_to_postid($link_test) != $post_ID) // If we haven't pung it already and it isn't a link to itself 692 700 && !is_local_attachment($link_test) ) : // Also, let's never ping local attachments. 693 701 $test = parse_url($link_test); 694 if ( isset($test['query']))702 if ( isset($test['query']) ) 695 703 $post_links[] = $link_test; 696 elseif (($test['path'] != '/') && ($test['path'] != ''))704 elseif ( ($test['path'] != '/') && ($test['path'] != '') ) 697 705 $post_links[] = $link_test; 698 706 endif; 699 707 endforeach; 700 708 701 do_action_ref_array('pre_ping', array(&$post_links, &$pung));702 703 foreach ( $post_links as $pagelinkedto){709 do_action_ref_array('pre_ping', array(&$post_links, &$pung)); 710 711 foreach ( (array) $post_links as $pagelinkedto ) { 704 712 debug_fwrite($log, "Processing -- $pagelinkedto\n"); 705 713 $pingback_server_url = discover_pingback_server_uri($pagelinkedto, 2048); 706 714 707 if ( $pingback_server_url) {715 if ( $pingback_server_url ) { 708 716 @ set_time_limit( 60 ); 709 717 // Now, the RPC call … … 732 740 } 733 741 734 function privacy_ping_filter( $sites ) { 742 743 function privacy_ping_filter($sites) { 735 744 if ( '0' != get_option('blog_public') ) 736 745 return $sites; … … 781 790 } 782 791 792 783 793 function weblog_ping($server = '', $path = '') { 784 794 global $wp_version; 785 include_once (ABSPATH . WPINC . '/class-IXR.php');795 include_once(ABSPATH . WPINC . '/class-IXR.php'); 786 796 787 797 // using a timeout of 3 seconds should be enough to cover slow servers
Note: See TracChangeset
for help on using the changeset viewer.