/**
 * This function filters the list of forums based on the users rank as set by the Mebmers plugin
 */
function tehnik_bpp_filter_forums_by_permissions($args = '')
{
    $bbp = bbpress();
    // Setup possible post__not_in array
    $post_stati[] = bbp_get_public_status_id();
    // Check if user can read private forums
    if (current_user_can('read_private_forums')) {
        $post_stati[] = bbp_get_private_status_id();
    }
    // Check if user can read hidden forums
    if (current_user_can('read_hidden_forums')) {
        $post_stati[] = bbp_get_hidden_status_id();
    }
    // The default forum query for most circumstances
    $meta_query = array('post_type' => bbp_get_forum_post_type(), 'post_parent' => bbp_is_forum_archive() ? 0 : bbp_get_forum_id(), 'post_status' => implode(',', $post_stati), 'posts_per_page' => get_option('_bbp_forums_per_page', 50), 'orderby' => 'menu_order', 'order' => 'ASC');
    //Get an array of IDs which the current user has permissions to view
    $allowed_forums = tehnik_bpp_get_permitted_post_ids(new WP_Query($meta_query));
    // The default forum query with allowed forum ids array added
    $meta_query['post__in'] = $allowed_forums;
    $bbp_f = bbp_parse_args($args, $meta_query, 'has_forums');
    // Run the query
    $bbp->forum_query = new WP_Query($bbp_f);
    return apply_filters('bpp_filter_forums_by_permissions', $bbp->forum_query->have_posts(), $bbp->forum_query);
}
Пример #2
0
/**
 * Query the DB and get a the child id's of all children
 *
 * @since 2.0.0 bbPress (r3325)
 *
 * @param int $parent_id  Parent id
 * @param string $post_type Post type. Defaults to 'post'
 * @uses wp_cache_get() To check if there is a cache of the children
 * @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_pending_status_id() To get the pending status id
 * @uses bbp_get_closed_status_id() To get the closed status id
 * @uses bbp_get_trash_status_id() To get the trash status id
 * @uses bbp_get_spam_status_id() To get the spam status id
 * @uses bbp_get_forum_post_type() To get the forum post type
 * @uses bbp_get_topic_post_type() To get the topic post type
 * @uses bbp_get_reply_post_type() To get the reply post type
 * @uses wpdb::prepare() To prepare the query
 * @uses wpdb::get_col() To get the result of the query in an array
 * @uses wp_cache_set() To set the cache for future use
 * @uses apply_filters() Calls 'bbp_get_all_child_ids' with the child ids,
 *                        parent id and post type
 * @return array The array of children
 */
function bbp_get_all_child_ids($parent_id = 0, $post_type = 'post')
{
    // Bail if nothing passed
    if (empty($parent_id)) {
        return false;
    }
    // The ID of the cached query
    $cache_id = 'bbp_parent_all_' . $parent_id . '_type_' . $post_type . '_child_ids';
    // Check for cache and set if needed
    $child_ids = wp_cache_get($cache_id, 'bbpress_posts');
    if (false === $child_ids) {
        $post_status = array(bbp_get_public_status_id());
        // Extra post statuses based on post type
        switch ($post_type) {
            // Forum
            case bbp_get_forum_post_type():
                $post_status[] = bbp_get_private_status_id();
                $post_status[] = bbp_get_hidden_status_id();
                break;
                // Topic
            // Topic
            case bbp_get_topic_post_type():
                $post_status[] = bbp_get_pending_status_id();
                $post_status[] = bbp_get_closed_status_id();
                $post_status[] = bbp_get_trash_status_id();
                $post_status[] = bbp_get_spam_status_id();
                break;
                // Reply
            // Reply
            case bbp_get_reply_post_type():
                $post_status[] = bbp_get_pending_status_id();
                $post_status[] = bbp_get_trash_status_id();
                $post_status[] = bbp_get_spam_status_id();
                break;
        }
        // Join post statuses together
        $post_status = "'" . implode("', '", $post_status) . "'";
        $bbp_db = bbp_db();
        $query = $bbp_db->prepare("SELECT ID FROM {$bbp_db->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s' ORDER BY ID DESC;", $parent_id, $post_type);
        $child_ids = (array) $bbp_db->get_col($query);
        wp_cache_set($cache_id, $child_ids, 'bbpress_posts');
    } else {
        $child_ids = (array) $child_ids;
    }
    // Filter and return
    return (array) apply_filters('bbp_get_all_child_ids', $child_ids, $parent_id, $post_type);
}
Пример #3
0
/**
 * Return the forum visibility dropdown
 *
 * @since bbPress (r3563)
 *
 * @param int $forum_id The forum id to use
 * @uses bbp_is_topic_edit() To check if it's the topic edit page
 * @uses bbp_get_forum_visibility() To get the forum visibility
 * @uses apply_filters()
 * @return string HTML select list for selecting forum visibility
 */
function bbp_get_form_forum_visibility_dropdown($forum_id = 0)
{
    $forum_id = bbp_get_forum_id($forum_id);
    $forum_attr = apply_filters('bbp_forum_visibilities', array(bbp_get_public_status_id() => __('Public', 'bbpress'), bbp_get_private_status_id() => __('Private', 'bbpress'), bbp_get_hidden_status_id() => __('Hidden', 'bbpress')));
    $visibility_output = '<select name="bbp_forum_visibility" id="bbp_forum_visibility_select">' . "\n";
    foreach ($forum_attr as $value => $label) {
        $visibility_output .= "\t" . '<option value="' . $value . '"' . selected(bbp_get_forum_visibility($forum_id), $value, false) . '>' . esc_html($label) . '</option>' . "\n";
    }
    $visibility_output .= '</select>';
    return apply_filters('bbp_get_form_forum_visibility_dropdown', $visibility_output, $forum_id, $forum_attr);
}
Пример #4
0
/**
 * Is the forum hidden?
 *
 * @since bbPress (r2997)
 *
 * @param int $forum_id Optional. Forum id
 * @param bool $check_ancestors Check if the ancestors are private (only if
 *                               they're a category)
 * @uses get_post_meta() To get the forum private meta
 * @uses bbp_get_forum_ancestors() To get the forum ancestors
 * @uses bbp_is_forum_category() To check if the forum is a category
 * @uses bbp_is_forum_closed() To check if the forum is closed
 * @return bool True if closed, false if not
 */
function bbp_is_forum_hidden($forum_id = 0, $check_ancestors = true)
{
    $forum_id = bbp_get_forum_id($forum_id);
    $visibility = bbp_get_forum_visibility($forum_id);
    // If post status is private, return true
    $retval = bbp_get_hidden_status_id() === $visibility;
    // Check ancestors and inherit their privacy setting for display
    if (!empty($check_ancestors)) {
        $ancestors = bbp_get_forum_ancestors($forum_id);
        foreach ((array) $ancestors as $ancestor) {
            if (bbp_is_forum($ancestor) && bbp_is_forum_hidden($ancestor, false)) {
                $retval = true;
            }
        }
    }
    return (bool) apply_filters('bbp_is_forum_hidden', (bool) $retval, $forum_id, $check_ancestors);
}
Пример #5
0
/**
 * Is the forum hidden?
 *
 * @since 2.0.0 bbPress (r2997)
 *
 * @param int $forum_id Optional. Forum id
 * @param bool $check_ancestors Check if the ancestors are private (only if
 *                               they're a category)
 * @uses bbp_get_forum_id() To get the forum ID
 * @uses bbp_is_forum_visibility() To check the forum visibility ID
 * @return bool True if hidden, false if not
 */
function bbp_is_forum_hidden($forum_id = 0, $check_ancestors = true)
{
    // Get the forum ID
    $forum_id = bbp_get_forum_id($forum_id);
    // Check if the forum or one of it's ancestors is hidden
    $retval = bbp_is_forum_visibility($forum_id, bbp_get_hidden_status_id(), $check_ancestors, 'OR');
    return (bool) apply_filters('bbp_is_forum_hidden', (bool) $retval, $forum_id, $check_ancestors);
}
Пример #6
0
 /**
  * Register the post statuses used by bbPress
  *
  * We do some manipulation of the 'trash' status so trashed topics and
  * replies can be viewed from within the theme.
  *
  * @since bbPress (r2727)
  * @uses register_post_status() To register post statuses
  * @uses $wp_post_statuses To modify trash and private statuses
  * @uses current_user_can() To check if the current user is capable &
  *                           modify $wp_post_statuses accordingly
  */
 public static function register_post_statuses()
 {
     // Closed
     register_post_status(bbp_get_closed_status_id(), apply_filters('bbp_register_closed_post_status', array('label' => _x('Closed', 'post', 'bbpress'), 'label_count' => _nx_noop('Closed <span class="count">(%s)</span>', 'Closed <span class="count">(%s)</span>', 'post', 'bbpress'), 'public' => true, 'show_in_admin_all' => true)));
     // Spam
     register_post_status(bbp_get_spam_status_id(), apply_filters('bbp_register_spam_post_status', array('label' => _x('Spam', 'post', 'bbpress'), 'label_count' => _nx_noop('Spam <span class="count">(%s)</span>', 'Spam <span class="count">(%s)</span>', 'post', 'bbpress'), 'protected' => true, 'exclude_from_search' => true, 'show_in_admin_status_list' => true, 'show_in_admin_all_list' => false)));
     // Orphan
     register_post_status(bbp_get_orphan_status_id(), apply_filters('bbp_register_orphan_post_status', array('label' => _x('Orphan', 'post', 'bbpress'), 'label_count' => _nx_noop('Orphan <span class="count">(%s)</span>', 'Orphans <span class="count">(%s)</span>', 'post', 'bbpress'), 'protected' => true, 'exclude_from_search' => true, 'show_in_admin_status_list' => true, 'show_in_admin_all_list' => false)));
     // Hidden
     register_post_status(bbp_get_hidden_status_id(), apply_filters('bbp_register_hidden_post_status', array('label' => _x('Hidden', 'post', 'bbpress'), 'label_count' => _nx_noop('Hidden <span class="count">(%s)</span>', 'Hidden <span class="count">(%s)</span>', 'post', 'bbpress'), 'private' => true, 'exclude_from_search' => true, 'show_in_admin_status_list' => true, 'show_in_admin_all_list' => true)));
     /**
      * Trash fix
      *
      * We need to remove the internal arg and change that to
      * protected so that the users with 'view_trash' cap can view
      * single trashed topics/replies in the front-end as wp_query
      * doesn't allow any hack for the trashed topics to be viewed.
      */
     global $wp_post_statuses;
     if (!empty($wp_post_statuses['trash'])) {
         // User can view trash so set internal to false
         if (current_user_can('view_trash')) {
             $wp_post_statuses['trash']->internal = false;
             $wp_post_statuses['trash']->protected = true;
             // User cannot view trash so set internal to true
         } else {
             $wp_post_statuses['trash']->internal = true;
         }
     }
 }
Пример #7
0
/**
 * Adjusts topic and reply queries to exclude items that might be contained
 * inside hidden or private forums that the user does not have the capability
 * to view.
 *
 * @since bbPress (r3291)
 *
 * @param WP_Query $posts_query
 *
 * @uses apply_filters()
 * @uses bbp_exclude_forum_ids()
 * @uses bbp_get_topic_post_type()
 * @uses bbp_get_reply_post_type()
 * @return WP_Query
 */
function bbp_pre_get_posts_exclude_forums($posts_query)
{
    // Bail if all forums are explicitly allowed
    if (true === apply_filters('bbp_include_all_forums', $posts_query)) {
        return;
    }
    // Bail if $posts_query is not an object or of incorrect class
    if (!is_object($posts_query) || !is_a($posts_query, 'WP_Query')) {
        return;
    }
    // Bail if filters are suppressed on this query
    if (true == $posts_query->get('suppress_filters')) {
        return;
    }
    // Only exclude forums on bbPress queries
    switch ($posts_query->get('post_type')) {
        // Forums
        case bbp_get_forum_post_type():
            // Prevent accidental wp-admin post_row override
            if (is_admin() && isset($_REQUEST['post_status'])) {
                break;
            }
            // Define local variable
            $status = array();
            // All users can see published forums
            $status[] = bbp_get_public_status_id();
            // Add bbp_get_private_status_id() if user is capable
            if (current_user_can('read_private_forums')) {
                $status[] = bbp_get_private_status_id();
            }
            // Add bbp_get_hidden_status_id() if user is capable
            if (current_user_can('read_hidden_forums')) {
                $status[] = bbp_get_hidden_status_id();
            }
            // Implode and add the statuses
            $posts_query->set('post_status', implode(',', $status));
            break;
            // Topics
        // Topics
        case bbp_get_topic_post_type():
            // Replies
        // Replies
        case bbp_get_reply_post_type():
            // Get forums to exclude
            $forum_ids = bbp_exclude_forum_ids('meta_query');
            // Bail if no forums to exclude
            if (empty($forum_ids)) {
                return;
            }
            // Get any existing meta queries
            $meta_query = $posts_query->get('meta_query');
            // Add our meta query to existing
            $meta_query[] = $forum_ids;
            // Set the meta_query var
            $posts_query->set('meta_query', $meta_query);
            break;
    }
}
function bbp_list_private_groups_subforums($args)
{
    // Use passed integer as post_parent
    if (is_numeric($args)) {
        $args = array('post_parent' => $args);
    }
    // Setup possible post__not_in array
    $post_stati[] = bbp_get_public_status_id();
    // Super admin get whitelisted post statuses
    if (bbp_is_user_keymaster()) {
        $post_stati = array(bbp_get_public_status_id(), bbp_get_private_status_id(), bbp_get_hidden_status_id());
        // Not a keymaster, so check caps
    } else {
        // Check if user can read private forums
        if (current_user_can('read_private_forums')) {
            $post_stati[] = bbp_get_private_status_id();
        }
        // Check if user can read hidden forums
        if (current_user_can('read_hidden_forums')) {
            $post_stati[] = bbp_get_hidden_status_id();
        }
    }
    $args['post_status'] = implode(',', $post_stati);
    return $args;
}
function bp_group_organizer_import_group($group, $args = array())
{
    if (empty($group['name'])) {
        return false;
    }
    if (isset($group['path'])) {
        if (bpgo_is_hierarchy_available()) {
            // Try to place the group in the requested spot, but if the spot doesn't exist (e.g. because of slug conflicts)
            // then place it as far down the tree as possible
            $parent_path = $group['path'];
            do {
                $parent_path = dirname($parent_path);
                $parent_id = BP_Groups_Hierarchy::get_id_from_slug($parent_path);
            } while ($parent_path != '.' && $parent_id == 0);
            $group['parent_id'] = $parent_id ? $parent_id : 0;
        }
        $group['slug'] = basename($group['path']);
        unset($group['path']);
    }
    $group['slug'] = groups_check_slug($group['slug']);
    $group_id = groups_create_group($group);
    if (!$group_id) {
        return false;
    }
    groups_update_groupmeta($group_id, 'total_member_count', 1);
    if (bpgo_is_hierarchy_available()) {
        $obj_group = new BP_Groups_Hierarchy($group_id);
        $obj_group->parent_id = (int) $group['parent_id'];
        $obj_group->save();
    }
    // Create the forum if enable_forum is checked
    if ($group['enable_forum']) {
        // Ensure group forums are activated, and group does not already have a forum
        if (bp_is_active('forums')) {
            // Check for BuddyPress group forums
            if (!groups_get_groupmeta($group_id, 'forum_id')) {
                groups_new_group_forum($group_id, $group['name'], $group['description']);
            }
        } else {
            if (function_exists('bbp_is_group_forums_active') && bbp_is_group_forums_active()) {
                // Check for bbPress group forums
                if (count(bbp_get_group_forum_ids($group_id)) == 0) {
                    // Create the group forum - implementation from BBP_Forums_Group_Extension:create_screen_save
                    // Set the default forum status
                    switch ($group['status']) {
                        case 'hidden':
                            $status = bbp_get_hidden_status_id();
                            break;
                        case 'private':
                            $status = bbp_get_private_status_id();
                            break;
                        case 'public':
                        default:
                            $status = bbp_get_public_status_id();
                            break;
                    }
                    // Create the initial forum
                    $forum_id = bbp_insert_forum(array('post_parent' => bbp_get_group_forums_root_id(), 'post_title' => $group['name'], 'post_content' => $group['description'], 'post_status' => $status));
                    bbp_add_forum_id_to_group($group_id, $forum_id);
                    bbp_add_group_id_to_forum($forum_id, $group_id);
                }
            }
        }
    }
    do_action('bp_group_organizer_import_group', $group_id);
    return $group_id;
}
Пример #10
0
function bp_group_organizer_admin_page()
{
    global $wpdb;
    // Permissions Check
    if (!current_user_can('manage_options')) {
        wp_die(__('Cheatin&#8217; uh?'));
    }
    // Load all the nav menu interface functions
    require_once 'includes/group-meta-boxes.php';
    require_once 'includes/group-organizer-template.php';
    require_once 'includes/group-organizer.php';
    // Container for any messages displayed to the user
    $messages = array();
    // Container that stores the name of the active menu
    $nav_menu_selected_title = '';
    // Allowed actions: add, update, delete
    $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'edit';
    $errored = false;
    switch ($action) {
        case 'add-group':
            check_admin_referer('add-group', 'group-settings-column-nonce');
            $group['name'] = stripslashes($_POST['group_name']);
            $group['description'] = stripslashes($_POST['group_desc']);
            $group['slug'] = groups_check_slug($_POST['group_slug']);
            $group['status'] = $_POST['group_status'];
            $group['enable_forum'] = isset($_POST['group_forum']) ? true : false;
            $group['date_created'] = date('Y-m-d H:i:s');
            if ($group['slug'] != $_POST['group_slug']) {
                $messages[] = '<div class="updated warning"><p>' . sprintf(__('The group slug you specified was unavailable or invalid. This group was created with the slug: <code>%s</code>.', 'bp-group-organizer'), $group['slug']) . '</p></div>';
            }
            if (empty($group['name'])) {
                $messages[] = '<div class="error"><p>' . __('Group could not be created because one or more required fields were not filled in', 'bp-group-organizer') . '</p></div>';
                $errored = true;
            }
            if (!$errored) {
                $group_id = groups_create_group($group);
                if (!$group_id) {
                    $wpdb->show_errors();
                    $wpdb->print_error();
                    $messages[] = '<div class="error"><p>' . __('Group was not successfully created.', 'bp-group-organizer') . '</p></div>';
                } else {
                    $messages[] = '<div class="updated"><p>' . __('Group was created successfully.', 'bp-group-organizer') . '</p></div>';
                }
            }
            if (!empty($group_id)) {
                groups_update_groupmeta($group_id, 'total_member_count', 1);
                if (bpgo_is_hierarchy_available()) {
                    $obj_group = new BP_Groups_Hierarchy($group_id);
                    $obj_group->parent_id = (int) $_POST['group_parent'];
                    $obj_group->save();
                }
                // Create the forum if enable_forum is checked
                if ($group['enable_forum']) {
                    // Ensure group forums are activated, and group does not already have a forum
                    if (bp_is_active('forums')) {
                        // Check for BuddyPress group forums
                        if (!groups_get_groupmeta($group_id, 'forum_id')) {
                            groups_new_group_forum($group_id, $group['name'], $group['description']);
                        }
                    } else {
                        if (function_exists('bbp_is_group_forums_active') && bbp_is_group_forums_active()) {
                            // Check for bbPress group forums
                            if (count(bbp_get_group_forum_ids($group_id)) == 0) {
                                // Create the group forum - implementation from BBP_Forums_Group_Extension:create_screen_save
                                // Set the default forum status
                                switch ($group['status']) {
                                    case 'hidden':
                                        $status = bbp_get_hidden_status_id();
                                        break;
                                    case 'private':
                                        $status = bbp_get_private_status_id();
                                        break;
                                    case 'public':
                                    default:
                                        $status = bbp_get_public_status_id();
                                        break;
                                }
                                // Create the initial forum
                                $forum_id = bbp_insert_forum(array('post_parent' => bbp_get_group_forums_root_id(), 'post_title' => $group['name'], 'post_content' => $group['description'], 'post_status' => $status));
                                bbp_add_forum_id_to_group($group_id, $forum_id);
                                bbp_add_group_id_to_forum($forum_id, $group_id);
                            }
                        }
                    }
                }
                do_action('bp_group_organizer_save_new_group_options', $group_id);
            }
            break;
        case 'delete-group':
            $group_id = (int) $_REQUEST['group_id'];
            check_admin_referer('delete-group_' . $group_id);
            break;
        case 'update':
            check_admin_referer('update-groups', 'update-groups-nonce');
            $groups_order = $_POST['group'];
            $parent_ids = $_POST['menu-item-parent-id'];
            $db_ids = $_POST['menu-item-db-id'];
            foreach ($groups_order as $id => $group) {
                $group_reference = new BP_Groups_Group($id);
                if (defined('BP_GROUP_HIERARCHY_IS_INSTALLED') && method_exists('BP_Groups_Hierarchy', 'get_tree')) {
                    // if group hierarchy is installed and available, check for tree changes
                    $group_hierarchy = new BP_Groups_Hierarchy($id);
                    if ($parent_ids[$id] !== null && $group_hierarchy->parent_id != $parent_ids[$id]) {
                        $group_hierarchy->parent_id = $parent_ids[$id];
                        $group_hierarchy->save();
                    } else {
                        if ($group_hierarchy->parent_id != $group['parent_id']) {
                            $group_hierarchy->parent_id = $group['parent_id'];
                            $group_hierarchy->save();
                        }
                    }
                    unset($group_hierarchy);
                }
                // check for group attribute changes
                $attrs_changed = array();
                if ($group['name'] != $group_reference->name) {
                    $group_reference->name = stripslashes($group['name']);
                    $attrs_changed[] = 'name';
                }
                if ($group['slug'] != $group_reference->slug) {
                    $slug = groups_check_slug($group['slug']);
                    if ($slug == $group['slug']) {
                        $group_reference->slug = $group['slug'];
                        $attrs_changed[] = 'slug';
                    }
                }
                if ($group['description'] != $group_reference->description) {
                    $group_reference->description = stripslashes($group['description']);
                    $attrs_changed[] = 'description';
                }
                if ($group['status'] != $group_reference->status && groups_is_valid_status($group['status'])) {
                    $group_reference->status = $group['status'];
                    $attrs_changed[] = 'status';
                }
                if (!isset($group['forum_enabled']) || $group['forum_enabled'] != $group_reference->enable_forum) {
                    $group_reference->enable_forum = isset($group['forum_enabled']) ? true : false;
                    $attrs_changed[] = 'enable_forum';
                }
                if (count($attrs_changed) > 0) {
                    $group_reference->save();
                }
                // finally, let plugins run any other changes
                do_action('group_details_updated', $group_reference->id);
                do_action('bp_group_organizer_save_group_options', $group, $group_reference);
            }
            break;
        case 'import':
            if (!isset($_FILES['import_groups'])) {
                // No files was uploaded
            }
            if (!is_uploaded_file($_FILES['import_groups']['tmp_name'])) {
                // Not an uploaded file
                $errors = array(UPLOAD_ERR_OK => sprintf(__('File uploaded successfully, but there is a problem. (%d)', 'bp-group-organizer'), UPLOAD_ERR_OK), UPLOAD_ERR_INI_SIZE => sprintf(__('File exceeded PHP\'s maximum upload size. (%d)', 'bp-group-organizer'), UPLOAD_ERR_INI_SIZE), UPLOAD_ERR_FORM_SIZE => sprintf(__('File exceeded the form\'s maximum upload size. (%d)', 'bp-group-organizer'), UPLOAD_ERR_FORM_SIZE), UPLOAD_ERR_PARTIAL => sprintf(__('File was only partially uploaded. (%d)', 'bp-group-organizer'), UPLOAD_ERR_PARTIAL), UPLOAD_ERR_NO_FILE => sprintf(__('No uploaded file was found. (%d)', 'bp-group-organizer'), UPLOAD_ERR_NO_FILE), 6 => sprintf(__('No temporary folder could be found for the uploaded file. (%d)', 'bp-group-organizer'), 6), 7 => sprintf(__('Could not write uploaded file to disk. (%d)', 'bp-group-organizer'), 7), 8 => sprintf(__('Upload was stopped by a PHP extension. (%d)', 'bp-group-organizer'), 8));
                $messages[] = '<div class="error"><p>' . sprintf(__('', 'bp-group-organizer'), $errors[$_FILES['import_groups']['error']]) . '</p></div>';
                break;
            }
            require_once dirname(__FILE__) . '/includes/group-organizer-import.php';
            if ($result = bp_group_organizer_import_csv_file($_FILES['import_groups']['tmp_name'], $_POST['import'])) {
                $messages[] = '<div class="updated"><p>' . implode('<br />', $result) . '</p></div>';
            } else {
                $messages[] = '<div class="error"><p>' . 'ERROR - IMPORT FAILED COMPLETELY' . '</p></div>';
            }
            break;
    }
    // Ensure the user will be able to scroll horizontally
    // by adding a class for the max menu depth.
    global $_wp_nav_menu_max_depth;
    $_wp_nav_menu_max_depth = 0;
    if (isset($_REQUEST['screen']) && $_REQUEST['screen'] == 'import') {
        $action = 'import';
    } else {
        $action = 'organize';
    }
    if ($action == 'import') {
        $edit_markup = bp_group_organizer_import_export_page();
    } else {
        $edit_markup = bp_get_groups_to_edit();
    }
    ?>
<div class="wrap">
	<h2><?php 
    esc_html_e('Group Organizer');
    ?>
</h2>
	<?php 
    foreach ($messages as $message) {
        echo $message . "\n";
    }
    ?>
	<div <?php 
    if ($action == 'organize') {
        echo 'id="nav-menus-frame"';
    }
    ?>
>
	<div id="menu-settings-column" class="metabox-holder nav-menus-php">
		<form id="group-organizer-meta" action="" class="group-organizer-meta" method="post" enctype="multipart/form-data">
			<input type="hidden" name="action" value="add-group" />
			<?php 
    wp_nonce_field('add-group', 'group-settings-column-nonce');
    ?>
			<?php 
    if ($action == 'organize') {
        do_meta_boxes('group-organizer', 'side', null);
    }
    ?>
		</form>
	</div><!-- /#menu-settings-column -->
	<div id="menu-management-liquid">
		<div id="menu-management" class="nav-menus-php">

			<div class="nav-tabs-wrapper">
			<div class="nav-tabs">
				<a href="<?php 
    echo esc_url(remove_query_arg(array('screen')));
    ?>
" class="nav-tab <?php 
    if ($action == 'organize') {
        echo 'nav-tab-active';
    }
    ?>
">
					<?php 
    printf('<abbr title="%s">%s</abbr>', esc_html__('Drag and drop your groups', 'bp-group-hierarchy'), __('Organize', 'bp-group-organizer'));
    ?>
				</a>
				<a href="<?php 
    echo esc_url(add_query_arg(array('screen' => 'import')));
    ?>
" class="nav-tab <?php 
    if ($action == 'import') {
        echo 'nav-tab-active';
    }
    ?>
">
					<?php 
    printf('<abbr title="%s">%s</abbr>', esc_html__('Import or export groups in bulk', 'bp-group-organizer'), __('Import / Export', 'bp-group-organizer'));
    ?>
				</a>
			</div>
			</div>


			<div class="menu-edit">
				<?php 
    if ($action == 'organize') {
        ?>
				<form id="update-nav-menu" action="" method="post" enctype="multipart/form-data">
				<?php 
    }
    ?>
					<div id="nav-menu-header">
						<div id="submitpost" class="submitbox">
							<div class="major-publishing-actions">
								<label class="menu-name-label howto open-label" for="menu-name">
									<span><?php 
    _e('Group Organizer', 'bp-group-organizer');
    ?>
</span>
								</label>
								<div class="publishing-action">
									<?php 
    if ($action == 'organize') {
        submit_button(__('Save Groups', 'bp-group-organizer'), 'button-primary menu-save', 'save_menu', false, array('id' => 'save_menu_header'));
    }
    ?>
								</div><!-- END .publishing-action -->
							</div><!-- END .major-publishing-actions -->
						</div><!-- END #submitpost .submitbox -->
						<?php 
    wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
    wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
    wp_nonce_field('update-groups', 'update-groups-nonce');
    ?>
						<input type="hidden" name="action" value="update" />
					</div><!-- END #nav-menu-header -->
					<div id="post-body">
						<div id="post-body-content">
							<?php 
    if (isset($edit_markup)) {
        if (!is_wp_error($edit_markup)) {
            echo $edit_markup;
        }
    } else {
        echo '<div class="post-body-plain">';
        echo '<p>' . __('You don\'t yet have any groups.', 'bp-group-organizer') . '</p>';
        echo '</div>';
    }
    ?>
						</div><!-- /#post-body-content -->
					</div><!-- /#post-body -->
					<div id="nav-menu-footer">
						<div class="major-publishing-actions">
						<div class="publishing-action">
							<?php 
    if ($action == 'organize') {
        submit_button(__('Save Groups', 'bp-group-organizer'), 'button-primary menu-save', 'save_menu', false, array('id' => 'save_menu_header'));
    }
    ?>
						</div>
						</div>
					</div><!-- /#nav-menu-footer -->
				<?php 
    if ($action == 'organize') {
        ?>
				</form><!-- /#update-nav-menu -->
				<?php 
    }
    ?>
			</div><!-- /.menu-edit -->
		</div><!-- /#menu-management -->
	</div><!-- /#menu-management-liquid -->
	</div><!-- /#nav-menus-frame -->
</div><!-- /.wrap-->

<?php 
}
Пример #11
0
 public function create_screen_save_notab($group_id = 0)
 {
     // No nonce check, since there's no tab
     // Check for possibly empty group_id
     if (empty($group_id)) {
         $group_id = bp_get_new_group_id();
     }
     // We always set this true, because we always create a forum (the user doesn't get to choose whether they want it or not anymore)
     $create_forum = true;
     //!empty( $_POST['bbp-create-group-forum'] ) ? true : false;
     $forum_id = 0;
     $forum_ids = bbp_get_group_forum_ids($group_id);
     if (!empty($forum_ids)) {
         $forum_id = (int) is_array($forum_ids) ? $forum_ids[0] : $forum_ids;
     }
     // Create a forum, or not
     switch ($create_forum) {
         case true:
             // Bail if initial content was already created
             if (!empty($forum_id)) {
                 return;
             }
             // Set the default forum status
             switch (bp_get_new_group_status()) {
                 case 'hidden':
                     $status = bbp_get_hidden_status_id();
                     break;
                 case 'private':
                     $status = bbp_get_private_status_id();
                     break;
                 case 'public':
                 default:
                     $status = bbp_get_public_status_id();
                     break;
             }
             // Create the initial forum
             $forum_id = bbp_insert_forum(array('post_parent' => bbp_get_group_forums_root_id(), 'post_title' => bp_get_new_group_name(), 'post_content' => bp_get_new_group_description(), 'post_status' => $status));
             // Run the BP-specific functions for new groups
             $this->new_forum(array('forum_id' => $forum_id));
             // Update forum active
             groups_update_groupmeta(bp_get_new_group_id(), '_bbp_forum_enabled_' . $forum_id, true);
             // Toggle forum on
             $this->toggle_group_forum(bp_get_new_group_id(), true);
             break;
         case false:
             // Forum was created but is now being undone
             if (!empty($forum_id)) {
                 // Delete the forum
                 wp_delete_post($forum_id, true);
                 // Delete meta values
                 groups_delete_groupmeta(bp_get_new_group_id(), 'forum_id');
                 groups_delete_groupmeta(bp_get_new_group_id(), '_bbp_forum_enabled_' . $forum_id);
                 // Toggle forum off
                 $this->toggle_group_forum(bp_get_new_group_id(), false);
             }
             break;
     }
 }
Пример #12
0
/**
 * Recaches the private and hidden forums
 *
 * @since bbPress (r4104)
 *
 * @uses delete_option() to delete private and hidden forum pointers
 * @uses WP_Query() To query post IDs
 * @uses is_wp_error() To return if error occurred
 * @uses update_option() To update the private and hidden post ID pointers
 * @return array An array of the status code and the message
 */
function bbp_admin_repair_forum_visibility()
{
    $statement = __('Recalculating forum visibility &hellip; %s', 'bbpress');
    $result = __('Failed!', 'bbpress');
    // First, delete everything.
    delete_option('_bbp_private_forums');
    delete_option('_bbp_hidden_forums');
    // Next, get all the private and hidden forums
    $private_forums = new WP_Query(array('suppress_filters' => true, 'nopaging' => true, 'post_type' => bbp_get_forum_post_type(), 'post_status' => bbp_get_private_status_id(), 'fields' => 'ids'));
    $hidden_forums = new WP_Query(array('suppress_filters' => true, 'nopaging' => true, 'post_type' => bbp_get_forum_post_type(), 'post_status' => bbp_get_hidden_status_id(), 'fields' => 'ids'));
    // Bail if queries returned errors
    if (is_wp_error($private_forums) || is_wp_error($hidden_forums)) {
        return array(2, sprintf($statement, $result));
    }
    update_option('_bbp_private_forums', $private_forums->posts);
    // Private forums
    update_option('_bbp_hidden_forums', $hidden_forums->posts);
    // Hidden forums
    // Complete results
    $result = __('Complete!', 'bbpress');
    return array(0, sprintf($statement, $result));
}
Пример #13
0
 /**
  * @covers ::bbp_is_forum_hidden
  */
 public function test_bbp_is_forum_hidden()
 {
     $f = $this->factory->forum->create(array('post_status' => 'hidden'));
     $forum = bbp_get_forum_visibility($f);
     $this->assertSame('hidden', $forum);
     $forum_status_id = bbp_get_hidden_status_id($f);
     $this->assertSame('hidden', $forum_status_id);
     $this->assertTrue(bbp_is_forum_hidden($f));
 }
Пример #14
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;
 }
Пример #15
0
/**
 * Output a select box allowing to pick which forum/topic a new
 * topic/reply belongs in.
 *
 * @since bbPress (r2746)
 *
 * @param mixed $args The function supports these args:
 *  - post_type: Post type, defaults to bbp_get_forum_post_type() (bbp_forum)
 *  - selected: Selected ID, to not have any value as selected, pass
 *               anything smaller than 0 (due to the nature of select
 *               box, the first value would of course be selected -
 *               though you can have that as none (pass 'show_none' arg))
 *  - sort_column: Sort by? Defaults to 'menu_order, post_title'
 *  - child_of: Child of. Defaults to 0
 *  - post_status: Which all post_statuses to find in? Can be an array
 *                  or CSV of publish, category, closed, private, spam,
 *                  trash (based on post type) - if not set, these are
 *                  automatically determined based on the post_type
 *  - posts_per_page: Retrieve all forums/topics. Defaults to -1 to get
 *                     all posts
 *  - walker: Which walker to use? Defaults to
 *             {@link BBP_Walker_Dropdown}
 *  - select_id: ID of the select box. Defaults to 'bbp_forum_id'
 *  - tab: Tabindex value. False or integer
 *  - options_only: Show only <options>? No <select>?
 *  - show_none: False or something like __( '(No Forum)', 'bbpress' ),
 *                will have value=""
 *  - none_found: False or something like
 *                 __( 'No forums to post to!', 'bbpress' )
 *  - disable_categories: Disable forum categories and closed forums?
 *                         Defaults to true. Only for forums and when
 *                         the category option is displayed.
 * @uses BBP_Walker_Dropdown() As the default walker to generate the
 *                              dropdown
 * @uses current_user_can() To check if the current user can read
 *                           private forums
 * @uses bbp_get_forum_post_type() To get the forum post type
 * @uses bbp_get_topic_post_type() To get the topic post type
 * @uses walk_page_dropdown_tree() To generate the dropdown using the
 *                                  walker
 * @uses apply_filters() Calls 'bbp_get_dropdown' with the dropdown
 *                        and args
 * @return string The dropdown
 */
function bbp_get_dropdown($args = '')
{
    /** Arguments *********************************************************/
    $defaults = array('post_type' => bbp_get_forum_post_type(), 'selected' => 0, 'sort_column' => 'menu_order', 'child_of' => '0', 'numberposts' => -1, 'orderby' => 'menu_order', 'order' => 'ASC', 'walker' => '', 'select_id' => 'bbp_forum_id', 'tab' => bbp_get_tab_index(), 'options_only' => false, 'show_none' => false, 'none_found' => false, 'disable_categories' => true);
    $r = bbp_parse_args($args, $defaults, 'get_dropdown');
    if (empty($r['walker'])) {
        $r['walker'] = new BBP_Walker_Dropdown();
        $r['walker']->tree_type = $r['post_type'];
    }
    // Force 0
    if (is_numeric($r['selected']) && $r['selected'] < 0) {
        $r['selected'] = 0;
    }
    extract($r);
    // Unset the args not needed for WP_Query to avoid any possible conflicts.
    // Note: walker and disable_categories are not unset
    unset($r['select_id'], $r['tab'], $r['options_only'], $r['show_none'], $r['none_found']);
    /** Post Status *******************************************************/
    // Define local variable(s)
    $post_stati = array();
    // Public
    $post_stati[] = bbp_get_public_status_id();
    // Forums
    if (bbp_get_forum_post_type() == $post_type) {
        // Private forums
        if (current_user_can('read_private_forums')) {
            $post_stati[] = bbp_get_private_status_id();
        }
        // Hidden forums
        if (current_user_can('read_hidden_forums')) {
            $post_stati[] = bbp_get_hidden_status_id();
        }
    }
    // Setup the post statuses
    $r['post_status'] = implode(',', $post_stati);
    /** Setup variables ***************************************************/
    $name = esc_attr($select_id);
    $select_id = $name;
    $tab = (int) $tab;
    $retval = '';
    $posts = get_posts($r);
    /** Drop Down *********************************************************/
    // Items found
    if (!empty($posts)) {
        if (empty($options_only)) {
            $tab = !empty($tab) ? ' tabindex="' . $tab . '"' : '';
            $retval .= '<select name="' . $name . '" id="' . $select_id . '"' . $tab . '>' . "\n";
        }
        $retval .= !empty($show_none) ? "\t<option value=\"\" class=\"level-0\">" . $show_none . '</option>' : '';
        $retval .= walk_page_dropdown_tree($posts, 0, $r);
        if (empty($options_only)) {
            $retval .= '</select>';
        }
        // No items found - Display feedback if no custom message was passed
    } elseif (empty($none_found)) {
        // Switch the response based on post type
        switch ($post_type) {
            // Topics
            case bbp_get_topic_post_type():
                $retval = __('No topics available', 'bbpress');
                break;
                // Forums
            // Forums
            case bbp_get_forum_post_type():
                $retval = __('No forums available', 'bbpress');
                break;
                // Any other
            // Any other
            default:
                $retval = __('None available', 'bbpress');
                break;
        }
    }
    return apply_filters('bbp_get_dropdown', $retval, $args);
}
Пример #16
0
 /**
  * Save the Group Forum data on create
  *
  * @since bbPress (r3465)
  */
 public function create_screen_save($group_id = 0)
 {
     // Nonce check
     if (!bbp_verify_nonce_request('groups_create_save_' . $this->slug)) {
         bbp_add_error('bbp_create_group_forum_screen_save', __('<strong>ERROR</strong>: Are you sure you wanted to do that?', 'bbpress'));
         return;
     }
     // Check for possibly empty group_id
     if (empty($group_id)) {
         $group_id = bp_get_new_group_id();
     }
     $create_forum = !empty($_POST['bbp-create-group-forum']) ? true : false;
     $forum_id = 0;
     $forum_ids = bbp_get_group_forum_ids($group_id);
     if (!empty($forum_ids)) {
         $forum_id = (int) is_array($forum_ids) ? $forum_ids[0] : $forum_ids;
     }
     // Create a forum, or not
     switch ($create_forum) {
         case true:
             // Bail if initial content was already created
             if (!empty($forum_id)) {
                 return;
             }
             // Set the default forum status
             switch (bp_get_new_group_status()) {
                 case 'hidden':
                     $status = bbp_get_hidden_status_id();
                     break;
                 case 'private':
                     $status = bbp_get_private_status_id();
                     break;
                 case 'public':
                 default:
                     $status = bbp_get_public_status_id();
                     break;
             }
             // Create the initial forum
             $forum_id = bbp_insert_forum(array('post_parent' => bbp_get_group_forums_root_id(), 'post_title' => bp_get_new_group_name(), 'post_content' => bp_get_new_group_description(), 'post_status' => $status));
             // Run the BP-specific functions for new groups
             $this->new_forum(array('forum_id' => $forum_id));
             // Update forum active
             groups_update_groupmeta(bp_get_new_group_id(), '_bbp_forum_enabled_' . $forum_id, true);
             // Toggle forum on
             $this->toggle_group_forum(bp_get_new_group_id(), true);
             break;
         case false:
             // Forum was created but is now being undone
             if (!empty($forum_id)) {
                 // Delete the forum
                 wp_delete_post($forum_id, true);
                 // Delete meta values
                 groups_delete_groupmeta(bp_get_new_group_id(), 'forum_id');
                 groups_delete_groupmeta(bp_get_new_group_id(), '_bbp_forum_enabled_' . $forum_id);
                 // Toggle forum off
                 $this->toggle_group_forum(bp_get_new_group_id(), false);
             }
             break;
     }
 }
Пример #17
0
/**
 * Adjusts forum, topic, and reply queries to exclude items that might be
 * contained inside hidden or private forums that the user does not have the
 * capability to view.
 *
 * Doing it with an action allows us to trap all WP_Query's rather than needing
 * to hardcode this logic into each query. It also protects forum content for
 * plugins that might be doing their own queries.
 *
 * @since bbPress (r3291)
 *
 * @param WP_Query $posts_query
 *
 * @uses apply_filters()
 * @uses bbp_exclude_forum_ids()
 * @uses bbp_get_topic_post_type()
 * @uses bbp_get_reply_post_type()
 * @return WP_Query
 */
function bbp_pre_get_posts_normalize_forum_visibility($posts_query = null)
{
    // Bail if all forums are explicitly allowed
    if (true === apply_filters('bbp_include_all_forums', false, $posts_query)) {
        return;
    }
    // Bail if $posts_query is not an object or of incorrect class
    if (!is_object($posts_query) || !is_a($posts_query, 'WP_Query')) {
        return;
    }
    // Get query post types array .
    $post_types = (array) $posts_query->get('post_type');
    // Forums
    if (bbp_get_forum_post_type() === implode('', $post_types)) {
        // Prevent accidental wp-admin post_row override
        if (is_admin() && isset($_REQUEST['post_status'])) {
            return;
        }
        /** Default ***********************************************************/
        // Get any existing post status
        $post_stati = $posts_query->get('post_status');
        // Default to public status
        if (empty($post_stati)) {
            $post_stati[] = bbp_get_public_status_id();
            // Split the status string
        } elseif (is_string($post_stati)) {
            $post_stati = explode(',', $post_stati);
        }
        /** Private ***********************************************************/
        // Remove bbp_get_private_status_id() if user is not capable
        if (!current_user_can('read_private_forums')) {
            $key = array_search(bbp_get_private_status_id(), $post_stati);
            if (!empty($key)) {
                unset($post_stati[$key]);
            }
            // ...or add it if they are
        } else {
            $post_stati[] = bbp_get_private_status_id();
        }
        /** Hidden ************************************************************/
        // Remove bbp_get_hidden_status_id() if user is not capable
        if (!current_user_can('read_hidden_forums')) {
            $key = array_search(bbp_get_hidden_status_id(), $post_stati);
            if (!empty($key)) {
                unset($post_stati[$key]);
            }
            // ...or add it if they are
        } else {
            $post_stati[] = bbp_get_hidden_status_id();
        }
        // Add the statuses
        $posts_query->set('post_status', array_unique(array_filter($post_stati)));
    }
    // Topics Or Replies
    if (array_intersect(array(bbp_get_topic_post_type(), bbp_get_reply_post_type()), $post_types)) {
        // Get forums to exclude
        $forum_ids = bbp_exclude_forum_ids('meta_query');
        // Bail if no forums to exclude
        if (!array_filter($forum_ids)) {
            return;
        }
        // Get any existing meta queries
        $meta_query = $posts_query->get('meta_query');
        // Add our meta query to existing
        $meta_query[] = $forum_ids;
        // Set the meta_query var
        $posts_query->set('meta_query', $meta_query);
    }
}
Пример #18
0
 /**
  * Save the Group Forum data on create
  *
  * @since bbPress (r3465)
  */
 public function create_screen_save()
 {
     check_admin_referer('groups_create_save_' . $this->slug);
     $create_forum = !empty($_POST['bbp-create-group-forum']) ? true : false;
     $forum_id = 0;
     $forum_ids = bbp_get_group_forum_ids(bp_get_new_group_id());
     if (!empty($forum_ids)) {
         $forum_id = (int) is_array($forum_ids) ? $forum_ids[0] : $forum_ids;
     }
     // Create a forum, or not
     switch ($create_forum) {
         case true:
             // Bail if initial content was already created
             if (!empty($forum_id)) {
                 return;
             }
             // Set the default forum status
             switch (bp_get_new_group_status()) {
                 case 'hidden':
                     $status = bbp_get_hidden_status_id();
                     break;
                 case 'private':
                     $status = bbp_get_private_status_id();
                     break;
                 case 'public':
                 default:
                     $status = bbp_get_public_status_id();
                     break;
             }
             // Create the initial forum
             $forum_id = bbp_insert_forum(array('post_parent' => bbp_get_group_forums_root_id(), 'post_title' => bp_get_new_group_name(), 'post_content' => bp_get_new_group_description(), 'post_status' => $status));
             // Run the BP-specific functions for new groups
             $this->new_forum(array('forum_id' => $forum_id));
             break;
         case false:
             // Forum was created but is now being undone
             if (!empty($forum_id)) {
                 wp_delete_post($forum_id, true);
                 groups_delete_groupmeta(bp_get_new_group_id(), 'forum_id');
             }
             break;
     }
 }