Changeset 3501
- Timestamp:
- 09/09/2011 09:43:33 PM (14 years ago)
- Location:
- branches/plugin/bbp-includes
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/plugin/bbp-includes/bbp-forum-functions.php
r3445 r3501 387 387 $forum_id = bbp_get_forum_id( $forum_id ); 388 388 389 // Define local variable(s) 390 $children_last_topic = 0; 391 389 392 // Do some calculation if not manually set 390 393 if ( empty( $topic_id ) ) { 391 394 392 395 // Loop through children and add together forum reply counts 393 if ( $children = bbp_forum_query_subforum_ids( $forum_id ) ) 394 foreach ( (array) $children as $child ) 395 $children_last_topic = bbp_update_forum_last_topic_id ( $child ); 396 if ( $children = bbp_forum_query_subforum_ids( $forum_id ) ) { 397 foreach ( (array) $children as $child ) { 398 $children_last_topic = bbp_update_forum_last_topic_id( $child ); // Recursive 399 } 400 } 396 401 397 402 // Setup recent topic query vars … … 405 410 406 411 // Get the most recent topic in this forum_id 407 if ( $recent_topic = get_posts( $post_vars ) ) 412 if ( $recent_topic = get_posts( $post_vars ) ) { 408 413 $topic_id = $recent_topic[0]->ID; 409 } 414 } 415 } 416 417 // Cast as integer in case of empty or string 418 $topic_id = (int) $topic_id; 419 $children_last_topic = (int) $children_last_topic; 410 420 411 421 // If child forums have higher id, use that instead … … 413 423 $topic_id = $children_last_topic; 414 424 415 // Update the last topic id 416 update_post_meta( $forum_id, '_bbp_last_topic_id', (int) $topic_id ); 417 418 return apply_filters( 'bbp_update_forum_last_topic_id', (int) $topic_id, $forum_id ); 425 // Update the last public topic ID 426 if ( bbp_is_topic_published( $topic_id ) ) 427 update_post_meta( $forum_id, '_bbp_last_topic_id', $topic_id ); 428 429 return apply_filters( 'bbp_update_forum_last_topic_id', $topic_id, $forum_id ); 419 430 } 420 431 … … 432 443 * @uses bbp_forum_query_topic_ids() To get the topic ids in the forum 433 444 * @uses bbp_forum_query_last_reply_id() To get the forum's last reply id 445 * @uses bbp_is_reply_published() To make sure the reply is published 434 446 * @uses update_post_meta() To update the forum's last active id meta 435 447 * @uses apply_filters() Calls 'bbp_update_forum_last_reply_id' with the last … … 440 452 $forum_id = bbp_get_forum_id( $forum_id ); 441 453 454 // Define local variable(s) 455 $children_last_reply = 0; 456 442 457 // Do some calculation if not manually set 443 458 if ( empty( $reply_id ) ) { 444 459 445 460 // Loop through children and get the most recent reply id 446 if ( $children = bbp_forum_query_subforum_ids( $forum_id ) ) 447 foreach ( (array) $children as $child ) 448 $children_last_reply = bbp_update_forum_last_reply_id ( $child ); 461 if ( $children = bbp_forum_query_subforum_ids( $forum_id ) ) { 462 foreach ( (array) $children as $child ) { 463 $children_last_reply = bbp_update_forum_last_reply_id( $child ); // Recursive 464 } 465 } 449 466 450 467 // If this forum has topics... … … 459 476 } 460 477 478 // Cast as integer in case of empty or string 479 $reply_id = (int) $reply_id; 480 $children_last_reply = (int) $children_last_reply; 481 461 482 // If child forums have higher ID, check for newer reply id 462 if ( !empty( $children ) && ( (int) $children_last_reply > (int)$reply_id ) )483 if ( !empty( $children ) && ( $children_last_reply > $reply_id ) ) 463 484 $reply_id = $children_last_reply; 464 485 465 // Update the last reply id with what was passed 466 update_post_meta( $forum_id, '_bbp_last_reply_id', (int) $reply_id ); 467 468 return apply_filters( 'bbp_update_forum_last_reply_id', (int) $reply_id, $forum_id ); 486 // Update the last public reply ID 487 if ( bbp_is_reply_published( $reply_id ) ) 488 update_post_meta( $forum_id, '_bbp_last_reply_id', $reply_id ); 489 490 return apply_filters( 'bbp_update_forum_last_reply_id', $reply_id, $forum_id ); 469 491 } 470 492 … … 482 504 * @uses bbp_forum_query_topic_ids() To get the topic ids in the forum 483 505 * @uses bbp_forum_query_last_reply_id() To get the forum's last reply id 506 * @uses get_post_status() To make sure the reply is published 484 507 * @uses update_post_meta() To update the forum's last active id meta 485 508 * @uses apply_filters() Calls 'bbp_update_forum_last_active_id' with the last … … 490 513 $forum_id = bbp_get_forum_id( $forum_id ); 491 514 515 // Define local variable(s) 516 $children_last_active = 0; 517 492 518 // Do some calculation if not manually set 493 519 if ( empty( $active_id ) ) { … … 509 535 } 510 536 537 // Cast as integer in case of empty or string 538 $active_id = (int) $active_id; 539 $children_last_active = (int) $children_last_active; 540 511 541 // If child forums have higher id, use that instead 512 542 if ( !empty( $children ) && ( $children_last_active > $active_id ) ) 513 543 $active_id = $children_last_active; 514 544 515 update_post_meta( $forum_id, '_bbp_last_active_id', (int) $active_id ); 545 // Update only if published 546 if ( 'publish' == get_post_status( $active_id ) ) 547 update_post_meta( $forum_id, '_bbp_last_active_id', (int) $active_id ); 516 548 517 549 return apply_filters( 'bbp_update_forum_last_active_id', (int) $active_id, $forum_id ); … … 540 572 $new_time = get_post_field( 'post_date', bbp_get_forum_last_active_id( $forum_id ) ); 541 573 542 update_post_meta( $forum_id, '_bbp_last_active_time', $new_time ); 574 // Update only if there is a time 575 if ( !empty( $new_time ) ) 576 update_post_meta( $forum_id, '_bbp_last_active_time', $new_time ); 543 577 544 578 return apply_filters( 'bbp_update_forum_last_active', $new_time, $forum_id ); … … 589 623 590 624 // Loop through subforums and add together forum topic counts 591 if ( $children = bbp_forum_query_subforum_ids( $forum_id ) ) 592 foreach ( (array) $children as $child ) 593 $children_topic_count += bbp_update_forum_topic_count( $child ); 625 if ( $children = bbp_forum_query_subforum_ids( $forum_id ) ) { 626 foreach ( (array) $children as $child ) { 627 $children_topic_count += bbp_update_forum_topic_count( $child ); // Recursive 628 } 629 } 594 630 595 631 // Get total topics for this forum … … 726 762 function bbp_update_forum( $args = '' ) { 727 763 $defaults = array( 728 'forum_id' => 0, 729 'post_parent' => 0, 730 'last_topic_id' => 0, 731 'last_reply_id' => 0, 732 'last_active_id' => 0, 733 'last_active_time' => 0, 764 'forum_id' => 0, 765 'post_parent' => 0, 766 'last_topic_id' => 0, 767 'last_reply_id' => 0, 768 'last_active_id' => 0, 769 'last_active_time' => 0, 770 'last_active_status' => 'publish' 734 771 ); 735 772 … … 748 785 $last_active_time = get_post_field( 'post_date', $last_active_id ); 749 786 750 bbp_update_forum_last_active_time( $forum_id, $last_active_time ); 787 if ( 'publish' == $last_active_status ) { 788 bbp_update_forum_last_active_time( $forum_id, $last_active_time ); 789 } 751 790 752 791 // Counts -
branches/plugin/bbp-includes/bbp-reply-functions.php
r3468 r3501 610 610 611 611 // Set transient for throttle check (only on new, not edit) 612 if ( empty( $is_edit ) ) 612 if ( empty( $is_edit ) ) { 613 613 set_transient( '_bbp_' . bbp_current_author_ip() . '_last_posted', time() ); 614 } 614 615 615 616 // Website is optional 616 if ( !empty( $bbp_anonymous_website ) ) 617 if ( !empty( $bbp_anonymous_website ) ) { 617 618 update_post_meta( $reply_id, '_bbp_anonymous_website', $bbp_anonymous_website, false ); 619 } 618 620 619 621 } else { 620 if ( empty( $is_edit ) && !current_user_can( 'throttle' ) ) 622 if ( empty( $is_edit ) && !current_user_can( 'throttle' ) ) { 621 623 update_user_meta( $author_id, '_bbp_last_posted', time() ); 624 } 622 625 } 623 626 … … 628 631 629 632 // Subscribed and unsubscribing 630 if ( true == $subscribed && false == $subscheck ) 633 if ( true == $subscribed && false == $subscheck ) { 631 634 bbp_remove_user_subscription( $author_id, $topic_id ); 632 635 633 636 // Subscribing 634 elseif ( false == $subscribed && true == $subscheck )637 } elseif ( false == $subscribed && true == $subscheck ) { 635 638 bbp_add_user_subscription( $author_id, $topic_id ); 639 } 636 640 } 637 641 … … 728 732 729 733 // Last reply and active ID's 730 bbp_update_topic_last_reply_id 731 bbp_update_topic_last_active_id 734 bbp_update_topic_last_reply_id ( $ancestor, $reply_id ); 735 bbp_update_topic_last_active_id( $ancestor, $active_id ); 732 736 733 737 // Get the last active time if none was passed 734 if ( empty( $last_active_time ) ) 738 $topic_last_active_time = $last_active_time; 739 if ( empty( $last_active_time ) ) { 735 740 $topic_last_active_time = get_post_field( 'post_date', bbp_get_topic_last_active_id( $ancestor ) ); 736 else 737 $topic_last_active_time = $last_active_time; 738 739 bbp_update_topic_last_active_time ( $ancestor, $topic_last_active_time ); 741 } 742 743 // Only update if reply is published 744 if ( bbp_is_reply_published( $reply_id ) ) { 745 bbp_update_topic_last_active_time( $ancestor, $topic_last_active_time ); 746 } 740 747 741 748 // Counts … … 754 761 bbp_update_forum_last_active_id( $ancestor, $active_id ); 755 762 756 if ( empty( $last_active_time ) ) 763 // Get the last active time if none was passed 764 $forum_last_active_time = $last_active_time; 765 if ( empty( $last_active_time ) ) { 757 766 $forum_last_active_time = get_post_field( 'post_date', bbp_get_forum_last_active_id( $ancestor ) ); 758 else 759 $forum_last_active_time = $last_active_time; 760 761 bbp_update_forum_last_active_time( $ancestor, $forum_last_active_time ); 767 } 768 769 // Only update if reply is published 770 if ( bbp_is_reply_published( $reply_id ) ) { 771 bbp_update_forum_last_active_time( $ancestor, $forum_last_active_time ); 772 } 762 773 763 774 // Counts -
branches/plugin/bbp-includes/bbp-reply-template.php
r3492 r3501 697 697 698 698 /** 699 * Is the reply not spam or deleted? 700 * 701 * @since bbPress (r3496) 702 * 703 * @param int $reply_id Optional. Topic id 704 * @uses bbp_get_reply_id() To get the reply id 705 * @uses bbp_get_reply_status() To get the reply status 706 * @return bool True if published, false if not. 707 */ 708 function bbp_is_reply_published( $reply_id = 0 ) { 709 global $bbp; 710 711 $reply_status = bbp_get_reply_status( bbp_get_reply_id( $reply_id ) ); 712 return apply_filters( 'bbp_is_reply_published', 'publish' == $reply_status, $reply_id ); 713 } 714 715 /** 699 716 * Is the reply marked as spam? 700 717 * -
branches/plugin/bbp-includes/bbp-topic-functions.php
r3489 r3501 74 74 $forum_id = bbp_get_topic_forum_id( $topic_id ); 75 75 if ( !empty( $forum_id ) ) 76 bbp_update_forum( $forum_id);76 bbp_update_forum( array( 'forum_id' => $forum_id ) ); 77 77 78 78 // Return new topic ID … … 339 339 340 340 // Get the topic URL 341 $ topic_url = bbp_get_topic_permalink( $topic_id, $redirect_to );341 $redirect_url = bbp_get_topic_permalink( $topic_id, $redirect_to ); 342 342 343 343 // Add view all? 344 if ( bbp_get_view_all() || ( current_user_can( 'moderate' ) && !empty( $view_all ) ) ) 345 $topic_url = bbp_add_view_all( $topic_url ); 344 if ( bbp_get_view_all() || !empty( $view_all ) ) { 345 346 // User can moderate, so redirect to topic with view all set 347 if ( current_user_can( 'moderate' ) ) { 348 $redirect_url = bbp_add_view_all( $redirect_url ); 349 350 // User cannot moderate, so redirect to forum 351 } else { 352 $redirect_url = bbp_get_forum_permalink( $forum_id ); 353 } 354 } 346 355 347 356 // Allow to be filtered 348 $ topic_url = apply_filters( 'bbp_new_topic_redirect_to', $topic_url, $redirect_to );357 $redirect_url = apply_filters( 'bbp_new_topic_redirect_to', $redirect_url, $redirect_to ); 349 358 350 359 /** Successful Save ***********************************************/ 351 360 352 361 // Redirect back to new topic 353 wp_safe_redirect( $ topic_url );362 wp_safe_redirect( $redirect_url ); 354 363 355 364 // For good measure … … 709 718 710 719 // Set transient for throttle check (only on new, not edit) 711 if ( empty( $is_edit ) ) 720 if ( empty( $is_edit ) ) { 712 721 set_transient( '_bbp_' . bbp_current_author_ip() . '_last_posted', time() ); 722 } 713 723 714 724 // Website is optional 715 if ( !empty( $bbp_anonymous_website ) ) 725 if ( !empty( $bbp_anonymous_website ) ) { 716 726 update_post_meta( $topic_id, '_bbp_anonymous_website', $bbp_anonymous_website, false ); 727 } 717 728 } else { 718 if ( empty( $is_edit ) && !current_user_can( 'throttle' ) ) 729 if ( empty( $is_edit ) && !current_user_can( 'throttle' ) ) { 719 730 update_user_meta( $author_id, '_bbp_last_posted', time() ); 731 } 720 732 } 721 733 … … 726 738 727 739 // Subscribed and unsubscribing 728 if ( true == $subscribed && false == $subscheck ) 740 if ( true == $subscribed && false == $subscheck ) { 729 741 bbp_remove_user_subscription( $author_id, $topic_id ); 730 742 731 743 // Subscribing 732 elseif ( false == $subscribed && true == $subscheck )744 } elseif ( false == $subscribed && true == $subscheck ) { 733 745 bbp_add_user_subscription( $author_id, $topic_id ); 746 } 734 747 } 735 748 … … 798 811 $ancestors = array_values( array_unique( array_merge( array( $forum_id ), get_post_ancestors( $topic_id ) ) ) ); 799 812 813 // Topic status 814 $topic_status = get_post_status( $topic_id ); 815 800 816 // If we want a full refresh, unset any of the possibly passed variables 801 if ( true == $refresh ) 817 if ( true == $refresh ) { 802 818 $forum_id = $topic_id = $reply_id = $active_id = $last_active_time = 0; 819 $topic_status = 'publish'; 820 } 803 821 804 822 // Loop through ancestors … … 810 828 // Update the forum 811 829 bbp_update_forum( array( 812 'forum_id' => $ancestor, 813 'last_topic_id' => $topic_id, 814 'last_reply_id' => $reply_id, 815 'last_active_id' => $active_id, 816 'last_active_time' => 0, 830 'forum_id' => $ancestor, 831 'last_topic_id' => $topic_id, 832 'last_reply_id' => $reply_id, 833 'last_active_id' => $active_id, 834 'last_active_time' => 0, 835 'last_active_status' => $topic_status 817 836 ) ); 818 837 } … … 1150 1169 /** Successful Merge **************************************************/ 1151 1170 1171 // Update topic's last meta data 1172 bbp_update_topic_last_reply_id ( $destination_topic->ID ); 1173 bbp_update_topic_last_active_id ( $destination_topic->ID ); 1174 bbp_update_topic_last_active_time( $destination_topic->ID ); 1175 1152 1176 // Send the post parent of the source topic as it has been shifted 1153 1177 // (possibly to a new forum) so we need to update the counts of the … … 2148 2172 $active_id = $topic_id; 2149 2173 2150 update_post_meta( $topic_id, '_bbp_last_active_id', (int) $active_id ); 2174 // Update only if published 2175 if ( 'publish' == get_post_status( $active_id ) ) 2176 update_post_meta( $topic_id, '_bbp_last_active_id', (int) $active_id ); 2151 2177 2152 2178 return apply_filters( 'bbp_update_topic_last_active_id', (int) $active_id, $topic_id ); … … 2178 2204 $new_time = get_post_field( 'post_date', bbp_get_public_child_last_id( $topic_id, bbp_get_reply_post_type() ) ); 2179 2205 2180 update_post_meta( $topic_id, '_bbp_last_active_time', $new_time ); 2206 // Update only if published 2207 if ( !empty( $new_time ) ) 2208 update_post_meta( $topic_id, '_bbp_last_active_time', $new_time ); 2181 2209 2182 2210 return apply_filters( 'bbp_update_topic_last_active_time', $new_time, $topic_id ); … … 2219 2247 $reply_id = 0; 2220 2248 2221 update_post_meta( $topic_id, '_bbp_last_reply_id', (int) $reply_id ); 2249 // Update if reply is published 2250 if ( bbp_is_reply_published( $reply_id ) ) 2251 update_post_meta( $topic_id, '_bbp_last_reply_id', (int) $reply_id ); 2222 2252 2223 2253 return apply_filters( 'bbp_update_topic_last_reply_id', (int) $reply_id, $topic_id ); … … 2667 2697 2668 2698 /** 2669 * Called before deleting a topic 2699 * Called before deleting a topic. 2700 * 2701 * This function is supplemental to the actual topic deletion which is 2702 * handled by WordPress core API functions. It is used to clean up after 2703 * a topic that is being deleted. 2670 2704 * 2671 2705 * @uses bbp_get_topic_id() To get the topic id … … 2679 2713 */ 2680 2714 function bbp_delete_topic( $topic_id = 0 ) { 2715 global $bbp; 2716 2717 // Validate topic ID 2681 2718 $topic_id = bbp_get_topic_id( $topic_id ); 2682 2719 … … 2686 2723 do_action( 'bbp_delete_topic', $topic_id ); 2687 2724 2725 // Valid topic/reply statuses 2726 $post_stati = join( ',', array( 'publish', $bbp->spam_status_id, 'trash' ) ); 2727 2688 2728 // Topic is being permanently deleted, so its replies gotta go too 2689 if ( bbp_has_replies( array( 'post_parent' => $topic_id, 'post_status' => 'publish', 'posts_per_page' => -1 ) ) ) { 2729 if ( bbp_has_replies( array( 2730 'post_type' => bbp_get_reply_post_type(), 2731 'post_status' => $post_stati, 2732 'posts_per_page' => -1, 2733 'meta_query' => array( array( 2734 'key' => '_bbp_topic_id', 2735 'value' => $topic_id, 2736 'compare' => '=' 2737 ) ) 2738 ) ) ) { 2690 2739 while ( bbp_replies() ) { 2691 2740 bbp_the_reply(); … … 2698 2747 * Called before trashing a topic 2699 2748 * 2749 * This function is supplemental to the actual topic being trashed which is 2750 * handled by WordPress core API functions. It is used to clean up after 2751 * a topic that is being trashed. 2752 * 2700 2753 * @uses bbp_get_topic_id() To get the topic id 2701 2754 * @uses bbp_is_topic() To check if the passed id is a topic … … 2709 2762 */ 2710 2763 function bbp_trash_topic( $topic_id = 0 ) { 2764 global $bbp; 2765 2711 2766 $topic_id = bbp_get_topic_id( $topic_id ); 2712 2767 … … 2717 2772 2718 2773 // Topic is being trashed, so its replies are trashed too 2719 if ( bbp_has_replies( array( 'post_parent' => $topic_id, 'post_status' => 'publish', 'posts_per_page' => -1 ) ) ) { 2720 global $bbp; 2774 if ( bbp_has_replies( array( 2775 'post_type' => bbp_get_reply_post_type(), 2776 'post_status' => 'publish', 2777 'posts_per_page' => -1, 2778 'meta_query' => array( array( 2779 'key' => '_bbp_topic_id', 2780 'value' => $topic_id, 2781 'compare' => '=' 2782 ) ) 2783 ) ) ) { 2721 2784 2722 2785 // Prevent debug notices -
branches/plugin/bbp-includes/bbp-topic-template.php
r3496 r3501 956 956 957 957 /** 958 * Is the topic not spam or deleted? 959 * 960 * @since bbPress (r3496) 961 * 962 * @param int $topic_id Optional. Topic id 963 * @uses bbp_get_topic_id() To get the topic id 964 * @uses bbp_get_topic_status() To get the topic status 965 * @return bool True if published, false if not. 966 */ 967 function bbp_is_topic_published( $topic_id = 0 ) { 968 global $bbp; 969 970 $topic_status = bbp_get_topic_status( bbp_get_topic_id( $topic_id ) ); 971 return 'publish' == $topic_status; 972 } 973 974 /** 958 975 * Is the topic marked as spam? 959 976 *
Note: See TracChangeset
for help on using the changeset viewer.