WordPress.org

Make WordPress Core

Changeset 6495


Ignore:
Timestamp:
12/26/2007 05:18:13 PM (14 years ago)
Author:
ryan
Message:

phpdoc for comment-template.php from darkdragon. fixes #5528

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/comment-template.php

    r6372 r6495  
    11<?php
    2 /*
    3  * Comment template functions.
    4  */
    5 
     2/**
     3 * Comment template functions
     4 *
     5 * These functions are meant to live inside of the WordPress loop.
     6 *
     7 * @package WordPress
     8 * @subpackage Template
     9 */
     10
     11/**
     12 * get_comment_author() - Retrieve the author of the current comment
     13 *
     14 * If the comment has an empty comment_author field, then 'Anonymous' person
     15 * is assumed.
     16 *
     17 * @since 1.5
     18 * @uses apply_filters() Calls 'get_comment_author' hook on the comment author
     19 *
     20 * @return string The comment author
     21 */
    622function get_comment_author() {
    723    global $comment;
     
    1329}
    1430
     31/**
     32 * comment_author() - Displays the author of the current comment
     33 *
     34 * @since 0.71
     35 * @uses apply_filters() Calls 'comment_author' on comment author before displaying
     36 */
    1537function comment_author() {
    1638    $author = apply_filters('comment_author', get_comment_author() );
     
    1840}
    1941
     42/**
     43 * get_comment_author_email() - Retrieve the email of the author of the current comment
     44 *
     45 * @since 1.5
     46 * @uses apply_filters() Calls the 'get_comment_author_email' hook on the comment author email
     47 * @uses $comment
     48 *
     49 * @return string The current comment author's email
     50 */
    2051function get_comment_author_email() {
    2152    global $comment;
     
    2354}
    2455
     56/**
     57 * comment_author_email() - Display the email of the author of the current global $comment
     58 *
     59 * Care should be taken to protect the email address and assure that email harvesters
     60 * do not capture your commentors' email address. Most assume that their email address will
     61 * not appear in raw form on the blog. Doing so will enable anyone, including those that
     62 * people don't want to get the email address and use it for their own means good and bad.
     63 *
     64 * @since 0.71
     65 * @uses apply_filters() Calls 'author_email' hook on the author email
     66 */
    2567function comment_author_email() {
    2668    echo apply_filters('author_email', get_comment_author_email() );
    2769}
    2870
     71/**
     72 * comment_author_email_link() - Display the html email link to the author of the current comment
     73 *
     74 * Care should be taken to protect the email address and assure that email harvesters
     75 * do not capture your commentors' email address. Most assume that their email address will
     76 * not appear in raw form on the blog. Doing so will enable anyone, including those that
     77 * people don't want to get the email address and use it for their own means good and bad.
     78 *
     79 * @since 0.71
     80 * @uses apply_filters() Calls 'comment_email' hook for the display of the comment author's email
     81 * @global object $comment The current Comment row object
     82 *
     83 * @param string $linktext The text to display instead of the comment author's email address
     84 * @param string $before The text or HTML to display before the email link.
     85 * @param string $after The text or HTML to display after the email link.
     86 */
    2987function comment_author_email_link($linktext='', $before='', $after='') {
    3088    global $comment;
     
    3896}
    3997
     98/**
     99 * get_comment_author_link() - Retrieve the html link to the url of the author of the current comment
     100 *
     101 * @since 1.5
     102 * @uses apply_filters() Calls 'get_comment_author_link' hook on the complete link HTML or author
     103 *
     104 * @return string Comment Author name or HTML link for author's URL
     105 */
    40106function get_comment_author_link() {
     107    /** @todo Only call these functions when they are needed. Include in if... else blocks */
    41108    $url    = get_comment_author_url();
    42109    $author = get_comment_author();
     
    49116}
    50117
     118/**
     119 * comment_author_link() - Display the html link to the url of the author of the current comment
     120 *
     121 * @since 0.71
     122 * @see get_comment_author_link() Echos result
     123 */
    51124function comment_author_link() {
    52125    echo get_comment_author_link();
    53126}
    54127
     128/**
     129 * get_comment_author_IP() - Retrieve the IP address of the author of the current comment
     130 *
     131 * @since 1.5
     132 * @uses $comment
     133 * @uses apply_filters()
     134 *
     135 * @return unknown
     136 */
    55137function get_comment_author_IP() {
    56138    global $comment;
     
    58140}
    59141
     142/**
     143 * comment_author_IP() - Displays the IP address of the author of the current comment
     144 *
     145 * @since 0.71
     146 * @see get_comment_author_IP() Echos Result
     147 */
    60148function comment_author_IP() {
    61149    echo get_comment_author_IP();
    62150}
    63151
     152/**
     153 * get_comment_author_url() - Returns the url of the author of the current comment
     154 *
     155 * @since 1.5
     156 * @uses apply_filters() Calls 'get_comment_author_url' hook on the comment author's URL
     157 *
     158 * @return string
     159 */
    64160function get_comment_author_url() {
    65161    global $comment;
     
    67163}
    68164
     165/**
     166 * comment_author_url() - Display the url of the author of the current comment
     167 *
     168 * @since 0.71
     169 * @uses apply_filters()
     170 * @uses get_comment_author_url() Retrieves the comment author's URL
     171 */
    69172function comment_author_url() {
    70173    echo apply_filters('comment_url', get_comment_author_url());
    71174}
    72175
     176/**
     177 * get_comment_author_url_link() - Retrieves the HTML link of the url of the author of the current comment
     178 *
     179 * $linktext parameter is only used if the URL does not exist for the comment author. If the URL does
     180 * exist then the URL will be used and the $linktext will be ignored.
     181 *
     182 * Encapsulate the HTML link between the $before and $after. So it will appear in the order of $before,
     183 * link, and finally $after.
     184 *
     185 * @since 1.5
     186 * @uses apply_filters() Calls the 'get_comment_author_url_link' on the complete HTML before returning.
     187 *
     188 * @param string $linktext The text to display instead of the comment author's email address
     189 * @param string $before The text or HTML to display before the email link.
     190 * @param string $after The text or HTML to display after the email link.
     191 * @return string The HTML link between the $before and $after parameters
     192 */
    73193function get_comment_author_url_link( $linktext = '', $before = '', $after = '' ) {
    74194    $url = get_comment_author_url();
     
    82202}
    83203
     204/**
     205 * comment_author_url_link() - Displays the HTML link of the url of the author of the current comment
     206 *
     207 * @since 0.71
     208 * @see get_comment_author_url_link() Echos result
     209 *
     210 * @param string $linktext The text to display instead of the comment author's email address
     211 * @param string $before The text or HTML to display before the email link.
     212 * @param string $after The text or HTML to display after the email link.
     213 */
    84214function comment_author_url_link( $linktext = '', $before = '', $after = '' ) {
    85215    echo get_comment_author_url_link( $linktext, $before, $after );
    86216}
    87217
     218/**
     219 * get_comment_date() - Retrieve the comment date of the current comment
     220 *
     221 * @since 1.5
     222 * @uses apply_filters() Calls 'get_comment_date' hook with the formated date and the $d parameter respectively
     223 * @uses $comment
     224 *
     225 * @param string $d The format of the date (defaults to user's config)
     226 * @return string The comment's date
     227 */
    88228function get_comment_date( $d = '' ) {
    89229    global $comment;
     
    95235}
    96236
     237/**
     238 * comment_date() - Display the comment date of the current comment
     239 *
     240 * @since 0.71
     241 *
     242 * @param string $d The format of the date (defaults to user's config)
     243 */
    97244function comment_date( $d = '' ) {
    98245    echo get_comment_date( $d );
    99246}
    100247
     248/**
     249 * get_comment_excerpt() - Retrieve the excerpt of the current comment
     250 *
     251 * Will cut each word and only output the first 20 words with '...' at the end.
     252 * If the word count is less than 20, then no truncating is done and no '...'
     253 * will appear.
     254 *
     255 * @since 1.5
     256 * @uses $comment
     257 * @uses apply_filters() Calls 'get_comment_excerpt' on truncated comment
     258 *
     259 * @return string The maybe truncated comment with 20 words or less
     260 */
    101261function get_comment_excerpt() {
    102262    global $comment;
     
    118278}
    119279
     280/**
     281 * comment_excerpt() - Returns the excerpt of the current comment
     282 *
     283 * @since 1.2
     284 * @uses apply_filters() Calls 'comment_excerpt' hook before displaying excerpt
     285 */
    120286function comment_excerpt() {
    121287    echo apply_filters('comment_excerpt', get_comment_excerpt() );
    122288}
    123289
     290/**
     291 * get_comment_ID() - Retrieve the comment id of the current comment
     292 *
     293 * @since 1.5
     294 * @uses $comment
     295 * @uses apply_filters() Calls the 'get_comment_ID' hook for the comment ID
     296 *
     297 * @return int The comment ID
     298 */
    124299function get_comment_ID() {
    125300    global $comment;
     
    127302}
    128303
     304/**
     305 * comment_ID() - Displays the comment id of the current comment
     306 *
     307 * @since 0.71
     308 * @see get_comment_ID() Echos Result
     309 */
    129310function comment_ID() {
    130311    echo get_comment_ID();
    131312}
    132313
     314/**
     315 * get_comment_link() - Retrieve the link to the current comment
     316 *
     317 * @since 1.5
     318 * @uses $comment
     319 *
     320 * @return string The permalink to the current comment
     321 */
    133322function get_comment_link() {
    134323    global $comment;
     
    136325}
    137326
     327/**
     328 * get_comments_link() - Retrieves the link to the current post comments
     329 *
     330 * @since 1.5
     331 *
     332 * @return string The link to the comments
     333 */
    138334function get_comments_link() {
    139335    return get_permalink() . '#comments';
    140336}
    141337
     338/**
     339 * comments_link() - Displays the link to the current post comments
     340 *
     341 * @since 0.71
     342 *
     343 * @param string $file Not Used
     344 * @param bool $echo Not Used
     345 */
    142346function comments_link( $file = '', $echo = true ) {
    143         echo get_comments_link();
    144 }
    145 
     347    echo get_comments_link();
     348}
     349
     350/**
     351 * get_comments_number() - Retrieve the amount of comments a post has
     352 *
     353 * @since 1.5
     354 * @uses apply_filters() Calls the 'get_comments_number' hook on the number of comments
     355 *
     356 * @param int $post_id The Post ID
     357 * @return int The number of comments a post has
     358 */
    146359function get_comments_number( $post_id = 0 ) {
    147360    $post_id = (int) $post_id;
     
    159372}
    160373
     374/**
     375 * comments_number() - Display the language string for the number of comments the current post has
     376 *
     377 * @since 0.71
     378 * @uses $id
     379 * @uses apply_filters() Calls the 'comments_number' hook on the output and number of comments respectively.
     380 *
     381 * @param string $zero Text for no comments
     382 * @param string $one Text for one comment
     383 * @param string $more Text for more than one comment
     384 * @param string $deprecated Not used.
     385 */
    161386function comments_number( $zero = false, $one = false, $more = false, $deprecated = '' ) {
    162387    global $id;
     
    173398}
    174399
     400/**
     401 * get_comment_text() - Retrieve the text of the current comment
     402 *
     403 * @since 1.5
     404 * @uses $comment
     405 *
     406 * @return string The comment content
     407 */
    175408function get_comment_text() {
    176409    global $comment;
     
    178411}
    179412
     413/**
     414 * comment_text() - Displays the text of the current comment
     415 *
     416 * @since 0.71
     417 * @uses apply_filters() Passes the comment content through the 'comment_text' hook before display
     418 * @uses get_comment_text() Gets the comment content
     419 */
    180420function comment_text() {
    181421    echo apply_filters('comment_text', get_comment_text() );
    182422}
    183423
     424/**
     425 * get_comment_time() - Retrieve the comment time of the current comment
     426 *
     427 * @since 1.5
     428 * @uses $comment
     429 * @uses apply_filter() Calls 'get_comment_time' hook with the formatted time, the $d parameter, and $gmt parameter passed.
     430 *
     431 * @param string $d Optional. The format of the time (defaults to user's config)
     432 * @param bool $gmt Whether to use the GMT date
     433 * @return string The formatted time
     434 */
    184435function get_comment_time( $d = '', $gmt = false ) {
    185436    global $comment;
     
    192443}
    193444
     445/**
     446 * comment_time() - Display the comment time of the current comment
     447 *
     448 * @since 0.71
     449 *
     450 * @param string $d Optional. The format of the time (defaults to user's config)
     451 */
    194452function comment_time( $d = '' ) {
    195453    echo get_comment_time($d);
    196454}
    197455
     456/**
     457 * get_comment_type() - Retrieve the comment type of the current comment
     458 *
     459 * @since 1.5
     460 * @uses $comment
     461 * @uses apply_filters() Calls the 'get_comment_type' hook on the comment type
     462 *
     463 * @return string The comment type
     464 */
    198465function get_comment_type() {
    199466    global $comment;
     
    205472}
    206473
     474/**
     475 * comment_type() - Display the comment type of the current comment
     476 *
     477 * @since 0.71
     478 *
     479 * @param string $commenttxt The string to display for comment type
     480 * @param string $trackbacktxt The string to display for trackback type
     481 * @param string $pingbacktxt The string to display for pingback type
     482 */
    207483function comment_type($commenttxt = 'Comment', $trackbacktxt = 'Trackback', $pingbacktxt = 'Pingback') {
    208484    $type = get_comment_type();
     
    219495}
    220496
     497/**
     498 * get_trackback_url() - Retrieve The current post's trackback URL
     499 *
     500 * There is a check to see if permalink's have been enabled and if so, will retrieve
     501 * the pretty path. If permalinks weren't enabled, the ID of the current post is used
     502 * and appended to the correct page to go to.
     503 *
     504 * @since 1.5
     505 * @uses apply_filters() Calls 'trackback_url' on the resulting trackback URL
     506 * @uses $id
     507 *
     508 * @return string The trackback URL after being filtered
     509 */
    221510function get_trackback_url() {
    222511    global $id;
     
    229518}
    230519
    231 function trackback_url($deprecated = true) { // remove backwards compat in 2.4
     520/**
     521 * trackback_url() - Displays the current post's trackback URL
     522 *
     523 * @since 0.71
     524 * @uses get_trackback_url() Gets the trackback url for the current post
     525 *
     526 * @param bool $deprecated Remove backwards compat in 2.4
     527 * @return void|string Should only be used to echo the trackback URL, use get_trackback_url() for the result instead.
     528 */
     529function trackback_url($deprecated = true) {
    232530    if ($deprecated) echo get_trackback_url();
    233531    else return get_trackback_url();
    234532}
    235533
     534/**
     535 * trackback_rdf() - Generates and displays the RDF for the trackback information of current post
     536 *
     537 * @since 0.71
     538 *
     539 * @param int $timezone Not used
     540 */
    236541function trackback_rdf($timezone = 0) {
    237542    if (stripos($_SERVER['HTTP_USER_AGENT'], 'W3C_Validator') === false) {
     
    251556}
    252557
     558/**
     559 * comments_open() - Whether the current post is open for comments
     560 *
     561 * @since 1.5
     562 * @uses $post
     563 *
     564 * @return bool True if the comments are open
     565 */
    253566function comments_open() {
    254567    global $post;
     
    259572}
    260573
     574/**
     575 * pings_open() - Whether the current post is open for pings
     576 *
     577 * @since 1.5
     578 * @uses $post
     579 *
     580 * @return bool True if pings are accepted
     581 */
    261582function pings_open() {
    262583    global $post;
     
    267588}
    268589
     590/**
     591 * wp_comment_form_unfiltered_html_nonce() - Displays form token for unfiltered comments
     592 *
     593 * Will only display nonce token if the current user has permissions for unfiltered html.
     594 * Won't display the token for other users.
     595 *
     596 * The function was backported to 2.0.10 and was added to versions 2.1.3 and above. Does not
     597 * exist in versions prior to 2.0.10 in the 2.0 branch and in the 2.1 branch, prior to 2.1.3.
     598 * Technically added in 2.2.0.
     599 *
     600 * @since 2.0.10 Backported to 2.0 branch
     601 * @since 2.1.3
     602 * @uses $post Gets the ID of the current post for the token
     603 */
    269604function wp_comment_form_unfiltered_html_nonce() {
    270605    global $post;
     
    273608}
    274609
     610/**
     611 * comments_template() - Loads the comment template specified in $file
     612 *
     613 * Will not display the comments template if not on single post or page, or
     614 * if the post does not have comments.
     615 *
     616 * Uses the WordPress database object to query for the comments. The comments
     617 * are passed through the 'comments_array' filter hook with the list of comments
     618 * and the post ID respectively.
     619 *
     620 * The $file path is passed through a filter hook called, 'comments_template'
     621 * which includes the TEMPLATEPATH and $file combined. Tries the $filtered path
     622 * first and if it fails it will require the default comment themplate from the
     623 * default theme. If either does not exist, then the WordPress process will be
     624 * halted. It is advised for that reason, that the default theme is not deleted.
     625 *
     626 * @since 1.5
     627 * @global array $comment List of comment objects for the current post
     628 * @uses $wpdb
     629 * @uses $id
     630 * @uses $post
     631 * @uses $withcomments Will not try to get the comments if the post has none.
     632 *
     633 * @param string $file Optional, default '/comments.php'. The file to load
     634 * @return null Returns null if no comments appear
     635 */
    275636function comments_template( $file = '/comments.php' ) {
    276637    global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity;
     
    283644    extract($commenter, EXTR_SKIP);
    284645
    285     // TODO: Use API instead of SELECTs.
     646    /** @todo Use API instead of SELECTs. */
    286647    if ( $user_ID) {
    287648        $comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND (comment_approved = '1' OR ( user_id = %d AND comment_approved = '0' ) )  ORDER BY comment_date", $post->ID, $user_ID));
     
    305666}
    306667
     668/**
     669 * comments_popup_script() - Displays the JS popup script to show a comment
     670 *
     671 * If the $file parameter is empty, then the home page is assumed. The defaults
     672 * for the window are 400px by 400px.
     673 *
     674 * For the comment link popup to work, this function has to be called or the
     675 * normal comment link will be assumed.
     676 *
     677 * @since 0.71
     678 * @global string $wpcommentspopupfile The URL to use for the popup window
     679 * @global int $wpcommentsjavascript Whether to use JavaScript or not. Set when function is called
     680 *
     681 * @param int $width Optional. The width of the popup window
     682 * @param int $height Optional. The height of the popup window
     683 * @param string $file Optional. Sets the location of the popup window
     684 */
    307685function comments_popup_script($width=400, $height=400, $file='') {
    308         global $wpcommentspopupfile, $wpcommentsjavascript;
    309 
    310         if (empty ($file)) {
    311             $wpcommentspopupfile = '';  // Use the index.
    312         } else {
    313             $wpcommentspopupfile = $file;
    314         }
    315 
    316         $wpcommentsjavascript = 1;
    317         $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";
    318         echo $javascript;
    319 }
    320 
     686    global $wpcommentspopupfile, $wpcommentsjavascript;
     687
     688    if (empty ($file)) {
     689        $wpcommentspopupfile = '';  // Use the index.
     690    } else {
     691        $wpcommentspopupfile = $file;
     692    }
     693
     694    $wpcommentsjavascript = 1;
     695    $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";
     696    echo $javascript;
     697}
     698
     699/**
     700 * comments_popup_link() - Displays the link to the comments popup window for the current post ID.
     701 *
     702 * Is not meant to be displayed on single posts and pages. Should be used on the lists of posts
     703 *
     704 * @since 0.71
     705 * @uses $id
     706 * @uses $wpcommentspopupfile
     707 * @uses $wpcommentsjavascript
     708 * @uses $post
     709 *
     710 * @param string $zero The string to display when no comments
     711 * @param string $one The string to display when only one comment is available
     712 * @param string $more The string to display when there are more than one comment
     713 * @param string $css_class The CSS class to use for comments
     714 * @param string $none The string to display when comments have been turned off
     715 * @return null Returns null on single posts and pages.
     716 */
    321717function comments_popup_link( $zero = 'No Comments', $one = '1 Comment', $more = '% Comments', $css_class = '', $none = 'Comments Off' ) {
    322718    global $id, $wpcommentspopupfile, $wpcommentsjavascript, $post;
Note: See TracChangeset for help on using the changeset viewer.