From 121516b1eb4e51e304ebfc23c2f68150ac09785c Mon Sep 17 00:00:00 2001
From: Tim Plunkett <git@plnktt.com>
Date: Tue, 15 May 2012 11:10:47 -0400
Subject: [PATCH] Replace $_GET[q] with current_path().

---
 includes/admin.inc                              | 17 +++++++++--------
 includes/ajax.inc                               |  6 +++---
 plugins/export_ui/views_ui.class.php            |  2 +-
 plugins/views_plugin_style_jump_menu.inc        |  4 ++--
 .../views_plugin_style_summary_jump_menu.inc    |  2 +-
 theme/theme.inc                                 | 12 ++++++------
 views.module                                    |  2 +-
 7 files changed, 23 insertions(+), 22 deletions(-)

diff --git a/includes/admin.inc b/includes/admin.inc
index d637181ba506..2c1de2e95ab0 100644
--- a/includes/admin.inc
+++ b/includes/admin.inc
@@ -109,8 +109,8 @@ function views_ui_preview($view, $display_id, $args = array()) {
     $args = array_slice(func_get_args(), 2);
   }
 
-  // Save $_GET['q'] so it can be restored before returning from this function.
-  $q = $_GET['q'];
+  // Save the current path so it can be restored before returning from this function.
+  $old_q = current_path();
 
   // Determine where the query and performance statistics should be output.
   $show_query = variable_get('views_ui_show_sql_query', FALSE);
@@ -161,11 +161,12 @@ function views_ui_preview($view, $display_id, $args = array()) {
     // Make view links come back to preview.
     $view->override_path = 'admin/structure/views/nojs/preview/' . $view->name . '/' . $display_id;
 
-    // Also override $_GET['q'] so we get the pager.
+    // Also override the current path so we get the pager.
     $original_path = current_path();
-    $_GET['q'] = $view->override_path;
+    $q = _current_path($view->override_path);
     if ($args) {
-      $_GET['q'] .= '/' . implode('/', $args);
+      $q .= '/' . implode('/', $args);
+      _current_path($q);
     }
 
     // Suppress contextual links of entities within the result set during a
@@ -178,7 +179,7 @@ function views_ui_preview($view, $display_id, $args = array()) {
 
     // Reset variables.
     unset($view->override_path);
-    $_GET['q'] = $original_path;
+    _current_path($original_path);
 
     // Prepare the query information and statistics to show either above or
     // below the view preview.
@@ -281,7 +282,7 @@ function views_ui_preview($view, $display_id, $args = array()) {
     $output .= '<div class="views-query-info">' . theme('table', array('rows' => $rows['statistics'])) . '</div>';
   }
 
-  $_GET['q'] = $q;
+  _current_path($old_q);
   return $output;
 }
 
@@ -1440,7 +1441,7 @@ function views_ui_edit_form_submit_preview($form, &$form_state) {
 function views_ui_edit_form_submit_delay_destination($form, &$form_state) {
   if (isset($_GET['destination']) && $form_state['redirect'] !== FALSE) {
     if (!isset($form_state['redirect'])) {
-      $form_state['redirect'] = $_GET['q'];
+      $form_state['redirect'] = current_path();
     }
     if (is_string($form_state['redirect'])) {
       $form_state['redirect'] = array($form_state['redirect']);
diff --git a/includes/ajax.inc b/includes/ajax.inc
index a71785d07061..e5904cfda36c 100644
--- a/includes/ajax.inc
+++ b/includes/ajax.inc
@@ -41,9 +41,9 @@ function views_ajax() {
     // Load the view.
     $view = views_get_view($name);
     if ($view && $view->access($display_id)) {
-      // Fix 'q' for paging.
+      // Fix the current path for paging.
       if (!empty($path)) {
-        $_GET['q'] = $path;
+        _current_path($path);
       }
 
       // Add all $_POST data, because AJAX is always a post and many things,
@@ -261,7 +261,7 @@ function views_ajax_form_wrapper($form_id, &$form_state) {
       }
     }
 
-    $url = empty($form_state['url']) ? url($_GET['q'], array('absolute' => TRUE)) : $form_state['url'];
+    $url = empty($form_state['url']) ? url(current_path(), array('absolute' => TRUE)) : $form_state['url'];
 
     $commands[] = views_ajax_command_set_form($display, $title, $url);
 
diff --git a/plugins/export_ui/views_ui.class.php b/plugins/export_ui/views_ui.class.php
index 22b65cb028f1..4938248cbbee 100644
--- a/plugins/export_ui/views_ui.class.php
+++ b/plugins/export_ui/views_ui.class.php
@@ -298,7 +298,7 @@ function tablesort_link($label, $field, $class) {
       'attributes' => array('title' => $title),
       'query' => $query,
     );
-    $link = l($label, $_GET['q'], $link_options);
+    $link = l($label, current_path(), $link_options);
     if ($this->active == $field) {
       $class .= ' active';
     }
diff --git a/plugins/views_plugin_style_jump_menu.inc b/plugins/views_plugin_style_jump_menu.inc
index f571f6225751..94612aaad385 100644
--- a/plugins/views_plugin_style_jump_menu.inc
+++ b/plugins/views_plugin_style_jump_menu.inc
@@ -127,8 +127,8 @@ function render() {
     unset($this->view->row_index);
 
     $default_value = '';
-    if ($this->options['default_value'] && !empty($paths[url($_GET['q'])])) {
-      $default_value = $paths[url($_GET['q'])];
+    if ($this->options['default_value'] && !empty($paths[url(current_path())])) {
+      $default_value = $paths[url(current_path())];
     }
 
     ctools_include('jump-menu');
diff --git a/plugins/views_plugin_style_summary_jump_menu.inc b/plugins/views_plugin_style_summary_jump_menu.inc
index 5b02163d85b7..be46db72847e 100644
--- a/plugins/views_plugin_style_summary_jump_menu.inc
+++ b/plugins/views_plugin_style_summary_jump_menu.inc
@@ -110,7 +110,7 @@ function render() {
       if (!empty($this->options['count'])) {
         $options[$key] .= ' (' . intval($row->{$argument->count_alias}) . ')';
       }
-      if ($this->options['default_value'] && $_GET['q'] == $this->view->get_url($args)) {
+      if ($this->options['default_value'] && current_path() == $this->view->get_url($args)) {
         $default_value = $key;
       }
     }
diff --git a/theme/theme.inc b/theme/theme.inc
index 5cda7d9a096d..333b9ff8e79e 100644
--- a/theme/theme.inc
+++ b/theme/theme.inc
@@ -125,7 +125,7 @@ function template_preprocess_views_view(&$vars) {
             'view_name' => $view->name,
             'view_display_id' => $view->current_display,
             'view_args' => check_plain(implode('/', $view->args)),
-            'view_path' => check_plain($_GET['q']),
+            'view_path' => check_plain(current_path()),
             // Pass through URL to ensure we get e.g. language prefixes.
 //            'view_base_path' => isset($view->display['page']) ? substr(url($view->display['page']->display_options['path']), strlen($base_path)) : '',
             'view_base_path' => $view->get_path(),
@@ -367,8 +367,8 @@ function template_preprocess_views_view_summary(&$vars) {
   }
 
   $active_urls = drupal_map_assoc(array(
-    url($_GET['q'], array('alias' => TRUE)), // force system path
-    url($_GET['q']), // could be an alias
+    url(current_path(), array('alias' => TRUE)), // force system path
+    url(current_path()), // could be an alias
   ));
 
   // Collect all arguments foreach row, to be able to alter them for example by the validator.
@@ -416,8 +416,8 @@ function template_preprocess_views_view_summary_unformatted(&$vars) {
 
   $count = 0;
   $active_urls = drupal_map_assoc(array(
-    url($_GET['q'], array('alias' => TRUE)), // force system path
-    url($_GET['q']), // could be an alias
+    url(current_path(), array('alias' => TRUE)), // force system path
+    url(current_path()), // could be an alias
   ));
 
   // Collect all arguments foreach row, to be able to alter them for example by the validator.
@@ -519,7 +519,7 @@ function template_preprocess_views_view_table(&$vars) {
           'attributes' => array('title' => $title),
           'query' => $query,
         );
-        $vars['header'][$field] = l($label, $_GET['q'], $link_options);
+        $vars['header'][$field] = l($label, current_path(), $link_options);
       }
 
       $vars['header_classes'][$field] = '';
diff --git a/views.module b/views.module
index cceebc70017d..ca024cef1b96 100644
--- a/views.module
+++ b/views.module
@@ -1697,7 +1697,7 @@ function views_form($form, &$form_state, $view, $output) {
   $form_state['cache'] = TRUE;
 
   $form = array();
-  $query = drupal_get_query_parameters($_GET, array('q'));
+  $query = drupal_get_query_parameters();
   $form['#action'] = url($view->get_url(), array('query' => $query));
   // Tell the preprocessor whether it should hide the header, footer, pager...
   $form['show_view_elements'] = array(
-- 
GitLab