Ticket #1925: 1925.003.patch
File 1925.003.patch, 14.6 KB (added by , 11 years ago) |
---|
-
includes/common/functions.php
364 364 } 365 365 366 366 /** 367 * Fix post modified times on post save 368 * 369 * When a forum or topic is update, 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' 374 * 375 * @since bbPress (rXXXX) 376 * 377 * @param array $data Post data 378 * @param array $postarr Original post array (includes post id) 379 * @uses bbp_get_topic_post_type() To get the topic post type 380 * @uses bbp_get_reply_post_type() To get the reply post type 381 * @uses bbp_is_post_request() To determine if we're in a POST request 382 * @uses update_post_meta() To update the '_bbp_last_edit_time_gmt' post meta field 383 * @uses get_post_field() To get the current post_modified(_gmt) fields 384 * @return array 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'] ) ) 390 return $data; 391 392 // Post is not a forum or topic, return 393 if ( !in_array( $data['post_type'], array( bbp_get_forum_post_type(), bbp_get_topic_post_type() ) ) ) 394 return $data; 395 396 // Are we editing? 397 if ( !bbp_is_post_request() && !in_array( $_POST['action'], array( 'bbp-edit-forum', 'bbp-edit-topic', 'editpost' ) ) ) 398 return $data; 399 400 // Set the last edited time in post meta 401 update_post_meta( $postarr['ID'], '_bbp_last_edit_time_gmt', $data['post_modified_gmt'] ); 402 403 // The post is being updated. It is a topic or a reply and is written by an anonymous user. 404 // Set the post_modified(_gmt) time back to their current values 405 $data['post_modified'] = get_post_field( 'post_modified', $postarr['ID'], 'raw' ); 406 $data['post_modified_gmt'] = get_post_field( 'post_modified_gmt', $postarr['ID'], 'raw' ); 407 408 return $data; 409 } 410 411 /** 367 412 * Check the date against the _bbp_edit_lock setting. 368 413 * 369 414 * @since bbPress (r3133) … … 1426 1471 return apply_filters( 'bbp_get_all_child_ids', $child_ids, (int) $parent_id, $post_type ); 1427 1472 } 1428 1473 1474 /** 1475 * Updates the post_modified and post_modified_gmt fields of a topic/forum. 1476 * 1477 * This is just a helper function, with minimal data validation. Therefore, 1478 * you will be better served using the appropriate wrapper funtions 1479 * bbp_update_topic_post_modified() or bbp_update_forum_post_modified(). 1480 * Proper data validation should be performed before calling these functions. 1481 * See bbp_update_forum_last_active_time() or bbp_update_topic_last_active_time() 1482 * for examples on how to use. 1483 * 1484 * @since bbPress (rXXXX) 1485 * @access private 1486 * 1487 * @global WPDB $wpdb 1488 * @param int $post_id Forum/topic post_id 1489 * @param string $post_modified MySQL timestamp 'Y-m-d H:i:s' 1490 * @param string $post_modified_gmt MySQL timestamp 'Y-m-d H:i:s'. Defaults to false. 1491 * @param string $type 'topic' or 'forum' 1492 * @uses wpdb::update() To update the post_modified/post_modified_gmt fields 1493 * @return int|bool The number of rows updated, or false on error. 1494 */ 1495 function bbp_update_post_modified_helper( $post_id, $post_modified, $post_modified_gmt = false, $type ) { 1496 1497 // Validate the post_id 1498 $post_id = call_user_func( "bbp_get_{$type}_id", $post_id ); 1499 1500 // Get the post_type. This is to mitigate the likelihood of getting a valid 1501 // post_id that's in the wrong post_type, and not the one we'd like to update 1502 $post_type = call_user_func( "bbp_get_{$type}_post_type" ); 1503 1504 // Make sure we have at least one date 1505 if ( empty( $post_modified ) && empty( $post_modified_gmt ) ) { 1506 return false; 1507 1508 // No post_modified_gmt provided 1509 } elseif ( empty( $post_modified_gmt ) ) { 1510 $post_modified = date( 'Y-m-d H:i:s', strtotime( $post_modified ) ); 1511 $post_modified_gmt = gmdate( 'Y-m-d H:i:s', strtotime( $post_modified ) ); 1512 1513 // No post_modified provided 1514 } elseif ( empty( $post_modified ) ) { 1515 $post_modified_gmt = gmdate( 'Y-m-d H:i:s', strtotime( $post_modified_gmt ) ); 1516 $post_modified = date( 'Y-m-d H:i:s', strtotime( $post_modified_gmt ) ); 1517 1518 // Looks good, but let's validate 1519 } else { 1520 $post_modified = date( 'Y-m-d H:i:s', strtotime( $post_modified ) ); 1521 $post_modified_gmt = gmdate( 'Y-m-d H:i:s', strtotime( $post_modified_gmt ) ); 1522 } 1523 1524 // Grab the database global 1525 global $wpdb; 1526 1527 // Update the, uh..., date? 1528 return $wpdb->update( 1529 // Table 1530 $wpdb->posts, 1531 // Field/value pairs to update 1532 array( 1533 'post_modified' => $post_modified, 1534 'post_modified_gmt' => $post_modified_gmt 1535 ), 1536 // Where conditions 1537 array( 1538 'ID' => $post_id, 1539 'post_type' => $post_type 1540 ), 1541 // Value formats for wpdb::prepare 1542 array( 1543 '%s', 1544 '%s' 1545 ), 1546 // Value formats for where conditions 1547 array( 1548 '%d', 1549 '%s' 1550 ) 1551 ); 1552 } 1553 1429 1554 /** Globals *******************************************************************/ 1430 1555 1431 1556 /** … … 1531 1656 1532 1657 // Forum/Topic/Reply Feed 1533 1658 if ( isset( $query_vars['post_type'] ) ) { 1534 1659 1535 1660 // Supported select query vars 1536 1661 $select_query_vars = array( 1537 1662 'p' => false, -
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' => 'modified', 748 747 'order' => 'DESC', 749 748 ); 750 749 break; -
includes/core/filters.php
51 51 // Fix post author id for anonymous posts (set it back to 0) when the post status is changed 52 52 add_filter( 'wp_insert_post_data', 'bbp_fix_post_author', 30, 2 ); 53 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', 30, 2 ); 56 54 57 // Force comments_status on bbPress post types 55 58 add_filter( 'comments_open', 'bbp_force_comment_status' ); 56 59 -
includes/forums/functions.php
1128 1128 $post_vars = array( 1129 1129 'post_parent' => $forum_id, 1130 1130 'post_type' => bbp_get_topic_post_type(), 1131 'meta_key' => '_bbp_last_active_time', 1132 'orderby' => 'meta_value', 1131 'orderby' => 'modified', 1133 1132 'numberposts' => 1 1134 1133 ); 1135 1134 … … 1283 1282 } 1284 1283 1285 1284 /** 1285 * Updates the post_modified/post_modified_gmt fields of a forum. 1286 * 1287 * @since bbPress (rXXXX) 1288 * 1289 * @param int $post_id Forum post_id 1290 * @param string $post_modified MySQL timestamp 'Y-m-d H:i:s' 1291 * @param string $post_modified_gmt MySQL timestamp 'Y-m-d H:i:s'. Defaults to false. 1292 * @uses bbp_update_post_modified_helper() To update the post_modified/post_modified_gmt fields 1293 * @return int|bool The number of rows updated, or false on error. 1294 */ 1295 function bbp_update_forum_post_modified( $forum_id, $post_modified, $post_modified_gmt = false ) { 1296 1297 // Validate the forum_id 1298 $topic_id = bbp_get_forum_id( $forum_id ); 1299 1300 return bbp_update_post_modified_helper( $forum_id, $post_modified, $post_modified_gmt, 'forum' ); 1301 } 1302 1303 /** 1286 1304 * Update the forums last active date/time (aka freshness) 1287 1305 * 1288 1306 * @since bbPress (r2680) … … 1305 1323 $new_time = get_post_field( 'post_date', bbp_get_forum_last_active_id( $forum_id ) ); 1306 1324 1307 1325 // Update only if there is a time 1308 if ( !empty( $new_time ) ) 1326 if ( !empty( $new_time ) ) { 1309 1327 update_post_meta( $forum_id, '_bbp_last_active_time', $new_time ); 1328 bbp_update_forum_post_modified( $forum_id, $new_time ); 1329 } 1310 1330 1311 1331 return (int) apply_filters( 'bbp_update_forum_last_active', $new_time, $forum_id ); 1312 1332 } -
includes/forums/template.php
432 432 * 433 433 * @param int $forum_id Optional. Forum id 434 434 * @uses bbp_get_forum_id() To get the forum id 435 * @uses get_post_ meta() To retrieve forum last active meta435 * @uses get_post_field() To retrieve forum last active meta 436 436 * @uses bbp_get_forum_last_reply_id() To get forum's last reply id 437 437 * @uses get_post_field() To get the post date of the reply 438 438 * @uses bbp_get_forum_last_topic_id() To get forum's last topic id … … 448 448 449 449 // Verify forum and get last active meta 450 450 $forum_id = bbp_get_forum_id( $forum_id ); 451 $last_active = get_post_ meta( $forum_id, '_bbp_last_active_time', true);451 $last_active = get_post_field( 'post_modified', $forum_id ); 452 452 453 453 if ( empty( $last_active ) ) { 454 454 $reply_id = bbp_get_forum_last_reply_id( $forum_id ); -
includes/replies/functions.php
870 870 update_post_meta( $reply_id, '_bbp_author_ip', bbp_current_author_ip(), false ); 871 871 872 872 // Last active time 873 $last_active_time = current_time( 'mysql');873 $last_active_time = get_post_field( 'post_date', $reply_id ); 874 874 875 875 // Walk up ancestors and do the dirty work 876 876 bbp_update_reply_walker( $reply_id, $last_active_time, $forum_id, $topic_id, false ); … … 1399 1399 bbp_update_reply_to( $child->ID, $parent ); 1400 1400 1401 1401 // Remove reply_to from moved reply 1402 delete_post_meta( $move_reply->ID, '_bbp_reply_to' ); 1402 delete_post_meta( $move_reply->ID, '_bbp_reply_to' ); 1403 1403 1404 1404 // It is a new topic and we need to set some default metas to make 1405 1405 // the topic display in bbp_has_topics() list -
includes/topics/functions.php
887 887 update_post_meta( $topic_id, '_bbp_author_ip', bbp_current_author_ip(), false ); 888 888 889 889 // Last active time 890 $last_active = current_time( 'mysql');890 $last_active = get_post_field( 'post_date', $topic_id ); 891 891 892 892 // Reply topic meta 893 893 bbp_update_topic_last_reply_id ( $topic_id, 0 ); … … 965 965 'last_topic_id' => $topic_id, 966 966 'last_reply_id' => $reply_id, 967 967 'last_active_id' => $active_id, 968 'last_active_time' => 0,968 'last_active_time' => $last_active_time, 969 969 'last_active_status' => $topic_status 970 970 ) ); 971 971 } … … 2494 2494 } 2495 2495 2496 2496 /** 2497 * Updates the post_modified/post_modified_gmt fields of a topic. 2498 * 2499 * @since bbPress (rXXXX) 2500 * 2501 * @param int $post_id Topic post_id 2502 * @param string $post_modified MySQL timestamp 'Y-m-d H:i:s' 2503 * @param string $post_modified_gmt MySQL timestamp 'Y-m-d H:i:s'. Defaults to false. 2504 * @uses bbp_update_post_modified_helper() To update the post_modified/post_modified_gmt fields 2505 * @return int|bool The number of rows updated, or false on error. 2506 */ 2507 function bbp_update_topic_post_modified( $topic_id, $post_modified, $post_modified_gmt = false ) { 2508 2509 // Validate the topic_id 2510 $topic_id = bbp_get_topic_id( $topic_id ); 2511 2512 return bbp_update_post_modified_helper( $topic_id, $post_modified, $post_modified_gmt, 'topic' ); 2513 } 2514 2515 /** 2497 2516 * Update the topics last active date/time (aka freshness) 2498 2517 * 2499 2518 * @since bbPress (r2680) … … 2523 2542 // Update only if published 2524 2543 if ( !empty( $new_time ) ) { 2525 2544 update_post_meta( $topic_id, '_bbp_last_active_time', $new_time ); 2545 bbp_update_topic_post_modified( $topic_id, $new_time ); 2526 2546 } 2527 2547 2528 2548 return apply_filters( 'bbp_update_topic_last_active_time', $new_time, $topic_id ); … … 3453 3473 <guid><?php bbp_topic_permalink(); ?></guid> 3454 3474 <title><![CDATA[<?php bbp_topic_title(); ?>]]></title> 3455 3475 <link><?php bbp_topic_permalink(); ?></link> 3456 <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>3476 <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_field( 'post_modified', bbp_get_topic_id() ) ); ?></pubDate> 3457 3477 <dc:creator><?php the_author() ?></dc:creator> 3458 3478 3459 3479 <?php if ( !post_password_required() ) : ?> -
includes/topics/template.php
95 95 $default = array( 96 96 'post_type' => bbp_get_topic_post_type(), // Narrow query down to bbPress topics 97 97 'post_parent' => $default_post_parent, // Forum ID 98 'meta_key' => '_bbp_last_active_time', // Make sure topic has some last activity time 99 'orderby' => 'meta_value', // 'meta_value', 'author', 'date', 'title', 'modified', 'parent', rand', 98 'orderby' => 'modified', // 'meta_value', 'author', 'date', 'title', 'modified', 'parent', rand', 100 99 'order' => 'DESC', // 'ASC', 'DESC' 101 100 'posts_per_page' => bbp_get_topics_per_page(), // Topics per page 102 101 'paged' => bbp_get_paged(), // Page Number … … 223 222 $sticky_query = array( 224 223 'post_type' => bbp_get_topic_post_type(), 225 224 'post_parent' => 'any', 226 'meta_key' => '_bbp_last_active_time', 227 'orderby' => 'meta_value', 225 'orderby' => 'modified', 228 226 'order' => 'DESC', 229 227 'include' => $stickies 230 228 ); … … 1716 1714 * 1717 1715 * @param int $topic_id Optional. Topic id 1718 1716 * @uses bbp_get_topic_id() To get topic id 1719 * @uses get_post_ meta() To get the topic lst active meta1717 * @uses get_post_field() To get the topic lst active meta 1720 1718 * @uses bbp_get_topic_last_reply_id() To get topic last reply id 1721 1719 * @uses get_post_field() To get the post date of topic/reply 1722 1720 * @uses bbp_convert_date() To convert date … … 1729 1727 $topic_id = bbp_get_topic_id( $topic_id ); 1730 1728 1731 1729 // Try to get the most accurate freshness time possible 1732 $last_active = get_post_ meta( $topic_id, '_bbp_last_active_time', true);1730 $last_active = get_post_field( 'post_modified', $topic_id ); 1733 1731 if ( empty( $last_active ) ) { 1734 1732 $reply_id = bbp_get_topic_last_reply_id( $topic_id ); 1735 1733 if ( !empty( $reply_id ) ) {