1: | <?php
|
2: | namespace Opencart\Admin\Controller\Cms;
|
3: | |
4: | |
5: | |
6: | |
7: |
|
8: | class Antispam extends \Opencart\System\Engine\Controller {
|
9: | |
10: | |
11: | |
12: | |
13: |
|
14: | public function index(): void {
|
15: | $this->load->language('cms/antispam');
|
16: |
|
17: | $this->document->setTitle($this->language->get('heading_title'));
|
18: |
|
19: | if (isset($this->request->get['filter_keyword'])) {
|
20: | $filter_keyword = (string)$this->request->get['filter_keyword'];
|
21: | } else {
|
22: | $filter_keyword = '';
|
23: | }
|
24: |
|
25: | $url = '';
|
26: |
|
27: | if (isset($this->request->get['sort'])) {
|
28: | $url .= '&sort=' . $this->request->get['sort'];
|
29: | }
|
30: |
|
31: | if (isset($this->request->get['order'])) {
|
32: | $url .= '&order=' . $this->request->get['order'];
|
33: | }
|
34: |
|
35: | if (isset($this->request->get['page'])) {
|
36: | $url .= '&page=' . $this->request->get['page'];
|
37: | }
|
38: |
|
39: | $data['breadcrumbs'] = [];
|
40: |
|
41: | $data['breadcrumbs'][] = [
|
42: | 'text' => $this->language->get('text_home'),
|
43: | 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
44: | ];
|
45: |
|
46: | $data['breadcrumbs'][] = [
|
47: | 'text' => $this->language->get('heading_title'),
|
48: | 'href' => $this->url->link('cms/antispam', 'user_token=' . $this->session->data['user_token'] . $url)
|
49: | ];
|
50: |
|
51: | $data['add'] = $this->url->link('cms/antispam.form', 'user_token=' . $this->session->data['user_token'] . $url);
|
52: | $data['delete'] = $this->url->link('cms/antispam.delete', 'user_token=' . $this->session->data['user_token']);
|
53: |
|
54: | $data['list'] = $this->getList();
|
55: |
|
56: | $data['filter_keyword'] = $filter_keyword;
|
57: |
|
58: | $data['user_token'] = $this->session->data['user_token'];
|
59: |
|
60: | $data['header'] = $this->load->controller('common/header');
|
61: | $data['column_left'] = $this->load->controller('common/column_left');
|
62: | $data['footer'] = $this->load->controller('common/footer');
|
63: |
|
64: | $this->response->setOutput($this->load->view('cms/antispam', $data));
|
65: | }
|
66: |
|
67: | |
68: | |
69: | |
70: | |
71: |
|
72: | public function list(): void {
|
73: | $this->load->language('cms/antispam');
|
74: |
|
75: | $this->response->setOutput($this->getList());
|
76: | }
|
77: |
|
78: | |
79: | |
80: | |
81: | |
82: |
|
83: | protected function getList(): string {
|
84: | if (isset($this->request->get['filter_keyword'])) {
|
85: | $filter_keyword = (string)$this->request->get['filter_keyword'];
|
86: | } else {
|
87: | $filter_keyword = '';
|
88: | }
|
89: |
|
90: | if (isset($this->request->get['sort'])) {
|
91: | $sort = (string)$this->request->get['sort'];
|
92: | } else {
|
93: | $sort = 'keyword';
|
94: | }
|
95: |
|
96: | if (isset($this->request->get['order'])) {
|
97: | $order = (string)$this->request->get['order'];
|
98: | } else {
|
99: | $order = 'ASC';
|
100: | }
|
101: |
|
102: | if (isset($this->request->get['page'])) {
|
103: | $page = (int)$this->request->get['page'];
|
104: | } else {
|
105: | $page = 1;
|
106: | }
|
107: |
|
108: | $url = '';
|
109: |
|
110: | if (isset($this->request->get['filter_keyword'])) {
|
111: | $url .= '&filter_keyword=' . urlencode(html_entity_decode($this->request->get['filter_keyword'], ENT_QUOTES, 'UTF-8'));
|
112: | }
|
113: |
|
114: | if (isset($this->request->get['sort'])) {
|
115: | $url .= '&sort=' . $this->request->get['sort'];
|
116: | }
|
117: |
|
118: | if (isset($this->request->get['order'])) {
|
119: | $url .= '&order=' . $this->request->get['order'];
|
120: | }
|
121: |
|
122: | if (isset($this->request->get['page'])) {
|
123: | $url .= '&page=' . $this->request->get['page'];
|
124: | }
|
125: |
|
126: | $data['action'] = $this->url->link('cms/antispam.list', 'user_token=' . $this->session->data['user_token'] . $url);
|
127: |
|
128: | $data['antispams'] = [];
|
129: |
|
130: | $filter_data = [
|
131: | 'filter_keyword' => $filter_keyword,
|
132: | 'sort' => $sort,
|
133: | 'order' => $order,
|
134: | 'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
|
135: | 'limit' => $this->config->get('config_pagination_admin')
|
136: | ];
|
137: |
|
138: | $this->load->model('cms/antispam');
|
139: |
|
140: | $results = $this->model_cms_antispam->getAntispams($filter_data);
|
141: |
|
142: | foreach ($results as $result) {
|
143: | $data['antispams'][] = [
|
144: | 'antispam_id' => $result['antispam_id'],
|
145: | 'keyword' => $result['keyword'],
|
146: | 'edit' => $this->url->link('cms/antispam.form', 'user_token=' . $this->session->data['user_token'] . '&antispam_id=' . $result['antispam_id'] . $url)
|
147: | ];
|
148: | }
|
149: |
|
150: | $url = '';
|
151: |
|
152: | if (isset($this->request->get['filter_keyword'])) {
|
153: | $url .= '&filter_keyword=' . urlencode(html_entity_decode($this->request->get['filter_keyword'], ENT_QUOTES, 'UTF-8'));
|
154: | }
|
155: |
|
156: | if ($order == 'ASC') {
|
157: | $url .= '&order=DESC';
|
158: | } else {
|
159: | $url .= '&order=ASC';
|
160: | }
|
161: |
|
162: | $data['sort_keyword'] = $this->url->link('cms/antispam.list', 'user_token=' . $this->session->data['user_token'] . '&sort=keyword' . $url);
|
163: |
|
164: | $url = '';
|
165: |
|
166: | if (isset($this->request->get['filter_keyword'])) {
|
167: | $url .= '&filter_keyword=' . urlencode(html_entity_decode($this->request->get['filter_keyword'], ENT_QUOTES, 'UTF-8'));
|
168: | }
|
169: |
|
170: | if (isset($this->request->get['sort'])) {
|
171: | $url .= '&sort=' . $this->request->get['sort'];
|
172: | }
|
173: |
|
174: | if (isset($this->request->get['order'])) {
|
175: | $url .= '&order=' . $this->request->get['order'];
|
176: | }
|
177: |
|
178: | $antispam_total = $this->model_cms_antispam->getTotalAntispams($filter_data);
|
179: |
|
180: | $data['pagination'] = $this->load->controller('common/pagination', [
|
181: | 'total' => $antispam_total,
|
182: | 'page' => $page,
|
183: | 'limit' => $this->config->get('config_pagination_admin'),
|
184: | 'url' => $this->url->link('cms/antispam.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
|
185: | ]);
|
186: |
|
187: | $data['results'] = sprintf($this->language->get('text_pagination'), ($antispam_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($antispam_total - $this->config->get('config_pagination_admin'))) ? $antispam_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $antispam_total, ceil($antispam_total / $this->config->get('config_pagination_admin')));
|
188: |
|
189: | $data['sort'] = $sort;
|
190: | $data['order'] = $order;
|
191: |
|
192: | return $this->load->view('cms/antispam_list', $data);
|
193: | }
|
194: |
|
195: | |
196: | |
197: | |
198: | |
199: |
|
200: | public function form(): void {
|
201: | $this->load->language('cms/antispam');
|
202: |
|
203: | $this->document->setTitle($this->language->get('heading_title'));
|
204: |
|
205: | $data['text_form'] = !isset($this->request->get['antispam_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
206: |
|
207: | $url = '';
|
208: |
|
209: | if (isset($this->request->get['filter_keyword'])) {
|
210: | $url .= '&filter_keyword=' . urlencode(html_entity_decode($this->request->get['filter_keyword'], ENT_QUOTES, 'UTF-8'));
|
211: | }
|
212: |
|
213: | if (isset($this->request->get['sort'])) {
|
214: | $url .= '&sort=' . $this->request->get['sort'];
|
215: | }
|
216: |
|
217: | if (isset($this->request->get['order'])) {
|
218: | $url .= '&order=' . $this->request->get['order'];
|
219: | }
|
220: |
|
221: | if (isset($this->request->get['page'])) {
|
222: | $url .= '&page=' . $this->request->get['page'];
|
223: | }
|
224: |
|
225: | $data['breadcrumbs'] = [];
|
226: |
|
227: | $data['breadcrumbs'][] = [
|
228: | 'text' => $this->language->get('text_home'),
|
229: | 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
230: | ];
|
231: |
|
232: | $data['breadcrumbs'][] = [
|
233: | 'text' => $this->language->get('heading_title'),
|
234: | 'href' => $this->url->link('cms/antispam', 'user_token=' . $this->session->data['user_token'] . $url)
|
235: | ];
|
236: |
|
237: | $data['save'] = $this->url->link('cms/antispam.save', 'user_token=' . $this->session->data['user_token']);
|
238: | $data['back'] = $this->url->link('cms/antispam', 'user_token=' . $this->session->data['user_token'] . $url);
|
239: |
|
240: | if (isset($this->request->get['antispam_id'])) {
|
241: | $this->load->model('cms/antispam');
|
242: |
|
243: | $antispam_info = $this->model_cms_antispam->getAntispam($this->request->get['antispam_id']);
|
244: | }
|
245: |
|
246: | if (isset($this->request->get['antispam_id'])) {
|
247: | $data['antispam_id'] = (int)$this->request->get['antispam_id'];
|
248: | } else {
|
249: | $data['antispam_id'] = 0;
|
250: | }
|
251: |
|
252: | if (!empty($antispam_info)) {
|
253: | $data['keyword'] = $antispam_info['keyword'];
|
254: | } else {
|
255: | $data['keyword'] = '';
|
256: | }
|
257: |
|
258: | $data['header'] = $this->load->controller('common/header');
|
259: | $data['column_left'] = $this->load->controller('common/column_left');
|
260: | $data['footer'] = $this->load->controller('common/footer');
|
261: |
|
262: | $this->response->setOutput($this->load->view('cms/antispam_form', $data));
|
263: | }
|
264: |
|
265: | |
266: | |
267: | |
268: | |
269: |
|
270: | public function save(): void {
|
271: | $this->load->language('cms/antispam');
|
272: |
|
273: | $json = [];
|
274: |
|
275: | if (!$this->user->hasPermission('modify', 'cms/antispam')) {
|
276: | $json['error']['warning'] = $this->language->get('error_permission');
|
277: | }
|
278: |
|
279: | if (!oc_validate_length($this->request->post['keyword'], 1, 64)) {
|
280: | $json['error']['keyword'] = $this->language->get('error_keyword');
|
281: | }
|
282: |
|
283: | if (!$json) {
|
284: | $this->load->model('cms/antispam');
|
285: |
|
286: | if (!$this->request->post['antispam_id']) {
|
287: | $json['antispam_id'] = $this->model_cms_antispam->addAntispam($this->request->post);
|
288: | } else {
|
289: | $this->model_cms_antispam->editAntispam($this->request->post['antispam_id'], $this->request->post);
|
290: | }
|
291: |
|
292: | $json['success'] = $this->language->get('text_success');
|
293: | }
|
294: |
|
295: | $this->response->addHeader('Content-Type: application/json');
|
296: | $this->response->setOutput(json_encode($json));
|
297: | }
|
298: |
|
299: | |
300: | |
301: | |
302: | |
303: |
|
304: | public function delete(): void {
|
305: | $this->load->language('cms/antispam');
|
306: |
|
307: | $json = [];
|
308: |
|
309: | if (isset($this->request->post['selected'])) {
|
310: | $selected = $this->request->post['selected'];
|
311: | } else {
|
312: | $selected = [];
|
313: | }
|
314: |
|
315: | if (!$this->user->hasPermission('modify', 'cms/antispam')) {
|
316: | $json['error'] = $this->language->get('error_permission');
|
317: | }
|
318: |
|
319: | if (!$json) {
|
320: | $this->load->model('cms/antispam');
|
321: |
|
322: | foreach ($selected as $antispam_id) {
|
323: | $this->model_cms_antispam->deleteAntispam($antispam_id);
|
324: | }
|
325: |
|
326: | $json['success'] = $this->language->get('text_success');
|
327: | }
|
328: |
|
329: | $this->response->addHeader('Content-Type: application/json');
|
330: | $this->response->setOutput(json_encode($json));
|
331: | }
|
332: | }
|
333: | |