forked from Martin-Gleiss/smartvisu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
assets.php
73 lines (58 loc) · 2.33 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
72
73
<?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' && \defined('config_debug') && !config_debug)
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();
chdir(\dirname(const_path.$fileName));
include const_path.$fileName;
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";
// avoid errors thrown by minifying already minified highcharts .js files
if ( $type != 'css' && substr_compare($fileName, 'vendor/plot.highcharts', 0, 22) == 0 )
$content .= preg_replace('#\/\*\*.*?\*\/#s', '', file_get_contents($fileName), 1);
else
// get minified content and strip first multiline comment
$content .= preg_replace('#\/\*[\*!].*?\*\/\n?#s', '', $minifier->execute("assets." . $type), 1);
if($type == 'javascript')
$content .= ';';
$cache->append($content);
}
?>