예제 #1
0
/**
 * Function for creating groups with parents programmatically
 * @param array Args same as groups_create_group, but accepts a 'parent_id' param
 */
function groups_hierarchy_create_group($args = '')
{
    if ($group_id = groups_create_group($args)) {
        if (isset($args['parent_id'])) {
            $group = new BP_Groups_Hierarchy($group_id);
            $group->parent_id = (int) $args['parent_id'];
            $group->save();
        }
        return $group_id;
    }
    return false;
}
/**
 * Before deleting a group, move all its child groups to its immediate parent.
 */
function bp_group_hierarchy_rescue_child_groups(&$parent_group)
{
    $parent_group_id = $parent_group->id;
    if ($child_groups = BP_Groups_Hierarchy::has_children($parent_group_id)) {
        $group = new BP_Groups_Hierarchy($parent_group_id);
        if ($group) {
            $new_parent_group_id = $group->parent_id;
        } else {
            $new_parent_group_id = 0;
        }
        foreach ($child_groups as $group_id) {
            $child_group = new BP_Groups_Hierarchy($group_id);
            $child_group->parent_id = $new_parent_group_id;
            $child_group->save();
        }
    }
}
/**
 * Catch requests for groups by parent and use BP_Groups_Hierarchy::get_by_parent to handle
 */
function bp_group_hierarchy_get_by_hierarchy($args)
{
    $defaults = array('type' => 'active', 'user_id' => false, 'search_terms' => false, 'per_page' => 20, 'page' => 1, 'parent_id' => 0, 'populate_extras' => true);
    $params = wp_parse_args($args, $defaults);
    extract($params, EXTR_SKIP);
    if (isset($parent_id)) {
        $groups = BP_Groups_Hierarchy::get_by_parent($parent_id, $type, $per_page, $page, $user_id, $search_terms, $populate_extras);
    }
    return $groups;
}
/**
 * Get an array of a group's children (direct descendants)
 * NOTE: please do not use this to create a pseudo-loop for child groups.
 *       Just use bp_has_groups_hierarchy and life will be better
 * @param BP_Groups_Hierarchy_Template $group optional group object (only needed if not in the loop)
 */
function bp_group_hierarchy_get_subgroups($group = null)
{
    global $groups_template;
    if (!$group) {
        $group =& $groups_template->group;
    }
    $children = BP_Groups_Hierarchy::has_children($group->id);
    return $children;
}
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;
}
예제 #6
0
function bp_group_organizer_admin_page()
{
    global $wpdb;
    // Permissions Check
    if (!current_user_can('manage_options')) {
        wp_die(__('Cheatin’ 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 
}
예제 #7
0
 /**
  * A hierarchy-aware copy of the setup_globals function from BP_Groups_Component
  */
 function setup_globals($args = array())
 {
     global $bp;
     // Define a slug, if necessary
     if (!defined('BP_GROUPS_SLUG')) {
         define('BP_GROUPS_SLUG', $this->id);
     }
     // Global tables for messaging component
     $global_tables = array('table_name' => $bp->table_prefix . 'bp_groups', 'table_name_members' => $bp->table_prefix . 'bp_groups_members', 'table_name_groupmeta' => $bp->table_prefix . 'bp_groups_groupmeta');
     // Metadata tables for groups component
     $meta_tables = array('group' => $bp->table_prefix . 'bp_groups_groupmeta');
     // All globals for messaging component.
     // Note that global_tables is included in this array.
     $globals = array('path' => BP_PLUGIN_DIR, 'slug' => BP_GROUPS_SLUG, 'root_slug' => isset($bp->pages->groups->slug) ? $bp->pages->groups->slug : BP_GROUPS_SLUG, 'has_directory' => true, 'notification_callback' => 'groups_format_notifications', 'search_string' => __('Search Groups...', 'buddypress'), 'global_tables' => $global_tables, 'meta_tables' => $meta_tables);
     call_user_func(array(get_parent_class(get_parent_class($this)), 'setup_globals'), $globals);
     /** Single Group Globals **********************************************/
     // Are we viewing a single group?
     if (bp_is_groups_component() && ($group_id = BP_Groups_Hierarchy::group_exists(bp_current_action()))) {
         $bp->is_single_item = true;
         $current_group_class = apply_filters('bp_groups_current_group_class', 'BP_Groups_Hierarchy');
         if ('BP_Groups_Hierarchy' == $current_group_class) {
             $this->current_group = new BP_Groups_Hierarchy($group_id, 0, array('populate_extras' => true));
         } else {
             $this->current_group = apply_filters('bp_groups_current_group_object', new $current_group_class($group_id));
         }
         // When in a single group, the first action is bumped down one because of the
         // group name, so we need to adjust this and set the group name to current_item.
         $bp->current_item = bp_current_action();
         $bp->current_action = bp_action_variable(0);
         array_shift($bp->action_variables);
         // Using "item" not "group" for generic support in other components.
         if (is_super_admin() || function_exists('bp_current_user_can') && bp_current_user_can('bp_moderate')) {
             bp_update_is_item_admin(true, 'groups');
         } else {
             bp_update_is_item_admin(groups_is_user_admin(bp_loggedin_user_id(), $this->current_group->id), 'groups');
         }
         // If the user is not an admin, check if they are a moderator
         if (!bp_is_item_admin()) {
             bp_update_is_item_mod(groups_is_user_mod(bp_loggedin_user_id(), $this->current_group->id), 'groups');
         }
         // Is the logged in user a member of the group?
         if (is_user_logged_in() && groups_is_user_member(bp_loggedin_user_id(), $this->current_group->id)) {
             $this->current_group->is_user_member = true;
         } else {
             $this->current_group->is_user_member = false;
         }
         // Should this group be visible to the logged in user?
         if ('public' == $this->current_group->status || $this->current_group->is_user_member) {
             $this->current_group->is_visible = true;
         } else {
             $this->current_group->is_visible = false;
         }
         // If this is a private or hidden group, does the user have access?
         if ('private' == $this->current_group->status || 'hidden' == $this->current_group->status) {
             if ($this->current_group->is_user_member && is_user_logged_in() || is_super_admin() || function_exists('bp_current_user_can') && bp_current_user_can('bp_moderate')) {
                 $this->current_group->user_has_access = true;
             } else {
                 $this->current_group->user_has_access = false;
             }
         } else {
             $this->current_group->user_has_access = true;
         }
         // Set current_group to 0 to prevent debug errors
     } else {
         $this->current_group = 0;
     }
     // Illegal group names/slugs
     $this->forbidden_names = apply_filters('groups_forbidden_names', array('my-groups', 'create', 'invites', 'send-invites', 'forum', 'delete', 'add', 'admin', 'request-membership', 'members', 'settings', 'avatar', $this->slug, $this->root_slug));
     // If the user was attempting to access a group, but no group by that name was found, 404
     if (bp_is_groups_component() && empty($this->current_group) && bp_current_action() && !in_array(bp_current_action(), $this->forbidden_names)) {
         bp_do_404();
         return;
     }
     if (bp_is_groups_component() && !empty($this->current_group)) {
         $this->default_extension = apply_filters('bp_groups_default_extension', defined('BP_GROUPS_DEFAULT_EXTENSION') ? BP_GROUPS_DEFAULT_EXTENSION : 'home');
         if (!bp_current_action()) {
             $bp->current_action = $this->default_extension;
         }
         // Prepare for a redirect to the canonical URL
         $bp->canonical_stack['base_url'] = bp_get_group_permalink($this->current_group);
         if (bp_current_action()) {
             $bp->canonical_stack['action'] = bp_current_action();
         }
         if (!empty($bp->action_variables)) {
             $bp->canonical_stack['action_variables'] = bp_action_variables();
         }
         // When viewing the default extension, the canonical URL should not have
         // that extension's slug, unless more has been tacked onto the URL via
         // action variables
         if (bp_is_current_action($this->default_extension) && empty($bp->action_variables)) {
             unset($bp->canonical_stack['action']);
         }
     }
     // Group access control
     if (bp_is_groups_component() && !empty($this->current_group)) {
         if (!$this->current_group->user_has_access) {
             // Hidden groups should return a 404 for non-members.
             // Unset the current group so that you're not redirected
             // to the default group tab
             if ('hidden' == $this->current_group->status) {
                 $this->current_group = 0;
                 $bp->is_single_item = false;
                 bp_do_404();
                 return;
                 // Skip the no_access check on home and membership request pages
             } elseif (!in_array(bp_current_action(), apply_filters('bp_group_hierarchy_allow_anon_access', array('home', 'request-membership', BP_GROUP_HIERARCHY_SLUG)))) {
                 // Off-limits to this user. Throw an error and redirect to the group's home page
                 if (is_user_logged_in()) {
                     bp_core_no_access(array('message' => __('You do not have access to this group.', 'buddypress'), 'root' => bp_get_group_permalink($bp->groups->current_group), 'redirect' => false));
                     // User does not have access, and does not get a message
                 } else {
                     bp_core_no_access();
                 }
             }
         }
         // Protect the admin tab from non-admins
         if (bp_is_current_action('admin') && !bp_is_item_admin()) {
             bp_core_no_access(array('message' => __('You are not an admin of this group.', 'buddypress'), 'root' => bp_get_group_permalink($bp->groups->current_group), 'redirect' => false));
         }
     }
     // Preconfigured group creation steps
     $this->group_creation_steps = apply_filters('groups_create_group_steps', array('group-details' => array('name' => __('Details', 'buddypress'), 'position' => 0), 'group-settings' => array('name' => __('Settings', 'buddypress'), 'position' => 10)));
     // If avatar uploads are not disabled, add avatar option
     if (!(int) bp_get_option('bp-disable-avatar-uploads')) {
         $this->group_creation_steps['group-avatar'] = array('name' => __('Avatar', 'buddypress'), 'position' => 20);
     }
     // If friends component is active, add invitations
     if (bp_is_active('friends')) {
         $this->group_creation_steps['group-invites'] = array('name' => __('Invites', 'buddypress'), 'position' => 30);
     }
     // Groups statuses
     $this->valid_status = apply_filters('groups_valid_status', array('public', 'private', 'hidden'));
     // Auto join group when non group member performs group activity
     $this->auto_join = defined('BP_DISABLE_AUTO_GROUP_JOIN') && BP_DISABLE_AUTO_GROUP_JOIN ? false : true;
 }
예제 #8
0
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 
}
/**
 * Override the group slug in permalinks with a group's full path
 */
function bp_group_hierarchy_fixup_permalink($permalink)
{
    global $bp;
    $group_slug = substr($permalink, strlen($bp->root_domain . '/' . bp_get_groups_root_slug() . '/'), -1);
    if (strpos($group_slug, '/')) {
        return $permalink;
    }
    $group_id = BP_Groups_Group::get_id_from_slug($group_slug);
    if ($group_id) {
        $group_path = BP_Groups_Hierarchy::get_path($group_id);
        return str_replace('/' . $group_slug . '/', '/' . $group_path . '/', $permalink);
    }
    return $permalink;
}
예제 #10
0
    function edit_screen()
    {
        global $bp;
        if (!bp_is_group_admin_screen($this->slug)) {
            return false;
        }
        if (is_super_admin()) {
            $exclude_groups = BP_Groups_Hierarchy::get_by_parent($bp->groups->current_group->id);
            if (count($exclude_groups['groups']) > 0) {
                foreach ($exclude_groups['groups'] as $key => $exclude_group) {
                    $exclude_groups['groups'][$key] = $exclude_group->id;
                }
                $exclude_groups = $exclude_groups['groups'];
            } else {
                $exclude_groups = array();
            }
            $exclude_groups[] = $bp->groups->current_group->id;
            $groups = BP_Groups_Hierarchy::get('alphabetical', null, null, 0, false, false, true, $exclude_groups);
            $site_root = new stdClass();
            $site_root->id = 0;
            $site_root->name = __('Site Root', 'bp-group-hierarchy');
            $display_groups = array($site_root);
            foreach ($groups['groups'] as $group) {
                $display_groups[] = $group;
            }
            /* deprecated */
            $display_groups = apply_filters('bp_group_hierarchy_display_groups', $display_groups);
            $display_groups = apply_filters('bp_group_hierarchy_available_parent_groups', $display_groups);
            ?>
			<label for="parent_id"><?php 
            _e('Parent Group', 'bp-group-hierarchy');
            ?>
</label>
			<select name="parent_id" id="parent_id">
				<?php 
            foreach ($display_groups as $group) {
                ?>
					<option value="<?php 
                echo $group->id;
                ?>
"<?php 
                if ($group->id == $bp->groups->current_group->parent_id) {
                    echo ' selected';
                }
                ?>
><?php 
                echo stripslashes($group->name);
                ?>
</option>
				<?php 
            }
            ?>
			</select>
			<?php 
        } else {
            ?>
			<div id="message">
				<p><?php 
            _e('Only a site administrator can edit the group hierarchy.', 'bp-group-hierarchy');
            ?>
</p>
			</div>
			<?php 
        }
        if (is_super_admin() || bp_group_is_admin()) {
            $subgroup_permission_options = apply_filters('bp_group_hierarchy_subgroup_permission_options', $this->subgroup_permission_options);
            $current_subgroup_permission = groups_get_groupmeta($bp->groups->current_group->id, 'bp_group_hierarchy_subgroup_creators');
            if ($current_subgroup_permission == '') {
                $current_subgroup_permission = $this->get_default_permission_option();
            }
            $permission_select = '<select name="allow_children_by" id="allow_children_by">';
            foreach ($subgroup_permission_options as $option => $text) {
                $permission_select .= '<option value="' . $option . '"' . ($option == $current_subgroup_permission ? ' selected' : '') . '>' . $text . '</option>' . "\n";
            }
            $permission_select .= '</select>';
            ?>
			<p>
				<label for="allow_children_by"><?php 
            _e('Member Groups', 'bp-group-hierarchy');
            ?>
</label>
				<?php 
            printf(__('Allow %1$s to create %2$s', 'bp-group-hierarchy'), $permission_select, __('Member Groups', 'bp-group-hierarchy'));
            ?>
			</p>
			<p>
				<input type="submit" class="button primary" id="save" name="save" value="<?php 
            _e('Save Changes', 'bp-group-hierarchy');
            ?>
" />
			</p>
			<?php 
            wp_nonce_field('groups_edit_save_' . $this->slug);
        }
    }
예제 #11
0
    /**
     * @see Walker::start_el()
     * @since 3.0.0
     *
     * @param string $output Passed by reference. Used to append additional content.
     * @param object $item Menu item data object.
     * @param int $depth Depth of menu item. Used for padding.
     * @param object $args
     */
    function start_el(&$output, $item, $depth, $args)
    {
        global $_wp_nav_menu_max_depth, $bp, $groups_template;
        $_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth;
        $indent = $depth ? str_repeat("\t", $depth) : '';
        ob_start();
        $item_id = esc_attr($item->id);
        $removed_args = array('action', 'customlink-tab', 'edit-menu-item', 'menu-item', 'page-tab', '_wpnonce');
        $classes = array('menu-item menu-item-depth-' . $depth, 'menu-item-edit-' . (isset($_GET['edit-menu-item']) && $item_id == $_GET['edit-menu-item'] ? 'active' : 'inactive'));
        /** Set global $groups_template to current group so we can use BP groups template functions */
        $groups_template->group = $item;
        $title = $item->name;
        if (isset($item->status) && 'private' == $item->status) {
            $classes[] = 'status-private';
            /* translators: %s: title of private group */
            $title = sprintf(__('%s (Private)', 'bp-group-organizer'), $title);
        } elseif (isset($item->status) && 'hidden' == $item->status) {
            $classes[] = 'status-hidden';
            /* translators: %s: title of hidden group */
            $title = sprintf(__('%s (Hidden)', 'bp-group-organizer'), $title);
        }
        if (defined('BP_GROUP_HIERARCHY_IS_INSTALLED') && method_exists('BP_Groups_Hierarchy', 'get_tree')) {
            $all_groups = BP_Groups_Hierarchy::get_tree();
        }
        ?>
		<li id="menu-item-<?php 
        echo $item_id;
        ?>
" class="<?php 
        echo implode(' ', $classes);
        ?>
">
			<dl class="menu-item-bar">
				<dt class="menu-item-handle">
					<span class="item-title"><?php 
        bp_group_avatar_micro();
        ?>
 <?php 
        echo esc_html(stripslashes($title));
        ?>
</span>
					<span class="item-controls">
						<span class="item-type"><?php 
        echo esc_html($item->slug);
        ?>
</span>
						<a class="item-edit" id="edit-<?php 
        echo $item_id;
        ?>
" title="<?php 
        _e('Edit Group', 'bp-group-organizer');
        ?>
" href="<?php 
        echo isset($_GET['edit-menu-item']) && $item_id == $_GET['edit-menu-item'] ? admin_url('nav-menus.php') : add_query_arg('edit-menu-item', $item_id, remove_query_arg($removed_args, admin_url('nav-menus.php#menu-item-settings-' . $item_id)));
        ?>
"><?php 
        _e('Edit Group', 'bp-group-organizer');
        ?>
</a>
					</span>
				</dt>
			</dl>

			<div class="menu-item-settings" id="menu-item-settings-<?php 
        echo $item_id;
        ?>
">
				<p class="description description-thin">
					<label for="group-name-<?php 
        echo $item_id;
        ?>
">
						<?php 
        _e('Group Name', 'bp-group-organizer');
        ?>
<br />
						<input type="text" id="group-name-<?php 
        echo $item_id;
        ?>
" class="widefat edit-menu-item-title" name="group[<?php 
        echo $item_id;
        ?>
][name]" value="<?php 
        echo esc_attr(stripslashes($item->name));
        ?>
" />
					</label>
				</p>
				<p class="description description-thin">
					<label for="group-slug-<?php 
        echo $item_id;
        ?>
">
						<?php 
        _e('Group Slug', 'bp-group-organizer');
        ?>
<br />
						<input type="text" id="group-slug-<?php 
        echo $item_id;
        ?>
" class="widefat edit-menu-item-attr-title" name="group[<?php 
        echo $item_id;
        ?>
][slug]" value="<?php 
        echo esc_attr($item->slug);
        ?>
" />
					</label>
				</p>
				<p class="field-description description description-wide">
					<label for="group-description-<?php 
        echo $item_id;
        ?>
">
						<?php 
        _e('Group Description', 'bp-group-organizer');
        ?>
<br />
						<textarea id="group-description-<?php 
        echo $item_id;
        ?>
" class="widefat edit-menu-item-description" rows="3" cols="20" name="group[<?php 
        echo $item_id;
        ?>
][description]"><?php 
        echo esc_textarea(stripslashes($item->description));
        // textarea_escaped
        ?>
</textarea>
						<span class="description"><?php 
        _e('Enter a brief description for this group.');
        ?>
</span>
					</label>
				</p>
				<?php 
        if (bp_is_active('forums') && (function_exists('bp_forums_is_installed_correctly') && bp_forums_is_installed_correctly())) {
            ?>
				<p class="field-css-classes description description-wide">
					<label for="group-forum-enabled-<?php 
            echo $item_id;
            ?>
">
						<?php 
            _e('Enable discussion forum', 'buddypress');
            ?>
<br />
						<input type="checkbox" id="group-forum-enabled-<?php 
            echo $item_id;
            ?>
" class="widefat edit-menu-item-classes" name="group[<?php 
            echo $item_id;
            ?>
][forum_enabled]" <?php 
            checked($item->enable_forum);
            ?>
 />
					</label>
				</p>
				<?php 
        }
        ?>
				<p class="field-link-target description description-thin">
					<label for="group-status-<?php 
        echo $item_id;
        ?>
">
						<?php 
        _e('Privacy Options', 'buddypress');
        ?>
<br />
						<select id="group-status-<?php 
        echo $item_id;
        ?>
" class="widefat edit-menu-item-target" name="group[<?php 
        echo $item_id;
        ?>
][status]">
							<?php 
        foreach ($bp->groups->valid_status as $status) {
            ?>
							<option value="<?php 
            echo $status;
            ?>
" <?php 
            selected($item->status, $status);
            ?>
><?php 
            echo ucfirst($status);
            ?>
</option>
							<?php 
        }
        ?>
						</select>
					</label>
				</p>
				
				<?php 
        if (defined('BP_GROUP_HIERARCHY_IS_INSTALLED') && method_exists('BP_Groups_Hierarchy', 'get_tree')) {
            ?>
				<p class="field-xfn description description-thin">
					<label for="group-parent-id-<?php 
            echo $item_id;
            ?>
">
						<?php 
            _e('Parent Group', 'bp-group-hierarchy');
            ?>
<br />
						<select id="group-parent-id-<?php 
            echo $item_id;
            ?>
" class="widefat edit-menu-item-target" name="group[<?php 
            echo $item_id;
            ?>
][parent_id]">
							<option value="0" <?php 
            selected($item->parent_id, 0);
            ?>
><?php 
            _e('Site Root', 'bp_group_hierarchy');
            ?>
</option>
							<?php 
            foreach ($all_groups as $group) {
                ?>
							<option value="<?php 
                echo $group->id;
                ?>
" <?php 
                selected($item->parent_id, $group->id);
                ?>
><?php 
                echo esc_html(stripslashes($group->name));
                ?>
 (<?php 
                echo $group->slug;
                ?>
)</option>
							<?php 
            }
            ?>
						</select>
					</label>
				</p>
				<?php 
        }
        ?>
				
				<?php 
        do_action('bp_group_organizer_display_group_options', $item);
        ?>
				
				<div class="menu-item-actions description-wide submitbox">
					<p class="link-to-original">
						<?php 
        printf(__('Link: %s', 'bp-group-organizer'), '<a href="' . bp_get_group_permalink() . '">' . esc_html(stripslashes($item->name)) . '</a>');
        ?>
					</p>
					<a class="item-delete submitdelete deletion" id="delete-<?php 
        echo $item_id;
        ?>
" href="<?php 
        echo wp_nonce_url(add_query_arg(array('action' => 'delete-group', 'group_id' => $item_id), remove_query_arg($removed_args, admin_url('admin.php?page=group_organizer'))), 'delete-group_' . $item_id);
        ?>
"><?php 
        _e('Delete Group', 'bp-group-organizer');
        ?>
</a> <span class="meta-sep"> | </span> <a class="item-cancel submitcancel" id="cancel-<?php 
        echo $item_id;
        ?>
" href="<?php 
        echo esc_url(add_query_arg(array('edit-menu-item' => $item_id, 'cancel' => time()), remove_query_arg($removed_args, admin_url('nav-menus.php'))));
        ?>
#menu-item-settings-<?php 
        echo $item_id;
        ?>
"><?php 
        _e('Cancel');
        ?>
</a>
				</div>

				<input class="menu-item-data-db-id" type="hidden" name="menu-item-db-id[<?php 
        echo $item_id;
        ?>
]" value="<?php 
        echo $item_id;
        ?>
" />
				<input class="menu-item-data-object-id" type="hidden" name="menu-item-object-id[<?php 
        echo $item_id;
        ?>
]" value="<?php 
        echo esc_attr($item->object_id);
        ?>
" />
				<input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php 
        echo $item_id;
        ?>
]" value="<?php 
        echo esc_attr($item->object);
        ?>
" />
				<input class="menu-item-data-parent-id" type="hidden" name="menu-item-parent-id[<?php 
        echo $item_id;
        ?>
]" value="<?php 
        echo esc_attr($item->parent_id);
        ?>
" />
				<input class="menu-item-data-position" type="hidden" name="menu-item-position[<?php 
        echo $item_id;
        ?>
]" value="<?php 
        echo esc_attr($item->menu_order);
        ?>
" />
				<input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php 
        echo $item_id;
        ?>
]" value="<?php 
        echo esc_attr($item->type);
        ?>
" />
			</div><!-- .menu-item-settings-->
			<ul class="menu-item-transport"></ul>
		<?php 
        $output .= ob_get_clean();
    }