3 * Utility functions for generating group URIs in HTML files
5 * Before including this file, /min/lib must be in your include_path.
10 require_once 'Minify/Build.php';
14 * Get a timestamped URI to a minified resource using the default Minify install
17 * <link rel="stylesheet" type="text/css" href="<?php echo Minify_groupUri('css'); ?>" />
18 * <script type="text/javascript" src="<?php echo Minify_groupUri('js'); ?>"></script>
21 * If you do not want ampersands as HTML entities, set Minify_Build::$ampersand = "&"
22 * before using this function.
24 * @param string $group a key from groupsConfig.php
25 * @param boolean $forceAmpersand (default false) Set to true if the RewriteRule
26 * directives in .htaccess are functional. This will remove the "?" from URIs, making them
27 * more cacheable by proxies.
30 function Minify_groupUri($group, $forceAmpersand = false)
32 $path = $forceAmpersand
35 return _Minify_getBuild($group)->uri(
36 '/' . basename(dirname(__FILE__)) . $path
43 * Get the last modification time of the source js/css files used by Minify to
46 * If you're caching the output of Minify_groupUri(), you'll want to rebuild
47 * the cache if it's older than this timestamp.
50 * // simplistic HTML cache system
51 * $file = '/path/to/cache/file';
52 * if (! file_exists($file) || filemtime($file) < Minify_groupsMtime(array('js', 'css'))) {
54 * $page = buildPage(); // this calls Minify_groupUri() for js and css
55 * file_put_contents($file, $page);
62 * @param array $groups an array of keys from groupsConfig.php
63 * @return int Unix timestamp of the latest modification
65 function Minify_groupsMtime($groups)
68 foreach ((array)$groups as $group) {
69 $max = max($max, _Minify_getBuild($group)->lastModified);
75 * @param string $group a key from groupsConfig.php
76 * @return Minify_Build
79 function _Minify_getBuild($group)
81 static $builds = array();
84 $gc = (require dirname(__FILE__) . '/groupsConfig.php');
86 if (! isset($builds[$group])) {
87 $builds[$group] = new Minify_Build($gc[$group]);
89 return $builds[$group];