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 ControllerBlogCategory extends \Divine\Engine\Core\Controller |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
private $error = array(); |
26
|
|
|
private $blog_category_id = 0; |
27
|
|
|
private $path = array(); |
28
|
|
|
|
29
|
|
|
public function index() |
|
|
|
|
30
|
|
|
{ |
31
|
|
|
$this->load->language('blog/category'); |
32
|
|
|
|
33
|
|
|
$this->document->setTitle($this->language->get('heading_title')); |
34
|
|
|
|
35
|
|
|
$this->load->model('blog/category'); |
36
|
|
|
|
37
|
|
|
$this->getList(); |
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function add() |
41
|
|
|
{ |
42
|
|
|
$this->load->language('blog/category'); |
43
|
|
|
|
44
|
|
|
$this->document->setTitle($this->language->get('heading_title')); |
45
|
|
|
|
46
|
|
|
$this->load->model('blog/category'); |
47
|
|
|
|
48
|
|
|
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { |
|
|
|
|
49
|
|
|
$this->model_blog_category->addCategory($this->request->post); |
50
|
|
|
|
51
|
|
|
$this->session->data['success'] = $this->language->get('text_success'); |
52
|
|
|
|
53
|
|
|
$url = ''; |
54
|
|
|
|
55
|
|
|
if (isset($this->request->get['sort'])) { |
56
|
|
|
$url .= '&sort=' . $this->request->get['sort']; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
if (isset($this->request->get['order'])) { |
60
|
|
|
$url .= '&order=' . $this->request->get['order']; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
if (isset($this->request->get['page'])) { |
64
|
|
|
$url .= '&page=' . $this->request->get['page']; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
$this->response->redirect($this->url->link('blog/category', 'token=' . $this->session->data['token'] . $url, true)); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$this->getForm(); |
|
|
|
|
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function edit() |
74
|
|
|
{ |
75
|
|
|
$this->load->language('blog/category'); |
76
|
|
|
|
77
|
|
|
$this->document->setTitle($this->language->get('heading_title')); |
78
|
|
|
|
79
|
|
|
$this->load->model('blog/category'); |
80
|
|
|
|
81
|
|
|
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { |
82
|
|
|
$this->model_blog_category->editCategory($this->request->get['blog_category_id'], $this->request->post); |
83
|
|
|
|
84
|
|
|
$this->session->data['success'] = $this->language->get('text_success'); |
85
|
|
|
|
86
|
|
|
$url = ''; |
87
|
|
|
|
88
|
|
|
if (isset($this->request->get['sort'])) { |
89
|
|
|
$url .= '&sort=' . $this->request->get['sort']; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
if (isset($this->request->get['order'])) { |
93
|
|
|
$url .= '&order=' . $this->request->get['order']; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
if (isset($this->request->get['page'])) { |
97
|
|
|
$url .= '&page=' . $this->request->get['page']; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
$this->response->redirect($this->url->link('blog/category', 'token=' . $this->session->data['token'] . $url, true)); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
$this->getForm(); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function delete() |
107
|
|
|
{ |
108
|
|
|
$this->load->language('blog/category'); |
109
|
|
|
|
110
|
|
|
$this->document->setTitle($this->language->get('heading_title')); |
111
|
|
|
|
112
|
|
|
$this->load->model('blog/category'); |
113
|
|
|
|
114
|
|
|
if (isset($this->request->post['selected']) && $this->validateDelete()) { |
|
|
|
|
115
|
|
|
foreach ($this->request->post['selected'] as $blog_category_id) { |
116
|
|
|
$this->model_blog_category->deleteCategory($blog_category_id); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
$this->session->data['success'] = $this->language->get('text_success'); |
120
|
|
|
|
121
|
|
|
$url = ''; |
122
|
|
|
|
123
|
|
|
if (isset($this->request->get['sort'])) { |
124
|
|
|
$url .= '&sort=' . $this->request->get['sort']; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
if (isset($this->request->get['order'])) { |
128
|
|
|
$url .= '&order=' . $this->request->get['order']; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
if (isset($this->request->get['page'])) { |
132
|
|
|
$url .= '&page=' . $this->request->get['page']; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
$this->response->redirect($this->url->link('blog/category', 'token=' . $this->session->data['token'] . $url, true)); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
$this->getList(); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
public function repair() |
142
|
|
|
{ |
143
|
|
|
$url = ''; |
144
|
|
|
|
145
|
|
|
$this->load->language('blog/category'); |
146
|
|
|
|
147
|
|
|
$this->document->setTitle($this->language->get('heading_title')); |
148
|
|
|
|
149
|
|
|
$this->load->model('blog/category'); |
150
|
|
|
|
151
|
|
|
if ($this->validateRepair()) { |
|
|
|
|
152
|
|
|
$this->model_blog_category->repairCategories(); |
153
|
|
|
|
154
|
|
|
$this->session->data['success'] = $this->language->get('text_success'); |
155
|
|
|
|
156
|
|
|
$this->response->redirect($this->url->link('blog/category', 'token=' . $this->session->data['token'] . $url, true)); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
$this->getList(); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
protected function getList() |
163
|
|
|
{ |
164
|
|
|
$url = ''; |
165
|
|
|
|
166
|
|
|
$data['breadcrumbs'] = array(); |
|
|
|
|
167
|
|
|
|
168
|
|
|
$data['breadcrumbs'][] = array( |
169
|
|
|
'text' => $this->language->get('text_home'), |
170
|
|
|
'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], true) |
171
|
|
|
); |
172
|
|
|
|
173
|
|
|
$data['breadcrumbs'][] = array( |
174
|
|
|
'text' => $this->language->get('heading_title'), |
175
|
|
|
'href' => $this->url->link('blog/category', 'token=' . $this->session->data['token'] . $url, true) |
176
|
|
|
); |
177
|
|
|
|
178
|
|
|
$data['add'] = $this->url->link('blog/category/add', 'token=' . $this->session->data['token'] . $url, true); |
179
|
|
|
$data['delete'] = $this->url->link('blog/category/delete', 'token=' . $this->session->data['token'] . $url, true); |
180
|
|
|
$data['repair'] = $this->url->link('blog/category/repair', 'token=' . $this->session->data['token'] . $url, true); |
181
|
|
|
|
182
|
|
|
$data['enabled'] = $this->url->link('blog/category/enable', 'token=' . $this->session->data['token'] . $url, true); |
183
|
|
|
$data['disabled'] = $this->url->link('blog/category/disable', 'token=' . $this->session->data['token'] . $url, true); |
184
|
|
|
|
185
|
|
|
if (isset($this->request->get['path'])) { |
186
|
|
|
if ($this->request->get['path'] != '') { |
187
|
|
|
$this->path = explode('_', $this->request->get['path']); |
|
|
|
|
188
|
|
|
$this->blog_category_id = end($this->path); |
|
|
|
|
189
|
|
|
$this->session->data['path'] = $this->request->get['path']; |
190
|
|
|
} else { |
191
|
|
|
unset($this->session->data['path']); |
192
|
|
|
} |
193
|
|
|
} elseif (isset($this->session->data['path'])) { |
194
|
|
|
$this->path = explode('_', $this->session->data['path']); |
195
|
|
|
$this->blog_category_id = end($this->path); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
$data['categories'] = $this->getCategories(0); |
|
|
|
|
199
|
|
|
|
200
|
|
|
$data['heading_title'] = $this->language->get('heading_title'); |
201
|
|
|
|
202
|
|
|
$data['text_list'] = $this->language->get('text_list'); |
203
|
|
|
$data['text_no_results'] = $this->language->get('text_no_results'); |
204
|
|
|
$data['text_confirm'] = $this->language->get('text_confirm'); |
205
|
|
|
|
206
|
|
|
$data['column_name'] = $this->language->get('column_name'); |
207
|
|
|
$data['column_sort_order'] = $this->language->get('column_sort_order'); |
208
|
|
|
$data['column_noindex'] = $this->language->get('column_noindex'); |
209
|
|
|
$data['column_action'] = $this->language->get('column_action'); |
210
|
|
|
|
211
|
|
|
$data['button_add'] = $this->language->get('button_add'); |
212
|
|
|
$data['button_edit'] = $this->language->get('button_edit'); |
213
|
|
|
$data['button_shop'] = $this->language->get('button_shop'); |
214
|
|
|
$data['button_delete'] = $this->language->get('button_delete'); |
215
|
|
|
$data['button_rebuild'] = $this->language->get('button_rebuild'); |
216
|
|
|
|
217
|
|
|
$data['button_enable'] = $this->language->get('button_enable'); |
218
|
|
|
$data['button_disable'] = $this->language->get('button_disable'); |
219
|
|
|
|
220
|
|
|
if (isset($this->error['warning'])) { |
221
|
|
|
$data['error_warning'] = $this->error['warning']; |
222
|
|
|
} else { |
223
|
|
|
$data['error_warning'] = ''; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
if (isset($this->session->data['success'])) { |
227
|
|
|
$data['success'] = $this->session->data['success']; |
228
|
|
|
|
229
|
|
|
unset($this->session->data['success']); |
230
|
|
|
} else { |
231
|
|
|
$data['success'] = ''; |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
if (isset($this->request->post['selected'])) { |
235
|
|
|
$data['selected'] = (array)$this->request->post['selected']; |
236
|
|
|
} else { |
237
|
|
|
$data['selected'] = array(); |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
$url = ''; |
|
|
|
|
241
|
|
|
$category_total = $this->model_blog_category->getTotalCategories(); |
242
|
|
|
|
243
|
|
|
$data['results'] = $this->language->get('text_category_total') . ($category_total); |
244
|
|
|
|
245
|
|
|
$data['header'] = $this->load->controller('common/header'); |
246
|
|
|
$data['column'] = $this->load->controller('common/column_left'); |
247
|
|
|
$data['footer'] = $this->load->controller('common/footer'); |
248
|
|
|
|
249
|
|
|
$this->response->setOutput($this->load->view('blog/category_list', $data)); |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
protected function getForm() |
253
|
|
|
{ |
254
|
|
|
$data['heading_title'] = $this->language->get('heading_title'); |
|
|
|
|
255
|
|
|
|
256
|
|
|
$data['text_form'] = !isset($this->request->get['blog_category_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); |
257
|
|
|
$data['text_none'] = $this->language->get('text_none'); |
258
|
|
|
$data['text_default'] = $this->language->get('text_default'); |
259
|
|
|
$data['text_enabled'] = $this->language->get('text_enabled'); |
260
|
|
|
$data['text_disabled'] = $this->language->get('text_disabled'); |
261
|
|
|
|
262
|
|
|
$data['entry_name'] = $this->language->get('entry_name'); |
263
|
|
|
$data['entry_description'] = $this->language->get('entry_description'); |
264
|
|
|
$data['entry_meta_title'] = $this->language->get('entry_meta_title'); |
265
|
|
|
$data['entry_meta_h1'] = $this->language->get('entry_meta_h1'); |
266
|
|
|
$data['entry_meta_description'] = $this->language->get('entry_meta_description'); |
267
|
|
|
$data['entry_keyword'] = $this->language->get('entry_keyword'); |
268
|
|
|
$data['entry_parent'] = $this->language->get('entry_parent'); |
269
|
|
|
$data['entry_image'] = $this->language->get('entry_image'); |
270
|
|
|
$data['entry_top'] = $this->language->get('entry_top'); |
271
|
|
|
$data['entry_column'] = $this->language->get('entry_column'); |
272
|
|
|
$data['entry_sort_order'] = $this->language->get('entry_sort_order'); |
273
|
|
|
$data['entry_status'] = $this->language->get('entry_status'); |
274
|
|
|
$data['entry_noindex'] = $this->language->get('entry_noindex'); |
275
|
|
|
$data['entry_layout'] = $this->language->get('entry_layout'); |
276
|
|
|
|
277
|
|
|
$data['help_keyword'] = $this->language->get('help_keyword'); |
278
|
|
|
$data['help_top'] = $this->language->get('help_top'); |
279
|
|
|
$data['help_column'] = $this->language->get('help_column'); |
280
|
|
|
$data['help_noindex'] = $this->language->get('help_noindex'); |
281
|
|
|
|
282
|
|
|
$data['button_save'] = $this->language->get('button_save'); |
283
|
|
|
$data['button_cancel'] = $this->language->get('button_cancel'); |
284
|
|
|
|
285
|
|
|
$data['tab_general'] = $this->language->get('tab_general'); |
286
|
|
|
$data['tab_data'] = $this->language->get('tab_data'); |
287
|
|
|
$data['tab_design'] = $this->language->get('tab_design'); |
288
|
|
|
|
289
|
|
|
if (isset($this->error['warning'])) { |
290
|
|
|
$data['error_warning'] = $this->error['warning']; |
291
|
|
|
} else { |
292
|
|
|
$data['error_warning'] = ''; |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
if (isset($this->error['name'])) { |
296
|
|
|
$data['error_name'] = $this->error['name']; |
297
|
|
|
} else { |
298
|
|
|
$data['error_name'] = array(); |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
if (isset($this->error['meta_title'])) { |
302
|
|
|
$data['error_meta_title'] = $this->error['meta_title']; |
303
|
|
|
} else { |
304
|
|
|
$data['error_meta_title'] = array(); |
305
|
|
|
} |
306
|
|
|
|
307
|
|
|
if (isset($this->error['meta_h1'])) { |
308
|
|
|
$data['error_meta_h1'] = $this->error['meta_h1']; |
309
|
|
|
} else { |
310
|
|
|
$data['error_meta_h1'] = array(); |
311
|
|
|
} |
312
|
|
|
|
313
|
|
|
if (isset($this->error['keyword'])) { |
314
|
|
|
$data['error_keyword'] = $this->error['keyword']; |
315
|
|
|
} else { |
316
|
|
|
$data['error_keyword'] = ''; |
317
|
|
|
} |
318
|
|
|
|
319
|
|
|
$url = ''; |
320
|
|
|
|
321
|
|
|
if (isset($this->request->get['sort'])) { |
322
|
|
|
$url .= '&sort=' . $this->request->get['sort']; |
323
|
|
|
} |
324
|
|
|
|
325
|
|
|
if (isset($this->request->get['order'])) { |
326
|
|
|
$url .= '&order=' . $this->request->get['order']; |
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
if (isset($this->request->get['page'])) { |
330
|
|
|
$url .= '&page=' . $this->request->get['page']; |
331
|
|
|
} |
332
|
|
|
|
333
|
|
|
$data['breadcrumbs'] = array(); |
334
|
|
|
|
335
|
|
|
$data['breadcrumbs'][] = array( |
336
|
|
|
'text' => $this->language->get('text_home'), |
337
|
|
|
'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], true) |
338
|
|
|
); |
339
|
|
|
|
340
|
|
|
$data['breadcrumbs'][] = array( |
341
|
|
|
'text' => $this->language->get('heading_title'), |
342
|
|
|
'href' => $this->url->link('blog/category', 'token=' . $this->session->data['token'] . $url, true) |
343
|
|
|
); |
344
|
|
|
|
345
|
|
|
if (!isset($this->request->get['blog_category_id'])) { |
346
|
|
|
$data['action'] = $this->url->link('blog/category/add', 'token=' . $this->session->data['token'] . $url, true); |
347
|
|
|
} else { |
348
|
|
|
$data['action'] = $this->url->link('blog/category/edit', 'token=' . $this->session->data['token'] . '&blog_category_id=' . $this->request->get['blog_category_id'] . $url, true); |
349
|
|
|
} |
350
|
|
|
|
351
|
|
|
$data['cancel'] = $this->url->link('blog/category', 'token=' . $this->session->data['token'] . $url, true); |
352
|
|
|
|
353
|
|
|
if (isset($this->request->get['blog_category_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { |
354
|
|
|
$category_info = $this->model_blog_category->getCategory($this->request->get['blog_category_id']); |
355
|
|
|
} |
356
|
|
|
|
357
|
|
|
$data['token'] = $this->session->data['token']; |
358
|
|
|
|
359
|
|
|
$this->load->model('localisation/language'); |
360
|
|
|
|
361
|
|
|
$data['languages'] = $this->model_localisation_language->getLanguages(); |
362
|
|
|
|
363
|
|
|
if (isset($this->request->post['category_description'])) { |
364
|
|
|
$data['category_description'] = $this->request->post['category_description']; |
365
|
|
|
} elseif (isset($this->request->get['blog_category_id'])) { |
366
|
|
|
$data['category_description'] = $this->model_blog_category->getCategoryDescriptions($this->request->get['blog_category_id']); |
367
|
|
|
} else { |
368
|
|
|
$data['category_description'] = array(); |
369
|
|
|
} |
370
|
|
|
|
371
|
|
|
$language_id = $this->config->get('config_language_id'); |
372
|
|
|
if (isset($data['category_description'][$language_id]['name'])) { |
373
|
|
|
$data['heading_title'] = $data['category_description'][$language_id]['name']; |
374
|
|
|
} |
375
|
|
|
|
376
|
|
|
if (isset($this->request->post['path'])) { |
377
|
|
|
$data['path'] = $this->request->post['path']; |
378
|
|
|
} elseif (!empty($category_info)) { |
379
|
|
|
$data['path'] = $category_info['path']; |
380
|
|
|
} else { |
381
|
|
|
$data['path'] = ''; |
382
|
|
|
} |
383
|
|
|
|
384
|
|
|
if (isset($this->request->post['parent_id'])) { |
385
|
|
|
$data['parent_id'] = $this->request->post['parent_id']; |
386
|
|
|
} elseif (!empty($category_info)) { |
387
|
|
|
$data['parent_id'] = $category_info['parent_id']; |
388
|
|
|
} else { |
389
|
|
|
$data['parent_id'] = 0; |
390
|
|
|
} |
391
|
|
|
|
392
|
|
|
if (isset($this->request->post['keyword'])) { |
393
|
|
|
$data['keyword'] = $this->request->post['keyword']; |
394
|
|
|
} elseif (!empty($category_info)) { |
395
|
|
|
$data['keyword'] = $category_info['keyword']; |
396
|
|
|
} else { |
397
|
|
|
$data['keyword'] = ''; |
398
|
|
|
} |
399
|
|
|
|
400
|
|
|
if (isset($this->request->post['image'])) { |
401
|
|
|
$data['image'] = $this->request->post['image']; |
402
|
|
|
} elseif (!empty($category_info)) { |
403
|
|
|
$data['image'] = $category_info['image']; |
404
|
|
|
} else { |
405
|
|
|
$data['image'] = ''; |
406
|
|
|
} |
407
|
|
|
|
408
|
|
|
|
409
|
|
|
|
410
|
|
|
if (isset($this->request->post['image']) && is_file($_SERVER['DOCUMENT_ROOT'] . '/public_html/assets/images/' . $this->request->post['image'])) { |
411
|
|
|
$data['thumb'] = '/public_html/assets/images/' . $this->request->post['image']; |
412
|
|
|
} elseif (!empty($article_info) && is_file($_SERVER['DOCUMENT_ROOT'] . '/public_html/assets/images/' . $category_info['image'])) { |
|
|
|
|
413
|
|
|
$data['thumb'] = '/public_html/assets/images/' . $category_info['image']; |
414
|
|
|
} else { |
415
|
|
|
$data['thumb'] = '/public_html/assets/images/no_image.png'; |
416
|
|
|
} |
417
|
|
|
|
418
|
|
|
$data['placeholder'] = '/public_html/assets/images/no_image.png'; |
419
|
|
|
|
420
|
|
|
if (isset($this->request->post['top'])) { |
421
|
|
|
$data['top'] = $this->request->post['top']; |
422
|
|
|
} elseif (!empty($category_info)) { |
423
|
|
|
$data['top'] = $category_info['top']; |
424
|
|
|
} else { |
425
|
|
|
$data['top'] = 0; |
426
|
|
|
} |
427
|
|
|
|
428
|
|
|
if (isset($this->request->post['column'])) { |
429
|
|
|
$data['column'] = $this->request->post['column']; |
430
|
|
|
} elseif (!empty($category_info)) { |
431
|
|
|
$data['column'] = $category_info['column']; |
432
|
|
|
} else { |
433
|
|
|
$data['column'] = 1; |
434
|
|
|
} |
435
|
|
|
|
436
|
|
|
if (isset($this->request->post['sort_order'])) { |
437
|
|
|
$data['sort_order'] = $this->request->post['sort_order']; |
438
|
|
|
} elseif (!empty($category_info)) { |
439
|
|
|
$data['sort_order'] = $category_info['sort_order']; |
440
|
|
|
} else { |
441
|
|
|
$data['sort_order'] = 0; |
442
|
|
|
} |
443
|
|
|
|
444
|
|
|
if (isset($this->request->post['status'])) { |
445
|
|
|
$data['status'] = $this->request->post['status']; |
446
|
|
|
} elseif (!empty($category_info)) { |
447
|
|
|
$data['status'] = $category_info['status']; |
448
|
|
|
} else { |
449
|
|
|
$data['status'] = true; |
450
|
|
|
} |
451
|
|
|
|
452
|
|
|
if (isset($this->request->post['noindex'])) { |
453
|
|
|
$data['noindex'] = $this->request->post['noindex']; |
454
|
|
|
} elseif (!empty($category_info)) { |
455
|
|
|
$data['noindex'] = $category_info['noindex']; |
456
|
|
|
} else { |
457
|
|
|
$data['noindex'] = 1; |
458
|
|
|
} |
459
|
|
|
|
460
|
|
|
if (isset($this->request->post['category_layout'])) { |
461
|
|
|
$data['category_layout'] = $this->request->post['category_layout']; |
462
|
|
|
} elseif (isset($this->request->get['blog_category_id'])) { |
463
|
|
|
$data['category_layout'] = $this->model_blog_category->getCategoryLayouts($this->request->get['blog_category_id']); |
464
|
|
|
} else { |
465
|
|
|
$data['category_layout'] = array(); |
466
|
|
|
} |
467
|
|
|
|
468
|
|
|
$this->load->model('design/layout'); |
469
|
|
|
|
470
|
|
|
$data['layouts'] = $this->model_design_layout->getLayouts(); |
471
|
|
|
|
472
|
|
|
$data['header'] = $this->load->controller('common/header'); |
473
|
|
|
$data['column'] = $this->load->controller('common/column_left'); |
474
|
|
|
$data['footer'] = $this->load->controller('common/footer'); |
475
|
|
|
|
476
|
|
|
$this->response->setOutput($this->load->view('blog/category_form', $data)); |
477
|
|
|
} |
478
|
|
|
|
479
|
|
|
protected function validateForm() |
480
|
|
|
{ |
481
|
|
|
if (!$this->user->hasPermission('modify', 'blog/category')) { |
482
|
|
|
$this->error['warning'] = $this->language->get('error_permission'); |
483
|
|
|
} |
484
|
|
|
|
485
|
|
|
foreach ($this->request->post['category_description'] as $language_id => $value) { |
486
|
|
|
if ((\voku\helper\UTF8::strlen($value['name']) < 2) || (\voku\helper\UTF8::strlen($value['name']) > 255)) { |
487
|
|
|
$this->error['name'][$language_id] = $this->language->get('error_name'); |
488
|
|
|
} |
489
|
|
|
|
490
|
|
|
if ((\voku\helper\UTF8::strlen($value['meta_title']) < 0) || (\voku\helper\UTF8::strlen($value['meta_title']) > 255)) { |
491
|
|
|
$this->error['meta_title'][$language_id] = $this->language->get('error_meta_title'); |
492
|
|
|
} |
493
|
|
|
|
494
|
|
|
if ((\voku\helper\UTF8::strlen($value['meta_h1']) < 0) || (\voku\helper\UTF8::strlen($value['meta_h1']) > 255)) { |
495
|
|
|
$this->error['meta_h1'][$language_id] = $this->language->get('error_meta_h1'); |
496
|
|
|
} |
497
|
|
|
} |
498
|
|
|
|
499
|
|
|
if (\voku\helper\UTF8::strlen($this->request->post['keyword']) > 0) { |
500
|
|
|
$this->load->model('catalog/url_alias'); |
501
|
|
|
|
502
|
|
|
$url_alias_info = $this->model_catalog_url_alias->getUrlAlias($this->request->post['keyword']); |
503
|
|
|
|
504
|
|
|
if ($url_alias_info && isset($this->request->get['blog_category_id']) && $url_alias_info['query'] != 'blog_category_id=' . $this->request->get['blog_category_id']) { |
505
|
|
|
$this->error['keyword'] = sprintf($this->language->get('error_keyword')); |
506
|
|
|
} |
507
|
|
|
|
508
|
|
|
if ($url_alias_info && !isset($this->request->get['blog_category_id'])) { |
509
|
|
|
$this->error['keyword'] = sprintf($this->language->get('error_keyword')); |
510
|
|
|
} |
511
|
|
|
|
512
|
|
|
if ($this->error && !isset($this->error['warning'])) { |
513
|
|
|
$this->error['warning'] = $this->language->get('error_warning'); |
514
|
|
|
} |
515
|
|
|
} |
516
|
|
|
|
517
|
|
|
return !$this->error; |
518
|
|
|
} |
519
|
|
|
|
520
|
|
|
public function enable() |
521
|
|
|
{ |
522
|
|
|
$this->load->language('blog/category'); |
523
|
|
|
|
524
|
|
|
$this->document->setTitle($this->language->get('heading_title')); |
525
|
|
|
|
526
|
|
|
$this->load->model('blog/category'); |
527
|
|
|
|
528
|
|
|
if (isset($this->request->post['selected'])) { |
529
|
|
|
foreach ($this->request->post['selected'] as $blog_category_id) { |
530
|
|
|
$this->model_blog_category->editCategoryStatus($blog_category_id, 1); |
531
|
|
|
} |
532
|
|
|
|
533
|
|
|
$this->session->data['success'] = $this->language->get('text_success'); |
534
|
|
|
|
535
|
|
|
$url = ''; |
536
|
|
|
|
537
|
|
|
if (isset($this->request->get['page'])) { |
538
|
|
|
$url .= '&page=' . $this->request->get['page']; |
539
|
|
|
} |
540
|
|
|
|
541
|
|
|
if (isset($this->request->get['sort'])) { |
542
|
|
|
$url .= '&sort=' . $this->request->get['sort']; |
543
|
|
|
} |
544
|
|
|
|
545
|
|
|
if (isset($this->request->get['order'])) { |
546
|
|
|
$url .= '&order=' . $this->request->get['order']; |
547
|
|
|
} |
548
|
|
|
|
549
|
|
|
$this->response->redirect($this->url->link('blog/category', 'token=' . $this->session->data['token'] . $url, true)); |
550
|
|
|
} |
551
|
|
|
|
552
|
|
|
$this->getList(); |
553
|
|
|
} |
554
|
|
|
|
555
|
|
|
public function disable() |
556
|
|
|
{ |
557
|
|
|
$this->load->language('blog/category'); |
558
|
|
|
|
559
|
|
|
$this->document->setTitle($this->language->get('heading_title')); |
560
|
|
|
|
561
|
|
|
$this->load->model('blog/category'); |
562
|
|
|
|
563
|
|
|
if (isset($this->request->post['selected'])) { |
564
|
|
|
foreach ($this->request->post['selected'] as $blog_category_id) { |
565
|
|
|
$this->model_blog_category->editCategoryStatus($blog_category_id, 0); |
566
|
|
|
} |
567
|
|
|
|
568
|
|
|
$this->session->data['success'] = $this->language->get('text_success'); |
569
|
|
|
|
570
|
|
|
$url = ''; |
571
|
|
|
|
572
|
|
|
if (isset($this->request->get['page'])) { |
573
|
|
|
$url .= '&page=' . $this->request->get['page']; |
574
|
|
|
} |
575
|
|
|
|
576
|
|
|
if (isset($this->request->get['sort'])) { |
577
|
|
|
$url .= '&sort=' . $this->request->get['sort']; |
578
|
|
|
} |
579
|
|
|
|
580
|
|
|
if (isset($this->request->get['order'])) { |
581
|
|
|
$url .= '&order=' . $this->request->get['order']; |
582
|
|
|
} |
583
|
|
|
|
584
|
|
|
$this->response->redirect($this->url->link('blog/category', 'token=' . $this->session->data['token'] . $url, true)); |
585
|
|
|
} |
586
|
|
|
|
587
|
|
|
$this->getList(); |
588
|
|
|
} |
589
|
|
|
|
590
|
|
|
protected function validateDelete() |
591
|
|
|
{ |
592
|
|
|
if (!$this->user->hasPermission('modify', 'blog/category')) { |
593
|
|
|
$this->error['warning'] = $this->language->get('error_permission'); |
594
|
|
|
} |
595
|
|
|
|
596
|
|
|
return !$this->error; |
597
|
|
|
} |
598
|
|
|
|
599
|
|
|
protected function validateRepair() |
600
|
|
|
{ |
601
|
|
|
if (!$this->user->hasPermission('modify', 'blog/category')) { |
602
|
|
|
$this->error['warning'] = $this->language->get('error_permission'); |
603
|
|
|
} |
604
|
|
|
|
605
|
|
|
return !$this->error; |
606
|
|
|
} |
607
|
|
|
|
608
|
|
|
public function autocomplete() |
609
|
|
|
{ |
610
|
|
|
$json = array(); |
611
|
|
|
|
612
|
|
|
if (isset($this->request->get['filter_name'])) { |
613
|
|
|
$this->load->model('blog/category'); |
614
|
|
|
|
615
|
|
|
$filter_data = array( |
616
|
|
|
'filter_name' => $this->request->get['filter_name'], |
617
|
|
|
'sort' => 'name', |
618
|
|
|
'order' => 'ASC', |
619
|
|
|
'start' => 0, |
620
|
|
|
'limit' => 5 |
621
|
|
|
); |
622
|
|
|
|
623
|
|
|
$results = $this->model_blog_category->getCategories($filter_data); |
624
|
|
|
|
625
|
|
|
foreach ($results as $result) { |
626
|
|
|
$json[] = array( |
627
|
|
|
'blog_category_id' => $result['blog_category_id'], |
628
|
|
|
'name' => strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8')) |
629
|
|
|
); |
630
|
|
|
} |
631
|
|
|
} |
632
|
|
|
|
633
|
|
|
$sort_order = array(); |
634
|
|
|
|
635
|
|
|
foreach ($json as $key => $value) { |
636
|
|
|
$sort_order[$key] = $value['name']; |
637
|
|
|
} |
638
|
|
|
|
639
|
|
|
array_multisort($sort_order, SORT_ASC, $json); |
640
|
|
|
|
641
|
|
|
$this->response->addHeader('Content-Type: application/json'); |
642
|
|
|
$this->response->setOutput(json_encode($json)); |
643
|
|
|
} |
644
|
|
|
|
645
|
|
|
private function getCategories($parent_id, $parent_path = '', $indent = '') |
646
|
|
|
{ |
647
|
|
|
$blog_category_id = array_shift($this->path); |
648
|
|
|
$output = array(); |
649
|
|
|
static $href_category = null; |
650
|
|
|
static $href_action = null; |
651
|
|
|
if ($href_category === null) { |
652
|
|
|
$href_category = $this->url->link('blog/category', 'token=' . $this->session->data['token'] . '&path=', true); |
653
|
|
|
$href_action = $this->url->link('blog/category/update', 'token=' . $this->session->data['token'] . '&blog_category_id=', true); |
654
|
|
|
} |
655
|
|
|
$results = $this->model_blog_category->getCategoriesByParentId($parent_id); |
656
|
|
|
foreach ($results as $result) { |
657
|
|
|
$path = $parent_path . $result['blog_category_id']; |
658
|
|
|
$href = ($result['children']) ? $href_category . $path : ''; |
659
|
|
|
$name = $result['name']; |
660
|
|
|
if ($blog_category_id == $result['blog_category_id']) { |
661
|
|
|
$name = '<b>' . $name . '</b>'; |
662
|
|
|
$data['breadcrumbs'][] = array( |
663
|
|
|
'text' => $result['name'], |
664
|
|
|
'href' => $href, |
665
|
|
|
'separator' => ' :: ' |
666
|
|
|
); |
667
|
|
|
$href = ''; |
668
|
|
|
} |
669
|
|
|
$selected = isset($this->request->post['selected']) && in_array($result['blog_category_id'], $this->request->post['selected']); |
670
|
|
|
$action = array(); |
671
|
|
|
$action[] = array( |
672
|
|
|
'text' => $this->language->get('text_edit'), |
673
|
|
|
'href' => $href_action . $result['blog_category_id'] |
674
|
|
|
); |
675
|
|
|
$output[$result['blog_category_id']] = array( |
676
|
|
|
'blog_category_id' => $result['blog_category_id'], |
677
|
|
|
'name' => $name, |
678
|
|
|
'sort_order' => $result['sort_order'], |
679
|
|
|
'noindex' => $result['noindex'], |
680
|
|
|
'edit' => $this->url->link('blog/category/edit', 'token=' . $this->session->data['token'] . '&blog_category_id=' . $result['blog_category_id'], true), |
681
|
|
|
'selected' => $selected, |
682
|
|
|
'action' => $action, |
683
|
|
|
'href' => $href, |
684
|
|
|
'href_shop' => '/index.php?route=blog/category&blog_category_id=' . ($result['blog_category_id']), |
685
|
|
|
'indent' => $indent |
686
|
|
|
); |
687
|
|
|
if ($blog_category_id == $result['blog_category_id']) { |
688
|
|
|
$output += $this->getCategories($result['blog_category_id'], $path . '_', $indent . str_repeat(' ', 8)); |
689
|
|
|
} |
690
|
|
|
} |
691
|
|
|
return $output; |
692
|
|
|
} |
693
|
|
|
private function getAllCategories($categories, $parent_id = 0, $parent_name = '') |
694
|
|
|
{ |
695
|
|
|
$output = array(); |
696
|
|
|
if (array_key_exists($parent_id, $categories)) { |
697
|
|
|
if ($parent_name != '') { |
698
|
|
|
$parent_name .= $this->language->get('text_separator'); |
699
|
|
|
} |
700
|
|
|
foreach ($categories[$parent_id] as $category) { |
701
|
|
|
$output[$category['blog_category_id']] = array( |
702
|
|
|
'blog_category_id' => $category['blog_category_id'], |
703
|
|
|
'name' => $parent_name . $category['name'] |
704
|
|
|
); |
705
|
|
|
$output += $this->getAllCategories($categories, $category['blog_category_id'], $parent_name . $category['name']); |
|
|
|
|
706
|
|
|
} |
707
|
|
|
} |
708
|
|
|
return $output; |
709
|
|
|
} |
710
|
|
|
} |
711
|
|
|
|
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.