web/wp-includes/comment-template.php
changeset 194 32102edaa81b
parent 136 bde1974c263b
child 204 09a1c134465b
equal deleted inserted replaced
193:2f6f6f7551ca 194:32102edaa81b
    15  * assumed.
    15  * assumed.
    16  *
    16  *
    17  * @since 1.5.0
    17  * @since 1.5.0
    18  * @uses apply_filters() Calls 'get_comment_author' hook on the comment author
    18  * @uses apply_filters() Calls 'get_comment_author' hook on the comment author
    19  *
    19  *
       
    20  * @param int $comment_ID The ID of the comment for which to retrieve the author. Optional.
    20  * @return string The comment author
    21  * @return string The comment author
    21  */
    22  */
    22 function get_comment_author() {
    23 function get_comment_author( $comment_ID = 0 ) {
    23 	global $comment;
    24 	$comment = get_comment( $comment_ID );
    24 	if ( empty($comment->comment_author) ) {
    25 	if ( empty($comment->comment_author) ) {
    25 		if (!empty($comment->user_id)){
    26 		if (!empty($comment->user_id)){
    26 			$user=get_userdata($comment->user_id);
    27 			$user=get_userdata($comment->user_id);
    27 			$author=$user->user_login;
    28 			$author=$user->user_login;
    28 		} else {
    29 		} else {
    37 /**
    38 /**
    38  * Displays the author of the current comment.
    39  * Displays the author of the current comment.
    39  *
    40  *
    40  * @since 0.71
    41  * @since 0.71
    41  * @uses apply_filters() Calls 'comment_author' on comment author before displaying
    42  * @uses apply_filters() Calls 'comment_author' on comment author before displaying
    42  */
    43  *
    43 function comment_author() {
    44  * @param int $comment_ID The ID of the comment for which to print the author. Optional.
    44 	$author = apply_filters('comment_author', get_comment_author() );
    45  */
       
    46 function comment_author( $comment_ID = 0 ) {
       
    47 	$author = apply_filters('comment_author', get_comment_author( $comment_ID ) );
    45 	echo $author;
    48 	echo $author;
    46 }
    49 }
    47 
    50 
    48 /**
    51 /**
    49  * Retrieve the email of the author of the current comment.
    52  * Retrieve the email of the author of the current comment.
    50  *
    53  *
    51  * @since 1.5.0
    54  * @since 1.5.0
    52  * @uses apply_filters() Calls the 'get_comment_author_email' hook on the comment author email
    55  * @uses apply_filters() Calls the 'get_comment_author_email' hook on the comment author email
    53  * @uses $comment
    56  * @uses $comment
    54  *
    57  *
       
    58  * @param int $comment_ID The ID of the comment for which to get the author's email. Optional.
    55  * @return string The current comment author's email
    59  * @return string The current comment author's email
    56  */
    60  */
    57 function get_comment_author_email() {
    61 function get_comment_author_email( $comment_ID = 0 ) {
    58 	global $comment;
    62 	$comment = get_comment( $comment_ID );
    59 	return apply_filters('get_comment_author_email', $comment->comment_author_email);
    63 	return apply_filters('get_comment_author_email', $comment->comment_author_email);
    60 }
    64 }
    61 
    65 
    62 /**
    66 /**
    63  * Display the email of the author of the current global $comment.
    67  * Display the email of the author of the current global $comment.
    68  * enable anyone, including those that people don't want to get the email
    72  * enable anyone, including those that people don't want to get the email
    69  * address and use it for their own means good and bad.
    73  * address and use it for their own means good and bad.
    70  *
    74  *
    71  * @since 0.71
    75  * @since 0.71
    72  * @uses apply_filters() Calls 'author_email' hook on the author email
    76  * @uses apply_filters() Calls 'author_email' hook on the author email
    73  */
    77  *
    74 function comment_author_email() {
    78  * @param int $comment_ID The ID of the comment for which to print the author's email. Optional.
    75 	echo apply_filters('author_email', get_comment_author_email() );
    79  */
       
    80 function comment_author_email( $comment_ID = 0 ) {
       
    81 	echo apply_filters('author_email', get_comment_author_email( $comment_ID ) );
    76 }
    82 }
    77 
    83 
    78 /**
    84 /**
    79  * Display the html email link to the author of the current comment.
    85  * Display the html email link to the author of the current comment.
    80  *
    86  *
   133  * Retrieve the html link to the url of the author of the current comment.
   139  * Retrieve the html link to the url of the author of the current comment.
   134  *
   140  *
   135  * @since 1.5.0
   141  * @since 1.5.0
   136  * @uses apply_filters() Calls 'get_comment_author_link' hook on the complete link HTML or author
   142  * @uses apply_filters() Calls 'get_comment_author_link' hook on the complete link HTML or author
   137  *
   143  *
       
   144  * @param int $comment_ID The ID of the comment for which to get the author's link. Optional.
   138  * @return string Comment Author name or HTML link for author's URL
   145  * @return string Comment Author name or HTML link for author's URL
   139  */
   146  */
   140 function get_comment_author_link() {
   147 function get_comment_author_link( $comment_ID = 0 ) {
   141 	/** @todo Only call these functions when they are needed. Include in if... else blocks */
   148 	/** @todo Only call these functions when they are needed. Include in if... else blocks */
   142 	$url    = get_comment_author_url();
   149 	$url    = get_comment_author_url( $comment_ID );
   143 	$author = get_comment_author();
   150 	$author = get_comment_author( $comment_ID );
   144 
   151 
   145 	if ( empty( $url ) || 'http://' == $url )
   152 	if ( empty( $url ) || 'http://' == $url )
   146 		$return = $author;
   153 		$return = $author;
   147 	else
   154 	else
   148 		$return = "<a href='$url' rel='external nofollow' class='url'>$author</a>";
   155 		$return = "<a href='$url' rel='external nofollow' class='url'>$author</a>";
   151 
   158 
   152 /**
   159 /**
   153  * Display the html link to the url of the author of the current comment.
   160  * Display the html link to the url of the author of the current comment.
   154  *
   161  *
   155  * @since 0.71
   162  * @since 0.71
   156  * @see get_comment_author_link() Echos result
   163  * @see get_comment_author_link() Echoes result
   157  */
   164  *
   158 function comment_author_link() {
   165  * @param int $comment_ID The ID of the comment for which to print the author's link. Optional.
   159 	echo get_comment_author_link();
   166  */
       
   167 function comment_author_link( $comment_ID = 0 ) {
       
   168 	echo get_comment_author_link( $comment_ID );
   160 }
   169 }
   161 
   170 
   162 /**
   171 /**
   163  * Retrieve the IP address of the author of the current comment.
   172  * Retrieve the IP address of the author of the current comment.
   164  *
   173  *
   165  * @since 1.5.0
   174  * @since 1.5.0
   166  * @uses $comment
   175  * @uses $comment
   167  * @uses apply_filters()
   176  * @uses apply_filters()
   168  *
   177  *
   169  * @return unknown
   178  * @param int $comment_ID The ID of the comment for which to get the author's IP address. Optional.
   170  */
   179  * @return string The comment author's IP address.
   171 function get_comment_author_IP() {
   180  */
   172 	global $comment;
   181 function get_comment_author_IP( $comment_ID = 0 ) {
       
   182 	$comment = get_comment( $comment_ID );
   173 	return apply_filters('get_comment_author_IP', $comment->comment_author_IP);
   183 	return apply_filters('get_comment_author_IP', $comment->comment_author_IP);
   174 }
   184 }
   175 
   185 
   176 /**
   186 /**
   177  * Display the IP address of the author of the current comment.
   187  * Display the IP address of the author of the current comment.
   178  *
   188  *
   179  * @since 0.71
   189  * @since 0.71
   180  * @see get_comment_author_IP() Echos Result
   190  * @see get_comment_author_IP() Echoes Result
   181  */
   191  *
   182 function comment_author_IP() {
   192  * @param int $comment_ID The ID of the comment for which to print the author's IP address. Optional.
   183 	echo get_comment_author_IP();
   193  */
       
   194 function comment_author_IP( $comment_ID = 0 ) {
       
   195 	echo get_comment_author_IP( $comment_ID );
   184 }
   196 }
   185 
   197 
   186 /**
   198 /**
   187  * Retrieve the url of the author of the current comment.
   199  * Retrieve the url of the author of the current comment.
   188  *
   200  *
   189  * @since 1.5.0
   201  * @since 1.5.0
   190  * @uses apply_filters() Calls 'get_comment_author_url' hook on the comment author's URL
   202  * @uses apply_filters() Calls 'get_comment_author_url' hook on the comment author's URL
   191  *
   203  *
       
   204  * @param int $comment_ID The ID of the comment for which to get the author's URL. Optional.
   192  * @return string
   205  * @return string
   193  */
   206  */
   194 function get_comment_author_url() {
   207 function get_comment_author_url( $comment_ID = 0 ) {
   195 	global $comment;
   208 	$comment = get_comment( $comment_ID );
   196 	$url = ('http://' == $comment->comment_author_url) ? '' : $comment->comment_author_url;
   209 	$url = ('http://' == $comment->comment_author_url) ? '' : $comment->comment_author_url;
   197 	$url = esc_url( $url, array('http', 'https') );
   210 	$url = esc_url( $url, array('http', 'https') );
   198 	return apply_filters('get_comment_author_url', $url);
   211 	return apply_filters('get_comment_author_url', $url);
   199 }
   212 }
   200 
   213 
   202  * Display the url of the author of the current comment.
   215  * Display the url of the author of the current comment.
   203  *
   216  *
   204  * @since 0.71
   217  * @since 0.71
   205  * @uses apply_filters()
   218  * @uses apply_filters()
   206  * @uses get_comment_author_url() Retrieves the comment author's URL
   219  * @uses get_comment_author_url() Retrieves the comment author's URL
   207  */
   220  *
   208 function comment_author_url() {
   221  * @param int $comment_ID The ID of the comment for which to print the author's URL. Optional.
   209 	echo apply_filters('comment_url', get_comment_author_url());
   222  */
       
   223 function comment_author_url( $comment_ID = 0 ) {
       
   224 	echo apply_filters('comment_url', get_comment_author_url( $comment_ID ));
   210 }
   225 }
   211 
   226 
   212 /**
   227 /**
   213  * Retrieves the HTML link of the url of the author of the current comment.
   228  * Retrieves the HTML link of the url of the author of the current comment.
   214  *
   229  *
   240 
   255 
   241 /**
   256 /**
   242  * Displays the HTML link of the url of the author of the current comment.
   257  * Displays the HTML link of the url of the author of the current comment.
   243  *
   258  *
   244  * @since 0.71
   259  * @since 0.71
   245  * @see get_comment_author_url_link() Echos result
   260  * @see get_comment_author_url_link() Echoes result
   246  *
   261  *
   247  * @param string $linktext The text to display instead of the comment author's email address
   262  * @param string $linktext The text to display instead of the comment author's email address
   248  * @param string $before The text or HTML to display before the email link.
   263  * @param string $before The text or HTML to display before the email link.
   249  * @param string $after The text or HTML to display after the email link.
   264  * @param string $after The text or HTML to display after the email link.
   250  */
   265  */
   345 
   360 
   346 /**
   361 /**
   347  * Retrieve the comment date of the current comment.
   362  * Retrieve the comment date of the current comment.
   348  *
   363  *
   349  * @since 1.5.0
   364  * @since 1.5.0
   350  * @uses apply_filters() Calls 'get_comment_date' hook with the formated date and the $d parameter respectively
   365  * @uses apply_filters() Calls 'get_comment_date' hook with the formatted date and the $d parameter respectively
   351  * @uses $comment
   366  * @uses $comment
   352  *
   367  *
   353  * @param string $d The format of the date (defaults to user's config)
   368  * @param string $d The format of the date (defaults to user's config)
       
   369  * @param int $comment_ID The ID of the comment for which to get the date. Optional.
   354  * @return string The comment's date
   370  * @return string The comment's date
   355  */
   371  */
   356 function get_comment_date( $d = '' ) {
   372 function get_comment_date( $d = '', $comment_ID = 0 ) {
   357 	global $comment;
   373 	$comment = get_comment( $comment_ID );
   358 	if ( '' == $d )
   374 	if ( '' == $d )
   359 		$date = mysql2date(get_option('date_format'), $comment->comment_date);
   375 		$date = mysql2date(get_option('date_format'), $comment->comment_date);
   360 	else
   376 	else
   361 		$date = mysql2date($d, $comment->comment_date);
   377 		$date = mysql2date($d, $comment->comment_date);
   362 	return apply_filters('get_comment_date', $date, $d);
   378 	return apply_filters('get_comment_date', $date, $d);
   366  * Display the comment date of the current comment.
   382  * Display the comment date of the current comment.
   367  *
   383  *
   368  * @since 0.71
   384  * @since 0.71
   369  *
   385  *
   370  * @param string $d The format of the date (defaults to user's config)
   386  * @param string $d The format of the date (defaults to user's config)
   371  */
   387  * @param int $comment_ID The ID of the comment for which to print the date. Optional.
   372 function comment_date( $d = '' ) {
   388  */
   373 	echo get_comment_date( $d );
   389 function comment_date( $d = '', $comment_ID = 0 ) {
       
   390 	echo get_comment_date( $d, $comment_ID );
   374 }
   391 }
   375 
   392 
   376 /**
   393 /**
   377  * Retrieve the excerpt of the current comment.
   394  * Retrieve the excerpt of the current comment.
   378  *
   395  *
   382  *
   399  *
   383  * @since 1.5.0
   400  * @since 1.5.0
   384  * @uses $comment
   401  * @uses $comment
   385  * @uses apply_filters() Calls 'get_comment_excerpt' on truncated comment
   402  * @uses apply_filters() Calls 'get_comment_excerpt' on truncated comment
   386  *
   403  *
       
   404  * @param int $comment_ID The ID of the comment for which to get the excerpt. Optional.
   387  * @return string The maybe truncated comment with 20 words or less
   405  * @return string The maybe truncated comment with 20 words or less
   388  */
   406  */
   389 function get_comment_excerpt() {
   407 function get_comment_excerpt( $comment_ID = 0 ) {
   390 	global $comment;
   408 	$comment = get_comment( $comment_ID );
   391 	$comment_text = strip_tags($comment->comment_content);
   409 	$comment_text = strip_tags($comment->comment_content);
   392 	$blah = explode(' ', $comment_text);
   410 	$blah = explode(' ', $comment_text);
   393 	if (count($blah) > 20) {
   411 	if (count($blah) > 20) {
   394 		$k = 20;
   412 		$k = 20;
   395 		$use_dotdotdot = 1;
   413 		$use_dotdotdot = 1;
   408 /**
   426 /**
   409  * Display the excerpt of the current comment.
   427  * Display the excerpt of the current comment.
   410  *
   428  *
   411  * @since 1.2.0
   429  * @since 1.2.0
   412  * @uses apply_filters() Calls 'comment_excerpt' hook before displaying excerpt
   430  * @uses apply_filters() Calls 'comment_excerpt' hook before displaying excerpt
   413  */
   431  *
   414 function comment_excerpt() {
   432  * @param int $comment_ID The ID of the comment for which to print the excerpt. Optional.
   415 	echo apply_filters('comment_excerpt', get_comment_excerpt() );
   433  */
       
   434 function comment_excerpt( $comment_ID = 0 ) {
       
   435 	echo apply_filters('comment_excerpt', get_comment_excerpt($comment_ID) );
   416 }
   436 }
   417 
   437 
   418 /**
   438 /**
   419  * Retrieve the comment id of the current comment.
   439  * Retrieve the comment id of the current comment.
   420  *
   440  *
   431 
   451 
   432 /**
   452 /**
   433  * Displays the comment id of the current comment.
   453  * Displays the comment id of the current comment.
   434  *
   454  *
   435  * @since 0.71
   455  * @since 0.71
   436  * @see get_comment_ID() Echos Result
   456  * @see get_comment_ID() Echoes Result
   437  */
   457  */
   438 function comment_ID() {
   458 function comment_ID() {
   439 	echo get_comment_ID();
   459 	echo get_comment_ID();
   440 }
   460 }
   441 
   461 
   490 /**
   510 /**
   491  * Retrieves the link to the current post comments.
   511  * Retrieves the link to the current post comments.
   492  *
   512  *
   493  * @since 1.5.0
   513  * @since 1.5.0
   494  *
   514  *
       
   515  * @param int $post_id Optional post id
   495  * @return string The link to the comments
   516  * @return string The link to the comments
   496  */
   517  */
   497 function get_comments_link() {
   518 function get_comments_link($post_id = 0) {
   498 	return get_permalink() . '#comments';
   519 	return get_permalink($post_id) . '#comments';
   499 }
   520 }
   500 
   521 
   501 /**
   522 /**
   502  * Displays the link to the current post comments.
   523  * Displays the link to the current post comments.
   503  *
   524  *
   504  * @since 0.71
   525  * @since 0.71
   505  *
   526  *
   506  * @param string $deprecated Not Used
   527  * @param string $deprecated Not Used
   507  * @param bool $deprecated Not Used
   528  * @param bool $deprecated_2 Not Used
   508  */
   529  */
   509 function comments_link( $deprecated = '', $deprecated = '' ) {
   530 function comments_link( $deprecated = '', $deprecated_2 = '' ) {
       
   531 	if ( !empty( $deprecated ) )
       
   532 		_deprecated_argument( __FUNCTION__, '0.72' );
       
   533 	if ( !empty( $deprecated_2 ) )
       
   534 		_deprecated_argument( __FUNCTION__, '1.3' );
   510 	echo get_comments_link();
   535 	echo get_comments_link();
   511 }
   536 }
   512 
   537 
   513 /**
   538 /**
   514  * Retrieve the amount of comments a post has.
   539  * Retrieve the amount of comments a post has.
   518  *
   543  *
   519  * @param int $post_id The Post ID
   544  * @param int $post_id The Post ID
   520  * @return int The number of comments a post has
   545  * @return int The number of comments a post has
   521  */
   546  */
   522 function get_comments_number( $post_id = 0 ) {
   547 function get_comments_number( $post_id = 0 ) {
   523 	global $id;
   548 	$post_id = absint( $post_id );
   524 	$post_id = (int) $post_id;
       
   525 
   549 
   526 	if ( !$post_id )
   550 	if ( !$post_id )
   527 		$post_id = (int) $id;
   551 		$post_id = get_the_ID();
   528 
   552 
   529 	$post = get_post($post_id);
   553 	$post = get_post($post_id);
   530 	if ( ! isset($post->comment_count) )
   554 	if ( ! isset($post->comment_count) )
   531 		$count = 0;
   555 		$count = 0;
   532 	else
   556 	else
   537 
   561 
   538 /**
   562 /**
   539  * Display the language string for the number of comments the current post has.
   563  * Display the language string for the number of comments the current post has.
   540  *
   564  *
   541  * @since 0.71
   565  * @since 0.71
   542  * @uses $id
       
   543  * @uses apply_filters() Calls the 'comments_number' hook on the output and number of comments respectively.
   566  * @uses apply_filters() Calls the 'comments_number' hook on the output and number of comments respectively.
   544  *
   567  *
   545  * @param string $zero Text for no comments
   568  * @param string $zero Text for no comments
   546  * @param string $one Text for one comment
   569  * @param string $one Text for one comment
   547  * @param string $more Text for more than one comment
   570  * @param string $more Text for more than one comment
   548  * @param string $deprecated Not used.
   571  * @param string $deprecated Not used.
   549  */
   572  */
   550 function comments_number( $zero = false, $one = false, $more = false, $deprecated = '' ) {
   573 function comments_number( $zero = false, $one = false, $more = false, $deprecated = '' ) {
   551 	global $id;
   574 	if ( !empty( $deprecated ) )
   552 	$number = get_comments_number($id);
   575 		_deprecated_argument( __FUNCTION__, '1.3' );
       
   576 
       
   577 	$number = get_comments_number();
   553 
   578 
   554 	if ( $number > 1 )
   579 	if ( $number > 1 )
   555 		$output = str_replace('%', number_format_i18n($number), ( false === $more ) ? __('% Comments') : $more);
   580 		$output = str_replace('%', number_format_i18n($number), ( false === $more ) ? __('% Comments') : $more);
   556 	elseif ( $number == 0 )
   581 	elseif ( $number == 0 )
   557 		$output = ( false === $zero ) ? __('No Comments') : $zero;
   582 		$output = ( false === $zero ) ? __('No Comments') : $zero;
   565  * Retrieve the text of the current comment.
   590  * Retrieve the text of the current comment.
   566  *
   591  *
   567  * @since 1.5.0
   592  * @since 1.5.0
   568  * @uses $comment
   593  * @uses $comment
   569  *
   594  *
       
   595  * @param int $comment_ID The ID of the comment for which to get the text. Optional.
   570  * @return string The comment content
   596  * @return string The comment content
   571  */
   597  */
   572 function get_comment_text() {
   598 function get_comment_text( $comment_ID = 0 ) {
   573 	global $comment;
   599 	$comment = get_comment( $comment_ID );
   574 	return apply_filters('get_comment_text', $comment->comment_content);
   600 	return apply_filters( 'get_comment_text', $comment->comment_content, $comment );
   575 }
   601 }
   576 
   602 
   577 /**
   603 /**
   578  * Displays the text of the current comment.
   604  * Displays the text of the current comment.
   579  *
   605  *
   580  * @since 0.71
   606  * @since 0.71
   581  * @uses apply_filters() Passes the comment content through the 'comment_text' hook before display
   607  * @uses apply_filters() Passes the comment content through the 'comment_text' hook before display
   582  * @uses get_comment_text() Gets the comment content
   608  * @uses get_comment_text() Gets the comment content
   583  */
   609  *
   584 function comment_text() {
   610  * @param int $comment_ID The ID of the comment for which to print the text. Optional.
   585 	echo apply_filters('comment_text', get_comment_text() );
   611  */
       
   612 function comment_text( $comment_ID = 0 ) {
       
   613 	$comment = get_comment( $comment_ID );
       
   614 	echo apply_filters( 'comment_text', get_comment_text( $comment_ID ), $comment );
   586 }
   615 }
   587 
   616 
   588 /**
   617 /**
   589  * Retrieve the comment time of the current comment.
   618  * Retrieve the comment time of the current comment.
   590  *
   619  *
   623  *
   652  *
   624  * @since 1.5.0
   653  * @since 1.5.0
   625  * @uses $comment
   654  * @uses $comment
   626  * @uses apply_filters() Calls the 'get_comment_type' hook on the comment type
   655  * @uses apply_filters() Calls the 'get_comment_type' hook on the comment type
   627  *
   656  *
       
   657  * @param int $comment_ID The ID of the comment for which to get the type. Optional.
   628  * @return string The comment type
   658  * @return string The comment type
   629  */
   659  */
   630 function get_comment_type() {
   660 function get_comment_type( $comment_ID = 0 ) {
   631 	global $comment;
   661 	$comment = get_comment( $comment_ID );
   632 
       
   633 	if ( '' == $comment->comment_type )
   662 	if ( '' == $comment->comment_type )
   634 		$comment->comment_type = 'comment';
   663 		$comment->comment_type = 'comment';
   635 
   664 
   636 	return apply_filters('get_comment_type', $comment->comment_type);
   665 	return apply_filters('get_comment_type', $comment->comment_type);
   637 }
   666 }
   644  * @param string $commenttxt The string to display for comment type
   673  * @param string $commenttxt The string to display for comment type
   645  * @param string $trackbacktxt The string to display for trackback type
   674  * @param string $trackbacktxt The string to display for trackback type
   646  * @param string $pingbacktxt The string to display for pingback type
   675  * @param string $pingbacktxt The string to display for pingback type
   647  */
   676  */
   648 function comment_type($commenttxt = false, $trackbacktxt = false, $pingbacktxt = false) {
   677 function comment_type($commenttxt = false, $trackbacktxt = false, $pingbacktxt = false) {
   649     if ( false === $commenttxt ) $commenttxt = _x( 'Comment', 'noun' );
   678 	if ( false === $commenttxt ) $commenttxt = _x( 'Comment', 'noun' );
   650     if ( false === $trackbacktxt ) $trackbacktxt = __( 'Trackback' );
   679 	if ( false === $trackbacktxt ) $trackbacktxt = __( 'Trackback' );
   651     if ( false === $pingbacktxt ) $pingbacktxt = __( 'Pingback' );
   680 	if ( false === $pingbacktxt ) $pingbacktxt = __( 'Pingback' );
   652 	$type = get_comment_type();
   681 	$type = get_comment_type();
   653 	switch( $type ) {
   682 	switch( $type ) {
   654 		case 'trackback' :
   683 		case 'trackback' :
   655 			echo $trackbacktxt;
   684 			echo $trackbacktxt;
   656 			break;
   685 			break;
   669  * retrieve the pretty path. If permalinks weren't enabled, the ID of the
   698  * retrieve the pretty path. If permalinks weren't enabled, the ID of the
   670  * current post is used and appended to the correct page to go to.
   699  * current post is used and appended to the correct page to go to.
   671  *
   700  *
   672  * @since 1.5.0
   701  * @since 1.5.0
   673  * @uses apply_filters() Calls 'trackback_url' on the resulting trackback URL
   702  * @uses apply_filters() Calls 'trackback_url' on the resulting trackback URL
   674  * @uses $id
       
   675  *
   703  *
   676  * @return string The trackback URL after being filtered
   704  * @return string The trackback URL after being filtered
   677  */
   705  */
   678 function get_trackback_url() {
   706 function get_trackback_url() {
   679 	global $id;
       
   680 	if ( '' != get_option('permalink_structure') ) {
   707 	if ( '' != get_option('permalink_structure') ) {
   681 		$tb_url = trailingslashit(get_permalink()) . user_trailingslashit('trackback', 'single_trackback');
   708 		$tb_url = trailingslashit(get_permalink()) . user_trailingslashit('trackback', 'single_trackback');
   682 	} else {
   709 	} else {
   683 		$tb_url = get_option('siteurl') . '/wp-trackback.php?p=' . $id;
   710 		$tb_url = get_option('siteurl') . '/wp-trackback.php?p=' . get_the_ID();
   684 	}
   711 	}
   685 	return apply_filters('trackback_url', $tb_url);
   712 	return apply_filters('trackback_url', $tb_url);
   686 }
   713 }
   687 
   714 
   688 /**
   715 /**
   689  * Displays the current post's trackback URL.
   716  * Displays the current post's trackback URL.
   690  *
   717  *
   691  * @since 0.71
   718  * @since 0.71
   692  * @uses get_trackback_url() Gets the trackback url for the current post
   719  * @uses get_trackback_url() Gets the trackback url for the current post
   693  *
   720  *
   694  * @param bool $deprecated Remove backwards compat in 2.5
   721  * @param bool $deprecated_echo Remove backwards compat in 2.5
   695  * @return void|string Should only be used to echo the trackback URL, use get_trackback_url() for the result instead.
   722  * @return void|string Should only be used to echo the trackback URL, use get_trackback_url() for the result instead.
   696  */
   723  */
   697 function trackback_url($deprecated = true) {
   724 function trackback_url( $deprecated_echo = true ) {
   698 	if ($deprecated) echo get_trackback_url();
   725 	if ( $deprecated_echo !== true )
   699 	else return get_trackback_url();
   726 		_deprecated_argument( __FUNCTION__, '2.5', __('Use <code>get_trackback_url()</code> instead if you do not want the value echoed.') );
       
   727 	if ( $deprecated_echo )
       
   728 		echo get_trackback_url();
       
   729 	else
       
   730 		return get_trackback_url();
   700 }
   731 }
   701 
   732 
   702 /**
   733 /**
   703  * Generates and displays the RDF for the trackback information of current post.
   734  * Generates and displays the RDF for the trackback information of current post.
   704  *
   735  *
       
   736  * Deprecated in 3.0.0, and restored in 3.0.1.
       
   737  *
   705  * @since 0.71
   738  * @since 0.71
   706  *
   739  *
   707  * @param int $deprecated Not used (Was $timezone = 0)
   740  * @param int $deprecated Not used (Was $timezone = 0)
   708  */
   741  */
   709 function trackback_rdf($deprecated = '') {
   742 function trackback_rdf( $deprecated = '' ) {
   710 	if (stripos($_SERVER['HTTP_USER_AGENT'], 'W3C_Validator') === false) {
   743 	if ( !empty( $deprecated ) )
   711 		echo '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   744 		_deprecated_argument( __FUNCTION__, '2.5' );
   712 				xmlns:dc="http://purl.org/dc/elements/1.1/"
   745 
   713 				xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
   746 	if ( false !== stripos($_SERVER['HTTP_USER_AGENT'], 'W3C_Validator') )
   714 			<rdf:Description rdf:about="';
   747 		return;
   715 		the_permalink();
   748 
   716 		echo '"'."\n";
   749 	echo '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   717 		echo '    dc:identifier="';
   750 			xmlns:dc="http://purl.org/dc/elements/1.1/"
   718 		the_permalink();
   751 			xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
   719 		echo '"'."\n";
   752 		<rdf:Description rdf:about="';
   720 		echo '    dc:title="'.str_replace('--', '&#x2d;&#x2d;', wptexturize(strip_tags(get_the_title()))).'"'."\n";
   753 	the_permalink();
   721 		echo '    trackback:ping="'.get_trackback_url().'"'." />\n";
   754 	echo '"'."\n";
   722 		echo '</rdf:RDF>';
   755 	echo '    dc:identifier="';
   723 	}
   756 	the_permalink();
       
   757 	echo '"'."\n";
       
   758 	echo '    dc:title="'.str_replace('--', '&#x2d;&#x2d;', wptexturize(strip_tags(get_the_title()))).'"'."\n";
       
   759 	echo '    trackback:ping="'.get_trackback_url().'"'." />\n";
       
   760 	echo '</rdf:RDF>';
   724 }
   761 }
   725 
   762 
   726 /**
   763 /**
   727  * Whether the current post is open for comments.
   764  * Whether the current post is open for comments.
   728  *
   765  *
   730  * @uses $post
   767  * @uses $post
   731  *
   768  *
   732  * @param int $post_id An optional post ID to check instead of the current post.
   769  * @param int $post_id An optional post ID to check instead of the current post.
   733  * @return bool True if the comments are open
   770  * @return bool True if the comments are open
   734  */
   771  */
   735 function comments_open( $post_id=NULL ) {
   772 function comments_open( $post_id = null ) {
   736 
   773 
   737 	$_post = get_post($post_id);
   774 	$_post = get_post($post_id);
   738 
   775 
   739 	$open = ( 'open' == $_post->comment_status );
   776 	$open = ( 'open' == $_post->comment_status );
   740 	return apply_filters( 'comments_open', $open, $post_id );
   777 	return apply_filters( 'comments_open', $open, $post_id );
   747  * @uses $post
   784  * @uses $post
   748  *
   785  *
   749  * @param int $post_id An optional post ID to check instead of the current post.
   786  * @param int $post_id An optional post ID to check instead of the current post.
   750  * @return bool True if pings are accepted
   787  * @return bool True if pings are accepted
   751  */
   788  */
   752 function pings_open( $post_id = NULL ) {
   789 function pings_open( $post_id = null ) {
   753 
   790 
   754 	$_post = get_post($post_id);
   791 	$_post = get_post($post_id);
   755 
   792 
   756 	$open = ( 'open' == $_post->ping_status );
   793 	$open = ( 'open' == $_post->ping_status );
   757 	return apply_filters( 'pings_open', $open, $post_id );
   794 	return apply_filters( 'pings_open', $open, $post_id );
   777 
   814 
   778 	$post_id = 0;
   815 	$post_id = 0;
   779 	if ( !empty($post) )
   816 	if ( !empty($post) )
   780 		$post_id = $post->ID;
   817 		$post_id = $post->ID;
   781 
   818 
   782 	if ( current_user_can('unfiltered_html') )
   819 	if ( current_user_can( 'unfiltered_html' ) ) {
   783 		wp_nonce_field('unfiltered-html-comment_' . $post_id, '_wp_unfiltered_html_comment', false);
   820 		wp_nonce_field( 'unfiltered-html-comment_' . $post_id, '_wp_unfiltered_html_comment_disabled', false );
       
   821 		echo "<script>(function(){if(window===window.parent){document.getElementById('_wp_unfiltered_html_comment_disabled').name='_wp_unfiltered_html_comment';}})();</script>\n";
       
   822 	}
   784 }
   823 }
   785 
   824 
   786 /**
   825 /**
   787  * Loads the comment template specified in $file.
   826  * Loads the comment template specified in $file.
   788  *
   827  *
   793  * are passed through the 'comments_array' filter hook with the list of comments
   832  * are passed through the 'comments_array' filter hook with the list of comments
   794  * and the post ID respectively.
   833  * and the post ID respectively.
   795  *
   834  *
   796  * The $file path is passed through a filter hook called, 'comments_template'
   835  * The $file path is passed through a filter hook called, 'comments_template'
   797  * which includes the TEMPLATEPATH and $file combined. Tries the $filtered path
   836  * which includes the TEMPLATEPATH and $file combined. Tries the $filtered path
   798  * first and if it fails it will require the default comment themplate from the
   837  * first and if it fails it will require the default comment template from the
   799  * default theme. If either does not exist, then the WordPress process will be
   838  * default theme. If either does not exist, then the WordPress process will be
   800  * halted. It is advised for that reason, that the default theme is not deleted.
   839  * halted. It is advised for that reason, that the default theme is not deleted.
   801  *
   840  *
   802  * @since 1.5.0
   841  * @since 1.5.0
   803  * @global array $comment List of comment objects for the current post
   842  * @global array $comment List of comment objects for the current post
   804  * @uses $wpdb
   843  * @uses $wpdb
   805  * @uses $id
       
   806  * @uses $post
   844  * @uses $post
   807  * @uses $withcomments Will not try to get the comments if the post has none.
   845  * @uses $withcomments Will not try to get the comments if the post has none.
   808  *
   846  *
   809  * @param string $file Optional, default '/comments.php'. The file to load
   847  * @param string $file Optional, default '/comments.php'. The file to load
   810  * @param bool $separate_comments Optional, whether to separate the comments by comment type. Default is false.
   848  * @param bool $separate_comments Optional, whether to separate the comments by comment type. Default is false.
   861 	if ( $separate_comments ) {
   899 	if ( $separate_comments ) {
   862 		$wp_query->comments_by_type = &separate_comments($comments);
   900 		$wp_query->comments_by_type = &separate_comments($comments);
   863 		$comments_by_type = &$wp_query->comments_by_type;
   901 		$comments_by_type = &$wp_query->comments_by_type;
   864 	}
   902 	}
   865 
   903 
   866 	$overridden_cpage = FALSE;
   904 	$overridden_cpage = false;
   867 	if ( '' == get_query_var('cpage') && get_option('page_comments') ) {
   905 	if ( '' == get_query_var('cpage') && get_option('page_comments') ) {
   868 		set_query_var( 'cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1 );
   906 		set_query_var( 'cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1 );
   869 		$overridden_cpage = TRUE;
   907 		$overridden_cpage = true;
   870 	}
   908 	}
   871 
   909 
   872 	if ( !defined('COMMENTS_TEMPLATE') || !COMMENTS_TEMPLATE)
   910 	if ( !defined('COMMENTS_TEMPLATE') || !COMMENTS_TEMPLATE)
   873 		define('COMMENTS_TEMPLATE', true);
   911 		define('COMMENTS_TEMPLATE', true);
   874 
   912 
   875 	$include = apply_filters('comments_template', STYLESHEETPATH . $file );
   913 	$include = apply_filters('comments_template', STYLESHEETPATH . $file );
   876 	if ( file_exists( $include ) )
   914 	if ( file_exists( $include ) )
   877 		require( $include );
   915 		require( $include );
   878 	elseif ( file_exists( TEMPLATEPATH . $file ) )
   916 	elseif ( file_exists( TEMPLATEPATH . $file ) )
   879 		require( TEMPLATEPATH .  $file );
   917 		require( TEMPLATEPATH . $file );
   880 	else
   918 	else // Backward compat code will be removed in a future release
   881 		require( get_theme_root() . '/default/comments.php');
   919 		require( ABSPATH . WPINC . '/theme-compat/comments.php');
   882 }
   920 }
   883 
   921 
   884 /**
   922 /**
   885  * Displays the JS popup script to show a comment.
   923  * Displays the JS popup script to show a comment.
   886  *
   924  *
   890  * For the comment link popup to work, this function has to be called or the
   928  * For the comment link popup to work, this function has to be called or the
   891  * normal comment link will be assumed.
   929  * normal comment link will be assumed.
   892  *
   930  *
   893  * @since 0.71
   931  * @since 0.71
   894  * @global string $wpcommentspopupfile The URL to use for the popup window
   932  * @global string $wpcommentspopupfile The URL to use for the popup window
   895  * @global int $wpcommentsjavascript Whether to use JavaScript or not. Set when function is called
   933  * @global int $wpcommentsjavascript Whether to use JavaScript. Set when function is called
   896  *
   934  *
   897  * @param int $width Optional. The width of the popup window
   935  * @param int $width Optional. The width of the popup window
   898  * @param int $height Optional. The height of the popup window
   936  * @param int $height Optional. The height of the popup window
   899  * @param string $file Optional. Sets the location of the popup window
   937  * @param string $file Optional. Sets the location of the popup window
   900  */
   938  */
   917  *
   955  *
   918  * Is not meant to be displayed on single posts and pages. Should be used on the
   956  * Is not meant to be displayed on single posts and pages. Should be used on the
   919  * lists of posts
   957  * lists of posts
   920  *
   958  *
   921  * @since 0.71
   959  * @since 0.71
   922  * @uses $id
       
   923  * @uses $wpcommentspopupfile
   960  * @uses $wpcommentspopupfile
   924  * @uses $wpcommentsjavascript
   961  * @uses $wpcommentsjavascript
   925  * @uses $post
   962  * @uses $post
   926  *
   963  *
   927  * @param string $zero The string to display when no comments
   964  * @param string $zero The string to display when no comments
   930  * @param string $css_class The CSS class to use for comments
   967  * @param string $css_class The CSS class to use for comments
   931  * @param string $none The string to display when comments have been turned off
   968  * @param string $none The string to display when comments have been turned off
   932  * @return null Returns null on single posts and pages.
   969  * @return null Returns null on single posts and pages.
   933  */
   970  */
   934 function comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false ) {
   971 function comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false ) {
   935 	global $id, $wpcommentspopupfile, $wpcommentsjavascript, $post;
   972 	global $wpcommentspopupfile, $wpcommentsjavascript;
   936 
   973 
   937     if ( false === $zero ) $zero = __( 'No Comments' );
   974 	$id = get_the_ID();
   938     if ( false === $one ) $one = __( '1 Comment' );
   975 
   939     if ( false === $more ) $more = __( '% Comments' );
   976 	if ( false === $zero ) $zero = __( 'No Comments' );
   940     if ( false === $none ) $none = __( 'Comments Off' );
   977 	if ( false === $one ) $one = __( '1 Comment' );
       
   978 	if ( false === $more ) $more = __( '% Comments' );
       
   979 	if ( false === $none ) $none = __( 'Comments Off' );
   941 
   980 
   942 	$number = get_comments_number( $id );
   981 	$number = get_comments_number( $id );
   943 
   982 
   944 	if ( 0 == $number && !comments_open() && !pings_open() ) {
   983 	if ( 0 == $number && !comments_open() && !pings_open() ) {
   945 		echo '<span' . ((!empty($css_class)) ? ' class="' . esc_attr( $css_class ) . '"' : '') . '>' . $none . '</span>';
   984 		echo '<span' . ((!empty($css_class)) ? ' class="' . esc_attr( $css_class ) . '"' : '') . '>' . $none . '</span>';
   946 		return;
   985 		return;
   947 	}
   986 	}
   948 
   987 
   949 	if ( post_password_required() ) {
   988 	if ( post_password_required() ) {
   950 		echo __('Enter your password to view comments');
   989 		echo __('Enter your password to view comments.');
   951 		return;
   990 		return;
   952 	}
   991 	}
   953 
   992 
   954 	echo '<a href="';
   993 	echo '<a href="';
   955 	if ( $wpcommentsjavascript ) {
   994 	if ( $wpcommentsjavascript ) {
   956 		if ( empty( $wpcommentspopupfile ) )
   995 		if ( empty( $wpcommentspopupfile ) )
   957 			$home = get_option('home');
   996 			$home = home_url();
   958 		else
   997 		else
   959 			$home = get_option('siteurl');
   998 			$home = get_option('siteurl');
   960 		echo $home . '/' . $wpcommentspopupfile . '?comments_popup=' . $id;
   999 		echo $home . '/' . $wpcommentspopupfile . '?comments_popup=' . $id;
   961 		echo '" onclick="wpopen(this.href); return false"';
  1000 		echo '" onclick="wpopen(this.href); return false"';
   962 	} else { // if comments_popup_script() is not in the template, display simple comment link
  1001 	} else { // if comments_popup_script() is not in the template, display simple comment link
   968 	}
  1007 	}
   969 
  1008 
   970 	if ( !empty( $css_class ) ) {
  1009 	if ( !empty( $css_class ) ) {
   971 		echo ' class="'.$css_class.'" ';
  1010 		echo ' class="'.$css_class.'" ';
   972 	}
  1011 	}
   973 	$title = the_title_attribute( 'echo=0' );
  1012 	$title = the_title_attribute( array('echo' => 0 ) );
   974 
  1013 
   975 	echo apply_filters( 'comments_popup_link_attributes', '' );
  1014 	echo apply_filters( 'comments_popup_link_attributes', '' );
   976 
  1015 
   977 	echo ' title="' . esc_attr( sprintf( __('Comment on %s'), $title ) ) . '">';
  1016 	echo ' title="' . esc_attr( sprintf( __('Comment on %s'), $title ) ) . '">';
   978 	comments_number( $zero, $one, $more, $number );
  1017 	comments_number( $zero, $one, $more );
   979 	echo '</a>';
  1018 	echo '</a>';
   980 }
  1019 }
   981 
  1020 
   982 /**
  1021 /**
   983  * Retrieve HTML content for reply to comment link.
  1022  * Retrieve HTML content for reply to comment link.
  1008 		return;
  1047 		return;
  1009 
  1048 
  1010 	extract($args, EXTR_SKIP);
  1049 	extract($args, EXTR_SKIP);
  1011 
  1050 
  1012 	$comment = get_comment($comment);
  1051 	$comment = get_comment($comment);
       
  1052 	if ( empty($post) )
       
  1053 		$post = $comment->comment_post_ID;
  1013 	$post = get_post($post);
  1054 	$post = get_post($post);
  1014 
  1055 
  1015 	if ( !comments_open($post->ID) )
  1056 	if ( !comments_open($post->ID) )
  1016 		return false;
  1057 		return false;
  1017 
  1058 
  1018 	$link = '';
  1059 	$link = '';
  1019 
  1060 
  1020 	if ( get_option('comment_registration') && !$user_ID )
  1061 	if ( get_option('comment_registration') && !$user_ID )
  1021 		$link = '<a rel="nofollow" class="comment-reply-login" href="' . esc_url( wp_login_url( get_permalink() ) ) . '">' . $login_text . '</a>';
  1062 		$link = '<a rel="nofollow" class="comment-reply-login" href="' . esc_url( wp_login_url( get_permalink() ) ) . '">' . $login_text . '</a>';
  1022 	else
  1063 	else
  1023 		$link = "<a rel='nofollow' class='comment-reply-link' href='" . esc_url( add_query_arg( 'replytocom', $comment->comment_ID ) ) . "#" . $respond_id . "' onclick='return addComment.moveForm(\"$add_below-$comment->comment_ID\", \"$comment->comment_ID\", \"$respond_id\", \"$post->ID\")'>$reply_text</a>";
  1064 		$link = "<a class='comment-reply-link' href='" . esc_url( add_query_arg( 'replytocom', $comment->comment_ID ) ) . "#" . $respond_id . "' onclick='return addComment.moveForm(\"$add_below-$comment->comment_ID\", \"$comment->comment_ID\", \"$respond_id\", \"$post->ID\")'>$reply_text</a>";
  1024 	return apply_filters('comment_reply_link', $before . $link . $after, $args, $comment, $post);
  1065 	return apply_filters('comment_reply_link', $before . $link . $after, $args, $comment, $post);
  1025 }
  1066 }
  1026 
  1067 
  1027 /**
  1068 /**
  1028  * Displays the HTML content for reply to comment link.
  1069  * Displays the HTML content for reply to comment link.
  1050  * parameters.
  1091  * parameters.
  1051  *
  1092  *
  1052  * @since 2.7.0
  1093  * @since 2.7.0
  1053  *
  1094  *
  1054  * @param array $args Optional. Override default options.
  1095  * @param array $args Optional. Override default options.
  1055  * @param int|object $post Optional. Post that the comment is going to be displayed on.  Defaults to current post.
  1096  * @param int|object $post Optional. Post that the comment is going to be displayed on. Defaults to current post.
  1056  * @return string|bool|null Link to show comment form, if successful. False, if comments are closed.
  1097  * @return string|bool|null Link to show comment form, if successful. False, if comments are closed.
  1057  */
  1098  */
  1058 function get_post_reply_link($args = array(), $post = null) {
  1099 function get_post_reply_link($args = array(), $post = null) {
  1059 	global $user_ID;
  1100 	global $user_ID;
  1060 
  1101 
  1115 function cancel_comment_reply_link($text = '') {
  1156 function cancel_comment_reply_link($text = '') {
  1116 	echo get_cancel_comment_reply_link($text);
  1157 	echo get_cancel_comment_reply_link($text);
  1117 }
  1158 }
  1118 
  1159 
  1119 /**
  1160 /**
       
  1161  * Retrieve hidden input HTML for replying to comments.
       
  1162  *
       
  1163  * @since 3.0.0
       
  1164  *
       
  1165  * @return string Hidden input HTML for replying to comments
       
  1166  */
       
  1167 function get_comment_id_fields( $id = 0 ) {
       
  1168 	if ( empty( $id ) )
       
  1169 		$id = get_the_ID();
       
  1170 
       
  1171 	$replytoid = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0;
       
  1172 	$result  = "<input type='hidden' name='comment_post_ID' value='$id' id='comment_post_ID' />\n";
       
  1173 	$result .= "<input type='hidden' name='comment_parent' id='comment_parent' value='$replytoid' />\n";
       
  1174 	return apply_filters('comment_id_fields', $result, $id, $replytoid);
       
  1175 }
       
  1176 
       
  1177 /**
  1120  * Output hidden input HTML for replying to comments.
  1178  * Output hidden input HTML for replying to comments.
  1121  *
  1179  *
  1122  * @since 2.7.0
  1180  * @since 2.7.0
  1123  */
  1181  * @see get_comment_id_fields() Echoes result
  1124 function comment_id_fields() {
  1182  */
  1125 	global $id;
  1183 function comment_id_fields( $id = 0 ) {
  1126 
  1184 	echo get_comment_id_fields( $id );
  1127 	$replytoid = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0;
       
  1128 	echo "<input type='hidden' name='comment_post_ID' value='$id' id='comment_post_ID' />\n";
       
  1129 	echo "<input type='hidden' name='comment_parent' id='comment_parent' value='$replytoid' />\n";
       
  1130 }
  1185 }
  1131 
  1186 
  1132 /**
  1187 /**
  1133  * Display text based on comment reply status. Only affects users with Javascript disabled.
  1188  * Display text based on comment reply status. Only affects users with Javascript disabled.
  1134  *
  1189  *
  1136  *
  1191  *
  1137  * @param string $noreplytext Optional. Text to display when not replying to a comment.
  1192  * @param string $noreplytext Optional. Text to display when not replying to a comment.
  1138  * @param string $replytext Optional. Text to display when replying to a comment. Accepts "%s" for the author of the comment being replied to.
  1193  * @param string $replytext Optional. Text to display when replying to a comment. Accepts "%s" for the author of the comment being replied to.
  1139  * @param string $linktoparent Optional. Boolean to control making the author's name a link to their comment.
  1194  * @param string $linktoparent Optional. Boolean to control making the author's name a link to their comment.
  1140  */
  1195  */
  1141 function comment_form_title( $noreplytext = false, $replytext = false, $linktoparent = TRUE ) {
  1196 function comment_form_title( $noreplytext = false, $replytext = false, $linktoparent = true ) {
  1142 	global $comment;
  1197 	global $comment;
  1143 
  1198 
  1144 	if ( false === $noreplytext ) $noreplytext = __( 'Leave a Reply' );
  1199 	if ( false === $noreplytext ) $noreplytext = __( 'Leave a Reply' );
  1145 	if ( false === $replytext ) $replytext = __( 'Leave a Reply to %s' );
  1200 	if ( false === $replytext ) $replytext = __( 'Leave a Reply to %s' );
  1146 
  1201 
  1158 /**
  1213 /**
  1159  * HTML comment list class.
  1214  * HTML comment list class.
  1160  *
  1215  *
  1161  * @package WordPress
  1216  * @package WordPress
  1162  * @uses Walker
  1217  * @uses Walker
  1163  * @since unknown
  1218  * @since 2.7.0
  1164  */
  1219  */
  1165 class Walker_Comment extends Walker {
  1220 class Walker_Comment extends Walker {
  1166 	/**
  1221 	/**
  1167 	 * @see Walker::$tree_type
  1222 	 * @see Walker::$tree_type
  1168 	 * @since unknown
  1223 	 * @since 2.7.0
  1169 	 * @var string
  1224 	 * @var string
  1170 	 */
  1225 	 */
  1171 	var $tree_type = 'comment';
  1226 	var $tree_type = 'comment';
  1172 
  1227 
  1173 	/**
  1228 	/**
  1174 	 * @see Walker::$db_fields
  1229 	 * @see Walker::$db_fields
  1175 	 * @since unknown
  1230 	 * @since 2.7.0
  1176 	 * @var array
  1231 	 * @var array
  1177 	 */
  1232 	 */
  1178 	var $db_fields = array ('parent' => 'comment_parent', 'id' => 'comment_ID');
  1233 	var $db_fields = array ('parent' => 'comment_parent', 'id' => 'comment_ID');
  1179 
  1234 
  1180 	/**
  1235 	/**
  1181 	 * @see Walker::start_lvl()
  1236 	 * @see Walker::start_lvl()
  1182 	 * @since unknown
  1237 	 * @since 2.7.0
  1183 	 *
  1238 	 *
  1184 	 * @param string $output Passed by reference. Used to append additional content.
  1239 	 * @param string $output Passed by reference. Used to append additional content.
  1185 	 * @param int $depth Depth of comment.
  1240 	 * @param int $depth Depth of comment.
  1186 	 * @param array $args Uses 'style' argument for type of HTML list.
  1241 	 * @param array $args Uses 'style' argument for type of HTML list.
  1187 	 */
  1242 	 */
  1188 	function start_lvl(&$output, $depth, $args) {
  1243 	function start_lvl( &$output, $depth = 0, $args = array() ) {
  1189 		$GLOBALS['comment_depth'] = $depth + 1;
  1244 		$GLOBALS['comment_depth'] = $depth + 1;
  1190 
  1245 
  1191 		switch ( $args['style'] ) {
  1246 		switch ( $args['style'] ) {
  1192 			case 'div':
  1247 			case 'div':
  1193 				break;
  1248 				break;
  1201 		}
  1256 		}
  1202 	}
  1257 	}
  1203 
  1258 
  1204 	/**
  1259 	/**
  1205 	 * @see Walker::end_lvl()
  1260 	 * @see Walker::end_lvl()
  1206 	 * @since unknown
  1261 	 * @since 2.7.0
  1207 	 *
  1262 	 *
  1208 	 * @param string $output Passed by reference. Used to append additional content.
  1263 	 * @param string $output Passed by reference. Used to append additional content.
  1209 	 * @param int $depth Depth of comment.
  1264 	 * @param int $depth Depth of comment.
  1210 	 * @param array $args Will only append content if style argument value is 'ol' or 'ul'.
  1265 	 * @param array $args Will only append content if style argument value is 'ol' or 'ul'.
  1211 	 */
  1266 	 */
  1212 	function end_lvl(&$output, $depth, $args) {
  1267 	function end_lvl( &$output, $depth = 0, $args = array() ) {
  1213 		$GLOBALS['comment_depth'] = $depth + 1;
  1268 		$GLOBALS['comment_depth'] = $depth + 1;
  1214 
  1269 
  1215 		switch ( $args['style'] ) {
  1270 		switch ( $args['style'] ) {
  1216 			case 'div':
  1271 			case 'div':
  1217 				break;
  1272 				break;
  1224 				break;
  1279 				break;
  1225 		}
  1280 		}
  1226 	}
  1281 	}
  1227 
  1282 
  1228 	/**
  1283 	/**
       
  1284 	 * This function is designed to enhance Walker::display_element() to
       
  1285 	 * display children of higher nesting levels than selected inline on
       
  1286 	 * the highest depth level displayed. This prevents them being orphaned
       
  1287 	 * at the end of the comment list.
       
  1288 	 *
       
  1289 	 * Example: max_depth = 2, with 5 levels of nested content.
       
  1290 	 * 1
       
  1291 	 *  1.1
       
  1292 	 *    1.1.1
       
  1293 	 *    1.1.1.1
       
  1294 	 *    1.1.1.1.1
       
  1295 	 *    1.1.2
       
  1296 	 *    1.1.2.1
       
  1297 	 * 2
       
  1298 	 *  2.2
       
  1299 	 *
       
  1300 	 */
       
  1301 	function display_element( $element, &$children_elements, $max_depth, $depth=0, $args, &$output ) {
       
  1302 
       
  1303 		if ( !$element )
       
  1304 			return;
       
  1305 
       
  1306 		$id_field = $this->db_fields['id'];
       
  1307 		$id = $element->$id_field;
       
  1308 
       
  1309 		parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
       
  1310 
       
  1311 		// If we're at the max depth, and the current element still has children, loop over those and display them at this level
       
  1312 		// This is to prevent them being orphaned to the end of the list.
       
  1313 		if ( $max_depth <= $depth + 1 && isset( $children_elements[$id]) ) {
       
  1314 			foreach ( $children_elements[ $id ] as $child )
       
  1315 				$this->display_element( $child, $children_elements, $max_depth, $depth, $args, $output );
       
  1316 
       
  1317 			unset( $children_elements[ $id ] );
       
  1318 		}
       
  1319 
       
  1320 	}
       
  1321 
       
  1322 	/**
  1229 	 * @see Walker::start_el()
  1323 	 * @see Walker::start_el()
  1230 	 * @since unknown
  1324 	 * @since 2.7.0
  1231 	 *
  1325 	 *
  1232 	 * @param string $output Passed by reference. Used to append additional content.
  1326 	 * @param string $output Passed by reference. Used to append additional content.
  1233 	 * @param object $comment Comment data object.
  1327 	 * @param object $comment Comment data object.
  1234 	 * @param int $depth Depth of comment in reference to parents.
  1328 	 * @param int $depth Depth of comment in reference to parents.
  1235 	 * @param array $args
  1329 	 * @param array $args
  1236 	 */
  1330 	 */
  1237 	function start_el(&$output, $comment, $depth, $args) {
  1331 	function start_el( &$output, $comment, $depth, $args, $id = 0 ) {
  1238 		$depth++;
  1332 		$depth++;
  1239 		$GLOBALS['comment_depth'] = $depth;
  1333 		$GLOBALS['comment_depth'] = $depth;
  1240 
  1334 
  1241 		if ( !empty($args['callback']) ) {
  1335 		if ( !empty($args['callback']) ) {
  1242 			call_user_func($args['callback'], $comment, $args, $depth);
  1336 			call_user_func($args['callback'], $comment, $args, $depth);
  1261 		<div class="comment-author vcard">
  1355 		<div class="comment-author vcard">
  1262 		<?php if ($args['avatar_size'] != 0) echo get_avatar( $comment, $args['avatar_size'] ); ?>
  1356 		<?php if ($args['avatar_size'] != 0) echo get_avatar( $comment, $args['avatar_size'] ); ?>
  1263 		<?php printf(__('<cite class="fn">%s</cite> <span class="says">says:</span>'), get_comment_author_link()) ?>
  1357 		<?php printf(__('<cite class="fn">%s</cite> <span class="says">says:</span>'), get_comment_author_link()) ?>
  1264 		</div>
  1358 		</div>
  1265 <?php if ($comment->comment_approved == '0') : ?>
  1359 <?php if ($comment->comment_approved == '0') : ?>
  1266 		<em><?php _e('Your comment is awaiting moderation.') ?></em>
  1360 		<em class="comment-awaiting-moderation"><?php _e('Your comment is awaiting moderation.') ?></em>
  1267 		<br />
  1361 		<br />
  1268 <?php endif; ?>
  1362 <?php endif; ?>
  1269 
  1363 
  1270 		<div class="comment-meta commentmetadata"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>"><?php printf(__('%1$s at %2$s'), get_comment_date(),  get_comment_time()) ?></a><?php edit_comment_link(__('(Edit)'),'&nbsp;&nbsp;','') ?></div>
  1364 		<div class="comment-meta commentmetadata"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>">
       
  1365 			<?php
       
  1366 				/* translators: 1: date, 2: time */
       
  1367 				printf( __('%1$s at %2$s'), get_comment_date(),  get_comment_time()) ?></a><?php edit_comment_link(__('(Edit)'),'&nbsp;&nbsp;','' );
       
  1368 			?>
       
  1369 		</div>
  1271 
  1370 
  1272 		<?php comment_text() ?>
  1371 		<?php comment_text() ?>
  1273 
  1372 
  1274 		<div class="reply">
  1373 		<div class="reply">
  1275 		<?php comment_reply_link(array_merge( $args, array('add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
  1374 		<?php comment_reply_link(array_merge( $args, array('add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
  1280 <?php
  1379 <?php
  1281 	}
  1380 	}
  1282 
  1381 
  1283 	/**
  1382 	/**
  1284 	 * @see Walker::end_el()
  1383 	 * @see Walker::end_el()
  1285 	 * @since unknown
  1384 	 * @since 2.7.0
  1286 	 *
  1385 	 *
  1287 	 * @param string $output Passed by reference. Used to append additional content.
  1386 	 * @param string $output Passed by reference. Used to append additional content.
  1288 	 * @param object $comment
  1387 	 * @param object $comment
  1289 	 * @param int $depth Depth of comment.
  1388 	 * @param int $depth Depth of comment.
  1290 	 * @param array $args
  1389 	 * @param array $args
  1291 	 */
  1390 	 */
  1292 	function end_el(&$output, $comment, $depth, $args) {
  1391 	function end_el(&$output, $comment, $depth = 0, $args = array() ) {
  1293 		if ( !empty($args['end-callback']) ) {
  1392 		if ( !empty($args['end-callback']) ) {
  1294 			call_user_func($args['end-callback'], $comment, $args, $depth);
  1393 			call_user_func($args['end-callback'], $comment, $args, $depth);
  1295 			return;
  1394 			return;
  1296 		}
  1395 		}
  1297 		if ( 'div' == $args['style'] )
  1396 		if ( 'div' == $args['style'] )
  1309  *
  1408  *
  1310  * @since 2.7.0
  1409  * @since 2.7.0
  1311  * @uses Walker_Comment
  1410  * @uses Walker_Comment
  1312  *
  1411  *
  1313  * @param string|array $args Formatting options
  1412  * @param string|array $args Formatting options
  1314  * @param array $comments Optional array of comment objects.  Defaults to $wp_query->comments
  1413  * @param array $comments Optional array of comment objects. Defaults to $wp_query->comments
  1315  */
  1414  */
  1316 function wp_list_comments($args = array(), $comments = null ) {
  1415 function wp_list_comments($args = array(), $comments = null ) {
  1317 	global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop;
  1416 	global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop;
  1318 
  1417 
  1319 	$in_comment_loop = true;
  1418 	$in_comment_loop = true;
  1370 
  1469 
  1371 	if ( '' === $r['page'] ) {
  1470 	if ( '' === $r['page'] ) {
  1372 		if ( empty($overridden_cpage) ) {
  1471 		if ( empty($overridden_cpage) ) {
  1373 			$r['page'] = get_query_var('cpage');
  1472 			$r['page'] = get_query_var('cpage');
  1374 		} else {
  1473 		} else {
  1375 			$threaded = ( -1 == $r['max_depth'] ) ? false : true;
  1474 			$threaded = ( -1 != $r['max_depth'] );
  1376 			$r['page'] = ( 'newest' == get_option('default_comments_page') ) ? get_comment_pages_count($_comments, $r['per_page'], $threaded) : 1;
  1475 			$r['page'] = ( 'newest' == get_option('default_comments_page') ) ? get_comment_pages_count($_comments, $r['per_page'], $threaded) : 1;
  1377 			set_query_var( 'cpage', $r['page'] );
  1476 			set_query_var( 'cpage', $r['page'] );
  1378 		}
  1477 		}
  1379 	}
  1478 	}
  1380 	// Validation check
  1479 	// Validation check
  1381 	$r['page'] = intval($r['page']);
  1480 	$r['page'] = intval($r['page']);
  1382 	if ( 0 == $r['page'] && 0 != $r['per_page'] )
  1481 	if ( 0 == $r['page'] && 0 != $r['per_page'] )
  1383 		$r['page'] = 1;
  1482 		$r['page'] = 1;
  1384 
  1483 
  1385 	if ( null === $r['reverse_top_level'] )
  1484 	if ( null === $r['reverse_top_level'] )
  1386 		$r['reverse_top_level'] = ( 'desc' == get_option('comment_order') ) ? TRUE : FALSE;
  1485 		$r['reverse_top_level'] = ( 'desc' == get_option('comment_order') );
  1387 
  1486 
  1388 	extract( $r, EXTR_SKIP );
  1487 	extract( $r, EXTR_SKIP );
  1389 
  1488 
  1390 	if ( empty($walker) )
  1489 	if ( empty($walker) )
  1391 		$walker = new Walker_Comment;
  1490 		$walker = new Walker_Comment;
  1394 	$wp_query->max_num_comment_pages = $walker->max_pages;
  1493 	$wp_query->max_num_comment_pages = $walker->max_pages;
  1395 
  1494 
  1396 	$in_comment_loop = false;
  1495 	$in_comment_loop = false;
  1397 }
  1496 }
  1398 
  1497 
  1399 ?>
  1498 /**
       
  1499  * Outputs a complete commenting form for use within a template.
       
  1500  * Most strings and form fields may be controlled through the $args array passed
       
  1501  * into the function, while you may also choose to use the comment_form_default_fields
       
  1502  * filter to modify the array of default fields if you'd just like to add a new
       
  1503  * one or remove a single field. All fields are also individually passed through
       
  1504  * a filter of the form comment_form_field_$name where $name is the key used
       
  1505  * in the array of fields.
       
  1506  *
       
  1507  * @since 3.0.0
       
  1508  * @param array $args Options for strings, fields etc in the form
       
  1509  * @param mixed $post_id Post ID to generate the form for, uses the current post if null
       
  1510  * @return void
       
  1511  */
       
  1512 function comment_form( $args = array(), $post_id = null ) {
       
  1513 	global $id;
       
  1514 
       
  1515 	if ( null === $post_id )
       
  1516 		$post_id = $id;
       
  1517 	else
       
  1518 		$id = $post_id;
       
  1519 
       
  1520 	$commenter = wp_get_current_commenter();
       
  1521 	$user = wp_get_current_user();
       
  1522 	$user_identity = $user->exists() ? $user->display_name : '';
       
  1523 
       
  1524 	$req = get_option( 'require_name_email' );
       
  1525 	$aria_req = ( $req ? " aria-required='true'" : '' );
       
  1526 	$fields =  array(
       
  1527 		'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) .
       
  1528 		            '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>',
       
  1529 		'email'  => '<p class="comment-form-email"><label for="email">' . __( 'Email' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) .
       
  1530 		            '<input id="email" name="email" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>',
       
  1531 		'url'    => '<p class="comment-form-url"><label for="url">' . __( 'Website' ) . '</label>' .
       
  1532 		            '<input id="url" name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></p>',
       
  1533 	);
       
  1534 
       
  1535 	$required_text = sprintf( ' ' . __('Required fields are marked %s'), '<span class="required">*</span>' );
       
  1536 	$defaults = array(
       
  1537 		'fields'               => apply_filters( 'comment_form_default_fields', $fields ),
       
  1538 		'comment_field'        => '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label><textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea></p>',
       
  1539 		'must_log_in'          => '<p class="must-log-in">' . sprintf( __( 'You must be <a href="%s">logged in</a> to post a comment.' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>',
       
  1540 		'logged_in_as'         => '<p class="logged-in-as">' . sprintf( __( 'Logged in as <a href="%1$s">%2$s</a>. <a href="%3$s" title="Log out of this account">Log out?</a>' ), admin_url( 'profile.php' ), $user_identity, wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>',
       
  1541 		'comment_notes_before' => '<p class="comment-notes">' . __( 'Your email address will not be published.' ) . ( $req ? $required_text : '' ) . '</p>',
       
  1542 		'comment_notes_after'  => '<p class="form-allowed-tags">' . sprintf( __( 'You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes: %s' ), ' <code>' . allowed_tags() . '</code>' ) . '</p>',
       
  1543 		'id_form'              => 'commentform',
       
  1544 		'id_submit'            => 'submit',
       
  1545 		'title_reply'          => __( 'Leave a Reply' ),
       
  1546 		'title_reply_to'       => __( 'Leave a Reply to %s' ),
       
  1547 		'cancel_reply_link'    => __( 'Cancel reply' ),
       
  1548 		'label_submit'         => __( 'Post Comment' ),
       
  1549 	);
       
  1550 
       
  1551 	$args = wp_parse_args( $args, apply_filters( 'comment_form_defaults', $defaults ) );
       
  1552 
       
  1553 	?>
       
  1554 		<?php if ( comments_open( $post_id ) ) : ?>
       
  1555 			<?php do_action( 'comment_form_before' ); ?>
       
  1556 			<div id="respond">
       
  1557 				<h3 id="reply-title"><?php comment_form_title( $args['title_reply'], $args['title_reply_to'] ); ?> <small><?php cancel_comment_reply_link( $args['cancel_reply_link'] ); ?></small></h3>
       
  1558 				<?php if ( get_option( 'comment_registration' ) && !is_user_logged_in() ) : ?>
       
  1559 					<?php echo $args['must_log_in']; ?>
       
  1560 					<?php do_action( 'comment_form_must_log_in_after' ); ?>
       
  1561 				<?php else : ?>
       
  1562 					<form action="<?php echo site_url( '/wp-comments-post.php' ); ?>" method="post" id="<?php echo esc_attr( $args['id_form'] ); ?>">
       
  1563 						<?php do_action( 'comment_form_top' ); ?>
       
  1564 						<?php if ( is_user_logged_in() ) : ?>
       
  1565 							<?php echo apply_filters( 'comment_form_logged_in', $args['logged_in_as'], $commenter, $user_identity ); ?>
       
  1566 							<?php do_action( 'comment_form_logged_in_after', $commenter, $user_identity ); ?>
       
  1567 						<?php else : ?>
       
  1568 							<?php echo $args['comment_notes_before']; ?>
       
  1569 							<?php
       
  1570 							do_action( 'comment_form_before_fields' );
       
  1571 							foreach ( (array) $args['fields'] as $name => $field ) {
       
  1572 								echo apply_filters( "comment_form_field_{$name}", $field ) . "\n";
       
  1573 							}
       
  1574 							do_action( 'comment_form_after_fields' );
       
  1575 							?>
       
  1576 						<?php endif; ?>
       
  1577 						<?php echo apply_filters( 'comment_form_field_comment', $args['comment_field'] ); ?>
       
  1578 						<?php echo $args['comment_notes_after']; ?>
       
  1579 						<p class="form-submit">
       
  1580 							<input name="submit" type="submit" id="<?php echo esc_attr( $args['id_submit'] ); ?>" value="<?php echo esc_attr( $args['label_submit'] ); ?>" />
       
  1581 							<?php comment_id_fields( $post_id ); ?>
       
  1582 						</p>
       
  1583 						<?php do_action( 'comment_form', $post_id ); ?>
       
  1584 					</form>
       
  1585 				<?php endif; ?>
       
  1586 			</div><!-- #respond -->
       
  1587 			<?php do_action( 'comment_form_after' ); ?>
       
  1588 		<?php else : ?>
       
  1589 			<?php do_action( 'comment_form_comments_closed' ); ?>
       
  1590 		<?php endif; ?>
       
  1591 	<?php
       
  1592 }