Newer
Older
The Great Git Migration
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
/**
* Filter handler for usernames
*/
class views_handler_filter_user_name extends views_handler_filter_in_operator {
var $no_single = TRUE;
function value_form(&$form, &$form_state) {
$values = array();
if ($this->value) {
$result = db_query("SELECT * FROM {users} u WHERE uid IN (" . implode(', ', $this->value) . ")");
while ($account = db_fetch_object($result)) {
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'];
$values = drupal_explode_tags($form_state['values'][$identifier]);
$uids = $this->validate_user_strings($form[$identifier], $values);
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 (" . implode(', ', $placeholders) . ")", $args);
while ($account = db_fetch_object($result)) {
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() {
// 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 (" . implode(', ', $this->value) . ")");
while ($account = db_fetch_object($result)) {
if ($account->uid) {
$this->value_options[$account->uid] = $account->name;
}
else {
$this->value_options[$account->uid] = 'Anonymous'; // Intentionally NOT translated.
}
}
}
return parent::admin_summary();
}
}