views_plugin_argument_default_user.inc

  1. 3.x modules/user/views_plugin_argument_default_user.inc
  2. 2.x modules/user/views_plugin_argument_default_user.inc

Contains the user from URL argument default plugin.

File

modules/user/views_plugin_argument_default_user.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Contains the user from URL argument default plugin.
  5. */
  6. /**
  7. * Default argument plugin to extract a user via menu_get_object
  8. */
  9. class views_plugin_argument_default_user extends views_plugin_argument_default {
  10. var $option_name = 'default_argument_user';
  11. function argument_form(&$form, &$form_state) {
  12. $form[$this->option_name] = array(
  13. '#type' => 'checkbox',
  14. '#title' => t('Also look for a node and use the node author'),
  15. '#default_value' => !empty($this->argument->options[$this->option_name]),
  16. '#process' => array('views_process_dependency'),
  17. '#dependency' => array(
  18. 'radio:options[default_action]' => array('default'),
  19. 'radio:options[default_argument_type]' => array($this->id)
  20. ),
  21. '#dependency_count' => 2,
  22. );
  23. }
  24. function get_argument() {
  25. foreach (range(1, 3) as $i) {
  26. $user = menu_get_object('user', $i);
  27. if (!empty($user)) {
  28. return $user->uid;
  29. }
  30. }
  31. foreach (range(1, 3) as $i) {
  32. $user = menu_get_object('user_uid_optional', $i);
  33. if (!empty($user)) {
  34. return $user->uid;
  35. }
  36. }
  37. if (!empty($this->argument->options[$this->option_name])) {
  38. foreach (range(1, 3) as $i) {
  39. $node = menu_get_object('node', $i);
  40. if (!empty($node)) {
  41. return $node->uid;
  42. }
  43. }
  44. }
  45. if (arg(0) == 'user' && is_numeric(arg(1))) {
  46. return arg(1);
  47. }
  48. if (!empty($this->argument->options[$this->option_name])) {
  49. if (arg(0) == 'node' && is_numeric(arg(1))) {
  50. $node = node_load(arg(1));
  51. if ($node) {
  52. return $node->uid;
  53. }
  54. }
  55. }
  56. // If the current page is a view that takes uid as an argument, return the uid.
  57. $views_page = views_get_page_view();
  58. if ($views_page && isset($views_page->view->argument['uid'])) {
  59. return $views_page->view->argument['uid']->argument;
  60. }
  61. }
  62. }