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 | * get_comment_author() - Retrieve the author of the current comment |
---|
13 | * |
---|
14 | * If the comment has an empty comment_author field, then 'Anonymous' person |
---|
15 | * is assumed. |
---|
16 | * |
---|
17 | * @since 1.5 |
---|
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 | $author = __('Anonymous'); |
---|
26 | else |
---|
27 | $author = $comment->comment_author; |
---|
28 | return apply_filters('get_comment_author', $author); |
---|
29 | } |
---|
30 | |
---|
31 | /** |
---|
32 | * comment_author() - Displays the author of the current comment |
---|
33 | * |
---|
34 | * @since 0.71 |
---|
35 | * @uses apply_filters() Calls 'comment_author' on comment author before displaying |
---|
36 | */ |
---|
37 | function comment_author() { |
---|
38 | $author = apply_filters('comment_author', get_comment_author() ); |
---|
39 | echo $author; |
---|
40 | } |
---|
41 | |
---|
42 | /** |
---|
43 | * get_comment_author_email() - Retrieve the email of the author of the current comment |
---|
44 | * |
---|
45 | * @since 1.5 |
---|
46 | * @uses apply_filters() Calls the 'get_comment_author_email' hook on the comment author email |
---|
47 | * @uses $comment |
---|
48 | * |
---|
49 | * @return string The current comment author's email |
---|
50 | */ |
---|
51 | function get_comment_author_email() { |
---|
52 | global $comment; |
---|
53 | return apply_filters('get_comment_author_email', $comment->comment_author_email); |
---|
54 | } |
---|
55 | |
---|
56 | /** |
---|
57 | * comment_author_email() - Display the email of the author of the current global $comment |
---|
58 | * |
---|
59 | * Care should be taken to protect the email address and assure that email harvesters |
---|
60 | * do not capture your commentors' email address. Most assume that their email address will |
---|
61 | * not appear in raw form on the blog. Doing so will enable anyone, including those that |
---|
62 | * people don't want to get the email address and use it for their own means good and bad. |
---|
63 | * |
---|
64 | * @since 0.71 |
---|
65 | * @uses apply_filters() Calls 'author_email' hook on the author email |
---|
66 | */ |
---|
67 | function comment_author_email() { |
---|
68 | echo apply_filters('author_email', get_comment_author_email() ); |
---|
69 | } |
---|
70 | |
---|
71 | /** |
---|
72 | * comment_author_email_link() - Display the html email link to the author of the current comment |
---|
73 | * |
---|
74 | * Care should be taken to protect the email address and assure that email harvesters |
---|
75 | * do not capture your commentors' email address. Most assume that their email address will |
---|
76 | * not appear in raw form on the blog. Doing so will enable anyone, including those that |
---|
77 | * people don't want to get the email address and use it for their own means good and bad. |
---|
78 | * |
---|
79 | * @since 0.71 |
---|
80 | * @uses apply_filters() Calls 'comment_email' hook for the display of the comment author's email |
---|
81 | * @global object $comment The current Comment row object |
---|
82 | * |
---|
83 | * @param string $linktext The text to display instead of the comment author's email address |
---|
84 | * @param string $before The text or HTML to display before the email link. |
---|
85 | * @param string $after The text or HTML to display after the email link. |
---|
86 | */ |
---|
87 | function comment_author_email_link($linktext='', $before='', $after='') { |
---|
88 | global $comment; |
---|
89 | $email = apply_filters('comment_email', $comment->comment_author_email); |
---|
90 | if ((!empty($email)) && ($email != '@')) { |
---|
91 | $display = ($linktext != '') ? $linktext : $email; |
---|
92 | echo $before; |
---|
93 | echo "<a href='mailto:$email'>$display</a>"; |
---|
94 | echo $after; |
---|
95 | } |
---|
96 | } |
---|
97 | |
---|
98 | /** |
---|
99 | * get_comment_author_link() - Retrieve the html link to the url of the author of the current comment |
---|
100 | * |
---|
101 | * @since 1.5 |
---|
102 | * @uses apply_filters() Calls 'get_comment_author_link' hook on the complete link HTML or author |
---|
103 | * |
---|
104 | * @return string Comment Author name or HTML link for author's URL |
---|
105 | */ |
---|
106 | function get_comment_author_link() { |
---|
107 | /** @todo Only call these functions when they are needed. Include in if... else blocks */ |
---|
108 | $url = get_comment_author_url(); |
---|
109 | $author = get_comment_author(); |
---|
110 | |
---|
111 | if ( empty( $url ) || 'http://' == $url ) |
---|
112 | $return = $author; |
---|
113 | else |
---|
114 | $return = "<a href='$url' rel='external nofollow'>$author</a>"; |
---|
115 | return apply_filters('get_comment_author_link', $return); |
---|
116 | } |
---|
117 | |
---|
118 | /** |
---|
119 | * comment_author_link() - Display the html link to the url of the author of the current comment |
---|
120 | * |
---|
121 | * @since 0.71 |
---|
122 | * @see get_comment_author_link() Echos result |
---|
123 | */ |
---|
124 | function comment_author_link() { |
---|
125 | echo get_comment_author_link(); |
---|
126 | } |
---|
127 | |
---|
128 | /** |
---|
129 | * get_comment_author_IP() - Retrieve the IP address of the author of the current comment |
---|
130 | * |
---|
131 | * @since 1.5 |
---|
132 | * @uses $comment |
---|
133 | * @uses apply_filters() |
---|
134 | * |
---|
135 | * @return unknown |
---|
136 | */ |
---|
137 | function get_comment_author_IP() { |
---|
138 | global $comment; |
---|
139 | return apply_filters('get_comment_author_IP', $comment->comment_author_IP); |
---|
140 | } |
---|
141 | |
---|
142 | /** |
---|
143 | * comment_author_IP() - Displays the IP address of the author of the current comment |
---|
144 | * |
---|
145 | * @since 0.71 |
---|
146 | * @see get_comment_author_IP() Echos Result |
---|
147 | */ |
---|
148 | function comment_author_IP() { |
---|
149 | echo get_comment_author_IP(); |
---|
150 | } |
---|
151 | |
---|
152 | /** |
---|
153 | * get_comment_author_url() - Returns the url of the author of the current comment |
---|
154 | * |
---|
155 | * @since 1.5 |
---|
156 | * @uses apply_filters() Calls 'get_comment_author_url' hook on the comment author's URL |
---|
157 | * |
---|
158 | * @return string |
---|
159 | */ |
---|
160 | function get_comment_author_url() { |
---|
161 | global $comment; |
---|
162 | return apply_filters('get_comment_author_url', $comment->comment_author_url); |
---|
163 | } |
---|
164 | |
---|
165 | /** |
---|
166 | * comment_author_url() - Display the url of the author of the current comment |
---|
167 | * |
---|
168 | * @since 0.71 |
---|
169 | * @uses apply_filters() |
---|
170 | * @uses get_comment_author_url() Retrieves the comment author's URL |
---|
171 | */ |
---|
172 | function comment_author_url() { |
---|
173 | echo apply_filters('comment_url', get_comment_author_url()); |
---|
174 | } |
---|
175 | |
---|
176 | /** |
---|
177 | * get_comment_author_url_link() - Retrieves the HTML link of the url of the author of the current comment |
---|
178 | * |
---|
179 | * $linktext parameter is only used if the URL does not exist for the comment author. If the URL does |
---|
180 | * exist then the URL will be used and the $linktext will be ignored. |
---|
181 | * |
---|
182 | * Encapsulate the HTML link between the $before and $after. So it will appear in the order of $before, |
---|
183 | * link, and finally $after. |
---|
184 | * |
---|
185 | * @since 1.5 |
---|
186 | * @uses apply_filters() Calls the 'get_comment_author_url_link' on the complete HTML before returning. |
---|
187 | * |
---|
188 | * @param string $linktext The text to display instead of the comment author's email address |
---|
189 | * @param string $before The text or HTML to display before the email link. |
---|
190 | * @param string $after The text or HTML to display after the email link. |
---|
191 | * @return string The HTML link between the $before and $after parameters |
---|
192 | */ |
---|
193 | function get_comment_author_url_link( $linktext = '', $before = '', $after = '' ) { |
---|
194 | $url = get_comment_author_url(); |
---|
195 | $display = ($linktext != '') ? $linktext : $url; |
---|
196 | $display = str_replace( 'http://www.', '', $display ); |
---|
197 | $display = str_replace( 'http://', '', $display ); |
---|
198 | if ( '/' == substr($display, -1) ) |
---|
199 | $display = substr($display, 0, -1); |
---|
200 | $return = "$before<a href='$url' rel='external'>$display</a>$after"; |
---|
201 | return apply_filters('get_comment_author_url_link', $return); |
---|
202 | } |
---|
203 | |
---|
204 | /** |
---|
205 | * comment_author_url_link() - Displays the HTML link of the url of the author of the current comment |
---|
206 | * |
---|
207 | * @since 0.71 |
---|
208 | * @see get_comment_author_url_link() Echos result |
---|
209 | * |
---|
210 | * @param string $linktext The text to display instead of the comment author's email address |
---|
211 | * @param string $before The text or HTML to display before the email link. |
---|
212 | * @param string $after The text or HTML to display after the email link. |
---|
213 | */ |
---|
214 | function comment_author_url_link( $linktext = '', $before = '', $after = '' ) { |
---|
215 | echo get_comment_author_url_link( $linktext, $before, $after ); |
---|
216 | } |
---|
217 | |
---|
218 | /** |
---|
219 | * get_comment_date() - Retrieve the comment date of the current comment |
---|
220 | * |
---|
221 | * @since 1.5 |
---|
222 | * @uses apply_filters() Calls 'get_comment_date' hook with the formated date and the $d parameter respectively |
---|
223 | * @uses $comment |
---|
224 | * |
---|
225 | * @param string $d The format of the date (defaults to user's config) |
---|
226 | * @return string The comment's date |
---|
227 | */ |
---|
228 | function get_comment_date( $d = '' ) { |
---|
229 | global $comment; |
---|
230 | if ( '' == $d ) |
---|
231 | $date = mysql2date( get_option('date_format'), $comment->comment_date); |
---|
232 | else |
---|
233 | $date = mysql2date($d, $comment->comment_date); |
---|
234 | return apply_filters('get_comment_date', $date, $d); |
---|
235 | } |
---|
236 | |
---|
237 | /** |
---|
238 | * comment_date() - Display the comment date of the current comment |
---|
239 | * |
---|
240 | * @since 0.71 |
---|
241 | * |
---|
242 | * @param string $d The format of the date (defaults to user's config) |
---|
243 | */ |
---|
244 | function comment_date( $d = '' ) { |
---|
245 | echo get_comment_date( $d ); |
---|
246 | } |
---|
247 | |
---|
248 | /** |
---|
249 | * get_comment_excerpt() - Retrieve the excerpt of the current comment |
---|
250 | * |
---|
251 | * Will cut each word and only output the first 20 words with '...' at the end. |
---|
252 | * If the word count is less than 20, then no truncating is done and no '...' |
---|
253 | * will appear. |
---|
254 | * |
---|
255 | * @since 1.5 |
---|
256 | * @uses $comment |
---|
257 | * @uses apply_filters() Calls 'get_comment_excerpt' on truncated comment |
---|
258 | * |
---|
259 | * @return string The maybe truncated comment with 20 words or less |
---|
260 | */ |
---|
261 | function get_comment_excerpt() { |
---|
262 | global $comment; |
---|
263 | $comment_text = strip_tags($comment->comment_content); |
---|
264 | $blah = explode(' ', $comment_text); |
---|
265 | if (count($blah) > 20) { |
---|
266 | $k = 20; |
---|
267 | $use_dotdotdot = 1; |
---|
268 | } else { |
---|
269 | $k = count($blah); |
---|
270 | $use_dotdotdot = 0; |
---|
271 | } |
---|
272 | $excerpt = ''; |
---|
273 | for ($i=0; $i<$k; $i++) { |
---|
274 | $excerpt .= $blah[$i] . ' '; |
---|
275 | } |
---|
276 | $excerpt .= ($use_dotdotdot) ? '...' : ''; |
---|
277 | return apply_filters('get_comment_excerpt', $excerpt); |
---|
278 | } |
---|
279 | |
---|
280 | /** |
---|
281 | * comment_excerpt() - Returns the excerpt of the current comment |
---|
282 | * |
---|
283 | * @since 1.2 |
---|
284 | * @uses apply_filters() Calls 'comment_excerpt' hook before displaying excerpt |
---|
285 | */ |
---|
286 | function comment_excerpt() { |
---|
287 | echo apply_filters('comment_excerpt', get_comment_excerpt() ); |
---|
288 | } |
---|
289 | |
---|
290 | /** |
---|
291 | * get_comment_ID() - Retrieve the comment id of the current comment |
---|
292 | * |
---|
293 | * @since 1.5 |
---|
294 | * @uses $comment |
---|
295 | * @uses apply_filters() Calls the 'get_comment_ID' hook for the comment ID |
---|
296 | * |
---|
297 | * @return int The comment ID |
---|
298 | */ |
---|
299 | function get_comment_ID() { |
---|
300 | global $comment; |
---|
301 | return apply_filters('get_comment_ID', $comment->comment_ID); |
---|
302 | } |
---|
303 | |
---|
304 | /** |
---|
305 | * comment_ID() - Displays the comment id of the current comment |
---|
306 | * |
---|
307 | * @since 0.71 |
---|
308 | * @see get_comment_ID() Echos Result |
---|
309 | */ |
---|
310 | function comment_ID() { |
---|
311 | echo get_comment_ID(); |
---|
312 | } |
---|
313 | |
---|
314 | /** |
---|
315 | * get_comment_link() - Retrieve the link to the current comment |
---|
316 | * |
---|
317 | * @since 1.5 |
---|
318 | * @uses $comment |
---|
319 | * |
---|
320 | * @return string The permalink to the current comment |
---|
321 | */ |
---|
322 | function get_comment_link() { |
---|
323 | global $comment; |
---|
324 | return get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment->comment_ID; |
---|
325 | } |
---|
326 | |
---|
327 | /** |
---|
328 | * get_comments_link() - Retrieves the link to the current post comments |
---|
329 | * |
---|
330 | * @since 1.5 |
---|
331 | * |
---|
332 | * @return string The link to the comments |
---|
333 | */ |
---|
334 | function get_comments_link() { |
---|
335 | return get_permalink() . '#comments'; |
---|
336 | } |
---|
337 | |
---|
338 | /** |
---|
339 | * comments_link() - Displays the link to the current post comments |
---|
340 | * |
---|
341 | * @since 0.71 |
---|
342 | * |
---|
343 | * @param string $deprecated Not Used |
---|
344 | * @param bool $deprecated Not Used |
---|
345 | */ |
---|
346 | function comments_link( $deprecated = '', $deprecated = '' ) { |
---|
347 | echo get_comments_link(); |
---|
348 | } |
---|
349 | |
---|
350 | /** |
---|
351 | * get_comments_number() - Retrieve the amount of comments a post has |
---|
352 | * |
---|
353 | * @since 1.5 |
---|
354 | * @uses apply_filters() Calls the 'get_comments_number' hook on the number of comments |
---|
355 | * |
---|
356 | * @param int $post_id The Post ID |
---|
357 | * @return int The number of comments a post has |
---|
358 | */ |
---|
359 | function get_comments_number( $post_id = 0 ) { |
---|
360 | global $id; |
---|
361 | $post_id = (int) $post_id; |
---|
362 | |
---|
363 | if ( !$post_id ) |
---|
364 | $post_id = (int) $id; |
---|
365 | |
---|
366 | $post = get_post($post_id); |
---|
367 | if ( ! isset($post->comment_count) ) |
---|
368 | $count = 0; |
---|
369 | else |
---|
370 | $count = $post->comment_count; |
---|
371 | |
---|
372 | return apply_filters('get_comments_number', $count); |
---|
373 | } |
---|
374 | |
---|
375 | /** |
---|
376 | * comments_number() - Display the language string for the number of comments the current post has |
---|
377 | * |
---|
378 | * @since 0.71 |
---|
379 | * @uses $id |
---|
380 | * @uses apply_filters() Calls the 'comments_number' hook on the output and number of comments respectively. |
---|
381 | * |
---|
382 | * @param string $zero Text for no comments |
---|
383 | * @param string $one Text for one comment |
---|
384 | * @param string $more Text for more than one comment |
---|
385 | * @param string $deprecated Not used. |
---|
386 | */ |
---|
387 | function comments_number( $zero = false, $one = false, $more = false, $deprecated = '' ) { |
---|
388 | global $id; |
---|
389 | $number = get_comments_number($id); |
---|
390 | |
---|
391 | if ( $number > 1 ) |
---|
392 | $output = str_replace('%', number_format_i18n($number), ( false === $more ) ? __('% Comments') : $more); |
---|
393 | elseif ( $number == 0 ) |
---|
394 | $output = ( false === $zero ) ? __('No Comments') : $zero; |
---|
395 | else // must be one |
---|
396 | $output = ( false === $one ) ? __('1 Comment') : $one; |
---|
397 | |
---|
398 | echo apply_filters('comments_number', $output, $number); |
---|
399 | } |
---|
400 | |
---|
401 | /** |
---|
402 | * get_comment_text() - Retrieve the text of the current comment |
---|
403 | * |
---|
404 | * @since 1.5 |
---|
405 | * @uses $comment |
---|
406 | * |
---|
407 | * @return string The comment content |
---|
408 | */ |
---|
409 | function get_comment_text() { |
---|
410 | global $comment; |
---|
411 | return apply_filters('get_comment_text', $comment->comment_content); |
---|
412 | } |
---|
413 | |
---|
414 | /** |
---|
415 | * comment_text() - Displays the text of the current comment |
---|
416 | * |
---|
417 | * @since 0.71 |
---|
418 | * @uses apply_filters() Passes the comment content through the 'comment_text' hook before display |
---|
419 | * @uses get_comment_text() Gets the comment content |
---|
420 | */ |
---|
421 | function comment_text() { |
---|
422 | echo apply_filters('comment_text', get_comment_text() ); |
---|
423 | } |
---|
424 | |
---|
425 | /** |
---|
426 | * get_comment_time() - Retrieve the comment time of the current comment |
---|
427 | * |
---|
428 | * @since 1.5 |
---|
429 | * @uses $comment |
---|
430 | * @uses apply_filter() Calls 'get_comment_time' hook with the formatted time, the $d parameter, and $gmt parameter passed. |
---|
431 | * |
---|
432 | * @param string $d Optional. The format of the time (defaults to user's config) |
---|
433 | * @param bool $gmt Whether to use the GMT date |
---|
434 | * @return string The formatted time |
---|
435 | */ |
---|
436 | function get_comment_time( $d = '', $gmt = false ) { |
---|
437 | global $comment; |
---|
438 | $comment_date = $gmt? $comment->comment_date_gmt : $comment->comment_date; |
---|
439 | if ( '' == $d ) |
---|
440 | $date = mysql2date(get_option('time_format'), $comment_date); |
---|
441 | else |
---|
442 | $date = mysql2date($d, $comment_date); |
---|
443 | return apply_filters('get_comment_time', $date, $d, $gmt); |
---|
444 | } |
---|
445 | |
---|
446 | /** |
---|
447 | * comment_time() - Display the comment time of the current comment |
---|
448 | * |
---|
449 | * @since 0.71 |
---|
450 | * |
---|
451 | * @param string $d Optional. The format of the time (defaults to user's config) |
---|
452 | */ |
---|
453 | function comment_time( $d = '' ) { |
---|
454 | echo get_comment_time($d); |
---|
455 | } |
---|
456 | |
---|
457 | /** |
---|
458 | * get_comment_type() - Retrieve the comment type of the current comment |
---|
459 | * |
---|
460 | * @since 1.5 |
---|
461 | * @uses $comment |
---|
462 | * @uses apply_filters() Calls the 'get_comment_type' hook on the comment type |
---|
463 | * |
---|
464 | * @return string The comment type |
---|
465 | */ |
---|
466 | function get_comment_type() { |
---|
467 | global $comment; |
---|
468 | |
---|
469 | if ( '' == $comment->comment_type ) |
---|
470 | $comment->comment_type = 'comment'; |
---|
471 | |
---|
472 | return apply_filters('get_comment_type', $comment->comment_type); |
---|
473 | } |
---|
474 | |
---|
475 | /** |
---|
476 | * comment_type() - Display the comment type of the current comment |
---|
477 | * |
---|
478 | * @since 0.71 |
---|
479 | * |
---|
480 | * @param string $commenttxt The string to display for comment type |
---|
481 | * @param string $trackbacktxt The string to display for trackback type |
---|
482 | * @param string $pingbacktxt The string to display for pingback type |
---|
483 | */ |
---|
484 | function comment_type($commenttxt = 'Comment', $trackbacktxt = 'Trackback', $pingbacktxt = 'Pingback') { |
---|
485 | $type = get_comment_type(); |
---|
486 | switch( $type ) { |
---|
487 | case 'trackback' : |
---|
488 | echo $trackbacktxt; |
---|
489 | break; |
---|
490 | case 'pingback' : |
---|
491 | echo $pingbacktxt; |
---|
492 | break; |
---|
493 | default : |
---|
494 | echo $commenttxt; |
---|
495 | } |
---|
496 | } |
---|
497 | |
---|
498 | /** |
---|
499 | * get_trackback_url() - Retrieve The current post's trackback URL |
---|
500 | * |
---|
501 | * There is a check to see if permalink's have been enabled and if so, will retrieve |
---|
502 | * the pretty path. If permalinks weren't enabled, the ID of the current post is used |
---|
503 | * and appended to the correct page to go to. |
---|
504 | * |
---|
505 | * @since 1.5 |
---|
506 | * @uses apply_filters() Calls 'trackback_url' on the resulting trackback URL |
---|
507 | * @uses $id |
---|
508 | * |
---|
509 | * @return string The trackback URL after being filtered |
---|
510 | */ |
---|
511 | function get_trackback_url() { |
---|
512 | global $id; |
---|
513 | if ( '' != get_option('permalink_structure') ) { |
---|
514 | $tb_url = trailingslashit(get_permalink()) . user_trailingslashit('trackback', 'single_trackback'); |
---|
515 | } else { |
---|
516 | $tb_url = get_option('siteurl') . '/wp-trackback.php?p=' . $id; |
---|
517 | } |
---|
518 | return apply_filters('trackback_url', $tb_url); |
---|
519 | } |
---|
520 | |
---|
521 | /** |
---|
522 | * trackback_url() - Displays the current post's trackback URL |
---|
523 | * |
---|
524 | * @since 0.71 |
---|
525 | * @uses get_trackback_url() Gets the trackback url for the current post |
---|
526 | * |
---|
527 | * @param bool $deprecated Remove backwards compat in 2.5 |
---|
528 | * @return void|string Should only be used to echo the trackback URL, use get_trackback_url() for the result instead. |
---|
529 | */ |
---|
530 | function trackback_url($deprecated = true) { |
---|
531 | if ($deprecated) echo get_trackback_url(); |
---|
532 | else return get_trackback_url(); |
---|
533 | } |
---|
534 | |
---|
535 | /** |
---|
536 | * trackback_rdf() - Generates and displays the RDF for the trackback information of current post |
---|
537 | * |
---|
538 | * @since 0.71 |
---|
539 | * |
---|
540 | * @param int $deprecated Not used (Was $timezone = 0) |
---|
541 | */ |
---|
542 | function trackback_rdf($deprecated = '') { |
---|
543 | if (stripos($_SERVER['HTTP_USER_AGENT'], 'W3C_Validator') === false) { |
---|
544 | echo '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" |
---|
545 | xmlns:dc="http://purl.org/dc/elements/1.1/" |
---|
546 | xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/"> |
---|
547 | <rdf:Description rdf:about="'; |
---|
548 | the_permalink(); |
---|
549 | echo '"'."\n"; |
---|
550 | echo ' dc:identifier="'; |
---|
551 | the_permalink(); |
---|
552 | echo '"'."\n"; |
---|
553 | echo ' dc:title="'.str_replace('--', '--', wptexturize(strip_tags(get_the_title()))).'"'."\n"; |
---|
554 | echo ' trackback:ping="'.get_trackback_url().'"'." />\n"; |
---|
555 | echo '</rdf:RDF>'; |
---|
556 | } |
---|
557 | } |
---|
558 | |
---|
559 | /** |
---|
560 | * comments_open() - Whether the current post is open for comments |
---|
561 | * |
---|
562 | * @since 1.5 |
---|
563 | * @uses $post |
---|
564 | * |
---|
565 | * @param int $post_id An optional post ID to check instead of the current post. |
---|
566 | * @return bool True if the comments are open |
---|
567 | */ |
---|
568 | function comments_open( $post_id=NULL ) { |
---|
569 | |
---|
570 | $_post = get_post($post_id); |
---|
571 | |
---|
572 | $open = ( 'open' == $_post->comment_status ); |
---|
573 | return apply_filters( 'comments_open', $open, $post_id ); |
---|
574 | } |
---|
575 | |
---|
576 | /** |
---|
577 | * pings_open() - Whether the current post is open for pings |
---|
578 | * |
---|
579 | * @since 1.5 |
---|
580 | * @uses $post |
---|
581 | * |
---|
582 | * @param int $post_id An optional post ID to check instead of the current post. |
---|
583 | * @return bool True if pings are accepted |
---|
584 | */ |
---|
585 | function pings_open( $post_id = NULL ) { |
---|
586 | |
---|
587 | $_post = get_post($post_id); |
---|
588 | |
---|
589 | $open = ( 'open' == $_post->ping_status ); |
---|
590 | return apply_filters( 'pings_open', $open, $post_id ); |
---|
591 | } |
---|
592 | |
---|
593 | /** |
---|
594 | * wp_comment_form_unfiltered_html_nonce() - Displays form token for unfiltered comments |
---|
595 | * |
---|
596 | * Will only display nonce token if the current user has permissions for unfiltered html. |
---|
597 | * Won't display the token for other users. |
---|
598 | * |
---|
599 | * The function was backported to 2.0.10 and was added to versions 2.1.3 and above. Does not |
---|
600 | * exist in versions prior to 2.0.10 in the 2.0 branch and in the 2.1 branch, prior to 2.1.3. |
---|
601 | * Technically added in 2.2.0. |
---|
602 | * |
---|
603 | * @since 2.0.10 Backported to 2.0 branch |
---|
604 | * @since 2.1.3 |
---|
605 | * @uses $post Gets the ID of the current post for the token |
---|
606 | */ |
---|
607 | function wp_comment_form_unfiltered_html_nonce() { |
---|
608 | global $post; |
---|
609 | if ( current_user_can('unfiltered_html') ) |
---|
610 | wp_nonce_field('unfiltered-html-comment_' . $post->ID, '_wp_unfiltered_html_comment', false); |
---|
611 | } |
---|
612 | |
---|
613 | /** |
---|
614 | * comments_template() - Loads the comment template specified in $file |
---|
615 | * |
---|
616 | * Will not display the comments template if not on single post or page, or |
---|
617 | * if the post does not have comments. |
---|
618 | * |
---|
619 | * Uses the WordPress database object to query for the comments. The comments |
---|
620 | * are passed through the 'comments_array' filter hook with the list of comments |
---|
621 | * and the post ID respectively. |
---|
622 | * |
---|
623 | * The $file path is passed through a filter hook called, 'comments_template' |
---|
624 | * which includes the TEMPLATEPATH and $file combined. Tries the $filtered path |
---|
625 | * first and if it fails it will require the default comment themplate from the |
---|
626 | * default theme. If either does not exist, then the WordPress process will be |
---|
627 | * halted. It is advised for that reason, that the default theme is not deleted. |
---|
628 | * |
---|
629 | * @since 1.5 |
---|
630 | * @global array $comment List of comment objects for the current post |
---|
631 | * @uses $wpdb |
---|
632 | * @uses $id |
---|
633 | * @uses $post |
---|
634 | * @uses $withcomments Will not try to get the comments if the post has none. |
---|
635 | * |
---|
636 | * @param string $file Optional, default '/comments.php'. The file to load |
---|
637 | * @return null Returns null if no comments appear |
---|
638 | */ |
---|
639 | function comments_template( $file = '/comments.php' ) { |
---|
640 | global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity; |
---|
641 | |
---|
642 | if ( ! (is_single() || is_page() || $withcomments) ) |
---|
643 | return; |
---|
644 | |
---|
645 | $req = get_option('require_name_email'); |
---|
646 | $commenter = wp_get_current_commenter(); |
---|
647 | extract($commenter, EXTR_SKIP); |
---|
648 | |
---|
649 | /** @todo Use API instead of SELECTs. */ |
---|
650 | if ( $user_ID) { |
---|
651 | $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)); |
---|
652 | } else if ( empty($comment_author) ) { |
---|
653 | $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)); |
---|
654 | } else { |
---|
655 | $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)); |
---|
656 | } |
---|
657 | |
---|
658 | // keep $comments for legacy's sake (remember $table*? ;) ) |
---|
659 | $comments = $wp_query->comments = apply_filters( 'comments_array', $comments, $post->ID ); |
---|
660 | $wp_query->comment_count = count($wp_query->comments); |
---|
661 | update_comment_cache($comments); |
---|
662 | |
---|
663 | define('COMMENTS_TEMPLATE', true); |
---|
664 | $include = apply_filters('comments_template', STYLESHEETPATH . $file ); |
---|
665 | if (file_exists( $include ) ) |
---|
666 | require( $include ); |
---|
667 | |
---|
668 | //not sure if this is needed - KKWangen |
---|
669 | elseif( TEMPLATEPATH == STYLESHEETPATH && file_exists(TEMPLATEPATH . $file) ) |
---|
670 | require( TEMPLATEPATH . $file ); |
---|
671 | |
---|
672 | else |
---|
673 | require( WP_CONTENT_DIR . '/themes/default/comments.php'); |
---|
674 | } |
---|
675 | |
---|
676 | /** |
---|
677 | * comments_popup_script() - Displays the JS popup script to show a comment |
---|
678 | * |
---|
679 | * If the $file parameter is empty, then the home page is assumed. The defaults |
---|
680 | * for the window are 400px by 400px. |
---|
681 | * |
---|
682 | * For the comment link popup to work, this function has to be called or the |
---|
683 | * normal comment link will be assumed. |
---|
684 | * |
---|
685 | * @since 0.71 |
---|
686 | * @global string $wpcommentspopupfile The URL to use for the popup window |
---|
687 | * @global int $wpcommentsjavascript Whether to use JavaScript or not. Set when function is called |
---|
688 | * |
---|
689 | * @param int $width Optional. The width of the popup window |
---|
690 | * @param int $height Optional. The height of the popup window |
---|
691 | * @param string $file Optional. Sets the location of the popup window |
---|
692 | */ |
---|
693 | function comments_popup_script($width=400, $height=400, $file='') { |
---|
694 | global $wpcommentspopupfile, $wpcommentsjavascript; |
---|
695 | |
---|
696 | if (empty ($file)) { |
---|
697 | $wpcommentspopupfile = ''; // Use the index. |
---|
698 | } else { |
---|
699 | $wpcommentspopupfile = $file; |
---|
700 | } |
---|
701 | |
---|
702 | $wpcommentsjavascript = 1; |
---|
703 | $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"; |
---|
704 | echo $javascript; |
---|
705 | } |
---|
706 | |
---|
707 | /** |
---|
708 | * comments_popup_link() - Displays the link to the comments popup window for the current post ID. |
---|
709 | * |
---|
710 | * Is not meant to be displayed on single posts and pages. Should be used on the lists of posts |
---|
711 | * |
---|
712 | * @since 0.71 |
---|
713 | * @uses $id |
---|
714 | * @uses $wpcommentspopupfile |
---|
715 | * @uses $wpcommentsjavascript |
---|
716 | * @uses $post |
---|
717 | * |
---|
718 | * @param string $zero The string to display when no comments |
---|
719 | * @param string $one The string to display when only one comment is available |
---|
720 | * @param string $more The string to display when there are more than one comment |
---|
721 | * @param string $css_class The CSS class to use for comments |
---|
722 | * @param string $none The string to display when comments have been turned off |
---|
723 | * @return null Returns null on single posts and pages. |
---|
724 | */ |
---|
725 | function comments_popup_link( $zero = 'No Comments', $one = '1 Comment', $more = '% Comments', $css_class = '', $none = 'Comments Off' ) { |
---|
726 | global $id, $wpcommentspopupfile, $wpcommentsjavascript, $post; |
---|
727 | |
---|
728 | if ( is_single() || is_page() ) |
---|
729 | return; |
---|
730 | |
---|
731 | $number = get_comments_number( $id ); |
---|
732 | |
---|
733 | if ( 0 == $number && 'closed' == $post->comment_status && 'closed' == $post->ping_status ) { |
---|
734 | echo '<span' . ((!empty($css_class)) ? ' class="' . $css_class . '"' : '') . '>' . $none . '</span>'; |
---|
735 | return; |
---|
736 | } |
---|
737 | |
---|
738 | if ( !empty($post->post_password) ) { // if there's a password |
---|
739 | if ( !isset($_COOKIE['wp-postpass_' . COOKIEHASH]) || $_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password ) { // and it doesn't match the cookie |
---|
740 | echo __('Enter your password to view comments'); |
---|
741 | return; |
---|
742 | } |
---|
743 | } |
---|
744 | |
---|
745 | echo '<a href="'; |
---|
746 | if ( $wpcommentsjavascript ) { |
---|
747 | if ( empty( $wpcommentspopupfile ) ) |
---|
748 | $home = get_option('home'); |
---|
749 | else |
---|
750 | $home = get_option('siteurl'); |
---|
751 | echo $home . '/' . $wpcommentspopupfile . '?comments_popup=' . $id; |
---|
752 | echo '" onclick="wpopen(this.href); return false"'; |
---|
753 | } else { // if comments_popup_script() is not in the template, display simple comment link |
---|
754 | if ( 0 == $number ) |
---|
755 | echo get_permalink() . '#respond'; |
---|
756 | else |
---|
757 | comments_link(); |
---|
758 | echo '"'; |
---|
759 | } |
---|
760 | |
---|
761 | if ( !empty( $css_class ) ) { |
---|
762 | echo ' class="'.$css_class.'" '; |
---|
763 | } |
---|
764 | $title = attribute_escape( get_the_title() ); |
---|
765 | |
---|
766 | echo apply_filters( 'comments_popup_link_attributes', '' ); |
---|
767 | |
---|
768 | echo ' title="' . sprintf( __('Comment on %s'), $title ) . '">'; |
---|
769 | comments_number( $zero, $one, $more, $number ); |
---|
770 | echo '</a>'; |
---|
771 | } |
---|
772 | |
---|
773 | ?> |
---|