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 ControllerDesignSticker extends \Divine\Engine\Core\Controller |
||
0 ignored issues
–
show
|
|||
24 | { |
||
25 | private $error = array(); |
||
26 | |||
27 | public function index() |
||
0 ignored issues
–
show
|
|||
28 | { |
||
29 | $this->language->load('design/sticker'); |
||
30 | |||
31 | $this->document->setTitle($this->language->get('heading_title')); |
||
32 | |||
33 | $this->load->model('design/sticker'); |
||
34 | |||
35 | $this->getList(); |
||
36 | } |
||
37 | |||
38 | public function add() |
||
39 | { |
||
40 | $this->language->load('design/sticker'); |
||
41 | |||
42 | $this->document->setTitle($this->language->get('heading_title')); |
||
43 | |||
44 | $this->load->model('design/sticker'); |
||
45 | |||
46 | if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { |
||
47 | $this->model_design_sticker->addSticker($this->request->post); |
||
48 | |||
49 | $this->session->data['success'] = $this->language->get('text_success'); |
||
50 | |||
51 | $url = ''; |
||
52 | |||
53 | if (isset($this->request->get['sort'])) { |
||
54 | $url .= '&sort=' . $this->request->get['sort']; |
||
55 | } |
||
56 | |||
57 | if (isset($this->request->get['order'])) { |
||
58 | $url .= '&order=' . $this->request->get['order']; |
||
59 | } |
||
60 | |||
61 | if (isset($this->request->get['page'])) { |
||
62 | $url .= '&page=' . $this->request->get['page']; |
||
63 | } |
||
64 | |||
65 | $this->response->redirect($this->url->link('design/sticker', 'token=' . $this->session->data['token'] . $url, true)); |
||
66 | } |
||
67 | |||
68 | $this->getForm(); |
||
69 | } |
||
70 | |||
71 | public function edit() |
||
72 | { |
||
73 | $this->language->load('design/sticker'); |
||
74 | |||
75 | $this->document->setTitle($this->language->get('heading_title')); |
||
76 | |||
77 | $this->load->model('design/sticker'); |
||
78 | |||
79 | if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { |
||
80 | $this->model_design_sticker->editSticker($this->request->get['sticker_id'], $this->request->post); |
||
81 | |||
82 | $this->session->data['success'] = $this->language->get('text_success'); |
||
83 | |||
84 | $url = ''; |
||
85 | |||
86 | if (isset($this->request->get['sort'])) { |
||
87 | $url .= '&sort=' . $this->request->get['sort']; |
||
88 | } |
||
89 | |||
90 | if (isset($this->request->get['order'])) { |
||
91 | $url .= '&order=' . $this->request->get['order']; |
||
92 | } |
||
93 | |||
94 | if (isset($this->request->get['page'])) { |
||
95 | $url .= '&page=' . $this->request->get['page']; |
||
96 | } |
||
97 | |||
98 | $this->response->redirect($this->url->link('design/sticker', 'token=' . $this->session->data['token'] . $url, true)); |
||
99 | } |
||
100 | |||
101 | $this->getForm(); |
||
102 | } |
||
103 | |||
104 | public function delete() |
||
105 | { |
||
106 | $this->load->language('design/sticker'); |
||
107 | |||
108 | $this->document->setTitle($this->language->get('heading_title')); |
||
109 | |||
110 | $this->load->model('design/sticker'); |
||
111 | |||
112 | if (isset($this->request->post['selected']) && $this->validateDelete()) { |
||
113 | foreach ($this->request->post['selected'] as $sticker_id) { |
||
114 | $this->model_design_sticker->deleteSticker($sticker_id); |
||
115 | } |
||
116 | |||
117 | $this->session->data['success'] = $this->language->get('text_success'); |
||
118 | |||
119 | $url = ''; |
||
120 | |||
121 | if (isset($this->request->get['sort'])) { |
||
122 | $url .= '&sort=' . $this->request->get['sort']; |
||
123 | } |
||
124 | |||
125 | if (isset($this->request->get['order'])) { |
||
126 | $url .= '&order=' . $this->request->get['order']; |
||
127 | } |
||
128 | |||
129 | if (isset($this->request->get['page'])) { |
||
130 | $url .= '&page=' . $this->request->get['page']; |
||
131 | } |
||
132 | |||
133 | $this->response->redirect($this->url->link('design/sticker', 'token=' . $this->session->data['token'] . $url, true)); |
||
134 | } |
||
135 | |||
136 | $this->getList(); |
||
137 | } |
||
138 | |||
139 | protected function getList() |
||
140 | { |
||
141 | if (isset($this->request->get['sort'])) { |
||
142 | $sort = $this->request->get['sort']; |
||
143 | } else { |
||
144 | $sort = 'name'; |
||
145 | } |
||
146 | |||
147 | if (isset($this->request->get['order'])) { |
||
148 | $order = $this->request->get['order']; |
||
149 | } else { |
||
150 | $order = 'ASC'; |
||
151 | } |
||
152 | |||
153 | if (isset($this->request->get['page'])) { |
||
154 | $page = $this->request->get['page']; |
||
155 | } else { |
||
156 | $page = 1; |
||
157 | } |
||
158 | |||
159 | $url = ''; |
||
160 | |||
161 | if (isset($this->request->get['sort'])) { |
||
162 | $url .= '&sort=' . $this->request->get['sort']; |
||
163 | } |
||
164 | |||
165 | if (isset($this->request->get['order'])) { |
||
166 | $url .= '&order=' . $this->request->get['order']; |
||
167 | } |
||
168 | |||
169 | if (isset($this->request->get['page'])) { |
||
170 | $url .= '&page=' . $this->request->get['page']; |
||
171 | } |
||
172 | |||
173 | $data['breadcrumbs'] = array(); |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
174 | |||
175 | $data['breadcrumbs'][] = array( |
||
176 | 'text' => $this->language->get('text_home'), |
||
177 | 'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], true) |
||
178 | ); |
||
179 | |||
180 | $data['breadcrumbs'][] = array( |
||
181 | 'text' => $this->language->get('heading_title'), |
||
182 | 'href' => $this->url->link('design/sticker', 'token=' . $this->session->data['token'] . $url, true) |
||
183 | ); |
||
184 | |||
185 | $data['add'] = $this->url->link('design/sticker/add', 'token=' . $this->session->data['token'] . $url, true); |
||
186 | $data['delete'] = $this->url->link('design/sticker/delete', 'token=' . $this->session->data['token'] . $url, true); |
||
187 | |||
188 | $data['stickers'] = array(); |
||
189 | |||
190 | $filter_data = array( |
||
191 | 'sort' => $sort, |
||
192 | 'order' => $order, |
||
193 | 'start' => ($page - 1) * $this->config->get('config_limit_admin'), |
||
194 | 'limit' => $this->config->get('config_limit_admin') |
||
195 | ); |
||
196 | |||
197 | $sticker_total = $this->model_design_sticker->getTotalStickers(); |
||
198 | |||
199 | $results = $this->model_design_sticker->getStickers($filter_data); |
||
200 | |||
201 | |||
202 | |||
203 | foreach ($results as $result) { |
||
204 | if ($result['image'] && file_exists($_SERVER['DOCUMENT_ROOT'] . '/public_html/assets/images/' . $result['image'])) { |
||
205 | $image = '/public_html/assets/images/' . $result['image']; |
||
206 | } else { |
||
207 | $image = '/public_html/assets/images/no_image.png'; |
||
208 | } |
||
209 | |||
210 | $data['stickers'][] = array( |
||
211 | 'sticker_id' => $result['sticker_id'], |
||
212 | 'name' => $result['name'], |
||
213 | 'status' => ($result['status'] ? $this->language->get('text_enabled') : $this->language->get('text_disabled')), |
||
214 | 'edit' => $this->url->link('design/sticker/edit', 'token=' . $this->session->data['token'] . '&sticker_id=' . $result['sticker_id'] . $url, true), |
||
215 | 'image' => $image, |
||
216 | ); |
||
217 | } |
||
218 | |||
219 | $data['heading_title'] = $this->language->get('heading_title'); |
||
220 | |||
221 | $data['text_list'] = $this->language->get('text_list'); |
||
222 | $data['text_no_results'] = $this->language->get('text_no_results'); |
||
223 | $data['text_confirm'] = $this->language->get('text_confirm'); |
||
224 | |||
225 | $data['column_image'] = $this->language->get('column_image'); |
||
226 | $data['column_name'] = $this->language->get('column_name'); |
||
227 | $data['column_status'] = $this->language->get('column_status'); |
||
228 | $data['column_action'] = $this->language->get('column_action'); |
||
229 | |||
230 | $data['button_add'] = $this->language->get('button_add'); |
||
231 | $data['button_edit'] = $this->language->get('button_edit'); |
||
232 | $data['button_delete'] = $this->language->get('button_delete'); |
||
233 | |||
234 | |||
235 | |||
236 | if (isset($this->error['warning'])) { |
||
237 | $data['error_warning'] = $this->error['warning']; |
||
238 | } else { |
||
239 | $data['error_warning'] = ''; |
||
240 | } |
||
241 | |||
242 | if (isset($this->session->data['success'])) { |
||
243 | $data['success'] = $this->session->data['success']; |
||
244 | |||
245 | unset($this->session->data['success']); |
||
246 | } else { |
||
247 | $data['success'] = ''; |
||
248 | } |
||
249 | |||
250 | if (isset($this->request->post['selected'])) { |
||
251 | $data['selected'] = (array)$this->request->post['selected']; |
||
252 | } else { |
||
253 | $data['selected'] = array(); |
||
254 | } |
||
255 | |||
256 | $url = ''; |
||
257 | |||
258 | if ($order == 'ASC') { |
||
259 | $url .= '&order=DESC'; |
||
260 | } else { |
||
261 | $url .= '&order=ASC'; |
||
262 | } |
||
263 | |||
264 | if (isset($this->request->get['page'])) { |
||
265 | $url .= '&page=' . $this->request->get['page']; |
||
266 | } |
||
267 | |||
268 | $data['sort_name'] = $this->url->link('design/sticker', 'token=' . $this->session->data['token'] . '&sort=name' . $url, true); |
||
269 | $data['sort_status'] = $this->url->link('design/sticker', 'token=' . $this->session->data['token'] . '&sort=status' . $url, true); |
||
270 | |||
271 | $url = ''; |
||
272 | |||
273 | if (isset($this->request->get['sort'])) { |
||
274 | $url .= '&sort=' . $this->request->get['sort']; |
||
275 | } |
||
276 | |||
277 | if (isset($this->request->get['order'])) { |
||
278 | $url .= '&order=' . $this->request->get['order']; |
||
279 | } |
||
280 | |||
281 | $pagination = new \Divine\Engine\Library\Pagination(); |
||
282 | $pagination->total = $sticker_total; |
||
283 | $pagination->page = $page; |
||
284 | $pagination->limit = $this->config->get('config_limit_admin'); |
||
285 | $pagination->url = $this->url->link('design/sticker', 'token=' . $this->session->data['token'] . $url . '&page={page}', true); |
||
286 | |||
287 | $data['pagination'] = $pagination->render(); |
||
288 | |||
289 | $data['results'] = sprintf($this->language->get('text_pagination'), ($sticker_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($sticker_total - $this->config->get('config_limit_admin'))) ? $sticker_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $sticker_total, ceil($sticker_total / $this->config->get('config_limit_admin'))); |
||
290 | |||
291 | $data['sort'] = $sort; |
||
292 | $data['order'] = $order; |
||
293 | |||
294 | $data['header'] = $this->load->controller('common/header'); |
||
295 | $data['column'] = $this->load->controller('common/column_left'); |
||
296 | $data['footer'] = $this->load->controller('common/footer'); |
||
297 | |||
298 | $this->response->setOutput($this->load->view('design/sticker_list', $data)); |
||
299 | } |
||
300 | |||
301 | protected function getForm() |
||
302 | { |
||
303 | $data['heading_title'] = $this->language->get('heading_title'); |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
304 | |||
305 | $data['text_form'] = !isset($this->request->get['sticker_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); |
||
306 | $data['text_enabled'] = $this->language->get('text_enabled'); |
||
307 | $data['text_disabled'] = $this->language->get('text_disabled'); |
||
308 | $data['text_default'] = $this->language->get('text_default'); |
||
309 | $data['text_image_manager'] = $this->language->get('text_image_manager'); |
||
310 | $data['text_browse'] = $this->language->get('text_browse'); |
||
311 | $data['text_clear'] = $this->language->get('text_clear'); |
||
312 | |||
313 | $data['entry_name'] = $this->language->get('entry_name'); |
||
314 | $data['entry_image'] = $this->language->get('entry_image'); |
||
315 | $data['entry_status'] = $this->language->get('entry_status'); |
||
316 | |||
317 | $data['button_save'] = $this->language->get('button_save'); |
||
318 | $data['button_cancel'] = $this->language->get('button_cancel'); |
||
319 | $data['button_remove'] = $this->language->get('button_remove'); |
||
320 | |||
321 | if (isset($this->error['warning'])) { |
||
322 | $data['error_warning'] = $this->error['warning']; |
||
323 | } else { |
||
324 | $data['error_warning'] = ''; |
||
325 | } |
||
326 | |||
327 | if (isset($this->error['name'])) { |
||
328 | $data['error_name'] = $this->error['name']; |
||
329 | } else { |
||
330 | $data['error_name'] = ''; |
||
331 | } |
||
332 | |||
333 | $url = ''; |
||
334 | |||
335 | if (isset($this->request->get['sort'])) { |
||
336 | $url .= '&sort=' . $this->request->get['sort']; |
||
337 | } |
||
338 | |||
339 | if (isset($this->request->get['order'])) { |
||
340 | $url .= '&order=' . $this->request->get['order']; |
||
341 | } |
||
342 | |||
343 | if (isset($this->request->get['page'])) { |
||
344 | $url .= '&page=' . $this->request->get['page']; |
||
345 | } |
||
346 | |||
347 | $data['breadcrumbs'] = array(); |
||
348 | |||
349 | $data['breadcrumbs'][] = array( |
||
350 | 'text' => $this->language->get('text_home'), |
||
351 | 'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], true), |
||
352 | 'separator' => false |
||
353 | ); |
||
354 | |||
355 | $data['breadcrumbs'][] = array( |
||
356 | 'text' => $this->language->get('heading_title'), |
||
357 | 'href' => $this->url->link('design/sticker', 'token=' . $this->session->data['token'] . $url, true), |
||
358 | 'separator' => ' :: ' |
||
359 | ); |
||
360 | |||
361 | if (!isset($this->request->get['sticker_id'])) { |
||
362 | $data['action'] = $this->url->link('design/sticker/add', 'token=' . $this->session->data['token'] . $url, true); |
||
363 | } else { |
||
364 | $data['action'] = $this->url->link('design/sticker/edit', 'token=' . $this->session->data['token'] . '&sticker_id=' . $this->request->get['sticker_id'] . $url, true); |
||
365 | } |
||
366 | |||
367 | $data['cancel'] = $this->url->link('design/sticker', 'token=' . $this->session->data['token'] . $url, true); |
||
368 | |||
369 | if (isset($this->request->get['sticker_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { |
||
370 | $sticker_info = $this->model_design_sticker->getSticker($this->request->get['sticker_id']); |
||
371 | } |
||
372 | |||
373 | $data['token'] = $this->session->data['token']; |
||
374 | |||
375 | if (isset($this->request->post['name'])) { |
||
376 | $data['name'] = $this->request->post['name']; |
||
377 | } elseif (!empty($sticker_info)) { |
||
378 | $data['name'] = $sticker_info['name']; |
||
379 | } else { |
||
380 | $data['name'] = ''; |
||
381 | } |
||
382 | |||
383 | if (isset($this->request->post['status'])) { |
||
384 | $data['status'] = $this->request->post['status']; |
||
385 | } elseif (!empty($sticker_info)) { |
||
386 | $data['status'] = $sticker_info['status']; |
||
387 | } else { |
||
388 | $data['status'] = true; |
||
389 | } |
||
390 | |||
391 | $this->load->model('localisation/language'); |
||
392 | |||
393 | $data['languages'] = $this->model_localisation_language->getLanguages(); |
||
394 | |||
395 | if (isset($this->request->post['image'])) { |
||
396 | $data['image'] = $this->request->post['image']; |
||
397 | } elseif (!empty($sticker_info)) { |
||
398 | $data['image'] = $sticker_info['image']; |
||
399 | } else { |
||
400 | $data['image'] = ''; |
||
401 | } |
||
402 | |||
403 | |||
404 | |||
405 | if (isset($this->request->post['image']) && file_exists($_SERVER['DOCUMENT_ROOT'] . '/public_html/assets/images/' . $this->request->post['image'])) { |
||
406 | $data['thumb'] = '/public_html/assets/images/' . $this->request->post['image']; |
||
407 | } elseif (!empty($sticker_info) && $sticker_info['image'] && file_exists($_SERVER['DOCUMENT_ROOT'] . '/public_html/assets/images/' . $sticker_info['image'])) { |
||
408 | $data['thumb'] = '/public_html/assets/images/' . $sticker_info['image']; |
||
409 | } else { |
||
410 | $data['thumb'] = '/public_html/assets/images/no_image.png'; |
||
411 | } |
||
412 | |||
413 | $data['placeholder'] = '/public_html/assets/images/no_image.png'; |
||
414 | |||
415 | $data['header'] = $this->load->controller('common/header'); |
||
416 | $data['column'] = $this->load->controller('common/column_left'); |
||
417 | $data['footer'] = $this->load->controller('common/footer'); |
||
418 | |||
419 | $this->response->setOutput($this->load->view('design/sticker_form', $data)); |
||
420 | } |
||
421 | |||
422 | protected function validateForm() |
||
423 | { |
||
424 | if (!$this->user->hasPermission('modify', 'design/sticker')) { |
||
425 | $this->error['warning'] = $this->language->get('error_permission'); |
||
426 | } |
||
427 | |||
428 | if ((\voku\helper\UTF8::strlen($this->request->post['name']) < 3) || (\voku\helper\UTF8::strlen($this->request->post['name']) > 64)) { |
||
429 | $this->error['name'] = $this->language->get('error_name'); |
||
430 | } |
||
431 | |||
432 | if (!$this->error) { |
||
0 ignored issues
–
show
The expression
$this->error of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using ![]() |
|||
433 | return true; |
||
434 | } else { |
||
435 | return false; |
||
436 | } |
||
437 | } |
||
438 | |||
439 | protected function validateDelete() |
||
440 | { |
||
441 | if (!$this->user->hasPermission('modify', 'design/sticker')) { |
||
442 | $this->error['warning'] = $this->language->get('error_permission'); |
||
443 | } |
||
444 | |||
445 | if (isset($this->request->post['selected'])) { |
||
446 | $selected = implode(',', $this->request->post['selected']); |
||
447 | |||
448 | $count = $this->model_design_sticker->validateDelete($selected); |
||
449 | |||
450 | if ($count) { |
||
451 | $this->error['warning'] = sprintf($this->language->get('error_product'), $count); |
||
452 | }; |
||
453 | } |
||
454 | |||
455 | |||
456 | if (!$this->error) { |
||
0 ignored issues
–
show
The expression
$this->error of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using ![]() |
|||
457 | return true; |
||
458 | } else { |
||
459 | return false; |
||
460 | } |
||
461 | } |
||
462 | } |
||
463 |
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.