These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * |
||
4 | * @package Quick Title Edition Extension |
||
5 | * @copyright (c) 2015 ABDev |
||
6 | * @copyright (c) 2015 PastisD |
||
7 | * @copyright (c) 2015 Geolim4 <http://geolim4.com> |
||
8 | * @copyright (c) 2015 Zoddo <[email protected]> |
||
9 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 |
||
10 | * |
||
11 | */ |
||
12 | |||
13 | namespace abdev\qte; |
||
14 | |||
15 | class qte |
||
16 | { |
||
17 | const KEEP = -2; |
||
18 | const REMOVE = -1; |
||
19 | |||
20 | /** @var \phpbb\request\request */ |
||
21 | protected $request; |
||
22 | |||
23 | /** @var \phpbb\cache\driver\driver_interface */ |
||
24 | protected $cache; |
||
25 | |||
26 | /** @var \phpbb\config\config */ |
||
27 | protected $config; |
||
28 | |||
29 | /** @var \phpbb\db\driver\driver_interface */ |
||
30 | protected $db; |
||
31 | |||
32 | /** @var \phpbb\template\template */ |
||
33 | protected $template; |
||
34 | |||
35 | /** @var \phpbb\user */ |
||
36 | protected $user; |
||
37 | |||
38 | /** @var \phpbb\log\log */ |
||
39 | protected $log; |
||
40 | |||
41 | /** @var string */ |
||
42 | protected $root_path; |
||
43 | |||
44 | /** @var string */ |
||
45 | protected $php_ext; |
||
46 | |||
47 | /** @var string */ |
||
48 | protected $table_prefix; |
||
49 | |||
50 | /** @var array */ |
||
51 | protected $attr = array(); |
||
52 | |||
53 | /** @var array */ |
||
54 | protected $name = array(); |
||
55 | |||
56 | public function __construct(\phpbb\request\request $request, \phpbb\cache\driver\driver_interface $cache, \phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, \phpbb\template\template $template, \phpbb\user $user, \phpbb\log\log $log, $root_path, $php_ext, $table_prefix) |
||
57 | { |
||
58 | $this->request = $request; |
||
59 | $this->cache = $cache; |
||
60 | $this->config = $config; |
||
61 | $this->db = $db; |
||
62 | $this->template = $template; |
||
63 | $this->user = $user; |
||
64 | $this->log = $log; |
||
65 | |||
66 | $this->root_path = $root_path; |
||
67 | $this->php_ext = $php_ext; |
||
68 | $this->table_prefix = $table_prefix; |
||
69 | |||
70 | $this->get_attributes(); |
||
71 | } |
||
72 | |||
73 | protected function get_attributes() |
||
74 | { |
||
75 | if (($this->attr = $this->cache->get('_attr')) === false) |
||
76 | { |
||
77 | $sql = 'SELECT * |
||
78 | FROM ' . $this->table_prefix . 'topics_attr |
||
79 | ORDER BY left_id ASC'; |
||
80 | $result = $this->db->sql_query($sql); |
||
81 | |||
82 | $this->attr = array(); |
||
83 | while ($row = $this->db->sql_fetchrow($result)) |
||
84 | { |
||
85 | $this->attr[$row['attr_id']] = array( |
||
86 | 'attr_id' => (int) $row['attr_id'], |
||
87 | 'attr_type' => (bool) $row['attr_type'], |
||
88 | 'attr_name' => $row['attr_name'], |
||
89 | 'attr_desc' => $row['attr_desc'], |
||
90 | 'attr_img' => $row['attr_img'], |
||
91 | 'attr_colour' => $row['attr_colour'], |
||
92 | 'attr_date' => $row['attr_date'], |
||
93 | 'attr_user_colour' => (bool) $row['attr_user_colour'], |
||
94 | 'attr_auths' => $row['attr_auths'], |
||
95 | ); |
||
96 | } |
||
97 | $this->db->sql_freeresult(); |
||
98 | |||
99 | $this->cache->put('_attr', $this->attr); |
||
100 | } |
||
101 | } |
||
102 | |||
103 | public function get_users_by_topic_id($topic_list) |
||
104 | { |
||
105 | $this->name = array(); |
||
106 | if (!empty($topic_list)) |
||
107 | { |
||
108 | $sql = 'SELECT u.user_id, u.username, u.user_colour |
||
109 | FROM ' . USERS_TABLE . ' u |
||
110 | LEFT JOIN ' . TOPICS_TABLE . ' t ON (u.user_id = t.topic_attr_user) |
||
111 | WHERE ' . $this->db->sql_in_set('t.topic_id', array_map('intval', $topic_list)) . ' |
||
112 | AND t.topic_attr_user <> ' . ANONYMOUS; |
||
113 | $result = $this->db->sql_query($sql); |
||
114 | |||
115 | View Code Duplication | while ($row = $this->db->sql_fetchrow($result)) |
|
1 ignored issue
–
show
|
|||
116 | { |
||
117 | $this->name[$row['user_id']] = array( |
||
118 | 'user_id' => (int) $row['user_id'], |
||
119 | 'username' => $row['username'], |
||
120 | 'user_colour' => $row['user_colour'], |
||
121 | ); |
||
122 | } |
||
123 | $this->db->sql_freeresult(); |
||
124 | } |
||
125 | } |
||
126 | |||
127 | public function get_users_by_user_id($user_id) |
||
128 | { |
||
129 | $sql = 'SELECT user_id, username, user_colour |
||
130 | FROM ' . USERS_TABLE . ' |
||
131 | WHERE user_id = ' . (int) $user_id; |
||
132 | $result = $this->db->sql_query($sql); |
||
133 | |||
134 | $this->name = array(); |
||
135 | View Code Duplication | while ($row = $this->db->sql_fetchrow($result)) |
|
1 ignored issue
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
136 | { |
||
137 | $this->name[$row['user_id']] = array( |
||
138 | 'user_id' => (int) $row['user_id'], |
||
139 | 'username' => $row['username'], |
||
140 | 'user_colour' => $row['user_colour'], |
||
141 | ); |
||
142 | } |
||
143 | $this->db->sql_freeresult(); |
||
144 | } |
||
145 | |||
146 | public function get_attr_name_by_id($attr_id) |
||
147 | { |
||
148 | $sql = 'SELECT attr_name |
||
149 | FROM ' . $this->table_prefix . 'topics_attr |
||
150 | WHERE attr_id = ' . (int) $attr_id; |
||
151 | $result = $this->db->sql_query($sql); |
||
152 | $attr_name = (string) $this->db->sql_fetchfield('attr_name'); |
||
153 | $this->db->sql_freeresult($result); |
||
154 | |||
155 | if (empty($attr_name)) |
||
156 | { |
||
157 | return; |
||
158 | } |
||
159 | |||
160 | return $attr_name; |
||
161 | } |
||
162 | |||
163 | public function attr_select($forum_id = 0, $author_id = 0, $attribute_id = 0, $hide_attr = array()) |
||
164 | { |
||
165 | // include that file ! |
||
166 | if (!function_exists('group_memberships')) |
||
167 | { |
||
168 | include $this->root_path . 'includes/functions_user.' . $this->php_ext; |
||
169 | } |
||
170 | |||
171 | // load language |
||
172 | $this->user->add_lang_ext('abdev/qte', 'attributes'); |
||
173 | |||
174 | // get groups membership ! |
||
175 | $user_membership = group_memberships(false, $this->user->data['user_id']); |
||
176 | |||
177 | $show_remove = true; |
||
178 | $user_groups = array(); |
||
179 | if (!empty($user_membership)) |
||
180 | { |
||
181 | foreach ($user_membership as $row) |
||
182 | { |
||
183 | $row['group_id'] = (int) $row['group_id']; |
||
184 | $user_groups[$row['group_id']] = $row['group_id']; |
||
185 | } |
||
186 | } |
||
187 | unset($user_membership); |
||
188 | |||
189 | // get current time once ! |
||
190 | $current_time = time(); |
||
191 | |||
192 | $show_select = false; |
||
193 | |||
194 | $attributes = array(); |
||
195 | foreach ($this->attr as $attr) |
||
196 | { |
||
197 | if (empty($attr['attr_auths'])) |
||
198 | { |
||
199 | $attr_auths = array(array( |
||
200 | 'forums_ids' => array(), |
||
201 | 'groups_ids' => array(), |
||
202 | 'author' => false, |
||
203 | )); |
||
204 | } |
||
205 | else |
||
206 | { |
||
207 | $attr_auths = json_decode($attr['attr_auths'], true); |
||
208 | } |
||
209 | |||
210 | foreach ($attr_auths as $attr_auth) |
||
211 | { |
||
212 | $forum_ids = $attr_auth['forums_ids']; |
||
213 | $group_ids = $attr_auth['groups_ids']; |
||
214 | |||
215 | if (is_array($forum_ids) && in_array($forum_id, $forum_ids)) |
||
216 | { |
||
217 | if (is_array($group_ids) && array_intersect($group_ids, $user_groups) || ($attr_auth['author'] && ($author_id == $this->user->data['user_id']))) |
||
218 | { |
||
219 | // show the selector ! |
||
220 | $show_select = true; |
||
221 | |||
222 | $groups_removed = array_intersect($user_groups, $hide_attr); |
||
223 | if (!empty($hide_attr) && (count($groups_removed) >= count($user_groups))) |
||
224 | { |
||
225 | $show_remove = false; |
||
226 | } |
||
227 | |||
228 | if (!isset($attributes[$attr['attr_id']])) |
||
229 | { |
||
230 | // parse the attribute name |
||
231 | $attribute_name = str_replace(array('%mod%', '%date%'), array($this->user->data['username'], $this->user->format_date($current_time, $attr['attr_date'])), $this->attr_lng_key($attr['attr_name'])); |
||
232 | |||
233 | $attributes[$attr['attr_id']] = array( |
||
234 | 'type' => $attr['attr_type'], |
||
235 | 'name' => $attribute_name, |
||
236 | 'desc' => $this->attr_lng_key($attr['attr_desc']), |
||
237 | 'colour' => $this->attr_colour($attr['attr_name'], $attr['attr_colour']), |
||
238 | |||
239 | 'select' => (!empty($attribute_id) && ($attr['attr_id'] == $attribute_id)), |
||
240 | |||
241 | 's_desc' => !empty($attr['attr_desc']), |
||
242 | ); |
||
243 | } |
||
244 | } |
||
245 | } |
||
246 | } |
||
247 | unset($attr_auth); |
||
248 | } |
||
249 | unset($attr); |
||
250 | |||
251 | foreach ($attributes as $attr_id => $attr_row) |
||
252 | { |
||
253 | $this->template->assign_block_vars('attributes', array( |
||
254 | 'QTE_ID' => $attr_id, |
||
255 | 'QTE_TYPE' => $attr_row['type'], |
||
256 | 'QTE_NAME' => $attr_row['name'], |
||
257 | 'QTE_DESC' => $attr_row['desc'], |
||
258 | 'QTE_COLOUR' => $attr_row['colour'], |
||
259 | |||
260 | 'IS_SELECTED' => $attr_row['select'], |
||
261 | |||
262 | 'S_QTE_DESC' => !empty($attr_row['s_desc']) ? true : false, |
||
263 | )); |
||
264 | } |
||
265 | unset($attr_id, $attr_row); |
||
266 | |||
267 | if ($show_select) |
||
268 | { |
||
269 | $this->template->assign_vars(array( |
||
270 | 'S_QTE_SELECT' => true, |
||
271 | 'S_QTE_REMOVE' => $show_remove, |
||
272 | 'S_QTE_EMPTY' => (empty($attribute_id) || ($attribute_id == -1) || ($attribute_id == -2)), |
||
273 | 'S_QTE_SELECTED' => ($show_remove && ($attribute_id == -1)), |
||
274 | |||
275 | 'L_QTE_SELECT' => $this->user->lang['QTE_ATTRIBUTE_' . (!empty($attribute_id) ? ($show_remove ? 'REMOVE' : 'RESTRICT') : 'ADD')], |
||
276 | )); |
||
277 | } |
||
278 | } |
||
279 | |||
280 | public function attr_search() |
||
281 | { |
||
282 | // load language |
||
283 | $this->user->add_lang_ext('abdev/qte', array('attributes', 'attributes_acp')); |
||
284 | |||
285 | $show_select = false; |
||
286 | |||
287 | $attributes = array(); |
||
288 | foreach ($this->attr as $attr) |
||
289 | { |
||
290 | if (empty($attr['attr_auths'])) |
||
291 | { |
||
292 | $attr_auths = array(array( |
||
293 | 'forums_ids' => array(), |
||
294 | 'groups_ids' => array(), |
||
295 | 'author' => false, |
||
296 | )); |
||
297 | } |
||
298 | else |
||
299 | { |
||
300 | $attr_auths = json_decode($attr['attr_auths'], true); |
||
301 | } |
||
302 | |||
303 | foreach ($attr_auths as $attr_auth) |
||
304 | { |
||
305 | // show the selector ! |
||
306 | $show_select = true; |
||
307 | |||
308 | if (!isset($attributes[$attr['attr_id']])) |
||
309 | { |
||
310 | // parse the attribute name |
||
311 | $attribute_name = str_replace(array('%mod%', '%date%'), array($this->user->lang['QTE_KEY_USERNAME'], $this->user->lang['QTE_KEY_DATE']), $this->attr_lng_key($attr['attr_name'])); |
||
312 | |||
313 | $attributes[$attr['attr_id']] = array( |
||
314 | 'type' => $attr['attr_type'], |
||
315 | 'name' => $attribute_name, |
||
316 | 'desc' => $this->attr_lng_key($attr['attr_desc']), |
||
317 | 'colour' => $this->attr_colour($attr['attr_name'], $attr['attr_colour']), |
||
318 | |||
319 | 's_desc' => !empty($attr['attr_desc']) ? true : false, |
||
320 | ); |
||
321 | } |
||
322 | } |
||
323 | unset($attr_auth); |
||
324 | } |
||
325 | unset($attr); |
||
326 | |||
327 | foreach ($attributes as $attr_id => $attr_row) |
||
328 | { |
||
329 | $this->template->assign_block_vars('attributes', array( |
||
330 | 'QTE_ID' => $attr_id, |
||
331 | 'QTE_TYPE' => $attr_row['type'], |
||
332 | 'QTE_NAME' => $attr_row['name'], |
||
333 | 'QTE_DESC' => $attr_row['desc'], |
||
334 | 'QTE_COLOUR' => $attr_row['colour'], |
||
335 | |||
336 | 'S_QTE_DESC' => $attr_row['s_desc'], |
||
337 | )); |
||
338 | } |
||
339 | unset($attr_id, $attr_row); |
||
340 | |||
341 | if ($show_select) |
||
342 | { |
||
343 | $this->template->assign_var('S_QTE_SELECT', true); |
||
344 | } |
||
345 | } |
||
346 | |||
347 | View Code Duplication | public function attr_sort($forum_id = 0, $attribute_id = 0) |
|
348 | { |
||
349 | // load language |
||
350 | $this->user->add_lang_ext('abdev/qte', array('attributes', 'attributes_acp')); |
||
351 | |||
352 | $show_select = false; |
||
353 | |||
354 | $attributes = array(); |
||
355 | foreach ($this->attr as $attr) |
||
356 | { |
||
357 | if (empty($attr['attr_auths'])) |
||
358 | { |
||
359 | $attr_auths = array(array( |
||
360 | 'forums_ids' => array(), |
||
361 | 'groups_ids' => array(), |
||
362 | 'author' => false, |
||
363 | )); |
||
364 | } |
||
365 | else |
||
366 | { |
||
367 | $attr_auths = json_decode($attr['attr_auths'], true); |
||
368 | } |
||
369 | |||
370 | foreach ($attr_auths as $attr_auth) |
||
371 | { |
||
372 | $forum_ids = $attr_auth['forums_ids']; |
||
373 | |||
374 | if (is_array($forum_ids) && in_array($forum_id, $forum_ids)) |
||
375 | { |
||
376 | // show the selector ! |
||
377 | $show_select = true; |
||
378 | |||
379 | if (!isset($attributes[$attr['attr_id']])) |
||
380 | { |
||
381 | // parse the attribute name |
||
382 | $attribute_name = str_replace(array('%mod%', '%date%'), array($this->user->lang['QTE_KEY_USERNAME'], $this->user->lang['QTE_KEY_DATE']), $this->attr_lng_key($attr['attr_name'])); |
||
383 | |||
384 | $attributes[$attr['attr_id']] = array( |
||
385 | 'type' => $attr['attr_type'], |
||
386 | 'name' => $attribute_name, |
||
387 | 'desc' => $this->attr_lng_key($attr['attr_desc']), |
||
388 | 'colour' => $this->attr_colour($attr['attr_name'], $attr['attr_colour']), |
||
389 | |||
390 | 'select' => (!empty($attribute_id) && ($attr['attr_id'] == $attribute_id)) ? true : false, |
||
391 | |||
392 | 's_desc' => !empty($attr['attr_desc']) ? true : false, |
||
393 | ); |
||
394 | } |
||
395 | } |
||
396 | } |
||
397 | unset($attr_auth); |
||
398 | } |
||
399 | unset($attr); |
||
400 | |||
401 | foreach ($attributes as $attr_id => $attr_row) |
||
402 | { |
||
403 | $this->template->assign_block_vars('attributes', array( |
||
404 | 'QTE_ID' => $attr_id, |
||
405 | 'QTE_TYPE' => $attr_row['type'], |
||
406 | 'QTE_NAME' => $attr_row['name'], |
||
407 | 'QTE_DESC' => $attr_row['desc'], |
||
408 | 'QTE_COLOUR' => $attr_row['colour'], |
||
409 | |||
410 | 'IS_SELECTED' => $attr_row['select'], |
||
411 | |||
412 | 'S_QTE_DESC' => $attr_row['s_desc'], |
||
413 | )); |
||
414 | } |
||
415 | unset($attr_id, $attr_row); |
||
416 | |||
417 | if ($show_select) |
||
418 | { |
||
419 | $this->template->assign_var('S_QTE_SELECT', true); |
||
420 | } |
||
421 | } |
||
422 | |||
423 | View Code Duplication | public function attr_default($forum_id = 0, $attribute_id = 0) |
|
424 | { |
||
425 | // load language |
||
426 | $this->user->add_lang_ext('abdev/qte', array('attributes', 'attributes_acp')); |
||
427 | |||
428 | $show_select = false; |
||
429 | |||
430 | $attributes = array(); |
||
431 | foreach ($this->attr as $attr) |
||
432 | { |
||
433 | if (empty($attr['attr_auths'])) |
||
434 | { |
||
435 | $attr_auths = array(array( |
||
436 | 'forums_ids' => array(), |
||
437 | 'groups_ids' => array(), |
||
438 | 'author' => false, |
||
439 | )); |
||
440 | } |
||
441 | else |
||
442 | { |
||
443 | $attr_auths = json_decode($attr['attr_auths'], true); |
||
444 | } |
||
445 | |||
446 | foreach ($attr_auths as $attr_auth) |
||
447 | { |
||
448 | $forum_ids = $attr_auth['forums_ids']; |
||
449 | |||
450 | if (is_array($forum_ids) && in_array($forum_id, $forum_ids)) |
||
451 | { |
||
452 | // show the selector ! |
||
453 | $show_select = true; |
||
454 | |||
455 | if (!isset($attributes[$attr['attr_id']])) |
||
456 | { |
||
457 | // parse the attribute name |
||
458 | $attribute_name = str_replace(array('%mod%', '%date%'), array($this->user->lang['QTE_KEY_USERNAME'], $this->user->lang['QTE_KEY_DATE']), $this->attr_lng_key($attr['attr_name'])); |
||
459 | |||
460 | $attributes[$attr['attr_id']] = array( |
||
461 | 'type' => $attr['attr_type'], |
||
462 | 'name' => $attribute_name, |
||
463 | 'desc' => $this->attr_lng_key($attr['attr_desc']), |
||
464 | 'colour' => $this->attr_colour($attr['attr_name'], $attr['attr_colour']), |
||
465 | |||
466 | 'select' => (!empty($attribute_id) && ($attr['attr_id'] == $attribute_id)) ? true : false, |
||
467 | |||
468 | 's_desc' => !empty($attr['attr_desc']) ? true : false, |
||
469 | ); |
||
470 | } |
||
471 | } |
||
472 | } |
||
473 | unset($attr_auth); |
||
474 | } |
||
475 | unset($attr); |
||
476 | |||
477 | foreach ($attributes as $attr_id => $attr_row) |
||
478 | { |
||
479 | $this->template->assign_block_vars('attributes', array( |
||
480 | 'QTE_ID' => $attr_id, |
||
481 | 'QTE_TYPE' => $attr_row['type'], |
||
482 | 'QTE_NAME' => $attr_row['name'], |
||
483 | 'QTE_DESC' => $attr_row['desc'], |
||
484 | 'QTE_COLOUR' => $attr_row['colour'], |
||
485 | |||
486 | 'IS_SELECTED' => $attr_row['select'], |
||
487 | |||
488 | 'S_QTE_DESC' => $attr_row['s_desc'], |
||
489 | )); |
||
490 | } |
||
491 | unset($attr_id, $attr_row); |
||
492 | |||
493 | if ($show_select) |
||
494 | { |
||
495 | $this->template->assign_var('S_QTE_SELECT', true); |
||
496 | } |
||
497 | } |
||
498 | |||
499 | public function attr_display($attribute_id = 0, $user_id = 0, $timestamp = 0) |
||
500 | { |
||
501 | if (empty($attribute_id) || empty($user_id) || empty($timestamp)) |
||
502 | { |
||
503 | return false; |
||
504 | } |
||
505 | |||
506 | if (isset($this->attr[$attribute_id])) |
||
507 | { |
||
508 | $attribute_colour = $this->attr_colour($this->attr[$attribute_id]['attr_name'], $this->attr[$attribute_id]['attr_colour']); |
||
509 | |||
510 | if (isset($this->name[$user_id]['user_id'])) |
||
511 | { |
||
512 | $attribute_username = get_username_string(($this->attr[$attribute_id]['attr_user_colour'] ? 'no_profile' : 'username'), $this->name[$user_id]['user_id'], $this->name[$user_id]['username'], $this->name[$user_id]['user_colour']); |
||
513 | } |
||
514 | else |
||
515 | { |
||
516 | $attribute_username = $this->user->lang['GUEST']; |
||
517 | } |
||
518 | |||
519 | $attribute_date = $this->user->format_date($timestamp, $this->attr[$attribute_id]['attr_date']); |
||
520 | |||
521 | $attribute_name = str_replace(array('%mod%', '%date%'), array($attribute_username, $attribute_date), $this->attr_lng_key($this->attr[$attribute_id]['attr_name'])); |
||
522 | |||
523 | return !$this->attr[$attribute_id]['attr_type'] ? '<span' . $attribute_colour . '>' . $attribute_name . '</span>' : $this->attr_img_key($this->attr[$attribute_id]['attr_img'], $attribute_name); |
||
524 | } |
||
525 | } |
||
526 | |||
527 | public function attr_title($attribute_id = 0, $user_id = 0, $timestamp = 0) |
||
528 | { |
||
529 | if (empty($attribute_id) || empty($user_id) || empty($timestamp)) |
||
530 | { |
||
531 | return false; |
||
532 | } |
||
533 | |||
534 | if (isset($this->attr[$attribute_id])) |
||
535 | { |
||
536 | if (isset($this->name[$user_id]['user_id'])) |
||
537 | { |
||
538 | $attribute_username = get_username_string('username', $this->name[$user_id]['user_id'], $this->name[$user_id]['username'], $this->name[$user_id]['user_colour']); |
||
539 | } |
||
540 | else |
||
541 | { |
||
542 | $attribute_username = $this->user->lang['GUEST']; |
||
543 | } |
||
544 | |||
545 | $attribute_date = $this->user->format_date($timestamp, $this->attr[$attribute_id]['attr_date']); |
||
546 | |||
547 | $attribute_name = str_replace(array('%mod%', '%date%'), array($attribute_username, $attribute_date), $this->attr_lng_key($this->attr[$attribute_id]['attr_name'])); |
||
548 | |||
549 | return $attribute_name; |
||
550 | } |
||
551 | } |
||
552 | |||
553 | public function attr_apply($attribute_id = 0, $topic_id = 0, $forum_id = 0, $topic_attribute = '') |
||
554 | { |
||
555 | if (empty($topic_id) || empty($forum_id) || empty($attribute_id)) |
||
556 | { |
||
557 | return; |
||
558 | } |
||
559 | |||
560 | // time ! |
||
561 | $current_time = time(); |
||
562 | |||
563 | View Code Duplication | if ($attribute_id == -1) |
|
1 ignored issue
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
564 | { |
||
565 | $fields = array( |
||
566 | 'topic_attr_id' => 0, |
||
567 | 'topic_attr_user' => 0, |
||
568 | 'topic_attr_time' => 0, |
||
569 | ); |
||
570 | } |
||
571 | else |
||
572 | { |
||
573 | $fields = array( |
||
574 | 'topic_attr_id' => $attribute_id, |
||
575 | 'topic_attr_user' => $this->user->data['user_id'], |
||
576 | 'topic_attr_time' => $current_time, |
||
577 | ); |
||
578 | } |
||
579 | |||
580 | $sql = 'UPDATE ' . TOPICS_TABLE . ' |
||
581 | SET ' . $this->db->sql_build_array('UPDATE', $fields) . ' |
||
582 | WHERE topic_id = ' . (int) $topic_id; |
||
583 | $this->db->sql_query($sql); |
||
584 | |||
585 | $sql = 'SELECT topic_id |
||
586 | FROM ' . TOPICS_TABLE . ' |
||
587 | WHERE topic_moved_id = ' . (int) $topic_id; |
||
588 | $result = $this->db->sql_query($sql); |
||
589 | $shadow_topic_id = (int) $this->db->sql_fetchfield('topic_id'); |
||
590 | $this->db->sql_freeresult($result); |
||
591 | |||
592 | if (!empty($shadow_topic_id)) |
||
593 | { |
||
594 | $sql = 'UPDATE ' . TOPICS_TABLE . ' |
||
595 | SET ' . $this->db->sql_build_array('UPDATE', $fields) . ' |
||
596 | WHERE topic_id = ' . $shadow_topic_id; |
||
597 | $this->db->sql_query($sql); |
||
598 | } |
||
599 | |||
600 | $meta_url = append_sid("{$this->root_path}viewtopic.$this->php_ext", "f=$forum_id&t=$topic_id"); |
||
601 | meta_refresh(3, $meta_url); |
||
602 | |||
603 | // load language |
||
604 | $this->user->add_lang('posting'); |
||
605 | $this->user->add_lang_ext('abdev/qte', 'attributes'); |
||
606 | |||
607 | $message = $this->user->lang['QTE_ATTRIBUTE_' . ($attribute_id == -1 ? 'REMOVED' : (empty($topic_attribute) ? 'ADDED' : 'UPDATED'))] . '<br /><br />' . sprintf($this->user->lang['VIEW_MESSAGE'], '<a href="' . $meta_url . '">', '</a>'); |
||
608 | $message .= '<br /><br />' . sprintf($this->user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$this->root_path}viewforum.$this->php_ext", 'f=' . $forum_id) . '">', '</a>'); |
||
609 | |||
610 | trigger_error($message); |
||
611 | } |
||
612 | |||
613 | public function mcp_attr_apply($attribute_id = 0, $topic_ids = array()) |
||
614 | { |
||
615 | // load language |
||
616 | $this->user->add_lang_ext('abdev/qte', 'attributes'); |
||
617 | |||
618 | if (!sizeof($topic_ids)) |
||
619 | { |
||
620 | trigger_error('NO_TOPIC_SELECTED'); |
||
621 | } |
||
622 | |||
623 | if (!phpbb_check_ids($topic_ids, TOPICS_TABLE, 'topic_id')) |
||
624 | { |
||
625 | return; |
||
626 | } |
||
627 | |||
628 | // time ! |
||
629 | $current_time = time(); |
||
630 | |||
631 | $sql = 'SELECT topic_id, forum_id, topic_title, topic_attr_id |
||
632 | FROM ' . TOPICS_TABLE . ' |
||
633 | WHERE ' . $this->db->sql_in_set('topic_id', array_map('intval', $topic_ids)); |
||
634 | $result = $this->db->sql_query($sql); |
||
635 | |||
636 | // log this action |
||
637 | while ($row = $this->db->sql_fetchrow($result)) |
||
638 | { |
||
639 | $message = ($attribute_id == -1) ? 'REMOVED' : (empty($row['topic_attr_id']) ? 'ADDED' : 'UPDATED'); |
||
640 | $additional_data = array( |
||
641 | 'forum_id' => $row['forum_id'], |
||
642 | 'topic_id' => $row['topic_id'], |
||
643 | $row['topic_title'], |
||
644 | ); |
||
645 | $this->log->add('mod', $this->user->data['user_id'], $this->user->ip, 'MCP_ATTRIBUTE_' . $message, $current_time, $additional_data); |
||
646 | } |
||
647 | $this->db->sql_freeresult($result); |
||
648 | |||
649 | View Code Duplication | if ($attribute_id == -1) |
|
1 ignored issue
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
650 | { |
||
651 | $fields = array( |
||
652 | 'topic_attr_id' => 0, |
||
653 | 'topic_attr_user' => 0, |
||
654 | 'topic_attr_time' => 0, |
||
655 | ); |
||
656 | } |
||
657 | else |
||
658 | { |
||
659 | $fields = array( |
||
660 | 'topic_attr_id' => $attribute_id, |
||
661 | 'topic_attr_user' => $this->user->data['user_id'], |
||
662 | 'topic_attr_time' => $current_time, |
||
663 | ); |
||
664 | } |
||
665 | |||
666 | $sql = 'UPDATE ' . TOPICS_TABLE . ' |
||
667 | SET ' . $this->db->sql_build_array('UPDATE', $fields) . ' |
||
668 | WHERE ' . $this->db->sql_in_set('topic_id', array_map('intval', $topic_ids)); |
||
669 | $this->db->sql_query($sql); |
||
670 | |||
671 | $sql = 'SELECT topic_id |
||
672 | FROM ' . TOPICS_TABLE . ' |
||
673 | WHERE ' . $this->db->sql_in_set('topic_moved_id', array_map('intval', $topic_ids)); |
||
674 | $result = $this->db->sql_query($sql); |
||
675 | |||
676 | $shadow_topic_ids = array(); |
||
677 | while ($row = $this->db->sql_fetchrow($result)) |
||
678 | { |
||
679 | $shadow_topic_ids[] = (int) $row['topic_id']; |
||
680 | } |
||
681 | $this->db->sql_freeresult($result); |
||
682 | |||
683 | if (sizeof($shadow_topic_ids)) |
||
684 | { |
||
685 | $sql = 'UPDATE ' . TOPICS_TABLE . ' |
||
686 | SET ' . $this->db->sql_build_array('UPDATE', $fields) . ' |
||
687 | WHERE ' . $this->db->sql_in_set('topic_id', array_map('intval', $shadow_topic_ids)); |
||
688 | $this->db->sql_query($sql); |
||
689 | } |
||
690 | |||
691 | $redirect = $this->request->variable('redirect', $this->user->data['session_page']); |
||
692 | |||
693 | meta_refresh(3, $redirect); |
||
694 | trigger_error($this->user->lang['QTE_TOPIC' . (sizeof($topic_ids) == 1 ? '' : 'S') . '_ATTRIBUTE_' . $message] . '<br /><br />' . sprintf($this->user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>')); |
||
695 | |||
696 | return; |
||
697 | } |
||
698 | |||
699 | public function getAttr() |
||
700 | { |
||
701 | return $this->attr; |
||
702 | } |
||
703 | |||
704 | // borrowed function from "ACP Announcement Centre" mod |
||
705 | public function qte_group_select($group_ids, $exclude_ids = array(), $manage_founder = false) |
||
706 | { |
||
707 | $exclude_sql = ($exclude_ids !== false && sizeof($exclude_ids)) ? 'WHERE ' . $this->db->sql_in_set('group_id', array_map('intval', $exclude_ids), true) : ''; |
||
708 | $sql_and = !$this->config['coppa_enable'] ? ($exclude_sql ? ' AND ' : ' WHERE ') . "group_name <> 'REGISTERED_COPPA'" : ''; |
||
709 | $sql_founder = ($manage_founder !== false) ? (($exclude_sql || $sql_and) ? ' AND ' : ' WHERE ') . 'group_founder_manage = ' . (int) $manage_founder : ''; |
||
710 | |||
711 | $sql = 'SELECT group_id, group_name, group_type |
||
712 | FROM ' . GROUPS_TABLE . " |
||
713 | $exclude_sql |
||
714 | $sql_and |
||
715 | $sql_founder |
||
716 | ORDER BY group_type DESC, group_name ASC"; |
||
717 | $result = $this->db->sql_query($sql); |
||
718 | |||
719 | $s_group_options = ''; |
||
720 | while ($row = $this->db->sql_fetchrow($result)) |
||
721 | { |
||
722 | $selected = in_array($row['group_id'], $group_ids) ? ' selected="selected"' : ''; |
||
723 | $s_group_options .= '<option' . (($row['group_type'] == GROUP_SPECIAL) ? ' class="sep"' : '') . ' value="' . $row['group_id'] . '"' . $selected . '>' . (($row['group_type'] == GROUP_SPECIAL) ? $this->user->lang['G_' . $row['group_name']] : $row['group_name']) . '</option>'; |
||
724 | } |
||
725 | $this->db->sql_freeresult($result); |
||
726 | |||
727 | return $s_group_options; |
||
728 | } |
||
729 | |||
730 | // borrowed from "Categories Hierarchy" : used to check if a language key exists |
||
731 | public function attr_lng_key($key) |
||
732 | { |
||
733 | // load language |
||
734 | $this->user->add_lang_ext('abdev/qte', 'attributes'); |
||
735 | |||
736 | return isset($this->user->lang[$key]) ? $this->user->lang[$key] : $key; |
||
737 | } |
||
738 | |||
739 | // borrowed from "Categories Hierarchy" : used to check if a image key exists |
||
740 | public function attr_img_key($key, $alt) |
||
741 | { |
||
742 | return empty($key) ? '' : (preg_match('#^[a-z0-9_-]+$#i', $key) ? $this->user->img($key, $alt) : '<img src="' . (preg_match('#^(ht|f)tp[s]?\://#i', $key) ? $key : $this->root_path . $key) . '" alt="' . $alt . '" title="' . $alt . '" />'); |
||
743 | } |
||
744 | |||
745 | public function attr_colour($a_name, $a_colour) |
||
746 | { |
||
747 | $a_name = preg_replace("#[^a-z0-9 _-]#", '', strtolower($a_name)); |
||
748 | if (!empty($a_name)) |
||
749 | { |
||
750 | $a_name .= '-qte'; |
||
751 | } |
||
752 | |||
753 | return ' class="qte-attr ' . $a_name . '"' . (!empty($a_colour) ? ' style="color:#' . $a_colour . '; font-weight:bold;"' : ''); |
||
754 | } |
||
755 | } |
||
756 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.