]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Minify/extlib/minify/min/utils.php
Issue #166 - we test exif data below, no need for error output
[quix0rs-gnu-social.git] / plugins / Minify / extlib / minify / min / utils.php
1 <?php
2 /**
3  * Utility functions for generating group URIs in HTML files
4  *
5  * Before including this file, /min/lib must be in your include_path.
6  * 
7  * @package Minify
8  */
9
10 require_once 'Minify/Build.php';
11
12
13 /**
14  * Get a timestamped URI to a minified resource using the default Minify install
15  *
16  * <code>
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>
19  * </code>
20  *
21  * If you do not want ampersands as HTML entities, set Minify_Build::$ampersand = "&" 
22  * before using this function.
23  *
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.
28  * @return string
29  */ 
30 function Minify_groupUri($group, $forceAmpersand = false)
31 {
32     $path = $forceAmpersand
33         ? "/g={$group}"
34         : "/?g={$group}";
35     return _Minify_getBuild($group)->uri(
36         '/' . basename(dirname(__FILE__)) . $path
37         ,$forceAmpersand
38     );
39 }
40
41
42 /**
43  * Get the last modification time of the source js/css files used by Minify to
44  * build the page.
45  * 
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.
48  * 
49  * <code>
50  * // simplistic HTML cache system
51  * $file = '/path/to/cache/file';
52  * if (! file_exists($file) || filemtime($file) < Minify_groupsMtime(array('js', 'css'))) {
53  *     // (re)build cache
54  *     $page = buildPage(); // this calls Minify_groupUri() for js and css
55  *     file_put_contents($file, $page);
56  *     echo $page;
57  *     exit();
58  * }
59  * readfile($file);
60  * </code>
61  *
62  * @param array $groups an array of keys from groupsConfig.php
63  * @return int Unix timestamp of the latest modification
64  */ 
65 function Minify_groupsMtime($groups)
66 {
67     $max = 0;
68     foreach ((array)$groups as $group) {
69         $max = max($max, _Minify_getBuild($group)->lastModified);
70     }
71     return $max;
72 }
73
74 /**
75  * @param string $group a key from groupsConfig.php
76  * @return Minify_Build
77  * @private
78  */
79 function _Minify_getBuild($group)
80 {
81     static $builds = array();
82     static $gc = false;
83     if (false === $gc) {
84         $gc = (require dirname(__FILE__) . '/groupsConfig.php');
85     }
86     if (! isset($builds[$group])) {
87         $builds[$group] = new Minify_Build($gc[$group]);
88     }
89     return $builds[$group];
90 }