|
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 */ |
|
22 function 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 */ |
|
43 function 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 */ |
|
57 function 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 */ |
|
74 function 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 */ |
|
96 function 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 */ |
|
118 function 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 */ |
|
140 function 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 $return = "<a href='$url' rel='external nofollow' class='url'>$author</a>"; |
|
149 return apply_filters('get_comment_author_link', $return); |
|
150 } |
|
151 |
|
152 /** |
|
153 * Display the html link to the url of the author of the current comment. |
|
154 * |
|
155 * @since 0.71 |
|
156 * @see get_comment_author_link() Echos result |
|
157 */ |
|
158 function comment_author_link() { |
|
159 echo get_comment_author_link(); |
|
160 } |
|
161 |
|
162 /** |
|
163 * Retrieve the IP address of the author of the current comment. |
|
164 * |
|
165 * @since 1.5.0 |
|
166 * @uses $comment |
|
167 * @uses apply_filters() |
|
168 * |
|
169 * @return unknown |
|
170 */ |
|
171 function get_comment_author_IP() { |
|
172 global $comment; |
|
173 return apply_filters('get_comment_author_IP', $comment->comment_author_IP); |
|
174 } |
|
175 |
|
176 /** |
|
177 * Display the IP address of the author of the current comment. |
|
178 * |
|
179 * @since 0.71 |
|
180 * @see get_comment_author_IP() Echos Result |
|
181 */ |
|
182 function comment_author_IP() { |
|
183 echo get_comment_author_IP(); |
|
184 } |
|
185 |
|
186 /** |
|
187 * Retrieve the url of the author of the current comment. |
|
188 * |
|
189 * @since 1.5.0 |
|
190 * @uses apply_filters() Calls 'get_comment_author_url' hook on the comment author's URL |
|
191 * |
|
192 * @return string |
|
193 */ |
|
194 function get_comment_author_url() { |
|
195 global $comment; |
|
196 $url = ('http://' == $comment->comment_author_url) ? '' : $comment->comment_author_url; |
|
197 $url = esc_url( $url, array('http', 'https') ); |
|
198 return apply_filters('get_comment_author_url', $url); |
|
199 } |
|
200 |
|
201 /** |
|
202 * Display the url of the author of the current comment. |
|
203 * |
|
204 * @since 0.71 |
|
205 * @uses apply_filters() |
|
206 * @uses get_comment_author_url() Retrieves the comment author's URL |
|
207 */ |
|
208 function comment_author_url() { |
|
209 echo apply_filters('comment_url', get_comment_author_url()); |
|
210 } |
|
211 |
|
212 /** |
|
213 * Retrieves the HTML link of the url of the author of the current comment. |
|
214 * |
|
215 * $linktext parameter is only used if the URL does not exist for the comment |
|
216 * author. If the URL does exist then the URL will be used and the $linktext |
|
217 * will be ignored. |
|
218 * |
|
219 * Encapsulate the HTML link between the $before and $after. So it will appear |
|
220 * in the order of $before, link, and finally $after. |
|
221 * |
|
222 * @since 1.5.0 |
|
223 * @uses apply_filters() Calls the 'get_comment_author_url_link' on the complete HTML before returning. |
|
224 * |
|
225 * @param string $linktext The text to display instead of the comment author's email address |
|
226 * @param string $before The text or HTML to display before the email link. |
|
227 * @param string $after The text or HTML to display after the email link. |
|
228 * @return string The HTML link between the $before and $after parameters |
|
229 */ |
|
230 function get_comment_author_url_link( $linktext = '', $before = '', $after = '' ) { |
|
231 $url = get_comment_author_url(); |
|
232 $display = ($linktext != '') ? $linktext : $url; |
|
233 $display = str_replace( 'http://www.', '', $display ); |
|
234 $display = str_replace( 'http://', '', $display ); |
|
235 if ( '/' == substr($display, -1) ) |
|
236 $display = substr($display, 0, -1); |
|
237 $return = "$before<a href='$url' rel='external'>$display</a>$after"; |
|
238 return apply_filters('get_comment_author_url_link', $return); |
|
239 } |
|
240 |
|
241 /** |
|
242 * Displays the HTML link of the url of the author of the current comment. |
|
243 * |
|
244 * @since 0.71 |
|
245 * @see get_comment_author_url_link() Echos result |
|
246 * |
|
247 * @param string $linktext The text to display instead of the comment author's email address |
|
248 * @param string $before The text or HTML to display before the email link. |
|
249 * @param string $after The text or HTML to display after the email link. |
|
250 */ |
|
251 function comment_author_url_link( $linktext = '', $before = '', $after = '' ) { |
|
252 echo get_comment_author_url_link( $linktext, $before, $after ); |
|
253 } |
|
254 |
|
255 /** |
|
256 * Generates semantic classes for each comment element |
|
257 * |
|
258 * @since 2.7.0 |
|
259 * |
|
260 * @param string|array $class One or more classes to add to the class list |
|
261 * @param int $comment_id An optional comment ID |
|
262 * @param int $post_id An optional post ID |
|
263 * @param bool $echo Whether comment_class should echo or return |
|
264 */ |
|
265 function comment_class( $class = '', $comment_id = null, $post_id = null, $echo = true ) { |
|
266 // Separates classes with a single space, collates classes for comment DIV |
|
267 $class = 'class="' . join( ' ', get_comment_class( $class, $comment_id, $post_id ) ) . '"'; |
|
268 if ( $echo) |
|
269 echo $class; |
|
270 else |
|
271 return $class; |
|
272 } |
|
273 |
|
274 /** |
|
275 * Returns the classes for the comment div as an array |
|
276 * |
|
277 * @since 2.7.0 |
|
278 * |
|
279 * @param string|array $class One or more classes to add to the class list |
|
280 * @param int $comment_id An optional comment ID |
|
281 * @param int $post_id An optional post ID |
|
282 * @return array Array of classes |
|
283 */ |
|
284 function get_comment_class( $class = '', $comment_id = null, $post_id = null ) { |
|
285 global $comment_alt, $comment_depth, $comment_thread_alt; |
|
286 |
|
287 $comment = get_comment($comment_id); |
|
288 |
|
289 $classes = array(); |
|
290 |
|
291 // Get the comment type (comment, trackback), |
|
292 $classes[] = ( empty( $comment->comment_type ) ) ? 'comment' : $comment->comment_type; |
|
293 |
|
294 // If the comment author has an id (registered), then print the log in name |
|
295 if ( $comment->user_id > 0 && $user = get_userdata($comment->user_id) ) { |
|
296 // For all registered users, 'byuser' |
|
297 $classes[] = 'byuser'; |
|
298 $classes[] = 'comment-author-' . sanitize_html_class($user->user_nicename, $comment->user_id); |
|
299 // For comment authors who are the author of the post |
|
300 if ( $post = get_post($post_id) ) { |
|
301 if ( $comment->user_id === $post->post_author ) |
|
302 $classes[] = 'bypostauthor'; |
|
303 } |
|
304 } |
|
305 |
|
306 if ( empty($comment_alt) ) |
|
307 $comment_alt = 0; |
|
308 if ( empty($comment_depth) ) |
|
309 $comment_depth = 1; |
|
310 if ( empty($comment_thread_alt) ) |
|
311 $comment_thread_alt = 0; |
|
312 |
|
313 if ( $comment_alt % 2 ) { |
|
314 $classes[] = 'odd'; |
|
315 $classes[] = 'alt'; |
|
316 } else { |
|
317 $classes[] = 'even'; |
|
318 } |
|
319 |
|
320 $comment_alt++; |
|
321 |
|
322 // Alt for top-level comments |
|
323 if ( 1 == $comment_depth ) { |
|
324 if ( $comment_thread_alt % 2 ) { |
|
325 $classes[] = 'thread-odd'; |
|
326 $classes[] = 'thread-alt'; |
|
327 } else { |
|
328 $classes[] = 'thread-even'; |
|
329 } |
|
330 $comment_thread_alt++; |
|
331 } |
|
332 |
|
333 $classes[] = "depth-$comment_depth"; |
|
334 |
|
335 if ( !empty($class) ) { |
|
336 if ( !is_array( $class ) ) |
|
337 $class = preg_split('#\s+#', $class); |
|
338 $classes = array_merge($classes, $class); |
|
339 } |
|
340 |
|
341 $classes = array_map('esc_attr', $classes); |
|
342 |
|
343 return apply_filters('comment_class', $classes, $class, $comment_id, $post_id); |
|
344 } |
|
345 |
|
346 /** |
|
347 * Retrieve the comment date of the current comment. |
|
348 * |
|
349 * @since 1.5.0 |
|
350 * @uses apply_filters() Calls 'get_comment_date' hook with the formated date and the $d parameter respectively |
|
351 * @uses $comment |
|
352 * |
|
353 * @param string $d The format of the date (defaults to user's config) |
|
354 * @return string The comment's date |
|
355 */ |
|
356 function get_comment_date( $d = '' ) { |
|
357 global $comment; |
|
358 if ( '' == $d ) |
|
359 $date = mysql2date(get_option('date_format'), $comment->comment_date); |
|
360 else |
|
361 $date = mysql2date($d, $comment->comment_date); |
|
362 return apply_filters('get_comment_date', $date, $d); |
|
363 } |
|
364 |
|
365 /** |
|
366 * Display the comment date of the current comment. |
|
367 * |
|
368 * @since 0.71 |
|
369 * |
|
370 * @param string $d The format of the date (defaults to user's config) |
|
371 */ |
|
372 function comment_date( $d = '' ) { |
|
373 echo get_comment_date( $d ); |
|
374 } |
|
375 |
|
376 /** |
|
377 * Retrieve the excerpt of the current comment. |
|
378 * |
|
379 * Will cut each word and only output the first 20 words with '...' at the end. |
|
380 * If the word count is less than 20, then no truncating is done and no '...' |
|
381 * will appear. |
|
382 * |
|
383 * @since 1.5.0 |
|
384 * @uses $comment |
|
385 * @uses apply_filters() Calls 'get_comment_excerpt' on truncated comment |
|
386 * |
|
387 * @return string The maybe truncated comment with 20 words or less |
|
388 */ |
|
389 function get_comment_excerpt() { |
|
390 global $comment; |
|
391 $comment_text = strip_tags($comment->comment_content); |
|
392 $blah = explode(' ', $comment_text); |
|
393 if (count($blah) > 20) { |
|
394 $k = 20; |
|
395 $use_dotdotdot = 1; |
|
396 } else { |
|
397 $k = count($blah); |
|
398 $use_dotdotdot = 0; |
|
399 } |
|
400 $excerpt = ''; |
|
401 for ($i=0; $i<$k; $i++) { |
|
402 $excerpt .= $blah[$i] . ' '; |
|
403 } |
|
404 $excerpt .= ($use_dotdotdot) ? '...' : ''; |
|
405 return apply_filters('get_comment_excerpt', $excerpt); |
|
406 } |
|
407 |
|
408 /** |
|
409 * Display the excerpt of the current comment. |
|
410 * |
|
411 * @since 1.2.0 |
|
412 * @uses apply_filters() Calls 'comment_excerpt' hook before displaying excerpt |
|
413 */ |
|
414 function comment_excerpt() { |
|
415 echo apply_filters('comment_excerpt', get_comment_excerpt() ); |
|
416 } |
|
417 |
|
418 /** |
|
419 * Retrieve the comment id of the current comment. |
|
420 * |
|
421 * @since 1.5.0 |
|
422 * @uses $comment |
|
423 * @uses apply_filters() Calls the 'get_comment_ID' hook for the comment ID |
|
424 * |
|
425 * @return int The comment ID |
|
426 */ |
|
427 function get_comment_ID() { |
|
428 global $comment; |
|
429 return apply_filters('get_comment_ID', $comment->comment_ID); |
|
430 } |
|
431 |
|
432 /** |
|
433 * Displays the comment id of the current comment. |
|
434 * |
|
435 * @since 0.71 |
|
436 * @see get_comment_ID() Echos Result |
|
437 */ |
|
438 function comment_ID() { |
|
439 echo get_comment_ID(); |
|
440 } |
|
441 |
|
442 /** |
|
443 * Retrieve the link to a given comment. |
|
444 * |
|
445 * @since 1.5.0 |
|
446 * @uses $comment |
|
447 * |
|
448 * @param object|string|int $comment Comment to retrieve. |
|
449 * @param array $args Optional args. |
|
450 * @return string The permalink to the given comment. |
|
451 */ |
|
452 function get_comment_link( $comment = null, $args = array() ) { |
|
453 global $wp_rewrite, $in_comment_loop; |
|
454 |
|
455 $comment = get_comment($comment); |
|
456 |
|
457 // Backwards compat |
|
458 if ( !is_array($args) ) { |
|
459 $page = $args; |
|
460 $args = array(); |
|
461 $args['page'] = $page; |
|
462 } |
|
463 |
|
464 $defaults = array( 'type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '' ); |
|
465 $args = wp_parse_args( $args, $defaults ); |
|
466 |
|
467 if ( '' === $args['per_page'] && get_option('page_comments') ) |
|
468 $args['per_page'] = get_option('comments_per_page'); |
|
469 |
|
470 if ( empty($args['per_page']) ) { |
|
471 $args['per_page'] = 0; |
|
472 $args['page'] = 0; |
|
473 } |
|
474 |
|
475 if ( $args['per_page'] ) { |
|
476 if ( '' == $args['page'] ) |
|
477 $args['page'] = ( !empty($in_comment_loop) ) ? get_query_var('cpage') : get_page_of_comment( $comment->comment_ID, $args ); |
|
478 |
|
479 if ( $wp_rewrite->using_permalinks() ) |
|
480 $link = user_trailingslashit( trailingslashit( get_permalink( $comment->comment_post_ID ) ) . 'comment-page-' . $args['page'], 'comment' ); |
|
481 else |
|
482 $link = add_query_arg( 'cpage', $args['page'], get_permalink( $comment->comment_post_ID ) ); |
|
483 } else { |
|
484 $link = get_permalink( $comment->comment_post_ID ); |
|
485 } |
|
486 |
|
487 return apply_filters( 'get_comment_link', $link . '#comment-' . $comment->comment_ID, $comment, $args ); |
|
488 } |
|
489 |
|
490 /** |
|
491 * Retrieves the link to the current post comments. |
|
492 * |
|
493 * @since 1.5.0 |
|
494 * |
|
495 * @return string The link to the comments |
|
496 */ |
|
497 function get_comments_link() { |
|
498 return get_permalink() . '#comments'; |
|
499 } |
|
500 |
|
501 /** |
|
502 * Displays the link to the current post comments. |
|
503 * |
|
504 * @since 0.71 |
|
505 * |
|
506 * @param string $deprecated Not Used |
|
507 * @param bool $deprecated Not Used |
|
508 */ |
|
509 function comments_link( $deprecated = '', $deprecated = '' ) { |
|
510 echo get_comments_link(); |
|
511 } |
|
512 |
|
513 /** |
|
514 * Retrieve the amount of comments a post has. |
|
515 * |
|
516 * @since 1.5.0 |
|
517 * @uses apply_filters() Calls the 'get_comments_number' hook on the number of comments |
|
518 * |
|
519 * @param int $post_id The Post ID |
|
520 * @return int The number of comments a post has |
|
521 */ |
|
522 function get_comments_number( $post_id = 0 ) { |
|
523 global $id; |
|
524 $post_id = (int) $post_id; |
|
525 |
|
526 if ( !$post_id ) |
|
527 $post_id = (int) $id; |
|
528 |
|
529 $post = get_post($post_id); |
|
530 if ( ! isset($post->comment_count) ) |
|
531 $count = 0; |
|
532 else |
|
533 $count = $post->comment_count; |
|
534 |
|
535 return apply_filters('get_comments_number', $count); |
|
536 } |
|
537 |
|
538 /** |
|
539 * Display the language string for the number of comments the current post has. |
|
540 * |
|
541 * @since 0.71 |
|
542 * @uses $id |
|
543 * @uses apply_filters() Calls the 'comments_number' hook on the output and number of comments respectively. |
|
544 * |
|
545 * @param string $zero Text for no comments |
|
546 * @param string $one Text for one comment |
|
547 * @param string $more Text for more than one comment |
|
548 * @param string $deprecated Not used. |
|
549 */ |
|
550 function comments_number( $zero = false, $one = false, $more = false, $deprecated = '' ) { |
|
551 global $id; |
|
552 $number = get_comments_number($id); |
|
553 |
|
554 if ( $number > 1 ) |
|
555 $output = str_replace('%', number_format_i18n($number), ( false === $more ) ? __('% Comments') : $more); |
|
556 elseif ( $number == 0 ) |
|
557 $output = ( false === $zero ) ? __('No Comments') : $zero; |
|
558 else // must be one |
|
559 $output = ( false === $one ) ? __('1 Comment') : $one; |
|
560 |
|
561 echo apply_filters('comments_number', $output, $number); |
|
562 } |
|
563 |
|
564 /** |
|
565 * Retrieve the text of the current comment. |
|
566 * |
|
567 * @since 1.5.0 |
|
568 * @uses $comment |
|
569 * |
|
570 * @return string The comment content |
|
571 */ |
|
572 function get_comment_text() { |
|
573 global $comment; |
|
574 return apply_filters('get_comment_text', $comment->comment_content); |
|
575 } |
|
576 |
|
577 /** |
|
578 * Displays the text of the current comment. |
|
579 * |
|
580 * @since 0.71 |
|
581 * @uses apply_filters() Passes the comment content through the 'comment_text' hook before display |
|
582 * @uses get_comment_text() Gets the comment content |
|
583 */ |
|
584 function comment_text() { |
|
585 echo apply_filters('comment_text', get_comment_text() ); |
|
586 } |
|
587 |
|
588 /** |
|
589 * Retrieve the comment time of the current comment. |
|
590 * |
|
591 * @since 1.5.0 |
|
592 * @uses $comment |
|
593 * @uses apply_filter() Calls 'get_comment_time' hook with the formatted time, the $d parameter, and $gmt parameter passed. |
|
594 * |
|
595 * @param string $d Optional. The format of the time (defaults to user's config) |
|
596 * @param bool $gmt Whether to use the GMT date |
|
597 * @param bool $translate Whether to translate the time (for use in feeds) |
|
598 * @return string The formatted time |
|
599 */ |
|
600 function get_comment_time( $d = '', $gmt = false, $translate = true ) { |
|
601 global $comment; |
|
602 $comment_date = $gmt? $comment->comment_date_gmt : $comment->comment_date; |
|
603 if ( '' == $d ) |
|
604 $date = mysql2date(get_option('time_format'), $comment_date, $translate); |
|
605 else |
|
606 $date = mysql2date($d, $comment_date, $translate); |
|
607 return apply_filters('get_comment_time', $date, $d, $gmt); |
|
608 } |
|
609 |
|
610 /** |
|
611 * Display the comment time of the current comment. |
|
612 * |
|
613 * @since 0.71 |
|
614 * |
|
615 * @param string $d Optional. The format of the time (defaults to user's config) |
|
616 */ |
|
617 function comment_time( $d = '' ) { |
|
618 echo get_comment_time($d); |
|
619 } |
|
620 |
|
621 /** |
|
622 * Retrieve the comment type of the current comment. |
|
623 * |
|
624 * @since 1.5.0 |
|
625 * @uses $comment |
|
626 * @uses apply_filters() Calls the 'get_comment_type' hook on the comment type |
|
627 * |
|
628 * @return string The comment type |
|
629 */ |
|
630 function get_comment_type() { |
|
631 global $comment; |
|
632 |
|
633 if ( '' == $comment->comment_type ) |
|
634 $comment->comment_type = 'comment'; |
|
635 |
|
636 return apply_filters('get_comment_type', $comment->comment_type); |
|
637 } |
|
638 |
|
639 /** |
|
640 * Display the comment type of the current comment. |
|
641 * |
|
642 * @since 0.71 |
|
643 * |
|
644 * @param string $commenttxt The string to display for comment type |
|
645 * @param string $trackbacktxt The string to display for trackback type |
|
646 * @param string $pingbacktxt The string to display for pingback type |
|
647 */ |
|
648 function comment_type($commenttxt = false, $trackbacktxt = false, $pingbacktxt = false) { |
|
649 if ( false === $commenttxt ) $commenttxt = _x( 'Comment', 'noun' ); |
|
650 if ( false === $trackbacktxt ) $trackbacktxt = __( 'Trackback' ); |
|
651 if ( false === $pingbacktxt ) $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 */ |
|
678 function 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 */ |
|
697 function 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 */ |
|
709 function 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('--', '--', 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 */ |
|
735 function 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 */ |
|
752 function 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 */ |
|
775 function 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 */ |
|
813 function 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 |
|
824 /** |
|
825 * Comment author information fetched from the comment cookies. |
|
826 * |
|
827 * @uses wp_get_current_commenter() |
|
828 */ |
|
829 $commenter = wp_get_current_commenter(); |
|
830 |
|
831 /** |
|
832 * The name of the current comment author escaped for use in attributes. |
|
833 */ |
|
834 $comment_author = $commenter['comment_author']; // Escaped by sanitize_comment_cookies() |
|
835 |
|
836 /** |
|
837 * The email address of the current comment author escaped for use in attributes. |
|
838 */ |
|
839 $comment_author_email = $commenter['comment_author_email']; // Escaped by sanitize_comment_cookies() |
|
840 |
|
841 /** |
|
842 * The url of the current comment author escaped for use in attributes. |
|
843 */ |
|
844 $comment_author_url = esc_url($commenter['comment_author_url']); |
|
845 |
|
846 /** @todo Use API instead of SELECTs. */ |
|
847 if ( $user_ID) { |
|
848 $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_gmt", $post->ID, $user_ID)); |
|
849 } else if ( empty($comment_author) ) { |
|
850 $comments = get_comments( array('post_id' => $post->ID, 'status' => 'approve', 'order' => 'ASC') ); |
|
851 } else { |
|
852 $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_gmt", $post->ID, wp_specialchars_decode($comment_author,ENT_QUOTES), $comment_author_email)); |
|
853 } |
|
854 |
|
855 // keep $comments for legacy's sake |
|
856 $wp_query->comments = apply_filters( 'comments_array', $comments, $post->ID ); |
|
857 $comments = &$wp_query->comments; |
|
858 $wp_query->comment_count = count($wp_query->comments); |
|
859 update_comment_cache($wp_query->comments); |
|
860 |
|
861 if ( $separate_comments ) { |
|
862 $wp_query->comments_by_type = &separate_comments($comments); |
|
863 $comments_by_type = &$wp_query->comments_by_type; |
|
864 } |
|
865 |
|
866 $overridden_cpage = FALSE; |
|
867 if ( '' == get_query_var('cpage') && get_option('page_comments') ) { |
|
868 set_query_var( 'cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1 ); |
|
869 $overridden_cpage = TRUE; |
|
870 } |
|
871 |
|
872 if ( !defined('COMMENTS_TEMPLATE') || !COMMENTS_TEMPLATE) |
|
873 define('COMMENTS_TEMPLATE', true); |
|
874 |
|
875 $include = apply_filters('comments_template', STYLESHEETPATH . $file ); |
|
876 if ( file_exists( $include ) ) |
|
877 require( $include ); |
|
878 elseif ( file_exists( TEMPLATEPATH . $file ) ) |
|
879 require( TEMPLATEPATH . $file ); |
|
880 else |
|
881 require( get_theme_root() . '/default/comments.php'); |
|
882 } |
|
883 |
|
884 /** |
|
885 * Displays the JS popup script to show a comment. |
|
886 * |
|
887 * If the $file parameter is empty, then the home page is assumed. The defaults |
|
888 * for the window are 400px by 400px. |
|
889 * |
|
890 * For the comment link popup to work, this function has to be called or the |
|
891 * normal comment link will be assumed. |
|
892 * |
|
893 * @since 0.71 |
|
894 * @global string $wpcommentspopupfile The URL to use for the popup window |
|
895 * @global int $wpcommentsjavascript Whether to use JavaScript or not. Set when function is called |
|
896 * |
|
897 * @param int $width Optional. The width of the popup window |
|
898 * @param int $height Optional. The height of the popup window |
|
899 * @param string $file Optional. Sets the location of the popup window |
|
900 */ |
|
901 function comments_popup_script($width=400, $height=400, $file='') { |
|
902 global $wpcommentspopupfile, $wpcommentsjavascript; |
|
903 |
|
904 if (empty ($file)) { |
|
905 $wpcommentspopupfile = ''; // Use the index. |
|
906 } else { |
|
907 $wpcommentspopupfile = $file; |
|
908 } |
|
909 |
|
910 $wpcommentsjavascript = 1; |
|
911 $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"; |
|
912 echo $javascript; |
|
913 } |
|
914 |
|
915 /** |
|
916 * Displays the link to the comments popup window for the current post ID. |
|
917 * |
|
918 * Is not meant to be displayed on single posts and pages. Should be used on the |
|
919 * lists of posts |
|
920 * |
|
921 * @since 0.71 |
|
922 * @uses $id |
|
923 * @uses $wpcommentspopupfile |
|
924 * @uses $wpcommentsjavascript |
|
925 * @uses $post |
|
926 * |
|
927 * @param string $zero The string to display when no comments |
|
928 * @param string $one The string to display when only one comment is available |
|
929 * @param string $more The string to display when there are more than one comment |
|
930 * @param string $css_class The CSS class to use for comments |
|
931 * @param string $none The string to display when comments have been turned off |
|
932 * @return null Returns null on single posts and pages. |
|
933 */ |
|
934 function comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false ) { |
|
935 global $id, $wpcommentspopupfile, $wpcommentsjavascript, $post; |
|
936 |
|
937 if ( false === $zero ) $zero = __( 'No Comments' ); |
|
938 if ( false === $one ) $one = __( '1 Comment' ); |
|
939 if ( false === $more ) $more = __( '% Comments' ); |
|
940 if ( false === $none ) $none = __( 'Comments Off' ); |
|
941 |
|
942 $number = get_comments_number( $id ); |
|
943 |
|
944 if ( 0 == $number && !comments_open() && !pings_open() ) { |
|
945 echo '<span' . ((!empty($css_class)) ? ' class="' . esc_attr( $css_class ) . '"' : '') . '>' . $none . '</span>'; |
|
946 return; |
|
947 } |
|
948 |
|
949 if ( post_password_required() ) { |
|
950 echo __('Enter your password to view comments'); |
|
951 return; |
|
952 } |
|
953 |
|
954 echo '<a href="'; |
|
955 if ( $wpcommentsjavascript ) { |
|
956 if ( empty( $wpcommentspopupfile ) ) |
|
957 $home = get_option('home'); |
|
958 else |
|
959 $home = get_option('siteurl'); |
|
960 echo $home . '/' . $wpcommentspopupfile . '?comments_popup=' . $id; |
|
961 echo '" onclick="wpopen(this.href); return false"'; |
|
962 } else { // if comments_popup_script() is not in the template, display simple comment link |
|
963 if ( 0 == $number ) |
|
964 echo get_permalink() . '#respond'; |
|
965 else |
|
966 comments_link(); |
|
967 echo '"'; |
|
968 } |
|
969 |
|
970 if ( !empty( $css_class ) ) { |
|
971 echo ' class="'.$css_class.'" '; |
|
972 } |
|
973 $title = esc_attr( get_the_title() ); |
|
974 |
|
975 echo apply_filters( 'comments_popup_link_attributes', '' ); |
|
976 |
|
977 echo ' title="' . esc_attr( sprintf( __('Comment on %s'), $title ) ) . '">'; |
|
978 comments_number( $zero, $one, $more, $number ); |
|
979 echo '</a>'; |
|
980 } |
|
981 |
|
982 /** |
|
983 * Retrieve HTML content for reply to comment link. |
|
984 * |
|
985 * The default arguments that can be override are 'add_below', 'respond_id', |
|
986 * 'reply_text', 'login_text', and 'depth'. The 'login_text' argument will be |
|
987 * used, if the user must log in or register first before posting a comment. The |
|
988 * 'reply_text' will be used, if they can post a reply. The 'add_below' and |
|
989 * 'respond_id' arguments are for the JavaScript moveAddCommentForm() function |
|
990 * parameters. |
|
991 * |
|
992 * @since 2.7.0 |
|
993 * |
|
994 * @param array $args Optional. Override default options. |
|
995 * @param int $comment Optional. Comment being replied to. |
|
996 * @param int $post Optional. Post that the comment is going to be displayed on. |
|
997 * @return string|bool|null Link to show comment form, if successful. False, if comments are closed. |
|
998 */ |
|
999 function get_comment_reply_link($args = array(), $comment = null, $post = null) { |
|
1000 global $user_ID; |
|
1001 |
|
1002 $defaults = array('add_below' => 'comment', 'respond_id' => 'respond', 'reply_text' => __('Reply'), |
|
1003 'login_text' => __('Log in to Reply'), 'depth' => 0, 'before' => '', 'after' => ''); |
|
1004 |
|
1005 $args = wp_parse_args($args, $defaults); |
|
1006 |
|
1007 if ( 0 == $args['depth'] || $args['max_depth'] <= $args['depth'] ) |
|
1008 return; |
|
1009 |
|
1010 extract($args, EXTR_SKIP); |
|
1011 |
|
1012 $comment = get_comment($comment); |
|
1013 $post = get_post($post); |
|
1014 |
|
1015 if ( !comments_open($post->ID) ) |
|
1016 return false; |
|
1017 |
|
1018 $link = ''; |
|
1019 |
|
1020 if ( get_option('comment_registration') && !$user_ID ) |
|
1021 $link = '<a rel="nofollow" class="comment-reply-login" href="' . esc_url( wp_login_url( get_permalink() ) ) . '">' . $login_text . '</a>'; |
|
1022 else |
|
1023 $link = "<a rel='nofollow' class='comment-reply-link' href='" . esc_url( 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>"; |
|
1024 return apply_filters('comment_reply_link', $before . $link . $after, $args, $comment, $post); |
|
1025 } |
|
1026 |
|
1027 /** |
|
1028 * Displays the HTML content for reply to comment link. |
|
1029 * |
|
1030 * @since 2.7.0 |
|
1031 * @see get_comment_reply_link() Echoes result |
|
1032 * |
|
1033 * @param array $args Optional. Override default options. |
|
1034 * @param int $comment Optional. Comment being replied to. |
|
1035 * @param int $post Optional. Post that the comment is going to be displayed on. |
|
1036 * @return string|bool|null Link to show comment form, if successful. False, if comments are closed. |
|
1037 */ |
|
1038 function comment_reply_link($args = array(), $comment = null, $post = null) { |
|
1039 echo get_comment_reply_link($args, $comment, $post); |
|
1040 } |
|
1041 |
|
1042 /** |
|
1043 * Retrieve HTML content for reply to post link. |
|
1044 * |
|
1045 * The default arguments that can be override are 'add_below', 'respond_id', |
|
1046 * 'reply_text', 'login_text', and 'depth'. The 'login_text' argument will be |
|
1047 * used, if the user must log in or register first before posting a comment. The |
|
1048 * 'reply_text' will be used, if they can post a reply. The 'add_below' and |
|
1049 * 'respond_id' arguments are for the JavaScript moveAddCommentForm() function |
|
1050 * parameters. |
|
1051 * |
|
1052 * @since 2.7.0 |
|
1053 * |
|
1054 * @param array $args Optional. Override default options. |
|
1055 * @param int|object $post Optional. Post that the comment is going to be displayed on. Defaults to current post. |
|
1056 * @return string|bool|null Link to show comment form, if successful. False, if comments are closed. |
|
1057 */ |
|
1058 function get_post_reply_link($args = array(), $post = null) { |
|
1059 global $user_ID; |
|
1060 |
|
1061 $defaults = array('add_below' => 'post', 'respond_id' => 'respond', 'reply_text' => __('Leave a Comment'), |
|
1062 'login_text' => __('Log in to leave a Comment'), 'before' => '', 'after' => ''); |
|
1063 |
|
1064 $args = wp_parse_args($args, $defaults); |
|
1065 extract($args, EXTR_SKIP); |
|
1066 $post = get_post($post); |
|
1067 |
|
1068 if ( !comments_open($post->ID) ) |
|
1069 return false; |
|
1070 |
|
1071 if ( get_option('comment_registration') && !$user_ID ) { |
|
1072 $link = '<a rel="nofollow" href="' . wp_login_url( get_permalink() ) . '">' . $login_text . '</a>'; |
|
1073 } else { |
|
1074 $link = "<a rel='nofollow' class='comment-reply-link' href='" . get_permalink($post->ID) . "#$respond_id' onclick='return addComment.moveForm(\"$add_below-$post->ID\", \"0\", \"$respond_id\", \"$post->ID\")'>$reply_text</a>"; |
|
1075 } |
|
1076 return apply_filters('post_comments_link', $before . $link . $after, $post); |
|
1077 } |
|
1078 |
|
1079 /** |
|
1080 * Displays the HTML content for reply to post link. |
|
1081 * @since 2.7.0 |
|
1082 * @see get_post_reply_link() |
|
1083 * |
|
1084 * @param array $args Optional. Override default options. |
|
1085 * @param int|object $post Optional. Post that the comment is going to be displayed on. |
|
1086 * @return string|bool|null Link to show comment form, if successful. False, if comments are closed. |
|
1087 */ |
|
1088 function post_reply_link($args = array(), $post = null) { |
|
1089 echo get_post_reply_link($args, $post); |
|
1090 } |
|
1091 |
|
1092 /** |
|
1093 * Retrieve HTML content for cancel comment reply link. |
|
1094 * |
|
1095 * @since 2.7.0 |
|
1096 * |
|
1097 * @param string $text Optional. Text to display for cancel reply link. |
|
1098 */ |
|
1099 function get_cancel_comment_reply_link($text = '') { |
|
1100 if ( empty($text) ) |
|
1101 $text = __('Click here to cancel reply.'); |
|
1102 |
|
1103 $style = isset($_GET['replytocom']) ? '' : ' style="display:none;"'; |
|
1104 $link = esc_html( remove_query_arg('replytocom') ) . '#respond'; |
|
1105 return apply_filters('cancel_comment_reply_link', '<a rel="nofollow" id="cancel-comment-reply-link" href="' . $link . '"' . $style . '>' . $text . '</a>', $link, $text); |
|
1106 } |
|
1107 |
|
1108 /** |
|
1109 * Display HTML content for cancel comment reply link. |
|
1110 * |
|
1111 * @since 2.7.0 |
|
1112 * |
|
1113 * @param string $text Optional. Text to display for cancel reply link. |
|
1114 */ |
|
1115 function cancel_comment_reply_link($text = '') { |
|
1116 echo get_cancel_comment_reply_link($text); |
|
1117 } |
|
1118 |
|
1119 /** |
|
1120 * Output hidden input HTML for replying to comments. |
|
1121 * |
|
1122 * @since 2.7.0 |
|
1123 */ |
|
1124 function comment_id_fields() { |
|
1125 global $id; |
|
1126 |
|
1127 $replytoid = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0; |
|
1128 echo "<input type='hidden' name='comment_post_ID' value='$id' id='comment_post_ID' />\n"; |
|
1129 echo "<input type='hidden' name='comment_parent' id='comment_parent' value='$replytoid' />\n"; |
|
1130 } |
|
1131 |
|
1132 /** |
|
1133 * Display text based on comment reply status. Only affects users with Javascript disabled. |
|
1134 * |
|
1135 * @since 2.7.0 |
|
1136 * |
|
1137 * @param string $noreplytext Optional. Text to display when not replying to a comment. |
|
1138 * @param string $replytext Optional. Text to display when replying to a comment. Accepts "%s" for the author of the comment being replied to. |
|
1139 * @param string $linktoparent Optional. Boolean to control making the author's name a link to their comment. |
|
1140 */ |
|
1141 function comment_form_title( $noreplytext = false, $replytext = false, $linktoparent = TRUE ) { |
|
1142 global $comment; |
|
1143 |
|
1144 if ( false === $noreplytext ) $noreplytext = __( 'Leave a Reply' ); |
|
1145 if ( false === $replytext ) $replytext = __( 'Leave a Reply to %s' ); |
|
1146 |
|
1147 $replytoid = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0; |
|
1148 |
|
1149 if ( 0 == $replytoid ) |
|
1150 echo $noreplytext; |
|
1151 else { |
|
1152 $comment = get_comment($replytoid); |
|
1153 $author = ( $linktoparent ) ? '<a href="#comment-' . get_comment_ID() . '">' . get_comment_author() . '</a>' : get_comment_author(); |
|
1154 printf( $replytext, $author ); |
|
1155 } |
|
1156 } |
|
1157 |
|
1158 /** |
|
1159 * HTML comment list class. |
|
1160 * |
|
1161 * @package WordPress |
|
1162 * @uses Walker |
|
1163 * @since unknown |
|
1164 */ |
|
1165 class Walker_Comment extends Walker { |
|
1166 /** |
|
1167 * @see Walker::$tree_type |
|
1168 * @since unknown |
|
1169 * @var string |
|
1170 */ |
|
1171 var $tree_type = 'comment'; |
|
1172 |
|
1173 /** |
|
1174 * @see Walker::$db_fields |
|
1175 * @since unknown |
|
1176 * @var array |
|
1177 */ |
|
1178 var $db_fields = array ('parent' => 'comment_parent', 'id' => 'comment_ID'); |
|
1179 |
|
1180 /** |
|
1181 * @see Walker::start_lvl() |
|
1182 * @since unknown |
|
1183 * |
|
1184 * @param string $output Passed by reference. Used to append additional content. |
|
1185 * @param int $depth Depth of comment. |
|
1186 * @param array $args Uses 'style' argument for type of HTML list. |
|
1187 */ |
|
1188 function start_lvl(&$output, $depth, $args) { |
|
1189 $GLOBALS['comment_depth'] = $depth + 1; |
|
1190 |
|
1191 switch ( $args['style'] ) { |
|
1192 case 'div': |
|
1193 break; |
|
1194 case 'ol': |
|
1195 echo "<ol class='children'>\n"; |
|
1196 break; |
|
1197 default: |
|
1198 case 'ul': |
|
1199 echo "<ul class='children'>\n"; |
|
1200 break; |
|
1201 } |
|
1202 } |
|
1203 |
|
1204 /** |
|
1205 * @see Walker::end_lvl() |
|
1206 * @since unknown |
|
1207 * |
|
1208 * @param string $output Passed by reference. Used to append additional content. |
|
1209 * @param int $depth Depth of comment. |
|
1210 * @param array $args Will only append content if style argument value is 'ol' or 'ul'. |
|
1211 */ |
|
1212 function end_lvl(&$output, $depth, $args) { |
|
1213 $GLOBALS['comment_depth'] = $depth + 1; |
|
1214 |
|
1215 switch ( $args['style'] ) { |
|
1216 case 'div': |
|
1217 break; |
|
1218 case 'ol': |
|
1219 echo "</ol>\n"; |
|
1220 break; |
|
1221 default: |
|
1222 case 'ul': |
|
1223 echo "</ul>\n"; |
|
1224 break; |
|
1225 } |
|
1226 } |
|
1227 |
|
1228 /** |
|
1229 * @see Walker::start_el() |
|
1230 * @since unknown |
|
1231 * |
|
1232 * @param string $output Passed by reference. Used to append additional content. |
|
1233 * @param object $comment Comment data object. |
|
1234 * @param int $depth Depth of comment in reference to parents. |
|
1235 * @param array $args |
|
1236 */ |
|
1237 function start_el(&$output, $comment, $depth, $args) { |
|
1238 $depth++; |
|
1239 $GLOBALS['comment_depth'] = $depth; |
|
1240 |
|
1241 if ( !empty($args['callback']) ) { |
|
1242 call_user_func($args['callback'], $comment, $args, $depth); |
|
1243 return; |
|
1244 } |
|
1245 |
|
1246 $GLOBALS['comment'] = $comment; |
|
1247 extract($args, EXTR_SKIP); |
|
1248 |
|
1249 if ( 'div' == $args['style'] ) { |
|
1250 $tag = 'div'; |
|
1251 $add_below = 'comment'; |
|
1252 } else { |
|
1253 $tag = 'li'; |
|
1254 $add_below = 'div-comment'; |
|
1255 } |
|
1256 ?> |
|
1257 <<?php echo $tag ?> <?php comment_class(empty( $args['has_children'] ) ? '' : 'parent') ?> id="comment-<?php comment_ID() ?>"> |
|
1258 <?php if ( 'ul' == $args['style'] ) : ?> |
|
1259 <div id="div-comment-<?php comment_ID() ?>" class="comment-body"> |
|
1260 <?php endif; ?> |
|
1261 <div class="comment-author vcard"> |
|
1262 <?php if ($args['avatar_size'] != 0) echo get_avatar( $comment, $args['avatar_size'] ); ?> |
|
1263 <?php printf(__('<cite class="fn">%s</cite> <span class="says">says:</span>'), get_comment_author_link()) ?> |
|
1264 </div> |
|
1265 <?php if ($comment->comment_approved == '0') : ?> |
|
1266 <em><?php _e('Your comment is awaiting moderation.') ?></em> |
|
1267 <br /> |
|
1268 <?php endif; ?> |
|
1269 |
|
1270 <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)'),' ','') ?></div> |
|
1271 |
|
1272 <?php comment_text() ?> |
|
1273 |
|
1274 <div class="reply"> |
|
1275 <?php comment_reply_link(array_merge( $args, array('add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth']))) ?> |
|
1276 </div> |
|
1277 <?php if ( 'ul' == $args['style'] ) : ?> |
|
1278 </div> |
|
1279 <?php endif; ?> |
|
1280 <?php |
|
1281 } |
|
1282 |
|
1283 /** |
|
1284 * @see Walker::end_el() |
|
1285 * @since unknown |
|
1286 * |
|
1287 * @param string $output Passed by reference. Used to append additional content. |
|
1288 * @param object $comment |
|
1289 * @param int $depth Depth of comment. |
|
1290 * @param array $args |
|
1291 */ |
|
1292 function end_el(&$output, $comment, $depth, $args) { |
|
1293 if ( !empty($args['end-callback']) ) { |
|
1294 call_user_func($args['end-callback'], $comment, $args, $depth); |
|
1295 return; |
|
1296 } |
|
1297 if ( 'div' == $args['style'] ) |
|
1298 echo "</div>\n"; |
|
1299 else |
|
1300 echo "</li>\n"; |
|
1301 } |
|
1302 |
|
1303 } |
|
1304 |
|
1305 /** |
|
1306 * List comments |
|
1307 * |
|
1308 * Used in the comments.php template to list comments for a particular post |
|
1309 * |
|
1310 * @since 2.7.0 |
|
1311 * @uses Walker_Comment |
|
1312 * |
|
1313 * @param string|array $args Formatting options |
|
1314 * @param array $comments Optional array of comment objects. Defaults to $wp_query->comments |
|
1315 */ |
|
1316 function wp_list_comments($args = array(), $comments = null ) { |
|
1317 global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop; |
|
1318 |
|
1319 $in_comment_loop = true; |
|
1320 |
|
1321 $comment_alt = $comment_thread_alt = 0; |
|
1322 $comment_depth = 1; |
|
1323 |
|
1324 $defaults = array('walker' => null, 'max_depth' => '', 'style' => 'ul', 'callback' => null, 'end-callback' => null, 'type' => 'all', |
|
1325 'page' => '', 'per_page' => '', 'avatar_size' => 32, 'reverse_top_level' => null, 'reverse_children' => ''); |
|
1326 |
|
1327 $r = wp_parse_args( $args, $defaults ); |
|
1328 |
|
1329 // Figure out what comments we'll be looping through ($_comments) |
|
1330 if ( null !== $comments ) { |
|
1331 $comments = (array) $comments; |
|
1332 if ( empty($comments) ) |
|
1333 return; |
|
1334 if ( 'all' != $r['type'] ) { |
|
1335 $comments_by_type = &separate_comments($comments); |
|
1336 if ( empty($comments_by_type[$r['type']]) ) |
|
1337 return; |
|
1338 $_comments = $comments_by_type[$r['type']]; |
|
1339 } else { |
|
1340 $_comments = $comments; |
|
1341 } |
|
1342 } else { |
|
1343 if ( empty($wp_query->comments) ) |
|
1344 return; |
|
1345 if ( 'all' != $r['type'] ) { |
|
1346 if ( empty($wp_query->comments_by_type) ) |
|
1347 $wp_query->comments_by_type = &separate_comments($wp_query->comments); |
|
1348 if ( empty($wp_query->comments_by_type[$r['type']]) ) |
|
1349 return; |
|
1350 $_comments = $wp_query->comments_by_type[$r['type']]; |
|
1351 } else { |
|
1352 $_comments = $wp_query->comments; |
|
1353 } |
|
1354 } |
|
1355 |
|
1356 if ( '' === $r['per_page'] && get_option('page_comments') ) |
|
1357 $r['per_page'] = get_query_var('comments_per_page'); |
|
1358 |
|
1359 if ( empty($r['per_page']) ) { |
|
1360 $r['per_page'] = 0; |
|
1361 $r['page'] = 0; |
|
1362 } |
|
1363 |
|
1364 if ( '' === $r['max_depth'] ) { |
|
1365 if ( get_option('thread_comments') ) |
|
1366 $r['max_depth'] = get_option('thread_comments_depth'); |
|
1367 else |
|
1368 $r['max_depth'] = -1; |
|
1369 } |
|
1370 |
|
1371 if ( '' === $r['page'] ) { |
|
1372 if ( empty($overridden_cpage) ) { |
|
1373 $r['page'] = get_query_var('cpage'); |
|
1374 } else { |
|
1375 $threaded = ( -1 == $r['max_depth'] ) ? false : true; |
|
1376 $r['page'] = ( 'newest' == get_option('default_comments_page') ) ? get_comment_pages_count($_comments, $r['per_page'], $threaded) : 1; |
|
1377 set_query_var( 'cpage', $r['page'] ); |
|
1378 } |
|
1379 } |
|
1380 // Validation check |
|
1381 $r['page'] = intval($r['page']); |
|
1382 if ( 0 == $r['page'] && 0 != $r['per_page'] ) |
|
1383 $r['page'] = 1; |
|
1384 |
|
1385 if ( null === $r['reverse_top_level'] ) |
|
1386 $r['reverse_top_level'] = ( 'desc' == get_option('comment_order') ) ? TRUE : FALSE; |
|
1387 |
|
1388 extract( $r, EXTR_SKIP ); |
|
1389 |
|
1390 if ( empty($walker) ) |
|
1391 $walker = new Walker_Comment; |
|
1392 |
|
1393 $walker->paged_walk($_comments, $max_depth, $page, $per_page, $r); |
|
1394 $wp_query->max_num_comment_pages = $walker->max_pages; |
|
1395 |
|
1396 $in_comment_loop = false; |
|
1397 } |
|
1398 |
|
1399 ?> |