diff --git a/modules/node/views_plugin_argument_default_node.inc b/modules/node/views_plugin_argument_default_node.inc index 65fc0eb..2beca3f 100644 --- a/modules/node/views_plugin_argument_default_node.inc +++ b/modules/node/views_plugin_argument_default_node.inc @@ -12,15 +12,16 @@ */ 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..e4e134f 100644 --- a/modules/taxonomy/views_plugin_argument_default_taxonomy_tid.inc +++ b/modules/taxonomy/views_plugin_argument_default_taxonomy_tid.inc @@ -98,16 +98,17 @@ 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..ab91256 100644 --- a/modules/user/views_plugin_argument_default_user.inc +++ b/modules/user/views_plugin_argument_default_user.inc @@ -31,15 +31,16 @@ 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 +48,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..6d0a835 100644 --- a/plugins/views_plugin_argument_default.inc +++ b/plugins/views_plugin_argument_default.inc @@ -87,6 +87,53 @@ 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() { + global $base_url, $language; + // 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($base_url . '/', '', $_SERVER['HTTP_REFERER']); + if ($language){ + $r = language_url_split_prefix($path, array($language)); + if ($r && $r[0] && $r[1]) { + $path = $r[1]; + } + } + } + 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 (!empty($router_item['delivery_callback']) && $router_item['delivery_callback'] == 'ajax_deliver') { + $ajax = TRUE; + } + } + return $ajax; + } } /**