1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @package Cadmium\System\Frames\Admin |
5
|
|
|
* @author Anton Romanov |
6
|
|
|
* @copyright Copyright (c) 2015-2017, Anton Romanov |
7
|
|
|
* @link http://cadmium-cms.com |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Frames\Admin { |
11
|
|
|
|
12
|
|
|
use Frames, Frames\Status, Modules\Auth, Ajax, Request, Template; |
13
|
|
|
|
14
|
|
|
abstract class Section extends Frames\Section { |
15
|
|
|
|
16
|
|
|
# Define active section |
17
|
|
|
|
18
|
|
|
const SECTION = SECTION_ADMIN; |
19
|
|
|
|
20
|
|
|
# Define phrases list |
21
|
|
|
|
22
|
|
|
const PHRASES = ['Admin', 'Ajax', 'Common', 'Install', 'Mail', 'Menuitem', 'Page', 'Range', 'User', 'Variable', 'Widget']; |
23
|
|
|
|
24
|
|
|
# Page settings |
25
|
|
|
|
26
|
|
|
protected $_title = ''; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Handle a form area request |
30
|
|
|
*/ |
31
|
|
|
|
32
|
|
|
private function handleFormArea() { |
33
|
|
|
|
34
|
|
|
# Check auth |
35
|
|
|
|
36
|
|
|
if (($this instanceof Area\Auth) && Auth::check()) Request::redirect(INSTALL_PATH . '/admin'); |
37
|
|
|
|
38
|
|
|
# Handle request |
39
|
|
|
|
40
|
|
|
if (Template::isBlock($result = $this->handle())) return (new View\Form($this->_title))->display($result); |
|
|
|
|
41
|
|
|
|
42
|
|
|
# ------------------------ |
43
|
|
|
|
44
|
|
|
return Status::displayError404(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Handle a panel area request |
49
|
|
|
*/ |
50
|
|
|
|
51
|
|
|
private function handlePanelArea() { |
52
|
|
|
|
53
|
|
|
# Check auth |
54
|
|
|
|
55
|
|
|
if (!Auth::check() || ((false !== Request::get('logout')) && Auth::logout())) { |
56
|
|
|
|
57
|
|
|
Request::redirect(INSTALL_PATH . '/admin/login'); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
# Handle request |
61
|
|
|
|
62
|
|
|
$request = (!Request::isSpecial('navigate') ? 'display' : 'navigate'); |
63
|
|
|
|
64
|
|
|
$result = $this->handle(Request::isAjax() && ($request === 'display')); |
|
|
|
|
65
|
|
|
|
66
|
|
|
if (Template::isBlock($result)) return (new View\Panel($this->_title))->$request($result); |
67
|
|
|
|
68
|
|
|
if (Ajax::isResponse($result)) return Ajax::output($result); |
|
|
|
|
69
|
|
|
|
70
|
|
|
# ------------------------ |
71
|
|
|
|
72
|
|
|
return Status::displayError404(); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* The branch method for the admin section |
77
|
|
|
*/ |
78
|
|
|
|
79
|
|
|
protected function _section() { |
80
|
|
|
|
81
|
|
|
# Check for restricted access |
82
|
|
|
|
83
|
|
|
if ('' !== CONFIG_ADMIN_IP) { |
84
|
|
|
|
85
|
|
|
$ips = preg_split('/ +/', CONFIG_ADMIN_IP, -1, PREG_SPLIT_NO_EMPTY); |
86
|
|
|
|
87
|
|
|
if (!in_array(REQUEST_CLIENT_IP, $ips, true)) return Status::displayError404(); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
# Handle request |
91
|
|
|
|
92
|
|
|
if (($this instanceof Area\Auth) || ($this instanceof Area\Install)) return $this->handleFormArea(); |
93
|
|
|
|
94
|
|
|
if ($this instanceof Area\Panel) return $this->handlePanelArea(); |
95
|
|
|
|
96
|
|
|
# ------------------------ |
97
|
|
|
|
98
|
|
|
return Status::displayError404(); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.