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 | if (!defined('BASEPATH')) { |
||
4 | exit('No direct script access allowed'); |
||
5 | } |
||
6 | |||
7 | /** |
||
8 | * Image CMS |
||
9 | * Comments admin |
||
10 | * @property Base comments |
||
11 | */ |
||
12 | class Admin extends BaseAdminController |
||
13 | { |
||
14 | |||
15 | private $per_page = 12; |
||
16 | |||
17 | public function __construct() { |
||
18 | parent::__construct(); |
||
19 | |||
20 | $this->load->library('DX_Auth'); |
||
21 | // cp_check_perm('module_admin'); |
||
22 | |||
23 | $this->load->model('base', 'comments'); |
||
24 | |||
25 | $obj = new MY_Lang(); |
||
26 | $obj->load('comments'); |
||
27 | } |
||
28 | |||
29 | // Display comments list |
||
30 | |||
31 | public function index() { |
||
32 | $segs = $this->uri->uri_to_assoc(6); |
||
33 | |||
34 | $status = $segs['status']; |
||
35 | $off_set = $segs['page']; |
||
36 | |||
37 | switch ($status) { |
||
38 | View Code Duplication | case 'all': |
|
39 | $this->db->where('status', '0'); |
||
40 | $this->db->or_where('status', '1'); |
||
41 | $this->db->or_where('status', '2'); |
||
42 | $status_all = 'all'; |
||
43 | break; |
||
44 | |||
45 | case 'waiting': |
||
46 | $this->db->where('status', 1); |
||
47 | $status_all = '1'; |
||
48 | break; |
||
49 | |||
50 | case 'approved': |
||
51 | $this->db->where('status', 0); |
||
52 | $status_all = '0'; |
||
53 | break; |
||
54 | |||
55 | case 'spam': |
||
56 | $this->db->where('status', 2); |
||
57 | $status_all = '2'; |
||
58 | break; |
||
59 | |||
60 | View Code Duplication | default: |
|
61 | $this->db->where('status', '0'); |
||
62 | $this->db->or_where('status', '1'); |
||
63 | $status_all = 'all'; |
||
64 | $status = 'all'; |
||
65 | break; |
||
66 | } |
||
67 | |||
68 | // $comments = $this->comments->all($this->per_page, $off_set); |
||
69 | $comments = $this->comments->all(0, 0, $status_all); |
||
70 | |||
71 | if ($comments == FALSE AND $off_set > $this->per_page - 1) { |
||
72 | redirect('admin/components/cp/comments/index/status/' . $segs['status']); |
||
73 | } |
||
74 | |||
75 | if ($comments != FALSE) { |
||
76 | $cnt = count($comments); |
||
77 | for ($i = 0; $i < $cnt; $i++) { |
||
78 | if ($comments[$i]['module'] == 'core') { |
||
79 | $this->db->select('content.id, content.title'); |
||
80 | $this->db->select('route.url, if(route.parent_url <> "", concat(route.parent_url ,"/"), "") as cat_url', false); |
||
81 | $this->db->join('route', 'route.id = content.route_id'); |
||
82 | $this->db->where('content.id', $comments[$i]['item_id']); |
||
83 | $query = $this->db->get('content')->row_array(); |
||
84 | |||
85 | $comments[$i]['page_title'] = $query['title']; |
||
86 | $comments[$i]['page_url'] = site_url($query['cat_url'] . $query['url']); |
||
87 | } |
||
88 | } |
||
89 | |||
90 | if (is_array($comments)) { |
||
91 | $children = $this->proccess_child_comments($comments); |
||
92 | } |
||
93 | |||
94 | foreach ($comments as $key => $comment) { |
||
95 | if ($comment['parent'] != 0 && $status_all != 1 && $status_all != 2 && $status == 'all') { |
||
96 | unset($comments[$key]); |
||
97 | } |
||
98 | } |
||
99 | |||
100 | $total = count($comments); |
||
101 | |||
102 | View Code Duplication | if ($total > $this->per_page) { |
|
103 | $this->load->library('Pagination'); |
||
104 | |||
105 | $config['base_url'] = site_url('admin/components/cp/comments/index/status/' . $status . '/page/'); |
||
0 ignored issues
–
show
|
|||
106 | $config['total_rows'] = $total; |
||
107 | $config['per_page'] = $this->per_page; |
||
108 | $config['uri_segment'] = $this->uri->total_segments(); |
||
109 | |||
110 | $config['separate_controls'] = true; |
||
111 | $config['full_tag_open'] = '<div class="pagination pull-left"><ul>'; |
||
112 | $config['full_tag_close'] = '</ul></div>'; |
||
113 | $config['controls_tag_open'] = '<div class="pagination pull-right"><ul>'; |
||
114 | $config['controls_tag_close'] = '</ul></div>'; |
||
115 | $config['next_link'] = lang('Next', 'admin') . ' >'; |
||
116 | $config['prev_link'] = '< ' . lang('Prev', 'admin'); |
||
117 | $config['cur_tag_open'] = '<li class="btn-primary active"><span>'; |
||
118 | $config['cur_tag_close'] = '</span></li>'; |
||
119 | $config['prev_tag_open'] = '<li>'; |
||
120 | $config['prev_tag_close'] = '</li>'; |
||
121 | $config['next_tag_open'] = '<li>'; |
||
122 | $config['next_tag_close'] = '</li>'; |
||
123 | $config['num_tag_close'] = '</li>'; |
||
124 | $config['num_tag_open'] = '<li>'; |
||
125 | $config['num_tag_close'] = '</li>'; |
||
126 | |||
127 | $this->pagination->num_links = 5; |
||
128 | $this->pagination->initialize($config); |
||
129 | $this->template->assign('paginator', $this->pagination->create_links_ajax()); |
||
130 | } |
||
131 | // End pagination |
||
132 | } |
||
133 | |||
134 | $this->load->helper('string'); |
||
135 | |||
136 | if ($comments) { |
||
137 | $comments = array_splice($comments, (int) $off_set, (int) $this->per_page); |
||
138 | } else { |
||
139 | $comments = []; |
||
140 | } |
||
141 | |||
142 | // $all_comments = count($this->db->get('comments')->result_array()); |
||
143 | \CMSFactory\assetManager::create() |
||
144 | ->setData( |
||
145 | [ |
||
146 | 'comments_cur_url' => site_url(trim_slashes($this->uri->uri_string())), |
||
147 | 'comments' => $comments, |
||
148 | 'status' => $status, |
||
149 | 'children' => $children, |
||
150 | 'total_waiting' => $this->comments->count_by_status(1), |
||
151 | 'total_spam' => $this->comments->count_by_status(2), |
||
152 | 'total_app' => $this->comments->count_by_status(0), |
||
153 | 'all_comm_show' => $total, |
||
154 | ] |
||
155 | ) |
||
156 | ->registerScript('admin') |
||
157 | ->renderAdmin('comments_list'); |
||
158 | } |
||
159 | |||
160 | public function proccess_child_comments($comments = []) { |
||
161 | $children = []; |
||
162 | $i = 0; |
||
163 | foreach ($comments as $comment) { |
||
164 | if ($comment['parent'] != 0) { |
||
165 | $children[$comment['parent']][] = $comment; |
||
166 | unset($comments[$i]); |
||
167 | } |
||
168 | $i++; |
||
169 | } |
||
170 | |||
171 | return $children; |
||
172 | } |
||
173 | |||
174 | View Code Duplication | public function render($viewName, array $data = []) { |
|
175 | if (!empty($data)) { |
||
176 | $this->template->add_array($data); |
||
177 | } |
||
178 | $modContDirName = getModContDirName('comments'); |
||
179 | $this->template->show('file:' . "application/{$modContDirName}comments/templates/$viewName"); |
||
180 | } |
||
181 | |||
182 | // Edit comment |
||
183 | |||
184 | public function edit($id, $update_list = 1) { |
||
185 | $this->template->assign('comment', $this->comments->get_one($id)); |
||
186 | $this->template->assign('update_list', $update_list); |
||
187 | $this->display_tpl('edit'); |
||
188 | } |
||
189 | |||
190 | // Update comment |
||
191 | |||
192 | public function update() { |
||
193 | |||
194 | $this->load->library('form_validation'); |
||
195 | |||
196 | $this->form_validation->set_rules('user_name', lang('Author', 'admin'), 'required|trim|min_length[2]'); |
||
197 | $this->form_validation->set_rules('user_mail', lang('Email', 'admin'), 'required|trim|valid_email'); |
||
198 | $this->form_validation->set_rules('text', lang('Contents', 'comments'), 'required|trim'); |
||
199 | |||
200 | if ($this->form_validation->run() == FALSE) { |
||
201 | showMessage(validation_errors(), '', 'r'); |
||
202 | return; |
||
203 | } |
||
204 | |||
205 | $data = [ |
||
206 | 'text' => $this->input->post('text'), |
||
207 | 'user_name' => htmlspecialchars($this->input->post('user_name')), |
||
208 | 'user_mail' => htmlspecialchars($this->input->post('user_mail')), |
||
209 | 'status' => (int) $this->input->post('status'), |
||
210 | ]; |
||
211 | |||
212 | $this->comments->update($this->input->post('id'), $data); |
||
213 | |||
214 | $comment = $this->comments->get_one($this->input->post('id')); |
||
215 | |||
216 | $this->drop_cache($this->input->post('id'), $comment['module']); |
||
217 | |||
218 | $this->load->module('comments')->_recount_comments($comment['item_id'], $comment['module']); |
||
219 | |||
220 | $this->lib_admin->log(lang('Comment successfully updated', 'comments')); |
||
221 | showMessage(lang('Comment successfully updated', 'comments'), lang('Message', 'comments')); |
||
222 | |||
223 | if ($this->input->post('action') == 'exit') { |
||
224 | pjax('/admin/components/cp/comments'); |
||
225 | } |
||
226 | } |
||
227 | |||
228 | public function update_status() { |
||
229 | $this->db->where_in('id', $this->input->post('id')); |
||
230 | $this->db->update('comments', ['status' => $this->input->post('status')]); |
||
231 | |||
232 | // for children comments |
||
233 | $this->db->where_in('parent', $this->input->post('id')); |
||
234 | $this->db->update('comments', ['status' => $this->input->post('status')]); |
||
235 | /* |
||
236 | $comment = $this->comments->get_one($this->input->post('id')); |
||
237 | |||
238 | $this->drop_cache($this->input->post('id'), $comment['module']); |
||
239 | |||
240 | $this->_recount_comments($comment['item_id'], $comment['module']); |
||
241 | */ |
||
242 | |||
243 | $ids = is_array($this->input->post('id')) ? implode(', ', $this->input->post('id')) : $this->input->post('id'); |
||
244 | $this->lib_admin->log(lang('Comments status was updated', 'comments') . '. Ids: ' . $ids); |
||
245 | showMessage(lang('Status updated', 'comments'), lang('Message', 'comments')); |
||
246 | $this->load->helper('url'); |
||
247 | $url = '/' . str_replace(base_url(), '', $this->input->server('HTTP_REFERER')); |
||
248 | pjax($url); |
||
249 | } |
||
250 | |||
251 | // Delete comment |
||
252 | |||
253 | public function delete() { |
||
254 | $id = $this->input->post('id'); |
||
255 | if (is_array($id)) { |
||
256 | foreach ($id as $item) { |
||
257 | $this->drop_cache($item); |
||
258 | } |
||
259 | $comment = $this->comments->get_many($id); |
||
260 | } else { |
||
261 | $this->drop_cache($id); |
||
262 | $comment = $this->comments->get_one($id); |
||
263 | } |
||
264 | |||
265 | $this->comments->delete($id); |
||
266 | |||
267 | $this->load->module('comments')->_recount_comments($comment['item_id'], $comment['module']); |
||
268 | |||
269 | $id = is_array($id) ? implode(', ', $id) : $id; |
||
270 | $this->lib_admin->log(lang('Comment(s) deleted', 'comments') . '. Ids: ' . $id); |
||
271 | showMessage(lang('Comment(s) deleted', 'comments')); |
||
272 | |||
273 | $this->load->helper('url'); |
||
274 | $url = '/' . str_replace(base_url(), '', $this->input->server('HTTP_REFERER')); |
||
275 | pjax($url); |
||
276 | } |
||
277 | |||
278 | public function delete_many() { |
||
279 | $comments = $this->input->post('comments'); |
||
280 | |||
281 | if (count($comments) > 0) { |
||
282 | foreach ($comments as $v) { |
||
283 | $id = substr($v, 5); |
||
284 | |||
285 | // Recount total page comments. |
||
286 | $comment = $this->comments->get_one($id); |
||
287 | $this->comments->delete($id); |
||
288 | |||
289 | $this->load->module('comments')->_recount_comments($comment['item_id'], $comment['module']); |
||
290 | } |
||
291 | } |
||
292 | |||
293 | // Delete all cached comments |
||
294 | $this->cache->delete_group('comments'); |
||
295 | } |
||
296 | |||
297 | /** |
||
298 | * Delete cached comments |
||
299 | */ |
||
300 | private function drop_cache($comment_id) { |
||
301 | $this->db->select('id, item_id, module'); |
||
302 | $comment = $this->comments->get_one($comment_id); |
||
303 | $this->cache->delete('comments_' . $comment['item_id'] . $comment['module'], 'comments'); |
||
304 | } |
||
305 | |||
306 | /** |
||
307 | * Show module settings |
||
308 | */ |
||
309 | public function show_settings() { |
||
310 | $settings = $this->comments->get_settings(); |
||
311 | |||
312 | \CMSFactory\assetManager::create() |
||
313 | ->setData('settings', $settings) |
||
314 | ->renderAdmin('settings'); |
||
315 | } |
||
316 | |||
317 | public function update_settings() { |
||
318 | $data = [ |
||
319 | 'max_comment_length' => (int) $this->input->post('max_comment_length'), |
||
320 | 'period' => (int) $this->input->post('period'), |
||
321 | 'can_comment' => (int) $this->input->post('can_comment'), |
||
322 | 'use_captcha' => (bool) $this->input->post('use_captcha'), |
||
323 | 'use_moderation' => (bool) $this->input->post('use_moderation'), |
||
324 | 'order_by' => $this->input->post('order_by'), |
||
325 | ]; |
||
326 | |||
327 | $this->comments->save_settings($data); |
||
328 | $this->lib_admin->log(lang('Comments settings was edited', 'comments')); |
||
329 | showMessage(lang('Changes saved', 'comments')); |
||
330 | |||
331 | if ($this->input->post('action') == 'toedit') { |
||
332 | pjax('/admin/components/cp/comments/show_settings'); |
||
333 | } else { |
||
334 | pjax('/admin/components/cp/comments'); |
||
335 | } |
||
336 | |||
337 | } |
||
338 | |||
339 | // Template functions |
||
340 | |||
341 | private function display_tpl($file) { |
||
342 | $file = realpath(__DIR__) . '/templates/' . $file; |
||
343 | $this->template->show('file:' . $file); |
||
344 | } |
||
345 | |||
346 | } |
||
347 | |||
348 | /* 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.