Subversion Repositories oidplus

Rev

Rev 456 | Rev 481 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
364 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
 
22
require_once __DIR__ . '/../includes/oidplus.inc.php';
462 daniel-mar 23
 
364 daniel-mar 24
require_once __DIR__ . '/../3p/minify/path-converter/ConverterInterface.php';
25
require_once __DIR__ . '/../3p/minify/path-converter/Converter.php';
26
require_once __DIR__ . '/../3p/minify/src/Minify.php';
27
require_once __DIR__ . '/../3p/minify/src/CSS.php';
28
require_once __DIR__ . '/../3p/minify/src/Exception.php';
29
 
462 daniel-mar 30
error_reporting(OIDplus::baseConfig()->getValue('DEBUG') ? E_ALL : 0);
364 daniel-mar 31
 
32
$out = '';
33
 
34
# ---
35
 
429 daniel-mar 36
$do_minify = OIDplus::baseConfig()->getValue('MINIFY_CSS', true);
37
 
364 daniel-mar 38
function process_file($filename) {
429 daniel-mar 39
        global $do_minify;
40
 
41
        if (!file_exists($filename)) return;
42
 
364 daniel-mar 43
        $dir = dirname((strpos($filename, __DIR__.'/') === 0) ? substr($filename, strlen(__DIR__.'/')) : $filename);
429 daniel-mar 44
        if ($do_minify) {
364 daniel-mar 45
                $minifier = new Minify\CSS($filename);
46
                $cont = $minifier->minify();
47
                $cont = str_ireplace("url(data:", "url###(data:", $cont);
48
                $cont = str_ireplace("url(", "url(".$dir.'/', $cont);
49
        } else {
50
                $cont = file_get_contents($filename);
51
                $cont = str_ireplace('url("data:', 'url###("data:', $cont);
52
                $cont = str_ireplace('url("', 'url("'.$dir.'/', $cont);
53
                $cont = str_ireplace("url('data:", "url###('data:", $cont);
54
                $cont = str_ireplace("url('", "url('".$dir.'/', $cont);
55
        }
56
        $cont = str_ireplace("url###(", "url(", $cont);
57
        return $cont."\n\n";
58
}
59
 
60
# ---
61
 
411 daniel-mar 62
// Third-party products
63
// (None)
380 daniel-mar 64
 
411 daniel-mar 65
// OIDplus basic definitions
364 daniel-mar 66
if (file_exists(__DIR__ . '/../userdata/styles/setup_base.css')) {
67
        $out .= process_file(__DIR__ . '/../userdata/styles/setup_base.css');
68
} else {
456 daniel-mar 69
        $out .= process_file(__DIR__ . '/includes/setup_base.css');
364 daniel-mar 70
}
71
 
411 daniel-mar 72
// Then plugins
73
OIDplus::registerAllPlugins('database', 'OIDplusDatabasePlugin', array('OIDplus','registerDatabasePlugin'));
74
$manifests = OIDplus::getAllPluginManifests('database', true);
75
foreach ($manifests as $manifest) {
76
        foreach ($manifest->getCSSFilesSetup() as $css_file) {
77
                $out .= process_file($css_file);
78
        }
79
}
80
 
81
// Now user-defined definitions
366 daniel-mar 82
if (file_exists(__DIR__ . '/userdata/styles/setup_add.css')) {
83
        $out .= process_file(__DIR__ . '/userdata/styles/setup_add.css');
84
}
85
 
364 daniel-mar 86
# ---
87
 
379 daniel-mar 88
httpOutWithETag($out, 'text/css', 'oidplus_setup.css');