Ejemplo n.º 1
0
/**
 * Performs a series of checks to ensure the current user can create replies.
 *
 * @since bbPress (r3127)
 *
 * @uses bbp_is_topic_edit()
 * @uses current_user_can()
 * @uses bbp_get_topic_id()
 * @uses bbp_allow_anonymous()
 * @uses is_user_logged_in()
 *
 * @return bool
 */
function bbp_current_user_can_access_create_reply_form()
{
    // Users need to earn access
    $retval = false;
    // Always allow super admins
    if (is_super_admin()) {
        $retval = true;
    } elseif ((bbp_is_single_topic() || is_page() || is_single()) && bbp_is_topic_open() && bbp_is_forum_open()) {
        $retval = bbp_current_user_can_publish_replies();
    } elseif (bbp_is_reply_edit()) {
        $retval = current_user_can('edit_reply', bbp_get_reply_id());
    }
    // Allow access to be filtered
    return (bool) apply_filters('bbp_current_user_can_access_create_reply_form', (bool) $retval);
}
Ejemplo n.º 2
0
/**
 * Performs a series of checks to ensure the current user can create replies.
 *
 * @since 2.0.0 bbPress (r3127)
 *
 * @uses bbp_is_user_keymaster()
 * @uses bbp_is_topic_edit()
 * @uses current_user_can()
 * @uses bbp_get_topic_id()
 * @uses bbp_allow_anonymous()
 * @uses is_user_logged_in()
 *
 * @return bool
 */
function bbp_current_user_can_access_create_reply_form()
{
    // Users need to earn access
    $retval = false;
    // Always allow keymasters
    if (bbp_is_user_keymaster()) {
        $retval = true;
        // Looking at a single topic, topic is open, and forum is open
    } elseif ((bbp_is_single_topic() || is_page() || is_single()) && bbp_is_topic_open() && bbp_is_forum_open()) {
        $retval = bbp_current_user_can_publish_replies();
        // User can edit this topic
    } elseif (bbp_is_reply_edit()) {
        $retval = current_user_can('edit_reply', bbp_get_reply_id());
    }
    // Allow access to be filtered
    return (bool) apply_filters('bbp_current_user_can_access_create_reply_form', (bool) $retval);
}
Ejemplo n.º 3
0
/**
 * Handle the saving of core forum metadata (Status, Visibility, and Type)
 *
 * @since 2.1.0 bbPress (r3678)
 *
 * @param int $forum_id
 * @uses bbp_is_forum_closed() To check if forum is closed
 * @uses bbp_close_forum() To close forum
 * @uses bbp_open_forum() To open forum
 * @uses bbp_is_forum_category() To check if forum is a category
 * @uses bbp_categorize_forum() To turn forum into a category
 * @uses bbp_normalize_forum() To turn category into forum
 * @uses bbp_get_public_status_id() To get the public status ID
 * @uses bbp_get_private_status_id() To get the private status ID
 * @uses bbp_get_hidden_status_id() To get the hidden status ID
 * @uses bbp_get_forum_visibility() To get the forums visibility
 * @uses bbp_hide_forum() To hide a forum
 * @uses bbp_privatize_forum() To make a forum private
 * @uses bbp_publicize_forum() To make a forum public
 * @return If forum ID is empty
 */
function bbp_save_forum_extras($forum_id = 0)
{
    // Validate the forum ID
    $forum_id = bbp_get_forum_id($forum_id);
    // Bail if forum ID is empty
    if (empty($forum_id) || !bbp_is_forum($forum_id)) {
        return;
    }
    /** Forum Status **********************************************************/
    if (!empty($_POST['bbp_forum_status']) && in_array($_POST['bbp_forum_status'], array('open', 'closed'))) {
        if ('closed' === $_POST['bbp_forum_status'] && !bbp_is_forum_closed($forum_id, false)) {
            bbp_close_forum($forum_id);
        } elseif ('open' === $_POST['bbp_forum_status'] && bbp_is_forum_open($forum_id, false)) {
            bbp_open_forum($forum_id);
        } elseif ('open' === $_POST['bbp_forum_status'] && bbp_is_forum_closed($forum_id, false)) {
            bbp_open_forum($forum_id);
        }
    }
    /** Forum Type ************************************************************/
    if (!empty($_POST['bbp_forum_type']) && in_array($_POST['bbp_forum_type'], array('forum', 'category'))) {
        if ('category' === $_POST['bbp_forum_type'] && !bbp_is_forum_category($forum_id)) {
            bbp_categorize_forum($forum_id);
        } elseif ('forum' === $_POST['bbp_forum_type'] && !bbp_is_forum_category($forum_id)) {
            bbp_normalize_forum($forum_id);
        } elseif ('forum' === $_POST['bbp_forum_type'] && bbp_is_forum_category($forum_id)) {
            bbp_normalize_forum($forum_id);
        }
    }
    /** Forum Visibility ******************************************************/
    if (!empty($_POST['bbp_forum_visibility']) && in_array($_POST['bbp_forum_visibility'], array_keys(bbp_get_forum_visibilities()))) {
        // Get forums current visibility
        $old_visibility = bbp_get_forum_visibility($forum_id);
        // Sanitize the new visibility
        $new_visibility = sanitize_key($_POST['bbp_forum_visibility']);
        // What is the new forum visibility setting?
        switch ($new_visibility) {
            // Hidden
            case bbp_get_hidden_status_id():
                bbp_hide_forum($forum_id, $old_visibility);
                break;
                // Private
            // Private
            case bbp_get_private_status_id():
                bbp_privatize_forum($forum_id, $old_visibility);
                break;
                // Publish (default)
            // Publish (default)
            case bbp_get_public_status_id():
            default:
                bbp_publicize_forum($forum_id, $old_visibility);
                break;
        }
        /**
         * Allow custom forum visibility save actions
         *
         * @since 2.6.0 bbPress (r5855)
         *
         * @param int    $forum_id       The forum ID
         * @param string $old_visibility The current forum visibility
         * @param string $new_visibility The new forum visibility
         */
        do_action('bbp_update_forum_visibility', $forum_id, $old_visibility, $new_visibility);
    }
    /** Forum Moderators ******************************************************/
    // Either replace terms
    if (bbp_allow_forum_mods()) {
        if (current_user_can('assign_moderators') && !empty($_POST['bbp_moderators'])) {
            // Escape tag input
            $users = sanitize_text_field($_POST['bbp_moderators']);
            // Explode by comma
            $users = strstr($users, ',') ? explode(',', $users) : (array) $users;
            $user_ids = bbp_get_user_ids_from_nicenames($users);
            // Update forum moderators
            if (!empty($user_ids)) {
                // Remove all moderators
                bbp_remove_moderator($forum_id, null);
                // Add moderators
                foreach ($user_ids as $user_id) {
                    bbp_add_moderator($forum_id, $user_id);
                }
            }
            // ...or remove them.
        } elseif (isset($_POST['bbp_moderators'])) {
            bbp_remove_moderator($forum_id, null);
        }
    }
}
Ejemplo n.º 4
0
 /**
  * @covers ::bbp_is_forum_open
  */
 public function test_bbp_is_forum_open()
 {
     $f = $this->factory->forum->create();
     $forum = bbp_is_forum_open($f);
     $this->assertTrue($forum);
 }
Ejemplo n.º 5
0
 /**
  * Forum Row actions
  *
  * Remove the quick-edit action link and display the description under
  * the forum title and add the open/close links
  *
  * @since 2.0.0 bbPress (r2577)
  *
  * @param array $actions Actions
  * @param array $forum Forum object
  * @uses bbp_get_public_status_id() To get the published forum id's
  * @uses bbp_get_private_status_id() To get the private forum id's
  * @uses bbp_get_hidden_status_id() To get the hidden forum id's
  * @uses bbp_get_closed_status_id() To get the closed forum id's
  * @uses wp_nonce_url() To nonce the url
  * @uses bbp_is_forum_open() To check if a forum is open
  * @uses bbp_forum_content() To output forum description
  * @return array $actions Actions
  */
 public function row_actions($actions, $forum)
 {
     if ($this->bail()) {
         return $actions;
     }
     unset($actions['inline hide-if-no-js']);
     // Only show the actions if the user is capable of viewing them :)
     if (current_user_can('keep_gate', $forum->ID)) {
         // Show the 'close' and 'open' link on published, private, hidden and closed posts only
         if (in_array($forum->post_status, array(bbp_get_public_status_id(), bbp_get_private_status_id(), bbp_get_hidden_status_id(), bbp_get_closed_status_id()))) {
             $close_uri = wp_nonce_url(add_query_arg(array('forum_id' => $forum->ID, 'action' => 'bbp_toggle_forum_close'), remove_query_arg(array('bbp_forum_toggle_notice', 'forum_id', 'failed', 'super'))), 'close-forum_' . $forum->ID);
             if (bbp_is_forum_open($forum->ID)) {
                 $actions['closed'] = '<a href="' . esc_url($close_uri) . '" title="' . esc_attr__('Close this forum', 'bbpress') . '">' . _x('Close', 'Close a Forum', 'bbpress') . '</a>';
             } else {
                 $actions['closed'] = '<a href="' . esc_url($close_uri) . '" title="' . esc_attr__('Open this forum', 'bbpress') . '">' . _x('Open', 'Open a Forum', 'bbpress') . '</a>';
             }
         }
     }
     // simple hack to show the forum description under the title
     bbp_forum_content($forum->ID);
     return $actions;
 }
Ejemplo n.º 6
0
 /**
  * @group canonical
  * @covers ::bbp_insert_forum
  */
 public function test_bbp_insert_forum()
 {
     $c = $this->factory->forum->create(array('post_title' => 'Category 1', 'post_content' => 'Content of Category 1', 'forum_meta' => array('forum_type' => 'category', 'status' => 'open')));
     $f = $this->factory->forum->create(array('post_title' => 'Forum 1', 'post_content' => 'Content of Forum 1', 'post_parent' => $c, 'forum_meta' => array('forum_id' => $c, 'forum_type' => 'forum', 'status' => 'open')));
     $now = time();
     $post_date = date('Y-m-d H:i:s', $now - 60 * 60 * 100);
     $t = $this->factory->topic->create(array('post_parent' => $f, 'post_date' => $post_date, 'topic_meta' => array('forum_id' => $f)));
     $r = $this->factory->reply->create(array('post_parent' => $t, 'post_date' => $post_date, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t)));
     // Get the category.
     $category = bbp_get_forum($c);
     // Get the forum.
     $forum = bbp_get_forum($f);
     // Category post.
     $this->assertSame('Category 1', bbp_get_forum_title($c));
     $this->assertSame('Content of Category 1', bbp_get_forum_content($c));
     $this->assertSame('open', bbp_get_forum_status($c));
     $this->assertSame('category', bbp_get_forum_type($c));
     $this->assertTrue(bbp_is_forum($c));
     $this->assertTrue(bbp_is_forum_category($c));
     $this->assertTrue(bbp_is_forum_open($c));
     $this->assertTrue(bbp_is_forum_public($c));
     $this->assertFalse(bbp_is_forum_closed($c));
     $this->assertFalse(bbp_is_forum_hidden($c));
     $this->assertFalse(bbp_is_forum_private($c));
     $this->assertSame(0, bbp_get_forum_parent_id($c));
     $this->assertEquals('http://' . WP_TESTS_DOMAIN . '/?forum=' . $category->post_name, $category->guid);
     // Forum post.
     $this->assertSame('Forum 1', bbp_get_forum_title($f));
     $this->assertSame('Content of Forum 1', bbp_get_forum_content($f));
     $this->assertSame('open', bbp_get_forum_status($f));
     $this->assertSame('forum', bbp_get_forum_type($f));
     $this->assertTrue(bbp_is_forum($f));
     $this->assertTrue(bbp_is_forum_open($f));
     $this->assertTrue(bbp_is_forum_public($f));
     $this->assertFalse(bbp_is_forum_closed($f));
     $this->assertFalse(bbp_is_forum_hidden($f));
     $this->assertFalse(bbp_is_forum_private($f));
     $this->assertSame($c, bbp_get_forum_parent_id($f));
     $this->assertEquals('http://' . WP_TESTS_DOMAIN . '/?forum=' . $category->post_name . '/' . $forum->post_name, $forum->guid);
     // Category meta.
     $this->assertSame(1, bbp_get_forum_subforum_count($c, true));
     $this->assertSame(0, bbp_get_forum_topic_count($c, false, true));
     $this->assertSame(1, bbp_get_forum_topic_count($c, true, true));
     $this->assertSame(0, bbp_get_forum_topic_count_hidden($c, true));
     $this->assertSame(0, bbp_get_forum_reply_count($c, false, true));
     $this->assertSame(1, bbp_get_forum_reply_count($c, true, true));
     $this->assertSame(0, bbp_get_forum_post_count($c, false, true));
     $this->assertSame(2, bbp_get_forum_post_count($c, true, true));
     $this->assertSame($t, bbp_get_forum_last_topic_id($c));
     $this->assertSame($r, bbp_get_forum_last_reply_id($c));
     $this->assertSame($r, bbp_get_forum_last_active_id($c));
     $this->assertSame('4 days, 4 hours ago', bbp_get_forum_last_active_time($c));
     // Forum meta.
     $this->assertSame(0, bbp_get_forum_subforum_count($f, true));
     $this->assertSame(1, bbp_get_forum_topic_count($f, false, true));
     $this->assertSame(1, bbp_get_forum_topic_count($f, true, true));
     $this->assertSame(0, bbp_get_forum_topic_count_hidden($f, true));
     $this->assertSame(1, bbp_get_forum_reply_count($f, false, true));
     $this->assertSame(1, bbp_get_forum_reply_count($f, true, true));
     $this->assertSame(2, bbp_get_forum_post_count($f, false, true));
     $this->assertSame(2, bbp_get_forum_post_count($f, true, true));
     $this->assertSame($t, bbp_get_forum_last_topic_id($f));
     $this->assertSame($r, bbp_get_forum_last_reply_id($f));
     $this->assertSame($r, bbp_get_forum_last_active_id($f));
     $this->assertSame('4 days, 4 hours ago', bbp_get_forum_last_active_time($f));
 }
Ejemplo n.º 7
0
/**
 * Handle the saving of core forum metadata (Status, Visibility, and Type)
 *
 * @since 2.1.0 bbPress (r3678)
 *
 * @param int $forum_id
 * @uses bbp_is_forum_closed() To check if forum is closed
 * @uses bbp_close_forum() To close forum
 * @uses bbp_open_forum() To open forum
 * @uses bbp_is_forum_category() To check if forum is a category
 * @uses bbp_categorize_forum() To turn forum into a category
 * @uses bbp_normalize_forum() To turn category into forum
 * @uses bbp_get_public_status_id() To get the public status ID
 * @uses bbp_get_private_status_id() To get the private status ID
 * @uses bbp_get_hidden_status_id() To get the hidden status ID
 * @uses bbp_get_forum_visibility() To get the forums visibility
 * @uses bbp_hide_forum() To hide a forum
 * @uses bbp_privatize_forum() To make a forum private
 * @uses bbp_publicize_forum() To make a forum public
 * @return If forum ID is empty
 */
function bbp_save_forum_extras($forum_id = 0)
{
    // Validate the forum ID
    $forum_id = bbp_get_forum_id($forum_id);
    // Bail if forum ID is empty
    if (empty($forum_id) || !bbp_is_forum($forum_id)) {
        return;
    }
    /** Forum Status **********************************************************/
    if (!empty($_POST['bbp_forum_status']) && in_array($_POST['bbp_forum_status'], array('open', 'closed'))) {
        if ('closed' === $_POST['bbp_forum_status'] && !bbp_is_forum_closed($forum_id, false)) {
            bbp_close_forum($forum_id);
        } elseif ('open' === $_POST['bbp_forum_status'] && bbp_is_forum_open($forum_id, false)) {
            bbp_open_forum($forum_id);
        } elseif ('open' === $_POST['bbp_forum_status'] && bbp_is_forum_closed($forum_id, false)) {
            bbp_open_forum($forum_id);
        }
    }
    /** Forum Type ************************************************************/
    if (!empty($_POST['bbp_forum_type']) && in_array($_POST['bbp_forum_type'], array('forum', 'category'))) {
        if ('category' === $_POST['bbp_forum_type'] && !bbp_is_forum_category($forum_id)) {
            bbp_categorize_forum($forum_id);
        } elseif ('forum' === $_POST['bbp_forum_type'] && !bbp_is_forum_category($forum_id)) {
            bbp_normalize_forum($forum_id);
        } elseif ('forum' === $_POST['bbp_forum_type'] && bbp_is_forum_category($forum_id)) {
            bbp_normalize_forum($forum_id);
        }
    }
    /** Forum Visibility ******************************************************/
    if (!empty($_POST['bbp_forum_visibility']) && in_array($_POST['bbp_forum_visibility'], array_keys(bbp_get_forum_visibilities()))) {
        // Get forums current visibility
        $old_visibility = bbp_get_forum_visibility($forum_id);
        // Sanitize the new visibility
        $new_visibility = sanitize_key($_POST['bbp_forum_visibility']);
        // What is the new forum visibility setting?
        switch ($new_visibility) {
            // Hidden
            case bbp_get_hidden_status_id():
                bbp_hide_forum($forum_id, $old_visibility);
                break;
                // Private
            // Private
            case bbp_get_private_status_id():
                bbp_privatize_forum($forum_id, $old_visibility);
                break;
                // Publish (default)
            // Publish (default)
            case bbp_get_public_status_id():
            default:
                bbp_publicize_forum($forum_id, $old_visibility);
                break;
        }
        /**
         * Allow custom forum visibility save actions
         *
         * @since 2.6.0 bbPress (r5855)
         *
         * @param int    $forum_id       The forum ID
         * @param string $old_visibility The current forum visibility
         * @param string $new_visibility The new forum visibility
         */
        do_action('bbp_update_forum_visibility', $forum_id, $old_visibility, $new_visibility);
    }
}