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