From e5b0e5f76c0695a01d13c55147a8287df8750594 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Sat, 6 Sep 2008 08:36:22 +0000 Subject: - Patch #302763 by Dave Reid, Rob Loach: replace time() by ['REQUEST_TIME'] as per Rasmus' suggestion. Removed drupal_referrer() for consistency. --- includes/bootstrap.inc | 13 ++----------- includes/cache.inc | 14 +++++++------- includes/common.inc | 14 +++++++------- includes/file.inc | 2 +- includes/form.inc | 12 ++++++------ includes/session.inc | 10 +++++----- 6 files changed, 28 insertions(+), 37 deletions(-) (limited to 'includes') diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc index 6de48d6e4..78a41f732 100644 --- a/includes/bootstrap.inc +++ b/includes/bootstrap.inc @@ -707,15 +707,6 @@ function drupal_unpack($obj, $field = 'data') { return $obj; } -/** - * Return the URI of the referring page. - */ -function referer_uri() { - if (isset($_SERVER['HTTP_REFERER'])) { - return $_SERVER['HTTP_REFERER']; - } -} - /** * Encode special characters in a plain-text string for display as HTML. * @@ -825,9 +816,9 @@ function watchdog($type, $message, $variables = array(), $severity = WATCHDOG_NO 'link' => $link, 'user' => $user, 'request_uri' => $base_root . request_uri(), - 'referer' => referer_uri(), + 'referer' => $_SERVER['HTTP_REFERER'], 'ip' => ip_address(), - 'timestamp' => time(), + 'timestamp' => $_SERVER['REQUEST_TIME'], ); // Call the logging hooks to log/process the message diff --git a/includes/cache.inc b/includes/cache.inc index 58e75e106..7c17e5484 100644 --- a/includes/cache.inc +++ b/includes/cache.inc @@ -17,7 +17,7 @@ function cache_get($cid, $table = 'cache') { // Garbage collection necessary when enforcing a minimum cache lifetime $cache_flush = variable_get('cache_flush', 0); - if ($cache_flush && ($cache_flush + variable_get('cache_lifetime', 0) <= time())) { + if ($cache_flush && ($cache_flush + variable_get('cache_lifetime', 0) <= $_SERVER['REQUEST_TIME'])) { // Reset the variable immediately to prevent a meltdown in heavy load situations. variable_set('cache_flush', 0); // Time to flush old cache data @@ -101,7 +101,7 @@ function cache_get($cid, $table = 'cache') { function cache_set($cid, $data, $table = 'cache', $expire = CACHE_PERMANENT, $headers = NULL) { $fields = array( 'serialized' => 0, - 'created' => time(), + 'created' => $_SERVER['REQUEST_TIME'], 'expire' => $expire, 'headers' => $headers, ); @@ -152,23 +152,23 @@ function cache_clear_all($cid = NULL, $table = NULL, $wildcard = FALSE) { // will be saved into the sessions table by sess_write(). We then // simulate that the cache was flushed for this user by not returning // cached data that was cached before the timestamp. - $user->cache = time(); + $user->cache = $_SERVER['REQUEST_TIME']; $cache_flush = variable_get('cache_flush', 0); if ($cache_flush == 0) { // This is the first request to clear the cache, start a timer. - variable_set('cache_flush', time()); + variable_set('cache_flush', $_SERVER['REQUEST_TIME']); } - else if (time() > ($cache_flush + variable_get('cache_lifetime', 0))) { + else if ($_SERVER['REQUEST_TIME'] > ($cache_flush + variable_get('cache_lifetime', 0))) { // Clear the cache for everyone, cache_flush_delay seconds have // passed since the first request to clear the cache. - db_query("DELETE FROM {" . $table . "} WHERE expire != %d AND expire < %d", CACHE_PERMANENT, time()); + db_query("DELETE FROM {" . $table . "} WHERE expire != %d AND expire < %d", CACHE_PERMANENT, $_SERVER['REQUEST_TIME']); variable_set('cache_flush', 0); } } else { // No minimum cache lifetime, flush all temporary cache entries now. - db_query("DELETE FROM {" . $table . "} WHERE expire != %d AND expire < %d", CACHE_PERMANENT, time()); + db_query("DELETE FROM {" . $table . "} WHERE expire != %d AND expire < %d", CACHE_PERMANENT, $_SERVER['REQUEST_TIME']); } } else { diff --git a/includes/common.inc b/includes/common.inc index dae0b0d61..be43d6638 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -873,7 +873,7 @@ function valid_url($url, $absolute = FALSE) { * The name of an event. */ function flood_register_event($name) { - db_query("INSERT INTO {flood} (event, hostname, timestamp) VALUES ('%s', '%s', %d)", $name, ip_address(), time()); + db_query("INSERT INTO {flood} (event, hostname, timestamp) VALUES ('%s', '%s', %d)", $name, ip_address(), $_SERVER['REQUEST_TIME']); } /** @@ -890,7 +890,7 @@ function flood_register_event($name) { * True if the user did not exceed the hourly threshold. False otherwise. */ function flood_is_allowed($name, $threshold) { - $number = db_result(db_query("SELECT COUNT(*) FROM {flood} WHERE event = '%s' AND hostname = '%s' AND timestamp > %d", $name, ip_address(), time() - 3600)); + $number = db_result(db_query("SELECT COUNT(*) FROM {flood} WHERE event = '%s' AND hostname = '%s' AND timestamp > %d", $name, ip_address(), $_SERVER['REQUEST_TIME'] - 3600)); return ($number < $threshold ? TRUE : FALSE); } @@ -2074,7 +2074,7 @@ function drupal_get_js($scope = 'header', $javascript = NULL) { // browser-caching. The string changes on every update or full cache // flush, forcing browsers to load a new copy of the files, as the // URL changed. Files that should not be cached (see drupal_add_js()) - // get time() as query-string instead, to enforce reload on every + // get $_SERVER['REQUEST_TIME'] as query-string instead, to enforce reload on every // page request. $query_string = '?' . substr(variable_get('css_js_query_string', '0'), 0, 1); @@ -2101,7 +2101,7 @@ function drupal_get_js($scope = 'header', $javascript = NULL) { // Additionally, go through any remaining scripts if JS preprocessing is on and output the non-cached ones. foreach ($data as $path => $info) { if (!$info['preprocess'] || !$is_writable || !$preprocess_js) { - $no_preprocess[$type] .= '\n"; + $no_preprocess[$type] .= '\n"; } else { $files[$path] = $info; @@ -2553,7 +2553,7 @@ function drupal_cron_run() { $semaphore = variable_get('cron_semaphore', FALSE); if ($semaphore) { - if (time() - $semaphore > 3600) { + if ($_SERVER['REQUEST_TIME'] - $semaphore > 3600) { // Either cron has been running for more than an hour or the semaphore // was not reset due to a database error. watchdog('cron', 'Cron has been running for more than an hour and is most likely stuck.', array(), WATCHDOG_ERROR); @@ -2571,13 +2571,13 @@ function drupal_cron_run() { register_shutdown_function('drupal_cron_cleanup'); // Lock cron semaphore - variable_set('cron_semaphore', time()); + variable_set('cron_semaphore', $_SERVER['REQUEST_TIME']); // Iterate through the modules calling their cron handlers (if any): module_invoke_all('cron'); // Record cron time - variable_set('cron_last', time()); + variable_set('cron_last', $_SERVER['REQUEST_TIME']); watchdog('cron', 'Cron run completed.', array(), WATCHDOG_NOTICE); // Release cron semaphore diff --git a/includes/file.inc b/includes/file.inc index 1be451823..abf5f69e4 100644 --- a/includes/file.inc +++ b/includes/file.inc @@ -613,7 +613,7 @@ function file_save_upload($source, $validators = array(), $dest = FALSE, $replac // If we made it this far it's safe to record this file in the database. $file->uid = $user->uid; $file->status = FILE_STATUS_TEMPORARY; - $file->timestamp = time(); + $file->timestamp = $_SERVER['REQUEST_TIME']; drupal_write_record('files', $file); // Add file to the cache. diff --git a/includes/form.inc b/includes/form.inc index f8341cc5b..d50c9efeb 100644 --- a/includes/form.inc +++ b/includes/form.inc @@ -235,9 +235,9 @@ function form_set_cache($form_build_id, $form, $form_state) { // 6 hours cache life time for forms should be plenty. $expire = 21600; - cache_set('form_' . $form_build_id, $form, 'cache_form', time() + $expire); + cache_set('form_' . $form_build_id, $form, 'cache_form', $_SERVER['REQUEST_TIME'] + $expire); if (!empty($form_state['storage'])) { - cache_set('storage_' . $form_build_id, $form_state['storage'], 'cache_form', time() + $expire); + cache_set('storage_' . $form_build_id, $form_state['storage'], 'cache_form', $_SERVER['REQUEST_TIME'] + $expire); } } @@ -1645,9 +1645,9 @@ function theme_date($element) { function form_process_date($element) { // Default to current date if (empty($element['#value'])) { - $element['#value'] = array('day' => format_date(time(), 'custom', 'j'), - 'month' => format_date(time(), 'custom', 'n'), - 'year' => format_date(time(), 'custom', 'Y')); + $element['#value'] = array('day' => format_date($_SERVER['REQUEST_TIME'], 'custom', 'j'), + 'month' => format_date($_SERVER['REQUEST_TIME'], 'custom', 'n'), + 'year' => format_date($_SERVER['REQUEST_TIME'], 'custom', 'Y')); } $element['#tree'] = TRUE; @@ -2483,7 +2483,7 @@ function batch_process($redirect = NULL, $url = NULL) { // Initiate db storage in order to get a batch id. We have to provide // at least an empty string for the (not null) 'token' column. - db_query("INSERT INTO {batch} (token, timestamp) VALUES ('', %d)", time()); + db_query("INSERT INTO {batch} (token, timestamp) VALUES ('', %d)", $_SERVER['REQUEST_TIME']); $batch['id'] = db_last_insert_id('batch', 'bid'); // Now that we have a batch id, we can generate the redirection link in diff --git a/includes/session.inc b/includes/session.inc index 13a043cef..ba579d5ee 100644 --- a/includes/session.inc +++ b/includes/session.inc @@ -73,17 +73,17 @@ function sess_write($key, $value) { // and gives more useful statistics. We can't eliminate anonymous session // table rows without breaking "Who's Online" block. if ($user->uid || $value || count($_COOKIE)) { - db_query("INSERT INTO {sessions} (sid, uid, cache, hostname, session, timestamp) VALUES ('%s', %d, %d, '%s', '%s', %d)", $key, $user->uid, isset($user->cache) ? $user->cache : 0, ip_address(), $value, time()); + db_query("INSERT INTO {sessions} (sid, uid, cache, hostname, session, timestamp) VALUES ('%s', %d, %d, '%s', '%s', %d)", $key, $user->uid, isset($user->cache) ? $user->cache : 0, ip_address(), $value, $_SERVER['REQUEST_TIME']); } } else { - db_query("UPDATE {sessions} SET uid = %d, cache = %d, hostname = '%s', session = '%s', timestamp = %d WHERE sid = '%s'", $user->uid, isset($user->cache) ? $user->cache : 0, ip_address(), $value, time(), $key); + db_query("UPDATE {sessions} SET uid = %d, cache = %d, hostname = '%s', session = '%s', timestamp = %d WHERE sid = '%s'", $user->uid, isset($user->cache) ? $user->cache : 0, ip_address(), $value, $_SERVER['REQUEST_TIME'], $key); if (db_affected_rows()) { // Last access time is updated no more frequently than once every 180 seconds. // This reduces contention in the users table. - if ($user->uid && time() - $user->access > variable_get('session_write_interval', 180)) { - db_query("UPDATE {users} SET access = %d WHERE uid = %d", time(), $user->uid); + if ($user->uid && $_SERVER['REQUEST_TIME'] - $user->access > variable_get('session_write_interval', 180)) { + db_query("UPDATE {users} SET access = %d WHERE uid = %d", $_SERVER['REQUEST_TIME'], $user->uid); } } } @@ -143,7 +143,7 @@ function sess_gc($lifetime) { // for three weeks before deleting them, you need to set gc_maxlifetime // to '1814400'. At that value, only after a user doesn't log in after // three weeks (1814400 seconds) will his/her session be removed. - db_query("DELETE FROM {sessions} WHERE timestamp < %d", time() - $lifetime); + db_query("DELETE FROM {sessions} WHERE timestamp < %d", $_SERVER['REQUEST_TIME'] - $lifetime); return TRUE; } -- cgit v1.2.3