? .git
Index: views.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/views/views.module,v
retrieving revision 1.332.2.15
diff -u -p -r1.332.2.15 views.module
--- views.module	3 Dec 2009 21:47:21 -0000	1.332.2.15
+++ views.module	3 Dec 2009 23:47:53 -0000
@@ -992,7 +992,7 @@ function views_exposed_form(&$form_state
   $form['submit'] = array(
     '#name' => '', // prevent from showing up in $_GET.
     '#type' => 'submit',
-    '#value' => t($form_state['submit_button']),
+    '#value' => t('Submit'),
     '#id' => form_clean_id('edit-submit-' . $view->name),
   );
 
@@ -1043,7 +1043,7 @@ function views_exposed_form_submit(&$for
   $form_state['view']->exposed_data = $form_state['values'];
   $form_state['view']->exposed_raw_input = array();
 
-  $exclude = array('q', 'submit', 'form_build_id', 'form_id', 'form_token', 'submit_button', 'exposed_form_plugin', '');
+  $exclude = array('q', 'submit', 'form_build_id', 'form_id', 'form_token', 'exposed_form_plugin', '');
   $exposed_form_plugin = $form_state['exposed_form_plugin'];
   $exposed_form_plugin->exposed_form_submit($form, $form_state, $exclude);
   
Index: handlers/views_handler_sort.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/views/handlers/views_handler_sort.inc,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 views_handler_sort.inc
--- handlers/views_handler_sort.inc	26 Jun 2009 00:23:37 -0000	1.1.2.1
+++ handlers/views_handler_sort.inc	3 Dec 2009 23:47:54 -0000
@@ -10,6 +10,12 @@
  * Base sort handler that has no options and performs a simple sort
  */
 class views_handler_sort extends views_handler {
+
+  /**
+   * Determine if a sort can be exposed.
+   */
+  function can_expose() { return TRUE; }
+
   /**
    * Called to add the sort to a query.
    */
@@ -23,7 +29,12 @@ class views_handler_sort extends views_h
     $options = parent::option_definition();
 
     $options['order'] = array('default' => 'ASC');
-
+    $options['exposed'] = array('default' => FALSE);
+    $options['expose'] = array(
+      'contains' => array(
+        'label' => array('default' => '', 'translatable' => TRUE),
+      ),
+    );
     return $options;
   }
 
@@ -31,29 +42,124 @@ class views_handler_sort extends views_h
    * Display whether or not the sort order is ascending or descending
    */
   function admin_summary() {
+    if (!empty($this->options['exposed'])) {
+      return t('Exposed');
+    }
     switch ($this->options['order']) {
       case 'ASC':
       case 'asc':
       default:
-        $type = t('asc');
+        return t('asc');
         break;
       case 'DESC';
       case 'desc';
-        $type = t('desc');
+        return t('desc');
         break;
     }
-    return '<span class="views-ascending"><span>' . $type . '</span></span>';
   }
 
   /**
    * Basic options for all sort criteria
    */
   function options_form(&$form, &$form_state) {
-    $form['order'] = array(
-      '#type' => 'radios',
-      '#title' => t('Sort order'),
-      '#options' => array('ASC' => t('Ascending'), 'DESC' => t('Descending')),
-      '#default_value' => $this->options['order'],
+    if ($this->can_expose()) {
+      $this->show_expose_button($form, $form_state);
+    }
+    $form['op_val_start'] = array('#value' => '<div class="clear-block">');
+    $this->show_sort_form($form, $form_state);
+    $form['op_val_end'] = array('#value' => '</div>');
+    if ($this->can_expose()) {
+      $this->show_expose_form($form, $form_state);
+    }
+  }
+
+  /**
+   * Simple validate handler
+   */
+  function options_validate(&$form, &$form_state) {
+    $this->sort_validate($form, $form_state);
+    if (!empty($this->options['exposed'])) {
+      $this->expose_validate($form, $form_state);
+    }
+
+  }
+
+  /**
+   * Simple submit handler
+   */
+  function options_submit(&$form, &$form_state) {
+    unset($form_state['values']['expose_button']); // don't store this.
+    $this->sort_submit($form, $form_state);
+    if (!empty($this->options['exposed'])) {
+      $this->expose_submit($form, $form_state);
+    }
+  }
+
+  /**
+   * Shortcut to display the value form.
+   */
+  function show_sort_form(&$form, &$form_state) {
+    $options = $this->sort_options();
+    if (!empty($options)) {
+      $form['order'] = array(
+        '#type' => 'radios',
+        '#options' => $options,
+        '#default_value' => $this->options['order'],
+      );
+    }
+  }
+
+  function sort_validate(&$form, &$form_state) { }
+
+  function sort_submit(&$form, &$form_state) { }
+
+  /**
+   * Provide a list of options for the default sort form.
+   * Should be overridden by classes that don't override sort_form
+   */
+  function sort_options() { 
+    return array(
+      'ASC' => t('Sort ascending'), 
+      'DESC' => t('Sort descending'),
+    ); 
+  }
+
+  /**
+   * Since all exposed sorts are grouped into one select box.
+   * We don't return nothing when views call to exposed_form()
+   */ 
+  function exposed_form(&$form, &$form_state) { }
+
+  /**
+   * Handle the 'left' side fo the exposed options form.
+   */
+ function expose_form_left(&$form, &$form_state) {
+    $form['expose']['label'] = array(
+      '#type' => 'textfield',
+      '#default_value' => $this->options['expose']['label'],
+      '#title' => t('Label'),
+      '#required' => TRUE,
+      '#size' => 40,
+   );
+  }
+  
+  /**
+   * Handle the 'right' side fo the exposed options form.
+   */
+  function expose_form_right(&$form, &$form_state) {
+    $form['expose']['order'] = array(
+      '#type' => 'value',
+      '#value' => 'ASC',
+     );
+  }
+
+  /**
+   * Provide default options for exposed sorts.
+   */
+  function expose_options() {
+    $this->options['expose'] = array(
+      'order' => $this->options['order'],
+      'label' => $this->ui_name(),
     );
   }
 }
Index: plugins/views_plugin_exposed_form.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/views/plugins/Attic/views_plugin_exposed_form.inc,v
retrieving revision 1.1.2.5
diff -u -p -r1.1.2.5 views_plugin_exposed_form.inc
--- plugins/views_plugin_exposed_form.inc	3 Dec 2009 23:28:53 -0000	1.1.2.5
+++ plugins/views_plugin_exposed_form.inc	3 Dec 2009 23:47:56 -0000
@@ -31,8 +31,11 @@ class views_plugin_exposed_form extends 
 
   function option_definition() {
     $options = parent::option_definition();
-    $options['submit_button'] = array('default' => t('Apply'), 'translatable' => TRUE);
+    $options['submit_button'] = array('default' => 'Apply', 'translatable' => TRUE);
     $options['reset_button'] = array('default' => FALSE, 'bool' => TRUE);
+    $options['exposed_sorts_label'] = array('default' => 'Sort By', 'translatable' => TRUE);
+    $options['sort_asc_label'] = array('default' => 'Asc', 'translatable' => TRUE);
+    $options['sort_desc_label'] = array('default' => 'Desc', 'translatable' => TRUE);
     return $options;
   }
 
@@ -42,6 +45,7 @@ class views_plugin_exposed_form extends 
       '#title' => t('Submit button text'),
       '#description' => t('Text to display in the submit button of the exposed form.'),
       '#default_value' => $this->options['submit_button'],
+      '#required' => TRUE,
     );
 
     $form['reset_button'] = array (
@@ -50,6 +54,30 @@ class views_plugin_exposed_form extends 
       '#description' => t('If checked the exposed form will provide a button to reset all the applied exposed filters'),
       '#default_value' => $this->options['reset_button'],
     );
+
+    $form['exposed_sorts_label'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Exposed sorts label'),
+      '#description' => t('Text to display as the label of the exposed sort select box.'),
+      '#default_value' => $this->options['exposed_sorts_label'],
+      '#required' => TRUE,
+    );
+
+    $form['sort_asc_label'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Ascending'),
+      '#description' => t('Text to use when exposed sort is ordered ascending.'),
+      '#default_value' => $this->options['sort_asc_label'],
+      '#required' => TRUE,
+    );
+
+    $form['sort_desc_label'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Descending'),
+      '#description' => t('Text to use when exposed sort is ordered descending.'),
+      '#default_value' => $this->options['sort_desc_label'],
+      '#required' => TRUE,
+    );
   }
 
   /**
@@ -67,7 +95,6 @@ class views_plugin_exposed_form extends 
       'method' => 'get',
       'rerender' => TRUE,
       'no_redirect' => TRUE,
-      'submit_button' => $this->options['submit_button'],
     );
 
     // Some types of displays (eg. attachments) may wish to use the exposed
@@ -91,7 +118,26 @@ class views_plugin_exposed_form extends 
     return $output;
   }
 
-  function query() { }
+  function query() {
+    $view = $this->view;
+    $exposed_data = $view->exposed_data;
+    $sort_by = $exposed_data['sort_by'];
+    if (!empty($sort_by)) {
+      $handler = $view->sort[$sort_by];
+      if (isset($handler)) {
+        $view->query->orderby = array();
+        if (isset($exposed_data['sort_order']) && in_array($exposed_data['sort_order'], array('asc', 'desc'))) {
+          $handler->options['order'] = $exposed_data['sort_order'];
+        }
+        $handler->query();  
+        foreach ($view->sort as $sort) {
+          if (!$sort->is_exposed()) {
+            $sort->query();
+          }
+        }
+      }
+    }
+  }
 
   function pre_render() { }
 
@@ -106,6 +152,33 @@ class views_plugin_exposed_form extends 
         '#type' => 'submit',
       );
     }
+
+    $form['submit']['#value'] = t($this->options['submit_button']);
+    // Check if there is exposed sorts for this view
+    $exposed_sorts = array();
+    foreach ($this->view->sort as $id => $handler) {
+      if ($handler->can_expose() && $handler->is_exposed()) {
+        $exposed_sorts[$id] = check_plain($handler->options['expose']['label']);
+      }
+    }
+ 
+    if (count($exposed_sorts)) {
+      $form['sort_by'] = array(
+        '#type' => 'select',
+        '#options' => $exposed_sorts,
+        '#title' => t($this->options['exposed_sorts_label']),
+      );
+      $sort_order = array(
+        'asc' => t($this->options['sort_asc_label']),
+        'desc' => t($this->options['sort_desc_label']),
+      );
+      $form['sort_order'] = array(
+        '#type' => 'select',
+        '#options' => $sort_order,
+        '#title' => t('Order'),
+      );
+      $form['submit']['#weight'] = 10;
+    }
   }
 
   function exposed_form_validate(&$form, &$form_state) { }
