|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @package CleverStyle CMS |
|
4
|
|
|
* @subpackage System module |
|
5
|
|
|
* @category modules |
|
6
|
|
|
* @author Nazar Mokrynskyi <[email protected]> |
|
7
|
|
|
* @copyright Copyright (c) 2015, Nazar Mokrynskyi |
|
8
|
|
|
* @license MIT License, see license.txt |
|
9
|
|
|
*/ |
|
10
|
|
|
namespace cs\modules\System\api\Controller\admin; |
|
11
|
|
|
use |
|
12
|
|
|
cs\Cache, |
|
13
|
|
|
cs\Config, |
|
14
|
|
|
cs\ExitException, |
|
15
|
|
|
cs\Page; |
|
16
|
|
|
trait optimization { |
|
17
|
|
|
/** |
|
18
|
|
|
* Get optimization settings |
|
19
|
|
|
*/ |
|
20
|
|
|
static function admin_optimization_get_settings () { |
|
21
|
|
|
$Config = Config::instance(); |
|
22
|
|
|
Page::instance()->json( |
|
23
|
|
|
[ |
|
24
|
|
|
'cache_compress_js_css' => $Config->core['cache_compress_js_css'], |
|
25
|
|
|
'vulcanization' => $Config->core['vulcanization'], |
|
26
|
|
|
'put_js_after_body' => $Config->core['put_js_after_body'], |
|
27
|
|
|
'inserts_limit' => $Config->core['inserts_limit'], |
|
28
|
|
|
'update_ratio' => $Config->core['update_ratio'], |
|
29
|
|
|
'cache_state' => Cache::instance()->cache_state(), |
|
30
|
|
|
'simple_admin_mode' => $Config->core['simple_admin_mode'], |
|
31
|
|
|
'applied' => $Config->cancel_available() |
|
32
|
|
|
] |
|
33
|
|
|
); |
|
34
|
|
|
} |
|
35
|
|
|
/** |
|
36
|
|
|
* Clean cache |
|
37
|
|
|
* |
|
38
|
|
|
* @throws ExitException |
|
39
|
|
|
*/ |
|
40
|
|
|
static function admin_optimization_clean_cache () { |
|
41
|
|
|
$Cache = Cache::instance(); |
|
42
|
|
|
time_limit_pause(); |
|
43
|
|
|
if (@$_POST['path_prefix']) { |
|
44
|
|
|
$result = $Cache->del($_POST['path_prefix']); |
|
45
|
|
|
} else { |
|
46
|
|
|
$result = $Cache->clean(); |
|
47
|
|
|
clean_classes_cache(); |
|
48
|
|
|
} |
|
49
|
|
|
time_limit_pause(false); |
|
50
|
|
|
if (!$result) { |
|
51
|
|
|
throw new ExitException(500); |
|
52
|
|
|
} |
|
53
|
|
|
$Cache->disable(); |
|
54
|
|
|
} |
|
55
|
|
|
/** |
|
56
|
|
|
* Clean public cache (CSS/JS/HTML) |
|
57
|
|
|
* |
|
58
|
|
|
* @throws ExitException |
|
59
|
|
|
*/ |
|
60
|
|
|
static function admin_optimization_clean_pcache () { |
|
61
|
|
|
if (!clean_pcache()) { |
|
62
|
|
|
throw new ExitException(500); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
/** |
|
66
|
|
|
* Apply optimization settings |
|
67
|
|
|
* |
|
68
|
|
|
* @throws ExitException |
|
69
|
|
|
*/ |
|
70
|
|
|
static function admin_optimization_apply_settings () { |
|
71
|
|
|
static::admin_optimization_settings_common(); |
|
72
|
|
|
if (!Config::instance()->apply()) { |
|
73
|
|
|
throw new ExitException(500); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
/** |
|
77
|
|
|
* @throws ExitException |
|
78
|
|
|
*/ |
|
79
|
|
|
protected static function admin_optimization_settings_common () { |
|
80
|
|
|
if (!isset( |
|
81
|
|
|
$_POST['cache_compress_js_css'], |
|
82
|
|
|
$_POST['vulcanization'], |
|
83
|
|
|
$_POST['put_js_after_body'], |
|
84
|
|
|
$_POST['inserts_limit'], |
|
85
|
|
|
$_POST['update_ratio'] |
|
86
|
|
|
) |
|
87
|
|
|
) { |
|
88
|
|
|
throw new ExitException(400); |
|
89
|
|
|
} |
|
90
|
|
|
$Config = Config::instance(); |
|
91
|
|
|
$Config->core['cache_compress_js_css'] = (int)(bool)$_POST['cache_compress_js_css']; |
|
92
|
|
|
$Config->core['vulcanization'] = (int)(bool)$_POST['vulcanization']; |
|
93
|
|
|
$Config->core['put_js_after_body'] = (int)(bool)$_POST['put_js_after_body']; |
|
94
|
|
|
$Config->core['inserts_limit'] = (int)$_POST['inserts_limit']; |
|
95
|
|
|
$Config->core['update_ratio'] = (int)$_POST['update_ratio']; |
|
96
|
|
|
} |
|
97
|
|
|
/** |
|
98
|
|
|
* Save optimization settings |
|
99
|
|
|
* |
|
100
|
|
|
* @throws ExitException |
|
101
|
|
|
*/ |
|
102
|
|
|
static function admin_optimization_save_settings () { |
|
103
|
|
|
static::admin_optimization_settings_common(); |
|
104
|
|
|
if (!Config::instance()->save()) { |
|
105
|
|
|
throw new ExitException(500); |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
/** |
|
109
|
|
|
* Cancel optimization settings |
|
110
|
|
|
* |
|
111
|
|
|
* @throws ExitException |
|
112
|
|
|
*/ |
|
113
|
|
|
static function admin_optimization_cancel_settings () { |
|
114
|
|
|
if (!Config::instance()->cancel()) { |
|
115
|
|
|
throw new ExitException(500); |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
|