Subversion Repositories oidplus

Rev

Rev 261 | Rev 307 | 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';
112 daniel-mar 23
require_once __DIR__ . '/3p/minify/src/Minify.php';
24
require_once __DIR__ . '/3p/minify/src/JS.php';
25
require_once __DIR__ . '/3p/minify/src/Exception.php';
26
 
27
error_reporting(E_ALL);
28
 
215 daniel-mar 29
$files = array();
112 daniel-mar 30
 
215 daniel-mar 31
$files[] = __DIR__ . '/3p/jquery/jquery-2.2.1.min.js'; // We are using jQuery 2.2.1, because 3.3.1 seems to be incompatible with jsTree (HTML content will not be loaded into jsTree!) TODO: File bug report
32
$files[] = __DIR__ . '/3p/bootstrap/js/bootstrap.min.js';
33
$files[] = __DIR__ . '/3p/jstree/jstree.min.js';
34
$files[] = __DIR__ . '/3p/tinymce/tinymce.min.js';
35
$files[] = __DIR__ . '/3p/jquery-ui/jquery-ui.min.js';
36
$files[] = __DIR__ . '/3p/layout/jquery.layout.min.js';
37
$files[] = __DIR__ . '/3p/spamspan/spamspan.js';
38
$files[] = __DIR__ . '/3p/bignumber.js/bignumber.min.js';
39
$files[] = __DIR__ . '/3p/sha3_js/sha3.js'; // https://github.com/emn178/js-sha3
40
 
41
$files[] = __DIR__ . '/oidplus_base.js';
42
 
277 daniel-mar 43
$ary = OIDplus::getAllPluginManifests('*Pages');
44
foreach ($ary as $plugintype_folder => $bry) {
45
        foreach ($bry as $pluginname_folder => $cry) {
46
                if (!isset($cry['JavaScript'])) continue;
47
                foreach ($cry['JavaScript'] as $dry_name => $dry) {
48
                        if ($dry_name != 'file') continue;
49
                        foreach ($dry as $js_file) {
50
                                $files[] = __DIR__ . '/plugins/'.$plugintype_folder.'/'.$pluginname_folder.'/'.$js_file;
51
                        }
52
                }
53
        }
54
}
112 daniel-mar 55
 
215 daniel-mar 56
# ---
57
 
58
$minifier = null;
261 daniel-mar 59
$out = '';
215 daniel-mar 60
 
61
foreach ($files as $file) {
261 daniel-mar 62
        if (OIDplus::baseConfig()->getValue('MINIFY_JS', true)) {
63
                if (is_null($minifier)) {
64
                        $minifier = new Minify\JS($file);
65
                } else {
66
                        $minifier->add($file);
67
                }
215 daniel-mar 68
        } else {
261 daniel-mar 69
                $out .= file_get_contents($file)."\n";
215 daniel-mar 70
        }
71
}
72
 
261 daniel-mar 73
if (OIDplus::baseConfig()->getValue('RECAPTCHA_ENABLED', false) == true) {
74
        if (OIDplus::baseConfig()->getValue('MINIFY_JS', true)) {
75
                $minifier->add('oidplus_external_recaptcha();');
76
        } else {
77
                $out .= "oidplus_external_recaptcha();\n";
78
        }
218 daniel-mar 79
}
80
 
261 daniel-mar 81
if (OIDplus::baseConfig()->getValue('DISABLE_MSIE_COMPAT', false) == false) {
82
        if (OIDplus::baseConfig()->getValue('MINIFY_JS', true)) {
83
                $minifier->add('oidplus_external_polyfill();');
84
        } else {
85
                $out .= "oidplus_external_polyfill();\n";
86
        }
218 daniel-mar 87
}
88
 
261 daniel-mar 89
if (OIDplus::baseConfig()->getValue('MINIFY_JS', true)) {
90
        $out = $minifier->minify();
91
}
218 daniel-mar 92
 
112 daniel-mar 93
$etag = md5($out);
94
header("Etag: $etag");
95
if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && (trim($_SERVER['HTTP_IF_NONE_MATCH']) == $etag)) {
96
        header("HTTP/1.1 304 Not Modified");
97
} else {
98
        header('Content-Type:application/javascript');
99
        echo $out;
100
}