Changeset 6553
- Timestamp:
- 01/04/2008 08:03:42 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/comment.php
r6551 r6553 1 1 <?php 2 2 /** 3 * Manages WordPress comments 4 * 5 * @package WordPress 6 */ 7 8 /** 9 * check_comment() - Checks whether a comment passes internal checks to be allowed to add 10 * 11 * {@internal Missing Long Description}} 12 * 13 * @since 1.2 14 * @uses $wpdb 15 * 16 * @param string $author {@internal Missing Description }} 17 * @param string $email {@internal Missing Description }} 18 * @param string $url {@internal Missing Description }} 19 * @param string $comment {@internal Missing Description }} 20 * @param string $user_ip {@internal Missing Description }} 21 * @param string $user_agent {@internal Missing Description }} 22 * @param string $comment_type {@internal Missing Description }} 23 * @return bool {@internal Missing Description }} 24 */ 3 25 function check_comment($author, $email, $url, $comment, $user_ip, $user_agent, $comment_type) { 4 26 global $wpdb; … … 61 83 } 62 84 63 85 /** 86 * get_approved_comments() - Returns the approved comments for post $post_id 87 * 88 * @since 2.0 89 * @uses $wpdb 90 * 91 * @param int $post_id The ID of the post 92 * @return array $comments The approved comments 93 */ 64 94 function get_approved_comments($post_id) { 65 95 global $wpdb; … … 67 97 } 68 98 69 70 // Retrieves comment data given a comment ID or comment object. 71 // Handles comment caching. 99 /** 100 * get_comment() - Retrieves comment data given a comment ID or comment object. 101 * 102 * {@internal Missing Long Description}} 103 * 104 * @since 2.0 105 * @uses $wpdb 106 * 107 * @param object|string|int $comment {@internal Missing Description}} 108 * @param string $output OBJECT or ARRAY_A or ARRAY_N constants 109 * @return object|array|null Depends on $output value. 110 */ 72 111 function &get_comment(&$comment, $output = OBJECT) { 73 112 global $wpdb; … … 103 142 } 104 143 105 106 // Deprecate in favor of get_comment()? 144 /** 145 * get_commentdata() - Returns an array of comment data about comment $comment_ID 146 * 147 * get_comment() technically does the same thing as this function. This function also 148 * appears to reference variables and then not use them or not update them when needed. 149 * It is advised to switch to get_comment(), since this function might be deprecated in 150 * favor of using get_comment(). 151 * 152 * @deprecated Use get_comment() 153 * @see get_comment() 154 * @since 0.71 155 * 156 * @uses $postc Comment cache, might not be used any more 157 * @uses $id 158 * @uses $wpdb Database Object 159 * 160 * @param int $comment_ID The ID of the comment 161 * @param int $no_cache Whether to use the cache or not (casted to bool) 162 * @param bool $include_unapproved Whether to include unapproved comments or not 163 * @return array The comment data 164 */ 107 165 function get_commentdata( $comment_ID, $no_cache = 0, $include_unapproved = false ) { // less flexible, but saves DB queries 108 166 global $postc, $wpdb; … … 128 186 } 129 187 130 188 /** 189 * get_lastcommentmodified() - The date the last comment was modified 190 * 191 * {@internal Missing Long Description}} 192 * 193 * @since 1.5.0 194 * @uses $wpdb 195 * @global array $cache_lastcommentmodified 196 * 197 * @param string $timezone Which timezone to use in reference to 'gmt', 'blog', or 'server' locations 198 * @return string Last comment modified date 199 */ 131 200 function get_lastcommentmodified($timezone = 'server') { 132 201 global $cache_lastcommentmodified, $wpdb; … … 152 221 } 153 222 154 223 /** 224 * get_comment_count() - The amount of comments in a post or total comments 225 * 226 * {@internal Missing Long Description}} 227 * 228 * @since 2.0.0 229 * @uses $wpdb 230 * 231 * @param int $post_id Optional. Comment amount in post if > 0, else total com 232 ments blog wide 233 * @return array The amount of spam, approved, awaiting moderation, and total 234 */ 155 235 function get_comment_count( $post_id = 0 ) { 156 global $wpdb; 157 158 $post_id = (int) $post_id; 159 160 $where = ''; 161 if ( $post_id > 0 ) { 162 $where = "WHERE comment_post_ID = {$post_id}"; 163 } 164 165 $totals = (array) $wpdb->get_results(" 166 SELECT comment_approved, COUNT( * ) AS total 167 FROM {$wpdb->comments} 168 {$where} 169 GROUP BY comment_approved 170 ", ARRAY_A); 171 172 $comment_count = array( 173 "approved" => 0, 174 "awaiting_moderation" => 0, 175 "spam" => 0, 176 "total_comments" => 0 177 ); 178 179 foreach ( $totals as $row ) { 180 switch ( $row['comment_approved'] ) { 181 case 'spam': 182 $comment_count['spam'] = $row['total']; 183 $comment_count["total_comments"] += $row['total']; 184 break; 185 case 1: 186 $comment_count['approved'] = $row['total']; 187 $comment_count['total_comments'] += $row['total']; 188 break; 189 case 0: 190 $comment_count['awaiting_moderation'] = $row['total']; 191 $comment_count['total_comments'] += $row['total']; 192 break; 193 default: 194 break; 195 } 196 } 197 198 return $comment_count; 199 } 200 201 236 global $wpdb; 237 238 $post_id = (int) $post_id; 239 240 $where = ''; 241 if ( $post_id > 0 ) { 242 $where = "WHERE comment_post_ID = {$post_id}"; 243 } 244 245 $totals = (array) $wpdb->get_results(" 246 SELECT comment_approved, COUNT( * ) AS total 247 FROM {$wpdb->comments} 248 {$where} 249 GROUP BY comment_approved 250 ", ARRAY_A); 251 252 $comment_count = array( 253 "approved" => 0, 254 "awaiting_moderation" => 0, 255 "spam" => 0, 256 "total_comments" => 0 257 ); 258 259 foreach ( $totals as $row ) { 260 switch ( $row['comment_approved'] ) { 261 case 'spam': 262 $comment_count['spam'] = $row['total']; 263 $comment_count["total_comments"] += $row['total']; 264 break; 265 case 1: 266 $comment_count['approved'] = $row['total']; 267 $comment_count['total_comments'] += $row['total']; 268 break; 269 case 0: 270 $comment_count['awaiting_moderation'] = $row['total']; 271 $comment_count['total_comments'] += $row['total']; 272 break; 273 default: 274 break; 275 } 276 } 277 278 return $comment_count; 279 } 280 281 /** 282 * sanitize_comment_cookies() - {@internal Missing Short Description}} 283 * 284 * {@internal Missing Long Description}} 285 * 286 * @since 2.0.4 287 * 288 */ 202 289 function sanitize_comment_cookies() { 203 290 if ( isset($_COOKIE['comment_author_'.COOKIEHASH]) ) { … … 222 309 } 223 310 224 311 /** 312 * wp_allow_comment() - Validates whether this comment is allowed to be made or not 313 * 314 * {@internal Missing Long Description}} 315 * 316 * @since 2.0.0 317 * @uses $wpdb 318 * @uses apply_filters() Calls 'pre_comment_approved' hook on the type of comment 319 * @uses do_action() Calls 'check_comment_flood' hook on $comment_author_IP, $comment_author_email, and $comment_date_gmt 320 * 321 * @param array $commentdata Contains information on the comment 322 * @return mixed Signifies the approval status (0|1|'spam') 323 */ 225 324 function wp_allow_comment($commentdata) { 226 325 global $wpdb; … … 261 360 } 262 361 362 /** 363 * check_comment_flood_db() - {@internal Missing Short Description}} 364 * 365 * {@internal Missing Long Description}} 366 * 367 * @since 2.3.0 368 * @uses $wpdb 369 * @uses apply_filters() {@internal Missing Description}} 370 * @uses do_action() {@internal Missing Description}} 371 * 372 * @param string $ip {@internal Missing Description}} 373 * @param string $email {@internal Missing Description}} 374 * @param unknown_type $date {@internal Missing Description}} 375 */ 263 376 function check_comment_flood_db( $ip, $email, $date ) { 264 377 global $wpdb; … … 274 387 } 275 388 389 /** 390 * wp_blacklist_check() - Does comment contain blacklisted characters or words 391 * 392 * {@internal Missing Long Description}} 393 * 394 * @since 1.5.0 395 * @uses do_action() Calls 'wp_blacklist_check' hook for all parameters 396 * 397 * @param string $author The author of the comment 398 * @param string $email The email of the comment 399 * @param string $url The url used in the comment 400 * @param string $comment The comment content 401 * @param string $user_ip The comment author IP address 402 * @param string $user_agent The author's browser user agent 403 * @return bool True if comment contains blacklisted content, false if comment does not 404 */ 276 405 function wp_blacklist_check($author, $email, $url, $comment, $user_ip, $user_agent) { 277 406 do_action('wp_blacklist_check', $author, $email, $url, $comment, $user_ip, $user_agent); … … 316 445 } 317 446 318 447 /** 448 * wp_delete_comment() - Removes comment ID and maybe updates post comment count 449 * 450 * The post comment count will be updated if the comment was approved and has a post 451 * ID available. 452 * 453 * @since 2.0.0 454 * @uses $wpdb 455 * @uses do_action() Calls 'delete_comment' hook on comment ID 456 * @uses do_action() Calls 'wp_set_comment_status' hook on comment ID with 'delete' set for the second parameter 457 * 458 * @param int $comment_id Comment ID 459 * @return bool False if delete comment query failure, true on success 460 */ 319 461 function wp_delete_comment($comment_id) { 320 462 global $wpdb; … … 336 478 } 337 479 338 480 /** 481 * wp_get_comment_status() - The status of a comment by ID 482 * 483 * @since 1.0.0 484 * 485 * @param int $comment_id Comment ID 486 * @return string|bool Status might be 'deleted', 'approved', 'unapproved', 'spam'. False on failure 487 */ 339 488 function wp_get_comment_status($comment_id) { 340 489 $comment = get_comment($comment_id); … … 356 505 } 357 506 358 507 /** 508 * wp_get_current_commenter() - Get current commenter's name, email, and URL 509 * 510 * Expects cookies content to already be sanitized. User of this function 511 * might wish to recheck the returned array for validity. 512 * 513 * @see sanitize_comment_cookies() Use to sanitize cookies 514 * 515 * @since 2.0.4 516 * 517 * @return array Comment author, email, url respectively 518 */ 359 519 function wp_get_current_commenter() { 360 520 // Cookies should already be sanitized. … … 375 535 } 376 536 377 537 /** 538 * wp_insert_comment() - Inserts a comment to the database 539 * 540 * {@internal Missing Long Description}} 541 * 542 * @since 2.0.0 543 * @uses $wpdb 544 * 545 * @param array $commentdata Contains information on the comment 546 * @return int The new comment's id 547 */ 378 548 function wp_insert_comment($commentdata) { 379 549 global $wpdb; … … 407 577 } 408 578 409 579 /** 580 * wp_filter_comment() - Parses and returns comment information 581 * 582 * Sets the comment data 'filtered' field to true when finished. This 583 * can be checked as to whether the comment should be filtered and to 584 * keep from filtering the same comment more than once. 585 * 586 * @since 2.0.0 587 * @uses apply_filters() Calls 'pre_user_id' hook on comment author's user ID 588 * @uses apply_filters() Calls 'pre_comment_user_agent' hook on comment author's user agent 589 * @uses apply_filters() Calls 'pre_comment_author_name' hook on comment author's name 590 * @uses apply_filters() Calls 'pre_comment_content' hook on the comment's content 591 * @uses apply_filters() Calls 'pre_comment_user_ip' hook on comment author's IP 592 * @uses apply_filters() Calls 'pre_comment_author_url' hook on comment author's URL 593 * @uses apply_filters() Calls 'pre_comment_author_email' hook on comment author's email address 594 * 595 * @param array $commentdata Contains information on the comment 596 * @return array Parsed comment information 597 */ 410 598 function wp_filter_comment($commentdata) { 411 599 $commentdata['user_id'] = apply_filters('pre_user_id', $commentdata['user_ID']); … … 420 608 } 421 609 422 610 /** 611 * wp_throttle_comment_flood() - {@internal Missing Short Description}} 612 * 613 * {@internal Missing Long Description}} 614 * 615 * @since 2.1.0 616 * 617 * @param unknown_type $block {@internal Missing Description}} 618 * @param unknown_type $time_lastcomment {@internal Missing Description}} 619 * @param unknown_type $time_newcomment {@internal Missing Description}} 620 * @return unknown {@internal Missing Description}} 621 */ 423 622 function wp_throttle_comment_flood($block, $time_lastcomment, $time_newcomment) { 424 623 if ( $block ) // a plugin has already blocked... we'll let that decision stand … … 429 628 } 430 629 431 630 /** 631 * wp_new_comment() - Parses and adds a new comment to the database 632 * 633 * {@internal Missing Long Description}} 634 * 635 * @since 1.5.0 636 * @uses apply_filters() Calls 'preprocess_comment' hook on $commentdata parameter array before processing 637 * @uses do_action() Calls 'comment_post' hook on $comment_ID returned from adding the comment and if the comment was approved. 638 * @uses wp_filter_comment() Used to filter comment before adding comment 639 * @uses wp_allow_comment() checks to see if comment is approved. 640 * @uses wp_insert_comment() Does the actual comment insertion to the database 641 * 642 * @param array $commentdata Contains information on the comment 643 * @return int The ID of the comment after adding. 644 */ 432 645 function wp_new_comment( $commentdata ) { 433 646 $commentdata = apply_filters('preprocess_comment', $commentdata); … … 463 676 } 464 677 465 678 /** 679 * wp_set_comment_status() - Sets the status of comment ID 680 * 681 * {@internal Missing Long Description}} 682 * 683 * @since 1.0.0 684 * 685 * @param int $comment_id Comment ID 686 * @param string $comment_status New comment status, either 'hold', 'approve', 'spam', or 'delete' 687 * @return bool False on failure or deletion and true on success. 688 */ 466 689 function wp_set_comment_status($comment_id, $comment_status) { 467 690 global $wpdb; … … 496 719 } 497 720 498 721 /** 722 * wp_update_comment() - Parses and updates an existing comment in the database 723 * 724 * {@internal Missing Long Description}} 725 * 726 * @since 2.0.0 727 * @uses $wpdb 728 * 729 * @param array $commentarr Contains information on the comment 730 * @return int Comment was updated if value is 1, or was not updated if value is 0. 731 */ 499 732 function wp_update_comment($commentarr) { 500 733 global $wpdb; … … 538 771 } 539 772 540 function wp_defer_comment_counting($defer=NULL) { 773 /** 774 * wp_defer_comment_counting() - Whether to defer comment counting 775 * 776 * When setting $defer to true, all post comment counts will not be updated 777 * until $defer is set to false. When $defer is set to false, then all 778 * previously deferred updated post comment counts will then be automatically 779 * updated without having to call wp_update_comment_count() after. 780 * 781 * @since 2.5 782 * @staticvar bool $_defer 783 * 784 * @param bool $defer 785 * @return unknown 786 */ 787 function wp_defer_comment_counting($defer=null) { 541 788 static $_defer = false; 542 789 … … 545 792 // flush any deferred counts 546 793 if ( !$defer ) 547 wp_update_comment_count( NULL, true );794 wp_update_comment_count( null, true ); 548 795 } 549 796 … … 551 798 } 552 799 800 /** 801 * wp_update_comment_count() - Updates the comment count for post(s) 802 * 803 * When $do_deferred is false (is by default) and the comments have been 804 * set to be deferred, the post_id will be added to a queue, which will 805 * be updated at a later date and only updated once per post ID. 806 * 807 * If the comments have not be set up to be deferred, then the post will 808 * be updated. When $do_deferred is set to true, then all previous deferred 809 * post IDs will be updated along with the current $post_id. 810 * 811 * @since 2.1.0 812 * @see wp_update_comment_count_now() For what could cause a false return value 813 * 814 * @param int $post_id Post ID 815 * @param bool $do_deferred Whether to process previously deferred post comment counts 816 * @return bool True on success, false on failure 817 */ 553 818 function wp_update_comment_count($post_id, $do_deferred=false) { 554 819 static $_deferred = array(); … … 558 823 foreach ( $_deferred as $i => $_post_id ) { 559 824 wp_update_comment_count_now($_post_id); 560 unset( $_deferred[$i] ); 825 unset( $_deferred[$i] ); /** @todo Move this outside of the foreach and reset $_deferred to an array instead */ 561 826 } 562 827 } … … 572 837 } 573 838 839 /** 840 * wp_update_comment_count_now() - Updates the comment count for the post 841 * 842 * @since 2.5 843 * @uses $wpdb 844 * @uses do_action() Calls 'wp_update_comment_count' hook on $post_id, $new, and $old 845 * @uses do_action() Calls 'edit_posts' hook on $post_id and $post 846 * 847 * @param int $post_id Post ID 848 * @return bool False on '0' $post_id or if post with ID does not exist. True on success. 849 */ 574 850 function wp_update_comment_count_now($post_id) { 575 851 global $wpdb; … … 595 871 } 596 872 597 598 873 // 599 874 // Ping and trackback functions. 600 875 // 601 876 877 /** 878 * discover_pingback_server_uri() - Finds a pingback server URI based on the given URL 879 * 880 * {@internal Missing Long Description}} 881 * 882 * @since 1.5.0 883 * @uses $wp_version 884 * 885 * @param string $url URL to ping 886 * @param int $timeout_bytes Number of bytes to timeout at. Prevents big file downloads, default is 2048. 887 * @return bool|string False on failure, string containing URI on success. 888 */ 602 889 function discover_pingback_server_uri($url, $timeout_bytes = 2048) { 603 890 global $wp_version; … … 680 967 } 681 968 682 969 /** 970 * do_all_pings() - {@internal Missing Short Description}} 971 * 972 * {@internal Missing Long Description}} 973 * 974 * @since 2.1.0 975 * @uses $wpdb 976 */ 683 977 function do_all_pings() { 684 978 global $wpdb; … … 707 1001 } 708 1002 1003 /** 1004 * do_trackbacks() - {@internal Missing Short Description}} 1005 * 1006 * {@internal Missing Long Description}} 1007 * 1008 * @since 1.5.0 1009 * @uses $wpdb 1010 * 1011 * @param int $post_id Post ID to do trackbacks on 1012 */ 709 1013 function do_trackbacks($post_id) { 710 1014 global $wpdb; … … 745 1049 } 746 1050 747 1051 /** 1052 * generic_ping() - {@internal Missing Short Description}} 1053 * 1054 * {@internal Missing Long Description}} 1055 * 1056 * @since 1.2.0 1057 * 1058 * @param int $post_id Post ID. Not actually used. 1059 * @return int Same as Post ID from parameter 1060 */ 748 1061 function generic_ping($post_id = 0) { 749 1062 $services = get_option('ping_sites'); … … 759 1072 } 760 1073 761 1074 /** 1075 * pingback() - Pings back the links found in a post 1076 * 1077 * {@internal Missing Long Description}} 1078 * 1079 * @since 0.71 1080 * @uses $wp_version 1081 * @uses IXR_Client 1082 * 1083 * @param string $content {@internal Missing Description}} 1084 * @param int $post_ID {@internal Missing Description}} 1085 */ 762 1086 function pingback($content, $post_ID) { 763 1087 global $wp_version; … … 825 1149 } 826 1150 827 1151 /** 1152 * privacy_ping_filter() - {@internal Missing Short Description}} 1153 * 1154 * {@internal Missing Long Description}} 1155 * 1156 * @since 2.1.0 1157 * 1158 * @param unknown_type $sites {@internal Missing Description}} 1159 * @return unknown {@internal Missing Description}} 1160 */ 828 1161 function privacy_ping_filter($sites) { 829 1162 if ( '0' != get_option('blog_public') ) … … 833 1166 } 834 1167 835 // Send a Trackback 1168 /** 1169 * trackback() - Send a Trackback 1170 * 1171 * {@internal Missing Long Description}} 1172 * 1173 * @since 0.71 1174 * @uses $wpdb 1175 * @uses $wp_version WordPress version 1176 * 1177 * @param string $trackback_url {@internal Missing Description}} 1178 * @param string $title {@internal Missing Description}} 1179 * @param string $excerpt {@internal Missing Description}} 1180 * @param int $ID {@internal Missing Description}} 1181 * @return unknown {@internal Missing Description}} 1182 */ 836 1183 function trackback($trackback_url, $title, $excerpt, $ID) { 837 1184 global $wpdb, $wp_version; … … 865 1212 } 866 1213 867 1214 /** 1215 * weblog_ping() - {@internal Missing Short Description}} 1216 * 1217 * {@internal Missing Long Description}} 1218 * 1219 * @since 1.2.0 1220 * @uses $wp_version 1221 * @uses IXR_Client 1222 * 1223 * @param unknown_type $server 1224 * @param unknown_type $path 1225 */ 868 1226 function weblog_ping($server = '', $path = '') { 869 1227 global $wp_version; … … 886 1244 // 887 1245 1246 /** 1247 * clean_comment_cache() - Removes comment ID from the comment cache 1248 * 1249 * @since 2.3.0 1250 * @package WordPress 1251 * @subpackage Cache 1252 * 1253 * @param int $id Comment ID to remove from cache 1254 */ 888 1255 function clean_comment_cache($id) { 889 1256 wp_cache_delete($id, 'comment'); 890 1257 } 891 1258 1259 /** 1260 * update_comment_cache() - Updates the comment cache of given comments 1261 * 1262 * Will add the comments in $comments to the cache. If comment ID already 1263 * exists in the comment cache then it will not be updated. 1264 * 1265 * The comment is added to the cache using the comment group with the key 1266 * using the ID of the comments. 1267 * 1268 * @since 2.3.0 1269 * 1270 * @param array $comments Array of comment row objects 1271 */ 892 1272 function update_comment_cache($comments) { 893 foreach ( $comments as $comment )1273 foreach ( (array) $comments as $comment ) 894 1274 wp_cache_add($comment->comment_ID, $comment, 'comment'); 895 1275 }
Note: See TracChangeset
for help on using the changeset viewer.