summaryrefslogtreecommitdiff
path: root/kohana/helpers/expires.php
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2008-12-15 08:56:18 +0000
committerBharat Mediratta <bharat@menalto.com>2008-12-15 08:56:18 +0000
commit3b35e8b91ce94c292b46a296d034542ac5f0f6da (patch)
tree7a1444b5e16475b66300be105b8fc39e5117c881 /kohana/helpers/expires.php
parent628058b4ed5aefb543ceb6ca9d3b87828c66bef1 (diff)
Refresh kohana from upstream svn trunk r3771.
During this process, remove a considerable number of files from kohana that we will not be needing in Gallery3, including the following files and directories: kohana/application kohana/example.htaccess kohana/index.php kohana/install.php kohana/kohana.png kohana/modules/archive kohana/modules/auth kohana/modules/flot kohana/modules/gmaps kohana/modules/kodoc kohana/modules/payment kohana/modules/smarty kohana/modules/unit_test/i18n kohana/modules/unit_test/tests/Example_Test.php kohana/modules/unit_test/tests/Valid_Test.php kohana/system/config/captcha.php kohana/system/controllers/captcha.php kohana/system/fonts kohana/system/i18n kohana/system/libraries/Calendar.php kohana/system/libraries/Calendar_Event.php kohana/system/libraries/Captcha.php kohana/system/libraries/Tagcloud.php kohana/system/vendor kohana/system/views/pagination kohana/system/views/kohana_calendar.php
Diffstat (limited to 'kohana/helpers/expires.php')
-rw-r--r--kohana/helpers/expires.php110
1 files changed, 110 insertions, 0 deletions
diff --git a/kohana/helpers/expires.php b/kohana/helpers/expires.php
new file mode 100644
index 00000000..454cf12a
--- /dev/null
+++ b/kohana/helpers/expires.php
@@ -0,0 +1,110 @@
+<?php defined('SYSPATH') OR die('No direct access allowed.');
+/**
+ * Controls headers that effect client caching of pages
+ *
+ * $Id$
+ *
+ * @package Core
+ * @author Kohana Team
+ * @copyright (c) 2007-2008 Kohana Team
+ * @license http://kohanaphp.com/license.html
+ */
+class expires_Core {
+
+ /**
+ * Sets the amount of time before a page expires
+ *
+ * @param integer Seconds before the page expires
+ * @return boolean
+ */
+ public static function set($seconds = 60)
+ {
+ if (expires::check_headers())
+ {
+ $now = $expires = time();
+
+ // Set the expiration timestamp
+ $expires += $seconds;
+
+ // Send headers
+ header('Last-Modified: '.gmdate('D, d M Y H:i:s T', $now));
+ header('Expires: '.gmdate('D, d M Y H:i:s T', $expires));
+ header('Cache-Control: max-age='.$seconds);
+
+ return $expires;
+ }
+
+ return FALSE;
+ }
+
+ /**
+ * Checks to see if a page should be updated or send Not Modified status
+ *
+ * @param integer Seconds added to the modified time received to calculate what should be sent
+ * @return bool FALSE when the request needs to be updated
+ */
+ public static function check($seconds = 60)
+ {
+ if ( ! empty($_SERVER['HTTP_IF_MODIFIED_SINCE']) AND expires::check_headers())
+ {
+ if (($strpos = strpos($_SERVER['HTTP_IF_MODIFIED_SINCE'], ';')) !== FALSE)
+ {
+ // IE6 and perhaps other IE versions send length too, compensate here
+ $mod_time = substr($_SERVER['HTTP_IF_MODIFIED_SINCE'], 0, $strpos);
+ }
+ else
+ {
+ $mod_time = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
+ }
+
+ $mod_time = strtotime($mod_time);
+ $mod_time_diff = $mod_time + $seconds - time();
+
+ if ($mod_time_diff > 0)
+ {
+ // Re-send headers
+ header('Last-Modified: '.gmdate('D, d M Y H:i:s T', $mod_time));
+ header('Expires: '.gmdate('D, d M Y H:i:s T', time() + $mod_time_diff));
+ header('Cache-Control: max-age='.$mod_time_diff);
+ header('Status: 304 Not Modified', TRUE, 304);
+
+ // Prevent any output
+ Event::add('system.display', array('expires', 'prevent_output'));
+
+ // Exit to prevent other output
+ exit;
+ }
+ }
+
+ return FALSE;
+ }
+
+ /**
+ * Check headers already created to not step on download or Img_lib's feet
+ *
+ * @return boolean
+ */
+ public static function check_headers()
+ {
+ foreach (headers_list() as $header)
+ {
+ if (stripos($header, 'Last-Modified:') === 0 OR stripos($header, 'Expires:') === 0)
+ {
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+ }
+
+ /**
+ * Prevent any output from being displayed. Executed during system.display.
+ *
+ * @return void
+ */
+ public static function prevent_output()
+ {
+ Kohana::$output = '';
+ }
+
+} // End expires \ No newline at end of file