Subversion Repositories oidplus

Rev

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

Rev Author Line No. Line
362 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
 
364 daniel-mar 20
use MatthiasMullie\Minify;
362 daniel-mar 21
 
364 daniel-mar 22
require_once __DIR__ . '/../includes/oidplus.inc.php';
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';
362 daniel-mar 26
 
364 daniel-mar 27
error_reporting(E_ALL);
362 daniel-mar 28
 
364 daniel-mar 29
$files = array();
30
 
31
$files[] = __DIR__ . '/../3p/sha3_js/sha3.js'; // https://github.com/emn178/js-sha3
32
 
33
$files[] = 'var DEFAULT_LANGUAGE = '.json_encode(OIDplus::DEFAULT_LANGUAGE).';';
34
 
362 daniel-mar 35
OIDplus::registerAllPlugins('language', 'OIDplusLanguagePlugin', null);
36
$translation_array = OIDplus::getTranslationArray();
364 daniel-mar 37
$files[] = 'var language_messages = '.json_encode($translation_array).';';
362 daniel-mar 38
 
39
//$tbl_prefix = OIDplus::baseConfig()->getValue('OIDPLUS_TABLENAME_PREFIX','');
40
//$files[] = 'var language_tblprefix = '.json_encode($tbl_prefix).';';
364 daniel-mar 41
$files[] = 'var language_tblprefix = "<tableprefix>";'; // hide OIDPLUS_TABLENAME_PREFIX from the client
362 daniel-mar 42
 
364 daniel-mar 43
$files[] = 'var setupdir = "'.((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://" . $_SERVER["HTTP_HOST"] . dirname($_SERVER['REQUEST_URI'])).'/";';
44
$files[] = 'var rebuild_callbacks = [];';
45
$files[] = 'var rebuild_config_callbacks = [];';
46
$files[] = 'var plugin_combobox_change_callbacks = [];';
362 daniel-mar 47
 
48
$found_db_plugins = 0;
49
OIDplus::registerAllPlugins('database', 'OIDplusDatabasePlugin', null);
50
foreach (get_declared_classes() as $c) {
51
        if (is_subclass_of($c, 'OIDplusDatabasePlugin')) {
364 daniel-mar 52
                $files[] = $c::setupJS();
362 daniel-mar 53
        }
54
}
55
 
364 daniel-mar 56
$files[] = __DIR__ . '/setup_base.js';
362 daniel-mar 57
 
364 daniel-mar 58
# ---
59
 
60
$minifier = null;
61
$out = '';
62
 
63
foreach ($files as $file) {
64
        if (OIDplus::baseConfig()->getValue('MINIFY_JS', true)) {
65
                if (is_null($minifier)) {
66
                        $minifier = new Minify\JS($file);
67
                } else {
68
                        $minifier->add($file);
69
                }
70
        } else {
71
                if (file_exists($file)) {
72
                        $out .= file_get_contents($file)."\n";
73
                } else {
74
                        $out .= "$file\n";
75
                }
76
        }
77
}
78
 
79
if (OIDplus::baseConfig()->getValue('MINIFY_JS', true)) {
80
        $out = $minifier->minify();
81
}
82
 
83
# ---
84
 
362 daniel-mar 85
$etag = md5($out);
86
header("Etag: $etag");
87
header('Content-MD5: '.$etag); // RFC 2616 clause 14.15
88
if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && (trim($_SERVER['HTTP_IF_NONE_MATCH']) == $etag)) {
89
        header("HTTP/1.1 304 Not Modified");
90
} else {
91
        header('Content-Type:application/javascript');
92
        echo $out;
364 daniel-mar 93
}