Tidy comment_author_url_link just like we do on the bookmarks page

git-svn-id: http://svn.automattic.com/wordpress/trunk@3723 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
matt 2006-04-19 08:36:45 +00:00
parent 7fea857c9f
commit b33778b079
1 changed files with 374 additions and 370 deletions

View File

@ -1,370 +1,374 @@
<?php <?php
/* /*
* Comment template functions. * Comment template functions.
*/ */
function get_comment_author() { function get_comment_author() {
global $comment; global $comment;
if ( empty($comment->comment_author) ) if ( empty($comment->comment_author) )
$author = __('Anonymous'); $author = __('Anonymous');
else else
$author = $comment->comment_author; $author = $comment->comment_author;
return apply_filters('get_comment_author', $author); return apply_filters('get_comment_author', $author);
} }
function comment_author() { function comment_author() {
$author = apply_filters('comment_author', get_comment_author() ); $author = apply_filters('comment_author', get_comment_author() );
echo $author; echo $author;
} }
function get_comment_author_email() { function get_comment_author_email() {
global $comment; global $comment;
return apply_filters('get_comment_author_email', $comment->comment_author_email); return apply_filters('get_comment_author_email', $comment->comment_author_email);
} }
function comment_author_email() { function comment_author_email() {
echo apply_filters('author_email', get_comment_author_email() ); echo apply_filters('author_email', get_comment_author_email() );
} }
function comment_author_email_link($linktext='', $before='', $after='') { function comment_author_email_link($linktext='', $before='', $after='') {
global $comment; global $comment;
$email = apply_filters('comment_email', $comment->comment_author_email); $email = apply_filters('comment_email', $comment->comment_author_email);
if ((!empty($email)) && ($email != '@')) { if ((!empty($email)) && ($email != '@')) {
$display = ($linktext != '') ? $linktext : $email; $display = ($linktext != '') ? $linktext : $email;
echo $before; echo $before;
echo "<a href='mailto:$email'>$display</a>"; echo "<a href='mailto:$email'>$display</a>";
echo $after; echo $after;
} }
} }
function get_comment_author_link() { function get_comment_author_link() {
global $comment; global $comment;
$url = get_comment_author_url(); $url = get_comment_author_url();
$author = get_comment_author(); $author = get_comment_author();
if ( empty( $url ) || 'http://' == $url ) if ( empty( $url ) || 'http://' == $url )
$return = $author; $return = $author;
else else
$return = "<a href='$url' rel='external nofollow'>$author</a>"; $return = "<a href='$url' rel='external nofollow'>$author</a>";
return apply_filters('get_comment_author_link', $return); return apply_filters('get_comment_author_link', $return);
} }
function comment_author_link() { function comment_author_link() {
echo get_comment_author_link(); echo get_comment_author_link();
} }
function get_comment_author_IP() { function get_comment_author_IP() {
global $comment; global $comment;
return apply_filters('get_comment_author_IP', $comment->comment_author_IP); return apply_filters('get_comment_author_IP', $comment->comment_author_IP);
} }
function comment_author_IP() { function comment_author_IP() {
echo get_comment_author_IP(); echo get_comment_author_IP();
} }
function get_comment_author_url() { function get_comment_author_url() {
global $comment; global $comment;
return apply_filters('get_comment_author_url', $comment->comment_author_url); return apply_filters('get_comment_author_url', $comment->comment_author_url);
} }
function comment_author_url() { function comment_author_url() {
echo apply_filters('comment_url', get_comment_author_url()); echo apply_filters('comment_url', get_comment_author_url());
} }
function get_comment_author_url_link( $linktext = '', $before = '', $after = '' ) { function get_comment_author_url_link( $linktext = '', $before = '', $after = '' ) {
global $comment; global $comment;
$url = get_comment_author_url(); $url = get_comment_author_url();
$display = ($linktext != '') ? $linktext : $url; $display = ($linktext != '') ? $linktext : $url;
$return = "$before<a href='$url' rel='external'>$display</a>$after"; $display = str_replace( 'http://www.', '', $display );
return apply_filters('get_comment_author_url_link', $return); $display = str_replace( 'http://', '', $display );
} if ( '/' == substr($display, -1) )
$display = substr($display, 0, -1);
function comment_author_url_link( $linktext = '', $before = '', $after = '' ) { $return = "$before<a href='$url' rel='external'>$display</a>$after";
echo get_comment_author_url_link( $linktext, $before, $after ); return apply_filters('get_comment_author_url_link', $return);
} }
function get_comment_date( $d = '' ) { function comment_author_url_link( $linktext = '', $before = '', $after = '' ) {
global $comment; echo get_comment_author_url_link( $linktext, $before, $after );
if ( '' == $d ) }
$date = mysql2date( get_settings('date_format'), $comment->comment_date);
else function get_comment_date( $d = '' ) {
$date = mysql2date($d, $comment->comment_date); global $comment;
return apply_filters('get_comment_date', $date); if ( '' == $d )
} $date = mysql2date( get_settings('date_format'), $comment->comment_date);
else
function comment_date( $d = '' ) { $date = mysql2date($d, $comment->comment_date);
echo get_comment_date( $d ); return apply_filters('get_comment_date', $date);
} }
function get_comment_excerpt() { function comment_date( $d = '' ) {
global $comment; echo get_comment_date( $d );
$comment_text = strip_tags($comment->comment_content); }
$blah = explode(' ', $comment_text);
if (count($blah) > 20) { function get_comment_excerpt() {
$k = 20; global $comment;
$use_dotdotdot = 1; $comment_text = strip_tags($comment->comment_content);
} else { $blah = explode(' ', $comment_text);
$k = count($blah); if (count($blah) > 20) {
$use_dotdotdot = 0; $k = 20;
} $use_dotdotdot = 1;
$excerpt = ''; } else {
for ($i=0; $i<$k; $i++) { $k = count($blah);
$excerpt .= $blah[$i] . ' '; $use_dotdotdot = 0;
} }
$excerpt .= ($use_dotdotdot) ? '...' : ''; $excerpt = '';
return apply_filters('get_comment_excerpt', $excerpt); for ($i=0; $i<$k; $i++) {
} $excerpt .= $blah[$i] . ' ';
}
function comment_excerpt() { $excerpt .= ($use_dotdotdot) ? '...' : '';
echo apply_filters('comment_excerpt', get_comment_excerpt() ); return apply_filters('get_comment_excerpt', $excerpt);
} }
function get_comment_ID() { function comment_excerpt() {
global $comment; echo apply_filters('comment_excerpt', get_comment_excerpt() );
return apply_filters('get_comment_ID', $comment->comment_ID); }
}
function get_comment_ID() {
function comment_ID() { global $comment;
echo get_comment_ID(); return apply_filters('get_comment_ID', $comment->comment_ID);
} }
function get_comment_link() { function comment_ID() {
global $comment; echo get_comment_ID();
return get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment->comment_ID; }
}
function get_comment_link() {
function get_comments_link() { global $comment;
return get_permalink() . '#comments'; return get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment->comment_ID;
} }
function comments_link( $file = '', $echo = true ) { function get_comments_link() {
echo get_comments_link(); return get_permalink() . '#comments';
} }
function get_comments_number( $post_id = 0 ) { function comments_link( $file = '', $echo = true ) {
global $wpdb, $id; echo get_comments_link();
$post_id = (int) $post_id; }
if ( !$post_id ) function get_comments_number( $post_id = 0 ) {
$post_id = $id; global $wpdb, $id;
$post_id = (int) $post_id;
$post = get_post($post_id);
if ( ! isset($post->comment_count) ) if ( !$post_id )
$count = 0; $post_id = $id;
else
$count = $post->comment_count; $post = get_post($post_id);
if ( ! isset($post->comment_count) )
return apply_filters('get_comments_number', $count); $count = 0;
} else
$count = $post->comment_count;
function comments_number( $zero = 'No Comments', $one = '1 Comment', $more = '% Comments', $number = '' ) {
global $id, $comment; return apply_filters('get_comments_number', $count);
$number = get_comments_number( $id ); }
if ($number == 0) {
$blah = $zero; function comments_number( $zero = 'No Comments', $one = '1 Comment', $more = '% Comments', $number = '' ) {
} elseif ($number == 1) { global $id, $comment;
$blah = $one; $number = get_comments_number( $id );
} elseif ($number > 1) { if ($number == 0) {
$blah = str_replace('%', $number, $more); $blah = $zero;
} } elseif ($number == 1) {
echo apply_filters('comments_number', $blah); $blah = $one;
} } elseif ($number > 1) {
$blah = str_replace('%', $number, $more);
function get_comment_text() { }
global $comment; echo apply_filters('comments_number', $blah);
return apply_filters('get_comment_text', $comment->comment_content); }
}
function get_comment_text() {
function comment_text() { global $comment;
echo apply_filters('comment_text', get_comment_text() ); return apply_filters('get_comment_text', $comment->comment_content);
} }
function get_comment_time( $d = '', $gmt = false ) { function comment_text() {
global $comment; echo apply_filters('comment_text', get_comment_text() );
$comment_date = $gmt? $comment->comment_date_gmt : $comment->comment_date; }
if ( '' == $d )
$date = mysql2date(get_settings('time_format'), $comment_date); function get_comment_time( $d = '', $gmt = false ) {
else global $comment;
$date = mysql2date($d, $comment_date); $comment_date = $gmt? $comment->comment_date_gmt : $comment->comment_date;
return apply_filters('get_comment_time', $date); if ( '' == $d )
} $date = mysql2date(get_settings('time_format'), $comment_date);
else
function comment_time( $d = '' ) { $date = mysql2date($d, $comment_date);
echo get_comment_time($d); return apply_filters('get_comment_time', $date);
} }
function get_comment_type() { function comment_time( $d = '' ) {
global $comment; echo get_comment_time($d);
}
if ( '' == $comment->comment_type )
$comment->comment_type = 'comment'; function get_comment_type() {
global $comment;
return apply_filters('get_comment_type', $comment->comment_type);
} if ( '' == $comment->comment_type )
$comment->comment_type = 'comment';
function comment_type($commenttxt = 'Comment', $trackbacktxt = 'Trackback', $pingbacktxt = 'Pingback') {
$type = get_comment_type(); return apply_filters('get_comment_type', $comment->comment_type);
switch( $type ) { }
case 'trackback' :
echo $trackbacktxt; function comment_type($commenttxt = 'Comment', $trackbacktxt = 'Trackback', $pingbacktxt = 'Pingback') {
break; $type = get_comment_type();
case 'pingback' : switch( $type ) {
echo $pingbacktxt; case 'trackback' :
break; echo $trackbacktxt;
default : break;
echo $commenttxt; case 'pingback' :
} echo $pingbacktxt;
} break;
default :
function get_trackback_url() { echo $commenttxt;
global $id; }
$tb_url = get_settings('siteurl') . '/wp-trackback.php?p=' . $id; }
if ( '' != get_settings('permalink_structure') ) function get_trackback_url() {
$tb_url = trailingslashit(get_permalink()) . 'trackback/'; global $id;
$tb_url = get_settings('siteurl') . '/wp-trackback.php?p=' . $id;
return $tb_url;
} if ( '' != get_settings('permalink_structure') )
function trackback_url( $display = true ) { $tb_url = trailingslashit(get_permalink()) . 'trackback/';
if ( $display)
echo get_trackback_url(); return $tb_url;
else }
return get_trackback_url(); function trackback_url( $display = true ) {
} if ( $display)
echo get_trackback_url();
function trackback_rdf($timezone = 0) { else
global $id; return get_trackback_url();
if (!stristr($_SERVER['HTTP_USER_AGENT'], 'W3C_Validator')) { }
echo '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/" function trackback_rdf($timezone = 0) {
xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/"> global $id;
<rdf:Description rdf:about="'; if (!stristr($_SERVER['HTTP_USER_AGENT'], 'W3C_Validator')) {
the_permalink(); echo '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
echo '"'."\n"; xmlns:dc="http://purl.org/dc/elements/1.1/"
echo ' dc:identifier="'; xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
the_permalink(); <rdf:Description rdf:about="';
echo '"'."\n"; the_permalink();
echo ' dc:title="'.str_replace('--', '&#x2d;&#x2d;', wptexturize(strip_tags(get_the_title()))).'"'."\n"; echo '"'."\n";
echo ' trackback:ping="'.trackback_url(0).'"'." />\n"; echo ' dc:identifier="';
echo '</rdf:RDF>'; the_permalink();
} echo '"'."\n";
} echo ' dc:title="'.str_replace('--', '&#x2d;&#x2d;', wptexturize(strip_tags(get_the_title()))).'"'."\n";
echo ' trackback:ping="'.trackback_url(0).'"'." />\n";
function comments_open() { echo '</rdf:RDF>';
global $post; }
if ( 'open' == $post->comment_status ) }
return true;
else function comments_open() {
return false; global $post;
} if ( 'open' == $post->comment_status )
return true;
function pings_open() { else
global $post; return false;
if ( 'open' == $post->ping_status ) }
return true;
else function pings_open() {
return false; global $post;
} if ( 'open' == $post->ping_status )
return true;
function comments_template( $file = '/comments.php' ) { else
global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity; return false;
}
if ( is_single() || is_page() || $withcomments ) :
$req = get_settings('require_name_email'); function comments_template( $file = '/comments.php' ) {
$comment_author = ''; global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity;
if ( isset($_COOKIE['comment_author_'.COOKIEHASH]) ) {
$comment_author = apply_filters('pre_comment_author_name', $_COOKIE['comment_author_'.COOKIEHASH]); if ( is_single() || is_page() || $withcomments ) :
$comment_author = stripslashes($comment_author); $req = get_settings('require_name_email');
$comment_author = wp_specialchars($comment_author, true); $comment_author = '';
} if ( isset($_COOKIE['comment_author_'.COOKIEHASH]) ) {
$comment_author_email = ''; $comment_author = apply_filters('pre_comment_author_name', $_COOKIE['comment_author_'.COOKIEHASH]);
if ( isset($_COOKIE['comment_author_email_'.COOKIEHASH]) ) { $comment_author = stripslashes($comment_author);
$comment_author_email = apply_filters('pre_comment_author_email', $_COOKIE['comment_author_email_'.COOKIEHASH]); $comment_author = wp_specialchars($comment_author, true);
$comment_author_email = stripslashes($comment_author_email); }
$comment_author_email = wp_specialchars($comment_author_email, true); $comment_author_email = '';
} if ( isset($_COOKIE['comment_author_email_'.COOKIEHASH]) ) {
$comment_author_url = ''; $comment_author_email = apply_filters('pre_comment_author_email', $_COOKIE['comment_author_email_'.COOKIEHASH]);
if ( isset($_COOKIE['comment_author_url_'.COOKIEHASH]) ) { $comment_author_email = stripslashes($comment_author_email);
$comment_author_url = apply_filters('pre_comment_author_url', $_COOKIE['comment_author_url_'.COOKIEHASH]); $comment_author_email = wp_specialchars($comment_author_email, true);
$comment_author_url = stripslashes($comment_author_url); }
$comment_author_url = wp_specialchars($comment_author_url, true); $comment_author_url = '';
} if ( isset($_COOKIE['comment_author_url_'.COOKIEHASH]) ) {
$comment_author_url = apply_filters('pre_comment_author_url', $_COOKIE['comment_author_url_'.COOKIEHASH]);
// TODO: Use API instead of SELECTs. $comment_author_url = stripslashes($comment_author_url);
if ( empty($comment_author) ) { $comment_author_url = wp_specialchars($comment_author_url, true);
$comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$post->ID' AND comment_approved = '1' ORDER BY comment_date"); }
} else {
$author_db = $wpdb->escape($comment_author); // TODO: Use API instead of SELECTs.
$email_db = $wpdb->escape($comment_author_email); if ( empty($comment_author) ) {
$comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$post->ID' AND ( comment_approved = '1' OR ( comment_author = '$author_db' AND comment_author_email = '$email_db' AND comment_approved = '0' ) ) ORDER BY comment_date"); $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$post->ID' AND comment_approved = '1' ORDER BY comment_date");
} } else {
$author_db = $wpdb->escape($comment_author);
define('COMMENTS_TEMPLATE', true); $email_db = $wpdb->escape($comment_author_email);
$include = apply_filters('comments_template', TEMPLATEPATH . $file ); $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$post->ID' AND ( comment_approved = '1' OR ( comment_author = '$author_db' AND comment_author_email = '$email_db' AND comment_approved = '0' ) ) ORDER BY comment_date");
if ( file_exists( $include ) ) }
require( $include );
else define('COMMENTS_TEMPLATE', true);
require( ABSPATH . 'wp-content/themes/default/comments.php'); $include = apply_filters('comments_template', TEMPLATEPATH . $file );
if ( file_exists( $include ) )
endif; require( $include );
} else
require( ABSPATH . 'wp-content/themes/default/comments.php');
function comments_popup_script($width=400, $height=400, $file='') {
global $wpcommentspopupfile, $wptrackbackpopupfile, $wppingbackpopupfile, $wpcommentsjavascript; endif;
}
if (empty ($file)) {
$wpcommentspopupfile = ''; // Use the index. function comments_popup_script($width=400, $height=400, $file='') {
} else { global $wpcommentspopupfile, $wptrackbackpopupfile, $wppingbackpopupfile, $wpcommentsjavascript;
$wpcommentspopupfile = $file;
} if (empty ($file)) {
$wpcommentspopupfile = ''; // Use the index.
$wpcommentsjavascript = 1; } else {
$javascript = "<script type='text/javascript'>\nfunction wpopen (macagna) {\n window.open(macagna, '_blank', 'width=$width,height=$height,scrollbars=yes,status=yes');\n}\n</script>\n"; $wpcommentspopupfile = $file;
echo $javascript; }
}
$wpcommentsjavascript = 1;
function comments_popup_link($zero='No Comments', $one='1 Comment', $more='% Comments', $CSSclass='', $none='Comments Off') { $javascript = "<script type='text/javascript'>\nfunction wpopen (macagna) {\n window.open(macagna, '_blank', 'width=$width,height=$height,scrollbars=yes,status=yes');\n}\n</script>\n";
global $id, $wpcommentspopupfile, $wpcommentsjavascript, $post, $wpdb; echo $javascript;
}
if ( is_single() || is_page() )
return; function comments_popup_link($zero='No Comments', $one='1 Comment', $more='% Comments', $CSSclass='', $none='Comments Off') {
global $id, $wpcommentspopupfile, $wpcommentsjavascript, $post, $wpdb;
$number = get_comments_number($id);
if ( is_single() || is_page() )
if ( 0 == $number && 'closed' == $post->comment_status && 'closed' == $post->ping_status ) { return;
echo $none;
return; $number = get_comments_number($id);
}
if ( 0 == $number && 'closed' == $post->comment_status && 'closed' == $post->ping_status ) {
if ( !empty($post->post_password) ) { // if there's a password echo $none;
if ($_COOKIE['wp-postpass_'.COOKIEHASH] != $post->post_password) { // and it doesn't match the cookie return;
echo(__('Enter your password to view comments')); }
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'));
echo '<a href="'; return;
if ($wpcommentsjavascript) { }
if ( empty($wpcommentspopupfile) ) }
$home = get_settings('home');
else echo '<a href="';
$home = get_settings('siteurl'); if ($wpcommentsjavascript) {
echo $home . '/' . $wpcommentspopupfile.'?comments_popup='.$id; if ( empty($wpcommentspopupfile) )
echo '" onclick="wpopen(this.href); return false"'; $home = get_settings('home');
} else { // if comments_popup_script() is not in the template, display simple comment link else
if ( 0 == $number ) $home = get_settings('siteurl');
echo get_permalink() . '#respond'; echo $home . '/' . $wpcommentspopupfile.'?comments_popup='.$id;
else echo '" onclick="wpopen(this.href); return false"';
comments_link(); } else { // if comments_popup_script() is not in the template, display simple comment link
echo '"'; if ( 0 == $number )
} echo get_permalink() . '#respond';
else
if (!empty($CSSclass)) { comments_link();
echo ' class="'.$CSSclass.'"'; echo '"';
} }
echo ' title="' . sprintf( __('Comment on %s'), $post->post_title ) .'">';
comments_number($zero, $one, $more, $number); if (!empty($CSSclass)) {
echo '</a>'; echo ' class="'.$CSSclass.'"';
} }
echo ' title="' . sprintf( __('Comment on %s'), $post->post_title ) .'">';
?> comments_number($zero, $one, $more, $number);
echo '</a>';
}
?>