summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--it_html.class3
-rw-r--r--itjs.class29
-rw-r--r--itjs.php15
3 files changed, 24 insertions, 23 deletions
diff --git a/it_html.class b/it_html.class
index 20b0c75..c7dfc22 100644
--- a/it_html.class
+++ b/it_html.class
@@ -217,10 +217,9 @@ function head($args = array())
if ($p['js'])
{
- $checksum = itjs::checksum(itjs::filenames($p['js']));
$js .= $this->_itjs("boot.js", "inline");
$js .= "function it_boot_start(){ " . trim($p['jsboot']) . " }\n";
- $js .= "it_boot('/itjs/" . U($p['js'], array('s' => $checksum)) . "');\n";
+ $js .= "it_boot('/itjs/" . U($p['js'], array('s' => itjs::checksum($p['js']))) . "');\n";
}
if ($js)
diff --git a/itjs.class b/itjs.class
index 46e3ff4..5aa13f0 100644
--- a/itjs.class
+++ b/itjs.class
@@ -149,6 +149,22 @@ static function filenames($filelist)
}
/**
+ * Return (interpreted) files that will be sent to client
+ */
+static function filecontents($filenames)
+{
+ foreach ($filenames as $filename)
+ {
+ ob_start(); # Needs to capture inside loop to guarantee file order
+ if (!(it::match('W3C_CSS_Validator', $_SERVER['HTTP_USER_AGENT']) && it::match('jquery-ui\.css', $filename)))
+ $result .= it::replace(array('^1$' => ""), @include($filename), array('utf8' => false));
+ $result .= ob_get_clean();
+ }
+
+ return $result;
+}
+
+/**
* Strip comments and trim lines
* @param $code String containing javascript code to be stripped
* @return Naked code
@@ -169,19 +185,14 @@ static function strip($code)
/**
* Compute checksum for list of files
- * @param $files Array of filenames to calculate checksum for
+ * @param $fnlist Either comma separated url or array of filenames to calculate checksum for
* @return Checksum for given files
*/
-static function checksum($files = array())
+static function checksum($fnlist)
{
- $itjs = "/www/server/phpinclude/itools/itjs";
- $itools_itjs = glob("$itjs/*.{js,css,php}", GLOB_BRACE);
- $service_itjs = glob($GLOBALS['ULTRAHOME'] . "/itjs/*.{js,css,php}", GLOB_BRACE);
-
- foreach (array_merge($files, $service_itjs, $itools_itjs, array("$itjs/itjs.php", "$itjs/itjs.class")) as $fn)
- $allfiles .= @file_get_contents($fn);
+ $key = "itjs_" . md5(join("", it::map('"$v" . filemtime("$v")', is_array($fnlist) ? $fnlist : itjs::filenames($fnlist))));
- return substr(md5($allfiles), 0, 8); # UTF8SAFE
+ return it_cache::get($key) ?: it_cache::put($key, substr(md5(self::filecontents(is_array($fnlist) ? $fnlist : itjs::filenames($fnlist))), 0, 8));
}
}
diff --git a/itjs.php b/itjs.php
index 65a78fe..90c9252 100644
--- a/itjs.php
+++ b/itjs.php
@@ -31,18 +31,9 @@ if ($_SERVER['HTTP_IF_NONE_MATCH'] && it::is_live() && !$_REQUEST['retry']) {
exit;
}
-$data = "";
$files = itjs::filenames(it::match('/itjs/([a-z0-9_,.-]*)', $_SERVER['PHP_SELF']));
-
-foreach ($files as $file)
-{
- ob_start(); # Needs to capture inside loop to guarantee file order
- if (!(it::match('W3C_CSS_Validator', $_SERVER['HTTP_USER_AGENT']) && it::match('jquery-ui\.css', $file)))
- $data .= it::replace(array('^1$' => ""), @include($file), array('utf8' => false));
- $data .= ob_get_clean();
-}
-
-$checksum = strlen($data) . itjs::checksum($files);
+$data = itjs::filecontents($files);
+$file = end($files);
if (it::match('\.gif$', $file))
{
@@ -67,7 +58,7 @@ else if (!it::match('\.html$', $file))
header("Content-Type: application/x-javascript; charset=$charset");
}
-@header("Etag: $checksum");
+@header("Etag: alwaysvalid");
if (!preg_match('/Opera/', $_SERVER['HTTP_USER_AGENT']) && it::is_live() && !$_REQUEST['retry'])
{