Ticket #2785: 2785.2.diff
File 2785.2.diff, 8.3 KB (added by , 9 years ago) |
---|
-
src/includes/common/classes.php
368 368 $id_field = $this->db_fields['id']; 369 369 $id = $element->$id_field; 370 370 371 // Now fetch child replies for each reply as they're listed... 372 373 $reply_search = !empty($_REQUEST['rs']) ? $_REQUEST['rs'] : false; 374 $post_type = (bbp_is_single_topic() && bbp_show_lead_topic()) ? bbp_get_reply_post_type() : array(bbp_get_topic_post_type(), bbp_get_reply_post_type()); 375 376 $child_args = array( 377 'post_type' => $post_type, 378 'post_parent' => bbp_get_topic_id(), 379 'posts_per_page' => '-1', 380 'orderby' => 'date', 381 'order' => 'ASC', 382 'hierarchical' => true, 383 'ignore_sticky_posts' => true, 384 's' => $reply_search, 385 'meta_query' => array(array( 386 'key' => '_bbp_reply_to', 387 'compare' => '=', 388 'value' => $id 389 )) 390 ); 391 392 $parsed_args = bbp_parse_args('', $child_args, 'has_replies'); 393 $child_posts = new WP_Query($parsed_args); 394 $children_elements = array($id => $child_posts->posts); 395 wp_reset_postdata(); 396 371 397 // Display element 372 398 parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output ); 373 399 -
src/includes/replies/functions.php
358 358 'post_parent' => $topic_id, 359 359 'post_type' => bbp_get_reply_post_type(), 360 360 'comment_status' => 'closed', 361 'menu_order' => bbp_get_topic_reply_count( $topic_id, true ) + 1361 'menu_order' => 0 362 362 ) ); 363 363 364 364 // Insert reply … … 1358 1358 'post_title' => '', 1359 1359 'post_name' => false, // will be automatically generated 1360 1360 'post_parent' => $destination_topic->ID, 1361 'menu_order' => $reply_position,1361 'menu_order' => 0, // will be automatically regenerated 1362 1362 'guid' => '' 1363 1363 ) ); 1364 1364 … … 2374 2374 $topic_id = !empty( $topic_id ) ? bbp_get_topic_id( $topic_id ) : bbp_get_reply_topic_id( $reply_id ); 2375 2375 $reply_position = 0; 2376 2376 2377 // If reply is actually the first post in a topic, return 0 2378 if ( $reply_id !== $topic_id ) { 2377 if ($reply_id != $topic_id) { 2378 $top_level_replies = array(); 2379 $replies_args = array( 2380 'post_type' => bbp_get_reply_post_type(), 2381 'post_parent' => $topic_id, 2382 'posts_per_page' => -1, 2383 'orderby' => 'ID', 2384 'meta_query' => array('relation' => 'OR', 2385 array( 2386 'key' => '_bbp_reply_to', 2387 'compare' => 'NOT EXISTS', 2388 'value' => '0' 2389 ), 2390 array( 2391 'key' => '_bbp_reply_to', 2392 'compare' => '=', 2393 'value' => '0' 2394 ) 2395 )); 2396 $top_level_reply_posts = get_posts($replies_args); 2397 foreach ($top_level_reply_posts as $top_level_reply_post) { 2398 array_unshift($top_level_replies, $top_level_reply_post->ID); 2399 } 2400 array_unshift($top_level_replies, $topic_id); 2379 2401 2380 // Make sure the topic has replies before running another query 2381 $reply_count = bbp_get_topic_reply_count( $topic_id, false ); 2382 if ( !empty( $reply_count ) ) { 2383 2384 // Get reply id's 2385 $topic_replies = bbp_get_all_child_ids( $topic_id, bbp_get_reply_post_type() ); 2386 if ( !empty( $topic_replies ) ) { 2387 2388 // Reverse replies array and search for current reply position 2389 $topic_replies = array_reverse( $topic_replies ); 2390 $reply_position = array_search( (string) $reply_id, $topic_replies ); 2391 2392 // Bump the position to compensate for the lead topic post 2393 $reply_position++; 2394 } 2402 $reply_position = array_search($reply_id, $top_level_replies); 2403 if (empty($reply_position)) { 2404 $next_up = $reply_id; 2405 do { 2406 $reply_to_id = get_post_meta($next_up, '_bbp_reply_to', true); 2407 $reply_position = array_search($reply_to_id, $top_level_replies); 2408 $next_up = $reply_to_id; 2409 } while ($reply_position == false); 2395 2410 } 2396 2411 } 2397 2412 … … 2427 2442 $walker = new BBP_Walker_Reply; 2428 2443 $walker->paged_walk( bbpress()->reply_query->posts, $r['max_depth'], $r['page'], $r['per_page'], $r ); 2429 2444 2430 bbpress()->max_num_pages 2445 bbpress()->max_num_pages = $walker->max_pages; 2431 2446 bbpress()->reply_query->in_the_loop = false; 2432 2447 } 2433 2448 -
src/includes/replies/template.php
146 146 $default['s'] = $_REQUEST['rs']; 147 147 } 148 148 149 // Suppress threaded replies for now... 150 if (bbp_thread_replies()) { 151 $default['meta_query'] = array('relation' => 'OR', 152 array( 153 'key' => '_bbp_reply_to', 154 'compare' => 'NOT EXISTS', 155 'value' => '0' 156 ), 157 array( 158 'key' => '_bbp_reply_to', 159 'compare' => '=', 160 'value' => '0' 161 ) 162 ); 163 } 164 149 165 // What are the default allowed statuses (based on user caps) 150 166 if ( bbp_get_view_all() ) { 151 167 … … 178 194 179 195 // Set posts_per_page value if replies are threaded 180 196 $replies_per_page = $r['posts_per_page']; 181 if ( true === $r['hierarchical'] ) {182 $r['posts_per_page'] = -1;183 }184 197 185 198 // Get bbPress 186 199 $bbp = bbpress(); … … 252 265 } 253 266 254 267 // Figure out total pages 255 if ( true === $r['hierarchical'] ) { 256 $walker = new BBP_Walker_Reply; 257 $total_pages = ceil( (int) $walker->get_number_of_root_elements( $bbp->reply_query->posts ) / (int) $replies_per_page ); 258 } else { 268 259 269 $total_pages = ceil( (int) $bbp->reply_query->found_posts / (int) $replies_per_page ); 260 270 261 271 // Add pagination to query object … … 276 286 } else { 277 287 $bbp->reply_query->pagination_links = str_replace( '&paged=1', '', $bbp->reply_query->pagination_links ); 278 288 } 279 } 289 280 290 } 281 291 282 292 // Return object … … 486 496 $reply_id = bbp_get_reply_id ( $reply_id ); 487 497 $topic_id = bbp_get_reply_topic_id( $reply_id ); 488 498 489 // Hierarchical reply page 490 if ( bbp_thread_replies() ) { 491 $reply_page = 1; 499 $reply_page = ceil( (int) bbp_get_reply_position( $reply_id, $topic_id ) / (int) bbp_get_replies_per_page() ); 492 500 493 // Standard reply page 494 } else { 495 $reply_page = ceil( (int) bbp_get_reply_position( $reply_id, $topic_id ) / (int) bbp_get_replies_per_page() ); 496 } 501 $reply_hash = '#post-' . $reply_id; 497 502 498 $reply_hash = '#post-' . $reply_id;499 503 $topic_link = bbp_get_topic_permalink( $topic_id, $redirect_to ); 500 504 $topic_url = remove_query_arg( 'view', $topic_link ); 501 505 … … 1800 1804 $reply_id = bbp_get_reply_id( $reply_id ); 1801 1805 $reply_position = get_post_field( 'menu_order', $reply_id ); 1802 1806 1803 // Reply doesn't have a position so get the raw value 1804 if ( empty( $reply_position ) ) { 1805 $topic_id = !empty( $topic_id ) ? bbp_get_topic_id( $topic_id ) : bbp_get_reply_topic_id( $reply_id ); 1806 1807 // Post is not the topic 1808 if ( $reply_id !== $topic_id ) { 1809 $reply_position = bbp_get_reply_position_raw( $reply_id, $topic_id ); 1810 1811 // Update the reply position in the posts table so we'll never have 1812 // to hit the DB again. 1813 if ( !empty( $reply_position ) ) { 1814 bbp_update_reply_position( $reply_id, $reply_position ); 1815 } 1816 1817 // Topic's position is always 0 1818 } else { 1819 $reply_position = 0; 1807 if (empty($reply_position)) { 1808 $reply_position = bbp_get_reply_position_raw( $reply_id, $topic_id ); 1809 // Bump the position by one if the lead topic isn't in the replies loop 1810 if (!bbp_show_lead_topic()) { 1811 $reply_position++; 1820 1812 } 1813 bbp_update_reply_position($reply_id, $reply_position); 1821 1814 } 1822 1815 1823 // Bump the position by one if the lead topic is in the replies loop1824 if ( ! bbp_show_lead_topic() ) {1825 $reply_position++;1826 }1827 1828 1816 return (int) apply_filters( 'bbp_get_reply_position', $reply_position, $reply_id, $topic_id ); 1829 1817 } 1830 1818 … … 2461 2449 2462 2450 // We are threading replies 2463 2451 if ( bbp_thread_replies() && bbp_is_single_topic() ) { 2464 return; 2452 2465 2453 $walker = new BBP_Walker_Reply; 2466 $threads = (int) $walker->get_number_of_root_elements( $bbp->reply_query->posts ) ;2454 $threads = (int) $walker->get_number_of_root_elements( $bbp->reply_query->posts ) + 1; // Not sure where this OB1 error comes from... 2467 2455 2468 2456 // Adjust for topic 2469 2457 $threads--;