--- scheduler.module 2009-05-03 15:57:27.000000000 +0100 +++ scheduler.module 2009-05-04 17:54:20.000000000 +0100 @@ -16,7 +16,7 @@ function scheduler_help($section) { * Implementation of hook_perm(). */ function scheduler_perm() { - return array('schedule (un)publishing of nodes'); + return array('schedule (un)publishing of nodes', 'administer scheduler'); } /** @@ -315,6 +315,7 @@ function _scheduler_get_user_timezone() * Implementation of hook_nodeapi(). */ function scheduler_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { + drupal_set_message('scheduler_nodeapi op='.$op.''); // Run $op == load for any user. if ($op == 'load') { if (isset($node->nid) && $node->nid && variable_get('scheduler_'.$node->type, 0) == 1) { @@ -330,6 +331,7 @@ function scheduler_nodeapi(&$node, $op, $node->scheduler = $row; } } + drupal_set_message('$node->publish_on='.$node->publish_on.'
$node->scheduler='.print_r($node->scheduler,true)); } } elseif (user_access('schedule (un)publishing of nodes')) { @@ -345,37 +347,49 @@ function scheduler_nodeapi(&$node, $op, // adjust the entered times for timezone consideration. // Note, we must check to see if the value is numeric, // if it is, assume we have already done the strtotime - // conversation. This prevents us running strtotime on + // conversion. This prevents us running strtotime on // a value we have already converted. This is needed // because DRUPAL6 removed 'submit' and added 'presave' // and all this happens at different times. - if (isset($node->publish_on) && !is_numeric($node->publish_on)) { + + $date_format = variable_get('scheduler_date_format', SCHEDULER_DATE_FORMAT); + drupal_set_message('isset($node->publish_on)='.isset($node->publish_on).' $node->publish_on='.$node->publish_on.' is_numeric($node->publish_on)='.is_numeric($node->publish_on)); + if (isset($node->publish_on) && $node->publish_on && !is_numeric($node->publish_on)) { $publishtime = _scheduler_strtotime($node->publish_on); + drupal_set_message('publishtime='.$publishtime); if ($publishtime === FALSE) { - form_set_error('publish_on', t('The entered publication date is invalid.')); + 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)))); + } + elseif (isset($publishtime) && $publishtime < time()) { + form_set_error('publish_on', t("The 'publish on' date must be in the future")); } else { $node->publish_on = $publishtime; } } - if (isset($node->unpublish_on) && !is_numeric($node->unpublish_on)) { + drupal_set_message('isset($node->unpublish_on)='.isset($node->unpublish_on).' $node->unpublish_on='.$node->unpublish_on.' is_numeric($node->unpublish_on)='.is_numeric($node->unpublish_on)); + if (isset($node->unpublish_on) && $node->unpublish_on && !is_numeric($node->unpublish_on)) { $unpublishtime = _scheduler_strtotime($node->unpublish_on); + drupal_set_message('unpublishtime='.$unpublishtime); if ($unpublishtime === FALSE) { - form_set_error('unpublish_on', t('The entered expiration date is invalid.')); + 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)))); + } + elseif ($unpublishtime < time()) { + form_set_error('unpublish_on', t("The 'unpublish on' time must be in the future")); } else { $node->unpublish_on = $unpublishtime; } } + if (isset($publishtime) && isset($unpublishtime) && $unpublishtime < $publishtime) { - form_set_error('unpublish_on', t("The expiration date is before publication date.")); + 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 (but only if the value is in the future. - if (isset($node->publish_on) && $node->publish_on != '' && is_numeric($node->publish_on) && $node->publish_on > time()) { + // 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->status = 0; } break;