Passed
Push — master ( a357e7...195a07 )
by Anton
04:22 queued 01:11
created

Section::displayForm()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 38
Code Lines 11

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 38
rs 8.8571
cc 2
eloc 11
nc 2
nop 2
1
<?php
2
3
namespace Frames\Admin {
4
5
	use Frames, Frames\Status, Modules\Auth, Modules\Extend, Utils\Messages, Utils\Popup, Utils\View;
6
	use DB, Debug, Language, Template;
7
8
	abstract class Section extends Frames\Section {
9
10
		# Define active section
11
12
		const SECTION = SECTION_ADMIN;
13
14
		# Define phrases list
15
16
		const PHRASES = ['Admin', 'Ajax', 'Common', 'Install', 'Mail', 'Menuitem', 'Page', 'Range', 'User', 'Variable', 'Widget'];
17
18
		# Page settings
19
20
		protected $title = '', $layout = 'Page';
21
22
		# Get layout
23
24
		private function getLayout(Template\Block $contents) {
25
26
			$layout = View::get('Layouts/' . $this->layout);
27
28
			# Set menu and user
29
30
			if (Auth::check()) {
31
32
				$layout->menu = View::get('Blocks/Utils/Menu');
33
34
				$layout->getBlock('user')->gravatar = Auth::user()->gravatar;
35
36
				$layout->getBlock('user')->name = Auth::user()->name;
37
38
				$layout->getBlock('user')->id = Auth::user()->id;
39
			}
40
41
			# Set title
42
43
			$layout->title = Language::get($this->title);
44
45
			# Set messages
46
47
			$layout->messages = Messages::block();
48
49
			# Set contents
50
51
			$layout->contents = $contents;
52
53
			# Set personalizer
54
55
			$layout->getBlock('language')->country = Extend\Languages::data('country');
56
57
			$layout->getBlock('language')->title = Extend\Languages::data('title');
58
59
			# Set copyright
60
61
			$layout->cadmium_home       = CADMIUM_HOME;
62
			$layout->cadmium_copy       = CADMIUM_COPY;
63
			$layout->cadmium_name       = CADMIUM_NAME;
64
			$layout->cadmium_version    = CADMIUM_VERSION;
65
66
			# Set popup
67
68
			$layout->popup = Popup::block();
69
70
			# Set report
71
72
			$layout->getBlock('report')->script_time = Debug::getTime();
73
74
			$layout->getBlock('report')->db_time = DB::getTime();
75
76
			# ------------------------
77
78
			return $layout;
79
		}
80
81
		# Display page
82
83
		protected function displayPage(Template\Block $contents, int $status = STATUS_CODE_200) {
84
85
			$page = View::get('Main/' . $this->layout);
86
87
			# Set language
88
89
			$page->language = Extend\Languages::data('iso');
90
91
			# Set title
92
93
			$page->title = ((('' !== $this->title) ? (Language::get($this->title) . ' | ') : '') . CADMIUM_NAME);
94
95
			# Set layout
96
97
			$page->layout = $this->getLayout($contents);
98
99
			# ------------------------
100
101
			Template::output($page, $status);
102
		}
103
104
		# Admin main method
105
106
		protected function section() {
107
108
			# Check for restricted access
109
110
			if ('' !== CONFIG_ADMIN_IP) {
111
112
				$ips = preg_split('/ +/', CONFIG_ADMIN_IP, -1, PREG_SPLIT_NO_EMPTY);
113
114
				if (!in_array(REQUEST_CLIENT_IP, $ips, true)) return Status::error404();
115
			}
116
117
			# ------------------------
118
119
			$this->area();
120
		}
121
	}
122
}
123