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. function option_definition() {
  11. $options = parent::option_definition();
  12. $options['user'] = array('default' => '', 'bool' => TRUE, 'translatable' => FALSE);
  13. return $options;
  14. }
  15. function options_form(&$form, &$form_state) {
  16. $form['user'] = array(
  17. '#type' => 'checkbox',
  18. '#title' => t('Also look for a node and use the node author'),
  19. '#default_value' => $this->options['user'],
  20. );
  21. }
  22. function convert_options(&$options) {
  23. if (!isset($options['user']) && isset($this->argument->options['default_argument_user'])) {
  24. $options['user'] = $this->argument->options['default_argument_user'];
  25. }
  26. }
  27. function get_argument() {
  28. foreach (range(1, 3) as $i) {
  29. $user = menu_get_object('user', $i);
  30. if (!empty($user)) {
  31. return $user->uid;
  32. }
  33. }
  34. foreach (range(1, 3) as $i) {
  35. $user = menu_get_object('user_uid_optional', $i);
  36. if (!empty($user)) {
  37. return $user->uid;
  38. }
  39. }
  40. if (!empty($this->options['user'])) {
  41. foreach (range(1, 3) as $i) {
  42. $node = menu_get_object('node', $i);
  43. if (!empty($node)) {
  44. return $node->uid;
  45. }
  46. }
  47. }
  48. if (arg(0) == 'user' && is_numeric(arg(1))) {
  49. return arg(1);
  50. }
  51. if (!empty($this->options['user'])) {
  52. if (arg(0) == 'node' && is_numeric(arg(1))) {
  53. $node = node_load(arg(1));
  54. if ($node) {
  55. return $node->uid;
  56. }
  57. }
  58. }
  59. // If the current page is a view that takes uid as an argument, return the uid.
  60. $view = views_get_page_view();
  61. if ($view && isset($view->argument['uid'])) {
  62. return $view->argument['uid']->argument;
  63. }
  64. }
  65. }