From df01a22705e1d560d3932fd482f5dcf2ecb5eca7 Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Wed, 16 Oct 2013 16:09:38 +0000 Subject: compute checksum over actually used files, cache checksum, kill checksum in delivery --- itjs.class | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'itjs.class') diff --git a/itjs.class b/itjs.class index 46e3ff4..5aa13f0 100644 --- a/itjs.class +++ b/itjs.class @@ -148,6 +148,22 @@ static function filenames($filelist) return $result; } +/** + * 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 @@ -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)); } } -- cgit v1.2.3