コード例 #1
0
ファイル: counts.php プロジェクト: joeyblake/bbpress
 /**
  * @covers ::bbp_topic_reply_count_hidden
  * @covers ::bbp_get_topic_reply_count_hidden
  */
 public function test_bbp_get_topic_reply_count_hidden()
 {
     $f = $this->factory->forum->create();
     $int_value = 3;
     $formatted_value = bbp_number_format($int_value);
     $t = $this->factory->topic->create(array('post_parent' => $f, 'topic_meta' => array('forum_id' => $f)));
     $r = $this->factory->reply->create_many($int_value, array('post_parent' => $t, 'post_status' => bbp_get_spam_status_id(), 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t)));
     bbp_update_topic_reply_count_hidden($t);
     bbp_spam_reply($r[1]);
     // Output
     $this->expectOutputString($formatted_value);
     bbp_topic_reply_count_hidden($t);
     // Formatted string
     $count = bbp_get_topic_reply_count_hidden($t, false);
     $this->assertSame($formatted_value, $count);
     // Integer
     $count = bbp_get_topic_reply_count_hidden($t, true);
     $this->assertSame($int_value, $count);
 }
コード例 #2
0
/**
 * Fix counts on topic split
 *
 * When a topic is split, update the counts of source and destination topic
 * and their forums.
 *
 * @since bbPress (r2756)
 *
 * @param int $from_reply_id From reply id
 * @param int $source_topic_id Source topic id
 * @param int $destination_topic_id Destination topic id
 * @uses bbp_update_forum_topic_count() To update the forum topic counts
 * @uses bbp_update_forum_reply_count() To update the forum reply counts
 * @uses bbp_update_topic_reply_count() To update the topic reply counts
 * @uses bbp_update_topic_voice_count() To update the topic voice counts
 * @uses bbp_update_topic_reply_count_hidden() To update the topic hidden reply
 *                                              count
 * @uses do_action() Calls 'bbp_split_topic_count' with the from reply id,
 *                    source topic id & destination topic id
 */
function bbp_split_topic_count($from_reply_id, $source_topic_id, $destination_topic_id)
{
    // Forum Topic Counts
    bbp_update_forum_topic_count(bbp_get_topic_forum_id($destination_topic_id));
    // Forum Reply Counts
    bbp_update_forum_reply_count(bbp_get_topic_forum_id($destination_topic_id));
    // Topic Reply Counts
    bbp_update_topic_reply_count($source_topic_id);
    bbp_update_topic_reply_count($destination_topic_id);
    // Topic Hidden Reply Counts
    bbp_update_topic_reply_count_hidden($source_topic_id);
    bbp_update_topic_reply_count_hidden($destination_topic_id);
    // Topic Voice Counts
    bbp_update_topic_voice_count($source_topic_id);
    bbp_update_topic_voice_count($destination_topic_id);
    do_action('bbp_split_topic_count', $from_reply_id, $source_topic_id, $destination_topic_id);
}
コード例 #3
0
/**
 * Fix counts on reply move
 *
 * When a reply is moved, update the counts of source and destination topic
 * and their forums.
 *
 * @since bbPress (r4521)
 *
 * @param int $move_reply_id Move reply id
 * @param int $source_topic_id Source topic id
 * @param int $destination_topic_id Destination topic id
 * @uses bbp_update_forum_topic_count() To update the forum topic counts
 * @uses bbp_update_forum_reply_count() To update the forum reply counts
 * @uses bbp_update_topic_reply_count() To update the topic reply counts
 * @uses bbp_update_topic_voice_count() To update the topic voice counts
 * @uses bbp_update_topic_reply_count_hidden() To update the topic hidden reply
 *                                              count
 * @uses do_action() Calls 'bbp_move_reply_count' with the move reply id,
 *                    source topic id & destination topic id
 */
function bbp_move_reply_count($move_reply_id, $source_topic_id, $destination_topic_id)
{
    // Forum topic counts
    bbp_update_forum_topic_count(bbp_get_topic_forum_id($destination_topic_id));
    // Forum reply counts
    bbp_update_forum_reply_count(bbp_get_topic_forum_id($destination_topic_id));
    // Topic reply counts
    bbp_update_topic_reply_count($source_topic_id);
    bbp_update_topic_reply_count($destination_topic_id);
    // Topic hidden reply counts
    bbp_update_topic_reply_count_hidden($source_topic_id);
    bbp_update_topic_reply_count_hidden($destination_topic_id);
    // Topic voice counts
    bbp_update_topic_voice_count($source_topic_id);
    bbp_update_topic_voice_count($destination_topic_id);
    do_action('bbp_move_reply_count', $move_reply_id, $source_topic_id, $destination_topic_id);
}
コード例 #4
0
ファイル: counts.php プロジェクト: joeyblake/bbpress
 /**
  * @covers ::bbp_update_topic_reply_count_hidden
  */
 public function test_bbp_update_topic_reply_count_hidden()
 {
     // Create a forum
     $f = $this->factory->forum->create();
     // Create a topic
     $t = $this->factory->topic->create(array('post_parent' => $f, 'topic_meta' => array('forum_id' => $f)));
     // Start with zero
     $count = bbp_get_topic_reply_count_hidden($t);
     $this->assertSame('0', $count);
     $r = $this->factory->reply->create_many(3, array('post_parent' => $t, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t)));
     bbp_update_topic_reply_count_hidden($t);
     $count = bbp_get_topic_reply_count_hidden($t);
     $this->assertSame('0', $count);
     bbp_spam_reply($r[2]);
     bbp_update_topic_reply_count_hidden($t);
     $count = bbp_get_topic_reply_count_hidden($t);
     $this->assertSame('1', $count);
     bbp_unapprove_reply($r[0]);
     bbp_update_topic_reply_count_hidden($t);
     $count = bbp_get_topic_reply_count_hidden($t);
     $this->assertSame('2', $count);
 }
コード例 #5
0
ファイル: functions.php プロジェクト: hscale/webento
/**
 * Walk up the ancestor tree from the current reply, and update all the counts
 *
 * @since bbPress (r2884)
 *
 * @param int $reply_id Optional. Reply id
 * @param string $last_active_time Optional. Last active time
 * @param int $forum_id Optional. Forum id
 * @param int $topic_id Optional. Topic id
 * @param bool $refresh If set to true, unsets all the previous parameters.
 *                       Defaults to true
 * @uses bbp_get_reply_id() To get the reply id
 * @uses bbp_get_reply_topic_id() To get the reply topic id
 * @uses bbp_get_reply_forum_id() To get the reply forum id
 * @uses get_post_ancestors() To get the ancestors of the reply
 * @uses bbp_is_reply() To check if the ancestor is a reply
 * @uses bbp_is_topic() To check if the ancestor is a topic
 * @uses bbp_update_topic_last_reply_id() To update the topic last reply id
 * @uses bbp_update_topic_last_active_id() To update the topic last active id
 * @uses bbp_get_topic_last_active_id() To get the topic last active id
 * @uses get_post_field() To get the post date of the last active id
 * @uses bbp_update_topic_last_active_time() To update the last active topic meta
 * @uses bbp_update_topic_voice_count() To update the topic voice count
 * @uses bbp_update_topic_reply_count() To update the topic reply count
 * @uses bbp_update_topic_reply_count_hidden() To update the topic hidden reply
 *                                              count
 * @uses bbp_is_forum() To check if the ancestor is a forum
 * @uses bbp_update_forum_last_topic_id() To update the last topic id forum meta
 * @uses bbp_update_forum_last_reply_id() To update the last reply id forum meta
 * @uses bbp_update_forum_last_active_id() To update the forum last active id
 * @uses bbp_get_forum_last_active_id() To get the forum last active id
 * @uses bbp_update_forum_last_active_time() To update the forum last active time
 * @uses bbp_update_forum_reply_count() To update the forum reply count
 */
function bbp_update_reply_walker($reply_id, $last_active_time = '', $forum_id = 0, $topic_id = 0, $refresh = true)
{
    // Verify the reply ID
    $reply_id = bbp_get_reply_id($reply_id);
    // Reply was passed
    if (!empty($reply_id)) {
        // Get the topic ID if none was passed
        if (empty($topic_id)) {
            $topic_id = bbp_get_reply_topic_id($reply_id);
        }
        // Get the forum ID if none was passed
        if (empty($forum_id)) {
            $forum_id = bbp_get_reply_forum_id($reply_id);
        }
    }
    // Set the active_id based on topic_id/reply_id
    $active_id = empty($reply_id) ? $topic_id : $reply_id;
    // Setup ancestors array to walk up
    $ancestors = array_values(array_unique(array_merge(array($topic_id, $forum_id), (array) get_post_ancestors($topic_id))));
    // If we want a full refresh, unset any of the possibly passed variables
    if (true == $refresh) {
        $forum_id = $topic_id = $reply_id = $active_id = $last_active_time = 0;
    }
    // Walk up ancestors
    if (!empty($ancestors)) {
        foreach ($ancestors as $ancestor) {
            // Reply meta relating to most recent reply
            if (bbp_is_reply($ancestor)) {
                // @todo - hierarchical replies
                // Topic meta relating to most recent reply
            } elseif (bbp_is_topic($ancestor)) {
                // Last reply and active ID's
                bbp_update_topic_last_reply_id($ancestor, $reply_id);
                bbp_update_topic_last_active_id($ancestor, $active_id);
                // Get the last active time if none was passed
                $topic_last_active_time = $last_active_time;
                if (empty($last_active_time)) {
                    $topic_last_active_time = get_post_field('post_date', bbp_get_topic_last_active_id($ancestor));
                }
                // Only update if reply is published
                if (bbp_is_reply_published($reply_id)) {
                    bbp_update_topic_last_active_time($ancestor, $topic_last_active_time);
                }
                // Counts
                bbp_update_topic_voice_count($ancestor);
                bbp_update_topic_reply_count($ancestor);
                bbp_update_topic_reply_count_hidden($ancestor);
                // Forum meta relating to most recent topic
            } elseif (bbp_is_forum($ancestor)) {
                // Last topic and reply ID's
                bbp_update_forum_last_topic_id($ancestor, $topic_id);
                bbp_update_forum_last_reply_id($ancestor, $reply_id);
                // Last Active
                bbp_update_forum_last_active_id($ancestor, $active_id);
                // Get the last active time if none was passed
                $forum_last_active_time = $last_active_time;
                if (empty($last_active_time)) {
                    $forum_last_active_time = get_post_field('post_date', bbp_get_forum_last_active_id($ancestor));
                }
                // Only update if reply is published
                if (bbp_is_reply_published($reply_id)) {
                    bbp_update_forum_last_active_time($ancestor, $forum_last_active_time);
                }
                // Counts
                bbp_update_forum_reply_count($ancestor);
            }
        }
    }
}