3 * Comment template functions.
6 function get_comment_author() {
8 if ( empty($comment->comment_author) )
9 $author = __('Anonymous');
11 $author = $comment->comment_author;
12 return apply_filters('get_comment_author', $author);
15 function comment_author() {
16 $author = apply_filters('comment_author', get_comment_author() );
20 function get_comment_author_email() {
22 return apply_filters('get_comment_author_email', $comment->comment_author_email);
25 function comment_author_email() {
26 echo apply_filters('author_email', get_comment_author_email() );
29 function comment_author_email_link($linktext='', $before='', $after='') {
31 $email = apply_filters('comment_email', $comment->comment_author_email);
32 if ((!empty($email)) && ($email != '@')) {
33 $display = ($linktext != '') ? $linktext : $email;
35 echo "<a href='mailto:$email'>$display</a>";
40 function get_comment_author_link() {
42 $url = get_comment_author_url();
43 $author = get_comment_author();
45 if ( empty( $url ) || 'http://' == $url )
48 $return = "<a href='$url' rel='external nofollow'>$author</a>";
49 return apply_filters('get_comment_author_link', $return);
52 function comment_author_link() {
53 echo get_comment_author_link();
56 function get_comment_author_IP() {
58 return apply_filters('get_comment_author_IP', $comment->comment_author_IP);
61 function comment_author_IP() {
62 echo get_comment_author_IP();
65 function get_comment_author_url() {
67 return apply_filters('get_comment_author_url', $comment->comment_author_url);
70 function comment_author_url() {
71 echo apply_filters('comment_url', get_comment_author_url());
74 function get_comment_author_url_link( $linktext = '', $before = '', $after = '' ) {
76 $url = get_comment_author_url();
77 $display = ($linktext != '') ? $linktext : $url;
78 $display = str_replace( 'http://www.', '', $display );
79 $display = str_replace( 'http://', '', $display );
80 if ( '/' == substr($display, -1) )
81 $display = substr($display, 0, -1);
82 $return = "$before<a href='$url' rel='external'>$display</a>$after";
83 return apply_filters('get_comment_author_url_link', $return);
86 function comment_author_url_link( $linktext = '', $before = '', $after = '' ) {
87 echo get_comment_author_url_link( $linktext, $before, $after );
90 function get_comment_date( $d = '' ) {
93 $date = mysql2date( get_option('date_format'), $comment->comment_date);
95 $date = mysql2date($d, $comment->comment_date);
96 return apply_filters('get_comment_date', $date, $d);
99 function comment_date( $d = '' ) {
100 echo get_comment_date( $d );
103 function get_comment_excerpt() {
105 $comment_text = strip_tags($comment->comment_content);
106 $blah = explode(' ', $comment_text);
107 if (count($blah) > 20) {
115 for ($i=0; $i<$k; $i++) {
116 $excerpt .= $blah[$i] . ' ';
118 $excerpt .= ($use_dotdotdot) ? '...' : '';
119 return apply_filters('get_comment_excerpt', $excerpt);
122 function comment_excerpt() {
123 echo apply_filters('comment_excerpt', get_comment_excerpt() );
126 function get_comment_ID() {
128 return apply_filters('get_comment_ID', $comment->comment_ID);
131 function comment_ID() {
132 echo get_comment_ID();
135 function get_comment_link() {
137 return get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment->comment_ID;
140 function get_comments_link() {
141 return get_permalink() . '#comments';
144 function comments_link( $file = '', $echo = true ) {
145 echo get_comments_link();
148 function get_comments_number( $post_id = 0 ) {
150 $post_id = (int) $post_id;
153 $post_id = (int) $id;
155 $post = get_post($post_id);
156 if ( ! isset($post->comment_count) )
159 $count = $post->comment_count;
161 return apply_filters('get_comments_number', $count);
164 function comments_number( $zero = false, $one = false, $more = false, $deprecated = '' ) {
166 $number = get_comments_number($id);
169 $output = str_replace('%', $number, ( false === $more ) ? __('% Comments') : $more);
170 elseif ( $number == 0 )
171 $output = ( false === $zero ) ? __('No Comments') : $zero;
173 $output = ( false === $one ) ? __('1 Comment') : $one;
175 echo apply_filters('comments_number', $output, $number);
178 function get_comment_text() {
180 return apply_filters('get_comment_text', $comment->comment_content);
183 function comment_text() {
184 echo apply_filters('comment_text', get_comment_text() );
187 function get_comment_time( $d = '', $gmt = false ) {
189 $comment_date = $gmt? $comment->comment_date_gmt : $comment->comment_date;
191 $date = mysql2date(get_option('time_format'), $comment_date);
193 $date = mysql2date($d, $comment_date);
194 return apply_filters('get_comment_time', $date, $d, $gmt);
197 function comment_time( $d = '' ) {
198 echo get_comment_time($d);
201 function get_comment_type() {
204 if ( '' == $comment->comment_type )
205 $comment->comment_type = 'comment';
207 return apply_filters('get_comment_type', $comment->comment_type);
210 function comment_type($commenttxt = 'Comment', $trackbacktxt = 'Trackback', $pingbacktxt = 'Pingback') {
211 $type = get_comment_type();
224 function get_trackback_url() {
226 if ( '' != get_option('permalink_structure') ) {
227 $tb_url = trailingslashit(get_permalink()) . user_trailingslashit('trackback', 'single_trackback');
229 $tb_url = get_option('siteurl') . '/wp-trackback.php?p=' . $id;
231 return apply_filters('trackback_url', $tb_url);
234 function trackback_url($deprecated = true) { // remove backwards compat in 2.4
235 if ($deprecated) echo get_trackback_url();
236 else return get_trackback_url();
239 function trackback_rdf($timezone = 0) {
241 if (stripos($_SERVER['HTTP_USER_AGENT'], 'W3C_Validator') === false) {
242 echo '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
243 xmlns:dc="http://purl.org/dc/elements/1.1/"
244 xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
245 <rdf:Description rdf:about="';
248 echo ' dc:identifier="';
251 echo ' dc:title="'.str_replace('--', '--', wptexturize(strip_tags(get_the_title()))).'"'."\n";
252 echo ' trackback:ping="'.get_trackback_url().'"'." />\n";
257 function comments_open() {
259 if ( 'open' == $post->comment_status )
265 function pings_open() {
267 if ( 'open' == $post->ping_status )
273 function wp_comment_form_unfiltered_html_nonce() {
275 if ( current_user_can('unfiltered_html') )
276 wp_nonce_field('unfiltered-html-comment_' . $post->ID, '_wp_unfiltered_html_comment', false);
279 function comments_template( $file = '/comments.php' ) {
280 global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity;
282 if ( ! (is_single() || is_page() || $withcomments) )
285 $req = get_option('require_name_email');
286 $commenter = wp_get_current_commenter();
287 extract($commenter, EXTR_SKIP);
289 // TODO: Use API instead of SELECTs.
291 $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$post->ID' AND (comment_approved = '1' OR ( user_id = '$user_ID' AND comment_approved = '0' ) ) ORDER BY comment_date");
292 } else if ( empty($comment_author) ) {
293 $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$post->ID' AND comment_approved = '1' ORDER BY comment_date");
295 $author_db = $wpdb->escape($comment_author);
296 $email_db = $wpdb->escape($comment_author_email);
297 $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");
300 // keep $comments for legacy's sake (remember $table*? ;) )
301 $comments = $wp_query->comments = apply_filters( 'comments_array', $comments, $post->ID );
302 $wp_query->comment_count = count($wp_query->comments);
303 update_comment_cache($comments);
305 define('COMMENTS_TEMPLATE', true);
306 $include = apply_filters('comments_template', TEMPLATEPATH . $file );
307 if ( file_exists( $include ) )
310 require( ABSPATH . 'wp-content/themes/default/comments.php');
313 function comments_popup_script($width=400, $height=400, $file='') {
314 global $wpcommentspopupfile, $wptrackbackpopupfile, $wppingbackpopupfile, $wpcommentsjavascript;
317 $wpcommentspopupfile = ''; // Use the index.
319 $wpcommentspopupfile = $file;
322 $wpcommentsjavascript = 1;
323 $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";
327 function comments_popup_link($zero='No Comments', $one='1 Comment', $more='% Comments', $CSSclass='', $none='Comments Off') {
328 global $id, $wpcommentspopupfile, $wpcommentsjavascript, $post, $wpdb;
330 if ( is_single() || is_page() )
333 $number = get_comments_number($id);
335 if ( 0 == $number && 'closed' == $post->comment_status && 'closed' == $post->ping_status ) {
336 echo '<span' . ((!empty($CSSclass)) ? ' class="' . $CSSclass . '"' : '') . '>' . $none . '</span>';
340 if ( !empty($post->post_password) ) { // if there's a password
341 if ($_COOKIE['wp-postpass_'.COOKIEHASH] != $post->post_password) { // and it doesn't match the cookie
342 echo(__('Enter your password to view comments'));
348 if ($wpcommentsjavascript) {
349 if ( empty($wpcommentspopupfile) )
350 $home = get_option('home');
352 $home = get_option('siteurl');
353 echo $home . '/' . $wpcommentspopupfile.'?comments_popup='.$id;
354 echo '" onclick="wpopen(this.href); return false"';
355 } else { // if comments_popup_script() is not in the template, display simple comment link
357 echo get_permalink() . '#respond';
363 if (!empty($CSSclass)) {
364 echo ' class="'.$CSSclass.'"';
366 $title = attribute_escape(get_the_title());
367 echo ' title="' . sprintf( __('Comment on %s'), $title ) .'">';
368 comments_number($zero, $one, $more, $number);