Subversion Repositories oidplus

Rev

Rev 429 | Rev 462 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 429 Rev 448
1
<?php
1
<?php
2
 
2
 
3
/*
3
/*
4
 * OIDplus 2.0
4
 * OIDplus 2.0
5
 * Copyright 2019 Daniel Marschall, ViaThinkSoft
5
 * Copyright 2019 Daniel Marschall, ViaThinkSoft
6
 *
6
 *
7
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * Licensed under the Apache License, Version 2.0 (the "License");
8
 * you may not use this file except in compliance with 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
9
 * You may obtain a copy of the License at
10
 *
10
 *
11
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *     http://www.apache.org/licenses/LICENSE-2.0
12
 *
12
 *
13
 * Unless required by applicable law or agreed to in writing, software
13
 * Unless required by applicable law or agreed to in writing, software
14
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * distributed under the License is distributed on an "AS IS" BASIS,
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 * See the License for the specific language governing permissions and
16
 * See the License for the specific language governing permissions and
17
 * limitations under the License.
17
 * limitations under the License.
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
require_once __DIR__ . '/../3p/minify/src/Minify.php';
23
require_once __DIR__ . '/../3p/minify/src/Minify.php';
24
require_once __DIR__ . '/../3p/minify/src/JS.php';
24
require_once __DIR__ . '/../3p/minify/src/JS.php';
25
require_once __DIR__ . '/../3p/minify/src/Exception.php';
25
require_once __DIR__ . '/../3p/minify/src/Exception.php';
26
 
26
 
27
error_reporting(E_ALL);
27
error_reporting(E_ALL);
28
 
28
 
29
$files = array();
29
$files = array();
30
 
30
 
31
$files[] = __DIR__ . '/../3p/sha3_js/sha3.js'; // https://github.com/emn178/js-sha3
31
$files[] = __DIR__ . '/../3p/sha3_js/sha3.js'; // https://github.com/emn178/js-sha3
32
 
32
 
33
$files[] = 'var DEFAULT_LANGUAGE = '.json_encode(OIDplus::DEFAULT_LANGUAGE).';';
33
$files[] = 'var DEFAULT_LANGUAGE = '.json_encode(OIDplus::DEFAULT_LANGUAGE).';';
34
 
34
 
35
OIDplus::registerAllPlugins('language', 'OIDplusLanguagePlugin', null);
35
OIDplus::registerAllPlugins('language', 'OIDplusLanguagePlugin', null);
36
$translation_array = OIDplus::getTranslationArray();
36
$translation_array = OIDplus::getTranslationArray();
37
$files[] = 'var language_messages = '.json_encode($translation_array).';';
37
$files[] = 'var language_messages = '.json_encode($translation_array).';';
38
 
38
 
39
//$tbl_prefix = OIDplus::baseConfig()->getValue('OIDPLUS_TABLENAME_PREFIX','');
39
//$tbl_prefix = OIDplus::baseConfig()->getValue('OIDPLUS_TABLENAME_PREFIX','');
40
//$files[] = 'var language_tblprefix = '.json_encode($tbl_prefix).';';
40
//$files[] = 'var language_tblprefix = '.json_encode($tbl_prefix).';';
41
$files[] = 'var language_tblprefix = "<tableprefix>";'; // hide OIDPLUS_TABLENAME_PREFIX from the client
41
$files[] = 'var language_tblprefix = "<tableprefix>";'; // hide OIDPLUS_TABLENAME_PREFIX from the client
42
 
42
 
43
$files[] = 'var setupdir = "'.((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://" . $_SERVER["HTTP_HOST"] . dirname($_SERVER['REQUEST_URI'])).'/";';
43
$files[] = 'var setupdir = "'.((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://" . $_SERVER["HTTP_HOST"] . dirname($_SERVER['REQUEST_URI'])).'/";';
44
$files[] = 'var rebuild_callbacks = [];';
44
$files[] = 'var rebuild_callbacks = [];';
45
$files[] = 'var rebuild_config_callbacks = [];';
45
$files[] = 'var rebuild_config_callbacks = [];';
46
$files[] = 'var plugin_combobox_change_callbacks = [];';
46
$files[] = 'var plugin_combobox_change_callbacks = [];';
47
 
47
 
48
OIDplus::registerAllPlugins('database', 'OIDplusDatabasePlugin', array('OIDplus','registerDatabasePlugin'));
48
OIDplus::registerAllPlugins('database', 'OIDplusDatabasePlugin', array('OIDplus','registerDatabasePlugin'));
49
$manifests = OIDplus::getAllPluginManifests('database', true);
49
$manifests = OIDplus::getAllPluginManifests('database', true);
50
foreach ($manifests as $manifest) {
50
foreach ($manifests as $manifest) {
51
        foreach ($manifest->getJsFilesSetup() as $js_file) {
51
        foreach ($manifest->getJsFilesSetup() as $js_file) {
52
                if (!file_exists($js_file)) {
52
                if (!file_exists($js_file)) {
53
                        $files[] = "console.error('Script file not found: $js_file');";
53
                        $files[] = "console.error('Script file not found: $js_file');";
54
                } else {
54
                } else {
55
                        $files[] = $js_file;
55
                        $files[] = $js_file;
56
                }
56
                }
57
        }
57
        }
58
}
58
}
59
 
59
 
60
$files[] = __DIR__ . '/setup_base.js';
60
$files[] = __DIR__ . '/includes/setup_base.js';
61
 
61
 
62
# ---
62
# ---
63
 
63
 
64
$minifier = null;
64
$minifier = null;
65
$out = '';
65
$out = '';
66
 
66
 
67
foreach ($files as $file) {
67
foreach ($files as $file) {
68
        if (OIDplus::baseConfig()->getValue('MINIFY_JS', true)) {
68
        if (OIDplus::baseConfig()->getValue('MINIFY_JS', true)) {
69
                if (is_null($minifier)) {
69
                if (is_null($minifier)) {
70
                        $minifier = new Minify\JS($file);
70
                        $minifier = new Minify\JS($file);
71
                } else {
71
                } else {
72
                        $minifier->add($file);
72
                        $minifier->add($file);
73
                }
73
                }
74
        } else {
74
        } else {
75
                if (file_exists($file)) {
75
                if (file_exists($file)) {
76
                        $out .= file_get_contents($file)."\n";
76
                        $out .= file_get_contents($file)."\n";
77
                } else {
77
                } else {
78
                        $out .= "$file\n";
78
                        $out .= "$file\n";
79
                }
79
                }
80
        }
80
        }
81
}
81
}
82
 
82
 
83
if (OIDplus::baseConfig()->getValue('MINIFY_JS', true)) {
83
if (OIDplus::baseConfig()->getValue('MINIFY_JS', true)) {
84
        $out = $minifier->minify();
84
        $out = $minifier->minify();
85
}
85
}
86
 
86
 
87
# ---
87
# ---
88
 
88
 
89
httpOutWithETag($out, 'application/javascript', 'oidplus_setup.js');
89
httpOutWithETag($out, 'application/javascript', 'oidplus_setup.js');
90
 
90