Ticket #2648: comment-functions.diff
| File comment-functions.diff, 16.7 KB (added by Pita, 6 years ago) |
|---|
-
comment-functions.php
2 2 3 3 // Template functions 4 4 5 /** 6 * Loads the comment template specified in $file 7 * @param string $file The file to load (default '/comments.php') 8 */ 5 9 function comments_template( $file = '/comments.php' ) { 6 10 global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity; 7 11 … … 44 48 endif; 45 49 } 46 50 51 /** 52 * Parses and adds a new comment to the database 53 * @param array $commentdata Contains information on the comment 54 */ 47 55 function wp_new_comment( $commentdata ) { 48 56 $commentdata = apply_filters('preprocess_comment', $commentdata); 49 57 … … 78 86 return $comment_ID; 79 87 } 80 88 89 /** 90 * Inserts a comment to the database 91 * @param array $commentdata Contains information on the comment 92 * @return int $id The new comment's id 93 */ 81 94 function wp_insert_comment($commentdata) { 82 95 global $wpdb; 83 96 extract($commentdata); … … 110 123 return $id; 111 124 } 112 125 126 /** 127 * Parses and returns comment information 128 * @param array $commentdata Contains information on the comment 129 * @return array $parseddata Parsed comment information 130 */ 113 131 function wp_filter_comment($commentdata) { 114 132 $commentdata['user_id'] = apply_filters('pre_user_id', $commentdata['user_ID']); 115 133 $commentdata['comment_agent'] = apply_filters('pre_comment_user_agent', $commentdata['comment_agent']); … … 122 140 return $commentdata; 123 141 } 124 142 143 /** 144 * Validates whether this comment is allowed to be made or not 145 * @param array $commentdata Contains information on the comment 146 * @return mixed $approved Signifies the approval status (0|1|'spam') 147 */ 125 148 function wp_allow_comment($commentdata) { 126 149 global $wpdb; 127 150 extract($commentdata); … … 171 194 return $approved; 172 195 } 173 196 174 197 /** 198 * Parses and updates an existing comment in the database 199 * @param array $commentdata Contains information on the comment 200 * @return int $success Success status (0|1) 201 */ 175 202 function wp_update_comment($commentarr) { 176 203 global $wpdb; 177 204 … … 213 240 return $rval; 214 241 } 215 242 243 /** 244 * Removes a comment from the database 245 * @param int $comment_id Id of the comment to remove 246 * @return boolean $success Success status 247 */ 216 248 function wp_delete_comment($comment_id) { 217 249 global $wpdb; 218 250 do_action('delete_comment', $comment_id); … … 230 262 return true; 231 263 } 232 264 265 /** 266 * Removes nasty characters from a URL string 267 * @param string $url 268 * @return string $cleanurl 269 */ 233 270 function clean_url( $url ) { 234 271 if ('' == $url) return $url; 235 272 $url = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $url); … … 239 276 return $url; 240 277 } 241 278 279 /** 280 * Returns the amount of comments a post has 281 * @param int $post_id The post to check, defaults to the current global $id 282 * @return int $total The number of comments the post has 283 */ 242 284 function get_comments_number( $post_id = 0 ) { 243 285 global $wpdb, $comment_count_cache, $id; 244 286 $post_id = (int) $post_id; … … 252 294 return apply_filters('get_comments_number', $comment_count_cache[$post_id]); 253 295 } 254 296 297 /** 298 * Echoes the language string for the number of comments the current global post $id has. 299 * Default language is english. 300 * @param string $zero String representing no comments 301 * @param string $one String representing 1 comment 302 * @param string $more String representing '%' comments. 303 * @param string $number Defunct. 304 */ 255 305 function comments_number( $zero = 'No Comments', $one = '1 Comment', $more = '% Comments', $number = '' ) { 256 306 global $id, $comment; 257 307 $number = get_comments_number( $id ); … … 265 315 echo apply_filters('comments_number', $blah); 266 316 } 267 317 318 /** 319 * Returns the link to the current working posts' comments 320 * @return string $postcommentslink 321 */ 268 322 function get_comments_link() { 269 323 return get_permalink() . '#comments'; 270 324 } 271 325 326 /** 327 * Returns the link to the current working comment 328 * @return string $commentlink 329 */ 272 330 function get_comment_link() { 273 331 global $comment; 274 332 return get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment->comment_ID; 275 333 } 276 334 335 /** 336 * Echoes the link to the current working posts' comments 337 */ 277 338 function comments_link( $file = '', $echo = true ) { 278 339 echo get_comments_link(); 279 340 } 280 341 342 /** 343 * Echoes the JS popup script to show a comment 344 * @param int $width Window width. Default is 400 345 * @param int $height Window height. Default is 400 346 * @param string $file The file to display. Defaults to index 347 */ 281 348 function comments_popup_script($width=400, $height=400, $file='') { 282 349 global $wpcommentspopupfile, $wptrackbackpopupfile, $wppingbackpopupfile, $wpcommentsjavascript; 283 350 … … 292 359 echo $javascript; 293 360 } 294 361 362 /** 363 * Echoes the link to the popup window of comments for the current global post $id. 364 * Default language is english. 365 * @param string $zero String representing no comments 366 * @param string $one String representing 1 comment 367 * @param string $more String representing '%' comments. 368 * @param string $CSSclass The css class to assign the link 369 * @param string $none String representing comments off 370 */ 295 371 function comments_popup_link($zero='No Comments', $one='1 Comment', $more='% Comments', $CSSclass='', $none='Comments Off') { 296 372 global $id, $wpcommentspopupfile, $wpcommentsjavascript, $post, $wpdb; 297 373 global $comment_count_cache; … … 336 412 } 337 413 } 338 414 } 339 415 /** 416 * Returns the comment id of the current global $comment 417 * @return int $commentid 418 */ 340 419 function get_comment_ID() { 341 420 global $comment; 342 421 return apply_filters('get_comment_ID', $comment->comment_ID); 343 422 } 344 423 /** 424 * Echoes the comment id of the current global $comment 425 */ 345 426 function comment_ID() { 346 427 echo get_comment_ID(); 347 428 } 348 429 /** 430 * Returns the author of the current global $comment 431 * @return string $commentauthor 432 */ 349 433 function get_comment_author() { 350 434 global $comment; 351 435 if ( empty($comment->comment_author) ) … … 354 438 $author = $comment->comment_author; 355 439 return apply_filters('get_comment_author', $author); 356 440 } 357 441 /** 442 * Echoes the author of the current global $comment 443 */ 358 444 function comment_author() { 359 445 $author = apply_filters('comment_author', get_comment_author() ); 360 446 echo $author; 361 447 } 362 448 /** 449 * Returns the email of the author of the current global $comment 450 * @return string $commentauthoremail 451 */ 363 452 function get_comment_author_email() { 364 453 global $comment; 365 454 return apply_filters('get_comment_author_email', $comment->comment_author_email); 366 455 } 367 456 /** 457 * Echoes the email of the author of the current global $comment 458 */ 368 459 function comment_author_email() { 369 460 echo apply_filters('author_email', get_comment_author_email() ); 370 461 } 371 462 463 /** 464 * Returns the html link to the url of the author of the current global $comment 465 * @return string $commentauthorurl 466 */ 372 467 function get_comment_author_link() { 373 468 global $comment; 374 469 $url = get_comment_author_url(); … … 381 476 return apply_filters('get_comment_author_link', $return); 382 477 } 383 478 479 /** 480 * Echoes the html link to the url of the author of the current global $comment 481 */ 384 482 function comment_author_link() { 385 483 echo get_comment_author_link(); 386 484 } 387 485 486 /** 487 * Returns the comment type of the current global $comment 488 * @return string $commenttype 489 */ 388 490 function get_comment_type() { 389 491 global $comment; 390 492 … … 394 496 return apply_filters('get_comment_type', $comment->comment_type); 395 497 } 396 498 499 /** 500 * Echoes the comment type of the current global $comment 501 */ 397 502 function comment_type($commenttxt = 'Comment', $trackbacktxt = 'Trackback', $pingbacktxt = 'Pingback') { 398 503 $type = get_comment_type(); 399 504 switch( $type ) { … … 408 513 } 409 514 } 410 515 516 /** 517 * Returns the url of the author of the current global $comment 518 * @return string $commenttype 519 */ 411 520 function get_comment_author_url() { 412 521 global $comment; 413 522 return apply_filters('get_comment_author_url', $comment->comment_author_url); 414 523 } 415 524 525 /** 526 * Echoes the url of the author of the current global $comment 527 */ 416 528 function comment_author_url() { 417 529 echo apply_filters('comment_url', get_comment_author_url()); 418 530 } 419 531 532 /** 533 * Echoes the html email link to the author of the current global $comment 534 */ 420 535 function comment_author_email_link($linktext='', $before='', $after='') { 421 536 global $comment; 422 537 $email = apply_filters('comment_email', $comment->comment_author_email); … … 428 543 } 429 544 } 430 545 546 /** 547 * Returns the HTML link of the url of the author of the current global $comment, 548 * encased in any pre or post text. 549 * @param string $linktext Text to put in the link. Defaults to the URL 550 * @param string $before Text to come before the link 551 * @param string $after Text to come after the link 552 * @return string $link The html link sandwiched between the $before and $after params 553 */ 431 554 function get_comment_author_url_link( $linktext = '', $before = '', $after = '' ) { 432 555 global $comment; 433 556 $url = get_comment_author_url(); … … 436 559 return apply_filters('get_comment_author_url_link', $return); 437 560 } 438 561 562 /** 563 * Echoss the HTML link of the url of the author of the current global $comment, 564 * encased in any pre or post text. 565 * @param string $linktext Text to put in the link. Defaults to the URL 566 * @param string $before Text to come before the link 567 * @param string $after Text to come after the link 568 */ 439 569 function comment_author_url_link( $linktext = '', $before = '', $after = '' ) { 440 570 echo get_comment_author_url_link( $linktext, $before, $after ); 441 571 } 442 572 /** 573 * Returns the IP address of the author of the current global $comment 574 * @return string $ipaddress 575 */ 443 576 function get_comment_author_IP() { 444 577 global $comment; 445 578 return apply_filters('get_comment_author_IP', $comment->comment_author_IP); 446 579 } 447 580 /** 581 * Echoes the IP address of the author of the current global $comment 582 */ 448 583 function comment_author_IP() { 449 584 echo get_comment_author_IP(); 450 585 } 451 586 /** 587 * Returns the text of the current global $comment 588 * @return string $text 589 */ 452 590 function get_comment_text() { 453 591 global $comment; 454 592 return apply_filters('get_comment_text', $comment->comment_content); 455 593 } 456 594 /** 595 * Echoes the text of the current global $comment 596 */ 457 597 function comment_text() { 458 598 echo apply_filters('comment_text', get_comment_text() ); 459 599 } 460 600 /** 601 * Returns the excerpt of the current global $comment 602 * @return string $excerpt 603 */ 461 604 function get_comment_excerpt() { 462 605 global $comment; 463 606 $comment_text = strip_tags($comment->comment_content); … … 476 619 $excerpt .= ($use_dotdotdot) ? '...' : ''; 477 620 return apply_filters('get_comment_excerpt', $excerpt); 478 621 } 479 622 /** 623 * Echoes the excerpt of the current global $comment 624 */ 480 625 function comment_excerpt() { 481 626 echo apply_filters('comment_excerpt', get_comment_excerpt() ); 482 627 } 483 628 /** 629 * Returns the comment date of the current global $comment 630 * @param string $d The format of the date (defaults to user's config) 631 * @return string $date The formatted date 632 */ 484 633 function get_comment_date( $d = '' ) { 485 634 global $comment; 486 635 if ( '' == $d ) … … 489 638 $date = mysql2date($d, $comment->comment_date); 490 639 return apply_filters('get_comment_date', $date); 491 640 } 492 641 /** 642 * Echoes the comment date of the current global $comment 643 * @param string $d The format of the date (defaults to user's config) 644 */ 493 645 function comment_date( $d = '' ) { 494 646 echo get_comment_date( $d ); 495 647 } 496 648 /** 649 * Returns the comment time of the current global $comment 650 * @param string $d The format of the time (defaults to user's config) 651 * @param boolean $gmt Whether to put the date into GMT 652 * @return string $time The formatted time 653 */ 497 654 function get_comment_time( $d = '', $gmt = false ) { 498 655 global $comment; 499 656 $comment_date = $gmt? $comment->comment_date_gmt : $comment->comment_date; … … 503 660 $date = mysql2date($d, $comment_date); 504 661 return apply_filters('get_comment_time', $date); 505 662 } 506 663 /** 664 * Echoes the comment time of the current global $comment 665 * @param string $d The format of the time (defaults to user's config) 666 */ 507 667 function comment_time( $d = '' ) { 508 668 echo get_comment_time($d); 509 669 } 510 670 /** 671 * Returns the current global $post's trackback URL 672 * @return string $url 673 */ 511 674 function get_trackback_url() { 512 675 global $id; 513 676 $tb_url = get_settings('siteurl') . '/wp-trackback.php?p=' . $id; … … 517 680 518 681 return $tb_url; 519 682 } 683 /** 684 * Echoes or returns the current global $post's trackback URL 685 * @param boolean $display Whether to display or echo 686 * @return mixed $ret void if echoing, string URL if returning 687 */ 520 688 function trackback_url( $display = true ) { 521 689 if ( $display) 522 690 echo get_trackback_url(); 523 691 else 524 692 return get_trackback_url(); 525 693 } 526 694 /** 695 * Generates and echoes the RDF for the trackback information of current global $post 696 * @param int $timezone 697 */ 527 698 function trackback_rdf($timezone = 0) { 528 699 global $id; 529 700 if (!stristr($_SERVER['HTTP_USER_AGENT'], 'W3C_Validator')) { … … 541 712 echo '</rdf:RDF>'; 542 713 } 543 714 } 544 715 /** 716 * Returns whether the current global $post is open for comments 717 * @return boolean $open 718 */ 545 719 function comments_open() { 546 720 global $post; 547 721 if ( 'open' == $post->comment_status ) … … 549 723 else 550 724 return false; 551 725 } 552 726 /** 727 * Returns whether the current global $post is open for pings 728 * @return boolean $open 729 */ 553 730 function pings_open() { 554 731 global $post; 555 732 if ( 'open' == $post->ping_status ) … … 559 736 } 560 737 561 738 // Non-template functions 562 739 /** 740 * Returns the date the last comment was modified 741 * @param string $timezone Timezone to apply date to ('server'|'blog'|'gmt') 742 * @return string $date 743 */ 563 744 function get_lastcommentmodified($timezone = 'server') { 564 745 global $cache_lastcommentmodified, $pagenow, $wpdb; 565 746 $add_seconds_blog = get_settings('gmt_offset') * 3600; … … 583 764 } 584 765 return $lastcommentmodified; 585 766 } 586 767 /** 768 * Returns an array of comment data about comment $comment_ID 769 * @param int $comment_ID 770 * @param int $no_cache Whether info is in global $postc object or not 771 * @param boolean $include_unapparoved Whether to retrieve unapproved comments 772 * @return mixed $ret array of information on success, false on failure 773 */ 587 774 function get_commentdata( $comment_ID, $no_cache = 0, $include_unapproved = false ) { // less flexible, but saves DB queries 588 775 global $postc, $id, $commentdata, $wpdb; 589 776 if ($no_cache) { … … 607 794 } 608 795 return $myrow; 609 796 } 610 797 /** 798 * Pings back the links found in a post 799 * @param string $content Content of post 800 * @param int $post_ID The id of the post 801 */ 611 802 function pingback($content, $post_ID) { 612 803 global $wp_version, $wpdb; 613 804 include_once (ABSPATH . WPINC . '/class-IXR.php'); … … 687 878 debug_fwrite($log, "\nEND: ".time()."\n****************************\n"); 688 879 debug_fclose($log); 689 880 } 690 881 /** 882 * Finds a pingback server URI based on the given URL 883 * @param string $url URL to ping 884 * @param int $timeout_bytes Number of bytes to timeout at. Prevents big file downloads, default is 2048. 885 * @return mixed $ret False on failure, string containing URI on success. 886 */ 691 887 function discover_pingback_server_uri($url, $timeout_bytes = 2048) { 692 888 global $wp_version; 693 889 … … 777 973 // We didn't find anything. 778 974 return false; 779 975 } 780 976 /** 977 * Checks whether an attachment is hosted locally 978 * @param string $url URL of the attachment 979 * @return boolean $is_local Whether the attachment is local 980 */ 781 981 function is_local_attachment($url) { 782 982 if ( !strstr($url, get_bloginfo('home') ) ) 783 983 return false; … … 790 990 } 791 991 return false; 792 992 } 793 993 /** 994 * Sets the status of comment $comment_id to $comment_status 995 * @param int $comment_id 996 * @param string $comment_status 'hold' | 'approve' | 'spam' | 'delete' 997 * @return boolean $success Whether the operation performed successfully 998 */ 794 999 function wp_set_comment_status($comment_id, $comment_status) { 795 1000 global $wpdb; 796 1001 … … 824 1029 return false; 825 1030 } 826 1031 } 827 1032 /** 1033 * Returns the status of a comment $comment_id 1034 * @param int $comment_id 1035 * @return mixed $status 'deleted' | 'approved' | 'unapproved' | 'spam' | false 1036 */ 828 1037 function wp_get_comment_status($comment_id) { 829 1038 global $wpdb; 830 1039 … … 841 1050 return false; 842 1051 } 843 1052 } 844 1053 /** 1054 * Checks whether a comment passes internal checks to be allowed to add 1055 * @param string $author 1056 * @param string $email 1057 * @param string $url 1058 * @param string $comment 1059 * @param string $user_ip 1060 * @param string $user_agent 1061 * @param string $comment_type 'comment' | 'trackback' | 'pingback' 1062 * @return boolean $allowed 1063 */ 845 1064 function check_comment($author, $email, $url, $comment, $user_ip, $user_agent, $comment_type) { 846 1065 global $wpdb; 847 1066 … … 899 1118 900 1119 return true; 901 1120 } 902 1121 /** 1122 * Returns the approved comments for post $post_id 1123 * @param int $post_id 1124 * @return array $comments The approved comments (objects) 1125 */ 903 1126 function get_approved_comments($post_id) { 904 1127 global $wpdb; 905 1128 return $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = $post_id AND comment_approved = '1' ORDER BY comment_date");
