|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* Divine CMS - Open source CMS for widespread use. |
|
4
|
|
|
Copyright (c) 2019 Mykola Burakov ([email protected]) |
|
5
|
|
|
|
|
6
|
|
|
See SOURCE.txt for other and additional information. |
|
7
|
|
|
|
|
8
|
|
|
This file is part of Divine CMS. |
|
9
|
|
|
|
|
10
|
|
|
This program is free software: you can redistribute it and/or modify |
|
11
|
|
|
it under the terms of the GNU General Public License as published by |
|
12
|
|
|
the Free Software Foundation, either version 3 of the License, or |
|
13
|
|
|
(at your option) any later version. |
|
14
|
|
|
|
|
15
|
|
|
This program is distributed in the hope that it will be useful, |
|
16
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
18
|
|
|
GNU General Public License for more details. |
|
19
|
|
|
|
|
20
|
|
|
You should have received a copy of the GNU General Public License |
|
21
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
|
22
|
|
|
|
|
23
|
|
|
class ControllerExtensionModuleFeaturedArticle extends \Divine\Engine\Core\Controller |
|
|
|
|
|
|
24
|
|
|
{ |
|
25
|
|
|
private $error = array(); |
|
26
|
|
|
|
|
27
|
|
|
public function index() |
|
|
|
|
|
|
28
|
|
|
{ |
|
29
|
|
|
$this->load->language('extension/module/featured_article'); |
|
30
|
|
|
|
|
31
|
|
|
$this->document->setTitle($this->language->get('heading_title')); |
|
32
|
|
|
|
|
33
|
|
|
$this->load->model('extension/module'); |
|
34
|
|
|
|
|
35
|
|
|
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { |
|
|
|
|
|
|
36
|
|
|
if (!isset($this->request->get['module_id'])) { |
|
37
|
|
|
$this->model_extension_module->addModule('featured_article', $this->request->post); |
|
38
|
|
|
} else { |
|
39
|
|
|
$this->model_extension_module->editModule($this->request->get['module_id'], $this->request->post); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
$this->cache->delete('product'); |
|
43
|
|
|
|
|
44
|
|
|
$this->session->data['success'] = $this->language->get('text_success'); |
|
45
|
|
|
|
|
46
|
|
|
$this->response->redirect($this->url->link('extension/extension', 'token=' . $this->session->data['token'] . '&type=module', true)); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
$data['heading_title'] = $this->language->get('heading_title'); |
|
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
$data['text_edit'] = $this->language->get('text_edit'); |
|
52
|
|
|
$data['text_enabled'] = $this->language->get('text_enabled'); |
|
53
|
|
|
$data['text_disabled'] = $this->language->get('text_disabled'); |
|
54
|
|
|
$data['text_help'] = $this->language->get('text_help'); |
|
55
|
|
|
|
|
56
|
|
|
$data['entry_name'] = $this->language->get('entry_name'); |
|
57
|
|
|
$data['entry_limit'] = $this->language->get('entry_limit'); |
|
58
|
|
|
$data['entry_width'] = $this->language->get('entry_width'); |
|
59
|
|
|
$data['entry_height'] = $this->language->get('entry_height'); |
|
60
|
|
|
$data['entry_status'] = $this->language->get('entry_status'); |
|
61
|
|
|
|
|
62
|
|
|
$data['button_save'] = $this->language->get('button_save'); |
|
63
|
|
|
$data['button_cancel'] = $this->language->get('button_cancel'); |
|
64
|
|
|
|
|
65
|
|
|
if (isset($this->error['warning'])) { |
|
66
|
|
|
$data['error_warning'] = $this->error['warning']; |
|
67
|
|
|
} else { |
|
68
|
|
|
$data['error_warning'] = ''; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
if (isset($this->error['name'])) { |
|
72
|
|
|
$data['error_name'] = $this->error['name']; |
|
73
|
|
|
} else { |
|
74
|
|
|
$data['error_name'] = ''; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
if (isset($this->error['width'])) { |
|
78
|
|
|
$data['error_width'] = $this->error['width']; |
|
79
|
|
|
} else { |
|
80
|
|
|
$data['error_width'] = ''; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
if (isset($this->error['height'])) { |
|
84
|
|
|
$data['error_height'] = $this->error['height']; |
|
85
|
|
|
} else { |
|
86
|
|
|
$data['error_height'] = ''; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
$data['breadcrumbs'] = array(); |
|
90
|
|
|
|
|
91
|
|
|
$data['breadcrumbs'][] = array( |
|
92
|
|
|
'text' => $this->language->get('text_home'), |
|
93
|
|
|
'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], true) |
|
94
|
|
|
); |
|
95
|
|
|
|
|
96
|
|
|
$data['breadcrumbs'][] = array( |
|
97
|
|
|
'text' => $this->language->get('text_extension'), |
|
98
|
|
|
'href' => $this->url->link('extension/extension', 'token=' . $this->session->data['token'] . '&type=module', true) |
|
99
|
|
|
); |
|
100
|
|
|
|
|
101
|
|
|
if (!isset($this->request->get['module_id'])) { |
|
102
|
|
|
$data['breadcrumbs'][] = array( |
|
103
|
|
|
'text' => $this->language->get('heading_title'), |
|
104
|
|
|
'href' => $this->url->link('extension/module/featured_article', 'token=' . $this->session->data['token'], true) |
|
105
|
|
|
); |
|
106
|
|
|
} else { |
|
107
|
|
|
$data['breadcrumbs'][] = array( |
|
108
|
|
|
'text' => $this->language->get('heading_title'), |
|
109
|
|
|
'href' => $this->url->link('extension/module/featured_article', 'token=' . $this->session->data['token'] . '&module_id=' . $this->request->get['module_id'], true) |
|
110
|
|
|
); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
if (!isset($this->request->get['module_id'])) { |
|
114
|
|
|
$data['action'] = $this->url->link('extension/module/featured_article', 'token=' . $this->session->data['token'], true); |
|
115
|
|
|
} else { |
|
116
|
|
|
$data['action'] = $this->url->link('extension/module/featured_article', 'token=' . $this->session->data['token'] . '&module_id=' . $this->request->get['module_id'], true); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
$data['cancel'] = $this->url->link('extension/extension', 'token=' . $this->session->data['token'] . '&type=module', true); |
|
120
|
|
|
|
|
121
|
|
|
if (isset($this->request->get['module_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { |
|
122
|
|
|
$module_info = $this->model_extension_module->getModule($this->request->get['module_id']); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
if (isset($this->request->post['name'])) { |
|
126
|
|
|
$data['name'] = $this->request->post['name']; |
|
127
|
|
|
} elseif (!empty($module_info)) { |
|
128
|
|
|
$data['name'] = $module_info['name']; |
|
129
|
|
|
} else { |
|
130
|
|
|
$data['name'] = ''; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
if (isset($this->request->post['limit'])) { |
|
134
|
|
|
$data['limit'] = $this->request->post['limit']; |
|
135
|
|
|
} elseif (!empty($module_info)) { |
|
136
|
|
|
$data['limit'] = $module_info['limit']; |
|
137
|
|
|
} else { |
|
138
|
|
|
$data['limit'] = 5; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
if (isset($this->request->post['width'])) { |
|
142
|
|
|
$data['width'] = $this->request->post['width']; |
|
143
|
|
|
} elseif (!empty($module_info)) { |
|
144
|
|
|
$data['width'] = $module_info['width']; |
|
145
|
|
|
} else { |
|
146
|
|
|
$data['width'] = 200; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
if (isset($this->request->post['height'])) { |
|
150
|
|
|
$data['height'] = $this->request->post['height']; |
|
151
|
|
|
} elseif (!empty($module_info)) { |
|
152
|
|
|
$data['height'] = $module_info['height']; |
|
153
|
|
|
} else { |
|
154
|
|
|
$data['height'] = 200; |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
if (isset($this->request->post['status'])) { |
|
158
|
|
|
$data['status'] = $this->request->post['status']; |
|
159
|
|
|
} elseif (!empty($module_info)) { |
|
160
|
|
|
$data['status'] = $module_info['status']; |
|
161
|
|
|
} else { |
|
162
|
|
|
$data['status'] = ''; |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
$data['header'] = $this->load->controller('common/header'); |
|
166
|
|
|
$data['column'] = $this->load->controller('common/column_left'); |
|
167
|
|
|
$data['footer'] = $this->load->controller('common/footer'); |
|
168
|
|
|
|
|
169
|
|
|
$this->response->setOutput($this->load->view('extension/module/featured_article', $data)); |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
protected function validate() |
|
173
|
|
|
{ |
|
174
|
|
|
if (!$this->user->hasPermission('modify', 'extension/module/featured_article')) { |
|
175
|
|
|
$this->error['warning'] = $this->language->get('error_permission'); |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
if ((\voku\helper\UTF8::strlen($this->request->post['name']) < 3) || (\voku\helper\UTF8::strlen($this->request->post['name']) > 64)) { |
|
179
|
|
|
$this->error['name'] = $this->language->get('error_name'); |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
if (!$this->request->post['width']) { |
|
183
|
|
|
$this->error['width'] = $this->language->get('error_width'); |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
if (!$this->request->post['height']) { |
|
187
|
|
|
$this->error['height'] = $this->language->get('error_height'); |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
return !$this->error; |
|
191
|
|
|
} |
|
192
|
|
|
} |
|
193
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.