} } else { if (!pp_has_group_cap('pp_edit_groups', $agent_id, $agent_type)) { wp_die(__('You are not permitted to do that.', 'pp')); } if ('wp_role' == $metagroup_type && !current_user_can('pp_administer_content')) { wp_die(__('You are not permitted to do that.', 'pp')); } if (!$agent) { wp_die(__('Invalid group ID.', 'pp')); } } if ($metagroup_type) { // metagroups cannot have name/description manually edited $agent->name = PP_GroupRetrieval::get_metagroup_name($metagroup_type, $agent->metagroup_id, $agent->name); $agent->group_description = PP_GroupRetrieval::get_metagroup_descript($metagroup_type, $agent->metagroup_id, $agent->group_description); } $url = apply_filters('pp_groups_base_url', 'admin.php'); if (isset($_REQUEST['wp_http_referer'])) { $wp_http_referer = $_REQUEST['wp_http_referer']; } elseif (isset($_SERVER['HTTP_REFERER']) && !strpos($_SERVER['HTTP_REFERER'], 'page=pp-group-new')) { $wp_http_referer = $_SERVER['HTTP_REFERER']; } else { $wp_http_referer = ''; } $wp_http_referer = remove_query_arg(array('update', 'delete_count'), stripslashes($wp_http_referer)); // contextual help - choose Help on the top right of admin panel to preview this. /* add_contextual_help($current_screen, '<p>' . __('Your profile contains information about you (your “account”) as well as some personal options related to using WordPress.') . '</p>' . '<p>' . __('Required fields are indicated; the rest are optional. Profile information will only be displayed if your theme is set up to do so.') . '</p>' .
/** * 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; }
function draw_row($agent_type, $agent_id, $agent_exceptions, $inclusions_active, $agent_info, $args = array()) { global $wp_roles; $defaults = array('reqd_caps' => false, 'hierarchical' => false, 'for_item_type' => '', 'op' => '', 'default_select' => false); $args = array_merge($defaults, $args); extract($args, EXTR_SKIP); $assignment_modes = array('item'); if ($hierarchical) { $assignment_modes[] = 'children'; } $this->opt_class[''] = ''; $disabled = ''; if ('wp_role' == $agent_type) { // also credit sitewide caps attached via supplemental role assignment to WP Role metagroup static $metagroup_caps; if (!isset($metagroup_caps)) { $metagroup_caps = array(); global $wpdb, $pp; $results = $wpdb->get_results("SELECT g.metagroup_id AS wp_rolename, r.role_name AS supplemental_role FROM {$wpdb->ppc_roles} AS r INNER JOIN {$wpdb->pp_groups} AS g ON g.ID = r.agent_id AND r.agent_type = 'pp_group' WHERE g.metagroup_type = 'wp_role'"); foreach ($results as $row) { $role_specs = explode(':', $row->supplemental_role); if (!empty($role_specs[2]) && $for_item_type != $role_specs[2]) { continue; } if (!isset($metagroup_caps[$row->wp_rolename])) { $metagroup_caps[$row->wp_rolename] = array(); } $metagroup_caps[$row->wp_rolename] = array_merge($metagroup_caps[$row->wp_rolename], array_fill_keys($pp->get_role_caps($row->supplemental_role), true)); } } $role_obj_caps = empty($wp_roles->role_objects[$agent_info->metagroup_id]->capabilities) ? array() : $wp_roles->role_objects[$agent_info->metagroup_id]->capabilities; $role_caps = isset($wp_roles->role_objects[$agent_info->metagroup_id]) ? array_intersect($role_obj_caps, array(true, 1, '1')) : array('read' => true, 'spectate' => true); if (isset($metagroup_caps[$agent_info->metagroup_id])) { $role_caps = array_merge($role_caps, $metagroup_caps[$agent_info->metagroup_id]); } $is_unfiltered = !empty($role_caps['pp_administer_content']) || !empty($role_caps['pp_unfiltered']); if ($is_unfiltered) { $disabled = ' disabled="disabled"'; } if ($reqd_caps) { if (!array_diff($reqd_caps, array_keys($role_caps)) || $is_unfiltered) { $this->opt_class[''] = " class='pp-yes' "; $this->options['standard'][''] = $this->opt_labels['default_yes']; } else { $this->opt_class[''] = " class='pp-no' "; $this->options['standard'][''] = $this->opt_labels['default_no']; } } } else { $this->options['standard'][''] = in_array($agent_type, array('wp_role', 'user')) ? $this->opt_labels['default'] : $this->opt_labels['no_setting']; } $_inclusions_active = isset($inclusions_active[$for_item_type][$op][$agent_type][$agent_id]); if ('wp_role' == $agent_type) { require_once PPC_ABSPATH . '/groups-retrieval_pp.php'; $title = " title='" . PP_GroupRetrieval::get_metagroup_descript('wp_role', $agent_info->metagroup_id, '') . "'"; } elseif ('user' == $agent_type && !empty($agent_info->display_name) && $agent_info->display_name != $agent_info->name) { $title = " title='{$agent_info->display_name}'"; } else { $title = ''; } $_name = 'user' == $agent_type && defined('PP_USER_RESULTS_DISPLAY_NAME') ? $agent_info->display_name : $agent_info->name; ?> <tr><td class='pp-exc-agent'><input type='hidden' value='<?php echo $agent_id; ?> ' /><a href='<?php echo "{$this->base_url}{$agent_id}"; ?> '<?php echo $title; ?> target='_blank'><?php echo $_name; ?> </a></td> <?php foreach ($assignment_modes as $assign_for) { if (!empty($agent_exceptions[$assign_for]['additional'])) { $current_val = 2; } elseif (isset($agent_exceptions[$assign_for]['include'])) { $current_val = 1; } else { if ($default_select) { $current_val = $_inclusions_active ? '1' : '2'; } else { $current_val = isset($agent_exceptions[$assign_for]['exclude']) ? 0 : ''; } } if ($_inclusions_active) { $option_set = 'includes'; $this->opt_class[''] = " class='pp-no' "; } else { $option_set = 'standard'; if (!$this->opt_class['']) { $this->opt_class[''] = " class='pp-def' "; } } $disabled = $disabled || 'children' == $assign_for && apply_filters('pp_assign_for_children_locked', false, $for_item_type, array('operation' => $op)) ? ' disabled="disabled" ' : ''; $for_type = $for_item_type ? $for_item_type : '(all)'; ?> <td class="<?php echo 'children' == $assign_for ? 'pp-exc-children' : 'pp-exc-item'; ?> "><select name='pp_exceptions<?php echo "[{$for_type}][{$op}][{$agent_type}][{$assign_for}][{$agent_id}]'{$this->opt_class[$current_val]}"; echo $disabled; ?> > <?php foreach ($this->options[$option_set] as $val => $lbl) { if ('wp_role' == $agent_type && in_array($agent_info->metagroup_id, array('wp_anon', 'wp_all')) && !defined('PP_ALL_ANON_FULL_EXCEPTIONS') && 2 == $val) { continue; } ?> <option value='<?php echo "{$val}'{$this->opt_class[$val]}"; selected($val, $current_val); ?> ><?php echo $lbl; ?> </option> <?php } ?> </select> <?php if ($disabled) { ?> <input type="hidden" name='pp_exceptions<?php echo "[{$for_type}][{$op}][{$agent_type}][{$assign_for}][{$agent_id}]"; ?> ' value="<?php echo $current_val; ?> " /> <?php } ?> </td> <?php } ?> </tr> <?php }
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>'; }