summaryrefslogtreecommitdiff
path: root/itjs.class
diff options
context:
space:
mode:
authorUrban Müller2013-10-16 16:09:38 +0000
committerUrban Müller2013-10-16 16:09:38 +0000
commitdf01a22705e1d560d3932fd482f5dcf2ecb5eca7 (patch)
treef02467aa5fc5f1cb4bf38e7fc5b72c6c8cbb4e8a /itjs.class
parent481159435fa6d3acc2532e1c3af181c2375a1e9d (diff)
downloaditools-df01a22705e1d560d3932fd482f5dcf2ecb5eca7.tar.gz
itools-df01a22705e1d560d3932fd482f5dcf2ecb5eca7.tar.bz2
itools-df01a22705e1d560d3932fd482f5dcf2ecb5eca7.zip
compute checksum over actually used files, cache checksum, kill checksum in delivery
Diffstat (limited to 'itjs.class')
-rw-r--r--itjs.class29
1 files changed, 20 insertions, 9 deletions
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));
}
}