Completed
Push — master ( e47f7c...7b57ac )
by Nazar
04:14
created

system::admin_system_save_settings()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4286
cc 2
eloc 4
nc 2
nop 0
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\Config,
13
	cs\ExitException,
14
	cs\Page;
15
trait system {
16
	/**
17
	 * Get system settings
18
	 */
19
	static function admin_system_get_settings () {
20
		$Config = Config::instance();
21
		Page::instance()->json(
22
			[
23
				'site_mode'         => $Config->core['site_mode'],
24
				'closed_title'      => get_core_ml_text('closed_title'),
25
				'closed_text'       => get_core_ml_text('closed_text'),
26
				'title_delimiter'   => $Config->core['title_delimiter'],
27
				'title_reverse'     => $Config->core['title_reverse'],
28
				'show_tooltips'     => $Config->core['show_tooltips'],
29
				'simple_admin_mode' => $Config->core['simple_admin_mode'],
30
				'applied'           => $Config->cancel_available()
31
			]
32
		);
33
	}
34
	/**
35
	 * Apply system settings
36
	 *
37
	 * @throws ExitException
38
	 */
39
	static function admin_system_apply_settings () {
40
		static::admin_system_settings_common();
41
		if (!Config::instance()->apply()) {
42
			throw new ExitException(500);
43
		}
44
	}
45
	/**
46
	 * @throws ExitException
47
	 */
48
	protected static function admin_system_settings_common () {
49
		if (!isset(
50
			$_POST['site_mode'],
51
			$_POST['closed_title'],
52
			$_POST['closed_text'],
53
			$_POST['title_delimiter'],
54
			$_POST['title_reverse'],
55
			$_POST['show_tooltips'],
56
			$_POST['simple_admin_mode']
57
		)
58
		) {
59
			throw new ExitException(400);
60
		}
61
		$Config                            = Config::instance();
62
		$Config->core['site_mode']         = (int)(bool)$_POST['site_mode'];
63
		$Config->core['closed_title']      = set_core_ml_text('closed_title', xap($_POST['closed_title']));
64
		$Config->core['closed_text']       = set_core_ml_text('closed_text', xap($_POST['closed_text'], true));
65
		$Config->core['title_delimiter']   = xap($_POST['title_delimiter']);
66
		$Config->core['title_reverse']     = (int)(bool)$_POST['title_reverse'];
67
		$Config->core['show_tooltips']     = (int)(bool)$_POST['show_tooltips'];
68
		$Config->core['simple_admin_mode'] = (int)(bool)$_POST['simple_admin_mode'];
69
	}
70
	/**
71
	 * Save system settings
72
	 *
73
	 * @throws ExitException
74
	 */
75
	static function admin_system_save_settings () {
76
		static::admin_system_settings_common();
77
		if (!Config::instance()->save()) {
78
			throw new ExitException(500);
79
		}
80
	}
81
	/**
82
	 * Cancel system settings
83
	 *
84
	 * @throws ExitException
85
	 */
86
	static function admin_system_cancel_settings () {
87
		if (!Config::instance()->cancel()) {
88
			throw new ExitException(500);
89
		}
90
	}
91
}
92