Ticket #1925: 1925.3.patch
File 1925.3.patch, 17.8 KB (added by , 11 years ago) |
---|
-
plugins/bbpress/includes/common/functions.php
diff --git a/plugins/bbpress/includes/common/functions.php b/plugins/bbpress/includes/common/functions.php index 7620d92..975bc2a 100644
a b 364 364 } 365 365 366 366 /** 367 * Fix post modified times on post save for topics/forums 368 * 369 * When a forum or topic is updated, the post_modified and post_modified_gmt 370 * fields are updated. Since these fields are used for freshness data, we 371 * don't want to stomp out the current data. This keeps the post_modified(_gmt) 372 * fields at their current status, and moves the last edit time (in GMT) to post 373 * meta as '_bbp_last_edit_time_gmt'. This also solves the problem of not being 374 * able to pass our own custom post_modified(_gmt) values 375 * 376 * @since bbPress (rXXXX) 377 * 378 * @param array $data Post data 379 * @param array $postarr Original post array data 380 * @uses bbp_get_topic_post_type() To get the topic post type 381 * @uses bbp_get_reply_post_type() To get the reply post type 382 * @uses bbp_is_post_request() To determine if we're in a POST request 383 * @uses update_post_meta() To update the '_bbp_last_edit_time_gmt' post meta field 384 * @return array Post data 385 */ 386 function bbp_fix_post_modified( $data = array(), $postarr = array() ) { 387 388 // Post is not being updated, return 389 if ( empty( $postarr['ID'] ) || ( empty( $postarr['post_modified'] ) && empty( $postarr['post_modified_gmt'] ) ) ) { 390 return $data; 391 } 392 393 // Post is not a forum or topic, return 394 if ( !in_array( $postarr['post_type'], array( bbp_get_forum_post_type(), bbp_get_topic_post_type() ) ) ) { 395 return $data; 396 } 397 398 // Are we editing? 399 if ( bbp_is_post_request() && in_array( $_POST['action'], array( 'bbp-edit-forum', 'bbp-edit-topic', 'editpost' ) ) ) { 400 401 // Set the last edited time in post meta to the new post_modified_gmt 402 update_post_meta( $postarr['ID'], '_bbp_last_edit_time_gmt', $data['post_modified_gmt'] ); 403 } 404 405 // Reset post_modified and post_modified_gmt back to their original values 406 $data['post_modified'] = $postarr['post_modified']; 407 $data['post_modified_gmt'] = $postarr['post_modified_gmt']; 408 409 return $data; 410 } 411 412 /** 413 * Fix revision post_(date/date_gmt/modified/modified_gmt) times 414 * 415 * When a revision is created, _wp_post_revision_fields() sets the post_date(_gmt) 416 * fields to the post_modified time of the of the post being revised. Since we 417 * are now using the post_modified(_gmt) fields for freshness times, these fields 418 * are no longer accurate with respect to revisions. Here we reset the post_* 419 * times to back their proper values 420 * 421 * @since bbPress (rXXXX) 422 * 423 * @param array $data Post data 424 * @param array $postarr Original post array (includes post id) 425 * @uses bbp_is_topic() To make sure the revision is of a topic 426 * @uses get_post_meta() To get the '_bbp_last_edit_time_gmt' post meta field 427 * @uses get_date_from_gmt() To get the localized date from a gmt date 428 * @uses current_time() To get the current_time in mysql format 429 * @return array Post data 430 */ 431 function bbp_fix_revision_times( $data = array(), $postarr = array() ) { 432 433 // Don't even bother. This is not a revision or we're updating 434 if ( 'revision' !== $postarr['post_type'] || !empty( $postarr['ID'] ) ) { 435 return $data; 436 } 437 438 // Make sure we're working with a revision of a topic or forum 439 // TODO: Add a bbp_is_forum when forum revisions are added 440 if ( bbp_is_topic( $postarr['post_parent'] ) ) { 441 $post_id = $postarr['post_parent']; 442 } 443 444 // Get the true last edited time from post meta 445 $edit_time = get_post_meta( $post_id, '_bbp_last_edit_time_gmt', true ); 446 447 // Reset post_modified and post_modified_gmt back to their original values 448 $data['post_date'] = get_date_from_gmt( $edit_time ); 449 $data['post_date_gmt'] = $edit_time; 450 $data['post_modified'] = current_time( 'mysql' ); 451 $data['post_modified_gmt'] = current_time( 'mysql', 1 ); 452 453 return $data; 454 } 455 456 /** 367 457 * Check the date against the _bbp_edit_lock setting. 368 458 * 369 459 * @since bbPress (r3133) -
plugins/bbpress/includes/common/widgets.php
diff --git a/plugins/bbpress/includes/common/widgets.php b/plugins/bbpress/includes/common/widgets.php index 3204dc7..9866888 100644
a b 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' => 'modified', 748 747 'order' => 'DESC', 749 748 ); 750 749 break; -
plugins/bbpress/includes/core/filters.php
diff --git a/plugins/bbpress/includes/core/filters.php b/plugins/bbpress/includes/core/filters.php index 8dcd42c..f7ff034 100644
a b 49 49 add_filter( 'plugin_locale', 'bbp_plugin_locale', 10, 2 ); 50 50 51 51 // Fix post author id for anonymous posts (set it back to 0) when the post status is changed 52 add_filter( 'wp_insert_post_data', 'bbp_fix_post_author', 30, 2 ); 52 add_filter( 'wp_insert_post_data', 'bbp_fix_post_author', 30, 2 ); 53 54 // Fix post modified and post modified gmt time for forums and topics when the post is edited 55 add_filter( 'wp_insert_post_data', 'bbp_fix_post_modified', 32, 2 ); 56 57 // Fix post revision times when topics and replies are edited 58 add_filter( 'wp_insert_post_data', 'bbp_fix_revision_times', 34, 2 ); 53 59 54 60 // Force comments_status on bbPress post types 55 61 add_filter( 'comments_open', 'bbp_force_comment_status' ); -
plugins/bbpress/includes/forums/functions.php
diff --git a/plugins/bbpress/includes/forums/functions.php b/plugins/bbpress/includes/forums/functions.php index 050791d..9cbfe57 100644
a b 1171 1171 $post_vars = array( 1172 1172 'post_parent' => $forum_id, 1173 1173 'post_type' => bbp_get_topic_post_type(), 1174 'meta_key' => '_bbp_last_active_time', 1175 'orderby' => 'meta_value', 1174 'orderby' => 'modified', 1176 1175 'numberposts' => 1 1177 1176 ); 1178 1177 … … 1326 1325 } 1327 1326 1328 1327 /** 1329 * Update the forum s last active date/time (aka freshness)1328 * Update the forum's last active date/time (aka freshness) 1330 1329 * 1331 1330 * @since bbPress (r2680) 1332 1331 * 1333 * @param int $forum_id Optional. Topicid1332 * @param int $forum_id Optional. Forum id 1334 1333 * @param string $new_time Optional. New time in mysql format 1335 1334 * @uses bbp_get_forum_id() To get the forum id 1336 1335 * @uses bbp_get_forum_last_active_id() To get the forum's last post id 1337 * @uses get_post_field() To get the post date of the forum's last post 1338 * @uses update_post_meta() To update the forum last active time 1336 * @uses get_post_field() To get the post_modified date of the forum 1337 * @uses update_post_meta() To update the forum last active meta 1338 * @uses wp_update_post() To update the post_modified date of the forum 1339 1339 * @uses apply_filters() Calls 'bbp_update_forum_last_active' with the new time 1340 1340 * and forum id 1341 1341 * @return bool True on success, false on failure … … 1344 1344 $forum_id = bbp_get_forum_id( $forum_id ); 1345 1345 1346 1346 // Check time and use current if empty 1347 if ( empty( $new_time ) ) 1347 if ( empty( $new_time ) ) { 1348 1348 $new_time = get_post_field( 'post_date', bbp_get_forum_last_active_id( $forum_id ) ); 1349 } 1349 1350 1350 1351 // Update only if there is a time 1351 if ( !empty( $new_time ) ) 1352 if ( !empty( $new_time ) ) { 1353 1354 // Update forum's meta - not used since 2.6 1352 1355 update_post_meta( $forum_id, '_bbp_last_active_time', $new_time ); 1356 1357 // Toggle revisions to avoid duplicates 1358 $revisions_removed = false; 1359 if ( post_type_supports( bbp_get_forum_post_type(), 'revisions' ) ) { 1360 $revisions_removed = true; 1361 remove_post_type_support( bbp_get_forum_post_type(), 'revisions' ); 1362 } 1363 1364 // Update forum's post_modified date - since 2.6 1365 wp_update_post( array( 1366 'ID' => $forum_id, 1367 'post_modified' => $new_time, 1368 'post_modified_gmt' => get_gmt_from_date( $new_time ) 1369 ) ); 1370 1371 // Toggle revisions back on 1372 if ( true === $revisions_removed ) { 1373 $revisions_removed = false; 1374 add_post_type_support( bbp_get_forum_post_type(), 'revisions' ); 1375 } 1376 } 1353 1377 1354 1378 return (int) apply_filters( 'bbp_update_forum_last_active', $new_time, $forum_id ); 1355 1379 } … … 1906 1930 * @return Position change based on sort 1907 1931 */ 1908 1932 function _bbp_forum_query_usort_subforum_ids( $a = 0, $b = 0 ) { 1909 $ta = get_post_ meta( $a, '_bbp_last_active_time', true);1910 $tb = get_post_ meta( $b, '_bbp_last_active_time', true);1933 $ta = get_post_field( 'post_modified', $a ); 1934 $tb = get_post_field( 'post_modified', $b ); 1911 1935 return ( $ta < $tb ) ? -1 : 1; 1912 1936 } 1913 1937 -
plugins/bbpress/includes/forums/template.php
diff --git a/plugins/bbpress/includes/forums/template.php b/plugins/bbpress/includes/forums/template.php index 890dbe0..0d65b5d 100644
a b 447 447 * Allow forum rows to have adminstrative actions 448 448 * 449 449 * @since bbPress (r3653) 450 * 450 451 * @uses do_action() 451 452 * @todo Links and filter 452 453 */ … … 496 497 echo bbp_get_forum_last_active_time( $forum_id ); 497 498 } 498 499 /** 499 * Return the forum s last update date/time (aka freshness)500 * Return the forum's last update date/time (aka freshness) 500 501 * 501 502 * @since bbPress (r2464) 502 503 * 503 504 * @param int $forum_id Optional. Forum id 504 505 * @uses bbp_get_forum_id() To get the forum id 505 * @uses get_post_meta() To retrieve forum last active meta 506 * @uses bbp_get_forum_last_reply_id() To get forum's last reply id 507 * @uses get_post_field() To get the post date of the reply 508 * @uses bbp_get_forum_last_topic_id() To get forum's last topic id 509 * @uses bbp_get_topic_last_active_time() To get time when the topic was 510 * last active 506 * @uses get_post_field() To get the post_modified of the forum 511 507 * @uses bbp_convert_date() To convert the date 512 508 * @uses bbp_get_time_since() To get time in since format 513 509 * @uses apply_filters() Calls 'bbp_get_forum_last_active' with last … … 516 512 */ 517 513 function bbp_get_forum_last_active_time( $forum_id = 0 ) { 518 514 519 // Verify forum and get last active meta515 // Verify forum and get last active time 520 516 $forum_id = bbp_get_forum_id( $forum_id ); 521 $last_active = get_post_ meta( $forum_id, '_bbp_last_active_time', true);517 $last_active = get_post_field( 'post_modified', $forum_id ); 522 518 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 } 532 } 533 } 519 // Convert to time since format 520 $active_time = bbp_get_time_since( bbp_convert_date( $last_active ) ); 534 521 535 $active_time = !empty( $last_active ) ? bbp_get_time_since( bbp_convert_date( $last_active ) ) : ''; 536 522 // Return the time since 537 523 return apply_filters( 'bbp_get_forum_last_active', $active_time, $forum_id ); 538 524 } 539 525 … … 2226 2212 2227 2213 return apply_filters( 'bbp_get_form_forum_visibility', esc_attr( $forum_visibility ) ); 2228 2214 } 2229 2215 2230 2216 /** 2231 2217 * Output checked value of forum subscription 2232 2218 * -
plugins/bbpress/includes/topics/functions.php
diff --git a/plugins/bbpress/includes/topics/functions.php b/plugins/bbpress/includes/topics/functions.php index d097d22..8dad245 100644
a b 2497 2497 } 2498 2498 2499 2499 /** 2500 * Update the topic s last active date/time (aka freshness)2500 * Update the topic's last active date/time (aka freshness) 2501 2501 * 2502 2502 * @since bbPress (r2680) 2503 2503 * 2504 2504 * @param int $topic_id Optional. Topic id 2505 2505 * @param string $new_time Optional. New time in mysql format 2506 * @uses bbp_ get_topic_id() To get the topic id2506 * @uses bbp_is_reply() To check if the id passed is a reply 2507 2507 * @uses bbp_get_reply_topic_id() To get the reply topic id 2508 * @uses current_time() To get the current time 2508 * @uses bbp_get_topic_id() To get the topic id 2509 * @uses bbp_get_reply_post_type() To get the reply post type 2510 * @uses bbp_get_public_child_last_id() To get the last public reply id 2511 * @uses get_post_field() To get the post_modified date of the topic 2509 2512 * @uses update_post_meta() To update the topic last active meta 2513 * @uses bbp_get_reply_post_type() To get the topic post type 2514 * @uses post_type_supports() To check if the them supports revisions 2515 * @uses remove_post_type_support() To remove support for revisions 2516 * @uses wp_update_post() To update the post_modified date of the topic 2517 * @uses remove_post_type_support() To add support for revisions 2518 * @uses apply_filters() Calls 'bbp_update_topic_last_active' with the new time 2519 * and topic id 2510 2520 * @return bool True on success, false on failure 2511 2521 */ 2512 2522 function bbp_update_topic_last_active_time( $topic_id = 0, $new_time = '' ) { … … 2525 2535 2526 2536 // Update only if published 2527 2537 if ( !empty( $new_time ) ) { 2538 2539 // Update topic's meta - not used since 2.6 2528 2540 update_post_meta( $topic_id, '_bbp_last_active_time', $new_time ); 2541 2542 // Toggle revisions to avoid duplicates 2543 $revisions_removed = false; 2544 if ( post_type_supports( bbp_get_topic_post_type(), 'revisions' ) ) { 2545 $revisions_removed = true; 2546 remove_post_type_support( bbp_get_topic_post_type(), 'revisions' ); 2547 } 2548 2549 // Update topic's post_modified date - since 2.6 2550 wp_update_post( array( 2551 'ID' => $topic_id, 2552 'post_modified' => $new_time, 2553 'post_modified_gmt' => get_gmt_from_date( $new_time ) 2554 ) ); 2555 2556 // Toggle revisions back on 2557 if ( true === $revisions_removed ) { 2558 $revisions_removed = false; 2559 add_post_type_support( bbp_get_topic_post_type(), 'revisions' ); 2560 } 2529 2561 } 2530 2562 2531 2563 return apply_filters( 'bbp_update_topic_last_active_time', $new_time, $topic_id ); … … 3456 3488 <guid><?php bbp_topic_permalink(); ?></guid> 3457 3489 <title><![CDATA[<?php bbp_topic_title(); ?>]]></title> 3458 3490 <link><?php bbp_topic_permalink(); ?></link> 3459 <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>3491 <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_field( 'post_modified', bbp_get_topic_id() ) ); ?></pubDate> 3460 3492 <dc:creator><?php the_author() ?></dc:creator> 3461 3493 3462 3494 <?php if ( !post_password_required() ) : ?> -
plugins/bbpress/includes/topics/template.php
diff --git a/plugins/bbpress/includes/topics/template.php b/plugins/bbpress/includes/topics/template.php index 98fe48d..65da984 100644
a b 97 97 * - New Style: Topics appear as "lead" posts, ahead of replies 98 98 * 99 99 * @since bbPress (r2954) 100 * 100 101 * @param $show_lead Optional. Default false 101 102 * @return bool Yes if the topic appears as a lead, otherwise false 102 103 */ … … 151 152 $default = array( 152 153 'post_type' => bbp_get_topic_post_type(), // Narrow query down to bbPress topics 153 154 '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', 155 'orderby' => 'modified', // 'meta_value', 'author', 'date', 'title', 'modified', 'parent', rand', 156 156 'order' => 'DESC', // 'ASC', 'DESC' 157 157 'posts_per_page' => bbp_get_topics_per_page(), // Topics per page 158 158 'paged' => bbp_get_paged(), // Page Number … … 279 279 $sticky_query = array( 280 280 'post_type' => bbp_get_topic_post_type(), 281 281 'post_parent' => 'any', 282 'meta_key' => '_bbp_last_active_time', 283 'orderby' => 'meta_value', 282 'orderby' => 'modified', 284 283 'order' => 'DESC', 285 284 'include' => $stickies 286 285 ); … … 1773 1772 echo bbp_get_topic_last_active_time( $topic_id ); 1774 1773 } 1775 1774 /** 1776 * Return the topic s last update date/time (aka freshness)1775 * Return the topic's last update date/time (aka freshness) 1777 1776 * 1778 1777 * @since bbPress (r2625) 1779 1778 * 1780 1779 * @param int $topic_id Optional. Topic id 1781 1780 * @uses bbp_get_topic_id() To get topic id 1782 * @uses get_post_meta() To get the topic lst active meta 1783 * @uses bbp_get_topic_last_reply_id() To get topic last reply id 1784 * @uses get_post_field() To get the post date of topic/reply 1785 * @uses bbp_convert_date() To convert date 1781 * @uses get_post_field() To get the post_modified of the topic 1782 * @uses bbp_convert_date() To convert the date 1786 1783 * @uses bbp_get_time_since() To get time in since format 1787 1784 * @uses apply_filters() Calls 'bbp_get_topic_last_active' with topic 1788 1785 * freshness and topic id 1789 1786 * @return string Topic freshness 1790 1787 */ 1791 1788 function bbp_get_topic_last_active_time( $topic_id = 0 ) { 1792 $topic_id = bbp_get_topic_id( $topic_id );1793 1789 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 } 1803 } 1790 // Verify forum and get last active time 1791 $topic_id = bbp_get_topic_id( $topic_id ); 1792 $last_active = get_post_field( 'post_modified', $topic_id ); 1804 1793 1805 $last_active = !empty( $last_active ) ? bbp_get_time_since( bbp_convert_date( $last_active ) ) : ''; 1794 // Convert to time since format 1795 $active_time = bbp_get_time_since( bbp_convert_date( $last_active ) ); 1806 1796 1807 1797 // Return the time since 1808 return apply_filters( 'bbp_get_topic_last_active', $ last_active, $topic_id );1798 return apply_filters( 'bbp_get_topic_last_active', $active_time, $topic_id ); 1809 1799 } 1810 1800 1811 1801 /** Topic Subscriptions *******************************************************/