2006-04-19 06:13:28 -04:00
< ? php
/*
* Comment template functions .
*/
function get_comment_author () {
global $comment ;
if ( empty ( $comment -> comment_author ) )
$author = __ ( 'Anonymous' );
else
$author = $comment -> comment_author ;
return apply_filters ( 'get_comment_author' , $author );
}
function comment_author () {
$author = apply_filters ( 'comment_author' , get_comment_author () );
echo $author ;
}
function get_comment_author_email () {
global $comment ;
return apply_filters ( 'get_comment_author_email' , $comment -> comment_author_email );
}
function comment_author_email () {
echo apply_filters ( 'author_email' , get_comment_author_email () );
}
function comment_author_email_link ( $linktext = '' , $before = '' , $after = '' ) {
global $comment ;
$email = apply_filters ( 'comment_email' , $comment -> comment_author_email );
if (( ! empty ( $email )) && ( $email != '@' )) {
$display = ( $linktext != '' ) ? $linktext : $email ;
echo $before ;
echo " <a href='mailto: $email '> $display </a> " ;
echo $after ;
}
}
function get_comment_author_link () {
$url = get_comment_author_url ();
$author = get_comment_author ();
if ( empty ( $url ) || 'http://' == $url )
$return = $author ;
else
$return = " <a href=' $url ' rel='external nofollow'> $author </a> " ;
return apply_filters ( 'get_comment_author_link' , $return );
}
function comment_author_link () {
echo get_comment_author_link ();
}
function get_comment_author_IP () {
global $comment ;
return apply_filters ( 'get_comment_author_IP' , $comment -> comment_author_IP );
}
function comment_author_IP () {
echo get_comment_author_IP ();
}
function get_comment_author_url () {
global $comment ;
return apply_filters ( 'get_comment_author_url' , $comment -> comment_author_url );
}
function comment_author_url () {
echo apply_filters ( 'comment_url' , get_comment_author_url ());
}
function get_comment_author_url_link ( $linktext = '' , $before = '' , $after = '' ) {
$url = get_comment_author_url ();
$display = ( $linktext != '' ) ? $linktext : $url ;
$display = str_replace ( 'http://www.' , '' , $display );
$display = str_replace ( 'http://' , '' , $display );
if ( '/' == substr ( $display , - 1 ) )
$display = substr ( $display , 0 , - 1 );
$return = " $before <a href=' $url ' rel='external'> $display </a> $after " ;
return apply_filters ( 'get_comment_author_url_link' , $return );
}
function comment_author_url_link ( $linktext = '' , $before = '' , $after = '' ) {
echo get_comment_author_url_link ( $linktext , $before , $after );
}
function get_comment_date ( $d = '' ) {
global $comment ;
if ( '' == $d )
2006-08-30 17:46:31 -04:00
$date = mysql2date ( get_option ( 'date_format' ), $comment -> comment_date );
2006-04-19 06:13:28 -04:00
else
$date = mysql2date ( $d , $comment -> comment_date );
2006-11-19 20:46:20 -05:00
return apply_filters ( 'get_comment_date' , $date , $d );
2006-04-19 06:13:28 -04:00
}
function comment_date ( $d = '' ) {
echo get_comment_date ( $d );
}
function get_comment_excerpt () {
global $comment ;
$comment_text = strip_tags ( $comment -> comment_content );
$blah = explode ( ' ' , $comment_text );
if ( count ( $blah ) > 20 ) {
$k = 20 ;
$use_dotdotdot = 1 ;
} else {
$k = count ( $blah );
$use_dotdotdot = 0 ;
}
$excerpt = '' ;
for ( $i = 0 ; $i < $k ; $i ++ ) {
$excerpt .= $blah [ $i ] . ' ' ;
}
$excerpt .= ( $use_dotdotdot ) ? '...' : '' ;
return apply_filters ( 'get_comment_excerpt' , $excerpt );
}
function comment_excerpt () {
echo apply_filters ( 'comment_excerpt' , get_comment_excerpt () );
}
function get_comment_ID () {
global $comment ;
return apply_filters ( 'get_comment_ID' , $comment -> comment_ID );
}
function comment_ID () {
echo get_comment_ID ();
}
function get_comment_link () {
global $comment ;
return get_permalink ( $comment -> comment_post_ID ) . '#comment-' . $comment -> comment_ID ;
}
function get_comments_link () {
return get_permalink () . '#comments' ;
}
function comments_link ( $file = '' , $echo = true ) {
2006-11-19 02:56:05 -05:00
echo get_comments_link ();
2006-04-19 06:13:28 -04:00
}
function get_comments_number ( $post_id = 0 ) {
$post_id = ( int ) $post_id ;
if ( ! $post_id )
2007-03-22 20:59:21 -04:00
$post_id = ( int ) $id ;
2006-04-19 06:13:28 -04:00
$post = get_post ( $post_id );
if ( ! isset ( $post -> comment_count ) )
$count = 0 ;
else
$count = $post -> comment_count ;
return apply_filters ( 'get_comments_number' , $count );
}
2007-03-25 19:18:19 -04:00
function comments_number ( $zero = false , $one = false , $more = false , $deprecated = '' ) {
2006-11-19 02:45:28 -05:00
global $id ;
$number = get_comments_number ( $id );
if ( $number > 1 )
$output = str_replace ( '%' , $number , ( false === $more ) ? __ ( '% Comments' ) : $more );
elseif ( $number == 0 )
$output = ( false === $zero ) ? __ ( 'No Comments' ) : $zero ;
else // must be one
$output = ( false === $one ) ? __ ( '1 Comment' ) : $one ;
echo apply_filters ( 'comments_number' , $output , $number );
2006-04-19 06:13:28 -04:00
}
function get_comment_text () {
global $comment ;
return apply_filters ( 'get_comment_text' , $comment -> comment_content );
}
function comment_text () {
echo apply_filters ( 'comment_text' , get_comment_text () );
}
function get_comment_time ( $d = '' , $gmt = false ) {
global $comment ;
$comment_date = $gmt ? $comment -> comment_date_gmt : $comment -> comment_date ;
if ( '' == $d )
2006-08-30 17:46:31 -04:00
$date = mysql2date ( get_option ( 'time_format' ), $comment_date );
2006-04-19 06:13:28 -04:00
else
$date = mysql2date ( $d , $comment_date );
2006-11-19 20:46:20 -05:00
return apply_filters ( 'get_comment_time' , $date , $d , $gmt );
2006-04-19 06:13:28 -04:00
}
function comment_time ( $d = '' ) {
echo get_comment_time ( $d );
}
function get_comment_type () {
global $comment ;
if ( '' == $comment -> comment_type )
$comment -> comment_type = 'comment' ;
return apply_filters ( 'get_comment_type' , $comment -> comment_type );
}
function comment_type ( $commenttxt = 'Comment' , $trackbacktxt = 'Trackback' , $pingbacktxt = 'Pingback' ) {
$type = get_comment_type ();
switch ( $type ) {
case 'trackback' :
echo $trackbacktxt ;
break ;
case 'pingback' :
echo $pingbacktxt ;
break ;
default :
echo $commenttxt ;
}
}
function get_trackback_url () {
global $id ;
2007-08-29 19:08:44 -04:00
if ( '' != get_option ( 'permalink_structure' ) ) {
2007-03-10 01:18:43 -05:00
$tb_url = trailingslashit ( get_permalink ()) . user_trailingslashit ( 'trackback' , 'single_trackback' );
2007-08-29 19:08:44 -04:00
} else {
$tb_url = get_option ( 'siteurl' ) . '/wp-trackback.php?p=' . $id ;
}
2007-03-26 19:40:49 -04:00
return apply_filters ( 'trackback_url' , $tb_url );
2006-04-19 06:13:28 -04:00
}
2007-08-29 19:08:44 -04:00
function trackback_url ( $deprecated = true ) { // remove backwards compat in 2.4
if ( $deprecated ) echo get_trackback_url ();
else return get_trackback_url ();
2006-04-19 06:13:28 -04:00
}
function trackback_rdf ( $timezone = 0 ) {
2007-06-01 19:10:03 -04:00
if ( stripos ( $_SERVER [ 'HTTP_USER_AGENT' ], 'W3C_Validator' ) === false ) {
2007-03-07 00:29:15 -05:00
echo ' < rdf : RDF xmlns : rdf = " http://www.w3.org/1999/02/22-rdf-syntax-ns# "
xmlns : dc = " http://purl.org/dc/elements/1.1/ "
xmlns : trackback = " http://madskills.com/public/xml/rss/module/trackback/ " >
< rdf : Description rdf : about = " ';
the_permalink ();
echo '"' . " \n " ;
echo ' dc:identifier="' ;
the_permalink ();
echo '"' . " \n " ;
echo ' dc:title="' . str_replace ( '--' , '--' , wptexturize ( strip_tags ( get_the_title ()))) . '"' . " \n " ;
2007-08-29 19:08:44 -04:00
echo ' trackback:ping="' . get_trackback_url () . '"' . " /> \n " ;
2007-03-07 00:29:15 -05:00
echo '</rdf:RDF>' ;
2006-04-19 06:13:28 -04:00
}
}
function comments_open () {
global $post ;
if ( 'open' == $post -> comment_status )
return true ;
else
return false ;
}
function pings_open () {
global $post ;
2006-11-19 02:56:05 -05:00
if ( 'open' == $post -> ping_status )
2006-04-19 06:13:28 -04:00
return true ;
else
return false ;
}
2007-03-14 19:10:57 -04:00
function wp_comment_form_unfiltered_html_nonce () {
global $post ;
if ( current_user_can ( 'unfiltered_html' ) )
wp_nonce_field ( 'unfiltered-html-comment_' . $post -> ID , '_wp_unfiltered_html_comment' , false );
}
2006-04-19 06:13:28 -04:00
function comments_template ( $file = '/comments.php' ) {
global $wp_query , $withcomments , $post , $wpdb , $id , $comment , $user_login , $user_ID , $user_identity ;
2006-06-22 16:52:12 -04:00
if ( ! ( is_single () || is_page () || $withcomments ) )
return ;
2006-08-30 17:46:31 -04:00
$req = get_option ( 'require_name_email' );
2006-06-22 16:52:12 -04:00
$commenter = wp_get_current_commenter ();
2007-06-14 18:45:40 -04:00
extract ( $commenter , EXTR_SKIP );
2006-04-19 06:13:28 -04:00
// TODO: Use API instead of SELECTs.
2007-04-10 23:12:11 -04:00
if ( $user_ID ) {
2007-09-27 03:34:15 -04:00
$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 ));
2007-09-03 19:32:58 -04:00
} else if ( empty ( $comment_author ) ) {
2007-09-27 03:34:15 -04:00
$comments = $wpdb -> get_results ( $wpdb -> prepare ( " SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1' ORDER BY comment_date " , $post -> ID ));
2006-04-19 06:13:28 -04:00
} else {
2007-09-27 03:34:15 -04:00
$comments = $wpdb -> get_results ( $wpdb -> prepare ( " SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND ( comment_approved = '1' OR ( comment_author = %s AND comment_author_email = %s AND comment_approved = '0' ) ) ORDER BY comment_date " , $post -> ID , $comment_author , $comment_author_email ));
2006-04-19 06:13:28 -04:00
}
2007-02-24 02:33:29 -05:00
// keep $comments for legacy's sake (remember $table*? ;) )
$comments = $wp_query -> comments = apply_filters ( 'comments_array' , $comments , $post -> ID );
$wp_query -> comment_count = count ( $wp_query -> comments );
2007-06-07 20:20:22 -04:00
update_comment_cache ( $comments );
2006-11-30 22:30:26 -05:00
2006-04-19 06:13:28 -04:00
define ( 'COMMENTS_TEMPLATE' , true );
$include = apply_filters ( 'comments_template' , TEMPLATEPATH . $file );
if ( file_exists ( $include ) )
require ( $include );
else
require ( ABSPATH . 'wp-content/themes/default/comments.php' );
}
function comments_popup_script ( $width = 400 , $height = 400 , $file = '' ) {
2007-12-06 14:49:33 -05:00
global $wpcommentspopupfile , $wpcommentsjavascript ;
2006-04-19 06:13:28 -04:00
if ( empty ( $file )) {
$wpcommentspopupfile = '' ; // Use the index.
} else {
$wpcommentspopupfile = $file ;
}
2006-11-19 02:56:05 -05:00
$wpcommentsjavascript = 1 ;
$javascript = " <script type='text/javascript'> \n function wpopen (macagna) { \n window.open(macagna, '_blank', 'width= $width ,height= $height ,scrollbars=yes,status=yes'); \n } \n </script> \n " ;
echo $javascript ;
2006-04-19 06:13:28 -04:00
}
function comments_popup_link ( $zero = 'No Comments' , $one = '1 Comment' , $more = '% Comments' , $CSSclass = '' , $none = 'Comments Off' ) {
2007-12-06 14:49:33 -05:00
global $id , $wpcommentspopupfile , $wpcommentsjavascript , $post ;
2006-04-19 06:13:28 -04:00
if ( is_single () || is_page () )
return ;
$number = get_comments_number ( $id );
if ( 0 == $number && 'closed' == $post -> comment_status && 'closed' == $post -> ping_status ) {
2007-04-01 11:57:13 -04:00
echo '<span' . (( ! empty ( $CSSclass )) ? ' class="' . $CSSclass . '"' : '' ) . '>' . $none . '</span>' ;
2006-04-19 06:13:28 -04:00
return ;
}
if ( ! empty ( $post -> post_password ) ) { // if there's a password
if ( $_COOKIE [ 'wp-postpass_' . COOKIEHASH ] != $post -> post_password ) { // and it doesn't match the cookie
echo ( __ ( 'Enter your password to view comments' ));
return ;
}
}
echo '<a href="' ;
if ( $wpcommentsjavascript ) {
if ( empty ( $wpcommentspopupfile ) )
2006-08-30 17:46:31 -04:00
$home = get_option ( 'home' );
2006-04-19 06:13:28 -04:00
else
2006-08-30 17:46:31 -04:00
$home = get_option ( 'siteurl' );
2006-04-19 06:13:28 -04:00
echo $home . '/' . $wpcommentspopupfile . '?comments_popup=' . $id ;
echo '" onclick="wpopen(this.href); return false"' ;
} else { // if comments_popup_script() is not in the template, display simple comment link
if ( 0 == $number )
echo get_permalink () . '#respond' ;
else
comments_link ();
echo '"' ;
}
if ( ! empty ( $CSSclass )) {
echo ' class="' . $CSSclass . '"' ;
}
2007-06-25 13:48:35 -04:00
$title = attribute_escape ( get_the_title ());
2006-06-15 03:32:06 -04:00
echo ' title="' . sprintf ( __ ( 'Comment on %s' ), $title ) . '">' ;
2006-04-19 06:13:28 -04:00
comments_number ( $zero , $one , $more , $number );
echo '</a>' ;
}
?>