Changeset 22074
- Timestamp:
- 09/27/2012 09:53:14 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/comment.php
r22068 r22074 191 191 */ 192 192 class WP_Comment_Query { 193 /** 194 * Metadata query container 195 * 196 * @since 3.? 197 * @access public 198 * @var object WP_Meta_Query 199 */ 200 var $meta_query = false; 193 201 194 202 /** … … 224 232 'search' => '', 225 233 'count' => false, 234 'meta_key' => '', 235 'meta_value' => '', 236 'meta_query' => '', 226 237 ); 227 238 239 $groupby = ''; 240 228 241 $this->query_vars = wp_parse_args( $query_vars, $defaults ); 242 243 // Parse meta query 244 $this->meta_query = new WP_Meta_Query(); 245 $this->meta_query->parse_query_vars( $this->query_vars ); 246 229 247 do_action_ref_array( 'pre_get_comments', array( &$this ) ); 230 248 extract( $this->query_vars, EXTR_SKIP ); … … 233 251 $key = md5( serialize( compact(array_keys($defaults)) ) ); 234 252 $last_changed = wp_cache_get('last_changed', 'comment'); 235 if ( ! $last_changed ) {253 if ( ! $last_changed ) { 236 254 $last_changed = time(); 237 255 wp_cache_set('last_changed', $last_changed, 'comment'); … … 240 258 241 259 if ( $cache = wp_cache_get( $cache_key, 'comment' ) ) { 242 return $cache;260 //return $cache; 243 261 } 244 262 … … 258 276 if ( ! empty( $orderby ) ) { 259 277 $ordersby = is_array($orderby) ? $orderby : preg_split('/[,\s]/', $orderby); 260 $ordersby = array_intersect( 261 $ordersby, 262 array( 263 'comment_agent', 264 'comment_approved', 265 'comment_author', 266 'comment_author_email', 267 'comment_author_IP', 268 'comment_author_url', 269 'comment_content', 270 'comment_date', 271 'comment_date_gmt', 272 'comment_ID', 273 'comment_karma', 274 'comment_parent', 275 'comment_post_ID', 276 'comment_type', 277 'user_id', 278 ) 278 $allowed_keys = array( 279 'comment_agent', 280 'comment_approved', 281 'comment_author', 282 'comment_author_email', 283 'comment_author_IP', 284 'comment_author_url', 285 'comment_content', 286 'comment_date', 287 'comment_date_gmt', 288 'comment_ID', 289 'comment_karma', 290 'comment_parent', 291 'comment_post_ID', 292 'comment_type', 293 'user_id', 279 294 ); 295 if ( ! empty( $this->query_vars['meta_key'] ) ) { 296 $allowed_keys[] = $q['meta_key']; 297 $allowed_keys[] = 'meta_value'; 298 $allowed_keys[] = 'meta_value_num'; 299 } 300 $ordersby = array_intersect( $ordersby, $allowed_keys ); 301 foreach ( $ordersby as $key => $value ) { 302 if ( $value == $q['meta_key'] || $value == 'meta_value' ) { 303 $ordersby[ $key ] = "$wpdb->commentmeta.meta_value"; 304 } elseif ( $value == 'meta_value_num' ) { 305 $ordersby[ $key ] = "$wpdb->commentmeta.meta_value+0"; 306 } 307 } 280 308 $orderby = empty( $ordersby ) ? 'comment_date_gmt' : implode(', ', $ordersby); 281 309 } else { … … 330 358 } 331 359 332 $pieces = array( 'fields', 'join', 'where', 'orderby', 'order', 'limits' ); 360 if ( ! empty( $this->meta_query->queries ) ) { 361 $clauses = $this->meta_query->get_sql( 'comment', $wpdb->comments, 'comment_ID', $this ); 362 $join .= $clauses['join']; 363 $where .= $clauses['where']; 364 $groupby = "{$wpdb->comments}.comment_ID"; 365 } 366 367 $pieces = array( 'fields', 'join', 'where', 'orderby', 'order', 'limits', 'groupby' ); 333 368 $clauses = apply_filters_ref_array( 'comments_clauses', array( compact( $pieces ), &$this ) ); 334 369 foreach ( $pieces as $piece ) 335 370 $$piece = isset( $clauses[ $piece ] ) ? $clauses[ $piece ] : ''; 336 371 337 $query = "SELECT $fields FROM $wpdb->comments $join WHERE $where ORDER BY $orderby $order $limits"; 372 if ( $groupby ) 373 $groupby = 'GROUP BY ' . $groupby; 374 375 $query = "SELECT $fields FROM $wpdb->comments $join WHERE $where $groupby ORDER BY $orderby $order $limits"; 338 376 339 377 if ( $count )
Note: See TracChangeset
for help on using the changeset viewer.