コード例 #1
0
ファイル: cache.php プロジェクト: CompositeUK/clone.bbPress
 /**
  * @covers ::bbp_clean_post_cache
  */
 public function test_bbp_clean_post_cache()
 {
     // Get the topic post type.
     $tpt = bbp_get_topic_post_type();
     // Set up a forum with 1 topic and 1 reply to that topic.
     $f = $this->factory->forum->create();
     $t = $this->factory->topic->create(array('post_parent' => $f, 'topic_meta' => array('forum_id' => $f)));
     $r = $this->factory->topic->create(array('post_parent' => $t, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t)));
     // Make sure we've cached some data.
     bbp_get_all_child_ids($f, $tpt);
     bbp_get_all_child_ids($t, $tpt);
     $this->assertEquals(array($t), wp_cache_get("bbp_parent_all_{$f}_type_{$tpt}_child_ids", 'bbpress_posts'));
     $this->assertEquals(array($r), wp_cache_get("bbp_parent_all_{$t}_type_{$tpt}_child_ids", 'bbpress_posts'));
     // Clean the cache.
     bbp_clean_post_cache($r);
     $this->assertEquals(false, wp_cache_get("bbp_parent_all_{$f}_type_{$tpt}_child_ids", 'bbpress_posts'));
     $this->assertEquals(false, wp_cache_get("bbp_parent_all_{$t}_type_{$tpt}_child_ids", 'bbpress_posts'));
 }
コード例 #2
0
/**
 * Handle the moving of a topic from one forum to another. This includes walking
 * up the old and new branches and updating the counts.
 *
 * @param int $topic_id Topic id
 * @param int $old_forum_id Old forum id
 * @param int $new_forum_id New forum id
 * @uses bbp_get_topic_id() To get the topic id
 * @uses bbp_get_forum_id() To get the forum id
 * @uses bbp_get_stickies() To get the old forums sticky topics
 * @uses delete_post_meta() To delete the forum sticky meta
 * @uses update_post_meta() To update the old forum sticky meta
 * @uses bbp_stick_topic() To stick the topic in the new forum
 * @uses bbp_get_reply_post_type() To get the reply post type
 * @uses bbp_get_all_child_ids() To get the public child ids
 * @uses bbp_update_reply_forum_id() To update the reply forum id
 * @uses bbp_update_topic_forum_id() To update the topic forum id
 * @uses get_post_ancestors() To get the topic's ancestors
 * @uses bbp_is_forum() To check if the ancestor is a forum
 * @uses bbp_update_forum() To update the forum
 */
function bbp_move_topic_handler($topic_id, $old_forum_id, $new_forum_id)
{
    // Validate parameters
    $topic_id = bbp_get_topic_id($topic_id);
    $old_forum_id = bbp_get_forum_id($old_forum_id);
    $new_forum_id = bbp_get_forum_id($new_forum_id);
    // Update topic forum's ID
    bbp_update_topic_forum_id($topic_id, $new_forum_id);
    /** Stickies **************************************************************/
    // Get forum stickies
    $old_stickies = bbp_get_stickies($old_forum_id);
    // Only proceed if stickies are found
    if (!empty($old_stickies)) {
        // Define local variables
        $updated_stickies = array();
        // Loop through stickies of forum and add misses to the updated array
        foreach ((array) $old_stickies as $sticky_topic_id) {
            if ($topic_id !== $sticky_topic_id) {
                $updated_stickies[] = $sticky_topic_id;
            }
        }
        // If stickies are different, update or delete them
        if ($updated_stickies !== $old_stickies) {
            // No more stickies so delete the meta
            if (empty($updated_stickies)) {
                delete_post_meta($old_forum_id, '_bbp_sticky_topics');
                // Still stickies so update the meta
            } else {
                update_post_meta($old_forum_id, '_bbp_sticky_topics', $updated_stickies);
            }
            // Topic was sticky, so restick in new forum
            bbp_stick_topic($topic_id);
        }
    }
    /** Topic Replies *********************************************************/
    // Get the topics replies
    $replies = bbp_get_all_child_ids($topic_id, bbp_get_reply_post_type());
    // Update the forum_id of all replies in the topic
    foreach ($replies as $reply_id) {
        bbp_update_reply_forum_id($reply_id, $new_forum_id);
    }
    /** Old forum_id **********************************************************/
    // Get topic ancestors
    $old_forum_ancestors = array_values(array_unique(array_merge(array($old_forum_id), (array) get_post_ancestors($old_forum_id))));
    // Loop through ancestors and update them
    if (!empty($old_forum_ancestors)) {
        foreach ($old_forum_ancestors as $ancestor) {
            if (bbp_is_forum($ancestor)) {
                bbp_update_forum(array('forum_id' => $ancestor));
            }
        }
    }
    /** New forum_id **********************************************************/
    // Make sure we're not walking twice
    if (!in_array($new_forum_id, $old_forum_ancestors)) {
        // Get topic ancestors
        $new_forum_ancestors = array_values(array_unique(array_merge(array($new_forum_id), (array) get_post_ancestors($new_forum_id))));
        // Make sure we're not walking twice
        $new_forum_ancestors = array_diff($new_forum_ancestors, $old_forum_ancestors);
        // Loop through ancestors and update them
        if (!empty($new_forum_ancestors)) {
            foreach ($new_forum_ancestors as $ancestor) {
                if (bbp_is_forum($ancestor)) {
                    bbp_update_forum(array('forum_id' => $ancestor));
                }
            }
        }
    }
}
コード例 #3
0
/**
 * Returns the forum's subforum ids
 *
 * Only forums with published status are returned
 *
 * @since bbPress (r2908)
 *
 * @param int $forum_id Forum id
 * @uses bbp_get_forum_post_type() To get the forum post type
 * @uses bbp_get_public_child_ids() To get the forum ids
 * @uses apply_filters() Calls 'bbp_forum_query_subforum_ids' with the subforum
 *                        ids and forum id
 */
function bbp_forum_query_subforum_ids($forum_id)
{
    $subforum_ids = bbp_get_all_child_ids($forum_id, bbp_get_forum_post_type());
    //usort( $subforum_ids, '_bbp_forum_query_usort_subforum_ids' );
    return apply_filters('bbp_get_forum_subforum_ids', $subforum_ids, $forum_id);
}
コード例 #4
0
/**
 * Get the position of a reply by querying the DB directly for the replies
 * of a given topic.
 *
 * @since bbPress (r3933)
 *
 * @param int $reply_id
 * @param int $topic_id
 */
function bbp_get_reply_position_raw($reply_id = 0, $topic_id = 0)
{
    // Get required data
    $reply_id = bbp_get_reply_id($reply_id);
    $topic_id = !empty($topic_id) ? bbp_get_topic_id($topic_id) : bbp_get_reply_topic_id($reply_id);
    $reply_position = 0;
    // If reply is actually the first post in a topic, return 0
    if ($reply_id !== $topic_id) {
        // Make sure the topic has replies before running another query
        $reply_count = bbp_get_topic_reply_count($topic_id, false);
        if (!empty($reply_count)) {
            // Get reply id's
            $topic_replies = bbp_get_all_child_ids($topic_id, bbp_get_reply_post_type());
            if (!empty($topic_replies)) {
                // Reverse replies array and search for current reply position
                $topic_replies = array_reverse($topic_replies);
                $reply_position = array_search((string) $reply_id, $topic_replies);
                // Bump the position to compensate for the lead topic post
                $reply_position++;
            }
        }
    }
    return (int) $reply_position;
}
コード例 #5
0
ファイル: query.php プロジェクト: joeyblake/bbpress
 /**
  * @covers ::bbp_get_all_child_ids
  */
 public function test_bbp_get_all_child_ids()
 {
     $f = $this->factory->forum->create();
     // Test initial forum public child counts
     $count = count(bbp_get_all_child_ids($f, bbp_get_forum_post_type()));
     $this->assertSame(0, $count);
     $count = count(bbp_get_all_child_ids($f, bbp_get_topic_post_type()));
     $this->assertSame(0, $count);
     /* Sub-Forums *********************************************************/
     $this->factory->forum->create_many(3, array('post_parent' => $f));
     $this->factory->forum->create(array('post_parent' => $f, 'post_status' => bbp_get_private_status_id()));
     $count = count(bbp_get_all_child_ids($f, bbp_get_forum_post_type()));
     $this->assertSame(4, $count);
     $this->factory->forum->create_many(2, array('post_parent' => $f));
     $count = count(bbp_get_all_child_ids($f, bbp_get_forum_post_type()));
     $this->assertSame(6, $count);
     /* Topics *************************************************************/
     $t1 = $this->factory->topic->create_many(3, array('post_parent' => $f, 'topic_meta' => array('forum_id' => $f)));
     $this->factory->topic->create(array('post_parent' => $f, 'post_status' => bbp_get_spam_status_id(), 'topic_meta' => array('forum_id' => $f)));
     $count = count(bbp_get_all_child_ids($f, bbp_get_topic_post_type()));
     $this->assertSame(4, $count);
     $this->factory->topic->create_many(2, array('post_parent' => $f, 'topic_meta' => array('forum_id' => $f)));
     $count = count(bbp_get_all_child_ids($f, bbp_get_topic_post_type()));
     $this->assertSame(6, $count);
     $this->factory->topic->create(array('post_parent' => $f, 'post_status' => bbp_get_pending_status_id(), 'topic_meta' => array('forum_id' => $f)));
     $count = count(bbp_get_all_child_ids($f, bbp_get_topic_post_type()));
     $this->assertSame(7, $count);
     /* Replies ************************************************************/
     $this->factory->reply->create_many(3, array('post_parent' => $t1[0], 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t1[0])));
     $this->factory->reply->create(array('post_parent' => $t1[0], 'post_status' => bbp_get_spam_status_id(), 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t1[0])));
     $count = count(bbp_get_all_child_ids($t1[0], bbp_get_reply_post_type()));
     $this->assertSame(4, $count);
     $this->factory->reply->create_many(2, array('post_parent' => $t1[0], 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t1[0])));
     $count = count(bbp_get_all_child_ids($t1[0], bbp_get_reply_post_type()));
     $this->assertSame(6, $count);
     $this->factory->reply->create(array('post_parent' => $t1[0], 'post_status' => bbp_get_pending_status_id(), 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t1[0])));
     $count = count(bbp_get_all_child_ids($t1[0], bbp_get_reply_post_type()));
     $this->assertSame(7, $count);
 }
コード例 #6
0
ファイル: topic.php プロジェクト: joeyblake/bbpress
 /**
  * @covers ::bbp_delete_topic_replies
  */
 public function test_bbp_delete_topic_replies()
 {
     $f = $this->factory->forum->create();
     $t = $this->factory->topic->create(array('post_parent' => $f, 'topic_meta' => array('forum_id' => $f)));
     $r = $this->factory->reply->create_many(2, array('post_parent' => $t, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t)));
     $this->assertSame(2, bbp_get_topic_reply_count($t, true));
     bbp_delete_topic_replies($t);
     $count = count(bbp_get_all_child_ids($t, bbp_get_reply_post_type()));
     $this->assertSame(0, $count);
 }
コード例 #7
0
<?php

/**
 * Topics Loop - Single
 *
 * @package bbPress
 * @subpackage Theme
 */
$date = bbp_get_reply_post_date();
$cDate = DateTime::createFromFormat('F j, Y \\a\\t g:ia', $date);
if ($replies = bbp_get_all_child_ids($post->ID, 'reply')) {
    $reply = $replies[0];
    $post = get_post($reply);
    setup_postdata($post);
    $date = $post->post_modified;
    $cDate = DateTime::createFromFormat('Y-m-d H:i:s', $date);
    wp_reset_postdata();
}
?>

<tr>
	<td class="message60">
		<p><a class="bbp-topic-permalink" href="<?php 
bbp_topic_permalink();
?>
"><?php 
bbp_topic_title();
?>
</a></p>
		<p><?php 
bbp_topic_excerpt();
コード例 #8
0
/**
 * Handle the moving of a topic from one forum to another. This includes walking
 * up the old and new branches and updating the counts.
 *
 * @since 2.0.0 bbPress (r2907)
 *
 * @param int $topic_id     The topic id.
 * @param int $old_forum_id Old forum id.
 * @param int $new_forum_id New forum id.
 * @uses bbp_get_topic_id() To get the topic id
 * @uses bbp_get_forum_id() To get the forum id
 * @uses bbp_clean_post_cache() To clean the old and new forum post caches
 * @uses bbp_update_topic_forum_id() To update the topic forum id
 * @uses wp_update_post() To update the topic post parent`
 * @uses bbp_get_stickies() To get the old forums sticky topics
 * @uses delete_post_meta() To delete the forum sticky meta
 * @uses update_post_meta() To update the old forum sticky meta
 * @uses bbp_stick_topic() To stick the topic in the new forum
 * @uses bbp_get_reply_post_type() To get the reply post type
 * @uses bbp_get_all_child_ids() To get all the child ids
 * @uses bbp_update_reply_forum_id() To update the reply forum id
 * @uses get_post_ancestors() To get the topic's ancestors
 * @uses bbp_get_public_child_ids() To get all the public child ids
 * @uses get_post_field() To get the topic's post status
 * @uses bbp_get_public_status_id() To get the public status id
 * @uses bbp_decrease_forum_topic_count() To bump the forum topic count by -1
 * @uses bbp_bump_forum_reply_count() To bump the forum reply count
 * @uses bbp_increase_forum_topic_count() To bump the forum topic count by 1
 * @uses bbp_decrease_forum_topic_count_hidden() To bump the forum topic hidden count by -1
 * @uses bbp_increase_forum_topic_count_hidden() To bump the forum topic hidden count by 1
 * @uses bbp_is_forum() To check if the ancestor is a forum
 * @uses bbp_update_forum() To update the forum
 */
function bbp_move_topic_handler($topic_id, $old_forum_id, $new_forum_id)
{
    // Validate parameters
    $topic_id = bbp_get_topic_id($topic_id);
    $old_forum_id = bbp_get_forum_id($old_forum_id);
    $new_forum_id = bbp_get_forum_id($new_forum_id);
    // Clean old and new forum caches before proceeding, to ensure subsequent
    // calls to forum objects are using updated data.
    bbp_clean_post_cache($old_forum_id);
    bbp_clean_post_cache($new_forum_id);
    // Update topic forum's ID
    bbp_update_topic_forum_id($topic_id, $new_forum_id);
    // Update topic post parent with the new forum ID
    wp_update_post(array('ID' => $topic_id, 'post_parent' => $new_forum_id));
    /** Stickies **************************************************************/
    // Get forum stickies
    $old_stickies = bbp_get_stickies($old_forum_id);
    // Only proceed if stickies are found
    if (!empty($old_stickies)) {
        // Define local variables
        $updated_stickies = array();
        // Loop through stickies of forum and add misses to the updated array
        foreach ((array) $old_stickies as $sticky_topic_id) {
            if ($topic_id !== $sticky_topic_id) {
                $updated_stickies[] = $sticky_topic_id;
            }
        }
        // If stickies are different, update or delete them
        if ($updated_stickies !== $old_stickies) {
            // No more stickies so delete the meta
            if (empty($updated_stickies)) {
                delete_post_meta($old_forum_id, '_bbp_sticky_topics');
                // Still stickies so update the meta
            } else {
                update_post_meta($old_forum_id, '_bbp_sticky_topics', $updated_stickies);
            }
            // Topic was sticky, so restick in new forum
            bbp_stick_topic($topic_id);
        }
    }
    /** Topic Replies *********************************************************/
    // Get the topics replies
    $replies = bbp_get_all_child_ids($topic_id, bbp_get_reply_post_type());
    // Update the forum_id of all replies in the topic
    foreach ($replies as $reply_id) {
        bbp_update_reply_forum_id($reply_id, $new_forum_id);
    }
    /** Old forum_id **********************************************************/
    // Get topic ancestors
    $old_forum_ancestors = array_values(array_unique(array_merge(array($old_forum_id), (array) get_post_ancestors($old_forum_id))));
    // Get reply count.
    $public_reply_count = count(bbp_get_public_child_ids($topic_id, bbp_get_reply_post_type()));
    // Topic status.
    $topic_status = get_post_field('post_status', $topic_id);
    // Update old/new forum counts.
    if ($topic_status === bbp_get_public_status_id()) {
        // Update old forum counts.
        bbp_decrease_forum_topic_count($old_forum_id);
        bbp_bump_forum_reply_count($old_forum_id, -$public_reply_count);
        // Update new forum counts.
        bbp_increase_forum_topic_count($new_forum_id);
        bbp_bump_forum_reply_count($new_forum_id, $public_reply_count);
    } else {
        // Update old forum counts.
        bbp_decrease_forum_topic_count_hidden($old_forum_id);
        // Update new forum counts.
        bbp_increase_forum_topic_count_hidden($new_forum_id);
    }
    // Loop through ancestors and update them
    if (!empty($old_forum_ancestors)) {
        foreach ($old_forum_ancestors as $ancestor) {
            if (bbp_is_forum($ancestor)) {
                bbp_update_forum(array('forum_id' => $ancestor));
            }
        }
    }
    /** New forum_id **********************************************************/
    // Make sure we're not walking twice
    if (!in_array($new_forum_id, $old_forum_ancestors)) {
        // Get topic ancestors
        $new_forum_ancestors = array_values(array_unique(array_merge(array($new_forum_id), (array) get_post_ancestors($new_forum_id))));
        // Make sure we're not walking twice
        $new_forum_ancestors = array_diff($new_forum_ancestors, $old_forum_ancestors);
        // Loop through ancestors and update them
        if (!empty($new_forum_ancestors)) {
            foreach ($new_forum_ancestors as $ancestor) {
                if (bbp_is_forum($ancestor)) {
                    bbp_update_forum(array('forum_id' => $ancestor));
                }
            }
        }
    }
}
コード例 #9
0
/**
 * Returns the forum's subforum ids
 *
 * Only forums with published status are returned
 *
 * @since 2.0.0 bbPress (r2908)
 *
 * @param int $forum_id Forum id
 * @uses bbp_get_forum_post_type() To get the forum post type
 * @uses bbp_get_all_child_ids() To get the forum ids
 * @uses apply_filters() Calls 'bbp_forum_query_subforum_ids' with the subforum
 *                        ids and forum id
 */
function bbp_forum_query_subforum_ids($forum_id)
{
    $subforum_ids = bbp_get_all_child_ids($forum_id, bbp_get_forum_post_type());
    return (array) apply_filters('bbp_forum_query_subforum_ids', $subforum_ids, $forum_id);
}