Projects : mp-wp : mp-wp_svg-screenshots-and-errorreporting-r2

mp-wp/wp-includes/comment-template.php

Dir - Raw

1<?php
2/**
3 * Comment template functions
4 *
5 * These functions are meant to live inside of the WordPress loop.
6 *
7 * @package WordPress
8 * @subpackage Template
9 */
10
11/**
12 * Retrieve the author of the current comment.
13 *
14 * If the comment has an empty comment_author field, then 'Anonymous' person is
15 * assumed.
16 *
17 * @since 1.5.0
18 * @uses apply_filters() Calls 'get_comment_author' hook on the comment author
19 *
20 * @return string The comment author
21 */
22function get_comment_author() {
23 global $comment;
24 if ( empty($comment->comment_author) ) {
25 if (!empty($comment->user_id)){
26 $user=get_userdata($comment->user_id);
27 $author=$user->user_login;
28 } else {
29 $author = __('Anonymous');
30 }
31 } else {
32 $author = $comment->comment_author;
33 }
34 return apply_filters('get_comment_author', $author);
35}
36
37/**
38 * Displays the author of the current comment.
39 *
40 * @since 0.71
41 * @uses apply_filters() Calls 'comment_author' on comment author before displaying
42 */
43function comment_author() {
44 $author = apply_filters('comment_author', get_comment_author() );
45 echo $author;
46}
47
48/**
49 * Retrieve the email of the author of the current comment.
50 *
51 * @since 1.5.0
52 * @uses apply_filters() Calls the 'get_comment_author_email' hook on the comment author email
53 * @uses $comment
54 *
55 * @return string The current comment author's email
56 */
57function get_comment_author_email() {
58 global $comment;
59 return apply_filters('get_comment_author_email', $comment->comment_author_email);
60}
61
62/**
63 * Display the email of the author of the current global $comment.
64 *
65 * Care should be taken to protect the email address and assure that email
66 * harvesters do not capture your commentors' email address. Most assume that
67 * their email address will not appear in raw form on the blog. Doing so will
68 * 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.
70 *
71 * @since 0.71
72 * @uses apply_filters() Calls 'author_email' hook on the author email
73 */
74function comment_author_email() {
75 echo apply_filters('author_email', get_comment_author_email() );
76}
77
78/**
79 * Display the html email link to the author of the current comment.
80 *
81 * Care should be taken to protect the email address and assure that email
82 * harvesters do not capture your commentors' email address. Most assume that
83 * their email address will not appear in raw form on the blog. Doing so will
84 * enable anyone, including those that people don't want to get the email
85 * address and use it for their own means good and bad.
86 *
87 * @since 0.71
88 * @uses apply_filters() Calls 'comment_email' hook for the display of the comment author's email
89 * @uses get_comment_author_email_link() For generating the link
90 * @global object $comment The current Comment row object
91 *
92 * @param string $linktext The text to display instead of the comment author's email address
93 * @param string $before The text or HTML to display before the email link.
94 * @param string $after The text or HTML to display after the email link.
95 */
96function comment_author_email_link($linktext='', $before='', $after='') {
97 if ( $link = get_comment_author_email_link( $linktext, $before, $after ) )
98 echo $link;
99}
100
101/**
102 * Return the html email link to the author of the current comment.
103 *
104 * Care should be taken to protect the email address and assure that email
105 * harvesters do not capture your commentors' email address. Most assume that
106 * their email address will not appear in raw form on the blog. Doing so will
107 * enable anyone, including those that people don't want to get the email
108 * address and use it for their own means good and bad.
109 *
110 * @since 2.7
111 * @uses apply_filters() Calls 'comment_email' hook for the display of the comment author's email
112 * @global object $comment The current Comment row object
113 *
114 * @param string $linktext The text to display instead of the comment author's email address
115 * @param string $before The text or HTML to display before the email link.
116 * @param string $after The text or HTML to display after the email link.
117 */
118function get_comment_author_email_link($linktext='', $before='', $after='') {
119 global $comment;
120 $email = apply_filters('comment_email', $comment->comment_author_email);
121 if ((!empty($email)) && ($email != '@')) {
122 $display = ($linktext != '') ? $linktext : $email;
123 $return = $before;
124 $return .= "<a href='mailto:$email'>$display</a>";
125 $return .= $after;
126 return $return;
127 } else {
128 return '';
129 }
130}
131
132/**
133 * Retrieve the html link to the url of the author of the current comment.
134 *
135 * @since 1.5.0
136 * @uses apply_filters() Calls 'get_comment_author_link' hook on the complete link HTML or author
137 *
138 * @return string Comment Author name or HTML link for author's URL
139 */
140function get_comment_author_link() {
141 /** @todo Only call these functions when they are needed. Include in if... else blocks */
142 $url = get_comment_author_url();
143 $author = get_comment_author();
144
145 if ( empty( $url ) || 'http://' == $url )
146 $return = $author;
147 else
148// Removed rel='external nofollow' from here
149 $return = "<a href='$url' class='url'>$author</a>";
150 return apply_filters('get_comment_author_link', $return);
151}
152
153/**
154 * Display the html link to the url of the author of the current comment.
155 *
156 * @since 0.71
157 * @see get_comment_author_link() Echos result
158 */
159function comment_author_link() {
160 echo get_comment_author_link();
161}
162
163/**
164 * Retrieve the IP address of the author of the current comment.
165 *
166 * @since 1.5.0
167 * @uses $comment
168 * @uses apply_filters()
169 *
170 * @return unknown
171 */
172function get_comment_author_IP() {
173 global $comment;
174 return apply_filters('get_comment_author_IP', $comment->comment_author_IP);
175}
176
177/**
178 * Display the IP address of the author of the current comment.
179 *
180 * @since 0.71
181 * @see get_comment_author_IP() Echos Result
182 */
183function comment_author_IP() {
184 echo get_comment_author_IP();
185}
186
187/**
188 * Retrieve the url of the author of the current comment.
189 *
190 * @since 1.5.0
191 * @uses apply_filters() Calls 'get_comment_author_url' hook on the comment author's URL
192 *
193 * @return string
194 */
195function get_comment_author_url() {
196 global $comment;
197 return apply_filters('get_comment_author_url', $comment->comment_author_url);
198}
199
200/**
201 * Display the url of the author of the current comment.
202 *
203 * @since 0.71
204 * @uses apply_filters()
205 * @uses get_comment_author_url() Retrieves the comment author's URL
206 */
207function comment_author_url() {
208 echo apply_filters('comment_url', get_comment_author_url());
209}
210
211/**
212 * Retrieves the HTML link of the url of the author of the current comment.
213 *
214 * $linktext parameter is only used if the URL does not exist for the comment
215 * author. If the URL does exist then the URL will be used and the $linktext
216 * will be ignored.
217 *
218 * Encapsulate the HTML link between the $before and $after. So it will appear
219 * in the order of $before, link, and finally $after.
220 *
221 * @since 1.5.0
222 * @uses apply_filters() Calls the 'get_comment_author_url_link' on the complete HTML before returning.
223 *
224 * @param string $linktext The text to display instead of the comment author's email address
225 * @param string $before The text or HTML to display before the email link.
226 * @param string $after The text or HTML to display after the email link.
227 * @return string The HTML link between the $before and $after parameters
228 */
229function get_comment_author_url_link( $linktext = '', $before = '', $after = '' ) {
230 $url = get_comment_author_url();
231 $display = ($linktext != '') ? $linktext : $url;
232 $display = str_replace( 'http://www.', '', $display );
233 $display = str_replace( 'http://', '', $display );
234 if ( '/' == substr($display, -1) )
235 $display = substr($display, 0, -1);
236 $return = "$before<a href='$url' rel='external'>$display</a>$after";
237 return apply_filters('get_comment_author_url_link', $return);
238}
239
240/**
241 * Displays the HTML link of the url of the author of the current comment.
242 *
243 * @since 0.71
244 * @see get_comment_author_url_link() Echos result
245 *
246 * @param string $linktext The text to display instead of the comment author's email address
247 * @param string $before The text or HTML to display before the email link.
248 * @param string $after The text or HTML to display after the email link.
249 */
250function comment_author_url_link( $linktext = '', $before = '', $after = '' ) {
251 echo get_comment_author_url_link( $linktext, $before, $after );
252}
253
254/**
255 * Generates semantic classes for each comment element
256 *
257 * @since 2.7.0
258 *
259 * @param string|array $class One or more classes to add to the class list
260 * @param int $comment_id An optional comment ID
261 * @param int $post_id An optional post ID
262 * @param bool $echo Whether comment_class should echo or return
263 */
264function comment_class( $class = '', $comment_id = null, $post_id = null, $echo = true ) {
265 // Separates classes with a single space, collates classes for comment DIV
266 $class = 'class="' . join( ' ', get_comment_class( $class, $comment_id, $post_id ) ) . '"';
267 if ( $echo)
268 echo $class;
269 else
270 return $class;
271}
272
273/**
274 * Returns the classes for the comment div as an array
275 *
276 * @since 2.7.0
277 *
278 * @param string|array $class One or more classes to add to the class list
279 * @param int $comment_id An optional comment ID
280 * @param int $post_id An optional post ID
281 * @return array Array of classes
282 */
283function get_comment_class( $class = '', $comment_id = null, $post_id = null ) {
284 global $comment_alt, $comment_depth, $comment_thread_alt;
285
286 $comment = get_comment($comment_id);
287
288 $classes = array();
289
290 // Get the comment type (comment, trackback),
291 $classes[] = ( empty( $comment->comment_type ) ) ? 'comment' : $comment->comment_type;
292
293 // If the comment author has an id (registered), then print the log in name
294 if ( $comment->user_id > 0 && $user = get_userdata($comment->user_id) ) {
295 // For all registered users, 'byuser'
296 $classes[] = 'byuser comment-author-' . $user->user_nicename;
297 // For comment authors who are the author of the post
298 if ( $post = get_post($post_id) ) {
299 if ( $comment->user_id === $post->post_author )
300 $classes[] = 'bypostauthor';
301 }
302 }
303
304 if ( empty($comment_alt) )
305 $comment_alt = 0;
306 if ( empty($comment_depth) )
307 $comment_depth = 1;
308 if ( empty($comment_thread_alt) )
309 $comment_thread_alt = 0;
310
311 if ( $comment_alt % 2 ) {
312 $classes[] = 'odd';
313 $classes[] = 'alt';
314 } else {
315 $classes[] = 'even';
316 }
317
318 $comment_alt++;
319
320 // Alt for top-level comments
321 if ( 1 == $comment_depth ) {
322 if ( $comment_thread_alt % 2 ) {
323 $classes[] = 'thread-odd';
324 $classes[] = 'thread-alt';
325 } else {
326 $classes[] = 'thread-even';
327 }
328 $comment_thread_alt++;
329 }
330
331 $classes[] = "depth-$comment_depth";
332
333 if ( !empty($class) ) {
334 if ( !is_array( $class ) )
335 $class = preg_split('#\s+#', $class);
336 $classes = array_merge($classes, $class);
337 }
338
339 return apply_filters('comment_class', $classes, $class, $comment_id, $post_id);
340}
341
342/**
343 * Retrieve the comment date of the current comment.
344 *
345 * @since 1.5.0
346 * @uses apply_filters() Calls 'get_comment_date' hook with the formated date and the $d parameter respectively
347 * @uses $comment
348 *
349 * @param string $d The format of the date (defaults to user's config)
350 * @return string The comment's date
351 */
352function get_comment_date( $d = '' ) {
353 global $comment;
354 if ( '' == $d )
355 $date = mysql2date( get_option('date_format'), $comment->comment_date);
356 else
357 $date = mysql2date($d, $comment->comment_date);
358 return apply_filters('get_comment_date', $date, $d);
359}
360
361/**
362 * Display the comment date of the current comment.
363 *
364 * @since 0.71
365 *
366 * @param string $d The format of the date (defaults to user's config)
367 */
368function comment_date( $d = '' ) {
369 echo get_comment_date( $d );
370}
371
372/**
373 * Retrieve the excerpt of the current comment.
374 *
375 * Will cut each word and only output the first 20 words with '...' at the end.
376 * If the word count is less than 20, then no truncating is done and no '...'
377 * will appear.
378 *
379 * @since 1.5.0
380 * @uses $comment
381 * @uses apply_filters() Calls 'get_comment_excerpt' on truncated comment
382 *
383 * @return string The maybe truncated comment with 20 words or less
384 */
385function get_comment_excerpt() {
386 global $comment;
387 $comment_text = strip_tags($comment->comment_content);
388 $blah = explode(' ', $comment_text);
389 if (count($blah) > 20) {
390 $k = 20;
391 $use_dotdotdot = 1;
392 } else {
393 $k = count($blah);
394 $use_dotdotdot = 0;
395 }
396 $excerpt = '';
397 for ($i=0; $i<$k; $i++) {
398 $excerpt .= $blah[$i] . ' ';
399 }
400 $excerpt .= ($use_dotdotdot) ? '...' : '';
401 return apply_filters('get_comment_excerpt', $excerpt);
402}
403
404/**
405 * Display the excerpt of the current comment.
406 *
407 * @since 1.2.0
408 * @uses apply_filters() Calls 'comment_excerpt' hook before displaying excerpt
409 */
410function comment_excerpt() {
411 echo apply_filters('comment_excerpt', get_comment_excerpt() );
412}
413
414/**
415 * Retrieve the comment id of the current comment.
416 *
417 * @since 1.5.0
418 * @uses $comment
419 * @uses apply_filters() Calls the 'get_comment_ID' hook for the comment ID
420 *
421 * @return int The comment ID
422 */
423function get_comment_ID() {
424 global $comment;
425 return apply_filters('get_comment_ID', $comment->comment_ID);
426}
427
428/**
429 * Displays the comment id of the current comment.
430 *
431 * @since 0.71
432 * @see get_comment_ID() Echos Result
433 */
434function comment_ID() {
435 echo get_comment_ID();
436}
437
438/**
439 * Retrieve the link to a given comment.
440 *
441 * @since 1.5.0
442 * @uses $comment
443 *
444 * @param object|string|int $comment Comment to retrieve.
445 * @param array $args Optional args.
446 * @return string The permalink to the current comment
447 */
448function get_comment_link( $comment = null, $args = array() ) {
449 global $wp_rewrite, $in_comment_loop;
450
451 $comment = get_comment($comment);
452
453 // Backwards compat
454 if ( !is_array($args) ) {
455 $page = $args;
456 $args = array();
457 $args['page'] = $page;
458 }
459
460 $defaults = array( 'type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '' );
461 $args = wp_parse_args( $args, $defaults );
462
463 if ( '' === $args['per_page'] && get_option('page_comments') )
464 $args['per_page'] = get_option('comments_per_page');
465
466 if ( empty($args['per_page']) ) {
467 $args['per_page'] = 0;
468 $args['page'] = 0;
469 }
470
471 if ( $args['per_page'] ) {
472 if ( '' == $args['page'] )
473 $args['page'] = ( !empty($in_comment_loop) ) ? get_query_var('cpage') : get_page_of_comment( $comment->comment_ID, $args );
474
475 if ( $wp_rewrite->using_permalinks() )
476 return user_trailingslashit( trailingslashit( get_permalink( $comment->comment_post_ID ) ) . 'comment-page-' . $args['page'], 'comment' ) . '#comment-' . $comment->comment_ID;
477 else
478 return add_query_arg( 'cpage', $args['page'], get_permalink( $comment->comment_post_ID ) ) . '#comment-' . $comment->comment_ID;
479 } else {
480 return get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment->comment_ID;
481 }
482}
483
484/**
485 * Retrieves the link to the current post comments.
486 *
487 * @since 1.5.0
488 *
489 * @return string The link to the comments
490 */
491function get_comments_link() {
492 return get_permalink() . '#comments';
493}
494
495/**
496 * Displays the link to the current post comments.
497 *
498 * @since 0.71
499 *
500 * @param string $deprecated Not Used
501 * @param bool $deprecated Not Used
502 */
503function comments_link( $deprecated = '', $deprecated = '' ) {
504 echo get_comments_link();
505}
506
507/**
508 * Retrieve the amount of comments a post has.
509 *
510 * @since 1.5.0
511 * @uses apply_filters() Calls the 'get_comments_number' hook on the number of comments
512 *
513 * @param int $post_id The Post ID
514 * @return int The number of comments a post has
515 */
516function get_comments_number( $post_id = 0 ) {
517 global $id;
518 $post_id = (int) $post_id;
519
520 if ( !$post_id )
521 $post_id = (int) $id;
522
523 $post = get_post($post_id);
524 if ( ! isset($post->comment_count) )
525 $count = 0;
526 else
527 $count = $post->comment_count;
528
529 return apply_filters('get_comments_number', $count);
530}
531
532/**
533 * Display the language string for the number of comments the current post has.
534 *
535 * @since 0.71
536 * @uses $id
537 * @uses apply_filters() Calls the 'comments_number' hook on the output and number of comments respectively.
538 *
539 * @param string $zero Text for no comments
540 * @param string $one Text for one comment
541 * @param string $more Text for more than one comment
542 * @param string $deprecated Not used.
543 */
544function comments_number( $zero = false, $one = false, $more = false, $deprecated = '' ) {
545 global $id;
546 $number = get_comments_number($id);
547
548 if ( $number > 1 )
549 $output = str_replace('%', number_format_i18n($number), ( false === $more ) ? __('% Comments') : $more);
550 elseif ( $number == 0 )
551 $output = ( false === $zero ) ? __('No Comments') : $zero;
552 else // must be one
553 $output = ( false === $one ) ? __('1 Comment') : $one;
554
555 echo apply_filters('comments_number', $output, $number);
556}
557
558/**
559 * Retrieve the text of the current comment.
560 *
561 * @since 1.5.0
562 * @uses $comment
563 *
564 * @return string The comment content
565 */
566function get_comment_text() {
567 global $comment;
568 return apply_filters('get_comment_text', $comment->comment_content);
569}
570
571/**
572 * Displays the text of the current comment.
573 *
574 * @since 0.71
575 * @uses apply_filters() Passes the comment content through the 'comment_text' hook before display
576 * @uses get_comment_text() Gets the comment content
577
578hacked for pgp.
579 */
580function comment_text() {
581
582 $comment_content = get_comment_text();
583
584 $dead = array("\n", ' ');
585 $live = array('<br />', '&nbsp;&nbsp;');
586
587 if (strpos($comment_content,"----BEGIN PGP ")>0)
588 echo str_replace($dead, $live, str_replace("\r\n","\n",strip_tags($comment_content)));
589 else echo apply_filters('comment_text', $comment_content);
590}
591
592/**
593 * Retrieve the comment time of the current comment.
594 *
595 * @since 1.5.0
596 * @uses $comment
597 * @uses apply_filter() Calls 'get_comment_time' hook with the formatted time, the $d parameter, and $gmt parameter passed.
598 *
599 * @param string $d Optional. The format of the time (defaults to user's config)
600 * @param bool $gmt Whether to use the GMT date
601 * @return string The formatted time
602 */
603function get_comment_time( $d = '', $gmt = false ) {
604 global $comment;
605 $comment_date = $gmt? $comment->comment_date_gmt : $comment->comment_date;
606 if ( '' == $d )
607 $date = mysql2date(get_option('time_format'), $comment_date);
608 else
609 $date = mysql2date($d, $comment_date);
610 return apply_filters('get_comment_time', $date, $d, $gmt);
611}
612
613/**
614 * Display the comment time of the current comment.
615 *
616 * @since 0.71
617 *
618 * @param string $d Optional. The format of the time (defaults to user's config)
619 */
620function comment_time( $d = '' ) {
621 echo get_comment_time($d);
622}
623
624/**
625 * Retrieve the comment type of the current comment.
626 *
627 * @since 1.5.0
628 * @uses $comment
629 * @uses apply_filters() Calls the 'get_comment_type' hook on the comment type
630 *
631 * @return string The comment type
632 */
633function get_comment_type() {
634 global $comment;
635
636 if ( '' == $comment->comment_type )
637 $comment->comment_type = 'comment';
638
639 return apply_filters('get_comment_type', $comment->comment_type);
640}
641
642/**
643 * Display the comment type of the current comment.
644 *
645 * @since 0.71
646 *
647 * @param string $commenttxt The string to display for comment type
648 * @param string $trackbacktxt The string to display for trackback type
649 * @param string $pingbacktxt The string to display for pingback type
650 */
651function comment_type($commenttxt = 'Comment', $trackbacktxt = 'Trackback', $pingbacktxt = 'Pingback') {
652 $type = get_comment_type();
653 switch( $type ) {
654 case 'trackback' :
655 echo $trackbacktxt;
656 break;
657 case 'pingback' :
658 echo $pingbacktxt;
659 break;
660 default :
661 echo $commenttxt;
662 }
663}
664
665/**
666 * Retrieve The current post's trackback URL.
667 *
668 * There is a check to see if permalink's have been enabled and if so, will
669 * 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.
671 *
672 * @since 1.5.0
673 * @uses apply_filters() Calls 'trackback_url' on the resulting trackback URL
674 * @uses $id
675 *
676 * @return string The trackback URL after being filtered
677 */
678function get_trackback_url() {
679 global $id;
680 if ( '' != get_option('permalink_structure') ) {
681 $tb_url = trailingslashit(get_permalink()) . user_trailingslashit('trackback', 'single_trackback');
682 } else {
683 $tb_url = get_option('siteurl') . '/wp-trackback.php?p=' . $id;
684 }
685 return apply_filters('trackback_url', $tb_url);
686}
687
688/**
689 * Displays the current post's trackback URL.
690 *
691 * @since 0.71
692 * @uses get_trackback_url() Gets the trackback url for the current post
693 *
694 * @param bool $deprecated 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.
696 */
697function trackback_url($deprecated = true) {
698 if ($deprecated) echo get_trackback_url();
699 else return get_trackback_url();
700}
701
702/**
703 * Generates and displays the RDF for the trackback information of current post.
704 *
705 * @since 0.71
706 *
707 * @param int $deprecated Not used (Was $timezone = 0)
708 */
709function trackback_rdf($deprecated = '') {
710 if (stripos($_SERVER['HTTP_USER_AGENT'], 'W3C_Validator') === false) {
711 echo '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
712 xmlns:dc="http://purl.org/dc/elements/1.1/"
713 xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
714 <rdf:Description rdf:about="';
715 the_permalink();
716 echo '"'."\n";
717 echo ' dc:identifier="';
718 the_permalink();
719 echo '"'."\n";
720 echo ' dc:title="'.str_replace('--', '&#x2d;&#x2d;', wptexturize(strip_tags(get_the_title()))).'"'."\n";
721 echo ' trackback:ping="'.get_trackback_url().'"'." />\n";
722 echo '</rdf:RDF>';
723 }
724}
725
726/**
727 * Whether the current post is open for comments.
728 *
729 * @since 1.5.0
730 * @uses $post
731 *
732 * @param int $post_id An optional post ID to check instead of the current post.
733 * @return bool True if the comments are open
734 */
735function comments_open( $post_id=NULL ) {
736
737 $_post = get_post($post_id);
738
739 $open = ( 'open' == $_post->comment_status );
740 return apply_filters( 'comments_open', $open, $post_id );
741}
742
743/**
744 * Whether the current post is open for pings.
745 *
746 * @since 1.5.0
747 * @uses $post
748 *
749 * @param int $post_id An optional post ID to check instead of the current post.
750 * @return bool True if pings are accepted
751 */
752function pings_open( $post_id = NULL ) {
753
754 $_post = get_post($post_id);
755
756 $open = ( 'open' == $_post->ping_status );
757 return apply_filters( 'pings_open', $open, $post_id );
758}
759
760/**
761 * Displays form token for unfiltered comments.
762 *
763 * Will only display nonce token if the current user has permissions for
764 * unfiltered html. Won't display the token for other users.
765 *
766 * The function was backported to 2.0.10 and was added to versions 2.1.3 and
767 * above. Does not exist in versions prior to 2.0.10 in the 2.0 branch and in
768 * the 2.1 branch, prior to 2.1.3. Technically added in 2.2.0.
769 *
770 * Backported to 2.0.10.
771 *
772 * @since 2.1.3
773 * @uses $post Gets the ID of the current post for the token
774 */
775function wp_comment_form_unfiltered_html_nonce() {
776 global $post;
777
778 $post_id = 0;
779 if ( !empty($post) )
780 $post_id = $post->ID;
781
782 if ( current_user_can('unfiltered_html') )
783 wp_nonce_field('unfiltered-html-comment_' . $post_id, '_wp_unfiltered_html_comment', false);
784}
785
786/**
787 * Loads the comment template specified in $file.
788 *
789 * Will not display the comments template if not on single post or page, or if
790 * the post does not have comments.
791 *
792 * Uses the WordPress database object to query for the comments. The comments
793 * are passed through the 'comments_array' filter hook with the list of comments
794 * and the post ID respectively.
795 *
796 * The $file path is passed through a filter hook called, 'comments_template'
797 * 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
799 * 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.
801 *
802 * @since 1.5.0
803 * @global array $comment List of comment objects for the current post
804 * @uses $wpdb
805 * @uses $id
806 * @uses $post
807 * @uses $withcomments Will not try to get the comments if the post has none.
808 *
809 * @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.
811 * @return null Returns null if no comments appear
812 */
813function comments_template( $file = '/comments.php', $separate_comments = false ) {
814 global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity, $overridden_cpage;
815
816 if ( ! (is_single() || is_page() || $withcomments) )
817 return;
818
819 if ( empty($file) )
820 $file = '/comments.php';
821
822 $req = get_option('require_name_email');
823 $commenter = wp_get_current_commenter();
824 extract($commenter, EXTR_SKIP);
825
826 /** @todo Use API instead of SELECTs. */
827 if ( $user_ID) {
828 $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));
829 } else if ( empty($comment_author) ) {
830 $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));
831 } else {
832 $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));
833 }
834
835 // keep $comments for legacy's sake
836 $wp_query->comments = apply_filters( 'comments_array', $comments, $post->ID );
837 $comments = &$wp_query->comments;
838 $wp_query->comment_count = count($wp_query->comments);
839 update_comment_cache($wp_query->comments);
840
841 if ( $separate_comments ) {
842 $wp_query->comments_by_type = &separate_comments($comments);
843 $comments_by_type = &$wp_query->comments_by_type;
844 }
845
846 $overridden_cpage = FALSE;
847 if ( '' == get_query_var('cpage') && get_option('page_comments') && 'newest' == get_option('default_comments_page') ) {
848 set_query_var( 'cpage', get_comment_pages_count() );
849 $overridden_cpage = TRUE;
850 }
851
852 define('COMMENTS_TEMPLATE', true);
853
854 $include = apply_filters('comments_template', STYLESHEETPATH . $file );
855 if ( file_exists( $include ) )
856 require( $include );
857 elseif ( file_exists( TEMPLATEPATH . $file ) )
858 require( TEMPLATEPATH . $file );
859 else
860 require( get_theme_root() . '/default/comments.php');
861}
862
863/**
864 * Displays the JS popup script to show a comment.
865 *
866 * If the $file parameter is empty, then the home page is assumed. The defaults
867 * for the window are 400px by 400px.
868 *
869 * For the comment link popup to work, this function has to be called or the
870 * normal comment link will be assumed.
871 *
872 * @since 0.71
873 * @global string $wpcommentspopupfile The URL to use for the popup window
874 * @global int $wpcommentsjavascript Whether to use JavaScript or not. Set when function is called
875 *
876 * @param int $width Optional. The width of the popup window
877 * @param int $height Optional. The height of the popup window
878 * @param string $file Optional. Sets the location of the popup window
879 */
880function comments_popup_script($width=400, $height=400, $file='') {
881 global $wpcommentspopupfile, $wpcommentsjavascript;
882
883 if (empty ($file)) {
884 $wpcommentspopupfile = ''; // Use the index.
885 } else {
886 $wpcommentspopupfile = $file;
887 }
888
889 $wpcommentsjavascript = 1;
890 $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";
891 echo $javascript;
892}
893
894/**
895 * Displays the link to the comments popup window for the current post ID.
896 *
897 * Is not meant to be displayed on single posts and pages. Should be used on the
898 * lists of posts
899 *
900 * @since 0.71
901 * @uses $id
902 * @uses $wpcommentspopupfile
903 * @uses $wpcommentsjavascript
904 * @uses $post
905 *
906 * @param string $zero The string to display when no comments
907 * @param string $one The string to display when only one comment is available
908 * @param string $more The string to display when there are more than one comment
909 * @param string $css_class The CSS class to use for comments
910 * @param string $none The string to display when comments have been turned off
911 * @return null Returns null on single posts and pages.
912 */
913function comments_popup_link( $zero = 'No Comments', $one = '1 Comment', $more = '% Comments', $css_class = '', $none = 'Comments Off' ) {
914 global $id, $wpcommentspopupfile, $wpcommentsjavascript, $post;
915
916 if ( is_single() || is_page() )
917 return;
918
919 $number = get_comments_number( $id );
920
921 if ( 0 == $number && 'closed' == $post->comment_status && 'closed' == $post->ping_status ) {
922 echo '<span' . ((!empty($css_class)) ? ' class="' . $css_class . '"' : '') . '>' . $none . '</span>';
923 return;
924 }
925
926 if ( post_password_required() ) {
927 echo __('Enter your password to view comments');
928 return;
929 }
930
931 echo '<a href="';
932 if ( $wpcommentsjavascript ) {
933 if ( empty( $wpcommentspopupfile ) )
934 $home = get_option('home');
935 else
936 $home = get_option('siteurl');
937 echo $home . '/' . $wpcommentspopupfile . '?comments_popup=' . $id;
938 echo '" onclick="wpopen(this.href); return false"';
939 } else { // if comments_popup_script() is not in the template, display simple comment link
940 if ( 0 == $number )
941 echo get_permalink() . '#respond';
942 else
943 comments_link();
944 echo '"';
945 }
946
947 if ( !empty( $css_class ) ) {
948 echo ' class="'.$css_class.'" ';
949 }
950 $title = attribute_escape( get_the_title() );
951
952 echo apply_filters( 'comments_popup_link_attributes', '' );
953
954 echo ' title="' . sprintf( __('Comment on %s'), $title ) . '">';
955 comments_number( $zero, $one, $more, $number );
956 echo '</a>';
957}
958
959/**
960 * Retrieve HTML content for reply to comment link.
961 *
962 * The default arguments that can be override are 'add_below', 'respond_id',
963 * 'reply_text', 'login_text', and 'depth'. The 'login_text' argument will be
964 * used, if the user must log in or register first before posting a comment. The
965 * 'reply_text' will be used, if they can post a reply. The 'add_below' and
966 * 'respond_id' arguments are for the JavaScript moveAddCommentForm() function
967 * parameters.
968 *
969 * @since 2.7.0
970 *
971 * @param array $args Optional. Override default options.
972 * @param int $comment Optional. Comment being replied to.
973 * @param int $post Optional. Post that the comment is going to be displayed on.
974 * @return string|bool|null Link to show comment form, if successful. False, if comments are closed.
975 */
976function get_comment_reply_link($args = array(), $comment = null, $post = null) {
977 global $user_ID;
978
979 $defaults = array('add_below' => 'comment', 'respond_id' => 'respond', 'reply_text' => __('Reply'),
980 'login_text' => __('Log in to Reply'), 'depth' => 0, 'before' => '', 'after' => '');
981
982 $args = wp_parse_args($args, $defaults);
983
984 if ( 0 == $args['depth'] || $args['max_depth'] <= $args['depth'] )
985 return;
986
987 extract($args, EXTR_SKIP);
988
989 $comment = get_comment($comment);
990 $post = get_post($post);
991
992 if ( 'open' != $post->comment_status )
993 return false;
994
995 $link = '';
996
997 if ( get_option('comment_registration') && !$user_ID )
998// Removed rel="nofollow" from here
999 $link = '<a href="' . site_url('wp-login.php?redirect_to=' . get_permalink()) . '">' . $login_text . '</a>';
1000 else
1001// Removed rel="nofollow" from here
1002 $link = "<a href='" . wp_specialchars( 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>";
1003 return apply_filters('comment_reply_link', $before . $link . $after, $args, $comment, $post);
1004}
1005
1006/**
1007 * Displays the HTML content for reply to comment link.
1008 *
1009 * @since 2.7.0
1010 * @see get_comment_reply_link() Echoes result
1011 *
1012 * @param array $args Optional. Override default options.
1013 * @param int $comment Optional. Comment being replied to.
1014 * @param int $post Optional. Post that the comment is going to be displayed on.
1015 * @return string|bool|null Link to show comment form, if successful. False, if comments are closed.
1016 */
1017function comment_reply_link($args = array(), $comment = null, $post = null) {
1018 echo get_comment_reply_link($args, $comment, $post);
1019}
1020
1021/**
1022 * Retrieve HTML content for reply to post link.
1023 *
1024 * The default arguments that can be override are 'add_below', 'respond_id',
1025 * 'reply_text', 'login_text', and 'depth'. The 'login_text' argument will be
1026 * used, if the user must log in or register first before posting a comment. The
1027 * 'reply_text' will be used, if they can post a reply. The 'add_below' and
1028 * 'respond_id' arguments are for the JavaScript moveAddCommentForm() function
1029 * parameters.
1030 *
1031 * @since 2.7.0
1032 *
1033 * @param array $args Optional. Override default options.
1034 * @param int|object $post Optional. Post that the comment is going to be displayed on. Defaults to current post.
1035 * @return string|bool|null Link to show comment form, if successful. False, if comments are closed.
1036 */
1037function get_post_reply_link($args = array(), $post = null) {
1038 global $user_ID;
1039
1040 $defaults = array('add_below' => 'post', 'respond_id' => 'respond', 'reply_text' => __('Leave a Comment'),
1041 'login_text' => __('Log in to leave a Comment'), 'before' => '', 'after' => '');
1042
1043 $args = wp_parse_args($args, $defaults);
1044 extract($args, EXTR_SKIP);
1045 $post = get_post($post);
1046
1047 if ( !comments_open($post->ID) )
1048 return false;
1049
1050 if ( get_option('comment_registration') && !$user_ID ) {
1051// Removed rel="nofollow" from here
1052 $link = '<a href="' . site_url('wp-login.php?redirect_to=' . get_permalink()) . '">' . $login_text . '</a>';
1053 } else {
1054// Removed rel="nofollow" from here
1055 $link = "<a href='" . get_permalink($post->ID) . "#$respond_id' onclick='return addComment.moveForm(\"$add_below-$post->ID\", \"0\", \"$respond_id\", \"$post->ID\")'>$reply_text</a>";
1056 }
1057 return apply_filters('post_comments_link', $before . $link . $after, $post);
1058}
1059
1060/**
1061 * Displays the HTML content for reply to post link.
1062 * @since 2.7.0
1063 * @see get_post_reply_link()
1064 *
1065 * @param array $args Optional. Override default options.
1066 * @param int|object $post Optional. Post that the comment is going to be displayed on.
1067 * @return string|bool|null Link to show comment form, if successful. False, if comments are closed.
1068 */
1069function post_reply_link($args = array(), $post = null) {
1070 echo get_post_reply_link($args, $post);
1071}
1072
1073/**
1074 * Retrieve HTML content for cancel comment reply link.
1075 *
1076 * @since 2.7.0
1077 *
1078 * @param string $text Optional. Text to display for cancel reply link.
1079 */
1080function get_cancel_comment_reply_link($text = '') {
1081 if ( empty($text) )
1082 $text = __('Click here to cancel reply.');
1083
1084 $style = isset($_GET['replytocom']) ? '' : ' style="display:none;"';
1085 $link = wp_specialchars( remove_query_arg('replytocom') ) . '#respond';
1086// Removed rel="nofollow" from here
1087 return apply_filters('cancel_comment_reply_link', '<a id="cancel-comment-reply-link" href="' . $link . '"' . $style . '>' . $text . '</a>', $link, $text);
1088}
1089
1090/**
1091 * Display HTML content for cancel comment reply link.
1092 *
1093 * @since 2.7.0
1094 *
1095 * @param string $text Optional. Text to display for cancel reply link.
1096 */
1097function cancel_comment_reply_link($text = '') {
1098 echo get_cancel_comment_reply_link($text);
1099}
1100
1101/**
1102 * Output hidden input HTML for replying to comments.
1103 *
1104 * @since 2.7.0
1105 */
1106function comment_id_fields() {
1107 global $id;
1108
1109 $replytoid = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0;
1110 echo "<input type='hidden' name='comment_post_ID' value='$id' id='comment_post_ID' />\n";
1111 echo "<input type='hidden' name='comment_parent' id='comment_parent' value='$replytoid' />\n";
1112}
1113
1114/**
1115 * Display text based on comment reply status. Only affects users with Javascript disabled.
1116 *
1117 * @since 2.7.0
1118 *
1119 * @param string $noreplytext Optional. Text to display when not replying to a comment.
1120 * @param string $replytext Optional. Text to display when replying to a comment. Accepts "%s" for the author of the comment being replied to.
1121 * @param string $linktoparent Optional. Boolean to control making the author's name a link to their comment.
1122 */
1123function comment_form_title( $noreplytext = 'Leave a Reply', $replytext = 'Leave a Reply to %s', $linktoparent = TRUE ) {
1124 global $comment;
1125
1126 $replytoid = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0;
1127
1128 if ( 0 == $replytoid )
1129 echo $noreplytext;
1130 else {
1131 $comment = get_comment($replytoid);
1132 $author = ( $linktoparent ) ? '<a href="#comment-' . get_comment_ID() . '">' . get_comment_author() . '</a>' : get_comment_author();
1133 printf( $replytext, $author );
1134 }
1135}
1136
1137/**
1138 * HTML comment list class.
1139 *
1140 * @package WordPress
1141 * @uses Walker
1142 * @since unknown
1143 */
1144class Walker_Comment extends Walker {
1145 /**
1146 * @see Walker::$tree_type
1147 * @since unknown
1148 * @var string
1149 */
1150 var $tree_type = 'comment';
1151
1152 /**
1153 * @see Walker::$db_fields
1154 * @since unknown
1155 * @var array
1156 */
1157 var $db_fields = array ('parent' => 'comment_parent', 'id' => 'comment_ID');
1158
1159 /**
1160 * @see Walker::start_lvl()
1161 * @since unknown
1162 *
1163 * @param string $output Passed by reference. Used to append additional content.
1164 * @param int $depth Depth of comment.
1165 * @param array $args Uses 'style' argument for type of HTML list.
1166 */
1167 function start_lvl(&$output, $depth, $args) {
1168 $GLOBALS['comment_depth'] = $depth + 1;
1169
1170 switch ( $args['style'] ) {
1171 case 'div':
1172 break;
1173 case 'ol':
1174 echo "<ol class='children'>\n";
1175 break;
1176 default:
1177 case 'ul':
1178 echo "<ul class='children'>\n";
1179 break;
1180 }
1181 }
1182
1183 /**
1184 * @see Walker::end_lvl()
1185 * @since unknown
1186 *
1187 * @param string $output Passed by reference. Used to append additional content.
1188 * @param int $depth Depth of comment.
1189 * @param array $args Will only append content if style argument value is 'ol' or 'ul'.
1190 */
1191 function end_lvl(&$output, $depth, $args) {
1192 $GLOBALS['comment_depth'] = $depth + 1;
1193
1194 switch ( $args['style'] ) {
1195 case 'div':
1196 break;
1197 case 'ol':
1198 echo "</ol>\n";
1199 break;
1200 default:
1201 case 'ul':
1202 echo "</ul>\n";
1203 break;
1204 }
1205 }
1206
1207 /**
1208 * @see Walker::start_el()
1209 * @since unknown
1210 *
1211 * @param string $output Passed by reference. Used to append additional content.
1212 * @param object $comment Comment data object.
1213 * @param int $depth Depth of comment in reference to parents.
1214 * @param array $args
1215 */
1216 function start_el(&$output, $comment, $depth, $args) {
1217 $depth++;
1218 $GLOBALS['comment_depth'] = $depth;
1219
1220 if ( !empty($args['callback']) ) {
1221 call_user_func($args['callback'], $comment, $args, $depth);
1222 return;
1223 }
1224
1225 $GLOBALS['comment'] = $comment;
1226 extract($args, EXTR_SKIP);
1227
1228 if ( 'div' == $args['style'] ) {
1229 $tag = 'div';
1230 $add_below = 'comment';
1231 } else {
1232 $tag = 'li';
1233 $add_below = 'div-comment';
1234 }
1235?>
1236 <<?php echo $tag ?> <?php comment_class(empty( $args['has_children'] ) ? '' : 'parent') ?> id="comment-<?php comment_ID() ?>">
1237 <?php if ( 'ul' == $args['style'] ) : ?>
1238 <div id="div-comment-<?php comment_ID() ?>">
1239 <?php endif; ?>
1240 <div class="comment-author vcard">
1241 <?php if ($args['avatar_size'] != 0) echo get_avatar( $comment, $args['avatar_size'] ); ?>
1242 <?php printf(__('<cite class="fn">%s</cite> <span class="says">says:</span>'), get_comment_author_link()) ?>
1243 </div>
1244<?php if ($comment->comment_approved == '0') : ?>
1245 <em><?php _e('Your comment is awaiting moderation.') ?></em>
1246 <br />
1247<?php endif; ?>
1248
1249 <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>
1250
1251 <?php comment_text() ?>
1252
1253 <div class="reply">
1254 <?php comment_reply_link(array_merge( $args, array('add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
1255 </div>
1256 <?php if ( 'ul' == $args['style'] ) : ?>
1257 </div>
1258 <?php endif; ?>
1259<?php
1260 }
1261
1262 /**
1263 * @see Walker::end_el()
1264 * @since unknown
1265 *
1266 * @param string $output Passed by reference. Used to append additional content.
1267 * @param object $comment
1268 * @param int $depth Depth of comment.
1269 * @param array $args
1270 */
1271 function end_el(&$output, $comment, $depth, $args) {
1272 if ( !empty($args['end-callback']) ) {
1273 call_user_func($args['end-callback'], $comment, $args, $depth);
1274 return;
1275 }
1276 if ( 'div' == $args['style'] )
1277 echo "</div>\n";
1278 else
1279 echo "</li>\n";
1280 }
1281
1282}
1283
1284/**
1285 * List comments
1286 *
1287 * Used in the comments.php template to list comments for a particular post
1288 *
1289 * @since 2.7.0
1290 * @uses Walker_Comment
1291 *
1292 * @param string|array $args Formatting options
1293 * @param array $comments Optional array of comment objects. Defaults to $wp_query->comments
1294 */
1295function wp_list_comments($args = array(), $comments = null ) {
1296 global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop;
1297
1298 $in_comment_loop = true;
1299
1300 $comment_alt = $comment_thread_alt = 0;
1301 $comment_depth = 1;
1302
1303 $defaults = array('walker' => null, 'max_depth' => '', 'style' => 'ul', 'callback' => null, 'end-callback' => null, 'type' => 'all',
1304 'page' => '', 'per_page' => '', 'avatar_size' => 32, 'reverse_top_level' => null, 'reverse_children' => '');
1305
1306 $r = wp_parse_args( $args, $defaults );
1307
1308 // Figure out what comments we'll be looping through ($_comments)
1309 if ( null !== $comments ) {
1310 $comments = (array) $comments;
1311 if ( empty($comments) )
1312 return;
1313 if ( 'all' != $r['type'] ) {
1314 $comments_by_type = &separate_comments($comments);
1315 if ( empty($comments_by_type[$r['type']]) )
1316 return;
1317 $_comments = $comments_by_type[$r['type']];
1318 } else {
1319 $_comments = $comments;
1320 }
1321 } else {
1322 if ( empty($wp_query->comments) )
1323 return;
1324 if ( 'all' != $r['type'] ) {
1325 if ( empty($wp_query->comments_by_type) )
1326 $wp_query->comments_by_type = &separate_comments($wp_query->comments);
1327 if ( empty($wp_query->comments_by_type[$r['type']]) )
1328 return;
1329 $_comments = $wp_query->comments_by_type[$r['type']];
1330 } else {
1331 $_comments = $wp_query->comments;
1332 }
1333 }
1334
1335 if ( '' === $r['per_page'] && get_option('page_comments') )
1336 $r['per_page'] = get_query_var('comments_per_page');
1337
1338 if ( empty($r['per_page']) ) {
1339 $r['per_page'] = 0;
1340 $r['page'] = 0;
1341 }
1342
1343 if ( '' === $r['max_depth'] ) {
1344 if ( get_option('thread_comments') )
1345 $r['max_depth'] = get_option('thread_comments_depth');
1346 else
1347 $r['max_depth'] = -1;
1348 }
1349
1350 if ( '' === $r['page'] ) {
1351 if ( empty($overridden_cpage) ) {
1352 $r['page'] = get_query_var('cpage');
1353 } else {
1354 $threaded = ( -1 == $r['max_depth'] ) ? false : true;
1355 $r['page'] = ( 'newest' == get_option('default_comments_page') ) ? get_comment_pages_count($_comments, $r['per_page'], $threaded) : 1;
1356 set_query_var( 'cpage', $r['page'] );
1357 }
1358 }
1359 // Validation check
1360 $r['page'] = intval($r['page']);
1361 if ( 0 == $r['page'] && 0 != $r['per_page'] )
1362 $r['page'] = 1;
1363
1364 if ( null === $r['reverse_top_level'] )
1365 $r['reverse_top_level'] = ( 'desc' == get_option('comment_order') ) ? TRUE : FALSE;
1366
1367 extract( $r, EXTR_SKIP );
1368
1369 if ( empty($walker) )
1370 $walker = new Walker_Comment;
1371
1372 $walker->paged_walk($_comments, $max_depth, $page, $per_page, $r);
1373 $wp_query->max_num_comment_pages = $walker->max_pages;
1374
1375 $in_comment_loop = false;
1376}
1377
1378?>