Ticket #1925: 1925.alt.01.diff
File 1925.alt.01.diff, 8.9 KB (added by , 11 years ago) |
---|
-
includes/common/widgets.php
743 743 'post_status' => array( bbp_get_public_status_id(), bbp_get_closed_status_id() ), 744 744 'ignore_sticky_posts' => true, 745 745 'no_found_rows' => true, 746 'meta_key' => '_bbp_last_active_time', 747 'orderby' => 'meta_value', 746 'orderby' => 'date', 748 747 'order' => 'DESC', 749 748 ); 750 749 break; -
includes/forums/functions.php
929 929 // First, delete everything. 930 930 delete_option( '_bbp_private_forums' ); 931 931 delete_option( '_bbp_hidden_forums' ); 932 932 933 933 /** 934 934 * Don't search for both private/hidden statuses. Since 'pre_get_posts' is an 935 * action, it's not removed by suppress_filters. We need to make sure that 935 * action, it's not removed by suppress_filters. We need to make sure that 936 936 * we're only searching for the supplied post_status. 937 937 * 938 938 * @see https://bbpress.trac.wordpress.org/ticket/2512 … … 954 954 'post_status' => bbp_get_hidden_status_id(), 955 955 'fields' => 'ids' 956 956 ) ); 957 957 958 958 // Enable forum visibilty normalization 959 959 add_action( 'pre_get_posts', 'bbp_pre_get_posts_normalize_forum_visibility', 4 ); 960 960 … … 1179 1179 } 1180 1180 } 1181 1181 1182 // Setup recent topic query vars1183 $ post_vars =array(1182 // Get the most recent topic in this forum_id 1183 $recent_topic = get_posts( array( 1184 1184 'post_parent' => $forum_id, 1185 1185 'post_type' => bbp_get_topic_post_type(), 1186 ' meta_key' => '_bbp_last_active_time',1187 'order by' => 'meta_value',1186 'orderby' => 'date', 1187 'order' => 'DESC', 1188 1188 'numberposts' => 1 1189 ) ;1189 ) ); 1190 1190 1191 // Get the most recent topic in this forum_id1192 $recent_topic = get_posts( $post_vars );1193 1191 if ( !empty( $recent_topic ) ) { 1194 1192 $topic_id = $recent_topic[0]->ID; 1195 1193 } … … 1360 1358 $new_time = get_post_field( 'post_date', bbp_get_forum_last_active_id( $forum_id ) ); 1361 1359 1362 1360 // Update only if there is a time 1363 if ( !empty( $new_time ) ) 1361 if ( !empty( $new_time ) ) { 1362 1363 // Update forum's meta - not used since 2.6 1364 1364 update_post_meta( $forum_id, '_bbp_last_active_time', $new_time ); 1365 } 1365 1366 1366 1367 return (int) apply_filters( 'bbp_update_forum_last_active', $new_time, $forum_id ); 1367 1368 } -
includes/forums/template.php
502 502 * 503 503 * @param int $forum_id Optional. Forum id 504 504 * @uses bbp_get_forum_id() To get the forum id 505 * @uses get_post_meta() To retrieve forum last active meta506 505 * @uses bbp_get_forum_last_reply_id() To get forum's last reply id 507 506 * @uses get_post_field() To get the post date of the reply 508 507 * @uses bbp_get_forum_last_topic_id() To get forum's last topic id … … 516 515 */ 517 516 function bbp_get_forum_last_active_time( $forum_id = 0 ) { 518 517 519 // Verify forum and get last active meta 520 $forum_id = bbp_get_forum_id( $forum_id ); 521 $last_active = get_post_meta( $forum_id, '_bbp_last_active_time', true ); 518 // Verify forum id 519 $forum_id = bbp_get_forum_id( $forum_id ); 522 520 523 if ( empty( $last_active ) ) { 524 $reply_id = bbp_get_forum_last_reply_id( $forum_id ); 525 if ( !empty( $reply_id ) ) { 526 $last_active = get_post_field( 'post_date', $reply_id ); 527 } else { 528 $topic_id = bbp_get_forum_last_topic_id( $forum_id ); 529 if ( !empty( $topic_id ) ) { 530 $last_active = bbp_get_topic_last_active_time( $topic_id ); 531 } 521 // Check the forum for the last reply id and use this time stamp 522 $reply_id = bbp_get_forum_last_reply_id( $forum_id ); 523 if ( !empty( $reply_id ) ) { 524 $last_active = get_post_field( 'post_date', $reply_id ); 525 526 // No reply's, lets try the last topic and use that time stamp 527 } else { 528 $topic_id = bbp_get_forum_last_topic_id( $forum_id ); 529 if ( !empty( $topic_id ) ) { 530 $last_active = bbp_get_topic_last_active_time( $topic_id ); 532 531 } 533 532 } 534 533 534 // Convert to time since format 535 535 $active_time = !empty( $last_active ) ? bbp_get_time_since( bbp_convert_date( $last_active ) ) : ''; 536 536 537 // Return the time since 537 538 return apply_filters( 'bbp_get_forum_last_active', $active_time, $forum_id ); 538 539 } 539 540 … … 2226 2227 2227 2228 return apply_filters( 'bbp_get_form_forum_visibility', esc_attr( $forum_visibility ) ); 2228 2229 } 2229 2230 2230 2231 /** 2231 2232 * Output checked value of forum subscription 2232 2233 * -
includes/topics/functions.php
2524 2524 2525 2525 // Update only if published 2526 2526 if ( !empty( $new_time ) ) { 2527 2528 // Update topic's meta - not used since 2.6 2527 2529 update_post_meta( $topic_id, '_bbp_last_active_time', $new_time ); 2528 2530 } 2529 2531 … … 3455 3457 <guid><?php bbp_topic_permalink(); ?></guid> 3456 3458 <title><![CDATA[<?php bbp_topic_title(); ?>]]></title> 3457 3459 <link><?php bbp_topic_permalink(); ?></link> 3458 <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_ meta( bbp_get_topic_id(), '_bbp_last_active_time', true) ); ?></pubDate>3460 <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_field( 'post_date', bbp_get_topic_id() ) ); ?></pubDate> 3459 3461 <dc:creator><?php the_author() ?></dc:creator> 3460 3462 3461 3463 <?php if ( !post_password_required() ) : ?> -
includes/topics/template.php
151 151 $default = array( 152 152 'post_type' => bbp_get_topic_post_type(), // Narrow query down to bbPress topics 153 153 'post_parent' => $default_post_parent, // Forum ID 154 'meta_key' => '_bbp_last_active_time', // Make sure topic has some last activity time 155 'orderby' => 'meta_value', // 'meta_value', 'author', 'date', 'title', 'modified', 'parent', rand', 154 'orderby' => 'date', // 'meta_value', 'author', 'date', 'title', 'modified', 'parent', rand', 156 155 'order' => 'DESC', // 'ASC', 'DESC' 157 156 'posts_per_page' => bbp_get_topics_per_page(), // Topics per page 158 157 'paged' => bbp_get_paged(), // Page Number … … 279 278 $sticky_query = array( 280 279 'post_type' => bbp_get_topic_post_type(), 281 280 'post_parent' => 'any', 282 'meta_key' => '_bbp_last_active_time', 283 'orderby' => 'meta_value', 284 'order' => 'DESC', 281 'orderby' => 'date', 282 'order' => 'ASC', 285 283 'include' => $stickies 286 284 ); 287 285 … … 411 409 412 410 // Return object 413 411 return apply_filters( 'bbp_has_topics', $bbp->topic_query->have_posts(), $bbp->topic_query ); 412 414 413 } 415 414 415 function bbp_topic_freshness_override( $orderby_statement ) { 416 global $wp_query; 417 418 $bbp = bbpress(); 419 420 // Currently inside a topic loop 421 if ( bbp_is_single_forum() ) { 422 $orderby_statement = "COALESCE( ( SELECT MAX( post_date ) FROM wp_posts bbp1 WHERE bbp1.post_parent = wp_posts.id ) , wp_posts.post_date ) DESC, ".$orderby_statement; 423 424 // Currently inside a search loop 425 } elseif ( !empty($bbp->topic_query ) ) { 426 $orderby_statement = "wp_posts.post_title DESC"; 427 428 // @ToDo - What other conditions do we need to alter the query? 429 430 // Fallback 431 } else { 432 $orderby_statement = $orderby_statement; 433 } 434 435 return $orderby_statement; 436 } 437 add_filter('posts_orderby', 'bbp_topic_freshness_override', 10, 2 ); 438 416 439 /** 417 440 * Whether there are more topics available in the loop 418 441 * … … 1789 1812 * @return string Topic freshness 1790 1813 */ 1791 1814 function bbp_get_topic_last_active_time( $topic_id = 0 ) { 1815 // Verify the topic id 1792 1816 $topic_id = bbp_get_topic_id( $topic_id ); 1793 1817 1794 // Try to get the most accurate freshness time possible 1795 $last_active = get_post_meta( $topic_id, '_bbp_last_active_time', true ); 1796 if ( empty( $last_active ) ) { 1797 $reply_id = bbp_get_topic_last_reply_id( $topic_id ); 1798 if ( !empty( $reply_id ) ) { 1799 $last_active = get_post_field( 'post_date', $reply_id ); 1800 } else { 1801 $last_active = get_post_field( 'post_date', $topic_id ); 1802 } 1818 // Check the topic for the last reply id 1819 $reply_id = bbp_get_topic_last_reply_id( $topic_id ); 1820 1821 // If we have a reply use that timestamp, if not use the topic timestamp 1822 if ( !empty( $reply_id ) ) { 1823 $last_active = get_post_field( 'post_date', $reply_id ); 1824 } else { 1825 $last_active = get_post_field( 'post_date', $topic_id ); 1803 1826 } 1804 1827 1828 // Convert to time since format 1805 1829 $last_active = !empty( $last_active ) ? bbp_get_time_since( bbp_convert_date( $last_active ) ) : ''; 1806 1830 1807 1831 // Return the time since