Merge branch 'MDL-31998_27' of git://github.com/grabs/moodle into MOODLE_27_STABLE
[moodle.git] / lib / minify / utils.php
blob7cf930ac901266db11f1119948d8e0354f20ba6d
1 <?php
2 /**
3 * Utility functions for generating URIs in HTML files
5 * @warning These functions execute min/groupsConfig.php, sometimes multiple times.
6 * You must make sure that functions are not redefined, and if your use custom sources,
7 * you must require_once dirname(__FILE__) . '/lib/Minify/Source.php' so that
8 * class is available.
10 * @package Minify
13 if (! class_exists('Minify_Loader', false)) {
14 require dirname(__FILE__) . '/lib/Minify/Loader.php';
15 Minify_Loader::register();
19 * Get an HTML-escaped Minify URI for a group or set of files. By default, URIs
20 * will contain timestamps to allow far-future Expires headers.
22 * <code>
23 * <link rel="stylesheet" type="text/css" href="<?= Minify_getUri('css'); ?>" />
24 * <script src="<?= Minify_getUri('js'); ?>"></script>
25 * <script src="<?= Minify_getUri(array(
26 * '//scripts/file1.js'
27 * ,'//scripts/file2.js'
28 * )); ?>"></script>
29 * </code>
31 * @param mixed $keyOrFiles a group key or array of file paths/URIs
32 * @param array $opts options:
33 * 'farExpires' : (default true) append a modified timestamp for cache revving
34 * 'debug' : (default false) append debug flag
35 * 'charset' : (default 'UTF-8') for htmlspecialchars
36 * 'minAppUri' : (default '/min') URI of min directory
37 * 'rewriteWorks' : (default true) does mod_rewrite work in min app?
38 * 'groupsConfigFile' : specify if different
39 * @return string
41 function Minify_getUri($keyOrFiles, $opts = array())
43 return Minify_HTML_Helper::getUri($keyOrFiles, $opts);
47 /**
48 * Get the last modification time of several source js/css files. If you're
49 * caching the output of Minify_getUri(), you might want to know if one of the
50 * dependent source files has changed so you can update the HTML.
52 * Since this makes a bunch of stat() calls, you might not want to check this
53 * on every request.
55 * @param array $keysAndFiles group keys and/or file paths/URIs.
56 * @return int latest modification time of all given keys/files
58 function Minify_mtime($keysAndFiles, $groupsConfigFile = null)
60 $gc = null;
61 if (! $groupsConfigFile) {
62 $groupsConfigFile = dirname(__FILE__) . '/groupsConfig.php';
64 $sources = array();
65 foreach ($keysAndFiles as $keyOrFile) {
66 if (is_object($keyOrFile)
67 || 0 === strpos($keyOrFile, '/')
68 || 1 === strpos($keyOrFile, ':\\')) {
69 // a file/source obj
70 $sources[] = $keyOrFile;
71 } else {
72 if (! $gc) {
73 $gc = (require $groupsConfigFile);
75 foreach ($gc[$keyOrFile] as $source) {
76 $sources[] = $source;
80 return Minify_HTML_Helper::getLastModified($sources);