public static function cred_scripts() { $agent_type = isset($_REQUEST['agent_type']) ? pp_sanitize_key($_REQUEST['agent_type']) : 'pp_group'; $agent_id = isset($_REQUEST['agent_id']) ? (int) $_REQUEST['agent_id'] : 0; if (!pp_has_group_cap('pp_manage_members', $agent_id, $agent_type) && !_pp_any_group_manager() && !current_user_can('pp_assign_roles') && !pp_bulk_roles_enabled()) { return array(); } $vars = array('addRoles' => __('Add Roles', 'pp'), 'clearRole' => __('clear', 'pp'), 'noConditions' => __('No statuses selected!', 'pp'), 'pleaseReview' => __('Review selection(s) below, then click Save.', 'pp'), 'alreadyRole' => __('Role already selected!', 'pp'), 'noAction' => __('No Action selected!', 'pp'), 'submissionMsg' => __('Role submission in progress...', 'pp'), 'reloadRequired' => __('Reload form for further changes to this role', 'pp'), 'ajaxurl' => admin_url('')); $vars['agentType'] = $agent_type; $vars['agentID'] = $agent_id; $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '.dev' : ''; wp_enqueue_script('pp_permit_edit', PP_URLPATH . "/admin/js/pp_permit_edit{$suffix}.js", array('jquery', 'jquery-form'), PPC_VERSION); wp_localize_script('pp_permit_edit', 'ppCred', $vars); return $vars; }
public static function remove_user_groups($user_id, $omit_group_ids = array()) { $group_types = pp_get_group_types(array('editable' => true)); foreach (pp_get_group_types(array('editable' => true)) as $agent_type) { if ('pp_group' == $agent_type && in_array('pp_net_group', $group_types)) { continue; } $posted_groups = isset($_POST[$agent_type]) ? array_map('intval', $_POST[$agent_type]) : array(); $stored_groups = array_keys(pp_get_groups_for_user($user_id, $agent_type, array('cols' => 'id'))); if ($omit_group_ids) { $stored_groups = array_diff($stored_groups, $omit_group_ids); } $delete_groups = array_diff($stored_groups, $posted_groups); foreach ($delete_groups as $group_id) { if (pp_has_group_cap('pp_manage_members', $group_id, $agent_type)) { pp_remove_group_user($group_id, $user_id, compact('agent_type')); } } } }
<?php if (pp_group_type_editable($agent_type) && (empty($agent->metagroup_type) || !in_array($agent->metagroup_type, array('wp_role', 'meta_role')) || apply_filters('pp_metagroup_editable', false, $agent->metagroup_type, $agent_id))) { submit_button(__('Update Group', 'pp')); } ?> </div> </td> </tr> </table> <?php do_action('pp_group_edit_form', $agent_type, $agent_id); if ($agent_id) { if (pp_group_type_editable($agent_type) && !in_array($agent->metagroup_type, array('wp_role', 'meta_role'))) { $member_types = array(); if (pp_has_group_cap('pp_manage_members', $agent_id, $agent_type)) { $member_types[] = 'member'; } if ($member_types) { PP_GroupsUI::_draw_member_checklists($agent_id, $agent_type, compact('member_types')); } } } elseif ('user' == $agent_type) { echo '<br />'; PP_GroupsUI::_draw_member_checklists(0, 'pp_group', array('suppress_caption' => true)); } do_action('pp_edit_group_profile', $agent_type, $agent_id); ?> <input type="hidden" name="action" value="update" /> <input type="hidden" name="agent_id" id="agent_id" value="<?php
/** * Edit group settings based on contents of $_POST * * @param int $group_id Optional. Group ID. * @return int group id of the updated group */ function _pp_edit_group($group_id = 0, $agent_type = 'pp_group', $members_only = false) { global $wpdb; if ($group_id) { $update = true; $group = pp_get_group($group_id, $agent_type); } else { $update = false; $group = (object) array(); } if (!$members_only) { if (isset($_REQUEST['group_name'])) { $group->group_name = sanitize_text_field($_REQUEST['group_name']); } if (isset($_REQUEST['description'])) { $group->group_description = sanitize_text_field($_REQUEST['description']); } $errors = new WP_Error(); /* checking that username has been typed */ if (!$group->group_name) { $errors->add('group_name', __('<strong>ERROR</strong>: Please enter a group name.', 'pp')); } elseif (!$update && !PP_GroupsUpdate::group_name_available($group->group_name, $agent_type)) { $errors->add('user_login', __('<strong>ERROR</strong>: This group name is already registered. Please choose another one.', 'pp')); } // Allow plugins to return their own errors. do_action_ref_array('pp_group_profile_update_errors', array(&$errors, $update, &$group)); if ($errors->get_error_codes()) { return $errors; } if ($update) { PP_GroupsUpdate::update_group($group_id, $group, $agent_type); } else { $group_id = PP_GroupsUpdate::create_group($group, $agent_type); } } if ($group_id) { $member_types = array(); if (pp_has_group_cap('pp_manage_members', $group_id, $agent_type)) { $member_types[] = 'member'; } foreach ($member_types as $member_type) { if (isset($_REQUEST["{$member_type}_csv"]) && $_REQUEST["{$member_type}_csv"] != -1) { // handle member changes $current = pp_get_group_members($group_id, $agent_type, 'id', compact('member_type')); $selected = isset($_REQUEST["{$member_type}_csv"]) ? explode(",", pp_sanitize_csv($_REQUEST["{$member_type}_csv"])) : array(); if ('member' != $member_type || !apply_filters('pp_custom_agent_update', false, $agent_type, $group_id, $selected)) { if ($add_users = array_diff($selected, $current)) { pp_add_group_user($group_id, $add_users, compact('agent_type', 'member_type')); } if ($remove_users = array_diff($current, $selected)) { pp_remove_group_user($group_id, $remove_users, compact('agent_type', 'member_type')); } } } } // end foreach member_types do_action('pp_edited_group', $agent_type, $group_id, $update); } return $group_id; }
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)) { ?> • <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>"; } }
/** * Generate HTML for a single row on the PP Role Groups admin panel. * * @param object $user_object * @param string $style Optional. Attributes added to the TR element. Must be sanitized. * @param int $num_users Optional. User count to display for this group. * @return string */ function single_row($group_object, $style = '') { //$group_object = sanitize_user_object( $group_object, 'display' ); global $pp_admin; static $base_url; static $members_cap; static $is_administrator; if (!isset($base_url)) { $base_url = apply_filters('pp_groups_base_url', 'admin.php'); // @todo: filter based on menu usage $is_administrator = pp_is_user_administrator(); } /* if ( ! $is_administrator ) { $members_cap = apply_filters( 'pp_edit_groups_reqd_caps', array('pp_manage_members'), 'edit-members' ); } */ $group_id = $group_object->ID; if ($group_object->metagroup_id) { if ('rvy_notice' == $group_object->metagroup_type && !defined('RVY_VERSION')) { return; } require_once PPC_ABSPATH . '/groups-retrieval_pp.php'; $group_object->group_name = PP_GroupRetrieval::get_metagroup_name($group_object->metagroup_type, $group_object->metagroup_id, $group_object->group_name); $group_object->group_description = PP_GroupRetrieval::get_metagroup_descript($group_object->metagroup_type, $group_object->metagroup_id, $group_object->group_description); } $group_object->group_name = stripslashes($group_object->group_name); $group_object->group_description = stripslashes($group_object->group_description); // Set up the hover actions for this user $actions = array(); $checkbox = ''; $can_manage_group = $is_administrator || pp_has_group_cap('pp_edit_groups', $group_id, $this->agent_type); $agent_type_clause = $this->agent_type && 'pp_group' != $this->agent_type ? "&agent_type={$this->agent_type}" : ''; // Check if the group for this row is editable if ($can_manage_group) { $edit_link = $base_url . "?page=pp-edit-permissions&action=edit{$agent_type_clause}&agent_id={$group_id}"; $edit = "<strong><a href=\"{$edit_link}\">{$group_object->group_name}</a></strong><br />"; $actions['edit'] = '<a href="' . $edit_link . '">' . __ppw('Edit') . '</a>'; } else { $edit_link = ''; $edit = '<strong>' . $group_object->group_name . '</strong>'; } $can_delete_group = $is_administrator || current_user_can('pp_delete_groups', $group_id); if ($can_delete_group && !$group_object->metagroup_id) { $actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url($base_url . "?page=pp-groups&pp_action=delete{$agent_type_clause}&group={$group_id}", 'bulk-groups') . "'>" . __('Delete') . "</a>"; } $actions = apply_filters('pp_group_row_actions', $actions, $group_object); $edit .= $this->row_actions($actions); // Set up the checkbox ( because the group or group members are editable, otherwise it's empty ) if ($actions && !$group_object->metagroup_id) { $checkbox = "<input type='checkbox' name='groups[]' id='group_{$group_id}' value='{$group_id}' />"; } else { $checkbox = ''; } //$avatar = get_avatar( $user_object->ID, 32 ); $r = "<tr id='group-{$group_id}'{$style}>"; list($columns, $hidden) = $this->get_column_info(); foreach ($columns as $column_name => $column_display_name) { $class = "class=\"{$column_name} column-{$column_name}\""; $style = ''; if (in_array($column_name, $hidden)) { $style = ' style="display:none;"'; } $attributes = "{$class}{$style}"; switch ($column_name) { case 'cb': $r .= "<th scope='row' class='check-column'>{$checkbox}</th>"; break; case 'ID': $r .= "<td {$attributes}>{$group_id}</td>"; break; case 'group_name': $r .= "<td {$attributes}>{$edit}</td>"; break; case 'num_users': if ('wp_role' == $group_object->metagroup_type) { $num_users = pp_count_role_users($group_object->metagroup_id); } else { $num_users = pp_get_group_members($group_id, $this->agent_type, 'count'); } $attributes = 'class="posts column-num_users num"' . $style; $r .= "<td {$attributes}>"; /* if ( $members_link ) $r .= "<a href='$members_link'>$num_users</a>"; else */ if ('wp_role' == $group_object->metagroup_type) { if (in_array($group_object->metagroup_id, array('wp_anon', 'wp_all', 'wp_auth'))) { $r .= ''; } else { $user_url = admin_url("users.php?role={$group_object->metagroup_id}"); $r .= "<a href='{$user_url}'>{$num_users}</a>"; } } else { $r .= $num_users; } $r .= "</td>"; break; case 'roles': case 'exceptions': $r .= $this->single_row_role_column($column_name, $group_id, $can_manage_group, $edit_link, $attributes); break; case 'description': $r .= "<td {$attributes}>{$group_object->group_description}</td>"; break; default: $r .= "<td {$attributes}>"; $r .= apply_filters('pp_manage_pp_groups_custom_column', '', $column_name, $group_id); $r .= "</td>"; } } $r .= '</tr>'; return $r; }
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'); ?> • <?php } ?> <a href='user-edit.php?user_id=<?php echo $user_id; ?> #userprofile_groupsdiv_pp' title='<?php echo esc_attr(__('Edit this user's group membership', 'pp')); ?> '><?php _e('add / edit membership'); ?> </a> <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' />"; }
public static function display($agents_subset, $agent_type, $all_agents, $name_attrib, $item_assignments, $args) { $defaults = array('eligible_ids' => array(), 'locked_ids' => array(), 'add_group_link' => true, 'show_subset_caption' => true, 'hide_checkboxes' => false); $args = array_merge($defaults, (array) $args); extract($args, EXTR_SKIP); $caption_length_limit = defined('PP_AGENTS_CAPTION_LIMIT') ? PP_AGENTS_CAPTION_LIMIT : 20; $emsize_threshold = defined('PP_AGENTS_EMSIZE_THRESHOLD') ? PP_AGENTS_EMSIZE_THRESHOLD : 4; static $exec_count = 0; $exec_count++; // support abbreviated checkbox id for label association if ('eligible' == $agents_subset) { $caption = __('eligible (%d):', 'pp'); $item_assignments = array_intersect_key($item_assignments, $all_agents); if (!($agent_count = count($all_agents) - count($item_assignments))) { return; } } else { $caption = __('current (%d):', 'pp'); $agent_count = count($item_assignments); } echo "<div>"; echo "<ul class='pp-list_horiz'><li>"; if ($show_subset_caption) { printf("<div class='pp-agents_caption'><strong>{$caption}</strong></div>", $agent_count); } echo '</li>'; echo '</ul>'; // -------- construct captions and determine required list item width ----------- $captions = $full_captions = $draw_agents = array(); global $wp_locale; $rtl = isset($wp_locale) && 'rtl' == $wp_locale->text_direction; $longest_caption_length = 10; foreach ($all_agents as $agent) { $id = $agent->ID; $skip = false; switch ($agents_subset) { case 'current': if (!isset($item_assignments[$id])) { $skip = true; } break; default: //'eligible' if (isset($item_assignments[$id])) { $skip = true; } if ($eligible_ids && !in_array($id, $eligible_ids)) { $skip = true; } } if ($skip) { unset($all_agents[$id]); continue; } if ('pp_group' == $agent_type && $agent->metagroup_id) { $caption = PP_GroupRetrieval::get_metagroup_name($agent->metagroup_type, $agent->metagroup_id, $agent->name); } else { $caption = $agent->name; } if (strlen($caption) > $caption_length_limit) { $full_captions[$id] = $caption; if ($rtl) { $caption = '...' . substr($caption, strlen($caption) - $caption_length_limit); } else { $caption = substr($caption, 0, $caption_length_limit) . '...'; } } if (strlen($caption) > $longest_caption_length) { $longest_caption_length = strlen($caption) >= $caption_length_limit ? $caption_length_limit + 2 : strlen($caption); } $captions[$id] = $caption; } //-------- end caption construction -------------- if ($agent_count > $emsize_threshold) { $ems_per_character = defined('PP_UI_EMS_PER_CHARACTER') ? PP_UI_EMS_PER_CHARACTER : 0.85; $list_width_ems = $ems_per_character * $longest_caption_length; $ul_class = 'pp-agents-list_' . intval($list_width_ems); echo "<div id='div_{$agents_subset}_{$name_attrib}' class='pp-{$agent_type} pp-{$agents_subset}'>" . "<div class='pp-agents_emsized'>" . "<ul class='pp-agents-list {$ul_class}' id='list_{$agents_subset}_{$name_attrib}'>"; } else { $ul_class = "pp-agents-list_auto"; echo "<div class='pp-{$agent_type}'>" . "<ul class='pp-agents-list {$ul_class}' id='list_{$agents_subset}_{$name_attrib}'>"; } if (pp_group_type_editable($agent_type)) { $edit_link_base = apply_filters('pp_groups_base_url', 'admin.php') . "?page=pp-edit-permissions&action=edit&agent_type={$agent_type}&agent_id="; $edit_title_text = __('view / edit group', 'pp'); $edit_caption = __ppw('edit', 'pp'); } else { $edit_link_base = ''; } foreach ($all_agents as $agent) { $id = $agent->ID; if (!empty($agent->metagroup_id)) { $display_name = isset($agent->display_name) ? $agent->display_name : ''; $li_title = "title='" . PP_GroupRetrieval::get_metagroup_descript($agent->metagroup_type, $agent->metagroup_id, $display_name) . "'"; } elseif (isset($full_captions[$id])) { $li_title = "title='{$full_captions[$id]}'"; } else { $li_title = "title='{$captions[$id]}'"; } $checked = isset($item_assignments[$id]) ? ' checked="checked"' : ''; $disabled = $locked_ids && in_array($id, $locked_ids) ? " disabled='disabled'" : ''; echo "<li {$li_title}>"; if ($hide_checkboxes) { echo '• '; } else { echo "<input type='checkbox' name='{$name_attrib}[]'{$disabled}{$checked} value='{$id}' id='r{$exec_count}_{$id}' />"; } echo "<label for='r{$exec_count}_{$id}'>"; echo ' ' . $captions[$id]; echo '</label>'; if ($edit_link_base && pp_has_group_cap('pp_edit_groups', $id, $agent_type)) { echo ' <a href=" ' . $edit_link_base . $id . '" style="display:none" target="_blank" title="' . $edit_title_text . '">' . $edit_caption . '</a>'; } echo '</li>'; } //foreach agent echo "<li></li></ul>"; // prevent invalid markup if no other li's if ($agent_count > $emsize_threshold) { echo '</div>'; } echo '</div></div>'; }