-
Notifications
You must be signed in to change notification settings - Fork 0
/
javascript.php
84 lines (75 loc) · 1.76 KB
/
javascript.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
$scripts = [
// libs
'lib/gettext/Gettext',
'lib/color',
'lib/sprintf',
// helpers
'app',
'functions',
'ajax',
'movable',
// autorun - main
'msg',
'cover',
'dialog',
'deleter',
'collapsible',
'tables',
'rapid-edit',
// autorun - secondary
'rapid-change',
'theme',
'navigation',
'forms',
'keyboard',
'autocomplete',
'list-edit',
'list-select',
'search',
'autoprice',
'pager',
'xdebug',
'gallery',
'category',
'print',
'tabbed',
'person',
'tooltip',
];
define('JS_CACHE_FILE', 'files/js/cache.js');
$settings = new \App\Utils\Settings();
if($settings->disableResourcesCaching) {
\App\Utils\Msg::warning(t('Resources cache is disabled, enable it from the settings page'));
foreach($scripts as $script) {
?>
<script src="<?= config('publicbase') ?>/js/<?= $script ?>.js"></script>
<?php
}
if(file_exists(JS_CACHE_FILE)) {
unlink(JS_CACHE_FILE);
}
}
else {
$recreate = $settings->recreateCacheContinuously;
if(!file_exists(JS_CACHE_FILE) || $recreate) {
if($recreate) {
\App\Utils\Msg::warning(t('Resources cache recreated at every page request, disable it from the settings page'));
}
createJsCache($scripts);
}
?>
<script src="<?= config('publicbase') . '/' . JS_CACHE_FILE . cacheBuster() ?>"></script>
<?php
}
function createJsCache($scripts) {
$path = dirname(JS_CACHE_FILE);
if(!is_dir($path)) {
mkdir($path);
}
$cache_content = '';
foreach($scripts as $script) {
$cache_content .= file_get_contents('js/' . $script.'.js') . PHP_EOL;
}
file_put_contents(JS_CACHE_FILE, $cache_content);
}