Merge branch 'MDL-37523_M23' of git://github.com/lazydaisy/moodle into MOODLE_23_STABLE
[moodle.git] / lib / minify / utils.php
bloba18d7ad10b83089c59bbe2d806ae1eb015fa3ea7
1 <?php
2 /**
3 * Utility functions for generating URIs in HTML files
5 * @package Minify
6 */
8 require_once dirname(__FILE__) . '/lib/Minify/HTML/Helper.php';
12 * Get an HTML-escaped Minify URI for a group or set of files. By default, URIs
13 * will contain timestamps to allow far-future Expires headers.
15 * <code>
16 * <link rel="stylesheet" type="text/css" href="<?= Minify_getUri('css'); ?>" />
17 * <script src="<?= Minify_getUri('js'); ?>"></script>
18 * <script src="<?= Minify_getUri(array(
19 * '//scripts/file1.js'
20 * ,'//scripts/file2.js'
21 * )); ?>"></script>
22 * </code>
24 * @param mixed $keyOrFiles a group key or array of file paths/URIs
25 * @param array $opts options:
26 * 'farExpires' : (default true) append a modified timestamp for cache revving
27 * 'debug' : (default false) append debug flag
28 * 'charset' : (default 'UTF-8') for htmlspecialchars
29 * 'minAppUri' : (default '/min') URI of min directory
30 * 'rewriteWorks' : (default true) does mod_rewrite work in min app?
31 * 'groupsConfigFile' : specify if different
32 * @return string
34 function Minify_getUri($keyOrFiles, $opts = array())
36 return Minify_HTML_Helper::getUri($keyOrFiles, $opts);
40 /**
41 * Get the last modification time of several source js/css files. If you're
42 * caching the output of Minify_getUri(), you might want to know if one of the
43 * dependent source files has changed so you can update the HTML.
45 * Since this makes a bunch of stat() calls, you might not want to check this
46 * on every request.
48 * @param array $keysAndFiles group keys and/or file paths/URIs.
49 * @return int latest modification time of all given keys/files
51 function Minify_mtime($keysAndFiles, $groupsConfigFile = null)
53 $gc = null;
54 if (! $groupsConfigFile) {
55 $groupsConfigFile = dirname(__FILE__) . '/groupsConfig.php';
57 $sources = array();
58 foreach ($keysAndFiles as $keyOrFile) {
59 if (is_object($keyOrFile)
60 || 0 === strpos($keyOrFile, '/')
61 || 1 === strpos($keyOrFile, ':\\')) {
62 // a file/source obj
63 $sources[] = $keyOrFile;
64 } else {
65 if (! $gc) {
66 $gc = (require $groupsConfigFile);
68 foreach ($gc[$keyOrFile] as $source) {
69 $sources[] = $source;
73 return Minify_HTML_Helper::getLastModified($sources);