Example #1
0
 /**
  * Instantiate classes for BuddyPress integration
  *
  * @since bbPress (r3395)
  */
 public function setup_components()
 {
     // Always load the members component
     bbpress()->extend->buddypress->members = new BBP_BuddyPress_Members();
     // Create new activity class
     if (bp_is_active('activity')) {
         bbpress()->extend->buddypress->activity = new BBP_BuddyPress_Activity();
     }
     // Register the group extension only if groups are active
     if (bbp_is_group_forums_active() && bp_is_active('groups')) {
         bp_register_group_extension('BBP_Forums_Group_Extension');
     }
 }
Example #2
0
/**
 * Allow BuddyPress group forums setting field
 *
 * @since 2.1.0 bbPress (r3575)
 *
 * @uses checked() To display the checked attribute
 */
function bbp_admin_setting_callback_group_forums()
{
    ?>

	<input name="_bbp_enable_group_forums" id="_bbp_enable_group_forums" type="checkbox" value="1" <?php 
    checked(bbp_is_group_forums_active(true));
    bbp_maybe_admin_setting_disabled('_bbp_enable_group_forums');
    ?>
 />
	<label for="_bbp_enable_group_forums"><?php 
    esc_html_e('Allow BuddyPress Groups to have their own forums', 'bbpress');
    ?>
</label>

<?php 
}
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;
}
Example #4
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 
}
Example #5
0
/**
 * Add the topic title to the <title> if viewing a single group forum topic
 *
 * @since bbPress (r5161)
 *
 * @param string $new_title The title to filter
 * @param string $old_title (Not used)
 * @param string $sep The separator to use
 * @return string The possibly modified title
 */
function bbp_filter_modify_page_title($new_title = '', $old_title = '', $sep = '')
{
    // Only filter if group forums are active
    if (bbp_is_group_forums_active()) {
        // Only filter for single group forum topics
        if (bp_is_group_forum_topic() || bp_is_group_forum_topic_edit()) {
            // Get the topic
            $topic = get_posts(array('name' => bp_action_variable(1), 'post_status' => 'publish', 'post_type' => bbp_get_topic_post_type(), 'numberposts' => 1));
            // Add the topic title to the <title>
            $new_title .= bbp_get_topic_title($topic[0]->ID) . ' ' . $sep . ' ';
        }
    }
    // Return the title
    return $new_title;
}
function add_group_meta_box()
{
    global $bp;
    ?>
	<fieldset>
		<legend class="screen-reader-text"><span><?php 
    _e('Core Group Options', 'bp-group-organizer');
    ?>
</span></legend>
		<p><label for="group_name">
			<?php 
    _e('Group Name', 'bp-group-organizer');
    ?>
<input id="group_name" type="text" name="group_name" value="" />
		</label></p>
		<p><label for="group_slug">
			<?php 
    _e('Group Slug', 'bp-group-organizer');
    ?>
			<input id="group_slug" type="text" name="group_slug" value="" />
		</label></p>
		<p><label for="group_desc">
			<?php 
    _e('Group Description', 'bp-group-organizer');
    ?>
			<input id="group_desc" type="text" name="group_desc" value="" />
		</label></p>
	</fieldset>
	<fieldset>
		<legend class="screen-reader-text"><span><?php 
    _e('Advanced Group Options', 'bp-group-organizer');
    ?>
</span></legend>
		<p><label for="group_status">
			<?php 
    _e('Privacy Options', 'buddypress');
    ?>
			<select id="group_status" name="group_status">
				<?php 
    foreach ($bp->groups->valid_status as $status) {
        ?>
				<option value="<?php 
        echo $status;
        ?>
"><?php 
        echo ucfirst($status);
        ?>
</option>
				<?php 
    }
    ?>
			</select>
		</label></p>
		<?php 
    if (bp_is_active('forums') && (function_exists('bp_forums_is_installed_correctly') && bp_forums_is_installed_correctly())) {
        ?>
		<p><label for="group_forum">
			<?php 
        _e('Enable discussion forum', 'buddypress');
        ?>
			<input id="group_forum" type="checkbox" name="group_forum" checked />
		</label></p>
		<?php 
    } elseif (function_exists('bbp_is_group_forums_active') && bbp_is_group_forums_active()) {
        ?>
		<p><label for="group_forum">
			<?php 
        _e('Enable bbPress discussion forum', 'bp-group-organizer');
        ?>
			<input id="group_forum" type="checkbox" name="group_forum" checked />
		</label></p>
		<?php 
    }
    ?>
		<p><label for="group_creator">
			<?php 
    _e('Group Creator', 'bp-group-organizer');
    ?>
			<input id="group_creator" type="text" name="group_creator" value="" />
		</label></p>
	</fieldset>
	<?php 
    if (defined('BP_GROUP_HIERARCHY_IS_INSTALLED')) {
        ?>
	<fieldset><legend class="screen-reader-text"><span><?php 
        _e('Group Hierarchy Options');
        ?>
</span></legend>
		<?php 
        if (method_exists('BP_Groups_Hierarchy', 'get_tree')) {
            ?>
		<p><label for="group_parent">
			<?php 
            _e('Parent Group', 'bp-group-hierarchy');
            ?>
			<?php 
            $all_groups = BP_Groups_Hierarchy::get_tree();
            ?>
			<select name="group_parent" id="group_parent">
				<option value="0"><?php 
            _e('Site Root', 'bp-group-hierarchy');
            ?>
</option>
				<?php 
            foreach ($all_groups as $group) {
                ?>
				<option value="<?php 
                echo $group->id;
                ?>
"><?php 
                echo esc_html(stripslashes($group->name));
                ?>
 (<?php 
                echo $group->slug;
                ?>
)</option>
				<?php 
            }
            ?>
			</select>
		</label></p>
		<?php 
        } else {
            ?>
		<p><?php 
            _e('Your version of BuddyPress Group Hierarchy is too old to use with the organizer. Please upgrade to version <code>1.2.1</code> or higher.', 'bp-group-organizer');
            ?>
</p>
		<?php 
        }
        ?>
	</fieldset>
	<?php 
    }
    ?>
	<?php 
    do_action('bp_group_organizer_display_new_group_options');
    ?>
	<p><?php 
    _e('Create a group to add to your site.', 'bp-group-organizer');
    ?>
</p>
	<p class="button-controls">
		<?php 
    submit_button(__('Add'), 'button-primary primary right', 'group-organizer-create', false);
    ?>
		<span class="spinner"></span>
	</p>
	<?php 
}
/**
 * Determine what type of forums are running on this BP install.
 *
 * Returns either 'bbpress' or 'buddypress' on success.
 * Boolean false if neither forums are enabled.
 *
 * @since 3.4
 *
 * @return mixed String of forum type on success; boolean false if forums aren't installed.
 */
function ass_get_forum_type()
{
    // sanity check
    if (!bp_is_active('groups')) {
        return false;
    }
    $type = false;
    // check if bbP is installed
    if (class_exists('bbpress') and function_exists('bbp_is_group_forums_active')) {
        // check if bbP group forum support is active
        if (!bbp_is_group_forums_active()) {
            return false;
        }
        $type = 'bbpress';
        // check for BP's bundled forums
    } else {
        // BP's bundled forums aren't installed correctly, so stop!
        if (!bp_is_active('forums') || !bp_forums_is_installed_correctly()) {
            return false;
        }
        $type = 'buddypress';
    }
    return $type;
}
Example #8
0
/**
 * Creates the Forums component in BuddyPress
 *
 * @since bbPress (r3653)
 *
 * @global type $bp
 * @return If bbPress is not active
 */
function bbp_setup_buddypress_component()
{
    global $bp;
    // Bail if no BuddyPress
    if (!empty($bp->maintenance_mode) || !defined('BP_VERSION')) {
        return;
    }
    // Bail if BuddyPress Forums are already active
    if (bp_is_active('forums') && bp_forums_is_installed_correctly()) {
        return;
    }
    // Create the new BuddyPress Forums component
    $bp->forums = new BBP_Forums_Component();
    // Register the group extension only if groups are active
    if (bbp_is_group_forums_active() && bp_is_active('groups')) {
        bp_register_group_extension('BBP_Forums_Group_Extension');
    }
}