-
Notifications
You must be signed in to change notification settings - Fork 103
/
assets.php
71 lines (56 loc) · 2 KB
/
assets.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/*
* Uses Minify by Matthias Mullie, https://github.com/matthiasmullie/minify
*/
$request = array_merge($_GET, $_POST);
$type = $request['type'];
$suffix = $type == 'javascript' ? 'js' : $type;
header('Content-Type: text/' . $type);
require_once 'lib/includes.php';
require_once 'lib/pagecache.php';
$key = hash('sha256', implode('|', $request['files']));
$cache = new Pagecache(const_path . 'temp/pagecache/' . config_cachefolder . '/' . $request['pages'] . '/' . $key . '.' . $suffix, config_cache);
echo '/** '.implode(' | ', $request['files']).' **/';
$path = 'vendor/MatthiasMullie';
require_once $path . '/minify/src/Minify.php';
require_once $path . '/minify/src/CSS.php';
require_once $path . '/minify/src/JS.php';
require_once $path . '/minify/src/Exception.php';
require_once $path . '/minify/src/Exceptions/BasicException.php';
require_once $path . '/minify/src/Exceptions/FileImportException.php';
require_once $path . '/minify/src/Exceptions/IOException.php';
require_once $path . '/path-converter/src/ConverterInterface.php';
require_once $path . '/path-converter/src/Converter.php';
if($type == 'javascript')
array_unshift($request['files'], 'console.log = function() {};');
foreach($request['files'] as $fileName) {
// if filename ends with '.php', evaluate it and add the result
if(substr_compare($fileName, '.php', -4) == 0) {
ob_start();
//$wd_was = getcwd();
chdir(dirname(const_path.$fileName));
include const_path.$fileName;
//chdir($wd_was);
chdir(dirname($_SERVER['SCRIPT_FILENAME']));
$rawcontent = ob_get_clean();
}
// otherwise just add it
else
$rawcontent = $fileName;
switch($type) {
case 'css':
$minifier = new MatthiasMullie\Minify\CSS($rawcontent);
break;
case 'js':
case 'javascript':
$minifier = new MatthiasMullie\Minify\JS($rawcontent);
break;
}
$content = "\n/* ".$fileName." */\n";
// get minified content
$content .= $minifier->execute("assets." . $type);
if($type == 'javascript')
$content .= ';';
$cache->append($content);
}
?>