Index: scheduler.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/scheduler/Attic/scheduler.info,v
retrieving revision 1.2.2.1
diff -u -r1.2.2.1 scheduler.info
--- scheduler.info	13 Feb 2008 00:09:29 -0000	1.2.2.1
+++ scheduler.info	13 Aug 2009 04:38:48 -0000
@@ -1,3 +1,4 @@
 name = Scheduler
 description = This module allows nodes to be published and unpublished on specified dates.
 core = 6.x
+dependencies[] = date_popup
Index: scheduler.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/scheduler/Attic/scheduler.install,v
retrieving revision 1.5.2.5
diff -u -r1.5.2.5 scheduler.install
--- scheduler.install	19 Apr 2009 11:29:33 -0000	1.5.2.5
+++ scheduler.install	13 Aug 2009 04:38:48 -0000
@@ -1,15 +1,24 @@
 <?php
 // $Id: scheduler.install,v 1.5.2.5 2009/04/19 11:29:33 ericschaefer Exp $
 
+/**
+ * Implementation of hook_install().
+ */
 function scheduler_install() {
   drupal_install_schema('scheduler');
 }
 
+/**
+ * Implementation of hook_uninstall().
+ */
 function scheduler_uninstall() {
   drupal_uninstall_schema('scheduler');
   db_query("DELETE FROM {variable} WHERE name LIKE '%s_%%'", 'scheduler');
 }
 
+/**
+ * Implementation of hook_schema().
+ */
 function scheduler_schema() {
   return array(
     'scheduler' => array(
@@ -64,17 +73,27 @@
 }
 
 function scheduler_update_3() {
-  $ret[] = update_sql("CREATE INDEX scheduler_publish_on ON {scheduler} (publish_on)");
-  $ret[] = update_sql("CREATE INDEX scheduler_unpublish_on ON {scheduler} (unpublish_on)");
+  $ret = array();
+  db_add_index($ret, 'scheduler', 'scheduler_publish_on', array('publish_on'));
+  db_add_index($ret, 'scheduler', 'scheduler_unpublish_on', array('unpublish_on'));
   return $ret;
 }
 
 function scheduler_update_6100() {
   $ret = array();
   if (db_column_exists('scheduler', 'timezone')) {
-    $ret[] = update_sql("UPDATE {scheduler} SET publish_on=publish_on-timezone WHERE publish_on<>0");
-    $ret[] = update_sql("UPDATE {scheduler} SET unpublish_on=unpublish_on-timezone WHERE unpublish_on<>0");
-    $ret[] = update_sql("ALTER TABLE {scheduler} DROP COLUMN timezone");
+    $ret[] = update_sql("UPDATE {scheduler} SET publish_on = publish_on-timezone WHERE publish_on <> 0");
+    $ret[] = update_sql("UPDATE {scheduler} SET unpublish_on = unpublish_on-timezone WHERE unpublish_on <> 0");
+    db_drop_field($ret, 'scheduler', 'timezone');
   }
-  return $ret; 
+  return $ret;
+}
+
+/**
+ * Remove time configuration variable. It is not used with date_popup.
+ */
+function scheduler_update_6101() {
+  $ret = array();
+  variable_del('scheduler_date_format');
+  return $ret;
 }
Index: scheduler.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/scheduler/Attic/scheduler.module,v
retrieving revision 1.50.2.23
diff -u -r1.50.2.23 scheduler.module
--- scheduler.module	12 Jul 2009 17:00:14 -0000	1.50.2.23
+++ scheduler.module	13 Aug 2009 04:38:48 -0000
@@ -1,16 +1,10 @@
 <?php
 // $Id: scheduler.module,v 1.50.2.23 2009/07/12 17:00:14 ericschaefer Exp $
 
-define('SCHEDULER_DATE_FORMAT', 'Y-m-d H:i:s');
-
 /**
- * Implementation of hook_help().
+ * @file
+ * Schedule changes to the published status of nodes.
  */
-function scheduler_help($section) {
-  if ($section == 'admin/modules#description') {
-    return t('A module to schedule when nodes are (un)published.');
-  }
-}
 
 /**
  * Implementation of hook_perm().
@@ -38,20 +32,12 @@
     'access arguments' => array('access administration pages'),
     'type' => MENU_CALLBACK,
   );
-  $items['admin/settings/scheduler'] = array(
-    'title' => 'Scheduler module settings',
-    'description' => 'Allows site admins to configure scheduler.',
-    'page callback' => 'drupal_get_form',
-    'page arguments' => array('scheduler_admin'),
-    'access arguments' => array('administer scheduler'),
-    'type' => MENU_NORMAL_ITEM,
-  );
   $items['admin/content/node/scheduler'] = array(
     'type' => MENU_LOCAL_TASK,
     'title' => 'Scheduled',
     'page callback' => 'scheduler_list',
     'access callback' => 'scheduler_list_access_callback',
-    'description' => t('Display a list of scheduled nodes'),
+    'description' => 'Display a list of scheduled nodes',
   );
   return $items;
 }
@@ -63,24 +49,12 @@
   return user_access('administer nodes') && user_access('schedule (un)publishing of nodes');
 }
 
-function scheduler_admin() {
-  $form['scheduler_date_format'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Date format'),
-    '#default_value' => variable_get('scheduler_date_format', SCHEDULER_DATE_FORMAT),
-    '#size' => 20,
-    '#maxlength' => 20,
-    '#description' => t('The input format for the (un)scheduling time/date. See the date() function for formatting options: http://www.php.net/manual/en/function.date.php'),	
-  );
-  return system_settings_form($form);
-}
-
 /**
  * Implementation of hook_form_alter().
  */
 function scheduler_form_alter(&$form, $form_state, $form_id) {
-  //allow scheduling on a per-node-type basis
-
+  // Add scheduler settings to the workflow section on the node type
+  // editing form.
   if ('node_type_form' == $form_id) {
     $form['workflow']['scheduler'] = array(
       '#type' => 'checkbox',
@@ -96,72 +70,62 @@
     );
   }
 
-  // is this a node form?
-  elseif (isset($form['type']['#value']) && $form['type']['#value'] .'_node_form' == $form_id) {
-    if (user_access('schedule (un)publishing of nodes')) {
-      // if scheduling has been enabled for this node type
-      if (variable_get('scheduler_'. $form['type']['#value'], 0) == 1) {
-
-        //use JScalendar picker for dates if the module exists and is enabled
-        $jscalendar = FALSE;
-        if (module_exists('jscalendar')) {
-          $jscalendar = TRUE;
-        }
+  // For the node form, show the scheduler options if user has access to
+  // scheduling and scheduling is enabled for this node type.
+  elseif ($form['#id'] == 'node-form' && user_access('schedule (un)publishing of nodes') && variable_get('scheduler_'. $form['type']['#value'], 0)) {
+    $node = $form['#node'];
+    $date_format = variable_get('date_format_short', 'm/d/Y - H:i');
+
+    // if this is a preview then get the values from the form, not the db
+    if (isset($form_state['values']) && $form_state['values']['op']=='Preview') {
+      $defaults = new StdClass;
+      $defaults->publish_on = $form_state['values']['publish_on'];
+      $defaults->unpublish_on = $form_state['values']['unpublish_on'];
+    }
+    elseif (isset($node->nid) && $node->nid > 0) {
+      // load the values if we are viewing an existing node
+      $defaults = db_fetch_object(db_query('SELECT publish_on, unpublish_on FROM {scheduler} WHERE nid = %d', $node->nid));
+    }
+    else {
+      // init standard values
+      $defaults = new StdClass;
+      $defaults->publish_on = $defaults->unpublish_on = NULL;
+    }
 
-        $node = $form['#node'];
+    // if there is a text value then convert it to a unix timestamp
+    if (isset($defaults->publish_on) && $defaults->publish_on && !is_numeric($defaults->publish_on)) {
+      $defaults->publish_on = strtotime($node->publish_on);
+    }
+    if (isset($defaults->unpublish_on) && $defaults->unpublish_on && !is_numeric($defaults->unpublish_on)) {
+      $defaults->unpublish_on = strtotime($node->unpublish_on);
+    }
 
-        $date_format = variable_get('scheduler_date_format', SCHEDULER_DATE_FORMAT);
-        
-        // if this is a preview then get the values from the form, not the db
-        if ($form_state['values']['op']=='Preview') {
-          $defaults = new StdClass;
-          $defaults->publish_on = $form_state['values']['publish_on'];
-          $defaults->unpublish_on = $form_state['values']['unpublish_on'];
-        }
-        elseif (isset($node->nid) && $node->nid > 0) {
-          // load the values if we are viewing an existing node
-          $defaults = db_fetch_object(db_query('SELECT publish_on, unpublish_on FROM {scheduler} WHERE nid = %d', $node->nid));
-        }
-        else {
-          // init standard values
-          $defaults = new StdClass;
-          $defaults->publish_on = $defaults->unpublish_on = NULL;
-        }
+    $form['scheduler_settings'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Scheduling options'),
+      '#collapsible' => TRUE,
+      '#collapsed' => ((isset($defaults->publish_on) && $defaults->publish_on != 0) || (isset($defaults->unpublish_on) && $defaults->unpublish_on != 0)) ? FALSE: TRUE,
+      '#weight' => 35
+    );
 
-        // if there is a text value then convert it to a unix timestamp
-        if (isset($defaults->publish_on) && $defaults->publish_on && !is_numeric($defaults->publish_on)) {
-          $defaults->publish_on = _scheduler_strtotime($defaults->publish_on);
-        }
-        if (isset($defaults->unpublish_on) && $defaults->unpublish_on && !is_numeric($defaults->unpublish_on)) {
-          $defaults->unpublish_on = _scheduler_strtotime($defaults->unpublish_on);
-        }
+    $form['scheduler_settings']['publish_on'] = array(
+      '#type' => 'date_text',
+      '#title' => t('Publish on'),
+      '#default_value' => isset($defaults->publish_on) && $defaults->publish_on ? format_date($defaults->publish_on, 'custom', $date_format) : '',
+      '#description' => t('Leave blank to disable scheduled publishing.'),
+    );
 
-        $form['scheduler_settings'] = array(
-          '#type' => 'fieldset',
-          '#title' => t('Scheduling options'),
-          '#collapsible' => TRUE,
-          '#collapsed' => ((isset($defaults->publish_on) && $defaults->publish_on != 0) || (isset($defaults->unpublish_on) && $defaults->unpublish_on != 0)) ? FALSE: TRUE,
-          '#weight' => 35
-        );
-
-        $form['scheduler_settings']['publish_on'] = array(
-          '#type' => 'textfield',
-          '#title' => t('Publish on'),
-          '#maxlength' => 25,
-          '#default_value' => isset($defaults->publish_on) && $defaults->publish_on ? format_date($defaults->publish_on, 'custom', $date_format) : '',
-          '#description' => t('Format: %time. Leave blank to disable scheduled publishing.', array('%time' => format_date(time(), 'custom', $date_format))),
-          '#attributes' => $jscalendar ? array('class' => 'jscalendar') : array()
-        );
-
-        $form['scheduler_settings']['unpublish_on'] = array(
-          '#type' => 'textfield',
-          '#title' => t('Unpublish on'),
-          '#maxlength' => 25,
-          '#default_value' => isset($defaults->unpublish_on) && $defaults->unpublish_on ? format_date($defaults->unpublish_on, 'custom', $date_format) : '',
-          '#description' => t('Format: %time. Leave blank to disable scheduled unpublishing.', array('%time' => format_date(time(), 'custom', $date_format))),
-          '#attributes' => $jscalendar ? array('class' => 'jscalendar') : array()
-        );
-      }
+    $form['scheduler_settings']['unpublish_on'] = array(
+      '#type' => 'date_text',
+      '#title' => t('Unpublish on'),
+      '#default_value' => isset($defaults->unpublish_on) && $defaults->unpublish_on ? format_date($defaults->unpublish_on, 'custom', $date_format) : '',
+      '#description' => t('Leave blank to disable scheduled unpublishing.'),
+    );
+
+    if (module_exists('date_popup')) {
+      // Make this a popup calendar widget if Date Popup module is enabled.
+      $form['scheduler_settings']['publish_on']['#type'] = 'date_popup';
+      $form['scheduler_settings']['unpublish_on']['#type'] = 'date_popup';
     }
   }
 }
@@ -211,109 +175,12 @@
 }
 
 /**
- * Converts an english time string ('Y-m-d H:i:s') from the users timezone into an unix timestamp
- * @param string $str the time string ('Y-m-d H:i:s')
- * @return the time in unix timestamp representation (utc);
- * NULL, if $str is NULL, FALSE, empty, or contains only white spaces;
- * FALSE, if $str is malformed
- */
-function _scheduler_strtotime($str) {
-  if ($str && trim($str) != "" ) {
-    $time=_scheduler_strptime(trim($str), variable_get('scheduler_date_format', SCHEDULER_DATE_FORMAT));
-    if ($time!==FALSE) {
-      // success
-      $time -= _scheduler_get_user_timezone();
-    }
-  } else {
-    // $str is empty
-    $time = NULL;
-  }
-  return $time;
-}
-
-/**
- * Parse a time/date as UTC time
- *
- * @param string $date The string to parse
- * @param string $format The format used in $date. See date() (http://www.php.net/manual/en/function.date.php) 
- * specification for format options. Right now only dHhmiaAsyY are supported. 
- * @return the parsed time as a UTC timestamp
- * @see date()
- */
-function _scheduler_strptime($date, $format) {
-  # we need to build a regex pattern for the date format
-  $date_entities = array('d', 'H', 'h', 'm', 'i', 'a', 'A', 's', 'y', 'Y');
-  $date_regex_replacements = array('(\d{2})', '(\d{2})', '(\d{2})', '(\d{2})', '(\d{2})', '([ap]m)', '([AP]M)', '(\d{2})', '(\d{2})', '(\d{4})'); 
-  $custom_pattern = str_replace($date_entities, $date_regex_replacements, $format);
-  if (!preg_match("#$custom_pattern#", $date, $value_matches)) {
-    return FALSE;
-  }
-  
-  if (!preg_match_all("/(\w)/", $format, $entity_matches)) {
-    return FALSE;
-  }
-
-  $results = array('day' => 0, 'hour' => 0, 'month' => 0, 'minute' => 0, 'meridiem' => NULL, 'second' => 0, 'year' => 0);
-  $index = 1;
-  foreach ($entity_matches[1] as $entity) {
-    $value = intval($value_matches[$index]);
-    switch ($entity) {
-      case 'd':
-        $results['day'] = $value;
-        break;
-      case 'H':
-      case 'h':
-        $results['hour'] = $value; 
-        break;
-      case 'm':
-        $results['month'] = $value; 
-        break;
-      case 'i':
-        $results['minute'] = $value; 
-        break;
-      case 'a':
-      case 'A':
-        $results['meridiem'] = $value_matches[$index]; 
-        break;
-      case 's':
-        $results['second'] = $value; 
-        break;
-      case 'y':
-      case 'Y':
-        $results['year'] = $value; 
-        break;
-    }    
-    $index++;
-  }
-  if ((strncasecmp($results['meridiem'], "pm", 2) == 0) && ($results['hour'] <= 12)) {
-    $results['hour'] += 12;
-  }
-
-  $time = gmmktime( $results['hour'], $results['minute'], $results['second'], $results['month'], $results['day'], $results['year'] );
-  return $time;
-}
-
-/**
- * Gets the users timezone if configurable timezones are enabled or otherwise the default timezone of the site
- *
- * @return the offset of the users timezone in seconds
- */
-function _scheduler_get_user_timezone() {
-  global $user;
-  $timezone = variable_get('date_default_timezone', 0);
-  if ((variable_get('configurable_timezones', 1) == 1) && (strlen($user->timezone))) {
-    $timezone = $user->timezone;
-  }
-  return $timezone;
-}
-
-/**
  * Implementation of hook_nodeapi().
  */
 function scheduler_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
   // Run $op == load for any user.
   if ($op == 'load') {
-    if (isset($node->nid) && $node->nid && variable_get('scheduler_'.$node->type, 0) == 1) {
+    if (isset($node->nid) && $node->nid && variable_get('scheduler_'. $node->type, 0) == 1) {
       $result = db_query('SELECT * FROM {scheduler} WHERE nid = %d', $node->nid);
       if ($result) {
         $row = db_fetch_array($result);
@@ -332,8 +199,8 @@
     switch ($op) {
       case 'view':
         if (isset($a4) && $a4 && isset($node->unpublish_on) && $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 .'">');
+          $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 'validate':
@@ -345,11 +212,11 @@
         // a value we have already converted. This is needed
         // because DRUPAL6 removed 'submit' and added 'presave'
         // and all this happens at different times.
-        
-        $date_format = variable_get('scheduler_date_format', SCHEDULER_DATE_FORMAT);
-        
+
+        $date_format = variable_get('date_format_short', 'm/d/Y - H:i');
+
         if (isset($node->publish_on) && $node->publish_on && !is_numeric($node->publish_on)) {
-          $publishtime = _scheduler_strtotime($node->publish_on);
+          $publishtime = strtotime($node->publish_on);
           if ($publishtime === FALSE) {
             form_set_error('publish_on', t("The 'publish on' value does not match the expected format of %time", array('%time' => format_date(time(), 'custom', $date_format))));
           }
@@ -360,9 +227,9 @@
             $node->publish_on = $publishtime;
           }
         }
-        
+
         if (isset($node->unpublish_on) && $node->unpublish_on && !is_numeric($node->unpublish_on)) {
-          $unpublishtime = _scheduler_strtotime($node->unpublish_on);
+          $unpublishtime = strtotime($node->unpublish_on);
           if ($unpublishtime === FALSE) {
             form_set_error('unpublish_on', t("The 'unpublish on' value does not match the expected format of %time", array('%time' => format_date(time(), 'custom', $date_format))));
           }
@@ -377,7 +244,7 @@
         if (isset($publishtime) && isset($unpublishtime) && $unpublishtime < $publishtime) {
           form_set_error('unpublish_on', t("The 'unpublish on' date must be later than the 'publish on' date."));
         }
-        
+
         // 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
         if (isset($node->publish_on) && $node->publish_on != '' && is_numeric($node->publish_on) && $node->publish_on > time()) {
@@ -393,7 +260,7 @@
       case 'update':
         if (isset($node->nid) && $node->nid) {
           $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
@@ -485,7 +352,7 @@
 }
 
 /**
- * Implementation of hook_theme()
+ * Implementation of hook_theme().
  */
 function scheduler_theme() {
   return array(
Index: scheduler.views.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/scheduler/Attic/scheduler.views.inc,v
retrieving revision 1.1.2.2
diff -u -r1.1.2.2 scheduler.views.inc
--- scheduler.views.inc	1 Nov 2008 16:32:03 -0000	1.1.2.2
+++ scheduler.views.inc	13 Aug 2009 04:38:48 -0000
@@ -1,15 +1,15 @@
 <?php
-// $id$
+// $Id$
 
 function scheduler_views_data() {
   $tables['scheduler']['table']['group'] = t('Scheduler');
-  
+
   // how is the scheduler table linked to the nodes
   $tables['scheduler']['table']['join']['node'] = array(
     'left_field' => 'nid',
     'field' => 'nid',
   );
-  
+
   // description of the fields (table columns)
   $tables['scheduler']['publish_on'] = array(
     'title' => t('Publish on'),
@@ -42,6 +42,6 @@
       'handler' => 'views_handler_sort_date',
     ),
   );
-  
+
   return $tables;
-}
\ No newline at end of file
+}
