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