/**
 * Outputs the markup for the Associated Group settings section
 *
 * @since 1.2
 */
function bp_docs_doc_associated_group_markup()
{
    // First, try to set the preselected group by looking at the URL params
    $selected_group_slug = isset($_GET['group']) ? $_GET['group'] : '';
    // Support for BP Group Hierarchy
    if (false !== ($slash = strrpos($selected_group_slug, '/'))) {
        $selected_group_slug = substr($selected_group_slug, $slash + 1);
    }
    $selected_group = BP_Groups_Group::get_id_from_slug($selected_group_slug);
    if ($selected_group && !current_user_can('bp_docs_associate_with_group', $selected_group)) {
        $selected_group = 0;
    }
    // If the selected group is still 0, see if there's something in the db
    if (!$selected_group && is_singular()) {
        $selected_group = bp_docs_get_associated_group_id(get_the_ID());
    }
    // Last check: if this is a second attempt at a newly created Doc,
    // there may be a previously submitted value
    if (empty($selected_group) && !empty(buddypress()->bp_docs->submitted_data->associated_group_id)) {
        $selected_group = intval(buddypress()->bp_docs->submitted_data->associated_group_id);
    }
    $selected_group = intval($selected_group);
    $groups_args = array('per_page' => false, 'populate_extras' => false, 'type' => 'alphabetical');
    if (!bp_current_user_can('bp_moderate')) {
        $groups_args['user_id'] = bp_loggedin_user_id();
    }
    // Populate the $groups_template global
    global $groups_template;
    $old_gt = $groups_template;
    bp_has_groups($groups_args);
    // Filter out the groups where associate_with permissions forbid
    $removed = 0;
    foreach ($groups_template->groups as $gtg_key => $gtg) {
        if (!current_user_can('bp_docs_associate_with_group', $gtg->id)) {
            unset($groups_template->groups[$gtg_key]);
            $removed++;
        }
    }
    // cleanup, if necessary from filter above
    if ($removed) {
        $groups_template->groups = array_values($groups_template->groups);
        $groups_template->group_count = $groups_template->group_count - $removed;
        $groups_template->total_group_count = $groups_template->total_group_count - $removed;
    }
    ?>
	<tr>
		<td class="desc-column">
			<label for="associated_group_id"><?php 
    _e('Which group should this Doc be associated with?', 'bp-docs');
    ?>
</label>
			<span class="description"><?php 
    _e('(Optional) Note that the Access settings available for this Doc may be limited by the privacy settings of the group you choose.', 'bp-docs');
    ?>
</span>
		</td>

		<td class="content-column">
			<select name="associated_group_id" id="associated_group_id">
				<option value=""><?php 
    _e('None', 'bp-docs');
    ?>
</option>
				<?php 
    foreach ($groups_template->groups as $g) {
        ?>
					<option value="<?php 
        echo esc_attr($g->id);
        ?>
" <?php 
        selected($selected_group, $g->id);
        ?>
><?php 
        echo esc_html($g->name);
        ?>
</option>
				<?php 
    }
    ?>
			</select>

			<div id="associated_group_summary">
				<?php 
    bp_docs_associated_group_summary();
    ?>
			</div>
		</td>
	</tr>
	<?php 
    $groups_template = $old_gt;
}
/**
 * Outputs the markup for the Associated Group settings section
 *
 * @since 1.2
 */
function bp_docs_doc_associated_group_markup()
{
    global $groups_template;
    $old_gt = $groups_template;
    // First, try to set the preselected group by looking at the URL params
    $selected_group_slug = isset($_GET['group']) ? $_GET['group'] : '';
    // Support for BP Group Hierarchy
    if (false !== ($slash = strrpos($selected_group_slug, '/'))) {
        $selected_group_slug = substr($selected_group_slug, $slash + 1);
    }
    $selected_group = BP_Groups_Group::get_id_from_slug($selected_group_slug);
    if ($selected_group && !current_user_can('bp_docs_associate_with_group', $selected_group)) {
        $selected_group = 0;
    }
    // If the selected group is still 0, see if there's something in the db
    if (!$selected_group && is_singular()) {
        $selected_group = bp_docs_get_associated_group_id(get_the_ID());
    }
    // Last check: if this is a second attempt at a newly created Doc,
    // there may be a previously submitted value
    if (empty($selected_group) && !empty(buddypress()->bp_docs->submitted_data->associated_group_id)) {
        $selected_group = buddypress()->bp_docs->submitted_data->associated_group_id;
    }
    $selected_group = intval($selected_group);
    ?>
	<tr>
		<td class="desc-column">
			<label for="associated_group_id"><?php 
    _e('Which group should this Doc be associated with?', 'bp-docs');
    ?>
</label>
			<span class="description"><?php 
    _e('(Optional) Note that the Access settings available for this Doc may be limited by the privacy settings of the group you choose.', 'bp-docs');
    ?>
</span>
		</td>

		<td class="content-column">
			<?php 
    bp_docs_associated_group_dropdown(array('name' => 'associated_group_id', 'id' => 'associated_group_id', 'selected' => $selected_group));
    ?>

			<div id="associated_group_summary">
				<?php 
    bp_docs_associated_group_summary();
    ?>
			</div>
		</td>
	</tr>
	<?php 
    $groups_template = $old_gt;
}
/**
 * Outputs the markup for the Associated Group settings section
 *
 * @since 1.2
 */
function bp_docs_doc_associated_group_markup()
{
    // First, try to set the preselected group by looking at the URL params
    $selected_group_slug = isset($_GET['group']) ? $_GET['group'] : '';
    // Support for BP Group Hierarchy
    if (false !== ($slash = strrpos($selected_group_slug, '/'))) {
        $selected_group_slug = substr($selected_group_slug, $slash + 1);
    }
    $selected_group = BP_Groups_Group::get_id_from_slug($selected_group_slug);
    if ($selected_group && !BP_Docs_Groups_Integration::user_can_associate_doc_with_group(bp_loggedin_user_id(), $selected_group)) {
        $selected_group = 0;
    }
    // If the selected group is still 0, see if there's something in the db
    if (!$selected_group && is_singular()) {
        $selected_group = bp_docs_get_associated_group_id(get_the_ID());
    }
    $groups_args = array('per_page' => false, 'populate_extras' => false);
    if (!bp_current_user_can('bp_moderate')) {
        $groups_args['user_id'] = bp_loggedin_user_id();
    }
    // Populate the $groups_template global
    global $groups_template;
    bp_has_groups($groups_args);
    // Filter out the groups where associate_with permissions forbid
    $removed = 0;
    foreach ($groups_template->groups as $gtg_key => $gtg) {
        $this_group_settings = groups_get_groupmeta($gtg->id, 'bp-docs');
        if (isset($this_group_settings['can-create']) && in_array($this_group_settings['can-create'], array('admin', 'mod'))) {
            $is_admin = groups_is_user_admin(bp_loggedin_user_id(), $gtg->id);
            if ('mod' == $this_group_settings['can-create']) {
                $is_mod = groups_is_user_mod(bp_loggedin_user_id(), $gtg->id);
                $remove = !$is_mod && !$is_admin;
            } else {
                $remove = !$is_admin;
            }
            if ($remove) {
                unset($groups_template->groups[$gtg_key]);
                $removed++;
            }
        }
    }
    // cleanup, if necessary from filter above
    if ($removed) {
        $groups_template->groups = array_values($groups_template->groups);
        $groups_template->group_count = $groups_template->group_count - $removed;
        $groups_template->total_group_count = $groups_template->total_group_count - $removed;
    }
    ?>
	<tr>
		<td class="desc-column">
			<label for="associated_group_id"><?php 
    _e('Which group should this Doc be associated with?', 'bp-docs');
    ?>
</label>
			<span class="description"><?php 
    _e('(Optional) Note that the Access settings available for this Doc may be limited by the privacy settings of the group you choose.', 'bp-docs');
    ?>
</span>
		</td>

		<td class="content-column">
			<select name="associated_group_id" id="associated_group_id">
				<option value=""><?php 
    _e('None', 'bp-docs');
    ?>
</option>
				<?php 
    foreach ($groups_template->groups as $g) {
        ?>
					<option value="<?php 
        echo esc_attr($g->id);
        ?>
" <?php 
        selected($selected_group, $g->id);
        ?>
><?php 
        echo esc_html($g->name);
        ?>
</option>
				<?php 
    }
    ?>
			</select>

			<div id="associated_group_summary">
				<?php 
    bp_docs_associated_group_summary();
    ?>
			</div>
		</td>
	</tr>
	<?php 
}
示例#4
0
/**
 * Outputs the markup for the Associated Group settings section
 *
 * @since 1.2
 */
function bp_docs_doc_associated_group_markup()
{
    // First, try to set the preselected group by looking at the URL params
    $selected_group_slug = isset($_GET['group']) ? $_GET['group'] : '';
    $selected_group = BP_Groups_Group::get_id_from_slug($selected_group_slug);
    if ($selected_group && !BP_Docs_Groups_Integration::user_can_associate_doc_with_group(bp_loggedin_user_id(), $selected_group)) {
        $selected_group = 0;
    }
    // If the selected group is still 0, see if there's something in the db
    if (!$selected_group && is_single()) {
        $selected_group = bp_docs_get_associated_group_id(get_the_ID());
    }
    $groups_args = array('per_page' => false, 'populate_extras' => false);
    if (!bp_current_user_can('bp_moderate')) {
        $groups_args['user_id'] = bp_loggedin_user_id();
    }
    // Populate the $groups_template global
    global $groups_template;
    bp_has_groups($groups_args);
    ?>
	<tr>
		<td class="desc-column">
			<label for="associated_group_id"><?php 
    _e('Which group should this Doc be associated with?', 'bp-docs');
    ?>
</label>
			<span class="description"><?php 
    _e('(Optional) Note that the Access settings available for this Doc may be limited by the privacy settings of the group you choose.', 'bp-docs');
    ?>
</span>
		</td>

		<td class="content-column">
			<select name="associated_group_id" id="associated_group_id">
				<option value=""><?php 
    _e('None', 'bp-docs');
    ?>
</option>
				<?php 
    foreach ($groups_template->groups as $g) {
        ?>
					<option value="<?php 
        echo esc_attr($g->id);
        ?>
" <?php 
        selected($selected_group, $g->id);
        ?>
><?php 
        echo esc_html($g->name);
        ?>
</option>
				<?php 
    }
    ?>
			</select>

			<div id="associated_group_summary">
				<?php 
    bp_docs_associated_group_summary();
    ?>
			</div>
		</td>
	</tr>
	<?php 
}
function bp_docs_val_refresh_associated_group()
{
    $group_id = isset($_POST['group_id']) ? intval($_POST['group_id']) : 0;
    bp_docs_associated_group_summary($group_id);
    die;
}