Completed
Push — master ( 8dbcbc...f734af )
by Nazar
07:14
created

Controller   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 11

Importance

Changes 6
Bugs 0 Features 1
Metric Value
wmc 20
c 6
b 0
f 1
lcom 0
cbo 11
dl 0
loc 64
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 0 16 2
D save() 0 40 18
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\admin;
11
use
12
	cs\Cache,
13
	cs\Config,
14
	cs\Event,
15
	cs\Index,
16
	cs\Language,
17
	cs\Page,
18
	cs\Text,
19
	cs\modules\System\admin\Controller\components,
20
	cs\modules\System\admin\Controller\general,
21
	cs\modules\System\admin\Controller\users,
22
	cs\modules\System\admin\Controller\users_save,
23
	cs\modules\System\admin\Controller\layout_elements;
24
25
class Controller {
26
	use
27
		components,
28
		general,
29
		users,
30
		users_save,
31
		layout_elements;
32
	static function index (
33
		/** @noinspection PhpUnusedParameterInspection */
34
		$route_ids,
35
		$route_path
36
	) {
37
		$L           = Language::instance();
38
		$Page        = Page::instance();
39
		$save_method = "$route_path[0]_$route_path[1]_save";
40
		if (method_exists(__CLASS__, $save_method)) {
41
			self::$save_method();
42
		} else {
43
			self::save();
44
		}
45
		$Page->title($L->{$route_path[0]});
46
		$Page->title($L->{$route_path[1]});
47
	}
48
	static function save () {
49
		$Index  = Index::instance();
50
		$Config = Config::instance();
51
		if (isset($_POST['apply']) || isset($_POST['save'])) {
52
			foreach (['core', 'db', 'storage', 'components'] as $part) {
53
				if (isset($_POST[$part])) {
54
					$temp = &$Config->$part;
55
					foreach ($_POST[$part] as $item => $value) {
56
						switch ($item) {
57
							case 'ip_black_list':
58
							case 'ip_admin_list':
59
								$value = _trim(explode("\n", $value));
60
								if ($value[0] == '') {
61
									$value = [];
62
								}
63
						}
64
						$temp[$item] = xap($value, true);
65
					}
66
					unset($item, $value);
67
				}
68
			}
69
			unset($part);
70
		}
71
		$Cache = Cache::instance();
72
		if (isset($_POST['apply']) && $Cache->cache_state()) {
73
			/** @noinspection NotOptimalIfConditionsInspection */
74
			if ($Index->apply() && !$Config->core['cache_compress_js_css']) {
75
				clean_pcache();
76
				Event::instance()->fire('admin/System/general/optimization/clean_pcache');
77
			}
78
		} elseif (isset($_POST['save'])) {
79
			$save = $Index->save();
80
			if ($save && !$Config->core['cache_compress_js_css']) {
81
				clean_pcache();
82
				Event::instance()->fire('admin/System/general/optimization/clean_pcache');
83
			}
84
		} /** @noinspection NotOptimalIfConditionsInspection */ elseif (isset($_POST['cancel']) && $Cache->cache_state()) {
85
			$Index->cancel();
86
		}
87
	}
88
}
89