Ticket #2648: comment-functions.diff

File comment-functions.diff, 16.7 KB (added by Pita, 6 years ago)

Preliminary patch

  • comment-functions.php

     
    22 
    33// Template functions 
    44 
     5/** 
     6 * Loads the comment template specified in $file 
     7 * @param string $file The file to load (default '/comments.php') 
     8 */ 
    59function comments_template( $file = '/comments.php' ) { 
    610        global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity; 
    711 
     
    4448        endif; 
    4549} 
    4650 
     51/** 
     52 * Parses and adds a new comment to the database 
     53 * @param array $commentdata Contains information on the comment 
     54 */ 
    4755function wp_new_comment( $commentdata ) { 
    4856        $commentdata = apply_filters('preprocess_comment', $commentdata); 
    4957 
     
    7886        return $comment_ID; 
    7987} 
    8088 
     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 */ 
    8194function wp_insert_comment($commentdata) { 
    8295        global $wpdb; 
    8396        extract($commentdata); 
     
    110123        return $id; 
    111124} 
    112125 
     126/** 
     127 * Parses and returns comment information 
     128 * @param array $commentdata Contains information on the comment 
     129 * @return array $parseddata Parsed comment information 
     130 */ 
    113131function wp_filter_comment($commentdata) { 
    114132        $commentdata['user_id']              = apply_filters('pre_user_id', $commentdata['user_ID']); 
    115133        $commentdata['comment_agent']        = apply_filters('pre_comment_user_agent', $commentdata['comment_agent']); 
     
    122140        return $commentdata; 
    123141} 
    124142 
     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 */ 
    125148function wp_allow_comment($commentdata) { 
    126149        global $wpdb; 
    127150        extract($commentdata); 
     
    171194        return $approved; 
    172195} 
    173196 
    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 */ 
    175202function wp_update_comment($commentarr) { 
    176203        global $wpdb; 
    177204 
     
    213240        return $rval; 
    214241} 
    215242 
     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 */ 
    216248function wp_delete_comment($comment_id) { 
    217249        global $wpdb; 
    218250        do_action('delete_comment', $comment_id); 
     
    230262        return true; 
    231263} 
    232264 
     265/** 
     266 * Removes nasty characters from a URL string 
     267 * @param string $url 
     268 * @return string $cleanurl 
     269 */ 
    233270function clean_url( $url ) { 
    234271        if ('' == $url) return $url; 
    235272        $url = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $url); 
     
    239276        return $url; 
    240277} 
    241278 
     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 */ 
    242284function get_comments_number( $post_id = 0 ) { 
    243285        global $wpdb, $comment_count_cache, $id; 
    244286        $post_id = (int) $post_id; 
     
    252294        return apply_filters('get_comments_number', $comment_count_cache[$post_id]); 
    253295} 
    254296 
     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 */ 
    255305function comments_number( $zero = 'No Comments', $one = '1 Comment', $more = '% Comments', $number = '' ) { 
    256306        global $id, $comment; 
    257307        $number = get_comments_number( $id ); 
     
    265315        echo apply_filters('comments_number', $blah); 
    266316} 
    267317 
     318/** 
     319 * Returns the link to the current working posts' comments 
     320 * @return string $postcommentslink 
     321 */ 
    268322function get_comments_link() { 
    269323        return get_permalink() . '#comments'; 
    270324} 
    271325 
     326/** 
     327 * Returns the link to the current working comment 
     328 * @return string $commentlink 
     329 */ 
    272330function get_comment_link() { 
    273331        global $comment; 
    274332        return get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment->comment_ID; 
    275333} 
    276334 
     335/** 
     336 * Echoes the link to the current working posts' comments 
     337 */ 
    277338function comments_link( $file = '', $echo = true ) { 
    278339    echo get_comments_link(); 
    279340} 
    280341 
     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 */ 
    281348function comments_popup_script($width=400, $height=400, $file='') { 
    282349    global $wpcommentspopupfile, $wptrackbackpopupfile, $wppingbackpopupfile, $wpcommentsjavascript; 
    283350 
     
    292359    echo $javascript; 
    293360} 
    294361 
     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 */ 
    295371function comments_popup_link($zero='No Comments', $one='1 Comment', $more='% Comments', $CSSclass='', $none='Comments Off') { 
    296372        global $id, $wpcommentspopupfile, $wpcommentsjavascript, $post, $wpdb; 
    297373        global $comment_count_cache; 
     
    336412        } 
    337413        } 
    338414} 
    339  
     415/** 
     416 * Returns the comment id of the current global $comment 
     417 * @return int $commentid 
     418 */ 
    340419function get_comment_ID() { 
    341420        global $comment; 
    342421        return apply_filters('get_comment_ID', $comment->comment_ID); 
    343422} 
    344  
     423/** 
     424 * Echoes the comment id of the current global $comment 
     425 */ 
    345426function comment_ID() { 
    346427        echo get_comment_ID(); 
    347428} 
    348  
     429/** 
     430 * Returns the author of the current global $comment 
     431 * @return string $commentauthor 
     432 */ 
    349433function get_comment_author() { 
    350434        global $comment; 
    351435        if ( empty($comment->comment_author) ) 
     
    354438                $author = $comment->comment_author; 
    355439        return apply_filters('get_comment_author', $author); 
    356440} 
    357  
     441/** 
     442 * Echoes the author of the current global $comment 
     443 */ 
    358444function comment_author() { 
    359445        $author = apply_filters('comment_author', get_comment_author() ); 
    360446        echo $author; 
    361447} 
    362  
     448/** 
     449 * Returns the email of the author of the current global $comment 
     450 * @return string $commentauthoremail 
     451 */ 
    363452function get_comment_author_email() { 
    364453        global $comment; 
    365454        return apply_filters('get_comment_author_email', $comment->comment_author_email); 
    366455} 
    367  
     456/** 
     457 * Echoes the email of the author of the current global $comment 
     458 */ 
    368459function comment_author_email() { 
    369460        echo apply_filters('author_email', get_comment_author_email() ); 
    370461} 
    371462 
     463/** 
     464 * Returns the html link to the url of the author of the current global $comment 
     465 * @return string $commentauthorurl 
     466 */ 
    372467function get_comment_author_link() { 
    373468        global $comment; 
    374469        $url    = get_comment_author_url(); 
     
    381476        return apply_filters('get_comment_author_link', $return); 
    382477} 
    383478 
     479/** 
     480 * Echoes the html link to the url of the author of the current global $comment 
     481 */ 
    384482function comment_author_link() { 
    385483        echo get_comment_author_link(); 
    386484} 
    387485 
     486/** 
     487 * Returns the comment type of the current global $comment 
     488 * @return string $commenttype 
     489 */ 
    388490function get_comment_type() { 
    389491        global $comment; 
    390492 
     
    394496        return apply_filters('get_comment_type', $comment->comment_type); 
    395497} 
    396498 
     499/** 
     500 * Echoes the comment type of the current global $comment 
     501 */ 
    397502function comment_type($commenttxt = 'Comment', $trackbacktxt = 'Trackback', $pingbacktxt = 'Pingback') { 
    398503        $type = get_comment_type(); 
    399504        switch( $type ) { 
     
    408513        } 
    409514} 
    410515 
     516/** 
     517 * Returns the url of the author of the current global $comment 
     518 * @return string $commenttype 
     519 */ 
    411520function get_comment_author_url() { 
    412521        global $comment; 
    413522        return apply_filters('get_comment_author_url', $comment->comment_author_url); 
    414523} 
    415524 
     525/** 
     526 * Echoes the url of the author of the current global $comment 
     527 */ 
    416528function comment_author_url() { 
    417529        echo apply_filters('comment_url', get_comment_author_url()); 
    418530} 
    419531 
     532/** 
     533 * Echoes the html email link to the author of the current global $comment 
     534 */ 
    420535function comment_author_email_link($linktext='', $before='', $after='') { 
    421536        global $comment; 
    422537        $email = apply_filters('comment_email', $comment->comment_author_email); 
     
    428543        } 
    429544} 
    430545 
     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 */ 
    431554function get_comment_author_url_link( $linktext = '', $before = '', $after = '' ) { 
    432555        global $comment; 
    433556        $url = get_comment_author_url(); 
     
    436559        return apply_filters('get_comment_author_url_link', $return); 
    437560} 
    438561 
     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 */ 
    439569function comment_author_url_link( $linktext = '', $before = '', $after = '' ) { 
    440570        echo get_comment_author_url_link( $linktext, $before, $after ); 
    441571} 
    442  
     572/** 
     573 * Returns the IP address of the author of the current global $comment 
     574 * @return string $ipaddress 
     575 */ 
    443576function get_comment_author_IP() { 
    444577        global $comment; 
    445578        return apply_filters('get_comment_author_IP', $comment->comment_author_IP); 
    446579} 
    447  
     580/** 
     581 * Echoes the IP address of the author of the current global $comment 
     582 */ 
    448583function comment_author_IP() { 
    449584        echo get_comment_author_IP(); 
    450585} 
    451  
     586/** 
     587 * Returns the text of the current global $comment 
     588 * @return string $text 
     589 */ 
    452590function get_comment_text() { 
    453591        global $comment; 
    454592        return apply_filters('get_comment_text', $comment->comment_content); 
    455593} 
    456  
     594/** 
     595 * Echoes the text of the current global $comment 
     596 */ 
    457597function comment_text() { 
    458598        echo apply_filters('comment_text', get_comment_text() ); 
    459599} 
    460  
     600/** 
     601 * Returns the excerpt of the current global $comment 
     602 * @return string $excerpt 
     603 */ 
    461604function get_comment_excerpt() { 
    462605        global $comment; 
    463606        $comment_text = strip_tags($comment->comment_content); 
     
    476619        $excerpt .= ($use_dotdotdot) ? '...' : ''; 
    477620        return apply_filters('get_comment_excerpt', $excerpt); 
    478621} 
    479  
     622/** 
     623 * Echoes the excerpt of the current global $comment 
     624 */ 
    480625function comment_excerpt() { 
    481626        echo apply_filters('comment_excerpt', get_comment_excerpt() ); 
    482627} 
    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 */ 
    484633function get_comment_date( $d = '' ) { 
    485634        global $comment; 
    486635        if ( '' == $d ) 
     
    489638                $date = mysql2date($d, $comment->comment_date); 
    490639        return apply_filters('get_comment_date', $date); 
    491640} 
    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 */ 
    493645function comment_date( $d = '' ) { 
    494646        echo get_comment_date( $d ); 
    495647} 
    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 */ 
    497654function get_comment_time( $d = '', $gmt = false ) { 
    498655        global $comment; 
    499656        $comment_date = $gmt? $comment->comment_date_gmt : $comment->comment_date; 
     
    503660                $date = mysql2date($d, $comment_date); 
    504661        return apply_filters('get_comment_time', $date); 
    505662} 
    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 */ 
    507667function comment_time( $d = '' ) { 
    508668        echo get_comment_time($d); 
    509669} 
    510  
     670/** 
     671 * Returns the current global $post's trackback URL 
     672 * @return string $url 
     673 */ 
    511674function get_trackback_url() { 
    512675        global $id; 
    513676        $tb_url = get_settings('siteurl') . '/wp-trackback.php?p=' . $id; 
     
    517680 
    518681        return $tb_url; 
    519682} 
     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 */ 
    520688function trackback_url( $display = true ) { 
    521689        if ( $display) 
    522690                echo get_trackback_url(); 
    523691        else 
    524692                return get_trackback_url(); 
    525693} 
    526  
     694/** 
     695 * Generates and echoes the RDF for the trackback information of current global $post 
     696 * @param int $timezone 
     697 */ 
    527698function trackback_rdf($timezone = 0) { 
    528699        global $id; 
    529700        if (!stristr($_SERVER['HTTP_USER_AGENT'], 'W3C_Validator')) { 
     
    541712        echo '</rdf:RDF>'; 
    542713        } 
    543714} 
    544  
     715/** 
     716 * Returns whether the current global $post is open for comments 
     717 * @return boolean $open 
     718 */ 
    545719function comments_open() { 
    546720        global $post; 
    547721        if ( 'open' == $post->comment_status ) 
     
    549723        else 
    550724                return false; 
    551725} 
    552  
     726/** 
     727 * Returns whether the current global $post is open for pings 
     728 * @return boolean $open 
     729 */ 
    553730function pings_open() { 
    554731        global $post; 
    555732        if ( 'open' == $post->ping_status )  
     
    559736} 
    560737 
    561738// 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 */ 
    563744function get_lastcommentmodified($timezone = 'server') { 
    564745        global $cache_lastcommentmodified, $pagenow, $wpdb; 
    565746        $add_seconds_blog = get_settings('gmt_offset') * 3600; 
     
    583764        } 
    584765        return $lastcommentmodified; 
    585766} 
    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 */ 
    587774function get_commentdata( $comment_ID, $no_cache = 0, $include_unapproved = false ) { // less flexible, but saves DB queries 
    588775        global $postc, $id, $commentdata, $wpdb; 
    589776        if ($no_cache) { 
     
    607794        } 
    608795        return $myrow; 
    609796} 
    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 */ 
    611802function pingback($content, $post_ID) { 
    612803        global $wp_version, $wpdb; 
    613804        include_once (ABSPATH . WPINC . '/class-IXR.php'); 
     
    687878        debug_fwrite($log, "\nEND: ".time()."\n****************************\n"); 
    688879        debug_fclose($log); 
    689880} 
    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 */ 
    691887function discover_pingback_server_uri($url, $timeout_bytes = 2048) { 
    692888        global $wp_version; 
    693889 
     
    777973        // We didn't find anything. 
    778974        return false; 
    779975} 
    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 */ 
    781981function is_local_attachment($url) { 
    782982        if ( !strstr($url, get_bloginfo('home') ) ) 
    783983                return false; 
     
    790990        } 
    791991        return false; 
    792992} 
    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 */ 
    794999function wp_set_comment_status($comment_id, $comment_status) { 
    7951000    global $wpdb; 
    7961001 
     
    8241029                return false; 
    8251030    } 
    8261031} 
    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 */ 
    8281037function wp_get_comment_status($comment_id) { 
    8291038        global $wpdb; 
    8301039 
     
    8411050                return false; 
    8421051        } 
    8431052} 
    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 */ 
    8451064function check_comment($author, $email, $url, $comment, $user_ip, $user_agent, $comment_type) { 
    8461065        global $wpdb; 
    8471066 
     
    8991118 
    9001119        return true; 
    9011120} 
    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 */ 
    9031126function get_approved_comments($post_id) { 
    9041127        global $wpdb; 
    9051128        return $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = $post_id AND comment_approved = '1' ORDER BY comment_date");