### Eclipse Workspace Patch 1.0 #P gaia-patch Index: app/sites/all/modules/contrib/scheduler/scheduler.module =================================================================== --- app/sites/all/modules/contrib/scheduler/scheduler.module (revision 8740) +++ app/sites/all/modules/contrib/scheduler/scheduler.module (working copy) @@ -7,7 +7,7 @@ * Implementation of hook_perm(). */ function scheduler_perm() { - return array('schedule (un)publishing of nodes', 'administer scheduler'); + return array('schedule (un)publishing of nodes', 'administer scheduler','publish on in the past'); } /** @@ -63,6 +63,7 @@ '#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)'), ); + return system_settings_form($form); } @@ -85,6 +86,12 @@ '#default_value' => variable_get('scheduler_touch_'. $form['#node_type']->type, 0), '#description' => t('Check this box to alter the published on time to match the scheduled time ("touch feature").') ); + $form['workflow']['scheduler_date_past'] = array( + '#type' => 'checkbox', + '#title' => t('Possibility to set publish on date in the past'), + '#default_value' => variable_get('scheduler_date_past_'. $form['#node_type']->type, 0), + '#description' => t('Check this box to allow \'publish on\' date in the past (only for users with \'publish on in the past\' permission).') + ); } // is this a node form? @@ -330,6 +337,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 +378,16 @@ $date_format = variable_get('scheduler_date_format', SCHEDULER_DATE_FORMAT); + // For some node type it could be possible to set previous 'publish' on date. + // It depends on node type and user permissions. + $permit_date_past = (variable_get('scheduler_date_past_'.$node->type, 0) && user_access('publish on in the past')); + 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 +398,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 +412,20 @@ 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()) { + if (isset($node->publish_on) && $node->publish_on != '' && is_numeric($node->publish_on)) { $node->status = 0; + // If publish_on is in the past change created date and remember real date for future aims + if ($permit_date_past && $node->publish_on < $now) { + $node->real_created = $node->created; + $node->created = $node->publish_on; + } } 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) || (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); } break;