Rev 481 | Rev 490 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
112 | daniel-mar | 1 | <?php |
2 | |||
3 | /* |
||
4 | * OIDplus 2.0 |
||
5 | * Copyright 2019 Daniel Marschall, ViaThinkSoft |
||
6 | * |
||
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
||
8 | * you may not use this file except in compliance with the License. |
||
9 | * You may obtain a copy of the License at |
||
10 | * |
||
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
||
12 | * |
||
13 | * Unless required by applicable law or agreed to in writing, software |
||
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
||
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||
16 | * See the License for the specific language governing permissions and |
||
17 | * limitations under the License. |
||
18 | */ |
||
19 | |||
20 | use MatthiasMullie\Minify; |
||
21 | |||
261 | daniel-mar | 22 | require_once __DIR__ . '/includes/oidplus.inc.php'; |
462 | daniel-mar | 23 | |
112 | daniel-mar | 24 | require_once __DIR__ . '/3p/minify/path-converter/ConverterInterface.php'; |
25 | require_once __DIR__ . '/3p/minify/path-converter/Converter.php'; |
||
474 | daniel-mar | 26 | require_once __DIR__ . '/3p/minify/php-fig-cache/CacheItemInterface.php'; |
112 | daniel-mar | 27 | require_once __DIR__ . '/3p/minify/src/Minify.php'; |
28 | require_once __DIR__ . '/3p/minify/src/CSS.php'; |
||
29 | require_once __DIR__ . '/3p/minify/src/Exception.php'; |
||
30 | |||
462 | daniel-mar | 31 | error_reporting(OIDplus::baseConfig()->getValue('DEBUG') ? E_ALL : 0); |
486 | daniel-mar | 32 | @ini_set('display_errors', OIDplus::baseConfig()->getValue('DEBUG') ? 1 : 0); |
112 | daniel-mar | 33 | |
142 | daniel-mar | 34 | $out = ''; |
112 | daniel-mar | 35 | |
142 | daniel-mar | 36 | # --- |
112 | daniel-mar | 37 | |
420 | daniel-mar | 38 | $do_minify = OIDplus::baseConfig()->getValue('MINIFY_CSS', true); |
39 | |||
142 | daniel-mar | 40 | function process_file($filename) { |
420 | daniel-mar | 41 | global $do_minify; |
42 | |||
462 | daniel-mar | 43 | $filename_min = preg_replace('/\.[^.]+$/', '.min.css', $filename); |
44 | $filename_full = $filename; |
||
429 | daniel-mar | 45 | |
420 | daniel-mar | 46 | if ($do_minify) { |
462 | daniel-mar | 47 | if (file_exists($filename_min)) { |
48 | // There is a file which is already minified |
||
49 | $filename = $filename_min; |
||
50 | $cont = file_get_contents($filename); |
||
51 | } else if (file_exists($filename_full)) { |
||
52 | // Otherwise, we minify it ourself |
||
53 | $filename = $filename_full; |
||
54 | $minifier = new Minify\CSS($filename); |
||
55 | $cont = $minifier->minify(); |
||
56 | } else { |
||
57 | return; |
||
58 | } |
||
142 | daniel-mar | 59 | } else { |
462 | daniel-mar | 60 | if (file_exists($filename_full)) { |
61 | $filename = $filename_full; |
||
62 | $cont = file_get_contents($filename); |
||
63 | } else if (file_exists($filename_min)) { |
||
64 | $filename = $filename_min; |
||
65 | $cont = file_get_contents($filename); |
||
66 | } else { |
||
67 | return; |
||
68 | } |
||
142 | daniel-mar | 69 | } |
462 | daniel-mar | 70 | |
71 | $dir = dirname((strpos($filename, __DIR__.'/') === 0) ? substr($filename, strlen(__DIR__.'/')) : $filename); |
||
368 | daniel-mar | 72 | $cont = preg_replace('@url\\(\s+@ism', 'url(', $cont); |
73 | $cont = str_ireplace('url("data:', 'url###("data:', $cont); |
||
74 | $cont = str_ireplace('url("', 'url###("'.$dir.'/', $cont); |
||
75 | $cont = str_ireplace("url('data:", "url###('data:", $cont); |
||
76 | $cont = str_ireplace("url('", "url###('".$dir.'/', $cont); |
||
77 | $cont = str_ireplace("url(data:", "url###(data:", $cont); |
||
78 | $cont = str_ireplace("url(", "url###(".$dir.'/', $cont); |
||
142 | daniel-mar | 79 | $cont = str_ireplace("url###(", "url(", $cont); |
261 | daniel-mar | 80 | return $cont."\n\n"; |
142 | daniel-mar | 81 | } |
112 | daniel-mar | 82 | |
142 | daniel-mar | 83 | # --- |
112 | daniel-mar | 84 | |
411 | daniel-mar | 85 | // Third-party products |
462 | daniel-mar | 86 | $out .= process_file(__DIR__ . '/3p/jstree/themes/default/style.css'); |
87 | $out .= process_file(__DIR__ . '/3p/jquery-ui/jquery-ui.css'); |
||
88 | $out .= process_file(__DIR__ . '/3p/bootstrap4/css/bootstrap.css'); |
||
411 | daniel-mar | 89 | |
448 | daniel-mar | 90 | // Find out base CSS |
91 | if (isset($_REQUEST['theme'])) { |
||
92 | $theme = $_REQUEST['theme']; |
||
93 | if (strpos($theme,'/') !== false) $theme = 'default'; |
||
94 | if (strpos($theme,'\\') !== false) $theme = 'default'; |
||
95 | if (strpos($theme,'..') !== false) $theme = 'default'; |
||
96 | } else { |
||
97 | $theme = 'default'; |
||
98 | } |
||
99 | |||
364 | daniel-mar | 100 | if (file_exists(__DIR__ . '/userdata/styles/oidplus_base.css')) { |
473 | daniel-mar | 101 | // There is a user defined CSS (not recommended, use design plugins instead!) |
364 | daniel-mar | 102 | $out .= process_file(__DIR__ . '/userdata/styles/oidplus_base.css'); |
287 | daniel-mar | 103 | } else { |
473 | daniel-mar | 104 | // Use CSS of the design plugin |
105 | OIDplus::registerAllPlugins('design', 'OIDplusDesignPlugin', array('OIDplus','registerDesignPlugin')); |
||
106 | $plugins = OIDplus::getDesignPlugins(); |
||
107 | foreach ($plugins as $plugin) { |
||
108 | if ((basename($plugin->getPluginDirectory())) == $theme) { |
||
109 | $manifest = $plugin->getManifest(); |
||
110 | foreach ($manifest->getCSSFiles() as $css_file) { |
||
111 | $out .= process_file($css_file); |
||
112 | } |
||
113 | } |
||
114 | } |
||
287 | daniel-mar | 115 | } |
142 | daniel-mar | 116 | |
411 | daniel-mar | 117 | // Then plugins |
307 | daniel-mar | 118 | $manifests = OIDplus::getAllPluginManifests('*Pages', true); |
119 | foreach ($manifests as $manifest) { |
||
120 | foreach ($manifest->getCSSFiles() as $css_file) { |
||
121 | $out .= process_file($css_file); |
||
277 | daniel-mar | 122 | } |
142 | daniel-mar | 123 | } |
124 | |||
474 | daniel-mar | 125 | // Now user-defined (additional) definitions |
411 | daniel-mar | 126 | if (file_exists(__DIR__ . '/userdata/styles/oidplus_add.css')) { |
127 | $out .= process_file(__DIR__ . '/userdata/styles/oidplus_add.css'); |
||
128 | } |
||
142 | daniel-mar | 129 | |
130 | # --- |
||
131 | |||
286 | daniel-mar | 132 | $inv = isset($_REQUEST['invert']) ? $_REQUEST['invert'] : 0; |
133 | if ($inv != 0) { |
||
134 | $out = invertColorsOfCSS($out); |
||
135 | } |
||
136 | |||
142 | daniel-mar | 137 | $hs = isset($_REQUEST['h_shift']) ? $_REQUEST['h_shift'] : 0; |
138 | $ss = isset($_REQUEST['s_shift']) ? $_REQUEST['s_shift'] : 0; |
||
139 | $vs = isset($_REQUEST['v_shift']) ? $_REQUEST['v_shift'] : 0; |
||
286 | daniel-mar | 140 | if (($hs != 0) ||($ss != 0) || ($vs != 0)) { |
141 | $out = changeHueOfCSS($out, $hs, $ss, $vs); |
||
142 | } |
||
142 | daniel-mar | 143 | |
144 | # --- |
||
145 | |||
481 | daniel-mar | 146 | if (OIDplus::baseConfig()->getValue('DEBUG')) { |
147 | // In debug mode, we might get PHP error messages (see "error_reporting" above), |
||
148 | // so it would be severe if we would allow ETAG! (since $out does not contain the PHP error messages!) |
||
149 | header('Content-Type:text/css'); |
||
150 | echo $out; |
||
151 | } else { |
||
152 | httpOutWithETag($out, 'text/css', 'oidplus.css'); |
||
153 | } |