- Patch #41133 by DriesK: as of PHP 5.1.0, strtotime() returns FALSE on failure instead of -1.

Changed code to be compatible with all versions.
4.7.x
Dries Buytaert 2005-12-15 16:02:50 +00:00
parent 264f7d5667
commit 5accfa08f5
7 changed files with 19 additions and 17 deletions

View File

@ -599,7 +599,7 @@ function drupal_page_header() {
// Check http headers: // Check http headers:
$modified_since = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? $_SERVER['HTTP_IF_MODIFIED_SINCE'] == $date : NULL; $modified_since = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? $_SERVER['HTTP_IF_MODIFIED_SINCE'] == $date : NULL;
if (!empty($_SERVER['HTTP_IF_MODIFIED_SINCE']) && ($timestamp = strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])) != -1) { if (!empty($_SERVER['HTTP_IF_MODIFIED_SINCE']) && ($timestamp = strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])) > 0) {
$modified_since = $cache->created <= $timestamp; $modified_since = $cache->created <= $timestamp;
} }
else { else {

View File

@ -484,7 +484,7 @@ function aggregator_parse_w3cdtf($date_str) {
return $epoch; return $epoch;
} }
else { else {
return -1; return FALSE;
} }
} }
@ -580,10 +580,10 @@ function aggregator_parse_feed(&$data, $feed) {
else if ($item['MODIFIED']) $date = $item['MODIFIED']; // Atom XML else if ($item['MODIFIED']) $date = $item['MODIFIED']; // Atom XML
else $date = 'now'; else $date = 'now';
$timestamp = strtotime($date); // strtotime() returns -1 on failure $timestamp = strtotime($date); // As of PHP 5.1.0, strtotime returns FALSE on failure instead of -1.
if ($timestamp < 0) { if ($timestamp <= 0) {
$timestamp = aggregator_parse_w3cdtf($date); // also returns -1 on failure $timestamp = aggregator_parse_w3cdtf($date); // Returns FALSE on failure
if ($timestamp < 0) { if (!$timestamp) {
$timestamp = time(); // better than nothing $timestamp = time(); // better than nothing
} }
} }

View File

@ -484,7 +484,7 @@ function aggregator_parse_w3cdtf($date_str) {
return $epoch; return $epoch;
} }
else { else {
return -1; return FALSE;
} }
} }
@ -580,10 +580,10 @@ function aggregator_parse_feed(&$data, $feed) {
else if ($item['MODIFIED']) $date = $item['MODIFIED']; // Atom XML else if ($item['MODIFIED']) $date = $item['MODIFIED']; // Atom XML
else $date = 'now'; else $date = 'now';
$timestamp = strtotime($date); // strtotime() returns -1 on failure $timestamp = strtotime($date); // As of PHP 5.1.0, strtotime returns FALSE on failure instead of -1.
if ($timestamp < 0) { if ($timestamp <= 0) {
$timestamp = aggregator_parse_w3cdtf($date); // also returns -1 on failure $timestamp = aggregator_parse_w3cdtf($date); // Returns FALSE on failure
if ($timestamp < 0) { if (!$timestamp) {
$timestamp = time(); // better than nothing $timestamp = time(); // better than nothing
} }
} }

View File

@ -517,7 +517,8 @@ function comment_validate(&$edit) {
} }
else { else {
$date = isset($edit['date']) ? $edit['date'] : 'now'; $date = isset($edit['date']) ? $edit['date'] : 'now';
if (strtotime($date) != -1) { // As of PHP 5.1.0, strtotime returns FALSE upon failure instead of -1.
if (strtotime($date) > 0) {
$edit['timestamp'] = strtotime($date); $edit['timestamp'] = strtotime($date);
} }
else { else {

View File

@ -517,7 +517,8 @@ function comment_validate(&$edit) {
} }
else { else {
$date = isset($edit['date']) ? $edit['date'] : 'now'; $date = isset($edit['date']) ? $edit['date'] : 'now';
if (strtotime($date) != -1) { // As of PHP 5.1.0, strtotime returns FALSE upon failure instead of -1.
if (strtotime($date) > 0) {
$edit['timestamp'] = strtotime($date); $edit['timestamp'] = strtotime($date);
} }
else { else {

View File

@ -1544,8 +1544,8 @@ function node_validate($node) {
form_set_error('name', t('The username %name does not exist.', array ('%name' => theme('placeholder', $node->name)))); form_set_error('name', t('The username %name does not exist.', array ('%name' => theme('placeholder', $node->name))));
} }
// Validate the "authored on" field. // Validate the "authored on" field. As of PHP 5.1.O, strtotime returns FALSE instead of -1 upon failure.
if (strtotime($node->date) == -1) { if (strtotime($node->date) <= 0) {
form_set_error('date', t('You have to specify a valid date.')); form_set_error('date', t('You have to specify a valid date.'));
} }
} }

View File

@ -1544,8 +1544,8 @@ function node_validate($node) {
form_set_error('name', t('The username %name does not exist.', array ('%name' => theme('placeholder', $node->name)))); form_set_error('name', t('The username %name does not exist.', array ('%name' => theme('placeholder', $node->name))));
} }
// Validate the "authored on" field. // Validate the "authored on" field. As of PHP 5.1.O, strtotime returns FALSE instead of -1 upon failure.
if (strtotime($node->date) == -1) { if (strtotime($node->date) <= 0) {
form_set_error('date', t('You have to specify a valid date.')); form_set_error('date', t('You have to specify a valid date.'));
} }
} }