diff --git a/modules/node/views_plugin_argument_default_node.inc b/modules/node/views_plugin_argument_default_node.inc index 65fc0eb..73bc105 100644 --- a/modules/node/views_plugin_argument_default_node.inc +++ b/modules/node/views_plugin_argument_default_node.inc @@ -8,19 +8,23 @@ /** * Default argument plugin to extract a node via menu_get_object * - * This plugin actually has no options so it odes not need to do a great deal. + * This plugin actually has no options so it does not need to do a great deal. */ class views_plugin_argument_default_node extends views_plugin_argument_default { + function get_argument() { + + $path = $this->get_path(); + foreach (range(1, 3) as $i) { - $node = menu_get_object('node', $i); + $node = menu_get_object('node', $i, $path); if (!empty($node)) { return $node->nid; } } - if (arg(0) == 'node' && is_numeric(arg(1))) { - return arg(1); + if (arg(0, $path) == 'node' && is_numeric(arg(1, $path))) { + return arg(1, $path); } } } diff --git a/modules/taxonomy/views_plugin_argument_default_taxonomy_tid.inc b/modules/taxonomy/views_plugin_argument_default_taxonomy_tid.inc index 9c1d81f..7b9c1ea 100644 --- a/modules/taxonomy/views_plugin_argument_default_taxonomy_tid.inc +++ b/modules/taxonomy/views_plugin_argument_default_taxonomy_tid.inc @@ -98,16 +98,19 @@ class views_plugin_argument_default_taxonomy_tid extends views_plugin_argument_d } function get_argument() { + + $path = $this->get_path(); + // Load default argument from taxonomy page. if (!empty($this->options['term_page'])) { - if (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2))) { - return arg(2); + if (arg(0, $path) == 'taxonomy' && arg(1, $path) == 'term' && is_numeric(arg(2, $path))) { + return arg(2, $path); } } // Load default argument from node. if (!empty($this->options['node'])) { foreach (range(1, 3) as $i) { - $node = menu_get_object('node', $i); + $node = menu_get_object('node', $i, $path); if (!empty($node)) { break; } diff --git a/modules/user/views_plugin_argument_default_user.inc b/modules/user/views_plugin_argument_default_user.inc index bb10429..6b7dabd 100644 --- a/modules/user/views_plugin_argument_default_user.inc +++ b/modules/user/views_plugin_argument_default_user.inc @@ -31,15 +31,18 @@ class views_plugin_argument_default_user extends views_plugin_argument_default { } function get_argument() { + + $path = $this->get_path(); + foreach (range(1, 3) as $i) { - $user = menu_get_object('user', $i); + $user = menu_get_object('user', $i, $path); if (!empty($user)) { return $user->uid; } } foreach (range(1, 3) as $i) { - $user = menu_get_object('user_uid_optional', $i); + $user = menu_get_object('user_uid_optional', $i, $path); if (!empty($user)) { return $user->uid; } @@ -47,20 +50,20 @@ class views_plugin_argument_default_user extends views_plugin_argument_default { if (!empty($this->options['user'])) { foreach (range(1, 3) as $i) { - $node = menu_get_object('node', $i); + $node = menu_get_object('node', $i, $path); if (!empty($node)) { return $node->uid; } } } - if (arg(0) == 'user' && is_numeric(arg(1))) { - return arg(1); + if (arg(0, $path) == 'user' && is_numeric(arg(1, $path))) { + return arg(1, $path); } if (!empty($this->options['user'])) { - if (arg(0) == 'node' && is_numeric(arg(1))) { - $node = node_load(arg(1)); + if (arg(0, $path) == 'node' && is_numeric(arg(1, $path))) { + $node = node_load(arg(1, $path)); if ($node) { return $node->uid; } diff --git a/plugins/views_plugin_argument_default.inc b/plugins/views_plugin_argument_default.inc index 2b87730..51bbdf6 100644 --- a/plugins/views_plugin_argument_default.inc +++ b/plugins/views_plugin_argument_default.inc @@ -87,6 +87,48 @@ class views_plugin_argument_default extends views_plugin { * views_plugin_argument_default_fixed for a good example of this method. */ function convert_options(&$options) { } + + /** + * Get the current path. + * + * This takes ajax calls into account where the path from the referrer is + * used. + * + * @return string + */ + protected function get_path() { + // In case of ajax requests we want the path of the referring page. + if ($this->is_ajax() && !empty($_SERVER['HTTP_REFERER'])) { + // Get a relative path. + $path = str_replace($GLOBALS['base_url'] . '/', '', $_SERVER['HTTP_REFERER']); + } + else { + $path = current_path(); + } + return $path; + } + + /** + * Guess if the current request was done through ajax. + * + * @return bool + */ + protected function is_ajax() { + $ajax = false; + // jQuery sets a header we can check. + if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') { + $ajax = true; + } + else { + // Module ajax callbacks have an ajax delivery callback. + $router_item = menu_get_item(); + if ($router_item['delivery callback'] == 'ajax_deliver') { + $ajax = TRUE; + } + } + return $ajax; + } + } /**