1
|
<?php
|
2
|
/**
|
3
|
* @file
|
4
|
* Contains the Flag Bookmark view argument validator.
|
5
|
*/
|
6
|
|
7
|
/**
|
8
|
* Validates whether an argument is a valid UID.
|
9
|
*
|
10
|
* @ingroup views
|
11
|
*/
|
12
|
class flag_bookmark_plugin_validate_user extends views_plugin_argument_validate_user {
|
13
|
|
14
|
/**
|
15
|
* Define the options for the plugin, including the default permission.
|
16
|
* @return multitype:string
|
17
|
*/
|
18
|
function option_definition() {
|
19
|
// Initialize the base class.
|
20
|
$options = parent::option_definition();
|
21
|
|
22
|
// Set the default permission.
|
23
|
$options['bypass_perm'] = array('default' => 'administer users');
|
24
|
|
25
|
return $options;
|
26
|
}
|
27
|
|
28
|
/**
|
29
|
* Returns a option form for the plugin.
|
30
|
*/
|
31
|
function options_form(&$form, &$form_state) {
|
32
|
// Get the options form from the base class.
|
33
|
parent::options_form($form, $form_state);
|
34
|
|
35
|
$perms = array();
|
36
|
$module_info = system_get_info('module');
|
37
|
|
38
|
$perms[] = t(' - None - ');
|
39
|
|
40
|
// Produce an array of permissions keyed by module name.
|
41
|
foreach (module_implements('permission') as $module) {
|
42
|
$permissions = module_invoke($module, 'permission');
|
43
|
foreach ($permissions as $name => $perm) {
|
44
|
$perms[$module_info[$module]['name']][$name] = strip_tags($perm['title']);
|
45
|
}
|
46
|
}
|
47
|
|
48
|
asort($perms);
|
49
|
|
50
|
// Create the form field for the validator. Returned by reference.
|
51
|
$form['bypass_perm'] = array(
|
52
|
'#type' => 'select',
|
53
|
'#options' => $perms,
|
54
|
'#title' => t('Override permission'),
|
55
|
'#default_value' => $this->options['bypass_perm'],
|
56
|
'#description' => t('Users with this permission bypass the argument check and are granted access.'),
|
57
|
);
|
58
|
}
|
59
|
|
60
|
/**
|
61
|
* Validates the argument to be a proper UID.
|
62
|
* @param mixed $argument
|
63
|
* @return boolean
|
64
|
*/
|
65
|
function validate_argument($argument) {
|
66
|
// The parent class takes care of all its options, returning TRUE if the
|
67
|
// argument value validates to a user account, and an account that has the
|
68
|
// required role.
|
69
|
$argument_validates = parent::validate_argument($argument);
|
70
|
|
71
|
// If the parent didn't validate the argument, then we certainly can't
|
72
|
// either.
|
73
|
if ($argument_validates == FALSE) {
|
74
|
return $argument_validates;
|
75
|
}
|
76
|
|
77
|
// If the current user has the bypass permission, then we're done: return
|
78
|
// the validation status we got from the parent.
|
79
|
if (!empty($this->options['bypass_perm']) && user_access($this->options['bypass_perm'])) {
|
80
|
return $argument_validates;
|
81
|
}
|
82
|
|
83
|
// Otherwise, perform our additional check to enforce that the argument
|
84
|
// user ID is the current user.
|
85
|
// The parent method has stored the uid from the argument.
|
86
|
return ($this->argument->argument == $GLOBALS['user']->uid);
|
87
|
}
|
88
|
|
89
|
}
|