PHP Cross Reference of WordPress Subversion HEAD

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]

title

Body

[close]

/wp-includes/ -> comment-template.php (source)

   1  <?php
   2  /*
   3   * Comment template functions.
   4   */
   5  
   6  function get_comment_author() {
   7      global $comment;
   8      if ( empty($comment->comment_author) )
   9          $author = __('Anonymous');
  10      else
  11          $author = $comment->comment_author;
  12      return apply_filters('get_comment_author', $author);
  13  }
  14  
  15  function comment_author() {
  16      $author = apply_filters('comment_author', get_comment_author() );
  17      echo $author;
  18  }
  19  
  20  function get_comment_author_email() {
  21      global $comment;
  22      return apply_filters('get_comment_author_email', $comment->comment_author_email);
  23  }
  24  
  25  function comment_author_email() {
  26      echo apply_filters('author_email', get_comment_author_email() );
  27  }
  28  
  29  function comment_author_email_link($linktext='', $before='', $after='') {
  30      global $comment;
  31      $email = apply_filters('comment_email', $comment->comment_author_email);
  32      if ((!empty($email)) && ($email != '@')) {
  33      $display = ($linktext != '') ? $linktext : $email;
  34          echo $before;
  35          echo "<a href='mailto:$email'>$display</a>";
  36          echo $after;
  37      }
  38  }
  39  
  40  function get_comment_author_link() {
  41      global $comment;
  42      $url    = get_comment_author_url();
  43      $author = get_comment_author();
  44  
  45      if ( empty( $url ) || 'http://' == $url )
  46          $return = $author;
  47      else
  48          $return = "<a href='$url' rel='external nofollow'>$author</a>";
  49      return apply_filters('get_comment_author_link', $return);
  50  }
  51  
  52  function comment_author_link() {
  53      echo get_comment_author_link();
  54  }
  55  
  56  function get_comment_author_IP() {
  57      global $comment;
  58      return apply_filters('get_comment_author_IP', $comment->comment_author_IP);
  59  }
  60  
  61  function comment_author_IP() {
  62      echo get_comment_author_IP();
  63  }
  64  
  65  function get_comment_author_url() {
  66      global $comment;
  67      return apply_filters('get_comment_author_url', $comment->comment_author_url);
  68  }
  69  
  70  function comment_author_url() {
  71      echo apply_filters('comment_url', get_comment_author_url());
  72  }
  73  
  74  function get_comment_author_url_link( $linktext = '', $before = '', $after = '' ) {
  75      global $comment;
  76      $url = get_comment_author_url();
  77      $display = ($linktext != '') ? $linktext : $url;
  78      $display = str_replace( 'http://www.', '', $display );
  79      $display = str_replace( 'http://', '', $display );
  80      if ( '/' == substr($display, -1) )
  81          $display = substr($display, 0, -1);
  82      $return = "$before<a href='$url' rel='external'>$display</a>$after";
  83      return apply_filters('get_comment_author_url_link', $return);
  84  }
  85  
  86  function comment_author_url_link( $linktext = '', $before = '', $after = '' ) {
  87      echo get_comment_author_url_link( $linktext, $before, $after );
  88  }
  89  
  90  function get_comment_date( $d = '' ) {
  91      global $comment;
  92      if ( '' == $d )
  93          $date = mysql2date( get_option('date_format'), $comment->comment_date);
  94      else
  95          $date = mysql2date($d, $comment->comment_date);
  96      return apply_filters('get_comment_date', $date, $d);
  97  }
  98  
  99  function comment_date( $d = '' ) {
 100      echo get_comment_date( $d );
 101  }
 102  
 103  function get_comment_excerpt() {
 104      global $comment;
 105      $comment_text = strip_tags($comment->comment_content);
 106      $blah = explode(' ', $comment_text);
 107      if (count($blah) > 20) {
 108          $k = 20;
 109          $use_dotdotdot = 1;
 110      } else {
 111          $k = count($blah);
 112          $use_dotdotdot = 0;
 113      }
 114      $excerpt = '';
 115      for ($i=0; $i<$k; $i++) {
 116          $excerpt .= $blah[$i] . ' ';
 117      }
 118      $excerpt .= ($use_dotdotdot) ? '...' : '';
 119      return apply_filters('get_comment_excerpt', $excerpt);
 120  }
 121  
 122  function comment_excerpt() {
 123      echo apply_filters('comment_excerpt', get_comment_excerpt() );
 124  }
 125  
 126  function get_comment_ID() {
 127      global $comment;
 128      return apply_filters('get_comment_ID', $comment->comment_ID);
 129  }
 130  
 131  function comment_ID() {
 132      echo get_comment_ID();
 133  }
 134  
 135  function get_comment_link() {
 136      global $comment;
 137      return get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment->comment_ID;
 138  }
 139  
 140  function get_comments_link() {
 141      return get_permalink() . '#comments';
 142  }
 143  
 144  function comments_link( $file = '', $echo = true ) {
 145          echo get_comments_link();
 146  }
 147  
 148  function get_comments_number( $post_id = 0 ) {
 149      global $wpdb, $id;
 150      $post_id = (int) $post_id;
 151  
 152      if ( !$post_id )
 153          $post_id = (int) $id;
 154  
 155      $post = get_post($post_id);
 156      if ( ! isset($post->comment_count) )
 157          $count = 0;
 158      else
 159          $count = $post->comment_count;
 160  
 161      return apply_filters('get_comments_number', $count);
 162  }
 163  
 164  function comments_number( $zero = false, $one = false, $more = false, $deprecated = '' ) {
 165      global $id;
 166      $number = get_comments_number($id);
 167  
 168      if ( $number > 1 )
 169          $output = str_replace('%', $number, ( false === $more ) ? __('% Comments') : $more);
 170      elseif ( $number == 0 )
 171          $output = ( false === $zero ) ? __('No Comments') : $zero;
 172      else // must be one
 173          $output = ( false === $one ) ? __('1 Comment') : $one;
 174  
 175      echo apply_filters('comments_number', $output, $number);
 176  }
 177  
 178  function get_comment_text() {
 179      global $comment;
 180      return apply_filters('get_comment_text', $comment->comment_content);
 181  }
 182  
 183  function comment_text() {
 184      echo apply_filters('comment_text', get_comment_text() );
 185  }
 186  
 187  function get_comment_time( $d = '', $gmt = false ) {
 188      global $comment;
 189      $comment_date = $gmt? $comment->comment_date_gmt : $comment->comment_date;
 190      if ( '' == $d )
 191          $date = mysql2date(get_option('time_format'), $comment_date);
 192      else
 193          $date = mysql2date($d, $comment_date);
 194      return apply_filters('get_comment_time', $date, $d, $gmt);
 195  }
 196  
 197  function comment_time( $d = '' ) {
 198      echo get_comment_time($d);
 199  }
 200  
 201  function get_comment_type() {
 202      global $comment;
 203  
 204      if ( '' == $comment->comment_type )
 205          $comment->comment_type = 'comment';
 206  
 207      return apply_filters('get_comment_type', $comment->comment_type);
 208  }
 209  
 210  function comment_type($commenttxt = 'Comment', $trackbacktxt = 'Trackback', $pingbacktxt = 'Pingback') {
 211      $type = get_comment_type();
 212      switch( $type ) {
 213          case 'trackback' :
 214              echo $trackbacktxt;
 215              break;
 216          case 'pingback' :
 217              echo $pingbacktxt;
 218              break;
 219          default :
 220              echo $commenttxt;
 221      }
 222  }
 223  
 224  function get_trackback_url() {
 225      global $id;
 226      if ( '' != get_option('permalink_structure') ) {
 227          $tb_url = trailingslashit(get_permalink()) . user_trailingslashit('trackback', 'single_trackback');
 228      } else {
 229          $tb_url = get_option('siteurl') . '/wp-trackback.php?p=' . $id;
 230      }
 231      return apply_filters('trackback_url', $tb_url);
 232  }
 233  
 234  function trackback_url($deprecated = true) { // remove backwards compat in 2.4
 235      if ($deprecated) echo get_trackback_url();
 236      else return get_trackback_url();
 237  }
 238  
 239  function trackback_rdf($timezone = 0) {
 240      global $id;
 241      if (stripos($_SERVER['HTTP_USER_AGENT'], 'W3C_Validator') === false) {
 242          echo '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 243                  xmlns:dc="http://purl.org/dc/elements/1.1/"
 244                  xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
 245              <rdf:Description rdf:about="';
 246          the_permalink();
 247          echo '"'."\n";
 248          echo '    dc:identifier="';
 249          the_permalink();
 250          echo '"'."\n";
 251          echo '    dc:title="'.str_replace('--', '&#x2d;&#x2d;', wptexturize(strip_tags(get_the_title()))).'"'."\n";
 252          echo '    trackback:ping="'.get_trackback_url().'"'." />\n";
 253          echo '</rdf:RDF>';
 254      }
 255  }
 256  
 257  function comments_open() {
 258      global $post;
 259      if ( 'open' == $post->comment_status )
 260          return true;
 261      else
 262          return false;
 263  }
 264  
 265  function pings_open() {
 266      global $post;
 267      if ( 'open' == $post->ping_status )
 268          return true;
 269      else
 270          return false;
 271  }
 272  
 273  function wp_comment_form_unfiltered_html_nonce() {
 274      global $post;
 275      if ( current_user_can('unfiltered_html') )
 276          wp_nonce_field('unfiltered-html-comment_' . $post->ID, '_wp_unfiltered_html_comment', false);
 277  }
 278  
 279  function comments_template( $file = '/comments.php' ) {
 280      global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity;
 281  
 282      if ( ! (is_single() || is_page() || $withcomments) )
 283          return;
 284  
 285      $req = get_option('require_name_email');
 286      $commenter = wp_get_current_commenter();
 287      extract($commenter, EXTR_SKIP);
 288  
 289      // TODO: Use API instead of SELECTs.
 290      if ( $user_ID) {
 291          $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));
 292      } else if ( empty($comment_author) ) {
 293          $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));
 294      } else {
 295          $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));
 296      }
 297  
 298      // keep $comments for legacy's sake (remember $table*? ;) )
 299      $comments = $wp_query->comments = apply_filters( 'comments_array', $comments, $post->ID );
 300      $wp_query->comment_count = count($wp_query->comments);
 301      update_comment_cache($comments);
 302  
 303      define('COMMENTS_TEMPLATE', true);
 304      $include = apply_filters('comments_template', TEMPLATEPATH . $file );
 305      if ( file_exists( $include ) )
 306          require( $include );
 307      else
 308          require ( ABSPATH . 'wp-content/themes/default/comments.php');
 309  }
 310  
 311  function comments_popup_script($width=400, $height=400, $file='') {
 312          global $wpcommentspopupfile, $wptrackbackpopupfile, $wppingbackpopupfile, $wpcommentsjavascript;
 313  
 314          if (empty ($file)) {
 315              $wpcommentspopupfile = '';  // Use the index.
 316          } else {
 317              $wpcommentspopupfile = $file;
 318          }
 319  
 320          $wpcommentsjavascript = 1;
 321          $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";
 322          echo $javascript;
 323  }
 324  
 325  function comments_popup_link($zero='No Comments', $one='1 Comment', $more='% Comments', $CSSclass='', $none='Comments Off') {
 326      global $id, $wpcommentspopupfile, $wpcommentsjavascript, $post, $wpdb;
 327  
 328      if ( is_single() || is_page() )
 329          return;
 330  
 331      $number = get_comments_number($id);
 332  
 333      if ( 0 == $number && 'closed' == $post->comment_status && 'closed' == $post->ping_status ) {
 334          echo '<span' . ((!empty($CSSclass)) ? ' class="' . $CSSclass . '"' : '') . '>' . $none . '</span>';
 335          return;
 336      }
 337  
 338      if ( !empty($post->post_password) ) { // if there's a password
 339          if ($_COOKIE['wp-postpass_'.COOKIEHASH] != $post->post_password) {  // and it doesn't match the cookie
 340              echo(__('Enter your password to view comments'));
 341              return;
 342          }
 343      }
 344  
 345      echo '<a href="';
 346      if ($wpcommentsjavascript) {
 347          if ( empty($wpcommentspopupfile) )
 348              $home = get_option('home');
 349          else
 350              $home = get_option('siteurl');
 351          echo $home . '/' . $wpcommentspopupfile.'?comments_popup='.$id;
 352          echo '" onclick="wpopen(this.href); return false"';
 353      } else { // if comments_popup_script() is not in the template, display simple comment link
 354          if ( 0 == $number )
 355              echo get_permalink() . '#respond';
 356          else
 357              comments_link();
 358          echo '"';
 359      }
 360  
 361      if (!empty($CSSclass)) {
 362          echo ' class="'.$CSSclass.'"';
 363      }
 364      $title = attribute_escape(get_the_title());
 365      echo ' title="' . sprintf( __('Comment on %s'), $title ) .'">';
 366      comments_number($zero, $one, $more, $number);
 367      echo '</a>';
 368  }
 369  
 370  ?>


Generated Thu Dec 6 06:47:08 2007 for RedAlt XRefs Cross-referenced by PHPXref 0.6 and RedAlt