2004-01-27 10:58:01 +01:00
< ? php
2004-02-17 05:56:29 +01:00
// Default filters for these functions
add_filter ( 'comment_author' , 'wptexturize' );
add_filter ( 'comment_author' , 'convert_chars' );
2004-02-17 09:35:04 +01:00
add_filter ( 'comment_email' , 'antispambot' );
2004-02-17 05:56:29 +01:00
add_filter ( 'comment_url' , 'clean_url' );
add_filter ( 'comment_text' , 'convert_chars' );
add_filter ( 'comment_text' , 'make_clickable' );
2004-02-17 09:35:04 +01:00
add_filter ( 'comment_text' , 'wpautop' , 30 );
2004-02-17 05:56:29 +01:00
add_filter ( 'comment_text' , 'balanceTags' );
add_filter ( 'comment_text' , 'convert_smilies' , 20 );
2004-02-17 09:35:04 +01:00
add_filter ( 'comment_excerpt' , 'convert_chars' );
2004-06-10 09:42:48 +02:00
function comments_template () {
2004-07-28 04:43:54 +02:00
global $withcomments , $post , $wpdb , $id , $comment , $cookiehash ;
2004-06-10 10:40:58 +02:00
2004-07-28 04:43:54 +02:00
if ( is_single () || $withcomments ) :
2004-06-10 11:17:41 +02:00
$req = get_settings ( 'require_name_email' );
2004-06-11 10:02:40 +02:00
$comment_author = isset ( $_COOKIE [ 'comment_author_' . $cookiehash ]) ? trim ( stripslashes ( $_COOKIE [ 'comment_author_' . $cookiehash ])) : '' ;
$comment_author_email = isset ( $_COOKIE [ 'comment_author_email_' . $cookiehash ]) ? trim ( stripslashes ( $_COOKIE [ 'comment_author_email_' . $cookiehash ])) : '' ;
$comment_author_url = isset ( $_COOKIE [ 'comment_author_url_' . $cookiehash ]) ? trim ( stripslashes ( $_COOKIE [ 'comment_author_url_' . $cookiehash ])) : '' ;
2004-06-10 11:17:41 +02:00
$comments = $wpdb -> get_results ( " SELECT * FROM $wpdb->comments WHERE comment_post_ID = ' $post->ID ' AND comment_approved = '1' ORDER BY comment_date " );
2004-09-15 04:50:29 +02:00
$wp_template = get_settings ( 'template' );
if ( $wp_template == 'default' ) {
$wp_template = '' ;
} else {
$wp_template = ABSPATH . " wp-content/themes/ $wp_template /comments.php " ;
}
if ( ! empty ( $wp_template ) && file_exists ( $wp_template )) {
include ( $wp_template );
} else {
include ( ABSPATH . 'wp-comments.php' );
}
2004-06-10 11:17:41 +02:00
endif ;
2004-06-10 09:42:48 +02:00
}
2004-02-17 05:56:29 +01:00
function clean_url ( $url ) {
2004-04-23 06:03:10 +02:00
if ( '' == $url ) return $url ;
2004-02-17 05:56:29 +01:00
$url = preg_replace ( '|[^a-z0-9-~+_.?#=&;,/:]|i' , '' , $url );
$url = str_replace ( ';//' , '://' , $url );
$url = ( ! strstr ( $url , '://' )) ? 'http://' . $url : $url ;
$url = preg_replace ( '/&([^#])(?![a-z]{2,8};)/' , '&$1' , $url );
return $url ;
}
2004-01-27 10:58:01 +01:00
function comments_number ( $zero = 'No Comments' , $one = '1 Comment' , $more = '% Comments' , $number = '' ) {
2004-05-24 10:22:18 +02:00
global $id , $comment , $wpdb , $comment_count_cache ;
if ( '' == $comment_count_cache [ " $id " ]) $number = $wpdb -> get_var ( " SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = $id AND comment_approved = '1' " );
2004-04-27 01:54:52 +02:00
else $number = $comment_count_cache [ " $id " ];
2004-01-27 10:58:01 +01:00
if ( $number == 0 ) {
$blah = $zero ;
} elseif ( $number == 1 ) {
$blah = $one ;
} elseif ( $number > 1 ) {
$blah = str_replace ( '%' , $number , $more );
}
echo $blah ;
}
function comments_link ( $file = '' , $echo = true ) {
global $id , $pagenow ;
if ( $file == '' ) $file = $pagenow ;
if ( $file == '/' ) $file = '' ;
if ( ! $echo ) return get_permalink () . '#comments' ;
else echo get_permalink () . '#comments' ;
}
function comments_popup_script ( $width = 400 , $height = 400 , $file = 'wp-comments-popup.php' ) {
global $wpcommentspopupfile , $wptrackbackpopupfile , $wppingbackpopupfile , $wpcommentsjavascript ;
$wpcommentspopupfile = $file ;
$wpcommentsjavascript = 1 ;
2004-02-20 02:42:39 +01:00
$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 " ;
2004-01-27 10:58:01 +01:00
echo $javascript ;
}
function comments_popup_link ( $zero = 'No Comments' , $one = '1 Comment' , $more = '% Comments' , $CSSclass = '' , $none = 'Comments Off' ) {
2004-05-24 10:22:18 +02:00
global $id , $wpcommentspopupfile , $wpcommentsjavascript , $post , $wpdb , $cookiehash ;
2004-02-26 17:15:48 +01:00
global $querystring_start , $querystring_equal , $querystring_separator ;
2004-07-28 04:43:54 +02:00
global $comment_count_cache ;
if ( ! is_single ()) {
2004-01-27 10:58:01 +01:00
if ( '' == $comment_count_cache [ " $id " ]) {
2004-05-24 10:22:18 +02:00
$number = $wpdb -> get_var ( " SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_post_ID = $id AND comment_approved = '1'; " );
2004-01-27 10:58:01 +01:00
} else {
$number = $comment_count_cache [ " $id " ];
}
if ( 0 == $number && 'closed' == $post -> comment_status && 'closed' == $post -> ping_status ) {
echo $none ;
return ;
} else {
if ( ! empty ( $post -> post_password )) { // if there's a password
2004-04-21 00:56:47 +02:00
if ( $_COOKIE [ 'wp-postpass_' . $cookiehash ] != $post -> post_password ) { // and it doesn't match the cookie
2004-02-20 02:42:39 +01:00
echo ( 'Enter your password to view comments' );
2004-01-27 10:58:01 +01:00
return ;
}
}
echo '<a href="' ;
if ( $wpcommentsjavascript ) {
2004-02-26 17:15:48 +01:00
echo get_settings ( 'siteurl' ) . '/' . $wpcommentspopupfile . $querystring_start . 'p' . $querystring_equal . $id . $querystring_separator . 'c' . $querystring_equal . '1' ;
2004-01-27 10:58:01 +01:00
//echo get_permalink();
echo '" onclick="wpopen(this.href); return false"' ;
} else {
// if comments_popup_script() is not in the template, display simple comment link
comments_link ();
echo '"' ;
}
if ( ! empty ( $CSSclass )) {
echo ' class="' . $CSSclass . '"' ;
}
echo '>' ;
comments_number ( $zero , $one , $more , $number );
echo '</a>' ;
}
2004-01-28 09:40:58 +01:00
}
2004-01-27 10:58:01 +01:00
}
function comment_ID () {
2004-02-17 05:56:29 +01:00
global $comment ;
echo $comment -> comment_ID ;
2004-01-27 10:58:01 +01:00
}
function comment_author () {
2004-02-17 05:56:29 +01:00
global $comment ;
$author = apply_filters ( 'comment_author' , $comment -> comment_author );
if ( empty ( $author )) {
echo 'Anonymous' ;
} else {
echo $author ;
}
2004-01-27 10:58:01 +01:00
}
function comment_author_email () {
2004-02-17 05:56:29 +01:00
global $comment ;
echo apply_filters ( 'author_email' , $comment -> comment_author_email );
2004-01-27 10:58:01 +01:00
}
function comment_author_link () {
2004-02-17 05:56:29 +01:00
global $comment ;
$url = apply_filters ( 'comment_url' , $comment -> comment_author_url );
$author = apply_filters ( 'comment_author' , $comment -> comment_author );
2004-04-23 06:03:10 +02:00
if ( ! $author ) $author = 'Anonymous' ;
2004-01-27 10:58:01 +01:00
2004-04-23 06:03:10 +02:00
if ( empty ( $url )) :
echo $author ;
else :
echo " <a href=' $url ' rel='external'> $author </a> " ;
endif ;
2004-01-27 10:58:01 +01:00
}
function comment_type ( $commenttxt = 'Comment' , $trackbacktxt = 'Trackback' , $pingbacktxt = 'Pingback' ) {
2004-02-17 05:56:29 +01:00
global $comment ;
if ( preg_match ( '|<trackback />|' , $comment -> comment_content ))
echo $trackbacktxt ;
elseif ( preg_match ( '|<pingback />|' , $comment -> comment_content ))
echo $pingbacktxt ;
else
echo $commenttxt ;
2004-01-27 10:58:01 +01:00
}
function comment_author_url () {
2004-02-17 05:56:29 +01:00
global $comment ;
echo apply_filters ( 'comment_url' , $comment -> comment_author_url );
2004-01-27 10:58:01 +01:00
}
function comment_author_email_link ( $linktext = '' , $before = '' , $after = '' ) {
2004-02-17 05:56:29 +01:00
global $comment ;
$email = apply_filters ( 'comment_email' , $comment -> comment_author_email );
if (( ! empty ( $email )) && ( $email != '@' )) {
2004-06-18 02:22:09 +02:00
$display = ( $linktext != '' ) ? $linktext : $email ;
2004-02-17 05:56:29 +01:00
echo $before ;
echo " <a href='mailto: $email '> $display </a> " ;
echo $after ;
}
2004-01-27 10:58:01 +01:00
}
function comment_author_url_link ( $linktext = '' , $before = '' , $after = '' ) {
2004-02-17 05:56:29 +01:00
global $comment ;
$url = apply_filters ( 'comment_url' , $comment -> comment_author_url );
if (( ! empty ( $url )) && ( $url != 'http://' ) && ( $url != 'http://url' )) {
2004-06-18 02:22:09 +02:00
$display = ( $linktext != '' ) ? $linktext : $url ;
2004-02-21 16:22:34 +01:00
echo " $before <a href=' $url ' rel='external'> $display </a> $after " ;
2004-02-17 05:56:29 +01:00
}
2004-01-27 10:58:01 +01:00
}
function comment_author_IP () {
2004-02-17 05:56:29 +01:00
global $comment ;
echo $comment -> comment_author_IP ;
2004-01-27 10:58:01 +01:00
}
function comment_text () {
2004-02-17 05:56:29 +01:00
global $comment ;
$comment_text = str_replace ( '<trackback />' , '' , $comment -> comment_content );
$comment_text = str_replace ( '<pingback />' , '' , $comment_text );
echo apply_filters ( 'comment_text' , $comment_text );
2004-01-27 10:58:01 +01:00
}
2004-02-17 09:35:04 +01:00
function comment_excerpt () {
global $comment ;
$comment_text = str_replace ( '<trackback />' , '' , $comment -> comment_content );
$comment_text = str_replace ( '<pingback />' , '' , $comment_text );
$comment_text = strip_tags ( $comment_text );
$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 ) ? '...' : '' ;
echo apply_filters ( 'comment_excerpt' , $excerpt );
}
2004-01-27 10:58:01 +01:00
function comment_date ( $d = '' ) {
2004-02-17 05:56:29 +01:00
global $comment ;
if ( '' == $d ) {
2004-03-25 02:58:48 +01:00
echo mysql2date ( get_settings ( 'date_format' ), $comment -> comment_date );
2004-02-17 05:56:29 +01:00
} else {
2004-03-25 02:58:48 +01:00
echo mysql2date ( $d , $comment -> comment_date );
2004-02-17 05:56:29 +01:00
}
2004-01-27 10:58:01 +01:00
}
function comment_time ( $d = '' ) {
2004-02-17 05:56:29 +01:00
global $comment ;
if ( $d == '' ) {
2004-03-25 02:58:48 +01:00
echo mysql2date ( get_settings ( 'time_format' ), $comment -> comment_date );
2004-02-17 05:56:29 +01:00
} else {
2004-03-25 02:58:48 +01:00
echo mysql2date ( $d , $comment -> comment_date );
2004-02-17 05:56:29 +01:00
}
2004-01-27 10:58:01 +01:00
}
function comments_rss_link ( $link_text = 'Comments RSS' , $commentsrssfilename = 'wp-commentsrss2.php' ) {
2004-05-10 09:51:50 +02:00
$url = comments_rss ( $commentsrssfilename );
echo " <a href=' $url '> $link_text </a> " ;
}
function comments_rss ( $commentsrssfilename = 'wp-commentsrss2.php' ) {
2004-02-17 05:56:29 +01:00
global $id ;
2004-02-26 17:15:48 +01:00
global $querystring_start , $querystring_equal , $querystring_separator ;
2004-02-05 21:55:50 +01:00
2004-02-17 05:56:29 +01:00
if ( '' != get_settings ( 'permalink_structure' )) {
2004-05-10 09:51:50 +02:00
$url = trailingslashit ( get_permalink ()) . 'feed/' ;
2004-02-17 05:56:29 +01:00
} else {
2004-02-26 17:15:48 +01:00
$url = get_settings ( 'siteurl' ) . '/' . $commentsrssfilename . $querystring_start . 'p' . $querystring_equal . $id ;
2004-02-17 05:56:29 +01:00
}
2004-05-10 09:51:50 +02:00
return $url ;
2004-01-27 10:58:01 +01:00
}
function comment_author_rss () {
2004-02-17 05:56:29 +01:00
global $comment ;
if ( empty ( $comment -> comment_author )) {
echo 'Anonymous' ;
} else {
echo htmlspecialchars ( apply_filters ( 'comment_author' , $comment -> comment_author ));
}
2004-01-27 10:58:01 +01:00
}
function comment_text_rss () {
2004-02-17 05:56:29 +01:00
global $comment ;
$comment_text = str_replace ( '<trackback />' , '' , $comment -> comment_content );
$comment_text = str_replace ( '<pingback />' , '' , $comment_text );
$comment_text = apply_filters ( 'comment_text' , $comment_text );
$comment_text = strip_tags ( $comment_text );
$comment_text = htmlspecialchars ( $comment_text );
echo $comment_text ;
2004-01-27 10:58:01 +01:00
}
function comment_link_rss () {
2004-02-17 05:56:29 +01:00
global $comment ;
echo get_permalink ( $comment -> comment_post_ID ) . '#comments' ;
2004-01-27 10:58:01 +01:00
}
function permalink_comments_rss () {
2004-02-17 05:56:29 +01:00
global $comment ;
echo get_permalink ( $comment -> comment_post_ID );
2004-01-27 10:58:01 +01:00
}
function trackback_url ( $display = true ) {
2004-02-17 05:56:29 +01:00
global $id ;
$tb_url = get_settings ( 'siteurl' ) . '/wp-trackback.php/' . $id ;
if ( '' != get_settings ( 'permalink_structure' )) {
$tb_url = trailingslashit ( get_permalink ()) . 'trackback/' ;
}
if ( $display ) {
echo $tb_url ;
} else {
return $tb_url ;
}
2004-01-27 10:58:01 +01:00
}
function trackback_rdf ( $timezone = 0 ) {
2004-02-26 17:15:48 +01:00
global $id ;
if ( ! stristr ( $_SERVER [ 'HTTP_USER_AGENT' ], 'W3C_Validator' )) {
2004-02-17 05:56:29 +01: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 = " ';
2004-05-09 07:47:02 +02:00
the_permalink ();
2004-02-17 05:56:29 +01:00
echo '"' . " \n " ;
echo ' dc:identifier="' ;
2004-05-09 07:47:02 +02:00
the_permalink ();
2004-02-17 05:56:29 +01:00
echo '"' . " \n " ;
2004-05-05 08:32:49 +02:00
echo ' dc:title="' . str_replace ( '--' , '--' , wptexturize ( strip_tags ( get_the_title ()))) . '"' . " \n " ;
2004-02-17 05:56:29 +01:00
echo ' trackback:ping="' . trackback_url ( 0 ) . '"' . " /> \n " ;
echo '</rdf:RDF>' ;
}
2004-01-27 10:58:01 +01:00
}
2004-06-10 10:40:58 +02:00
function comments_open () {
global $post ;
if ( 'open' == $post -> comment_status ) return true ;
else return false ;
}
function pings_open () {
global $post ;
if ( 'open' == $post -> ping_status ) return true ;
else return false ;
}
2004-02-17 05:56:29 +01:00
?>