1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Frames\Site { |
4
|
|
|
|
5
|
|
|
use Frames, Frames\Status, Modules\Auth, Modules\Extend, Modules\Settings, Utils\Menu, Utils\Messages, Utils\View; |
6
|
|
|
use Utils\Template\Variables, Utils\Template\Widgets, Date, Request, Template; |
7
|
|
|
|
8
|
|
|
abstract class Section extends Frames\Section { |
9
|
|
|
|
10
|
|
|
# Define active section |
11
|
|
|
|
12
|
|
|
const SECTION = SECTION_SITE; |
13
|
|
|
|
14
|
|
|
# Define phrases list |
15
|
|
|
|
16
|
|
|
const PHRASES = ['Common', 'Lister', 'Mail', 'Site', 'User']; |
17
|
|
|
|
18
|
|
|
# Section settings |
19
|
|
|
|
20
|
|
|
protected $title = '', $layout = 'Common'; |
21
|
|
|
|
22
|
|
|
protected $description = '', $keywords = '', $robots_index = false, $robots_follow = false, $canonical = ''; |
23
|
|
|
|
24
|
|
|
# Get layout |
25
|
|
|
|
26
|
|
|
private function getLayout(Template\Asset\Block $contents) { |
27
|
|
|
|
28
|
|
|
$layout = View::get('Layouts\\' . $this->layout); |
29
|
|
|
|
30
|
|
|
# Create layout components |
31
|
|
|
|
32
|
|
|
$menu = new Menu(); |
33
|
|
|
|
34
|
|
|
# Set menu |
35
|
|
|
|
36
|
|
|
$layout->menu = $menu->block(); |
37
|
|
|
|
38
|
|
|
# Set auth |
39
|
|
|
|
40
|
|
|
if (Settings::get('users_registration')) { |
41
|
|
|
|
42
|
|
|
if (!Auth::check()) $layout->block('auth')->enable(); else { |
43
|
|
|
|
44
|
|
|
$layout->block('user')->enable(); |
45
|
|
|
|
46
|
|
|
$layout->block('user')->gravatar = md5(strtolower(Auth::user()->email)); |
47
|
|
|
|
48
|
|
|
$layout->block('user')->name = Auth::user()->name; |
49
|
|
|
|
50
|
|
|
if (Auth::user()->rank === RANK_ADMINISTRATOR) $layout->block('user')->block('admin')->enable(); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
# Set title |
55
|
|
|
|
56
|
|
|
$layout->title = (('' !== $this->title) ? $this->title : Settings::get('site_title')); |
57
|
|
|
|
58
|
|
|
# Set slogan |
59
|
|
|
|
60
|
|
|
$layout->slogan = Settings::get('site_slogan'); |
61
|
|
|
|
62
|
|
|
# Set messages |
63
|
|
|
|
64
|
|
|
$layout->messages = Messages::block(); |
65
|
|
|
|
66
|
|
|
# Set contents |
67
|
|
|
|
68
|
|
|
$layout->contents = $contents; |
69
|
|
|
|
70
|
|
|
# Set copyright |
71
|
|
|
|
72
|
|
|
$layout->copyright = Date::year(); |
73
|
|
|
|
74
|
|
|
# Set powered by |
75
|
|
|
|
76
|
|
|
$layout->cadmium_home = CADMIUM_HOME; |
77
|
|
|
$layout->cadmium_name = CADMIUM_NAME; |
78
|
|
|
$layout->cadmium_version = CADMIUM_VERSION; |
79
|
|
|
|
80
|
|
|
# ------------------------ |
81
|
|
|
|
82
|
|
|
return $layout; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
# Display page |
86
|
|
|
|
87
|
|
|
private function displayPage(Template\Asset\Block $contents) { |
88
|
|
|
|
89
|
|
|
# Process template |
90
|
|
|
|
91
|
|
|
$page = View::get('Main\Page'); |
92
|
|
|
|
93
|
|
|
# Set language |
94
|
|
|
|
95
|
|
|
$page->language = Extend\Languages::data('iso'); |
96
|
|
|
|
97
|
|
|
# Set SEO data |
98
|
|
|
|
99
|
|
|
$page->description = ('' !== $this->description) ? $this->description : Settings::get('site_description'); |
100
|
|
|
|
101
|
|
|
$page->keywords = ('' !== $this->keywords) ? $this->keywords : Settings::get('site_keywords'); |
102
|
|
|
|
103
|
|
|
$page->robots = (($this->robots_index ? 'INDEX' : 'NOINDEX') . ',' . ($this->robots_follow ? 'FOLLOW' : 'NOFOLLOW')); |
104
|
|
|
|
105
|
|
|
# Set title |
106
|
|
|
|
107
|
|
|
$page->title = ((('' !== $this->title) ? ($this->title . ' | ') : '') . Settings::get('site_title')); |
108
|
|
|
|
109
|
|
|
# Set canonical |
110
|
|
|
|
111
|
|
|
if ('' === $this->canonical) $page->block('canonical')->disable(); |
112
|
|
|
|
113
|
|
|
else $page->block('canonical')->link = $this->canonical; |
114
|
|
|
|
115
|
|
|
# Set layout |
116
|
|
|
|
117
|
|
|
$page->layout = $this->getLayout($contents); |
118
|
|
|
|
119
|
|
|
# ------------------------ |
120
|
|
|
|
121
|
|
|
Template::output($page, STATUS_CODE_200); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
# Site main method |
125
|
|
|
|
126
|
|
|
protected function section() { |
127
|
|
|
|
128
|
|
|
# Check site status |
129
|
|
|
|
130
|
|
|
if (Settings::get('site_status') === STATUS_MAINTENANCE) return Status::maintenance(); |
131
|
|
|
|
132
|
|
|
if (Settings::get('site_status') === STATUS_UPDATE) return Status::update(); |
133
|
|
|
|
134
|
|
|
# Check access rights |
135
|
|
|
|
136
|
|
|
if ($this instanceof Component\Profile) { |
137
|
|
|
|
138
|
|
|
if (!Settings::get('users_registration')) return Status::error404(); |
139
|
|
|
|
140
|
|
|
if (($this instanceof Component\Profile\Auth)) { |
141
|
|
|
|
142
|
|
|
if (Auth::check()) Request::redirect(INSTALL_PATH . '/profile'); |
143
|
|
|
|
144
|
|
View Code Duplication |
} else if (!Auth::check() || ((false !== Request::get('logout')) && Auth::logout())) { |
|
|
|
|
145
|
|
|
|
146
|
|
|
Request::redirect(INSTALL_PATH . '/profile/login'); |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
# Handle request |
151
|
|
|
|
152
|
|
|
if (Template::isBlock($result = $this->handle())) { |
153
|
|
|
|
154
|
|
|
# Set global components |
155
|
|
|
|
156
|
|
|
$variables = new Variables(); $widgets = new Widgets(); |
157
|
|
|
|
158
|
|
|
foreach ($variables->items() as $name => $value) Template::global($name, $value); |
159
|
|
|
|
160
|
|
|
foreach ($widgets->items() as $name => $block) Template::widget($name, $block); |
161
|
|
|
|
162
|
|
|
# Display page |
163
|
|
|
|
164
|
|
|
return $this->displayPage($result); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
# ------------------------ |
168
|
|
|
|
169
|
|
|
return Status::error404(); |
170
|
|
|
} |
171
|
|
|
} |
172
|
|
|
} |
173
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.