From fbc1fdd0b7244d2f03164b62eb893223ff930319 Mon Sep 17 00:00:00 2001 From: ewinslow Date: Sat, 12 Feb 2011 01:07:33 +0000 Subject: Converted most forms to use elgg_view_form (therefore also moved the views to forms/*). Some views are left that _only_ do elgg_view_form, so I wonder if those should even be kept around. git-svn-id: http://code.elgg.org/elgg/trunk@8127 36083f99-b078-4883-b0ff-0f9b5a30f544 --- mod/minify/lib/min/utils.php | 90 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 mod/minify/lib/min/utils.php (limited to 'mod/minify/lib/min/utils.php') diff --git a/mod/minify/lib/min/utils.php b/mod/minify/lib/min/utils.php new file mode 100644 index 000000000..c73594152 --- /dev/null +++ b/mod/minify/lib/min/utils.php @@ -0,0 +1,90 @@ + + * + * + * + * + * If you do not want ampersands as HTML entities, set Minify_Build::$ampersand = "&" + * before using this function. + * + * @param string $group a key from groupsConfig.php + * @param boolean $forceAmpersand (default false) Set to true if the RewriteRule + * directives in .htaccess are functional. This will remove the "?" from URIs, making them + * more cacheable by proxies. + * @return string + */ +function Minify_groupUri($group, $forceAmpersand = false) +{ + $path = $forceAmpersand + ? "/g={$group}" + : "/?g={$group}"; + return _Minify_getBuild($group)->uri( + '/' . basename(dirname(__FILE__)) . $path + ,$forceAmpersand + ); +} + + +/** + * Get the last modification time of the source js/css files used by Minify to + * build the page. + * + * If you're caching the output of Minify_groupUri(), you'll want to rebuild + * the cache if it's older than this timestamp. + * + * + * // simplistic HTML cache system + * $file = '/path/to/cache/file'; + * if (! file_exists($file) || filemtime($file) < Minify_groupsMtime(array('js', 'css'))) { + * // (re)build cache + * $page = buildPage(); // this calls Minify_groupUri() for js and css + * file_put_contents($file, $page); + * echo $page; + * exit(); + * } + * readfile($file); + * + * + * @param array $groups an array of keys from groupsConfig.php + * @return int Unix timestamp of the latest modification + */ +function Minify_groupsMtime($groups) +{ + $max = 0; + foreach ((array)$groups as $group) { + $max = max($max, _Minify_getBuild($group)->lastModified); + } + return $max; +} + +/** + * @param string $group a key from groupsConfig.php + * @return Minify_Build + * @private + */ +function _Minify_getBuild($group) +{ + static $builds = array(); + static $gc = false; + if (false === $gc) { + $gc = (require dirname(__FILE__) . '/groupsConfig.php'); + } + if (! isset($builds[$group])) { + $builds[$group] = new Minify_Build($gc[$group]); + } + return $builds[$group]; +} -- cgit v1.2.3