33
modules/user/views_handler_argument_user_uid.inc
Normal file
33
modules/user/views_handler_argument_user_uid.inc
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of views_handler_argument_user_uid.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Argument handler to accept a user id.
|
||||
*
|
||||
* @ingroup views_argument_handlers
|
||||
*/
|
||||
class views_handler_argument_user_uid extends views_handler_argument_numeric {
|
||||
/**
|
||||
* Override the behavior of title(). Get the name of the user.
|
||||
*
|
||||
* @return array
|
||||
* A list of usernames.
|
||||
*/
|
||||
function title_query() {
|
||||
if (!$this->argument) {
|
||||
return array(variable_get('anonymous', t('Anonymous')));
|
||||
}
|
||||
|
||||
$titles = array();
|
||||
|
||||
$result = db_query("SELECT u.name FROM {users} u WHERE u.uid IN (:uids)", array(':uids' => $this->value));
|
||||
foreach ($result as $term) {
|
||||
$titles[] = check_plain($term->name);
|
||||
}
|
||||
return $titles;
|
||||
}
|
||||
}
|
23
modules/user/views_handler_argument_users_roles_rid.inc
Normal file
23
modules/user/views_handler_argument_users_roles_rid.inc
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of views_handler_argument_users_roles_rid.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Allow role ID(s) as argument.
|
||||
*
|
||||
* @ingroup views_argument_handlers
|
||||
*/
|
||||
class views_handler_argument_users_roles_rid extends views_handler_argument_many_to_one {
|
||||
function title_query() {
|
||||
$titles = array();
|
||||
|
||||
$result = db_query("SELECT name FROM {role} WHERE rid IN (:rids)", array(':rids' => $this->value));
|
||||
foreach ($result as $term) {
|
||||
$titles[] = check_plain($term->name);
|
||||
}
|
||||
return $titles;
|
||||
}
|
||||
}
|
55
modules/user/views_handler_field_user.inc
Normal file
55
modules/user/views_handler_field_user.inc
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of views_handler_field_user.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Field handler to provide simple renderer that allows linking to a user.
|
||||
*
|
||||
* @ingroup views_field_handlers
|
||||
*/
|
||||
class views_handler_field_user extends views_handler_field {
|
||||
/**
|
||||
* Override init function to provide generic option to link to user.
|
||||
*/
|
||||
function init(&$view, &$data) {
|
||||
parent::init($view, $data);
|
||||
if (!empty($this->options['link_to_user'])) {
|
||||
$this->additional_fields['uid'] = 'uid';
|
||||
}
|
||||
}
|
||||
|
||||
function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['link_to_user'] = array('default' => TRUE, 'bool' => TRUE);
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide link to node option
|
||||
*/
|
||||
function options_form(&$form, &$form_state) {
|
||||
$form['link_to_user'] = array(
|
||||
'#title' => t('Link this field to its user'),
|
||||
'#description' => t("Enable to override this field's links."),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => $this->options['link_to_user'],
|
||||
);
|
||||
parent::options_form($form, $form_state);
|
||||
}
|
||||
|
||||
function render_link($data, $values) {
|
||||
if (!empty($this->options['link_to_user']) && user_access('access user profiles') && ($uid = $this->get_value($values, 'uid')) && $data !== NULL && $data !== '') {
|
||||
$this->options['alter']['make_link'] = TRUE;
|
||||
$this->options['alter']['path'] = "user/" . $uid;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
function render($values) {
|
||||
$value = $this->get_value($values);
|
||||
return $this->render_link($this->sanitize_value($value), $values);
|
||||
}
|
||||
}
|
39
modules/user/views_handler_field_user_language.inc
Normal file
39
modules/user/views_handler_field_user_language.inc
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of views_handler_field_user_language.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Views field handler for user language.
|
||||
*
|
||||
* @ingroup views_field_handlers
|
||||
*/
|
||||
class views_handler_field_user_language extends views_handler_field_user {
|
||||
|
||||
function render_link($data, $values) {
|
||||
$uid = $this->get_value($values, 'uid');
|
||||
if (!empty($this->options['link_to_user'])) {
|
||||
$uid = $this->get_value($values, 'uid');
|
||||
if (user_access('access user profiles') && $uid) {
|
||||
$this->options['alter']['make_link'] = TRUE;
|
||||
$this->options['alter']['path'] = 'user/' . $uid;
|
||||
}
|
||||
}
|
||||
if (empty($data)) {
|
||||
$lang = language_default();
|
||||
}
|
||||
else {
|
||||
$lang = language_list();
|
||||
$lang = $lang[$data];
|
||||
}
|
||||
|
||||
return $this->sanitize_value($lang->name);
|
||||
}
|
||||
|
||||
function render($values) {
|
||||
$value = $this->get_value($values);
|
||||
return $this->render_link($this->sanitize_value($value), $values);
|
||||
}
|
||||
}
|
58
modules/user/views_handler_field_user_link.inc
Normal file
58
modules/user/views_handler_field_user_link.inc
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of views_handler_field_user_link.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Field handler to present a link to the user.
|
||||
*
|
||||
* @ingroup views_field_handlers
|
||||
*/
|
||||
class views_handler_field_user_link extends views_handler_field {
|
||||
function construct() {
|
||||
parent::construct();
|
||||
$this->additional_fields['uid'] = 'uid';
|
||||
}
|
||||
|
||||
function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['text'] = array('default' => '', 'translatable' => TRUE);
|
||||
return $options;
|
||||
}
|
||||
|
||||
function options_form(&$form, &$form_state) {
|
||||
$form['text'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Text to display'),
|
||||
'#default_value' => $this->options['text'],
|
||||
);
|
||||
parent::options_form($form, $form_state);
|
||||
}
|
||||
|
||||
// An example of field level access control.
|
||||
function access() {
|
||||
return user_access('access user profiles');
|
||||
}
|
||||
|
||||
function query() {
|
||||
$this->ensure_my_table();
|
||||
$this->add_additional_fields();
|
||||
}
|
||||
|
||||
function render($values) {
|
||||
$value = $this->get_value($values, 'uid');
|
||||
return $this->render_link($this->sanitize_value($value), $values);
|
||||
}
|
||||
|
||||
function render_link($data, $values) {
|
||||
$text = !empty($this->options['text']) ? $this->options['text'] : t('view');
|
||||
|
||||
$this->options['alter']['make_link'] = TRUE;
|
||||
$this->options['alter']['path'] = "user/" . $data;
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
}
|
33
modules/user/views_handler_field_user_link_cancel.inc
Normal file
33
modules/user/views_handler_field_user_link_cancel.inc
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of views_handler_field_user_link_cancel.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Field handler to present a link to user cancel.
|
||||
*
|
||||
* @ingroup views_field_handlers
|
||||
*/
|
||||
class views_handler_field_user_link_cancel extends views_handler_field_user_link {
|
||||
|
||||
function render_link($data, $values) {
|
||||
$uid = $values->{$this->aliases['uid']};
|
||||
|
||||
// Build a pseudo account object to be able to check the access.
|
||||
$account = new stdClass();
|
||||
$account->uid = $uid;
|
||||
|
||||
if ($uid && user_cancel_access($account)) {
|
||||
$this->options['alter']['make_link'] = TRUE;
|
||||
|
||||
$text = !empty($this->options['text']) ? $this->options['text'] : t('cancel');
|
||||
|
||||
$this->options['alter']['path'] = "user/$uid/cancel";
|
||||
$this->options['alter']['query'] = drupal_get_destination();
|
||||
|
||||
return $text;
|
||||
}
|
||||
}
|
||||
}
|
30
modules/user/views_handler_field_user_link_edit.inc
Normal file
30
modules/user/views_handler_field_user_link_edit.inc
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of views_handler_field_user_link_edit.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Field handler to present a link to user edit.
|
||||
*
|
||||
* @ingroup views_field_handlers
|
||||
*/
|
||||
class views_handler_field_user_link_edit extends views_handler_field_user_link {
|
||||
function render_link($data, $values) {
|
||||
// Build a pseudo account object to be able to check the access.
|
||||
$account = new stdClass();
|
||||
$account->uid = $data;
|
||||
|
||||
if ($data && user_edit_access($account)) {
|
||||
$this->options['alter']['make_link'] = TRUE;
|
||||
|
||||
$text = !empty($this->options['text']) ? $this->options['text'] : t('edit');
|
||||
|
||||
$this->options['alter']['path'] = "user/$data/edit";
|
||||
$this->options['alter']['query'] = drupal_get_destination();
|
||||
|
||||
return $text;
|
||||
}
|
||||
}
|
||||
}
|
44
modules/user/views_handler_field_user_mail.inc
Normal file
44
modules/user/views_handler_field_user_mail.inc
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of views_handler_field_user_mail.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Field handler to provide acess control for the email field.
|
||||
*
|
||||
* @ingroup views_field_handlers
|
||||
*/
|
||||
class views_handler_field_user_mail extends views_handler_field_user {
|
||||
function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['link_to_user'] = array('default' => 'mailto');
|
||||
return $options;
|
||||
}
|
||||
|
||||
function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
$form['link_to_user'] = array(
|
||||
'#title' => t('Link this field'),
|
||||
'#type' => 'radios',
|
||||
'#options' => array(
|
||||
0 => t('No link'),
|
||||
'user' => t('To the user'),
|
||||
'mailto' => t("With a mailto:"),
|
||||
),
|
||||
'#default_value' => $this->options['link_to_user'],
|
||||
);
|
||||
}
|
||||
|
||||
function render_link($data, $values) {
|
||||
parent::render_link($data, $values);
|
||||
|
||||
if ($this->options['link_to_user'] == 'mailto') {
|
||||
$this->options['alter']['make_link'] = TRUE;
|
||||
$this->options['alter']['path'] = "mailto:" . $data;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
83
modules/user/views_handler_field_user_name.inc
Normal file
83
modules/user/views_handler_field_user_name.inc
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of views_handler_field_user_name.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Field handler to provide simple renderer that allows using a themed user link.
|
||||
*
|
||||
* @ingroup views_field_handlers
|
||||
*/
|
||||
class views_handler_field_user_name extends views_handler_field_user {
|
||||
/**
|
||||
* Add uid in the query so we can test for anonymous if needed.
|
||||
*/
|
||||
function init(&$view, &$data) {
|
||||
parent::init($view, $data);
|
||||
if (!empty($this->options['overwrite_anonymous']) || !empty($this->options['format_username'])) {
|
||||
$this->additional_fields['uid'] = 'uid';
|
||||
}
|
||||
}
|
||||
|
||||
function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
|
||||
$options['overwrite_anonymous'] = array('default' => FALSE, 'bool' => TRUE);
|
||||
$options['anonymous_text'] = array('default' => '', 'translatable' => TRUE);
|
||||
$options['format_username'] = array('default' => TRUE, 'bool' => TRUE);
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
function options_form(&$form, &$form_state) {
|
||||
$form['format_username'] = array(
|
||||
'#title' => t('Use formatted username'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => !empty($this->options['format_username']),
|
||||
'#description' => t('If checked, the username will be formatted by the system. If unchecked, it will be displayed raw.'),
|
||||
'#fieldset' => 'more',
|
||||
);
|
||||
$form['overwrite_anonymous'] = array(
|
||||
'#title' => t('Overwrite the value to display for anonymous users'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => !empty($this->options['overwrite_anonymous']),
|
||||
'#description' => t('Enable to display different text for anonymous users.'),
|
||||
'#fieldset' => 'more',
|
||||
);
|
||||
$form['anonymous_text'] = array(
|
||||
'#title' => t('Text to display for anonymous users'),
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => $this->options['anonymous_text'],
|
||||
'#dependency' => array(
|
||||
'edit-options-overwrite-anonymous' => array(1),
|
||||
),
|
||||
'#fieldset' => 'more',
|
||||
);
|
||||
|
||||
parent::options_form($form, $form_state);
|
||||
}
|
||||
|
||||
function render_link($data, $values) {
|
||||
$account = new stdClass();
|
||||
$account->uid = $this->get_value($values, 'uid');
|
||||
$account->name = $this->get_value($values);
|
||||
if (!empty($this->options['link_to_user']) || !empty($this->options['overwrite_anonymous'])) {
|
||||
if (!empty($this->options['overwrite_anonymous']) && !$account->uid) {
|
||||
// This is an anonymous user, and we're overriting the text.
|
||||
return check_plain($this->options['anonymous_text']);
|
||||
}
|
||||
elseif (!empty($this->options['link_to_user'])) {
|
||||
$account->name = $this->get_value($values);
|
||||
return theme('username', array('account' => $account));
|
||||
}
|
||||
}
|
||||
// If we want a formatted username, do that.
|
||||
if (!empty($this->options['format_username'])) {
|
||||
return format_username($account);
|
||||
}
|
||||
// Otherwise, there's no special handling, so return the data directly.
|
||||
return $data;
|
||||
}
|
||||
}
|
68
modules/user/views_handler_field_user_permissions.inc
Normal file
68
modules/user/views_handler_field_user_permissions.inc
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of views_handler_field_user_permissions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Field handler to provide a list of permissions.
|
||||
*
|
||||
* @ingroup views_field_handlers
|
||||
*/
|
||||
class views_handler_field_user_permissions extends views_handler_field_prerender_list {
|
||||
function construct() {
|
||||
parent::construct();
|
||||
$this->additional_fields['uid'] = array('table' => 'users', 'field' => 'uid');
|
||||
}
|
||||
|
||||
function query() {
|
||||
$this->add_additional_fields();
|
||||
$this->field_alias = $this->aliases['uid'];
|
||||
}
|
||||
|
||||
function pre_render(&$values) {
|
||||
$uids = array();
|
||||
$this->items = array();
|
||||
|
||||
foreach ($values as $result) {
|
||||
$uids[] = $this->get_value($result, NULL, TRUE);
|
||||
}
|
||||
|
||||
if ($uids) {
|
||||
// Get a list of all the modules implementing a hook_permission() and sort by
|
||||
// display name.
|
||||
$module_info = system_get_info('module');
|
||||
$modules = array();
|
||||
foreach (module_implements('permission') as $module) {
|
||||
$modules[$module] = $module_info[$module]['name'];
|
||||
}
|
||||
asort($modules);
|
||||
|
||||
$permissions = module_invoke_all('permission');
|
||||
|
||||
$result = db_query("SELECT u.uid, u.rid, rp.permission FROM {role_permission} rp INNER JOIN {users_roles} u ON u.rid = rp.rid WHERE u.uid IN (:uids) AND rp.module IN (:modules) ORDER BY rp.permission",
|
||||
array(':uids' => $uids, ':modules' => array_keys($modules)));
|
||||
|
||||
foreach ($result as $perm) {
|
||||
$this->items[$perm->uid][$perm->permission]['permission'] = $permissions[$perm->permission]['title'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function render_item($count, $item) {
|
||||
return $item['permission'];
|
||||
}
|
||||
|
||||
/*
|
||||
function document_self_tokens(&$tokens) {
|
||||
$tokens['[' . $this->options['id'] . '-role' . ']'] = t('The name of the role.');
|
||||
$tokens['[' . $this->options['id'] . '-rid' . ']'] = t('The role ID of the role.');
|
||||
}
|
||||
|
||||
function add_self_tokens(&$tokens, $item) {
|
||||
$tokens['[' . $this->options['id'] . '-role' . ']'] = $item['role'];
|
||||
$tokens['[' . $this->options['id'] . '-rid' . ']'] = $item['rid'];
|
||||
}
|
||||
*/
|
||||
}
|
114
modules/user/views_handler_field_user_picture.inc
Normal file
114
modules/user/views_handler_field_user_picture.inc
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of views_handler_field_user_picture.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Field handler to provide simple renderer that allows using a themed user link.
|
||||
*
|
||||
* @ingroup views_field_handlers
|
||||
*/
|
||||
class views_handler_field_user_picture extends views_handler_field {
|
||||
function construct() {
|
||||
parent::construct();
|
||||
$this->additional_fields['uid'] = 'uid';
|
||||
$this->additional_fields['name'] = 'name';
|
||||
$this->additional_fields['mail'] = 'mail';
|
||||
}
|
||||
|
||||
function element_type($none_supported = FALSE, $default_empty = FALSE, $inline = FALSE) {
|
||||
if ($inline) {
|
||||
return 'span';
|
||||
}
|
||||
if ($none_supported) {
|
||||
if ($this->options['element_type'] === '0') {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
if ($this->options['element_type']) {
|
||||
return check_plain($this->options['element_type']);
|
||||
}
|
||||
if ($default_empty) {
|
||||
return '';
|
||||
}
|
||||
if (isset($this->definition['element type'])) {
|
||||
return $this->definition['element type'];
|
||||
}
|
||||
|
||||
return 'div';
|
||||
}
|
||||
|
||||
function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['link_photo_to_profile'] = array('default' => TRUE, 'bool' => TRUE);
|
||||
$options['image_style'] = array('default' => '');
|
||||
return $options;
|
||||
}
|
||||
|
||||
function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
$form['link_photo_to_profile'] = array(
|
||||
'#title' => t("Link to user's profile"),
|
||||
'#description' => t("Link the user picture to the user's profile"),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => $this->options['link_photo_to_profile'],
|
||||
);
|
||||
|
||||
if (module_exists('image')) {
|
||||
$styles = image_styles();
|
||||
$style_options = array('' => t('Default'));
|
||||
foreach ($styles as $style) {
|
||||
$style_options[$style['name']] = $style['name'];
|
||||
}
|
||||
|
||||
$form['image_style'] = array(
|
||||
'#title' => t('Image style'),
|
||||
'#description' => t('Using <em>Default</em> will use the site-wide image style for user pictures set in the <a href="!account-settings">Account settings</a>.', array('!account-settings' => url('admin/config/people/accounts', array('fragment' => 'edit-personalization')))),
|
||||
'#type' => 'select',
|
||||
'#options' => $style_options,
|
||||
'#default_value' => $this->options['image_style'],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function render($values) {
|
||||
if ($this->options['image_style'] && module_exists('image')) {
|
||||
// @todo: Switch to always using theme('user_picture') when it starts
|
||||
// supporting image styles. See http://drupal.org/node/1021564
|
||||
if ($picture_fid = $this->get_value($values)) {
|
||||
$picture = file_load($picture_fid);
|
||||
$picture_filepath = $picture->uri;
|
||||
}
|
||||
else {
|
||||
$picture_filepath = variable_get('user_picture_default', '');
|
||||
}
|
||||
if (file_valid_uri($picture_filepath)) {
|
||||
$output = theme('image_style', array('style_name' => $this->options['image_style'], 'path' => $picture_filepath));
|
||||
if ($this->options['link_photo_to_profile'] && user_access('access user profiles')) {
|
||||
$uid = $this->get_value($values, 'uid');
|
||||
$output = l($output, "user/$uid", array('html' => TRUE));
|
||||
}
|
||||
}
|
||||
else {
|
||||
$output = '';
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Fake an account object.
|
||||
$account = new stdClass();
|
||||
if ($this->options['link_photo_to_profile']) {
|
||||
// Prevent template_preprocess_user_picture from adding a link
|
||||
// by not setting the uid.
|
||||
$account->uid = $this->get_value($values, 'uid');
|
||||
}
|
||||
$account->name = $this->get_value($values, 'name');
|
||||
$account->mail = $this->get_value($values, 'mail');
|
||||
$account->picture = $this->get_value($values);
|
||||
$output = theme('user_picture', array('account' => $account));
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
57
modules/user/views_handler_field_user_roles.inc
Normal file
57
modules/user/views_handler_field_user_roles.inc
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of views_handler_field_user_roles.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Field handler to provide a list of roles.
|
||||
*
|
||||
* @ingroup views_field_handlers
|
||||
*/
|
||||
class views_handler_field_user_roles extends views_handler_field_prerender_list {
|
||||
function construct() {
|
||||
parent::construct();
|
||||
$this->additional_fields['uid'] = array('table' => 'users', 'field' => 'uid');
|
||||
}
|
||||
|
||||
function query() {
|
||||
$this->add_additional_fields();
|
||||
$this->field_alias = $this->aliases['uid'];
|
||||
}
|
||||
|
||||
function pre_render(&$values) {
|
||||
$uids = array();
|
||||
$this->items = array();
|
||||
|
||||
foreach ($values as $result) {
|
||||
$uids[] = $this->get_value($result, NULL, TRUE);
|
||||
}
|
||||
|
||||
if ($uids) {
|
||||
$result = db_query("SELECT u.uid, u.rid, r.name FROM {role} r INNER JOIN {users_roles} u ON u.rid = r.rid WHERE u.uid IN (:uids) ORDER BY r.name",
|
||||
array(':uids' => $uids));
|
||||
foreach ($result as $role) {
|
||||
$this->items[$role->uid][$role->rid]['role'] = check_plain($role->name);
|
||||
$this->items[$role->uid][$role->rid]['rid'] = $role->rid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function render_item($count, $item) {
|
||||
return $item['role'];
|
||||
}
|
||||
|
||||
function document_self_tokens(&$tokens) {
|
||||
$tokens['[' . $this->options['id'] . '-role' . ']'] = t('The name of the role.');
|
||||
$tokens['[' . $this->options['id'] . '-rid' . ']'] = t('The role ID of the role.');
|
||||
}
|
||||
|
||||
function add_self_tokens(&$tokens, $item) {
|
||||
if (!empty($item['role'])) {
|
||||
$tokens['[' . $this->options['id'] . '-role' . ']'] = $item['role'];
|
||||
$tokens['[' . $this->options['id'] . '-rid' . ']'] = $item['rid'];
|
||||
}
|
||||
}
|
||||
}
|
36
modules/user/views_handler_filter_user_current.inc
Normal file
36
modules/user/views_handler_filter_user_current.inc
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of views_handler_filter_user_current.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Filter handler for the current user.
|
||||
*
|
||||
* @ingroup views_filter_handlers
|
||||
*/
|
||||
class views_handler_filter_user_current extends views_handler_filter_boolean_operator {
|
||||
function construct() {
|
||||
parent::construct();
|
||||
$this->value_value = t('Is the logged in user');
|
||||
}
|
||||
|
||||
function query() {
|
||||
$this->ensure_my_table();
|
||||
|
||||
$field = $this->table_alias . '.' . $this->real_field . ' ';
|
||||
$or = db_or();
|
||||
|
||||
if (empty($this->value)) {
|
||||
$or->condition($field, '***CURRENT_USER***', '<>');
|
||||
if ($this->accept_null) {
|
||||
$or->isNull($field);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$or->condition($field, '***CURRENT_USER***', '=');
|
||||
}
|
||||
$this->query->add_where($this->options['group'], $or);
|
||||
}
|
||||
}
|
162
modules/user/views_handler_filter_user_name.inc
Normal file
162
modules/user/views_handler_filter_user_name.inc
Normal file
@@ -0,0 +1,162 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of views_handler_filter_user_name.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Filter handler for usernames.
|
||||
*
|
||||
* @ingroup views_filter_handlers
|
||||
*/
|
||||
class views_handler_filter_user_name extends views_handler_filter_in_operator {
|
||||
var $always_multiple = TRUE;
|
||||
|
||||
function value_form(&$form, &$form_state) {
|
||||
$values = array();
|
||||
if ($this->value) {
|
||||
$result = db_query("SELECT * FROM {users} u WHERE uid IN (:uids)", array(':uids' => $this->value));
|
||||
foreach ($result as $account) {
|
||||
if ($account->uid) {
|
||||
$values[] = $account->name;
|
||||
}
|
||||
else {
|
||||
$values[] = 'Anonymous'; // Intentionally NOT translated.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sort($values);
|
||||
$default_value = implode(', ', $values);
|
||||
$form['value'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Usernames'),
|
||||
'#description' => t('Enter a comma separated list of user names.'),
|
||||
'#default_value' => $default_value,
|
||||
'#autocomplete_path' => 'admin/views/ajax/autocomplete/user',
|
||||
);
|
||||
|
||||
if (!empty($form_state['exposed']) && !isset($form_state['input'][$this->options['expose']['identifier']])) {
|
||||
$form_state['input'][$this->options['expose']['identifier']] = $default_value;
|
||||
}
|
||||
}
|
||||
|
||||
function value_validate($form, &$form_state) {
|
||||
$values = drupal_explode_tags($form_state['values']['options']['value']);
|
||||
$uids = $this->validate_user_strings($form['value'], $values);
|
||||
|
||||
if ($uids) {
|
||||
$form_state['values']['options']['value'] = $uids;
|
||||
}
|
||||
}
|
||||
|
||||
function accept_exposed_input($input) {
|
||||
$rc = parent::accept_exposed_input($input);
|
||||
|
||||
if ($rc) {
|
||||
// If we have previously validated input, override.
|
||||
if (isset($this->validated_exposed_input)) {
|
||||
$this->value = $this->validated_exposed_input;
|
||||
}
|
||||
}
|
||||
|
||||
return $rc;
|
||||
}
|
||||
|
||||
function exposed_validate(&$form, &$form_state) {
|
||||
if (empty($this->options['exposed'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (empty($this->options['expose']['identifier'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$identifier = $this->options['expose']['identifier'];
|
||||
$input = $form_state['values'][$identifier];
|
||||
|
||||
if ($this->options['is_grouped'] && isset($this->options['group_info']['group_items'][$input])) {
|
||||
$this->operator = $this->options['group_info']['group_items'][$input]['operator'];
|
||||
$input = $this->options['group_info']['group_items'][$input]['value'];
|
||||
}
|
||||
|
||||
$values = drupal_explode_tags($input);
|
||||
|
||||
if (!$this->options['is_grouped'] || ($this->options['is_grouped'] && ($input != 'All'))) {
|
||||
$uids = $this->validate_user_strings($form[$identifier], $values);
|
||||
}
|
||||
else {
|
||||
$uids = FALSE;
|
||||
}
|
||||
|
||||
if ($uids) {
|
||||
$this->validated_exposed_input = $uids;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the user string. Since this can come from either the form
|
||||
* or the exposed filter, this is abstracted out a bit so it can
|
||||
* handle the multiple input sources.
|
||||
*/
|
||||
function validate_user_strings(&$form, $values) {
|
||||
$uids = array();
|
||||
$placeholders = array();
|
||||
$args = array();
|
||||
$results = array();
|
||||
foreach ($values as $value) {
|
||||
if (strtolower($value) == 'anonymous') {
|
||||
$uids[] = 0;
|
||||
}
|
||||
else {
|
||||
$missing[strtolower($value)] = TRUE;
|
||||
$args[] = $value;
|
||||
$placeholders[] = "'%s'";
|
||||
}
|
||||
}
|
||||
|
||||
if (!$args) {
|
||||
return $uids;
|
||||
}
|
||||
|
||||
$result = db_query("SELECT * FROM {users} WHERE name IN (:names)", array(':names' => $args));
|
||||
foreach ($result as $account) {
|
||||
unset($missing[strtolower($account->name)]);
|
||||
$uids[] = $account->uid;
|
||||
}
|
||||
|
||||
if ($missing) {
|
||||
form_error($form, format_plural(count($missing), 'Unable to find user: @users', 'Unable to find users: @users', array('@users' => implode(', ', array_keys($missing)))));
|
||||
}
|
||||
|
||||
return $uids;
|
||||
}
|
||||
|
||||
function value_submit($form, &$form_state) {
|
||||
// prevent array filter from removing our anonymous user.
|
||||
}
|
||||
|
||||
// Override to do nothing.
|
||||
function get_value_options() { }
|
||||
|
||||
function admin_summary() {
|
||||
// set up $this->value_options for the parent summary
|
||||
$this->value_options = array();
|
||||
|
||||
if ($this->value) {
|
||||
$result = db_query("SELECT * FROM {users} u WHERE uid IN (:uids)", array(':uids' => $this->value));
|
||||
|
||||
foreach ($result as $account) {
|
||||
if ($account->uid) {
|
||||
$this->value_options[$account->uid] = $account->name;
|
||||
}
|
||||
else {
|
||||
$this->value_options[$account->uid] = 'Anonymous'; // Intentionally NOT translated.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return parent::admin_summary();
|
||||
}
|
||||
}
|
35
modules/user/views_handler_filter_user_permissions.inc
Normal file
35
modules/user/views_handler_filter_user_permissions.inc
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of views_handler_filter_user_permissions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Filter handler for user roles.
|
||||
*
|
||||
* @ingroup views_filter_handlers
|
||||
*/
|
||||
class views_handler_filter_user_permissions extends views_handler_filter_many_to_one {
|
||||
function get_value_options() {
|
||||
$module_info = system_get_info('module');
|
||||
|
||||
// Get a list of all the modules implementing a hook_permission() and sort by
|
||||
// display name.
|
||||
$modules = array();
|
||||
foreach (module_implements('permission') as $module) {
|
||||
$modules[$module] = $module_info[$module]['name'];
|
||||
}
|
||||
asort($modules);
|
||||
|
||||
$this->value_options = array();
|
||||
foreach ($modules as $module => $display_name) {
|
||||
if ($permissions = module_invoke($module, 'permission')) {
|
||||
foreach ($permissions as $perm => $perm_item) {
|
||||
// @todo: group by module but views_handler_filter_many_to_one does not support this.
|
||||
$this->value_options[$perm] = check_plain(strip_tags($perm_item['title']));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
28
modules/user/views_handler_filter_user_roles.inc
Normal file
28
modules/user/views_handler_filter_user_roles.inc
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of views_handler_filter_user_roles.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Filter handler for user roles.
|
||||
*
|
||||
* @ingroup views_filter_handlers
|
||||
*/
|
||||
class views_handler_filter_user_roles extends views_handler_filter_many_to_one {
|
||||
function get_value_options() {
|
||||
$this->value_options = user_roles(TRUE);
|
||||
unset($this->value_options[DRUPAL_AUTHENTICATED_RID]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Override empty and not empty operator labels to be clearer for user roles.
|
||||
*/
|
||||
function operators() {
|
||||
$operators = parent::operators();
|
||||
$operators['empty']['title'] = t("Only has the 'authenticated user' role");
|
||||
$operators['not empty']['title'] = t("Has roles in addition to 'authenticated user'");
|
||||
return $operators;
|
||||
}
|
||||
}
|
18
modules/user/views_plugin_argument_default_current_user.inc
Normal file
18
modules/user/views_plugin_argument_default_current_user.inc
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains the current user argument default plugin.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Default argument plugin to extract the global $user
|
||||
*
|
||||
* This plugin actually has no options so it odes not need to do a great deal.
|
||||
*/
|
||||
class views_plugin_argument_default_current_user extends views_plugin_argument_default {
|
||||
function get_argument() {
|
||||
global $user;
|
||||
return $user->uid;
|
||||
}
|
||||
}
|
77
modules/user/views_plugin_argument_default_user.inc
Normal file
77
modules/user/views_plugin_argument_default_user.inc
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains the user from URL argument default plugin.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Default argument plugin to extract a user via menu_get_object.
|
||||
*/
|
||||
class views_plugin_argument_default_user extends views_plugin_argument_default {
|
||||
function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['user'] = array('default' => '', 'bool' => TRUE, 'translatable' => FALSE);
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
function options_form(&$form, &$form_state) {
|
||||
$form['user'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Also look for a node and use the node author'),
|
||||
'#default_value' => $this->options['user'],
|
||||
);
|
||||
}
|
||||
|
||||
function convert_options(&$options) {
|
||||
if (!isset($options['user']) && isset($this->argument->options['default_argument_user'])) {
|
||||
$options['user'] = $this->argument->options['default_argument_user'];
|
||||
}
|
||||
}
|
||||
|
||||
function get_argument() {
|
||||
foreach (range(1, 3) as $i) {
|
||||
$user = menu_get_object('user', $i);
|
||||
if (!empty($user)) {
|
||||
return $user->uid;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (range(1, 3) as $i) {
|
||||
$user = menu_get_object('user_uid_optional', $i);
|
||||
if (!empty($user)) {
|
||||
return $user->uid;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($this->options['user'])) {
|
||||
foreach (range(1, 3) as $i) {
|
||||
$node = menu_get_object('node', $i);
|
||||
if (!empty($node)) {
|
||||
return $node->uid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (arg(0) == 'user' && is_numeric(arg(1))) {
|
||||
return arg(1);
|
||||
}
|
||||
|
||||
if (!empty($this->options['user'])) {
|
||||
if (arg(0) == 'node' && is_numeric(arg(1))) {
|
||||
$node = node_load(arg(1));
|
||||
if ($node) {
|
||||
return $node->uid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If the current page is a view that takes uid as an argument, return the uid.
|
||||
$view = views_get_page_view();
|
||||
|
||||
if ($view && isset($view->argument['uid'])) {
|
||||
return $view->argument['uid']->argument;
|
||||
}
|
||||
}
|
||||
}
|
140
modules/user/views_plugin_argument_validate_user.inc
Normal file
140
modules/user/views_plugin_argument_validate_user.inc
Normal file
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of views_plugin_argument_validate_user.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Validate whether an argument is a valid user.
|
||||
*
|
||||
* This supports either numeric arguments (UID) or strings (username) and
|
||||
* converts either one into the user's UID. This validator also sets the
|
||||
* argument's title to the username.
|
||||
*/
|
||||
class views_plugin_argument_validate_user extends views_plugin_argument_validate {
|
||||
function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['type'] = array('default' => 'uid');
|
||||
$options['restrict_roles'] = array('default' => FALSE, 'bool' => TRUE);
|
||||
$options['roles'] = array('default' => array());
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
function options_form(&$form, &$form_state) {
|
||||
$form['type'] = array(
|
||||
'#type' => 'radios',
|
||||
'#title' => t('Type of user filter value to allow'),
|
||||
'#options' => array(
|
||||
'uid' => t('Only allow numeric UIDs'),
|
||||
'name' => t('Only allow string usernames'),
|
||||
'either' => t('Allow both numeric UIDs and string usernames'),
|
||||
),
|
||||
'#default_value' => $this->options['type'],
|
||||
);
|
||||
|
||||
$form['restrict_roles'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Restrict user based on role'),
|
||||
'#default_value' => $this->options['restrict_roles'],
|
||||
);
|
||||
|
||||
$form['roles'] = array(
|
||||
'#type' => 'checkboxes',
|
||||
'#prefix' => '<div id="edit-options-validate-options-user-roles-wrapper">',
|
||||
'#suffix' => '</div>',
|
||||
'#title' => t('Restrict to the selected roles'),
|
||||
'#options' => array_map('check_plain', user_roles(TRUE)),
|
||||
'#default_value' => $this->options['roles'],
|
||||
'#description' => t('If no roles are selected, users from any role will be allowed.'),
|
||||
'#dependency' => array(
|
||||
'edit-options-validate-options-user-restrict-roles' => array(1),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
function options_submit(&$form, &$form_state, &$options = array()) {
|
||||
// filter trash out of the options so we don't store giant unnecessary arrays
|
||||
$options['roles'] = array_filter($options['roles']);
|
||||
}
|
||||
|
||||
function convert_options(&$options) {
|
||||
if (!isset($options['type']) && isset($this->argument->options['validate_user_argument_type'])) {
|
||||
$options['type'] = $this->argument->options['validate_user_argument_type'];
|
||||
$options['restrict_roles'] = $this->argument->options['validate_user_restrict_roles'];
|
||||
$options['roles'] = $this->argument->options['validate_user_roles'];
|
||||
}
|
||||
}
|
||||
|
||||
function validate_argument($argument) {
|
||||
$type = $this->options['type'];
|
||||
// is_numeric() can return false positives, so we ensure it's an integer.
|
||||
// However, is_integer() will always fail, since $argument is a string.
|
||||
if (is_numeric($argument) && $argument == (int)$argument) {
|
||||
if ($type == 'uid' || $type == 'either') {
|
||||
if ($argument == $GLOBALS['user']->uid) {
|
||||
// If you assign an object to a variable in PHP, the variable
|
||||
// automatically acts as a reference, not a copy, so we use
|
||||
// clone to ensure that we don't actually mess with the
|
||||
// real global $user object.
|
||||
$account = clone $GLOBALS['user'];
|
||||
}
|
||||
$where = 'uid = :argument';
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ($type == 'name' || $type == 'either') {
|
||||
$name = !empty($GLOBALS['user']->name) ? $GLOBALS['user']->name : variable_get('anonymous', t('Anonymous'));
|
||||
if ($argument == $name) {
|
||||
$account = clone $GLOBALS['user'];
|
||||
}
|
||||
$where = "name = :argument";
|
||||
}
|
||||
}
|
||||
|
||||
// If we don't have a WHERE clause, the argument is invalid.
|
||||
if (empty($where)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!isset($account)) {
|
||||
$query = "SELECT uid, name FROM {users} WHERE $where";
|
||||
$account = db_query($query, array(':argument' => $argument))->fetchObject();
|
||||
}
|
||||
if (empty($account)) {
|
||||
// User not found.
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// See if we're filtering users based on roles.
|
||||
if (!empty($this->options['restrict_roles']) && !empty($this->options['roles'])) {
|
||||
$roles = $this->options['roles'];
|
||||
$account->roles = array();
|
||||
$account->roles[] = $account->uid ? DRUPAL_AUTHENTICATED_RID : DRUPAL_ANONYMOUS_RID;
|
||||
$result = db_query('SELECT rid FROM {users_roles} WHERE uid = :uid', array(':uid' => $account->uid));
|
||||
foreach ($result as $role) {
|
||||
$account->roles[] = $role->rid;
|
||||
}
|
||||
if (!(bool) array_intersect($account->roles, $roles)) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
$this->argument->argument = $account->uid;
|
||||
$this->argument->validated_title = check_plain(format_username($account));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
function process_summary_arguments(&$args) {
|
||||
// If the validation says the input is an username, we should reverse the
|
||||
// argument so it works for example for generation summary urls.
|
||||
$uids_arg_keys = array_flip($args);
|
||||
if ($this->options['type'] == 'name') {
|
||||
$users = user_load_multiple($args);
|
||||
foreach ($users as $uid => $account) {
|
||||
$args[$uids_arg_keys[$uid]] = $account->name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
81
modules/user/views_plugin_row_user_view.inc
Normal file
81
modules/user/views_plugin_row_user_view.inc
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains the user view row plugin.
|
||||
*/
|
||||
|
||||
/**
|
||||
* A row plugin which renders a user via user_view.
|
||||
*
|
||||
* @ingroup views_row_plugins
|
||||
*/
|
||||
class views_plugin_row_user_view extends views_plugin_row {
|
||||
var $base_table = 'users';
|
||||
var $base_field = 'uid';
|
||||
|
||||
// Store the users to be used for pre_render.
|
||||
var $users = array();
|
||||
|
||||
function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['view_mode'] = array('default' => 'full');
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
|
||||
$options = $this->options_form_summary_options();
|
||||
$form['view_mode'] = array(
|
||||
'#type' => 'select',
|
||||
'#options' => $options,
|
||||
'#title' => t('View mode'),
|
||||
'#default_value' => $this->options['view_mode'],
|
||||
);
|
||||
$form['help']['#markup'] = t("Display the user with standard user view. It might be necessary to add a user-profile.tpl.php in your themes template folder, because the default <a href=\"@user-profile-api-link\">user-profile</a>e template don't show the username per default.", array('@user-profile-api-link' => url('http://api.drupal.org/api/drupal/modules--user--user-profile.tpl.php/7')));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the main options, which are shown in the summary title.
|
||||
*/
|
||||
function options_form_summary_options() {
|
||||
$entity_info = entity_get_info('user');
|
||||
$options = array();
|
||||
if (!empty($entity_info['view modes'])) {
|
||||
foreach ($entity_info['view modes'] as $mode => $settings) {
|
||||
$options[$mode] = $settings['label'];
|
||||
}
|
||||
}
|
||||
if (empty($options)) {
|
||||
$options = array(
|
||||
'full' => t('User account')
|
||||
);
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
function summary_title() {
|
||||
$options = $this->options_form_summary_options();
|
||||
return check_plain($options[$this->options['view_mode']]);
|
||||
}
|
||||
|
||||
function pre_render($values) {
|
||||
$uids = array();
|
||||
foreach ($values as $row) {
|
||||
$uids[] = $row->{$this->field_alias};
|
||||
}
|
||||
$this->users = user_load_multiple($uids);
|
||||
}
|
||||
|
||||
function render($row) {
|
||||
$account = $this->users[$row->{$this->field_alias}];
|
||||
$account->view = $this->view;
|
||||
$build = user_view($account, $this->options['view_mode']);
|
||||
|
||||
return drupal_render($build);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user