Ticket #8120: 8120.getting-started.diff
| File 8120.getting-started.diff, 3.8 KB (added by , 18 years ago) |
|---|
-
wp-includes/comment.php
180 180 function get_comments( $args = '' ) { 181 181 global $wpdb; 182 182 183 $defaults = array('status' => '', 'orderby' => 'comment_date_gmt', 'order' => 'DESC', 'number' => '', 'offset' => '', 'post_id' => 0 );183 $defaults = array('status' => '', 'orderby' => 'comment_date_gmt', 'order' => 'DESC', 'number' => '', 'offset' => '', 'post_id' => 0, 'paged' => FALSE, 'page' => 1, 'comments_per_page' => get_option( 'comments_per_page' ), 'threaded' => FALSE, 'child_of' => 0, $passed_comments = NULL ); 184 184 185 185 $args = wp_parse_args( $args, $defaults ); 186 186 extract( $args, EXTR_SKIP ); … … 198 198 return $cache; 199 199 } 200 200 201 $post_id = absint($post_id); 201 $post_id = absint( $post_id ); 202 $page = absint( $page ); 203 $comments_per_page = absint( $comments_per_page ); 202 204 205 if ( is_string( $child_of) || is_int( $child_of ) ) 206 $child_of = explode( ',', $child_of ); 207 208 if ( is_array( $child_of ) ) { 209 $_child_of = array(); 210 foreach ( (array) $child_of as $_child ) 211 $_child_of[] = absint( trim( $_child, " '" ) ); 212 $child_of = implode( ',', $_child_of ); 213 } else { 214 $child_of = 0; 215 } 216 203 217 if ( 'hold' == $status ) 204 218 $approved = "comment_approved = '0'"; 205 219 elseif ( 'approve' == $status ) … … 209 223 else 210 224 $approved = "( comment_approved = '0' OR comment_approved = '1' )"; 211 225 212 $order = ( 'ASC' == $order) ? 'ASC' : 'DESC';226 $order = ( 'ASC' == strtoupper( $order ) ) ? 'ASC' : 'DESC'; 213 227 214 228 $orderby = 'comment_date_gmt'; // Hard code for now 215 229 216 230 $number = absint($number); 217 231 $offset = absint($offset); 218 232 219 if ( !empty($number) ) { 233 $threaded_where = ''; 234 235 if ( $paged && $post_id && !$threaded ) { 236 $number = 'LIMIT ' . ( $page - 1 ) * $comments_per_page . ',' . $comments_per_page; 237 } elseif ( $paged && $post_id ) { 238 if ( ( $comments_per_page * 2 ) >= get_comment_count( $post_id ) ) { // just query them all 239 $threaded = false; // we'll get them all in one query, so cancel any recursive queries 240 $number = ''; 241 } elseif ( 0 == $child_of ) { // first level of recursion 242 $threaded_where = 'comment_parent = 0 AND '; 243 } else { // further level of recursion 244 $threaded_where = "comment_parent IN( $child_of ) AND "; 245 } 246 } elseif ( !empty($number) ) { 220 247 if ( $offset ) 221 248 $number = 'LIMIT ' . $offset . ',' . $number; 222 249 else … … 227 254 } 228 255 229 256 if ( ! empty($post_id) ) 230 $post_where = "comment_post_ID = $post_id AND";257 $post_where = $wpdb->prepare( 'comment_post_ID = %d AND', $post_id ); 231 258 else 232 259 $post_where = ''; 233 260 234 $comments = $wpdb->get_results( "SELECT * FROM $wpdb->comments WHERE $post_where $approved ORDER BY $orderby $order $number" ); 235 wp_cache_add( $cache_key, $comments, 'comment' ); 261 $comments = $wpdb->get_results( "SELECT * FROM $wpdb->comments WHERE $threaded_where $post_where $approved ORDER BY $orderby $order $number" ); 236 262 263 if ( $threaded && $paged ) { 264 if ( count( $comments ) ) { // have to recurse 265 if ( count( $passed_comments ) ) 266 $passed_comments = array_merge( (array) $passed_comments, (array) $comments ); 267 else 268 $passed_comments = $comments; 269 $_new_ids = array(); 270 foreach ( (array) $comments as $_c ) 271 $_new_ids[] = $_c->comment_ID; 272 $_args = compact( 'status', 'orderby', 'order', 'number', 'offset', 'post_id', 'paged', 'page', 'comments_per_page', 'threaded', 'passed_comments'); 273 $_args['child_of'] = $_new_ids; 274 $comments = get_comments( $_args ); 275 } else { // found them all! 276 $comments = $passed_comments; 277 } 278 } 279 280 // we only add to the cache when we've gathered the full comment tree 281 if ( ! ( $threaded && $paged && $child_of != 0 ) ) 282 wp_cache_add( $cache_key, $comments, 'comment' ); 283 237 284 return $comments; 238 285 } 239 286
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)