home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Blogs / wordpress2.6.exe / wordpress2.6 / wp-includes / comment-template.php < prev    next >
Encoding:
PHP Script  |  2008-06-23  |  23.3 KB  |  772 lines

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