Example #1
0
 public static function user_selection_ui($group_id = 0, $agent_type, $user_class = 'member', $all_users = '')
 {
     global $pp;
     // This is only needed for checkbox selection
     if (!$all_users) {
         $all_users = self::get_all_users('id_name');
     }
     $current_users = $group_id ? pp_get_group_members($group_id, $agent_type, 'all', array('member_type' => $user_class, 'status' => 'any')) : array();
     $args = array('suppress_extra_prefix' => true, 'ajax_selection' => true, 'agent_id' => $group_id);
     echo '<div>';
     echo '<div class="pp-agent-select">';
     $pp_agents_ui = pp_init_agents_ui();
     $pp_agents_ui->agents_ui('user', $all_users, $user_class, $current_users, $args);
     echo '</div>';
     echo '</div>';
 }
    function draw_exceptions_ui($box, $args)
    {
        if (!isset($box['args'])) {
            return;
        }
        extract($box['args'], EXTR_SKIP);
        // $op
        extract($args, EXTR_SKIP);
        // $for_item_source, for_item_type, via_item_source
        global $wp_roles, $pp_current_user;
        $is_draft_post = false;
        if ('post' == $via_item_source) {
            if ('read' == $op) {
                global $post;
                $status_obj = get_post_status_object($post->post_status);
                if (!$status_obj || !$status_obj->public && !$status_obj->private) {
                    $is_draft_post = true;
                }
            }
            $hierarchical = is_post_type_hierarchical($via_item_type);
        } else {
            $hierarchical = is_taxonomy_hierarchical($via_item_type);
        }
        if ($hierarchical = apply_filters('pp_do_assign_for_children_ui', $hierarchical, $via_item_type, $args)) {
            $type_obj = 'post' == $via_item_source ? get_post_type_object($via_item_type) : get_taxonomy($via_item_type);
        }
        $agent_types['wp_role'] = (object) array('labels' => (object) array('name' => __('WP Roles', 'pp'), 'singular_name' => __('WP Role', 'pp')));
        $agent_types = apply_filters('pp_list_group_types', array_merge($agent_types, pp_get_group_types(array(), 'object')));
        $agent_types['user'] = (object) array('labels' => (object) array('name' => __('Users'), 'singular_name' => __('User')));
        //if ( ! $skip_user_validation && ! $pp_admin->user_can_admin_role($role_name, $item_id, $src_name, $object_type) )
        //	return;
        static $drew_itemroles_marker;
        if (empty($drew_itemroles_marker)) {
            echo "<input type='hidden' name='pp_post_exceptions' value='true' />";
            $drew_itemroles_marker = true;
        }
        $current_exceptions = isset($this->data->current_exceptions[$for_item_type]) ? $this->data->current_exceptions[$for_item_type] : array();
        // ========== OBJECT / TERM EXCEPTION DROPDOWNS ============
        $toggle_agents = count($agent_types) > 1;
        if ($toggle_agents) {
            global $is_ID;
            $class_selected = 'agp-selected_agent agp-agent';
            $class_unselected = 'agp-unselected_agent agp-agent';
            $bottom_margin = !empty($is_IE) ? '-0.7em' : 0;
            $default_agent_type = 'wp_role';
            echo "<div class='hide-if-not-js' style='margin:0 0 {$bottom_margin} 0'>" . "<ul class='pp-list_horiz' style='margin-bottom:-0.1em'>";
            foreach ($agent_types as $agent_type => $gtype_obj) {
                $label = !empty($current_exceptions[$op][$agent_type]) ? sprintf(__('%1$s (%2$s)', 'pp'), $gtype_obj->labels->name, count($current_exceptions[$op][$agent_type])) : $gtype_obj->labels->name;
                $class = $default_agent_type == $agent_type ? "class='{$class_selected}'" : "class='{$class_unselected}'";
                echo "<li {$class}><a href='javascript:void(0)' class='{$op}-{$for_item_type}-{$agent_type}'>" . $label . '</a></li>';
            }
            echo '</ul></div>';
        }
        $class = "class='pp-agents pp-exceptions'";
        //need effective line break here if not IE
        echo "<div style='clear:both;margin:0 0 0.3em 0' {$class}>";
        $pp_agents_ui = pp_init_agents_ui();
        foreach (array_keys($agent_types) as $agent_type) {
            $hide_class = $toggle_agents && $agent_type != $default_agent_type ? ' class="hide-if-js"' : '';
            echo "\r\n<div id='{$op}-{$for_item_type}-{$agent_type}' {$hide_class} style='overflow-x:auto'>";
            $this->render->set_options($agent_type);
            // list all WP roles
            if ('wp_role' == $agent_type) {
                if (!isset($current_exceptions[$op][$agent_type])) {
                    $current_exceptions[$op][$agent_type] = array();
                }
                foreach ($this->data->agent_info['wp_role'] as $agent_id => $role) {
                    if (in_array($role->metagroup_id, array('wp_anon', 'wp_all')) && !defined('PP_ALL_ANON_FULL_EXCEPTIONS') && ('read' != $op || pp_get_option('anonymous_unfiltered'))) {
                        continue;
                    }
                    if (!isset($current_exceptions[$op][$agent_type][$agent_id])) {
                        $current_exceptions[$op][$agent_type][$agent_id] = array();
                    }
                }
                if (!$is_draft_post && 'post' == $via_item_source && 'attachment' != $via_item_type && in_array($op, array('read', 'edit', 'delete'))) {
                    $reqd_caps = map_meta_cap("{$op}_post", 0, $item_id);
                } else {
                    $reqd_caps = false;
                }
            }
            global $wp_roles;
            ?>
			
			<table class="pp-item-exceptions-ui pp-exc-<?php 
            echo $agent_type;
            ?>
" style="width:100%"><tr>
			<?php 
            if ('wp_role' != $agent_type) {
                ?>
				<td class="pp-select-exception-agents" style="display:none;">
				<?php 
                // Select Groups / Users UI
                echo '<div>';
                echo '<div class="pp-agent-select">';
                $args = array_merge($args, array('suppress_extra_prefix' => true, 'ajax_selection' => true, 'display_stored_selections' => false, 'create_dropdowns' => true, 'op' => $op, 'via_item_type' => $via_item_type));
                $pp_agents_ui = pp_init_agents_ui();
                $pp_agents_ui->agents_ui($agent_type, array(), "{$op}:{$for_item_type}:{$agent_type}", array(), $args);
                echo '</div>';
                echo '</div>';
                $colspan = 'colspan="2"';
                ?>
				</td>
			<?php 
            } else {
                $colspan = '';
                // for html5 compliance
            }
            ?>
			
			<?php 
            $any_stored = empty($current_exceptions[$op][$agent_type]) ? 0 : count($current_exceptions[$op][$agent_type]);
            ?>
			<td class="pp-current-item-exceptions" style="width:100%">
				<div style="overflow:auto;max-height:325px">
				<table <?php 
            if (!$any_stored) {
                echo 'style="display:none"';
            }
            ?>
>
				<?php 
            if ($hierarchical) {
                ?>
					<thead>
					<tr>
					<th></th>
					<th><?php 
                printf(__('This %s', 'pp'), $type_obj->labels->singular_name);
                ?>
</th>
					<th><?php 
                if ($caption = apply_filters('pp_item_assign_for_children_caption', '', $via_item_type)) {
                    printf($caption);
                } else {
                    printf(__('Sub-%s', 'pp'), $type_obj->labels->name);
                }
                ?>
</th>
					</tr>
					</thead>
				<?php 
            }
            ?>
					<tbody>
					<?php 
            // @todo: why is agent_id=0 in current_exceptions array?
            if ($any_stored) {
                if ('wp_role' == $agent_type) {
                    foreach ($current_exceptions[$op][$agent_type] as $agent_id => $agent_exceptions) {
                        if ($agent_id && isset($this->data->agent_info[$agent_type][$agent_id])) {
                            $this->render->draw_row($agent_type, $agent_id, $current_exceptions[$op][$agent_type][$agent_id], $this->data->inclusions_active, $this->data->agent_info[$agent_type][$agent_id], compact('for_item_type', 'op', 'reqd_caps', 'hierarchical'));
                        }
                    }
                } else {
                    foreach (array_keys($this->data->agent_info[$agent_type]) as $agent_id) {
                        // order by agent name
                        if ($agent_id && isset($current_exceptions[$op][$agent_type][$agent_id])) {
                            $this->render->draw_row($agent_type, $agent_id, $current_exceptions[$op][$agent_type][$agent_id], $this->data->inclusions_active, $this->data->agent_info[$agent_type][$agent_id], compact('for_item_type', 'op', 'reqd_caps', 'hierarchical'));
                        }
                    }
                }
            }
            ?>
					</tbody>
					
					<tfoot<?php 
            if ($any_stored < 2) {
                echo ' style="display:none;"';
            }
            ?>
>
					<?php 
            $link_caption = 'wp_role' == $agent_type ? __('default all', 'pp') : __('clear all', 'pp');
            ?>
						<tr>
						<td></td><td style="text-align:center"><a href="#clear-item-exc"><?php 
            echo $link_caption;
            ?>
</a></td>
						<?php 
            if ($hierarchical) {
                ?>
						<td style="text-align:center"><a href="#clear-sub-exc"><?php 
                echo $link_caption;
                ?>
</a></td>
						<?php 
            }
            ?>
						</tr>
					</tfoot>
				
				</table>
				
				</div>
				
				<?php 
            if (!$any_stored) {
                ?>
				<div class="pp-no-exceptions"><?php 
                _e('No access customizations stored.', 'pp');
                ?>
</div>
				<?php 
            }
            ?>
			</td>
			</tr>
			
			<tr>
			<td class="pp-exception-actions" <?php 
            echo $colspan;
            ?>
>
			<?php 
            if ('wp_role' != $agent_type) {
                ?>
				<a class="pp-select-exception-agents" href="#"><?php 
                'user' == $agent_type ? _e('select users', 'pp') : _e('select groups', 'pp');
                ?>
</a>
				<a class="pp-close-select-exception-agents" href="#" style="display:none;"><?php 
                _e('close', 'pp');
                ?>
</a>
			<?php 
            }
            if (pp_group_type_editable($agent_type) && pp_has_group_cap('pp_create_groups', 0, $agent_type)) {
                ?>
				&nbsp;&bull;&nbsp;<a class="pp-create-exception-agent" href="admin.php?page=pp-group-new" target="_blank"><?php 
                _e('create group', 'pp');
                ?>
</a>
			<?php 
            }
            ?>
			</td>
			</tr>
			</table>
			
			</div>
			<?php 
        }
        // end foreach group type caption
        echo '</div>';
        // class pp-agents
        if ('read' == $op && pp_get_option('display_extension_hints') && ('attachment' == $for_item_type && !defined('PPFF_VERSION') || !defined('PPCE_VERSION'))) {
            require_once dirname(__FILE__) . '/item-exceptions-ui-hints_pp.php';
            _ppc_item_ui_hints($for_item_type);
        }
        if ('term' == $via_item_source && in_array($op, array('read', 'edit'))) {
            $msg = __('To customize <strong>for a specific post status</strong>, edit the desired role / group / user permissions directly (Permissions > Groups or Users)', 'pp');
            echo "<div class='pp-exc-notes'>{$msg}</div>";
        }
    }
Example #3
0
    public static function display_ui_user_groups($include_role_metagroups = false, $args = array())
    {
        $defaults = array('initial_hide' => false, 'selected_only' => false, 'hide_checkboxes' => false, 'force_display' => false, 'edit_membership_link' => false, 'user_id' => false);
        extract(array_merge($defaults, $args), EXTR_SKIP);
        require_once dirname(__FILE__) . '/permissions-ui_pp.php';
        if (!is_numeric($user_id)) {
            global $profileuser;
            $user_id = !empty($profileuser) ? $profileuser->ID : 0;
        }
        $group_types = pp_get_group_types(array('editable' => true));
        foreach ($group_types as $agent_type) {
            //if ( ! $agent_type = apply_filters( 'pp_query_group_type', '' ) )
            //	$agent_type = 'pp_group';
            if ('pp_group' == $agent_type && in_array('pp_net_group', $group_types)) {
                continue;
            }
            if (!pp_has_group_cap('pp_manage_members', 0, $agent_type)) {
                continue;
            }
            if (!($all_groups = pp_get_groups($agent_type))) {
                continue;
            }
            $reqd_caps = (array) apply_filters('pp_edit_groups_reqd_caps', array('pp_edit_groups'));
            // @todo: reinstate?
            //$editable_ids = pp_get_groups( 'pp_group', FILTERED_PP, 'id', compact('reqd_caps') );
            if (current_user_can('pp_manage_members')) {
                $editable_ids = array_keys($all_groups);
            } else {
                $editable_ids = array();
            }
            $stored_groups = pp_get_groups_for_user($user_id, $agent_type, array('cols' => 'id'));
            //$addable_ids = array_diff( $editable_ids, array_keys($stored_groups) );
            $locked_ids = array_diff(array_keys($stored_groups), $editable_ids);
            // can't manually edit membership of WP Roles groups or other metagroups lacking _ed_ suffix
            $all_ids = array();
            foreach ($all_groups as $key => $group) {
                if ($selected_only && !isset($stored_groups[$group->ID])) {
                    unset($all_groups[$key]);
                    continue;
                }
                $all_ids[] = $group->ID;
                if (!$include_role_metagroups && !empty($group->metagroup_id) && 'wp_role' == $group->metagroup_type) {
                    $editable_ids = array_diff($editable_ids, array($group->ID));
                    unset($stored_groups[$group->ID]);
                    unset($all_groups[$key]);
                } elseif (!in_array($group->ID, $editable_ids) && !in_array($group->ID, $locked_ids)) {
                    unset($all_groups[$key]);
                }
            }
            $locked_ids = array_diff(array_keys($stored_groups), $editable_ids);
            // avoid incorrect eligible count if orphaned group roles are included in editable_ids
            $editable_ids = array_intersect($editable_ids, $all_ids);
            if (!$all_groups && !$force_display) {
                continue;
            }
            $style = $initial_hide ? "style='display:none'" : '';
            echo "<div id='userprofile_groupsdiv_pp' class='pp-group-box pp-group_members' {$style}>";
            echo "<h3>";
            if ('pp_group' == $agent_type) {
                if (defined('GROUPS_CAPTION_RS')) {
                    echo GROUPS_CAPTION_RS;
                } else {
                    _e('Permission Groups', 'pp');
                }
            } else {
                $group_type_obj = pp_get_group_type_object($agent_type);
                echo $group_type_obj->labels->name;
            }
            echo "</h3>";
            $css_id = $agent_type;
            $args = array('eligible_ids' => $editable_ids, 'locked_ids' => $locked_ids, 'show_subset_caption' => false, 'hide_checkboxes' => $hide_checkboxes);
            require_once dirname(__FILE__) . '/agents_ui_pp.php';
            $pp_agents_ui = pp_init_agents_ui();
            $pp_agents_ui->agents_ui($agent_type, $all_groups, $css_id, $stored_groups, $args);
            if ($edit_membership_link || !$all_groups && $force_display) {
                ?>
				<p>
				<?php 
                if (!$all_groups && $force_display) {
                    _e('This user is not a member of any Permission Groups.', 'pp');
                    ?>
&nbsp;&bull;&nbsp;
				<?php 
                }
                ?>
				<a href='user-edit.php?user_id=<?php 
                echo $user_id;
                ?>
#userprofile_groupsdiv_pp' title='<?php 
                echo esc_attr(__('Edit this user&apos;s group membership', 'pp'));
                ?>
'><?php 
                _e('add / edit membership');
                ?>
</a>
				&nbsp;&nbsp;
				<span class="pp-subtext">
				<?php 
                $note = apply_filters('pp_user_profile_groups_note', defined('BP_VERSION') ? __('note: BuddyPress Groups and other externally defined groups are not listed here, even if they modify permissions', 'pp') : '', $user_id, $args);
                echo $note;
                ?>
				</span>
				</p>
			<?php 
            }
            echo '</div>';
        }
        // end foreach agent_type
        echo "<input type='hidden' name='pp_editing_user_groups' value='1' />";
    }