/** * 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; }
wp_die(__('Invalid user ID.', 'pp')); } } 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>' .
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>'; }