Index: /Users/dburns/Sites/myplay/trunk/public_html/sites/all/modules/contrib/scheduler/scheduler.module
===================================================================
--- /Users/dburns/Sites/myplay/trunk/public_html/sites/all/modules/contrib/scheduler/scheduler.module	(revision 1864)
+++ /Users/dburns/Sites/myplay/trunk/public_html/sites/all/modules/contrib/scheduler/scheduler.module	(working copy)
@@ -48,8 +48,8 @@
 
   if ('node_type_form' == $form_id) {
     $form['workflow']['scheduler'] = array(
-      '#type' => 'checkbox', 
-      '#title' => t('Enable scheduled (un)publishing'), 
+      '#type' => 'checkbox',
+      '#title' => t('Enable scheduled (un)publishing'),
       '#default_value' => variable_get('scheduler_'. $form['#node_type']->type, 0),
       '#description' => t('Check this box to enable scheduled (un)publishing for this node type.')
     );
@@ -74,9 +74,9 @@
           // Show 24-hour clock for JScalendar
           $form['#jscalendar_timeFormat'] = '24';
         }
-        
+
         $node = $form['#node'];
-        
+
         //only load the values if we are viewing an existing node
         if ($node->nid > 0) {
           $defaults = db_fetch_object(db_query('SELECT publish_on, unpublish_on, timezone FROM {scheduler} WHERE nid = %d', $node->nid));
@@ -81,12 +81,12 @@
         if ($node->nid > 0) {
           $defaults = db_fetch_object(db_query('SELECT publish_on, unpublish_on, timezone FROM {scheduler} WHERE nid = %d', $node->nid));
         }
-	else {
+  else {
           // init standard values
           $defaults = new StdClass;
           $defaults->publish_on = $defaults->unpublish_on = NULL;
-	}
-        
+  }
+
         //note don't use format_date() because drupal automatically formats the date to the user's timezone
         //this will show the wrong time because scheduler can set nodes to be published in different timezones
         $form['scheduler_settings'] = array(
@@ -96,10 +96,10 @@
           '#collapsed' => ($defaults->publish_on != 0 || $defaults->unpublish_on != 0) ? FALSE: TRUE,
           '#weight' => 35
         );
-        
+
         $form['scheduler_settings']['publish_on'] = array(
-          '#type' => 'textfield', 
-          '#title' => t('Publish on'), 
+          '#type' => 'textfield',
+          '#title' => t('Publish on'),
           '#maxlength' => 25,
           //we subtract the time zone to show the user the correct time they entered
           //and below that we show the timezone to adjust this time by
@@ -108,11 +108,11 @@
           '#description' => t('Format: %time. Leave blank to publish on the time of form submission.', array('%time' => date('Y-m-d H:i:s'))),
           '#attributes' => $jscalendar ? array('class' => 'jscalendar') : array()
         );
-        
+
         $form['scheduler_settings']['unpublish_on'] = array(
-          '#type' => 'textfield', 
-          '#title' => t('Unpublish on'), 
-          '#maxlength' => 25, 
+          '#type' => 'textfield',
+          '#title' => t('Unpublish on'),
+          '#maxlength' => 25,
           //we subtract the time zone to show the user the correct time they entered
           //and below that we show the timezone to adjust this time by
           //we store the adjusted timezone value in the database for cron
@@ -120,7 +120,7 @@
           '#description' => t('Format: %time. Leave blank to not unpublish this node.', array('%time' => date('Y-m-d H:i:s'))),
           '#attributes' => $jscalendar ? array('class' => 'jscalendar') : array()
         );
-        
+
         //default to user timezone, if not specified, default to system wide timezone
         if (variable_get('configurable_timezones', 1) == 1) {
           global $user;
@@ -126,10 +126,10 @@
           global $user;
           $zones = _system_zonelist();
           $form['scheduler_settings']['timezone'] = array(
-            '#type' => 'select', 
-            '#title' => t('Time zone'), 
+            '#type' => 'select',
+            '#title' => t('Time zone'),
             '#default_value' => $defaults->timezone ? $defaults->timezone : (strlen($user->timezone) ? $user->timezone : variable_get('date_default_timezone', 0)),
-            '#options' => $zones, 
+            '#options' => $zones,
             '#description' => t('Select the time zone to (un)publish in.')
           );
         }
@@ -139,8 +139,8 @@
             '#value' => $defaults->timezone ? $defaults->timezone : (strlen($user->timezone) ? $user->timezone : variable_get('date_default_timezone', 0)),
           );
         }
-      }    
-    } 
+      }
+    }
   }
 }
 
@@ -166,9 +166,9 @@
             $row['unpublished'] = $row['unpublish_on'] ? date(variable_get('date_format_long', 'l, F j, Y - H:i'), $row['unpublish_on']) : NULL;
             $node->scheduler = $row;
           }
-        }	    
+        }
         break;
-        
+
       case 'submit':
         // right before we save the node, we need to check if a "publish on" value has been set
         // if it has been set, we want to make sure the node is unpublished
@@ -176,7 +176,7 @@
         if ($node->publish_on != '') {
           $node->status = 0;
         }
-      
+
         //adjust the entered times for timezone consideration
         $node->publish_on = $node->publish_on ? strtotime($node->publish_on) + $node->timezone : NULL;
         $node->unpublish_on = $node->unpublish_on ? strtotime($node->unpublish_on) + $node->timezone : NULL;
@@ -182,7 +182,7 @@
         $node->unpublish_on = $node->unpublish_on ? strtotime($node->unpublish_on) + $node->timezone : NULL;
 
         break;
-      
+
       case 'insert':
         //only insert into database if we need to (un)publish this node at some date
         if ($node->publish_on != NULL || $node->unpublish_on != NULL) {
@@ -192,7 +192,7 @@
 
       case 'update':
         $exists = db_result(db_query('SELECT nid FROM {scheduler} WHERE nid = %d', $node->nid));
-          
+
         //if this node has already been scheduled, update its record
         if ($exists) {
           //only update database if we need to (un)publish this node at some date
@@ -209,7 +209,7 @@
           db_query('INSERT INTO {scheduler} (nid, publish_on, unpublish_on, timezone) VALUES (%d, %d, %d, %d)', $node->nid, $node->publish_on, $node->unpublish_on, $node->timezone);
         }
         break;
-  
+
       case 'delete':
         db_query('DELETE FROM {scheduler} WHERE nid = %d', $node->nid);
         break;
@@ -223,10 +223,10 @@
  */
 function scheduler_cron() {
   $clear_cache = FALSE;
-  
+
   //if the time now is greater than the time to publish a node, publish it
   $nodes = db_query('SELECT *, (publish_on - timezone) AS utc_publish_on FROM {scheduler} s LEFT JOIN {node} n ON s.nid = n.nid WHERE n.status = 0 AND s.publish_on > 0 AND s.publish_on < %d + s.timezone', time());
-  
+
   while ($node = db_fetch_object($nodes)) {
     $n = node_load($node->nid);
     $n->changed = $node->utc_publish_on;
@@ -235,7 +235,7 @@
       $n->created = $node->utc_publish_on;
     }
     node_save($n);
-    
+
     //if this node is not to be unpublished, then we can delete the record
     if ($n->unpublish_on == 0) {
       db_query('DELETE FROM {scheduler} WHERE nid = %d', $n->nid);
@@ -244,17 +244,17 @@
     else {
       db_query('UPDATE {scheduler} SET publish_on = 0 WHERE nid = %d', $n->nid);
     }
-    
+
     //invoke scheduler API
     _scheduler_scheduler_api($n, 'publish');
-    
+
     watchdog('content', t('@type: scheduled publishing of %title.', array('@type' => $n->type, '%title' => $n->title)), WATCHDOG_NOTICE, l(t('view'), 'node/'. $n->nid));
     $clear_cache = TRUE;
   }
-  
+
   //if the time is greater than the time to unpublish a node, unpublish it
   $nodes = db_query('SELECT *, (unpublish_on - timezone) AS utc_unpublish_on FROM {scheduler} s LEFT JOIN {node} n ON s.nid = n.nid WHERE n.status = 1 AND s.unpublish_on > 0 AND s.unpublish_on < %d + s.timezone', time());
-  
+
   while ($node = db_fetch_object($nodes)) {
     //if this node is to be unpublished, we can update the node and remove the record since it can't be republished
     $n = node_load($node->nid);
@@ -263,14 +263,14 @@
     node_save($n);
 
     db_query('DELETE FROM {scheduler} WHERE nid = %d', $n->nid);
-    
+
     //invoke scheduler API
     _scheduler_scheduler_api($n, 'unpublish');
-    
+
     watchdog('content', t('@type: scheduled unpublishing of %title.', array('@type' => $n->type, '%title' => $n->title)), WATCHDOG_NOTICE, l(t('view'), 'node/'. $n->nid));
     $clear_cache = TRUE;
   }
-  
+
   if ($clear_cache) {
     // clear the cache so an anonymous poster can see the node being published or unpublished
     cache_clear_all();
@@ -296,7 +296,7 @@
 function _scheduler_scheduler_api($node, $action) {
   foreach (module_implements('scheduler_api') as $module) {
     $function = $module .'_scheduler_api';
-    $function($node, $action); 
+    $function($node, $action);
   }
 }
 
@@ -314,7 +314,7 @@
   $lt = ($t['tm_year']+1900) .'-'. ($t['tm_mon']+1) .'-'. $t['tm_mday'] .' '. $t['tm_hour'] .':'. $t['tm_min'] .':'. $t['tm_sec'];
 
   $t_options = array(
-    '%time' => date("Y-m-d H:i:s", $now), 
+    '%time' => date("Y-m-d H:i:s", $now),
     '%lt' => $lt,
   );
 
@@ -319,7 +319,7 @@
   );
 
   return
-    t('Your server reports the UTC time as %time and "localtime" as %lt.', $t_options) . 
+    t('Your server reports the UTC time as %time and "localtime" as %lt.', $t_options) .
    '<p />'.
     t('If all is well with your server\'s time configuration UTC should match <a target="_blank" href="http://wwp.greenwichmeantime.com/">UTC London Time</a> and the localtime should be the time where you are.') .
     '<p />'.
@@ -355,6 +355,14 @@
         'handler' => views_handler_field_dates(),
       ),
     ),
+    'sorts' => array(
+      'publish_on' => array(
+        'name' => t('Scheduler: publish on'),
+        'handler' => 'views_handler_sort_date',
+        'option' => views_handler_sort_date_options(),
+        'help' => t('Date/time on which the article will be automatically published'),
+      ),
+    ),
   );
   return $tables;
 }
