1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Definition of views_plugin_argument_default_user.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Default argument plugin to extract a user via menu_get_object.
|
10
|
*/
|
11
|
class views_plugin_argument_default_user extends views_plugin_argument_default {
|
12
|
|
13
|
/**
|
14
|
* {@inheritdoc}
|
15
|
*/
|
16
|
public function option_definition() {
|
17
|
$options = parent::option_definition();
|
18
|
$options['user'] = array('default' => '', 'bool' => TRUE, 'translatable' => FALSE);
|
19
|
|
20
|
return $options;
|
21
|
}
|
22
|
|
23
|
/**
|
24
|
* {@inheritdoc}
|
25
|
*/
|
26
|
public function options_form(&$form, &$form_state) {
|
27
|
$form['user'] = array(
|
28
|
'#type' => 'checkbox',
|
29
|
'#title' => t('Also look for a node and use the node author'),
|
30
|
'#default_value' => $this->options['user'],
|
31
|
);
|
32
|
}
|
33
|
|
34
|
/**
|
35
|
* {@inheritdoc}
|
36
|
*/
|
37
|
public function convert_options(&$options) {
|
38
|
if (!isset($options['user']) && isset($this->argument->options['default_argument_user'])) {
|
39
|
$options['user'] = $this->argument->options['default_argument_user'];
|
40
|
}
|
41
|
}
|
42
|
|
43
|
/**
|
44
|
* {@inheritdoc}
|
45
|
*/
|
46
|
public function get_argument() {
|
47
|
foreach (range(1, 3) as $i) {
|
48
|
$user = menu_get_object('user', $i);
|
49
|
if (!empty($user)) {
|
50
|
return $user->uid;
|
51
|
}
|
52
|
}
|
53
|
|
54
|
foreach (range(1, 3) as $i) {
|
55
|
$user = menu_get_object('user_uid_optional', $i);
|
56
|
if (!empty($user)) {
|
57
|
return $user->uid;
|
58
|
}
|
59
|
}
|
60
|
|
61
|
if (!empty($this->options['user'])) {
|
62
|
foreach (range(1, 3) as $i) {
|
63
|
$node = menu_get_object('node', $i);
|
64
|
if (!empty($node)) {
|
65
|
return $node->uid;
|
66
|
}
|
67
|
}
|
68
|
}
|
69
|
|
70
|
if (arg(0) == 'user' && is_numeric(arg(1))) {
|
71
|
return arg(1);
|
72
|
}
|
73
|
|
74
|
if (!empty($this->options['user'])) {
|
75
|
if (arg(0) == 'node' && is_numeric(arg(1))) {
|
76
|
$node = node_load(arg(1));
|
77
|
if ($node) {
|
78
|
return $node->uid;
|
79
|
}
|
80
|
}
|
81
|
}
|
82
|
|
83
|
// If the current page is a view that takes uid as an argument, return the
|
84
|
// uid.
|
85
|
$view = views_get_page_view();
|
86
|
|
87
|
if ($view && isset($view->argument['uid'])) {
|
88
|
return $view->argument['uid']->argument;
|
89
|
}
|
90
|
}
|
91
|
|
92
|
}
|