Advertisement
Guest User

Untitled

a guest
Nov 29th, 2010
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.23 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. function comments_template( $file = '/comments.php', $separate_comments = false, $ajax = false ) {
  5.     global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity, $overridden_cpage;
  6.  
  7.     if ( !(is_single() || is_page() || $withcomments) || empty($post) )
  8.         return;
  9.  
  10.     if ( empty($file) )
  11.         $file = '/comments.php';
  12.  
  13.     $req = get_option('require_name_email');
  14.  
  15.     /**
  16.      * Comment author information fetched from the comment cookies.
  17.      *
  18.      * @uses wp_get_current_commenter()
  19.      */
  20.     $commenter = wp_get_current_commenter();
  21.  
  22.     /**
  23.      * The name of the current comment author escaped for use in attributes.
  24.      */
  25.     $comment_author = $commenter['comment_author']; // Escaped by sanitize_comment_cookies()
  26.  
  27.     /**
  28.      * The email address of the current comment author escaped for use in attributes.
  29.      */
  30.     $comment_author_email = $commenter['comment_author_email'];  // Escaped by sanitize_comment_cookies()
  31.  
  32.     /**
  33.      * The url of the current comment author escaped for use in attributes.
  34.      */
  35.     $comment_author_url = esc_url($commenter['comment_author_url']);
  36.  
  37.  
  38.     if($ajax):
  39.      global $post, $wpdb;
  40.      $comments = get_comments(array(
  41.       'type' => 'comment',
  42.       'post_id' => $post->ID,
  43.        'status' => 'approve',
  44.       'number' => 10
  45.      ));
  46.  
  47.     else:
  48.     //  $limits = "LIMIT 10";
  49.  
  50.     /** @todo Use API instead of SELECTs. */
  51.     if ( $user_ID) {
  52.         $comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND (comment_approved = '1' OR ( user_id = %d AND comment_approved = '0' ) )  ORDER BY comment_date_gmt $limits", $post->ID, $user_ID));
  53.     } else if ( empty($comment_author) ) {
  54.         $comments = get_comments( array('post_id' => $post->ID, 'status' => 'approve', 'order' => 'ASC') );
  55.     } else {
  56.         $comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND ( comment_approved = '1' OR ( comment_author = %s AND comment_author_email = %s AND comment_approved = '0' ) ) ORDER BY comment_date_gmt $limits", $post->ID, wp_specialchars_decode($comment_author,ENT_QUOTES), $comment_author_email));
  57.     }
  58.  
  59.     endif;
  60.  
  61.     // keep $comments for legacy's sake
  62.     $wp_query->comments = apply_filters( 'comments_array', $comments, $post->ID );
  63.     $comments = &$wp_query->comments;
  64.     $wp_query->comment_count = count($wp_query->comments);
  65.     update_comment_cache($wp_query->comments);
  66.  
  67.     if ( $separate_comments ) {
  68.         $wp_query->comments_by_type = &separate_comments($comments);
  69.         $comments_by_type = &$wp_query->comments_by_type;
  70.     }
  71.  
  72.     $overridden_cpage = FALSE;
  73.     if ( '' == get_query_var('cpage') && get_option('page_comments') ) {
  74.         set_query_var( 'cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1 );
  75.         $overridden_cpage = TRUE;
  76.     }
  77.  
  78.     if ( !defined('COMMENTS_TEMPLATE') || !COMMENTS_TEMPLATE)
  79.         define('COMMENTS_TEMPLATE', true);
  80.  
  81.     $include = apply_filters('comments_template', STYLESHEETPATH . $file );
  82.     if ( file_exists( $include ) )
  83.         require( $include );
  84.     elseif ( file_exists( TEMPLATEPATH . $file ) )
  85.         require( TEMPLATEPATH .  $file );
  86.     else // Backward compat code will be removed in a future release
  87.         require( ABSPATH . WPINC . '/theme-compat/comments.php');
  88. }
  89.  
  90.  
  91. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement