function prepare_items() { global $post_id, $comment_status, $search, $comment_type; $comment_status = isset($_REQUEST['comment_status']) ? $_REQUEST['comment_status'] : 'all'; if (!in_array($comment_status, array('all', 'moderated', 'approved', 'spam', 'trash'))) { $comment_status = 'all'; } $comment_type = !empty($_REQUEST['comment_type']) ? $_REQUEST['comment_type'] : ''; $search = isset($_REQUEST['s']) ? $_REQUEST['s'] : ''; $post_type = isset($_REQUEST['post_type']) ? sanitize_key($_REQUEST['post_type']) : ''; $user_id = isset($_REQUEST['user_id']) ? $_REQUEST['user_id'] : ''; $orderby = isset($_REQUEST['orderby']) ? $_REQUEST['orderby'] : ''; $order = isset($_REQUEST['order']) ? $_REQUEST['order'] : ''; $comments_per_page = $this->get_per_page($comment_status); $doing_ajax = defined('DOING_AJAX') && DOING_AJAX; if (isset($_REQUEST['number'])) { $number = (int) $_REQUEST['number']; } else { $number = $comments_per_page + min(8, $comments_per_page); // Grab a few extra } $page = $this->get_pagenum(); if (isset($_REQUEST['start'])) { $start = $_REQUEST['start']; } else { $start = ($page - 1) * $comments_per_page; } if ($doing_ajax && isset($_REQUEST['offset'])) { $start += $_REQUEST['offset']; } $status_map = array('moderated' => 'hold', 'approved' => 'approve', 'all' => ''); $args = array('status' => isset($status_map[$comment_status]) ? $status_map[$comment_status] : $comment_status, 'search' => $search, 'user_id' => $user_id, 'offset' => $start, 'number' => $number, 'post_id' => $post_id, 'type' => $comment_type, 'orderby' => $orderby, 'order' => $order, 'post_type' => $post_type); $_comments = get_comments($args); update_comment_cache($_comments); $this->items = array_slice($_comments, 0, $comments_per_page); $this->extra_items = array_slice($_comments, $comments_per_page); $total_comments = get_comments(array_merge($args, array('count' => true, 'offset' => 0, 'number' => 0))); $_comment_post_ids = array(); foreach ($_comments as $_c) { $_comment_post_ids[] = $_c->comment_post_ID; } $_comment_post_ids = array_unique($_comment_post_ids); $this->pending_count = get_pending_comments_num($_comment_post_ids); $this->set_pagination_args(array('total_items' => $total_comments, 'per_page' => $comments_per_page)); }
/** * {@internal Missing Short Description}} * * @since unknown * * @param unknown_type $status * @param unknown_type $s * @param unknown_type $start * @param unknown_type $num * @param unknown_type $post * @param unknown_type $type * @return unknown */ function _wp_get_comment_list( $status = '', $s = false, $start, $num, $post = 0, $type = '' ) { global $wpdb; $start = abs( (int) $start ); $num = (int) $num; $post = (int) $post; if ( 'moderated' == $status ) $approved = "comment_approved = '0'"; elseif ( 'approved' == $status ) $approved = "comment_approved = '1'"; elseif ( 'spam' == $status ) $approved = "comment_approved = 'spam'"; else $approved = "( comment_approved = '0' OR comment_approved = '1' )"; if ( $post ) { $post = " AND comment_post_ID = '$post'"; $orderby = "ORDER BY comment_date_gmt ASC LIMIT $start, $num"; } else { $post = ''; $orderby = "ORDER BY comment_date_gmt DESC LIMIT $start, $num"; } if ( 'comment' == $type ) $typesql = "AND comment_type = ''"; elseif ( 'pingback' == $type ) $typesql = "AND comment_type = 'pingback'"; elseif ( 'trackback' == $type ) $typesql = "AND comment_type = 'trackback'"; elseif ( 'pings' == $type ) $typesql = "AND ( comment_type = 'pingback' OR comment_type = 'trackback' )"; else $typesql = ''; if ( $s ) { $s = $wpdb->escape($s); $comments = $wpdb->get_results("SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->comments WHERE (comment_author LIKE '%$s%' OR comment_author_email LIKE '%$s%' OR comment_author_url LIKE ('%$s%') OR comment_author_IP LIKE ('%$s%') OR comment_content LIKE ('%$s%') ) AND $approved $typesql $orderby"); } else { $comments = $wpdb->get_results( "SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->comments WHERE $approved $post $typesql $orderby" ); } update_comment_cache($comments); $total = $wpdb->get_var( "SELECT FOUND_ROWS()" ); return array($comments, $total); }
/** * Loads the comment template specified in $file. * * Will not display the comments template if not on single post or page, or if * the post does not have comments. * * Uses the WordPress database object to query for the comments. The comments * are passed through the 'comments_array' filter hook with the list of comments * and the post ID respectively. * * The $file path is passed through a filter hook called, 'comments_template' * which includes the TEMPLATEPATH and $file combined. Tries the $filtered path * first and if it fails it will require the default comment themplate from the * default theme. If either does not exist, then the WordPress process will be * halted. It is advised for that reason, that the default theme is not deleted. * * @since 1.5.0 * @global array $comment List of comment objects for the current post * @uses $wpdb * @uses $id * @uses $post * @uses $withcomments Will not try to get the comments if the post has none. * * @param string $file Optional, default '/comments.php'. The file to load * @param bool $separate_comments Optional, whether to separate the comments by comment type. Default is false. * @return null Returns null if no comments appear */ function comments_template($file = '/comments.php', $separate_comments = false) { global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity, $overridden_cpage; if (!(is_single() || is_page() || $withcomments)) { return; } if (empty($file)) { $file = '/comments.php'; } $req = get_option('require_name_email'); $commenter = wp_get_current_commenter(); extract($commenter, EXTR_SKIP); /** @todo Use API instead of SELECTs. */ if ($user_ID) { $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", $post->ID, $user_ID)); } else { if (empty($comment_author)) { $comments = get_comments(array('post_id' => $post->ID, 'status' => 'approve', 'order' => 'ASC')); } else { $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", $post->ID, $comment_author, $comment_author_email)); } } // keep $comments for legacy's sake $wp_query->comments = apply_filters('comments_array', $comments, $post->ID); $comments =& $wp_query->comments; $wp_query->comment_count = count($wp_query->comments); update_comment_cache($wp_query->comments); if ($separate_comments) { $wp_query->comments_by_type =& separate_comments($comments); $comments_by_type =& $wp_query->comments_by_type; } $overridden_cpage = FALSE; if ('' == get_query_var('cpage') && get_option('page_comments')) { set_query_var('cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1); $overridden_cpage = TRUE; } define('COMMENTS_TEMPLATE', true); $include = apply_filters('comments_template', STYLESHEETPATH . $file); if (file_exists($include)) { require $include; } elseif (file_exists(TEMPLATEPATH . $file)) { require TEMPLATEPATH . $file; } else { require get_theme_root() . '/default/comments.php'; } }
function callback($path = '', $blog_id = 0, $object_id = 0) { $blog_id = $this->api->switch_to_blog_and_validate_user($this->api->get_blog_id($blog_id)); if (is_wp_error($blog_id)) { return $blog_id; } $args = $this->query_args(); if ($args['number'] < 1) { $args['number'] = 20; } elseif (100 < $args['number']) { return new WP_Error('invalid_number', 'The NUMBER parameter must be less than or equal to 100.', 400); } if (false !== strpos($path, '/posts/')) { // We're looking for comments of a particular post $post_id = $object_id; $comment_id = 0; } else { // We're looking for comments for the whole blog, or replies to a single comment $comment_id = $object_id; $post_id = 0; } // We can't efficiently get the number of replies to a single comment $count = false; $found = -1; if (!$comment_id) { // We can get comment counts for the whole site or for a single post, but only for certain queries if ('any' === $args['type'] && !isset($args['after']) && !isset($args['before'])) { $count = wp_count_comments($post_id); } } switch ($args['status']) { case 'approved': $status = 'approve'; if ($count) { $found = $count->approved; } break; default: if (!current_user_can('moderate_comments')) { return new WP_Error('unauthorized', 'User cannot read non-approved comments', 403); } if ('unapproved' === $args['status']) { $status = 'hold'; $count_status = 'moderated'; } elseif ('all' === $args['status']) { $status = 'all'; $count_status = 'total_comments'; } else { $status = $count_status = $args['status']; } if ($count) { $found = $count->{$count_status}; } } $query = array('order' => $args['order'], 'type' => 'any' === $args['type'] ? false : $args['type'], 'status' => $status); if (isset($args['page'])) { if ($args['page'] < 1) { $args['page'] = 1; } } else { if ($args['offset'] < 0) { $args['offset'] = 0; } } if (!$args['hierarchical']) { $query['number'] = $args['number']; if (isset($args['page'])) { $query['offset'] = ($args['page'] - 1) * $args['number']; } else { $query['offset'] = $args['offset']; } $is_before = isset($args['before_gmt']); $is_after = isset($args['after_gmt']); if ($is_before || $is_after) { $query['date_query'] = array('column' => 'comment_date_gmt', 'inclusive' => true); if ($is_before) { $query['date_query']['before'] = $args['before_gmt']; } if ($is_after) { $query['date_query']['after'] = $args['after_gmt']; } } } if ($post_id) { $post = get_post($post_id); if (!$post || is_wp_error($post)) { return new WP_Error('unknown_post', 'Unknown post', 404); } $query['post_id'] = $post->ID; if ($this->api->ends_with($this->path, '/replies')) { $query['parent'] = 0; } } elseif ($comment_id) { $comment = get_comment($comment_id); if (!$comment || is_wp_error($comment)) { return new WP_Error('unknown_comment', 'Unknown comment', 404); } $query['parent'] = $comment_id; } $comments = get_comments($query); update_comment_cache($comments); if ($args['hierarchical']) { $walker = new WPCOM_JSON_API_List_Comments_Walker(); $comment_ids = $walker->paged_walk($comments, get_option('thread_comments_depth', -1), isset($args['page']) ? $args['page'] : 1, $args['number']); $comments = array_map('get_comment', $comment_ids); } $return = array(); foreach (array_keys($this->response_format) as $key) { switch ($key) { case 'found': $return[$key] = (int) $found; break; case 'site_ID': $return[$key] = (int) $blog_id; break; case 'comments': $return_comments = array(); foreach ($comments as $comment) { $the_comment = $this->get_comment($comment->comment_ID, $args['context']); if ($the_comment && !is_wp_error($the_comment)) { $return_comments[] = $the_comment; } } if ($return_comments) { /** This action is documented in json-endpoints/class.wpcom-json-api-site-settings-endpoint.php */ do_action('wpcom_json_api_objects', 'comments', count($return_comments)); } $return[$key] = $return_comments; break; } } return $return; }
function ddl_load_comments_array() { global $wpddlayout, $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity, $overridden_cpage; $commenter = wp_get_current_commenter(); $comment_author = $commenter['comment_author']; $comment_author_email = $commenter['comment_author_email']; $comment_author_url = esc_url($commenter['comment_author_url']); if ($user_ID) { $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", $post->ID, $user_ID)); } else { if (empty($comment_author)) { $comments = get_comments(array('post_id' => $post->ID, 'status' => 'approve', 'order' => 'ASC')); } else { $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", $post->ID, wp_specialchars_decode($comment_author, ENT_QUOTES), $comment_author_email)); } } $wp_query->comments = apply_filters('comments_array', $comments, $post->ID); $comments =& $wp_query->comments; $wp_query->comment_count = count($wp_query->comments); update_comment_cache($wp_query->comments); return $comments; }
/** * Get a list of comments matching the query vars. * * @since 0.0.1 * @access public * * @global hqdb $hqdb HiveQueen database abstraction object. * * @return int|array The list of comments. */ public function get_comments() { global $hqdb; $groupby = ''; $this->parse_query(); // Parse meta query $this->meta_query = new HQ_Meta_Query(); $this->meta_query->parse_query_vars($this->query_vars); /** * Fires before comments are retrieved. * * @since 0.0.1 * * @param HQ_Comment_Query &$this Current instance of HQ_Comment_Query, passed by reference. */ do_action_ref_array('pre_get_comments', array(&$this)); // Reparse query vars, in case they were modified in a 'pre_get_comments' callback. $this->meta_query->parse_query_vars($this->query_vars); if (!empty($this->meta_query->queries)) { $meta_query_clauses = $this->meta_query->get_sql('comment', $hqdb->comments, 'comment_ID', $this); } // $args can include anything. Only use the args defined in the query_var_defaults to compute the key. $key = md5(serialize(hq_array_slice_assoc($this->query_vars, array_keys($this->query_var_defaults)))); $last_changed = hq_cache_get('last_changed', 'comment'); if (!$last_changed) { $last_changed = microtime(); hq_cache_set('last_changed', $last_changed, 'comment'); } $cache_key = "get_comments:{$key}:{$last_changed}"; if ($cache = hq_cache_get($cache_key, 'comment')) { $this->comments = $cache; return $this->comments; } $where = array(); // Assemble clauses related to 'comment_approved'. $approved_clauses = array(); // 'status' accepts an array or a comma-separated string. $status_clauses = array(); $statuses = $this->query_vars['status']; if (!is_array($statuses)) { $statuses = preg_split('/[\\s,]+/', $statuses); } // 'any' overrides other statuses. if (!in_array('any', $statuses)) { foreach ($statuses as $status) { switch ($status) { case 'hold': $status_clauses[] = "comment_approved = '0'"; break; case 'approve': $status_clauses[] = "comment_approved = '1'"; break; case 'all': case '': $status_clauses[] = "( comment_approved = '0' OR comment_approved = '1' )"; break; default: $status_clauses[] = $hqdb->prepare("comment_approved = %s", $status); break; } } if (!empty($status_clauses)) { $approved_clauses[] = '( ' . implode(' OR ', $status_clauses) . ' )'; } } // User IDs or emails whose unapproved comments are included, regardless of $status. if (!empty($this->query_vars['include_unapproved'])) { $include_unapproved = $this->query_vars['include_unapproved']; // Accepts arrays or comma-separated strings. if (!is_array($include_unapproved)) { $include_unapproved = preg_split('/[\\s,]+/', $include_unapproved); } $unapproved_ids = $unapproved_emails = array(); foreach ($include_unapproved as $unapproved_identifier) { // Numeric values are assumed to be user ids. if (is_numeric($unapproved_identifier)) { $approved_clauses[] = $hqdb->prepare("( user_id = %d AND comment_approved = '0' )", $unapproved_identifier); // Otherwise we match against email addresses. } else { $approved_clauses[] = $hqdb->prepare("( comment_author_email = %s AND comment_approved = '0' )", $unapproved_identifier); } } } // Collapse comment_approved clauses into a single OR-separated clause. if (!empty($approved_clauses)) { if (1 === count($approved_clauses)) { $where[] = $approved_clauses[0]; } else { $where[] = '( ' . implode(' OR ', $approved_clauses) . ' )'; } } $order = 'ASC' == strtoupper($this->query_vars['order']) ? 'ASC' : 'DESC'; // Disable ORDER BY with 'none', an empty array, or boolean false. if (in_array($this->query_vars['orderby'], array('none', array(), false), true)) { $orderby = ''; } elseif (!empty($this->query_vars['orderby'])) { $ordersby = is_array($this->query_vars['orderby']) ? $this->query_vars['orderby'] : preg_split('/[,\\s]/', $this->query_vars['orderby']); $orderby_array = array(); $found_orderby_comment_ID = false; foreach ($ordersby as $_key => $_value) { if (!$_value) { continue; } if (is_int($_key)) { $_orderby = $_value; $_order = $order; } else { $_orderby = $_key; $_order = $_value; } if (!$found_orderby_comment_ID && 'comment_ID' === $_orderby) { $found_orderby_comment_ID = true; } $parsed = $this->parse_orderby($_orderby); if (!$parsed) { continue; } $orderby_array[] = $parsed . ' ' . $this->parse_order($_order); } // If no valid clauses were found, order by comment_date_gmt. if (empty($orderby_array)) { $orderby_array[] = "{$hqdb->comments}.comment_date_gmt {$order}"; } // To ensure determinate sorting, always include a comment_ID clause. if (!$found_orderby_comment_ID) { $comment_ID_order = ''; // Inherit order from comment_date or comment_date_gmt, if available. foreach ($orderby_array as $orderby_clause) { if (preg_match('/comment_date(?:_gmt)*\\ (ASC|DESC)/', $orderby_clause, $match)) { $comment_ID_order = $match[1]; break; } } // If no date-related order is available, use the date from the first available clause. if (!$comment_ID_order) { foreach ($orderby_array as $orderby_clause) { if (false !== strpos('ASC', $orderby_clause)) { $comment_ID_order = 'ASC'; } else { $comment_ID_order = 'DESC'; } break; } } // Default to DESC. if (!$comment_ID_order) { $comment_ID_order = 'DESC'; } $orderby_array[] = "{$hqdb->comments}.comment_ID {$comment_ID_order}"; } $orderby = implode(', ', $orderby_array); } else { $orderby = "{$hqdb->comments}.comment_date_gmt {$order}"; } $number = absint($this->query_vars['number']); $offset = absint($this->query_vars['offset']); if (!empty($number)) { if ($offset) { $limits = 'LIMIT ' . $offset . ',' . $number; } else { $limits = 'LIMIT ' . $number; } } else { $limits = ''; } if ($this->query_vars['count']) { $fields = 'COUNT(*)'; } else { switch (strtolower($this->query_vars['fields'])) { case 'ids': $fields = "{$hqdb->comments}.comment_ID"; break; default: $fields = "*"; break; } } $join = ''; $post_id = absint($this->query_vars['post_id']); if (!empty($post_id)) { $where[] = $hqdb->prepare('comment_post_ID = %d', $post_id); } // Parse comment IDs for an IN clause. if (!empty($this->query_vars['comment__in'])) { $where[] = "{$hqdb->comments}.comment_ID IN ( " . implode(',', hq_parse_id_list($this->query_vars['comment__in'])) . ' )'; } // Parse comment IDs for a NOT IN clause. if (!empty($this->query_vars['comment__not_in'])) { $where[] = "{$hqdb->comments}.comment_ID NOT IN ( " . implode(',', hq_parse_id_list($this->query_vars['comment__not_in'])) . ' )'; } // Parse comment post IDs for an IN clause. if (!empty($this->query_vars['post__in'])) { $where[] = 'comment_post_ID IN ( ' . implode(',', hq_parse_id_list($this->query_vars['post__in'])) . ' )'; } // Parse comment post IDs for a NOT IN clause. if (!empty($this->query_vars['post__not_in'])) { $where[] = 'comment_post_ID NOT IN ( ' . implode(',', hq_parse_id_list($this->query_vars['post__not_in'])) . ' )'; } if ('' !== $this->query_vars['author_email']) { $where[] = $hqdb->prepare('comment_author_email = %s', $this->query_vars['author_email']); } if ('' !== $this->query_vars['karma']) { $where[] = $hqdb->prepare('comment_karma = %d', $this->query_vars['karma']); } // Filtering by comment_type: 'type', 'type__in', 'type__not_in'. $raw_types = array('IN' => array_merge((array) $this->query_vars['type'], (array) $this->query_vars['type__in']), 'NOT IN' => (array) $this->query_vars['type__not_in']); $comment_types = array(); foreach ($raw_types as $operator => $_raw_types) { $_raw_types = array_unique($_raw_types); foreach ($_raw_types as $type) { switch ($type) { // An empty translates to 'all', for backward compatibility case '': case 'all': break; case 'comment': case 'comments': $comment_types[$operator][] = "''"; break; case 'pings': $comment_types[$operator][] = "'pingback'"; $comment_types[$operator][] = "'trackback'"; break; default: $comment_types[$operator][] = $hqdb->prepare('%s', $type); break; } } if (!empty($comment_types[$operator])) { $types_sql = implode(', ', $comment_types[$operator]); $where[] = "comment_type {$operator} ({$types_sql})"; } } if ('' !== $this->query_vars['parent']) { $where[] = $hqdb->prepare('comment_parent = %d', $this->query_vars['parent']); } if (is_array($this->query_vars['user_id'])) { $where[] = 'user_id IN (' . implode(',', array_map('absint', $this->query_vars['user_id'])) . ')'; } elseif ('' !== $this->query_vars['user_id']) { $where[] = $hqdb->prepare('user_id = %d', $this->query_vars['user_id']); } if ('' !== $this->query_vars['search']) { $search_sql = $this->get_search_sql($this->query_vars['search'], array('comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_content')); // Strip leading 'AND'. $where[] = preg_replace('/^\\s*AND\\s*/', '', $search_sql); } // If any post-related query vars are passed, join the posts table. $join_posts_table = false; $plucked = hq_array_slice_assoc($this->query_vars, array('post_author', 'post_name', 'post_parent', 'post_status', 'post_type')); $post_fields = array_filter($plucked); if (!empty($post_fields)) { $join_posts_table = true; foreach ($post_fields as $field_name => $field_value) { // $field_value may be an array. $esses = array_fill(0, count((array) $field_value), '%s'); $where[] = $hqdb->prepare(" {$hqdb->posts}.{$field_name} IN (" . implode(',', $esses) . ')', $field_value); } } // Comment author IDs for an IN clause. if (!empty($this->query_vars['author__in'])) { $where[] = 'user_id IN ( ' . implode(',', hq_parse_id_list($this->query_vars['author__in'])) . ' )'; } // Comment author IDs for a NOT IN clause. if (!empty($this->query_vars['author__not_in'])) { $where[] = 'user_id NOT IN ( ' . implode(',', hq_parse_id_list($this->query_vars['author__not_in'])) . ' )'; } // Post author IDs for an IN clause. if (!empty($this->query_vars['post_author__in'])) { $join_posts_table = true; $where[] = 'post_author IN ( ' . implode(',', hq_parse_id_list($this->query_vars['post_author__in'])) . ' )'; } // Post author IDs for a NOT IN clause. if (!empty($this->query_vars['post_author__not_in'])) { $join_posts_table = true; $where[] = 'post_author NOT IN ( ' . implode(',', hq_parse_id_list($this->query_vars['post_author__not_in'])) . ' )'; } if ($join_posts_table) { $join = "JOIN {$hqdb->posts} ON {$hqdb->posts}.ID = {$hqdb->comments}.comment_post_ID"; } if (!empty($meta_query_clauses)) { $join .= $meta_query_clauses['join']; // Strip leading 'AND'. $where[] = preg_replace('/^\\s*AND\\s*/', '', $meta_query_clauses['where']); if (!$this->query_vars['count']) { $groupby = "{$hqdb->comments}.comment_ID"; } } $date_query = $this->query_vars['date_query']; if (!empty($date_query) && is_array($date_query)) { $date_query_object = new HQ_Date_Query($date_query, 'comment_date'); $where[] = preg_replace('/^\\s*AND\\s*/', '', $date_query_object->get_sql()); } $where = implode(' AND ', $where); $pieces = array('fields', 'join', 'where', 'orderby', 'limits', 'groupby'); /** * Filter the comment query clauses. * * @since 0.0.1 * * @param array $pieces A compacted array of comment query clauses. * @param HQ_Comment_Query &$this Current instance of HQ_Comment_Query, passed by reference. */ $clauses = apply_filters_ref_array('comments_clauses', array(compact($pieces), &$this)); $fields = isset($clauses['fields']) ? $clauses['fields'] : ''; $join = isset($clauses['join']) ? $clauses['join'] : ''; $where = isset($clauses['where']) ? $clauses['where'] : ''; $orderby = isset($clauses['orderby']) ? $clauses['orderby'] : ''; $limits = isset($clauses['limits']) ? $clauses['limits'] : ''; $groupby = isset($clauses['groupby']) ? $clauses['groupby'] : ''; if ($where) { $where = 'WHERE ' . $where; } if ($groupby) { $groupby = 'GROUP BY ' . $groupby; } if ($orderby) { $orderby = "ORDER BY {$orderby}"; } $this->request = "SELECT {$fields} FROM {$hqdb->comments} {$join} {$where} {$groupby} {$orderby} {$limits}"; if ($this->query_vars['count']) { return $hqdb->get_var($this->request); } if ('ids' == $this->query_vars['fields']) { $this->comments = $hqdb->get_col($this->request); return array_map('intval', $this->comments); } $results = $hqdb->get_results($this->request); /** * Filter the comment query results. * * @since 0.0.1 * * @param array $results An array of comments. * @param HQ_Comment_Query &$this Current instance of HQ_Comment_Query, passed by reference. */ $comments = apply_filters_ref_array('the_comments', array($results, &$this)); hq_cache_add($cache_key, $comments, 'comment'); if ('*' === $fields) { update_comment_cache($comments); } $this->comments = $comments; return $this->comments; }
/** * Loads the comment template specified in $file. * * Will not display the comments template if not on single post or page, or if * the post does not have comments. * * Uses the WordPress database object to query for the comments. The comments * are passed through the 'comments_array' filter hook with the list of comments * and the post ID respectively. * * The $file path is passed through a filter hook called, 'comments_template' * which includes the TEMPLATEPATH and $file combined. Tries the $filtered path * first and if it fails it will require the default comment themplate from the * default theme. If either does not exist, then the WordPress process will be * halted. It is advised for that reason, that the default theme is not deleted. * * @since 1.5.0 * @global array $comment List of comment objects for the current post * @uses $wpdb * @uses $id * @uses $post * @uses $withcomments Will not try to get the comments if the post has none. * * @param string $file Optional, default '/comments.php'. The file to load * @param bool $separate_comments Optional, whether to separate the comments by comment type. Default is false. * @return null Returns null if no comments appear */ function comments_template($file = '/comments.php', $separate_comments = false) { global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity, $overridden_cpage; if (!(is_single() || is_page() || $withcomments)) { return; } if (empty($file)) { $file = '/comments.php'; } $req = get_option('require_name_email'); /** * Comment author information fetched from the comment cookies. * * @uses wp_get_current_commenter() */ $commenter = wp_get_current_commenter(); /** * The name of the current comment author escaped for use in attributes. */ $comment_author = $commenter['comment_author']; // Escaped by sanitize_comment_cookies() /** * The email address of the current comment author escaped for use in attributes. */ $comment_author_email = $commenter['comment_author_email']; // Escaped by sanitize_comment_cookies() /** * The url of the current comment author escaped for use in attributes. */ $comment_author_url = esc_url($commenter['comment_author_url']); /** @todo Use API instead of SELECTs. */ if ($user_ID) { $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", $post->ID, $user_ID)); } else { if (empty($comment_author)) { $comments = get_comments(array('post_id' => $post->ID, 'status' => 'approve', 'order' => 'ASC')); } else { $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", $post->ID, wp_specialchars_decode($comment_author, ENT_QUOTES), $comment_author_email)); } } // keep $comments for legacy's sake $wp_query->comments = apply_filters('comments_array', $comments, $post->ID); $comments =& $wp_query->comments; $wp_query->comment_count = count($wp_query->comments); update_comment_cache($wp_query->comments); if ($separate_comments) { $wp_query->comments_by_type =& separate_comments($comments); $comments_by_type =& $wp_query->comments_by_type; } $overridden_cpage = FALSE; if ('' == get_query_var('cpage') && get_option('page_comments')) { set_query_var('cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1); $overridden_cpage = TRUE; } if (!defined('COMMENTS_TEMPLATE') || !COMMENTS_TEMPLATE) { define('COMMENTS_TEMPLATE', true); } $include = apply_filters('comments_template', STYLESHEETPATH . $file); if (file_exists($include)) { require $include; } elseif (file_exists(TEMPLATEPATH . $file)) { require TEMPLATEPATH . $file; } else { require get_theme_root() . '/default/comments.php'; } }
function _wap_get_comment_list($s = false, $start, $num, $view_all = false) { global $wpdb; $start = abs((int) $start); $num = (int) $num; if ($view_all) { $comments = $wpdb->get_results("SELECT SQL_CALC_FOUND_ROWS * FROM {$wpdb->comments} WHERE comment_approved = '0' OR comment_approved = '1' ORDER BY comment_date DESC LIMIT {$start}, {$num}"); } else { $comments = $wpdb->get_results("SELECT SQL_CALC_FOUND_ROWS * FROM {$wpdb->comments} WHERE comment_approved = '0' ORDER BY comment_date DESC LIMIT {$start}, {$num}"); } update_comment_cache($comments); $total = $wpdb->get_var("SELECT FOUND_ROWS()"); return array($comments, $total); }
/** * Load the comment template specified in $file. * * Will not display the comments template if not on single post or page, or if * the post does not have comments. * * Uses the WordPress database object to query for the comments. The comments * are passed through the 'comments_array' filter hook with the list of comments * and the post ID respectively. * * The $file path is passed through a filter hook called, 'comments_template' * which includes the TEMPLATEPATH and $file combined. Tries the $filtered path * first and if it fails it will require the default comment template from the * default theme. If either does not exist, then the WordPress process will be * halted. It is advised for that reason, that the default theme is not deleted. * * @todo Document globals * @uses $withcomments Will not try to get the comments if the post has none. * * @since 1.5.0 * * @param string $file Optional. The file to load. Default '/comments.php'. * @param bool $separate_comments Optional. Whether to separate the comments by comment type. Default false. * @return null Returns null if no comments appear. */ function comments_template($file = '/comments.php', $separate_comments = false) { global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity, $overridden_cpage; if (!(is_single() || is_page() || $withcomments) || empty($post)) { return; } if (empty($file)) { $file = '/comments.php'; } $req = get_option('require_name_email'); /** * Comment author information fetched from the comment cookies. * * @uses wp_get_current_commenter() */ $commenter = wp_get_current_commenter(); /** * The name of the current comment author escaped for use in attributes. */ $comment_author = $commenter['comment_author']; // Escaped by sanitize_comment_cookies() /** * The email address of the current comment author escaped for use in attributes. */ $comment_author_email = $commenter['comment_author_email']; // Escaped by sanitize_comment_cookies() /** * The url of the current comment author escaped for use in attributes. */ $comment_author_url = esc_url($commenter['comment_author_url']); /** @todo Use API instead of SELECTs. */ if ($user_ID) { $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", $post->ID, $user_ID)); } else { if (empty($comment_author)) { $comments = get_comments(array('post_id' => $post->ID, 'status' => 'approve', 'order' => 'ASC')); } else { $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", $post->ID, wp_specialchars_decode($comment_author, ENT_QUOTES), $comment_author_email)); } } // keep $comments for legacy's sake /** * Filter the comments array. * * @since 2.1.0 * * @param array $comments The array of comments supplied to the comments template. * @param int $post->ID The post ID. */ $wp_query->comments = apply_filters('comments_array', $comments, $post->ID); $comments =& $wp_query->comments; $wp_query->comment_count = count($wp_query->comments); update_comment_cache($wp_query->comments); if ($separate_comments) { $wp_query->comments_by_type = separate_comments($comments); $comments_by_type =& $wp_query->comments_by_type; } $overridden_cpage = false; if ('' == get_query_var('cpage') && get_option('page_comments')) { set_query_var('cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1); $overridden_cpage = true; } if (!defined('COMMENTS_TEMPLATE')) { define('COMMENTS_TEMPLATE', true); } $theme_template = STYLESHEETPATH . $file; /** * Filter the path to the theme template file used for the comments template. * * @since 1.5.2 * * @param string $theme_template The path to the theme template file. */ $include = apply_filters('comments_template', $theme_template); if (file_exists($include)) { require $include; } elseif (file_exists(TEMPLATEPATH . $file)) { require TEMPLATEPATH . $file; } else { // Backward compat code will be removed in a future release require ABSPATH . WPINC . '/theme-compat/comments.php'; } }
/** * {@internal Missing Short Description}} * * @since unknown * * @param unknown_type $status * @param unknown_type $s * @param unknown_type $start * @param unknown_type $num * @param unknown_type $post * @param unknown_type $type * @return unknown */ function _wp_get_comment_list( $status = '', $s = false, $start, $num, $post = 0, $type = '' ) { global $wpdb; $start = abs( (int) $start ); $num = (int) $num; $post = (int) $post; $count = wp_count_comments(); $index = ''; if ( 'moderated' == $status ) { $approved = "comment_approved = '0'"; $total = $count->moderated; } elseif ( 'approved' == $status ) { $approved = "comment_approved = '1'"; $total = $count->approved; } elseif ( 'spam' == $status ) { $approved = "comment_approved = 'spam'"; $total = $count->spam; } else { $approved = "( comment_approved = '0' OR comment_approved = '1' )"; $total = $count->moderated + $count->approved; $index = 'USE INDEX (comment_date_gmt)'; } if ( $post ) { $total = ''; $post = " AND comment_post_ID = '$post'"; $orderby = "ORDER BY comment_date_gmt ASC LIMIT $start, $num"; } else { $post = ''; $orderby = "ORDER BY comment_date_gmt DESC LIMIT $start, $num"; } if ( 'comment' == $type ) $typesql = "AND comment_type = ''"; elseif ( 'pingback' == $type ) $typesql = "AND comment_type = 'pingback'"; elseif ( 'trackback' == $type ) $typesql = "AND comment_type = 'trackback'"; elseif ( 'pings' == $type ) $typesql = "AND ( comment_type = 'pingback' OR comment_type = 'trackback' )"; else $typesql = ''; if ( !empty($type) ) $total = ''; if ( $s ) { $total = ''; $s = $wpdb->escape($s); $query = "FROM $wpdb->comments WHERE (comment_author LIKE '%$s%' OR comment_author_email LIKE '%$s%' OR comment_author_url LIKE ('%$s%') OR comment_author_IP LIKE ('%$s%') OR comment_content LIKE ('%$s%') ) AND $approved $typesql"; } else { $query = "FROM $wpdb->comments $index WHERE $approved $post $typesql"; } $comments = $wpdb->get_results("SELECT * $query $orderby"); if ( '' === $total ) $total = $wpdb->get_var("SELECT COUNT(comment_ID) $query"); update_comment_cache($comments); return array($comments, $total); }
/** * LazyestCommentor::edit_comments() * * @param mixed $filevar * @return void */ function edit_comments($filevar) { global $lg_gallery; switch ($this->comments_from) { case 'folder': $folder = new LazyestFolder($filevar); $folder->open(); $comments = $this->get_comments($folder->id); $caption = $folder->caption; break; case 'image': $folder = new LazyestFolder(dirname($filevar)); $folder->load('images'); $image = $folder->single_image(basename($filevar)); $comments = $this->get_comments($image->id); $caption = $image->caption; break; case 'gallery': $comments = $this->get_root_comments(); $page_id = $lg_gallery->get_option('gallery_id'); $gallery_page = get_post($page_id); $caption = $gallery_page->post_title; break; case 'all': default: $page_id = (int) $lg_gallery->get_option('gallery_id'); $comments = $this->get_approved_comments($page_id); $gallery_page = get_post($page_id); $caption = $gallery_page->post_title; break; } $do_pagination = false; if ($comments) { update_comment_cache($comments); $comments = array_reverse($comments); $comments_table = new LazyestCommentsTable($comments); $perpage = 20; $total_pages = ceil(count($comments) / $perpage); $query_var = 'lg_paged'; if (isset($paged)) { $current = $paged; } else { $current = isset($_REQUEST[$query_var]) ? absint($_REQUEST[$query_var]) : 0; $current = min(max(1, $current), $total_pages); } $start = ($current - 1) * $perpage + 1; $end = min(count($comments), $current * $perpage); $do_pagination = 1 < $total_pages; if ($do_pagination) { $pagination = $lg_gallery->pagination('comments', $comments); ?> <div class="tablenav"><?php echo $pagination; ?> </div> <?php } ?> <br class="clear" /> <?php $comments_table->display(); ?> <?php } if ($do_pagination) { ?> <div class="tablenav"><?php echo $pagination; ?> </div> <?php } if (isset($folder)) { unset($folder); } unset($comments_table); }
/** * Replicates the core comments_template function, but uses the API * to fetch the comments and includes more filters. * * Loads the comment template specified in $file. * * Will not display the comments template if not on single post or page, or if * the post does not have comments. * * Uses the WordPress database object to query for the comments. The comments * are passed through the 'comments_array' filter hook with the list of comments * and the post ID respectively. * * The $file path is passed through a filter hook called, 'comments_template' * which includes the TEMPLATEPATH and $file combined. Tries the $filtered path * first and if it fails it will require the default comment template from the * default theme. If either does not exist, then the WordPress process will be * halted. It is advised for that reason, that the default theme is not deleted. * * @since 1.5.0 * @global array $comment List of comment objects for the current post * @uses $wpdb * @uses $post * @uses $withcomments Will not try to get the comments if the post has none. * * @see comments_template() * * @param string $file Optional, default '/comments.php'. The file to load * @param bool $separate_comments Optional, whether to separate the comments by comment type. Default is false. * @return null Returns null if no comments appear */ function bbl_comments_template($file = '/comments.php', $separate_comments = false) { global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity, $overridden_cpage; if (!(is_single() || is_page() || $withcomments) || empty($post)) { return; } if (empty($file)) { $file = '/comments.php'; } $req = get_option('require_name_email'); /** * Comment author information fetched from the comment cookies. * * @uses wp_get_current_commenter() */ $commenter = wp_get_current_commenter(); /** * The name of the current comment author escaped for use in attributes. */ $comment_author = $commenter['comment_author']; // Escaped by sanitize_comment_cookies() /** * The email address of the current comment author escaped for use in attributes. */ $comment_author_email = $commenter['comment_author_email']; // Escaped by sanitize_comment_cookies() /** * The url of the current comment author escaped for use in attributes. */ $comment_author_url = esc_url($commenter['comment_author_url']); $query = new Bbl_Comment_Query(); $args = array('order' => 'ASC', 'post_id' => $post->ID, 'status' => 'approve', 'status' => 'approve'); if ($user_ID) { $args['unapproved_user_id'] = $user_ID; } else { if (!empty($comment_author)) { $args['unapproved_author'] = wp_specialchars_decode($comment_author, ENT_QUOTES); $args['unapproved_author_email'] = $comment_author_email; } } $args = apply_filters('comments_template_args', $args); $comments = $query->query($args); // keep $comments for legacy's sake $wp_query->comments = apply_filters('comments_array', $comments, $post->ID); $comments =& $wp_query->comments; $wp_query->comment_count = count($wp_query->comments); update_comment_cache($wp_query->comments); if ($separate_comments) { $wp_query->comments_by_type =& separate_comments($comments); $comments_by_type =& $wp_query->comments_by_type; } $overridden_cpage = FALSE; if ('' == get_query_var('cpage') && get_option('page_comments')) { set_query_var('cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1); $overridden_cpage = TRUE; } if (!defined('COMMENTS_TEMPLATE') || !COMMENTS_TEMPLATE) { define('COMMENTS_TEMPLATE', true); } $include = apply_filters('comments_template', trailingslashit(get_stylesheet_directory()) . sanitize_file_name($file)); if (file_exists($include)) { require $include; } elseif (file_exists(trailingslashit(get_template_directory()) . sanitize_file_name($file))) { require trailingslashit(get_template_directory()) . sanitize_file_name($file); } else { // Backward compat code will be removed in a future release require ABSPATH . WPINC . '/theme-compat/comments.php'; } }
function prepare_items() { global $post_id, $comment_status, $search; $post_id = isset($_REQUEST['p']) ? absint($_REQUEST['p']) : 0; $comment_status = isset($_REQUEST['comment_status']) ? $_REQUEST['comment_status'] : 'all'; if (!in_array($comment_status, array('all', 'moderated', 'approved', 'spam', 'trash'))) { $comment_status = 'all'; } $comment_type = !empty($_REQUEST['comment_type']) ? $_REQUEST['comment_type'] : ''; $search = isset($_REQUEST['s']) ? $_REQUEST['s'] : ''; if (isset($_POST['per_page'])) { $comments_per_page = $_POST['per_page']; } else { $comments_per_page = (int) get_user_option('edit_comments_per_page'); } if (empty($comments_per_page) || $comments_per_page < 1) { $comments_per_page = 20; } $comments_per_page = apply_filters('comments_per_page', $comments_per_page, $comment_status); if (isset($_POST['number'])) { $number = (int) $_POST['number']; } else { $number = $comments_per_page + min(8, $comments_per_page); } // Grab a few extra $page = $this->get_pagenum(); $start = $offset = ($page - 1) * $comments_per_page; $args = array('status' => 'moderated' == $comment_status ? 'hold' : $comment_status, 'search' => $search, 'offset' => $start, 'number' => $number, 'post_id' => $post_id, 'type' => $comment_type, 'orderby' => @$_REQUEST['orderby'], 'order' => @$_REQUEST['order']); $_comments = get_comments($args); update_comment_cache($_comments); $this->items = array_slice($_comments, 0, $comments_per_page); $this->extra_items = array_slice($_comments, $comments_per_page); $total_comments = get_comments(array_merge($args, array('count' => true, 'offset' => 0, 'number' => 0))); $_comment_post_ids = array(); foreach ($_comments as $_c) { $_comment_post_ids[] = $_c->comment_post_ID; } $_comment_pending_count = get_pending_comments_num($_comment_post_ids); $this->set_pagination_args(array('total_items' => $total_comments, 'per_page' => $comments_per_page)); }
function _wp_get_comment_list($s = false, $start, $num) { global $wpdb; $start = abs((int) $start); $num = (int) $num; if ($s) { $s = $wpdb->escape($s); $comments = $wpdb->get_results("SELECT SQL_CALC_FOUND_ROWS * FROM {$wpdb->comments} WHERE\n\t\t\t(comment_author LIKE '%{$s}%' OR\n\t\t\tcomment_author_email LIKE '%{$s}%' OR\n\t\t\tcomment_author_url LIKE ('%{$s}%') OR\n\t\t\tcomment_author_IP LIKE ('%{$s}%') OR\n\t\t\tcomment_content LIKE ('%{$s}%') ) AND\n\t\t\tcomment_approved != 'spam'\n\t\t\tORDER BY comment_date DESC LIMIT {$start}, {$num}"); } else { $comments = $wpdb->get_results("SELECT SQL_CALC_FOUND_ROWS * FROM {$wpdb->comments} WHERE comment_approved = '0' OR comment_approved = '1' ORDER BY comment_date DESC LIMIT {$start}, {$num}"); } update_comment_cache($comments); $total = $wpdb->get_var("SELECT FOUND_ROWS()"); return array($comments, $total); }
/** * Loads the comment template specified in $file. * * Will not display the comments template if not on single post or page, or if * the post does not have comments. * * Uses the WordPress database object to query for the comments. The comments * are passed through the 'comments_array' filter hook with the list of comments * and the post ID respectively. * * The $file path is passed through a filter hook called, 'comments_template' * which includes the TEMPLATEPATH and $file combined. Tries the $filtered path * first and if it fails it will require the default comment template from the * default theme. If either does not exist, then the WordPress process will be * halted. It is advised for that reason, that the default theme is not deleted. * * @since 1.5.0 * @global array $comment List of comment objects for the current post * @uses $wpdb * @uses $post * @uses $withcomments Will not try to get the comments if the post has none. * * @param string $file Optional, default '/comments.php'. The file to load * @param bool $separate_comments Optional, whether to separate the comments by comment type. Default is false. * @return null Returns null if no comments appear */ function comments_template($file = '/comments.php', $separate_comments = false) { global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity, $overridden_cpage; if (!(is_single() || is_page() || $withcomments) || empty($post)) { return; } if (empty($file)) { $file = '/comments.php'; } $req = get_option('require_name_email'); /** * Comment author information fetched from the comment cookies. * * @uses wp_get_current_commenter() */ $commenter = wp_get_current_commenter(); /** * The name of the current comment author escaped for use in attributes. */ $comment_author = $commenter['comment_author']; // Escaped by sanitize_comment_cookies() /** * The email address of the current comment author escaped for use in attributes. */ $comment_author_email = $commenter['comment_author_email']; // Escaped by sanitize_comment_cookies() /** * The url of the current comment author escaped for use in attributes. */ $comment_author_url = esc_url($commenter['comment_author_url']); /** @todo Use API instead of SELECTs. */ #echo "HERE!! - UID: $user_ID "; if ($user_ID or $user_ID == 0) { // show only one language if logged in (ToDo: allow selection of languages instead) // or if not logged in (important for search engine localization #echo "DONE!"; // comment_id FROM $wpdb->commentmeta WHERE meta_key = 'rating-id' AND meta_value = $ratingid //$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", $post->ID, $user_ID)); $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", $post->ID, $user_ID)); //print_r($comments); global $lang; global $region; $a_size = sizeof($comments); #echo "<br>size: $a_size <br>"; #echo "LANG: $lang<br>"; #echo "Reg: $region<br>"; $j = 0; for ($i = 0; $i < $a_size; $i++) { $cid = $comments[$i]->comment_ID; //echo "CID:".$cid; $clang = get_comment_meta($cid, 'language', true); //echo "Lang: $clang"."<br>"; $check = lhg_show_language($clang, $region); //echo "CHK: $check<br>"; if ($check == 1) { $comments_temp[$j] = $comments[$i]; $j++; } } //overwrited with filtered version $comments = $comments_temp; } else { if (empty($comment_author)) { #echo "empty"; $comments = get_comments(array('post_id' => $post->ID, 'status' => 'approve', 'order' => 'ASC')); } else { #echo "not logged in"; $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", $post->ID, wp_specialchars_decode($comment_author, ENT_QUOTES), $comment_author_email)); } } // keep $comments for legacy's sake $wp_query->comments = apply_filters('comments_array', $comments, $post->ID); $comments =& $wp_query->comments; $wp_query->comment_count = count($wp_query->comments); update_comment_cache($wp_query->comments); if ($separate_comments) { $wp_query->comments_by_type =& separate_comments($comments); $comments_by_type =& $wp_query->comments_by_type; } $overridden_cpage = FALSE; if ('' == get_query_var('cpage') && get_option('page_comments')) { set_query_var('cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1); $overridden_cpage = TRUE; } if (!defined('COMMENTS_TEMPLATE') || !COMMENTS_TEMPLATE) { define('COMMENTS_TEMPLATE', true); } $include = apply_filters('comments_template', STYLESHEETPATH . $file); if (file_exists($include)) { require $include; } elseif (file_exists(TEMPLATEPATH . $file)) { require TEMPLATEPATH . $file; } else { // Backward compat code will be removed in a future release require ABSPATH . WPINC . '/theme-compat/comments.php'; } }
/** * Load the comment template specified in $file. * * Will not display the comments template if not on single post or page, or if * the post does not have comments. * * Uses the WordPress database object to query for the comments. The comments * are passed through the 'comments_array' filter hook with the list of comments * and the post ID respectively. * * The $file path is passed through a filter hook called, 'comments_template' * which includes the TEMPLATEPATH and $file combined. Tries the $filtered path * first and if it fails it will require the default comment template from the * default theme. If either does not exist, then the WordPress process will be * halted. It is advised for that reason, that the default theme is not deleted. * * @todo Document globals * @uses $withcomments Will not try to get the comments if the post has none. * * @since 1.5.0 * * @param string $file Optional. The file to load. Default '/comments.php'. * @param bool $separate_comments Optional. Whether to separate the comments by comment type. * Default false. * @return null Returns null if no comments appear. */ function comments_template($file = '/comments.php', $separate_comments = false) { global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity, $overridden_cpage; if (!(is_single() || is_page() || $withcomments) || empty($post)) { return; } if (empty($file)) { $file = '/comments.php'; } $req = get_option('require_name_email'); /* * Comment author information fetched from the comment cookies. */ $commenter = wp_get_current_commenter(); /* * The name of the current comment author escaped for use in attributes. * Escaped by sanitize_comment_cookies(). */ $comment_author = $commenter['comment_author']; /* * The email address of the current comment author escaped for use in attributes. * Escaped by sanitize_comment_cookies(). */ $comment_author_email = $commenter['comment_author_email']; /* * The url of the current comment author escaped for use in attributes. */ $comment_author_url = esc_url($commenter['comment_author_url']); $comment_args = array('order' => 'ASC', 'orderby' => 'comment_date_gmt', 'status' => 'approve', 'post_id' => $post->ID); if ($user_ID) { $comment_args['include_unapproved'] = array($user_ID); } elseif (!empty($comment_author_email)) { $comment_args['include_unapproved'] = array($comment_author_email); } $comments = get_comments($comment_args); /** * Filter the comments array. * * @since 2.1.0 * * @param array $comments Array of comments supplied to the comments template. * @param int $post_ID Post ID. */ $wp_query->comments = apply_filters('comments_array', $comments, $post->ID); $comments =& $wp_query->comments; $wp_query->comment_count = count($wp_query->comments); update_comment_cache($wp_query->comments); if ($separate_comments) { $wp_query->comments_by_type = separate_comments($comments); $comments_by_type =& $wp_query->comments_by_type; } $overridden_cpage = false; if ('' == get_query_var('cpage') && get_option('page_comments')) { set_query_var('cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1); $overridden_cpage = true; } if (!defined('COMMENTS_TEMPLATE')) { define('COMMENTS_TEMPLATE', true); } $theme_template = STYLESHEETPATH . $file; /** * Filter the path to the theme template file used for the comments template. * * @since 1.5.1 * * @param string $theme_template The path to the theme template file. */ $include = apply_filters('comments_template', $theme_template); if (file_exists($include)) { require $include; } elseif (file_exists(TEMPLATEPATH . $file)) { require TEMPLATEPATH . $file; } else { // Backward compat code will be removed in a future release require ABSPATH . WPINC . '/theme-compat/comments.php'; } }
/** * Gets comments * @return array of WpLatteCommentEntity entities */ protected function getComments() { // copy&paste from comments_template() function global $wp_query, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity, $overridden_cpage; //if (!(is_single() || is_page())) // return; $req = get_option('require_name_email'); $commenter = wp_get_current_commenter(); $comment_author = $commenter['comment_author']; // Escaped by sanitize_comment_cookies() $comment_author_email = $commenter['comment_author_email']; // Escaped by sanitize_comment_cookies() $comment_author_url = esc_url($commenter['comment_author_url']); if ($user_ID) { $comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->comments}\r\n\t\t\t\tWHERE\r\n\t\t\t\t\tcomment_post_ID = %d AND (comment_approved = '1' OR (user_id = %d AND comment_approved = '0'))\r\n\t\t\t\tORDER BY\r\n\t\t\t\t\tcomment_date_gmt", $this->id, $user_ID)); } elseif (empty($comment_author)) { $comments = get_comments(array('post_id' => $post->ID, 'status' => 'approve', 'order' => 'ASC')); } else { $comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->comments}\r\n\t\t\tWHERE\r\n\t\t\t\tcomment_post_ID = %d AND (comment_approved = '1' OR (comment_author = %s AND comment_author_email = %s AND comment_approved = '0'))\r\n\t\t\tORDER BY\r\n\t\t\t\tcomment_date_gmt", $post->ID, wp_specialchars_decode($comment_author, ENT_QUOTES), $comment_author_email)); } $wp_query->comments = apply_filters('comments_array', $comments, $post->ID); $comments =& $wp_query->comments; $wp_query->comment_count = count($wp_query->comments); update_comment_cache($wp_query->comments); $separate_comments = false; // $separate_comments Optional, whether to separate the comments by comment type. Default is false. if ($separate_comments) { $wp_query->comments_by_type =& separate_comments($comments); $comments_by_type =& $wp_query->comments_by_type; } $overridden_cpage = FALSE; if (get_query_var('cpage') == '' && get_option('page_comments')) { set_query_var('cpage', get_option('default_comments_page') == 'newest' ? get_comment_pages_count() : 1); $overridden_cpage = TRUE; } // end of copy&paste code wp_list_comments(array('callback' => 'WpLattePostEntity::createCommentEntity', 'walker' => new WpLatteCommentWalker())); $this->comments = self::$commentEntities; self::$commentEntities = array(); // unset return $this->comments; }
/** * comments_template() - Loads the comment template specified in $file * * Will not display the comments template if not on single post or page, or * if the post does not have comments. * * Uses the WordPress database object to query for the comments. The comments * are passed through the 'comments_array' filter hook with the list of comments * and the post ID respectively. * * The $file path is passed through a filter hook called, 'comments_template' * which includes the TEMPLATEPATH and $file combined. Tries the $filtered path * first and if it fails it will require the default comment themplate from the * default theme. If either does not exist, then the WordPress process will be * halted. It is advised for that reason, that the default theme is not deleted. * * @since 1.5 * @global array $comment List of comment objects for the current post * @uses $wpdb * @uses $id * @uses $post * @uses $withcomments Will not try to get the comments if the post has none. * * @param string $file Optional, default '/comments.php'. The file to load * @return null Returns null if no comments appear */ function comments_template($file = '/comments.php') { global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity; if (!(is_single() || is_page() || $withcomments)) { return; } $req = get_option('require_name_email'); $commenter = wp_get_current_commenter(); extract($commenter, EXTR_SKIP); /** @todo Use API instead of SELECTs. */ if ($user_ID) { $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)); } else { if (empty($comment_author)) { $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)); } else { $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)); } } // keep $comments for legacy's sake (remember $table*? ;) ) $comments = $wp_query->comments = apply_filters('comments_array', $comments, $post->ID); $wp_query->comment_count = count($wp_query->comments); update_comment_cache($comments); define('COMMENTS_TEMPLATE', true); $include = apply_filters('comments_template', TEMPLATEPATH . $file); if (file_exists($include)) { require $include; } else { require ABSPATH . 'wp-content/themes/default/comments.php'; } }
/** * {@internal Missing Short Description}} * * @since unknown * * @param string $status Comment status (approved, spam, trash, etc) * @param string $s Term to search for * @param int $start Offset to start at for pagination * @param int $num Maximum number of comments to return * @param int $post Post ID or 0 to return all comments * @param string $type Comment type (comment, trackback, pingback, etc) * @return array [0] contains the comments and [1] contains the total number of comments that match (ignoring $start and $num) */ function _wp_get_comment_list($status = '', $s = false, $start, $num, $post = 0, $type = '') { global $wpdb; $start = abs((int) $start); $num = (int) $num; $post = (int) $post; $count = wp_count_comments(); $index = ''; if ('moderated' == $status) { $approved = "c.comment_approved = '0'"; $total = $count->moderated; } elseif ('approved' == $status) { $approved = "c.comment_approved = '1'"; $total = $count->approved; } elseif ('spam' == $status) { $approved = "c.comment_approved = 'spam'"; $total = $count->spam; } elseif ('trash' == $status) { $approved = "c.comment_approved = 'trash'"; $total = $count->trash; } else { $approved = "( c.comment_approved = '0' OR c.comment_approved = '1' )"; $total = $count->moderated + $count->approved; $index = 'USE INDEX (c.comment_date_gmt)'; } if ($post) { $total = ''; $post = " AND c.comment_post_ID = '{$post}'"; } else { $post = ''; } $orderby = "ORDER BY c.comment_date_gmt DESC LIMIT {$start}, {$num}"; if ('comment' == $type) { $typesql = "AND c.comment_type = ''"; } elseif ('pings' == $type) { $typesql = "AND ( c.comment_type = 'pingback' OR c.comment_type = 'trackback' )"; } elseif (!empty($type)) { $typesql = $wpdb->prepare("AND c.comment_type = %s", $type); } else { $typesql = ''; } if (!empty($type)) { $total = ''; } $query = "FROM {$wpdb->comments} c LEFT JOIN {$wpdb->posts} p ON c.comment_post_ID = p.ID WHERE p.post_status != 'trash' "; if ($s) { $total = ''; $s = $wpdb->escape($s); $query .= "AND\n\t\t\t(c.comment_author LIKE '%{$s}%' OR\n\t\t\tc.comment_author_email LIKE '%{$s}%' OR\n\t\t\tc.comment_author_url LIKE ('%{$s}%') OR\n\t\t\tc.comment_author_IP LIKE ('%{$s}%') OR\n\t\t\tc.comment_content LIKE ('%{$s}%') ) AND\n\t\t\t{$approved}\n\t\t\t{$typesql}"; } else { $query .= "AND {$approved} {$post} {$typesql}"; } $comments = $wpdb->get_results("SELECT * {$query} {$orderby}"); if ('' === $total) { $total = $wpdb->get_var("SELECT COUNT(c.comment_ID) {$query}"); } update_comment_cache($comments); return array($comments, $total); }
</form> <?php inline_edit_row('page'); ?> <div id="ajax-response"></div> <?php if (1 == count($posts) && is_singular()) { $comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->comments} WHERE comment_post_ID = %d AND comment_approved != 'spam' ORDER BY comment_date", $id)); if ($comments) { // Make sure comments, post, and post_author are cached update_comment_cache($comments); $post = get_post($id); $authordata = get_userdata($post->post_author); ?> <br class="clear" /> <table class="widefat" cellspacing="0"> <thead> <tr> <th scope="col" class="column-comment"><?php echo _c('Comment|noun'); ?> </th> <th scope="col" class="column-author"><?php _e('Author');
function _wp_get_comment_list( $status = '', $s = false, $start, $num ) { global $wpdb; $start = abs( (int) $start ); $num = (int) $num; if ( 'moderated' == $status ) $approved = "comment_approved = '0'"; elseif ( 'approved' == $status ) $approved = "comment_approved = '1'"; elseif ( 'spam' == $status ) $approved = "comment_approved = 'spam'"; else $approved = "comment_approved != 'spam'"; if ( $s ) { $s = $wpdb->escape($s); $comments = $wpdb->get_results("SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->comments WHERE (comment_author LIKE '%$s%' OR comment_author_email LIKE '%$s%' OR comment_author_url LIKE ('%$s%') OR comment_author_IP LIKE ('%$s%') OR comment_content LIKE ('%$s%') ) AND $approved ORDER BY comment_date_gmt DESC LIMIT $start, $num"); } else { $comments = $wpdb->get_results( "SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->comments USE INDEX (comment_date_gmt) WHERE $approved ORDER BY comment_date_gmt DESC LIMIT $start, $num" ); } update_comment_cache($comments); $total = $wpdb->get_var( "SELECT FOUND_ROWS()" ); return array($comments, $total); }
/** * Adds any comments from the given IDs to the cache that do not already exist in cache. * * @since 4.4.0 * @access private * * @see update_comment_cache() * @global wpdb $wpdb WordPress database abstraction object. * * @param array $comment_ids Array of comment IDs. * @param bool $update_meta_cache Optional. Whether to update the meta cache. Default true. */ function _prime_comment_caches($comment_ids, $update_meta_cache = true) { global $wpdb; $non_cached_ids = _get_non_cached_ids($comment_ids, 'comment'); if (!empty($non_cached_ids)) { $fresh_comments = $wpdb->get_results(sprintf("SELECT {$wpdb->comments}.* FROM {$wpdb->comments} WHERE comment_ID IN (%s)", join(",", array_map('intval', $non_cached_ids)))); update_comment_cache($fresh_comments, $update_meta_cache); } }
function widget($args, $instance) { global $wpdb, $wp_query, $post, $user_ID, $comment, $overridden_bizzpage; $form_args = array_merge($args, $instance); // If the comments have been modified by a third-party plugin (there is a filter hook on comments_template) then call the WordPress default comments if (has_filter('comments_template') && !class_exists('Woocommerce')) { // call the WordPress default comment template comments_template(); // show the bizz comments } else { // Will not display the comments template if not on single post or page. if (!is_singular() || empty($post)) { return false; } // Will not display the comments loop if the post does not have comments. if ('0' != $post->comment_count) { // Comment author information fetched from the comment cookies. $commenter = wp_get_current_commenter(); // The name of the current comment author escaped for use in attributes. $comment_author = $commenter['comment_author']; // Escaped by sanitize_comment_cookies() // The email address of the current comment author escaped for use in attributes. $comment_author_email = $commenter['comment_author_email']; // Escaped by sanitize_comment_cookies() // The url of the current comment author escaped for use in attributes. $comment_author_url = esc_url($commenter['comment_author_url']); // allow widget to override $post->ID $post_id = $post->ID; // Grabs the comments for the $post->ID from the db. if ($user_ID) { $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", $post_id, $user_ID)); } else { if (empty($comment_author)) { $comments = get_comments(array('post_id' => $post_id, 'status' => 'approve', 'order' => 'ASC')); } else { $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", $post_id, wp_specialchars_decode($comment_author, ENT_QUOTES), $comment_author_email)); } } // Adds the comments retrieved from the db into the main $wp_query $wp_query->comments = apply_filters('comments_array', $comments, $post_id); // keep $comments for legacy's sake $comments =& $wp_query->comments; // Set the comment count $wp_query->comment_count = count($wp_query->comments); // Update the cache update_comment_cache($wp_query->comments); // Paged comments $overridden_bizzpage = FALSE; if ('' == get_query_var('bizzpage') && get_option('page_comments')) { set_query_var('bizzpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1); $overridden_bizzpage = TRUE; } /**/ /**/ // All the preliminary work is complete. Let's get down to business... $wp_list_comments_args = array(); $wp_list_comments_args['type'] = $instance['type']; $wp_list_comments_args['reply_text'] = (string) apply_filters('widget_reply_text', $instance['reply_text'], $instance); $wp_list_comments_args['login_text'] = (string) apply_filters('widget_login_text', $instance['login_text'], $instance); $wp_list_comments_args['max_depth'] = (int) $instance['max_depth']; $wp_list_comments_args['enable_reply'] = $instance['enable_reply']; $wp_list_comments_args['comment_meta'] = $instance['comment_meta']; $wp_list_comments_args['comment_moderation'] = apply_filters('widget_comment_moderation', $instance['comment_moderation'], $instance); $wp_list_comments_args['callback'] = 'bizz_comments_loop_callback'; $wp_list_comments_args['password_text'] = apply_filters('widget_password_text', $instance['password_text'], $instance); $wp_list_comments_args['pass_protected_text'] = apply_filters('widget_password_text', $instance['password_text'], $instance); $wp_list_comments_args['sing_comment_text'] = apply_filters('widget_sing_comment_text', $instance['sing_comment_text'], $instance); $wp_list_comments_args['plu_comment_text'] = apply_filters('widget_plu_comment_text', $instance['plu_comment_text'], $instance); $wp_list_comments_args['sing_trackback_text'] = apply_filters('widget_sing_trackback_text', $instance['sing_trackback_text'], $instance); $wp_list_comments_args['plu_trackback_text'] = apply_filters('widget_plu_trackback_text', $instance['plu_trackback_text'], $instance); $wp_list_comments_args['sing_pingback_text'] = apply_filters('widget_sing_pingback_text', $instance['sing_pingback_text'], $instance); $wp_list_comments_args['plu_pingback_text'] = apply_filters('widget_plu_pingback_text', $instance['plu_pingback_text'], $instance); $wp_list_comments_args['sing_ping_text'] = apply_filters('widget_sing_ping_text', $instance['sing_ping_text'], $instance); $wp_list_comments_args['plu_ping_text'] = apply_filters('widget_plu_ping_text', $instance['plu_ping_text'], $instance); $wp_list_comments_args['no_text'] = apply_filters('widget_no_text', $instance['no_text'], $instance); $wp_list_comments_args['to_text'] = apply_filters('widget_to_text', $instance['to_text'], $instance); $paginate_comments_links = paginate_comments_links(array('echo' => false)); $wp_list_comments_args['reverse_top_level'] = $instance['reverse_top_level']; $comment_type = 'all' == $instance['type'] ? 'comment' : $instance['type']; $type_plural = 'pings' == $comment_type ? $comment_type : "{$comment_type}s"; $type_singular = 'pings' == $comment_type ? 'ping' : $comment_type; $type_plural == 'comments' ? $type_plural = $wp_list_comments_args['plu_comment_text'] : ($type_plural = $type_plural); $type_plural == 'trackbacks' ? $type_plural = $wp_list_comments_args['plu_trackback_text'] : ($type_plural = $type_plural); $type_plural == 'pingbacks' ? $type_plural = $wp_list_comments_args['plu_pingback_text'] : ($type_plural = $type_plural); $type_plural == 'pings' ? $type_plural = $wp_list_comments_args['plu_ping_text'] : ($type_plural = $type_plural); $type_singular == 'comment' ? $type_singular = $wp_list_comments_args['sing_comment_text'] : ($type_singular = $type_singular); $type_singular == 'trackback' ? $type_singular = $wp_list_comments_args['sing_trackback_text'] : ($type_singular = $type_singular); $type_singular == 'pingback' ? $type_singular = $wp_list_comments_args['sing_pingback_text'] : ($type_singular = $type_singular); $type_singular == 'ping' ? $type_singular = $wp_list_comments_args['sing_ping_text'] : ($type_singular = $type_singular); // Check to see if post is password protected if (post_password_required()) { echo "<{$instance['comment_header']}>" . $wp_list_comments_args['password_text'] . "</{$instance['comment_header']}>"; echo '<p class="post_password_required">' . $wp_list_comments_args['pass_protected_text'] . '</p>'; return false; } echo '<div id="bizz-comments-loop-' . $post_id . '" class="widget-bizz-comments-loop">'; /* Open the output of the widget. */ echo $args['before_widget']; // If we have comments if (have_comments()) { do_action("before_{$comment_type}_div"); $div_id = 'comment' == $comment_type ? 'comments' : $comment_type; echo '<div id="' . $div_id . '">'; // div#comments $title = the_title('“', '”', false); $local_comments = $comments; $_comments_by_type = separate_comments($local_comments); echo "<{$instance['comment_header']} id=\"comments-number\" class=\"comments-header\">"; bizz_comments_number("" . $wp_list_comments_args['no_text'] . " {$type_plural} " . $wp_list_comments_args['to_text'] . " {$title}", "1 {$type_singular} " . $wp_list_comments_args['to_text'] . " {$title}", "% {$type_plural} " . $wp_list_comments_args['to_text'] . " {$title}", $instance['type'], $_comments_by_type); echo "</{$instance['comment_header']}>"; unset($local_comments, $_comments_by_type); ?> <?php if ($instance['enable_pagination'] and get_option('page_comments') and $paginate_comments_links) { ?> <div class="comment-navigation paged-navigation"> <?php echo $paginate_comments_links; ?> <?php do_action("{$comment_type}_pagination"); ?> </div><!-- .comment-navigation --> <?php } ?> <?php do_action("before_{$comment_type}_list"); ?> <ol class="commentlist"> <?php wp_list_comments($wp_list_comments_args); ?> </ol> <?php do_action("after_{$comment_type}_list"); ?> <?php if ($instance['enable_pagination'] and get_option('page_comments') and $paginate_comments_links) { ?> <div class="comment-navigation paged-navigation"> <?php echo $paginate_comments_links; ?> <?php do_action("{$comment_type}_pagination"); ?> </div><!-- .comment-navigation --> <?php } ?> <?php echo '</div>'; // div#comments do_action("after_{$comment_type}_div"); } /* Close the output of the widget. */ echo $args['after_widget']; echo '</div>'; } /* Load Comments Form. */ bizz_comment_form($form_args); } }