Index: scheduler.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/scheduler/Attic/scheduler.module,v
retrieving revision 1.46.4.21
diff -u -r1.46.4.21 scheduler.module
--- scheduler.module	11 Mar 2008 13:06:39 -0000	1.46.4.21
+++ scheduler.module	22 Mar 2008 17:04:17 -0000
@@ -47,8 +47,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.')
     );
@@ -73,9 +73,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));
@@ -85,7 +85,7 @@
           $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(
@@ -95,10 +95,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
@@ -107,11 +107,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
@@ -119,16 +119,16 @@
           '#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;
           $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.')
           );
         }
@@ -138,8 +138,8 @@
             '#value' => $defaults->timezone ? $defaults->timezone : (strlen($user->timezone) ? $user->timezone : variable_get('date_default_timezone', 0)),
           );
         }
-      }    
-    } 
+      }
+    }
   }
 }
 
@@ -165,55 +165,55 @@
         }
       }
     }
-    elseif (user_access('schedule (un)publishing of nodes')) {
-      switch ($op) {
-        case 'view':
-          if ($page && $node->unpublish_on) {
-            $unavailable_after = date ("d-M-Y H:i:s e", $node->unpublish_on);
-            drupal_set_html_head('<META NAME="GOOGLEBOT" CONTENT="unavailable_after: '. $unavailable_after .'">');
-          }
-          break;
-        case 'submit':
-          //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;
-
-          // 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
-          // since it will be published at a later date (but only if the value is in the future.
-          if ($node->publish_on != '' && is_numeric($node->publish_on) && $node->publish_on > time()) {
-            $node->status = 0;
-          }
-          break;
-       case 'insert':
-          //only insert into database if we need to (un)publish this node at some date
+  }
+  if (user_access('schedule (un)publishing of nodes')) {
+    switch ($op) {
+      case 'view':
+        if ($page && $node->unpublish_on) {
+          $unavailable_after = date ("d-M-Y H:i:s e", $node->unpublish_on);
+          drupal_set_html_head('<META NAME="GOOGLEBOT" CONTENT="unavailable_after: '. $unavailable_after .'">');
+        }
+        break;
+      case 'submit':
+        //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;
+
+        // 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
+        // since it will be published at a later date (but only if the value is in the future.
+        if ($node->publish_on != '' && is_numeric($node->publish_on) && $node->publish_on > time()) {
+          $node->status = 0;
+        }
+        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) {
+          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 '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
+          // otherwise the user probably cleared out the (un)publish dates so we should remove the record
           if ($node->publish_on != NULL || $node->unpublish_on != NULL) {
-            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 '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
-            // otherwise the user probably cleared out the (un)publish dates so we should remove the record
-            if ($node->publish_on != NULL || $node->unpublish_on != NULL) {
-              db_query('UPDATE {scheduler} SET publish_on = %d, unpublish_on = %d, timezone = %d WHERE nid = %d', $node->publish_on, $node->unpublish_on, $node->timezone, $node->nid);
-            }
-            else {
-              db_query('DELETE FROM {scheduler} WHERE nid = %d', $node->nid);
-            }
+            db_query('UPDATE {scheduler} SET publish_on = %d, unpublish_on = %d, timezone = %d WHERE nid = %d', $node->publish_on, $node->unpublish_on, $node->timezone, $node->nid);
           }
-          // node doesn't exist, create a record only if the (un)publish fields are blank
-          else if ($node->publish_on != NULL || $node->unpublish_on != NULL) {
-            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);
+          else {
+            db_query('DELETE FROM {scheduler} WHERE nid = %d', $node->nid);
           }
-          break;
-        case 'delete':
-          db_query('DELETE FROM {scheduler} WHERE nid = %d', $node->nid);
-          break;
-      }
+        }
+        // node doesn't exist, create a record only if the (un)publish fields are blank
+        else if ($node->publish_on != NULL || $node->unpublish_on != NULL) {
+          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;
@@ -236,7 +236,7 @@
     $n = node_submit($n);
     $n->status = 1;
     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);
@@ -245,17 +245,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);
@@ -265,14 +265,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();
@@ -298,7 +298,7 @@
 function _scheduler_scheduler_api($node, $action) {
   foreach (module_implements('scheduler_api') as $module) {
     $function = $module .'_scheduler_api';
-    $function($node, $action); 
+    $function($node, $action);
   }
 }
 
@@ -316,12 +316,12 @@
   $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,
   );
 
   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 />'.
