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 ControllerExtensionModuleBlocksforallcategories extends \Divine\Engine\Core\Controller |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
private $error = array(); |
26
|
|
|
|
27
|
|
|
public function index() |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
$this->load->language('extension/module/blocksforallcategories'); |
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('blocksforallcategories', $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
|
|
|
|
55
|
|
|
$data['entry_name'] = $this->language->get('entry_name'); |
56
|
|
|
$data['entry_category_limit'] = $this->language->get('entry_category_limit'); |
57
|
|
|
$data['entry_sub_category_limit'] = $this->language->get('entry_sub_category_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
|
|
|
$data['entry_cover_status'] = $this->language->get('entry_cover_status'); |
62
|
|
|
|
63
|
|
|
$data['button_save'] = $this->language->get('button_save'); |
64
|
|
|
$data['button_cancel'] = $this->language->get('button_cancel'); |
65
|
|
|
|
66
|
|
|
if (isset($this->error['warning'])) { |
67
|
|
|
$data['error_warning'] = $this->error['warning']; |
68
|
|
|
} else { |
69
|
|
|
$data['error_warning'] = ''; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
if (isset($this->error['name'])) { |
73
|
|
|
$data['error_name'] = $this->error['name']; |
74
|
|
|
} else { |
75
|
|
|
$data['error_name'] = ''; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
if (isset($this->error['width'])) { |
79
|
|
|
$data['error_width'] = $this->error['width']; |
80
|
|
|
} else { |
81
|
|
|
$data['error_width'] = ''; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
if (isset($this->error['height'])) { |
85
|
|
|
$data['error_height'] = $this->error['height']; |
86
|
|
|
} else { |
87
|
|
|
$data['error_height'] = ''; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
$data['breadcrumbs'] = array(); |
91
|
|
|
|
92
|
|
|
$data['breadcrumbs'][] = array( |
93
|
|
|
'text' => $this->language->get('text_home'), |
94
|
|
|
'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], true) |
95
|
|
|
); |
96
|
|
|
|
97
|
|
|
$data['breadcrumbs'][] = array( |
98
|
|
|
'text' => $this->language->get('text_extension'), |
99
|
|
|
'href' => $this->url->link('extension/extension', 'token=' . $this->session->data['token'] . '&type=module', true) |
100
|
|
|
); |
101
|
|
|
|
102
|
|
|
if (!isset($this->request->get['module_id'])) { |
103
|
|
|
$data['breadcrumbs'][] = array( |
104
|
|
|
'text' => $this->language->get('heading_title'), |
105
|
|
|
'href' => $this->url->link('extension/module/blocksforallcategories', 'token=' . $this->session->data['token'], true) |
106
|
|
|
); |
107
|
|
|
} else { |
108
|
|
|
$data['breadcrumbs'][] = array( |
109
|
|
|
'text' => $this->language->get('heading_title'), |
110
|
|
|
'href' => $this->url->link('extension/module/blocksforallcategories', 'token=' . $this->session->data['token'] . '&module_id=' . $this->request->get['module_id'], true) |
111
|
|
|
); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
if (!isset($this->request->get['module_id'])) { |
115
|
|
|
$data['action'] = $this->url->link('extension/module/blocksforallcategories', 'token=' . $this->session->data['token'], true); |
116
|
|
|
} else { |
117
|
|
|
$data['action'] = $this->url->link('extension/module/blocksforallcategories', 'token=' . $this->session->data['token'] . '&module_id=' . $this->request->get['module_id'], true); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
$data['cancel'] = $this->url->link('extension/extension', 'token=' . $this->session->data['token'] . '&type=module', true); |
121
|
|
|
|
122
|
|
|
if (isset($this->request->get['module_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { |
123
|
|
|
$module_info = $this->model_extension_module->getModule($this->request->get['module_id']); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
if (isset($this->request->post['name'])) { |
127
|
|
|
$data['name'] = $this->request->post['name']; |
128
|
|
|
} elseif (!empty($module_info)) { |
129
|
|
|
$data['name'] = $module_info['name']; |
130
|
|
|
} else { |
131
|
|
|
$data['name'] = ''; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
if (isset($this->request->post['category_limit'])) { |
135
|
|
|
$data['category_limit'] = $this->request->post['category_limit']; |
136
|
|
|
} elseif (!empty($module_info)) { |
137
|
|
|
$data['category_limit'] = $module_info['category_limit']; |
138
|
|
|
} else { |
139
|
|
|
$data['category_limit'] = 100; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
if (isset($this->request->post['sub_category_limit'])) { |
143
|
|
|
$data['sub_category_limit'] = $this->request->post['sub_category_limit']; |
144
|
|
|
} elseif (!empty($module_info)) { |
145
|
|
|
$data['sub_category_limit'] = $module_info['sub_category_limit']; |
146
|
|
|
} else { |
147
|
|
|
$data['sub_category_limit'] = 4; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
if (isset($this->request->post['width'])) { |
151
|
|
|
$data['width'] = $this->request->post['width']; |
152
|
|
|
} elseif (!empty($module_info)) { |
153
|
|
|
$data['width'] = $module_info['width']; |
154
|
|
|
} else { |
155
|
|
|
$data['width'] = 609; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
if (isset($this->request->post['height'])) { |
159
|
|
|
$data['height'] = $this->request->post['height']; |
160
|
|
|
} elseif (!empty($module_info)) { |
161
|
|
|
$data['height'] = $module_info['height']; |
162
|
|
|
} else { |
163
|
|
|
$data['height'] = 609; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
if (isset($this->request->post['status'])) { |
167
|
|
|
$data['status'] = $this->request->post['status']; |
168
|
|
|
} elseif (!empty($module_info)) { |
169
|
|
|
$data['status'] = $module_info['status']; |
170
|
|
|
} else { |
171
|
|
|
$data['status'] = ''; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
if (isset($this->request->post['cover_status'])) { |
175
|
|
|
$data['cover_status'] = $this->request->post['cover_status']; |
176
|
|
|
} elseif (!empty($module_info)) { |
177
|
|
|
$data['cover_status'] = $module_info['cover_status']; |
178
|
|
|
} else { |
179
|
|
|
$data['cover_status'] = ''; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
$data['header'] = $this->load->controller('common/header'); |
183
|
|
|
$data['column'] = $this->load->controller('common/column_left'); |
184
|
|
|
$data['footer'] = $this->load->controller('common/footer'); |
185
|
|
|
|
186
|
|
|
$this->response->setOutput($this->load->view('extension/module/blocksforallcategories', $data)); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
protected function validate() |
190
|
|
|
{ |
191
|
|
|
if (!$this->user->hasPermission('modify', 'extension/module/blocksforallcategories')) { |
192
|
|
|
$this->error['warning'] = $this->language->get('error_permission'); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
if ((\voku\helper\UTF8::strlen($this->request->post['name']) < 3) || (\voku\helper\UTF8::strlen($this->request->post['name']) > 64)) { |
196
|
|
|
$this->error['name'] = $this->language->get('error_name'); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
if (!$this->request->post['width']) { |
200
|
|
|
$this->error['width'] = $this->language->get('error_width'); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
if (!$this->request->post['height']) { |
204
|
|
|
$this->error['height'] = $this->language->get('error_height'); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
return !$this->error; |
208
|
|
|
} |
209
|
|
|
} |
210
|
|
|
|
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.