Index: scheduler.module =================================================================== --- scheduler.module (revision 8639) +++ scheduler.module (working copy) @@ -2,6 +2,7 @@ // $Id: scheduler.module,v 1.50.2.36 2010/05/02 16:36:06 ericschaefer Exp $ define('SCHEDULER_DATE_FORMAT', 'Y-m-d H:i:s'); +define('SCHEDULER_DATE_PAST', FALSE); /** * Implementation of hook_perm(). @@ -63,6 +64,14 @@ '#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 (only the following format characters are supported (don\'t use \'G\', \'a\' or \'A\' with Date Popup): djmnyYhHgGisaA)'), ); + $form['scheduler_date_past'] = array( + '#type' => 'textfield', + '#title' => t('Roles with permission to set \'publish on\' date in the past'), + '#default_value' => variable_get('scheduler_date_past', ''), + '#size' => 60, + '#description' => t('Fill in all user roles that should have permission to set \'publish on\' date in the past. Seperate roles with comma'), + ); + return system_settings_form($form); } @@ -330,6 +339,10 @@ * Implementation of hook_nodeapi(). */ function scheduler_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { + + // Current time + $now = time(); + // Run $op == load for any user. if ($op == 'load') { if (isset($node->nid) && $node->nid && variable_get('scheduler_'. $node->type, 0) == 1) { @@ -367,12 +380,23 @@ $date_format = variable_get('scheduler_date_format', SCHEDULER_DATE_FORMAT); + // Users with some roles should have permission to set 'publish on' date in the past. + // 'Unpublish on' date always must be in the future or empty + $permit_date_past = FALSE; + $roles = explode(',', variable_get('scheduler_date_past', '')); + foreach ($roles as $role) { + if (user_access(trim($role))) { + $permit_date_past = TRUE; + break; + } + } + if (isset($node->publish_on) && $node->publish_on && !is_numeric($node->publish_on)) { $publishtime = _scheduler_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)))); + form_set_error('publish_on', t("The 'publish on' value does not match the expected format of %time", array('%time' => format_date($now, 'custom', $date_format)))); } - elseif ($publishtime && $publishtime < time()) { + elseif ($permit_date_past == FALSE && $publishtime && $publishtime < $now) { form_set_error('publish_on', t("The 'publish on' date must be in the future")); } else { @@ -383,9 +407,9 @@ if (isset($node->unpublish_on) && $node->unpublish_on && !is_numeric($node->unpublish_on)) { $unpublishtime = _scheduler_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)))); + form_set_error('unpublish_on', t("The 'unpublish on' value does not match the expected format of %time", array('%time' => format_date($now, 'custom', $date_format)))); } - elseif ($unpublishtime && $unpublishtime < time()) { + elseif ($unpublishtime && $unpublishtime < $now) { form_set_error('unpublish_on', t("The 'unpublish on' date must be in the future")); } else { @@ -397,15 +421,25 @@ 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. + // Right before we save the node, we need to check if a "publish on" value has been. // 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()) { - $node->status = 0; + if (isset($node->publish_on) && $node->publish_on != '' && is_numeric($node->publish_on)) { + // One exception is if "publish on" is in the past but "unpublish_on" is in the future + if ($permit_date_past && $node->publish_on < $now) { + $node->status = 1; + // Remember real created date for your future aims + $node->real_created = $node->created; + // Change created date + $node->created = $node->publish_on; + } else { + $node->status = 0; + } } + // If "publish on" value has been set in the past break; case 'insert': // only insert into database if we need to (un)publish this node at some date - if (isset($node->nid) && $node->nid && (isset($node->publish_on) && $node->publish_on != NULL) || (isset($node->unpublish_on) && $node->unpublish_on != NULL)) { + if (isset($node->nid) && $node->nid && ((isset($node->publish_on) && $node->publish_on != NULL && $node->publish_on > $now) || (isset($node->unpublish_on) && $node->unpublish_on != NULL && $node->unpublish_on > $now))) { db_query('INSERT INTO {scheduler} (nid, publish_on, unpublish_on) VALUES (%d, %d, %d)', $node->nid, $node->publish_on, $node->unpublish_on); } break; @@ -417,7 +451,7 @@ 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->status == 0 && isset($node->publish_on) && $node->publish_on != NULL) || (isset($node->unpublish_on) && $node->unpublish_on != NULL)) { + if (($node->status == 0 && isset($node->publish_on) && $node->publish_on != NULL && $node->publish_on > $now) || (isset($node->unpublish_on) && $node->unpublish_on != NULL)) { db_query('UPDATE {scheduler} SET publish_on = %d, unpublish_on = %d WHERE nid = %d', $node->publish_on, $node->unpublish_on, $node->nid); } else { @@ -425,7 +459,7 @@ } } // node doesn't exist, create a record only if the (un)publish fields are blank - elseif ((isset($node->publish_on) && $node->publish_on != NULL) || (isset($node->unpublish_on) && $node->unpublish_on != NULL)) { + elseif ((isset($node->publish_on) && $node->publish_on != NULL && $node->publish_on > $now) || (isset($node->unpublish_on) && $node->unpublish_on != NULL)) { db_query('INSERT INTO {scheduler} (nid, publish_on, unpublish_on) VALUES (%d, %d, %d)', $node->nid, $node->publish_on, $node->unpublish_on); } }