@@ -14,8 +14,9 @@ discard block |
||
14 | 14 | * @version 2.1 Beta 3 |
15 | 15 | */ |
16 | 16 | |
17 | -if (!defined('SMF')) |
|
17 | +if (!defined('SMF')) { |
|
18 | 18 | die('No direct access...'); |
19 | +} |
|
19 | 20 | |
20 | 21 | /** |
21 | 22 | * The central part of the board - topic display. |
@@ -34,8 +35,9 @@ discard block |
||
34 | 35 | global $attachments, $messages_request, $language, $smcFunc; |
35 | 36 | |
36 | 37 | // What are you gonna display if these are empty?! |
37 | - if (empty($topic)) |
|
38 | - fatal_lang_error('no_board', false); |
|
38 | + if (empty($topic)) { |
|
39 | + fatal_lang_error('no_board', false); |
|
40 | + } |
|
39 | 41 | |
40 | 42 | // Load the proper template. |
41 | 43 | loadTemplate('Display'); |
@@ -52,15 +54,17 @@ discard block |
||
52 | 54 | $context['messages_per_page'] = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages']; |
53 | 55 | |
54 | 56 | // Let's do some work on what to search index. |
55 | - if (count($_GET) > 2) |
|
56 | - foreach ($_GET as $k => $v) |
|
57 | + if (count($_GET) > 2) { |
|
58 | + foreach ($_GET as $k => $v) |
|
57 | 59 | { |
58 | 60 | if (!in_array($k, array('topic', 'board', 'start', session_name()))) |
59 | 61 | $context['robot_no_index'] = true; |
62 | + } |
|
60 | 63 | } |
61 | 64 | |
62 | - if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0)) |
|
63 | - $context['robot_no_index'] = true; |
|
65 | + if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0)) { |
|
66 | + $context['robot_no_index'] = true; |
|
67 | + } |
|
64 | 68 | |
65 | 69 | // Find the previous or next topic. Make a fuss if there are no more. |
66 | 70 | if (isset($_REQUEST['prev_next']) && ($_REQUEST['prev_next'] == 'prev' || $_REQUEST['prev_next'] == 'next')) |
@@ -172,8 +176,9 @@ discard block |
||
172 | 176 | $topic_parameters |
173 | 177 | ); |
174 | 178 | |
175 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
176 | - fatal_lang_error('not_a_topic', false, 404); |
|
179 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
180 | + fatal_lang_error('not_a_topic', false, 404); |
|
181 | + } |
|
177 | 182 | $context['topicinfo'] = $smcFunc['db_fetch_assoc']($request); |
178 | 183 | $smcFunc['db_free_result']($request); |
179 | 184 | |
@@ -210,8 +215,9 @@ discard block |
||
210 | 215 | $context['topic_unwatched'] = isset($context['topicinfo']['unwatched']) ? $context['topicinfo']['unwatched'] : 0; |
211 | 216 | |
212 | 217 | // Add up unapproved replies to get real number of replies... |
213 | - if ($modSettings['postmod_active'] && $approve_posts) |
|
214 | - $context['real_num_replies'] += $context['topicinfo']['unapproved_posts'] - ($context['topicinfo']['approved'] ? 0 : 1); |
|
218 | + if ($modSettings['postmod_active'] && $approve_posts) { |
|
219 | + $context['real_num_replies'] += $context['topicinfo']['unapproved_posts'] - ($context['topicinfo']['approved'] ? 0 : 1); |
|
220 | + } |
|
215 | 221 | |
216 | 222 | // If this topic has unapproved posts, we need to work out how many posts the user can see, for page indexing. |
217 | 223 | if ($modSettings['postmod_active'] && $context['topicinfo']['unapproved_posts'] && !$user_info['is_guest'] && !$approve_posts) |
@@ -231,11 +237,11 @@ discard block |
||
231 | 237 | $smcFunc['db_free_result']($request); |
232 | 238 | |
233 | 239 | $context['total_visible_posts'] = $context['num_replies'] + $myUnapprovedPosts + ($context['topicinfo']['approved'] ? 1 : 0); |
240 | + } elseif ($user_info['is_guest']) { |
|
241 | + $context['total_visible_posts'] = $context['num_replies'] + ($context['topicinfo']['approved'] ? 1 : 0); |
|
242 | + } else { |
|
243 | + $context['total_visible_posts'] = $context['num_replies'] + $context['topicinfo']['unapproved_posts'] + ($context['topicinfo']['approved'] ? 1 : 0); |
|
234 | 244 | } |
235 | - elseif ($user_info['is_guest']) |
|
236 | - $context['total_visible_posts'] = $context['num_replies'] + ($context['topicinfo']['approved'] ? 1 : 0); |
|
237 | - else |
|
238 | - $context['total_visible_posts'] = $context['num_replies'] + $context['topicinfo']['unapproved_posts'] + ($context['topicinfo']['approved'] ? 1 : 0); |
|
239 | 245 | |
240 | 246 | // The start isn't a number; it's information about what to do, where to go. |
241 | 247 | if (!is_numeric($_REQUEST['start'])) |
@@ -248,8 +254,7 @@ discard block |
||
248 | 254 | { |
249 | 255 | $context['start_from'] = $context['total_visible_posts'] - 1; |
250 | 256 | $_REQUEST['start'] = empty($options['view_newest_first']) ? $context['start_from'] : 0; |
251 | - } |
|
252 | - else |
|
257 | + } else |
|
253 | 258 | { |
254 | 259 | // Find the earliest unread message in the topic. (the use of topics here is just for both tables.) |
255 | 260 | $request = $smcFunc['db_query']('', ' |
@@ -277,9 +282,9 @@ discard block |
||
277 | 282 | if (substr($_REQUEST['start'], 0, 4) == 'from') |
278 | 283 | { |
279 | 284 | $timestamp = (int) substr($_REQUEST['start'], 4); |
280 | - if ($timestamp === 0) |
|
281 | - $_REQUEST['start'] = 0; |
|
282 | - else |
|
285 | + if ($timestamp === 0) { |
|
286 | + $_REQUEST['start'] = 0; |
|
287 | + } else |
|
283 | 288 | { |
284 | 289 | // Find the number of messages posted before said time... |
285 | 290 | $request = $smcFunc['db_query']('', ' |
@@ -307,11 +312,11 @@ discard block |
||
307 | 312 | elseif (substr($_REQUEST['start'], 0, 3) == 'msg') |
308 | 313 | { |
309 | 314 | $virtual_msg = (int) substr($_REQUEST['start'], 3); |
310 | - if (!$context['topicinfo']['unapproved_posts'] && $virtual_msg >= $context['topicinfo']['id_last_msg']) |
|
311 | - $context['start_from'] = $context['total_visible_posts'] - 1; |
|
312 | - elseif (!$context['topicinfo']['unapproved_posts'] && $virtual_msg <= $context['topicinfo']['id_first_msg']) |
|
313 | - $context['start_from'] = 0; |
|
314 | - else |
|
315 | + if (!$context['topicinfo']['unapproved_posts'] && $virtual_msg >= $context['topicinfo']['id_last_msg']) { |
|
316 | + $context['start_from'] = $context['total_visible_posts'] - 1; |
|
317 | + } elseif (!$context['topicinfo']['unapproved_posts'] && $virtual_msg <= $context['topicinfo']['id_first_msg']) { |
|
318 | + $context['start_from'] = 0; |
|
319 | + } else |
|
315 | 320 | { |
316 | 321 | // Find the start value for that message...... |
317 | 322 | $request = $smcFunc['db_query']('', ' |
@@ -394,21 +399,25 @@ discard block |
||
394 | 399 | ); |
395 | 400 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
396 | 401 | { |
397 | - if (empty($row['id_member'])) |
|
398 | - continue; |
|
402 | + if (empty($row['id_member'])) { |
|
403 | + continue; |
|
404 | + } |
|
399 | 405 | |
400 | - if (!empty($row['online_color'])) |
|
401 | - $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>'; |
|
402 | - else |
|
403 | - $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
406 | + if (!empty($row['online_color'])) { |
|
407 | + $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>'; |
|
408 | + } else { |
|
409 | + $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
410 | + } |
|
404 | 411 | |
405 | 412 | $is_buddy = in_array($row['id_member'], $user_info['buddies']); |
406 | - if ($is_buddy) |
|
407 | - $link = '<strong>' . $link . '</strong>'; |
|
413 | + if ($is_buddy) { |
|
414 | + $link = '<strong>' . $link . '</strong>'; |
|
415 | + } |
|
408 | 416 | |
409 | 417 | // Add them both to the list and to the more detailed list. |
410 | - if (!empty($row['show_online']) || allowedTo('moderate_forum')) |
|
411 | - $context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link; |
|
418 | + if (!empty($row['show_online']) || allowedTo('moderate_forum')) { |
|
419 | + $context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link; |
|
420 | + } |
|
412 | 421 | $context['view_members'][$row['log_time'] . $row['member_name']] = array( |
413 | 422 | 'id' => $row['id_member'], |
414 | 423 | 'username' => $row['member_name'], |
@@ -420,8 +429,9 @@ discard block |
||
420 | 429 | 'hidden' => empty($row['show_online']), |
421 | 430 | ); |
422 | 431 | |
423 | - if (empty($row['show_online'])) |
|
424 | - $context['view_num_hidden']++; |
|
432 | + if (empty($row['show_online'])) { |
|
433 | + $context['view_num_hidden']++; |
|
434 | + } |
|
425 | 435 | } |
426 | 436 | |
427 | 437 | // The number of guests is equal to the rows minus the ones we actually used ;). |
@@ -435,11 +445,13 @@ discard block |
||
435 | 445 | |
436 | 446 | // If all is set, but not allowed... just unset it. |
437 | 447 | $can_show_all = !empty($modSettings['enableAllMessages']) && $context['total_visible_posts'] > $context['messages_per_page'] && $context['total_visible_posts'] < $modSettings['enableAllMessages']; |
438 | - if (isset($_REQUEST['all']) && !$can_show_all) |
|
439 | - unset($_REQUEST['all']); |
|
448 | + if (isset($_REQUEST['all']) && !$can_show_all) { |
|
449 | + unset($_REQUEST['all']); |
|
450 | + } |
|
440 | 451 | // Otherwise, it must be allowed... so pretend start was -1. |
441 | - elseif (isset($_REQUEST['all'])) |
|
442 | - $_REQUEST['start'] = -1; |
|
452 | + elseif (isset($_REQUEST['all'])) { |
|
453 | + $_REQUEST['start'] = -1; |
|
454 | + } |
|
443 | 455 | |
444 | 456 | // Construct the page index, allowing for the .START method... |
445 | 457 | $context['page_index'] = constructPageIndex($scripturl . '?topic=' . $topic . '.%1$d', $_REQUEST['start'], $context['total_visible_posts'], $context['messages_per_page'], true); |
@@ -476,8 +488,9 @@ discard block |
||
476 | 488 | $_REQUEST['start'] = 0; |
477 | 489 | } |
478 | 490 | // They aren't using it, but the *option* is there, at least. |
479 | - else |
|
480 | - $context['page_index'] .= ' <a href="' . $scripturl . '?topic=' . $topic . '.0;all">' . $txt['all'] . '</a> '; |
|
491 | + else { |
|
492 | + $context['page_index'] .= ' <a href="' . $scripturl . '?topic=' . $topic . '.0;all">' . $txt['all'] . '</a> '; |
|
493 | + } |
|
481 | 494 | } |
482 | 495 | |
483 | 496 | // Build the link tree. |
@@ -493,14 +506,16 @@ discard block |
||
493 | 506 | if (!empty($board_info['moderators'])) |
494 | 507 | { |
495 | 508 | // Add a link for each moderator... |
496 | - foreach ($board_info['moderators'] as $mod) |
|
497 | - $context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>'; |
|
509 | + foreach ($board_info['moderators'] as $mod) { |
|
510 | + $context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>'; |
|
511 | + } |
|
498 | 512 | } |
499 | 513 | if (!empty($board_info['moderator_groups'])) |
500 | 514 | { |
501 | 515 | // Add a link for each moderator group as well... |
502 | - foreach ($board_info['moderator_groups'] as $mod_group) |
|
503 | - $context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=viewmemberes;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>'; |
|
516 | + foreach ($board_info['moderator_groups'] as $mod_group) { |
|
517 | + $context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=viewmemberes;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>'; |
|
518 | + } |
|
504 | 519 | } |
505 | 520 | |
506 | 521 | if (!empty($context['link_moderators'])) |
@@ -531,9 +546,9 @@ discard block |
||
531 | 546 | // For quick reply we need a response prefix in the default forum language. |
532 | 547 | if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix', 600))) |
533 | 548 | { |
534 | - if ($language === $user_info['language']) |
|
535 | - $context['response_prefix'] = $txt['response_prefix']; |
|
536 | - else |
|
549 | + if ($language === $user_info['language']) { |
|
550 | + $context['response_prefix'] = $txt['response_prefix']; |
|
551 | + } else |
|
537 | 552 | { |
538 | 553 | loadLanguage('index', $language, false); |
539 | 554 | $context['response_prefix'] = $txt['response_prefix']; |
@@ -565,8 +580,9 @@ discard block |
||
565 | 580 | list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row); |
566 | 581 | |
567 | 582 | // Sanity check |
568 | - if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) |
|
569 | - continue; |
|
583 | + if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) { |
|
584 | + continue; |
|
585 | + } |
|
570 | 586 | |
571 | 587 | $linked_calendar_event = array( |
572 | 588 | 'id' => $row['id_event'], |
@@ -615,8 +631,9 @@ discard block |
||
615 | 631 | } |
616 | 632 | $smcFunc['db_free_result']($request); |
617 | 633 | |
618 | - if (!empty($context['linked_calendar_events'])) |
|
619 | - $context['linked_calendar_events'][count($context['linked_calendar_events']) - 1]['is_last'] = true; |
|
634 | + if (!empty($context['linked_calendar_events'])) { |
|
635 | + $context['linked_calendar_events'][count($context['linked_calendar_events']) - 1]['is_last'] = true; |
|
636 | + } |
|
620 | 637 | } |
621 | 638 | |
622 | 639 | // Create the poll info if it exists. |
@@ -689,20 +706,21 @@ discard block |
||
689 | 706 | foreach ($guestinfo as $i => $guestvoted) |
690 | 707 | { |
691 | 708 | $guestvoted = explode(',', $guestvoted); |
692 | - if ($guestvoted[0] == $context['topicinfo']['id_poll']) |
|
693 | - break; |
|
709 | + if ($guestvoted[0] == $context['topicinfo']['id_poll']) { |
|
710 | + break; |
|
711 | + } |
|
694 | 712 | } |
695 | 713 | // Has the poll been reset since guest voted? |
696 | 714 | if ($pollinfo['reset_poll'] > $guestvoted[1]) |
697 | 715 | { |
698 | 716 | // Remove the poll info from the cookie to allow guest to vote again |
699 | 717 | unset($guestinfo[$i]); |
700 | - if (!empty($guestinfo)) |
|
701 | - $_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo); |
|
702 | - else |
|
703 | - unset($_COOKIE['guest_poll_vote']); |
|
704 | - } |
|
705 | - else |
|
718 | + if (!empty($guestinfo)) { |
|
719 | + $_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo); |
|
720 | + } else { |
|
721 | + unset($_COOKIE['guest_poll_vote']); |
|
722 | + } |
|
723 | + } else |
|
706 | 724 | { |
707 | 725 | // What did they vote for? |
708 | 726 | unset($guestvoted[0], $guestvoted[1]); |
@@ -816,23 +834,29 @@ discard block |
||
816 | 834 | // Build the poll moderation button array. |
817 | 835 | $context['poll_buttons'] = array(); |
818 | 836 | |
819 | - if ($context['allow_return_vote']) |
|
820 | - $context['poll_buttons']['vote'] = array('text' => 'poll_return_vote', 'image' => 'poll_options.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start']); |
|
837 | + if ($context['allow_return_vote']) { |
|
838 | + $context['poll_buttons']['vote'] = array('text' => 'poll_return_vote', 'image' => 'poll_options.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start']); |
|
839 | + } |
|
821 | 840 | |
822 | - if ($context['show_view_results_button']) |
|
823 | - $context['poll_buttons']['results'] = array('text' => 'poll_results', 'image' => 'poll_results.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start'] . ';viewresults'); |
|
841 | + if ($context['show_view_results_button']) { |
|
842 | + $context['poll_buttons']['results'] = array('text' => 'poll_results', 'image' => 'poll_results.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start'] . ';viewresults'); |
|
843 | + } |
|
824 | 844 | |
825 | - if ($context['allow_change_vote']) |
|
826 | - $context['poll_buttons']['change_vote'] = array('text' => 'poll_change_vote', 'image' => 'poll_change_vote.png', 'url' => $scripturl . '?action=vote;topic=' . $context['current_topic'] . '.' . $context['start'] . ';poll=' . $context['poll']['id'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
845 | + if ($context['allow_change_vote']) { |
|
846 | + $context['poll_buttons']['change_vote'] = array('text' => 'poll_change_vote', 'image' => 'poll_change_vote.png', 'url' => $scripturl . '?action=vote;topic=' . $context['current_topic'] . '.' . $context['start'] . ';poll=' . $context['poll']['id'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
847 | + } |
|
827 | 848 | |
828 | - if ($context['allow_lock_poll']) |
|
829 | - $context['poll_buttons']['lock'] = array('text' => (!$context['poll']['is_locked'] ? 'poll_lock' : 'poll_unlock'), 'image' => 'poll_lock.png', 'url' => $scripturl . '?action=lockvoting;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
849 | + if ($context['allow_lock_poll']) { |
|
850 | + $context['poll_buttons']['lock'] = array('text' => (!$context['poll']['is_locked'] ? 'poll_lock' : 'poll_unlock'), 'image' => 'poll_lock.png', 'url' => $scripturl . '?action=lockvoting;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
851 | + } |
|
830 | 852 | |
831 | - if ($context['allow_edit_poll']) |
|
832 | - $context['poll_buttons']['edit'] = array('text' => 'poll_edit', 'image' => 'poll_edit.png', 'url' => $scripturl . '?action=editpoll;topic=' . $context['current_topic'] . '.' . $context['start']); |
|
853 | + if ($context['allow_edit_poll']) { |
|
854 | + $context['poll_buttons']['edit'] = array('text' => 'poll_edit', 'image' => 'poll_edit.png', 'url' => $scripturl . '?action=editpoll;topic=' . $context['current_topic'] . '.' . $context['start']); |
|
855 | + } |
|
833 | 856 | |
834 | - if ($context['can_remove_poll']) |
|
835 | - $context['poll_buttons']['remove_poll'] = array('text' => 'poll_remove', 'image' => 'admin_remove_poll.png', 'custom' => 'data-confirm="' . $txt['poll_remove_warn'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removepoll;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
857 | + if ($context['can_remove_poll']) { |
|
858 | + $context['poll_buttons']['remove_poll'] = array('text' => 'poll_remove', 'image' => 'admin_remove_poll.png', 'custom' => 'data-confirm="' . $txt['poll_remove_warn'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removepoll;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
859 | + } |
|
836 | 860 | |
837 | 861 | // Allow mods to add additional buttons here |
838 | 862 | call_integration_hook('integrate_poll_buttons'); |
@@ -873,8 +897,9 @@ discard block |
||
873 | 897 | $all_posters = array(); |
874 | 898 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
875 | 899 | { |
876 | - if (!empty($row['id_member'])) |
|
877 | - $all_posters[$row['id_msg']] = $row['id_member']; |
|
900 | + if (!empty($row['id_member'])) { |
|
901 | + $all_posters[$row['id_msg']] = $row['id_member']; |
|
902 | + } |
|
878 | 903 | $messages[] = $row['id_msg']; |
879 | 904 | } |
880 | 905 | $smcFunc['db_free_result']($request); |
@@ -886,8 +911,9 @@ discard block |
||
886 | 911 | if (!$user_info['is_guest'] && !empty($messages)) |
887 | 912 | { |
888 | 913 | $mark_at_msg = max($messages); |
889 | - if ($mark_at_msg >= $context['topicinfo']['id_last_msg']) |
|
890 | - $mark_at_msg = $modSettings['maxMsgID']; |
|
914 | + if ($mark_at_msg >= $context['topicinfo']['id_last_msg']) { |
|
915 | + $mark_at_msg = $modSettings['maxMsgID']; |
|
916 | + } |
|
891 | 917 | if ($mark_at_msg >= $context['topicinfo']['new_from']) |
892 | 918 | { |
893 | 919 | $smcFunc['db_insert']($context['topicinfo']['new_from'] == 0 ? 'ignore' : 'replace', |
@@ -919,8 +945,9 @@ discard block |
||
919 | 945 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
920 | 946 | { |
921 | 947 | // Find if this topic is marked for notification... |
922 | - if (!empty($row['id_topic'])) |
|
923 | - $context['is_marked_notify'] = true; |
|
948 | + if (!empty($row['id_topic'])) { |
|
949 | + $context['is_marked_notify'] = true; |
|
950 | + } |
|
924 | 951 | |
925 | 952 | // Only do this once, but mark the notifications as "not sent yet" for next time. |
926 | 953 | if (!empty($row['sent']) && $do_once) |
@@ -942,8 +969,9 @@ discard block |
||
942 | 969 | } |
943 | 970 | |
944 | 971 | // Have we recently cached the number of new topics in this board, and it's still a lot? |
945 | - if (isset($_REQUEST['topicseen']) && isset($_SESSION['topicseen_cache'][$board]) && $_SESSION['topicseen_cache'][$board] > 5) |
|
946 | - $_SESSION['topicseen_cache'][$board]--; |
|
972 | + if (isset($_REQUEST['topicseen']) && isset($_SESSION['topicseen_cache'][$board]) && $_SESSION['topicseen_cache'][$board] > 5) { |
|
973 | + $_SESSION['topicseen_cache'][$board]--; |
|
974 | + } |
|
947 | 975 | // Mark board as seen if this is the only new topic. |
948 | 976 | elseif (isset($_REQUEST['topicseen'])) |
949 | 977 | { |
@@ -967,14 +995,16 @@ discard block |
||
967 | 995 | $smcFunc['db_free_result']($request); |
968 | 996 | |
969 | 997 | // If there're no real new topics in this board, mark the board as seen. |
970 | - if (empty($numNewTopics)) |
|
971 | - $_REQUEST['boardseen'] = true; |
|
972 | - else |
|
973 | - $_SESSION['topicseen_cache'][$board] = $numNewTopics; |
|
998 | + if (empty($numNewTopics)) { |
|
999 | + $_REQUEST['boardseen'] = true; |
|
1000 | + } else { |
|
1001 | + $_SESSION['topicseen_cache'][$board] = $numNewTopics; |
|
1002 | + } |
|
974 | 1003 | } |
975 | 1004 | // Probably one less topic - maybe not, but even if we decrease this too fast it will only make us look more often. |
976 | - elseif (isset($_SESSION['topicseen_cache'][$board])) |
|
977 | - $_SESSION['topicseen_cache'][$board]--; |
|
1005 | + elseif (isset($_SESSION['topicseen_cache'][$board])) { |
|
1006 | + $_SESSION['topicseen_cache'][$board]--; |
|
1007 | + } |
|
978 | 1008 | |
979 | 1009 | // Mark board as seen if we came using last post link from BoardIndex. (or other places...) |
980 | 1010 | if (isset($_REQUEST['boardseen'])) |
@@ -1031,23 +1061,26 @@ discard block |
||
1031 | 1061 | $temp = array(); |
1032 | 1062 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1033 | 1063 | { |
1034 | - if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) |
|
1035 | - continue; |
|
1064 | + if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) { |
|
1065 | + continue; |
|
1066 | + } |
|
1036 | 1067 | |
1037 | 1068 | $temp[$row['id_attach']] = $row; |
1038 | 1069 | $temp[$row['id_attach']]['topic'] = $topic; |
1039 | 1070 | $temp[$row['id_attach']]['board'] = $board; |
1040 | 1071 | |
1041 | - if (!isset($context['loaded_attachments'][$row['id_msg']])) |
|
1042 | - $context['loaded_attachments'][$row['id_msg']] = array(); |
|
1072 | + if (!isset($context['loaded_attachments'][$row['id_msg']])) { |
|
1073 | + $context['loaded_attachments'][$row['id_msg']] = array(); |
|
1074 | + } |
|
1043 | 1075 | } |
1044 | 1076 | $smcFunc['db_free_result']($request); |
1045 | 1077 | |
1046 | 1078 | // This is better than sorting it with the query... |
1047 | 1079 | ksort($temp); |
1048 | 1080 | |
1049 | - foreach ($temp as $row) |
|
1050 | - $context['loaded_attachments'][$row['id_msg']][] = $row; |
|
1081 | + foreach ($temp as $row) { |
|
1082 | + $context['loaded_attachments'][$row['id_msg']][] = $row; |
|
1083 | + } |
|
1051 | 1084 | } |
1052 | 1085 | |
1053 | 1086 | $msg_parameters = array( |
@@ -1074,21 +1107,23 @@ discard block |
||
1074 | 1107 | ); |
1075 | 1108 | |
1076 | 1109 | // And the likes |
1077 | - if (!empty($modSettings['enable_likes'])) |
|
1078 | - $context['my_likes'] = $context['user']['is_guest'] ? array() : prepareLikesContext($topic); |
|
1110 | + if (!empty($modSettings['enable_likes'])) { |
|
1111 | + $context['my_likes'] = $context['user']['is_guest'] ? array() : prepareLikesContext($topic); |
|
1112 | + } |
|
1079 | 1113 | |
1080 | 1114 | // Go to the last message if the given time is beyond the time of the last message. |
1081 | - if (isset($context['start_from']) && $context['start_from'] >= $context['topicinfo']['num_replies']) |
|
1082 | - $context['start_from'] = $context['topicinfo']['num_replies']; |
|
1115 | + if (isset($context['start_from']) && $context['start_from'] >= $context['topicinfo']['num_replies']) { |
|
1116 | + $context['start_from'] = $context['topicinfo']['num_replies']; |
|
1117 | + } |
|
1083 | 1118 | |
1084 | 1119 | // Since the anchor information is needed on the top of the page we load these variables beforehand. |
1085 | 1120 | $context['first_message'] = isset($messages[$firstIndex]) ? $messages[$firstIndex] : $messages[0]; |
1086 | - if (empty($options['view_newest_first'])) |
|
1087 | - $context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['start_from']; |
|
1088 | - else |
|
1089 | - $context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['topicinfo']['num_replies'] - $context['start_from']; |
|
1090 | - } |
|
1091 | - else |
|
1121 | + if (empty($options['view_newest_first'])) { |
|
1122 | + $context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['start_from']; |
|
1123 | + } else { |
|
1124 | + $context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['topicinfo']['num_replies'] - $context['start_from']; |
|
1125 | + } |
|
1126 | + } else |
|
1092 | 1127 | { |
1093 | 1128 | $messages_request = false; |
1094 | 1129 | $context['first_message'] = 0; |
@@ -1124,8 +1159,9 @@ discard block |
||
1124 | 1159 | 'can_see_likes' => 'likes_view', |
1125 | 1160 | 'can_like' => 'likes_like', |
1126 | 1161 | ); |
1127 | - foreach ($common_permissions as $contextual => $perm) |
|
1128 | - $context[$contextual] = allowedTo($perm); |
|
1162 | + foreach ($common_permissions as $contextual => $perm) { |
|
1163 | + $context[$contextual] = allowedTo($perm); |
|
1164 | + } |
|
1129 | 1165 | |
1130 | 1166 | // Permissions with _any/_own versions. $context[YYY] => ZZZ_any/_own. |
1131 | 1167 | $anyown_permissions = array( |
@@ -1138,8 +1174,9 @@ discard block |
||
1138 | 1174 | 'can_reply_unapproved' => 'post_unapproved_replies', |
1139 | 1175 | 'can_view_warning' => 'profile_warning', |
1140 | 1176 | ); |
1141 | - foreach ($anyown_permissions as $contextual => $perm) |
|
1142 | - $context[$contextual] = allowedTo($perm . '_any') || ($context['user']['started'] && allowedTo($perm . '_own')); |
|
1177 | + foreach ($anyown_permissions as $contextual => $perm) { |
|
1178 | + $context[$contextual] = allowedTo($perm . '_any') || ($context['user']['started'] && allowedTo($perm . '_own')); |
|
1179 | + } |
|
1143 | 1180 | |
1144 | 1181 | if (!$user_info['is_admin'] && !$modSettings['topic_move_any']) |
1145 | 1182 | { |
@@ -1185,8 +1222,9 @@ discard block |
||
1185 | 1222 | // Check if the draft functions are enabled and that they have permission to use them (for quick reply.) |
1186 | 1223 | $context['drafts_save'] = !empty($modSettings['drafts_post_enabled']) && allowedTo('post_draft') && $context['can_reply']; |
1187 | 1224 | $context['drafts_autosave'] = !empty($context['drafts_save']) && !empty($modSettings['drafts_autosave_enabled']); |
1188 | - if (!empty($context['drafts_save'])) |
|
1189 | - loadLanguage('Drafts'); |
|
1225 | + if (!empty($context['drafts_save'])) { |
|
1226 | + loadLanguage('Drafts'); |
|
1227 | + } |
|
1190 | 1228 | |
1191 | 1229 | // When was the last time this topic was replied to? Should we warn them about it? |
1192 | 1230 | if (!empty($modSettings['oldTopicDays']) && ($context['can_reply'] || $context['can_reply_unapproved']) && empty($context['topicinfo']['is_sticky'])) |
@@ -1247,26 +1285,31 @@ discard block |
||
1247 | 1285 | // Message icons - customized icons are off? |
1248 | 1286 | $context['icons'] = getMessageIcons($board); |
1249 | 1287 | |
1250 | - if (!empty($context['icons'])) |
|
1251 | - $context['icons'][count($context['icons']) - 1]['is_last'] = true; |
|
1288 | + if (!empty($context['icons'])) { |
|
1289 | + $context['icons'][count($context['icons']) - 1]['is_last'] = true; |
|
1290 | + } |
|
1252 | 1291 | |
1253 | 1292 | // Build the normal button array. |
1254 | 1293 | $context['normal_buttons'] = array(); |
1255 | 1294 | |
1256 | - if ($context['can_reply']) |
|
1257 | - $context['normal_buttons']['reply'] = array('text' => 'reply', 'image' => 'reply.png', 'url' => $scripturl . '?action=post;topic=' . $context['current_topic'] . '.' . $context['start'] . ';last_msg=' . $context['topic_last_message'], 'active' => true); |
|
1295 | + if ($context['can_reply']) { |
|
1296 | + $context['normal_buttons']['reply'] = array('text' => 'reply', 'image' => 'reply.png', 'url' => $scripturl . '?action=post;topic=' . $context['current_topic'] . '.' . $context['start'] . ';last_msg=' . $context['topic_last_message'], 'active' => true); |
|
1297 | + } |
|
1258 | 1298 | |
1259 | - if ($context['can_add_poll']) |
|
1260 | - $context['normal_buttons']['add_poll'] = array('text' => 'add_poll', 'image' => 'add_poll.png', 'url' => $scripturl . '?action=editpoll;add;topic=' . $context['current_topic'] . '.' . $context['start']); |
|
1299 | + if ($context['can_add_poll']) { |
|
1300 | + $context['normal_buttons']['add_poll'] = array('text' => 'add_poll', 'image' => 'add_poll.png', 'url' => $scripturl . '?action=editpoll;add;topic=' . $context['current_topic'] . '.' . $context['start']); |
|
1301 | + } |
|
1261 | 1302 | |
1262 | - if ($context['can_mark_unread']) |
|
1263 | - $context['normal_buttons']['mark_unread'] = array('text' => 'mark_unread', 'image' => 'markunread.png', 'url' => $scripturl . '?action=markasread;sa=topic;t=' . $context['mark_unread_time'] . ';topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
1303 | + if ($context['can_mark_unread']) { |
|
1304 | + $context['normal_buttons']['mark_unread'] = array('text' => 'mark_unread', 'image' => 'markunread.png', 'url' => $scripturl . '?action=markasread;sa=topic;t=' . $context['mark_unread_time'] . ';topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
1305 | + } |
|
1264 | 1306 | |
1265 | - if ($context['can_print']) |
|
1266 | - $context['normal_buttons']['print'] = array('text' => 'print', 'image' => 'print.png', 'custom' => 'rel="nofollow"', 'url' => $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0'); |
|
1307 | + if ($context['can_print']) { |
|
1308 | + $context['normal_buttons']['print'] = array('text' => 'print', 'image' => 'print.png', 'custom' => 'rel="nofollow"', 'url' => $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0'); |
|
1309 | + } |
|
1267 | 1310 | |
1268 | - if ($context['can_set_notify']) |
|
1269 | - $context['normal_buttons']['notify'] = array( |
|
1311 | + if ($context['can_set_notify']) { |
|
1312 | + $context['normal_buttons']['notify'] = array( |
|
1270 | 1313 | 'text' => 'notify_topic_' . $context['topic_notification_mode'], |
1271 | 1314 | 'sub_buttons' => array( |
1272 | 1315 | array( |
@@ -1288,38 +1331,47 @@ discard block |
||
1288 | 1331 | ), |
1289 | 1332 | ), |
1290 | 1333 | ); |
1334 | + } |
|
1291 | 1335 | |
1292 | 1336 | // Build the mod button array |
1293 | 1337 | $context['mod_buttons'] = array(); |
1294 | 1338 | |
1295 | - if ($context['can_move']) |
|
1296 | - $context['mod_buttons']['move'] = array('text' => 'move_topic', 'image' => 'admin_move.png', 'url' => $scripturl . '?action=movetopic;current_board=' . $context['current_board'] . ';topic=' . $context['current_topic'] . '.0'); |
|
1339 | + if ($context['can_move']) { |
|
1340 | + $context['mod_buttons']['move'] = array('text' => 'move_topic', 'image' => 'admin_move.png', 'url' => $scripturl . '?action=movetopic;current_board=' . $context['current_board'] . ';topic=' . $context['current_topic'] . '.0'); |
|
1341 | + } |
|
1297 | 1342 | |
1298 | - if ($context['can_delete']) |
|
1299 | - $context['mod_buttons']['delete'] = array('text' => 'remove_topic', 'image' => 'admin_rem.png', 'custom' => 'data-confirm="' . $txt['are_sure_remove_topic'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removetopic2;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id']); |
|
1343 | + if ($context['can_delete']) { |
|
1344 | + $context['mod_buttons']['delete'] = array('text' => 'remove_topic', 'image' => 'admin_rem.png', 'custom' => 'data-confirm="' . $txt['are_sure_remove_topic'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removetopic2;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id']); |
|
1345 | + } |
|
1300 | 1346 | |
1301 | - if ($context['can_lock']) |
|
1302 | - $context['mod_buttons']['lock'] = array('text' => empty($context['is_locked']) ? 'set_lock' : 'set_unlock', 'image' => 'admin_lock.png', 'url' => $scripturl . '?action=lock;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
1347 | + if ($context['can_lock']) { |
|
1348 | + $context['mod_buttons']['lock'] = array('text' => empty($context['is_locked']) ? 'set_lock' : 'set_unlock', 'image' => 'admin_lock.png', 'url' => $scripturl . '?action=lock;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
1349 | + } |
|
1303 | 1350 | |
1304 | - if ($context['can_sticky']) |
|
1305 | - $context['mod_buttons']['sticky'] = array('text' => empty($context['is_sticky']) ? 'set_sticky' : 'set_nonsticky', 'image' => 'admin_sticky.png', 'url' => $scripturl . '?action=sticky;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
1351 | + if ($context['can_sticky']) { |
|
1352 | + $context['mod_buttons']['sticky'] = array('text' => empty($context['is_sticky']) ? 'set_sticky' : 'set_nonsticky', 'image' => 'admin_sticky.png', 'url' => $scripturl . '?action=sticky;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
1353 | + } |
|
1306 | 1354 | |
1307 | - if ($context['can_merge']) |
|
1308 | - $context['mod_buttons']['merge'] = array('text' => 'merge', 'image' => 'merge.png', 'url' => $scripturl . '?action=mergetopics;board=' . $context['current_board'] . '.0;from=' . $context['current_topic']); |
|
1355 | + if ($context['can_merge']) { |
|
1356 | + $context['mod_buttons']['merge'] = array('text' => 'merge', 'image' => 'merge.png', 'url' => $scripturl . '?action=mergetopics;board=' . $context['current_board'] . '.0;from=' . $context['current_topic']); |
|
1357 | + } |
|
1309 | 1358 | |
1310 | - if ($context['calendar_post']) |
|
1311 | - $context['mod_buttons']['calendar'] = array('text' => 'calendar_link', 'image' => 'linktocal.png', 'url' => $scripturl . '?action=post;calendar;msg=' . $context['topic_first_message'] . ';topic=' . $context['current_topic'] . '.0'); |
|
1359 | + if ($context['calendar_post']) { |
|
1360 | + $context['mod_buttons']['calendar'] = array('text' => 'calendar_link', 'image' => 'linktocal.png', 'url' => $scripturl . '?action=post;calendar;msg=' . $context['topic_first_message'] . ';topic=' . $context['current_topic'] . '.0'); |
|
1361 | + } |
|
1312 | 1362 | |
1313 | 1363 | // Restore topic. eh? No monkey business. |
1314 | - if ($context['can_restore_topic']) |
|
1315 | - $context['mod_buttons']['restore_topic'] = array('text' => 'restore_topic', 'image' => '', 'url' => $scripturl . '?action=restoretopic;topics=' . $context['current_topic'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
1364 | + if ($context['can_restore_topic']) { |
|
1365 | + $context['mod_buttons']['restore_topic'] = array('text' => 'restore_topic', 'image' => '', 'url' => $scripturl . '?action=restoretopic;topics=' . $context['current_topic'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
1366 | + } |
|
1316 | 1367 | |
1317 | 1368 | // Show a message in case a recently posted message became unapproved. |
1318 | 1369 | $context['becomesUnapproved'] = !empty($_SESSION['becomesUnapproved']) ? true : false; |
1319 | 1370 | |
1320 | 1371 | // Don't want to show this forever... |
1321 | - if ($context['becomesUnapproved']) |
|
1322 | - unset($_SESSION['becomesUnapproved']); |
|
1372 | + if ($context['becomesUnapproved']) { |
|
1373 | + unset($_SESSION['becomesUnapproved']); |
|
1374 | + } |
|
1323 | 1375 | |
1324 | 1376 | // Allow adding new mod buttons easily. |
1325 | 1377 | // Note: $context['normal_buttons'] and $context['mod_buttons'] are added for backward compatibility with 2.0, but are deprecated and should not be used |
@@ -1328,12 +1380,14 @@ discard block |
||
1328 | 1380 | call_integration_hook('integrate_mod_buttons', array(&$context['mod_buttons'])); |
1329 | 1381 | |
1330 | 1382 | // Load the drafts js file |
1331 | - if ($context['drafts_autosave']) |
|
1332 | - loadJavaScriptFile('drafts.js', array('defer' => false), 'smf_drafts'); |
|
1383 | + if ($context['drafts_autosave']) { |
|
1384 | + loadJavaScriptFile('drafts.js', array('defer' => false), 'smf_drafts'); |
|
1385 | + } |
|
1333 | 1386 | |
1334 | 1387 | // Spellcheck |
1335 | - if ($context['show_spellchecking']) |
|
1336 | - loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck'); |
|
1388 | + if ($context['show_spellchecking']) { |
|
1389 | + loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck'); |
|
1390 | + } |
|
1337 | 1391 | |
1338 | 1392 | // topic.js |
1339 | 1393 | loadJavaScriptFile('topic.js', array('defer' => false), 'smf_topic'); |
@@ -1367,16 +1421,19 @@ discard block |
||
1367 | 1421 | static $counter = null; |
1368 | 1422 | |
1369 | 1423 | // If the query returned false, bail. |
1370 | - if ($messages_request == false) |
|
1371 | - return false; |
|
1424 | + if ($messages_request == false) { |
|
1425 | + return false; |
|
1426 | + } |
|
1372 | 1427 | |
1373 | 1428 | // Remember which message this is. (ie. reply #83) |
1374 | - if ($counter === null || $reset) |
|
1375 | - $counter = empty($options['view_newest_first']) ? $context['start'] : $context['total_visible_posts'] - $context['start']; |
|
1429 | + if ($counter === null || $reset) { |
|
1430 | + $counter = empty($options['view_newest_first']) ? $context['start'] : $context['total_visible_posts'] - $context['start']; |
|
1431 | + } |
|
1376 | 1432 | |
1377 | 1433 | // Start from the beginning... |
1378 | - if ($reset) |
|
1379 | - return @$smcFunc['db_data_seek']($messages_request, 0); |
|
1434 | + if ($reset) { |
|
1435 | + return @$smcFunc['db_data_seek']($messages_request, 0); |
|
1436 | + } |
|
1380 | 1437 | |
1381 | 1438 | // Attempt to get the next message. |
1382 | 1439 | $message = $smcFunc['db_fetch_assoc']($messages_request); |
@@ -1390,19 +1447,21 @@ discard block |
||
1390 | 1447 | if (empty($context['icon_sources'])) |
1391 | 1448 | { |
1392 | 1449 | $context['icon_sources'] = array(); |
1393 | - foreach ($context['stable_icons'] as $icon) |
|
1394 | - $context['icon_sources'][$icon] = 'images_url'; |
|
1450 | + foreach ($context['stable_icons'] as $icon) { |
|
1451 | + $context['icon_sources'][$icon] = 'images_url'; |
|
1452 | + } |
|
1395 | 1453 | } |
1396 | 1454 | |
1397 | 1455 | // Message Icon Management... check the images exist. |
1398 | 1456 | if (empty($modSettings['messageIconChecks_disable'])) |
1399 | 1457 | { |
1400 | 1458 | // If the current icon isn't known, then we need to do something... |
1401 | - if (!isset($context['icon_sources'][$message['icon']])) |
|
1402 | - $context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
1459 | + if (!isset($context['icon_sources'][$message['icon']])) { |
|
1460 | + $context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
1461 | + } |
|
1462 | + } elseif (!isset($context['icon_sources'][$message['icon']])) { |
|
1463 | + $context['icon_sources'][$message['icon']] = 'images_url'; |
|
1403 | 1464 | } |
1404 | - elseif (!isset($context['icon_sources'][$message['icon']])) |
|
1405 | - $context['icon_sources'][$message['icon']] = 'images_url'; |
|
1406 | 1465 | |
1407 | 1466 | // If you're a lazy bum, you probably didn't give a subject... |
1408 | 1467 | $message['subject'] = $message['subject'] != '' ? $message['subject'] : $txt['no_subject']; |
@@ -1427,8 +1486,7 @@ discard block |
||
1427 | 1486 | $memberContext[$message['id_member']]['email'] = $message['poster_email']; |
1428 | 1487 | $memberContext[$message['id_member']]['show_email'] = allowedTo('moderate_forum'); |
1429 | 1488 | $memberContext[$message['id_member']]['is_guest'] = true; |
1430 | - } |
|
1431 | - else |
|
1489 | + } else |
|
1432 | 1490 | { |
1433 | 1491 | // Define this here to make things a bit more readable |
1434 | 1492 | $can_view_warning = $context['user']['can_mod'] || allowedTo('view_warning_any') || ($message['id_member'] == $user_info['id'] && allowedTo('view_warning_own')); |
@@ -1451,8 +1509,9 @@ discard block |
||
1451 | 1509 | $message['body'] = parse_bbc($message['body'], $message['smileys_enabled'], $message['id_msg']); |
1452 | 1510 | |
1453 | 1511 | // If it's in the recycle bin we need to override whatever icon we did have. |
1454 | - if (!empty($board_info['recycle'])) |
|
1455 | - $message['icon'] = 'recycled'; |
|
1512 | + if (!empty($board_info['recycle'])) { |
|
1513 | + $message['icon'] = 'recycled'; |
|
1514 | + } |
|
1456 | 1515 | |
1457 | 1516 | require_once($sourcedir . '/Subs-Attachments.php'); |
1458 | 1517 | |
@@ -1496,32 +1555,36 @@ discard block |
||
1496 | 1555 | } |
1497 | 1556 | |
1498 | 1557 | // Are likes enable? |
1499 | - if (!empty($modSettings['enable_likes'])) |
|
1500 | - $output['likes'] = array( |
|
1558 | + if (!empty($modSettings['enable_likes'])) { |
|
1559 | + $output['likes'] = array( |
|
1501 | 1560 | 'count' => $message['likes'], |
1502 | 1561 | 'you' => in_array($message['id_msg'], $context['my_likes']), |
1503 | 1562 | 'can_like' => !$context['user']['is_guest'] && $message['id_member'] != $context['user']['id'] && !empty($context['can_like']), |
1504 | 1563 | ); |
1564 | + } |
|
1505 | 1565 | |
1506 | 1566 | // Is this user the message author? |
1507 | 1567 | $output['is_message_author'] = $message['id_member'] == $user_info['id']; |
1508 | - if (!empty($output['modified']['name'])) |
|
1509 | - $output['modified']['last_edit_text'] = sprintf($txt['last_edit_by'], $output['modified']['time'], $output['modified']['name']); |
|
1568 | + if (!empty($output['modified']['name'])) { |
|
1569 | + $output['modified']['last_edit_text'] = sprintf($txt['last_edit_by'], $output['modified']['time'], $output['modified']['name']); |
|
1570 | + } |
|
1510 | 1571 | |
1511 | 1572 | // Did they give a reason for editing? |
1512 | - if (!empty($output['modified']['name']) && !empty($output['modified']['reason'])) |
|
1513 | - $output['modified']['last_edit_text'] .= ' ' . sprintf($txt['last_edit_reason'], $output['modified']['reason']); |
|
1573 | + if (!empty($output['modified']['name']) && !empty($output['modified']['reason'])) { |
|
1574 | + $output['modified']['last_edit_text'] .= ' ' . sprintf($txt['last_edit_reason'], $output['modified']['reason']); |
|
1575 | + } |
|
1514 | 1576 | |
1515 | 1577 | // Any custom profile fields? |
1516 | - if (!empty($memberContext[$message['id_member']]['custom_fields'])) |
|
1517 | - foreach ($memberContext[$message['id_member']]['custom_fields'] as $custom) |
|
1578 | + if (!empty($memberContext[$message['id_member']]['custom_fields'])) { |
|
1579 | + foreach ($memberContext[$message['id_member']]['custom_fields'] as $custom) |
|
1518 | 1580 | $output['custom_fields'][$context['cust_profile_fields_placement'][$custom['placement']]][] = $custom; |
1581 | + } |
|
1519 | 1582 | |
1520 | - if (empty($options['view_newest_first'])) |
|
1521 | - $counter++; |
|
1522 | - |
|
1523 | - else |
|
1524 | - $counter--; |
|
1583 | + if (empty($options['view_newest_first'])) { |
|
1584 | + $counter++; |
|
1585 | + } else { |
|
1586 | + $counter--; |
|
1587 | + } |
|
1525 | 1588 | |
1526 | 1589 | call_integration_hook('integrate_prepare_display_context', array(&$output, &$message, $counter)); |
1527 | 1590 | |
@@ -1547,21 +1610,23 @@ discard block |
||
1547 | 1610 | $context['no_last_modified'] = true; |
1548 | 1611 | |
1549 | 1612 | // Prevent a preview image from being displayed twice. |
1550 | - if (isset($_GET['action']) && $_GET['action'] == 'dlattach' && isset($_GET['type']) && ($_GET['type'] == 'avatar' || $_GET['type'] == 'preview')) |
|
1551 | - return; |
|
1613 | + if (isset($_GET['action']) && $_GET['action'] == 'dlattach' && isset($_GET['type']) && ($_GET['type'] == 'avatar' || $_GET['type'] == 'preview')) { |
|
1614 | + return; |
|
1615 | + } |
|
1552 | 1616 | |
1553 | 1617 | // Make sure some attachment was requested! |
1554 | - if (!isset($_REQUEST['attach']) && !isset($_REQUEST['id'])) |
|
1555 | - fatal_lang_error('no_access', false); |
|
1618 | + if (!isset($_REQUEST['attach']) && !isset($_REQUEST['id'])) { |
|
1619 | + fatal_lang_error('no_access', false); |
|
1620 | + } |
|
1556 | 1621 | |
1557 | 1622 | $_REQUEST['attach'] = isset($_REQUEST['attach']) ? (int) $_REQUEST['attach'] : (int) $_REQUEST['id']; |
1558 | 1623 | |
1559 | 1624 | // Do we have a hook wanting to use our attachment system? We use $attachRequest to prevent accidental usage of $request. |
1560 | 1625 | $attachRequest = null; |
1561 | 1626 | call_integration_hook('integrate_download_request', array(&$attachRequest)); |
1562 | - if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest)) |
|
1563 | - $request = $attachRequest; |
|
1564 | - else |
|
1627 | + if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest)) { |
|
1628 | + $request = $attachRequest; |
|
1629 | + } else |
|
1565 | 1630 | { |
1566 | 1631 | // This checks only the current board for $board/$topic's permissions. |
1567 | 1632 | isAllowedTo('view_attachments'); |
@@ -1582,19 +1647,21 @@ discard block |
||
1582 | 1647 | ); |
1583 | 1648 | } |
1584 | 1649 | |
1585 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
1586 | - fatal_lang_error('no_access', false); |
|
1650 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
1651 | + fatal_lang_error('no_access', false); |
|
1652 | + } |
|
1587 | 1653 | |
1588 | 1654 | list ($id_folder, $real_filename, $file_hash, $file_ext, $id_attach, $attachment_type, $mime_type, $is_approved, $id_member) = $smcFunc['db_fetch_row']($request); |
1589 | 1655 | $smcFunc['db_free_result']($request); |
1590 | 1656 | |
1591 | 1657 | // If it isn't yet approved, do they have permission to view it? |
1592 | - if (!$is_approved && ($id_member == 0 || $user_info['id'] != $id_member) && ($attachment_type == 0 || $attachment_type == 3)) |
|
1593 | - isAllowedTo('approve_posts'); |
|
1658 | + if (!$is_approved && ($id_member == 0 || $user_info['id'] != $id_member) && ($attachment_type == 0 || $attachment_type == 3)) { |
|
1659 | + isAllowedTo('approve_posts'); |
|
1660 | + } |
|
1594 | 1661 | |
1595 | 1662 | // Update the download counter (unless it's a thumbnail). |
1596 | - if ($attachment_type != 3) |
|
1597 | - $smcFunc['db_query']('attach_download_increase', ' |
|
1663 | + if ($attachment_type != 3) { |
|
1664 | + $smcFunc['db_query']('attach_download_increase', ' |
|
1598 | 1665 | UPDATE LOW_PRIORITY {db_prefix}attachments |
1599 | 1666 | SET downloads = downloads + 1 |
1600 | 1667 | WHERE id_attach = {int:id_attach}', |
@@ -1602,15 +1669,15 @@ discard block |
||
1602 | 1669 | 'id_attach' => $id_attach, |
1603 | 1670 | ) |
1604 | 1671 | ); |
1672 | + } |
|
1605 | 1673 | |
1606 | 1674 | $filename = getAttachmentFilename($real_filename, $_REQUEST['attach'], $id_folder, false, $file_hash); |
1607 | 1675 | |
1608 | 1676 | // This is done to clear any output that was made before now. |
1609 | 1677 | ob_end_clean(); |
1610 | - if (!empty($modSettings['enableCompressedOutput']) && @filesize($filename) <= 4194304 && in_array($file_ext, array('txt', 'html', 'htm', 'js', 'doc', 'docx', 'rtf', 'css', 'php', 'log', 'xml', 'sql', 'c', 'java'))) |
|
1611 | - @ob_start('ob_gzhandler'); |
|
1612 | - |
|
1613 | - else |
|
1678 | + if (!empty($modSettings['enableCompressedOutput']) && @filesize($filename) <= 4194304 && in_array($file_ext, array('txt', 'html', 'htm', 'js', 'doc', 'docx', 'rtf', 'css', 'php', 'log', 'xml', 'sql', 'c', 'java'))) { |
|
1679 | + @ob_start('ob_gzhandler'); |
|
1680 | + } else |
|
1614 | 1681 | { |
1615 | 1682 | ob_start(); |
1616 | 1683 | header('Content-Encoding: none'); |
@@ -1653,8 +1720,9 @@ discard block |
||
1653 | 1720 | // Send the attachment headers. |
1654 | 1721 | header('Pragma: '); |
1655 | 1722 | |
1656 | - if (!isBrowser('gecko')) |
|
1657 | - header('Content-Transfer-Encoding: binary'); |
|
1723 | + if (!isBrowser('gecko')) { |
|
1724 | + header('Content-Transfer-Encoding: binary'); |
|
1725 | + } |
|
1658 | 1726 | |
1659 | 1727 | header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 525600 * 60) . ' GMT'); |
1660 | 1728 | header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($filename)) . ' GMT'); |
@@ -1663,18 +1731,19 @@ discard block |
||
1663 | 1731 | header('ETag: ' . $eTag); |
1664 | 1732 | |
1665 | 1733 | // Make sure the mime type warrants an inline display. |
1666 | - if (isset($_REQUEST['image']) && !empty($mime_type) && strpos($mime_type, 'image/') !== 0) |
|
1667 | - unset($_REQUEST['image']); |
|
1734 | + if (isset($_REQUEST['image']) && !empty($mime_type) && strpos($mime_type, 'image/') !== 0) { |
|
1735 | + unset($_REQUEST['image']); |
|
1736 | + } |
|
1668 | 1737 | |
1669 | 1738 | // Does this have a mime type? |
1670 | - elseif (!empty($mime_type) && (isset($_REQUEST['image']) || !in_array($file_ext, array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff')))) |
|
1671 | - header('Content-Type: ' . strtr($mime_type, array('image/bmp' => 'image/x-ms-bmp'))); |
|
1672 | - |
|
1673 | - else |
|
1739 | + elseif (!empty($mime_type) && (isset($_REQUEST['image']) || !in_array($file_ext, array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff')))) { |
|
1740 | + header('Content-Type: ' . strtr($mime_type, array('image/bmp' => 'image/x-ms-bmp'))); |
|
1741 | + } else |
|
1674 | 1742 | { |
1675 | 1743 | header('Content-Type: ' . (isBrowser('ie') || isBrowser('opera') ? 'application/octetstream' : 'application/octet-stream')); |
1676 | - if (isset($_REQUEST['image'])) |
|
1677 | - unset($_REQUEST['image']); |
|
1744 | + if (isset($_REQUEST['image'])) { |
|
1745 | + unset($_REQUEST['image']); |
|
1746 | + } |
|
1678 | 1747 | } |
1679 | 1748 | |
1680 | 1749 | // Convert the file to UTF-8, cuz most browsers dig that. |
@@ -1682,23 +1751,22 @@ discard block |
||
1682 | 1751 | $disposition = !isset($_REQUEST['image']) ? 'attachment' : 'inline'; |
1683 | 1752 | |
1684 | 1753 | // Different browsers like different standards... |
1685 | - if (isBrowser('firefox')) |
|
1686 | - header('Content-Disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name))); |
|
1687 | - |
|
1688 | - elseif (isBrowser('opera')) |
|
1689 | - header('Content-Disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"'); |
|
1690 | - |
|
1691 | - elseif (isBrowser('ie')) |
|
1692 | - header('Content-Disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"'); |
|
1693 | - |
|
1694 | - else |
|
1695 | - header('Content-Disposition: ' . $disposition . '; filename="' . $utf8name . '"'); |
|
1754 | + if (isBrowser('firefox')) { |
|
1755 | + header('Content-Disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name))); |
|
1756 | + } elseif (isBrowser('opera')) { |
|
1757 | + header('Content-Disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"'); |
|
1758 | + } elseif (isBrowser('ie')) { |
|
1759 | + header('Content-Disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"'); |
|
1760 | + } else { |
|
1761 | + header('Content-Disposition: ' . $disposition . '; filename="' . $utf8name . '"'); |
|
1762 | + } |
|
1696 | 1763 | |
1697 | 1764 | // If this has an "image extension" - but isn't actually an image - then ensure it isn't cached cause of silly IE. |
1698 | - if (!isset($_REQUEST['image']) && in_array($file_ext, array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff'))) |
|
1699 | - header('Cache-Control: no-cache'); |
|
1700 | - else |
|
1701 | - header('Cache-Control: max-age=' . (525600 * 60) . ', private'); |
|
1765 | + if (!isset($_REQUEST['image']) && in_array($file_ext, array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff'))) { |
|
1766 | + header('Cache-Control: no-cache'); |
|
1767 | + } else { |
|
1768 | + header('Cache-Control: max-age=' . (525600 * 60) . ', private'); |
|
1769 | + } |
|
1702 | 1770 | |
1703 | 1771 | header('Content-Length: ' . filesize($filename)); |
1704 | 1772 | |
@@ -1708,20 +1776,23 @@ discard block |
||
1708 | 1776 | // Recode line endings for text files, if enabled. |
1709 | 1777 | if (!empty($modSettings['attachmentRecodeLineEndings']) && !isset($_REQUEST['image']) && in_array($file_ext, array('txt', 'css', 'htm', 'html', 'php', 'xml'))) |
1710 | 1778 | { |
1711 | - if (strpos($_SERVER['HTTP_USER_AGENT'], 'Windows') !== false) |
|
1712 | - $callback = function($buffer) |
|
1779 | + if (strpos($_SERVER['HTTP_USER_AGENT'], 'Windows') !== false) { |
|
1780 | + $callback = function($buffer) |
|
1713 | 1781 | { |
1714 | 1782 | return preg_replace('~[\r]?\n~', "\r\n", $buffer); |
1783 | + } |
|
1715 | 1784 | }; |
1716 | - elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false) |
|
1717 | - $callback = function($buffer) |
|
1785 | + elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false) { |
|
1786 | + $callback = function($buffer) |
|
1718 | 1787 | { |
1719 | 1788 | return preg_replace('~[\r]?\n~', "\r", $buffer); |
1789 | + } |
|
1720 | 1790 | }; |
1721 | - else |
|
1722 | - $callback = function($buffer) |
|
1791 | + else { |
|
1792 | + $callback = function($buffer) |
|
1723 | 1793 | { |
1724 | 1794 | return preg_replace('~[\r]?\n~', "\n", $buffer); |
1795 | + } |
|
1725 | 1796 | }; |
1726 | 1797 | } |
1727 | 1798 | |
@@ -1729,23 +1800,26 @@ discard block |
||
1729 | 1800 | if (filesize($filename) > 4194304) |
1730 | 1801 | { |
1731 | 1802 | // Forcibly end any output buffering going on. |
1732 | - while (@ob_get_level() > 0) |
|
1733 | - @ob_end_clean(); |
|
1803 | + while (@ob_get_level() > 0) { |
|
1804 | + @ob_end_clean(); |
|
1805 | + } |
|
1734 | 1806 | |
1735 | 1807 | $fp = fopen($filename, 'rb'); |
1736 | 1808 | while (!feof($fp)) |
1737 | 1809 | { |
1738 | - if (isset($callback)) |
|
1739 | - echo $callback(fread($fp, 8192)); |
|
1740 | - else |
|
1741 | - echo fread($fp, 8192); |
|
1810 | + if (isset($callback)) { |
|
1811 | + echo $callback(fread($fp, 8192)); |
|
1812 | + } else { |
|
1813 | + echo fread($fp, 8192); |
|
1814 | + } |
|
1742 | 1815 | flush(); |
1743 | 1816 | } |
1744 | 1817 | fclose($fp); |
1745 | 1818 | } |
1746 | 1819 | // On some of the less-bright hosts, readfile() is disabled. It's just a faster, more byte safe, version of what's in the if. |
1747 | - elseif (isset($callback) || @readfile($filename) === null) |
|
1748 | - echo isset($callback) ? $callback(file_get_contents($filename)) : file_get_contents($filename); |
|
1820 | + elseif (isset($callback) || @readfile($filename) === null) { |
|
1821 | + echo isset($callback) ? $callback(file_get_contents($filename)) : file_get_contents($filename); |
|
1822 | + } |
|
1749 | 1823 | |
1750 | 1824 | obExit(false); |
1751 | 1825 | } |
@@ -1758,8 +1832,9 @@ discard block |
||
1758 | 1832 | */ |
1759 | 1833 | function approved_attach_sort($a, $b) |
1760 | 1834 | { |
1761 | - if ($a['is_approved'] == $b['is_approved']) |
|
1762 | - return 0; |
|
1835 | + if ($a['is_approved'] == $b['is_approved']) { |
|
1836 | + return 0; |
|
1837 | + } |
|
1763 | 1838 | |
1764 | 1839 | return $a['is_approved'] > $b['is_approved'] ? -1 : 1; |
1765 | 1840 | } |
@@ -1776,16 +1851,19 @@ discard block |
||
1776 | 1851 | |
1777 | 1852 | require_once($sourcedir . '/RemoveTopic.php'); |
1778 | 1853 | |
1779 | - if (empty($_REQUEST['msgs'])) |
|
1780 | - redirectexit('topic=' . $topic . '.' . $_REQUEST['start']); |
|
1854 | + if (empty($_REQUEST['msgs'])) { |
|
1855 | + redirectexit('topic=' . $topic . '.' . $_REQUEST['start']); |
|
1856 | + } |
|
1781 | 1857 | |
1782 | 1858 | $messages = array(); |
1783 | - foreach ($_REQUEST['msgs'] as $dummy) |
|
1784 | - $messages[] = (int) $dummy; |
|
1859 | + foreach ($_REQUEST['msgs'] as $dummy) { |
|
1860 | + $messages[] = (int) $dummy; |
|
1861 | + } |
|
1785 | 1862 | |
1786 | 1863 | // We are restoring messages. We handle this in another place. |
1787 | - if (isset($_REQUEST['restore_selected'])) |
|
1788 | - redirectexit('action=restoretopic;msgs=' . implode(',', $messages) . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
1864 | + if (isset($_REQUEST['restore_selected'])) { |
|
1865 | + redirectexit('action=restoretopic;msgs=' . implode(',', $messages) . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
1866 | + } |
|
1789 | 1867 | if (isset($_REQUEST['split_selection'])) |
1790 | 1868 | { |
1791 | 1869 | $request = $smcFunc['db_query']('', ' |
@@ -1804,8 +1882,9 @@ discard block |
||
1804 | 1882 | } |
1805 | 1883 | |
1806 | 1884 | // Allowed to delete any message? |
1807 | - if (allowedTo('delete_any')) |
|
1808 | - $allowed_all = true; |
|
1885 | + if (allowedTo('delete_any')) { |
|
1886 | + $allowed_all = true; |
|
1887 | + } |
|
1809 | 1888 | // Allowed to delete replies to their messages? |
1810 | 1889 | elseif (allowedTo('delete_replies')) |
1811 | 1890 | { |
@@ -1822,13 +1901,14 @@ discard block |
||
1822 | 1901 | $smcFunc['db_free_result']($request); |
1823 | 1902 | |
1824 | 1903 | $allowed_all = $starter == $user_info['id']; |
1904 | + } else { |
|
1905 | + $allowed_all = false; |
|
1825 | 1906 | } |
1826 | - else |
|
1827 | - $allowed_all = false; |
|
1828 | 1907 | |
1829 | 1908 | // Make sure they're allowed to delete their own messages, if not any. |
1830 | - if (!$allowed_all) |
|
1831 | - isAllowedTo('delete_own'); |
|
1909 | + if (!$allowed_all) { |
|
1910 | + isAllowedTo('delete_own'); |
|
1911 | + } |
|
1832 | 1912 | |
1833 | 1913 | // Allowed to remove which messages? |
1834 | 1914 | $request = $smcFunc['db_query']('', ' |
@@ -1848,8 +1928,9 @@ discard block |
||
1848 | 1928 | $messages = array(); |
1849 | 1929 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1850 | 1930 | { |
1851 | - if (!$allowed_all && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) |
|
1852 | - continue; |
|
1931 | + if (!$allowed_all && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) { |
|
1932 | + continue; |
|
1933 | + } |
|
1853 | 1934 | |
1854 | 1935 | $messages[$row['id_msg']] = array($row['subject'], $row['id_member']); |
1855 | 1936 | } |
@@ -1872,17 +1953,20 @@ discard block |
||
1872 | 1953 | foreach ($messages as $message => $info) |
1873 | 1954 | { |
1874 | 1955 | // Just skip the first message - if it's not the last. |
1875 | - if ($message == $first_message && $message != $last_message) |
|
1876 | - continue; |
|
1956 | + if ($message == $first_message && $message != $last_message) { |
|
1957 | + continue; |
|
1958 | + } |
|
1877 | 1959 | // If the first message is going then don't bother going back to the topic as we're effectively deleting it. |
1878 | - elseif ($message == $first_message) |
|
1879 | - $topicGone = true; |
|
1960 | + elseif ($message == $first_message) { |
|
1961 | + $topicGone = true; |
|
1962 | + } |
|
1880 | 1963 | |
1881 | 1964 | removeMessage($message); |
1882 | 1965 | |
1883 | 1966 | // Log this moderation action ;). |
1884 | - if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id'])) |
|
1885 | - logAction('delete', array('topic' => $topic, 'subject' => $info[0], 'member' => $info[1], 'board' => $board)); |
|
1967 | + if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id'])) { |
|
1968 | + logAction('delete', array('topic' => $topic, 'subject' => $info[0], 'member' => $info[1], 'board' => $board)); |
|
1969 | + } |
|
1886 | 1970 | } |
1887 | 1971 | |
1888 | 1972 | redirectexit(!empty($topicGone) ? 'board=' . $board : 'topic=' . $topic . '.' . $_REQUEST['start']); |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 3 |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF')) |
|
16 | +if (!defined('SMF')) { |
|
17 | 17 | die('No direct access...'); |
18 | +} |
|
18 | 19 | |
19 | 20 | /** |
20 | 21 | * The main entrance point for the Manage Members screen. |
@@ -62,16 +63,18 @@ discard block |
||
62 | 63 | $context['activation_numbers'] = array(); |
63 | 64 | $context['awaiting_activation'] = 0; |
64 | 65 | $context['awaiting_approval'] = 0; |
65 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
66 | - $context['activation_numbers'][$row['is_activated']] = $row['total_members']; |
|
66 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
67 | + $context['activation_numbers'][$row['is_activated']] = $row['total_members']; |
|
68 | + } |
|
67 | 69 | $smcFunc['db_free_result']($request); |
68 | 70 | |
69 | 71 | foreach ($context['activation_numbers'] as $activation_type => $total_members) |
70 | 72 | { |
71 | - if (in_array($activation_type, array(0, 2))) |
|
72 | - $context['awaiting_activation'] += $total_members; |
|
73 | - elseif (in_array($activation_type, array(3, 4, 5))) |
|
74 | - $context['awaiting_approval'] += $total_members; |
|
73 | + if (in_array($activation_type, array(0, 2))) { |
|
74 | + $context['awaiting_activation'] += $total_members; |
|
75 | + } elseif (in_array($activation_type, array(3, 4, 5))) { |
|
76 | + $context['awaiting_approval'] += $total_members; |
|
77 | + } |
|
75 | 78 | } |
76 | 79 | |
77 | 80 | // For the page header... do we show activation? |
@@ -124,8 +127,9 @@ discard block |
||
124 | 127 | } |
125 | 128 | if (!$context['show_approve'] && ($_REQUEST['sa'] != 'browse' || $_REQUEST['type'] != 'approve')) |
126 | 129 | { |
127 | - if (!$context['show_activate'] && ($_REQUEST['sa'] != 'browse' || $_REQUEST['type'] != 'activate')) |
|
128 | - $context['tabs']['search']['is_last'] = true; |
|
130 | + if (!$context['show_activate'] && ($_REQUEST['sa'] != 'browse' || $_REQUEST['type'] != 'activate')) { |
|
131 | + $context['tabs']['search']['is_last'] = true; |
|
132 | + } |
|
129 | 133 | unset($context['tabs']['approve']); |
130 | 134 | } |
131 | 135 | |
@@ -157,8 +161,9 @@ discard block |
||
157 | 161 | foreach ($_POST['delete'] as $key => $value) |
158 | 162 | { |
159 | 163 | // Don't delete yourself, idiot. |
160 | - if ($value != $user_info['id']) |
|
161 | - $delete[$key] = (int) $value; |
|
164 | + if ($value != $user_info['id']) { |
|
165 | + $delete[$key] = (int) $value; |
|
166 | + } |
|
162 | 167 | } |
163 | 168 | |
164 | 169 | if (!empty($delete)) |
@@ -194,17 +199,18 @@ discard block |
||
194 | 199 | ); |
195 | 200 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
196 | 201 | { |
197 | - if ($row['min_posts'] == -1) |
|
198 | - $context['membergroups'][] = array( |
|
202 | + if ($row['min_posts'] == -1) { |
|
203 | + $context['membergroups'][] = array( |
|
199 | 204 | 'id' => $row['id_group'], |
200 | 205 | 'name' => $row['group_name'], |
201 | 206 | 'can_be_additional' => true |
202 | 207 | ); |
203 | - else |
|
204 | - $context['postgroups'][] = array( |
|
208 | + } else { |
|
209 | + $context['postgroups'][] = array( |
|
205 | 210 | 'id' => $row['id_group'], |
206 | 211 | 'name' => $row['group_name'] |
207 | 212 | ); |
213 | + } |
|
208 | 214 | } |
209 | 215 | $smcFunc['db_free_result']($request); |
210 | 216 | |
@@ -268,14 +274,15 @@ discard block |
||
268 | 274 | call_integration_hook('integrate_view_members_params', array(&$params)); |
269 | 275 | |
270 | 276 | $search_params = array(); |
271 | - if ($context['sub_action'] == 'query' && !empty($_REQUEST['params']) && empty($_POST['types'])) |
|
272 | - $search_params = smf_json_decode(base64_decode($_REQUEST['params']), true); |
|
273 | - elseif (!empty($_POST)) |
|
277 | + if ($context['sub_action'] == 'query' && !empty($_REQUEST['params']) && empty($_POST['types'])) { |
|
278 | + $search_params = smf_json_decode(base64_decode($_REQUEST['params']), true); |
|
279 | + } elseif (!empty($_POST)) |
|
274 | 280 | { |
275 | 281 | $search_params['types'] = $_POST['types']; |
276 | - foreach ($params as $param_name => $param_info) |
|
277 | - if (isset($_POST[$param_name])) |
|
282 | + foreach ($params as $param_name => $param_info) { |
|
283 | + if (isset($_POST[$param_name])) |
|
278 | 284 | $search_params[$param_name] = $_POST[$param_name]; |
285 | + } |
|
279 | 286 | } |
280 | 287 | |
281 | 288 | $search_url_params = isset($search_params) ? base64_encode(json_encode($search_params)) : null; |
@@ -288,18 +295,21 @@ discard block |
||
288 | 295 | foreach ($params as $param_name => $param_info) |
289 | 296 | { |
290 | 297 | // Not filled in? |
291 | - if (!isset($search_params[$param_name]) || $search_params[$param_name] === '') |
|
292 | - continue; |
|
298 | + if (!isset($search_params[$param_name]) || $search_params[$param_name] === '') { |
|
299 | + continue; |
|
300 | + } |
|
293 | 301 | |
294 | 302 | // Make sure numeric values are really numeric. |
295 | - if (in_array($param_info['type'], array('int', 'age'))) |
|
296 | - $search_params[$param_name] = (int) $search_params[$param_name]; |
|
303 | + if (in_array($param_info['type'], array('int', 'age'))) { |
|
304 | + $search_params[$param_name] = (int) $search_params[$param_name]; |
|
305 | + } |
|
297 | 306 | // Date values have to match the specified format. |
298 | 307 | elseif ($param_info['type'] == 'date') |
299 | 308 | { |
300 | 309 | // Check if this date format is valid. |
301 | - if (preg_match('/^\d{4}-\d{1,2}-\d{1,2}$/', $search_params[$param_name]) == 0) |
|
302 | - continue; |
|
310 | + if (preg_match('/^\d{4}-\d{1,2}-\d{1,2}$/', $search_params[$param_name]) == 0) { |
|
311 | + continue; |
|
312 | + } |
|
303 | 313 | |
304 | 314 | $search_params[$param_name] = strtotime($search_params[$param_name]); |
305 | 315 | } |
@@ -308,8 +318,9 @@ discard block |
||
308 | 318 | if (!empty($param_info['range'])) |
309 | 319 | { |
310 | 320 | // Default to '=', just in case... |
311 | - if (empty($range_trans[$search_params['types'][$param_name]])) |
|
312 | - $search_params['types'][$param_name] = '='; |
|
321 | + if (empty($range_trans[$search_params['types'][$param_name]])) { |
|
322 | + $search_params['types'][$param_name] = '='; |
|
323 | + } |
|
313 | 324 | |
314 | 325 | // Handle special case 'age'. |
315 | 326 | if ($param_info['type'] == 'age') |
@@ -337,29 +348,30 @@ discard block |
||
337 | 348 | elseif ($param_info['type'] == 'date' && $search_params['types'][$param_name] == '=') |
338 | 349 | { |
339 | 350 | $query_parts[] = $param_info['db_fields'][0] . ' > ' . $search_params[$param_name] . ' AND ' . $param_info['db_fields'][0] . ' < ' . ($search_params[$param_name] + 86400); |
351 | + } else { |
|
352 | + $query_parts[] = $param_info['db_fields'][0] . ' ' . $range_trans[$search_params['types'][$param_name]] . ' ' . $search_params[$param_name]; |
|
340 | 353 | } |
341 | - else |
|
342 | - $query_parts[] = $param_info['db_fields'][0] . ' ' . $range_trans[$search_params['types'][$param_name]] . ' ' . $search_params[$param_name]; |
|
343 | 354 | } |
344 | 355 | // Checkboxes. |
345 | 356 | elseif ($param_info['type'] == 'checkbox') |
346 | 357 | { |
347 | 358 | // Each checkbox or no checkbox at all is checked -> ignore. |
348 | - if (!is_array($search_params[$param_name]) || count($search_params[$param_name]) == 0 || count($search_params[$param_name]) == count($param_info['values'])) |
|
349 | - continue; |
|
359 | + if (!is_array($search_params[$param_name]) || count($search_params[$param_name]) == 0 || count($search_params[$param_name]) == count($param_info['values'])) { |
|
360 | + continue; |
|
361 | + } |
|
350 | 362 | |
351 | 363 | $query_parts[] = ($param_info['db_fields'][0]) . ' IN ({array_string:' . $param_name . '_check})'; |
352 | 364 | $where_params[$param_name . '_check'] = $search_params[$param_name]; |
353 | - } |
|
354 | - else |
|
365 | + } else |
|
355 | 366 | { |
356 | 367 | // Replace the wildcard characters ('*' and '?') into MySQL ones. |
357 | 368 | $parameter = strtolower(strtr($smcFunc['htmlspecialchars']($search_params[$param_name], ENT_QUOTES), array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_'))); |
358 | 369 | |
359 | - if ($smcFunc['db_case_sensitive']) |
|
360 | - $query_parts[] = '(LOWER(' . implode(') LIKE {string:' . $param_name . '_normal} OR LOWER(', $param_info['db_fields']) . ') LIKE {string:' . $param_name . '_normal})'; |
|
361 | - else |
|
362 | - $query_parts[] = '(' . implode(' LIKE {string:' . $param_name . '_normal} OR ', $param_info['db_fields']) . ' LIKE {string:' . $param_name . '_normal})'; |
|
370 | + if ($smcFunc['db_case_sensitive']) { |
|
371 | + $query_parts[] = '(LOWER(' . implode(') LIKE {string:' . $param_name . '_normal} OR LOWER(', $param_info['db_fields']) . ') LIKE {string:' . $param_name . '_normal})'; |
|
372 | + } else { |
|
373 | + $query_parts[] = '(' . implode(' LIKE {string:' . $param_name . '_normal} OR ', $param_info['db_fields']) . ' LIKE {string:' . $param_name . '_normal})'; |
|
374 | + } |
|
363 | 375 | $where_params[$param_name . '_normal'] = '%' . $parameter . '%'; |
364 | 376 | } |
365 | 377 | } |
@@ -375,16 +387,18 @@ discard block |
||
375 | 387 | } |
376 | 388 | |
377 | 389 | // Additional membergroups (these are only relevant if not all primary groups where selected!). |
378 | - if (!empty($search_params['membergroups'][2]) && (empty($search_params['membergroups'][1]) || count($context['membergroups']) != count($search_params['membergroups'][1]))) |
|
379 | - foreach ($search_params['membergroups'][2] as $mg) |
|
390 | + if (!empty($search_params['membergroups'][2]) && (empty($search_params['membergroups'][1]) || count($context['membergroups']) != count($search_params['membergroups'][1]))) { |
|
391 | + foreach ($search_params['membergroups'][2] as $mg) |
|
380 | 392 | { |
381 | 393 | $mg_query_parts[] = 'FIND_IN_SET({int:add_group_' . $mg . '}, mem.additional_groups) != 0'; |
394 | + } |
|
382 | 395 | $where_params['add_group_' . $mg] = $mg; |
383 | 396 | } |
384 | 397 | |
385 | 398 | // Combine the one or two membergroup parts into one query part linked with an OR. |
386 | - if (!empty($mg_query_parts)) |
|
387 | - $query_parts[] = '(' . implode(' OR ', $mg_query_parts) . ')'; |
|
399 | + if (!empty($mg_query_parts)) { |
|
400 | + $query_parts[] = '(' . implode(' OR ', $mg_query_parts) . ')'; |
|
401 | + } |
|
388 | 402 | |
389 | 403 | // Get all selected post count related membergroups. |
390 | 404 | if (!empty($search_params['postgroups']) && count($search_params['postgroups']) != count($context['postgroups'])) |
@@ -396,9 +410,9 @@ discard block |
||
396 | 410 | // Construct the where part of the query. |
397 | 411 | $where = empty($query_parts) ? '1=1' : implode(' |
398 | 412 | AND ', $query_parts); |
413 | + } else { |
|
414 | + $search_url_params = null; |
|
399 | 415 | } |
400 | - else |
|
401 | - $search_url_params = null; |
|
402 | 416 | |
403 | 417 | // Construct the additional URL part with the query info in it. |
404 | 418 | $context['params_url'] = $context['sub_action'] == 'query' ? ';sa=query;params=' . $search_url_params : ''; |
@@ -521,28 +535,32 @@ discard block |
||
521 | 535 | 'function' => function($rowData) use ($txt) |
522 | 536 | { |
523 | 537 | // Calculate number of days since last online. |
524 | - if (empty($rowData['last_login'])) |
|
525 | - $difference = $txt['never']; |
|
526 | - else |
|
538 | + if (empty($rowData['last_login'])) { |
|
539 | + $difference = $txt['never']; |
|
540 | + } else |
|
527 | 541 | { |
528 | 542 | $num_days_difference = jeffsdatediff($rowData['last_login']); |
529 | 543 | |
530 | 544 | // Today. |
531 | - if (empty($num_days_difference)) |
|
532 | - $difference = $txt['viewmembers_today']; |
|
545 | + if (empty($num_days_difference)) { |
|
546 | + $difference = $txt['viewmembers_today']; |
|
547 | + } |
|
533 | 548 | |
534 | 549 | // Yesterday. |
535 | - elseif ($num_days_difference == 1) |
|
536 | - $difference = sprintf('1 %1$s', $txt['viewmembers_day_ago']); |
|
550 | + elseif ($num_days_difference == 1) { |
|
551 | + $difference = sprintf('1 %1$s', $txt['viewmembers_day_ago']); |
|
552 | + } |
|
537 | 553 | |
538 | 554 | // X days ago. |
539 | - else |
|
540 | - $difference = sprintf('%1$d %2$s', $num_days_difference, $txt['viewmembers_days_ago']); |
|
555 | + else { |
|
556 | + $difference = sprintf('%1$d %2$s', $num_days_difference, $txt['viewmembers_days_ago']); |
|
557 | + } |
|
541 | 558 | } |
542 | 559 | |
543 | 560 | // Show it in italics if they're not activated... |
544 | - if ($rowData['is_activated'] % 10 != 1) |
|
545 | - $difference = sprintf('<em title="%1$s">%2$s</em>', $txt['not_activated'], $difference); |
|
561 | + if ($rowData['is_activated'] % 10 != 1) { |
|
562 | + $difference = sprintf('<em title="%1$s">%2$s</em>', $txt['not_activated'], $difference); |
|
563 | + } |
|
546 | 564 | |
547 | 565 | return $difference; |
548 | 566 | }, |
@@ -594,8 +612,9 @@ discard block |
||
594 | 612 | ); |
595 | 613 | |
596 | 614 | // Without enough permissions, don't show 'delete members' checkboxes. |
597 | - if (!allowedTo('profile_remove_any')) |
|
598 | - unset($listOptions['cols']['check'], $listOptions['form'], $listOptions['additional_rows']); |
|
615 | + if (!allowedTo('profile_remove_any')) { |
|
616 | + unset($listOptions['cols']['check'], $listOptions['form'], $listOptions['additional_rows']); |
|
617 | + } |
|
599 | 618 | |
600 | 619 | require_once($sourcedir . '/Subs-List.php'); |
601 | 620 | createList($listOptions); |
@@ -638,17 +657,18 @@ discard block |
||
638 | 657 | ); |
639 | 658 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
640 | 659 | { |
641 | - if ($row['min_posts'] == -1) |
|
642 | - $context['membergroups'][] = array( |
|
660 | + if ($row['min_posts'] == -1) { |
|
661 | + $context['membergroups'][] = array( |
|
643 | 662 | 'id' => $row['id_group'], |
644 | 663 | 'name' => $row['group_name'], |
645 | 664 | 'can_be_additional' => true |
646 | 665 | ); |
647 | - else |
|
648 | - $context['postgroups'][] = array( |
|
666 | + } else { |
|
667 | + $context['postgroups'][] = array( |
|
649 | 668 | 'id' => $row['id_group'], |
650 | 669 | 'name' => $row['group_name'] |
651 | 670 | ); |
671 | + } |
|
652 | 672 | } |
653 | 673 | $smcFunc['db_free_result']($request); |
654 | 674 | |
@@ -675,8 +695,9 @@ discard block |
||
675 | 695 | $context['page_title'] = $txt['admin_members']; |
676 | 696 | $context['sub_template'] = 'admin_browse'; |
677 | 697 | $context['browse_type'] = isset($_REQUEST['type']) ? $_REQUEST['type'] : (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1 ? 'activate' : 'approve'); |
678 | - if (isset($context['tabs'][$context['browse_type']])) |
|
679 | - $context['tabs'][$context['browse_type']]['is_selected'] = true; |
|
698 | + if (isset($context['tabs'][$context['browse_type']])) { |
|
699 | + $context['tabs'][$context['browse_type']]['is_selected'] = true; |
|
700 | + } |
|
680 | 701 | |
681 | 702 | // Allowed filters are those we can have, in theory. |
682 | 703 | $context['allowed_filters'] = $context['browse_type'] == 'approve' ? array(3, 4, 5) : array(0, 2); |
@@ -687,18 +708,20 @@ discard block |
||
687 | 708 | foreach ($context['activation_numbers'] as $type => $amount) |
688 | 709 | { |
689 | 710 | // We have some of these... |
690 | - if (in_array($type, $context['allowed_filters']) && $amount > 0) |
|
691 | - $context['available_filters'][] = array( |
|
711 | + if (in_array($type, $context['allowed_filters']) && $amount > 0) { |
|
712 | + $context['available_filters'][] = array( |
|
692 | 713 | 'type' => $type, |
693 | 714 | 'amount' => $amount, |
694 | 715 | 'desc' => isset($txt['admin_browse_filter_type_' . $type]) ? $txt['admin_browse_filter_type_' . $type] : '?', |
695 | 716 | 'selected' => $type == $context['current_filter'] |
696 | 717 | ); |
718 | + } |
|
697 | 719 | } |
698 | 720 | |
699 | 721 | // If the filter was not sent, set it to whatever has people in it! |
700 | - if ($context['current_filter'] == -1 && !empty($context['available_filters'][0]['amount'])) |
|
701 | - $context['current_filter'] = $context['available_filters'][0]['type']; |
|
722 | + if ($context['current_filter'] == -1 && !empty($context['available_filters'][0]['amount'])) { |
|
723 | + $context['current_filter'] = $context['available_filters'][0]['type']; |
|
724 | + } |
|
702 | 725 | |
703 | 726 | // This little variable is used to determine if we should flag where we are looking. |
704 | 727 | $context['show_filter'] = ($context['current_filter'] != 0 && $context['current_filter'] != 3) || count($context['available_filters']) > 1; |
@@ -713,44 +736,47 @@ discard block |
||
713 | 736 | ); |
714 | 737 | |
715 | 738 | // Are we showing duplicate information? |
716 | - if (isset($_GET['showdupes'])) |
|
717 | - $_SESSION['showdupes'] = (int) $_GET['showdupes']; |
|
739 | + if (isset($_GET['showdupes'])) { |
|
740 | + $_SESSION['showdupes'] = (int) $_GET['showdupes']; |
|
741 | + } |
|
718 | 742 | $context['show_duplicates'] = !empty($_SESSION['showdupes']); |
719 | 743 | |
720 | 744 | // Determine which actions we should allow on this page. |
721 | 745 | if ($context['browse_type'] == 'approve') |
722 | 746 | { |
723 | 747 | // If we are approving deleted accounts we have a slightly different list... actually a mirror ;) |
724 | - if ($context['current_filter'] == 4) |
|
725 | - $context['allowed_actions'] = array( |
|
748 | + if ($context['current_filter'] == 4) { |
|
749 | + $context['allowed_actions'] = array( |
|
726 | 750 | 'reject' => $txt['admin_browse_w_approve_deletion'], |
727 | 751 | 'ok' => $txt['admin_browse_w_reject'], |
728 | 752 | ); |
729 | - else |
|
730 | - $context['allowed_actions'] = array( |
|
753 | + } else { |
|
754 | + $context['allowed_actions'] = array( |
|
731 | 755 | 'ok' => $txt['admin_browse_w_approve'], |
732 | 756 | 'okemail' => $txt['admin_browse_w_approve'] . ' ' . $txt['admin_browse_w_email'], |
733 | 757 | 'require_activation' => $txt['admin_browse_w_approve_require_activate'], |
734 | 758 | 'reject' => $txt['admin_browse_w_reject'], |
735 | 759 | 'rejectemail' => $txt['admin_browse_w_reject'] . ' ' . $txt['admin_browse_w_email'], |
736 | 760 | ); |
737 | - } |
|
738 | - elseif ($context['browse_type'] == 'activate') |
|
739 | - $context['allowed_actions'] = array( |
|
761 | + } |
|
762 | + } elseif ($context['browse_type'] == 'activate') { |
|
763 | + $context['allowed_actions'] = array( |
|
740 | 764 | 'ok' => $txt['admin_browse_w_activate'], |
741 | 765 | 'okemail' => $txt['admin_browse_w_activate'] . ' ' . $txt['admin_browse_w_email'], |
742 | 766 | 'delete' => $txt['admin_browse_w_delete'], |
743 | 767 | 'deleteemail' => $txt['admin_browse_w_delete'] . ' ' . $txt['admin_browse_w_email'], |
744 | 768 | 'remind' => $txt['admin_browse_w_remind'] . ' ' . $txt['admin_browse_w_email'], |
745 | 769 | ); |
770 | + } |
|
746 | 771 | |
747 | 772 | // Create an option list for actions allowed to be done with selected members. |
748 | 773 | $allowed_actions = ' |
749 | 774 | <option selected value="">' . $txt['admin_browse_with_selected'] . ':</option> |
750 | 775 | <option value="" disabled>-----------------------------</option>'; |
751 | - foreach ($context['allowed_actions'] as $key => $desc) |
|
752 | - $allowed_actions .= ' |
|
776 | + foreach ($context['allowed_actions'] as $key => $desc) { |
|
777 | + $allowed_actions .= ' |
|
753 | 778 | <option value="' . $key . '">' . $desc . '</option>'; |
779 | + } |
|
754 | 780 | |
755 | 781 | // Setup the Javascript function for selecting an action for the list. |
756 | 782 | $javascript = ' |
@@ -762,15 +788,16 @@ discard block |
||
762 | 788 | var message = "";'; |
763 | 789 | |
764 | 790 | // We have special messages for approving deletion of accounts - it's surprisingly logical - honest. |
765 | - if ($context['current_filter'] == 4) |
|
766 | - $javascript .= ' |
|
791 | + if ($context['current_filter'] == 4) { |
|
792 | + $javascript .= ' |
|
767 | 793 | if (document.forms.postForm.todo.value.indexOf("reject") != -1) |
768 | 794 | message = "' . $txt['admin_browse_w_delete'] . '"; |
769 | 795 | else |
770 | 796 | message = "' . $txt['admin_browse_w_reject'] . '";'; |
797 | + } |
|
771 | 798 | // Otherwise a nice standard message. |
772 | - else |
|
773 | - $javascript .= ' |
|
799 | + else { |
|
800 | + $javascript .= ' |
|
774 | 801 | if (document.forms.postForm.todo.value.indexOf("delete") != -1) |
775 | 802 | message = "' . $txt['admin_browse_w_delete'] . '"; |
776 | 803 | else if (document.forms.postForm.todo.value.indexOf("reject") != -1) |
@@ -779,6 +806,7 @@ discard block |
||
779 | 806 | message = "' . $txt['admin_browse_w_remind'] . '"; |
780 | 807 | else |
781 | 808 | message = "' . ($context['browse_type'] == 'approve' ? $txt['admin_browse_w_approve'] : $txt['admin_browse_w_activate']) . '";'; |
809 | + } |
|
782 | 810 | $javascript .= ' |
783 | 811 | if (confirm(message + " ' . $txt['admin_browse_warn'] . '")) |
784 | 812 | document.forms.postForm.submit(); |
@@ -911,10 +939,11 @@ discard block |
||
911 | 939 | $member_links = array(); |
912 | 940 | foreach ($rowData['duplicate_members'] as $member) |
913 | 941 | { |
914 | - if ($member['id']) |
|
915 | - $member_links[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '" ' . (!empty($member['is_banned']) ? 'class="red"' : '') . '>' . $member['name'] . '</a>'; |
|
916 | - else |
|
917 | - $member_links[] = $member['name'] . ' (' . $txt['guest'] . ')'; |
|
942 | + if ($member['id']) { |
|
943 | + $member_links[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '" ' . (!empty($member['is_banned']) ? 'class="red"' : '') . '>' . $member['name'] . '</a>'; |
|
944 | + } else { |
|
945 | + $member_links[] = $member['name'] . ' (' . $txt['guest'] . ')'; |
|
946 | + } |
|
918 | 947 | } |
919 | 948 | return implode(', ', $member_links); |
920 | 949 | }, |
@@ -963,14 +992,16 @@ discard block |
||
963 | 992 | ); |
964 | 993 | |
965 | 994 | // Pick what column to actually include if we're showing duplicates. |
966 | - if ($context['show_duplicates']) |
|
967 | - unset($listOptions['columns']['email']); |
|
968 | - else |
|
969 | - unset($listOptions['columns']['duplicates']); |
|
995 | + if ($context['show_duplicates']) { |
|
996 | + unset($listOptions['columns']['email']); |
|
997 | + } else { |
|
998 | + unset($listOptions['columns']['duplicates']); |
|
999 | + } |
|
970 | 1000 | |
971 | 1001 | // Only show hostname on duplicates as it takes a lot of time. |
972 | - if (!$context['show_duplicates'] || !empty($modSettings['disableHostnameLookup'])) |
|
973 | - unset($listOptions['columns']['hostname']); |
|
1002 | + if (!$context['show_duplicates'] || !empty($modSettings['disableHostnameLookup'])) { |
|
1003 | + unset($listOptions['columns']['hostname']); |
|
1004 | + } |
|
974 | 1005 | |
975 | 1006 | // Is there any need to show filters? |
976 | 1007 | if (isset($context['available_filters']) && count($context['available_filters']) > 1) |
@@ -978,9 +1009,10 @@ discard block |
||
978 | 1009 | $filterOptions = ' |
979 | 1010 | <strong>' . $txt['admin_browse_filter_by'] . ':</strong> |
980 | 1011 | <select name="filter" onchange="this.form.submit();">'; |
981 | - foreach ($context['available_filters'] as $filter) |
|
982 | - $filterOptions .= ' |
|
1012 | + foreach ($context['available_filters'] as $filter) { |
|
1013 | + $filterOptions .= ' |
|
983 | 1014 | <option value="' . $filter['type'] . '"' . ($filter['selected'] ? ' selected' : '') . '>' . $filter['desc'] . ' - ' . $filter['amount'] . ' ' . ($filter['amount'] == 1 ? $txt['user'] : $txt['users']) . '</option>'; |
1015 | + } |
|
984 | 1016 | $filterOptions .= ' |
985 | 1017 | </select> |
986 | 1018 | <noscript><input type="submit" value="' . $txt['go'] . '" name="filter" class="button_submit"></noscript>'; |
@@ -992,12 +1024,13 @@ discard block |
||
992 | 1024 | } |
993 | 1025 | |
994 | 1026 | // What about if we only have one filter, but it's not the "standard" filter - show them what they are looking at. |
995 | - if (!empty($context['show_filter']) && !empty($context['available_filters'])) |
|
996 | - $listOptions['additional_rows'][] = array( |
|
1027 | + if (!empty($context['show_filter']) && !empty($context['available_filters'])) { |
|
1028 | + $listOptions['additional_rows'][] = array( |
|
997 | 1029 | 'position' => 'above_column_headers', |
998 | 1030 | 'value' => '<strong>' . $txt['admin_browse_filter_show'] . ':</strong> ' . $context['available_filters'][0]['desc'], |
999 | 1031 | 'class' => 'smalltext floatright', |
1000 | 1032 | ); |
1033 | + } |
|
1001 | 1034 | |
1002 | 1035 | // Now that we have all the options, create the list. |
1003 | 1036 | require_once($sourcedir . '/Subs-List.php'); |
@@ -1027,12 +1060,14 @@ discard block |
||
1027 | 1060 | $current_filter = (int) $_REQUEST['orig_filter']; |
1028 | 1061 | |
1029 | 1062 | // If we are applying a filter do just that - then redirect. |
1030 | - if (isset($_REQUEST['filter']) && $_REQUEST['filter'] != $_REQUEST['orig_filter']) |
|
1031 | - redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $_REQUEST['filter'] . ';start=' . $_REQUEST['start']); |
|
1063 | + if (isset($_REQUEST['filter']) && $_REQUEST['filter'] != $_REQUEST['orig_filter']) { |
|
1064 | + redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $_REQUEST['filter'] . ';start=' . $_REQUEST['start']); |
|
1065 | + } |
|
1032 | 1066 | |
1033 | 1067 | // Nothing to do? |
1034 | - if (!isset($_POST['todoAction']) && !isset($_POST['time_passed'])) |
|
1035 | - redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']); |
|
1068 | + if (!isset($_POST['todoAction']) && !isset($_POST['time_passed'])) { |
|
1069 | + redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']); |
|
1070 | + } |
|
1036 | 1071 | |
1037 | 1072 | // Are we dealing with members who have been waiting for > set amount of time? |
1038 | 1073 | if (isset($_POST['time_passed'])) |
@@ -1045,8 +1080,9 @@ discard block |
||
1045 | 1080 | else |
1046 | 1081 | { |
1047 | 1082 | $members = array(); |
1048 | - foreach ($_POST['todoAction'] as $id) |
|
1049 | - $members[] = (int) $id; |
|
1083 | + foreach ($_POST['todoAction'] as $id) { |
|
1084 | + $members[] = (int) $id; |
|
1085 | + } |
|
1050 | 1086 | $condition = ' |
1051 | 1087 | AND id_member IN ({array_int:members})'; |
1052 | 1088 | } |
@@ -1067,8 +1103,9 @@ discard block |
||
1067 | 1103 | $member_count = $smcFunc['db_num_rows']($request); |
1068 | 1104 | |
1069 | 1105 | // If no results then just return! |
1070 | - if ($member_count == 0) |
|
1071 | - redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']); |
|
1106 | + if ($member_count == 0) { |
|
1107 | + redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']); |
|
1108 | + } |
|
1072 | 1109 | |
1073 | 1110 | $member_info = array(); |
1074 | 1111 | $members = array(); |
@@ -1107,8 +1144,9 @@ discard block |
||
1107 | 1144 | // Do we have to let the integration code know about the activations? |
1108 | 1145 | if (!empty($modSettings['integrate_activate'])) |
1109 | 1146 | { |
1110 | - foreach ($member_info as $member) |
|
1111 | - call_integration_hook('integrate_activate', array($member['username'])); |
|
1147 | + foreach ($member_info as $member) { |
|
1148 | + call_integration_hook('integrate_activate', array($member['username'])); |
|
1149 | + } |
|
1112 | 1150 | } |
1113 | 1151 | |
1114 | 1152 | // Check for email. |
@@ -1238,20 +1276,23 @@ discard block |
||
1238 | 1276 | $log_action = $_POST['todo'] == 'remind' ? 'remind_member' : 'approve_member'; |
1239 | 1277 | |
1240 | 1278 | require_once($sourcedir . '/Logging.php'); |
1241 | - foreach ($member_info as $member) |
|
1242 | - logAction($log_action, array('member' => $member['id']), 'admin'); |
|
1279 | + foreach ($member_info as $member) { |
|
1280 | + logAction($log_action, array('member' => $member['id']), 'admin'); |
|
1281 | + } |
|
1243 | 1282 | } |
1244 | 1283 | |
1245 | 1284 | // Although updateStats *may* catch this, best to do it manually just in case (Doesn't always sort out unapprovedMembers). |
1246 | - if (in_array($current_filter, array(3, 4, 5))) |
|
1247 | - updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > $member_count ? $modSettings['unapprovedMembers'] - $member_count : 0))); |
|
1285 | + if (in_array($current_filter, array(3, 4, 5))) { |
|
1286 | + updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > $member_count ? $modSettings['unapprovedMembers'] - $member_count : 0))); |
|
1287 | + } |
|
1248 | 1288 | |
1249 | 1289 | // Update the member's stats. (but, we know the member didn't change their name.) |
1250 | 1290 | updateStats('member', false); |
1251 | 1291 | |
1252 | 1292 | // If they haven't been deleted, update the post group statistics on them... |
1253 | - if (!in_array($_POST['todo'], array('delete', 'deleteemail', 'reject', 'rejectemail', 'remind'))) |
|
1254 | - updateStats('postgroups', $members); |
|
1293 | + if (!in_array($_POST['todo'], array('delete', 'deleteemail', 'reject', 'rejectemail', 'remind'))) { |
|
1294 | + updateStats('postgroups', $members); |
|
1295 | + } |
|
1255 | 1296 | |
1256 | 1297 | redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']); |
1257 | 1298 | } |
@@ -1276,10 +1317,11 @@ discard block |
||
1276 | 1317 | $dis = time() - $old; |
1277 | 1318 | |
1278 | 1319 | // Before midnight? |
1279 | - if ($dis < $sinceMidnight) |
|
1280 | - return 0; |
|
1281 | - else |
|
1282 | - $dis -= $sinceMidnight; |
|
1320 | + if ($dis < $sinceMidnight) { |
|
1321 | + return 0; |
|
1322 | + } else { |
|
1323 | + $dis -= $sinceMidnight; |
|
1324 | + } |
|
1283 | 1325 | |
1284 | 1326 | // Divide out the seconds in a day to get the number of days. |
1285 | 1327 | return ceil($dis / (24 * 60 * 60)); |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 3 |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF')) |
|
16 | +if (!defined('SMF')) { |
|
17 | 17 | die('No direct access...'); |
18 | +} |
|
18 | 19 | |
19 | 20 | /** |
20 | 21 | * Class Likes |
@@ -108,8 +109,9 @@ discard block |
||
108 | 109 | $this->_extra = isset($_GET['extra']) ? $_GET['extra'] : false; |
109 | 110 | |
110 | 111 | // We do not want to output debug information here. |
111 | - if ($this->_js) |
|
112 | - $db_show_debug = false; |
|
112 | + if ($this->_js) { |
|
113 | + $db_show_debug = false; |
|
114 | + } |
|
113 | 115 | } |
114 | 116 | |
115 | 117 | /** |
@@ -143,8 +145,9 @@ discard block |
||
143 | 145 | $call = $this->_sa; |
144 | 146 | |
145 | 147 | // Guest can only view likes. |
146 | - if ($call != 'view') |
|
147 | - is_not_guest(); |
|
148 | + if ($call != 'view') { |
|
149 | + is_not_guest(); |
|
150 | + } |
|
148 | 151 | |
149 | 152 | checkSession('get'); |
150 | 153 | |
@@ -182,15 +185,17 @@ discard block |
||
182 | 185 | global $smcFunc, $modSettings; |
183 | 186 | |
184 | 187 | // This feature is currently disable. |
185 | - if (empty($modSettings['enable_likes'])) |
|
186 | - return $this->_error = 'like_disable'; |
|
188 | + if (empty($modSettings['enable_likes'])) { |
|
189 | + return $this->_error = 'like_disable'; |
|
190 | + } |
|
187 | 191 | |
188 | 192 | // Zerothly, they did indicate some kind of content to like, right? |
189 | 193 | preg_match('~^([a-z0-9\-\_]{1,6})~i', $this->_type, $matches); |
190 | 194 | $this->_type = isset($matches[1]) ? $matches[1] : ''; |
191 | 195 | |
192 | - if ($this->_type == '' || $this->_content <= 0) |
|
193 | - return $this->_error = 'cannot_'; |
|
196 | + if ($this->_type == '' || $this->_content <= 0) { |
|
197 | + return $this->_error = 'cannot_'; |
|
198 | + } |
|
194 | 199 | |
195 | 200 | // First we need to verify if the user can see the type of content or not. This is set up to be extensible, |
196 | 201 | // so we'll check for the one type we do know about, and if it's not that, we'll defer to any hooks. |
@@ -209,12 +214,14 @@ discard block |
||
209 | 214 | 'msg' => $this->_content, |
210 | 215 | ) |
211 | 216 | ); |
212 | - if ($smcFunc['db_num_rows']($request) == 1) |
|
213 | - list ($this->_idTopic, $topicOwner) = $smcFunc['db_fetch_row']($request); |
|
217 | + if ($smcFunc['db_num_rows']($request) == 1) { |
|
218 | + list ($this->_idTopic, $topicOwner) = $smcFunc['db_fetch_row']($request); |
|
219 | + } |
|
214 | 220 | |
215 | 221 | $smcFunc['db_free_result']($request); |
216 | - if (empty($this->_idTopic)) |
|
217 | - return $this->_error = 'cannot_'; |
|
222 | + if (empty($this->_idTopic)) { |
|
223 | + return $this->_error = 'cannot_'; |
|
224 | + } |
|
218 | 225 | |
219 | 226 | // So we know what topic it's in and more importantly we know the user can see it. |
220 | 227 | // If we're not viewing, we need some info set up. |
@@ -224,9 +231,7 @@ discard block |
||
224 | 231 | $this->_validLikes['can_see'] = allowedTo('likes_view') ? true : 'cannot_view_likes'; |
225 | 232 | |
226 | 233 | $this->_validLikes['can_like'] = ($this->_user['id'] == $topicOwner ? 'cannot_like_content' : (allowedTo('likes_like') ? true : 'cannot_like_content')); |
227 | - } |
|
228 | - |
|
229 | - else |
|
234 | + } else |
|
230 | 235 | { |
231 | 236 | // Modders: This will give you whatever the user offers up in terms of liking, e.g. $this->_type=msg, $this->_content=1 |
232 | 237 | // When you hook this, check $this->_type first. If it is not something your mod worries about, return false. |
@@ -244,8 +249,9 @@ discard block |
||
244 | 249 | if ($result !== false) |
245 | 250 | { |
246 | 251 | // Match the type with what we already have. |
247 | - if (!isset($result['type']) || $result['type'] != $this->_type) |
|
248 | - return $this->_error = 'not_valid_like_type'; |
|
252 | + if (!isset($result['type']) || $result['type'] != $this->_type) { |
|
253 | + return $this->_error = 'not_valid_like_type'; |
|
254 | + } |
|
249 | 255 | |
250 | 256 | // Fill out the rest. |
251 | 257 | $this->_type = $result['type']; |
@@ -256,17 +262,20 @@ discard block |
||
256 | 262 | } |
257 | 263 | } |
258 | 264 | |
259 | - if (!$found) |
|
260 | - return $this->_error = 'cannot_'; |
|
265 | + if (!$found) { |
|
266 | + return $this->_error = 'cannot_'; |
|
267 | + } |
|
261 | 268 | } |
262 | 269 | |
263 | 270 | // Does the user can see this? |
264 | - if (isset($this->_validLikes['can_see']) && is_string($this->_validLikes['can_see'])) |
|
265 | - return $this->_error = $this->_validLikes['can_see']; |
|
271 | + if (isset($this->_validLikes['can_see']) && is_string($this->_validLikes['can_see'])) { |
|
272 | + return $this->_error = $this->_validLikes['can_see']; |
|
273 | + } |
|
266 | 274 | |
267 | 275 | // Does the user can like this? Viewing a list of likes doesn't require this permission. |
268 | - if ($this->_sa != 'view' && isset($this->_validLikes['can_like']) && is_string($this->_validLikes['can_like'])) |
|
269 | - return $this->_error = $this->_validLikes['can_like']; |
|
276 | + if ($this->_sa != 'view' && isset($this->_validLikes['can_like']) && is_string($this->_validLikes['can_like'])) { |
|
277 | + return $this->_error = $this->_validLikes['can_like']; |
|
278 | + } |
|
270 | 279 | } |
271 | 280 | |
272 | 281 | /** |
@@ -291,8 +300,9 @@ discard block |
||
291 | 300 | ); |
292 | 301 | |
293 | 302 | // Are we calling this directly? if so, set a proper data for the response. Do note that __METHOD__ returns both the class name and the function name. |
294 | - if ($this->_sa == __FUNCTION__) |
|
295 | - $this->_data = __FUNCTION__; |
|
303 | + if ($this->_sa == __FUNCTION__) { |
|
304 | + $this->_data = __FUNCTION__; |
|
305 | + } |
|
296 | 306 | } |
297 | 307 | |
298 | 308 | /** |
@@ -322,8 +332,8 @@ discard block |
||
322 | 332 | |
323 | 333 | // Add a background task to process sending alerts. |
324 | 334 | // Mod author, you can add your own background task for your own custom like event using the "integrate_issue_like" hook or your callback, both are immediately called after this. |
325 | - if ($this->_type == 'msg') |
|
326 | - $smcFunc['db_insert']('insert', |
|
335 | + if ($this->_type == 'msg') { |
|
336 | + $smcFunc['db_insert']('insert', |
|
327 | 337 | '{db_prefix}background_tasks', |
328 | 338 | array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
329 | 339 | array('$sourcedir/tasks/Likes-Notify.php', 'Likes_Notify_Background', json_encode(array( |
@@ -335,10 +345,12 @@ discard block |
||
335 | 345 | )), 0), |
336 | 346 | array('id_task') |
337 | 347 | ); |
348 | + } |
|
338 | 349 | |
339 | 350 | // Are we calling this directly? if so, set a proper data for the response. Do note that __METHOD__ returns both the class name and the function name. |
340 | - if ($this->_sa == __FUNCTION__) |
|
341 | - $this->_data = __FUNCTION__; |
|
351 | + if ($this->_sa == __FUNCTION__) { |
|
352 | + $this->_data = __FUNCTION__; |
|
353 | + } |
|
342 | 354 | } |
343 | 355 | |
344 | 356 | /** |
@@ -364,8 +376,9 @@ discard block |
||
364 | 376 | $smcFunc['db_free_result']($request); |
365 | 377 | |
366 | 378 | // If you want to call this directly, fill out _data property too. |
367 | - if ($this->_sa == __FUNCTION__) |
|
368 | - $this->_data = $this->_numLikes; |
|
379 | + if ($this->_sa == __FUNCTION__) { |
|
380 | + $this->_data = $this->_numLikes; |
|
381 | + } |
|
369 | 382 | } |
370 | 383 | |
371 | 384 | /** |
@@ -378,8 +391,9 @@ discard block |
||
378 | 391 | global $smcFunc; |
379 | 392 | |
380 | 393 | // Safety first! |
381 | - if (empty($this->_type) || empty($this->_content)) |
|
382 | - return $this->_error = 'cannot_'; |
|
394 | + if (empty($this->_type) || empty($this->_content)) { |
|
395 | + return $this->_error = 'cannot_'; |
|
396 | + } |
|
383 | 397 | |
384 | 398 | // Do we already like this? |
385 | 399 | $request = $smcFunc['db_query']('', ' |
@@ -397,26 +411,28 @@ discard block |
||
397 | 411 | $this->_alreadyLiked = (bool) $smcFunc['db_num_rows']($request) != 0; |
398 | 412 | $smcFunc['db_free_result']($request); |
399 | 413 | |
400 | - if ($this->_alreadyLiked) |
|
401 | - $this->delete(); |
|
402 | - |
|
403 | - else |
|
404 | - $this->insert(); |
|
414 | + if ($this->_alreadyLiked) { |
|
415 | + $this->delete(); |
|
416 | + } else { |
|
417 | + $this->insert(); |
|
418 | + } |
|
405 | 419 | |
406 | 420 | // Now, how many people like this content now? We *could* just +1 / -1 the relevant container but that has proven to become unstable. |
407 | 421 | $this->_count(); |
408 | 422 | |
409 | 423 | // Update the likes count for messages. |
410 | - if ($this->_type == 'msg') |
|
411 | - $this->msgIssueLike(); |
|
424 | + if ($this->_type == 'msg') { |
|
425 | + $this->msgIssueLike(); |
|
426 | + } |
|
412 | 427 | |
413 | 428 | // Any callbacks? |
414 | 429 | elseif (!empty($this->_validLikes['callback'])) |
415 | 430 | { |
416 | 431 | $call = call_helper($this->_validLikes['callback'], true); |
417 | 432 | |
418 | - if (!empty($call)) |
|
419 | - call_user_func_array($call, array($this)); |
|
433 | + if (!empty($call)) { |
|
434 | + call_user_func_array($call, array($this)); |
|
435 | + } |
|
420 | 436 | } |
421 | 437 | |
422 | 438 | // Sometimes there might be other things that need updating after we do this like. |
@@ -425,8 +441,9 @@ discard block |
||
425 | 441 | // Now some clean up. This is provided here for any like handlers that want to do any cache flushing. |
426 | 442 | // This way a like handler doesn't need to explicitly declare anything in integrate_issue_like, but do so |
427 | 443 | // in integrate_valid_likes where it absolutely has to exist. |
428 | - if (!empty($this->_validLikes['flush_cache'])) |
|
429 | - cache_put_data($this->_validLikes['flush_cache'], null); |
|
444 | + if (!empty($this->_validLikes['flush_cache'])) { |
|
445 | + cache_put_data($this->_validLikes['flush_cache'], null); |
|
446 | + } |
|
430 | 447 | |
431 | 448 | // All done, start building the data to pass as response. |
432 | 449 | $this->_data = array( |
@@ -450,8 +467,9 @@ discard block |
||
450 | 467 | { |
451 | 468 | global $smcFunc; |
452 | 469 | |
453 | - if ($this->_type !== 'msg') |
|
454 | - return; |
|
470 | + if ($this->_type !== 'msg') { |
|
471 | + return; |
|
472 | + } |
|
455 | 473 | |
456 | 474 | $smcFunc['db_query']('', ' |
457 | 475 | UPDATE {db_prefix}messages |
@@ -492,8 +510,9 @@ discard block |
||
492 | 510 | 'like_type' => $this->_type, |
493 | 511 | ) |
494 | 512 | ); |
495 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
496 | - $context['likers'][$row['id_member']] = array('timestamp' => $row['like_time']); |
|
513 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
514 | + $context['likers'][$row['id_member']] = array('timestamp' => $row['like_time']); |
|
515 | + } |
|
497 | 516 | |
498 | 517 | // Now to get member data, including avatars and so on. |
499 | 518 | $members = array_keys($context['likers']); |
@@ -501,8 +520,9 @@ discard block |
||
501 | 520 | if (count($loaded) != count($members)) |
502 | 521 | { |
503 | 522 | $members = array_diff($members, $loaded); |
504 | - foreach ($members as $not_loaded) |
|
505 | - unset ($context['likers'][$not_loaded]); |
|
523 | + foreach ($members as $not_loaded) { |
|
524 | + unset ($context['likers'][$not_loaded]); |
|
525 | + } |
|
506 | 526 | } |
507 | 527 | |
508 | 528 | foreach ($context['likers'] as $liker => $dummy) |
@@ -544,12 +564,14 @@ discard block |
||
544 | 564 | global $context, $txt; |
545 | 565 | |
546 | 566 | // Don't do anything if someone else has already take care of the response. |
547 | - if (!$this->_setResponse) |
|
548 | - return; |
|
567 | + if (!$this->_setResponse) { |
|
568 | + return; |
|
569 | + } |
|
549 | 570 | |
550 | 571 | // Want a json response huh? |
551 | - if ($this->_validLikes['json']) |
|
552 | - return $this->jsonResponse(); |
|
572 | + if ($this->_validLikes['json']) { |
|
573 | + return $this->jsonResponse(); |
|
574 | + } |
|
553 | 575 | |
554 | 576 | // Set everything up for display. |
555 | 577 | loadTemplate('Likes'); |
@@ -559,8 +581,9 @@ discard block |
||
559 | 581 | if ($this->_error) |
560 | 582 | { |
561 | 583 | // If this is a generic error, set it up good. |
562 | - if ($this->_error == 'cannot_') |
|
563 | - $this->_error = $this->_sa == 'view' ? 'cannot_view_likes' : 'cannot_like_content'; |
|
584 | + if ($this->_error == 'cannot_') { |
|
585 | + $this->_error = $this->_sa == 'view' ? 'cannot_view_likes' : 'cannot_like_content'; |
|
586 | + } |
|
564 | 587 | |
565 | 588 | // Is this request coming from an ajax call? |
566 | 589 | if ($this->_js) |
@@ -570,8 +593,9 @@ discard block |
||
570 | 593 | } |
571 | 594 | |
572 | 595 | // Nope? then just do a redirect to whatever URL was provided. |
573 | - else |
|
574 | - redirectexit(!empty($this->_validLikes['redirect']) ? $this->_validLikes['redirect'] . ';error=' . $this->_error : ''); |
|
596 | + else { |
|
597 | + redirectexit(!empty($this->_validLikes['redirect']) ? $this->_validLikes['redirect'] . ';error=' . $this->_error : ''); |
|
598 | + } |
|
575 | 599 | |
576 | 600 | return; |
577 | 601 | } |
@@ -580,8 +604,9 @@ discard block |
||
580 | 604 | else |
581 | 605 | { |
582 | 606 | // Not an ajax request so send the user back to the previous location or the main page. |
583 | - if (!$this->_js) |
|
584 | - redirectexit(!empty($this->_validLikes['redirect']) ? $this->_validLikes['redirect'] : ''); |
|
607 | + if (!$this->_js) { |
|
608 | + redirectexit(!empty($this->_validLikes['redirect']) ? $this->_validLikes['redirect'] : ''); |
|
609 | + } |
|
585 | 610 | |
586 | 611 | // These fine gentlemen all share the same template. |
587 | 612 | $generic = array('delete', 'insert', '_count'); |
@@ -612,8 +637,9 @@ discard block |
||
612 | 637 | // If there is an error, send it. |
613 | 638 | if ($this->_error) |
614 | 639 | { |
615 | - if ($this->_error == 'cannot_') |
|
616 | - $this->_error = $this->_sa == 'view' ? 'cannot_view_likes' : 'cannot_like_content'; |
|
640 | + if ($this->_error == 'cannot_') { |
|
641 | + $this->_error = $this->_sa == 'view' ? 'cannot_view_likes' : 'cannot_like_content'; |
|
642 | + } |
|
617 | 643 | |
618 | 644 | $print['error'] = $this->_error; |
619 | 645 | } |
@@ -649,33 +675,36 @@ discard block |
||
649 | 675 | <body style="background-color: #444455; color: white; font-style: italic; font-family: serif;"> |
650 | 676 | <div style="margin-top: 12%; font-size: 1.1em; line-height: 1.4; text-align: center;">'; |
651 | 677 | |
652 | - if (!isset($_GET['verse']) || ($_GET['verse'] != '2:18' && $_GET['verse'] != '22:1-2')) |
|
653 | - $_GET['verse'] = '4:16'; |
|
678 | + if (!isset($_GET['verse']) || ($_GET['verse'] != '2:18' && $_GET['verse'] != '22:1-2')) { |
|
679 | + $_GET['verse'] = '4:16'; |
|
680 | + } |
|
654 | 681 | |
655 | - if ($_GET['verse'] == '2:18') |
|
656 | - echo ' |
|
682 | + if ($_GET['verse'] == '2:18') { |
|
683 | + echo ' |
|
657 | 684 | Woe, it was that his name wasn\'t <em>known</em>, that he came in mystery, and was recognized by none. And it became to be in those days <em>something</em>. Something not yet <em id="unknown" name="[Unknown]">unknown</em> to mankind. And thus what was to be known the <em>secret project</em> began into its existence. Henceforth the opposition was only <em>weary</em> and <em>fearful</em>, for now their match was at arms against them.'; |
658 | - elseif ($_GET['verse'] == '4:16') |
|
659 | - echo ' |
|
685 | + } elseif ($_GET['verse'] == '4:16') { |
|
686 | + echo ' |
|
660 | 687 | And it came to pass that the <em>unbelievers</em> dwindled in number and saw rise of many <em>proselytizers</em>, and the opposition found fear in the face of the <em>x</em> and the <em>j</em> while those who stood with the <em>something</em> grew stronger and came together. Still, this was only the <em>beginning</em>, and what lay in the future was <em id="unknown" name="[Unknown]">unknown</em> to all, even those on the right side.'; |
661 | - elseif ($_GET['verse'] == '22:1-2') |
|
662 | - echo ' |
|
688 | + } elseif ($_GET['verse'] == '22:1-2') { |
|
689 | + echo ' |
|
663 | 690 | <p>Now <em>behold</em>, that which was once the secret project was <em id="unknown" name="[Unknown]">unknown</em> no longer. Alas, it needed more than <em>only one</em>, but yet even thought otherwise. It became that the opposition <em>rumored</em> and lied, but still to no avail. Their match, though not <em>perfect</em>, had them outdone.</p> |
664 | 691 | <p style="margin: 2ex 1ex 0 1ex; font-size: 1.05em; line-height: 1.5; text-align: center;">Let it continue. <em>The end</em>.</p>'; |
692 | + } |
|
665 | 693 | |
666 | 694 | echo ' |
667 | 695 | </div> |
668 | 696 | <div style="margin-top: 2ex; font-size: 2em; text-align: right;">'; |
669 | 697 | |
670 | - if ($_GET['verse'] == '2:18') |
|
671 | - echo ' |
|
698 | + if ($_GET['verse'] == '2:18') { |
|
699 | + echo ' |
|
672 | 700 | from <span style="font-family: Georgia, serif;"><strong><a href="', $scripturl, '?action=about:unknown;verse=4:16" style="color: white; text-decoration: none; cursor: text;">The Book of Unknown</a></strong>, 2:18</span>'; |
673 | - elseif ($_GET['verse'] == '4:16') |
|
674 | - echo ' |
|
701 | + } elseif ($_GET['verse'] == '4:16') { |
|
702 | + echo ' |
|
675 | 703 | from <span style="font-family: Georgia, serif;"><strong><a href="', $scripturl, '?action=about:unknown;verse=22:1-2" style="color: white; text-decoration: none; cursor: text;">The Book of Unknown</a></strong>, 4:16</span>'; |
676 | - elseif ($_GET['verse'] == '22:1-2') |
|
677 | - echo ' |
|
704 | + } elseif ($_GET['verse'] == '22:1-2') { |
|
705 | + echo ' |
|
678 | 706 | from <span style="font-family: Georgia, serif;"><strong>The Book of Unknown</strong>, 22:1-2</span>'; |
707 | + } |
|
679 | 708 | |
680 | 709 | echo ' |
681 | 710 | </div> |
@@ -17,8 +17,9 @@ discard block |
||
17 | 17 | * @version 2.1 Beta 3 |
18 | 18 | */ |
19 | 19 | |
20 | -if (!defined('SMF')) |
|
20 | +if (!defined('SMF')) { |
|
21 | 21 | die('No direct access...'); |
22 | +} |
|
22 | 23 | |
23 | 24 | /** |
24 | 25 | * Attempt to start the session, unless it already has been. |
@@ -38,8 +39,9 @@ discard block |
||
38 | 39 | { |
39 | 40 | $parsed_url = parse_url($boardurl); |
40 | 41 | |
41 | - if (preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1) |
|
42 | - @ini_set('session.cookie_domain', '.' . $parts[1]); |
|
42 | + if (preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1) { |
|
43 | + @ini_set('session.cookie_domain', '.' . $parts[1]); |
|
44 | + } |
|
43 | 45 | } |
44 | 46 | // @todo Set the session cookie path? |
45 | 47 | |
@@ -47,8 +49,9 @@ discard block |
||
47 | 49 | if ((ini_get('session.auto_start') == 1 && !empty($modSettings['databaseSession_enable'])) || session_id() == '') |
48 | 50 | { |
49 | 51 | // Attempt to end the already-started session. |
50 | - if (ini_get('session.auto_start') == 1) |
|
51 | - session_write_close(); |
|
52 | + if (ini_get('session.auto_start') == 1) { |
|
53 | + session_write_close(); |
|
54 | + } |
|
52 | 55 | |
53 | 56 | // This is here to stop people from using bad junky PHPSESSIDs. |
54 | 57 | if (isset($_REQUEST[session_name()]) && preg_match('~^[A-Za-z0-9,-]{16,64}$~', $_REQUEST[session_name()]) == 0 && !isset($_COOKIE[session_name()])) |
@@ -65,19 +68,21 @@ discard block |
||
65 | 68 | @ini_set('session.serialize_handler', 'php'); |
66 | 69 | session_set_save_handler('sessionOpen', 'sessionClose', 'sessionRead', 'sessionWrite', 'sessionDestroy', 'sessionGC'); |
67 | 70 | @ini_set('session.gc_probability', '1'); |
71 | + } elseif (ini_get('session.gc_maxlifetime') <= 1440 && !empty($modSettings['databaseSession_lifetime'])) { |
|
72 | + @ini_set('session.gc_maxlifetime', max($modSettings['databaseSession_lifetime'], 60)); |
|
68 | 73 | } |
69 | - elseif (ini_get('session.gc_maxlifetime') <= 1440 && !empty($modSettings['databaseSession_lifetime'])) |
|
70 | - @ini_set('session.gc_maxlifetime', max($modSettings['databaseSession_lifetime'], 60)); |
|
71 | 74 | |
72 | 75 | // Use cache setting sessions? |
73 | - if (empty($modSettings['databaseSession_enable']) && !empty($modSettings['cache_enable']) && php_sapi_name() != 'cli') |
|
74 | - call_integration_hook('integrate_session_handlers'); |
|
76 | + if (empty($modSettings['databaseSession_enable']) && !empty($modSettings['cache_enable']) && php_sapi_name() != 'cli') { |
|
77 | + call_integration_hook('integrate_session_handlers'); |
|
78 | + } |
|
75 | 79 | |
76 | 80 | session_start(); |
77 | 81 | |
78 | 82 | // Change it so the cache settings are a little looser than default. |
79 | - if (!empty($modSettings['databaseSession_loose'])) |
|
80 | - header('Cache-Control: private'); |
|
83 | + if (!empty($modSettings['databaseSession_loose'])) { |
|
84 | + header('Cache-Control: private'); |
|
85 | + } |
|
81 | 86 | } |
82 | 87 | |
83 | 88 | // Set the randomly generated code. |
@@ -123,8 +128,9 @@ discard block |
||
123 | 128 | { |
124 | 129 | global $smcFunc; |
125 | 130 | |
126 | - if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) |
|
127 | - return ''; |
|
131 | + if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) { |
|
132 | + return ''; |
|
133 | + } |
|
128 | 134 | |
129 | 135 | // Look for it in the database. |
130 | 136 | $result = $smcFunc['db_query']('', ' |
@@ -153,8 +159,9 @@ discard block |
||
153 | 159 | { |
154 | 160 | global $smcFunc; |
155 | 161 | |
156 | - if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) |
|
157 | - return false; |
|
162 | + if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) { |
|
163 | + return false; |
|
164 | + } |
|
158 | 165 | |
159 | 166 | // First try to update an existing row... |
160 | 167 | $smcFunc['db_query']('', ' |
@@ -169,13 +176,14 @@ discard block |
||
169 | 176 | ); |
170 | 177 | |
171 | 178 | // If that didn't work, try inserting a new one. |
172 | - if ($smcFunc['db_affected_rows']() == 0) |
|
173 | - $smcFunc['db_insert']('ignore', |
|
179 | + if ($smcFunc['db_affected_rows']() == 0) { |
|
180 | + $smcFunc['db_insert']('ignore', |
|
174 | 181 | '{db_prefix}sessions', |
175 | 182 | array('session_id' => 'string', 'data' => 'string', 'last_update' => 'int'), |
176 | 183 | array($session_id, $data, time()), |
177 | 184 | array('session_id') |
178 | 185 | ); |
186 | + } |
|
179 | 187 | |
180 | 188 | return ($smcFunc['db_affected_rows']() == 0 ? false : true); |
181 | 189 | } |
@@ -190,8 +198,9 @@ discard block |
||
190 | 198 | { |
191 | 199 | global $smcFunc; |
192 | 200 | |
193 | - if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) |
|
194 | - return false; |
|
201 | + if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) { |
|
202 | + return false; |
|
203 | + } |
|
195 | 204 | |
196 | 205 | // Just delete the row... |
197 | 206 | $smcFunc['db_query']('', ' |
@@ -217,8 +226,9 @@ discard block |
||
217 | 226 | global $modSettings, $smcFunc; |
218 | 227 | |
219 | 228 | // Just set to the default or lower? Ignore it for a higher value. (hopefully) |
220 | - if (!empty($modSettings['databaseSession_lifetime']) && ($max_lifetime <= 1440 || $modSettings['databaseSession_lifetime'] > $max_lifetime)) |
|
221 | - $max_lifetime = max($modSettings['databaseSession_lifetime'], 60); |
|
229 | + if (!empty($modSettings['databaseSession_lifetime']) && ($max_lifetime <= 1440 || $modSettings['databaseSession_lifetime'] > $max_lifetime)) { |
|
230 | + $max_lifetime = max($modSettings['databaseSession_lifetime'], 60); |
|
231 | + } |
|
222 | 232 | |
223 | 233 | // Clean up after yerself ;). |
224 | 234 | $smcFunc['db_query']('', ' |
@@ -14,8 +14,9 @@ discard block |
||
14 | 14 | * @version 2.1 Beta 3 |
15 | 15 | */ |
16 | 16 | |
17 | -if (!defined('SMF')) |
|
17 | +if (!defined('SMF')) { |
|
18 | 18 | die('No direct access...'); |
19 | +} |
|
19 | 20 | |
20 | 21 | /** |
21 | 22 | * This function allows to move a topic, making sure to ask the moderator |
@@ -32,8 +33,9 @@ discard block |
||
32 | 33 | { |
33 | 34 | global $txt, $board, $topic, $user_info, $context, $language, $scripturl, $smcFunc, $modSettings, $sourcedir; |
34 | 35 | |
35 | - if (empty($topic)) |
|
36 | - fatal_lang_error('no_access', false); |
|
36 | + if (empty($topic)) { |
|
37 | + fatal_lang_error('no_access', false); |
|
38 | + } |
|
37 | 39 | |
38 | 40 | $request = $smcFunc['db_query']('', ' |
39 | 41 | SELECT t.id_member_started, ms.subject, t.approved |
@@ -49,8 +51,9 @@ discard block |
||
49 | 51 | $smcFunc['db_free_result']($request); |
50 | 52 | |
51 | 53 | // Can they see it - if not approved? |
52 | - if ($modSettings['postmod_active'] && !$context['is_approved']) |
|
53 | - isAllowedTo('approve_posts'); |
|
54 | + if ($modSettings['postmod_active'] && !$context['is_approved']) { |
|
55 | + isAllowedTo('approve_posts'); |
|
56 | + } |
|
54 | 57 | |
55 | 58 | // Permission check! |
56 | 59 | // @todo |
@@ -59,9 +62,9 @@ discard block |
||
59 | 62 | if ($id_member_started == $user_info['id']) |
60 | 63 | { |
61 | 64 | isAllowedTo('move_own'); |
65 | + } else { |
|
66 | + isAllowedTo('move_any'); |
|
62 | 67 | } |
63 | - else |
|
64 | - isAllowedTo('move_any'); |
|
65 | 68 | } |
66 | 69 | |
67 | 70 | $context['move_any'] = $user_info['is_admin'] || $modSettings['topic_move_any']; |
@@ -83,11 +86,13 @@ discard block |
||
83 | 86 | 'not_redirection' => true, |
84 | 87 | ); |
85 | 88 | |
86 | - if (!empty($_SESSION['move_to_topic']) && $_SESSION['move_to_topic'] != $board) |
|
87 | - $options['selected_board'] = $_SESSION['move_to_topic']; |
|
89 | + if (!empty($_SESSION['move_to_topic']) && $_SESSION['move_to_topic'] != $board) { |
|
90 | + $options['selected_board'] = $_SESSION['move_to_topic']; |
|
91 | + } |
|
88 | 92 | |
89 | - if (!$context['move_any']) |
|
90 | - $options['included_boards'] = $boards; |
|
93 | + if (!$context['move_any']) { |
|
94 | + $options['included_boards'] = $boards; |
|
95 | + } |
|
91 | 96 | |
92 | 97 | require_once($sourcedir . '/Subs-MessageIndex.php'); |
93 | 98 | $context['categories'] = getBoardList($options); |
@@ -138,12 +143,14 @@ discard block |
||
138 | 143 | global $txt, $board, $topic, $scripturl, $sourcedir, $modSettings, $context; |
139 | 144 | global $board, $language, $user_info, $smcFunc; |
140 | 145 | |
141 | - if (empty($topic)) |
|
142 | - fatal_lang_error('no_access', false); |
|
146 | + if (empty($topic)) { |
|
147 | + fatal_lang_error('no_access', false); |
|
148 | + } |
|
143 | 149 | |
144 | 150 | // You can't choose to have a redirection topic and use an empty reason. |
145 | - if (isset($_POST['postRedirect']) && (!isset($_POST['reason']) || trim($_POST['reason']) == '')) |
|
146 | - fatal_lang_error('movetopic_no_reason', false); |
|
151 | + if (isset($_POST['postRedirect']) && (!isset($_POST['reason']) || trim($_POST['reason']) == '')) { |
|
152 | + fatal_lang_error('movetopic_no_reason', false); |
|
153 | + } |
|
147 | 154 | |
148 | 155 | moveTopicConcurrence(); |
149 | 156 | |
@@ -163,16 +170,18 @@ discard block |
||
163 | 170 | $smcFunc['db_free_result']($request); |
164 | 171 | |
165 | 172 | // Can they see it? |
166 | - if (!$context['is_approved']) |
|
167 | - isAllowedTo('approve_posts'); |
|
173 | + if (!$context['is_approved']) { |
|
174 | + isAllowedTo('approve_posts'); |
|
175 | + } |
|
168 | 176 | |
169 | 177 | // Can they move topics on this board? |
170 | 178 | if (!allowedTo('move_any')) |
171 | 179 | { |
172 | - if ($id_member_started == $user_info['id']) |
|
173 | - isAllowedTo('move_own'); |
|
174 | - else |
|
175 | - isAllowedTo('move_any'); |
|
180 | + if ($id_member_started == $user_info['id']) { |
|
181 | + isAllowedTo('move_own'); |
|
182 | + } else { |
|
183 | + isAllowedTo('move_any'); |
|
184 | + } |
|
176 | 185 | } |
177 | 186 | |
178 | 187 | checkSession(); |
@@ -197,8 +206,9 @@ discard block |
||
197 | 206 | 'blank_redirect' => '', |
198 | 207 | ) |
199 | 208 | ); |
200 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
201 | - fatal_lang_error('no_board'); |
|
209 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
210 | + fatal_lang_error('no_board'); |
|
211 | + } |
|
202 | 212 | list ($pcounter, $board_name, $subject) = $smcFunc['db_fetch_row']($request); |
203 | 213 | $smcFunc['db_free_result']($request); |
204 | 214 | |
@@ -210,8 +220,9 @@ discard block |
||
210 | 220 | { |
211 | 221 | $_POST['custom_subject'] = strtr($smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['custom_subject'])), array("\r" => '', "\n" => '', "\t" => '')); |
212 | 222 | // Keep checking the length. |
213 | - if ($smcFunc['strlen']($_POST['custom_subject']) > 100) |
|
214 | - $_POST['custom_subject'] = $smcFunc['substr']($_POST['custom_subject'], 0, 100); |
|
223 | + if ($smcFunc['strlen']($_POST['custom_subject']) > 100) { |
|
224 | + $_POST['custom_subject'] = $smcFunc['substr']($_POST['custom_subject'], 0, 100); |
|
225 | + } |
|
215 | 226 | |
216 | 227 | // If it's still valid move onwards and upwards. |
217 | 228 | if ($_POST['custom_subject'] != '') |
@@ -221,9 +232,9 @@ discard block |
||
221 | 232 | // Get a response prefix, but in the forum's default language. |
222 | 233 | if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix'))) |
223 | 234 | { |
224 | - if ($language === $user_info['language']) |
|
225 | - $context['response_prefix'] = $txt['response_prefix']; |
|
226 | - else |
|
235 | + if ($language === $user_info['language']) { |
|
236 | + $context['response_prefix'] = $txt['response_prefix']; |
|
237 | + } else |
|
227 | 238 | { |
228 | 239 | loadLanguage('index', $language, false); |
229 | 240 | $context['response_prefix'] = $txt['response_prefix']; |
@@ -263,8 +274,9 @@ discard block |
||
263 | 274 | if (isset($_POST['postRedirect'])) |
264 | 275 | { |
265 | 276 | // Should be in the boardwide language. |
266 | - if ($user_info['language'] != $language) |
|
267 | - loadLanguage('index', $language); |
|
277 | + if ($user_info['language'] != $language) { |
|
278 | + loadLanguage('index', $language); |
|
279 | + } |
|
268 | 280 | |
269 | 281 | $_POST['reason'] = $smcFunc['htmlspecialchars']($_POST['reason'], ENT_QUOTES); |
270 | 282 | preparsecode($_POST['reason']); |
@@ -328,8 +340,9 @@ discard block |
||
328 | 340 | $posters = array(); |
329 | 341 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
330 | 342 | { |
331 | - if (!isset($posters[$row['id_member']])) |
|
332 | - $posters[$row['id_member']] = 0; |
|
343 | + if (!isset($posters[$row['id_member']])) { |
|
344 | + $posters[$row['id_member']] = 0; |
|
345 | + } |
|
333 | 346 | |
334 | 347 | $posters[$row['id_member']]++; |
335 | 348 | } |
@@ -338,11 +351,13 @@ discard block |
||
338 | 351 | foreach ($posters as $id_member => $posts) |
339 | 352 | { |
340 | 353 | // The board we're moving from counted posts, but not to. |
341 | - if (empty($pcounter_from)) |
|
342 | - updateMemberData($id_member, array('posts' => 'posts - ' . $posts)); |
|
354 | + if (empty($pcounter_from)) { |
|
355 | + updateMemberData($id_member, array('posts' => 'posts - ' . $posts)); |
|
356 | + } |
|
343 | 357 | // The reverse: from didn't, to did. |
344 | - else |
|
345 | - updateMemberData($id_member, array('posts' => 'posts + ' . $posts)); |
|
358 | + else { |
|
359 | + updateMemberData($id_member, array('posts' => 'posts + ' . $posts)); |
|
360 | + } |
|
346 | 361 | } |
347 | 362 | } |
348 | 363 | |
@@ -350,17 +365,19 @@ discard block |
||
350 | 365 | moveTopics($topic, $_POST['toboard']); |
351 | 366 | |
352 | 367 | // Log that they moved this topic. |
353 | - if (!allowedTo('move_own') || $id_member_started != $user_info['id']) |
|
354 | - logAction('move', array('topic' => $topic, 'board_from' => $board, 'board_to' => $_POST['toboard'])); |
|
368 | + if (!allowedTo('move_own') || $id_member_started != $user_info['id']) { |
|
369 | + logAction('move', array('topic' => $topic, 'board_from' => $board, 'board_to' => $_POST['toboard'])); |
|
370 | + } |
|
355 | 371 | // Notify people that this topic has been moved? |
356 | 372 | sendNotifications($topic, 'move'); |
357 | 373 | |
358 | 374 | // Why not go back to the original board in case they want to keep moving? |
359 | - if (!isset($_REQUEST['goback'])) |
|
360 | - redirectexit('board=' . $board . '.0'); |
|
361 | - else |
|
362 | - redirectexit('topic=' . $topic . '.0'); |
|
363 | -} |
|
375 | + if (!isset($_REQUEST['goback'])) { |
|
376 | + redirectexit('board=' . $board . '.0'); |
|
377 | + } else { |
|
378 | + redirectexit('topic=' . $topic . '.0'); |
|
379 | + } |
|
380 | + } |
|
364 | 381 | |
365 | 382 | /** |
366 | 383 | * Moves one or more topics to a specific board. (doesn't check permissions.) |
@@ -376,18 +393,21 @@ discard block |
||
376 | 393 | global $sourcedir, $user_info, $modSettings, $smcFunc; |
377 | 394 | |
378 | 395 | // Empty array? |
379 | - if (empty($topics)) |
|
380 | - return; |
|
396 | + if (empty($topics)) { |
|
397 | + return; |
|
398 | + } |
|
381 | 399 | |
382 | 400 | // Only a single topic. |
383 | - if (is_numeric($topics)) |
|
384 | - $topics = array($topics); |
|
401 | + if (is_numeric($topics)) { |
|
402 | + $topics = array($topics); |
|
403 | + } |
|
385 | 404 | |
386 | 405 | $fromBoards = array(); |
387 | 406 | |
388 | 407 | // Destination board empty or equal to 0? |
389 | - if (empty($toBoard)) |
|
390 | - return; |
|
408 | + if (empty($toBoard)) { |
|
409 | + return; |
|
410 | + } |
|
391 | 411 | |
392 | 412 | // Are we moving to the recycle board? |
393 | 413 | $isRecycleDest = !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] == $toBoard; |
@@ -395,8 +415,9 @@ discard block |
||
395 | 415 | // Callback for search APIs to do their thing |
396 | 416 | require_once($sourcedir . '/Search.php'); |
397 | 417 | $searchAPI = findSearchAPI(); |
398 | - if ($searchAPI->supportsMethod('topicsMoved')) |
|
399 | - $searchAPI->topicsMoved($topics, $toBoard); |
|
418 | + if ($searchAPI->supportsMethod('topicsMoved')) { |
|
419 | + $searchAPI->topicsMoved($topics, $toBoard); |
|
420 | + } |
|
400 | 421 | |
401 | 422 | // Determine the source boards... |
402 | 423 | $request = $smcFunc['db_query']('', ' |
@@ -410,8 +431,9 @@ discard block |
||
410 | 431 | ) |
411 | 432 | ); |
412 | 433 | // Num of rows = 0 -> no topics found. Num of rows > 1 -> topics are on multiple boards. |
413 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
414 | - return; |
|
434 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
435 | + return; |
|
436 | + } |
|
415 | 437 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
416 | 438 | { |
417 | 439 | if (!isset($fromBoards[$row['id_board']]['num_posts'])) |
@@ -429,10 +451,11 @@ discard block |
||
429 | 451 | $fromBoards[$row['id_board']]['unapproved_posts'] += $row['unapproved_posts']; |
430 | 452 | |
431 | 453 | // Add the topics to the right type. |
432 | - if ($row['approved']) |
|
433 | - $fromBoards[$row['id_board']]['num_topics'] += $row['num_topics']; |
|
434 | - else |
|
435 | - $fromBoards[$row['id_board']]['unapproved_topics'] += $row['num_topics']; |
|
454 | + if ($row['approved']) { |
|
455 | + $fromBoards[$row['id_board']]['num_topics'] += $row['num_topics']; |
|
456 | + } else { |
|
457 | + $fromBoards[$row['id_board']]['unapproved_topics'] += $row['num_topics']; |
|
458 | + } |
|
436 | 459 | } |
437 | 460 | $smcFunc['db_free_result']($request); |
438 | 461 | |
@@ -558,13 +581,14 @@ discard block |
||
558 | 581 | ) |
559 | 582 | ); |
560 | 583 | $approval_msgs = array(); |
561 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
562 | - $approval_msgs[] = $row['id_msg']; |
|
584 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
585 | + $approval_msgs[] = $row['id_msg']; |
|
586 | + } |
|
563 | 587 | $smcFunc['db_free_result']($request); |
564 | 588 | |
565 | 589 | // Empty the approval queue for these, as we're going to approve them next. |
566 | - if (!empty($approval_msgs)) |
|
567 | - $smcFunc['db_query']('', ' |
|
590 | + if (!empty($approval_msgs)) { |
|
591 | + $smcFunc['db_query']('', ' |
|
568 | 592 | DELETE FROM {db_prefix}approval_queue |
569 | 593 | WHERE id_msg IN ({array_int:message_list}) |
570 | 594 | AND id_attach = {int:id_attach}', |
@@ -573,6 +597,7 @@ discard block |
||
573 | 597 | 'id_attach' => 0, |
574 | 598 | ) |
575 | 599 | ); |
600 | + } |
|
576 | 601 | |
577 | 602 | // Get all the current max and mins. |
578 | 603 | $request = $smcFunc['db_query']('', ' |
@@ -606,8 +631,8 @@ discard block |
||
606 | 631 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
607 | 632 | { |
608 | 633 | // If not, update. |
609 | - if ($row['first_msg'] != $topicMaxMin[$row['id_topic']]['min'] || $row['last_msg'] != $topicMaxMin[$row['id_topic']]['max']) |
|
610 | - $smcFunc['db_query']('', ' |
|
634 | + if ($row['first_msg'] != $topicMaxMin[$row['id_topic']]['min'] || $row['last_msg'] != $topicMaxMin[$row['id_topic']]['max']) { |
|
635 | + $smcFunc['db_query']('', ' |
|
611 | 636 | UPDATE {db_prefix}topics |
612 | 637 | SET id_first_msg = {int:first_msg}, id_last_msg = {int:last_msg} |
613 | 638 | WHERE id_topic = {int:selected_topic}', |
@@ -617,6 +642,7 @@ discard block |
||
617 | 642 | 'selected_topic' => $row['id_topic'], |
618 | 643 | ) |
619 | 644 | ); |
645 | + } |
|
620 | 646 | } |
621 | 647 | $smcFunc['db_free_result']($request); |
622 | 648 | } |
@@ -675,9 +701,10 @@ discard block |
||
675 | 701 | } |
676 | 702 | |
677 | 703 | // Update the cache? |
678 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3) |
|
679 | - foreach ($topics as $topic_id) |
|
704 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3) { |
|
705 | + foreach ($topics as $topic_id) |
|
680 | 706 | cache_put_data('topic_board-' . $topic_id, null, 120); |
707 | + } |
|
681 | 708 | |
682 | 709 | require_once($sourcedir . '/Subs-Post.php'); |
683 | 710 | |
@@ -701,15 +728,17 @@ discard block |
||
701 | 728 | { |
702 | 729 | global $board, $topic, $smcFunc, $scripturl; |
703 | 730 | |
704 | - if (isset($_GET['current_board'])) |
|
705 | - $move_from = (int) $_GET['current_board']; |
|
731 | + if (isset($_GET['current_board'])) { |
|
732 | + $move_from = (int) $_GET['current_board']; |
|
733 | + } |
|
706 | 734 | |
707 | - if (empty($move_from) || empty($board) || empty($topic)) |
|
708 | - return true; |
|
735 | + if (empty($move_from) || empty($board) || empty($topic)) { |
|
736 | + return true; |
|
737 | + } |
|
709 | 738 | |
710 | - if ($move_from == $board) |
|
711 | - return true; |
|
712 | - else |
|
739 | + if ($move_from == $board) { |
|
740 | + return true; |
|
741 | + } else |
|
713 | 742 | { |
714 | 743 | $request = $smcFunc['db_query']('', ' |
715 | 744 | SELECT m.subject, b.name |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 3 |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF')) |
|
16 | +if (!defined('SMF')) { |
|
17 | 17 | die('No direct access...'); |
18 | +} |
|
18 | 19 | |
19 | 20 | |
20 | 21 | /** |
@@ -44,8 +45,9 @@ discard block |
||
44 | 45 | $_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : (allowedTo('manage_membergroups') ? 'index' : 'settings'); |
45 | 46 | |
46 | 47 | // Is it elsewhere? |
47 | - if (isset($subActions[$_REQUEST['sa']][2])) |
|
48 | - require_once($sourcedir . '/' . $subActions[$_REQUEST['sa']][2]); |
|
48 | + if (isset($subActions[$_REQUEST['sa']][2])) { |
|
49 | + require_once($sourcedir . '/' . $subActions[$_REQUEST['sa']][2]); |
|
50 | + } |
|
49 | 51 | |
50 | 52 | // Do the permission check, you might not be allowed her. |
51 | 53 | isAllowedTo($subActions[$_REQUEST['sa']][1]); |
@@ -104,19 +106,20 @@ discard block |
||
104 | 106 | 'function' => function($rowData) use ($scripturl) |
105 | 107 | { |
106 | 108 | // Since the moderator group has no explicit members, no link is needed. |
107 | - if ($rowData['id_group'] == 3) |
|
108 | - $group_name = $rowData['group_name']; |
|
109 | - else |
|
109 | + if ($rowData['id_group'] == 3) { |
|
110 | + $group_name = $rowData['group_name']; |
|
111 | + } else |
|
110 | 112 | { |
111 | 113 | $color_style = empty($rowData['online_color']) ? '' : sprintf(' style="color: %1$s;"', $rowData['online_color']); |
112 | 114 | $group_name = sprintf('<a href="%1$s?action=admin;area=membergroups;sa=members;group=%2$d"%3$s>%4$s</a>', $scripturl, $rowData['id_group'], $color_style, $rowData['group_name']); |
113 | 115 | } |
114 | 116 | |
115 | 117 | // Add a help option for moderator and administrator. |
116 | - if ($rowData['id_group'] == 1) |
|
117 | - $group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_administrator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl); |
|
118 | - elseif ($rowData['id_group'] == 3) |
|
119 | - $group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_moderator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl); |
|
118 | + if ($rowData['id_group'] == 1) { |
|
119 | + $group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_administrator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl); |
|
120 | + } elseif ($rowData['id_group'] == 3) { |
|
121 | + $group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_moderator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl); |
|
122 | + } |
|
120 | 123 | |
121 | 124 | return $group_name; |
122 | 125 | }, |
@@ -330,12 +333,14 @@ discard block |
||
330 | 333 | call_integration_hook('integrate_add_membergroup', array($id_group, $postCountBasedGroup)); |
331 | 334 | |
332 | 335 | // Update the post groups now, if this is a post group! |
333 | - if (isset($_POST['min_posts'])) |
|
334 | - updateStats('postgroups'); |
|
336 | + if (isset($_POST['min_posts'])) { |
|
337 | + updateStats('postgroups'); |
|
338 | + } |
|
335 | 339 | |
336 | 340 | // You cannot set permissions for post groups if they are disabled. |
337 | - if ($postCountBasedGroup && empty($modSettings['permission_enable_postgroups'])) |
|
338 | - $_POST['perm_type'] = ''; |
|
341 | + if ($postCountBasedGroup && empty($modSettings['permission_enable_postgroups'])) { |
|
342 | + $_POST['perm_type'] = ''; |
|
343 | + } |
|
339 | 344 | |
340 | 345 | if ($_POST['perm_type'] == 'predefined') |
341 | 346 | { |
@@ -365,8 +370,9 @@ discard block |
||
365 | 370 | $smcFunc['db_free_result']($request); |
366 | 371 | |
367 | 372 | // Protected groups are... well, protected! |
368 | - if ($copy_type == 1) |
|
369 | - fatal_lang_error('membergroup_does_not_exist'); |
|
373 | + if ($copy_type == 1) { |
|
374 | + fatal_lang_error('membergroup_does_not_exist'); |
|
375 | + } |
|
370 | 376 | } |
371 | 377 | |
372 | 378 | // Don't allow copying of a real priviledged person! |
@@ -384,18 +390,20 @@ discard block |
||
384 | 390 | $inserts = array(); |
385 | 391 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
386 | 392 | { |
387 | - if (empty($context['illegal_permissions']) || !in_array($row['permission'], $context['illegal_permissions'])) |
|
388 | - $inserts[] = array($id_group, $row['permission'], $row['add_deny']); |
|
393 | + if (empty($context['illegal_permissions']) || !in_array($row['permission'], $context['illegal_permissions'])) { |
|
394 | + $inserts[] = array($id_group, $row['permission'], $row['add_deny']); |
|
395 | + } |
|
389 | 396 | } |
390 | 397 | $smcFunc['db_free_result']($request); |
391 | 398 | |
392 | - if (!empty($inserts)) |
|
393 | - $smcFunc['db_insert']('insert', |
|
399 | + if (!empty($inserts)) { |
|
400 | + $smcFunc['db_insert']('insert', |
|
394 | 401 | '{db_prefix}permissions', |
395 | 402 | array('id_group' => 'int', 'permission' => 'string', 'add_deny' => 'int'), |
396 | 403 | $inserts, |
397 | 404 | array('id_group', 'permission') |
398 | 405 | ); |
406 | + } |
|
399 | 407 | |
400 | 408 | $request = $smcFunc['db_query']('', ' |
401 | 409 | SELECT id_profile, permission, add_deny |
@@ -406,17 +414,19 @@ discard block |
||
406 | 414 | ) |
407 | 415 | ); |
408 | 416 | $inserts = array(); |
409 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
410 | - $inserts[] = array($id_group, $row['id_profile'], $row['permission'], $row['add_deny']); |
|
417 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
418 | + $inserts[] = array($id_group, $row['id_profile'], $row['permission'], $row['add_deny']); |
|
419 | + } |
|
411 | 420 | $smcFunc['db_free_result']($request); |
412 | 421 | |
413 | - if (!empty($inserts)) |
|
414 | - $smcFunc['db_insert']('insert', |
|
422 | + if (!empty($inserts)) { |
|
423 | + $smcFunc['db_insert']('insert', |
|
415 | 424 | '{db_prefix}board_permissions', |
416 | 425 | array('id_group' => 'int', 'id_profile' => 'int', 'permission' => 'string', 'add_deny' => 'int'), |
417 | 426 | $inserts, |
418 | 427 | array('id_group', 'id_profile', 'permission') |
419 | 428 | ); |
429 | + } |
|
420 | 430 | |
421 | 431 | // Also get some membergroup information if we're copying and not copying from guests... |
422 | 432 | if ($copy_id > 0 && $_POST['perm_type'] == 'copy') |
@@ -469,14 +479,15 @@ discard block |
||
469 | 479 | $changed_boards['allow'] = array(); |
470 | 480 | $changed_boards['deny'] = array(); |
471 | 481 | $changed_boards['ignore'] = array(); |
472 | - foreach ($accesses as $group_id => $action) |
|
473 | - $changed_boards[$action][] = (int) $group_id; |
|
482 | + foreach ($accesses as $group_id => $action) { |
|
483 | + $changed_boards[$action][] = (int) $group_id; |
|
484 | + } |
|
474 | 485 | |
475 | 486 | foreach (array('allow', 'deny') as $board_action) |
476 | 487 | { |
477 | 488 | // Only do this if they have special access requirements. |
478 | - if (!empty($changed_boards[$board_action])) |
|
479 | - $smcFunc['db_query']('', ' |
|
489 | + if (!empty($changed_boards[$board_action])) { |
|
490 | + $smcFunc['db_query']('', ' |
|
480 | 491 | UPDATE {db_prefix}boards |
481 | 492 | SET {raw:column} = CASE WHEN {raw:column} = {string:blank_string} THEN {string:group_id_string} ELSE CONCAT({raw:column}, {string:comma_group}) END |
482 | 493 | WHERE id_board IN ({array_int:board_list})', |
@@ -488,11 +499,13 @@ discard block |
||
488 | 499 | 'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups', |
489 | 500 | ) |
490 | 501 | ); |
502 | + } |
|
491 | 503 | } |
492 | 504 | |
493 | 505 | // If this is joinable then set it to show group membership in people's profiles. |
494 | - if (empty($modSettings['show_group_membership']) && $_POST['group_type'] > 1) |
|
495 | - updateSettings(array('show_group_membership' => 1)); |
|
506 | + if (empty($modSettings['show_group_membership']) && $_POST['group_type'] > 1) { |
|
507 | + updateSettings(array('show_group_membership' => 1)); |
|
508 | + } |
|
496 | 509 | |
497 | 510 | // Rebuild the group cache. |
498 | 511 | updateSettings(array( |
@@ -513,8 +526,9 @@ discard block |
||
513 | 526 | $context['undefined_group'] = !isset($_REQUEST['postgroup']) && !isset($_REQUEST['generalgroup']); |
514 | 527 | $context['allow_protected'] = allowedTo('admin_forum'); |
515 | 528 | |
516 | - if (!empty($modSettings['deny_boards_access'])) |
|
517 | - loadLanguage('ManagePermissions'); |
|
529 | + if (!empty($modSettings['deny_boards_access'])) { |
|
530 | + loadLanguage('ManagePermissions'); |
|
531 | + } |
|
518 | 532 | |
519 | 533 | $result = $smcFunc['db_query']('', ' |
520 | 534 | SELECT id_group, group_name |
@@ -531,11 +545,12 @@ discard block |
||
531 | 545 | ) |
532 | 546 | ); |
533 | 547 | $context['groups'] = array(); |
534 | - while ($row = $smcFunc['db_fetch_assoc']($result)) |
|
535 | - $context['groups'][] = array( |
|
548 | + while ($row = $smcFunc['db_fetch_assoc']($result)) { |
|
549 | + $context['groups'][] = array( |
|
536 | 550 | 'id' => $row['id_group'], |
537 | 551 | 'name' => $row['group_name'] |
538 | 552 | ); |
553 | + } |
|
539 | 554 | $smcFunc['db_free_result']($result); |
540 | 555 | |
541 | 556 | $request = $smcFunc['db_query']('', ' |
@@ -552,12 +567,13 @@ discard block |
||
552 | 567 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
553 | 568 | { |
554 | 569 | // This category hasn't been set up yet.. |
555 | - if (!isset($context['categories'][$row['id_cat']])) |
|
556 | - $context['categories'][$row['id_cat']] = array( |
|
570 | + if (!isset($context['categories'][$row['id_cat']])) { |
|
571 | + $context['categories'][$row['id_cat']] = array( |
|
557 | 572 | 'id' => $row['id_cat'], |
558 | 573 | 'name' => $row['cat_name'], |
559 | 574 | 'boards' => array() |
560 | 575 | ); |
576 | + } |
|
561 | 577 | |
562 | 578 | // Set this board up, and let the template know when it's a child. (indent them..) |
563 | 579 | $context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array( |
@@ -605,8 +621,9 @@ discard block |
||
605 | 621 | require_once($sourcedir . '/Subs-Membergroups.php'); |
606 | 622 | $result = deleteMembergroups((int) $_REQUEST['group']); |
607 | 623 | // Need to throw a warning if it went wrong, but this is the only one we have a message for... |
608 | - if ($result === 'group_cannot_delete_sub') |
|
609 | - fatal_lang_error('membergroups_cannot_delete_paid', false); |
|
624 | + if ($result === 'group_cannot_delete_sub') { |
|
625 | + fatal_lang_error('membergroups_cannot_delete_paid', false); |
|
626 | + } |
|
610 | 627 | |
611 | 628 | // Go back to the membergroup index. |
612 | 629 | redirectexit('action=admin;area=membergroups;'); |
@@ -628,8 +645,9 @@ discard block |
||
628 | 645 | |
629 | 646 | $_REQUEST['group'] = isset($_REQUEST['group']) && $_REQUEST['group'] > 0 ? (int) $_REQUEST['group'] : 0; |
630 | 647 | |
631 | - if (!empty($modSettings['deny_boards_access'])) |
|
632 | - loadLanguage('ManagePermissions'); |
|
648 | + if (!empty($modSettings['deny_boards_access'])) { |
|
649 | + loadLanguage('ManagePermissions'); |
|
650 | + } |
|
633 | 651 | |
634 | 652 | // Make sure this group is editable. |
635 | 653 | if (!empty($_REQUEST['group'])) |
@@ -651,8 +669,9 @@ discard block |
||
651 | 669 | } |
652 | 670 | |
653 | 671 | // Now, do we have a valid id? |
654 | - if (empty($_REQUEST['group'])) |
|
655 | - fatal_lang_error('membergroup_does_not_exist', false); |
|
672 | + if (empty($_REQUEST['group'])) { |
|
673 | + fatal_lang_error('membergroup_does_not_exist', false); |
|
674 | + } |
|
656 | 675 | |
657 | 676 | // People who can manage boards are a bit special. |
658 | 677 | require_once($sourcedir . '/Subs-Members.php'); |
@@ -683,8 +702,9 @@ discard block |
||
683 | 702 | require_once($sourcedir . '/Subs-Membergroups.php'); |
684 | 703 | $result = deleteMembergroups($_REQUEST['group']); |
685 | 704 | // Need to throw a warning if it went wrong, but this is the only one we have a message for... |
686 | - if ($result === 'group_cannot_delete_sub') |
|
687 | - fatal_lang_error('membergroups_cannot_delete_paid', false); |
|
705 | + if ($result === 'group_cannot_delete_sub') { |
|
706 | + fatal_lang_error('membergroups_cannot_delete_paid', false); |
|
707 | + } |
|
688 | 708 | |
689 | 709 | redirectexit('action=admin;area=membergroups;'); |
690 | 710 | } |
@@ -761,16 +781,18 @@ discard block |
||
761 | 781 | $request = $smcFunc['db_query']('', ' |
762 | 782 | SELECT id_board |
763 | 783 | FROM {db_prefix}boards'); |
764 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
765 | - $accesses[(int) $row['id_board']] = 'allow'; |
|
784 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
785 | + $accesses[(int) $row['id_board']] = 'allow'; |
|
786 | + } |
|
766 | 787 | $smcFunc['db_free_result']($request); |
767 | 788 | } |
768 | 789 | |
769 | 790 | $changed_boards['allow'] = array(); |
770 | 791 | $changed_boards['deny'] = array(); |
771 | 792 | $changed_boards['ignore'] = array(); |
772 | - foreach ($accesses as $group_id => $action) |
|
773 | - $changed_boards[$action][] = (int) $group_id; |
|
793 | + foreach ($accesses as $group_id => $action) { |
|
794 | + $changed_boards[$action][] = (int) $group_id; |
|
795 | + } |
|
774 | 796 | |
775 | 797 | foreach (array('allow', 'deny') as $board_action) |
776 | 798 | { |
@@ -786,8 +808,8 @@ discard block |
||
786 | 808 | 'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups', |
787 | 809 | ) |
788 | 810 | ); |
789 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
790 | - $smcFunc['db_query']('', ' |
|
811 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
812 | + $smcFunc['db_query']('', ' |
|
791 | 813 | UPDATE {db_prefix}boards |
792 | 814 | SET {raw:column} = {string:member_group_access} |
793 | 815 | WHERE id_board = {int:current_board}', |
@@ -797,11 +819,12 @@ discard block |
||
797 | 819 | 'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups', |
798 | 820 | ) |
799 | 821 | ); |
822 | + } |
|
800 | 823 | $smcFunc['db_free_result']($request); |
801 | 824 | |
802 | 825 | // Add the membergroup to all boards that hadn't been set yet. |
803 | - if (!empty($changed_boards[$board_action])) |
|
804 | - $smcFunc['db_query']('', ' |
|
826 | + if (!empty($changed_boards[$board_action])) { |
|
827 | + $smcFunc['db_query']('', ' |
|
805 | 828 | UPDATE {db_prefix}boards |
806 | 829 | SET {raw:column} = CASE WHEN {raw:column} = {string:blank_string} THEN {string:group_id_string} ELSE CONCAT({raw:column}, {string:comma_group}) END |
807 | 830 | WHERE id_board IN ({array_int:board_list}) |
@@ -815,6 +838,7 @@ discard block |
||
815 | 838 | 'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups', |
816 | 839 | ) |
817 | 840 | ); |
841 | + } |
|
818 | 842 | } |
819 | 843 | } |
820 | 844 | |
@@ -840,12 +864,14 @@ discard block |
||
840 | 864 | ) |
841 | 865 | ); |
842 | 866 | $updates = array(); |
843 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
844 | - $updates[$row['additional_groups']][] = $row['id_member']; |
|
867 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
868 | + $updates[$row['additional_groups']][] = $row['id_member']; |
|
869 | + } |
|
845 | 870 | $smcFunc['db_free_result']($request); |
846 | 871 | |
847 | - foreach ($updates as $additional_groups => $memberArray) |
|
848 | - updateMemberData($memberArray, array('additional_groups' => implode(',', array_diff(explode(',', $additional_groups), array((int) $_REQUEST['group']))))); |
|
872 | + foreach ($updates as $additional_groups => $memberArray) { |
|
873 | + updateMemberData($memberArray, array('additional_groups' => implode(',', array_diff(explode(',', $additional_groups), array((int) $_REQUEST['group']))))); |
|
874 | + } |
|
849 | 875 | |
850 | 876 | // Sorry, but post groups can't moderate boards |
851 | 877 | $smcFunc['db_query']('', ' |
@@ -855,8 +881,7 @@ discard block |
||
855 | 881 | 'current_group' => (int) $_REQUEST['group'], |
856 | 882 | ) |
857 | 883 | ); |
858 | - } |
|
859 | - elseif ($_REQUEST['group'] != 3) |
|
884 | + } elseif ($_REQUEST['group'] != 3) |
|
860 | 885 | { |
861 | 886 | // Making it a hidden group? If so remove everyone with it as primary group (Actually, just make them additional). |
862 | 887 | if ($_POST['group_hidden'] == 2) |
@@ -871,8 +896,9 @@ discard block |
||
871 | 896 | ) |
872 | 897 | ); |
873 | 898 | $updates = array(); |
874 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
875 | - $updates[$row['additional_groups']][] = $row['id_member']; |
|
899 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
900 | + $updates[$row['additional_groups']][] = $row['id_member']; |
|
901 | + } |
|
876 | 902 | $smcFunc['db_free_result']($request); |
877 | 903 | |
878 | 904 | foreach ($updates as $additional_groups => $memberArray) |
@@ -914,8 +940,9 @@ discard block |
||
914 | 940 | $smcFunc['db_free_result']($request); |
915 | 941 | |
916 | 942 | // Do we need to update the setting? |
917 | - if ((empty($modSettings['show_group_membership']) && $have_joinable) || (!empty($modSettings['show_group_membership']) && !$have_joinable)) |
|
918 | - updateSettings(array('show_group_membership' => $have_joinable ? 1 : 0)); |
|
943 | + if ((empty($modSettings['show_group_membership']) && $have_joinable) || (!empty($modSettings['show_group_membership']) && !$have_joinable)) { |
|
944 | + updateSettings(array('show_group_membership' => $have_joinable ? 1 : 0)); |
|
945 | + } |
|
919 | 946 | } |
920 | 947 | |
921 | 948 | // Do we need to set inherited permissions? |
@@ -948,8 +975,9 @@ discard block |
||
948 | 975 | { |
949 | 976 | $moderators[$k] = trim($moderators[$k]); |
950 | 977 | |
951 | - if (strlen($moderators[$k]) == 0) |
|
952 | - unset($moderators[$k]); |
|
978 | + if (strlen($moderators[$k]) == 0) { |
|
979 | + unset($moderators[$k]); |
|
980 | + } |
|
953 | 981 | } |
954 | 982 | |
955 | 983 | // Find all the id_member's for the member_name's in the list. |
@@ -965,8 +993,9 @@ discard block |
||
965 | 993 | 'count' => count($moderators), |
966 | 994 | ) |
967 | 995 | ); |
968 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
969 | - $group_moderators[] = $row['id_member']; |
|
996 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
997 | + $group_moderators[] = $row['id_member']; |
|
998 | + } |
|
970 | 999 | $smcFunc['db_free_result']($request); |
971 | 1000 | } |
972 | 1001 | } |
@@ -974,8 +1003,9 @@ discard block |
||
974 | 1003 | if (!empty($_POST['moderator_list'])) |
975 | 1004 | { |
976 | 1005 | $moderators = array(); |
977 | - foreach ($_POST['moderator_list'] as $moderator) |
|
978 | - $moderators[] = (int) $moderator; |
|
1006 | + foreach ($_POST['moderator_list'] as $moderator) { |
|
1007 | + $moderators[] = (int) $moderator; |
|
1008 | + } |
|
979 | 1009 | |
980 | 1010 | if (!empty($moderators)) |
981 | 1011 | { |
@@ -989,8 +1019,9 @@ discard block |
||
989 | 1019 | 'num_moderators' => count($moderators), |
990 | 1020 | ) |
991 | 1021 | ); |
992 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
993 | - $group_moderators[] = $row['id_member']; |
|
1022 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1023 | + $group_moderators[] = $row['id_member']; |
|
1024 | + } |
|
994 | 1025 | $smcFunc['db_free_result']($request); |
995 | 1026 | } |
996 | 1027 | } |
@@ -1002,8 +1033,9 @@ discard block |
||
1002 | 1033 | if (!empty($group_moderators)) |
1003 | 1034 | { |
1004 | 1035 | $mod_insert = array(); |
1005 | - foreach ($group_moderators as $moderator) |
|
1006 | - $mod_insert[] = array($_REQUEST['group'], $moderator); |
|
1036 | + foreach ($group_moderators as $moderator) { |
|
1037 | + $mod_insert[] = array($_REQUEST['group'], $moderator); |
|
1038 | + } |
|
1007 | 1039 | |
1008 | 1040 | $smcFunc['db_insert']('insert', |
1009 | 1041 | '{db_prefix}group_moderators', |
@@ -1037,8 +1069,9 @@ discard block |
||
1037 | 1069 | 'current_group' => (int) $_REQUEST['group'], |
1038 | 1070 | ) |
1039 | 1071 | ); |
1040 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
1041 | - fatal_lang_error('membergroup_does_not_exist', false); |
|
1072 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
1073 | + fatal_lang_error('membergroup_does_not_exist', false); |
|
1074 | + } |
|
1042 | 1075 | $row = $smcFunc['db_fetch_assoc']($request); |
1043 | 1076 | $smcFunc['db_free_result']($request); |
1044 | 1077 | |
@@ -1075,14 +1108,16 @@ discard block |
||
1075 | 1108 | ) |
1076 | 1109 | ); |
1077 | 1110 | $context['group']['moderators'] = array(); |
1078 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1079 | - $context['group']['moderators'][$row['id_member']] = $row['real_name']; |
|
1111 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1112 | + $context['group']['moderators'][$row['id_member']] = $row['real_name']; |
|
1113 | + } |
|
1080 | 1114 | $smcFunc['db_free_result']($request); |
1081 | 1115 | |
1082 | 1116 | $context['group']['moderator_list'] = empty($context['group']['moderators']) ? '' : '"' . implode('", "', $context['group']['moderators']) . '"'; |
1083 | 1117 | |
1084 | - if (!empty($context['group']['moderators'])) |
|
1085 | - list ($context['group']['last_moderator_id']) = array_slice(array_keys($context['group']['moderators']), -1); |
|
1118 | + if (!empty($context['group']['moderators'])) { |
|
1119 | + list ($context['group']['last_moderator_id']) = array_slice(array_keys($context['group']['moderators']), -1); |
|
1120 | + } |
|
1086 | 1121 | |
1087 | 1122 | // Get a list of boards this membergroup is allowed to see. |
1088 | 1123 | $context['boards'] = array(); |
@@ -1102,12 +1137,13 @@ discard block |
||
1102 | 1137 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1103 | 1138 | { |
1104 | 1139 | // This category hasn't been set up yet.. |
1105 | - if (!isset($context['categories'][$row['id_cat']])) |
|
1106 | - $context['categories'][$row['id_cat']] = array( |
|
1140 | + if (!isset($context['categories'][$row['id_cat']])) { |
|
1141 | + $context['categories'][$row['id_cat']] = array( |
|
1107 | 1142 | 'id' => $row['id_cat'], |
1108 | 1143 | 'name' => $row['cat_name'], |
1109 | 1144 | 'boards' => array() |
1110 | 1145 | ); |
1146 | + } |
|
1111 | 1147 | |
1112 | 1148 | // Set this board up, and let the template know when it's a child. (indent them..) |
1113 | 1149 | $context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array( |
@@ -1155,19 +1191,22 @@ discard block |
||
1155 | 1191 | $image_info = getimagesize($settings['default_theme_dir'] . '/images/membericons/' . $value); |
1156 | 1192 | |
1157 | 1193 | // If this is bigger than 128 in width or 32 in height, skip this one. |
1158 | - if ($image_info == false || $image_info[0] > 128 || $image_info[1] > 32) |
|
1159 | - continue; |
|
1194 | + if ($image_info == false || $image_info[0] > 128 || $image_info[1] > 32) { |
|
1195 | + continue; |
|
1196 | + } |
|
1160 | 1197 | |
1161 | 1198 | // Else it's valid. Add it in. |
1162 | - else |
|
1163 | - $context['possible_icons'][] = $value; |
|
1199 | + else { |
|
1200 | + $context['possible_icons'][] = $value; |
|
1201 | + } |
|
1164 | 1202 | } |
1165 | 1203 | } |
1166 | 1204 | } |
1167 | 1205 | |
1168 | 1206 | // Insert our JS, if we have possible icons. |
1169 | - if (!empty($context['possible_icons'])) |
|
1170 | - loadJavaScriptFile('icondropdown.js', array('validate' => true), 'smf_icondropdown'); |
|
1207 | + if (!empty($context['possible_icons'])) { |
|
1208 | + loadJavaScriptFile('icondropdown.js', array('validate' => true), 'smf_icondropdown'); |
|
1209 | + } |
|
1171 | 1210 | |
1172 | 1211 | loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest'); |
1173 | 1212 | |
@@ -1189,8 +1228,9 @@ discard block |
||
1189 | 1228 | ) |
1190 | 1229 | ); |
1191 | 1230 | $context['inheritable_groups'] = array(); |
1192 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1193 | - $context['inheritable_groups'][$row['id_group']] = $row['group_name']; |
|
1231 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1232 | + $context['inheritable_groups'][$row['id_group']] = $row['group_name']; |
|
1233 | + } |
|
1194 | 1234 | $smcFunc['db_free_result']($request); |
1195 | 1235 | |
1196 | 1236 | call_integration_hook('integrate_view_membergroup'); |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 3 |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF')) |
|
16 | +if (!defined('SMF')) { |
|
17 | 17 | die('No direct access...'); |
18 | +} |
|
18 | 19 | |
19 | 20 | /** |
20 | 21 | * This is the notoriously defunct package manager..... :/. |
@@ -57,10 +58,11 @@ discard block |
||
57 | 58 | ); |
58 | 59 | |
59 | 60 | // Work out exactly who it is we are calling. |
60 | - if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) |
|
61 | - $context['sub_action'] = $_REQUEST['sa']; |
|
62 | - else |
|
63 | - $context['sub_action'] = 'browse'; |
|
61 | + if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) { |
|
62 | + $context['sub_action'] = $_REQUEST['sa']; |
|
63 | + } else { |
|
64 | + $context['sub_action'] = 'browse'; |
|
65 | + } |
|
64 | 66 | |
65 | 67 | // Set up some tabs... |
66 | 68 | $context[$context['admin_menu_name']]['tab_data'] = array( |
@@ -82,8 +84,9 @@ discard block |
||
82 | 84 | ), |
83 | 85 | ); |
84 | 86 | |
85 | - if ($context['sub_action'] == 'browse') |
|
86 | - loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest'); |
|
87 | + if ($context['sub_action'] == 'browse') { |
|
88 | + loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest'); |
|
89 | + } |
|
87 | 90 | |
88 | 91 | call_integration_hook('integrate_manage_packages', array(&$subActions)); |
89 | 92 | |
@@ -99,8 +102,9 @@ discard block |
||
99 | 102 | global $boarddir, $txt, $context, $scripturl, $sourcedir, $packagesdir, $modSettings, $smcFunc, $settings; |
100 | 103 | |
101 | 104 | // You have to specify a file!! |
102 | - if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') |
|
103 | - redirectexit('action=admin;area=packages'); |
|
105 | + if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') { |
|
106 | + redirectexit('action=admin;area=packages'); |
|
107 | + } |
|
104 | 108 | $context['filename'] = preg_replace('~[\.]+~', '.', $_REQUEST['package']); |
105 | 109 | |
106 | 110 | // Do we have an existing id, for uninstalls and the like. |
@@ -112,8 +116,9 @@ discard block |
||
112 | 116 | create_chmod_control(); |
113 | 117 | |
114 | 118 | // Make sure temp directory exists and is empty. |
115 | - if (file_exists($packagesdir . '/temp')) |
|
116 | - deltree($packagesdir . '/temp', false); |
|
119 | + if (file_exists($packagesdir . '/temp')) { |
|
120 | + deltree($packagesdir . '/temp', false); |
|
121 | + } |
|
117 | 122 | |
118 | 123 | if (!mktree($packagesdir . '/temp', 0755)) |
119 | 124 | { |
@@ -124,8 +129,9 @@ discard block |
||
124 | 129 | create_chmod_control(array($packagesdir . '/temp/delme.tmp'), array('destination_url' => $scripturl . '?action=admin;area=packages;sa=' . $_REQUEST['sa'] . ';package=' . $_REQUEST['package'], 'crash_on_error' => true)); |
125 | 130 | |
126 | 131 | deltree($packagesdir . '/temp', false); |
127 | - if (!mktree($packagesdir . '/temp', 0777)) |
|
128 | - fatal_lang_error('package_cant_download', false); |
|
132 | + if (!mktree($packagesdir . '/temp', 0777)) { |
|
133 | + fatal_lang_error('package_cant_download', false); |
|
134 | + } |
|
129 | 135 | } |
130 | 136 | } |
131 | 137 | |
@@ -151,25 +157,26 @@ discard block |
||
151 | 157 | { |
152 | 158 | $context['extracted_files'] = read_tgz_file($packagesdir . '/' . $context['filename'], $packagesdir . '/temp'); |
153 | 159 | |
154 | - if ($context['extracted_files'] && !file_exists($packagesdir . '/temp/package-info.xml')) |
|
155 | - foreach ($context['extracted_files'] as $file) |
|
160 | + if ($context['extracted_files'] && !file_exists($packagesdir . '/temp/package-info.xml')) { |
|
161 | + foreach ($context['extracted_files'] as $file) |
|
156 | 162 | if (basename($file['filename']) == 'package-info.xml') |
157 | 163 | { |
158 | 164 | $context['base_path'] = dirname($file['filename']) . '/'; |
165 | + } |
|
159 | 166 | break; |
160 | 167 | } |
161 | 168 | |
162 | - if (!isset($context['base_path'])) |
|
163 | - $context['base_path'] = ''; |
|
164 | - } |
|
165 | - elseif (is_dir($packagesdir . '/' . $context['filename'])) |
|
169 | + if (!isset($context['base_path'])) { |
|
170 | + $context['base_path'] = ''; |
|
171 | + } |
|
172 | + } elseif (is_dir($packagesdir . '/' . $context['filename'])) |
|
166 | 173 | { |
167 | 174 | copytree($packagesdir . '/' . $context['filename'], $packagesdir . '/temp'); |
168 | 175 | $context['extracted_files'] = listtree($packagesdir . '/temp'); |
169 | 176 | $context['base_path'] = ''; |
177 | + } else { |
|
178 | + fatal_lang_error('no_access', false); |
|
170 | 179 | } |
171 | - else |
|
172 | - fatal_lang_error('no_access', false); |
|
173 | 180 | |
174 | 181 | // Load up any custom themes we may want to install into... |
175 | 182 | $request = $smcFunc['db_query']('', ' |
@@ -185,15 +192,17 @@ discard block |
||
185 | 192 | ) |
186 | 193 | ); |
187 | 194 | $theme_paths = array(); |
188 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
189 | - $theme_paths[$row['id_theme']][$row['variable']] = $row['value']; |
|
195 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
196 | + $theme_paths[$row['id_theme']][$row['variable']] = $row['value']; |
|
197 | + } |
|
190 | 198 | $smcFunc['db_free_result']($request); |
191 | 199 | |
192 | 200 | // Get the package info... |
193 | 201 | $packageInfo = getPackageInfo($context['filename']); |
194 | 202 | |
195 | - if (!is_array($packageInfo)) |
|
196 | - fatal_lang_error($packageInfo); |
|
203 | + if (!is_array($packageInfo)) { |
|
204 | + fatal_lang_error($packageInfo); |
|
205 | + } |
|
197 | 206 | |
198 | 207 | $packageInfo['filename'] = $context['filename']; |
199 | 208 | $context['package_name'] = isset($packageInfo['name']) ? $packageInfo['name'] : $context['filename']; |
@@ -227,18 +236,19 @@ discard block |
||
227 | 236 | $smcFunc['db_free_result']($request); |
228 | 237 | |
229 | 238 | $context['database_changes'] = array(); |
230 | - if (isset($packageInfo['uninstall']['database'])) |
|
231 | - $context['database_changes'][] = $txt['execute_database_changes'] . ' - ' . $packageInfo['uninstall']['database']; |
|
232 | - elseif (!empty($db_changes)) |
|
239 | + if (isset($packageInfo['uninstall']['database'])) { |
|
240 | + $context['database_changes'][] = $txt['execute_database_changes'] . ' - ' . $packageInfo['uninstall']['database']; |
|
241 | + } elseif (!empty($db_changes)) |
|
233 | 242 | { |
234 | 243 | foreach ($db_changes as $change) |
235 | 244 | { |
236 | - if (isset($change[2]) && isset($txt['package_db_' . $change[0]])) |
|
237 | - $context['database_changes'][] = sprintf($txt['package_db_' . $change[0]], $change[1], $change[2]); |
|
238 | - elseif (isset($txt['package_db_' . $change[0]])) |
|
239 | - $context['database_changes'][] = sprintf($txt['package_db_' . $change[0]], $change[1]); |
|
240 | - else |
|
241 | - $context['database_changes'][] = $change[0] . '-' . $change[1] . (isset($change[2]) ? '-' . $change[2] : ''); |
|
245 | + if (isset($change[2]) && isset($txt['package_db_' . $change[0]])) { |
|
246 | + $context['database_changes'][] = sprintf($txt['package_db_' . $change[0]], $change[1], $change[2]); |
|
247 | + } elseif (isset($txt['package_db_' . $change[0]])) { |
|
248 | + $context['database_changes'][] = sprintf($txt['package_db_' . $change[0]], $change[1]); |
|
249 | + } else { |
|
250 | + $context['database_changes'][] = $change[0] . '-' . $change[1] . (isset($change[2]) ? '-' . $change[2] : ''); |
|
251 | + } |
|
242 | 252 | } |
243 | 253 | } |
244 | 254 | |
@@ -265,31 +275,33 @@ discard block |
||
265 | 275 | $context['themes_locked'] = true; |
266 | 276 | |
267 | 277 | // Only let them uninstall themes it was installed into. |
268 | - foreach ($theme_paths as $id => $data) |
|
269 | - if ($id != 1 && !in_array($id, $old_themes)) |
|
278 | + foreach ($theme_paths as $id => $data) { |
|
279 | + if ($id != 1 && !in_array($id, $old_themes)) |
|
270 | 280 | unset($theme_paths[$id]); |
271 | - } |
|
272 | - elseif (isset($old_version) && $old_version != $packageInfo['version']) |
|
281 | + } |
|
282 | + } elseif (isset($old_version) && $old_version != $packageInfo['version']) |
|
273 | 283 | { |
274 | 284 | // Look for an upgrade... |
275 | 285 | $actions = parsePackageInfo($packageInfo['xml'], true, 'upgrade', $old_version); |
276 | 286 | |
277 | 287 | // There was no upgrade.... |
278 | - if (empty($actions)) |
|
279 | - $context['is_installed'] = true; |
|
280 | - else |
|
288 | + if (empty($actions)) { |
|
289 | + $context['is_installed'] = true; |
|
290 | + } else |
|
281 | 291 | { |
282 | 292 | // Otherwise they can only upgrade themes from the first time around. |
283 | - foreach ($theme_paths as $id => $data) |
|
284 | - if ($id != 1 && !in_array($id, $old_themes)) |
|
293 | + foreach ($theme_paths as $id => $data) { |
|
294 | + if ($id != 1 && !in_array($id, $old_themes)) |
|
285 | 295 | unset($theme_paths[$id]); |
296 | + } |
|
286 | 297 | } |
298 | + } elseif (isset($old_version) && $old_version == $packageInfo['version']) { |
|
299 | + $context['is_installed'] = true; |
|
287 | 300 | } |
288 | - elseif (isset($old_version) && $old_version == $packageInfo['version']) |
|
289 | - $context['is_installed'] = true; |
|
290 | 301 | |
291 | - if (!isset($old_version) || $context['is_installed']) |
|
292 | - $actions = parsePackageInfo($packageInfo['xml'], true, 'install'); |
|
302 | + if (!isset($old_version) || $context['is_installed']) { |
|
303 | + $actions = parsePackageInfo($packageInfo['xml'], true, 'install'); |
|
304 | + } |
|
293 | 305 | |
294 | 306 | $context['actions'] = array(); |
295 | 307 | $context['ftp_needed'] = false; |
@@ -297,8 +309,9 @@ discard block |
||
297 | 309 | $chmod_files = array(); |
298 | 310 | |
299 | 311 | // no actions found, return so we can display an error |
300 | - if (empty($actions)) |
|
301 | - return; |
|
312 | + if (empty($actions)) { |
|
313 | + return; |
|
314 | + } |
|
302 | 315 | |
303 | 316 | // This will hold data about anything that can be installed in other themes. |
304 | 317 | $themeFinds = array( |
@@ -317,14 +330,14 @@ discard block |
||
317 | 330 | { |
318 | 331 | $chmod_files[] = $action['filename']; |
319 | 332 | continue; |
320 | - } |
|
321 | - elseif ($action['type'] == 'readme' || $action['type'] == 'license') |
|
333 | + } elseif ($action['type'] == 'readme' || $action['type'] == 'license') |
|
322 | 334 | { |
323 | 335 | $type = 'package_' . $action['type']; |
324 | - if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename'])) |
|
325 | - $context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), "\n\r")); |
|
326 | - elseif (file_exists($action['filename'])) |
|
327 | - $context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($action['filename']), "\n\r")); |
|
336 | + if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename'])) { |
|
337 | + $context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), "\n\r")); |
|
338 | + } elseif (file_exists($action['filename'])) { |
|
339 | + $context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($action['filename']), "\n\r")); |
|
340 | + } |
|
328 | 341 | |
329 | 342 | if (!empty($action['parse_bbc'])) |
330 | 343 | { |
@@ -332,24 +345,24 @@ discard block |
||
332 | 345 | $context[$type] = preg_replace('~\[[/]?html\]~i', '', $context[$type]); |
333 | 346 | preparsecode($context[$type]); |
334 | 347 | $context[$type] = parse_bbc($context[$type]); |
348 | + } else { |
|
349 | + $context[$type] = nl2br($context[$type]); |
|
335 | 350 | } |
336 | - else |
|
337 | - $context[$type] = nl2br($context[$type]); |
|
338 | 351 | |
339 | 352 | continue; |
340 | 353 | } |
341 | 354 | // Don't show redirects. |
342 | - elseif ($action['type'] == 'redirect') |
|
343 | - continue; |
|
344 | - elseif ($action['type'] == 'error') |
|
355 | + elseif ($action['type'] == 'redirect') { |
|
356 | + continue; |
|
357 | + } elseif ($action['type'] == 'error') |
|
345 | 358 | { |
346 | 359 | $context['has_failure'] = true; |
347 | - if (isset($action['error_msg']) && isset($action['error_var'])) |
|
348 | - $context['failure_details'] = sprintf($txt['package_will_fail_' . $action['error_msg']], $action['error_var']); |
|
349 | - elseif (isset($action['error_msg'])) |
|
350 | - $context['failure_details'] = isset($txt['package_will_fail_' . $action['error_msg']]) ? $txt['package_will_fail_' . $action['error_msg']] : $action['error_msg']; |
|
351 | - } |
|
352 | - elseif ($action['type'] == 'modification') |
|
360 | + if (isset($action['error_msg']) && isset($action['error_var'])) { |
|
361 | + $context['failure_details'] = sprintf($txt['package_will_fail_' . $action['error_msg']], $action['error_var']); |
|
362 | + } elseif (isset($action['error_msg'])) { |
|
363 | + $context['failure_details'] = isset($txt['package_will_fail_' . $action['error_msg']]) ? $txt['package_will_fail_' . $action['error_msg']] : $action['error_msg']; |
|
364 | + } |
|
365 | + } elseif ($action['type'] == 'modification') |
|
353 | 366 | { |
354 | 367 | if (!file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename'])) |
355 | 368 | { |
@@ -361,52 +374,54 @@ discard block |
||
361 | 374 | 'description' => $txt['package_action_missing'], |
362 | 375 | 'failed' => true, |
363 | 376 | ); |
364 | - } |
|
365 | - else |
|
377 | + } else |
|
366 | 378 | { |
367 | 379 | |
368 | - if ($action['boardmod']) |
|
369 | - $mod_actions = parseBoardMod(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), true, $action['reverse'], $theme_paths); |
|
370 | - else |
|
371 | - $mod_actions = parseModification(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), true, $action['reverse'], $theme_paths); |
|
380 | + if ($action['boardmod']) { |
|
381 | + $mod_actions = parseBoardMod(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), true, $action['reverse'], $theme_paths); |
|
382 | + } else { |
|
383 | + $mod_actions = parseModification(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), true, $action['reverse'], $theme_paths); |
|
384 | + } |
|
372 | 385 | |
373 | - if (count($mod_actions) == 1 && isset($mod_actions[0]) && $mod_actions[0]['type'] == 'error' && $mod_actions[0]['filename'] == '-') |
|
374 | - $mod_actions[0]['filename'] = $action['filename']; |
|
386 | + if (count($mod_actions) == 1 && isset($mod_actions[0]) && $mod_actions[0]['type'] == 'error' && $mod_actions[0]['filename'] == '-') { |
|
387 | + $mod_actions[0]['filename'] = $action['filename']; |
|
388 | + } |
|
375 | 389 | |
376 | 390 | foreach ($mod_actions as $key => $mod_action) |
377 | 391 | { |
378 | 392 | // Lets get the last section of the file name. |
379 | - if (isset($mod_action['filename']) && substr($mod_action['filename'], -13) != '.template.php') |
|
380 | - $actual_filename = strtolower(substr(strrchr($mod_action['filename'], '/'), 1) . '||' . $action['filename']); |
|
381 | - elseif (isset($mod_action['filename']) && preg_match('~([\w]*)/([\w]*)\.template\.php$~', $mod_action['filename'], $matches)) |
|
382 | - $actual_filename = strtolower($matches[1] . '/' . $matches[2] . '.template.php' . '||' . $action['filename']); |
|
383 | - else |
|
384 | - $actual_filename = $key; |
|
385 | - |
|
386 | - if ($mod_action['type'] == 'opened') |
|
387 | - $failed = false; |
|
388 | - elseif ($mod_action['type'] == 'failure') |
|
393 | + if (isset($mod_action['filename']) && substr($mod_action['filename'], -13) != '.template.php') { |
|
394 | + $actual_filename = strtolower(substr(strrchr($mod_action['filename'], '/'), 1) . '||' . $action['filename']); |
|
395 | + } elseif (isset($mod_action['filename']) && preg_match('~([\w]*)/([\w]*)\.template\.php$~', $mod_action['filename'], $matches)) { |
|
396 | + $actual_filename = strtolower($matches[1] . '/' . $matches[2] . '.template.php' . '||' . $action['filename']); |
|
397 | + } else { |
|
398 | + $actual_filename = $key; |
|
399 | + } |
|
400 | + |
|
401 | + if ($mod_action['type'] == 'opened') { |
|
402 | + $failed = false; |
|
403 | + } elseif ($mod_action['type'] == 'failure') |
|
389 | 404 | { |
390 | - if (empty($mod_action['is_custom'])) |
|
391 | - $context['has_failure'] = true; |
|
405 | + if (empty($mod_action['is_custom'])) { |
|
406 | + $context['has_failure'] = true; |
|
407 | + } |
|
392 | 408 | $failed = true; |
393 | - } |
|
394 | - elseif ($mod_action['type'] == 'chmod') |
|
409 | + } elseif ($mod_action['type'] == 'chmod') |
|
395 | 410 | { |
396 | 411 | $chmod_files[] = $mod_action['filename']; |
397 | - } |
|
398 | - elseif ($mod_action['type'] == 'saved') |
|
412 | + } elseif ($mod_action['type'] == 'saved') |
|
399 | 413 | { |
400 | 414 | if (!empty($mod_action['is_custom'])) |
401 | 415 | { |
402 | - if (!isset($context['theme_actions'][$mod_action['is_custom']])) |
|
403 | - $context['theme_actions'][$mod_action['is_custom']] = array( |
|
416 | + if (!isset($context['theme_actions'][$mod_action['is_custom']])) { |
|
417 | + $context['theme_actions'][$mod_action['is_custom']] = array( |
|
404 | 418 | 'name' => $theme_paths[$mod_action['is_custom']]['name'], |
405 | 419 | 'actions' => array(), |
406 | 420 | 'has_failure' => $failed, |
407 | 421 | ); |
408 | - else |
|
409 | - $context['theme_actions'][$mod_action['is_custom']]['has_failure'] |= $failed; |
|
422 | + } else { |
|
423 | + $context['theme_actions'][$mod_action['is_custom']]['has_failure'] |= $failed; |
|
424 | + } |
|
410 | 425 | |
411 | 426 | $context['theme_actions'][$mod_action['is_custom']]['actions'][$actual_filename] = array( |
412 | 427 | 'type' => $txt['execute_modification'], |
@@ -414,8 +429,7 @@ discard block |
||
414 | 429 | 'description' => $failed ? $txt['package_action_failure'] : $txt['package_action_success'], |
415 | 430 | 'failed' => $failed, |
416 | 431 | ); |
417 | - } |
|
418 | - elseif (!isset($context['actions'][$actual_filename])) |
|
432 | + } elseif (!isset($context['actions'][$actual_filename])) |
|
419 | 433 | { |
420 | 434 | $context['actions'][$actual_filename] = array( |
421 | 435 | 'type' => $txt['execute_modification'], |
@@ -423,22 +437,19 @@ discard block |
||
423 | 437 | 'description' => $failed ? $txt['package_action_failure'] : $txt['package_action_success'], |
424 | 438 | 'failed' => $failed, |
425 | 439 | ); |
426 | - } |
|
427 | - else |
|
440 | + } else |
|
428 | 441 | { |
429 | 442 | $context['actions'][$actual_filename]['failed'] |= $failed; |
430 | 443 | $context['actions'][$actual_filename]['description'] = $context['actions'][$actual_filename]['failed'] ? $txt['package_action_failure'] : $txt['package_action_success']; |
431 | 444 | } |
432 | - } |
|
433 | - elseif ($mod_action['type'] == 'skipping') |
|
445 | + } elseif ($mod_action['type'] == 'skipping') |
|
434 | 446 | { |
435 | 447 | $context['actions'][$actual_filename] = array( |
436 | 448 | 'type' => $txt['execute_modification'], |
437 | 449 | 'action' => $smcFunc['htmlspecialchars'](strtr($mod_action['filename'], array($boarddir => '.'))), |
438 | 450 | 'description' => $txt['package_action_skipping'] |
439 | 451 | ); |
440 | - } |
|
441 | - elseif ($mod_action['type'] == 'missing' && empty($mod_action['is_custom'])) |
|
452 | + } elseif ($mod_action['type'] == 'missing' && empty($mod_action['is_custom'])) |
|
442 | 453 | { |
443 | 454 | $context['has_failure'] = true; |
444 | 455 | $context['actions'][$actual_filename] = array( |
@@ -447,32 +458,33 @@ discard block |
||
447 | 458 | 'description' => $txt['package_action_missing'], |
448 | 459 | 'failed' => true, |
449 | 460 | ); |
450 | - } |
|
451 | - elseif ($mod_action['type'] == 'error') |
|
452 | - $context['actions'][$actual_filename] = array( |
|
461 | + } elseif ($mod_action['type'] == 'error') { |
|
462 | + $context['actions'][$actual_filename] = array( |
|
453 | 463 | 'type' => $txt['execute_modification'], |
454 | 464 | 'action' => $smcFunc['htmlspecialchars'](strtr($mod_action['filename'], array($boarddir => '.'))), |
455 | 465 | 'description' => $txt['package_action_error'], |
456 | 466 | 'failed' => true, |
457 | 467 | ); |
468 | + } |
|
458 | 469 | } |
459 | 470 | |
460 | 471 | // We need to loop again just to get the operations down correctly. |
461 | 472 | foreach ($mod_actions as $operation_key => $mod_action) |
462 | 473 | { |
463 | 474 | // Lets get the last section of the file name. |
464 | - if (isset($mod_action['filename']) && substr($mod_action['filename'], -13) != '.template.php') |
|
465 | - $actual_filename = strtolower(substr(strrchr($mod_action['filename'], '/'), 1) . '||' . $action['filename']); |
|
466 | - elseif (isset($mod_action['filename']) && preg_match('~([\w]*)/([\w]*)\.template\.php$~', $mod_action['filename'], $matches)) |
|
467 | - $actual_filename = strtolower($matches[1] . '/' . $matches[2] . '.template.php' . '||' . $action['filename']); |
|
468 | - else |
|
469 | - $actual_filename = $key; |
|
475 | + if (isset($mod_action['filename']) && substr($mod_action['filename'], -13) != '.template.php') { |
|
476 | + $actual_filename = strtolower(substr(strrchr($mod_action['filename'], '/'), 1) . '||' . $action['filename']); |
|
477 | + } elseif (isset($mod_action['filename']) && preg_match('~([\w]*)/([\w]*)\.template\.php$~', $mod_action['filename'], $matches)) { |
|
478 | + $actual_filename = strtolower($matches[1] . '/' . $matches[2] . '.template.php' . '||' . $action['filename']); |
|
479 | + } else { |
|
480 | + $actual_filename = $key; |
|
481 | + } |
|
470 | 482 | |
471 | 483 | // We just need it for actual parse changes. |
472 | 484 | if (!in_array($mod_action['type'], array('error', 'result', 'opened', 'saved', 'end', 'missing', 'skipping', 'chmod'))) |
473 | 485 | { |
474 | - if (empty($mod_action['is_custom'])) |
|
475 | - $context['actions'][$actual_filename]['operations'][] = array( |
|
486 | + if (empty($mod_action['is_custom'])) { |
|
487 | + $context['actions'][$actual_filename]['operations'][] = array( |
|
476 | 488 | 'type' => $txt['execute_modification'], |
477 | 489 | 'action' => $smcFunc['htmlspecialchars'](strtr($mod_action['filename'], array($boarddir => '.'))), |
478 | 490 | 'description' => $mod_action['failed'] ? $txt['package_action_failure'] : $txt['package_action_success'], |
@@ -483,10 +495,11 @@ discard block |
||
483 | 495 | 'failed' => $mod_action['failed'], |
484 | 496 | 'ignore_failure' => !empty($mod_action['ignore_failure']), |
485 | 497 | ); |
498 | + } |
|
486 | 499 | |
487 | 500 | // Themes are under the saved type. |
488 | - if (isset($mod_action['is_custom']) && isset($context['theme_actions'][$mod_action['is_custom']])) |
|
489 | - $context['theme_actions'][$mod_action['is_custom']]['actions'][$actual_filename]['operations'][] = array( |
|
501 | + if (isset($mod_action['is_custom']) && isset($context['theme_actions'][$mod_action['is_custom']])) { |
|
502 | + $context['theme_actions'][$mod_action['is_custom']]['actions'][$actual_filename]['operations'][] = array( |
|
490 | 503 | 'type' => $txt['execute_modification'], |
491 | 504 | 'action' => $smcFunc['htmlspecialchars'](strtr($mod_action['filename'], array($boarddir => '.'))), |
492 | 505 | 'description' => $mod_action['failed'] ? $txt['package_action_failure'] : $txt['package_action_success'], |
@@ -497,59 +510,55 @@ discard block |
||
497 | 510 | 'failed' => $mod_action['failed'], |
498 | 511 | 'ignore_failure' => !empty($mod_action['ignore_failure']), |
499 | 512 | ); |
513 | + } |
|
500 | 514 | } |
501 | 515 | } |
502 | 516 | } |
503 | - } |
|
504 | - elseif ($action['type'] == 'code') |
|
517 | + } elseif ($action['type'] == 'code') |
|
505 | 518 | { |
506 | 519 | $thisAction = array( |
507 | 520 | 'type' => $txt['execute_code'], |
508 | 521 | 'action' => $smcFunc['htmlspecialchars']($action['filename']), |
509 | 522 | ); |
510 | - } |
|
511 | - elseif ($action['type'] == 'database') |
|
523 | + } elseif ($action['type'] == 'database') |
|
512 | 524 | { |
513 | 525 | $thisAction = array( |
514 | 526 | 'type' => $txt['execute_database_changes'], |
515 | 527 | 'action' => $smcFunc['htmlspecialchars']($action['filename']), |
516 | 528 | ); |
517 | - } |
|
518 | - elseif (in_array($action['type'], array('create-dir', 'create-file'))) |
|
529 | + } elseif (in_array($action['type'], array('create-dir', 'create-file'))) |
|
519 | 530 | { |
520 | 531 | $thisAction = array( |
521 | 532 | 'type' => $txt['package_create'] . ' ' . ($action['type'] == 'create-dir' ? $txt['package_tree'] : $txt['package_file']), |
522 | 533 | 'action' => $smcFunc['htmlspecialchars'](strtr($action['destination'], array($boarddir => '.'))) |
523 | 534 | ); |
524 | - } |
|
525 | - elseif ($action['type'] == 'hook') |
|
535 | + } elseif ($action['type'] == 'hook') |
|
526 | 536 | { |
527 | 537 | $action['description'] = !isset($action['hook'], $action['function']) ? $txt['package_action_failure'] : $txt['package_action_success']; |
528 | 538 | |
529 | - if (!isset($action['hook'], $action['function'])) |
|
530 | - $context['has_failure'] = true; |
|
539 | + if (!isset($action['hook'], $action['function'])) { |
|
540 | + $context['has_failure'] = true; |
|
541 | + } |
|
531 | 542 | |
532 | 543 | $thisAction = array( |
533 | 544 | 'type' => $action['reverse'] ? $txt['execute_hook_remove'] : $txt['execute_hook_add'], |
534 | 545 | 'action' => sprintf($txt['execute_hook_action' . ($action['reverse'] ? '_inverse' : '')], $smcFunc['htmlspecialchars']($action['hook'])), |
535 | 546 | ); |
536 | - } |
|
537 | - elseif ($action['type'] == 'credits') |
|
547 | + } elseif ($action['type'] == 'credits') |
|
538 | 548 | { |
539 | 549 | $thisAction = array( |
540 | 550 | 'type' => $txt['execute_credits_add'], |
541 | 551 | 'action' => sprintf($txt['execute_credits_action'], $smcFunc['htmlspecialchars']($action['title'])), |
542 | 552 | ); |
543 | - } |
|
544 | - elseif ($action['type'] == 'requires') |
|
553 | + } elseif ($action['type'] == 'requires') |
|
545 | 554 | { |
546 | 555 | $installed = false; |
547 | 556 | $version = true; |
548 | 557 | |
549 | 558 | // package missing required values? |
550 | - if (!isset($action['id'])) |
|
551 | - $context['has_failure'] = true; |
|
552 | - else |
|
559 | + if (!isset($action['id'])) { |
|
560 | + $context['has_failure'] = true; |
|
561 | + } else |
|
553 | 562 | { |
554 | 563 | // See if this dependancy is installed |
555 | 564 | $request = $smcFunc['db_query']('', ' |
@@ -565,8 +574,9 @@ discard block |
||
565 | 574 | ) |
566 | 575 | ); |
567 | 576 | $installed = ($smcFunc['db_num_rows']($request) !== 0); |
568 | - if ($installed) |
|
569 | - list ($version) = $smcFunc['db_fetch_row']($request); |
|
577 | + if ($installed) { |
|
578 | + list ($version) = $smcFunc['db_fetch_row']($request); |
|
579 | + } |
|
570 | 580 | $smcFunc['db_free_result']($request); |
571 | 581 | |
572 | 582 | // do a version level check (if requested) in the most basic way |
@@ -581,8 +591,7 @@ discard block |
||
581 | 591 | 'type' => $txt['package_requires'], |
582 | 592 | 'action' => $txt['package_check_for'] . ' ' . $action['id'] . (isset($action['version']) ? (' / ' . ($version ? $action['version'] : '<span class="error">' . $action['version'] . '</span>')) : ''), |
583 | 593 | ); |
584 | - } |
|
585 | - elseif (in_array($action['type'], array('require-dir', 'require-file'))) |
|
594 | + } elseif (in_array($action['type'], array('require-dir', 'require-file'))) |
|
586 | 595 | { |
587 | 596 | // Do this one... |
588 | 597 | $thisAction = array( |
@@ -596,26 +605,29 @@ discard block |
||
596 | 605 | // Is the action already stated? |
597 | 606 | $theme_action = !empty($action['theme_action']) && in_array($action['theme_action'], array('no', 'yes', 'auto')) ? $action['theme_action'] : 'auto'; |
598 | 607 | // If it's not auto do we think we have something we can act upon? |
599 | - if ($theme_action != 'auto' && !in_array($matches[1], array('languagedir', 'languages_dir', 'imagesdir', 'themedir'))) |
|
600 | - $theme_action = ''; |
|
608 | + if ($theme_action != 'auto' && !in_array($matches[1], array('languagedir', 'languages_dir', 'imagesdir', 'themedir'))) { |
|
609 | + $theme_action = ''; |
|
610 | + } |
|
601 | 611 | // ... or if it's auto do we even want to do anything? |
602 | - elseif ($theme_action == 'auto' && $matches[1] != 'imagesdir') |
|
603 | - $theme_action = ''; |
|
612 | + elseif ($theme_action == 'auto' && $matches[1] != 'imagesdir') { |
|
613 | + $theme_action = ''; |
|
614 | + } |
|
604 | 615 | |
605 | 616 | // So, we still want to do something? |
606 | - if ($theme_action != '') |
|
607 | - $themeFinds['candidates'][] = $action; |
|
617 | + if ($theme_action != '') { |
|
618 | + $themeFinds['candidates'][] = $action; |
|
619 | + } |
|
608 | 620 | // Otherwise is this is going into another theme record it. |
609 | - elseif ($matches[1] == 'themes_dir') |
|
610 | - $themeFinds['other_themes'][] = strtolower(strtr(parse_path($action['unparsed_destination']), array('\\' => '/')) . '/' . basename($action['filename'])); |
|
621 | + elseif ($matches[1] == 'themes_dir') { |
|
622 | + $themeFinds['other_themes'][] = strtolower(strtr(parse_path($action['unparsed_destination']), array('\\' => '/')) . '/' . basename($action['filename'])); |
|
623 | + } |
|
611 | 624 | } |
612 | - } |
|
613 | - elseif (in_array($action['type'], array('move-dir', 'move-file'))) |
|
614 | - $thisAction = array( |
|
625 | + } elseif (in_array($action['type'], array('move-dir', 'move-file'))) { |
|
626 | + $thisAction = array( |
|
615 | 627 | 'type' => $txt['package_move'] . ' ' . ($action['type'] == 'move-dir' ? $txt['package_tree'] : $txt['package_file']), |
616 | 628 | 'action' => $smcFunc['htmlspecialchars'](strtr($action['source'], array($boarddir => '.'))) . ' => ' . $smcFunc['htmlspecialchars'](strtr($action['destination'], array($boarddir => '.'))) |
617 | 629 | ); |
618 | - elseif (in_array($action['type'], array('remove-dir', 'remove-file'))) |
|
630 | + } elseif (in_array($action['type'], array('remove-dir', 'remove-file'))) |
|
619 | 631 | { |
620 | 632 | $thisAction = array( |
621 | 633 | 'type' => $txt['package_delete'] . ' ' . ($action['type'] == 'remove-dir' ? $txt['package_tree'] : $txt['package_file']), |
@@ -631,30 +643,36 @@ discard block |
||
631 | 643 | $action['unparsed_destination'] = $action['unparsed_filename']; |
632 | 644 | |
633 | 645 | // If it's not auto do we think we have something we can act upon? |
634 | - if ($theme_action != 'auto' && !in_array($matches[1], array('languagedir', 'languages_dir', 'imagesdir', 'themedir'))) |
|
635 | - $theme_action = ''; |
|
646 | + if ($theme_action != 'auto' && !in_array($matches[1], array('languagedir', 'languages_dir', 'imagesdir', 'themedir'))) { |
|
647 | + $theme_action = ''; |
|
648 | + } |
|
636 | 649 | // ... or if it's auto do we even want to do anything? |
637 | - elseif ($theme_action == 'auto' && $matches[1] != 'imagesdir') |
|
638 | - $theme_action = ''; |
|
650 | + elseif ($theme_action == 'auto' && $matches[1] != 'imagesdir') { |
|
651 | + $theme_action = ''; |
|
652 | + } |
|
639 | 653 | |
640 | 654 | // So, we still want to do something? |
641 | - if ($theme_action != '') |
|
642 | - $themeFinds['candidates'][] = $action; |
|
655 | + if ($theme_action != '') { |
|
656 | + $themeFinds['candidates'][] = $action; |
|
657 | + } |
|
643 | 658 | // Otherwise is this is going into another theme record it. |
644 | - elseif ($matches[1] == 'themes_dir') |
|
645 | - $themeFinds['other_themes'][] = strtolower(strtr(parse_path($action['unparsed_filename']), array('\\' => '/')) . '/' . basename($action['filename'])); |
|
659 | + elseif ($matches[1] == 'themes_dir') { |
|
660 | + $themeFinds['other_themes'][] = strtolower(strtr(parse_path($action['unparsed_filename']), array('\\' => '/')) . '/' . basename($action['filename'])); |
|
661 | + } |
|
646 | 662 | } |
647 | 663 | } |
648 | 664 | |
649 | - if (empty($thisAction)) |
|
650 | - continue; |
|
665 | + if (empty($thisAction)) { |
|
666 | + continue; |
|
667 | + } |
|
651 | 668 | |
652 | 669 | if (!in_array($action['type'], array('hook', 'credits'))) |
653 | 670 | { |
654 | - if ($context['uninstalling']) |
|
655 | - $file = in_array($action['type'], array('remove-dir', 'remove-file')) ? $action['filename'] : $packagesdir . '/temp/' . $context['base_path'] . $action['filename']; |
|
656 | - else |
|
657 | - $file = $packagesdir . '/temp/' . $context['base_path'] . $action['filename']; |
|
671 | + if ($context['uninstalling']) { |
|
672 | + $file = in_array($action['type'], array('remove-dir', 'remove-file')) ? $action['filename'] : $packagesdir . '/temp/' . $context['base_path'] . $action['filename']; |
|
673 | + } else { |
|
674 | + $file = $packagesdir . '/temp/' . $context['base_path'] . $action['filename']; |
|
675 | + } |
|
658 | 676 | } |
659 | 677 | |
660 | 678 | // Don't fail if a file/directory we're trying to create doesn't exist... |
@@ -669,8 +687,9 @@ discard block |
||
669 | 687 | } |
670 | 688 | |
671 | 689 | // @todo None given? |
672 | - if (empty($thisAction['description'])) |
|
673 | - $thisAction['description'] = isset($action['description']) ? $action['description'] : ''; |
|
690 | + if (empty($thisAction['description'])) { |
|
691 | + $thisAction['description'] = isset($action['description']) ? $action['description'] : ''; |
|
692 | + } |
|
674 | 693 | |
675 | 694 | $context['actions'][] = $thisAction; |
676 | 695 | } |
@@ -683,18 +702,21 @@ discard block |
||
683 | 702 | // Get the part of the file we'll be dealing with. |
684 | 703 | preg_match('~^\$(languagedir|languages_dir|imagesdir|themedir)(\\|/)*(.+)*~i', $action_data['unparsed_destination'], $matches); |
685 | 704 | |
686 | - if ($matches[1] == 'imagesdir') |
|
687 | - $path = '/' . basename($settings['default_images_url']); |
|
688 | - elseif ($matches[1] == 'languagedir' || $matches[1] == 'languages_dir') |
|
689 | - $path = '/languages'; |
|
690 | - else |
|
691 | - $path = ''; |
|
705 | + if ($matches[1] == 'imagesdir') { |
|
706 | + $path = '/' . basename($settings['default_images_url']); |
|
707 | + } elseif ($matches[1] == 'languagedir' || $matches[1] == 'languages_dir') { |
|
708 | + $path = '/languages'; |
|
709 | + } else { |
|
710 | + $path = ''; |
|
711 | + } |
|
692 | 712 | |
693 | - if (!empty($matches[3])) |
|
694 | - $path .= $matches[3]; |
|
713 | + if (!empty($matches[3])) { |
|
714 | + $path .= $matches[3]; |
|
715 | + } |
|
695 | 716 | |
696 | - if (!$context['uninstalling']) |
|
697 | - $path .= '/' . basename($action_data['filename']); |
|
717 | + if (!$context['uninstalling']) { |
|
718 | + $path .= '/' . basename($action_data['filename']); |
|
719 | + } |
|
698 | 720 | |
699 | 721 | // Loop through each custom theme to note it's candidacy! |
700 | 722 | foreach ($theme_paths as $id => $theme_data) |
@@ -710,36 +732,40 @@ discard block |
||
710 | 732 | if (!mktree(dirname($real_path), false)) |
711 | 733 | { |
712 | 734 | $temp = dirname($real_path); |
713 | - while (!file_exists($temp) && strlen($temp) > 1) |
|
714 | - $temp = dirname($temp); |
|
735 | + while (!file_exists($temp) && strlen($temp) > 1) { |
|
736 | + $temp = dirname($temp); |
|
737 | + } |
|
715 | 738 | $chmod_files[] = $temp; |
716 | 739 | } |
717 | 740 | |
718 | - if ($action_data['type'] == 'require-dir' && !is_writable($real_path) && (file_exists($real_path) || !is_writable(dirname($real_path)))) |
|
719 | - $chmod_files[] = $real_path; |
|
741 | + if ($action_data['type'] == 'require-dir' && !is_writable($real_path) && (file_exists($real_path) || !is_writable(dirname($real_path)))) { |
|
742 | + $chmod_files[] = $real_path; |
|
743 | + } |
|
720 | 744 | |
721 | - if (!isset($context['theme_actions'][$id])) |
|
722 | - $context['theme_actions'][$id] = array( |
|
745 | + if (!isset($context['theme_actions'][$id])) { |
|
746 | + $context['theme_actions'][$id] = array( |
|
723 | 747 | 'name' => $theme_data['name'], |
724 | 748 | 'actions' => array(), |
725 | 749 | ); |
750 | + } |
|
726 | 751 | |
727 | - if ($context['uninstalling']) |
|
728 | - $context['theme_actions'][$id]['actions'][] = array( |
|
752 | + if ($context['uninstalling']) { |
|
753 | + $context['theme_actions'][$id]['actions'][] = array( |
|
729 | 754 | 'type' => $txt['package_delete'] . ' ' . ($action_data['type'] == 'require-dir' ? $txt['package_tree'] : $txt['package_file']), |
730 | 755 | 'action' => strtr($real_path, array('\\' => '/', $boarddir => '.')), |
731 | 756 | 'description' => '', |
732 | 757 | 'value' => base64_encode(json_encode(array('type' => $action_data['type'], 'orig' => $action_data['filename'], 'future' => $real_path, 'id' => $id))), |
733 | 758 | 'not_mod' => true, |
734 | 759 | ); |
735 | - else |
|
736 | - $context['theme_actions'][$id]['actions'][] = array( |
|
760 | + } else { |
|
761 | + $context['theme_actions'][$id]['actions'][] = array( |
|
737 | 762 | 'type' => $txt['package_extract'] . ' ' . ($action_data['type'] == 'require-dir' ? $txt['package_tree'] : $txt['package_file']), |
738 | 763 | 'action' => strtr($real_path, array('\\' => '/', $boarddir => '.')), |
739 | 764 | 'description' => '', |
740 | 765 | 'value' => base64_encode(json_encode(array('type' => $action_data['type'], 'orig' => $action_data['destination'], 'future' => $real_path, 'id' => $id))), |
741 | 766 | 'not_mod' => true, |
742 | 767 | ); |
768 | + } |
|
743 | 769 | } |
744 | 770 | } |
745 | 771 | } |
@@ -749,8 +775,9 @@ discard block |
||
749 | 775 | // Trash the cache... which will also check permissions for us! |
750 | 776 | package_flush_cache(true); |
751 | 777 | |
752 | - if (file_exists($packagesdir . '/temp')) |
|
753 | - deltree($packagesdir . '/temp'); |
|
778 | + if (file_exists($packagesdir . '/temp')) { |
|
779 | + deltree($packagesdir . '/temp'); |
|
780 | + } |
|
754 | 781 | |
755 | 782 | if (!empty($chmod_files)) |
756 | 783 | { |
@@ -775,8 +802,9 @@ discard block |
||
775 | 802 | checkSession(); |
776 | 803 | |
777 | 804 | // If there's no file, what are we installing? |
778 | - if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') |
|
779 | - redirectexit('action=admin;area=packages'); |
|
805 | + if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') { |
|
806 | + redirectexit('action=admin;area=packages'); |
|
807 | + } |
|
780 | 808 | $context['filename'] = $_REQUEST['package']; |
781 | 809 | |
782 | 810 | // If this is an uninstall, we'll have an id. |
@@ -797,51 +825,55 @@ discard block |
||
797 | 825 | |
798 | 826 | $context['sub_template'] = 'extract_package'; |
799 | 827 | |
800 | - if (!file_exists($packagesdir . '/' . $context['filename'])) |
|
801 | - fatal_lang_error('package_no_file', false); |
|
828 | + if (!file_exists($packagesdir . '/' . $context['filename'])) { |
|
829 | + fatal_lang_error('package_no_file', false); |
|
830 | + } |
|
802 | 831 | |
803 | 832 | // Load up the package FTP information? |
804 | 833 | create_chmod_control(array(), array('destination_url' => $scripturl . '?action=admin;area=packages;sa=' . $_REQUEST['sa'] . ';package=' . $_REQUEST['package'])); |
805 | 834 | |
806 | 835 | // Make sure temp directory exists and is empty! |
807 | - if (file_exists($packagesdir . '/temp')) |
|
808 | - deltree($packagesdir . '/temp', false); |
|
809 | - else |
|
810 | - mktree($packagesdir . '/temp', 0777); |
|
836 | + if (file_exists($packagesdir . '/temp')) { |
|
837 | + deltree($packagesdir . '/temp', false); |
|
838 | + } else { |
|
839 | + mktree($packagesdir . '/temp', 0777); |
|
840 | + } |
|
811 | 841 | |
812 | 842 | // Let the unpacker do the work. |
813 | 843 | if (is_file($packagesdir . '/' . $context['filename'])) |
814 | 844 | { |
815 | 845 | $context['extracted_files'] = read_tgz_file($packagesdir . '/' . $context['filename'], $packagesdir . '/temp'); |
816 | 846 | |
817 | - if (!file_exists($packagesdir . '/temp/package-info.xml')) |
|
818 | - foreach ($context['extracted_files'] as $file) |
|
847 | + if (!file_exists($packagesdir . '/temp/package-info.xml')) { |
|
848 | + foreach ($context['extracted_files'] as $file) |
|
819 | 849 | if (basename($file['filename']) == 'package-info.xml') |
820 | 850 | { |
821 | 851 | $context['base_path'] = dirname($file['filename']) . '/'; |
852 | + } |
|
822 | 853 | break; |
823 | 854 | } |
824 | 855 | |
825 | - if (!isset($context['base_path'])) |
|
826 | - $context['base_path'] = ''; |
|
827 | - } |
|
828 | - elseif (is_dir($packagesdir . '/' . $context['filename'])) |
|
856 | + if (!isset($context['base_path'])) { |
|
857 | + $context['base_path'] = ''; |
|
858 | + } |
|
859 | + } elseif (is_dir($packagesdir . '/' . $context['filename'])) |
|
829 | 860 | { |
830 | 861 | copytree($packagesdir . '/' . $context['filename'], $packagesdir . '/temp'); |
831 | 862 | $context['extracted_files'] = listtree($packagesdir . '/temp'); |
832 | 863 | $context['base_path'] = ''; |
864 | + } else { |
|
865 | + fatal_lang_error('no_access', false); |
|
833 | 866 | } |
834 | - else |
|
835 | - fatal_lang_error('no_access', false); |
|
836 | 867 | |
837 | 868 | // Are we installing this into any custom themes? |
838 | 869 | $custom_themes = array(1); |
839 | 870 | $known_themes = explode(',', $modSettings['knownThemes']); |
840 | 871 | if (!empty($_POST['custom_theme'])) |
841 | 872 | { |
842 | - foreach ($_POST['custom_theme'] as $tid) |
|
843 | - if (in_array($tid, $known_themes)) |
|
873 | + foreach ($_POST['custom_theme'] as $tid) { |
|
874 | + if (in_array($tid, $known_themes)) |
|
844 | 875 | $custom_themes[] = (int) $tid; |
876 | + } |
|
845 | 877 | } |
846 | 878 | |
847 | 879 | // Now load up the paths of the themes that we need to know about. |
@@ -858,8 +890,9 @@ discard block |
||
858 | 890 | ); |
859 | 891 | $theme_paths = array(); |
860 | 892 | $themes_installed = array(1); |
861 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
862 | - $theme_paths[$row['id_theme']][$row['variable']] = $row['value']; |
|
893 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
894 | + $theme_paths[$row['id_theme']][$row['variable']] = $row['value']; |
|
895 | + } |
|
863 | 896 | $smcFunc['db_free_result']($request); |
864 | 897 | |
865 | 898 | // Are there any theme copying that we want to take place? |
@@ -871,11 +904,13 @@ discard block |
||
871 | 904 | { |
872 | 905 | foreach ($_POST['theme_changes'] as $change) |
873 | 906 | { |
874 | - if (empty($change)) |
|
875 | - continue; |
|
907 | + if (empty($change)) { |
|
908 | + continue; |
|
909 | + } |
|
876 | 910 | $theme_data = smf_json_decode(base64_decode($change), true); |
877 | - if (empty($theme_data['type'])) |
|
878 | - continue; |
|
911 | + if (empty($theme_data['type'])) { |
|
912 | + continue; |
|
913 | + } |
|
879 | 914 | |
880 | 915 | $themes_installed[] = $theme_data['id']; |
881 | 916 | $context['theme_copies'][$theme_data['type']][$theme_data['orig']][] = $theme_data['future']; |
@@ -884,8 +919,9 @@ discard block |
||
884 | 919 | |
885 | 920 | // Get the package info... |
886 | 921 | $packageInfo = getPackageInfo($context['filename']); |
887 | - if (!is_array($packageInfo)) |
|
888 | - fatal_lang_error($packageInfo); |
|
922 | + if (!is_array($packageInfo)) { |
|
923 | + fatal_lang_error($packageInfo); |
|
924 | + } |
|
889 | 925 | |
890 | 926 | $packageInfo['filename'] = $context['filename']; |
891 | 927 | |
@@ -897,8 +933,9 @@ discard block |
||
897 | 933 | { |
898 | 934 | $_SESSION['last_backup_for'] = $context['filename'] . ($context['uninstalling'] ? '$$' : '$'); |
899 | 935 | $result = package_create_backup(($context['uninstalling'] ? 'backup_' : 'before_') . strtok($context['filename'], '.')); |
900 | - if (!$result) |
|
901 | - fatal_lang_error('could_not_package_backup', false); |
|
936 | + if (!$result) { |
|
937 | + fatal_lang_error('could_not_package_backup', false); |
|
938 | + } |
|
902 | 939 | } |
903 | 940 | |
904 | 941 | // The mod isn't installed.... unless proven otherwise. |
@@ -938,35 +975,38 @@ discard block |
||
938 | 975 | $install_log = parsePackageInfo($packageInfo['xml'], false, 'uninstall'); |
939 | 976 | |
940 | 977 | // Gadzooks! There's no uninstaller at all!? |
941 | - if (empty($install_log)) |
|
942 | - fatal_lang_error('package_uninstall_cannot', false); |
|
978 | + if (empty($install_log)) { |
|
979 | + fatal_lang_error('package_uninstall_cannot', false); |
|
980 | + } |
|
943 | 981 | |
944 | 982 | // They can only uninstall from what it was originally installed into. |
945 | - foreach ($theme_paths as $id => $data) |
|
946 | - if ($id != 1 && !in_array($id, $old_themes)) |
|
983 | + foreach ($theme_paths as $id => $data) { |
|
984 | + if ($id != 1 && !in_array($id, $old_themes)) |
|
947 | 985 | unset($theme_paths[$id]); |
948 | - } |
|
949 | - elseif (isset($old_version) && $old_version != $packageInfo['version']) |
|
986 | + } |
|
987 | + } elseif (isset($old_version) && $old_version != $packageInfo['version']) |
|
950 | 988 | { |
951 | 989 | // Look for an upgrade... |
952 | 990 | $install_log = parsePackageInfo($packageInfo['xml'], false, 'upgrade', $old_version); |
953 | 991 | |
954 | 992 | // There was no upgrade.... |
955 | - if (empty($install_log)) |
|
956 | - $context['is_installed'] = true; |
|
957 | - else |
|
993 | + if (empty($install_log)) { |
|
994 | + $context['is_installed'] = true; |
|
995 | + } else |
|
958 | 996 | { |
959 | 997 | // Upgrade previous themes only! |
960 | - foreach ($theme_paths as $id => $data) |
|
961 | - if ($id != 1 && !in_array($id, $old_themes)) |
|
998 | + foreach ($theme_paths as $id => $data) { |
|
999 | + if ($id != 1 && !in_array($id, $old_themes)) |
|
962 | 1000 | unset($theme_paths[$id]); |
1001 | + } |
|
963 | 1002 | } |
1003 | + } elseif (isset($old_version) && $old_version == $packageInfo['version']) { |
|
1004 | + $context['is_installed'] = true; |
|
964 | 1005 | } |
965 | - elseif (isset($old_version) && $old_version == $packageInfo['version']) |
|
966 | - $context['is_installed'] = true; |
|
967 | 1006 | |
968 | - if (!isset($old_version) || $context['is_installed']) |
|
969 | - $install_log = parsePackageInfo($packageInfo['xml'], false, 'install'); |
|
1007 | + if (!isset($old_version) || $context['is_installed']) { |
|
1008 | + $install_log = parsePackageInfo($packageInfo['xml'], false, 'install'); |
|
1009 | + } |
|
970 | 1010 | |
971 | 1011 | $context['install_finished'] = false; |
972 | 1012 | |
@@ -983,37 +1023,39 @@ discard block |
||
983 | 1023 | |
984 | 1024 | if ($action['type'] == 'modification' && !empty($action['filename'])) |
985 | 1025 | { |
986 | - if ($action['boardmod']) |
|
987 | - $mod_actions = parseBoardMod(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), false, $action['reverse'], $theme_paths); |
|
988 | - else |
|
989 | - $mod_actions = parseModification(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), false, $action['reverse'], $theme_paths); |
|
1026 | + if ($action['boardmod']) { |
|
1027 | + $mod_actions = parseBoardMod(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), false, $action['reverse'], $theme_paths); |
|
1028 | + } else { |
|
1029 | + $mod_actions = parseModification(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), false, $action['reverse'], $theme_paths); |
|
1030 | + } |
|
990 | 1031 | |
991 | 1032 | // Any errors worth noting? |
992 | 1033 | foreach ($mod_actions as $key => $action) |
993 | 1034 | { |
994 | - if ($action['type'] == 'failure') |
|
995 | - $failed_steps[] = array( |
|
1035 | + if ($action['type'] == 'failure') { |
|
1036 | + $failed_steps[] = array( |
|
996 | 1037 | 'file' => $action['filename'], |
997 | 1038 | 'large_step' => $failed_count, |
998 | 1039 | 'sub_step' => $key, |
999 | 1040 | 'theme' => 1, |
1000 | 1041 | ); |
1042 | + } |
|
1001 | 1043 | |
1002 | 1044 | // Gather the themes we installed into. |
1003 | - if (!empty($action['is_custom'])) |
|
1004 | - $themes_installed[] = $action['is_custom']; |
|
1045 | + if (!empty($action['is_custom'])) { |
|
1046 | + $themes_installed[] = $action['is_custom']; |
|
1047 | + } |
|
1005 | 1048 | } |
1006 | - } |
|
1007 | - elseif ($action['type'] == 'code' && !empty($action['filename'])) |
|
1049 | + } elseif ($action['type'] == 'code' && !empty($action['filename'])) |
|
1008 | 1050 | { |
1009 | 1051 | // This is just here as reference for what is available. |
1010 | 1052 | global $txt, $boarddir, $sourcedir, $modSettings, $context, $settings, $forum_version, $smcFunc; |
1011 | 1053 | |
1012 | 1054 | // Now include the file and be done with it ;). |
1013 | - if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename'])) |
|
1014 | - require($packagesdir . '/temp/' . $context['base_path'] . $action['filename']); |
|
1015 | - } |
|
1016 | - elseif ($action['type'] == 'credits') |
|
1055 | + if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename'])) { |
|
1056 | + require($packagesdir . '/temp/' . $context['base_path'] . $action['filename']); |
|
1057 | + } |
|
1058 | + } elseif ($action['type'] == 'credits') |
|
1017 | 1059 | { |
1018 | 1060 | // Time to build the billboard |
1019 | 1061 | $credits_tag = array( |
@@ -1023,13 +1065,13 @@ discard block |
||
1023 | 1065 | 'copyright' => $action['copyright'], |
1024 | 1066 | 'title' => $action['title'], |
1025 | 1067 | ); |
1026 | - } |
|
1027 | - elseif ($action['type'] == 'hook' && isset($action['hook'], $action['function'])) |
|
1068 | + } elseif ($action['type'] == 'hook' && isset($action['hook'], $action['function'])) |
|
1028 | 1069 | { |
1029 | - if ($action['reverse']) |
|
1030 | - remove_integration_function($action['hook'], $action['function'], true, $action['include_file'], $action['object']); |
|
1031 | - else |
|
1032 | - add_integration_function($action['hook'], $action['function'], true, $action['include_file'], $action['object']); |
|
1070 | + if ($action['reverse']) { |
|
1071 | + remove_integration_function($action['hook'], $action['function'], true, $action['include_file'], $action['object']); |
|
1072 | + } else { |
|
1073 | + add_integration_function($action['hook'], $action['function'], true, $action['include_file'], $action['object']); |
|
1074 | + } |
|
1033 | 1075 | } |
1034 | 1076 | // Only do the database changes on uninstall if requested. |
1035 | 1077 | elseif ($action['type'] == 'database' && !empty($action['filename']) && (!$context['uninstalling'] || !empty($_POST['do_db_changes']))) |
@@ -1042,8 +1084,9 @@ discard block |
||
1042 | 1084 | db_extend('packages'); |
1043 | 1085 | |
1044 | 1086 | // Let the file work its magic ;) |
1045 | - if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename'])) |
|
1046 | - require($packagesdir . '/temp/' . $context['base_path'] . $action['filename']); |
|
1087 | + if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename'])) { |
|
1088 | + require($packagesdir . '/temp/' . $context['base_path'] . $action['filename']); |
|
1089 | + } |
|
1047 | 1090 | } |
1048 | 1091 | // Handle a redirect... |
1049 | 1092 | elseif ($action['type'] == 'redirect' && !empty($action['redirect_url'])) |
@@ -1125,8 +1168,9 @@ discard block |
||
1125 | 1168 | reloadSettings(); |
1126 | 1169 | |
1127 | 1170 | // Any db changes from older version? |
1128 | - if (!empty($old_db_changes)) |
|
1129 | - $db_package_log = empty($db_package_log) ? $old_db_changes : array_merge($old_db_changes, $db_package_log); |
|
1171 | + if (!empty($old_db_changes)) { |
|
1172 | + $db_package_log = empty($db_package_log) ? $old_db_changes : array_merge($old_db_changes, $db_package_log); |
|
1173 | + } |
|
1130 | 1174 | |
1131 | 1175 | // If there are some database changes we might want to remove then filter them out. |
1132 | 1176 | if (!empty($db_package_log)) |
@@ -1142,22 +1186,24 @@ discard block |
||
1142 | 1186 | */ |
1143 | 1187 | function sort_table_first($a, $b) |
1144 | 1188 | { |
1145 | - if ($a[0] == $b[0]) |
|
1146 | - return 0; |
|
1189 | + if ($a[0] == $b[0]) { |
|
1190 | + return 0; |
|
1191 | + } |
|
1147 | 1192 | return $a[0] == 'remove_table' ? -1 : 1; |
1148 | 1193 | } |
1149 | 1194 | usort($db_package_log, 'sort_table_first'); |
1150 | 1195 | foreach ($db_package_log as $k => $log) |
1151 | 1196 | { |
1152 | - if ($log[0] == 'remove_table') |
|
1153 | - $tables[] = $log[1]; |
|
1154 | - elseif (in_array($log[1], $tables)) |
|
1155 | - unset($db_package_log[$k]); |
|
1197 | + if ($log[0] == 'remove_table') { |
|
1198 | + $tables[] = $log[1]; |
|
1199 | + } elseif (in_array($log[1], $tables)) { |
|
1200 | + unset($db_package_log[$k]); |
|
1201 | + } |
|
1156 | 1202 | } |
1157 | 1203 | $db_changes = json_encode($db_package_log); |
1204 | + } else { |
|
1205 | + $db_changes = ''; |
|
1158 | 1206 | } |
1159 | - else |
|
1160 | - $db_changes = ''; |
|
1161 | 1207 | |
1162 | 1208 | // What themes did we actually install? |
1163 | 1209 | $themes_installed = array_unique($themes_installed); |
@@ -1206,18 +1252,20 @@ discard block |
||
1206 | 1252 | |
1207 | 1253 | foreach ($db_changes as $change) |
1208 | 1254 | { |
1209 | - if ($change[0] == 'remove_table' && isset($change[1])) |
|
1210 | - $smcFunc['db_drop_table']($change[1]); |
|
1211 | - elseif ($change[0] == 'remove_column' && isset($change[2])) |
|
1212 | - $smcFunc['db_remove_column']($change[1], $change[2]); |
|
1213 | - elseif ($change[0] == 'remove_index' && isset($change[2])) |
|
1214 | - $smcFunc['db_remove_index']($change[1], $change[2]); |
|
1255 | + if ($change[0] == 'remove_table' && isset($change[1])) { |
|
1256 | + $smcFunc['db_drop_table']($change[1]); |
|
1257 | + } elseif ($change[0] == 'remove_column' && isset($change[2])) { |
|
1258 | + $smcFunc['db_remove_column']($change[1], $change[2]); |
|
1259 | + } elseif ($change[0] == 'remove_index' && isset($change[2])) { |
|
1260 | + $smcFunc['db_remove_index']($change[1], $change[2]); |
|
1261 | + } |
|
1215 | 1262 | } |
1216 | 1263 | } |
1217 | 1264 | |
1218 | 1265 | // Clean house... get rid of the evidence ;). |
1219 | - if (file_exists($packagesdir . '/temp')) |
|
1220 | - deltree($packagesdir . '/temp'); |
|
1266 | + if (file_exists($packagesdir . '/temp')) { |
|
1267 | + deltree($packagesdir . '/temp'); |
|
1268 | + } |
|
1221 | 1269 | |
1222 | 1270 | // Log what we just did. |
1223 | 1271 | logAction($context['uninstalling'] ? 'uninstall_package' : (!empty($is_upgrade) ? 'upgrade_package' : 'install_package'), array('package' => $smcFunc['htmlspecialchars']($packageInfo['name']), 'version' => $smcFunc['htmlspecialchars']($packageInfo['version'])), 'admin'); |
@@ -1239,8 +1287,9 @@ discard block |
||
1239 | 1287 | require_once($sourcedir . '/Subs-Package.php'); |
1240 | 1288 | |
1241 | 1289 | // No package? Show him or her the door. |
1242 | - if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') |
|
1243 | - redirectexit('action=admin;area=packages'); |
|
1290 | + if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') { |
|
1291 | + redirectexit('action=admin;area=packages'); |
|
1292 | + } |
|
1244 | 1293 | |
1245 | 1294 | $context['linktree'][] = array( |
1246 | 1295 | 'url' => $scripturl . '?action=admin;area=packages;sa=list;package=' . $_REQUEST['package'], |
@@ -1253,11 +1302,12 @@ discard block |
||
1253 | 1302 | $context['filename'] = $_REQUEST['package']; |
1254 | 1303 | |
1255 | 1304 | // Let the unpacker do the work. |
1256 | - if (is_file($packagesdir . '/' . $context['filename'])) |
|
1257 | - $context['files'] = read_tgz_file($packagesdir . '/' . $context['filename'], null); |
|
1258 | - elseif (is_dir($packagesdir . '/' . $context['filename'])) |
|
1259 | - $context['files'] = listtree($packagesdir . '/' . $context['filename']); |
|
1260 | -} |
|
1305 | + if (is_file($packagesdir . '/' . $context['filename'])) { |
|
1306 | + $context['files'] = read_tgz_file($packagesdir . '/' . $context['filename'], null); |
|
1307 | + } elseif (is_dir($packagesdir . '/' . $context['filename'])) { |
|
1308 | + $context['files'] = listtree($packagesdir . '/' . $context['filename']); |
|
1309 | + } |
|
1310 | + } |
|
1261 | 1311 | |
1262 | 1312 | /** |
1263 | 1313 | * Display one of the files in a package. |
@@ -1269,22 +1319,25 @@ discard block |
||
1269 | 1319 | require_once($sourcedir . '/Subs-Package.php'); |
1270 | 1320 | |
1271 | 1321 | // No package? Show him or her the door. |
1272 | - if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') |
|
1273 | - redirectexit('action=admin;area=packages'); |
|
1322 | + if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') { |
|
1323 | + redirectexit('action=admin;area=packages'); |
|
1324 | + } |
|
1274 | 1325 | |
1275 | 1326 | // No file? Show him or her the door. |
1276 | - if (!isset($_REQUEST['file']) || $_REQUEST['file'] == '') |
|
1277 | - redirectexit('action=admin;area=packages'); |
|
1327 | + if (!isset($_REQUEST['file']) || $_REQUEST['file'] == '') { |
|
1328 | + redirectexit('action=admin;area=packages'); |
|
1329 | + } |
|
1278 | 1330 | |
1279 | 1331 | $_REQUEST['package'] = preg_replace('~[\.]+~', '.', strtr($_REQUEST['package'], array('/' => '_', '\\' => '_'))); |
1280 | 1332 | $_REQUEST['file'] = preg_replace('~[\.]+~', '.', $_REQUEST['file']); |
1281 | 1333 | |
1282 | 1334 | if (isset($_REQUEST['raw'])) |
1283 | 1335 | { |
1284 | - if (is_file($packagesdir . '/' . $_REQUEST['package'])) |
|
1285 | - echo read_tgz_file($packagesdir . '/' . $_REQUEST['package'], $_REQUEST['file'], true); |
|
1286 | - elseif (is_dir($packagesdir . '/' . $_REQUEST['package'])) |
|
1287 | - echo file_get_contents($packagesdir . '/' . $_REQUEST['package'] . '/' . $_REQUEST['file']); |
|
1336 | + if (is_file($packagesdir . '/' . $_REQUEST['package'])) { |
|
1337 | + echo read_tgz_file($packagesdir . '/' . $_REQUEST['package'], $_REQUEST['file'], true); |
|
1338 | + } elseif (is_dir($packagesdir . '/' . $_REQUEST['package'])) { |
|
1339 | + echo file_get_contents($packagesdir . '/' . $_REQUEST['package'] . '/' . $_REQUEST['file']); |
|
1340 | + } |
|
1288 | 1341 | |
1289 | 1342 | obExit(false); |
1290 | 1343 | } |
@@ -1301,17 +1354,19 @@ discard block |
||
1301 | 1354 | $context['filename'] = $_REQUEST['file']; |
1302 | 1355 | |
1303 | 1356 | // Let the unpacker do the work.... but make sure we handle images properly. |
1304 | - if (in_array(strtolower(strrchr($_REQUEST['file'], '.')), array('.bmp', '.gif', '.jpeg', '.jpg', '.png'))) |
|
1305 | - $context['filedata'] = '<img src="' . $scripturl . '?action=admin;area=packages;sa=examine;package=' . $_REQUEST['package'] . ';file=' . $_REQUEST['file'] . ';raw" alt="' . $_REQUEST['file'] . '">'; |
|
1306 | - else |
|
1357 | + if (in_array(strtolower(strrchr($_REQUEST['file'], '.')), array('.bmp', '.gif', '.jpeg', '.jpg', '.png'))) { |
|
1358 | + $context['filedata'] = '<img src="' . $scripturl . '?action=admin;area=packages;sa=examine;package=' . $_REQUEST['package'] . ';file=' . $_REQUEST['file'] . ';raw" alt="' . $_REQUEST['file'] . '">'; |
|
1359 | + } else |
|
1307 | 1360 | { |
1308 | - if (is_file($packagesdir . '/' . $_REQUEST['package'])) |
|
1309 | - $context['filedata'] = $smcFunc['htmlspecialchars'](read_tgz_file($packagesdir . '/' . $_REQUEST['package'], $_REQUEST['file'], true)); |
|
1310 | - elseif (is_dir($packagesdir . '/' . $_REQUEST['package'])) |
|
1311 | - $context['filedata'] = $smcFunc['htmlspecialchars'](file_get_contents($packagesdir . '/' . $_REQUEST['package'] . '/' . $_REQUEST['file'])); |
|
1361 | + if (is_file($packagesdir . '/' . $_REQUEST['package'])) { |
|
1362 | + $context['filedata'] = $smcFunc['htmlspecialchars'](read_tgz_file($packagesdir . '/' . $_REQUEST['package'], $_REQUEST['file'], true)); |
|
1363 | + } elseif (is_dir($packagesdir . '/' . $_REQUEST['package'])) { |
|
1364 | + $context['filedata'] = $smcFunc['htmlspecialchars'](file_get_contents($packagesdir . '/' . $_REQUEST['package'] . '/' . $_REQUEST['file'])); |
|
1365 | + } |
|
1312 | 1366 | |
1313 | - if (strtolower(strrchr($_REQUEST['file'], '.')) == '.php') |
|
1314 | - $context['filedata'] = highlight_php_code($context['filedata']); |
|
1367 | + if (strtolower(strrchr($_REQUEST['file'], '.')) == '.php') { |
|
1368 | + $context['filedata'] = highlight_php_code($context['filedata']); |
|
1369 | + } |
|
1315 | 1370 | } |
1316 | 1371 | } |
1317 | 1372 | |
@@ -1326,8 +1381,9 @@ discard block |
||
1326 | 1381 | checkSession('get'); |
1327 | 1382 | |
1328 | 1383 | // Ack, don't allow deletion of arbitrary files here, could become a security hole somehow! |
1329 | - if (!isset($_GET['package']) || $_GET['package'] == 'index.php' || $_GET['package'] == 'backups') |
|
1330 | - redirectexit('action=admin;area=packages;sa=browse'); |
|
1384 | + if (!isset($_GET['package']) || $_GET['package'] == 'index.php' || $_GET['package'] == 'backups') { |
|
1385 | + redirectexit('action=admin;area=packages;sa=browse'); |
|
1386 | + } |
|
1331 | 1387 | $_GET['package'] = preg_replace('~[\.]+~', '.', strtr($_GET['package'], array('/' => '_', '\\' => '_'))); |
1332 | 1388 | |
1333 | 1389 | // Can't delete what's not there. |
@@ -1335,9 +1391,9 @@ discard block |
||
1335 | 1391 | { |
1336 | 1392 | create_chmod_control(array($packagesdir . '/' . $_GET['package']), array('destination_url' => $scripturl . '?action=admin;area=packages;sa=remove;package=' . $_GET['package'], 'crash_on_error' => true)); |
1337 | 1393 | |
1338 | - if (is_dir($packagesdir . '/' . $_GET['package'])) |
|
1339 | - deltree($packagesdir . '/' . $_GET['package']); |
|
1340 | - else |
|
1394 | + if (is_dir($packagesdir . '/' . $_GET['package'])) { |
|
1395 | + deltree($packagesdir . '/' . $_GET['package']); |
|
1396 | + } else |
|
1341 | 1397 | { |
1342 | 1398 | smf_chmod($packagesdir . '/' . $_GET['package'], 0777); |
1343 | 1399 | unlink($packagesdir . '/' . $_GET['package']); |
@@ -1385,8 +1441,9 @@ discard block |
||
1385 | 1441 | 'data' => array( |
1386 | 1442 | 'function' => function($package_md5) use ($type, &$context) |
1387 | 1443 | { |
1388 | - if (isset($context['available_' . $type . ''][$package_md5])) |
|
1389 | - return $context['available_' . $type . ''][$package_md5]['sort_id']; |
|
1444 | + if (isset($context['available_' . $type . ''][$package_md5])) { |
|
1445 | + return $context['available_' . $type . ''][$package_md5]['sort_id']; |
|
1446 | + } |
|
1390 | 1447 | }, |
1391 | 1448 | ), |
1392 | 1449 | 'sort' => array( |
@@ -1402,8 +1459,9 @@ discard block |
||
1402 | 1459 | 'data' => array( |
1403 | 1460 | 'function' => function($package_md5) use ($type, &$context) |
1404 | 1461 | { |
1405 | - if (isset($context['available_' . $type . ''][$package_md5])) |
|
1406 | - return $context['available_' . $type . ''][$package_md5]['name']; |
|
1462 | + if (isset($context['available_' . $type . ''][$package_md5])) { |
|
1463 | + return $context['available_' . $type . ''][$package_md5]['name']; |
|
1464 | + } |
|
1407 | 1465 | }, |
1408 | 1466 | ), |
1409 | 1467 | 'sort' => array( |
@@ -1418,8 +1476,9 @@ discard block |
||
1418 | 1476 | 'data' => array( |
1419 | 1477 | 'function' => function($package_md5) use ($type, &$context) |
1420 | 1478 | { |
1421 | - if (isset($context['available_' . $type . ''][$package_md5])) |
|
1422 | - return $context['available_' . $type . ''][$package_md5]['version']; |
|
1479 | + if (isset($context['available_' . $type . ''][$package_md5])) { |
|
1480 | + return $context['available_' . $type . ''][$package_md5]['version']; |
|
1481 | + } |
|
1423 | 1482 | }, |
1424 | 1483 | ), |
1425 | 1484 | 'sort' => array( |
@@ -1434,8 +1493,9 @@ discard block |
||
1434 | 1493 | 'data' => array( |
1435 | 1494 | 'function' => function($package_md5) use ($type, $txt, &$context) |
1436 | 1495 | { |
1437 | - if (isset($context['available_' . $type . ''][$package_md5])) |
|
1438 | - return !empty($context['available_' . $type . ''][$package_md5]['time_installed']) ? timeformat($context['available_' . $type . ''][$package_md5]['time_installed']) : $txt['not_applicable']; |
|
1496 | + if (isset($context['available_' . $type . ''][$package_md5])) { |
|
1497 | + return !empty($context['available_' . $type . ''][$package_md5]['time_installed']) ? timeformat($context['available_' . $type . ''][$package_md5]['time_installed']) : $txt['not_applicable']; |
|
1498 | + } |
|
1439 | 1499 | }, |
1440 | 1500 | 'class' => 'smalltext', |
1441 | 1501 | ), |
@@ -1451,28 +1511,30 @@ discard block |
||
1451 | 1511 | 'data' => array( |
1452 | 1512 | 'function' => function($package_md5) use ($type, &$context, $scripturl, $txt) |
1453 | 1513 | { |
1454 | - if (!isset($context['available_' . $type . ''][$package_md5])) |
|
1455 | - return ''; |
|
1514 | + if (!isset($context['available_' . $type . ''][$package_md5])) { |
|
1515 | + return ''; |
|
1516 | + } |
|
1456 | 1517 | |
1457 | 1518 | // Rewrite shortcut |
1458 | 1519 | $package = $context['available_' . $type . ''][$package_md5]; |
1459 | 1520 | $return = ''; |
1460 | 1521 | |
1461 | - if ($package['can_uninstall']) |
|
1462 | - $return = ' |
|
1522 | + if ($package['can_uninstall']) { |
|
1523 | + $return = ' |
|
1463 | 1524 | <a href="' . $scripturl . '?action=admin;area=packages;sa=uninstall;package=' . $package['filename'] . ';pid=' . $package['installed_id'] . '" class="button">' . $txt['uninstall'] . '</a>'; |
1464 | - elseif ($package['can_emulate_uninstall']) |
|
1465 | - $return = ' |
|
1525 | + } elseif ($package['can_emulate_uninstall']) { |
|
1526 | + $return = ' |
|
1466 | 1527 | <a href="' . $scripturl . '?action=admin;area=packages;sa=uninstall;ve=' . $package['can_emulate_uninstall'] . ';package=' . $package['filename'] . ';pid=' . $package['installed_id'] . '" class="button">' . $txt['package_emulate_uninstall'] . ' ' . $package['can_emulate_uninstall'] . '</a>'; |
1467 | - elseif ($package['can_upgrade']) |
|
1468 | - $return = ' |
|
1528 | + } elseif ($package['can_upgrade']) { |
|
1529 | + $return = ' |
|
1469 | 1530 | <a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $package['filename'] . '" class="button">' . $txt['package_upgrade'] . '</a>'; |
1470 | - elseif ($package['can_install']) |
|
1471 | - $return = ' |
|
1531 | + } elseif ($package['can_install']) { |
|
1532 | + $return = ' |
|
1472 | 1533 | <a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $package['filename'] . '" class="button">' . $txt['install_mod'] . '</a>'; |
1473 | - elseif ($package['can_emulate_install']) |
|
1474 | - $return = ' |
|
1534 | + } elseif ($package['can_emulate_install']) { |
|
1535 | + $return = ' |
|
1475 | 1536 | <a href="' . $scripturl . '?action=admin;area=packages;sa=install;ve=' . $package['can_emulate_install'] . ';package=' . $package['filename'] . '" class="button">' . $txt['package_emulate_install'] . ' ' . $package['can_emulate_install'] . '</a>'; |
1537 | + } |
|
1476 | 1538 | |
1477 | 1539 | return $return . ' |
1478 | 1540 | <a href="' . $scripturl . '?action=admin;area=packages;sa=list;package=' . $package['filename'] . '" class="button">' . $txt['list_files'] . '</a> |
@@ -1537,12 +1599,14 @@ discard block |
||
1537 | 1599 | static $packages, $installed_mods; |
1538 | 1600 | |
1539 | 1601 | // Start things up |
1540 | - if (!isset($packages[$params])) |
|
1541 | - $packages[$params] = array(); |
|
1602 | + if (!isset($packages[$params])) { |
|
1603 | + $packages[$params] = array(); |
|
1604 | + } |
|
1542 | 1605 | |
1543 | 1606 | // We need the packages directory to be writable for this. |
1544 | - if (!@is_writable($packagesdir)) |
|
1545 | - create_chmod_control(array($packagesdir), array('destination_url' => $scripturl . '?action=admin;area=packages', 'crash_on_error' => true)); |
|
1607 | + if (!@is_writable($packagesdir)) { |
|
1608 | + create_chmod_control(array($packagesdir), array('destination_url' => $scripturl . '?action=admin;area=packages', 'crash_on_error' => true)); |
|
1609 | + } |
|
1546 | 1610 | |
1547 | 1611 | $the_version = strtr($forum_version, array('SMF ' => '')); |
1548 | 1612 | |
@@ -1550,41 +1614,44 @@ discard block |
||
1550 | 1614 | if (isset($_GET['version_emulate']) && strtr($_GET['version_emulate'], array('SMF ' => '')) == $the_version) |
1551 | 1615 | { |
1552 | 1616 | unset($_SESSION['version_emulate']); |
1553 | - } |
|
1554 | - elseif (isset($_GET['version_emulate'])) |
|
1617 | + } elseif (isset($_GET['version_emulate'])) |
|
1555 | 1618 | { |
1556 | - if (($_GET['version_emulate'] === 0 || $_GET['version_emulate'] === $forum_version) && isset($_SESSION['version_emulate'])) |
|
1557 | - unset($_SESSION['version_emulate']); |
|
1558 | - elseif ($_GET['version_emulate'] !== 0) |
|
1559 | - $_SESSION['version_emulate'] = strtr($_GET['version_emulate'], array('-' => ' ', '+' => ' ', 'SMF ' => '')); |
|
1619 | + if (($_GET['version_emulate'] === 0 || $_GET['version_emulate'] === $forum_version) && isset($_SESSION['version_emulate'])) { |
|
1620 | + unset($_SESSION['version_emulate']); |
|
1621 | + } elseif ($_GET['version_emulate'] !== 0) { |
|
1622 | + $_SESSION['version_emulate'] = strtr($_GET['version_emulate'], array('-' => ' ', '+' => ' ', 'SMF ' => '')); |
|
1623 | + } |
|
1560 | 1624 | } |
1561 | 1625 | if (!empty($_SESSION['version_emulate'])) |
1562 | 1626 | { |
1563 | 1627 | $context['forum_version'] = 'SMF ' . $_SESSION['version_emulate']; |
1564 | 1628 | $the_version = $_SESSION['version_emulate']; |
1565 | 1629 | } |
1566 | - if (isset($_SESSION['single_version_emulate'])) |
|
1567 | - unset($_SESSION['single_version_emulate']); |
|
1630 | + if (isset($_SESSION['single_version_emulate'])) { |
|
1631 | + unset($_SESSION['single_version_emulate']); |
|
1632 | + } |
|
1568 | 1633 | |
1569 | 1634 | if (empty($installed_mods)) |
1570 | 1635 | { |
1571 | 1636 | $instmods = loadInstalledPackages(); |
1572 | 1637 | $installed_mods = array(); |
1573 | 1638 | // Look through the list of installed mods... |
1574 | - foreach ($instmods as $installed_mod) |
|
1575 | - $installed_mods[$installed_mod['package_id']] = array( |
|
1639 | + foreach ($instmods as $installed_mod) { |
|
1640 | + $installed_mods[$installed_mod['package_id']] = array( |
|
1576 | 1641 | 'id' => $installed_mod['id'], |
1577 | 1642 | 'version' => $installed_mod['version'], |
1578 | 1643 | 'time_installed' => $installed_mod['time_installed'], |
1579 | 1644 | ); |
1645 | + } |
|
1580 | 1646 | |
1581 | 1647 | // Get a list of all the ids installed, so the latest packages won't include already installed ones. |
1582 | 1648 | $context['installed_mods'] = array_keys($installed_mods); |
1583 | 1649 | } |
1584 | 1650 | |
1585 | - if (empty($packages)) |
|
1586 | - foreach ($context['modification_types'] as $type) |
|
1651 | + if (empty($packages)) { |
|
1652 | + foreach ($context['modification_types'] as $type) |
|
1587 | 1653 | $packages[$type] = array(); |
1654 | + } |
|
1588 | 1655 | |
1589 | 1656 | if ($dir = @opendir($packagesdir)) |
1590 | 1657 | { |
@@ -1600,50 +1667,56 @@ discard block |
||
1600 | 1667 | |
1601 | 1668 | while ($package = readdir($dir)) |
1602 | 1669 | { |
1603 | - if ($package == '.' || $package == '..' || $package == 'temp' || (!(is_dir($packagesdir . '/' . $package) && file_exists($packagesdir . '/' . $package . '/package-info.xml')) && substr(strtolower($package), -7) != '.tar.gz' && substr(strtolower($package), -4) != '.tgz' && substr(strtolower($package), -4) != '.zip')) |
|
1604 | - continue; |
|
1670 | + if ($package == '.' || $package == '..' || $package == 'temp' || (!(is_dir($packagesdir . '/' . $package) && file_exists($packagesdir . '/' . $package . '/package-info.xml')) && substr(strtolower($package), -7) != '.tar.gz' && substr(strtolower($package), -4) != '.tgz' && substr(strtolower($package), -4) != '.zip')) { |
|
1671 | + continue; |
|
1672 | + } |
|
1605 | 1673 | |
1606 | 1674 | $skip = false; |
1607 | - foreach ($context['modification_types'] as $type) |
|
1608 | - if (isset($context['available_' . $type][md5($package)])) |
|
1675 | + foreach ($context['modification_types'] as $type) { |
|
1676 | + if (isset($context['available_' . $type][md5($package)])) |
|
1609 | 1677 | $skip = true; |
1678 | + } |
|
1610 | 1679 | |
1611 | - if ($skip) |
|
1612 | - continue; |
|
1680 | + if ($skip) { |
|
1681 | + continue; |
|
1682 | + } |
|
1613 | 1683 | |
1614 | 1684 | // Skip directories or files that are named the same. |
1615 | 1685 | if (is_dir($packagesdir . '/' . $package)) |
1616 | 1686 | { |
1617 | - if (in_array($package, $dirs)) |
|
1618 | - continue; |
|
1687 | + if (in_array($package, $dirs)) { |
|
1688 | + continue; |
|
1689 | + } |
|
1619 | 1690 | $dirs[] = $package; |
1620 | - } |
|
1621 | - elseif (substr(strtolower($package), -7) == '.tar.gz') |
|
1691 | + } elseif (substr(strtolower($package), -7) == '.tar.gz') |
|
1622 | 1692 | { |
1623 | - if (in_array(substr($package, 0, -7), $dirs)) |
|
1624 | - continue; |
|
1693 | + if (in_array(substr($package, 0, -7), $dirs)) { |
|
1694 | + continue; |
|
1695 | + } |
|
1625 | 1696 | $dirs[] = substr($package, 0, -7); |
1626 | - } |
|
1627 | - elseif (substr(strtolower($package), -4) == '.zip' || substr(strtolower($package), -4) == '.tgz') |
|
1697 | + } elseif (substr(strtolower($package), -4) == '.zip' || substr(strtolower($package), -4) == '.tgz') |
|
1628 | 1698 | { |
1629 | - if (in_array(substr($package, 0, -4), $dirs)) |
|
1630 | - continue; |
|
1699 | + if (in_array(substr($package, 0, -4), $dirs)) { |
|
1700 | + continue; |
|
1701 | + } |
|
1631 | 1702 | $dirs[] = substr($package, 0, -4); |
1632 | 1703 | } |
1633 | 1704 | |
1634 | 1705 | $packageInfo = getPackageInfo($package); |
1635 | - if (!is_array($packageInfo)) |
|
1636 | - continue; |
|
1706 | + if (!is_array($packageInfo)) { |
|
1707 | + continue; |
|
1708 | + } |
|
1637 | 1709 | |
1638 | 1710 | if (!empty($packageInfo)) |
1639 | 1711 | { |
1640 | 1712 | $packageInfo['installed_id'] = isset($installed_mods[$packageInfo['id']]) ? $installed_mods[$packageInfo['id']]['id'] : 0; |
1641 | 1713 | $packageInfo['time_installed'] = isset($installed_mods[$packageInfo['id']]) ? $installed_mods[$packageInfo['id']]['time_installed'] : 0; |
1642 | 1714 | |
1643 | - if (!isset($sort_id[$packageInfo['type']])) |
|
1644 | - $packageInfo['sort_id'] = $sort_id['unknown']; |
|
1645 | - else |
|
1646 | - $packageInfo['sort_id'] = $sort_id[$packageInfo['type']]; |
|
1715 | + if (!isset($sort_id[$packageInfo['type']])) { |
|
1716 | + $packageInfo['sort_id'] = $sort_id['unknown']; |
|
1717 | + } else { |
|
1718 | + $packageInfo['sort_id'] = $sort_id[$packageInfo['type']]; |
|
1719 | + } |
|
1647 | 1720 | |
1648 | 1721 | $packageInfo['is_installed'] = isset($installed_mods[$packageInfo['id']]); |
1649 | 1722 | $packageInfo['is_current'] = $packageInfo['is_installed'] && ($installed_mods[$packageInfo['id']]['version'] == $packageInfo['version']); |
@@ -1692,10 +1765,11 @@ discard block |
||
1692 | 1765 | foreach ($upgrades as $upgrade) |
1693 | 1766 | { |
1694 | 1767 | // Even if it is for this SMF, is it for the installed version of the mod? |
1695 | - if (!$upgrade->exists('@for') || matchPackageVersion($the_version, $upgrade->fetch('@for'))) |
|
1696 | - if (!$upgrade->exists('@from') || matchPackageVersion($installed_mods[$packageInfo['id']]['version'], $upgrade->fetch('@from'))) |
|
1768 | + if (!$upgrade->exists('@for') || matchPackageVersion($the_version, $upgrade->fetch('@for'))) { |
|
1769 | + if (!$upgrade->exists('@from') || matchPackageVersion($installed_mods[$packageInfo['id']]['version'], $upgrade->fetch('@from'))) |
|
1697 | 1770 | { |
1698 | 1771 | $packageInfo['can_upgrade'] = true; |
1772 | + } |
|
1699 | 1773 | break; |
1700 | 1774 | } |
1701 | 1775 | } |
@@ -1772,10 +1846,11 @@ discard block |
||
1772 | 1846 | |
1773 | 1847 | if (isset($_GET['type']) && $_GET['type'] == $params) |
1774 | 1848 | { |
1775 | - if (isset($_GET['desc'])) |
|
1776 | - krsort($packages[$params]); |
|
1777 | - else |
|
1778 | - ksort($packages[$params]); |
|
1849 | + if (isset($_GET['desc'])) { |
|
1850 | + krsort($packages[$params]); |
|
1851 | + } else { |
|
1852 | + ksort($packages[$params]); |
|
1853 | + } |
|
1779 | 1854 | } |
1780 | 1855 | |
1781 | 1856 | return $packages[$params]; |
@@ -1804,10 +1879,11 @@ discard block |
||
1804 | 1879 | redirectexit('action=admin;area=packages;sa=options'); |
1805 | 1880 | } |
1806 | 1881 | |
1807 | - if (preg_match('~^/home\d*/([^/]+?)/public_html~', $_SERVER['DOCUMENT_ROOT'], $match)) |
|
1808 | - $default_username = $match[1]; |
|
1809 | - else |
|
1810 | - $default_username = ''; |
|
1882 | + if (preg_match('~^/home\d*/([^/]+?)/public_html~', $_SERVER['DOCUMENT_ROOT'], $match)) { |
|
1883 | + $default_username = $match[1]; |
|
1884 | + } else { |
|
1885 | + $default_username = ''; |
|
1886 | + } |
|
1811 | 1887 | |
1812 | 1888 | $context['page_title'] = $txt['package_settings']; |
1813 | 1889 | $context['sub_template'] = 'install_options'; |
@@ -1836,8 +1912,9 @@ discard block |
||
1836 | 1912 | isAllowedTo('admin_forum'); |
1837 | 1913 | |
1838 | 1914 | // We need to know the operation key for the search and replace, mod file looking at, is it a board mod? |
1839 | - if (!isset($_REQUEST['operation_key'], $_REQUEST['filename']) && !is_numeric($_REQUEST['operation_key'])) |
|
1840 | - fatal_lang_error('operation_invalid', 'general'); |
|
1915 | + if (!isset($_REQUEST['operation_key'], $_REQUEST['filename']) && !is_numeric($_REQUEST['operation_key'])) { |
|
1916 | + fatal_lang_error('operation_invalid', 'general'); |
|
1917 | + } |
|
1841 | 1918 | |
1842 | 1919 | // Load the required file. |
1843 | 1920 | require_once($sourcedir . '/Subs-Package.php'); |
@@ -1853,18 +1930,19 @@ discard block |
||
1853 | 1930 | { |
1854 | 1931 | $context['extracted_files'] = read_tgz_file($packagesdir . '/' . $context['filename'], $packagesdir . '/temp'); |
1855 | 1932 | |
1856 | - if ($context['extracted_files'] && !file_exists($packagesdir . '/temp/package-info.xml')) |
|
1857 | - foreach ($context['extracted_files'] as $file) |
|
1933 | + if ($context['extracted_files'] && !file_exists($packagesdir . '/temp/package-info.xml')) { |
|
1934 | + foreach ($context['extracted_files'] as $file) |
|
1858 | 1935 | if (basename($file['filename']) == 'package-info.xml') |
1859 | 1936 | { |
1860 | 1937 | $context['base_path'] = dirname($file['filename']) . '/'; |
1938 | + } |
|
1861 | 1939 | break; |
1862 | 1940 | } |
1863 | 1941 | |
1864 | - if (!isset($context['base_path'])) |
|
1865 | - $context['base_path'] = ''; |
|
1866 | - } |
|
1867 | - elseif (is_dir($packagesdir . '/' . $context['filename'])) |
|
1942 | + if (!isset($context['base_path'])) { |
|
1943 | + $context['base_path'] = ''; |
|
1944 | + } |
|
1945 | + } elseif (is_dir($packagesdir . '/' . $context['filename'])) |
|
1868 | 1946 | { |
1869 | 1947 | copytree($packagesdir . '/' . $context['filename'], $packagesdir . '/temp'); |
1870 | 1948 | $context['extracted_files'] = listtree($packagesdir . '/temp'); |
@@ -1885,8 +1963,9 @@ discard block |
||
1885 | 1963 | ) |
1886 | 1964 | ); |
1887 | 1965 | $theme_paths = array(); |
1888 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1889 | - $theme_paths[$row['id_theme']][$row['variable']] = $row['value']; |
|
1966 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1967 | + $theme_paths[$row['id_theme']][$row['variable']] = $row['value']; |
|
1968 | + } |
|
1890 | 1969 | $smcFunc['db_free_result']($request); |
1891 | 1970 | |
1892 | 1971 | // If we're viewing uninstall operations, only consider themes that |
@@ -1911,19 +1990,21 @@ discard block |
||
1911 | 1990 | list ($old_themes) = $smcFunc['db_fetch_row']($request); |
1912 | 1991 | $old_themes = explode(',', $old_themes); |
1913 | 1992 | |
1914 | - foreach ($theme_paths as $id => $data) |
|
1915 | - if ($id != 1 && !in_array($id, $old_themes)) |
|
1993 | + foreach ($theme_paths as $id => $data) { |
|
1994 | + if ($id != 1 && !in_array($id, $old_themes)) |
|
1916 | 1995 | unset($theme_paths[$id]); |
1996 | + } |
|
1917 | 1997 | } |
1918 | 1998 | $smcFunc['db_free_result']($request); |
1919 | 1999 | } |
1920 | 2000 | } |
1921 | 2001 | |
1922 | 2002 | // Boardmod? |
1923 | - if (isset($_REQUEST['boardmod'])) |
|
1924 | - $mod_actions = parseBoardMod(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $_REQUEST['filename']), true, $reverse, $theme_paths); |
|
1925 | - else |
|
1926 | - $mod_actions = parseModification(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $_REQUEST['filename']), true, $reverse, $theme_paths); |
|
2003 | + if (isset($_REQUEST['boardmod'])) { |
|
2004 | + $mod_actions = parseBoardMod(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $_REQUEST['filename']), true, $reverse, $theme_paths); |
|
2005 | + } else { |
|
2006 | + $mod_actions = parseModification(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $_REQUEST['filename']), true, $reverse, $theme_paths); |
|
2007 | + } |
|
1927 | 2008 | |
1928 | 2009 | // Ok lets get the content of the file. |
1929 | 2010 | $context['operations'] = array( |
@@ -1979,9 +2060,9 @@ discard block |
||
1979 | 2060 | 'path' => $detect_path, |
1980 | 2061 | 'form_elements_only' => true, |
1981 | 2062 | ); |
2063 | + } else { |
|
2064 | + $context['ftp_connected'] = true; |
|
1982 | 2065 | } |
1983 | - else |
|
1984 | - $context['ftp_connected'] = true; |
|
1985 | 2066 | |
1986 | 2067 | // Define the template. |
1987 | 2068 | $context['page_title'] = $txt['package_file_perms']; |
@@ -2094,18 +2175,19 @@ discard block |
||
2094 | 2175 | { |
2095 | 2176 | unset($context['file_tree'][strtr($boarddir, array('\\' => '/'))]['contents']['attachments']); |
2096 | 2177 | |
2097 | - if (!is_array($modSettings['attachmentUploadDir'])) |
|
2098 | - $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
2178 | + if (!is_array($modSettings['attachmentUploadDir'])) { |
|
2179 | + $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
2180 | + } |
|
2099 | 2181 | |
2100 | 2182 | // @todo Should we suggest non-current directories be read only? |
2101 | - foreach ($modSettings['attachmentUploadDir'] as $dir) |
|
2102 | - $context['file_tree'][strtr($dir, array('\\' => '/'))] = array( |
|
2183 | + foreach ($modSettings['attachmentUploadDir'] as $dir) { |
|
2184 | + $context['file_tree'][strtr($dir, array('\\' => '/'))] = array( |
|
2103 | 2185 | 'type' => 'dir', |
2104 | 2186 | 'writable_on' => 'restrictive', |
2105 | 2187 | ); |
2188 | + } |
|
2106 | 2189 | |
2107 | - } |
|
2108 | - elseif (substr($modSettings['attachmentUploadDir'], 0, strlen($boarddir)) != $boarddir) |
|
2190 | + } elseif (substr($modSettings['attachmentUploadDir'], 0, strlen($boarddir)) != $boarddir) |
|
2109 | 2191 | { |
2110 | 2192 | unset($context['file_tree'][strtr($boarddir, array('\\' => '/'))]['contents']['attachments']); |
2111 | 2193 | $context['file_tree'][strtr($modSettings['attachmentUploadDir'], array('\\' => '/'))] = array( |
@@ -2155,8 +2237,8 @@ discard block |
||
2155 | 2237 | ); |
2156 | 2238 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
2157 | 2239 | { |
2158 | - if (substr(strtolower(strtr($row['value'], array('\\' => '/'))), 0, strlen($boarddir) + 7) == strtolower(strtr($boarddir, array('\\' => '/')) . '/Themes')) |
|
2159 | - $context['file_tree'][strtr($boarddir, array('\\' => '/'))]['contents']['Themes']['contents'][substr($row['value'], strlen($boarddir) + 8)] = array( |
|
2240 | + if (substr(strtolower(strtr($row['value'], array('\\' => '/'))), 0, strlen($boarddir) + 7) == strtolower(strtr($boarddir, array('\\' => '/')) . '/Themes')) { |
|
2241 | + $context['file_tree'][strtr($boarddir, array('\\' => '/'))]['contents']['Themes']['contents'][substr($row['value'], strlen($boarddir) + 8)] = array( |
|
2160 | 2242 | 'type' => 'dir_recursive', |
2161 | 2243 | 'list_contents' => true, |
2162 | 2244 | 'contents' => array( |
@@ -2166,7 +2248,7 @@ discard block |
||
2166 | 2248 | ), |
2167 | 2249 | ), |
2168 | 2250 | ); |
2169 | - else |
|
2251 | + } else |
|
2170 | 2252 | { |
2171 | 2253 | $context['file_tree'][strtr($row['value'], array('\\' => '/'))] = array( |
2172 | 2254 | 'type' => 'dir_recursive', |
@@ -2183,28 +2265,33 @@ discard block |
||
2183 | 2265 | $smcFunc['db_free_result']($request); |
2184 | 2266 | |
2185 | 2267 | // If we're submitting then let's move on to another function to keep things cleaner.. |
2186 | - if (isset($_POST['action_changes'])) |
|
2187 | - return PackagePermissionsAction(); |
|
2268 | + if (isset($_POST['action_changes'])) { |
|
2269 | + return PackagePermissionsAction(); |
|
2270 | + } |
|
2188 | 2271 | |
2189 | 2272 | $context['look_for'] = array(); |
2190 | 2273 | // Are we looking for a particular tree - normally an expansion? |
2191 | - if (!empty($_REQUEST['find'])) |
|
2192 | - $context['look_for'][] = base64_decode($_REQUEST['find']); |
|
2274 | + if (!empty($_REQUEST['find'])) { |
|
2275 | + $context['look_for'][] = base64_decode($_REQUEST['find']); |
|
2276 | + } |
|
2193 | 2277 | // Only that tree? |
2194 | 2278 | $context['only_find'] = isset($_GET['xml']) && !empty($_REQUEST['onlyfind']) ? $_REQUEST['onlyfind'] : ''; |
2195 | - if ($context['only_find']) |
|
2196 | - $context['look_for'][] = $context['only_find']; |
|
2279 | + if ($context['only_find']) { |
|
2280 | + $context['look_for'][] = $context['only_find']; |
|
2281 | + } |
|
2197 | 2282 | |
2198 | 2283 | // Have we got a load of back-catalogue trees to expand from a submit etc? |
2199 | 2284 | if (!empty($_GET['back_look'])) |
2200 | 2285 | { |
2201 | 2286 | $potententialTrees = smf_json_decode(base64_decode($_GET['back_look']), true); |
2202 | - foreach ($potententialTrees as $tree) |
|
2203 | - $context['look_for'][] = $tree; |
|
2287 | + foreach ($potententialTrees as $tree) { |
|
2288 | + $context['look_for'][] = $tree; |
|
2289 | + } |
|
2204 | 2290 | } |
2205 | 2291 | // ... maybe posted? |
2206 | - if (!empty($_POST['back_look'])) |
|
2207 | - $context['only_find'] = array_merge($context['only_find'], $_POST['back_look']); |
|
2292 | + if (!empty($_POST['back_look'])) { |
|
2293 | + $context['only_find'] = array_merge($context['only_find'], $_POST['back_look']); |
|
2294 | + } |
|
2208 | 2295 | |
2209 | 2296 | $context['back_look_data'] = base64_encode(json_encode(array_slice($context['look_for'], 0, 15))); |
2210 | 2297 | |
@@ -2243,9 +2330,9 @@ discard block |
||
2243 | 2330 | 'chmod' => @is_writable($path), |
2244 | 2331 | 'perms' => @fileperms($path), |
2245 | 2332 | ); |
2333 | + } else { |
|
2334 | + unset($context['file_tree'][$path]); |
|
2246 | 2335 | } |
2247 | - else |
|
2248 | - unset($context['file_tree'][$path]); |
|
2249 | 2336 | } |
2250 | 2337 | |
2251 | 2338 | // Is this actually xml? |
@@ -2269,22 +2356,25 @@ discard block |
||
2269 | 2356 | global $context; |
2270 | 2357 | |
2271 | 2358 | $isLikelyPath = false; |
2272 | - foreach ($context['look_for'] as $possiblePath) |
|
2273 | - if (substr($possiblePath, 0, strlen($path)) == $path) |
|
2359 | + foreach ($context['look_for'] as $possiblePath) { |
|
2360 | + if (substr($possiblePath, 0, strlen($path)) == $path) |
|
2274 | 2361 | $isLikelyPath = true; |
2362 | + } |
|
2275 | 2363 | |
2276 | 2364 | // Is this where we stop? |
2277 | - if (isset($_GET['xml']) && !empty($context['look_for']) && !$isLikelyPath) |
|
2278 | - return; |
|
2279 | - elseif ($level > $context['default_level'] && !$isLikelyPath) |
|
2280 | - return; |
|
2365 | + if (isset($_GET['xml']) && !empty($context['look_for']) && !$isLikelyPath) { |
|
2366 | + return; |
|
2367 | + } elseif ($level > $context['default_level'] && !$isLikelyPath) { |
|
2368 | + return; |
|
2369 | + } |
|
2281 | 2370 | |
2282 | 2371 | // Are we actually interested in saving this data? |
2283 | 2372 | $save_data = empty($context['only_find']) || $context['only_find'] == $path; |
2284 | 2373 | |
2285 | 2374 | // @todo Shouldn't happen - but better error message? |
2286 | - if (!is_dir($path)) |
|
2287 | - fatal_lang_error('no_access', false); |
|
2375 | + if (!is_dir($path)) { |
|
2376 | + fatal_lang_error('no_access', false); |
|
2377 | + } |
|
2288 | 2378 | |
2289 | 2379 | // This is where we put stuff we've found for sorting. |
2290 | 2380 | $foundData = array( |
@@ -2299,11 +2389,13 @@ discard block |
||
2299 | 2389 | if (is_file($path . '/' . $entry)) |
2300 | 2390 | { |
2301 | 2391 | // Are we listing PHP files in this directory? |
2302 | - if ($save_data && !empty($data['list_contents']) && substr($entry, -4) == '.php') |
|
2303 | - $foundData['files'][$entry] = true; |
|
2392 | + if ($save_data && !empty($data['list_contents']) && substr($entry, -4) == '.php') { |
|
2393 | + $foundData['files'][$entry] = true; |
|
2394 | + } |
|
2304 | 2395 | // A file we were looking for. |
2305 | - elseif ($save_data && isset($data['contents'][$entry])) |
|
2306 | - $foundData['files'][$entry] = true; |
|
2396 | + elseif ($save_data && isset($data['contents'][$entry])) { |
|
2397 | + $foundData['files'][$entry] = true; |
|
2398 | + } |
|
2307 | 2399 | } |
2308 | 2400 | // It's a directory - we're interested one way or another, probably... |
2309 | 2401 | elseif ($entry != '.' && $entry != '..') |
@@ -2311,32 +2403,36 @@ discard block |
||
2311 | 2403 | // Going further? |
2312 | 2404 | if ((!empty($data['type']) && $data['type'] == 'dir_recursive') || (isset($data['contents'][$entry]) && (!empty($data['contents'][$entry]['list_contents']) || (!empty($data['contents'][$entry]['type']) && $data['contents'][$entry]['type'] == 'dir_recursive')))) |
2313 | 2405 | { |
2314 | - if (!isset($data['contents'][$entry])) |
|
2315 | - $foundData['folders'][$entry] = 'dir_recursive'; |
|
2316 | - else |
|
2317 | - $foundData['folders'][$entry] = true; |
|
2406 | + if (!isset($data['contents'][$entry])) { |
|
2407 | + $foundData['folders'][$entry] = 'dir_recursive'; |
|
2408 | + } else { |
|
2409 | + $foundData['folders'][$entry] = true; |
|
2410 | + } |
|
2318 | 2411 | |
2319 | 2412 | // If this wasn't expected inherit the recusiveness... |
2320 | - if (!isset($data['contents'][$entry])) |
|
2321 | - // We need to do this as we will be going all recursive. |
|
2413 | + if (!isset($data['contents'][$entry])) { |
|
2414 | + // We need to do this as we will be going all recursive. |
|
2322 | 2415 | $data['contents'][$entry] = array( |
2323 | 2416 | 'type' => 'dir_recursive', |
2324 | 2417 | ); |
2418 | + } |
|
2325 | 2419 | |
2326 | 2420 | // Actually do the recursive stuff... |
2327 | 2421 | fetchPerms__recursive($path . '/' . $entry, $data['contents'][$entry], $level + 1); |
2328 | 2422 | } |
2329 | 2423 | // Maybe it is a folder we are not descending into. |
2330 | - elseif (isset($data['contents'][$entry])) |
|
2331 | - $foundData['folders'][$entry] = true; |
|
2424 | + elseif (isset($data['contents'][$entry])) { |
|
2425 | + $foundData['folders'][$entry] = true; |
|
2426 | + } |
|
2332 | 2427 | // Otherwise we stop here. |
2333 | 2428 | } |
2334 | 2429 | } |
2335 | 2430 | closedir($dh); |
2336 | 2431 | |
2337 | 2432 | // Nothing to see here? |
2338 | - if (!$save_data) |
|
2339 | - return; |
|
2433 | + if (!$save_data) { |
|
2434 | + return; |
|
2435 | + } |
|
2340 | 2436 | |
2341 | 2437 | // Now actually add the data, starting with the folders. |
2342 | 2438 | ksort($foundData['folders']); |
@@ -2348,8 +2444,9 @@ discard block |
||
2348 | 2444 | 'perms' => @fileperms($path . '/' . $folder), |
2349 | 2445 | ), |
2350 | 2446 | ); |
2351 | - if ($type !== true) |
|
2352 | - $additional_data['type'] = $type; |
|
2447 | + if ($type !== true) { |
|
2448 | + $additional_data['type'] = $type; |
|
2449 | + } |
|
2353 | 2450 | |
2354 | 2451 | // If there's an offset ignore any folders in XML mode. |
2355 | 2452 | if (isset($_GET['xml']) && $context['file_offset'] == 0) |
@@ -2368,13 +2465,13 @@ discard block |
||
2368 | 2465 | ), |
2369 | 2466 | 'value' => $folder, |
2370 | 2467 | ); |
2371 | - } |
|
2372 | - elseif (!isset($_GET['xml'])) |
|
2468 | + } elseif (!isset($_GET['xml'])) |
|
2373 | 2469 | { |
2374 | - if (isset($data['contents'][$folder])) |
|
2375 | - $data['contents'][$folder] = array_merge($data['contents'][$folder], $additional_data); |
|
2376 | - else |
|
2377 | - $data['contents'][$folder] = $additional_data; |
|
2470 | + if (isset($data['contents'][$folder])) { |
|
2471 | + $data['contents'][$folder] = array_merge($data['contents'][$folder], $additional_data); |
|
2472 | + } else { |
|
2473 | + $data['contents'][$folder] = $additional_data; |
|
2474 | + } |
|
2378 | 2475 | } |
2379 | 2476 | } |
2380 | 2477 | |
@@ -2386,11 +2483,13 @@ discard block |
||
2386 | 2483 | $counter++; |
2387 | 2484 | |
2388 | 2485 | // Have we reached our offset? |
2389 | - if ($context['file_offset'] > $counter) |
|
2390 | - continue; |
|
2486 | + if ($context['file_offset'] > $counter) { |
|
2487 | + continue; |
|
2488 | + } |
|
2391 | 2489 | // Gone too far? |
2392 | - if ($counter > ($context['file_offset'] + $context['file_limit'])) |
|
2393 | - continue; |
|
2490 | + if ($counter > ($context['file_offset'] + $context['file_limit'])) { |
|
2491 | + continue; |
|
2492 | + } |
|
2394 | 2493 | |
2395 | 2494 | $additional_data = array( |
2396 | 2495 | 'perms' => array( |
@@ -2416,13 +2515,13 @@ discard block |
||
2416 | 2515 | ), |
2417 | 2516 | 'value' => $file, |
2418 | 2517 | ); |
2419 | - } |
|
2420 | - elseif ($counter != ($context['file_offset'] + $context['file_limit'])) |
|
2518 | + } elseif ($counter != ($context['file_offset'] + $context['file_limit'])) |
|
2421 | 2519 | { |
2422 | - if (isset($data['contents'][$file])) |
|
2423 | - $data['contents'][$file] = array_merge($data['contents'][$file], $additional_data); |
|
2424 | - else |
|
2425 | - $data['contents'][$file] = $additional_data; |
|
2520 | + if (isset($data['contents'][$file])) { |
|
2521 | + $data['contents'][$file] = array_merge($data['contents'][$file], $additional_data); |
|
2522 | + } else { |
|
2523 | + $data['contents'][$file] = $additional_data; |
|
2524 | + } |
|
2426 | 2525 | } |
2427 | 2526 | } |
2428 | 2527 | } |
@@ -2444,8 +2543,9 @@ discard block |
||
2444 | 2543 | $context['back_look_data'] = isset($_POST['back_look']) ? $_POST['back_look'] : array(); |
2445 | 2544 | |
2446 | 2545 | // Skipping use of FTP? |
2447 | - if (empty($package_ftp)) |
|
2448 | - $context['skip_ftp'] = true; |
|
2546 | + if (empty($package_ftp)) { |
|
2547 | + $context['skip_ftp'] = true; |
|
2548 | + } |
|
2449 | 2549 | |
2450 | 2550 | // We'll start off in a good place, security. Make sure that if we're dealing with individual files that they seem in the right place. |
2451 | 2551 | if ($context['method'] == 'individual') |
@@ -2455,8 +2555,9 @@ discard block |
||
2455 | 2555 | $context['custom_value'] = (int) $_POST['custom_value']; |
2456 | 2556 | |
2457 | 2557 | // Continuing? |
2458 | - if (isset($_POST['toProcess'])) |
|
2459 | - $_POST['permStatus'] = smf_json_decode(base64_decode($_POST['toProcess']), true); |
|
2558 | + if (isset($_POST['toProcess'])) { |
|
2559 | + $_POST['permStatus'] = smf_json_decode(base64_decode($_POST['toProcess']), true); |
|
2560 | + } |
|
2460 | 2561 | |
2461 | 2562 | if (isset($_POST['permStatus'])) |
2462 | 2563 | { |
@@ -2465,22 +2566,27 @@ discard block |
||
2465 | 2566 | foreach ($_POST['permStatus'] as $path => $status) |
2466 | 2567 | { |
2467 | 2568 | // Nothing to see here? |
2468 | - if ($status == 'no_change') |
|
2469 | - continue; |
|
2569 | + if ($status == 'no_change') { |
|
2570 | + continue; |
|
2571 | + } |
|
2470 | 2572 | $legal = false; |
2471 | - foreach ($legal_roots as $root) |
|
2472 | - if (substr($path, 0, strlen($root)) == $root) |
|
2573 | + foreach ($legal_roots as $root) { |
|
2574 | + if (substr($path, 0, strlen($root)) == $root) |
|
2473 | 2575 | $legal = true; |
2576 | + } |
|
2474 | 2577 | |
2475 | - if (!$legal) |
|
2476 | - continue; |
|
2578 | + if (!$legal) { |
|
2579 | + continue; |
|
2580 | + } |
|
2477 | 2581 | |
2478 | 2582 | // Check it exists. |
2479 | - if (!file_exists($path)) |
|
2480 | - continue; |
|
2583 | + if (!file_exists($path)) { |
|
2584 | + continue; |
|
2585 | + } |
|
2481 | 2586 | |
2482 | - if ($status == 'custom') |
|
2483 | - $validate_custom = true; |
|
2587 | + if ($status == 'custom') { |
|
2588 | + $validate_custom = true; |
|
2589 | + } |
|
2484 | 2590 | |
2485 | 2591 | // Now add it. |
2486 | 2592 | $context['to_process'][$path] = $status; |
@@ -2490,17 +2596,20 @@ discard block |
||
2490 | 2596 | // Make sure the chmod status is valid? |
2491 | 2597 | if ($validate_custom) |
2492 | 2598 | { |
2493 | - if (preg_match('~^[4567][4567][4567]$~', $context['custom_value']) == false) |
|
2494 | - fatal_error($txt['chmod_value_invalid']); |
|
2599 | + if (preg_match('~^[4567][4567][4567]$~', $context['custom_value']) == false) { |
|
2600 | + fatal_error($txt['chmod_value_invalid']); |
|
2601 | + } |
|
2495 | 2602 | } |
2496 | 2603 | |
2497 | 2604 | // Nothing to do? |
2498 | - if (empty($context['to_process'])) |
|
2499 | - redirectexit('action=admin;area=packages;sa=perms' . (!empty($context['back_look_data']) ? ';back_look=' . base64_encode(json_encode($context['back_look_data'])) : '') . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
2605 | + if (empty($context['to_process'])) { |
|
2606 | + redirectexit('action=admin;area=packages;sa=perms' . (!empty($context['back_look_data']) ? ';back_look=' . base64_encode(json_encode($context['back_look_data'])) : '') . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
2607 | + } |
|
2500 | 2608 | } |
2501 | 2609 | // Should never get here, |
2502 | - else |
|
2503 | - fatal_lang_error('no_access', false); |
|
2610 | + else { |
|
2611 | + fatal_lang_error('no_access', false); |
|
2612 | + } |
|
2504 | 2613 | |
2505 | 2614 | // Setup the custom value. |
2506 | 2615 | $custom_value = octdec('0' . $context['custom_value']); |
@@ -2508,26 +2617,27 @@ discard block |
||
2508 | 2617 | // Start processing items. |
2509 | 2618 | foreach ($context['to_process'] as $path => $status) |
2510 | 2619 | { |
2511 | - if (in_array($status, array('execute', 'writable', 'read'))) |
|
2512 | - package_chmod($path, $status); |
|
2513 | - elseif ($status == 'custom' && !empty($custom_value)) |
|
2620 | + if (in_array($status, array('execute', 'writable', 'read'))) { |
|
2621 | + package_chmod($path, $status); |
|
2622 | + } elseif ($status == 'custom' && !empty($custom_value)) |
|
2514 | 2623 | { |
2515 | 2624 | // Use FTP if we have it. |
2516 | 2625 | if (!empty($package_ftp) && !empty($_SESSION['pack_ftp'])) |
2517 | 2626 | { |
2518 | 2627 | $ftp_file = strtr($path, array($_SESSION['pack_ftp']['root'] => '')); |
2519 | 2628 | $package_ftp->chmod($ftp_file, $custom_value); |
2629 | + } else { |
|
2630 | + smf_chmod($path, $custom_value); |
|
2520 | 2631 | } |
2521 | - else |
|
2522 | - smf_chmod($path, $custom_value); |
|
2523 | 2632 | } |
2524 | 2633 | |
2525 | 2634 | // This fish is fried... |
2526 | 2635 | unset($context['to_process'][$path]); |
2527 | 2636 | |
2528 | 2637 | // See if we're out of time? |
2529 | - if (time() - array_sum(explode(' ', $time_start)) > $timeout_limit) |
|
2530 | - return false; |
|
2638 | + if (time() - array_sum(explode(' ', $time_start)) > $timeout_limit) { |
|
2639 | + return false; |
|
2640 | + } |
|
2531 | 2641 | } |
2532 | 2642 | } |
2533 | 2643 | // If predefined this is a little different. |
@@ -2595,23 +2705,27 @@ discard block |
||
2595 | 2705 | { |
2596 | 2706 | global $context; |
2597 | 2707 | |
2598 | - if (!empty($data['writable_on'])) |
|
2599 | - if ($context['predefined_type'] == 'standard' || $data['writable_on'] == 'restrictive') |
|
2708 | + if (!empty($data['writable_on'])) { |
|
2709 | + if ($context['predefined_type'] == 'standard' || $data['writable_on'] == 'restrictive') |
|
2600 | 2710 | $context['special_files'][$path] = 1; |
2711 | + } |
|
2601 | 2712 | |
2602 | - if (!empty($data['contents'])) |
|
2603 | - foreach ($data['contents'] as $name => $contents) |
|
2713 | + if (!empty($data['contents'])) { |
|
2714 | + foreach ($data['contents'] as $name => $contents) |
|
2604 | 2715 | build_special_files__recursive($path . '/' . $name, $contents); |
2716 | + } |
|
2605 | 2717 | } |
2606 | 2718 | |
2607 | - foreach ($context['file_tree'] as $path => $data) |
|
2608 | - build_special_files__recursive($path, $data); |
|
2719 | + foreach ($context['file_tree'] as $path => $data) { |
|
2720 | + build_special_files__recursive($path, $data); |
|
2721 | + } |
|
2609 | 2722 | } |
2610 | 2723 | // Free doesn't need special files. |
2611 | - elseif ($context['predefined_type'] == 'free') |
|
2612 | - $context['special_files'] = array(); |
|
2613 | - else |
|
2614 | - $context['special_files'] = smf_json_decode(base64_decode($_POST['specialFiles']), true); |
|
2724 | + elseif ($context['predefined_type'] == 'free') { |
|
2725 | + $context['special_files'] = array(); |
|
2726 | + } else { |
|
2727 | + $context['special_files'] = smf_json_decode(base64_decode($_POST['specialFiles']), true); |
|
2728 | + } |
|
2615 | 2729 | |
2616 | 2730 | // Now we definitely know where we are, we need to go through again doing the chmod! |
2617 | 2731 | foreach ($context['directory_list'] as $path => $dummy) |
@@ -2656,8 +2770,9 @@ discard block |
||
2656 | 2770 | unset($context['directory_list'][$path]); |
2657 | 2771 | |
2658 | 2772 | // See if we're out of time? |
2659 | - if (time() - array_sum(explode(' ', $time_start)) > $timeout_limit) |
|
2660 | - return false; |
|
2773 | + if (time() - array_sum(explode(' ', $time_start)) > $timeout_limit) { |
|
2774 | + return false; |
|
2775 | + } |
|
2661 | 2776 | } |
2662 | 2777 | } |
2663 | 2778 |
@@ -14,8 +14,9 @@ discard block |
||
14 | 14 | * @version 2.1 Beta 3 |
15 | 15 | */ |
16 | 16 | |
17 | -if (!defined('SMF')) |
|
17 | +if (!defined('SMF')) { |
|
18 | 18 | die('No direct access...'); |
19 | +} |
|
19 | 20 | |
20 | 21 | /** |
21 | 22 | * Show the list of topics in this board, along with any child boards. |
@@ -56,8 +57,9 @@ discard block |
||
56 | 57 | |
57 | 58 | $context['name'] = $board_info['name']; |
58 | 59 | $context['description'] = $board_info['description']; |
59 | - if (!empty($board_info['description'])) |
|
60 | - $context['meta_description'] = strip_tags($board_info['description']); |
|
60 | + if (!empty($board_info['description'])) { |
|
61 | + $context['meta_description'] = strip_tags($board_info['description']); |
|
62 | + } |
|
61 | 63 | |
62 | 64 | // How many topics do we have in total? |
63 | 65 | $board_info['total_topics'] = allowedTo('approve_posts') ? $board_info['num_topics'] + $board_info['unapproved_topics'] : $board_info['num_topics'] + $board_info['unapproved_user_topics']; |
@@ -73,12 +75,14 @@ discard block |
||
73 | 75 | $session_name = session_name(); |
74 | 76 | foreach ($_GET as $k => $v) |
75 | 77 | { |
76 | - if (!in_array($k, array('board', 'start', $session_name))) |
|
77 | - $context['robot_no_index'] = true; |
|
78 | + if (!in_array($k, array('board', 'start', $session_name))) { |
|
79 | + $context['robot_no_index'] = true; |
|
80 | + } |
|
78 | 81 | } |
79 | 82 | } |
80 | - if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0)) |
|
81 | - $context['robot_no_index'] = true; |
|
83 | + if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0)) { |
|
84 | + $context['robot_no_index'] = true; |
|
85 | + } |
|
82 | 86 | |
83 | 87 | // If we can view unapproved messages and there are some build up a list. |
84 | 88 | if (allowedTo('approve_posts') && ($board_info['unapproved_topics'] || $board_info['unapproved_posts'])) |
@@ -89,14 +93,16 @@ discard block |
||
89 | 93 | } |
90 | 94 | |
91 | 95 | // We only know these. |
92 | - if (isset($_REQUEST['sort']) && !in_array($_REQUEST['sort'], array('subject', 'starter', 'last_poster', 'replies', 'views', 'first_post', 'last_post'))) |
|
93 | - $_REQUEST['sort'] = 'last_post'; |
|
96 | + if (isset($_REQUEST['sort']) && !in_array($_REQUEST['sort'], array('subject', 'starter', 'last_poster', 'replies', 'views', 'first_post', 'last_post'))) { |
|
97 | + $_REQUEST['sort'] = 'last_post'; |
|
98 | + } |
|
94 | 99 | |
95 | 100 | // Make sure the starting place makes sense and construct the page index. |
96 | - if (isset($_REQUEST['sort'])) |
|
97 | - $context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%1$d;sort=' . $_REQUEST['sort'] . (isset($_REQUEST['desc']) ? ';desc' : ''), $_REQUEST['start'], $board_info['total_topics'], $maxindex, true); |
|
98 | - else |
|
99 | - $context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%1$d', $_REQUEST['start'], $board_info['total_topics'], $maxindex, true); |
|
101 | + if (isset($_REQUEST['sort'])) { |
|
102 | + $context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%1$d;sort=' . $_REQUEST['sort'] . (isset($_REQUEST['desc']) ? ';desc' : ''), $_REQUEST['start'], $board_info['total_topics'], $maxindex, true); |
|
103 | + } else { |
|
104 | + $context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%1$d', $_REQUEST['start'], $board_info['total_topics'], $maxindex, true); |
|
105 | + } |
|
100 | 106 | $context['start'] = &$_REQUEST['start']; |
101 | 107 | |
102 | 108 | // Set a canonical URL for this page. |
@@ -132,14 +138,16 @@ discard block |
||
132 | 138 | $context['link_moderators'] = array(); |
133 | 139 | if (!empty($board_info['moderators'])) |
134 | 140 | { |
135 | - foreach ($board_info['moderators'] as $mod) |
|
136 | - $context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>'; |
|
141 | + foreach ($board_info['moderators'] as $mod) { |
|
142 | + $context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>'; |
|
143 | + } |
|
137 | 144 | } |
138 | 145 | if (!empty($board_info['moderator_groups'])) |
139 | 146 | { |
140 | 147 | // By default just tack the moderator groups onto the end of the members |
141 | - foreach ($board_info['moderator_groups'] as $mod_group) |
|
142 | - $context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>'; |
|
148 | + foreach ($board_info['moderator_groups'] as $mod_group) { |
|
149 | + $context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>'; |
|
150 | + } |
|
143 | 151 | } |
144 | 152 | |
145 | 153 | // Now we tack the info onto the end of the linktree |
@@ -191,20 +199,24 @@ discard block |
||
191 | 199 | ); |
192 | 200 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
193 | 201 | { |
194 | - if (empty($row['id_member'])) |
|
195 | - continue; |
|
202 | + if (empty($row['id_member'])) { |
|
203 | + continue; |
|
204 | + } |
|
196 | 205 | |
197 | - if (!empty($row['online_color'])) |
|
198 | - $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>'; |
|
199 | - else |
|
200 | - $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
206 | + if (!empty($row['online_color'])) { |
|
207 | + $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>'; |
|
208 | + } else { |
|
209 | + $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
210 | + } |
|
201 | 211 | |
202 | 212 | $is_buddy = in_array($row['id_member'], $user_info['buddies']); |
203 | - if ($is_buddy) |
|
204 | - $link = '<strong>' . $link . '</strong>'; |
|
213 | + if ($is_buddy) { |
|
214 | + $link = '<strong>' . $link . '</strong>'; |
|
215 | + } |
|
205 | 216 | |
206 | - if (!empty($row['show_online']) || allowedTo('moderate_forum')) |
|
207 | - $context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link; |
|
217 | + if (!empty($row['show_online']) || allowedTo('moderate_forum')) { |
|
218 | + $context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link; |
|
219 | + } |
|
208 | 220 | // @todo why are we filling this array of data that are just counted (twice) and discarded? ??? |
209 | 221 | $context['view_members'][$row['log_time'] . $row['member_name']] = array( |
210 | 222 | 'id' => $row['id_member'], |
@@ -217,8 +229,9 @@ discard block |
||
217 | 229 | 'hidden' => empty($row['show_online']), |
218 | 230 | ); |
219 | 231 | |
220 | - if (empty($row['show_online'])) |
|
221 | - $context['view_num_hidden']++; |
|
232 | + if (empty($row['show_online'])) { |
|
233 | + $context['view_num_hidden']++; |
|
234 | + } |
|
222 | 235 | } |
223 | 236 | $context['view_num_guests'] = $smcFunc['db_num_rows']($request) - count($context['view_members']); |
224 | 237 | $smcFunc['db_free_result']($request); |
@@ -257,8 +270,9 @@ discard block |
||
257 | 270 | $context['sort_direction'] = $ascending ? 'up' : 'down'; |
258 | 271 | $txt['starter'] = $txt['started_by']; |
259 | 272 | |
260 | - foreach ($sort_methods as $key => $val) |
|
261 | - $context['topics_headers'][$key] = '<a href="' . $scripturl . '?board=' . $context['current_board'] . '.' . $context['start'] . ';sort=' . $key . ($context['sort_by'] == $key && $context['sort_direction'] == 'up' ? ';desc' : '') . '">' . $txt[$key] . ($context['sort_by'] == $key ? '<span class="sort sort_' . $context['sort_direction'] . '"></span>' : '') . '</a>'; |
|
273 | + foreach ($sort_methods as $key => $val) { |
|
274 | + $context['topics_headers'][$key] = '<a href="' . $scripturl . '?board=' . $context['current_board'] . '.' . $context['start'] . ';sort=' . $key . ($context['sort_by'] == $key && $context['sort_direction'] == 'up' ? ';desc' : '') . '">' . $txt[$key] . ($context['sort_by'] == $key ? '<span class="sort sort_' . $context['sort_direction'] . '"></span>' : '') . '</a>'; |
|
275 | + } |
|
262 | 276 | |
263 | 277 | // Calculate the fastest way to get the topics. |
264 | 278 | $start = (int) $_REQUEST['start']; |
@@ -268,14 +282,15 @@ discard block |
||
268 | 282 | $fake_ascending = true; |
269 | 283 | $maxindex = $board_info['total_topics'] < $start + $maxindex + 1 ? $board_info['total_topics'] - $start : $maxindex; |
270 | 284 | $start = $board_info['total_topics'] < $start + $maxindex + 1 ? 0 : $board_info['total_topics'] - $start - $maxindex; |
285 | + } else { |
|
286 | + $fake_ascending = false; |
|
271 | 287 | } |
272 | - else |
|
273 | - $fake_ascending = false; |
|
274 | 288 | |
275 | 289 | // Setup the default topic icons... |
276 | 290 | $context['icon_sources'] = array(); |
277 | - foreach ($context['stable_icons'] as $icon) |
|
278 | - $context['icon_sources'][$icon] = 'images_url'; |
|
291 | + foreach ($context['stable_icons'] as $icon) { |
|
292 | + $context['icon_sources'][$icon] = 'images_url'; |
|
293 | + } |
|
279 | 294 | |
280 | 295 | $topic_ids = array(); |
281 | 296 | $context['topics'] = array(); |
@@ -306,8 +321,9 @@ discard block |
||
306 | 321 | ) |
307 | 322 | ); |
308 | 323 | $topic_ids = array(); |
309 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
310 | - $topic_ids[] = $row['id_topic']; |
|
324 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
325 | + $topic_ids[] = $row['id_topic']; |
|
326 | + } |
|
311 | 327 | } |
312 | 328 | |
313 | 329 | // Grab the appropriate topic information... |
@@ -363,11 +379,13 @@ discard block |
||
363 | 379 | // Begin 'printing' the message index for current board. |
364 | 380 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
365 | 381 | { |
366 | - if ($row['id_poll'] > 0 && $modSettings['pollMode'] == '0') |
|
367 | - continue; |
|
382 | + if ($row['id_poll'] > 0 && $modSettings['pollMode'] == '0') { |
|
383 | + continue; |
|
384 | + } |
|
368 | 385 | |
369 | - if (!$pre_query) |
|
370 | - $topic_ids[] = $row['id_topic']; |
|
386 | + if (!$pre_query) { |
|
387 | + $topic_ids[] = $row['id_topic']; |
|
388 | + } |
|
371 | 389 | |
372 | 390 | // Reference the main color class. |
373 | 391 | $colorClass = 'windowbg'; |
@@ -377,8 +395,9 @@ discard block |
||
377 | 395 | { |
378 | 396 | // Limit them to $modSettings['preview_characters'] characters |
379 | 397 | $row['first_body'] = strip_tags(strtr(parse_bbc($row['first_body'], $row['first_smileys'], $row['id_first_msg']), array('<br>' => ' '))); |
380 | - if ($smcFunc['strlen']($row['first_body']) > $modSettings['preview_characters']) |
|
381 | - $row['first_body'] = $smcFunc['substr']($row['first_body'], 0, $modSettings['preview_characters']) . '...'; |
|
398 | + if ($smcFunc['strlen']($row['first_body']) > $modSettings['preview_characters']) { |
|
399 | + $row['first_body'] = $smcFunc['substr']($row['first_body'], 0, $modSettings['preview_characters']) . '...'; |
|
400 | + } |
|
382 | 401 | |
383 | 402 | // Censor the subject and message preview. |
384 | 403 | censorText($row['first_subject']); |
@@ -389,27 +408,27 @@ discard block |
||
389 | 408 | { |
390 | 409 | $row['last_subject'] = $row['first_subject']; |
391 | 410 | $row['last_body'] = $row['first_body']; |
392 | - } |
|
393 | - else |
|
411 | + } else |
|
394 | 412 | { |
395 | 413 | $row['last_body'] = strip_tags(strtr(parse_bbc($row['last_body'], $row['last_smileys'], $row['id_last_msg']), array('<br>' => ' '))); |
396 | - if ($smcFunc['strlen']($row['last_body']) > $modSettings['preview_characters']) |
|
397 | - $row['last_body'] = $smcFunc['substr']($row['last_body'], 0, $modSettings['preview_characters']) . '...'; |
|
414 | + if ($smcFunc['strlen']($row['last_body']) > $modSettings['preview_characters']) { |
|
415 | + $row['last_body'] = $smcFunc['substr']($row['last_body'], 0, $modSettings['preview_characters']) . '...'; |
|
416 | + } |
|
398 | 417 | |
399 | 418 | censorText($row['last_subject']); |
400 | 419 | censorText($row['last_body']); |
401 | 420 | } |
402 | - } |
|
403 | - else |
|
421 | + } else |
|
404 | 422 | { |
405 | 423 | $row['first_body'] = ''; |
406 | 424 | $row['last_body'] = ''; |
407 | 425 | censorText($row['first_subject']); |
408 | 426 | |
409 | - if ($row['id_first_msg'] == $row['id_last_msg']) |
|
410 | - $row['last_subject'] = $row['first_subject']; |
|
411 | - else |
|
412 | - censorText($row['last_subject']); |
|
427 | + if ($row['id_first_msg'] == $row['id_last_msg']) { |
|
428 | + $row['last_subject'] = $row['first_subject']; |
|
429 | + } else { |
|
430 | + censorText($row['last_subject']); |
|
431 | + } |
|
413 | 432 | } |
414 | 433 | |
415 | 434 | // Decide how many pages the topic should have. |
@@ -420,42 +439,50 @@ discard block |
||
420 | 439 | $pages = constructPageIndex($scripturl . '?topic=' . $row['id_topic'] . '.%1$d', $start, $row['num_replies'] + 1, $context['messages_per_page'], true, false); |
421 | 440 | |
422 | 441 | // If we can use all, show all. |
423 | - if (!empty($modSettings['enableAllMessages']) && $row['num_replies'] + 1 < $modSettings['enableAllMessages']) |
|
424 | - $pages .= ' <a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;all">' . $txt['all'] . '</a>'; |
|
442 | + if (!empty($modSettings['enableAllMessages']) && $row['num_replies'] + 1 < $modSettings['enableAllMessages']) { |
|
443 | + $pages .= ' <a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;all">' . $txt['all'] . '</a>'; |
|
444 | + } |
|
445 | + } else { |
|
446 | + $pages = ''; |
|
425 | 447 | } |
426 | - else |
|
427 | - $pages = ''; |
|
428 | 448 | |
429 | 449 | // We need to check the topic icons exist... |
430 | 450 | if (!empty($modSettings['messageIconChecks_enable'])) |
431 | 451 | { |
432 | - if (!isset($context['icon_sources'][$row['first_icon']])) |
|
433 | - $context['icon_sources'][$row['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['first_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
434 | - if (!isset($context['icon_sources'][$row['last_icon']])) |
|
435 | - $context['icon_sources'][$row['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['last_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
436 | - } |
|
437 | - else |
|
452 | + if (!isset($context['icon_sources'][$row['first_icon']])) { |
|
453 | + $context['icon_sources'][$row['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['first_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
454 | + } |
|
455 | + if (!isset($context['icon_sources'][$row['last_icon']])) { |
|
456 | + $context['icon_sources'][$row['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['last_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
457 | + } |
|
458 | + } else |
|
438 | 459 | { |
439 | - if (!isset($context['icon_sources'][$row['first_icon']])) |
|
440 | - $context['icon_sources'][$row['first_icon']] = 'images_url'; |
|
441 | - if (!isset($context['icon_sources'][$row['last_icon']])) |
|
442 | - $context['icon_sources'][$row['last_icon']] = 'images_url'; |
|
460 | + if (!isset($context['icon_sources'][$row['first_icon']])) { |
|
461 | + $context['icon_sources'][$row['first_icon']] = 'images_url'; |
|
462 | + } |
|
463 | + if (!isset($context['icon_sources'][$row['last_icon']])) { |
|
464 | + $context['icon_sources'][$row['last_icon']] = 'images_url'; |
|
465 | + } |
|
443 | 466 | } |
444 | 467 | |
445 | - if (!empty($board_info['recycle'])) |
|
446 | - $row['first_icon'] = 'recycled'; |
|
468 | + if (!empty($board_info['recycle'])) { |
|
469 | + $row['first_icon'] = 'recycled'; |
|
470 | + } |
|
447 | 471 | |
448 | 472 | // Is this topic pending approval, or does it have any posts pending approval? |
449 | - if ($context['can_approve_posts'] && $row['unapproved_posts']) |
|
450 | - $colorClass .= (!$row['approved'] ? ' approvetopic' : ' approvepost'); |
|
473 | + if ($context['can_approve_posts'] && $row['unapproved_posts']) { |
|
474 | + $colorClass .= (!$row['approved'] ? ' approvetopic' : ' approvepost'); |
|
475 | + } |
|
451 | 476 | |
452 | 477 | // Sticky topics should get a different color, too. |
453 | - if ($row['is_sticky']) |
|
454 | - $colorClass .= ' sticky'; |
|
478 | + if ($row['is_sticky']) { |
|
479 | + $colorClass .= ' sticky'; |
|
480 | + } |
|
455 | 481 | |
456 | 482 | // Locked topics get special treatment as well. |
457 | - if ($row['locked']) |
|
458 | - $colorClass .= ' locked'; |
|
483 | + if ($row['locked']) { |
|
484 | + $colorClass .= ' locked'; |
|
485 | + } |
|
459 | 486 | |
460 | 487 | // 'Print' the topic info. |
461 | 488 | $context['topics'][$row['id_topic']] = array_merge($row, array( |
@@ -536,8 +563,9 @@ discard block |
||
536 | 563 | $smcFunc['db_free_result']($result); |
537 | 564 | |
538 | 565 | // Fix the sequence of topics if they were retrieved in the wrong order. (for speed reasons...) |
539 | - if ($fake_ascending) |
|
540 | - $context['topics'] = array_reverse($context['topics'], true); |
|
566 | + if ($fake_ascending) { |
|
567 | + $context['topics'] = array_reverse($context['topics'], true); |
|
568 | + } |
|
541 | 569 | |
542 | 570 | if (!empty($modSettings['enableParticipation']) && !$user_info['is_guest'] && !empty($topic_ids)) |
543 | 571 | { |
@@ -554,8 +582,9 @@ discard block |
||
554 | 582 | 'limit' => count($topic_ids), |
555 | 583 | ) |
556 | 584 | ); |
557 | - while ($row = $smcFunc['db_fetch_assoc']($result)) |
|
558 | - $context['topics'][$row['id_topic']]['is_posted_in'] = true; |
|
585 | + while ($row = $smcFunc['db_fetch_assoc']($result)) { |
|
586 | + $context['topics'][$row['id_topic']]['is_posted_in'] = true; |
|
587 | + } |
|
559 | 588 | $smcFunc['db_free_result']($result); |
560 | 589 | } |
561 | 590 | } |
@@ -580,9 +609,9 @@ discard block |
||
580 | 609 | // Can we restore topics? |
581 | 610 | $context['can_restore'] = allowedTo('move_any') && !empty($board_info['recycle']); |
582 | 611 | |
583 | - if ($user_info['is_admin'] || $modSettings['topic_move_any']) |
|
584 | - $context['can_move_any'] = true; |
|
585 | - else |
|
612 | + if ($user_info['is_admin'] || $modSettings['topic_move_any']) { |
|
613 | + $context['can_move_any'] = true; |
|
614 | + } else |
|
586 | 615 | { |
587 | 616 | // We'll use this in a minute |
588 | 617 | $boards_allowed = boardsAllowedTo('post_new'); |
@@ -609,11 +638,13 @@ discard block |
||
609 | 638 | } |
610 | 639 | |
611 | 640 | // Can we use quick moderation checkboxes? |
612 | - if ($options['display_quick_mod'] == 1) |
|
613 | - $context['can_quick_mod'] = $context['user']['is_logged'] || $context['can_approve'] || $context['can_remove'] || $context['can_lock'] || $context['can_sticky'] || $context['can_move'] || $context['can_merge'] || $context['can_restore']; |
|
641 | + if ($options['display_quick_mod'] == 1) { |
|
642 | + $context['can_quick_mod'] = $context['user']['is_logged'] || $context['can_approve'] || $context['can_remove'] || $context['can_lock'] || $context['can_sticky'] || $context['can_move'] || $context['can_merge'] || $context['can_restore']; |
|
643 | + } |
|
614 | 644 | // Or the icons? |
615 | - else |
|
616 | - $context['can_quick_mod'] = $context['can_remove'] || $context['can_lock'] || $context['can_sticky'] || $context['can_move']; |
|
645 | + else { |
|
646 | + $context['can_quick_mod'] = $context['can_remove'] || $context['can_lock'] || $context['can_sticky'] || $context['can_move']; |
|
647 | + } |
|
617 | 648 | } |
618 | 649 | |
619 | 650 | if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] == 1) |
@@ -647,13 +678,15 @@ discard block |
||
647 | 678 | ); |
648 | 679 | |
649 | 680 | // We've seen all these boards now! |
650 | - foreach ($board_info['parent_boards'] as $k => $dummy) |
|
651 | - if (isset($_SESSION['topicseen_cache'][$k])) |
|
681 | + foreach ($board_info['parent_boards'] as $k => $dummy) { |
|
682 | + if (isset($_SESSION['topicseen_cache'][$k])) |
|
652 | 683 | unset($_SESSION['topicseen_cache'][$k]); |
684 | + } |
|
653 | 685 | } |
654 | 686 | |
655 | - if (isset($_SESSION['topicseen_cache'][$board])) |
|
656 | - unset($_SESSION['topicseen_cache'][$board]); |
|
687 | + if (isset($_SESSION['topicseen_cache'][$board])) { |
|
688 | + unset($_SESSION['topicseen_cache'][$board]); |
|
689 | + } |
|
657 | 690 | |
658 | 691 | $request = $smcFunc['db_query']('', ' |
659 | 692 | SELECT id_topic, id_board, sent |
@@ -674,8 +707,9 @@ discard block |
||
674 | 707 | $context['is_marked_notify'] = true; |
675 | 708 | $board_sent = $row['sent']; |
676 | 709 | } |
677 | - if (!empty($row['id_topic'])) |
|
678 | - $context['topics'][$row['id_topic']]['is_watched'] = true; |
|
710 | + if (!empty($row['id_topic'])) { |
|
711 | + $context['topics'][$row['id_topic']]['is_watched'] = true; |
|
712 | + } |
|
679 | 713 | } |
680 | 714 | $smcFunc['db_free_result']($request); |
681 | 715 | |
@@ -699,8 +733,7 @@ discard block |
||
699 | 733 | $pref = !empty($pref[$user_info['id']]) ? $pref[$user_info['id']] : array(); |
700 | 734 | $pref = isset($pref['board_notify_' . $board]) ? $pref['board_notify_' . $board] : (!empty($pref['board_notify']) ? $pref['board_notify'] : 0); |
701 | 735 | $context['board_notification_mode'] = !$context['is_marked_notify'] ? 1 : ($pref & 0x02 ? 3 : ($pref & 0x01 ? 2 : 1)); |
702 | - } |
|
703 | - else |
|
736 | + } else |
|
704 | 737 | { |
705 | 738 | $context['is_marked_notify'] = false; |
706 | 739 | $context['board_notification_mode'] = 1; |
@@ -713,23 +746,27 @@ discard block |
||
713 | 746 | $context['becomesUnapproved'] = !empty($_SESSION['becomesUnapproved']) ? true : false; |
714 | 747 | |
715 | 748 | // Don't want to show this forever... |
716 | - if ($context['becomesUnapproved']) |
|
717 | - unset($_SESSION['becomesUnapproved']); |
|
749 | + if ($context['becomesUnapproved']) { |
|
750 | + unset($_SESSION['becomesUnapproved']); |
|
751 | + } |
|
718 | 752 | |
719 | 753 | // Build the message index button array. |
720 | 754 | $context['normal_buttons'] = array(); |
721 | 755 | |
722 | - if ($context['can_post_new']) |
|
723 | - $context['normal_buttons']['new_topic'] = array('text' => 'new_topic', 'image' => 'new_topic.png', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0', 'active' => true); |
|
756 | + if ($context['can_post_new']) { |
|
757 | + $context['normal_buttons']['new_topic'] = array('text' => 'new_topic', 'image' => 'new_topic.png', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0', 'active' => true); |
|
758 | + } |
|
724 | 759 | |
725 | - if ($context['can_post_poll']) |
|
726 | - $context['normal_buttons']['post_poll'] = array('text' => 'new_poll', 'image' => 'new_poll.png', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0;poll'); |
|
760 | + if ($context['can_post_poll']) { |
|
761 | + $context['normal_buttons']['post_poll'] = array('text' => 'new_poll', 'image' => 'new_poll.png', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0;poll'); |
|
762 | + } |
|
727 | 763 | |
728 | - if (!$context['user']['is_logged']) |
|
729 | - $context['normal_buttons']['markread'] = array('text' => 'mark_read_short', 'image' => 'markread.png', 'lang' => true, 'custom' => 'data-confirm="' . $txt['are_sure_mark_read'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=markasread;sa=board;board=' . $context['current_board'] . '.0;' . $context['session_var'] . '=' . $context['session_id']); |
|
764 | + if (!$context['user']['is_logged']) { |
|
765 | + $context['normal_buttons']['markread'] = array('text' => 'mark_read_short', 'image' => 'markread.png', 'lang' => true, 'custom' => 'data-confirm="' . $txt['are_sure_mark_read'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=markasread;sa=board;board=' . $context['current_board'] . '.0;' . $context['session_var'] . '=' . $context['session_id']); |
|
766 | + } |
|
730 | 767 | |
731 | - if ($context['can_mark_notify']) |
|
732 | - $context['normal_buttons']['notify'] = array( |
|
768 | + if ($context['can_mark_notify']) { |
|
769 | + $context['normal_buttons']['notify'] = array( |
|
733 | 770 | 'lang' => true, |
734 | 771 | 'text' => 'notify_board_' . $context['board_notification_mode'], |
735 | 772 | 'sub_buttons' => array( |
@@ -747,6 +784,7 @@ discard block |
||
747 | 784 | ), |
748 | 785 | ), |
749 | 786 | ); |
787 | + } |
|
750 | 788 | |
751 | 789 | // Javascript for inline editing. |
752 | 790 | loadJavaScriptFile('topic.js', array('defer' => false), 'smf_topic'); |
@@ -768,18 +806,21 @@ discard block |
||
768 | 806 | checkSession('request'); |
769 | 807 | |
770 | 808 | // Lets go straight to the restore area. |
771 | - if (isset($_REQUEST['qaction']) && $_REQUEST['qaction'] == 'restore' && !empty($_REQUEST['topics'])) |
|
772 | - redirectexit('action=restoretopic;topics=' . implode(',', $_REQUEST['topics']) . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
809 | + if (isset($_REQUEST['qaction']) && $_REQUEST['qaction'] == 'restore' && !empty($_REQUEST['topics'])) { |
|
810 | + redirectexit('action=restoretopic;topics=' . implode(',', $_REQUEST['topics']) . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
811 | + } |
|
773 | 812 | |
774 | - if (isset($_SESSION['topicseen_cache'])) |
|
775 | - $_SESSION['topicseen_cache'] = array(); |
|
813 | + if (isset($_SESSION['topicseen_cache'])) { |
|
814 | + $_SESSION['topicseen_cache'] = array(); |
|
815 | + } |
|
776 | 816 | |
777 | 817 | // This is going to be needed to send off the notifications and for updateLastMessages(). |
778 | 818 | require_once($sourcedir . '/Subs-Post.php'); |
779 | 819 | |
780 | 820 | // Remember the last board they moved things to. |
781 | - if (isset($_REQUEST['move_to'])) |
|
782 | - $_SESSION['move_to_topic'] = $_REQUEST['move_to']; |
|
821 | + if (isset($_REQUEST['move_to'])) { |
|
822 | + $_SESSION['move_to_topic'] = $_REQUEST['move_to']; |
|
823 | + } |
|
783 | 824 | |
784 | 825 | // Only a few possible actions. |
785 | 826 | $possibleActions = array(); |
@@ -799,8 +840,7 @@ discard block |
||
799 | 840 | ); |
800 | 841 | |
801 | 842 | $redirect_url = 'board=' . $board . '.' . $_REQUEST['start']; |
802 | - } |
|
803 | - else |
|
843 | + } else |
|
804 | 844 | { |
805 | 845 | /** |
806 | 846 | * @todo Ugly. There's no getting around this, is there? |
@@ -818,8 +858,7 @@ discard block |
||
818 | 858 | if (!empty($board)) |
819 | 859 | { |
820 | 860 | $boards_can['post_new'] = array_diff(boardsAllowedTo('post_new'), array($board)); |
821 | - } |
|
822 | - else |
|
861 | + } else |
|
823 | 862 | { |
824 | 863 | $boards_can['post_new'] = boardsAllowedTo('post_new'); |
825 | 864 | } |
@@ -830,55 +869,67 @@ discard block |
||
830 | 869 | } |
831 | 870 | } |
832 | 871 | |
833 | - if (!$user_info['is_guest']) |
|
834 | - $possibleActions[] = 'markread'; |
|
835 | - if (!empty($boards_can['make_sticky'])) |
|
836 | - $possibleActions[] = 'sticky'; |
|
837 | - if (!empty($boards_can['move_any']) || !empty($boards_can['move_own'])) |
|
838 | - $possibleActions[] = 'move'; |
|
839 | - if (!empty($boards_can['remove_any']) || !empty($boards_can['remove_own'])) |
|
840 | - $possibleActions[] = 'remove'; |
|
841 | - if (!empty($boards_can['lock_any']) || !empty($boards_can['lock_own'])) |
|
842 | - $possibleActions[] = 'lock'; |
|
843 | - if (!empty($boards_can['merge_any'])) |
|
844 | - $possibleActions[] = 'merge'; |
|
845 | - if (!empty($boards_can['approve_posts'])) |
|
846 | - $possibleActions[] = 'approve'; |
|
872 | + if (!$user_info['is_guest']) { |
|
873 | + $possibleActions[] = 'markread'; |
|
874 | + } |
|
875 | + if (!empty($boards_can['make_sticky'])) { |
|
876 | + $possibleActions[] = 'sticky'; |
|
877 | + } |
|
878 | + if (!empty($boards_can['move_any']) || !empty($boards_can['move_own'])) { |
|
879 | + $possibleActions[] = 'move'; |
|
880 | + } |
|
881 | + if (!empty($boards_can['remove_any']) || !empty($boards_can['remove_own'])) { |
|
882 | + $possibleActions[] = 'remove'; |
|
883 | + } |
|
884 | + if (!empty($boards_can['lock_any']) || !empty($boards_can['lock_own'])) { |
|
885 | + $possibleActions[] = 'lock'; |
|
886 | + } |
|
887 | + if (!empty($boards_can['merge_any'])) { |
|
888 | + $possibleActions[] = 'merge'; |
|
889 | + } |
|
890 | + if (!empty($boards_can['approve_posts'])) { |
|
891 | + $possibleActions[] = 'approve'; |
|
892 | + } |
|
847 | 893 | |
848 | 894 | // Two methods: $_REQUEST['actions'] (id_topic => action), and $_REQUEST['topics'] and $_REQUEST['qaction']. |
849 | 895 | // (if action is 'move', $_REQUEST['move_to'] or $_REQUEST['move_tos'][$topic] is used.) |
850 | 896 | if (!empty($_REQUEST['topics'])) |
851 | 897 | { |
852 | 898 | // If the action isn't valid, just quit now. |
853 | - if (empty($_REQUEST['qaction']) || !in_array($_REQUEST['qaction'], $possibleActions)) |
|
854 | - redirectexit($redirect_url); |
|
899 | + if (empty($_REQUEST['qaction']) || !in_array($_REQUEST['qaction'], $possibleActions)) { |
|
900 | + redirectexit($redirect_url); |
|
901 | + } |
|
855 | 902 | |
856 | 903 | // Merge requires all topics as one parameter and can be done at once. |
857 | 904 | if ($_REQUEST['qaction'] == 'merge') |
858 | 905 | { |
859 | 906 | // Merge requires at least two topics. |
860 | - if (empty($_REQUEST['topics']) || count($_REQUEST['topics']) < 2) |
|
861 | - redirectexit($redirect_url); |
|
907 | + if (empty($_REQUEST['topics']) || count($_REQUEST['topics']) < 2) { |
|
908 | + redirectexit($redirect_url); |
|
909 | + } |
|
862 | 910 | |
863 | 911 | require_once($sourcedir . '/SplitTopics.php'); |
864 | 912 | return MergeExecute($_REQUEST['topics']); |
865 | 913 | } |
866 | 914 | |
867 | 915 | // Just convert to the other method, to make it easier. |
868 | - foreach ($_REQUEST['topics'] as $topic) |
|
869 | - $_REQUEST['actions'][(int) $topic] = $_REQUEST['qaction']; |
|
916 | + foreach ($_REQUEST['topics'] as $topic) { |
|
917 | + $_REQUEST['actions'][(int) $topic] = $_REQUEST['qaction']; |
|
918 | + } |
|
870 | 919 | } |
871 | 920 | |
872 | 921 | // Weird... how'd you get here? |
873 | - if (empty($_REQUEST['actions'])) |
|
874 | - redirectexit($redirect_url); |
|
922 | + if (empty($_REQUEST['actions'])) { |
|
923 | + redirectexit($redirect_url); |
|
924 | + } |
|
875 | 925 | |
876 | 926 | // Validate each action. |
877 | 927 | $temp = array(); |
878 | 928 | foreach ($_REQUEST['actions'] as $topic => $action) |
879 | 929 | { |
880 | - if (in_array($action, $possibleActions)) |
|
881 | - $temp[(int) $topic] = $action; |
|
930 | + if (in_array($action, $possibleActions)) { |
|
931 | + $temp[(int) $topic] = $action; |
|
932 | + } |
|
882 | 933 | } |
883 | 934 | $_REQUEST['actions'] = $temp; |
884 | 935 | |
@@ -899,27 +950,31 @@ discard block |
||
899 | 950 | { |
900 | 951 | if (!empty($board)) |
901 | 952 | { |
902 | - if ($row['id_board'] != $board || ($modSettings['postmod_active'] && !$row['approved'] && !allowedTo('approve_posts'))) |
|
903 | - unset($_REQUEST['actions'][$row['id_topic']]); |
|
904 | - } |
|
905 | - else |
|
953 | + if ($row['id_board'] != $board || ($modSettings['postmod_active'] && !$row['approved'] && !allowedTo('approve_posts'))) { |
|
954 | + unset($_REQUEST['actions'][$row['id_topic']]); |
|
955 | + } |
|
956 | + } else |
|
906 | 957 | { |
907 | 958 | // Don't allow them to act on unapproved posts they can't see... |
908 | - if ($modSettings['postmod_active'] && !$row['approved'] && !in_array(0, $boards_can['approve_posts']) && !in_array($row['id_board'], $boards_can['approve_posts'])) |
|
909 | - unset($_REQUEST['actions'][$row['id_topic']]); |
|
959 | + if ($modSettings['postmod_active'] && !$row['approved'] && !in_array(0, $boards_can['approve_posts']) && !in_array($row['id_board'], $boards_can['approve_posts'])) { |
|
960 | + unset($_REQUEST['actions'][$row['id_topic']]); |
|
961 | + } |
|
910 | 962 | // Goodness, this is fun. We need to validate the action. |
911 | - elseif ($_REQUEST['actions'][$row['id_topic']] == 'sticky' && !in_array(0, $boards_can['make_sticky']) && !in_array($row['id_board'], $boards_can['make_sticky'])) |
|
912 | - unset($_REQUEST['actions'][$row['id_topic']]); |
|
913 | - elseif ($_REQUEST['actions'][$row['id_topic']] == 'move' && !in_array(0, $boards_can['move_any']) && !in_array($row['id_board'], $boards_can['move_any']) && ($row['id_member_started'] != $user_info['id'] || (!in_array(0, $boards_can['move_own']) && !in_array($row['id_board'], $boards_can['move_own'])))) |
|
914 | - unset($_REQUEST['actions'][$row['id_topic']]); |
|
915 | - elseif ($_REQUEST['actions'][$row['id_topic']] == 'remove' && !in_array(0, $boards_can['remove_any']) && !in_array($row['id_board'], $boards_can['remove_any']) && ($row['id_member_started'] != $user_info['id'] || (!in_array(0, $boards_can['remove_own']) && !in_array($row['id_board'], $boards_can['remove_own'])))) |
|
916 | - unset($_REQUEST['actions'][$row['id_topic']]); |
|
963 | + elseif ($_REQUEST['actions'][$row['id_topic']] == 'sticky' && !in_array(0, $boards_can['make_sticky']) && !in_array($row['id_board'], $boards_can['make_sticky'])) { |
|
964 | + unset($_REQUEST['actions'][$row['id_topic']]); |
|
965 | + } elseif ($_REQUEST['actions'][$row['id_topic']] == 'move' && !in_array(0, $boards_can['move_any']) && !in_array($row['id_board'], $boards_can['move_any']) && ($row['id_member_started'] != $user_info['id'] || (!in_array(0, $boards_can['move_own']) && !in_array($row['id_board'], $boards_can['move_own'])))) { |
|
966 | + unset($_REQUEST['actions'][$row['id_topic']]); |
|
967 | + } elseif ($_REQUEST['actions'][$row['id_topic']] == 'remove' && !in_array(0, $boards_can['remove_any']) && !in_array($row['id_board'], $boards_can['remove_any']) && ($row['id_member_started'] != $user_info['id'] || (!in_array(0, $boards_can['remove_own']) && !in_array($row['id_board'], $boards_can['remove_own'])))) { |
|
968 | + unset($_REQUEST['actions'][$row['id_topic']]); |
|
969 | + } |
|
917 | 970 | // @todo $locked is not set, what are you trying to do? (taking the change it is supposed to be $row['locked']) |
918 | - elseif ($_REQUEST['actions'][$row['id_topic']] == 'lock' && !in_array(0, $boards_can['lock_any']) && !in_array($row['id_board'], $boards_can['lock_any']) && ($row['id_member_started'] != $user_info['id'] || $row['locked'] == 1 || (!in_array(0, $boards_can['lock_own']) && !in_array($row['id_board'], $boards_can['lock_own'])))) |
|
919 | - unset($_REQUEST['actions'][$row['id_topic']]); |
|
971 | + elseif ($_REQUEST['actions'][$row['id_topic']] == 'lock' && !in_array(0, $boards_can['lock_any']) && !in_array($row['id_board'], $boards_can['lock_any']) && ($row['id_member_started'] != $user_info['id'] || $row['locked'] == 1 || (!in_array(0, $boards_can['lock_own']) && !in_array($row['id_board'], $boards_can['lock_own'])))) { |
|
972 | + unset($_REQUEST['actions'][$row['id_topic']]); |
|
973 | + } |
|
920 | 974 | // If the topic is approved then you need permission to approve the posts within. |
921 | - elseif ($_REQUEST['actions'][$row['id_topic']] == 'approve' && (!$row['unapproved_posts'] || (!in_array(0, $boards_can['approve_posts']) && !in_array($row['id_board'], $boards_can['approve_posts'])))) |
|
922 | - unset($_REQUEST['actions'][$row['id_topic']]); |
|
975 | + elseif ($_REQUEST['actions'][$row['id_topic']] == 'approve' && (!$row['unapproved_posts'] || (!in_array(0, $boards_can['approve_posts']) && !in_array($row['id_board'], $boards_can['approve_posts'])))) { |
|
976 | + unset($_REQUEST['actions'][$row['id_topic']]); |
|
977 | + } |
|
923 | 978 | } |
924 | 979 | } |
925 | 980 | $smcFunc['db_free_result']($request); |
@@ -937,11 +992,11 @@ discard block |
||
937 | 992 | { |
938 | 993 | $topic = (int) $topic; |
939 | 994 | |
940 | - if ($action == 'markread') |
|
941 | - $markCache[] = $topic; |
|
942 | - elseif ($action == 'sticky') |
|
943 | - $stickyCache[] = $topic; |
|
944 | - elseif ($action == 'move') |
|
995 | + if ($action == 'markread') { |
|
996 | + $markCache[] = $topic; |
|
997 | + } elseif ($action == 'sticky') { |
|
998 | + $stickyCache[] = $topic; |
|
999 | + } elseif ($action == 'move') |
|
945 | 1000 | { |
946 | 1001 | require_once($sourcedir . '/MoveTopic.php'); |
947 | 1002 | moveTopicConcurrence(); |
@@ -949,23 +1004,25 @@ discard block |
||
949 | 1004 | // $moveCache[0] is the topic, $moveCache[1] is the board to move to. |
950 | 1005 | $moveCache[1][$topic] = (int) (isset($_REQUEST['move_tos'][$topic]) ? $_REQUEST['move_tos'][$topic] : $_REQUEST['move_to']); |
951 | 1006 | |
952 | - if (empty($moveCache[1][$topic])) |
|
953 | - continue; |
|
1007 | + if (empty($moveCache[1][$topic])) { |
|
1008 | + continue; |
|
1009 | + } |
|
954 | 1010 | |
955 | 1011 | $moveCache[0][] = $topic; |
1012 | + } elseif ($action == 'remove') { |
|
1013 | + $removeCache[] = $topic; |
|
1014 | + } elseif ($action == 'lock') { |
|
1015 | + $lockCache[] = $topic; |
|
1016 | + } elseif ($action == 'approve') { |
|
1017 | + $approveCache[] = $topic; |
|
956 | 1018 | } |
957 | - elseif ($action == 'remove') |
|
958 | - $removeCache[] = $topic; |
|
959 | - elseif ($action == 'lock') |
|
960 | - $lockCache[] = $topic; |
|
961 | - elseif ($action == 'approve') |
|
962 | - $approveCache[] = $topic; |
|
963 | 1019 | } |
964 | 1020 | |
965 | - if (empty($board)) |
|
966 | - $affectedBoards = array(); |
|
967 | - else |
|
968 | - $affectedBoards = array($board => array(0, 0)); |
|
1021 | + if (empty($board)) { |
|
1022 | + $affectedBoards = array(); |
|
1023 | + } else { |
|
1024 | + $affectedBoards = array($board => array(0, 0)); |
|
1025 | + } |
|
969 | 1026 | |
970 | 1027 | // Do all the stickies... |
971 | 1028 | if (!empty($stickyCache)) |
@@ -1025,14 +1082,16 @@ discard block |
||
1025 | 1082 | { |
1026 | 1083 | $to = $moveCache[1][$row['id_topic']]; |
1027 | 1084 | |
1028 | - if (empty($to)) |
|
1029 | - continue; |
|
1085 | + if (empty($to)) { |
|
1086 | + continue; |
|
1087 | + } |
|
1030 | 1088 | |
1031 | 1089 | // Does this topic's board count the posts or not? |
1032 | 1090 | $countPosts[$row['id_topic']] = empty($row['count_posts']); |
1033 | 1091 | |
1034 | - if (!isset($moveTos[$to])) |
|
1035 | - $moveTos[$to] = array(); |
|
1092 | + if (!isset($moveTos[$to])) { |
|
1093 | + $moveTos[$to] = array(); |
|
1094 | + } |
|
1036 | 1095 | |
1037 | 1096 | $moveTos[$to][] = $row['id_topic']; |
1038 | 1097 | |
@@ -1046,8 +1105,9 @@ discard block |
||
1046 | 1105 | require_once($sourcedir . '/MoveTopic.php'); |
1047 | 1106 | |
1048 | 1107 | // Do the actual moves... |
1049 | - foreach ($moveTos as $to => $topics) |
|
1050 | - moveTopics($topics, $to); |
|
1108 | + foreach ($moveTos as $to => $topics) { |
|
1109 | + moveTopics($topics, $to); |
|
1110 | + } |
|
1051 | 1111 | |
1052 | 1112 | // Does the post counts need to be updated? |
1053 | 1113 | if (!empty($moveTos)) |
@@ -1096,20 +1156,23 @@ discard block |
||
1096 | 1156 | |
1097 | 1157 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1098 | 1158 | { |
1099 | - if (!isset($members[$row['id_member']])) |
|
1100 | - $members[$row['id_member']] = 0; |
|
1159 | + if (!isset($members[$row['id_member']])) { |
|
1160 | + $members[$row['id_member']] = 0; |
|
1161 | + } |
|
1101 | 1162 | |
1102 | - if ($topicRecounts[$row['id_topic']] === '+') |
|
1103 | - $members[$row['id_member']] += 1; |
|
1104 | - else |
|
1105 | - $members[$row['id_member']] -= 1; |
|
1163 | + if ($topicRecounts[$row['id_topic']] === '+') { |
|
1164 | + $members[$row['id_member']] += 1; |
|
1165 | + } else { |
|
1166 | + $members[$row['id_member']] -= 1; |
|
1167 | + } |
|
1106 | 1168 | } |
1107 | 1169 | |
1108 | 1170 | $smcFunc['db_free_result']($request); |
1109 | 1171 | |
1110 | 1172 | // And now update them member's post counts |
1111 | - foreach ($members as $id_member => $post_adj) |
|
1112 | - updateMemberData($id_member, array('posts' => 'posts + ' . $post_adj)); |
|
1173 | + foreach ($members as $id_member => $post_adj) { |
|
1174 | + updateMemberData($id_member, array('posts' => 'posts + ' . $post_adj)); |
|
1175 | + } |
|
1113 | 1176 | |
1114 | 1177 | } |
1115 | 1178 | } |
@@ -1189,8 +1252,9 @@ discard block |
||
1189 | 1252 | approveTopics($approveCache); |
1190 | 1253 | |
1191 | 1254 | // Time for some logging! |
1192 | - foreach ($approveCache as $topic) |
|
1193 | - logAction('approve_topic', array('topic' => $topic, 'member' => $approveCacheMembers[$topic])); |
|
1255 | + foreach ($approveCache as $topic) { |
|
1256 | + logAction('approve_topic', array('topic' => $topic, 'member' => $approveCacheMembers[$topic])); |
|
1257 | + } |
|
1194 | 1258 | } |
1195 | 1259 | } |
1196 | 1260 | |
@@ -1225,8 +1289,7 @@ discard block |
||
1225 | 1289 | $lockStatus[$row['id_topic']] = empty($row['locked']); |
1226 | 1290 | } |
1227 | 1291 | $smcFunc['db_free_result']($result); |
1228 | - } |
|
1229 | - else |
|
1292 | + } else |
|
1230 | 1293 | { |
1231 | 1294 | $result = $smcFunc['db_query']('', ' |
1232 | 1295 | SELECT id_topic, locked, id_board |
@@ -1276,13 +1339,15 @@ discard block |
||
1276 | 1339 | ) |
1277 | 1340 | ); |
1278 | 1341 | $logged_topics = array(); |
1279 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1280 | - $logged_topics[$row['id_topic']] = $row['unwatched']; |
|
1342 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1343 | + $logged_topics[$row['id_topic']] = $row['unwatched']; |
|
1344 | + } |
|
1281 | 1345 | $smcFunc['db_free_result']($request); |
1282 | 1346 | |
1283 | 1347 | $markArray = array(); |
1284 | - foreach ($markCache as $topic) |
|
1285 | - $markArray[] = array($modSettings['maxMsgID'], $user_info['id'], $topic, (isset($logged_topics[$topic]) ? $logged_topics[$topic] : 0)); |
|
1348 | + foreach ($markCache as $topic) { |
|
1349 | + $markArray[] = array($modSettings['maxMsgID'], $user_info['id'], $topic, (isset($logged_topics[$topic]) ? $logged_topics[$topic] : 0)); |
|
1350 | + } |
|
1286 | 1351 | |
1287 | 1352 | $smcFunc['db_insert']('replace', |
1288 | 1353 | '{db_prefix}log_topics', |
@@ -1295,8 +1360,9 @@ discard block |
||
1295 | 1360 | foreach ($moveCache as $topic) |
1296 | 1361 | { |
1297 | 1362 | // Didn't actually move anything! |
1298 | - if (!isset($topic[0])) |
|
1299 | - break; |
|
1363 | + if (!isset($topic[0])) { |
|
1364 | + break; |
|
1365 | + } |
|
1300 | 1366 | |
1301 | 1367 | logAction('move', array('topic' => $topic[0], 'board_from' => $topic[1], 'board_to' => $topic[2])); |
1302 | 1368 | sendNotifications($topic[0], 'move'); |
@@ -1318,8 +1384,9 @@ discard block |
||
1318 | 1384 | 'calendar_updated' => time(), |
1319 | 1385 | )); |
1320 | 1386 | |
1321 | - if (!empty($affectedBoards)) |
|
1322 | - updateLastMessages(array_keys($affectedBoards)); |
|
1387 | + if (!empty($affectedBoards)) { |
|
1388 | + updateLastMessages(array_keys($affectedBoards)); |
|
1389 | + } |
|
1323 | 1390 | |
1324 | 1391 | redirectexit($redirect_url); |
1325 | 1392 | } |
@@ -18,178 +18,178 @@ |
||
18 | 18 | */ |
19 | 19 | class Converter |
20 | 20 | { |
21 | - /** |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - protected $from; |
|
25 | - |
|
26 | - /** |
|
27 | - * @var string |
|
28 | - */ |
|
29 | - protected $to; |
|
30 | - |
|
31 | - /** |
|
32 | - * @param string $from The original base path (directory, not file!) |
|
33 | - * @param string $to The new base path (directory, not file!) |
|
34 | - */ |
|
35 | - public function __construct($from, $to) |
|
36 | - { |
|
37 | - $shared = $this->shared($from, $to); |
|
38 | - if ($shared === '') { |
|
39 | - // when both paths have nothing in common, one of them is probably |
|
40 | - // absolute while the other is relative |
|
41 | - $cwd = getcwd(); |
|
42 | - $from = strpos($from, $cwd) === 0 ? $from : $cwd.'/'.$from; |
|
43 | - $to = strpos($to, $cwd) === 0 ? $to : $cwd.'/'.$to; |
|
44 | - |
|
45 | - // or traveling the tree via `..` |
|
46 | - // attempt to resolve path, or assume it's fine if it doesn't exist |
|
47 | - $from = realpath($from) ?: $from; |
|
48 | - $to = realpath($to) ?: $to; |
|
49 | - } |
|
50 | - |
|
51 | - $from = $this->dirname($from); |
|
52 | - $to = $this->dirname($to); |
|
53 | - |
|
54 | - $from = $this->normalize($from); |
|
55 | - $to = $this->normalize($to); |
|
56 | - |
|
57 | - $this->from = $from; |
|
58 | - $this->to = $to; |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * Normalize path. |
|
63 | - * |
|
64 | - * @param string $path |
|
65 | - * |
|
66 | - * @return string |
|
67 | - */ |
|
68 | - protected function normalize($path) |
|
69 | - { |
|
70 | - // deal with different operating systems' directory structure |
|
71 | - $path = rtrim(str_replace(DIRECTORY_SEPARATOR, '/', $path), '/'); |
|
72 | - |
|
73 | - /* |
|
21 | + /** |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + protected $from; |
|
25 | + |
|
26 | + /** |
|
27 | + * @var string |
|
28 | + */ |
|
29 | + protected $to; |
|
30 | + |
|
31 | + /** |
|
32 | + * @param string $from The original base path (directory, not file!) |
|
33 | + * @param string $to The new base path (directory, not file!) |
|
34 | + */ |
|
35 | + public function __construct($from, $to) |
|
36 | + { |
|
37 | + $shared = $this->shared($from, $to); |
|
38 | + if ($shared === '') { |
|
39 | + // when both paths have nothing in common, one of them is probably |
|
40 | + // absolute while the other is relative |
|
41 | + $cwd = getcwd(); |
|
42 | + $from = strpos($from, $cwd) === 0 ? $from : $cwd.'/'.$from; |
|
43 | + $to = strpos($to, $cwd) === 0 ? $to : $cwd.'/'.$to; |
|
44 | + |
|
45 | + // or traveling the tree via `..` |
|
46 | + // attempt to resolve path, or assume it's fine if it doesn't exist |
|
47 | + $from = realpath($from) ?: $from; |
|
48 | + $to = realpath($to) ?: $to; |
|
49 | + } |
|
50 | + |
|
51 | + $from = $this->dirname($from); |
|
52 | + $to = $this->dirname($to); |
|
53 | + |
|
54 | + $from = $this->normalize($from); |
|
55 | + $to = $this->normalize($to); |
|
56 | + |
|
57 | + $this->from = $from; |
|
58 | + $this->to = $to; |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * Normalize path. |
|
63 | + * |
|
64 | + * @param string $path |
|
65 | + * |
|
66 | + * @return string |
|
67 | + */ |
|
68 | + protected function normalize($path) |
|
69 | + { |
|
70 | + // deal with different operating systems' directory structure |
|
71 | + $path = rtrim(str_replace(DIRECTORY_SEPARATOR, '/', $path), '/'); |
|
72 | + |
|
73 | + /* |
|
74 | 74 | * Example: |
75 | 75 | * /home/forkcms/frontend/cache/compiled_templates/../../core/layout/css/../images/img.gif |
76 | 76 | * to |
77 | 77 | * /home/forkcms/frontend/core/layout/images/img.gif |
78 | 78 | */ |
79 | - do { |
|
80 | - $path = preg_replace('/[^\/]+(?<!\.\.)\/\.\.\//', '', $path, -1, $count); |
|
81 | - } while ($count); |
|
82 | - |
|
83 | - return $path; |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * Figure out the shared path of 2 locations. |
|
88 | - * |
|
89 | - * Example: |
|
90 | - * /home/forkcms/frontend/core/layout/images/img.gif |
|
91 | - * and |
|
92 | - * /home/forkcms/frontend/cache/minified_css |
|
93 | - * share |
|
94 | - * /home/forkcms/frontend |
|
95 | - * |
|
96 | - * @param string $path1 |
|
97 | - * @param string $path2 |
|
98 | - * |
|
99 | - * @return string |
|
100 | - */ |
|
101 | - protected function shared($path1, $path2) |
|
102 | - { |
|
103 | - // $path could theoretically be empty (e.g. no path is given), in which |
|
104 | - // case it shouldn't expand to array(''), which would compare to one's |
|
105 | - // root / |
|
106 | - $path1 = $path1 ? explode('/', $path1) : array(); |
|
107 | - $path2 = $path2 ? explode('/', $path2) : array(); |
|
108 | - |
|
109 | - $shared = array(); |
|
110 | - |
|
111 | - // compare paths & strip identical ancestors |
|
112 | - foreach ($path1 as $i => $chunk) { |
|
113 | - if (isset($path2[$i]) && $path1[$i] == $path2[$i]) { |
|
114 | - $shared[] = $chunk; |
|
115 | - } else { |
|
116 | - break; |
|
117 | - } |
|
118 | - } |
|
119 | - |
|
120 | - return implode('/', $shared); |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Convert paths relative from 1 file to another. |
|
125 | - * |
|
126 | - * E.g. |
|
127 | - * ../images/img.gif relative to /home/forkcms/frontend/core/layout/css |
|
128 | - * should become: |
|
129 | - * ../../core/layout/images/img.gif relative to |
|
130 | - * /home/forkcms/frontend/cache/minified_css |
|
131 | - * |
|
132 | - * @param string $path The relative path that needs to be converted. |
|
133 | - * |
|
134 | - * @return string The new relative path. |
|
135 | - */ |
|
136 | - public function convert($path) |
|
137 | - { |
|
138 | - // quit early if conversion makes no sense |
|
139 | - if ($this->from === $this->to) { |
|
140 | - return $path; |
|
141 | - } |
|
142 | - |
|
143 | - $path = $this->normalize($path); |
|
144 | - // if we're not dealing with a relative path, just return absolute |
|
145 | - if (strpos($path, '/') === 0) { |
|
146 | - return $path; |
|
147 | - } |
|
148 | - |
|
149 | - // normalize paths |
|
150 | - $path = $this->normalize($this->from.'/'.$path); |
|
151 | - |
|
152 | - // strip shared ancestor paths |
|
153 | - $shared = $this->shared($path, $this->to); |
|
154 | - $path = mb_substr($path, mb_strlen($shared)); |
|
155 | - $to = mb_substr($this->to, mb_strlen($shared)); |
|
156 | - |
|
157 | - // add .. for every directory that needs to be traversed to new path |
|
158 | - $to = str_repeat('../', mb_substr_count($to, '/')); |
|
159 | - |
|
160 | - return $to.ltrim($path, '/'); |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * Attempt to get the directory name from a path. |
|
165 | - * |
|
166 | - * @param string $path |
|
167 | - * |
|
168 | - * @return string |
|
169 | - */ |
|
170 | - public function dirname($path) |
|
171 | - { |
|
172 | - if (is_file($path)) { |
|
173 | - return dirname($path); |
|
174 | - } |
|
175 | - |
|
176 | - if (is_dir($path)) { |
|
177 | - return rtrim($path, '/'); |
|
178 | - } |
|
179 | - |
|
180 | - // no known file/dir, start making assumptions |
|
181 | - |
|
182 | - // ends in / = dir |
|
183 | - if (mb_substr($path, -1) === '/') { |
|
184 | - return rtrim($path, '/'); |
|
185 | - } |
|
186 | - |
|
187 | - // has a dot in the name, likely a file |
|
188 | - if (preg_match('/.*\..*$/', basename($path)) !== 0) { |
|
189 | - return dirname($path); |
|
190 | - } |
|
191 | - |
|
192 | - // you're on your own here! |
|
193 | - return $path; |
|
194 | - } |
|
79 | + do { |
|
80 | + $path = preg_replace('/[^\/]+(?<!\.\.)\/\.\.\//', '', $path, -1, $count); |
|
81 | + } while ($count); |
|
82 | + |
|
83 | + return $path; |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * Figure out the shared path of 2 locations. |
|
88 | + * |
|
89 | + * Example: |
|
90 | + * /home/forkcms/frontend/core/layout/images/img.gif |
|
91 | + * and |
|
92 | + * /home/forkcms/frontend/cache/minified_css |
|
93 | + * share |
|
94 | + * /home/forkcms/frontend |
|
95 | + * |
|
96 | + * @param string $path1 |
|
97 | + * @param string $path2 |
|
98 | + * |
|
99 | + * @return string |
|
100 | + */ |
|
101 | + protected function shared($path1, $path2) |
|
102 | + { |
|
103 | + // $path could theoretically be empty (e.g. no path is given), in which |
|
104 | + // case it shouldn't expand to array(''), which would compare to one's |
|
105 | + // root / |
|
106 | + $path1 = $path1 ? explode('/', $path1) : array(); |
|
107 | + $path2 = $path2 ? explode('/', $path2) : array(); |
|
108 | + |
|
109 | + $shared = array(); |
|
110 | + |
|
111 | + // compare paths & strip identical ancestors |
|
112 | + foreach ($path1 as $i => $chunk) { |
|
113 | + if (isset($path2[$i]) && $path1[$i] == $path2[$i]) { |
|
114 | + $shared[] = $chunk; |
|
115 | + } else { |
|
116 | + break; |
|
117 | + } |
|
118 | + } |
|
119 | + |
|
120 | + return implode('/', $shared); |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Convert paths relative from 1 file to another. |
|
125 | + * |
|
126 | + * E.g. |
|
127 | + * ../images/img.gif relative to /home/forkcms/frontend/core/layout/css |
|
128 | + * should become: |
|
129 | + * ../../core/layout/images/img.gif relative to |
|
130 | + * /home/forkcms/frontend/cache/minified_css |
|
131 | + * |
|
132 | + * @param string $path The relative path that needs to be converted. |
|
133 | + * |
|
134 | + * @return string The new relative path. |
|
135 | + */ |
|
136 | + public function convert($path) |
|
137 | + { |
|
138 | + // quit early if conversion makes no sense |
|
139 | + if ($this->from === $this->to) { |
|
140 | + return $path; |
|
141 | + } |
|
142 | + |
|
143 | + $path = $this->normalize($path); |
|
144 | + // if we're not dealing with a relative path, just return absolute |
|
145 | + if (strpos($path, '/') === 0) { |
|
146 | + return $path; |
|
147 | + } |
|
148 | + |
|
149 | + // normalize paths |
|
150 | + $path = $this->normalize($this->from.'/'.$path); |
|
151 | + |
|
152 | + // strip shared ancestor paths |
|
153 | + $shared = $this->shared($path, $this->to); |
|
154 | + $path = mb_substr($path, mb_strlen($shared)); |
|
155 | + $to = mb_substr($this->to, mb_strlen($shared)); |
|
156 | + |
|
157 | + // add .. for every directory that needs to be traversed to new path |
|
158 | + $to = str_repeat('../', mb_substr_count($to, '/')); |
|
159 | + |
|
160 | + return $to.ltrim($path, '/'); |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * Attempt to get the directory name from a path. |
|
165 | + * |
|
166 | + * @param string $path |
|
167 | + * |
|
168 | + * @return string |
|
169 | + */ |
|
170 | + public function dirname($path) |
|
171 | + { |
|
172 | + if (is_file($path)) { |
|
173 | + return dirname($path); |
|
174 | + } |
|
175 | + |
|
176 | + if (is_dir($path)) { |
|
177 | + return rtrim($path, '/'); |
|
178 | + } |
|
179 | + |
|
180 | + // no known file/dir, start making assumptions |
|
181 | + |
|
182 | + // ends in / = dir |
|
183 | + if (mb_substr($path, -1) === '/') { |
|
184 | + return rtrim($path, '/'); |
|
185 | + } |
|
186 | + |
|
187 | + // has a dot in the name, likely a file |
|
188 | + if (preg_match('/.*\..*$/', basename($path)) !== 0) { |
|
189 | + return dirname($path); |
|
190 | + } |
|
191 | + |
|
192 | + // you're on your own here! |
|
193 | + return $path; |
|
194 | + } |
|
195 | 195 | } |
@@ -39,8 +39,8 @@ discard block |
||
39 | 39 | // when both paths have nothing in common, one of them is probably |
40 | 40 | // absolute while the other is relative |
41 | 41 | $cwd = getcwd(); |
42 | - $from = strpos($from, $cwd) === 0 ? $from : $cwd.'/'.$from; |
|
43 | - $to = strpos($to, $cwd) === 0 ? $to : $cwd.'/'.$to; |
|
42 | + $from = strpos($from, $cwd) === 0 ? $from : $cwd . '/' . $from; |
|
43 | + $to = strpos($to, $cwd) === 0 ? $to : $cwd . '/' . $to; |
|
44 | 44 | |
45 | 45 | // or traveling the tree via `..` |
46 | 46 | // attempt to resolve path, or assume it's fine if it doesn't exist |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | } |
148 | 148 | |
149 | 149 | // normalize paths |
150 | - $path = $this->normalize($this->from.'/'.$path); |
|
150 | + $path = $this->normalize($this->from . '/' . $path); |
|
151 | 151 | |
152 | 152 | // strip shared ancestor paths |
153 | 153 | $shared = $this->shared($path, $this->to); |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | // add .. for every directory that needs to be traversed to new path |
158 | 158 | $to = str_repeat('../', mb_substr_count($to, '/')); |
159 | 159 | |
160 | - return $to.ltrim($path, '/'); |
|
160 | + return $to . ltrim($path, '/'); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | /** |