--- views.info	2 Nov 2009 22:01:25 -0000	1.7.6.1
+++ views.info	13 Nov 2009 13:39:42 -0000
@@ -191,6 +191,10 @@ files[] = plugins/views_plugin_display_b
 files[] = plugins/views_plugin_display_default.inc
 files[] = plugins/views_plugin_display_feed.inc
 files[] = plugins/views_plugin_display_page.inc
+files[] = plugins/views_plugin_exposed_form_basic.inc
+files[] = plugins/views_plugin_exposed_form.inc
+files[] = plugins/views_plugin_exposed_form_input_required.inc
+files[] = plugins/views_plugin_exposed_form_on_demand.inc
 files[] = plugins/views_plugin_query.inc
 files[] = plugins/views_plugin_query_default.inc
 files[] = plugins/views_plugin_row.inc
Index: views.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/views/views.module,v
retrieving revision 1.341.4.2
diff -u -p -r1.341.4.2 views.module
--- views.module	3 Nov 2009 08:33:16 -0000	1.341.4.2
+++ views.module	13 Nov 2009 13:39:43 -0000
@@ -996,7 +996,7 @@ function views_exposed_form_submit(&$for
   $form_state['view']->exposed_raw_input = array();
 
   foreach ($form_state['values'] as $key => $value) {
-    if (!in_array($key, array('q', 'submit', 'form_build_id', 'form_id', 'form_token', ''))) {
+    if (!in_array($key, array('q', 'submit', 'form_build_id', 'form_id', 'form_token', 'submit_button', ''))) {
       $form_state['view']->exposed_raw_input[$key] = $value;
     }
   }
Index: includes/plugins.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/views/includes/plugins.inc,v
retrieving revision 1.156.4.1
diff -u -p -r1.156.4.1 plugins.inc
--- includes/plugins.inc	2 Nov 2009 22:01:26 -0000	1.156.4.1
+++ includes/plugins.inc	13 Nov 2009 13:39:45 -0000
@@ -233,6 +233,27 @@ function views_views_plugins() {
         'help topic' => 'cache-time',
       ),
     ),
+    'exposed_form' => array(
+      'parent' => array(
+        'no ui' => TRUE,
+        'handler' => 'views_plugin_exposed_form',
+        'parent' => '',
+      ),
+      'basic' => array(
+        'title' => t('Basic'),
+        'help' => t('Basic exposed form'),
+        'handler' => 'views_plugin_exposed_form_basic',
+        'uses options' => TRUE,
+        'help topic' => 'exposed-form-basic',
+      ),
+      'input_required' => array(
+        'title' => t('Input required'),
+        'help' => t('An exposed form that only renders a view if the form contains user input.'),
+        'handler' => 'views_plugin_exposed_form_input_required',
+        'uses options' => TRUE,
+        'help topic' => 'exposed-form-input-required',
+      ),
+    ),
   );
 }
 
@@ -242,7 +263,7 @@ function views_views_plugins() {
  * @return Nested array of plugins, grouped by type.
  */
 function views_discover_plugins() {
-  $cache = array('display' => array(), 'style' => array(), 'row' => array(), 'argument default' => array(), 'argument validator' => array(), 'access' => array(), 'cache' => array());
+  $cache = array('display' => array(), 'style' => array(), 'row' => array(), 'argument default' => array(), 'argument validator' => array(), 'access' => array(), 'cache' => array(), 'exposed_form' => array());
   // Get plugins from all mdoules.
   foreach (module_implements('views_plugins') as $module) {
     $function = $module . '_views_plugins';
Index: includes/view.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/views/includes/view.inc,v
retrieving revision 1.167.4.2
diff -u -p -r1.167.4.2 view.inc
--- includes/view.inc	9 Nov 2009 22:38:07 -0000	1.167.4.2
+++ includes/view.inc	13 Nov 2009 13:39:47 -0000
@@ -399,7 +399,7 @@ class view extends views_db_object {
       'no_redirect' => TRUE,
       'build_info' => array(
         'args' => array(),
-    ),
+      ),
     );
 
     // Some types of displays (eg. attachments) may wish to use the exposed
@@ -587,7 +587,8 @@ class view extends views_db_object {
     $this->_pre_query();
 
     if ($this->display_handler->uses_exposed()) {
-      $this->exposed_widgets = $this->render_exposed_form();
+      $exposed_form = $this->display_handler->get_exposed_form_plugin();
+      $this->exposed_widgets = $exposed_form->render_exposed_form();
       if (form_set_error() || !empty($this->build_info['abort'])) {
         $this->built = TRUE;
         return empty($this->build_info['fail']);
@@ -637,6 +638,11 @@ class view extends views_db_object {
     // Allow style handler to affect the query:
     $this->style_plugin->query();
 
+    // Allow exposed form to affect the query:
+    if (isset($exposed_form)) {
+      $exposed_form->query();
+    }
+
     if (variable_get('views_sql_signature', FALSE)) {
       $this->query->add_signature($this);
     }
@@ -644,8 +650,11 @@ class view extends views_db_object {
     // Let modules modify the query just prior to finalizing it.
     $this->query->alter($this);
 
-    // Build the necessary info to execute the query.
-    $this->query->build($this);
+    // Only build the query if we weren't interrupted.
+    if (empty($this->built)) {
+      // Build the necessary info to execute the query.
+      $this->query->build($this);
+    }
 
     $this->built = TRUE;
     $this->build_time = microtime(TRUE) - $start;
@@ -734,6 +743,9 @@ class view extends views_db_object {
       $this->start_query_capture();
     }
 
+    $exposed_form = $this->display_handler->get_exposed_form_plugin();
+    $exposed_form->pre_render();
+
     // Check for already-cached output.
     if (!empty($this->live_preview)) {
       $cache = FALSE;
@@ -781,6 +793,8 @@ class view extends views_db_object {
       }
     }
 
+    $exposed_form->post_render($this->display_handler->output);
+
     if ($cache) {
       $cache->post_render($this->display_handler->output);
     }
Index: plugins/views_plugin_display.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/views/plugins/views_plugin_display.inc,v
retrieving revision 1.27.4.4
diff -u -p -r1.27.4.4 views_plugin_display.inc
--- plugins/views_plugin_display.inc	2 Nov 2009 23:57:54 -0000	1.27.4.4
+++ plugins/views_plugin_display.inc	13 Nov 2009 13:39:52 -0000
@@ -180,6 +180,7 @@ class views_plugin_display extends views
       'link_display' => array('link_display'),
       'distinct' => array('distinct'),
       'exposed_block' => array('exposed_block'),
+      'exposed_form' => array('exposed_form'),
 
       // Force these to cascade properly.
       'style_plugin' => array('style_plugin', 'style_options', 'row_plugin', 'row_options'),
@@ -254,6 +255,7 @@ class views_plugin_display extends views
           'use_more_text' => TRUE,
           'distinct' => TRUE,
           'exposed_block' => TRUE,
+          'exposed_form' => TRUE,
 
           'link_display' => TRUE,
 
@@ -378,6 +380,12 @@ class views_plugin_display extends views
       'exposed_block' => array(
         'default' => FALSE,
       ),
+      'exposed_form' => array(
+        'contains' => array(
+          'type' => array('default' => 'basic'),
+          'options' => array('default' => array()),
+         ),
+      ),
     );
 
     if ($this->is_default_display()) {
@@ -534,6 +542,22 @@ class views_plugin_display extends views
   }
 
   /**
+   * Get the exposed form plugin
+   */
+  function get_exposed_form_plugin($name = NULL) {
+    if (!$name) {
+      $exposed_form = $this->get_option('exposed_form');
+      $name = $exposed_form['type'];
+    }
+
+    $plugin = views_get_plugin('exposed_form', $name);
+    if ($plugin) {
+      $plugin->init($this->view, $this->display);
+      return $plugin;
+    }
+  }
+
+  /**
    * Get the handler object for a single handler.
    */
   function &get_handler($type, $id) {
@@ -801,6 +825,25 @@ class views_plugin_display extends views
       'desc' => t('Allow the exposed form to appear in a block instead of the view.'),
     );
 
+    $exposed_form_plugin = $this->get_exposed_form_plugin();
+    if (!$exposed_form_plugin) {
+      // default to the no cache control plugin.
+      $exposed_form_plugin = views_get_plugin('exposed_form', 'basic');
+    }
+
+    $exposed_form_str = $exposed_form_plugin->summary_title();
+
+    $options['exposed_form'] = array(
+      'category' => 'exposed',
+      'title' => t('Exposed form style'),
+      'value' => $exposed_form_str,
+      'desc' => t('Select the kind of exposed filter to use.'),
+    );
+
+    if (!empty($exposed_form_plugin->definition['uses options'])) {
+      $options['exposed_form']['links']['exposed_form_options'] = t('Exposed form settings for this exposed form style.');
+    }
+
     foreach (array('header' => t('Header'), 'footer' => t('Footer'), 'empty' => t('Empty text')) as $type => $name) {
       if (!$this->get_option($type)) {
         $field = t('None');
@@ -1353,6 +1396,43 @@ class views_plugin_display extends views
           '#default_value' => $this->get_option('exposed_block') ? 1 : 0,
         );
         break;
+      case 'exposed_form':
+        $form['#title'] .= t('Exposed Form');
+        $form['exposed_form'] = array(
+          '#prefix' => '<div class="clear-block">',
+          '#suffix' => '</div>',
+          '#tree' => TRUE,
+        );
+
+        $exposed_form = $this->get_option('exposed_form');
+        $form['exposed_form']['type'] =  array(
+          '#type' => 'radios',
+          '#options' => views_fetch_plugin_names('exposed_form'),
+          '#default_value' => $exposed_form['type'],
+        );
+
+        $exposed_form_plugin = views_fetch_plugin_data('exposed_form', $exposed_form['type']);
+        if (!empty($exposed_form_plugin['uses options'])) {
+          $form['markup'] = array(
+            '#prefix' => '<div class="form-item description">',
+            '#suffix' => '</div>',
+            '#value' => t('You may also adjust the !settings for the currently selected style by clicking on the icon.', array('!settings' => $this->option_link(t('settings'), 'exposed_form_options'))),
+          );
+        }
+        break;
+      case 'exposed_form_options':
+        $exposed_form = $this->get_option('exposed_form');
+        $plugin = $this->get_exposed_form_plugin();
+        $form['#title'] .= t('Exposed form options');
+        if ($plugin) {
+          $form['#help_topic'] = $plugin->definition['help topic'];
+
+          $form['exposed_form_options'] = array(
+            '#tree' => TRUE,
+          );
+          $plugin->options_form($form['exposed_form_options'], $form_state);
+        }
+        break;
     }
   }
 
@@ -1419,6 +1499,12 @@ class views_plugin_display extends views
           $plugin->options_validate($form['cache_options'], $form_state);
         }
         break;
+      case 'exposed_form_options':
+        $plugin = $this->get_exposed_form_plugin();
+        if ($plugin) {
+          $plugin->options_validate($form['exposed_form_options'], $form_state);
+        }
+        break;
     }
   }
 
@@ -1557,6 +1643,29 @@ class views_plugin_display extends views
       case 'exposed_block':
         $this->set_option($section, (bool) $form_state['values'][$section]);
         break;
+      case 'exposed_form':
+        $exposed_form = $this->get_option('exposed_form');
+        if ($exposed_form['type'] != $form_state['values']['exposed_form']['type']) {
+          $plugin = views_get_plugin('exposed_form', $form_state['values']['exposed_form']['type']);
+          if ($plugin) {
+            $exposed_form = array('type' => $form_state['values']['exposed_form']['type'], 'options' => array());
+            $this->set_option('exposed_form', $exposed_form);
+            if (!empty($plugin->definition['uses options'])) {
+              views_ui_add_form_to_stack('display', $this->view, $this->display->id, array('exposed_form_options'));
+            }
+          }
+        }
+
+        break;
+      case 'exposed_form_options':
+        $plugin = $this->get_exposed_form_plugin();
+        if ($plugin) {
+          $exposed_form = $this->get_option('exposed_form');
+          $plugin->options_submit($form['exposed_form_options'], $form_state);
+          $exposed_form['options'] = $form_state['values'][$section];
+          $this->set_option('exposed_form', $exposed_form);
+        }
+        break;
     }
   }
 
Index: plugins/views_plugin_exposed_form.inc
===================================================================
RCS file: plugins/views_plugin_exposed_form.inc
diff -N plugins/views_plugin_exposed_form.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ plugins/views_plugin_exposed_form.inc	13 Nov 2009 13:39:52 -0000
@@ -0,0 +1,97 @@
+<?php
+// $Id: views_plugin_exposed_form.inc,v 1.1.2.1 2009-11-11 01:42:53 merlinofchaos Exp $
+
+/**
+ * The base plugin to handle exposed filter forms.
+ */
+class views_plugin_exposed_form extends views_plugin {
+
+  /**
+   * Initialize the plugin.
+   *
+   * @param $view
+   *   The view object.
+   * @param $display
+   *   The display handler.
+   */
+  function init(&$view, &$display) {
+    $this->view = &$view;
+    $this->display = &$display;
+
+    $exposed_form = $display->handler->get_option('exposed_form');
+    $this->unpack_options($this->options, $exposed_form['options']);
+  }
+
+  /**
+   * Return a string to display as the clickable title for the
+   * control.
+   */
+  function summary_title() {
+    return t('Unknown');
+  }
+
+  function option_definition() {
+    $options = parent::option_definition();
+    $options['submit_button'] = array('default' => t('Apply'), 'translatable' => TRUE);
+    return $options;
+  }
+
+  function options_form(&$form, &$form_state) {
+    $form['submit_button'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Submit button text'),
+      '#description' => t('Text to display in the submit button of the exposed form.'),
+      '#default_value' => $this->options['submit_button'],
+    );
+  }
+
+  /**
+   * Render the exposed filter form.
+   *
+   * This actually does more than that; because it's using FAPI, the form will
+   * also assign data to the appropriate handlers for use in building the
+   * query.
+   */
+  function render_exposed_form($block = FALSE) {
+    // Deal with any exposed filters we may have, before building.
+    $form_state = array(
+      'view' => &$this->view,
+      'display' => &$this->display,
+      'method' => 'get',
+      'rerender' => TRUE,
+      'no_redirect' => TRUE,
+      'submit_button' => $this->options['submit_button'],
+      'build_info' => array(
+        'args' => array(),
+      ),
+    );
+
+    // Some types of displays (eg. attachments) may wish to use the exposed
+    // filters of their parent displays instead of showing an additional
+    // exposed filter form for the attachment as well as that for the parent.
+    if (!$this->view->display_handler->displays_exposed() || (!$block && $this->view->display_handler->get_option('exposed_block'))) {
+      unset($form_state['rerender']);
+    }
+
+    if (!empty($this->ajax)) {
+      $form_state['ajax'] = TRUE;
+    }
+
+    $output = drupal_render(drupal_build_form('views_exposed_form', $form_state));
+    if (!empty($form_state['js settings'])) {
+      $this->view->js_settings = $form_state['js settings'];
+    }
+
+    return $output;
+  }
+
+  function query() { }
+
+  function pre_render() { }
+
+  function post_render(&$output) { }
+
+  function pre_execute() { }
+
+  function post_execute() { }
+}
Index: plugins/views_plugin_exposed_form_basic.inc
===================================================================
RCS file: plugins/views_plugin_exposed_form_basic.inc
diff -N plugins/views_plugin_exposed_form_basic.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ plugins/views_plugin_exposed_form_basic.inc	13 Nov 2009 13:39:52 -0000
@@ -0,0 +1,13 @@
+<?php
+// $Id: views_plugin_exposed_form_basic.inc,v 1.1.2.1 2009-11-11 01:42:53 merlinofchaos Exp $
+
+/**
+ * Exposed form plugin that provides basic exposed form
+ */
+class views_plugin_exposed_form_basic extends views_plugin_exposed_form {
+
+  function summary_title() {
+    return t('Basic');
+  }
+
+}
Index: plugins/views_plugin_exposed_form_input_required.inc
===================================================================
RCS file: plugins/views_plugin_exposed_form_input_required.inc
diff -N plugins/views_plugin_exposed_form_input_required.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ plugins/views_plugin_exposed_form_input_required.inc	13 Nov 2009 13:39:52 -0000
@@ -0,0 +1,78 @@
+<?php
+// $Id: views_plugin_exposed_form_input_required.inc,v 1.1.2.1 2009-11-11 01:42:53 merlinofchaos Exp $
+
+/**
+ * Exposed form plugin that provides basic exposed form
+ */
+class views_plugin_exposed_form_input_required extends views_plugin_exposed_form {
+
+  function summary_title() {
+    return t('Input required');
+  }
+
+  function option_definition() {
+    $options = parent::option_definition();
+
+    $options['text_input_required'] = array('default' => t('Select any filter and click on Apply to see results'), 'translatable' => TRUE);
+    $options['text_input_required_format'] = array('default' => FILTER_FORMAT_DEFAULT);
+    return $options;
+  }
+
+  function options_form(&$form, &$form_state) {
+    parent::options_form($form, $form_state);
+
+    $form['text_input_required'] = array(
+      '#type' => 'textarea',
+      '#title' => t('Text on demand'),
+      '#description' => t('Text to display instead results until user select and apply an expose filter.'),
+      '#default_value' => $this->options['text_input_required'],
+    );
+
+    $form['text_input_required_format'] = filter_form($this->options['text_input_required_format'], NULL, array('text_input_required_format'));
+  }
+
+  function options_submit(&$form, &$form_state) {
+    $form_state['values']['exposed_form_options']['text_input_required_format'] = $form_state['values']['text_input_required_format'];
+
+    parent::options_submit($form, $form_state);
+  }
+
+  function exposed_filter_applied() {
+    static $cache = NULL;
+    if (!isset($cache)) {
+      $view = $this->view;
+      $exposed_data = $view->exposed_data;
+      if (is_array($view->filter) && count($view->filter)) {
+        foreach ($view->filter as $filter_id => $filter) {
+          if ($filter->is_exposed()) {
+            $identifier = $filter->options['expose']['identifier'];
+            if (isset($view->exposed_input[$identifier])) {
+              $cache = TRUE;
+              return $cache;
+            }
+          }
+        }
+      }
+      $cache = FALSE;
+    }
+
+    return $cache;
+  }
+
+  function pre_render() {
+    if (!$this->exposed_filter_applied()) {
+      $this->view->display_handler->set_option('empty', $this->options['text_input_required']);
+      $this->view->display_handler->set_option('empty_format', $this->options['text_input_required_format']);
+    }
+  }
+
+  function query() {
+    if (!$this->exposed_filter_applied()) {
+      // We return with no query; this will force the empty text.
+      $this->view->built = TRUE;
+      $this->view->executed = TRUE;
+      $this->view->result = array();
+    }
+  }
+
+}
Index: plugins/views_plugin_exposed_form_on_demand.inc
===================================================================
RCS file: plugins/views_plugin_exposed_form_on_demand.inc
diff -N plugins/views_plugin_exposed_form_on_demand.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ plugins/views_plugin_exposed_form_on_demand.inc	13 Nov 2009 13:39:52 -0000
@@ -0,0 +1,71 @@
+<?php
+// $Id: views_plugin_exposed_form_basic.inc,v Exp $
+
+/**
+ * Exposed form plugin that provides basic exposed form
+ */
+class views_plugin_exposed_form_on_demand extends views_plugin_exposed_form {
+
+  function summary_title() {
+    return t('On demand');
+  }
+
+  function option_definition() {
+    parent::option_definition();
+    $options['submit_button'] = array('default' => 'Apply');
+    $options['text_on_demand'] = array('default' => t('Select any filter and click on Apply to see results'));
+    $options['text_on_demand_format'] = array('default' => FILTER_FORMAT_DEFAULT);
+
+    return $options;
+  }
+
+  function options_form(&$form, &$form_state) {
+    $form['submit_button'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Submit button text'),
+      '#description' => t('Text to display in the submit button of the exposed form.'),
+      '#default_value' => $this->options['submit_button'],
+    );
+
+    $form['text_on_demand'] = array(
+      '#type' => 'textarea',
+      '#title' => t('Text on demand'),
+      '#description' => t('Text to display instead results until user select and apply an expose filter.'),
+      '#default_value' => $this->options['text_on_demand'],
+    );
+    // $form['text_on_demand_format'] = filter_form($this->options['text_on_demand_format'], NULL, array('text_on_demand_format'));
+    // TODO: see how can use this input format into empty text
+  }
+
+  function exposed_filter_applied() {
+    $view = $this->view;
+    $exposed_data = $view->exposed_data;
+    if (is_array($view->filter) && count($view->filter)) {
+      foreach ($view->filter as $filter_id => $filter) {
+        if ($filter->is_exposed()) {
+          $filter_value = $exposed_data[$filter->options['expose']['identifier']];
+          if (!empty($filter_value) && $filter_value != 'All') {
+            return TRUE;
+          }
+        }
+      }
+    }
+    return FALSE;
+  }
+
+  function pre_render() {
+    if (!$this->exposed_filter_applied()) {
+      $this->view->display_handler->set_option('empty', $this->options['text_on_demand']);
+      $this->view->display_handler->set_option('empty_format', $this->options['text_on_demand_format']);
+    }
+  }
+
+  function query() {
+    if (!$this->exposed_filter_applied()) {
+      // clear WHERE statment to display empty text
+      $this->view->query->where = array();
+      $this->view->query->add_where(0, '1 = 0');
+    }
+  }
+
+}
