Rev 448 | Rev 473 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 448 | Rev 462 | ||
---|---|---|---|
Line 18... | Line 18... | ||
18 | */ |
18 | */ |
19 | 19 | ||
20 | use MatthiasMullie\Minify; |
20 | use MatthiasMullie\Minify; |
21 | 21 | ||
22 | require_once __DIR__ . '/includes/oidplus.inc.php'; |
22 | require_once __DIR__ . '/includes/oidplus.inc.php'; |
- | 23 | ||
23 | require_once __DIR__ . '/3p/minify/path-converter/ConverterInterface.php'; |
24 | require_once __DIR__ . '/3p/minify/path-converter/ConverterInterface.php'; |
24 | require_once __DIR__ . '/3p/minify/path-converter/Converter.php'; |
25 | require_once __DIR__ . '/3p/minify/path-converter/Converter.php'; |
25 | require_once __DIR__ . '/3p/minify/src/Minify.php'; |
26 | require_once __DIR__ . '/3p/minify/src/Minify.php'; |
26 | require_once __DIR__ . '/3p/minify/src/CSS.php'; |
27 | require_once __DIR__ . '/3p/minify/src/CSS.php'; |
27 | require_once __DIR__ . '/3p/minify/src/Exception.php'; |
28 | require_once __DIR__ . '/3p/minify/src/Exception.php'; |
28 | 29 | ||
29 | error_reporting(E_ALL); |
30 | error_reporting(OIDplus::baseConfig()->getValue('DEBUG') ? E_ALL : 0); |
30 | 31 | ||
31 | $out = ''; |
32 | $out = ''; |
32 | 33 | ||
33 | # --- |
34 | # --- |
34 | 35 | ||
35 | $do_minify = OIDplus::baseConfig()->getValue('MINIFY_CSS', true); |
36 | $do_minify = OIDplus::baseConfig()->getValue('MINIFY_CSS', true); |
36 | 37 | ||
37 | function process_file($filename) { |
38 | function process_file($filename) { |
38 | global $do_minify; |
39 | global $do_minify; |
39 | 40 | ||
- | 41 | $filename_min = preg_replace('/\.[^.]+$/', '.min.css', $filename); |
|
40 | if (!file_exists($filename)) return; |
42 | $filename_full = $filename; |
41 | 43 | ||
42 | $dir = dirname((strpos($filename, __DIR__.'/') === 0) ? substr($filename, strlen(__DIR__.'/')) : $filename); |
- | |
43 | if ($do_minify) { |
44 | if ($do_minify) { |
- | 45 | if (file_exists($filename_min)) { |
|
- | 46 | // There is a file which is already minified |
|
- | 47 | $filename = $filename_min; |
|
- | 48 | $cont = file_get_contents($filename); |
|
- | 49 | } else if (file_exists($filename_full)) { |
|
- | 50 | // Otherwise, we minify it ourself |
|
- | 51 | $filename = $filename_full; |
|
44 | $minifier = new Minify\CSS($filename); |
52 | $minifier = new Minify\CSS($filename); |
45 | $cont = $minifier->minify(); |
53 | $cont = $minifier->minify(); |
46 | } else { |
54 | } else { |
- | 55 | return; |
|
- | 56 | } |
|
- | 57 | } else { |
|
- | 58 | if (file_exists($filename_full)) { |
|
- | 59 | $filename = $filename_full; |
|
47 | $cont = file_get_contents($filename); |
60 | $cont = file_get_contents($filename); |
- | 61 | } else if (file_exists($filename_min)) { |
|
- | 62 | $filename = $filename_min; |
|
- | 63 | $cont = file_get_contents($filename); |
|
- | 64 | } else { |
|
- | 65 | return; |
|
- | 66 | } |
|
48 | } |
67 | } |
- | 68 | ||
- | 69 | $dir = dirname((strpos($filename, __DIR__.'/') === 0) ? substr($filename, strlen(__DIR__.'/')) : $filename); |
|
49 | $cont = preg_replace('@url\\(\s+@ism', 'url(', $cont); |
70 | $cont = preg_replace('@url\\(\s+@ism', 'url(', $cont); |
50 | $cont = str_ireplace('url("data:', 'url###("data:', $cont); |
71 | $cont = str_ireplace('url("data:', 'url###("data:', $cont); |
51 | $cont = str_ireplace('url("', 'url###("'.$dir.'/', $cont); |
72 | $cont = str_ireplace('url("', 'url###("'.$dir.'/', $cont); |
52 | $cont = str_ireplace("url('data:", "url###('data:", $cont); |
73 | $cont = str_ireplace("url('data:", "url###('data:", $cont); |
53 | $cont = str_ireplace("url('", "url###('".$dir.'/', $cont); |
74 | $cont = str_ireplace("url('", "url###('".$dir.'/', $cont); |
Line 58... | Line 79... | ||
58 | } |
79 | } |
59 | 80 | ||
60 | # --- |
81 | # --- |
61 | 82 | ||
62 | // Third-party products |
83 | // Third-party products |
63 | $out .= process_file(__DIR__ . '/3p/jstree/themes/default/style'.($do_minify ? '.min' : '').'.css'); |
84 | $out .= process_file(__DIR__ . '/3p/jstree/themes/default/style.css'); |
64 | $out .= process_file(__DIR__ . '/3p/jquery-ui/jquery-ui'.($do_minify ? '.min' : '').'.css'); |
85 | $out .= process_file(__DIR__ . '/3p/jquery-ui/jquery-ui.css'); |
65 | $out .= process_file(__DIR__ . '/3p/bootstrap4/css/bootstrap'.($do_minify ? '.min' : '').'.css'); |
86 | $out .= process_file(__DIR__ . '/3p/bootstrap4/css/bootstrap.css'); |
66 | 87 | ||
67 | // Find out base CSS |
88 | // Find out base CSS |
68 | if (isset($_REQUEST['theme'])) { |
89 | if (isset($_REQUEST['theme'])) { |
69 | $theme = $_REQUEST['theme']; |
90 | $theme = $_REQUEST['theme']; |
70 | if (strpos($theme,'/') !== false) $theme = 'default'; |
91 | if (strpos($theme,'/') !== false) $theme = 'default'; |