This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | use CMSFactory\assetManager; |
||
4 | use core\models\Route; |
||
5 | use core\models\RouteQuery; |
||
6 | |||
7 | (defined('BASEPATH')) OR exit('No direct script access allowed'); |
||
8 | |||
9 | /** |
||
10 | * @author Gula Andrew <[email protected]> |
||
11 | * @property Cms_base $cms_base |
||
12 | */ |
||
13 | class Admin extends BaseAdminController |
||
14 | { |
||
15 | |||
16 | public function __construct() { |
||
17 | parent::__construct(); |
||
18 | $lang = new MY_Lang(); |
||
19 | $lang->load('trash'); |
||
20 | |||
21 | $this->load->library('DX_Auth'); |
||
22 | |||
23 | assetManager::create()->registerScript('script'); |
||
24 | //cp_check_perm('module_admin'); |
||
25 | } |
||
26 | |||
27 | public function search_url($type_search = 'old') { |
||
28 | $type_search = $type_search == 'old' ? 'old' : 'new'; |
||
29 | // old = старый урл, new - новый урл |
||
30 | if ($this->input->get()) { |
||
31 | $get = $this->input->get(); |
||
32 | if ($type_search == 'old') { |
||
33 | $this->db->select('id, trash_url as text'); |
||
34 | $this->db->like('trash_url', $get['term'], 'both'); |
||
35 | } else { |
||
36 | $this->db->select('id, trash_redirect as text'); |
||
37 | $this->db->like('trash_redirect', $get['term'], 'both'); |
||
38 | } |
||
39 | |||
40 | $this->db->order_by('id', 'DESC'); |
||
41 | $this->db->limit(100); |
||
42 | $result = $this->db->get('trash')->result_array(); |
||
43 | $json_answer = []; |
||
44 | if ($result) { |
||
45 | foreach ($result as $res) { |
||
46 | $json_answer[] = [ |
||
47 | 'value' => $res['text'], |
||
48 | 'identifier' => [ |
||
49 | 'id' => $res['id'], |
||
50 | ], |
||
51 | ]; |
||
52 | } |
||
53 | return json_encode($json_answer); |
||
54 | } else { |
||
55 | return json_encode([]); |
||
56 | } |
||
57 | } |
||
58 | } |
||
59 | |||
60 | public function index() { |
||
61 | $countTotalRows = (int) $this->db->get('trash')->num_rows(); |
||
62 | $perPage = (int) $this->input->get('per_page'); |
||
63 | if (empty($perPage)) { |
||
64 | $perPage = 0; |
||
65 | } |
||
66 | $this->db->offset($perPage); |
||
67 | $this->db->limit(25); |
||
68 | $query = $this->db->get('trash')->result(); |
||
69 | |||
70 | $this->load->library('pagination'); |
||
71 | $config['base_url'] = site_url('admin/components/cp/trash?'); |
||
0 ignored issues
–
show
|
|||
72 | $config['uri_segment'] = $perPage; |
||
73 | $config['total_rows'] = $countTotalRows; |
||
74 | $config['per_page'] = 25; |
||
75 | $config['page_query_string'] = true; |
||
76 | $config['full_tag_open'] = '<div class="pagination pull-left"><ul>'; |
||
77 | $config['full_tag_close'] = '</ul></div>'; |
||
78 | $config['controls_tag_open'] = '<div class="pagination pull-right"><ul>'; |
||
79 | $config['controls_tag_close'] = '</ul></div>'; |
||
80 | $config['next_link'] = lang('Next', 'admin') . ' >'; |
||
81 | $config['prev_link'] = '< ' . lang('Prev', 'admin'); |
||
82 | $config['cur_tag_open'] = '<li class="btn-primary active"><span>'; |
||
83 | $config['cur_tag_close'] = '</span></li>'; |
||
84 | $config['prev_tag_open'] = '<li>'; |
||
85 | $config['last_tag_close'] = '</li>'; |
||
86 | $config['last_tag_open'] = '<li>'; |
||
87 | $config['first_tag_close'] = '</li>'; |
||
88 | $config['first_tag_open'] = '<li>'; |
||
89 | $config['prev_tag_close'] = '</li>'; |
||
90 | $config['next_tag_open'] = '<li>'; |
||
91 | $config['next_tag_close'] = '</li>'; |
||
92 | $config['num_tag_close'] = '</li>'; |
||
93 | $config['num_tag_open'] = '<li>'; |
||
94 | $config['num_tag_close'] = '</li>'; |
||
95 | $this->pagination->num_links = 5; |
||
96 | $this->pagination->initialize($config); |
||
97 | |||
98 | assetManager::create() |
||
99 | ->setData('model', $query) |
||
100 | ->setData('pagination', $this->pagination->create_links_ajax()) |
||
101 | ->registerScript('admin') |
||
102 | ->renderAdmin('main'); |
||
103 | } |
||
104 | |||
105 | public function create_trash_list() { |
||
106 | assetManager::create()->registerScript('admin')->renderAdmin('create_trash_list'); |
||
107 | } |
||
108 | |||
109 | public function trash_list() { |
||
110 | if ($this->input->post('urls')) { |
||
111 | $data = nl2br($this->input->post('urls')); |
||
112 | $data = explode('<br />', $data); |
||
113 | $data = array_map('trim', $data); |
||
114 | $data = array_filter($data); |
||
115 | |||
116 | $this->load->module('trash'); |
||
117 | |||
118 | foreach ($data as $value) { |
||
119 | |||
120 | $value = explode(' ', $value); |
||
121 | try { |
||
122 | $this->trash->create_redirect($value[0], $value[1], $value[2]); |
||
123 | $this->lib_admin->log(lang('Redirect created', 'trash') . '. Id:' . $this->db->insert_id()); |
||
124 | } catch (Exception $exc) { |
||
125 | showMessage($exc->getMessage(), false, 'r'); |
||
126 | exit; |
||
127 | } |
||
128 | } |
||
129 | |||
130 | showMessage(lang('List of redirects has been created', 'trash')); |
||
131 | |||
132 | if ($this->input->post('action') == 'exit') { |
||
133 | pjax('/admin/components/init_window/trash'); |
||
134 | } |
||
135 | } else { |
||
136 | showMessage(lang('Error', 'admin'), false, 'r'); |
||
137 | } |
||
138 | } |
||
139 | |||
140 | public function create_trash() { |
||
141 | $this->form_validation->set_rules('url', 'Url', 'required'); |
||
142 | |||
143 | $this->db->where('name', 'shop')->get('components'); |
||
144 | |||
145 | $this->_addShopData(); |
||
146 | |||
147 | $this->db->order_by('name', 'asc'); |
||
148 | $query = $this->db->get('category'); |
||
149 | |||
150 | ($this->ajaxRequest) OR assetManager::create()->setData(['category_base' => $query->result()])->registerScript('admin')->renderAdmin('create_trash'); |
||
151 | |||
152 | if ($this->input->post()) { |
||
153 | if ($this->form_validation->run($this) == false) { |
||
154 | showMessage(validation_errors(), '', 'r'); |
||
155 | } else { |
||
156 | |||
157 | switch ($this->input->post('redirect_type')) { |
||
158 | |||
159 | View Code Duplication | case 'url': |
|
160 | $array = [ |
||
161 | 'trash_url' => ltrim($this->input->post('url'), '/'), |
||
162 | 'trash_redirect_type' => $this->input->post('redirect_type'), |
||
163 | 'trash_type' => $this->input->post('type'), |
||
164 | 'trash_redirect' => $this->input->post('redirect_url'), |
||
165 | ]; |
||
166 | break; |
||
167 | |||
168 | View Code Duplication | case 'product': |
|
169 | $route = RouteQuery::create() |
||
170 | ->filterByEntityId($this->input->post('products')) |
||
171 | ->filterByType(Route::TYPE_PRODUCT) |
||
172 | ->findOne(); |
||
173 | |||
174 | $array = [ |
||
175 | 'trash_id' => $this->input->post('products'), |
||
176 | 'trash_url' => ltrim($this->input->post('url'), '/'), |
||
177 | 'trash_redirect_type' => $this->input->post('redirect_type'), |
||
178 | 'trash_type' => $this->input->post('type'), |
||
179 | 'trash_redirect' => site_url($route->getRouteUrl()), |
||
180 | ]; |
||
181 | break; |
||
182 | |||
183 | View Code Duplication | case 'category': |
|
184 | $route = RouteQuery::create() |
||
185 | ->filterByEntityId($this->input->post('category')) |
||
186 | ->filterByType(Route::TYPE_SHOP_CATEGORY) |
||
187 | ->findOne(); |
||
188 | |||
189 | $array = [ |
||
190 | 'trash_id' => $this->input->post('category'), |
||
191 | 'trash_url' => ltrim($this->input->post('url'), '/'), |
||
192 | 'trash_redirect_type' => $this->input->post('redirect_type'), |
||
193 | 'trash_type' => $this->input->post('type'), |
||
194 | 'trash_redirect' => site_url($route->getRouteUrl()), |
||
195 | ]; |
||
196 | break; |
||
197 | |||
198 | View Code Duplication | case 'basecategory': |
|
199 | $query = $this->db->get_where('category', ['id' => $this->input->post('category_base')]); |
||
200 | $url = $query->row(); |
||
201 | $array = [ |
||
202 | 'trash_id' => $this->input->post('category_base'), |
||
203 | 'trash_url' => ltrim($this->input->post('url'), '/'), |
||
204 | 'trash_redirect_type' => $this->input->post('redirect_type'), |
||
205 | 'trash_type' => $this->input->post('type'), |
||
206 | 'trash_redirect' => site_url($this->cms_base->get_category_full_path($url->id)), |
||
207 | ]; |
||
208 | break; |
||
209 | |||
210 | View Code Duplication | case '404': |
|
211 | $array = [ |
||
212 | 'trash_url' => ltrim($this->input->post('url'), '/'), |
||
213 | 'trash_type' => $this->input->post('type'), |
||
214 | 'trash_redirect_type' => '404', |
||
215 | ]; |
||
216 | break; |
||
217 | |||
218 | View Code Duplication | default : |
|
219 | $array = [ |
||
220 | 'trash_url' => ltrim($this->input->post('url'), '/'), |
||
221 | 'trash_type' => $this->input->post('type'), |
||
222 | 'trash_redirect_type' => '404', |
||
223 | ]; |
||
224 | break; |
||
225 | } |
||
226 | |||
227 | $this->db->set($array); |
||
228 | $this->db->insert('trash'); |
||
229 | $lastId = $this->db->insert_id(); |
||
230 | |||
231 | showMessage(lang('Trash was created', 'trash')); |
||
232 | |||
233 | $this->lib_admin->log(lang('Trash was created', 'trash') . '. Url: ' . $array['trash_url']); |
||
234 | |||
235 | if ($this->input->post('action') == 'create') { |
||
236 | pjax('/admin/components/init_window/trash/edit_trash/' . $lastId); |
||
237 | } |
||
238 | if ($this->input->post('action') == 'exit') { |
||
239 | pjax('/admin/components/init_window/trash'); |
||
240 | } |
||
241 | } |
||
242 | } |
||
243 | } |
||
244 | |||
245 | /** |
||
246 | * |
||
247 | * @param integer $id |
||
248 | */ |
||
249 | public function edit_trash($id) { |
||
250 | $query = $this->db->get_where('trash', ['id' => $id]); |
||
251 | $this->template->add_array(['trash' => $query->row()]); |
||
252 | |||
253 | $this->_addShopData(); |
||
254 | |||
255 | $this->db->order_by('name', 'asc'); |
||
256 | $query = $this->db->get('category'); |
||
257 | |||
258 | if (!$this->ajaxRequest) { |
||
259 | assetManager::create() |
||
260 | ->setData(['category_base' => $query->result()]) |
||
261 | ->registerScript('admin') |
||
262 | ->renderAdmin('edit_trash'); |
||
263 | } |
||
264 | |||
265 | if ($this->input->post()) { |
||
266 | switch ($this->input->post('redirect_type')) { |
||
267 | View Code Duplication | case 'url': |
|
268 | $array = [ |
||
269 | 'id' => $this->input->post('id'), |
||
270 | 'trash_url' => $this->input->post('old_url'), |
||
271 | 'trash_redirect_type' => $this->input->post('redirect_type'), |
||
272 | 'trash_type' => $this->input->post('type'), |
||
273 | 'trash_redirect' => $this->input->post('redirect_url'), |
||
274 | ]; |
||
275 | break; |
||
276 | |||
277 | View Code Duplication | case 'product': |
|
278 | $route = RouteQuery::create() |
||
279 | ->filterByEntityId($this->input->post('products')) |
||
280 | ->filterByType(Route::TYPE_PRODUCT) |
||
281 | ->findOne(); |
||
282 | |||
283 | $array = [ |
||
284 | 'id' => $this->input->post('id'), |
||
285 | 'trash_id' => $this->input->post('products'), |
||
286 | 'trash_url' => $this->input->post('old_url'), |
||
287 | 'trash_redirect_type' => $this->input->post('redirect_type'), |
||
288 | 'trash_type' => $this->input->post('type'), |
||
289 | 'trash_redirect' => site_url($route->getRouteUrl()), |
||
290 | |||
291 | ]; |
||
292 | break; |
||
293 | |||
294 | View Code Duplication | case 'category': |
|
295 | $route = RouteQuery::create() |
||
296 | ->filterByEntityId($this->input->post('category')) |
||
297 | ->filterByType(Route::TYPE_SHOP_CATEGORY) |
||
298 | ->findOne(); |
||
299 | $array = [ |
||
300 | 'id' => $this->input->post('id'), |
||
301 | 'trash_id' => $this->input->post('category'), |
||
302 | 'trash_url' => $this->input->post('old_url'), |
||
303 | 'trash_redirect_type' => $this->input->post('redirect_type'), |
||
304 | 'trash_type' => $this->input->post('type'), |
||
305 | 'trash_redirect' => site_url($route->getRouteUrl()), |
||
306 | |||
307 | ]; |
||
308 | break; |
||
309 | |||
310 | View Code Duplication | case 'basecategory': |
|
311 | $query = $this->db->get_where('category', ['id' => $this->input->post('category_base')]); |
||
312 | $url = $query->row(); |
||
313 | |||
314 | $array = [ |
||
315 | 'id' => $this->input->post('id'), |
||
316 | 'trash_id' => $this->input->post('category_base'), |
||
317 | 'trash_url' => $this->input->post('old_url'), |
||
318 | 'trash_redirect_type' => $this->input->post('redirect_type'), |
||
319 | 'trash_type' => $this->input->post('type'), |
||
320 | 'trash_redirect' => site_url($this->cms_base->get_category_full_path($url->id)), |
||
321 | ]; |
||
322 | break; |
||
323 | |||
324 | View Code Duplication | case '404': |
|
325 | $array = [ |
||
326 | 'id' => $this->input->post('id'), |
||
327 | 'trash_redirect_type' => $this->input->post('redirect_type'), |
||
328 | 'trash_type' => $this->input->post('type'), |
||
329 | 'trash_redirect' => '', |
||
330 | ]; |
||
331 | |||
332 | break; |
||
333 | |||
334 | View Code Duplication | default : |
|
335 | $array = [ |
||
336 | 'id' => $this->input->post('id'), |
||
337 | 'trash_url' => $this->input->post('old_url'), |
||
338 | 'trash_redirect_type' => $this->input->post('redirect_type'), |
||
339 | ]; |
||
340 | break; |
||
341 | } |
||
342 | |||
343 | $this->db->where('id', $this->input->post('id')); |
||
344 | $this->db->update('trash', $array); |
||
345 | $this->lib_admin->log(lang('Redirect was edited', 'trash') . '. Url: ' . $array['trash_url']); |
||
346 | } |
||
347 | |||
348 | if ($this->input->post('action')) { |
||
349 | showMessage(lang('Successfully saved', 'trash')); |
||
350 | } |
||
351 | if ($this->input->post('action') == 'exit') { |
||
352 | pjax('/admin/components/init_window/trash'); |
||
353 | } |
||
354 | } |
||
355 | |||
356 | public function delete_trash() { |
||
357 | foreach ($this->input->post('ids') as $item) { |
||
358 | $this->db->where('id', $item); |
||
359 | $this->db->delete('trash'); |
||
360 | } |
||
361 | $this->lib_admin->log(lang('Redirect deleted', 'trash')); |
||
362 | |||
363 | showMessage(lang('Redirect deleted', 'trash')); |
||
364 | } |
||
365 | |||
366 | public function _addShopData() { |
||
367 | if (count($this->db->where('name', 'shop')->get('components')->row()) > 0) { |
||
368 | |||
369 | $locale = MY_Controller::defaultLocale(); |
||
370 | |||
371 | $shop_products_i18n = $this->db |
||
372 | ->where('locale', $locale) |
||
373 | ->order_by('name', 'asc') |
||
374 | ->get('shop_products_i18n'); |
||
375 | assetManager::create()->setData('products', $shop_products_i18n->result()); |
||
376 | |||
377 | assetManager::create()->setData('category', ShopCore::app()->SCategoryTree->getTree_()); |
||
378 | } |
||
379 | } |
||
380 | |||
381 | } |
||
382 | |||
383 | /* End of file admin.php */ |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.