? scheduler-module-255010-2.patch
? scheduler-module-255010-3.patch
? scheduler-module-255010-7.patch
Index: scheduler.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/scheduler/Attic/scheduler.module,v
retrieving revision 1.46.4.29
diff -u -p -r1.46.4.29 scheduler.module
--- scheduler.module	28 Apr 2008 12:09:01 -0000	1.46.4.29
+++ scheduler.module	7 May 2008 19:38:09 -0000
@@ -66,6 +66,9 @@ function scheduler_form_alter($form_id, 
       // if scheduling has been enabled for this node type
       if (variable_get('scheduler_'. $form['type']['#value'], 0) == 1) {
 
+        // We add the additional validation function this way to preserve any existing validation function
+        $form['#validate']['_scheduler_form_validate' ] = array();
+
         //use JScalendar picker for dates if the module exists and is enabled
         $jscalendar = FALSE;
         if (module_exists('jscalendar')) {
@@ -144,6 +147,56 @@ function scheduler_form_alter($form_id, 
 }
 
 /**
+ * Returns
+ * - integer time (numeric) shifted by $timezone, if $str is a valid time.
+ * - NULL, if $str is NULL, FALSE, empty, or contains only white spaces
+ * - FALSE, if $str is malformed
+ */
+function _scheduler_strtotime($str, $timezone = 0) {
+  if ($str && trim($str) != "" ) {
+    $time=strtotime(trim($str));
+    if ($time!==FALSE) {
+      // success
+      return $time + $timezone;
+    } else {
+      // str is malformed
+      return FALSE;
+    }
+  } else {
+    // $str is empty
+    return NULL;
+  }
+}
+
+/**
+ * Implementation of hook_form_validate()
+ * Validate the input of the publish and unpublish date fields
+ */
+function _scheduler_form_validate($form_id, $form) {
+
+  $publishtime = NULL;
+  $unpublishtime = NULL;
+
+  if (isset($form['publish_on'])) {
+    $publishtime=_scheduler_strtotime($form['publish_on']);
+    if ($publishtime === FALSE) {
+      form_set_error('publish_on', t('The entered publication date is invalid.'));
+    }
+  }
+
+  if (isset($form['unpublish_on'])) {
+    $unpublishtime = _scheduler_strtotime($form['unpublish_on']);
+    if ($unpublishtime === FALSE) {
+      form_set_error('unpublish_on', t('The entered expiration date is invalid.'));
+    }
+  }
+
+  if (is_integer($publishtime) && is_integer($unpublishtime) && $unpublishtime < $publishtime) {
+    form_set_error('unpublish_on', t("The expiration date is before publication date."));
+  }
+}
+
+/**
  * Implementation of hook_nodeapi().
  */
 function scheduler_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
@@ -176,8 +229,8 @@ function scheduler_nodeapi(&$node, $op, 
         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;
+        $node->publish_on = _scheduler_strtotime($node->publish_on, $node->timezone);
+        $node->unpublish_on = _scheduler_strtotime($node->unpublish_on, $node->timezone);
 
         // 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
