From a1c6d8b118c79c1adea198654c2f86094fd9b611 Mon Sep 17 00:00:00 2001
From: Tom Kirkpatrick <tom@systemseed.com>
Date: Sun, 4 Dec 2011 21:48:39 +0100
Subject: [PATCH 1/2] Allow path contexts to handle query string (by Kristen
 Pol)

---
 context.plugins.inc                        |   13 ++++++++++++
 plugins/context_condition_query_string.inc |   29 ++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+), 0 deletions(-)
 create mode 100644 plugins/context_condition_query_string.inc

diff --git a/context.plugins.inc b/context.plugins.inc
index 46dfac1..0dea24a 100644
--- a/context.plugins.inc
+++ b/context.plugins.inc
@@ -26,6 +26,11 @@ function _context_context_registry() {
       'description' => t('Set this context when any of the paths above match the page path. Put each path on a separate line. You can use the "*" character as a wildcard and <code>~</code> to exclude one or more paths. Use &lt;front&gt; for the site front page.'),
       'plugin' => 'context_condition_path',
     ),
+    'query_string' => array(
+      'title' => t('Query String'),
+      'description' => t('Set this context when any of the query strings above match the page query string. Put each query string on a separate line. You can use the "*" character as a wildcard and <code>~</code> to exclude one or more query strings.'),
+      'plugin' => 'context_condition_query_string',
+    ),
     'user' => array(
       'title' => t('User role'),
       'description' => t('Set this context when the current user has one of the selected role(s).'),
@@ -179,6 +184,14 @@ function _context_context_plugins() {
       'parent' => 'context_condition',
     ),
   );
+  $plugins['context_condition_query_string'] = array(
+    'handler' => array(
+      'path' => drupal_get_path('module', 'context') .'/plugins',
+      'file' => 'context_condition_query_string.inc',
+      'class' => 'context_condition_query_string',
+      'parent' => 'context_condition_path',
+    ),
+  );
   $plugins['context_condition_user'] = array(
     'handler' => array(
       'path' => drupal_get_path('module', 'context') . '/plugins',
diff --git a/plugins/context_condition_query_string.inc b/plugins/context_condition_query_string.inc
new file mode 100644
index 0000000..ac4ad0c
--- /dev/null
+++ b/plugins/context_condition_query_string.inc
@@ -0,0 +1,29 @@
+<?php
+// $Id: context_condition_query_string.inc,v 1.1.2.6 2010/07/30 14:39:06 yhahn Exp $
+
+/**
+ * @file context_condition_query_string.inc
+ *
+ * Similar to context_condition_path but for entire query string.
+ */
+
+/**
+ * Expose query strings as a context condition.
+ */
+class context_condition_query_string extends context_condition_path {
+
+  /**
+   * Execute.
+   */
+  function execute() {
+    if ($this->condition_used()) {
+      $current_query_string = $_SERVER["QUERY_STRING"];
+      foreach ($this->get_contexts() as $context) {
+        $query_strings = $this->fetch_from_context($context, 'values');
+        if ($this->match($current_query_string, $query_strings, TRUE)) {
+          $this->condition_met($context);
+        }
+      }
+    }
+  }
+}
-- 
1.7.4.4


From e00609d5c634fde23cf785ca053ecb2ad6a69134 Mon Sep 17 00:00:00 2001
From: Tom Kirkpatrick <tom@systemseed.com>
Date: Sun, 4 Dec 2011 21:50:25 +0100
Subject: [PATCH 2/2] Ensure that query_string condition is fired correctly
 (Thanks NaX)

---
 context.module |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/context.module b/context.module
index 613cf98..e634626 100644
--- a/context.module
+++ b/context.module
@@ -168,6 +168,9 @@ function context_init() {
   if ($plugin = context_get_plugin('condition', 'path')) {
     $plugin->execute();
   }
+  if ($plugin = context_get_plugin('condition', 'query_string')) {
+    $plugin->execute();
+  }
   if ($plugin = context_get_plugin('condition', 'language')) {
     global $language;
     $plugin->execute($language->language);
-- 
1.7.4.4

