$args = compact($post_types, $taxonomies); $args['query_agent_ids'] = array_keys($user->groups[$agent_type]); $roles = array_merge($roles, ppc_get_roles($agent_type, $_agent_id, $args)); } } require_once dirname(__FILE__) . '/profile_ui_pp.php'; PP_ProfileUI::display_ui_user_groups(false, array('initial_hide' => true, 'selected_only' => true, 'force_display' => true, 'edit_membership_link' => true, 'hide_checkboxes' => true, 'user_id' => $agent_id)); $role_group_caption = sprintf(__('Supplemental Roles %1$s(from primary role or %2$sgroup membership%3$s)%4$s', 'pp'), '<small>', "<a class='pp-show-groups' href='#'>", '</a>', '</small>'); PP_GroupsUI::_current_roles_ui($roles, array('read_only' => true, 'class' => 'pp-group-roles', 'caption' => $role_group_caption)); $exceptions = array(); $args = array('assign_for' => '', 'inherited_from' => 0, 'extra_cols' => array('i.assign_for', 'i.eitem_id'), 'post_types' => array_keys($post_types), 'taxonomies' => array_keys($taxonomies), 'return_raw_results' => true); foreach (array_keys($user->groups) as $agent_type) { $args['agent_type'] = $agent_type; $args['ug_clause'] = " AND e.agent_type = '{$agent_type}' AND e.agent_id IN ('" . implode("','", array_keys($user->groups[$agent_type])) . "')"; $args['query_agent_ids'] = array_keys($user->groups[$agent_type]); $exceptions = array_merge($exceptions, ppc_get_exceptions($args)); } $role_group_caption = sprintf(__('Exceptions %1$s(from primary role or %2$sgroup membership%3$s)%4$s', 'pp'), '<small>', "<a class='pp-show-groups' href='#'>", '</a>', '</small>'); PP_GroupsUI::_current_exceptions_ui($exceptions, array('read_only' => true, 'class' => 'pp-group-roles', 'caption' => $role_group_caption)); } else { ?> <h4> <?php $url = "users.php"; printf(__('View currently stored user permissions:', 'pp')); ?> </h4> <ul class="pp-notes"> <li><?php printf(__('%1$sUsers who have Supplemental Roles assigned directly%2$s', 'pp'), "<a href='{$url}?pp_user_roles=1'>", '</a>'); ?>
function retrieve_exceptions($operations = array(), $for_item_sources = array(), $args = array()) { $args['ug_clause'] = $this->get_usergroups_clause('e', array('user_adjust' => pp_get_option('user_exceptions'))); // note: Custom Group and User assignments are only for additions $args['operations'] = $operations; $args['for_item_sources'] = $for_item_sources; $this->except = array_merge($this->except, ppc_get_exceptions($args)); }
function load_exceptions($via_item_source, $for_item_source, $via_item_type, $item_id, $args = array()) { global $wpdb, $wp_roles; $this->loaded_item_id = $item_id; if (!isset($this->current_exceptions)) { $this->current_exceptions = array(); $this->agent_info = array(); } $args = array_merge(compact('for_item_source', 'item_id'), array('for_item_type' => '', 'for_item_status' => ''), $args, array('cols' => 'e.agent_type, e.agent_id, e.operation, e.mod_type, i.eitem_id, i.assign_for', 'return_raw_results' => true, 'inherited_from' => '', 'assign_for' => '', 'hierarchical' => false)); $for_item_type = isset($args['for_item_type']) ? $args['for_item_type'] : $via_item_type; extract($args, EXTR_SKIP); if ('term' == $via_item_source && !$for_item_type) { unset($args['for_item_source']); $args['post_types'] = array(''); } //if ( 'term' == $for_item_source ) $args['cols'] .= ', e.for_item_type'; if (!empty($agent_type)) { $agents_by_type = array($agent_type => array()); } else { $agents_by_type = array(); } $exc = ppc_get_exceptions($args); foreach ($exc as $row) { pp_set_array_elem($this->current_exceptions, array($row->for_item_type, $row->operation, $row->agent_type, $row->agent_id, $row->assign_for, $row->mod_type)); $this->current_exceptions[$row->for_item_type][$row->operation][$row->agent_type][$row->agent_id][$row->assign_for][$row->mod_type] = $row->eitem_id; if (!isset($agents_by_type[$row->agent_type])) { $agents_by_type[$row->agent_type] = array(); } $agents_by_type[$row->agent_type][] = $row->agent_id; } foreach (array_keys($agents_by_type) as $agent_type) { $agents_by_type[$agent_type] = array_unique($agents_by_type[$agent_type]); $ids = $agents_by_type[$agent_type]; if (!empty($agent_id)) { $ids = array_merge($ids, (array) $agent_id); } // ajax passes in specific id(s) if ('user' == $agent_type) { $this->agent_info['user'] = $wpdb->get_results("SELECT ID, user_login as name, display_name FROM {$wpdb->users} WHERE ID IN ('" . implode("','", array_map('intval', $ids)) . "') ORDER BY user_login", OBJECT_K); } elseif ('pp_group' != $agent_type) { $args = array('ids' => $ids); $this->agent_info[$agent_type] = pp_get_groups($agent_type, $args); } } // retrieve info for all WP roles regardless of exception storage $_args = array('cols' => "ID, group_name AS name, metagroup_type, metagroup_id"); if (!empty($agent_id)) { // ajax usage $_args['ids'] = (array) $agent_id; } else { $_where = isset($agents_by_type['pp_group']) ? "ID IN ('" . implode("','", $agents_by_type['pp_group']) . "')" : " metagroup_type != 'wp_role'"; if (!($pp_only_roles = pp_get_option('supplemental_role_defs'))) { $pp_only_roles = array(); } $_args['where'] = " AND ( {$_where} OR ( metagroup_type = 'wp_role' AND metagroup_id NOT IN ('" . implode("','", $pp_only_roles) . "') ) )"; } $this->agent_info['pp_group'] = pp_get_groups('pp_group', $_args); $this->agent_info['wp_role'] = array(); // rekey WP role exceptions foreach ($this->agent_info['pp_group'] as $agent_id => $group) { if ('wp_role' == $group->metagroup_type) { /* if ( 'wp_anon' == $group->metagroup_id ) { unset( $this->agent_info['pp_group'][$agent_id] ); continue; } */ $this->agent_info['wp_role'][$agent_id] = (object) $this->agent_info['pp_group'][$agent_id]; if ($role_exists = isset($wp_roles->role_names[$group->metagroup_id])) { $this->agent_info['wp_role'][$agent_id]->name = $wp_roles->role_names[$group->metagroup_id]; } unset($this->agent_info['pp_group'][$agent_id]); if ($role_exists || in_array($group->metagroup_id, array('wp_anon', 'wp_all', 'wp_auth'))) { foreach (array_keys($this->current_exceptions) as $for_item_type) { foreach (array_keys($this->current_exceptions[$for_item_type]) as $op) { if (isset($this->current_exceptions[$for_item_type][$op]['pp_group'][$agent_id])) { $this->current_exceptions[$for_item_type][$op]['wp_role'][$agent_id] = (array) $this->current_exceptions[$for_item_type][$op]['pp_group'][$agent_id]; unset($this->current_exceptions[$for_item_type][$op]['pp_group'][$agent_id]); } } } } } } // don't include orphaned assignments in metabox tab count foreach (array_keys($this->current_exceptions) as $for_item_type) { foreach (array_keys($this->current_exceptions[$for_item_type]) as $op) { foreach (array_keys($this->current_exceptions[$for_item_type][$op]) as $agent_type) { $this->current_exceptions[$for_item_type][$op][$agent_type] = array_intersect_key($this->current_exceptions[$for_item_type][$op][$agent_type], $this->agent_info[$agent_type]); } } } // determine if inclusions are set for any agents $where = 'term' == $via_item_source ? "AND e.via_item_type = '{$via_item_type}'" : ''; $where .= 'term' == $via_item_source ? '' : " AND e.for_item_source = '{$for_item_source}'"; $query_users = isset($this->agent_info['user']) ? array_keys($this->agent_info['user']) : array(); if (!empty($args['agent_type']) && 'user' == $args['agent_type'] && !empty($args['agent_id'])) { $query_users = array_merge($query_users, (array) $args['agent_id']); } $user_clause = $query_users ? "OR ( e.agent_type = 'user' AND e.agent_id IN ('" . implode("','", $query_users) . "') )" : ''; //$agents_clause = "( ( e.agent_type = 'pp_group' AND e.agent_id IN ('" . implode( "','", array_keys($this->agent_info['wp_role']) ) . "') ) $user_clause )"; $agents_clause = "( ( e.agent_type = 'pp_group' ) {$user_clause} )"; $_assignment_modes = $hierarchical ? array('item', 'children') : array('item'); // Populate only for wp roles, groups and users with stored exceptions. Will query for additional individual users as needed. foreach ($_assignment_modes as $_assign_for) { $results = $wpdb->get_results("SELECT DISTINCT e.agent_type, e.agent_id, e.operation, e.for_item_type FROM {$wpdb->ppc_exceptions} AS e INNER JOIN {$wpdb->ppc_exception_items} AS i ON e.exception_id = i.exception_id WHERE {$agents_clause} AND i.assign_for = '{$_assign_for}' AND e.mod_type = 'include' {$where}"); foreach ($results as $row) { //$_agent_type = ( 'pp_group' == $row->agent_type ) ? 'wp_role' : $row->agent_type; if ('pp_group' == $row->agent_type && in_array($row->agent_id, array_keys($this->agent_info['wp_role']))) { $_agent_type = 'wp_role'; } else { $_agent_type = $row->agent_type; } pp_set_array_elem($this->inclusions_active, array($row->for_item_type, $row->operation, $_agent_type, $row->agent_id, $_assign_for)); $this->inclusions_active[$row->for_item_type][$row->operation][$_agent_type][$row->agent_id][$_assign_for] = true; } } }
public static function _draw_group_permissions($agent_id, $agent_type, $url, $wp_http_referer = '', $args = array()) { global $current_user; //$defaults = array( 'agent' => (object) array() ); $post_types = _pp_order_types(pp_get_enabled_post_types(array(), 'object')); $taxonomies = _pp_order_types(pp_get_enabled_taxonomies(array('object_type' => false), 'object')); //$taxonomies ['link_category'] = (object) array( 'name' => 'link_category', 'labels' => (object) array( 'name' => __ppw('Link Categories'), 'singular_name' => __ppw('Link Categories') ) ); $perms = array(); if ('pp_group' == $agent_type && ($group = pp_get_group($agent_id))) { $is_wp_role = 'wp_role' == $group->metagroup_type; } if (empty($group) || !in_array($group->metagroup_id, array('wp_anon', 'wp_all')) || defined('PP_ALL_ANON_ROLES')) { $perms['roles'] = __('Add Supplemental Roles', 'pp'); } $perms['exceptions'] = __('Add Exceptions', 'pp'); if (!isset($perms['roles'])) { $current_tab = 'pp-add-exceptions'; } elseif (!isset($perms['roles'])) { $current_tab = 'pp-add-roles'; } elseif (!($current_tab = get_user_option('pp-permissions-tab'))) { $current_tab = isset($perms['roles']) ? 'pp-add-roles' : 'pp-add-exceptions'; } if ($args['agent']->metagroup_type == 'wp_role' && !in_array($args['agent']->metagroup_id, array('wp_anon', 'wp_all'))) { $perms['clone'] = __('Clone', 'pp'); } // --- add permission tabs --- echo "<ul id='pp_add_permission_tabs' class='pp-list_horiz' style='margin-bottom:-3px'>"; foreach ($perms as $perm_type => $_caption) { $class = "pp-add-{$perm_type}" == $current_tab ? 'agp-selected_agent' : 'agp-unselected_agent'; echo "<li class='agp-agent pp-add-{$perm_type} pp-add-permissions {$class}'><a class='pp-add-{$perm_type}' href='javascript:void(0)'>" . $_caption . '</a></li>'; } echo '</ul>'; // --- divs for add Roles / Exceptions --- $arr = array_keys($perms); $first_perm_type = reset($arr); foreach (array_keys($perms) as $perm_type) { $display_style = "pp-add-{$perm_type}" == $current_tab ? '' : ';display:none'; echo "<div class='pp-group-box pp-add-permissions pp-add-{$perm_type}' style='clear:both{$display_style}'>"; echo '<div>'; if ('roles' == $perm_type) { // temp workaround for bbPress self::_select_roles_ui(array_diff_key($post_types, array_fill_keys(array('topic', 'reply'), true)), $taxonomies); } elseif ('exceptions' == $perm_type) { if (!isset($args['external'])) { $args['external'] = array(); } self::_select_exceptions_ui(array_diff_key($post_types, array_fill_keys(array('topic', 'reply'), true)), $taxonomies, $args); } ?> <form id="group-<?php echo $perm_type; ?> -selections" action="<?php echo esc_url($url); ?> " method="post"<?php do_action('pp_group_edit_form_tag'); ?> > <?php wp_nonce_field("pp-update-{$perm_type}_" . $agent_id, "_pp_nonce_{$perm_type}"); ?> <?php if ('clone' == $perm_type) { self::_select_clone_ui($args['agent']); } ?> <?php if ($wp_http_referer) { ?> <input type="hidden" name="wp_http_referer" value="<?php echo esc_url($wp_http_referer); ?> " /> <?php } ?> <input type="hidden" name="action" value="pp_update<?php echo $perm_type; ?> " /> <input type="hidden" name="agent_id" value="<?php echo esc_attr($agent_id); ?> " /> <input type="hidden" name="agent_type" value="<?php echo esc_attr($agent_type); ?> " /> <input type="hidden" name="member_csv" value="-1" /> <input type="hidden" name="group_name" value="-1" /> <input type="hidden" name="description" value="-1" /> <?php if ('roles' == $perm_type) { self::_selected_roles_ui(); } elseif ('exceptions' == $perm_type) { self::_selected_exceptions_ui(); } ?> </form> <?php echo '</div></div>'; } // end foreach perm_type (roles, exceptions) $args['agent_type'] = $agent_type; $roles = ppc_get_roles($agent_type, $agent_id, compact($post_types, $taxonomies)); $args['class'] = 'user' == $agent_type ? 'pp-user-roles' : 'pp-group-roles'; $args['agent_type'] = $agent_type; self::_current_roles_ui($roles, $args); $post_types[''] = ''; // also retrieve exceptions for (all) post type $_args = array('assign_for' => '', 'extra_cols' => array('i.assign_for', 'i.eitem_id'), 'agent_type' => $agent_type, 'agent_id' => $agent_id, 'post_types' => array_keys($post_types), 'taxonomies' => array_keys($taxonomies), 'return_raw_results' => true); if (empty($_REQUEST['show_propagated'])) { $_args['inherited_from'] = 0; } else { $_args['extra_cols'][] = 'i.inherited_from'; } $exc = ppc_get_exceptions($_args); $args['class'] = 'user' == $agent_type ? 'pp-user-roles' : 'pp-group-roles'; self::_current_exceptions_ui($exc, $args); do_action('pp_group_roles_ui', $agent_type, $agent_id); }