@@ -14,8 +14,9 @@ discard block |
||
14 | 14 | * @version 2.1 Beta 4 |
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, $topic, $scripturl, $sourcedir, $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 |
@@ -824,7 +824,7 @@ discard block |
||
824 | 824 | call_integration_hook('integrate_poll_buttons'); |
825 | 825 | } |
826 | 826 | |
827 | - if(!empty($_REQUEST['page_id'])) |
|
827 | + if (!empty($_REQUEST['page_id'])) |
|
828 | 828 | $start_char = substr($_REQUEST['page_id'], 0, 1); |
829 | 829 | else |
830 | 830 | $start_char = null; |
@@ -886,7 +886,7 @@ discard block |
||
886 | 886 | SELECT id_msg, id_member, approved |
887 | 887 | FROM {db_prefix}messages |
888 | 888 | WHERE id_topic = {int:current_topic} |
889 | - AND id_msg '. $page_operator . ' {int:page_id}'. (!$modSettings['postmod_active'] || $approve_posts ? '' : ' |
|
889 | + AND id_msg '. $page_operator . ' {int:page_id}' . (!$modSettings['postmod_active'] || $approve_posts ? '' : ' |
|
890 | 890 | AND (approved = {int:is_approved}' . ($user_info['is_guest'] ? '' : ' OR id_member = {int:current_member}') . ')') . ' |
891 | 891 | ORDER BY id_msg ' . ($ascending ? '' : 'DESC') . ($context['messages_per_page'] == -1 ? '' : ' |
892 | 892 | LIMIT {int:limit}'), |
@@ -14,8 +14,9 @@ discard block |
||
14 | 14 | * @version 2.1 Beta 4 |
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 $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 allowing for the .START method... |
445 | 457 | $context['start'] = $_REQUEST['start']; |
@@ -475,14 +487,16 @@ discard block |
||
475 | 487 | if (!empty($board_info['moderators'])) |
476 | 488 | { |
477 | 489 | // Add a link for each moderator... |
478 | - foreach ($board_info['moderators'] as $mod) |
|
479 | - $context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>'; |
|
490 | + foreach ($board_info['moderators'] as $mod) { |
|
491 | + $context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>'; |
|
492 | + } |
|
480 | 493 | } |
481 | 494 | if (!empty($board_info['moderator_groups'])) |
482 | 495 | { |
483 | 496 | // Add a link for each moderator group as well... |
484 | - foreach ($board_info['moderator_groups'] as $mod_group) |
|
485 | - $context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=viewmemberes;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>'; |
|
497 | + foreach ($board_info['moderator_groups'] as $mod_group) { |
|
498 | + $context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=viewmemberes;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>'; |
|
499 | + } |
|
486 | 500 | } |
487 | 501 | |
488 | 502 | if (!empty($context['link_moderators'])) |
@@ -513,9 +527,9 @@ discard block |
||
513 | 527 | // For quick reply we need a response prefix in the default forum language. |
514 | 528 | if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix', 600))) |
515 | 529 | { |
516 | - if ($language === $user_info['language']) |
|
517 | - $context['response_prefix'] = $txt['response_prefix']; |
|
518 | - else |
|
530 | + if ($language === $user_info['language']) { |
|
531 | + $context['response_prefix'] = $txt['response_prefix']; |
|
532 | + } else |
|
519 | 533 | { |
520 | 534 | loadLanguage('index', $language, false); |
521 | 535 | $context['response_prefix'] = $txt['response_prefix']; |
@@ -547,8 +561,9 @@ discard block |
||
547 | 561 | list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row); |
548 | 562 | |
549 | 563 | // Sanity check |
550 | - if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) |
|
551 | - continue; |
|
564 | + if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) { |
|
565 | + continue; |
|
566 | + } |
|
552 | 567 | |
553 | 568 | $linked_calendar_event = array( |
554 | 569 | 'id' => $row['id_event'], |
@@ -597,8 +612,9 @@ discard block |
||
597 | 612 | } |
598 | 613 | $smcFunc['db_free_result']($request); |
599 | 614 | |
600 | - if (!empty($context['linked_calendar_events'])) |
|
601 | - $context['linked_calendar_events'][count($context['linked_calendar_events']) - 1]['is_last'] = true; |
|
615 | + if (!empty($context['linked_calendar_events'])) { |
|
616 | + $context['linked_calendar_events'][count($context['linked_calendar_events']) - 1]['is_last'] = true; |
|
617 | + } |
|
602 | 618 | } |
603 | 619 | |
604 | 620 | // Create the poll info if it exists. |
@@ -661,8 +677,9 @@ discard block |
||
661 | 677 | $smcFunc['db_free_result']($request); |
662 | 678 | |
663 | 679 | // Got we multi choice? |
664 | - if ($pollinfo['max_votes'] > 1) |
|
665 | - $realtotal = $pollinfo['total']; |
|
680 | + if ($pollinfo['max_votes'] > 1) { |
|
681 | + $realtotal = $pollinfo['total']; |
|
682 | + } |
|
666 | 683 | |
667 | 684 | // If this is a guest we need to do our best to work out if they have voted, and what they voted for. |
668 | 685 | if ($user_info['is_guest'] && $pollinfo['guest_vote'] && allowedTo('poll_vote')) |
@@ -675,20 +692,21 @@ discard block |
||
675 | 692 | foreach ($guestinfo as $i => $guestvoted) |
676 | 693 | { |
677 | 694 | $guestvoted = explode(',', $guestvoted); |
678 | - if ($guestvoted[0] == $context['topicinfo']['id_poll']) |
|
679 | - break; |
|
695 | + if ($guestvoted[0] == $context['topicinfo']['id_poll']) { |
|
696 | + break; |
|
697 | + } |
|
680 | 698 | } |
681 | 699 | // Has the poll been reset since guest voted? |
682 | 700 | if ($pollinfo['reset_poll'] > $guestvoted[1]) |
683 | 701 | { |
684 | 702 | // Remove the poll info from the cookie to allow guest to vote again |
685 | 703 | unset($guestinfo[$i]); |
686 | - if (!empty($guestinfo)) |
|
687 | - $_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo); |
|
688 | - else |
|
689 | - unset($_COOKIE['guest_poll_vote']); |
|
690 | - } |
|
691 | - else |
|
704 | + if (!empty($guestinfo)) { |
|
705 | + $_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo); |
|
706 | + } else { |
|
707 | + unset($_COOKIE['guest_poll_vote']); |
|
708 | + } |
|
709 | + } else |
|
692 | 710 | { |
693 | 711 | // What did they vote for? |
694 | 712 | unset($guestvoted[0], $guestvoted[1]); |
@@ -802,35 +820,43 @@ discard block |
||
802 | 820 | // Build the poll moderation button array. |
803 | 821 | $context['poll_buttons'] = array(); |
804 | 822 | |
805 | - if ($context['allow_return_vote']) |
|
806 | - $context['poll_buttons']['vote'] = array('text' => 'poll_return_vote', 'image' => 'poll_options.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start']); |
|
823 | + if ($context['allow_return_vote']) { |
|
824 | + $context['poll_buttons']['vote'] = array('text' => 'poll_return_vote', 'image' => 'poll_options.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start']); |
|
825 | + } |
|
807 | 826 | |
808 | - if ($context['show_view_results_button']) |
|
809 | - $context['poll_buttons']['results'] = array('text' => 'poll_results', 'image' => 'poll_results.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start'] . ';viewresults'); |
|
827 | + if ($context['show_view_results_button']) { |
|
828 | + $context['poll_buttons']['results'] = array('text' => 'poll_results', 'image' => 'poll_results.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start'] . ';viewresults'); |
|
829 | + } |
|
810 | 830 | |
811 | - if ($context['allow_change_vote']) |
|
812 | - $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']); |
|
831 | + if ($context['allow_change_vote']) { |
|
832 | + $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']); |
|
833 | + } |
|
813 | 834 | |
814 | - if ($context['allow_lock_poll']) |
|
815 | - $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']); |
|
835 | + if ($context['allow_lock_poll']) { |
|
836 | + $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']); |
|
837 | + } |
|
816 | 838 | |
817 | - if ($context['allow_edit_poll']) |
|
818 | - $context['poll_buttons']['edit'] = array('text' => 'poll_edit', 'image' => 'poll_edit.png', 'url' => $scripturl . '?action=editpoll;topic=' . $context['current_topic'] . '.' . $context['start']); |
|
839 | + if ($context['allow_edit_poll']) { |
|
840 | + $context['poll_buttons']['edit'] = array('text' => 'poll_edit', 'image' => 'poll_edit.png', 'url' => $scripturl . '?action=editpoll;topic=' . $context['current_topic'] . '.' . $context['start']); |
|
841 | + } |
|
819 | 842 | |
820 | - if ($context['can_remove_poll']) |
|
821 | - $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']); |
|
843 | + if ($context['can_remove_poll']) { |
|
844 | + $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']); |
|
845 | + } |
|
822 | 846 | |
823 | 847 | // Allow mods to add additional buttons here |
824 | 848 | call_integration_hook('integrate_poll_buttons'); |
825 | 849 | } |
826 | 850 | |
827 | - if(!empty($_REQUEST['page_id'])) |
|
828 | - $start_char = substr($_REQUEST['page_id'], 0, 1); |
|
829 | - else |
|
830 | - $start_char = null; |
|
851 | + if(!empty($_REQUEST['page_id'])) { |
|
852 | + $start_char = substr($_REQUEST['page_id'], 0, 1); |
|
853 | + } else { |
|
854 | + $start_char = null; |
|
855 | + } |
|
831 | 856 | |
832 | - if ($start_char === 'M' || $start_char === 'L') |
|
833 | - $page_id = substr($_REQUEST['page_id'], 1); |
|
857 | + if ($start_char === 'M' || $start_char === 'L') { |
|
858 | + $page_id = substr($_REQUEST['page_id'], 1); |
|
859 | + } |
|
834 | 860 | |
835 | 861 | $limit = $context['messages_per_page']; |
836 | 862 | |
@@ -866,8 +892,7 @@ discard block |
||
866 | 892 | 'max' => $limit, |
867 | 893 | ) |
868 | 894 | ); |
869 | - } |
|
870 | - else //next or before page |
|
895 | + } else //next or before page |
|
871 | 896 | { |
872 | 897 | $firstIndex = 0; |
873 | 898 | |
@@ -875,8 +900,7 @@ discard block |
||
875 | 900 | { |
876 | 901 | $ascending = true; |
877 | 902 | $page_operator = '>'; |
878 | - } |
|
879 | - else |
|
903 | + } else |
|
880 | 904 | { |
881 | 905 | $ascending = false; |
882 | 906 | $page_operator = '<'; |
@@ -906,14 +930,16 @@ discard block |
||
906 | 930 | $all_posters = array(); |
907 | 931 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
908 | 932 | { |
909 | - if (!empty($row['id_member'])) |
|
910 | - $all_posters[$row['id_msg']] = $row['id_member']; |
|
933 | + if (!empty($row['id_member'])) { |
|
934 | + $all_posters[$row['id_msg']] = $row['id_member']; |
|
935 | + } |
|
911 | 936 | $messages[] = $row['id_msg']; |
912 | 937 | } |
913 | 938 | |
914 | 939 | // Before Page bring in the right order |
915 | - if (!empty($start_char) && $start_char === 'L') |
|
916 | - krsort($messages); |
|
940 | + if (!empty($start_char) && $start_char === 'L') { |
|
941 | + krsort($messages); |
|
942 | + } |
|
917 | 943 | |
918 | 944 | // Construct the page index, allowing for the .START method... |
919 | 945 | $page_options = array( |
@@ -935,8 +961,9 @@ discard block |
||
935 | 961 | $_REQUEST['start'] = 0; |
936 | 962 | } |
937 | 963 | // They aren't using it, but the *option* is there, at least. |
938 | - else |
|
939 | - $context['page_index'] .= ' <a href="' . $scripturl . '?topic=' . $topic . '.0;all">' . $txt['all'] . '</a> '; |
|
964 | + else { |
|
965 | + $context['page_index'] .= ' <a href="' . $scripturl . '?topic=' . $topic . '.0;all">' . $txt['all'] . '</a> '; |
|
966 | + } |
|
940 | 967 | } |
941 | 968 | |
942 | 969 | $smcFunc['db_free_result']($request); |
@@ -948,8 +975,9 @@ discard block |
||
948 | 975 | if (!$user_info['is_guest'] && !empty($messages)) |
949 | 976 | { |
950 | 977 | $mark_at_msg = max($messages); |
951 | - if ($mark_at_msg >= $context['topicinfo']['id_last_msg']) |
|
952 | - $mark_at_msg = $modSettings['maxMsgID']; |
|
978 | + if ($mark_at_msg >= $context['topicinfo']['id_last_msg']) { |
|
979 | + $mark_at_msg = $modSettings['maxMsgID']; |
|
980 | + } |
|
953 | 981 | if ($mark_at_msg >= $context['topicinfo']['new_from']) |
954 | 982 | { |
955 | 983 | $smcFunc['db_insert']($context['topicinfo']['new_from'] == 0 ? 'ignore' : 'replace', |
@@ -981,8 +1009,9 @@ discard block |
||
981 | 1009 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
982 | 1010 | { |
983 | 1011 | // Find if this topic is marked for notification... |
984 | - if (!empty($row['id_topic'])) |
|
985 | - $context['is_marked_notify'] = true; |
|
1012 | + if (!empty($row['id_topic'])) { |
|
1013 | + $context['is_marked_notify'] = true; |
|
1014 | + } |
|
986 | 1015 | |
987 | 1016 | // Only do this once, but mark the notifications as "not sent yet" for next time. |
988 | 1017 | if (!empty($row['sent']) && $do_once) |
@@ -1004,8 +1033,9 @@ discard block |
||
1004 | 1033 | } |
1005 | 1034 | |
1006 | 1035 | // Have we recently cached the number of new topics in this board, and it's still a lot? |
1007 | - if (isset($_REQUEST['topicseen']) && isset($_SESSION['topicseen_cache'][$board]) && $_SESSION['topicseen_cache'][$board] > 5) |
|
1008 | - $_SESSION['topicseen_cache'][$board]--; |
|
1036 | + if (isset($_REQUEST['topicseen']) && isset($_SESSION['topicseen_cache'][$board]) && $_SESSION['topicseen_cache'][$board] > 5) { |
|
1037 | + $_SESSION['topicseen_cache'][$board]--; |
|
1038 | + } |
|
1009 | 1039 | // Mark board as seen if this is the only new topic. |
1010 | 1040 | elseif (isset($_REQUEST['topicseen'])) |
1011 | 1041 | { |
@@ -1029,14 +1059,16 @@ discard block |
||
1029 | 1059 | $smcFunc['db_free_result']($request); |
1030 | 1060 | |
1031 | 1061 | // If there're no real new topics in this board, mark the board as seen. |
1032 | - if (empty($numNewTopics)) |
|
1033 | - $_REQUEST['boardseen'] = true; |
|
1034 | - else |
|
1035 | - $_SESSION['topicseen_cache'][$board] = $numNewTopics; |
|
1062 | + if (empty($numNewTopics)) { |
|
1063 | + $_REQUEST['boardseen'] = true; |
|
1064 | + } else { |
|
1065 | + $_SESSION['topicseen_cache'][$board] = $numNewTopics; |
|
1066 | + } |
|
1036 | 1067 | } |
1037 | 1068 | // Probably one less topic - maybe not, but even if we decrease this too fast it will only make us look more often. |
1038 | - elseif (isset($_SESSION['topicseen_cache'][$board])) |
|
1039 | - $_SESSION['topicseen_cache'][$board]--; |
|
1069 | + elseif (isset($_SESSION['topicseen_cache'][$board])) { |
|
1070 | + $_SESSION['topicseen_cache'][$board]--; |
|
1071 | + } |
|
1040 | 1072 | |
1041 | 1073 | // Mark board as seen if we came using last post link from BoardIndex. (or other places...) |
1042 | 1074 | if (isset($_REQUEST['boardseen'])) |
@@ -1093,23 +1125,26 @@ discard block |
||
1093 | 1125 | $temp = array(); |
1094 | 1126 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1095 | 1127 | { |
1096 | - if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) |
|
1097 | - continue; |
|
1128 | + if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) { |
|
1129 | + continue; |
|
1130 | + } |
|
1098 | 1131 | |
1099 | 1132 | $temp[$row['id_attach']] = $row; |
1100 | 1133 | $temp[$row['id_attach']]['topic'] = $topic; |
1101 | 1134 | $temp[$row['id_attach']]['board'] = $board; |
1102 | 1135 | |
1103 | - if (!isset($context['loaded_attachments'][$row['id_msg']])) |
|
1104 | - $context['loaded_attachments'][$row['id_msg']] = array(); |
|
1136 | + if (!isset($context['loaded_attachments'][$row['id_msg']])) { |
|
1137 | + $context['loaded_attachments'][$row['id_msg']] = array(); |
|
1138 | + } |
|
1105 | 1139 | } |
1106 | 1140 | $smcFunc['db_free_result']($request); |
1107 | 1141 | |
1108 | 1142 | // This is better than sorting it with the query... |
1109 | 1143 | ksort($temp); |
1110 | 1144 | |
1111 | - foreach ($temp as $row) |
|
1112 | - $context['loaded_attachments'][$row['id_msg']][] = $row; |
|
1145 | + foreach ($temp as $row) { |
|
1146 | + $context['loaded_attachments'][$row['id_msg']][] = $row; |
|
1147 | + } |
|
1113 | 1148 | } |
1114 | 1149 | |
1115 | 1150 | $msg_parameters = array( |
@@ -1136,21 +1171,23 @@ discard block |
||
1136 | 1171 | ); |
1137 | 1172 | |
1138 | 1173 | // And the likes |
1139 | - if (!empty($modSettings['enable_likes'])) |
|
1140 | - $context['my_likes'] = $context['user']['is_guest'] ? array() : prepareLikesContext($topic); |
|
1174 | + if (!empty($modSettings['enable_likes'])) { |
|
1175 | + $context['my_likes'] = $context['user']['is_guest'] ? array() : prepareLikesContext($topic); |
|
1176 | + } |
|
1141 | 1177 | |
1142 | 1178 | // Go to the last message if the given time is beyond the time of the last message. |
1143 | - if (isset($context['start_from']) && $context['start_from'] >= $context['topicinfo']['num_replies']) |
|
1144 | - $context['start_from'] = $context['topicinfo']['num_replies']; |
|
1179 | + if (isset($context['start_from']) && $context['start_from'] >= $context['topicinfo']['num_replies']) { |
|
1180 | + $context['start_from'] = $context['topicinfo']['num_replies']; |
|
1181 | + } |
|
1145 | 1182 | |
1146 | 1183 | // Since the anchor information is needed on the top of the page we load these variables beforehand. |
1147 | 1184 | $context['first_message'] = isset($messages[$firstIndex]) ? $messages[$firstIndex] : $messages[0]; |
1148 | - if (empty($options['view_newest_first'])) |
|
1149 | - $context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['start_from']; |
|
1150 | - else |
|
1151 | - $context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['topicinfo']['num_replies'] - $context['start_from']; |
|
1152 | - } |
|
1153 | - else |
|
1185 | + if (empty($options['view_newest_first'])) { |
|
1186 | + $context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['start_from']; |
|
1187 | + } else { |
|
1188 | + $context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['topicinfo']['num_replies'] - $context['start_from']; |
|
1189 | + } |
|
1190 | + } else |
|
1154 | 1191 | { |
1155 | 1192 | $messages_request = false; |
1156 | 1193 | $context['first_message'] = 0; |
@@ -1186,8 +1223,9 @@ discard block |
||
1186 | 1223 | 'can_see_likes' => 'likes_view', |
1187 | 1224 | 'can_like' => 'likes_like', |
1188 | 1225 | ); |
1189 | - foreach ($common_permissions as $contextual => $perm) |
|
1190 | - $context[$contextual] = allowedTo($perm); |
|
1226 | + foreach ($common_permissions as $contextual => $perm) { |
|
1227 | + $context[$contextual] = allowedTo($perm); |
|
1228 | + } |
|
1191 | 1229 | |
1192 | 1230 | // Permissions with _any/_own versions. $context[YYY] => ZZZ_any/_own. |
1193 | 1231 | $anyown_permissions = array( |
@@ -1200,8 +1238,9 @@ discard block |
||
1200 | 1238 | 'can_reply_unapproved' => 'post_unapproved_replies', |
1201 | 1239 | 'can_view_warning' => 'profile_warning', |
1202 | 1240 | ); |
1203 | - foreach ($anyown_permissions as $contextual => $perm) |
|
1204 | - $context[$contextual] = allowedTo($perm . '_any') || ($context['user']['started'] && allowedTo($perm . '_own')); |
|
1241 | + foreach ($anyown_permissions as $contextual => $perm) { |
|
1242 | + $context[$contextual] = allowedTo($perm . '_any') || ($context['user']['started'] && allowedTo($perm . '_own')); |
|
1243 | + } |
|
1205 | 1244 | |
1206 | 1245 | if (!$user_info['is_admin'] && !$modSettings['topic_move_any']) |
1207 | 1246 | { |
@@ -1247,8 +1286,9 @@ discard block |
||
1247 | 1286 | // Check if the draft functions are enabled and that they have permission to use them (for quick reply.) |
1248 | 1287 | $context['drafts_save'] = !empty($modSettings['drafts_post_enabled']) && allowedTo('post_draft') && $context['can_reply']; |
1249 | 1288 | $context['drafts_autosave'] = !empty($context['drafts_save']) && !empty($modSettings['drafts_autosave_enabled']); |
1250 | - if (!empty($context['drafts_save'])) |
|
1251 | - loadLanguage('Drafts'); |
|
1289 | + if (!empty($context['drafts_save'])) { |
|
1290 | + loadLanguage('Drafts'); |
|
1291 | + } |
|
1252 | 1292 | |
1253 | 1293 | // When was the last time this topic was replied to? Should we warn them about it? |
1254 | 1294 | if (!empty($modSettings['oldTopicDays']) && ($context['can_reply'] || $context['can_reply_unapproved']) && empty($context['topicinfo']['is_sticky'])) |
@@ -1309,26 +1349,31 @@ discard block |
||
1309 | 1349 | // Message icons - customized icons are off? |
1310 | 1350 | $context['icons'] = getMessageIcons($board); |
1311 | 1351 | |
1312 | - if (!empty($context['icons'])) |
|
1313 | - $context['icons'][count($context['icons']) - 1]['is_last'] = true; |
|
1352 | + if (!empty($context['icons'])) { |
|
1353 | + $context['icons'][count($context['icons']) - 1]['is_last'] = true; |
|
1354 | + } |
|
1314 | 1355 | |
1315 | 1356 | // Build the normal button array. |
1316 | 1357 | $context['normal_buttons'] = array(); |
1317 | 1358 | |
1318 | - if ($context['can_reply']) |
|
1319 | - $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); |
|
1359 | + if ($context['can_reply']) { |
|
1360 | + $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); |
|
1361 | + } |
|
1320 | 1362 | |
1321 | - if ($context['can_add_poll']) |
|
1322 | - $context['normal_buttons']['add_poll'] = array('text' => 'add_poll', 'image' => 'add_poll.png', 'url' => $scripturl . '?action=editpoll;add;topic=' . $context['current_topic'] . '.' . $context['start']); |
|
1363 | + if ($context['can_add_poll']) { |
|
1364 | + $context['normal_buttons']['add_poll'] = array('text' => 'add_poll', 'image' => 'add_poll.png', 'url' => $scripturl . '?action=editpoll;add;topic=' . $context['current_topic'] . '.' . $context['start']); |
|
1365 | + } |
|
1323 | 1366 | |
1324 | - if ($context['can_mark_unread']) |
|
1325 | - $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']); |
|
1367 | + if ($context['can_mark_unread']) { |
|
1368 | + $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']); |
|
1369 | + } |
|
1326 | 1370 | |
1327 | - if ($context['can_print']) |
|
1328 | - $context['normal_buttons']['print'] = array('text' => 'print', 'image' => 'print.png', 'custom' => 'rel="nofollow"', 'url' => $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0'); |
|
1371 | + if ($context['can_print']) { |
|
1372 | + $context['normal_buttons']['print'] = array('text' => 'print', 'image' => 'print.png', 'custom' => 'rel="nofollow"', 'url' => $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0'); |
|
1373 | + } |
|
1329 | 1374 | |
1330 | - if ($context['can_set_notify']) |
|
1331 | - $context['normal_buttons']['notify'] = array( |
|
1375 | + if ($context['can_set_notify']) { |
|
1376 | + $context['normal_buttons']['notify'] = array( |
|
1332 | 1377 | 'text' => 'notify_topic_' . $context['topic_notification_mode'], |
1333 | 1378 | 'sub_buttons' => array( |
1334 | 1379 | array( |
@@ -1350,38 +1395,47 @@ discard block |
||
1350 | 1395 | ), |
1351 | 1396 | ), |
1352 | 1397 | ); |
1398 | + } |
|
1353 | 1399 | |
1354 | 1400 | // Build the mod button array |
1355 | 1401 | $context['mod_buttons'] = array(); |
1356 | 1402 | |
1357 | - if ($context['can_move']) |
|
1358 | - $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'); |
|
1403 | + if ($context['can_move']) { |
|
1404 | + $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'); |
|
1405 | + } |
|
1359 | 1406 | |
1360 | - if ($context['can_delete']) |
|
1361 | - $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']); |
|
1407 | + if ($context['can_delete']) { |
|
1408 | + $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']); |
|
1409 | + } |
|
1362 | 1410 | |
1363 | - if ($context['can_lock']) |
|
1364 | - $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']); |
|
1411 | + if ($context['can_lock']) { |
|
1412 | + $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']); |
|
1413 | + } |
|
1365 | 1414 | |
1366 | - if ($context['can_sticky']) |
|
1367 | - $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']); |
|
1415 | + if ($context['can_sticky']) { |
|
1416 | + $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']); |
|
1417 | + } |
|
1368 | 1418 | |
1369 | - if ($context['can_merge']) |
|
1370 | - $context['mod_buttons']['merge'] = array('text' => 'merge', 'image' => 'merge.png', 'url' => $scripturl . '?action=mergetopics;board=' . $context['current_board'] . '.0;from=' . $context['current_topic']); |
|
1419 | + if ($context['can_merge']) { |
|
1420 | + $context['mod_buttons']['merge'] = array('text' => 'merge', 'image' => 'merge.png', 'url' => $scripturl . '?action=mergetopics;board=' . $context['current_board'] . '.0;from=' . $context['current_topic']); |
|
1421 | + } |
|
1371 | 1422 | |
1372 | - if ($context['calendar_post']) |
|
1373 | - $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'); |
|
1423 | + if ($context['calendar_post']) { |
|
1424 | + $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'); |
|
1425 | + } |
|
1374 | 1426 | |
1375 | 1427 | // Restore topic. eh? No monkey business. |
1376 | - if ($context['can_restore_topic']) |
|
1377 | - $context['mod_buttons']['restore_topic'] = array('text' => 'restore_topic', 'image' => '', 'url' => $scripturl . '?action=restoretopic;topics=' . $context['current_topic'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
1428 | + if ($context['can_restore_topic']) { |
|
1429 | + $context['mod_buttons']['restore_topic'] = array('text' => 'restore_topic', 'image' => '', 'url' => $scripturl . '?action=restoretopic;topics=' . $context['current_topic'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
1430 | + } |
|
1378 | 1431 | |
1379 | 1432 | // Show a message in case a recently posted message became unapproved. |
1380 | 1433 | $context['becomesUnapproved'] = !empty($_SESSION['becomesUnapproved']) ? true : false; |
1381 | 1434 | |
1382 | 1435 | // Don't want to show this forever... |
1383 | - if ($context['becomesUnapproved']) |
|
1384 | - unset($_SESSION['becomesUnapproved']); |
|
1436 | + if ($context['becomesUnapproved']) { |
|
1437 | + unset($_SESSION['becomesUnapproved']); |
|
1438 | + } |
|
1385 | 1439 | |
1386 | 1440 | // Allow adding new mod buttons easily. |
1387 | 1441 | // Note: $context['normal_buttons'] and $context['mod_buttons'] are added for backward compatibility with 2.0, but are deprecated and should not be used |
@@ -1390,12 +1444,14 @@ discard block |
||
1390 | 1444 | call_integration_hook('integrate_mod_buttons', array(&$context['mod_buttons'])); |
1391 | 1445 | |
1392 | 1446 | // Load the drafts js file |
1393 | - if ($context['drafts_autosave']) |
|
1394 | - loadJavaScriptFile('drafts.js', array('defer' => false), 'smf_drafts'); |
|
1447 | + if ($context['drafts_autosave']) { |
|
1448 | + loadJavaScriptFile('drafts.js', array('defer' => false), 'smf_drafts'); |
|
1449 | + } |
|
1395 | 1450 | |
1396 | 1451 | // Spellcheck |
1397 | - if ($context['show_spellchecking']) |
|
1398 | - loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck'); |
|
1452 | + if ($context['show_spellchecking']) { |
|
1453 | + loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck'); |
|
1454 | + } |
|
1399 | 1455 | |
1400 | 1456 | // topic.js |
1401 | 1457 | loadJavaScriptFile('topic.js', array('defer' => false), 'smf_topic'); |
@@ -1429,16 +1485,19 @@ discard block |
||
1429 | 1485 | static $counter = null; |
1430 | 1486 | |
1431 | 1487 | // If the query returned false, bail. |
1432 | - if ($messages_request == false) |
|
1433 | - return false; |
|
1488 | + if ($messages_request == false) { |
|
1489 | + return false; |
|
1490 | + } |
|
1434 | 1491 | |
1435 | 1492 | // Remember which message this is. (ie. reply #83) |
1436 | - if ($counter === null || $reset) |
|
1437 | - $counter = empty($options['view_newest_first']) ? $context['start'] : $context['total_visible_posts'] - $context['start']; |
|
1493 | + if ($counter === null || $reset) { |
|
1494 | + $counter = empty($options['view_newest_first']) ? $context['start'] : $context['total_visible_posts'] - $context['start']; |
|
1495 | + } |
|
1438 | 1496 | |
1439 | 1497 | // Start from the beginning... |
1440 | - if ($reset) |
|
1441 | - return @$smcFunc['db_data_seek']($messages_request, 0); |
|
1498 | + if ($reset) { |
|
1499 | + return @$smcFunc['db_data_seek']($messages_request, 0); |
|
1500 | + } |
|
1442 | 1501 | |
1443 | 1502 | // Attempt to get the next message. |
1444 | 1503 | $message = $smcFunc['db_fetch_assoc']($messages_request); |
@@ -1452,19 +1511,21 @@ discard block |
||
1452 | 1511 | if (empty($context['icon_sources'])) |
1453 | 1512 | { |
1454 | 1513 | $context['icon_sources'] = array(); |
1455 | - foreach ($context['stable_icons'] as $icon) |
|
1456 | - $context['icon_sources'][$icon] = 'images_url'; |
|
1514 | + foreach ($context['stable_icons'] as $icon) { |
|
1515 | + $context['icon_sources'][$icon] = 'images_url'; |
|
1516 | + } |
|
1457 | 1517 | } |
1458 | 1518 | |
1459 | 1519 | // Message Icon Management... check the images exist. |
1460 | 1520 | if (empty($modSettings['messageIconChecks_disable'])) |
1461 | 1521 | { |
1462 | 1522 | // If the current icon isn't known, then we need to do something... |
1463 | - if (!isset($context['icon_sources'][$message['icon']])) |
|
1464 | - $context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
1523 | + if (!isset($context['icon_sources'][$message['icon']])) { |
|
1524 | + $context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
1525 | + } |
|
1526 | + } elseif (!isset($context['icon_sources'][$message['icon']])) { |
|
1527 | + $context['icon_sources'][$message['icon']] = 'images_url'; |
|
1465 | 1528 | } |
1466 | - elseif (!isset($context['icon_sources'][$message['icon']])) |
|
1467 | - $context['icon_sources'][$message['icon']] = 'images_url'; |
|
1468 | 1529 | |
1469 | 1530 | // If you're a lazy bum, you probably didn't give a subject... |
1470 | 1531 | $message['subject'] = $message['subject'] != '' ? $message['subject'] : $txt['no_subject']; |
@@ -1489,8 +1550,7 @@ discard block |
||
1489 | 1550 | $memberContext[$message['id_member']]['email'] = $message['poster_email']; |
1490 | 1551 | $memberContext[$message['id_member']]['show_email'] = allowedTo('moderate_forum'); |
1491 | 1552 | $memberContext[$message['id_member']]['is_guest'] = true; |
1492 | - } |
|
1493 | - else |
|
1553 | + } else |
|
1494 | 1554 | { |
1495 | 1555 | // Define this here to make things a bit more readable |
1496 | 1556 | $can_view_warning = $context['user']['can_mod'] || allowedTo('view_warning_any') || ($message['id_member'] == $user_info['id'] && allowedTo('view_warning_own')); |
@@ -1513,8 +1573,9 @@ discard block |
||
1513 | 1573 | $message['body'] = parse_bbc($message['body'], $message['smileys_enabled'], $message['id_msg']); |
1514 | 1574 | |
1515 | 1575 | // If it's in the recycle bin we need to override whatever icon we did have. |
1516 | - if (!empty($board_info['recycle'])) |
|
1517 | - $message['icon'] = 'recycled'; |
|
1576 | + if (!empty($board_info['recycle'])) { |
|
1577 | + $message['icon'] = 'recycled'; |
|
1578 | + } |
|
1518 | 1579 | |
1519 | 1580 | require_once($sourcedir . '/Subs-Attachments.php'); |
1520 | 1581 | |
@@ -1558,32 +1619,36 @@ discard block |
||
1558 | 1619 | } |
1559 | 1620 | |
1560 | 1621 | // Are likes enable? |
1561 | - if (!empty($modSettings['enable_likes'])) |
|
1562 | - $output['likes'] = array( |
|
1622 | + if (!empty($modSettings['enable_likes'])) { |
|
1623 | + $output['likes'] = array( |
|
1563 | 1624 | 'count' => $message['likes'], |
1564 | 1625 | 'you' => in_array($message['id_msg'], $context['my_likes']), |
1565 | 1626 | 'can_like' => !$context['user']['is_guest'] && $message['id_member'] != $context['user']['id'] && !empty($context['can_like']), |
1566 | 1627 | ); |
1628 | + } |
|
1567 | 1629 | |
1568 | 1630 | // Is this user the message author? |
1569 | 1631 | $output['is_message_author'] = $message['id_member'] == $user_info['id']; |
1570 | - if (!empty($output['modified']['name'])) |
|
1571 | - $output['modified']['last_edit_text'] = sprintf($txt['last_edit_by'], $output['modified']['time'], $output['modified']['name']); |
|
1632 | + if (!empty($output['modified']['name'])) { |
|
1633 | + $output['modified']['last_edit_text'] = sprintf($txt['last_edit_by'], $output['modified']['time'], $output['modified']['name']); |
|
1634 | + } |
|
1572 | 1635 | |
1573 | 1636 | // Did they give a reason for editing? |
1574 | - if (!empty($output['modified']['name']) && !empty($output['modified']['reason'])) |
|
1575 | - $output['modified']['last_edit_text'] .= ' ' . sprintf($txt['last_edit_reason'], $output['modified']['reason']); |
|
1637 | + if (!empty($output['modified']['name']) && !empty($output['modified']['reason'])) { |
|
1638 | + $output['modified']['last_edit_text'] .= ' ' . sprintf($txt['last_edit_reason'], $output['modified']['reason']); |
|
1639 | + } |
|
1576 | 1640 | |
1577 | 1641 | // Any custom profile fields? |
1578 | - if (!empty($memberContext[$message['id_member']]['custom_fields'])) |
|
1579 | - foreach ($memberContext[$message['id_member']]['custom_fields'] as $custom) |
|
1642 | + if (!empty($memberContext[$message['id_member']]['custom_fields'])) { |
|
1643 | + foreach ($memberContext[$message['id_member']]['custom_fields'] as $custom) |
|
1580 | 1644 | $output['custom_fields'][$context['cust_profile_fields_placement'][$custom['placement']]][] = $custom; |
1645 | + } |
|
1581 | 1646 | |
1582 | - if (empty($options['view_newest_first'])) |
|
1583 | - $counter++; |
|
1584 | - |
|
1585 | - else |
|
1586 | - $counter--; |
|
1647 | + if (empty($options['view_newest_first'])) { |
|
1648 | + $counter++; |
|
1649 | + } else { |
|
1650 | + $counter--; |
|
1651 | + } |
|
1587 | 1652 | |
1588 | 1653 | call_integration_hook('integrate_prepare_display_context', array(&$output, &$message, $counter)); |
1589 | 1654 | |
@@ -1609,21 +1674,23 @@ discard block |
||
1609 | 1674 | $context['no_last_modified'] = true; |
1610 | 1675 | |
1611 | 1676 | // Prevent a preview image from being displayed twice. |
1612 | - if (isset($_GET['action']) && $_GET['action'] == 'dlattach' && isset($_GET['type']) && ($_GET['type'] == 'avatar' || $_GET['type'] == 'preview')) |
|
1613 | - return; |
|
1677 | + if (isset($_GET['action']) && $_GET['action'] == 'dlattach' && isset($_GET['type']) && ($_GET['type'] == 'avatar' || $_GET['type'] == 'preview')) { |
|
1678 | + return; |
|
1679 | + } |
|
1614 | 1680 | |
1615 | 1681 | // Make sure some attachment was requested! |
1616 | - if (!isset($_REQUEST['attach']) && !isset($_REQUEST['id'])) |
|
1617 | - fatal_lang_error('no_access', false); |
|
1682 | + if (!isset($_REQUEST['attach']) && !isset($_REQUEST['id'])) { |
|
1683 | + fatal_lang_error('no_access', false); |
|
1684 | + } |
|
1618 | 1685 | |
1619 | 1686 | $_REQUEST['attach'] = isset($_REQUEST['attach']) ? (int) $_REQUEST['attach'] : (int) $_REQUEST['id']; |
1620 | 1687 | |
1621 | 1688 | // Do we have a hook wanting to use our attachment system? We use $attachRequest to prevent accidental usage of $request. |
1622 | 1689 | $attachRequest = null; |
1623 | 1690 | call_integration_hook('integrate_download_request', array(&$attachRequest)); |
1624 | - if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest)) |
|
1625 | - $request = $attachRequest; |
|
1626 | - else |
|
1691 | + if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest)) { |
|
1692 | + $request = $attachRequest; |
|
1693 | + } else |
|
1627 | 1694 | { |
1628 | 1695 | // This checks only the current board for $board/$topic's permissions. |
1629 | 1696 | isAllowedTo('view_attachments'); |
@@ -1644,19 +1711,21 @@ discard block |
||
1644 | 1711 | ); |
1645 | 1712 | } |
1646 | 1713 | |
1647 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
1648 | - fatal_lang_error('no_access', false); |
|
1714 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
1715 | + fatal_lang_error('no_access', false); |
|
1716 | + } |
|
1649 | 1717 | |
1650 | 1718 | list ($id_folder, $real_filename, $file_hash, $file_ext, $id_attach, $attachment_type, $mime_type, $is_approved, $id_member) = $smcFunc['db_fetch_row']($request); |
1651 | 1719 | $smcFunc['db_free_result']($request); |
1652 | 1720 | |
1653 | 1721 | // If it isn't yet approved, do they have permission to view it? |
1654 | - if (!$is_approved && ($id_member == 0 || $user_info['id'] != $id_member) && ($attachment_type == 0 || $attachment_type == 3)) |
|
1655 | - isAllowedTo('approve_posts'); |
|
1722 | + if (!$is_approved && ($id_member == 0 || $user_info['id'] != $id_member) && ($attachment_type == 0 || $attachment_type == 3)) { |
|
1723 | + isAllowedTo('approve_posts'); |
|
1724 | + } |
|
1656 | 1725 | |
1657 | 1726 | // Update the download counter (unless it's a thumbnail). |
1658 | - if ($attachment_type != 3) |
|
1659 | - $smcFunc['db_query']('attach_download_increase', ' |
|
1727 | + if ($attachment_type != 3) { |
|
1728 | + $smcFunc['db_query']('attach_download_increase', ' |
|
1660 | 1729 | UPDATE LOW_PRIORITY {db_prefix}attachments |
1661 | 1730 | SET downloads = downloads + 1 |
1662 | 1731 | WHERE id_attach = {int:id_attach}', |
@@ -1664,15 +1733,15 @@ discard block |
||
1664 | 1733 | 'id_attach' => $id_attach, |
1665 | 1734 | ) |
1666 | 1735 | ); |
1736 | + } |
|
1667 | 1737 | |
1668 | 1738 | $filename = getAttachmentFilename($real_filename, $_REQUEST['attach'], $id_folder, false, $file_hash); |
1669 | 1739 | |
1670 | 1740 | // This is done to clear any output that was made before now. |
1671 | 1741 | ob_end_clean(); |
1672 | - 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'))) |
|
1673 | - @ob_start('ob_gzhandler'); |
|
1674 | - |
|
1675 | - else |
|
1742 | + 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'))) { |
|
1743 | + @ob_start('ob_gzhandler'); |
|
1744 | + } else |
|
1676 | 1745 | { |
1677 | 1746 | ob_start(); |
1678 | 1747 | header('Content-Encoding: none'); |
@@ -1715,8 +1784,9 @@ discard block |
||
1715 | 1784 | // Send the attachment headers. |
1716 | 1785 | header('Pragma: '); |
1717 | 1786 | |
1718 | - if (!isBrowser('gecko')) |
|
1719 | - header('Content-Transfer-Encoding: binary'); |
|
1787 | + if (!isBrowser('gecko')) { |
|
1788 | + header('Content-Transfer-Encoding: binary'); |
|
1789 | + } |
|
1720 | 1790 | |
1721 | 1791 | header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 525600 * 60) . ' GMT'); |
1722 | 1792 | header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($filename)) . ' GMT'); |
@@ -1725,18 +1795,19 @@ discard block |
||
1725 | 1795 | header('ETag: ' . $eTag); |
1726 | 1796 | |
1727 | 1797 | // Make sure the mime type warrants an inline display. |
1728 | - if (isset($_REQUEST['image']) && !empty($mime_type) && strpos($mime_type, 'image/') !== 0) |
|
1729 | - unset($_REQUEST['image']); |
|
1798 | + if (isset($_REQUEST['image']) && !empty($mime_type) && strpos($mime_type, 'image/') !== 0) { |
|
1799 | + unset($_REQUEST['image']); |
|
1800 | + } |
|
1730 | 1801 | |
1731 | 1802 | // Does this have a mime type? |
1732 | - elseif (!empty($mime_type) && (isset($_REQUEST['image']) || !in_array($file_ext, array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff')))) |
|
1733 | - header('Content-Type: ' . strtr($mime_type, array('image/bmp' => 'image/x-ms-bmp'))); |
|
1734 | - |
|
1735 | - else |
|
1803 | + elseif (!empty($mime_type) && (isset($_REQUEST['image']) || !in_array($file_ext, array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff')))) { |
|
1804 | + header('Content-Type: ' . strtr($mime_type, array('image/bmp' => 'image/x-ms-bmp'))); |
|
1805 | + } else |
|
1736 | 1806 | { |
1737 | 1807 | header('Content-Type: ' . (isBrowser('ie') || isBrowser('opera') ? 'application/octetstream' : 'application/octet-stream')); |
1738 | - if (isset($_REQUEST['image'])) |
|
1739 | - unset($_REQUEST['image']); |
|
1808 | + if (isset($_REQUEST['image'])) { |
|
1809 | + unset($_REQUEST['image']); |
|
1810 | + } |
|
1740 | 1811 | } |
1741 | 1812 | |
1742 | 1813 | // Convert the file to UTF-8, cuz most browsers dig that. |
@@ -1744,23 +1815,22 @@ discard block |
||
1744 | 1815 | $disposition = !isset($_REQUEST['image']) ? 'attachment' : 'inline'; |
1745 | 1816 | |
1746 | 1817 | // Different browsers like different standards... |
1747 | - if (isBrowser('firefox')) |
|
1748 | - header('Content-Disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name))); |
|
1749 | - |
|
1750 | - elseif (isBrowser('opera')) |
|
1751 | - header('Content-Disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"'); |
|
1752 | - |
|
1753 | - elseif (isBrowser('ie')) |
|
1754 | - header('Content-Disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"'); |
|
1755 | - |
|
1756 | - else |
|
1757 | - header('Content-Disposition: ' . $disposition . '; filename="' . $utf8name . '"'); |
|
1818 | + if (isBrowser('firefox')) { |
|
1819 | + header('Content-Disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name))); |
|
1820 | + } elseif (isBrowser('opera')) { |
|
1821 | + header('Content-Disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"'); |
|
1822 | + } elseif (isBrowser('ie')) { |
|
1823 | + header('Content-Disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"'); |
|
1824 | + } else { |
|
1825 | + header('Content-Disposition: ' . $disposition . '; filename="' . $utf8name . '"'); |
|
1826 | + } |
|
1758 | 1827 | |
1759 | 1828 | // If this has an "image extension" - but isn't actually an image - then ensure it isn't cached cause of silly IE. |
1760 | - if (!isset($_REQUEST['image']) && in_array($file_ext, array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff'))) |
|
1761 | - header('Cache-Control: no-cache'); |
|
1762 | - else |
|
1763 | - header('Cache-Control: max-age=' . (525600 * 60) . ', private'); |
|
1829 | + if (!isset($_REQUEST['image']) && in_array($file_ext, array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff'))) { |
|
1830 | + header('Cache-Control: no-cache'); |
|
1831 | + } else { |
|
1832 | + header('Cache-Control: max-age=' . (525600 * 60) . ', private'); |
|
1833 | + } |
|
1764 | 1834 | |
1765 | 1835 | header('Content-Length: ' . filesize($filename)); |
1766 | 1836 | |
@@ -1770,20 +1840,23 @@ discard block |
||
1770 | 1840 | // Recode line endings for text files, if enabled. |
1771 | 1841 | if (!empty($modSettings['attachmentRecodeLineEndings']) && !isset($_REQUEST['image']) && in_array($file_ext, array('txt', 'css', 'htm', 'html', 'php', 'xml'))) |
1772 | 1842 | { |
1773 | - if (strpos($_SERVER['HTTP_USER_AGENT'], 'Windows') !== false) |
|
1774 | - $callback = function($buffer) |
|
1843 | + if (strpos($_SERVER['HTTP_USER_AGENT'], 'Windows') !== false) { |
|
1844 | + $callback = function($buffer) |
|
1775 | 1845 | { |
1776 | 1846 | return preg_replace('~[\r]?\n~', "\r\n", $buffer); |
1847 | + } |
|
1777 | 1848 | }; |
1778 | - elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false) |
|
1779 | - $callback = function($buffer) |
|
1849 | + elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false) { |
|
1850 | + $callback = function($buffer) |
|
1780 | 1851 | { |
1781 | 1852 | return preg_replace('~[\r]?\n~', "\r", $buffer); |
1853 | + } |
|
1782 | 1854 | }; |
1783 | - else |
|
1784 | - $callback = function($buffer) |
|
1855 | + else { |
|
1856 | + $callback = function($buffer) |
|
1785 | 1857 | { |
1786 | 1858 | return preg_replace('~[\r]?\n~', "\n", $buffer); |
1859 | + } |
|
1787 | 1860 | }; |
1788 | 1861 | } |
1789 | 1862 | |
@@ -1791,23 +1864,26 @@ discard block |
||
1791 | 1864 | if (filesize($filename) > 4194304) |
1792 | 1865 | { |
1793 | 1866 | // Forcibly end any output buffering going on. |
1794 | - while (@ob_get_level() > 0) |
|
1795 | - @ob_end_clean(); |
|
1867 | + while (@ob_get_level() > 0) { |
|
1868 | + @ob_end_clean(); |
|
1869 | + } |
|
1796 | 1870 | |
1797 | 1871 | $fp = fopen($filename, 'rb'); |
1798 | 1872 | while (!feof($fp)) |
1799 | 1873 | { |
1800 | - if (isset($callback)) |
|
1801 | - echo $callback(fread($fp, 8192)); |
|
1802 | - else |
|
1803 | - echo fread($fp, 8192); |
|
1874 | + if (isset($callback)) { |
|
1875 | + echo $callback(fread($fp, 8192)); |
|
1876 | + } else { |
|
1877 | + echo fread($fp, 8192); |
|
1878 | + } |
|
1804 | 1879 | flush(); |
1805 | 1880 | } |
1806 | 1881 | fclose($fp); |
1807 | 1882 | } |
1808 | 1883 | // 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. |
1809 | - elseif (isset($callback) || @readfile($filename) === null) |
|
1810 | - echo isset($callback) ? $callback(file_get_contents($filename)) : file_get_contents($filename); |
|
1884 | + elseif (isset($callback) || @readfile($filename) === null) { |
|
1885 | + echo isset($callback) ? $callback(file_get_contents($filename)) : file_get_contents($filename); |
|
1886 | + } |
|
1811 | 1887 | |
1812 | 1888 | obExit(false); |
1813 | 1889 | } |
@@ -1820,8 +1896,9 @@ discard block |
||
1820 | 1896 | */ |
1821 | 1897 | function approved_attach_sort($a, $b) |
1822 | 1898 | { |
1823 | - if ($a['is_approved'] == $b['is_approved']) |
|
1824 | - return 0; |
|
1899 | + if ($a['is_approved'] == $b['is_approved']) { |
|
1900 | + return 0; |
|
1901 | + } |
|
1825 | 1902 | |
1826 | 1903 | return $a['is_approved'] > $b['is_approved'] ? -1 : 1; |
1827 | 1904 | } |
@@ -1838,16 +1915,19 @@ discard block |
||
1838 | 1915 | |
1839 | 1916 | require_once($sourcedir . '/RemoveTopic.php'); |
1840 | 1917 | |
1841 | - if (empty($_REQUEST['msgs'])) |
|
1842 | - redirectexit('topic=' . $topic . '.' . $_REQUEST['start']); |
|
1918 | + if (empty($_REQUEST['msgs'])) { |
|
1919 | + redirectexit('topic=' . $topic . '.' . $_REQUEST['start']); |
|
1920 | + } |
|
1843 | 1921 | |
1844 | 1922 | $messages = array(); |
1845 | - foreach ($_REQUEST['msgs'] as $dummy) |
|
1846 | - $messages[] = (int) $dummy; |
|
1923 | + foreach ($_REQUEST['msgs'] as $dummy) { |
|
1924 | + $messages[] = (int) $dummy; |
|
1925 | + } |
|
1847 | 1926 | |
1848 | 1927 | // We are restoring messages. We handle this in another place. |
1849 | - if (isset($_REQUEST['restore_selected'])) |
|
1850 | - redirectexit('action=restoretopic;msgs=' . implode(',', $messages) . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
1928 | + if (isset($_REQUEST['restore_selected'])) { |
|
1929 | + redirectexit('action=restoretopic;msgs=' . implode(',', $messages) . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
1930 | + } |
|
1851 | 1931 | if (isset($_REQUEST['split_selection'])) |
1852 | 1932 | { |
1853 | 1933 | $request = $smcFunc['db_query']('', ' |
@@ -1866,8 +1946,9 @@ discard block |
||
1866 | 1946 | } |
1867 | 1947 | |
1868 | 1948 | // Allowed to delete any message? |
1869 | - if (allowedTo('delete_any')) |
|
1870 | - $allowed_all = true; |
|
1949 | + if (allowedTo('delete_any')) { |
|
1950 | + $allowed_all = true; |
|
1951 | + } |
|
1871 | 1952 | // Allowed to delete replies to their messages? |
1872 | 1953 | elseif (allowedTo('delete_replies')) |
1873 | 1954 | { |
@@ -1884,13 +1965,14 @@ discard block |
||
1884 | 1965 | $smcFunc['db_free_result']($request); |
1885 | 1966 | |
1886 | 1967 | $allowed_all = $starter == $user_info['id']; |
1968 | + } else { |
|
1969 | + $allowed_all = false; |
|
1887 | 1970 | } |
1888 | - else |
|
1889 | - $allowed_all = false; |
|
1890 | 1971 | |
1891 | 1972 | // Make sure they're allowed to delete their own messages, if not any. |
1892 | - if (!$allowed_all) |
|
1893 | - isAllowedTo('delete_own'); |
|
1973 | + if (!$allowed_all) { |
|
1974 | + isAllowedTo('delete_own'); |
|
1975 | + } |
|
1894 | 1976 | |
1895 | 1977 | // Allowed to remove which messages? |
1896 | 1978 | $request = $smcFunc['db_query']('', ' |
@@ -1910,8 +1992,9 @@ discard block |
||
1910 | 1992 | $messages = array(); |
1911 | 1993 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1912 | 1994 | { |
1913 | - if (!$allowed_all && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) |
|
1914 | - continue; |
|
1995 | + if (!$allowed_all && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) { |
|
1996 | + continue; |
|
1997 | + } |
|
1915 | 1998 | |
1916 | 1999 | $messages[$row['id_msg']] = array($row['subject'], $row['id_member']); |
1917 | 2000 | } |
@@ -1934,17 +2017,20 @@ discard block |
||
1934 | 2017 | foreach ($messages as $message => $info) |
1935 | 2018 | { |
1936 | 2019 | // Just skip the first message - if it's not the last. |
1937 | - if ($message == $first_message && $message != $last_message) |
|
1938 | - continue; |
|
2020 | + if ($message == $first_message && $message != $last_message) { |
|
2021 | + continue; |
|
2022 | + } |
|
1939 | 2023 | // If the first message is going then don't bother going back to the topic as we're effectively deleting it. |
1940 | - elseif ($message == $first_message) |
|
1941 | - $topicGone = true; |
|
2024 | + elseif ($message == $first_message) { |
|
2025 | + $topicGone = true; |
|
2026 | + } |
|
1942 | 2027 | |
1943 | 2028 | removeMessage($message); |
1944 | 2029 | |
1945 | 2030 | // Log this moderation action ;). |
1946 | - if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id'])) |
|
1947 | - logAction('delete', array('topic' => $topic, 'subject' => $info[0], 'member' => $info[1], 'board' => $board)); |
|
2031 | + if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id'])) { |
|
2032 | + logAction('delete', array('topic' => $topic, 'subject' => $info[0], 'member' => $info[1], 'board' => $board)); |
|
2033 | + } |
|
1948 | 2034 | } |
1949 | 2035 | |
1950 | 2036 | redirectexit(!empty($topicGone) ? 'board=' . $board : 'topic=' . $topic . '.' . $_REQUEST['start']); |
@@ -14,8 +14,9 @@ discard block |
||
14 | 14 | * @version 2.1 Beta 4 |
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 | * Check if the user is who he/she says he is |
@@ -42,12 +43,14 @@ discard block |
||
42 | 43 | $refreshTime = isset($_GET['xml']) ? 4200 : 3600; |
43 | 44 | |
44 | 45 | // Is the security option off? |
45 | - if (!empty($modSettings['securityDisable' . ($type != 'admin' ? '_' . $type : '')])) |
|
46 | - return; |
|
46 | + if (!empty($modSettings['securityDisable' . ($type != 'admin' ? '_' . $type : '')])) { |
|
47 | + return; |
|
48 | + } |
|
47 | 49 | |
48 | 50 | // Or are they already logged in?, Moderator or admin session is need for this area |
49 | - if ((!empty($_SESSION[$type . '_time']) && $_SESSION[$type . '_time'] + $refreshTime >= time()) || (!empty($_SESSION['admin_time']) && $_SESSION['admin_time'] + $refreshTime >= time())) |
|
50 | - return; |
|
51 | + if ((!empty($_SESSION[$type . '_time']) && $_SESSION[$type . '_time'] + $refreshTime >= time()) || (!empty($_SESSION['admin_time']) && $_SESSION['admin_time'] + $refreshTime >= time())) { |
|
52 | + return; |
|
53 | + } |
|
51 | 54 | |
52 | 55 | require_once($sourcedir . '/Subs-Auth.php'); |
53 | 56 | |
@@ -55,8 +58,9 @@ discard block |
||
55 | 58 | if (isset($_POST[$type . '_pass'])) |
56 | 59 | { |
57 | 60 | // Check to ensure we're forcing SSL for authentication |
58 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) |
|
59 | - fatal_lang_error('login_ssl_required'); |
|
61 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) { |
|
62 | + fatal_lang_error('login_ssl_required'); |
|
63 | + } |
|
60 | 64 | |
61 | 65 | checkSession(); |
62 | 66 | |
@@ -72,17 +76,19 @@ discard block |
||
72 | 76 | } |
73 | 77 | |
74 | 78 | // Better be sure to remember the real referer |
75 | - if (empty($_SESSION['request_referer'])) |
|
76 | - $_SESSION['request_referer'] = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array(); |
|
77 | - elseif (empty($_POST)) |
|
78 | - unset($_SESSION['request_referer']); |
|
79 | + if (empty($_SESSION['request_referer'])) { |
|
80 | + $_SESSION['request_referer'] = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array(); |
|
81 | + } elseif (empty($_POST)) { |
|
82 | + unset($_SESSION['request_referer']); |
|
83 | + } |
|
79 | 84 | |
80 | 85 | // Need to type in a password for that, man. |
81 | - if (!isset($_GET['xml'])) |
|
82 | - adminLogin($type); |
|
83 | - else |
|
84 | - return 'session_verify_fail'; |
|
85 | -} |
|
86 | + if (!isset($_GET['xml'])) { |
|
87 | + adminLogin($type); |
|
88 | + } else { |
|
89 | + return 'session_verify_fail'; |
|
90 | + } |
|
91 | + } |
|
86 | 92 | |
87 | 93 | /** |
88 | 94 | * Require a user who is logged in. (not a guest.) |
@@ -96,25 +102,30 @@ discard block |
||
96 | 102 | global $user_info, $txt, $context, $scripturl, $modSettings; |
97 | 103 | |
98 | 104 | // Luckily, this person isn't a guest. |
99 | - if (!$user_info['is_guest']) |
|
100 | - return; |
|
105 | + if (!$user_info['is_guest']) { |
|
106 | + return; |
|
107 | + } |
|
101 | 108 | |
102 | 109 | // Log what they were trying to do didn't work) |
103 | - if (!empty($modSettings['who_enabled'])) |
|
104 | - $_GET['error'] = 'guest_login'; |
|
110 | + if (!empty($modSettings['who_enabled'])) { |
|
111 | + $_GET['error'] = 'guest_login'; |
|
112 | + } |
|
105 | 113 | writeLog(true); |
106 | 114 | |
107 | 115 | // Just die. |
108 | - if (isset($_REQUEST['xml'])) |
|
109 | - obExit(false); |
|
116 | + if (isset($_REQUEST['xml'])) { |
|
117 | + obExit(false); |
|
118 | + } |
|
110 | 119 | |
111 | 120 | // Attempt to detect if they came from dlattach. |
112 | - if (SMF != 'SSI' && empty($context['theme_loaded'])) |
|
113 | - loadTheme(); |
|
121 | + if (SMF != 'SSI' && empty($context['theme_loaded'])) { |
|
122 | + loadTheme(); |
|
123 | + } |
|
114 | 124 | |
115 | 125 | // Never redirect to an attachment |
116 | - if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) |
|
117 | - $_SESSION['login_url'] = $_SERVER['REQUEST_URL']; |
|
126 | + if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) { |
|
127 | + $_SESSION['login_url'] = $_SERVER['REQUEST_URL']; |
|
128 | + } |
|
118 | 129 | |
119 | 130 | // Load the Login template and language file. |
120 | 131 | loadLanguage('Login'); |
@@ -124,8 +135,7 @@ discard block |
||
124 | 135 | { |
125 | 136 | $_SESSION['login_url'] = $scripturl . '?' . $_SERVER['QUERY_STRING']; |
126 | 137 | redirectexit('action=login'); |
127 | - } |
|
128 | - else |
|
138 | + } else |
|
129 | 139 | { |
130 | 140 | loadTemplate('Login'); |
131 | 141 | $context['sub_template'] = 'kick_guest'; |
@@ -155,8 +165,9 @@ discard block |
||
155 | 165 | global $sourcedir, $cookiename, $user_settings, $smcFunc; |
156 | 166 | |
157 | 167 | // You cannot be banned if you are an admin - doesn't help if you log out. |
158 | - if ($user_info['is_admin']) |
|
159 | - return; |
|
168 | + if ($user_info['is_admin']) { |
|
169 | + return; |
|
170 | + } |
|
160 | 171 | |
161 | 172 | // Only check the ban every so often. (to reduce load.) |
162 | 173 | if ($forceCheck || !isset($_SESSION['ban']) || empty($modSettings['banLastUpdated']) || ($_SESSION['ban']['last_checked'] < $modSettings['banLastUpdated']) || $_SESSION['ban']['id_member'] != $user_info['id'] || $_SESSION['ban']['ip'] != $user_info['ip'] || $_SESSION['ban']['ip2'] != $user_info['ip2'] || (isset($user_info['email'], $_SESSION['ban']['email']) && $_SESSION['ban']['email'] != $user_info['email'])) |
@@ -177,8 +188,9 @@ discard block |
||
177 | 188 | // Check both IP addresses. |
178 | 189 | foreach (array('ip', 'ip2') as $ip_number) |
179 | 190 | { |
180 | - if ($ip_number == 'ip2' && $user_info['ip2'] == $user_info['ip']) |
|
181 | - continue; |
|
191 | + if ($ip_number == 'ip2' && $user_info['ip2'] == $user_info['ip']) { |
|
192 | + continue; |
|
193 | + } |
|
182 | 194 | $ban_query[] = ' {inet:' . $ip_number . '} BETWEEN bi.ip_low and bi.ip_high'; |
183 | 195 | $ban_query_vars[$ip_number] = $user_info[$ip_number]; |
184 | 196 | // IP was valid, maybe there's also a hostname... |
@@ -228,24 +240,28 @@ discard block |
||
228 | 240 | // Store every type of ban that applies to you in your session. |
229 | 241 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
230 | 242 | { |
231 | - foreach ($restrictions as $restriction) |
|
232 | - if (!empty($row[$restriction])) |
|
243 | + foreach ($restrictions as $restriction) { |
|
244 | + if (!empty($row[$restriction])) |
|
233 | 245 | { |
234 | 246 | $_SESSION['ban'][$restriction]['reason'] = $row['reason']; |
247 | + } |
|
235 | 248 | $_SESSION['ban'][$restriction]['ids'][] = $row['id_ban']; |
236 | - if (!isset($_SESSION['ban']['expire_time']) || ($_SESSION['ban']['expire_time'] != 0 && ($row['expire_time'] == 0 || $row['expire_time'] > $_SESSION['ban']['expire_time']))) |
|
237 | - $_SESSION['ban']['expire_time'] = $row['expire_time']; |
|
249 | + if (!isset($_SESSION['ban']['expire_time']) || ($_SESSION['ban']['expire_time'] != 0 && ($row['expire_time'] == 0 || $row['expire_time'] > $_SESSION['ban']['expire_time']))) { |
|
250 | + $_SESSION['ban']['expire_time'] = $row['expire_time']; |
|
251 | + } |
|
238 | 252 | |
239 | - if (!$user_info['is_guest'] && $restriction == 'cannot_access' && ($row['id_member'] == $user_info['id'] || $row['email_address'] == $user_info['email'])) |
|
240 | - $flag_is_activated = true; |
|
253 | + if (!$user_info['is_guest'] && $restriction == 'cannot_access' && ($row['id_member'] == $user_info['id'] || $row['email_address'] == $user_info['email'])) { |
|
254 | + $flag_is_activated = true; |
|
255 | + } |
|
241 | 256 | } |
242 | 257 | } |
243 | 258 | $smcFunc['db_free_result']($request); |
244 | 259 | } |
245 | 260 | |
246 | 261 | // Mark the cannot_access and cannot_post bans as being 'hit'. |
247 | - if (isset($_SESSION['ban']['cannot_access']) || isset($_SESSION['ban']['cannot_post']) || isset($_SESSION['ban']['cannot_login'])) |
|
248 | - log_ban(array_merge(isset($_SESSION['ban']['cannot_access']) ? $_SESSION['ban']['cannot_access']['ids'] : array(), isset($_SESSION['ban']['cannot_post']) ? $_SESSION['ban']['cannot_post']['ids'] : array(), isset($_SESSION['ban']['cannot_login']) ? $_SESSION['ban']['cannot_login']['ids'] : array())); |
|
262 | + if (isset($_SESSION['ban']['cannot_access']) || isset($_SESSION['ban']['cannot_post']) || isset($_SESSION['ban']['cannot_login'])) { |
|
263 | + log_ban(array_merge(isset($_SESSION['ban']['cannot_access']) ? $_SESSION['ban']['cannot_access']['ids'] : array(), isset($_SESSION['ban']['cannot_post']) ? $_SESSION['ban']['cannot_post']['ids'] : array(), isset($_SESSION['ban']['cannot_login']) ? $_SESSION['ban']['cannot_login']['ids'] : array())); |
|
264 | + } |
|
249 | 265 | |
250 | 266 | // If for whatever reason the is_activated flag seems wrong, do a little work to clear it up. |
251 | 267 | if ($user_info['id'] && (($user_settings['is_activated'] >= 10 && !$flag_is_activated) |
@@ -260,8 +276,9 @@ discard block |
||
260 | 276 | if (!isset($_SESSION['ban']['cannot_access']) && !empty($_COOKIE[$cookiename . '_'])) |
261 | 277 | { |
262 | 278 | $bans = explode(',', $_COOKIE[$cookiename . '_']); |
263 | - foreach ($bans as $key => $value) |
|
264 | - $bans[$key] = (int) $value; |
|
279 | + foreach ($bans as $key => $value) { |
|
280 | + $bans[$key] = (int) $value; |
|
281 | + } |
|
265 | 282 | $request = $smcFunc['db_query']('', ' |
266 | 283 | SELECT bi.id_ban, bg.reason |
267 | 284 | FROM {db_prefix}ban_items AS bi |
@@ -297,14 +314,15 @@ discard block |
||
297 | 314 | if (isset($_SESSION['ban']['cannot_access'])) |
298 | 315 | { |
299 | 316 | // We don't wanna see you! |
300 | - if (!$user_info['is_guest']) |
|
301 | - $smcFunc['db_query']('', ' |
|
317 | + if (!$user_info['is_guest']) { |
|
318 | + $smcFunc['db_query']('', ' |
|
302 | 319 | DELETE FROM {db_prefix}log_online |
303 | 320 | WHERE id_member = {int:current_member}', |
304 | 321 | array( |
305 | 322 | 'current_member' => $user_info['id'], |
306 | 323 | ) |
307 | 324 | ); |
325 | + } |
|
308 | 326 | |
309 | 327 | // 'Log' the user out. Can't have any funny business... (save the name!) |
310 | 328 | $old_name = isset($user_info['name']) && $user_info['name'] != '' ? $user_info['name'] : $txt['guest_title']; |
@@ -390,9 +408,10 @@ discard block |
||
390 | 408 | } |
391 | 409 | |
392 | 410 | // Fix up the banning permissions. |
393 | - if (isset($user_info['permissions'])) |
|
394 | - banPermissions(); |
|
395 | -} |
|
411 | + if (isset($user_info['permissions'])) { |
|
412 | + banPermissions(); |
|
413 | + } |
|
414 | + } |
|
396 | 415 | |
397 | 416 | /** |
398 | 417 | * Fix permissions according to ban status. |
@@ -403,8 +422,9 @@ discard block |
||
403 | 422 | global $user_info, $sourcedir, $modSettings, $context; |
404 | 423 | |
405 | 424 | // Somehow they got here, at least take away all permissions... |
406 | - if (isset($_SESSION['ban']['cannot_access'])) |
|
407 | - $user_info['permissions'] = array(); |
|
425 | + if (isset($_SESSION['ban']['cannot_access'])) { |
|
426 | + $user_info['permissions'] = array(); |
|
427 | + } |
|
408 | 428 | // Okay, well, you can watch, but don't touch a thing. |
409 | 429 | elseif (isset($_SESSION['ban']['cannot_post']) || (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $user_info['warning'])) |
410 | 430 | { |
@@ -446,19 +466,20 @@ discard block |
||
446 | 466 | call_integration_hook('integrate_warn_permissions', array(&$permission_change)); |
447 | 467 | foreach ($permission_change as $old => $new) |
448 | 468 | { |
449 | - if (!in_array($old, $user_info['permissions'])) |
|
450 | - unset($permission_change[$old]); |
|
451 | - else |
|
452 | - $user_info['permissions'][] = $new; |
|
469 | + if (!in_array($old, $user_info['permissions'])) { |
|
470 | + unset($permission_change[$old]); |
|
471 | + } else { |
|
472 | + $user_info['permissions'][] = $new; |
|
473 | + } |
|
453 | 474 | } |
454 | 475 | $user_info['permissions'] = array_diff($user_info['permissions'], array_keys($permission_change)); |
455 | 476 | } |
456 | 477 | |
457 | 478 | // @todo Find a better place to call this? Needs to be after permissions loaded! |
458 | 479 | // Finally, some bits we cache in the session because it saves queries. |
459 | - if (isset($_SESSION['mc']) && $_SESSION['mc']['time'] > $modSettings['settings_updated'] && $_SESSION['mc']['id'] == $user_info['id']) |
|
460 | - $user_info['mod_cache'] = $_SESSION['mc']; |
|
461 | - else |
|
480 | + if (isset($_SESSION['mc']) && $_SESSION['mc']['time'] > $modSettings['settings_updated'] && $_SESSION['mc']['id'] == $user_info['id']) { |
|
481 | + $user_info['mod_cache'] = $_SESSION['mc']; |
|
482 | + } else |
|
462 | 483 | { |
463 | 484 | require_once($sourcedir . '/Subs-Auth.php'); |
464 | 485 | rebuildModCache(); |
@@ -469,14 +490,12 @@ discard block |
||
469 | 490 | { |
470 | 491 | $context['open_mod_reports'] = $_SESSION['rc']['reports']; |
471 | 492 | $context['open_member_reports'] = $_SESSION['rc']['member_reports']; |
472 | - } |
|
473 | - elseif ($_SESSION['mc']['bq'] != '0=1') |
|
493 | + } elseif ($_SESSION['mc']['bq'] != '0=1') |
|
474 | 494 | { |
475 | 495 | require_once($sourcedir . '/Subs-ReportedContent.php'); |
476 | 496 | $context['open_mod_reports'] = recountOpenReports('posts'); |
477 | 497 | $context['open_member_reports'] = recountOpenReports('members'); |
478 | - } |
|
479 | - else |
|
498 | + } else |
|
480 | 499 | { |
481 | 500 | $context['open_mod_reports'] = 0; |
482 | 501 | $context['open_member_reports'] = 0; |
@@ -497,8 +516,9 @@ discard block |
||
497 | 516 | global $user_info, $smcFunc; |
498 | 517 | |
499 | 518 | // Don't log web accelerators, it's very confusing... |
500 | - if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') |
|
501 | - return; |
|
519 | + if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') { |
|
520 | + return; |
|
521 | + } |
|
502 | 522 | |
503 | 523 | $smcFunc['db_insert']('', |
504 | 524 | '{db_prefix}log_banned', |
@@ -508,8 +528,8 @@ discard block |
||
508 | 528 | ); |
509 | 529 | |
510 | 530 | // One extra point for these bans. |
511 | - if (!empty($ban_ids)) |
|
512 | - $smcFunc['db_query']('', ' |
|
531 | + if (!empty($ban_ids)) { |
|
532 | + $smcFunc['db_query']('', ' |
|
513 | 533 | UPDATE {db_prefix}ban_items |
514 | 534 | SET hits = hits + 1 |
515 | 535 | WHERE id_ban IN ({array_int:ban_ids})', |
@@ -517,7 +537,8 @@ discard block |
||
517 | 537 | 'ban_ids' => $ban_ids, |
518 | 538 | ) |
519 | 539 | ); |
520 | -} |
|
540 | + } |
|
541 | + } |
|
521 | 542 | |
522 | 543 | /** |
523 | 544 | * Checks if a given email address might be banned. |
@@ -533,8 +554,9 @@ discard block |
||
533 | 554 | global $txt, $smcFunc; |
534 | 555 | |
535 | 556 | // Can't ban an empty email |
536 | - if (empty($email) || trim($email) == '') |
|
537 | - return; |
|
557 | + if (empty($email) || trim($email) == '') { |
|
558 | + return; |
|
559 | + } |
|
538 | 560 | |
539 | 561 | // Let's start with the bans based on your IP/hostname/memberID... |
540 | 562 | $ban_ids = isset($_SESSION['ban'][$restriction]) ? $_SESSION['ban'][$restriction]['ids'] : array(); |
@@ -607,16 +629,18 @@ discard block |
||
607 | 629 | if ($type == 'post') |
608 | 630 | { |
609 | 631 | $check = isset($_POST[$_SESSION['session_var']]) ? $_POST[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_POST['sc']) ? $_POST['sc'] : null); |
610 | - if ($check !== $sc) |
|
611 | - $error = 'session_timeout'; |
|
632 | + if ($check !== $sc) { |
|
633 | + $error = 'session_timeout'; |
|
634 | + } |
|
612 | 635 | } |
613 | 636 | |
614 | 637 | // How about $_GET['sesc']? |
615 | 638 | elseif ($type == 'get') |
616 | 639 | { |
617 | 640 | $check = isset($_GET[$_SESSION['session_var']]) ? $_GET[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_GET['sesc']) ? $_GET['sesc'] : null); |
618 | - if ($check !== $sc) |
|
619 | - $error = 'session_verify_fail'; |
|
641 | + if ($check !== $sc) { |
|
642 | + $error = 'session_verify_fail'; |
|
643 | + } |
|
620 | 644 | } |
621 | 645 | |
622 | 646 | // Or can it be in either? |
@@ -624,13 +648,15 @@ discard block |
||
624 | 648 | { |
625 | 649 | $check = isset($_GET[$_SESSION['session_var']]) ? $_GET[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_GET['sesc']) ? $_GET['sesc'] : (isset($_POST[$_SESSION['session_var']]) ? $_POST[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_POST['sc']) ? $_POST['sc'] : null))); |
626 | 650 | |
627 | - if ($check !== $sc) |
|
628 | - $error = 'session_verify_fail'; |
|
651 | + if ($check !== $sc) { |
|
652 | + $error = 'session_verify_fail'; |
|
653 | + } |
|
629 | 654 | } |
630 | 655 | |
631 | 656 | // Verify that they aren't changing user agents on us - that could be bad. |
632 | - if ((!isset($_SESSION['USER_AGENT']) || $_SESSION['USER_AGENT'] != $_SERVER['HTTP_USER_AGENT']) && empty($modSettings['disableCheckUA'])) |
|
633 | - $error = 'session_verify_fail'; |
|
657 | + if ((!isset($_SESSION['USER_AGENT']) || $_SESSION['USER_AGENT'] != $_SERVER['HTTP_USER_AGENT']) && empty($modSettings['disableCheckUA'])) { |
|
658 | + $error = 'session_verify_fail'; |
|
659 | + } |
|
634 | 660 | |
635 | 661 | // Make sure a page with session check requirement is not being prefetched. |
636 | 662 | if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') |
@@ -641,30 +667,35 @@ discard block |
||
641 | 667 | } |
642 | 668 | |
643 | 669 | // Check the referring site - it should be the same server at least! |
644 | - if (isset($_SESSION['request_referer'])) |
|
645 | - $referrer = $_SESSION['request_referer']; |
|
646 | - else |
|
647 | - $referrer = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array(); |
|
670 | + if (isset($_SESSION['request_referer'])) { |
|
671 | + $referrer = $_SESSION['request_referer']; |
|
672 | + } else { |
|
673 | + $referrer = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array(); |
|
674 | + } |
|
648 | 675 | if (!empty($referrer['host'])) |
649 | 676 | { |
650 | - if (strpos($_SERVER['HTTP_HOST'], ':') !== false) |
|
651 | - $real_host = substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], ':')); |
|
652 | - else |
|
653 | - $real_host = $_SERVER['HTTP_HOST']; |
|
677 | + if (strpos($_SERVER['HTTP_HOST'], ':') !== false) { |
|
678 | + $real_host = substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], ':')); |
|
679 | + } else { |
|
680 | + $real_host = $_SERVER['HTTP_HOST']; |
|
681 | + } |
|
654 | 682 | |
655 | 683 | $parsed_url = parse_url($boardurl); |
656 | 684 | |
657 | 685 | // Are global cookies on? If so, let's check them ;). |
658 | 686 | if (!empty($modSettings['globalCookies'])) |
659 | 687 | { |
660 | - if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $parsed_url['host'], $parts) == 1) |
|
661 | - $parsed_url['host'] = $parts[1]; |
|
688 | + if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $parsed_url['host'], $parts) == 1) { |
|
689 | + $parsed_url['host'] = $parts[1]; |
|
690 | + } |
|
662 | 691 | |
663 | - if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $referrer['host'], $parts) == 1) |
|
664 | - $referrer['host'] = $parts[1]; |
|
692 | + if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $referrer['host'], $parts) == 1) { |
|
693 | + $referrer['host'] = $parts[1]; |
|
694 | + } |
|
665 | 695 | |
666 | - if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $real_host, $parts) == 1) |
|
667 | - $real_host = $parts[1]; |
|
696 | + if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $real_host, $parts) == 1) { |
|
697 | + $real_host = $parts[1]; |
|
698 | + } |
|
668 | 699 | } |
669 | 700 | |
670 | 701 | // Okay: referrer must either match parsed_url or real_host. |
@@ -682,12 +713,14 @@ discard block |
||
682 | 713 | $log_error = true; |
683 | 714 | } |
684 | 715 | |
685 | - if (strtolower($_SERVER['HTTP_USER_AGENT']) == 'hacker') |
|
686 | - fatal_error('Sound the alarm! It\'s a hacker! Close the castle gates!!', false); |
|
716 | + if (strtolower($_SERVER['HTTP_USER_AGENT']) == 'hacker') { |
|
717 | + fatal_error('Sound the alarm! It\'s a hacker! Close the castle gates!!', false); |
|
718 | + } |
|
687 | 719 | |
688 | 720 | // Everything is ok, return an empty string. |
689 | - if (!isset($error)) |
|
690 | - return ''; |
|
721 | + if (!isset($error)) { |
|
722 | + return ''; |
|
723 | + } |
|
691 | 724 | // A session error occurred, show the error. |
692 | 725 | elseif ($is_fatal) |
693 | 726 | { |
@@ -696,13 +729,14 @@ discard block |
||
696 | 729 | ob_end_clean(); |
697 | 730 | header('HTTP/1.1 403 Forbidden - Session timeout'); |
698 | 731 | die; |
732 | + } else { |
|
733 | + fatal_lang_error($error, isset($log_error) ? 'user' : false); |
|
699 | 734 | } |
700 | - else |
|
701 | - fatal_lang_error($error, isset($log_error) ? 'user' : false); |
|
702 | 735 | } |
703 | 736 | // A session error occurred, return the error to the calling function. |
704 | - else |
|
705 | - return $error; |
|
737 | + else { |
|
738 | + return $error; |
|
739 | + } |
|
706 | 740 | |
707 | 741 | // We really should never fall through here, for very important reasons. Let's make sure. |
708 | 742 | trigger_error('Hacking attempt...', E_USER_ERROR); |
@@ -718,10 +752,9 @@ discard block |
||
718 | 752 | { |
719 | 753 | global $modSettings; |
720 | 754 | |
721 | - if (isset($_GET['confirm']) && isset($_SESSION['confirm_' . $action]) && md5($_GET['confirm'] . $_SERVER['HTTP_USER_AGENT']) == $_SESSION['confirm_' . $action]) |
|
722 | - return true; |
|
723 | - |
|
724 | - else |
|
755 | + if (isset($_GET['confirm']) && isset($_SESSION['confirm_' . $action]) && md5($_GET['confirm'] . $_SERVER['HTTP_USER_AGENT']) == $_SESSION['confirm_' . $action]) { |
|
756 | + return true; |
|
757 | + } else |
|
725 | 758 | { |
726 | 759 | $token = md5(mt_rand() . session_id() . (string) microtime() . $modSettings['rand_seed']); |
727 | 760 | $_SESSION['confirm_' . $action] = md5($token . $_SERVER['HTTP_USER_AGENT']); |
@@ -772,9 +805,9 @@ discard block |
||
772 | 805 | $return = $_SESSION['token'][$type . '-' . $action][3]; |
773 | 806 | unset($_SESSION['token'][$type . '-' . $action]); |
774 | 807 | return $return; |
808 | + } else { |
|
809 | + return ''; |
|
775 | 810 | } |
776 | - else |
|
777 | - return ''; |
|
778 | 811 | } |
779 | 812 | |
780 | 813 | // This nasty piece of code validates a token. |
@@ -805,12 +838,14 @@ discard block |
||
805 | 838 | fatal_lang_error('token_verify_fail', false); |
806 | 839 | } |
807 | 840 | // Remove this token as its useless |
808 | - else |
|
809 | - unset($_SESSION['token'][$type . '-' . $action]); |
|
841 | + else { |
|
842 | + unset($_SESSION['token'][$type . '-' . $action]); |
|
843 | + } |
|
810 | 844 | |
811 | 845 | // Randomly check if we should remove some older tokens. |
812 | - if (mt_rand(0, 138) == 23) |
|
813 | - cleanTokens(); |
|
846 | + if (mt_rand(0, 138) == 23) { |
|
847 | + cleanTokens(); |
|
848 | + } |
|
814 | 849 | |
815 | 850 | return false; |
816 | 851 | } |
@@ -825,14 +860,16 @@ discard block |
||
825 | 860 | function cleanTokens($complete = false) |
826 | 861 | { |
827 | 862 | // We appreciate cleaning up after yourselves. |
828 | - if (!isset($_SESSION['token'])) |
|
829 | - return; |
|
863 | + if (!isset($_SESSION['token'])) { |
|
864 | + return; |
|
865 | + } |
|
830 | 866 | |
831 | 867 | // Clean up tokens, trying to give enough time still. |
832 | - foreach ($_SESSION['token'] as $key => $data) |
|
833 | - if ($data[2] + 10800 < time() || $complete) |
|
868 | + foreach ($_SESSION['token'] as $key => $data) { |
|
869 | + if ($data[2] + 10800 < time() || $complete) |
|
834 | 870 | unset($_SESSION['token'][$key]); |
835 | -} |
|
871 | + } |
|
872 | + } |
|
836 | 873 | |
837 | 874 | /** |
838 | 875 | * Check whether a form has been submitted twice. |
@@ -850,37 +887,40 @@ discard block |
||
850 | 887 | { |
851 | 888 | global $context; |
852 | 889 | |
853 | - if (!isset($_SESSION['forms'])) |
|
854 | - $_SESSION['forms'] = array(); |
|
890 | + if (!isset($_SESSION['forms'])) { |
|
891 | + $_SESSION['forms'] = array(); |
|
892 | + } |
|
855 | 893 | |
856 | 894 | // Register a form number and store it in the session stack. (use this on the page that has the form.) |
857 | 895 | if ($action == 'register') |
858 | 896 | { |
859 | 897 | $context['form_sequence_number'] = 0; |
860 | - while (empty($context['form_sequence_number']) || in_array($context['form_sequence_number'], $_SESSION['forms'])) |
|
861 | - $context['form_sequence_number'] = mt_rand(1, 16000000); |
|
898 | + while (empty($context['form_sequence_number']) || in_array($context['form_sequence_number'], $_SESSION['forms'])) { |
|
899 | + $context['form_sequence_number'] = mt_rand(1, 16000000); |
|
900 | + } |
|
862 | 901 | } |
863 | 902 | // Check whether the submitted number can be found in the session. |
864 | 903 | elseif ($action == 'check') |
865 | 904 | { |
866 | - if (!isset($_REQUEST['seqnum'])) |
|
867 | - return true; |
|
868 | - elseif (!in_array($_REQUEST['seqnum'], $_SESSION['forms'])) |
|
905 | + if (!isset($_REQUEST['seqnum'])) { |
|
906 | + return true; |
|
907 | + } elseif (!in_array($_REQUEST['seqnum'], $_SESSION['forms'])) |
|
869 | 908 | { |
870 | 909 | $_SESSION['forms'][] = (int) $_REQUEST['seqnum']; |
871 | 910 | return true; |
911 | + } elseif ($is_fatal) { |
|
912 | + fatal_lang_error('error_form_already_submitted', false); |
|
913 | + } else { |
|
914 | + return false; |
|
872 | 915 | } |
873 | - elseif ($is_fatal) |
|
874 | - fatal_lang_error('error_form_already_submitted', false); |
|
875 | - else |
|
876 | - return false; |
|
877 | 916 | } |
878 | 917 | // Don't check, just free the stack number. |
879 | - elseif ($action == 'free' && isset($_REQUEST['seqnum']) && in_array($_REQUEST['seqnum'], $_SESSION['forms'])) |
|
880 | - $_SESSION['forms'] = array_diff($_SESSION['forms'], array($_REQUEST['seqnum'])); |
|
881 | - elseif ($action != 'free') |
|
882 | - trigger_error('checkSubmitOnce(): Invalid action \'' . $action . '\'', E_USER_WARNING); |
|
883 | -} |
|
918 | + elseif ($action == 'free' && isset($_REQUEST['seqnum']) && in_array($_REQUEST['seqnum'], $_SESSION['forms'])) { |
|
919 | + $_SESSION['forms'] = array_diff($_SESSION['forms'], array($_REQUEST['seqnum'])); |
|
920 | + } elseif ($action != 'free') { |
|
921 | + trigger_error('checkSubmitOnce(): Invalid action \'' . $action . '\'', E_USER_WARNING); |
|
922 | + } |
|
923 | + } |
|
884 | 924 | |
885 | 925 | /** |
886 | 926 | * Check the user's permissions. |
@@ -897,16 +937,19 @@ discard block |
||
897 | 937 | global $user_info, $smcFunc; |
898 | 938 | |
899 | 939 | // You're always allowed to do nothing. (unless you're a working man, MR. LAZY :P!) |
900 | - if (empty($permission)) |
|
901 | - return true; |
|
940 | + if (empty($permission)) { |
|
941 | + return true; |
|
942 | + } |
|
902 | 943 | |
903 | 944 | // You're never allowed to do something if your data hasn't been loaded yet! |
904 | - if (empty($user_info)) |
|
905 | - return false; |
|
945 | + if (empty($user_info)) { |
|
946 | + return false; |
|
947 | + } |
|
906 | 948 | |
907 | 949 | // Administrators are supermen :P. |
908 | - if ($user_info['is_admin']) |
|
909 | - return true; |
|
950 | + if ($user_info['is_admin']) { |
|
951 | + return true; |
|
952 | + } |
|
910 | 953 | |
911 | 954 | // Let's ensure this is an array. |
912 | 955 | $permission = (array) $permission; |
@@ -914,14 +957,16 @@ discard block |
||
914 | 957 | // Are we checking the _current_ board, or some other boards? |
915 | 958 | if ($boards === null) |
916 | 959 | { |
917 | - if (count(array_intersect($permission, $user_info['permissions'])) != 0) |
|
918 | - return true; |
|
960 | + if (count(array_intersect($permission, $user_info['permissions'])) != 0) { |
|
961 | + return true; |
|
962 | + } |
|
919 | 963 | // You aren't allowed, by default. |
920 | - else |
|
921 | - return false; |
|
964 | + else { |
|
965 | + return false; |
|
966 | + } |
|
967 | + } elseif (!is_array($boards)) { |
|
968 | + $boards = array($boards); |
|
922 | 969 | } |
923 | - elseif (!is_array($boards)) |
|
924 | - $boards = array($boards); |
|
925 | 970 | |
926 | 971 | $request = $smcFunc['db_query']('', ' |
927 | 972 | SELECT MIN(bp.add_deny) AS add_deny |
@@ -944,12 +989,14 @@ discard block |
||
944 | 989 | ); |
945 | 990 | |
946 | 991 | // Make sure they can do it on all of the boards. |
947 | - if ($smcFunc['db_num_rows']($request) != count($boards)) |
|
948 | - return false; |
|
992 | + if ($smcFunc['db_num_rows']($request) != count($boards)) { |
|
993 | + return false; |
|
994 | + } |
|
949 | 995 | |
950 | 996 | $result = true; |
951 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
952 | - $result &= !empty($row['add_deny']); |
|
997 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
998 | + $result &= !empty($row['add_deny']); |
|
999 | + } |
|
953 | 1000 | $smcFunc['db_free_result']($request); |
954 | 1001 | |
955 | 1002 | // If the query returned 1, they can do it... otherwise, they can't. |
@@ -1014,9 +1061,10 @@ discard block |
||
1014 | 1061 | |
1015 | 1062 | // If you're doing something on behalf of some "heavy" permissions, validate your session. |
1016 | 1063 | // (take out the heavy permissions, and if you can't do anything but those, you need a validated session.) |
1017 | - if (!allowedTo(array_diff($permission, $heavy_permissions), $boards)) |
|
1018 | - validateSession(); |
|
1019 | -} |
|
1064 | + if (!allowedTo(array_diff($permission, $heavy_permissions), $boards)) { |
|
1065 | + validateSession(); |
|
1066 | + } |
|
1067 | + } |
|
1020 | 1068 | |
1021 | 1069 | /** |
1022 | 1070 | * Return the boards a user has a certain (board) permission on. (array(0) if all.) |
@@ -1035,8 +1083,9 @@ discard block |
||
1035 | 1083 | global $user_info, $smcFunc; |
1036 | 1084 | |
1037 | 1085 | // Arrays are nice, most of the time. |
1038 | - if (!is_array($permissions)) |
|
1039 | - $permissions = array($permissions); |
|
1086 | + if (!is_array($permissions)) { |
|
1087 | + $permissions = array($permissions); |
|
1088 | + } |
|
1040 | 1089 | |
1041 | 1090 | /* |
1042 | 1091 | * Set $simple to true to use this function as it were in SMF 2.0.x. |
@@ -1048,13 +1097,14 @@ discard block |
||
1048 | 1097 | // Administrators are all powerful, sorry. |
1049 | 1098 | if ($user_info['is_admin']) |
1050 | 1099 | { |
1051 | - if ($simple) |
|
1052 | - return array(0); |
|
1053 | - else |
|
1100 | + if ($simple) { |
|
1101 | + return array(0); |
|
1102 | + } else |
|
1054 | 1103 | { |
1055 | 1104 | $boards = array(); |
1056 | - foreach ($permissions as $permission) |
|
1057 | - $boards[$permission] = array(0); |
|
1105 | + foreach ($permissions as $permission) { |
|
1106 | + $boards[$permission] = array(0); |
|
1107 | + } |
|
1058 | 1108 | |
1059 | 1109 | return $boards; |
1060 | 1110 | } |
@@ -1086,31 +1136,32 @@ discard block |
||
1086 | 1136 | { |
1087 | 1137 | if ($simple) |
1088 | 1138 | { |
1089 | - if (empty($row['add_deny'])) |
|
1090 | - $deny_boards[] = $row['id_board']; |
|
1091 | - else |
|
1092 | - $boards[] = $row['id_board']; |
|
1093 | - } |
|
1094 | - else |
|
1139 | + if (empty($row['add_deny'])) { |
|
1140 | + $deny_boards[] = $row['id_board']; |
|
1141 | + } else { |
|
1142 | + $boards[] = $row['id_board']; |
|
1143 | + } |
|
1144 | + } else |
|
1095 | 1145 | { |
1096 | - if (empty($row['add_deny'])) |
|
1097 | - $deny_boards[$row['permission']][] = $row['id_board']; |
|
1098 | - else |
|
1099 | - $boards[$row['permission']][] = $row['id_board']; |
|
1146 | + if (empty($row['add_deny'])) { |
|
1147 | + $deny_boards[$row['permission']][] = $row['id_board']; |
|
1148 | + } else { |
|
1149 | + $boards[$row['permission']][] = $row['id_board']; |
|
1150 | + } |
|
1100 | 1151 | } |
1101 | 1152 | } |
1102 | 1153 | $smcFunc['db_free_result']($request); |
1103 | 1154 | |
1104 | - if ($simple) |
|
1105 | - $boards = array_unique(array_values(array_diff($boards, $deny_boards))); |
|
1106 | - else |
|
1155 | + if ($simple) { |
|
1156 | + $boards = array_unique(array_values(array_diff($boards, $deny_boards))); |
|
1157 | + } else |
|
1107 | 1158 | { |
1108 | 1159 | foreach ($permissions as $permission) |
1109 | 1160 | { |
1110 | 1161 | // never had it to start with |
1111 | - if (empty($boards[$permission])) |
|
1112 | - $boards[$permission] = array(); |
|
1113 | - else |
|
1162 | + if (empty($boards[$permission])) { |
|
1163 | + $boards[$permission] = array(); |
|
1164 | + } else |
|
1114 | 1165 | { |
1115 | 1166 | // Or it may have been removed |
1116 | 1167 | $deny_boards[$permission] = isset($deny_boards[$permission]) ? $deny_boards[$permission] : array(); |
@@ -1146,10 +1197,11 @@ discard block |
||
1146 | 1197 | |
1147 | 1198 | |
1148 | 1199 | // Moderators are free... |
1149 | - if (!allowedTo('moderate_board')) |
|
1150 | - $timeLimit = isset($timeOverrides[$error_type]) ? $timeOverrides[$error_type] : $modSettings['spamWaitTime']; |
|
1151 | - else |
|
1152 | - $timeLimit = 2; |
|
1200 | + if (!allowedTo('moderate_board')) { |
|
1201 | + $timeLimit = isset($timeOverrides[$error_type]) ? $timeOverrides[$error_type] : $modSettings['spamWaitTime']; |
|
1202 | + } else { |
|
1203 | + $timeLimit = 2; |
|
1204 | + } |
|
1153 | 1205 | |
1154 | 1206 | call_integration_hook('integrate_spam_protection', array(&$timeOverrides, &$timeLimit)); |
1155 | 1207 | |
@@ -1176,8 +1228,9 @@ discard block |
||
1176 | 1228 | if ($smcFunc['db_affected_rows']() != 1) |
1177 | 1229 | { |
1178 | 1230 | // Spammer! You only have to wait a *few* seconds! |
1179 | - if (!$only_return_result) |
|
1180 | - fatal_lang_error($error_type . '_WaitTime_broken', false, array($timeLimit)); |
|
1231 | + if (!$only_return_result) { |
|
1232 | + fatal_lang_error($error_type . '_WaitTime_broken', false, array($timeLimit)); |
|
1233 | + } |
|
1181 | 1234 | |
1182 | 1235 | return true; |
1183 | 1236 | } |
@@ -1195,11 +1248,13 @@ discard block |
||
1195 | 1248 | */ |
1196 | 1249 | function secureDirectory($path, $attachments = false) |
1197 | 1250 | { |
1198 | - if (empty($path)) |
|
1199 | - return 'empty_path'; |
|
1251 | + if (empty($path)) { |
|
1252 | + return 'empty_path'; |
|
1253 | + } |
|
1200 | 1254 | |
1201 | - if (!is_writable($path)) |
|
1202 | - return 'path_not_writable'; |
|
1255 | + if (!is_writable($path)) { |
|
1256 | + return 'path_not_writable'; |
|
1257 | + } |
|
1203 | 1258 | |
1204 | 1259 | $directoryname = basename($path); |
1205 | 1260 | |
@@ -1211,9 +1266,9 @@ discard block |
||
1211 | 1266 | |
1212 | 1267 | RemoveHandler .php .php3 .phtml .cgi .fcgi .pl .fpl .shtml'; |
1213 | 1268 | |
1214 | - if (file_exists($path . '/.htaccess')) |
|
1215 | - $errors[] = 'htaccess_exists'; |
|
1216 | - else |
|
1269 | + if (file_exists($path . '/.htaccess')) { |
|
1270 | + $errors[] = 'htaccess_exists'; |
|
1271 | + } else |
|
1217 | 1272 | { |
1218 | 1273 | $fh = @fopen($path . '/.htaccess', 'w'); |
1219 | 1274 | if ($fh) { |
@@ -1225,9 +1280,9 @@ discard block |
||
1225 | 1280 | $errors[] = 'htaccess_cannot_create_file'; |
1226 | 1281 | } |
1227 | 1282 | |
1228 | - if (file_exists($path . '/index.php')) |
|
1229 | - $errors[] = 'index-php_exists'; |
|
1230 | - else |
|
1283 | + if (file_exists($path . '/index.php')) { |
|
1284 | + $errors[] = 'index-php_exists'; |
|
1285 | + } else |
|
1231 | 1286 | { |
1232 | 1287 | $fh = @fopen($path . '/index.php', 'w'); |
1233 | 1288 | if ($fh) { |
@@ -1254,11 +1309,12 @@ discard block |
||
1254 | 1309 | $errors[] = 'index-php_cannot_create_file'; |
1255 | 1310 | } |
1256 | 1311 | |
1257 | - if (!empty($errors)) |
|
1258 | - return $errors; |
|
1259 | - else |
|
1260 | - return true; |
|
1261 | -} |
|
1312 | + if (!empty($errors)) { |
|
1313 | + return $errors; |
|
1314 | + } else { |
|
1315 | + return true; |
|
1316 | + } |
|
1317 | + } |
|
1262 | 1318 | |
1263 | 1319 | /** |
1264 | 1320 | * This sets the X-Frame-Options header. |
@@ -1271,14 +1327,16 @@ discard block |
||
1271 | 1327 | global $modSettings; |
1272 | 1328 | |
1273 | 1329 | $option = 'SAMEORIGIN'; |
1274 | - if (is_null($override) && !empty($modSettings['frame_security'])) |
|
1275 | - $option = $modSettings['frame_security']; |
|
1276 | - elseif (in_array($override, array('SAMEORIGIN', 'DENY'))) |
|
1277 | - $option = $override; |
|
1330 | + if (is_null($override) && !empty($modSettings['frame_security'])) { |
|
1331 | + $option = $modSettings['frame_security']; |
|
1332 | + } elseif (in_array($override, array('SAMEORIGIN', 'DENY'))) { |
|
1333 | + $option = $override; |
|
1334 | + } |
|
1278 | 1335 | |
1279 | 1336 | // Don't bother setting the header if we have disabled it. |
1280 | - if ($option == 'DISABLE') |
|
1281 | - return; |
|
1337 | + if ($option == 'DISABLE') { |
|
1338 | + return; |
|
1339 | + } |
|
1282 | 1340 | |
1283 | 1341 | // Finally set it. |
1284 | 1342 | header('X-Frame-Options: ' . $option); |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | 'value' => $txt['date'], |
137 | 137 | ), |
138 | 138 | 'data' => array( |
139 | - 'function' => function ($rowData) use ($txt) |
|
139 | + 'function' => function($rowData) use ($txt) |
|
140 | 140 | { |
141 | 141 | // Recurring every year or just a single year? |
142 | 142 | $year = $rowData['year'] == '1004' ? sprintf('(%1$s)', $txt['every_year']) : $rowData['year']; |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | checkSession(); |
219 | 219 | |
220 | 220 | // Not too long good sir? |
221 | - $_REQUEST['title'] = $smcFunc['substr']($_REQUEST['title'], 0, 60); |
|
221 | + $_REQUEST['title'] = $smcFunc['substr']($_REQUEST['title'], 0, 60); |
|
222 | 222 | $_REQUEST['holiday'] = isset($_REQUEST['holiday']) ? (int) $_REQUEST['holiday'] : 0; |
223 | 223 | |
224 | 224 | if (isset($_REQUEST['delete'])) |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 4 |
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 controlling function doesn't have much to do... yet. |
@@ -43,8 +44,7 @@ discard block |
||
43 | 44 | 'settings' => 'ModifyCalendarSettings' |
44 | 45 | ); |
45 | 46 | $default = 'holidays'; |
46 | - } |
|
47 | - else |
|
47 | + } else |
|
48 | 48 | { |
49 | 49 | $subActions = array( |
50 | 50 | 'settings' => 'ModifyCalendarSettings' |
@@ -60,8 +60,8 @@ discard block |
||
60 | 60 | 'help' => 'calendar', |
61 | 61 | 'description' => $txt['calendar_settings_desc'], |
62 | 62 | ); |
63 | - if (!empty($modSettings['cal_enabled'])) |
|
64 | - $context[$context['admin_menu_name']]['tab_data']['tabs'] = array( |
|
63 | + if (!empty($modSettings['cal_enabled'])) { |
|
64 | + $context[$context['admin_menu_name']]['tab_data']['tabs'] = array( |
|
65 | 65 | 'holidays' => array( |
66 | 66 | 'description' => $txt['manage_holidays_desc'], |
67 | 67 | ), |
@@ -69,6 +69,7 @@ discard block |
||
69 | 69 | 'description' => $txt['calendar_settings_desc'], |
70 | 70 | ), |
71 | 71 | ); |
72 | + } |
|
72 | 73 | |
73 | 74 | call_integration_hook('integrate_manage_calendar', array(&$subActions)); |
74 | 75 | |
@@ -88,8 +89,9 @@ discard block |
||
88 | 89 | checkSession(); |
89 | 90 | validateToken('admin-mc'); |
90 | 91 | |
91 | - foreach ($_REQUEST['holiday'] as $id => $value) |
|
92 | - $_REQUEST['holiday'][$id] = (int) $id; |
|
92 | + foreach ($_REQUEST['holiday'] as $id => $value) { |
|
93 | + $_REQUEST['holiday'][$id] = (int) $id; |
|
94 | + } |
|
93 | 95 | |
94 | 96 | // Now the IDs are "safe" do the delete... |
95 | 97 | require_once($sourcedir . '/Subs-Calendar.php'); |
@@ -209,8 +211,9 @@ discard block |
||
209 | 211 | $context['sub_template'] = 'edit_holiday'; |
210 | 212 | |
211 | 213 | // Cast this for safety... |
212 | - if (isset($_REQUEST['holiday'])) |
|
213 | - $_REQUEST['holiday'] = (int) $_REQUEST['holiday']; |
|
214 | + if (isset($_REQUEST['holiday'])) { |
|
215 | + $_REQUEST['holiday'] = (int) $_REQUEST['holiday']; |
|
216 | + } |
|
214 | 217 | |
215 | 218 | // Submitting? |
216 | 219 | if (isset($_POST[$context['session_var']]) && (isset($_REQUEST['delete']) || $_REQUEST['title'] != '')) |
@@ -221,19 +224,19 @@ discard block |
||
221 | 224 | $_REQUEST['title'] = $smcFunc['substr']($_REQUEST['title'], 0, 60); |
222 | 225 | $_REQUEST['holiday'] = isset($_REQUEST['holiday']) ? (int) $_REQUEST['holiday'] : 0; |
223 | 226 | |
224 | - if (isset($_REQUEST['delete'])) |
|
225 | - $smcFunc['db_query']('', ' |
|
227 | + if (isset($_REQUEST['delete'])) { |
|
228 | + $smcFunc['db_query']('', ' |
|
226 | 229 | DELETE FROM {db_prefix}calendar_holidays |
227 | 230 | WHERE id_holiday = {int:selected_holiday}', |
228 | 231 | array( |
229 | 232 | 'selected_holiday' => $_REQUEST['holiday'], |
230 | 233 | ) |
231 | 234 | ); |
232 | - else |
|
235 | + } else |
|
233 | 236 | { |
234 | 237 | $date = strftime($_REQUEST['year'] <= 1004 ? '1004-%m-%d' : '%Y-%m-%d', mktime(0, 0, 0, $_REQUEST['month'], $_REQUEST['day'], $_REQUEST['year'])); |
235 | - if (isset($_REQUEST['edit'])) |
|
236 | - $smcFunc['db_query']('', ' |
|
238 | + if (isset($_REQUEST['edit'])) { |
|
239 | + $smcFunc['db_query']('', ' |
|
237 | 240 | UPDATE {db_prefix}calendar_holidays |
238 | 241 | SET event_date = {date:holiday_date}, title = {string:holiday_title} |
239 | 242 | WHERE id_holiday = {int:selected_holiday}', |
@@ -243,8 +246,8 @@ discard block |
||
243 | 246 | 'holiday_title' => $_REQUEST['title'], |
244 | 247 | ) |
245 | 248 | ); |
246 | - else |
|
247 | - $smcFunc['db_insert']('', |
|
249 | + } else { |
|
250 | + $smcFunc['db_insert']('', |
|
248 | 251 | '{db_prefix}calendar_holidays', |
249 | 252 | array( |
250 | 253 | 'event_date' => 'date', 'title' => 'string-60', |
@@ -254,6 +257,7 @@ discard block |
||
254 | 257 | ), |
255 | 258 | array('id_holiday') |
256 | 259 | ); |
260 | + } |
|
257 | 261 | } |
258 | 262 | |
259 | 263 | updateSettings(array( |
@@ -265,14 +269,15 @@ discard block |
||
265 | 269 | } |
266 | 270 | |
267 | 271 | // Default states... |
268 | - if ($context['is_new']) |
|
269 | - $context['holiday'] = array( |
|
272 | + if ($context['is_new']) { |
|
273 | + $context['holiday'] = array( |
|
270 | 274 | 'id' => 0, |
271 | 275 | 'day' => date('d'), |
272 | 276 | 'month' => date('m'), |
273 | 277 | 'year' => '0000', |
274 | 278 | 'title' => '' |
275 | 279 | ); |
280 | + } |
|
276 | 281 | // If it's not new load the data. |
277 | 282 | else |
278 | 283 | { |
@@ -285,14 +290,15 @@ discard block |
||
285 | 290 | 'selected_holiday' => $_REQUEST['holiday'], |
286 | 291 | ) |
287 | 292 | ); |
288 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
289 | - $context['holiday'] = array( |
|
293 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
294 | + $context['holiday'] = array( |
|
290 | 295 | 'id' => $row['id_holiday'], |
291 | 296 | 'day' => $row['day'], |
292 | 297 | 'month' => $row['month'], |
293 | 298 | 'year' => $row['year'] <= 4 ? 0 : $row['year'], |
294 | 299 | 'title' => $row['title'] |
295 | 300 | ); |
301 | + } |
|
296 | 302 | $smcFunc['db_free_result']($request); |
297 | 303 | } |
298 | 304 | |
@@ -319,16 +325,17 @@ discard block |
||
319 | 325 | array( |
320 | 326 | ) |
321 | 327 | ); |
322 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
323 | - $boards[$row['id_board']] = $row['cat_name'] . ' - ' . $row['board_name']; |
|
328 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
329 | + $boards[$row['id_board']] = $row['cat_name'] . ' - ' . $row['board_name']; |
|
330 | + } |
|
324 | 331 | $smcFunc['db_free_result']($request); |
325 | 332 | |
326 | 333 | require_once($sourcedir . '/Subs-Boards.php'); |
327 | 334 | sortBoards($boards); |
328 | 335 | |
329 | 336 | // Look, all the calendar settings - of which there are many! |
330 | - if (!empty($modSettings['cal_enabled'])) |
|
331 | - $config_vars = array( |
|
337 | + if (!empty($modSettings['cal_enabled'])) { |
|
338 | + $config_vars = array( |
|
332 | 339 | array('check', 'cal_enabled'), |
333 | 340 | '', |
334 | 341 | // All the permissions: |
@@ -371,14 +378,16 @@ discard block |
||
371 | 378 | array('check', 'cal_short_days'), |
372 | 379 | array('check', 'cal_short_months'), |
373 | 380 | ); |
374 | - else |
|
375 | - $config_vars = array( |
|
381 | + } else { |
|
382 | + $config_vars = array( |
|
376 | 383 | array('check', 'cal_enabled'), |
377 | 384 | ); |
385 | + } |
|
378 | 386 | |
379 | 387 | call_integration_hook('integrate_modify_calendar_settings', array(&$config_vars)); |
380 | - if ($return_config) |
|
381 | - return $config_vars; |
|
388 | + if ($return_config) { |
|
389 | + return $config_vars; |
|
390 | + } |
|
382 | 391 | |
383 | 392 | // Get the settings template fired up. |
384 | 393 | require_once($sourcedir . '/ManageServer.php'); |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | /** |
82 | 82 | * Make files writable. First try to use regular chmod, but if that fails, try to use FTP. |
83 | 83 | * |
84 | - * @param $files |
|
84 | + * @param string[] $files |
|
85 | 85 | * @return bool |
86 | 86 | */ |
87 | 87 | function makeFilesWritable(&$files) |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | /** |
323 | 323 | * Prints an error to stderr. |
324 | 324 | * |
325 | - * @param $message |
|
325 | + * @param string $message |
|
326 | 326 | * @param bool $fatal |
327 | 327 | */ |
328 | 328 | function print_error($message, $fatal = false) |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * This file contains helper functions for upgrade.php |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF_VERSION')) |
|
16 | +if (!defined('SMF_VERSION')) { |
|
17 | 17 | die('No direct access!'); |
18 | +} |
|
18 | 19 | |
19 | 20 | /** |
20 | 21 | * Clean the cache using the SMF 2.1 CacheAPI. |
@@ -45,8 +46,9 @@ discard block |
||
45 | 46 | global $smcFunc; |
46 | 47 | static $member_groups = array(); |
47 | 48 | |
48 | - if (!empty($member_groups)) |
|
49 | - return $member_groups; |
|
49 | + if (!empty($member_groups)) { |
|
50 | + return $member_groups; |
|
51 | + } |
|
50 | 52 | |
51 | 53 | $request = $smcFunc['db_query']('', ' |
52 | 54 | SELECT group_name, id_group |
@@ -71,8 +73,9 @@ discard block |
||
71 | 73 | ) |
72 | 74 | ); |
73 | 75 | } |
74 | - while ($row = $smcFunc['db_fetch_row']($request)) |
|
75 | - $member_groups[trim($row[0])] = $row[1]; |
|
76 | + while ($row = $smcFunc['db_fetch_row']($request)) { |
|
77 | + $member_groups[trim($row[0])] = $row[1]; |
|
78 | + } |
|
76 | 79 | $smcFunc['db_free_result']($request); |
77 | 80 | |
78 | 81 | return $member_groups; |
@@ -88,8 +91,9 @@ discard block |
||
88 | 91 | { |
89 | 92 | global $upcontext, $boarddir, $sourcedir; |
90 | 93 | |
91 | - if (empty($files)) |
|
92 | - return true; |
|
94 | + if (empty($files)) { |
|
95 | + return true; |
|
96 | + } |
|
93 | 97 | |
94 | 98 | $failure = false; |
95 | 99 | // On linux, it's easy - just use is_writable! |
@@ -100,22 +104,25 @@ discard block |
||
100 | 104 | foreach ($files as $k => $file) |
101 | 105 | { |
102 | 106 | // Some files won't exist, try to address up front |
103 | - if (!file_exists($file)) |
|
104 | - @touch($file); |
|
107 | + if (!file_exists($file)) { |
|
108 | + @touch($file); |
|
109 | + } |
|
105 | 110 | // NOW do the writable check... |
106 | 111 | if (!is_writable($file)) |
107 | 112 | { |
108 | 113 | @chmod($file, 0755); |
109 | 114 | |
110 | 115 | // Well, 755 hopefully worked... if not, try 777. |
111 | - if (!is_writable($file) && !@chmod($file, 0777)) |
|
112 | - $failure = true; |
|
116 | + if (!is_writable($file) && !@chmod($file, 0777)) { |
|
117 | + $failure = true; |
|
118 | + } |
|
113 | 119 | // Otherwise remove it as it's good! |
114 | - else |
|
115 | - unset($files[$k]); |
|
120 | + else { |
|
121 | + unset($files[$k]); |
|
122 | + } |
|
123 | + } else { |
|
124 | + unset($files[$k]); |
|
116 | 125 | } |
117 | - else |
|
118 | - unset($files[$k]); |
|
119 | 126 | } |
120 | 127 | } |
121 | 128 | // Windows is trickier. Let's try opening for r+... |
@@ -126,30 +133,35 @@ discard block |
||
126 | 133 | foreach ($files as $k => $file) |
127 | 134 | { |
128 | 135 | // Folders can't be opened for write... but the index.php in them can ;). |
129 | - if (is_dir($file)) |
|
130 | - $file .= '/index.php'; |
|
136 | + if (is_dir($file)) { |
|
137 | + $file .= '/index.php'; |
|
138 | + } |
|
131 | 139 | |
132 | 140 | // Funny enough, chmod actually does do something on windows - it removes the read only attribute. |
133 | 141 | @chmod($file, 0777); |
134 | 142 | $fp = @fopen($file, 'r+'); |
135 | 143 | |
136 | 144 | // Hmm, okay, try just for write in that case... |
137 | - if (!$fp) |
|
138 | - $fp = @fopen($file, 'w'); |
|
145 | + if (!$fp) { |
|
146 | + $fp = @fopen($file, 'w'); |
|
147 | + } |
|
139 | 148 | |
140 | - if (!$fp) |
|
141 | - $failure = true; |
|
142 | - else |
|
143 | - unset($files[$k]); |
|
149 | + if (!$fp) { |
|
150 | + $failure = true; |
|
151 | + } else { |
|
152 | + unset($files[$k]); |
|
153 | + } |
|
144 | 154 | @fclose($fp); |
145 | 155 | } |
146 | 156 | } |
147 | 157 | |
148 | - if (empty($files)) |
|
149 | - return true; |
|
158 | + if (empty($files)) { |
|
159 | + return true; |
|
160 | + } |
|
150 | 161 | |
151 | - if (!isset($_SERVER)) |
|
152 | - return !$failure; |
|
162 | + if (!isset($_SERVER)) { |
|
163 | + return !$failure; |
|
164 | + } |
|
153 | 165 | |
154 | 166 | // What still needs to be done? |
155 | 167 | $upcontext['chmod']['files'] = $files; |
@@ -201,36 +213,40 @@ discard block |
||
201 | 213 | |
202 | 214 | if (!isset($ftp) || $ftp->error !== false) |
203 | 215 | { |
204 | - if (!isset($ftp)) |
|
205 | - $ftp = new ftp_connection(null); |
|
216 | + if (!isset($ftp)) { |
|
217 | + $ftp = new ftp_connection(null); |
|
218 | + } |
|
206 | 219 | // Save the error so we can mess with listing... |
207 | - elseif ($ftp->error !== false && !isset($upcontext['chmod']['ftp_error'])) |
|
208 | - $upcontext['chmod']['ftp_error'] = $ftp->last_message === null ? '' : $ftp->last_message; |
|
220 | + elseif ($ftp->error !== false && !isset($upcontext['chmod']['ftp_error'])) { |
|
221 | + $upcontext['chmod']['ftp_error'] = $ftp->last_message === null ? '' : $ftp->last_message; |
|
222 | + } |
|
209 | 223 | |
210 | 224 | list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__)); |
211 | 225 | |
212 | - if ($found_path || !isset($upcontext['chmod']['path'])) |
|
213 | - $upcontext['chmod']['path'] = $detect_path; |
|
226 | + if ($found_path || !isset($upcontext['chmod']['path'])) { |
|
227 | + $upcontext['chmod']['path'] = $detect_path; |
|
228 | + } |
|
214 | 229 | |
215 | - if (!isset($upcontext['chmod']['username'])) |
|
216 | - $upcontext['chmod']['username'] = $username; |
|
230 | + if (!isset($upcontext['chmod']['username'])) { |
|
231 | + $upcontext['chmod']['username'] = $username; |
|
232 | + } |
|
217 | 233 | |
218 | 234 | // Don't forget the login token. |
219 | 235 | $upcontext += createToken('login'); |
220 | 236 | |
221 | 237 | return false; |
222 | - } |
|
223 | - else |
|
238 | + } else |
|
224 | 239 | { |
225 | 240 | // We want to do a relative path for FTP. |
226 | 241 | if (!in_array($upcontext['chmod']['path'], array('', '/'))) |
227 | 242 | { |
228 | 243 | $ftp_root = strtr($boarddir, array($upcontext['chmod']['path'] => '')); |
229 | - if (substr($ftp_root, -1) == '/' && ($upcontext['chmod']['path'] == '' || $upcontext['chmod']['path'][0] === '/')) |
|
230 | - $ftp_root = substr($ftp_root, 0, -1); |
|
244 | + if (substr($ftp_root, -1) == '/' && ($upcontext['chmod']['path'] == '' || $upcontext['chmod']['path'][0] === '/')) { |
|
245 | + $ftp_root = substr($ftp_root, 0, -1); |
|
246 | + } |
|
247 | + } else { |
|
248 | + $ftp_root = $boarddir; |
|
231 | 249 | } |
232 | - else |
|
233 | - $ftp_root = $boarddir; |
|
234 | 250 | |
235 | 251 | // Save the info for next time! |
236 | 252 | $_SESSION['installer_temp_ftp'] = array( |
@@ -244,10 +260,12 @@ discard block |
||
244 | 260 | |
245 | 261 | foreach ($files as $k => $file) |
246 | 262 | { |
247 | - if (!is_writable($file)) |
|
248 | - $ftp->chmod($file, 0755); |
|
249 | - if (!is_writable($file)) |
|
250 | - $ftp->chmod($file, 0777); |
|
263 | + if (!is_writable($file)) { |
|
264 | + $ftp->chmod($file, 0755); |
|
265 | + } |
|
266 | + if (!is_writable($file)) { |
|
267 | + $ftp->chmod($file, 0777); |
|
268 | + } |
|
251 | 269 | |
252 | 270 | // Assuming that didn't work calculate the path without the boarddir. |
253 | 271 | if (!is_writable($file)) |
@@ -256,19 +274,23 @@ discard block |
||
256 | 274 | { |
257 | 275 | $ftp_file = strtr($file, array($_SESSION['installer_temp_ftp']['root'] => '')); |
258 | 276 | $ftp->chmod($ftp_file, 0755); |
259 | - if (!is_writable($file)) |
|
260 | - $ftp->chmod($ftp_file, 0777); |
|
277 | + if (!is_writable($file)) { |
|
278 | + $ftp->chmod($ftp_file, 0777); |
|
279 | + } |
|
261 | 280 | // Sometimes an extra slash can help... |
262 | 281 | $ftp_file = '/' . $ftp_file; |
263 | - if (!is_writable($file)) |
|
264 | - $ftp->chmod($ftp_file, 0755); |
|
265 | - if (!is_writable($file)) |
|
266 | - $ftp->chmod($ftp_file, 0777); |
|
282 | + if (!is_writable($file)) { |
|
283 | + $ftp->chmod($ftp_file, 0755); |
|
284 | + } |
|
285 | + if (!is_writable($file)) { |
|
286 | + $ftp->chmod($ftp_file, 0777); |
|
287 | + } |
|
267 | 288 | } |
268 | 289 | } |
269 | 290 | |
270 | - if (is_writable($file)) |
|
271 | - unset($files[$k]); |
|
291 | + if (is_writable($file)) { |
|
292 | + unset($files[$k]); |
|
293 | + } |
|
272 | 294 | } |
273 | 295 | |
274 | 296 | $ftp->close(); |
@@ -278,8 +300,9 @@ discard block |
||
278 | 300 | // What remains? |
279 | 301 | $upcontext['chmod']['files'] = $files; |
280 | 302 | |
281 | - if (empty($files)) |
|
282 | - return true; |
|
303 | + if (empty($files)) { |
|
304 | + return true; |
|
305 | + } |
|
283 | 306 | |
284 | 307 | return false; |
285 | 308 | } |
@@ -294,12 +317,14 @@ discard block |
||
294 | 317 | { |
295 | 318 | |
296 | 319 | // Some files won't exist, try to address up front |
297 | - if (!file_exists($file)) |
|
298 | - @touch($file); |
|
320 | + if (!file_exists($file)) { |
|
321 | + @touch($file); |
|
322 | + } |
|
299 | 323 | |
300 | 324 | // NOW do the writable check... |
301 | - if (is_writable($file)) |
|
302 | - return true; |
|
325 | + if (is_writable($file)) { |
|
326 | + return true; |
|
327 | + } |
|
303 | 328 | |
304 | 329 | @chmod($file, 0755); |
305 | 330 | |
@@ -309,10 +334,11 @@ discard block |
||
309 | 334 | foreach ($chmod_values as $val) |
310 | 335 | { |
311 | 336 | // If it's writable, break out of the loop |
312 | - if (is_writable($file)) |
|
313 | - break; |
|
314 | - else |
|
315 | - @chmod($file, $val); |
|
337 | + if (is_writable($file)) { |
|
338 | + break; |
|
339 | + } else { |
|
340 | + @chmod($file, $val); |
|
341 | + } |
|
316 | 342 | } |
317 | 343 | |
318 | 344 | return is_writable($file); |
@@ -339,14 +365,16 @@ discard block |
||
339 | 365 | { |
340 | 366 | static $fp = null; |
341 | 367 | |
342 | - if ($fp === null) |
|
343 | - $fp = fopen('php://stderr', 'wb'); |
|
368 | + if ($fp === null) { |
|
369 | + $fp = fopen('php://stderr', 'wb'); |
|
370 | + } |
|
344 | 371 | |
345 | 372 | fwrite($fp, $message . "\n"); |
346 | 373 | |
347 | - if ($fatal) |
|
348 | - exit; |
|
349 | -} |
|
374 | + if ($fatal) { |
|
375 | + exit; |
|
376 | + } |
|
377 | + } |
|
350 | 378 | |
351 | 379 | /** |
352 | 380 | * Throws a graphical error message. |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 4 |
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 | * Get all birthdays within the given time range. |
@@ -60,8 +61,7 @@ discard block |
||
60 | 61 | 'max_year' => $year_high, |
61 | 62 | ) |
62 | 63 | ); |
63 | - } |
|
64 | - else |
|
64 | + } else |
|
65 | 65 | { |
66 | 66 | $result = $smcFunc['db_query']('birthday_array', ' |
67 | 67 | SELECT id_member, real_name, YEAR(birthdate) AS birth_year, birthdate |
@@ -91,10 +91,11 @@ discard block |
||
91 | 91 | $bday = array(); |
92 | 92 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
93 | 93 | { |
94 | - if ($year_low != $year_high) |
|
95 | - $age_year = substr($row['birthdate'], 5) < substr($high_date, 5) ? $year_high : $year_low; |
|
96 | - else |
|
97 | - $age_year = $year_low; |
|
94 | + if ($year_low != $year_high) { |
|
95 | + $age_year = substr($row['birthdate'], 5) < substr($high_date, 5) ? $year_high : $year_low; |
|
96 | + } else { |
|
97 | + $age_year = $year_low; |
|
98 | + } |
|
98 | 99 | |
99 | 100 | $bday[$age_year . substr($row['birthdate'], 4)][] = array( |
100 | 101 | 'id' => $row['id_member'], |
@@ -108,8 +109,9 @@ discard block |
||
108 | 109 | ksort($bday); |
109 | 110 | |
110 | 111 | // Set is_last, so the themes know when to stop placing separators. |
111 | - foreach ($bday as $mday => $array) |
|
112 | - $bday[$mday][count($array) - 1]['is_last'] = true; |
|
112 | + foreach ($bday as $mday => $array) { |
|
113 | + $bday[$mday][count($array) - 1]['is_last'] = true; |
|
114 | + } |
|
113 | 115 | |
114 | 116 | return $bday; |
115 | 117 | } |
@@ -157,8 +159,9 @@ discard block |
||
157 | 159 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
158 | 160 | { |
159 | 161 | // If the attached topic is not approved then for the moment pretend it doesn't exist |
160 | - if (!empty($row['id_first_msg']) && $modSettings['postmod_active'] && !$row['approved']) |
|
161 | - continue; |
|
162 | + if (!empty($row['id_first_msg']) && $modSettings['postmod_active'] && !$row['approved']) { |
|
163 | + continue; |
|
164 | + } |
|
162 | 165 | |
163 | 166 | // Force a censor of the title - as often these are used by others. |
164 | 167 | censorText($row['title'], $use_permissions ? false : true); |
@@ -167,8 +170,9 @@ discard block |
||
167 | 170 | list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row); |
168 | 171 | |
169 | 172 | // Sanity check |
170 | - if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) |
|
171 | - continue; |
|
173 | + if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) { |
|
174 | + continue; |
|
175 | + } |
|
172 | 176 | |
173 | 177 | // Get set up for the loop |
174 | 178 | $start_object = date_create($row['start_date'] . (!$allday ? ' ' . $row['start_time'] : ''), timezone_open($tz)); |
@@ -232,8 +236,8 @@ discard block |
||
232 | 236 | ); |
233 | 237 | |
234 | 238 | // If we're using permissions (calendar pages?) then just ouput normal contextual style information. |
235 | - if ($use_permissions) |
|
236 | - $events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array( |
|
239 | + if ($use_permissions) { |
|
240 | + $events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array( |
|
237 | 241 | 'href' => $row['id_board'] == 0 ? '' : $scripturl . '?topic=' . $row['id_topic'] . '.0', |
238 | 242 | 'link' => $row['id_board'] == 0 ? $row['title'] : '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['title'] . '</a>', |
239 | 243 | 'can_edit' => allowedTo('calendar_edit_any') || ($row['id_member'] == $user_info['id'] && allowedTo('calendar_edit_own')), |
@@ -241,9 +245,10 @@ discard block |
||
241 | 245 | 'can_export' => !empty($modSettings['cal_export']) ? true : false, |
242 | 246 | 'export_href' => $scripturl . '?action=calendar;sa=ical;eventid=' . $row['id_event'] . ';' . $context['session_var'] . '=' . $context['session_id'], |
243 | 247 | )); |
248 | + } |
|
244 | 249 | // Otherwise, this is going to be cached and the VIEWER'S permissions should apply... just put together some info. |
245 | - else |
|
246 | - $events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array( |
|
250 | + else { |
|
251 | + $events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array( |
|
247 | 252 | 'href' => $row['id_topic'] == 0 ? '' : $scripturl . '?topic=' . $row['id_topic'] . '.0', |
248 | 253 | 'link' => $row['id_topic'] == 0 ? $row['title'] : '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['title'] . '</a>', |
249 | 254 | 'can_edit' => false, |
@@ -253,6 +258,7 @@ discard block |
||
253 | 258 | 'poster' => $row['id_member'], |
254 | 259 | 'allowed_groups' => explode(',', $row['member_groups']), |
255 | 260 | )); |
261 | + } |
|
256 | 262 | |
257 | 263 | date_add($cal_date, date_interval_create_from_date_string('1 day')); |
258 | 264 | } |
@@ -262,8 +268,9 @@ discard block |
||
262 | 268 | // If we're doing normal contextual data, go through and make things clear to the templates ;). |
263 | 269 | if ($use_permissions) |
264 | 270 | { |
265 | - foreach ($events as $mday => $array) |
|
266 | - $events[$mday][count($array) - 1]['is_last'] = true; |
|
271 | + foreach ($events as $mday => $array) { |
|
272 | + $events[$mday][count($array) - 1]['is_last'] = true; |
|
273 | + } |
|
267 | 274 | } |
268 | 275 | |
269 | 276 | ksort($events); |
@@ -283,11 +290,12 @@ discard block |
||
283 | 290 | global $smcFunc; |
284 | 291 | |
285 | 292 | // Get the lowest and highest dates for "all years". |
286 | - if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) |
|
287 | - $allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_dec} |
|
293 | + if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) { |
|
294 | + $allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_dec} |
|
288 | 295 | OR event_date BETWEEN {date:all_year_jan} AND {date:all_year_high}'; |
289 | - else |
|
290 | - $allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_high}'; |
|
296 | + } else { |
|
297 | + $allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_high}'; |
|
298 | + } |
|
291 | 299 | |
292 | 300 | // Find some holidays... ;). |
293 | 301 | $result = $smcFunc['db_query']('', ' |
@@ -307,10 +315,11 @@ discard block |
||
307 | 315 | $holidays = array(); |
308 | 316 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
309 | 317 | { |
310 | - if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) |
|
311 | - $event_year = substr($row['event_date'], 5) < substr($high_date, 5) ? substr($high_date, 0, 4) : substr($low_date, 0, 4); |
|
312 | - else |
|
313 | - $event_year = substr($low_date, 0, 4); |
|
318 | + if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) { |
|
319 | + $event_year = substr($row['event_date'], 5) < substr($high_date, 5) ? substr($high_date, 0, 4) : substr($low_date, 0, 4); |
|
320 | + } else { |
|
321 | + $event_year = substr($low_date, 0, 4); |
|
322 | + } |
|
314 | 323 | |
315 | 324 | $holidays[$event_year . substr($row['event_date'], 4)][] = $row['title']; |
316 | 325 | } |
@@ -336,10 +345,12 @@ discard block |
||
336 | 345 | isAllowedTo('calendar_post'); |
337 | 346 | |
338 | 347 | // No board? No topic?!? |
339 | - if (empty($board)) |
|
340 | - fatal_lang_error('missing_board_id', false); |
|
341 | - if (empty($topic)) |
|
342 | - fatal_lang_error('missing_topic_id', false); |
|
348 | + if (empty($board)) { |
|
349 | + fatal_lang_error('missing_board_id', false); |
|
350 | + } |
|
351 | + if (empty($topic)) { |
|
352 | + fatal_lang_error('missing_topic_id', false); |
|
353 | + } |
|
343 | 354 | |
344 | 355 | // Administrator, Moderator, or owner. Period. |
345 | 356 | if (!allowedTo('admin_forum') && !allowedTo('moderate_board')) |
@@ -357,12 +368,14 @@ discard block |
||
357 | 368 | if ($row = $smcFunc['db_fetch_assoc']($result)) |
358 | 369 | { |
359 | 370 | // Not the owner of the topic. |
360 | - if ($row['id_member_started'] != $user_info['id']) |
|
361 | - fatal_lang_error('not_your_topic', 'user'); |
|
371 | + if ($row['id_member_started'] != $user_info['id']) { |
|
372 | + fatal_lang_error('not_your_topic', 'user'); |
|
373 | + } |
|
362 | 374 | } |
363 | 375 | // Topic/Board doesn't exist..... |
364 | - else |
|
365 | - fatal_lang_error('calendar_no_topic', 'general'); |
|
376 | + else { |
|
377 | + fatal_lang_error('calendar_no_topic', 'general'); |
|
378 | + } |
|
366 | 379 | $smcFunc['db_free_result']($result); |
367 | 380 | } |
368 | 381 | } |
@@ -450,14 +463,16 @@ discard block |
||
450 | 463 | if (!empty($calendarOptions['start_day'])) |
451 | 464 | { |
452 | 465 | $nShift -= $calendarOptions['start_day']; |
453 | - if ($nShift < 0) |
|
454 | - $nShift = 7 + $nShift; |
|
466 | + if ($nShift < 0) { |
|
467 | + $nShift = 7 + $nShift; |
|
468 | + } |
|
455 | 469 | } |
456 | 470 | |
457 | 471 | // Number of rows required to fit the month. |
458 | 472 | $nRows = floor(($month_info['last_day']['day_of_month'] + $nShift) / 7); |
459 | - if (($month_info['last_day']['day_of_month'] + $nShift) % 7) |
|
460 | - $nRows++; |
|
473 | + if (($month_info['last_day']['day_of_month'] + $nShift) % 7) { |
|
474 | + $nRows++; |
|
475 | + } |
|
461 | 476 | |
462 | 477 | // Fetch the arrays for birthdays, posted events, and holidays. |
463 | 478 | $bday = $calendarOptions['show_birthdays'] ? getBirthdayRange($month_info['first_day']['date'], $month_info['last_day']['date']) : array(); |
@@ -470,8 +485,9 @@ discard block |
||
470 | 485 | { |
471 | 486 | $calendarGrid['week_days'][] = $count; |
472 | 487 | $count++; |
473 | - if ($count == 7) |
|
474 | - $count = 0; |
|
488 | + if ($count == 7) { |
|
489 | + $count = 0; |
|
490 | + } |
|
475 | 491 | } |
476 | 492 | |
477 | 493 | // Iterate through each week. |
@@ -488,8 +504,9 @@ discard block |
||
488 | 504 | { |
489 | 505 | $nDay = ($nRow * 7) + $nCol - $nShift + 1; |
490 | 506 | |
491 | - if ($nDay < 1 || $nDay > $month_info['last_day']['day_of_month']) |
|
492 | - $nDay = 0; |
|
507 | + if ($nDay < 1 || $nDay > $month_info['last_day']['day_of_month']) { |
|
508 | + $nDay = 0; |
|
509 | + } |
|
493 | 510 | |
494 | 511 | $date = sprintf('%04d-%02d-%02d', $year, $month, $nDay); |
495 | 512 | |
@@ -507,8 +524,9 @@ discard block |
||
507 | 524 | } |
508 | 525 | |
509 | 526 | // What is the last day of the month? |
510 | - if ($is_previous === true) |
|
511 | - $calendarGrid['last_of_month'] = $month_info['last_day']['day_of_month']; |
|
527 | + if ($is_previous === true) { |
|
528 | + $calendarGrid['last_of_month'] = $month_info['last_day']['day_of_month']; |
|
529 | + } |
|
512 | 530 | |
513 | 531 | // We'll use the shift in the template. |
514 | 532 | $calendarGrid['shift'] = $nShift; |
@@ -542,8 +560,9 @@ discard block |
||
542 | 560 | { |
543 | 561 | // Here we offset accordingly to get things to the real start of a week. |
544 | 562 | $date_diff = $day_of_week - $calendarOptions['start_day']; |
545 | - if ($date_diff < 0) |
|
546 | - $date_diff += 7; |
|
563 | + if ($date_diff < 0) { |
|
564 | + $date_diff += 7; |
|
565 | + } |
|
547 | 566 | $new_timestamp = mktime(0, 0, 0, $month, $day, $year) - $date_diff * 86400; |
548 | 567 | $day = (int) strftime('%d', $new_timestamp); |
549 | 568 | $month = (int) strftime('%m', $new_timestamp); |
@@ -673,18 +692,20 @@ discard block |
||
673 | 692 | { |
674 | 693 | foreach ($date_events as $event_key => $event_val) |
675 | 694 | { |
676 | - if (in_array($event_val['id'], $temp)) |
|
677 | - unset($calendarGrid['events'][$date][$event_key]); |
|
678 | - else |
|
679 | - $temp[] = $event_val['id']; |
|
695 | + if (in_array($event_val['id'], $temp)) { |
|
696 | + unset($calendarGrid['events'][$date][$event_key]); |
|
697 | + } else { |
|
698 | + $temp[] = $event_val['id']; |
|
699 | + } |
|
680 | 700 | } |
681 | 701 | } |
682 | 702 | |
683 | 703 | // Give birthdays and holidays a friendly format, without the year |
684 | - if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) |
|
685 | - $date_format = '%b %d'; |
|
686 | - else |
|
687 | - $date_format = str_replace(array('%Y', '%y', '%G', '%g', '%C', '%c', '%D'), array('', '', '', '', '', '%b %d', '%m/%d'), $matches[0]); |
|
704 | + if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) { |
|
705 | + $date_format = '%b %d'; |
|
706 | + } else { |
|
707 | + $date_format = str_replace(array('%Y', '%y', '%G', '%g', '%C', '%c', '%D'), array('', '', '', '', '', '%b %d', '%m/%d'), $matches[0]); |
|
708 | + } |
|
688 | 709 | |
689 | 710 | foreach (array('birthdays', 'holidays') as $type) |
690 | 711 | { |
@@ -779,8 +800,9 @@ discard block |
||
779 | 800 | // Holidays between now and now + days. |
780 | 801 | for ($i = $now; $i < $now + $days_for_index; $i += 86400) |
781 | 802 | { |
782 | - if (isset($cached_data['holidays'][strftime('%Y-%m-%d', $i)])) |
|
783 | - $return_data['calendar_holidays'] = array_merge($return_data['calendar_holidays'], $cached_data['holidays'][strftime('%Y-%m-%d', $i)]); |
|
803 | + if (isset($cached_data['holidays'][strftime('%Y-%m-%d', $i)])) { |
|
804 | + $return_data['calendar_holidays'] = array_merge($return_data['calendar_holidays'], $cached_data['holidays'][strftime('%Y-%m-%d', $i)]); |
|
805 | + } |
|
784 | 806 | } |
785 | 807 | |
786 | 808 | // Happy Birthday, guys and gals! |
@@ -789,8 +811,9 @@ discard block |
||
789 | 811 | $loop_date = strftime('%Y-%m-%d', $i); |
790 | 812 | if (isset($cached_data['birthdays'][$loop_date])) |
791 | 813 | { |
792 | - foreach ($cached_data['birthdays'][$loop_date] as $index => $dummy) |
|
793 | - $cached_data['birthdays'][strftime('%Y-%m-%d', $i)][$index]['is_today'] = $loop_date === $today['date']; |
|
814 | + foreach ($cached_data['birthdays'][$loop_date] as $index => $dummy) { |
|
815 | + $cached_data['birthdays'][strftime('%Y-%m-%d', $i)][$index]['is_today'] = $loop_date === $today['date']; |
|
816 | + } |
|
794 | 817 | $return_data['calendar_birthdays'] = array_merge($return_data['calendar_birthdays'], $cached_data['birthdays'][$loop_date]); |
795 | 818 | } |
796 | 819 | } |
@@ -802,8 +825,9 @@ discard block |
||
802 | 825 | $loop_date = strftime('%Y-%m-%d', $i); |
803 | 826 | |
804 | 827 | // No events today? Check the next day. |
805 | - if (empty($cached_data['events'][$loop_date])) |
|
806 | - continue; |
|
828 | + if (empty($cached_data['events'][$loop_date])) { |
|
829 | + continue; |
|
830 | + } |
|
807 | 831 | |
808 | 832 | // Loop through all events to add a few last-minute values. |
809 | 833 | foreach ($cached_data['events'][$loop_date] as $ev => $event) |
@@ -816,9 +840,9 @@ discard block |
||
816 | 840 | { |
817 | 841 | unset($cached_data['events'][$loop_date][$ev]); |
818 | 842 | continue; |
843 | + } else { |
|
844 | + $duplicates[$this_event['topic'] . $this_event['title']] = true; |
|
819 | 845 | } |
820 | - else |
|
821 | - $duplicates[$this_event['topic'] . $this_event['title']] = true; |
|
822 | 846 | |
823 | 847 | // Might be set to true afterwards, depending on the permissions. |
824 | 848 | $this_event['can_edit'] = false; |
@@ -826,15 +850,18 @@ discard block |
||
826 | 850 | $this_event['date'] = $loop_date; |
827 | 851 | } |
828 | 852 | |
829 | - if (!empty($cached_data['events'][$loop_date])) |
|
830 | - $return_data['calendar_events'] = array_merge($return_data['calendar_events'], $cached_data['events'][$loop_date]); |
|
853 | + if (!empty($cached_data['events'][$loop_date])) { |
|
854 | + $return_data['calendar_events'] = array_merge($return_data['calendar_events'], $cached_data['events'][$loop_date]); |
|
855 | + } |
|
831 | 856 | } |
832 | 857 | |
833 | 858 | // Mark the last item so that a list separator can be used in the template. |
834 | - for ($i = 0, $n = count($return_data['calendar_birthdays']); $i < $n; $i++) |
|
835 | - $return_data['calendar_birthdays'][$i]['is_last'] = !isset($return_data['calendar_birthdays'][$i + 1]); |
|
836 | - for ($i = 0, $n = count($return_data['calendar_events']); $i < $n; $i++) |
|
837 | - $return_data['calendar_events'][$i]['is_last'] = !isset($return_data['calendar_events'][$i + 1]); |
|
859 | + for ($i = 0, $n = count($return_data['calendar_birthdays']); $i < $n; $i++) { |
|
860 | + $return_data['calendar_birthdays'][$i]['is_last'] = !isset($return_data['calendar_birthdays'][$i + 1]); |
|
861 | + } |
|
862 | + for ($i = 0, $n = count($return_data['calendar_events']); $i < $n; $i++) { |
|
863 | + $return_data['calendar_events'][$i]['is_last'] = !isset($return_data['calendar_events'][$i + 1]); |
|
864 | + } |
|
838 | 865 | |
839 | 866 | return array( |
840 | 867 | 'data' => $return_data, |
@@ -882,37 +909,46 @@ discard block |
||
882 | 909 | if (isset($_POST['start_date'])) |
883 | 910 | { |
884 | 911 | $d = date_parse($_POST['start_date']); |
885 | - if (!empty($d['error_count']) || !empty($d['warning_count'])) |
|
886 | - fatal_lang_error('invalid_date', false); |
|
887 | - if (empty($d['year'])) |
|
888 | - fatal_lang_error('event_year_missing', false); |
|
889 | - if (empty($d['month'])) |
|
890 | - fatal_lang_error('event_month_missing', false); |
|
891 | - } |
|
892 | - elseif (isset($_POST['start_datetime'])) |
|
912 | + if (!empty($d['error_count']) || !empty($d['warning_count'])) { |
|
913 | + fatal_lang_error('invalid_date', false); |
|
914 | + } |
|
915 | + if (empty($d['year'])) { |
|
916 | + fatal_lang_error('event_year_missing', false); |
|
917 | + } |
|
918 | + if (empty($d['month'])) { |
|
919 | + fatal_lang_error('event_month_missing', false); |
|
920 | + } |
|
921 | + } elseif (isset($_POST['start_datetime'])) |
|
893 | 922 | { |
894 | 923 | $d = date_parse($_POST['start_datetime']); |
895 | - if (!empty($d['error_count']) || !empty($d['warning_count'])) |
|
896 | - fatal_lang_error('invalid_date', false); |
|
897 | - if (empty($d['year'])) |
|
898 | - fatal_lang_error('event_year_missing', false); |
|
899 | - if (empty($d['month'])) |
|
900 | - fatal_lang_error('event_month_missing', false); |
|
924 | + if (!empty($d['error_count']) || !empty($d['warning_count'])) { |
|
925 | + fatal_lang_error('invalid_date', false); |
|
926 | + } |
|
927 | + if (empty($d['year'])) { |
|
928 | + fatal_lang_error('event_year_missing', false); |
|
929 | + } |
|
930 | + if (empty($d['month'])) { |
|
931 | + fatal_lang_error('event_month_missing', false); |
|
932 | + } |
|
901 | 933 | } |
902 | 934 | // The 2.0 way |
903 | 935 | else |
904 | 936 | { |
905 | 937 | // No month? No year? |
906 | - if (!isset($_POST['month'])) |
|
907 | - fatal_lang_error('event_month_missing', false); |
|
908 | - if (!isset($_POST['year'])) |
|
909 | - fatal_lang_error('event_year_missing', false); |
|
938 | + if (!isset($_POST['month'])) { |
|
939 | + fatal_lang_error('event_month_missing', false); |
|
940 | + } |
|
941 | + if (!isset($_POST['year'])) { |
|
942 | + fatal_lang_error('event_year_missing', false); |
|
943 | + } |
|
910 | 944 | |
911 | 945 | // Check the month and year... |
912 | - if ($_POST['month'] < 1 || $_POST['month'] > 12) |
|
913 | - fatal_lang_error('invalid_month', false); |
|
914 | - if ($_POST['year'] < $modSettings['cal_minyear'] || $_POST['year'] > $modSettings['cal_maxyear']) |
|
915 | - fatal_lang_error('invalid_year', false); |
|
946 | + if ($_POST['month'] < 1 || $_POST['month'] > 12) { |
|
947 | + fatal_lang_error('invalid_month', false); |
|
948 | + } |
|
949 | + if ($_POST['year'] < $modSettings['cal_minyear'] || $_POST['year'] > $modSettings['cal_maxyear']) { |
|
950 | + fatal_lang_error('invalid_year', false); |
|
951 | + } |
|
916 | 952 | } |
917 | 953 | } |
918 | 954 | |
@@ -922,8 +958,9 @@ discard block |
||
922 | 958 | // If they want to us to calculate an end date, make sure it will fit in an acceptable range. |
923 | 959 | if (isset($_POST['span'])) |
924 | 960 | { |
925 | - if (($_POST['span'] < 1) || (!empty($modSettings['cal_maxspan']) && $_POST['span'] > $modSettings['cal_maxspan'])) |
|
926 | - fatal_lang_error('invalid_days_numb', false); |
|
961 | + if (($_POST['span'] < 1) || (!empty($modSettings['cal_maxspan']) && $_POST['span'] > $modSettings['cal_maxspan'])) { |
|
962 | + fatal_lang_error('invalid_days_numb', false); |
|
963 | + } |
|
927 | 964 | } |
928 | 965 | |
929 | 966 | // There is no need to validate the following values if we are just deleting the event. |
@@ -933,24 +970,29 @@ discard block |
||
933 | 970 | if (empty($_POST['start_date']) && empty($_POST['start_datetime'])) |
934 | 971 | { |
935 | 972 | // No day? |
936 | - if (!isset($_POST['day'])) |
|
937 | - fatal_lang_error('event_day_missing', false); |
|
973 | + if (!isset($_POST['day'])) { |
|
974 | + fatal_lang_error('event_day_missing', false); |
|
975 | + } |
|
938 | 976 | |
939 | 977 | // Bad day? |
940 | - if (!checkdate($_POST['month'], $_POST['day'], $_POST['year'])) |
|
941 | - fatal_lang_error('invalid_date', false); |
|
978 | + if (!checkdate($_POST['month'], $_POST['day'], $_POST['year'])) { |
|
979 | + fatal_lang_error('invalid_date', false); |
|
980 | + } |
|
942 | 981 | } |
943 | 982 | |
944 | - if (!isset($_POST['evtitle']) && !isset($_POST['subject'])) |
|
945 | - fatal_lang_error('event_title_missing', false); |
|
946 | - elseif (!isset($_POST['evtitle'])) |
|
947 | - $_POST['evtitle'] = $_POST['subject']; |
|
983 | + if (!isset($_POST['evtitle']) && !isset($_POST['subject'])) { |
|
984 | + fatal_lang_error('event_title_missing', false); |
|
985 | + } elseif (!isset($_POST['evtitle'])) { |
|
986 | + $_POST['evtitle'] = $_POST['subject']; |
|
987 | + } |
|
948 | 988 | |
949 | 989 | // No title? |
950 | - if ($smcFunc['htmltrim']($_POST['evtitle']) === '') |
|
951 | - fatal_lang_error('no_event_title', false); |
|
952 | - if ($smcFunc['strlen']($_POST['evtitle']) > 100) |
|
953 | - $_POST['evtitle'] = $smcFunc['substr']($_POST['evtitle'], 0, 100); |
|
990 | + if ($smcFunc['htmltrim']($_POST['evtitle']) === '') { |
|
991 | + fatal_lang_error('no_event_title', false); |
|
992 | + } |
|
993 | + if ($smcFunc['strlen']($_POST['evtitle']) > 100) { |
|
994 | + $_POST['evtitle'] = $smcFunc['substr']($_POST['evtitle'], 0, 100); |
|
995 | + } |
|
954 | 996 | $_POST['evtitle'] = str_replace(';', '', $_POST['evtitle']); |
955 | 997 | } |
956 | 998 | } |
@@ -977,8 +1019,9 @@ discard block |
||
977 | 1019 | ); |
978 | 1020 | |
979 | 1021 | // No results, return false. |
980 | - if ($smcFunc['db_num_rows'] === 0) |
|
981 | - return false; |
|
1022 | + if ($smcFunc['db_num_rows'] === 0) { |
|
1023 | + return false; |
|
1024 | + } |
|
982 | 1025 | |
983 | 1026 | // Grab the results and return. |
984 | 1027 | list ($poster) = $smcFunc['db_fetch_row']($request); |
@@ -1112,8 +1155,9 @@ discard block |
||
1112 | 1155 | call_integration_hook('integrate_modify_event', array($event_id, &$eventOptions, &$event_columns, &$event_parameters)); |
1113 | 1156 | |
1114 | 1157 | $column_clauses = array(); |
1115 | - foreach ($event_columns as $col => $crit) |
|
1116 | - $column_clauses[] = $col . ' = ' . $crit; |
|
1158 | + foreach ($event_columns as $col => $crit) { |
|
1159 | + $column_clauses[] = $col . ' = ' . $crit; |
|
1160 | + } |
|
1117 | 1161 | |
1118 | 1162 | $smcFunc['db_query']('', ' |
1119 | 1163 | UPDATE {db_prefix}calendar |
@@ -1198,8 +1242,9 @@ discard block |
||
1198 | 1242 | ); |
1199 | 1243 | |
1200 | 1244 | // If nothing returned, we are in poo, poo. |
1201 | - if ($smcFunc['db_num_rows']($request) === 0) |
|
1202 | - return false; |
|
1245 | + if ($smcFunc['db_num_rows']($request) === 0) { |
|
1246 | + return false; |
|
1247 | + } |
|
1203 | 1248 | |
1204 | 1249 | $row = $smcFunc['db_fetch_assoc']($request); |
1205 | 1250 | $smcFunc['db_free_result']($request); |
@@ -1207,8 +1252,9 @@ discard block |
||
1207 | 1252 | list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row); |
1208 | 1253 | |
1209 | 1254 | // Sanity check |
1210 | - if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) |
|
1211 | - return false; |
|
1255 | + if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) { |
|
1256 | + return false; |
|
1257 | + } |
|
1212 | 1258 | |
1213 | 1259 | $return_value = array( |
1214 | 1260 | 'boards' => array(), |
@@ -1345,24 +1391,27 @@ discard block |
||
1345 | 1391 | |
1346 | 1392 | // Set $span, in case we need it |
1347 | 1393 | $span = isset($eventOptions['span']) ? $eventOptions['span'] : (isset($_POST['span']) ? $_POST['span'] : 0); |
1348 | - if ($span > 0) |
|
1349 | - $span = !empty($modSettings['cal_maxspan']) ? min($modSettings['cal_maxspan'], $span - 1) : $span - 1; |
|
1394 | + if ($span > 0) { |
|
1395 | + $span = !empty($modSettings['cal_maxspan']) ? min($modSettings['cal_maxspan'], $span - 1) : $span - 1; |
|
1396 | + } |
|
1350 | 1397 | |
1351 | 1398 | // Define the timezone for this event, falling back to the default if not provided |
1352 | - if (!empty($eventOptions['tz']) && in_array($eventOptions['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) |
|
1353 | - $tz = $eventOptions['tz']; |
|
1354 | - elseif (!empty($_POST['tz']) && in_array($_POST['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) |
|
1355 | - $tz = $_POST['tz']; |
|
1356 | - else |
|
1357 | - $tz = getUserTimezone(); |
|
1399 | + if (!empty($eventOptions['tz']) && in_array($eventOptions['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) { |
|
1400 | + $tz = $eventOptions['tz']; |
|
1401 | + } elseif (!empty($_POST['tz']) && in_array($_POST['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) { |
|
1402 | + $tz = $_POST['tz']; |
|
1403 | + } else { |
|
1404 | + $tz = getUserTimezone(); |
|
1405 | + } |
|
1358 | 1406 | |
1359 | 1407 | // Is this supposed to be an all day event, or should it have specific start and end times? |
1360 | - if (isset($eventOptions['allday'])) |
|
1361 | - $allday = $eventOptions['allday']; |
|
1362 | - elseif (empty($_POST['allday'])) |
|
1363 | - $allday = false; |
|
1364 | - else |
|
1365 | - $allday = true; |
|
1408 | + if (isset($eventOptions['allday'])) { |
|
1409 | + $allday = $eventOptions['allday']; |
|
1410 | + } elseif (empty($_POST['allday'])) { |
|
1411 | + $allday = false; |
|
1412 | + } else { |
|
1413 | + $allday = true; |
|
1414 | + } |
|
1366 | 1415 | |
1367 | 1416 | // Input might come as individual parameters... |
1368 | 1417 | $start_year = isset($eventOptions['year']) ? $eventOptions['year'] : (isset($_POST['year']) ? $_POST['year'] : null); |
@@ -1389,10 +1438,12 @@ discard block |
||
1389 | 1438 | $end_time_string = isset($eventOptions['end_time']) ? $eventOptions['end_time'] : (isset($_POST['end_time']) ? $_POST['end_time'] : null); |
1390 | 1439 | |
1391 | 1440 | // If the date and time were given in separate strings, combine them |
1392 | - if (empty($start_string) && isset($start_date_string)) |
|
1393 | - $start_string = $start_date_string . (isset($start_time_string) ? ' ' . $start_time_string : ''); |
|
1394 | - if (empty($end_string) && isset($end_date_string)) |
|
1395 | - $end_string = $end_date_string . (isset($end_time_string) ? ' ' . $end_time_string : ''); |
|
1441 | + if (empty($start_string) && isset($start_date_string)) { |
|
1442 | + $start_string = $start_date_string . (isset($start_time_string) ? ' ' . $start_time_string : ''); |
|
1443 | + } |
|
1444 | + if (empty($end_string) && isset($end_date_string)) { |
|
1445 | + $end_string = $end_date_string . (isset($end_time_string) ? ' ' . $end_time_string : ''); |
|
1446 | + } |
|
1396 | 1447 | |
1397 | 1448 | // If some form of string input was given, override individually defined options with it |
1398 | 1449 | if (isset($start_string)) |
@@ -1483,10 +1534,11 @@ discard block |
||
1483 | 1534 | if ($start_object >= $end_object) |
1484 | 1535 | { |
1485 | 1536 | $end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, $start_hour, $start_minute, $start_second) . ' ' . $tz); |
1486 | - if ($span > 0) |
|
1487 | - date_add($end_object, date_interval_create_from_date_string($span . ' days')); |
|
1488 | - else |
|
1489 | - date_add($end_object, date_interval_create_from_date_string('1 hour')); |
|
1537 | + if ($span > 0) { |
|
1538 | + date_add($end_object, date_interval_create_from_date_string($span . ' days')); |
|
1539 | + } else { |
|
1540 | + date_add($end_object, date_interval_create_from_date_string('1 hour')); |
|
1541 | + } |
|
1490 | 1542 | } |
1491 | 1543 | |
1492 | 1544 | // Is $end_object too late? |
@@ -1499,9 +1551,9 @@ discard block |
||
1499 | 1551 | { |
1500 | 1552 | $end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, $start_hour, $start_minute, $start_second) . ' ' . $tz); |
1501 | 1553 | date_add($end_object, date_interval_create_from_date_string($modSettings['cal_maxspan'] . ' days')); |
1554 | + } else { |
|
1555 | + $end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, '11', '59', '59') . ' ' . $tz); |
|
1502 | 1556 | } |
1503 | - else |
|
1504 | - $end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, '11', '59', '59') . ' ' . $tz); |
|
1505 | 1557 | } |
1506 | 1558 | } |
1507 | 1559 | |
@@ -1514,8 +1566,7 @@ discard block |
||
1514 | 1566 | $start_time = null; |
1515 | 1567 | $end_time = null; |
1516 | 1568 | $tz = null; |
1517 | - } |
|
1518 | - else |
|
1569 | + } else |
|
1519 | 1570 | { |
1520 | 1571 | $start_time = date_format($start_object, 'H:i:s'); |
1521 | 1572 | $end_time = date_format($end_object, 'H:i:s'); |
@@ -1536,16 +1587,18 @@ discard block |
||
1536 | 1587 | require_once($sourcedir . '/Subs.php'); |
1537 | 1588 | |
1538 | 1589 | // First, try to create a better date format, ignoring the "time" elements. |
1539 | - if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) |
|
1540 | - $date_format = '%F'; |
|
1541 | - else |
|
1542 | - $date_format = $matches[0]; |
|
1590 | + if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) { |
|
1591 | + $date_format = '%F'; |
|
1592 | + } else { |
|
1593 | + $date_format = $matches[0]; |
|
1594 | + } |
|
1543 | 1595 | |
1544 | 1596 | // We want a fairly compact version of the time, but as close as possible to the user's settings. |
1545 | - if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) |
|
1546 | - $time_format = '%k:%M'; |
|
1547 | - else |
|
1548 | - $time_format = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]); |
|
1597 | + if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) { |
|
1598 | + $time_format = '%k:%M'; |
|
1599 | + } else { |
|
1600 | + $time_format = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]); |
|
1601 | + } |
|
1549 | 1602 | |
1550 | 1603 | // Should this be an all day event? |
1551 | 1604 | $allday = (empty($row['start_time']) || empty($row['end_time']) || empty($row['timezone']) || !in_array($row['timezone'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) ? true : false; |
@@ -1554,8 +1607,9 @@ discard block |
||
1554 | 1607 | $span = 1 + date_interval_format(date_diff(date_create($row['start_date']), date_create($row['end_date'])), '%d'); |
1555 | 1608 | |
1556 | 1609 | // We need to have a defined timezone in the steps below |
1557 | - if (empty($row['timezone'])) |
|
1558 | - $row['timezone'] = getUserTimezone(); |
|
1610 | + if (empty($row['timezone'])) { |
|
1611 | + $row['timezone'] = getUserTimezone(); |
|
1612 | + } |
|
1559 | 1613 | |
1560 | 1614 | // Get most of the standard date information for the start and end datetimes |
1561 | 1615 | $start = date_parse($row['start_date'] . (!$allday ? ' ' . $row['start_time'] : '')); |
@@ -1607,8 +1661,9 @@ discard block |
||
1607 | 1661 | global $smcFunc, $context, $user_info, $modSettings, $user_settings; |
1608 | 1662 | static $member_cache = array(); |
1609 | 1663 | |
1610 | - if (is_null($id_member) && $user_info['is_guest'] == false) |
|
1611 | - $id_member = $context['user']['id']; |
|
1664 | + if (is_null($id_member) && $user_info['is_guest'] == false) { |
|
1665 | + $id_member = $context['user']['id']; |
|
1666 | + } |
|
1612 | 1667 | |
1613 | 1668 | //check if the cache got the data |
1614 | 1669 | if (isset($id_member) && isset($member_cache[$id_member])) |
@@ -1637,11 +1692,13 @@ discard block |
||
1637 | 1692 | $smcFunc['db_free_result']($request); |
1638 | 1693 | } |
1639 | 1694 | |
1640 | - if (empty($timezone) || !in_array($timezone, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) |
|
1641 | - $timezone = isset($modSettings['default_timezone']) ? $modSettings['default_timezone'] : date_default_timezone_get(); |
|
1695 | + if (empty($timezone) || !in_array($timezone, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) { |
|
1696 | + $timezone = isset($modSettings['default_timezone']) ? $modSettings['default_timezone'] : date_default_timezone_get(); |
|
1697 | + } |
|
1642 | 1698 | |
1643 | - if (isset($id_member)) |
|
1644 | - $member_cache[$id_member] = $timezone; |
|
1699 | + if (isset($id_member)) { |
|
1700 | + $member_cache[$id_member] = $timezone; |
|
1701 | + } |
|
1645 | 1702 | |
1646 | 1703 | return $timezone; |
1647 | 1704 | } |
@@ -1670,8 +1727,9 @@ discard block |
||
1670 | 1727 | ) |
1671 | 1728 | ); |
1672 | 1729 | $holidays = array(); |
1673 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1674 | - $holidays[] = $row; |
|
1730 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1731 | + $holidays[] = $row; |
|
1732 | + } |
|
1675 | 1733 | $smcFunc['db_free_result']($request); |
1676 | 1734 | |
1677 | 1735 | return $holidays; |
@@ -15,8 +15,9 @@ discard block |
||
15 | 15 | * @version 2.1 Beta 4 |
16 | 16 | */ |
17 | 17 | |
18 | -if (!defined('SMF')) |
|
18 | +if (!defined('SMF')) { |
|
19 | 19 | die('No direct access...'); |
20 | +} |
|
20 | 21 | |
21 | 22 | /** |
22 | 23 | * Begin the registration process. |
@@ -29,19 +30,23 @@ discard block |
||
29 | 30 | global $language, $scripturl, $smcFunc, $sourcedir, $cur_profile; |
30 | 31 | |
31 | 32 | // Is this an incoming AJAX check? |
32 | - if (isset($_GET['sa']) && $_GET['sa'] == 'usernamecheck') |
|
33 | - return RegisterCheckUsername(); |
|
33 | + if (isset($_GET['sa']) && $_GET['sa'] == 'usernamecheck') { |
|
34 | + return RegisterCheckUsername(); |
|
35 | + } |
|
34 | 36 | |
35 | 37 | // Check if the administrator has it disabled. |
36 | - if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == '3') |
|
37 | - fatal_lang_error('registration_disabled', false); |
|
38 | + if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == '3') { |
|
39 | + fatal_lang_error('registration_disabled', false); |
|
40 | + } |
|
38 | 41 | |
39 | 42 | // If this user is an admin - redirect them to the admin registration page. |
40 | - if (allowedTo('moderate_forum') && !$user_info['is_guest']) |
|
41 | - redirectexit('action=admin;area=regcenter;sa=register'); |
|
43 | + if (allowedTo('moderate_forum') && !$user_info['is_guest']) { |
|
44 | + redirectexit('action=admin;area=regcenter;sa=register'); |
|
45 | + } |
|
42 | 46 | // You are not a guest, so you are a member - and members don't get to register twice! |
43 | - elseif (empty($user_info['is_guest'])) |
|
44 | - redirectexit(); |
|
47 | + elseif (empty($user_info['is_guest'])) { |
|
48 | + redirectexit(); |
|
49 | + } |
|
45 | 50 | |
46 | 51 | loadLanguage('Login'); |
47 | 52 | loadTemplate('Register'); |
@@ -82,16 +87,18 @@ discard block |
||
82 | 87 | } |
83 | 88 | } |
84 | 89 | // Make sure they don't squeeze through without agreeing. |
85 | - elseif ($current_step > 1 && $context['require_agreement'] && !$context['registration_passed_agreement']) |
|
86 | - $current_step = 1; |
|
90 | + elseif ($current_step > 1 && $context['require_agreement'] && !$context['registration_passed_agreement']) { |
|
91 | + $current_step = 1; |
|
92 | + } |
|
87 | 93 | |
88 | 94 | // Show the user the right form. |
89 | 95 | $context['sub_template'] = $current_step == 1 ? 'registration_agreement' : 'registration_form'; |
90 | 96 | $context['page_title'] = $current_step == 1 ? $txt['registration_agreement'] : $txt['registration_form']; |
91 | 97 | |
92 | 98 | // Kinda need this. |
93 | - if ($context['sub_template'] == 'registration_form') |
|
94 | - loadJavaScriptFile('register.js', array('defer' => false), 'smf_register'); |
|
99 | + if ($context['sub_template'] == 'registration_form') { |
|
100 | + loadJavaScriptFile('register.js', array('defer' => false), 'smf_register'); |
|
101 | + } |
|
95 | 102 | |
96 | 103 | // Add the register chain to the link tree. |
97 | 104 | $context['linktree'][] = array( |
@@ -100,24 +107,26 @@ discard block |
||
100 | 107 | ); |
101 | 108 | |
102 | 109 | // Prepare the time gate! Do it like so, in case later steps want to reset the limit for any reason, but make sure the time is the current one. |
103 | - if (!isset($_SESSION['register'])) |
|
104 | - $_SESSION['register'] = array( |
|
110 | + if (!isset($_SESSION['register'])) { |
|
111 | + $_SESSION['register'] = array( |
|
105 | 112 | 'timenow' => time(), |
106 | 113 | 'limit' => 10, // minimum number of seconds required on this page for registration |
107 | 114 | ); |
108 | - else |
|
109 | - $_SESSION['register']['timenow'] = time(); |
|
115 | + } else { |
|
116 | + $_SESSION['register']['timenow'] = time(); |
|
117 | + } |
|
110 | 118 | |
111 | 119 | // If you have to agree to the agreement, it needs to be fetched from the file. |
112 | 120 | if ($context['require_agreement']) |
113 | 121 | { |
114 | 122 | // Have we got a localized one? |
115 | - if (file_exists($boarddir . '/agreement.' . $user_info['language'] . '.txt')) |
|
116 | - $context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.' . $user_info['language'] . '.txt'), true, 'agreement_' . $user_info['language']); |
|
117 | - elseif (file_exists($boarddir . '/agreement.txt')) |
|
118 | - $context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.txt'), true, 'agreement'); |
|
119 | - else |
|
120 | - $context['agreement'] = ''; |
|
123 | + if (file_exists($boarddir . '/agreement.' . $user_info['language'] . '.txt')) { |
|
124 | + $context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.' . $user_info['language'] . '.txt'), true, 'agreement_' . $user_info['language']); |
|
125 | + } elseif (file_exists($boarddir . '/agreement.txt')) { |
|
126 | + $context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.txt'), true, 'agreement'); |
|
127 | + } else { |
|
128 | + $context['agreement'] = ''; |
|
129 | + } |
|
121 | 130 | |
122 | 131 | // Nothing to show, lets disable registration and inform the admin of this error |
123 | 132 | if (empty($context['agreement'])) |
@@ -133,8 +142,9 @@ discard block |
||
133 | 142 | $selectedLanguage = empty($_SESSION['language']) ? $language : $_SESSION['language']; |
134 | 143 | |
135 | 144 | // Do we have any languages? |
136 | - if (empty($context['languages'])) |
|
137 | - getLanguages(); |
|
145 | + if (empty($context['languages'])) { |
|
146 | + getLanguages(); |
|
147 | + } |
|
138 | 148 | |
139 | 149 | // Try to find our selected language. |
140 | 150 | foreach ($context['languages'] as $key => $lang) |
@@ -142,8 +152,9 @@ discard block |
||
142 | 152 | $context['languages'][$key]['name'] = strtr($lang['name'], array('-utf8' => '')); |
143 | 153 | |
144 | 154 | // Found it! |
145 | - if ($selectedLanguage == $lang['filename']) |
|
146 | - $context['languages'][$key]['selected'] = true; |
|
155 | + if ($selectedLanguage == $lang['filename']) { |
|
156 | + $context['languages'][$key]['selected'] = true; |
|
157 | + } |
|
147 | 158 | } |
148 | 159 | } |
149 | 160 | |
@@ -167,9 +178,10 @@ discard block |
||
167 | 178 | $reg_fields = explode(',', $modSettings['registration_fields']); |
168 | 179 | |
169 | 180 | // We might have had some submissions on this front - go check. |
170 | - foreach ($reg_fields as $field) |
|
171 | - if (isset($_POST[$field])) |
|
181 | + foreach ($reg_fields as $field) { |
|
182 | + if (isset($_POST[$field])) |
|
172 | 183 | $cur_profile[$field] = $smcFunc['htmlspecialchars']($_POST[$field]); |
184 | + } |
|
173 | 185 | |
174 | 186 | // Load all the fields in question. |
175 | 187 | setupProfileContext($reg_fields); |
@@ -186,8 +198,9 @@ discard block |
||
186 | 198 | $context['visual_verification_id'] = $verificationOptions['id']; |
187 | 199 | } |
188 | 200 | // Otherwise we have nothing to show. |
189 | - else |
|
190 | - $context['visual_verification'] = false; |
|
201 | + else { |
|
202 | + $context['visual_verification'] = false; |
|
203 | + } |
|
191 | 204 | |
192 | 205 | |
193 | 206 | $context += array( |
@@ -198,8 +211,9 @@ discard block |
||
198 | 211 | |
199 | 212 | // Were there any errors? |
200 | 213 | $context['registration_errors'] = array(); |
201 | - if (!empty($reg_errors)) |
|
202 | - $context['registration_errors'] = $reg_errors; |
|
214 | + if (!empty($reg_errors)) { |
|
215 | + $context['registration_errors'] = $reg_errors; |
|
216 | + } |
|
203 | 217 | |
204 | 218 | createToken('register'); |
205 | 219 | } |
@@ -216,27 +230,32 @@ discard block |
||
216 | 230 | validateToken('register'); |
217 | 231 | |
218 | 232 | // Check to ensure we're forcing SSL for authentication |
219 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) |
|
220 | - fatal_lang_error('register_ssl_required'); |
|
233 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) { |
|
234 | + fatal_lang_error('register_ssl_required'); |
|
235 | + } |
|
221 | 236 | |
222 | 237 | // Start collecting together any errors. |
223 | 238 | $reg_errors = array(); |
224 | 239 | |
225 | 240 | // You can't register if it's disabled. |
226 | - if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 3) |
|
227 | - fatal_lang_error('registration_disabled', false); |
|
241 | + if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 3) { |
|
242 | + fatal_lang_error('registration_disabled', false); |
|
243 | + } |
|
228 | 244 | |
229 | 245 | // Well, if you don't agree, you can't register. |
230 | - if (!empty($modSettings['requireAgreement']) && empty($_SESSION['registration_agreed'])) |
|
231 | - redirectexit(); |
|
246 | + if (!empty($modSettings['requireAgreement']) && empty($_SESSION['registration_agreed'])) { |
|
247 | + redirectexit(); |
|
248 | + } |
|
232 | 249 | |
233 | 250 | // Make sure they came from *somewhere*, have a session. |
234 | - if (!isset($_SESSION['old_url'])) |
|
235 | - redirectexit('action=signup'); |
|
251 | + if (!isset($_SESSION['old_url'])) { |
|
252 | + redirectexit('action=signup'); |
|
253 | + } |
|
236 | 254 | |
237 | 255 | // If we don't require an agreement, we need a extra check for coppa. |
238 | - if (empty($modSettings['requireAgreement']) && !empty($modSettings['coppaAge'])) |
|
239 | - $_SESSION['skip_coppa'] = !empty($_POST['accept_agreement']); |
|
256 | + if (empty($modSettings['requireAgreement']) && !empty($modSettings['coppaAge'])) { |
|
257 | + $_SESSION['skip_coppa'] = !empty($_POST['accept_agreement']); |
|
258 | + } |
|
240 | 259 | // Are they under age, and under age users are banned? |
241 | 260 | if (!empty($modSettings['coppaAge']) && empty($modSettings['coppaType']) && empty($_SESSION['skip_coppa'])) |
242 | 261 | { |
@@ -245,8 +264,9 @@ discard block |
||
245 | 264 | } |
246 | 265 | |
247 | 266 | // Check the time gate for miscreants. First make sure they came from somewhere that actually set it up. |
248 | - if (empty($_SESSION['register']['timenow']) || empty($_SESSION['register']['limit'])) |
|
249 | - redirectexit('action=signup'); |
|
267 | + if (empty($_SESSION['register']['timenow']) || empty($_SESSION['register']['limit'])) { |
|
268 | + redirectexit('action=signup'); |
|
269 | + } |
|
250 | 270 | // Failing that, check the time on it. |
251 | 271 | if (time() - $_SESSION['register']['timenow'] < $_SESSION['register']['limit']) |
252 | 272 | { |
@@ -266,15 +286,17 @@ discard block |
||
266 | 286 | if (is_array($context['visual_verification'])) |
267 | 287 | { |
268 | 288 | loadLanguage('Errors'); |
269 | - foreach ($context['visual_verification'] as $error) |
|
270 | - $reg_errors[] = $txt['error_' . $error]; |
|
289 | + foreach ($context['visual_verification'] as $error) { |
|
290 | + $reg_errors[] = $txt['error_' . $error]; |
|
291 | + } |
|
271 | 292 | } |
272 | 293 | } |
273 | 294 | |
274 | 295 | foreach ($_POST as $key => $value) |
275 | 296 | { |
276 | - if (!is_array($_POST[$key])) |
|
277 | - $_POST[$key] = htmltrim__recursive(str_replace(array("\n", "\r"), '', $_POST[$key])); |
|
297 | + if (!is_array($_POST[$key])) { |
|
298 | + $_POST[$key] = htmltrim__recursive(str_replace(array("\n", "\r"), '', $_POST[$key])); |
|
299 | + } |
|
278 | 300 | } |
279 | 301 | |
280 | 302 | // Collect all extra registration fields someone might have filled in. |
@@ -304,12 +326,14 @@ discard block |
||
304 | 326 | $reg_fields = explode(',', $modSettings['registration_fields']); |
305 | 327 | |
306 | 328 | // Website is a little different |
307 | - if (in_array('website', $reg_fields)) |
|
308 | - $possible_strings += array('website_url', 'website_title'); |
|
329 | + if (in_array('website', $reg_fields)) { |
|
330 | + $possible_strings += array('website_url', 'website_title'); |
|
331 | + } |
|
309 | 332 | } |
310 | 333 | |
311 | - if (isset($_POST['secret_answer']) && $_POST['secret_answer'] != '') |
|
312 | - $_POST['secret_answer'] = md5($_POST['secret_answer']); |
|
334 | + if (isset($_POST['secret_answer']) && $_POST['secret_answer'] != '') { |
|
335 | + $_POST['secret_answer'] = md5($_POST['secret_answer']); |
|
336 | + } |
|
313 | 337 | |
314 | 338 | // Needed for isReservedName() and registerMember(). |
315 | 339 | require_once($sourcedir . '/Subs-Members.php'); |
@@ -318,8 +342,9 @@ discard block |
||
318 | 342 | if (isset($_POST['real_name'])) |
319 | 343 | { |
320 | 344 | // Are you already allowed to edit the displayed name? |
321 | - if (allowedTo('profile_displayed_name') || allowedTo('moderate_forum')) |
|
322 | - $canEditDisplayName = true; |
|
345 | + if (allowedTo('profile_displayed_name') || allowedTo('moderate_forum')) { |
|
346 | + $canEditDisplayName = true; |
|
347 | + } |
|
323 | 348 | |
324 | 349 | // If you are a guest, will you be allowed to once you register? |
325 | 350 | else |
@@ -343,33 +368,38 @@ discard block |
||
343 | 368 | $_POST['real_name'] = trim(preg_replace('~[\t\n\r \x0B\0' . ($context['utf8'] ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : '\x00-\x08\x0B\x0C\x0E-\x19\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $_POST['real_name'])); |
344 | 369 | |
345 | 370 | // Only set it if we are sure it is good |
346 | - if (trim($_POST['real_name']) != '' && !isReservedName($_POST['real_name']) && $smcFunc['strlen']($_POST['real_name']) < 60) |
|
347 | - $possible_strings[] = 'real_name'; |
|
371 | + if (trim($_POST['real_name']) != '' && !isReservedName($_POST['real_name']) && $smcFunc['strlen']($_POST['real_name']) < 60) { |
|
372 | + $possible_strings[] = 'real_name'; |
|
373 | + } |
|
348 | 374 | } |
349 | 375 | } |
350 | 376 | |
351 | 377 | // Handle a string as a birthdate... |
352 | - if (isset($_POST['birthdate']) && $_POST['birthdate'] != '') |
|
353 | - $_POST['birthdate'] = strftime('%Y-%m-%d', strtotime($_POST['birthdate'])); |
|
378 | + if (isset($_POST['birthdate']) && $_POST['birthdate'] != '') { |
|
379 | + $_POST['birthdate'] = strftime('%Y-%m-%d', strtotime($_POST['birthdate'])); |
|
380 | + } |
|
354 | 381 | // Or birthdate parts... |
355 | - elseif (!empty($_POST['bday1']) && !empty($_POST['bday2'])) |
|
356 | - $_POST['birthdate'] = sprintf('%04d-%02d-%02d', empty($_POST['bday3']) ? 0 : (int) $_POST['bday3'], (int) $_POST['bday1'], (int) $_POST['bday2']); |
|
382 | + elseif (!empty($_POST['bday1']) && !empty($_POST['bday2'])) { |
|
383 | + $_POST['birthdate'] = sprintf('%04d-%02d-%02d', empty($_POST['bday3']) ? 0 : (int) $_POST['bday3'], (int) $_POST['bday1'], (int) $_POST['bday2']); |
|
384 | + } |
|
357 | 385 | |
358 | 386 | // Validate the passed language file. |
359 | 387 | if (isset($_POST['lngfile']) && !empty($modSettings['userLanguage'])) |
360 | 388 | { |
361 | 389 | // Do we have any languages? |
362 | - if (empty($context['languages'])) |
|
363 | - getLanguages(); |
|
390 | + if (empty($context['languages'])) { |
|
391 | + getLanguages(); |
|
392 | + } |
|
364 | 393 | |
365 | 394 | // Did we find it? |
366 | - if (isset($context['languages'][$_POST['lngfile']])) |
|
367 | - $_SESSION['language'] = $_POST['lngfile']; |
|
368 | - else |
|
395 | + if (isset($context['languages'][$_POST['lngfile']])) { |
|
396 | + $_SESSION['language'] = $_POST['lngfile']; |
|
397 | + } else { |
|
398 | + unset($_POST['lngfile']); |
|
399 | + } |
|
400 | + } else { |
|
369 | 401 | unset($_POST['lngfile']); |
370 | 402 | } |
371 | - else |
|
372 | - unset($_POST['lngfile']); |
|
373 | 403 | |
374 | 404 | // Set the options needed for registration. |
375 | 405 | $regOptions = array( |
@@ -389,22 +419,27 @@ discard block |
||
389 | 419 | ); |
390 | 420 | |
391 | 421 | // Include the additional options that might have been filled in. |
392 | - foreach ($possible_strings as $var) |
|
393 | - if (isset($_POST[$var])) |
|
422 | + foreach ($possible_strings as $var) { |
|
423 | + if (isset($_POST[$var])) |
|
394 | 424 | $regOptions['extra_register_vars'][$var] = $smcFunc['htmlspecialchars']($_POST[$var], ENT_QUOTES); |
395 | - foreach ($possible_ints as $var) |
|
396 | - if (isset($_POST[$var])) |
|
425 | + } |
|
426 | + foreach ($possible_ints as $var) { |
|
427 | + if (isset($_POST[$var])) |
|
397 | 428 | $regOptions['extra_register_vars'][$var] = (int) $_POST[$var]; |
398 | - foreach ($possible_floats as $var) |
|
399 | - if (isset($_POST[$var])) |
|
429 | + } |
|
430 | + foreach ($possible_floats as $var) { |
|
431 | + if (isset($_POST[$var])) |
|
400 | 432 | $regOptions['extra_register_vars'][$var] = (float) $_POST[$var]; |
401 | - foreach ($possible_bools as $var) |
|
402 | - if (isset($_POST[$var])) |
|
433 | + } |
|
434 | + foreach ($possible_bools as $var) { |
|
435 | + if (isset($_POST[$var])) |
|
403 | 436 | $regOptions['extra_register_vars'][$var] = empty($_POST[$var]) ? 0 : 1; |
437 | + } |
|
404 | 438 | |
405 | 439 | // Registration options are always default options... |
406 | - if (isset($_POST['default_options'])) |
|
407 | - $_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options']; |
|
440 | + if (isset($_POST['default_options'])) { |
|
441 | + $_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options']; |
|
442 | + } |
|
408 | 443 | $regOptions['theme_vars'] = isset($_POST['options']) && is_array($_POST['options']) ? $_POST['options'] : array(); |
409 | 444 | |
410 | 445 | // Make sure they are clean, dammit! |
@@ -424,12 +459,14 @@ discard block |
||
424 | 459 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
425 | 460 | { |
426 | 461 | // Don't allow overriding of the theme variables. |
427 | - if (isset($regOptions['theme_vars'][$row['col_name']])) |
|
428 | - unset($regOptions['theme_vars'][$row['col_name']]); |
|
462 | + if (isset($regOptions['theme_vars'][$row['col_name']])) { |
|
463 | + unset($regOptions['theme_vars'][$row['col_name']]); |
|
464 | + } |
|
429 | 465 | |
430 | 466 | // Not actually showing it then? |
431 | - if (!$row['show_reg']) |
|
432 | - continue; |
|
467 | + if (!$row['show_reg']) { |
|
468 | + continue; |
|
469 | + } |
|
433 | 470 | |
434 | 471 | // Prepare the value! |
435 | 472 | $value = isset($_POST['customfield'][$row['col_name']]) ? trim($_POST['customfield'][$row['col_name']]) : ''; |
@@ -438,24 +475,27 @@ discard block |
||
438 | 475 | if (!in_array($row['field_type'], array('check', 'select', 'radio'))) |
439 | 476 | { |
440 | 477 | // Is it too long? |
441 | - if ($row['field_length'] && $row['field_length'] < $smcFunc['strlen']($value)) |
|
442 | - $custom_field_errors[] = array('custom_field_too_long', array($row['field_name'], $row['field_length'])); |
|
478 | + if ($row['field_length'] && $row['field_length'] < $smcFunc['strlen']($value)) { |
|
479 | + $custom_field_errors[] = array('custom_field_too_long', array($row['field_name'], $row['field_length'])); |
|
480 | + } |
|
443 | 481 | |
444 | 482 | // Any masks to apply? |
445 | 483 | if ($row['field_type'] == 'text' && !empty($row['mask']) && $row['mask'] != 'none') |
446 | 484 | { |
447 | - if ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255)) |
|
448 | - $custom_field_errors[] = array('custom_field_invalid_email', array($row['field_name'])); |
|
449 | - elseif ($row['mask'] == 'number' && preg_match('~[^\d]~', $value)) |
|
450 | - $custom_field_errors[] = array('custom_field_not_number', array($row['field_name'])); |
|
451 | - elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0) |
|
452 | - $custom_field_errors[] = array('custom_field_inproper_format', array($row['field_name'])); |
|
485 | + if ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255)) { |
|
486 | + $custom_field_errors[] = array('custom_field_invalid_email', array($row['field_name'])); |
|
487 | + } elseif ($row['mask'] == 'number' && preg_match('~[^\d]~', $value)) { |
|
488 | + $custom_field_errors[] = array('custom_field_not_number', array($row['field_name'])); |
|
489 | + } elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0) { |
|
490 | + $custom_field_errors[] = array('custom_field_inproper_format', array($row['field_name'])); |
|
491 | + } |
|
453 | 492 | } |
454 | 493 | } |
455 | 494 | |
456 | 495 | // Is this required but not there? |
457 | - if (trim($value) == '' && $row['show_reg'] > 1) |
|
458 | - $custom_field_errors[] = array('custom_field_empty', array($row['field_name'])); |
|
496 | + if (trim($value) == '' && $row['show_reg'] > 1) { |
|
497 | + $custom_field_errors[] = array('custom_field_empty', array($row['field_name'])); |
|
498 | + } |
|
459 | 499 | } |
460 | 500 | $smcFunc['db_free_result']($request); |
461 | 501 | |
@@ -463,8 +503,9 @@ discard block |
||
463 | 503 | if (!empty($custom_field_errors)) |
464 | 504 | { |
465 | 505 | loadLanguage('Errors'); |
466 | - foreach ($custom_field_errors as $error) |
|
467 | - $reg_errors[] = vsprintf($txt['error_' . $error[0]], $error[1]); |
|
506 | + foreach ($custom_field_errors as $error) { |
|
507 | + $reg_errors[] = vsprintf($txt['error_' . $error[0]], $error[1]); |
|
508 | + } |
|
468 | 509 | } |
469 | 510 | |
470 | 511 | // Lets check for other errors before trying to register the member. |
@@ -509,8 +550,9 @@ discard block |
||
509 | 550 | } |
510 | 551 | |
511 | 552 | // If COPPA has been selected then things get complicated, setup the template. |
512 | - if (!empty($modSettings['coppaAge']) && empty($_SESSION['skip_coppa'])) |
|
513 | - redirectexit('action=coppa;member=' . $memberID); |
|
553 | + if (!empty($modSettings['coppaAge']) && empty($_SESSION['skip_coppa'])) { |
|
554 | + redirectexit('action=coppa;member=' . $memberID); |
|
555 | + } |
|
514 | 556 | // Basic template variable setup. |
515 | 557 | elseif (!empty($modSettings['registration_method'])) |
516 | 558 | { |
@@ -522,8 +564,7 @@ discard block |
||
522 | 564 | 'sub_template' => 'after', |
523 | 565 | 'description' => $modSettings['registration_method'] == 2 ? $txt['approval_after_registration'] : $txt['activate_after_registration'] |
524 | 566 | ); |
525 | - } |
|
526 | - else |
|
567 | + } else |
|
527 | 568 | { |
528 | 569 | call_integration_hook('integrate_activate', array($regOptions['username'])); |
529 | 570 | |
@@ -543,16 +584,18 @@ discard block |
||
543 | 584 | global $context, $txt, $modSettings, $scripturl, $sourcedir, $smcFunc, $language, $user_info; |
544 | 585 | |
545 | 586 | // Logged in users should not bother to activate their accounts |
546 | - if (!empty($user_info['id'])) |
|
547 | - redirectexit(); |
|
587 | + if (!empty($user_info['id'])) { |
|
588 | + redirectexit(); |
|
589 | + } |
|
548 | 590 | |
549 | 591 | loadLanguage('Login'); |
550 | 592 | loadTemplate('Login'); |
551 | 593 | |
552 | 594 | if (empty($_REQUEST['u']) && empty($_POST['user'])) |
553 | 595 | { |
554 | - if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == '3') |
|
555 | - fatal_lang_error('no_access', false); |
|
596 | + if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == '3') { |
|
597 | + fatal_lang_error('no_access', false); |
|
598 | + } |
|
556 | 599 | |
557 | 600 | $context['member_id'] = 0; |
558 | 601 | $context['sub_template'] = 'resend'; |
@@ -592,11 +635,13 @@ discard block |
||
592 | 635 | // Change their email address? (they probably tried a fake one first :P.) |
593 | 636 | if (isset($_POST['new_email'], $_REQUEST['passwd']) && hash_password($row['member_name'], $_REQUEST['passwd']) == $row['passwd'] && ($row['is_activated'] == 0 || $row['is_activated'] == 2)) |
594 | 637 | { |
595 | - if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == 3) |
|
596 | - fatal_lang_error('no_access', false); |
|
638 | + if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == 3) { |
|
639 | + fatal_lang_error('no_access', false); |
|
640 | + } |
|
597 | 641 | |
598 | - if (!filter_var($_POST['new_email'], FILTER_VALIDATE_EMAIL)) |
|
599 | - fatal_error(sprintf($txt['valid_email_needed'], $smcFunc['htmlspecialchars']($_POST['new_email'])), false); |
|
642 | + if (!filter_var($_POST['new_email'], FILTER_VALIDATE_EMAIL)) { |
|
643 | + fatal_error(sprintf($txt['valid_email_needed'], $smcFunc['htmlspecialchars']($_POST['new_email'])), false); |
|
644 | + } |
|
600 | 645 | |
601 | 646 | // Make sure their email isn't banned. |
602 | 647 | isBannedEmail($_POST['new_email'], 'cannot_register', $txt['ban_register_prohibited']); |
@@ -612,8 +657,9 @@ discard block |
||
612 | 657 | ) |
613 | 658 | ); |
614 | 659 | |
615 | - if ($smcFunc['db_num_rows']($request) != 0) |
|
616 | - fatal_lang_error('email_in_use', false, array($smcFunc['htmlspecialchars']($_POST['new_email']))); |
|
660 | + if ($smcFunc['db_num_rows']($request) != 0) { |
|
661 | + fatal_lang_error('email_in_use', false, array($smcFunc['htmlspecialchars']($_POST['new_email']))); |
|
662 | + } |
|
617 | 663 | $smcFunc['db_free_result']($request); |
618 | 664 | |
619 | 665 | updateMemberData($row['id_member'], array('email_address' => $_POST['new_email'])); |
@@ -651,9 +697,9 @@ discard block |
||
651 | 697 | // Quit if this code is not right. |
652 | 698 | if (empty($_REQUEST['code']) || $row['validation_code'] != $_REQUEST['code']) |
653 | 699 | { |
654 | - if (!empty($row['is_activated'])) |
|
655 | - fatal_lang_error('already_activated', false); |
|
656 | - elseif ($row['validation_code'] == '') |
|
700 | + if (!empty($row['is_activated'])) { |
|
701 | + fatal_lang_error('already_activated', false); |
|
702 | + } elseif ($row['validation_code'] == '') |
|
657 | 703 | { |
658 | 704 | loadLanguage('Profile'); |
659 | 705 | fatal_error(sprintf($txt['registration_not_approved'], $scripturl . '?action=activate;user=' . $row['member_name']), false); |
@@ -703,8 +749,9 @@ discard block |
||
703 | 749 | loadTemplate('Register'); |
704 | 750 | |
705 | 751 | // No User ID?? |
706 | - if (!isset($_GET['member'])) |
|
707 | - fatal_lang_error('no_access', false); |
|
752 | + if (!isset($_GET['member'])) { |
|
753 | + fatal_lang_error('no_access', false); |
|
754 | + } |
|
708 | 755 | |
709 | 756 | // Get the user details... |
710 | 757 | $request = $smcFunc['db_query']('', ' |
@@ -717,8 +764,9 @@ discard block |
||
717 | 764 | 'is_coppa' => 5, |
718 | 765 | ) |
719 | 766 | ); |
720 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
721 | - fatal_lang_error('no_access', false); |
|
767 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
768 | + fatal_lang_error('no_access', false); |
|
769 | + } |
|
722 | 770 | list ($username) = $smcFunc['db_fetch_row']($request); |
723 | 771 | $smcFunc['db_free_result']($request); |
724 | 772 | |
@@ -756,8 +804,7 @@ discard block |
||
756 | 804 | echo $data; |
757 | 805 | obExit(false); |
758 | 806 | } |
759 | - } |
|
760 | - else |
|
807 | + } else |
|
761 | 808 | { |
762 | 809 | $context += array( |
763 | 810 | 'page_title' => $txt['coppa_title'], |
@@ -810,8 +857,9 @@ discard block |
||
810 | 857 | { |
811 | 858 | require_once($sourcedir . '/Subs-Graphics.php'); |
812 | 859 | |
813 | - if (in_array('gd', get_loaded_extensions()) && !showCodeImage($code)) |
|
814 | - header('HTTP/1.1 400 Bad Request'); |
|
860 | + if (in_array('gd', get_loaded_extensions()) && !showCodeImage($code)) { |
|
861 | + header('HTTP/1.1 400 Bad Request'); |
|
862 | + } |
|
815 | 863 | |
816 | 864 | // Otherwise just show a pre-defined letter. |
817 | 865 | elseif (isset($_REQUEST['letter'])) |
@@ -829,14 +877,13 @@ discard block |
||
829 | 877 | header('Content-Type: image/gif'); |
830 | 878 | die("\x47\x49\x46\x38\x39\x61\x01\x00\x01\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x21\xF9\x04\x01\x00\x00\x00\x00\x2C\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02\x44\x01\x00\x3B"); |
831 | 879 | } |
832 | - } |
|
833 | - |
|
834 | - elseif ($_REQUEST['format'] === '.wav') |
|
880 | + } elseif ($_REQUEST['format'] === '.wav') |
|
835 | 881 | { |
836 | 882 | require_once($sourcedir . '/Subs-Sound.php'); |
837 | 883 | |
838 | - if (!createWaveFile($code)) |
|
839 | - header('HTTP/1.1 400 Bad Request'); |
|
884 | + if (!createWaveFile($code)) { |
|
885 | + header('HTTP/1.1 400 Bad Request'); |
|
886 | + } |
|
840 | 887 | } |
841 | 888 | |
842 | 889 | // We all die one day... |
@@ -2259,9 +2259,9 @@ discard block |
||
2259 | 2259 | * |
2260 | 2260 | * @uses the template_include() function to include the file. |
2261 | 2261 | * @param string $template_name The name of the template to load |
2262 | - * @param array|string $style_sheets The name of a single stylesheet or an array of names of stylesheets to load |
|
2262 | + * @param string $style_sheets The name of a single stylesheet or an array of names of stylesheets to load |
|
2263 | 2263 | * @param bool $fatal If true, dies with an error message if the template cannot be found |
2264 | - * @return boolean Whether or not the template was loaded |
|
2264 | + * @return boolean|null Whether or not the template was loaded |
|
2265 | 2265 | */ |
2266 | 2266 | function loadTemplate($template_name, $style_sheets = array(), $fatal = true) |
2267 | 2267 | { |
@@ -2444,7 +2444,7 @@ discard block |
||
2444 | 2444 | * - all code added with this function is added to the same <style> tag so do make sure your css is valid! |
2445 | 2445 | * |
2446 | 2446 | * @param string $css Some css code |
2447 | - * @return void|bool Adds the CSS to the $context['css_header'] array or returns if no CSS is specified |
|
2447 | + * @return false|null Adds the CSS to the $context['css_header'] array or returns if no CSS is specified |
|
2448 | 2448 | */ |
2449 | 2449 | function addInlineCss($css) |
2450 | 2450 | { |
@@ -2460,7 +2460,7 @@ discard block |
||
2460 | 2460 | /** |
2461 | 2461 | * Add a Javascript file for output later |
2462 | 2462 | * |
2463 | - * @param string $filename The name of the file to load |
|
2463 | + * @param string $fileName The name of the file to load |
|
2464 | 2464 | * @param array $params An array of parameter info |
2465 | 2465 | * Keys are the following: |
2466 | 2466 | * - ['external'] (true/false): define if the file is a externally located file. Needs to be set to true if you are loading an external file |
@@ -2558,7 +2558,7 @@ discard block |
||
2558 | 2558 | * |
2559 | 2559 | * @param string $javascript Some JS code |
2560 | 2560 | * @param bool $defer Whether the script should load in <head> or before the closing <html> tag |
2561 | - * @return void|bool Adds the code to one of the $context['javascript_inline'] arrays or returns if no JS was specified |
|
2561 | + * @return false|null Adds the code to one of the $context['javascript_inline'] arrays or returns if no JS was specified |
|
2562 | 2562 | */ |
2563 | 2563 | function addInlineJavaScript($javascript, $defer = false) |
2564 | 2564 | { |
@@ -2791,7 +2791,7 @@ discard block |
||
2791 | 2791 | * It will try to choose only utf8 or non-utf8 languages. |
2792 | 2792 | * |
2793 | 2793 | * @param bool $use_cache Whether or not to use the cache |
2794 | - * @return array An array of information about available languages |
|
2794 | + * @return string An array of information about available languages |
|
2795 | 2795 | */ |
2796 | 2796 | function getLanguages($use_cache = true) |
2797 | 2797 | { |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 4 |
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 | * Load the $modSettings array. |
@@ -25,13 +26,14 @@ discard block |
||
25 | 26 | global $cache_enable, $sourcedir, $context; |
26 | 27 | |
27 | 28 | // Most database systems have not set UTF-8 as their default input charset. |
28 | - if (!empty($db_character_set)) |
|
29 | - $smcFunc['db_query']('', ' |
|
29 | + if (!empty($db_character_set)) { |
|
30 | + $smcFunc['db_query']('', ' |
|
30 | 31 | SET NAMES {string:db_character_set}', |
31 | 32 | array( |
32 | 33 | 'db_character_set' => $db_character_set, |
33 | 34 | ) |
34 | 35 | ); |
36 | + } |
|
35 | 37 | |
36 | 38 | // We need some caching support, maybe. |
37 | 39 | loadCacheAccelerator(); |
@@ -46,28 +48,36 @@ discard block |
||
46 | 48 | ) |
47 | 49 | ); |
48 | 50 | $modSettings = array(); |
49 | - if (!$request) |
|
50 | - display_db_error(); |
|
51 | - while ($row = $smcFunc['db_fetch_row']($request)) |
|
52 | - $modSettings[$row[0]] = $row[1]; |
|
51 | + if (!$request) { |
|
52 | + display_db_error(); |
|
53 | + } |
|
54 | + while ($row = $smcFunc['db_fetch_row']($request)) { |
|
55 | + $modSettings[$row[0]] = $row[1]; |
|
56 | + } |
|
53 | 57 | $smcFunc['db_free_result']($request); |
54 | 58 | |
55 | 59 | // Do a few things to protect against missing settings or settings with invalid values... |
56 | - if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999) |
|
57 | - $modSettings['defaultMaxTopics'] = 20; |
|
58 | - if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999) |
|
59 | - $modSettings['defaultMaxMessages'] = 15; |
|
60 | - if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999) |
|
61 | - $modSettings['defaultMaxMembers'] = 30; |
|
62 | - if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999) |
|
63 | - $modSettings['defaultMaxListItems'] = 15; |
|
60 | + if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999) { |
|
61 | + $modSettings['defaultMaxTopics'] = 20; |
|
62 | + } |
|
63 | + if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999) { |
|
64 | + $modSettings['defaultMaxMessages'] = 15; |
|
65 | + } |
|
66 | + if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999) { |
|
67 | + $modSettings['defaultMaxMembers'] = 30; |
|
68 | + } |
|
69 | + if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999) { |
|
70 | + $modSettings['defaultMaxListItems'] = 15; |
|
71 | + } |
|
64 | 72 | |
65 | 73 | // We excpiclity do not use $smcFunc['json_decode'] here yet, as $smcFunc is not fully loaded. |
66 | - if (!is_array($modSettings['attachmentUploadDir'])) |
|
67 | - $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
74 | + if (!is_array($modSettings['attachmentUploadDir'])) { |
|
75 | + $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
76 | + } |
|
68 | 77 | |
69 | - if (!empty($cache_enable)) |
|
70 | - cache_put_data('modSettings', $modSettings, 90); |
|
78 | + if (!empty($cache_enable)) { |
|
79 | + cache_put_data('modSettings', $modSettings, 90); |
|
80 | + } |
|
71 | 81 | } |
72 | 82 | |
73 | 83 | $modSettings['cache_enable'] = $cache_enable; |
@@ -87,8 +97,9 @@ discard block |
||
87 | 97 | }; |
88 | 98 | $fix_utf8mb4 = function($string) use ($utf8, $smcFunc) |
89 | 99 | { |
90 | - if (!$utf8 || $smcFunc['db_mb4']) |
|
91 | - return $string; |
|
100 | + if (!$utf8 || $smcFunc['db_mb4']) { |
|
101 | + return $string; |
|
102 | + } |
|
92 | 103 | |
93 | 104 | $i = 0; |
94 | 105 | $len = strlen($string); |
@@ -100,18 +111,15 @@ discard block |
||
100 | 111 | { |
101 | 112 | $new_string .= $string[$i]; |
102 | 113 | $i++; |
103 | - } |
|
104 | - elseif ($ord < 224) |
|
114 | + } elseif ($ord < 224) |
|
105 | 115 | { |
106 | 116 | $new_string .= $string[$i] . $string[$i + 1]; |
107 | 117 | $i += 2; |
108 | - } |
|
109 | - elseif ($ord < 240) |
|
118 | + } elseif ($ord < 240) |
|
110 | 119 | { |
111 | 120 | $new_string .= $string[$i] . $string[$i + 1] . $string[$i + 2]; |
112 | 121 | $i += 3; |
113 | - } |
|
114 | - elseif ($ord < 248) |
|
122 | + } elseif ($ord < 248) |
|
115 | 123 | { |
116 | 124 | // Magic happens. |
117 | 125 | $val = (ord($string[$i]) & 0x07) << 18; |
@@ -155,8 +163,7 @@ discard block |
||
155 | 163 | { |
156 | 164 | $result = array_search($needle, array_slice($haystack_arr, $offset)); |
157 | 165 | return is_int($result) ? $result + $offset : false; |
158 | - } |
|
159 | - else |
|
166 | + } else |
|
160 | 167 | { |
161 | 168 | $needle_arr = preg_split('~(&#' . (empty($modSettings['disableEntityCheck']) ? '\d{1,7}' : '021') . ';|"|&|<|>| |.)~' . ($utf8 ? 'u' : '') . '', $ent_check($needle), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); |
162 | 169 | $needle_size = count($needle_arr); |
@@ -165,8 +172,9 @@ discard block |
||
165 | 172 | while ((int) $result === $result) |
166 | 173 | { |
167 | 174 | $offset += $result; |
168 | - if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) |
|
169 | - return $offset; |
|
175 | + if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) { |
|
176 | + return $offset; |
|
177 | + } |
|
170 | 178 | $result = array_search($needle_arr[0], array_slice($haystack_arr, ++$offset)); |
171 | 179 | } |
172 | 180 | return false; |
@@ -204,8 +212,9 @@ discard block |
||
204 | 212 | $string = $ent_check($string); |
205 | 213 | preg_match('~^(' . $ent_list . '|.){' . $smcFunc['strlen'](substr($string, 0, $length)) . '}~' . ($utf8 ? 'u' : ''), $string, $matches); |
206 | 214 | $string = $matches[0]; |
207 | - while (strlen($string) > $length) |
|
208 | - $string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string); |
|
215 | + while (strlen($string) > $length) { |
|
216 | + $string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string); |
|
217 | + } |
|
209 | 218 | return $string; |
210 | 219 | }, |
211 | 220 | 'ucfirst' => $utf8 ? function($string) use (&$smcFunc) |
@@ -215,8 +224,9 @@ discard block |
||
215 | 224 | 'ucwords' => $utf8 ? function($string) use (&$smcFunc) |
216 | 225 | { |
217 | 226 | $words = preg_split('~([\s\r\n\t]+)~', $string, -1, PREG_SPLIT_DELIM_CAPTURE); |
218 | - for ($i = 0, $n = count($words); $i < $n; $i += 2) |
|
219 | - $words[$i] = $smcFunc['ucfirst']($words[$i]); |
|
227 | + for ($i = 0, $n = count($words); $i < $n; $i += 2) { |
|
228 | + $words[$i] = $smcFunc['ucfirst']($words[$i]); |
|
229 | + } |
|
220 | 230 | return implode('', $words); |
221 | 231 | } : 'ucwords', |
222 | 232 | 'json_decode' => 'smf_json_decode', |
@@ -224,16 +234,17 @@ discard block |
||
224 | 234 | ); |
225 | 235 | |
226 | 236 | // Setting the timezone is a requirement for some functions. |
227 | - if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list())) |
|
228 | - date_default_timezone_set($modSettings['default_timezone']); |
|
229 | - else |
|
237 | + if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list())) { |
|
238 | + date_default_timezone_set($modSettings['default_timezone']); |
|
239 | + } else |
|
230 | 240 | { |
231 | 241 | // Get PHP's default timezone, if set |
232 | 242 | $ini_tz = ini_get('date.timezone'); |
233 | - if (!empty($ini_tz)) |
|
234 | - $modSettings['default_timezone'] = $ini_tz; |
|
235 | - else |
|
236 | - $modSettings['default_timezone'] = ''; |
|
243 | + if (!empty($ini_tz)) { |
|
244 | + $modSettings['default_timezone'] = $ini_tz; |
|
245 | + } else { |
|
246 | + $modSettings['default_timezone'] = ''; |
|
247 | + } |
|
237 | 248 | |
238 | 249 | // If date.timezone is unset, invalid, or just plain weird, make a best guess |
239 | 250 | if (!in_array($modSettings['default_timezone'], timezone_identifiers_list())) |
@@ -251,22 +262,26 @@ discard block |
||
251 | 262 | if (($modSettings['load_average'] = cache_get_data('loadavg', 90)) == null) |
252 | 263 | { |
253 | 264 | $modSettings['load_average'] = @file_get_contents('/proc/loadavg'); |
254 | - if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) |
|
255 | - $modSettings['load_average'] = (float) $matches[1]; |
|
256 | - elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) |
|
257 | - $modSettings['load_average'] = (float) $matches[1]; |
|
258 | - else |
|
259 | - unset($modSettings['load_average']); |
|
265 | + if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) { |
|
266 | + $modSettings['load_average'] = (float) $matches[1]; |
|
267 | + } elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) { |
|
268 | + $modSettings['load_average'] = (float) $matches[1]; |
|
269 | + } else { |
|
270 | + unset($modSettings['load_average']); |
|
271 | + } |
|
260 | 272 | |
261 | - if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) |
|
262 | - cache_put_data('loadavg', $modSettings['load_average'], 90); |
|
273 | + if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) { |
|
274 | + cache_put_data('loadavg', $modSettings['load_average'], 90); |
|
275 | + } |
|
263 | 276 | } |
264 | 277 | |
265 | - if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) |
|
266 | - call_integration_hook('integrate_load_average', array($modSettings['load_average'])); |
|
278 | + if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) { |
|
279 | + call_integration_hook('integrate_load_average', array($modSettings['load_average'])); |
|
280 | + } |
|
267 | 281 | |
268 | - if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) |
|
269 | - display_loadavg_error(); |
|
282 | + if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) { |
|
283 | + display_loadavg_error(); |
|
284 | + } |
|
270 | 285 | } |
271 | 286 | |
272 | 287 | // Is post moderation alive and well? Everywhere else assumes this has been defined, so let's make sure it is. |
@@ -287,8 +302,9 @@ discard block |
||
287 | 302 | if (defined('SMF_INTEGRATION_SETTINGS')) |
288 | 303 | { |
289 | 304 | $integration_settings = $smcFUnc['json_decode'](SMF_INTEGRATION_SETTINGS, true); |
290 | - foreach ($integration_settings as $hook => $function) |
|
291 | - add_integration_function($hook, $function, '', false); |
|
305 | + foreach ($integration_settings as $hook => $function) { |
|
306 | + add_integration_function($hook, $function, '', false); |
|
307 | + } |
|
292 | 308 | } |
293 | 309 | |
294 | 310 | // Any files to pre include? |
@@ -298,8 +314,9 @@ discard block |
||
298 | 314 | foreach ($pre_includes as $include) |
299 | 315 | { |
300 | 316 | $include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
301 | - if (file_exists($include)) |
|
302 | - require_once($include); |
|
317 | + if (file_exists($include)) { |
|
318 | + require_once($include); |
|
319 | + } |
|
303 | 320 | } |
304 | 321 | } |
305 | 322 | |
@@ -403,27 +420,28 @@ discard block |
||
403 | 420 | break; |
404 | 421 | } |
405 | 422 | } |
423 | + } else { |
|
424 | + $id_member = 0; |
|
406 | 425 | } |
407 | - else |
|
408 | - $id_member = 0; |
|
409 | 426 | |
410 | 427 | if (empty($id_member) && isset($_COOKIE[$cookiename])) |
411 | 428 | { |
412 | 429 | $cookie_data = $smcFunc['json_decode']($_COOKIE[$cookiename], true, false); |
413 | 430 | |
414 | - if (empty($cookie_data)) |
|
415 | - $cookie_data = safe_unserialize($_COOKIE[$cookiename]); |
|
431 | + if (empty($cookie_data)) { |
|
432 | + $cookie_data = safe_unserialize($_COOKIE[$cookiename]); |
|
433 | + } |
|
416 | 434 | |
417 | 435 | list ($id_member, $password) = $cookie_data; |
418 | 436 | $id_member = !empty($id_member) && strlen($password) > 0 ? (int) $id_member : 0; |
419 | - } |
|
420 | - elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA']))) |
|
437 | + } elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA']))) |
|
421 | 438 | { |
422 | 439 | // @todo Perhaps we can do some more checking on this, such as on the first octet of the IP? |
423 | 440 | $cookie_data = $smcFunc['json_decode']($_SESSION['login_' . $cookiename]); |
424 | 441 | |
425 | - if (empty($cookie_data)) |
|
426 | - $cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]); |
|
442 | + if (empty($cookie_data)) { |
|
443 | + $cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]); |
|
444 | + } |
|
427 | 445 | |
428 | 446 | list ($id_member, $password, $login_span) = $cookie_data; |
429 | 447 | $id_member = !empty($id_member) && strlen($password) == 128 && $login_span > time() ? (int) $id_member : 0; |
@@ -448,30 +466,34 @@ discard block |
||
448 | 466 | $user_settings = $smcFunc['db_fetch_assoc']($request); |
449 | 467 | $smcFunc['db_free_result']($request); |
450 | 468 | |
451 | - if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false) |
|
452 | - $user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret); |
|
469 | + if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false) { |
|
470 | + $user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret); |
|
471 | + } |
|
453 | 472 | |
454 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
455 | - cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
473 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
474 | + cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
475 | + } |
|
456 | 476 | } |
457 | 477 | |
458 | 478 | // Did we find 'im? If not, junk it. |
459 | 479 | if (!empty($user_settings)) |
460 | 480 | { |
461 | 481 | // As much as the password should be right, we can assume the integration set things up. |
462 | - if (!empty($already_verified) && $already_verified === true) |
|
463 | - $check = true; |
|
482 | + if (!empty($already_verified) && $already_verified === true) { |
|
483 | + $check = true; |
|
484 | + } |
|
464 | 485 | // SHA-512 hash should be 128 characters long. |
465 | - elseif (strlen($password) == 128) |
|
466 | - $check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password; |
|
467 | - else |
|
468 | - $check = false; |
|
486 | + elseif (strlen($password) == 128) { |
|
487 | + $check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password; |
|
488 | + } else { |
|
489 | + $check = false; |
|
490 | + } |
|
469 | 491 | |
470 | 492 | // Wrong password or not activated - either way, you're going nowhere. |
471 | 493 | $id_member = $check && ($user_settings['is_activated'] == 1 || $user_settings['is_activated'] == 11) ? (int) $user_settings['id_member'] : 0; |
494 | + } else { |
|
495 | + $id_member = 0; |
|
472 | 496 | } |
473 | - else |
|
474 | - $id_member = 0; |
|
475 | 497 | |
476 | 498 | // If we no longer have the member maybe they're being all hackey, stop brute force! |
477 | 499 | if (!$id_member) |
@@ -495,8 +517,9 @@ discard block |
||
495 | 517 | |
496 | 518 | list ($tfamember, $tfasecret) = $tfa_data; |
497 | 519 | |
498 | - if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member) |
|
499 | - $tfasecret = null; |
|
520 | + if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member) { |
|
521 | + $tfasecret = null; |
|
522 | + } |
|
500 | 523 | } |
501 | 524 | |
502 | 525 | if (empty($tfasecret) || hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']) != $tfasecret) |
@@ -516,10 +539,12 @@ discard block |
||
516 | 539 | // Are we forcing 2FA? Need to check if the user groups actually require 2FA |
517 | 540 | elseif (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] >= 2 && $id_member && empty($user_settings['tfa_secret'])) |
518 | 541 | { |
519 | - if ($modSettings['tfa_mode'] == 2) //only do this if we are just forcing SOME membergroups |
|
542 | + if ($modSettings['tfa_mode'] == 2) { |
|
543 | + //only do this if we are just forcing SOME membergroups |
|
520 | 544 | { |
521 | 545 | //Build an array of ALL user membergroups. |
522 | 546 | $full_groups = array($user_settings['id_group']); |
547 | + } |
|
523 | 548 | if (!empty($user_settings['additional_groups'])) |
524 | 549 | { |
525 | 550 | $full_groups = array_merge($full_groups, explode(',', $user_settings['additional_groups'])); |
@@ -539,15 +564,17 @@ discard block |
||
539 | 564 | ); |
540 | 565 | $row = $smcFunc['db_fetch_assoc']($request); |
541 | 566 | $smcFunc['db_free_result']($request); |
567 | + } else { |
|
568 | + $row['total'] = 1; |
|
542 | 569 | } |
543 | - else |
|
544 | - $row['total'] = 1; //simplifies logics in the next "if" |
|
570 | + //simplifies logics in the next "if" |
|
545 | 571 | |
546 | 572 | $area = !empty($_REQUEST['area']) ? $_REQUEST['area'] : ''; |
547 | 573 | $action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : ''; |
548 | 574 | |
549 | - if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) |
|
550 | - redirectexit('action=profile;area=tfasetup;forced'); |
|
575 | + if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) { |
|
576 | + redirectexit('action=profile;area=tfasetup;forced'); |
|
577 | + } |
|
551 | 578 | } |
552 | 579 | } |
553 | 580 | |
@@ -584,33 +611,37 @@ discard block |
||
584 | 611 | updateMemberData($id_member, array('id_msg_last_visit' => (int) $modSettings['maxMsgID'], 'last_login' => time(), 'member_ip' => $_SERVER['REMOTE_ADDR'], 'member_ip2' => $_SERVER['BAN_CHECK_IP'])); |
585 | 612 | $user_settings['last_login'] = time(); |
586 | 613 | |
587 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
588 | - cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
614 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
615 | + cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
616 | + } |
|
589 | 617 | |
590 | - if (!empty($modSettings['cache_enable'])) |
|
591 | - cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600); |
|
618 | + if (!empty($modSettings['cache_enable'])) { |
|
619 | + cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600); |
|
620 | + } |
|
592 | 621 | } |
622 | + } elseif (empty($_SESSION['id_msg_last_visit'])) { |
|
623 | + $_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit']; |
|
593 | 624 | } |
594 | - elseif (empty($_SESSION['id_msg_last_visit'])) |
|
595 | - $_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit']; |
|
596 | 625 | |
597 | 626 | $username = $user_settings['member_name']; |
598 | 627 | |
599 | - if (empty($user_settings['additional_groups'])) |
|
600 | - $user_info = array( |
|
628 | + if (empty($user_settings['additional_groups'])) { |
|
629 | + $user_info = array( |
|
601 | 630 | 'groups' => array($user_settings['id_group'], $user_settings['id_post_group']) |
602 | 631 | ); |
603 | - else |
|
604 | - $user_info = array( |
|
632 | + } else { |
|
633 | + $user_info = array( |
|
605 | 634 | 'groups' => array_merge( |
606 | 635 | array($user_settings['id_group'], $user_settings['id_post_group']), |
607 | 636 | explode(',', $user_settings['additional_groups']) |
608 | 637 | ) |
609 | 638 | ); |
639 | + } |
|
610 | 640 | |
611 | 641 | // Because history has proven that it is possible for groups to go bad - clean up in case. |
612 | - foreach ($user_info['groups'] as $k => $v) |
|
613 | - $user_info['groups'][$k] = (int) $v; |
|
642 | + foreach ($user_info['groups'] as $k => $v) { |
|
643 | + $user_info['groups'][$k] = (int) $v; |
|
644 | + } |
|
614 | 645 | |
615 | 646 | // This is a logged in user, so definitely not a spider. |
616 | 647 | $user_info['possibly_robot'] = false; |
@@ -624,8 +655,7 @@ discard block |
||
624 | 655 | $time_system = new DateTime('now', $tz_system); |
625 | 656 | $time_user = new DateTime('now', $tz_user); |
626 | 657 | $user_info['time_offset'] = ($tz_user->getOffset($time_user) - $tz_system->getOffset($time_system)) / 3600; |
627 | - } |
|
628 | - else |
|
658 | + } else |
|
629 | 659 | { |
630 | 660 | // !!! Compatibility. |
631 | 661 | $user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 : $user_settings['time_offset']; |
@@ -639,8 +669,9 @@ discard block |
||
639 | 669 | $user_info = array('groups' => array(-1)); |
640 | 670 | $user_settings = array(); |
641 | 671 | |
642 | - if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) |
|
643 | - $_COOKIE[$cookiename] = ''; |
|
672 | + if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) { |
|
673 | + $_COOKIE[$cookiename] = ''; |
|
674 | + } |
|
644 | 675 | |
645 | 676 | // Expire the 2FA cookie |
646 | 677 | if (isset($_COOKIE[$cookiename . '_tfa']) && empty($context['tfa_member'])) |
@@ -657,19 +688,20 @@ discard block |
||
657 | 688 | } |
658 | 689 | |
659 | 690 | // Create a login token if it doesn't exist yet. |
660 | - if (!isset($_SESSION['token']['post-login'])) |
|
661 | - createToken('login'); |
|
662 | - else |
|
663 | - list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login']; |
|
691 | + if (!isset($_SESSION['token']['post-login'])) { |
|
692 | + createToken('login'); |
|
693 | + } else { |
|
694 | + list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login']; |
|
695 | + } |
|
664 | 696 | |
665 | 697 | // Do we perhaps think this is a search robot? Check every five minutes just in case... |
666 | 698 | if ((!empty($modSettings['spider_mode']) || !empty($modSettings['spider_group'])) && (!isset($_SESSION['robot_check']) || $_SESSION['robot_check'] < time() - 300)) |
667 | 699 | { |
668 | 700 | require_once($sourcedir . '/ManageSearchEngines.php'); |
669 | 701 | $user_info['possibly_robot'] = SpiderCheck(); |
702 | + } elseif (!empty($modSettings['spider_mode'])) { |
|
703 | + $user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0; |
|
670 | 704 | } |
671 | - elseif (!empty($modSettings['spider_mode'])) |
|
672 | - $user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0; |
|
673 | 705 | // If we haven't turned on proper spider hunts then have a guess! |
674 | 706 | else |
675 | 707 | { |
@@ -717,8 +749,9 @@ discard block |
||
717 | 749 | $user_info['groups'] = array_unique($user_info['groups']); |
718 | 750 | |
719 | 751 | // Make sure that the last item in the ignore boards array is valid. If the list was too long it could have an ending comma that could cause problems. |
720 | - if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) |
|
721 | - unset($user_info['ignoreboards'][$tmp]); |
|
752 | + if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) { |
|
753 | + unset($user_info['ignoreboards'][$tmp]); |
|
754 | + } |
|
722 | 755 | |
723 | 756 | // Allow the user to change their language. |
724 | 757 | if (!empty($modSettings['userLanguage'])) |
@@ -731,31 +764,36 @@ discard block |
||
731 | 764 | $user_info['language'] = strtr($_GET['language'], './\\:', '____'); |
732 | 765 | |
733 | 766 | // Make it permanent for members. |
734 | - if (!empty($user_info['id'])) |
|
735 | - updateMemberData($user_info['id'], array('lngfile' => $user_info['language'])); |
|
736 | - else |
|
737 | - $_SESSION['language'] = $user_info['language']; |
|
767 | + if (!empty($user_info['id'])) { |
|
768 | + updateMemberData($user_info['id'], array('lngfile' => $user_info['language'])); |
|
769 | + } else { |
|
770 | + $_SESSION['language'] = $user_info['language']; |
|
771 | + } |
|
772 | + } elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) { |
|
773 | + $user_info['language'] = strtr($_SESSION['language'], './\\:', '____'); |
|
738 | 774 | } |
739 | - elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) |
|
740 | - $user_info['language'] = strtr($_SESSION['language'], './\\:', '____'); |
|
741 | 775 | } |
742 | 776 | |
743 | 777 | // Just build this here, it makes it easier to change/use - administrators can see all boards. |
744 | - if ($user_info['is_admin']) |
|
745 | - $user_info['query_see_board'] = '1=1'; |
|
778 | + if ($user_info['is_admin']) { |
|
779 | + $user_info['query_see_board'] = '1=1'; |
|
780 | + } |
|
746 | 781 | // Otherwise just the groups in $user_info['groups']. |
747 | - else |
|
748 | - $user_info['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $user_info['groups']) . ', b.member_groups) != 0)' . (!empty($modSettings['deny_boards_access']) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $user_info['groups']) . ', b.deny_member_groups) = 0)' : '') . (isset($user_info['mod_cache']) ? ' OR ' . $user_info['mod_cache']['mq'] : '') . ')'; |
|
782 | + else { |
|
783 | + $user_info['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $user_info['groups']) . ', b.member_groups) != 0)' . (!empty($modSettings['deny_boards_access']) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $user_info['groups']) . ', b.deny_member_groups) = 0)' : '') . (isset($user_info['mod_cache']) ? ' OR ' . $user_info['mod_cache']['mq'] : '') . ')'; |
|
784 | + } |
|
749 | 785 | |
750 | 786 | // Build the list of boards they WANT to see. |
751 | 787 | // This will take the place of query_see_boards in certain spots, so it better include the boards they can see also |
752 | 788 | |
753 | 789 | // If they aren't ignoring any boards then they want to see all the boards they can see |
754 | - if (empty($user_info['ignoreboards'])) |
|
755 | - $user_info['query_wanna_see_board'] = $user_info['query_see_board']; |
|
790 | + if (empty($user_info['ignoreboards'])) { |
|
791 | + $user_info['query_wanna_see_board'] = $user_info['query_see_board']; |
|
792 | + } |
|
756 | 793 | // Ok I guess they don't want to see all the boards |
757 | - else |
|
758 | - $user_info['query_wanna_see_board'] = '(' . $user_info['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $user_info['ignoreboards']) . '))'; |
|
794 | + else { |
|
795 | + $user_info['query_wanna_see_board'] = '(' . $user_info['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $user_info['ignoreboards']) . '))'; |
|
796 | + } |
|
759 | 797 | |
760 | 798 | call_integration_hook('integrate_user_info'); |
761 | 799 | } |
@@ -813,9 +851,9 @@ discard block |
||
813 | 851 | } |
814 | 852 | |
815 | 853 | // Remember redirection is the key to avoiding fallout from your bosses. |
816 | - if (!empty($topic)) |
|
817 | - redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']); |
|
818 | - else |
|
854 | + if (!empty($topic)) { |
|
855 | + redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']); |
|
856 | + } else |
|
819 | 857 | { |
820 | 858 | loadPermissions(); |
821 | 859 | loadTheme(); |
@@ -833,10 +871,11 @@ discard block |
||
833 | 871 | if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3)) |
834 | 872 | { |
835 | 873 | // @todo SLOW? |
836 | - if (!empty($topic)) |
|
837 | - $temp = cache_get_data('topic_board-' . $topic, 120); |
|
838 | - else |
|
839 | - $temp = cache_get_data('board-' . $board, 120); |
|
874 | + if (!empty($topic)) { |
|
875 | + $temp = cache_get_data('topic_board-' . $topic, 120); |
|
876 | + } else { |
|
877 | + $temp = cache_get_data('board-' . $board, 120); |
|
878 | + } |
|
840 | 879 | |
841 | 880 | if (!empty($temp)) |
842 | 881 | { |
@@ -874,8 +913,9 @@ discard block |
||
874 | 913 | $row = $smcFunc['db_fetch_assoc']($request); |
875 | 914 | |
876 | 915 | // Set the current board. |
877 | - if (!empty($row['id_board'])) |
|
878 | - $board = $row['id_board']; |
|
916 | + if (!empty($row['id_board'])) { |
|
917 | + $board = $row['id_board']; |
|
918 | + } |
|
879 | 919 | |
880 | 920 | // Basic operating information. (globals... :/) |
881 | 921 | $board_info = array( |
@@ -911,21 +951,23 @@ discard block |
||
911 | 951 | |
912 | 952 | do |
913 | 953 | { |
914 | - if (!empty($row['id_moderator'])) |
|
915 | - $board_info['moderators'][$row['id_moderator']] = array( |
|
954 | + if (!empty($row['id_moderator'])) { |
|
955 | + $board_info['moderators'][$row['id_moderator']] = array( |
|
916 | 956 | 'id' => $row['id_moderator'], |
917 | 957 | 'name' => $row['real_name'], |
918 | 958 | 'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'], |
919 | 959 | 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>' |
920 | 960 | ); |
961 | + } |
|
921 | 962 | |
922 | - if (!empty($row['id_moderator_group'])) |
|
923 | - $board_info['moderator_groups'][$row['id_moderator_group']] = array( |
|
963 | + if (!empty($row['id_moderator_group'])) { |
|
964 | + $board_info['moderator_groups'][$row['id_moderator_group']] = array( |
|
924 | 965 | 'id' => $row['id_moderator_group'], |
925 | 966 | 'name' => $row['group_name'], |
926 | 967 | 'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'], |
927 | 968 | 'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>' |
928 | 969 | ); |
970 | + } |
|
929 | 971 | } |
930 | 972 | while ($row = $smcFunc['db_fetch_assoc']($request)); |
931 | 973 | |
@@ -957,12 +999,12 @@ discard block |
||
957 | 999 | if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3)) |
958 | 1000 | { |
959 | 1001 | // @todo SLOW? |
960 | - if (!empty($topic)) |
|
961 | - cache_put_data('topic_board-' . $topic, $board_info, 120); |
|
1002 | + if (!empty($topic)) { |
|
1003 | + cache_put_data('topic_board-' . $topic, $board_info, 120); |
|
1004 | + } |
|
962 | 1005 | cache_put_data('board-' . $board, $board_info, 120); |
963 | 1006 | } |
964 | - } |
|
965 | - else |
|
1007 | + } else |
|
966 | 1008 | { |
967 | 1009 | // Otherwise the topic is invalid, there are no moderators, etc. |
968 | 1010 | $board_info = array( |
@@ -976,8 +1018,9 @@ discard block |
||
976 | 1018 | $smcFunc['db_free_result']($request); |
977 | 1019 | } |
978 | 1020 | |
979 | - if (!empty($topic)) |
|
980 | - $_GET['board'] = (int) $board; |
|
1021 | + if (!empty($topic)) { |
|
1022 | + $_GET['board'] = (int) $board; |
|
1023 | + } |
|
981 | 1024 | |
982 | 1025 | if (!empty($board)) |
983 | 1026 | { |
@@ -987,10 +1030,12 @@ discard block |
||
987 | 1030 | // Now check if the user is a moderator. |
988 | 1031 | $user_info['is_mod'] = isset($board_info['moderators'][$user_info['id']]) || count(array_intersect($user_info['groups'], $moderator_groups)) != 0; |
989 | 1032 | |
990 | - if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) |
|
991 | - $board_info['error'] = 'access'; |
|
992 | - if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) |
|
993 | - $board_info['error'] = 'access'; |
|
1033 | + if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) { |
|
1034 | + $board_info['error'] = 'access'; |
|
1035 | + } |
|
1036 | + if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) { |
|
1037 | + $board_info['error'] = 'access'; |
|
1038 | + } |
|
994 | 1039 | |
995 | 1040 | // Build up the linktree. |
996 | 1041 | $context['linktree'] = array_merge( |
@@ -1013,8 +1058,9 @@ discard block |
||
1013 | 1058 | $context['current_board'] = $board; |
1014 | 1059 | |
1015 | 1060 | // No posting in redirection boards! |
1016 | - if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) |
|
1017 | - $board_info['error'] == 'post_in_redirect'; |
|
1061 | + if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) { |
|
1062 | + $board_info['error'] == 'post_in_redirect'; |
|
1063 | + } |
|
1018 | 1064 | |
1019 | 1065 | // Hacker... you can't see this topic, I'll tell you that. (but moderators can!) |
1020 | 1066 | if (!empty($board_info['error']) && (!empty($modSettings['deny_boards_access']) || $board_info['error'] != 'access' || !$user_info['is_mod'])) |
@@ -1040,24 +1086,23 @@ discard block |
||
1040 | 1086 | ob_end_clean(); |
1041 | 1087 | header('HTTP/1.1 403 Forbidden'); |
1042 | 1088 | die; |
1043 | - } |
|
1044 | - elseif ($board_info['error'] == 'post_in_redirect') |
|
1089 | + } elseif ($board_info['error'] == 'post_in_redirect') |
|
1045 | 1090 | { |
1046 | 1091 | // Slightly different error message here... |
1047 | 1092 | fatal_lang_error('cannot_post_redirect', false); |
1048 | - } |
|
1049 | - elseif ($user_info['is_guest']) |
|
1093 | + } elseif ($user_info['is_guest']) |
|
1050 | 1094 | { |
1051 | 1095 | loadLanguage('Errors'); |
1052 | 1096 | is_not_guest($txt['topic_gone']); |
1097 | + } else { |
|
1098 | + fatal_lang_error('topic_gone', false); |
|
1053 | 1099 | } |
1054 | - else |
|
1055 | - fatal_lang_error('topic_gone', false); |
|
1056 | 1100 | } |
1057 | 1101 | |
1058 | - if ($user_info['is_mod']) |
|
1059 | - $user_info['groups'][] = 3; |
|
1060 | -} |
|
1102 | + if ($user_info['is_mod']) { |
|
1103 | + $user_info['groups'][] = 3; |
|
1104 | + } |
|
1105 | + } |
|
1061 | 1106 | |
1062 | 1107 | /** |
1063 | 1108 | * Load this user's permissions. |
@@ -1078,8 +1123,9 @@ discard block |
||
1078 | 1123 | asort($cache_groups); |
1079 | 1124 | $cache_groups = implode(',', $cache_groups); |
1080 | 1125 | // If it's a spider then cache it different. |
1081 | - if ($user_info['possibly_robot']) |
|
1082 | - $cache_groups .= '-spider'; |
|
1126 | + if ($user_info['possibly_robot']) { |
|
1127 | + $cache_groups .= '-spider'; |
|
1128 | + } |
|
1083 | 1129 | |
1084 | 1130 | if ($modSettings['cache_enable'] >= 2 && !empty($board) && ($temp = cache_get_data('permissions:' . $cache_groups . ':' . $board, 240)) != null && time() - 240 > $modSettings['settings_updated']) |
1085 | 1131 | { |
@@ -1087,9 +1133,9 @@ discard block |
||
1087 | 1133 | banPermissions(); |
1088 | 1134 | |
1089 | 1135 | return; |
1136 | + } elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) { |
|
1137 | + list ($user_info['permissions'], $removals) = $temp; |
|
1090 | 1138 | } |
1091 | - elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) |
|
1092 | - list ($user_info['permissions'], $removals) = $temp; |
|
1093 | 1139 | } |
1094 | 1140 | |
1095 | 1141 | // If it is detected as a robot, and we are restricting permissions as a special group - then implement this. |
@@ -1111,23 +1157,26 @@ discard block |
||
1111 | 1157 | $removals = array(); |
1112 | 1158 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1113 | 1159 | { |
1114 | - if (empty($row['add_deny'])) |
|
1115 | - $removals[] = $row['permission']; |
|
1116 | - else |
|
1117 | - $user_info['permissions'][] = $row['permission']; |
|
1160 | + if (empty($row['add_deny'])) { |
|
1161 | + $removals[] = $row['permission']; |
|
1162 | + } else { |
|
1163 | + $user_info['permissions'][] = $row['permission']; |
|
1164 | + } |
|
1118 | 1165 | } |
1119 | 1166 | $smcFunc['db_free_result']($request); |
1120 | 1167 | |
1121 | - if (isset($cache_groups)) |
|
1122 | - cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240); |
|
1168 | + if (isset($cache_groups)) { |
|
1169 | + cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240); |
|
1170 | + } |
|
1123 | 1171 | } |
1124 | 1172 | |
1125 | 1173 | // Get the board permissions. |
1126 | 1174 | if (!empty($board)) |
1127 | 1175 | { |
1128 | 1176 | // Make sure the board (if any) has been loaded by loadBoard(). |
1129 | - if (!isset($board_info['profile'])) |
|
1130 | - fatal_lang_error('no_board'); |
|
1177 | + if (!isset($board_info['profile'])) { |
|
1178 | + fatal_lang_error('no_board'); |
|
1179 | + } |
|
1131 | 1180 | |
1132 | 1181 | $request = $smcFunc['db_query']('', ' |
1133 | 1182 | SELECT permission, add_deny |
@@ -1143,20 +1192,23 @@ discard block |
||
1143 | 1192 | ); |
1144 | 1193 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1145 | 1194 | { |
1146 | - if (empty($row['add_deny'])) |
|
1147 | - $removals[] = $row['permission']; |
|
1148 | - else |
|
1149 | - $user_info['permissions'][] = $row['permission']; |
|
1195 | + if (empty($row['add_deny'])) { |
|
1196 | + $removals[] = $row['permission']; |
|
1197 | + } else { |
|
1198 | + $user_info['permissions'][] = $row['permission']; |
|
1199 | + } |
|
1150 | 1200 | } |
1151 | 1201 | $smcFunc['db_free_result']($request); |
1152 | 1202 | } |
1153 | 1203 | |
1154 | 1204 | // Remove all the permissions they shouldn't have ;). |
1155 | - if (!empty($modSettings['permission_enable_deny'])) |
|
1156 | - $user_info['permissions'] = array_diff($user_info['permissions'], $removals); |
|
1205 | + if (!empty($modSettings['permission_enable_deny'])) { |
|
1206 | + $user_info['permissions'] = array_diff($user_info['permissions'], $removals); |
|
1207 | + } |
|
1157 | 1208 | |
1158 | - if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) |
|
1159 | - cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240); |
|
1209 | + if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) { |
|
1210 | + cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240); |
|
1211 | + } |
|
1160 | 1212 | |
1161 | 1213 | // Banned? Watch, don't touch.. |
1162 | 1214 | banPermissions(); |
@@ -1168,17 +1220,18 @@ discard block |
||
1168 | 1220 | { |
1169 | 1221 | require_once($sourcedir . '/Subs-Auth.php'); |
1170 | 1222 | rebuildModCache(); |
1223 | + } else { |
|
1224 | + $user_info['mod_cache'] = $_SESSION['mc']; |
|
1171 | 1225 | } |
1172 | - else |
|
1173 | - $user_info['mod_cache'] = $_SESSION['mc']; |
|
1174 | 1226 | |
1175 | 1227 | // This is a useful phantom permission added to the current user, and only the current user while they are logged in. |
1176 | 1228 | // For example this drastically simplifies certain changes to the profile area. |
1177 | 1229 | $user_info['permissions'][] = 'is_not_guest'; |
1178 | 1230 | // And now some backwards compatibility stuff for mods and whatnot that aren't expecting the new permissions. |
1179 | 1231 | $user_info['permissions'][] = 'profile_view_own'; |
1180 | - if (in_array('profile_view', $user_info['permissions'])) |
|
1181 | - $user_info['permissions'][] = 'profile_view_any'; |
|
1232 | + if (in_array('profile_view', $user_info['permissions'])) { |
|
1233 | + $user_info['permissions'][] = 'profile_view_any'; |
|
1234 | + } |
|
1182 | 1235 | } |
1183 | 1236 | } |
1184 | 1237 | |
@@ -1196,8 +1249,9 @@ discard block |
||
1196 | 1249 | global $image_proxy_enabled, $image_proxy_secret, $boardurl; |
1197 | 1250 | |
1198 | 1251 | // Can't just look for no users :P. |
1199 | - if (empty($users)) |
|
1200 | - return array(); |
|
1252 | + if (empty($users)) { |
|
1253 | + return array(); |
|
1254 | + } |
|
1201 | 1255 | |
1202 | 1256 | // Pass the set value |
1203 | 1257 | $context['loadMemberContext_set'] = $set; |
@@ -1212,8 +1266,9 @@ discard block |
||
1212 | 1266 | for ($i = 0, $n = count($users); $i < $n; $i++) |
1213 | 1267 | { |
1214 | 1268 | $data = cache_get_data('member_data-' . $set . '-' . $users[$i], 240); |
1215 | - if ($data == null) |
|
1216 | - continue; |
|
1269 | + if ($data == null) { |
|
1270 | + continue; |
|
1271 | + } |
|
1217 | 1272 | |
1218 | 1273 | $loaded_ids[] = $data['id_member']; |
1219 | 1274 | $user_profile[$data['id_member']] = $data; |
@@ -1280,13 +1335,16 @@ discard block |
||
1280 | 1335 | $row['avatar_original'] = !empty($row['avatar']) ? $row['avatar'] : ''; |
1281 | 1336 | |
1282 | 1337 | // Take care of proxying avatar if required, do this here for maximum reach |
1283 | - if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false) |
|
1284 | - $row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret); |
|
1338 | + if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false) { |
|
1339 | + $row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret); |
|
1340 | + } |
|
1285 | 1341 | |
1286 | - if (isset($row['member_ip'])) |
|
1287 | - $row['member_ip'] = inet_dtop($row['member_ip']); |
|
1288 | - if (isset($row['member_ip2'])) |
|
1289 | - $row['member_ip2'] = inet_dtop($row['member_ip2']); |
|
1342 | + if (isset($row['member_ip'])) { |
|
1343 | + $row['member_ip'] = inet_dtop($row['member_ip']); |
|
1344 | + } |
|
1345 | + if (isset($row['member_ip2'])) { |
|
1346 | + $row['member_ip2'] = inet_dtop($row['member_ip2']); |
|
1347 | + } |
|
1290 | 1348 | $new_loaded_ids[] = $row['id_member']; |
1291 | 1349 | $loaded_ids[] = $row['id_member']; |
1292 | 1350 | $row['options'] = array(); |
@@ -1305,8 +1363,9 @@ discard block |
||
1305 | 1363 | 'loaded_ids' => $new_loaded_ids, |
1306 | 1364 | ) |
1307 | 1365 | ); |
1308 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1309 | - $user_profile[$row['id_member']]['options'][$row['variable']] = $row['value']; |
|
1366 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1367 | + $user_profile[$row['id_member']]['options'][$row['variable']] = $row['value']; |
|
1368 | + } |
|
1310 | 1369 | $smcFunc['db_free_result']($request); |
1311 | 1370 | } |
1312 | 1371 | |
@@ -1317,10 +1376,11 @@ discard block |
||
1317 | 1376 | { |
1318 | 1377 | foreach ($loaded_ids as $a_member) |
1319 | 1378 | { |
1320 | - if (!empty($user_profile[$a_member]['additional_groups'])) |
|
1321 | - $groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups'])); |
|
1322 | - else |
|
1323 | - $groups = array($user_profile[$a_member]['id_group']); |
|
1379 | + if (!empty($user_profile[$a_member]['additional_groups'])) { |
|
1380 | + $groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups'])); |
|
1381 | + } else { |
|
1382 | + $groups = array($user_profile[$a_member]['id_group']); |
|
1383 | + } |
|
1324 | 1384 | |
1325 | 1385 | $temp = array_intersect($groups, array_keys($board_info['moderator_groups'])); |
1326 | 1386 | |
@@ -1333,8 +1393,9 @@ discard block |
||
1333 | 1393 | |
1334 | 1394 | if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3) |
1335 | 1395 | { |
1336 | - for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) |
|
1337 | - cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240); |
|
1396 | + for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) { |
|
1397 | + cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240); |
|
1398 | + } |
|
1338 | 1399 | } |
1339 | 1400 | |
1340 | 1401 | // Are we loading any moderators? If so, fix their group data... |
@@ -1360,14 +1421,17 @@ discard block |
||
1360 | 1421 | foreach ($temp_mods as $id) |
1361 | 1422 | { |
1362 | 1423 | // By popular demand, don't show admins or global moderators as moderators. |
1363 | - if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) |
|
1364 | - $user_profile[$id]['member_group'] = $row['member_group']; |
|
1424 | + if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) { |
|
1425 | + $user_profile[$id]['member_group'] = $row['member_group']; |
|
1426 | + } |
|
1365 | 1427 | |
1366 | 1428 | // If the Moderator group has no color or icons, but their group does... don't overwrite. |
1367 | - if (!empty($row['icons'])) |
|
1368 | - $user_profile[$id]['icons'] = $row['icons']; |
|
1369 | - if (!empty($row['member_group_color'])) |
|
1370 | - $user_profile[$id]['member_group_color'] = $row['member_group_color']; |
|
1429 | + if (!empty($row['icons'])) { |
|
1430 | + $user_profile[$id]['icons'] = $row['icons']; |
|
1431 | + } |
|
1432 | + if (!empty($row['member_group_color'])) { |
|
1433 | + $user_profile[$id]['member_group_color'] = $row['member_group_color']; |
|
1434 | + } |
|
1371 | 1435 | } |
1372 | 1436 | } |
1373 | 1437 | |
@@ -1389,12 +1453,14 @@ discard block |
||
1389 | 1453 | static $loadedLanguages = array(); |
1390 | 1454 | |
1391 | 1455 | // If this person's data is already loaded, skip it. |
1392 | - if (isset($dataLoaded[$user])) |
|
1393 | - return true; |
|
1456 | + if (isset($dataLoaded[$user])) { |
|
1457 | + return true; |
|
1458 | + } |
|
1394 | 1459 | |
1395 | 1460 | // We can't load guests or members not loaded by loadMemberData()! |
1396 | - if ($user == 0) |
|
1397 | - return false; |
|
1461 | + if ($user == 0) { |
|
1462 | + return false; |
|
1463 | + } |
|
1398 | 1464 | if (!isset($user_profile[$user])) |
1399 | 1465 | { |
1400 | 1466 | trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING); |
@@ -1420,12 +1486,16 @@ discard block |
||
1420 | 1486 | $buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array(); |
1421 | 1487 | |
1422 | 1488 | //We need a little fallback for the membergroup icons. If it doesn't exist in the current theme, fallback to default theme |
1423 | - if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) //icon is set and exists |
|
1489 | + if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) { |
|
1490 | + //icon is set and exists |
|
1424 | 1491 | $group_icon_url = $settings['images_url'] . '/membericons/' . $profile['icons'][1]; |
1425 | - elseif (isset($profile['icons'][1])) //icon is set and doesn't exist, fallback to default |
|
1492 | + } elseif (isset($profile['icons'][1])) { |
|
1493 | + //icon is set and doesn't exist, fallback to default |
|
1426 | 1494 | $group_icon_url = $settings['default_images_url'] . '/membericons/' . $profile['icons'][1]; |
1427 | - else //not set, bye bye |
|
1495 | + } else { |
|
1496 | + //not set, bye bye |
|
1428 | 1497 | $group_icon_url = ''; |
1498 | + } |
|
1429 | 1499 | |
1430 | 1500 | // These minimal values are always loaded |
1431 | 1501 | $memberContext[$user] = array( |
@@ -1444,8 +1514,9 @@ discard block |
||
1444 | 1514 | if ($context['loadMemberContext_set'] != 'minimal') |
1445 | 1515 | { |
1446 | 1516 | // Go the extra mile and load the user's native language name. |
1447 | - if (empty($loadedLanguages)) |
|
1448 | - $loadedLanguages = getLanguages(); |
|
1517 | + if (empty($loadedLanguages)) { |
|
1518 | + $loadedLanguages = getLanguages(); |
|
1519 | + } |
|
1449 | 1520 | |
1450 | 1521 | $memberContext[$user] += array( |
1451 | 1522 | 'username_color' => '<span ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['member_name'] . '</span>', |
@@ -1499,31 +1570,33 @@ discard block |
||
1499 | 1570 | { |
1500 | 1571 | if (!empty($modSettings['gravatarOverride']) || (!empty($modSettings['gravatarEnabled']) && stristr($profile['avatar'], 'gravatar://'))) |
1501 | 1572 | { |
1502 | - if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) |
|
1503 | - $image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11)); |
|
1504 | - else |
|
1505 | - $image = get_gravatar_url($profile['email_address']); |
|
1506 | - } |
|
1507 | - else |
|
1573 | + if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) { |
|
1574 | + $image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11)); |
|
1575 | + } else { |
|
1576 | + $image = get_gravatar_url($profile['email_address']); |
|
1577 | + } |
|
1578 | + } else |
|
1508 | 1579 | { |
1509 | 1580 | // So it's stored in the member table? |
1510 | 1581 | if (!empty($profile['avatar'])) |
1511 | 1582 | { |
1512 | 1583 | $image = (stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar']; |
1584 | + } elseif (!empty($profile['filename'])) { |
|
1585 | + $image = $modSettings['custom_avatar_url'] . '/' . $profile['filename']; |
|
1513 | 1586 | } |
1514 | - elseif (!empty($profile['filename'])) |
|
1515 | - $image = $modSettings['custom_avatar_url'] . '/' . $profile['filename']; |
|
1516 | 1587 | // Right... no avatar...use the default one |
1517 | - else |
|
1518 | - $image = $modSettings['avatar_url'] . '/default.png'; |
|
1588 | + else { |
|
1589 | + $image = $modSettings['avatar_url'] . '/default.png'; |
|
1590 | + } |
|
1519 | 1591 | } |
1520 | - if (!empty($image)) |
|
1521 | - $memberContext[$user]['avatar'] = array( |
|
1592 | + if (!empty($image)) { |
|
1593 | + $memberContext[$user]['avatar'] = array( |
|
1522 | 1594 | 'name' => $profile['avatar'], |
1523 | 1595 | 'image' => '<img class="avatar" src="' . $image . '" alt="avatar_' . $profile['member_name'] . '">', |
1524 | 1596 | 'href' => $image, |
1525 | 1597 | 'url' => $image, |
1526 | 1598 | ); |
1599 | + } |
|
1527 | 1600 | } |
1528 | 1601 | |
1529 | 1602 | // Are we also loading the members custom fields into context? |
@@ -1531,35 +1604,41 @@ discard block |
||
1531 | 1604 | { |
1532 | 1605 | $memberContext[$user]['custom_fields'] = array(); |
1533 | 1606 | |
1534 | - if (!isset($context['display_fields'])) |
|
1535 | - $context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true); |
|
1607 | + if (!isset($context['display_fields'])) { |
|
1608 | + $context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true); |
|
1609 | + } |
|
1536 | 1610 | |
1537 | 1611 | foreach ($context['display_fields'] as $custom) |
1538 | 1612 | { |
1539 | - if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) |
|
1540 | - continue; |
|
1613 | + if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) { |
|
1614 | + continue; |
|
1615 | + } |
|
1541 | 1616 | |
1542 | 1617 | $value = $profile['options'][$custom['col_name']]; |
1543 | 1618 | |
1544 | 1619 | // Don't show the "disabled" option for the "gender" field. |
1545 | - if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled') |
|
1546 | - continue; |
|
1620 | + if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled') { |
|
1621 | + continue; |
|
1622 | + } |
|
1547 | 1623 | |
1548 | 1624 | // BBC? |
1549 | - if ($custom['bbc']) |
|
1550 | - $value = parse_bbc($value); |
|
1625 | + if ($custom['bbc']) { |
|
1626 | + $value = parse_bbc($value); |
|
1627 | + } |
|
1551 | 1628 | // ... or checkbox? |
1552 | - elseif (isset($custom['type']) && $custom['type'] == 'check') |
|
1553 | - $value = $value ? $txt['yes'] : $txt['no']; |
|
1629 | + elseif (isset($custom['type']) && $custom['type'] == 'check') { |
|
1630 | + $value = $value ? $txt['yes'] : $txt['no']; |
|
1631 | + } |
|
1554 | 1632 | |
1555 | 1633 | // Enclosing the user input within some other text? |
1556 | - if (!empty($custom['enclose'])) |
|
1557 | - $value = strtr($custom['enclose'], array( |
|
1634 | + if (!empty($custom['enclose'])) { |
|
1635 | + $value = strtr($custom['enclose'], array( |
|
1558 | 1636 | '{SCRIPTURL}' => $scripturl, |
1559 | 1637 | '{IMAGES_URL}' => $settings['images_url'], |
1560 | 1638 | '{DEFAULT_IMAGES_URL}' => $settings['default_images_url'], |
1561 | 1639 | '{INPUT}' => $value, |
1562 | 1640 | )); |
1641 | + } |
|
1563 | 1642 | |
1564 | 1643 | $memberContext[$user]['custom_fields'][] = array( |
1565 | 1644 | 'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'], |
@@ -1586,8 +1665,9 @@ discard block |
||
1586 | 1665 | global $smcFunc, $txt, $scripturl, $settings; |
1587 | 1666 | |
1588 | 1667 | // Do not waste my time... |
1589 | - if (empty($users) || empty($params)) |
|
1590 | - return false; |
|
1668 | + if (empty($users) || empty($params)) { |
|
1669 | + return false; |
|
1670 | + } |
|
1591 | 1671 | |
1592 | 1672 | // Make sure it's an array. |
1593 | 1673 | $users = !is_array($users) ? array($users) : array_unique($users); |
@@ -1611,31 +1691,36 @@ discard block |
||
1611 | 1691 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1612 | 1692 | { |
1613 | 1693 | // BBC? |
1614 | - if (!empty($row['bbc'])) |
|
1615 | - $row['value'] = parse_bbc($row['value']); |
|
1694 | + if (!empty($row['bbc'])) { |
|
1695 | + $row['value'] = parse_bbc($row['value']); |
|
1696 | + } |
|
1616 | 1697 | |
1617 | 1698 | // ... or checkbox? |
1618 | - elseif (isset($row['type']) && $row['type'] == 'check') |
|
1619 | - $row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no']; |
|
1699 | + elseif (isset($row['type']) && $row['type'] == 'check') { |
|
1700 | + $row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no']; |
|
1701 | + } |
|
1620 | 1702 | |
1621 | 1703 | // Enclosing the user input within some other text? |
1622 | - if (!empty($row['enclose'])) |
|
1623 | - $row['value'] = strtr($row['enclose'], array( |
|
1704 | + if (!empty($row['enclose'])) { |
|
1705 | + $row['value'] = strtr($row['enclose'], array( |
|
1624 | 1706 | '{SCRIPTURL}' => $scripturl, |
1625 | 1707 | '{IMAGES_URL}' => $settings['images_url'], |
1626 | 1708 | '{DEFAULT_IMAGES_URL}' => $settings['default_images_url'], |
1627 | 1709 | '{INPUT}' => un_htmlspecialchars($row['value']), |
1628 | 1710 | )); |
1711 | + } |
|
1629 | 1712 | |
1630 | 1713 | // Send a simple array if there is just 1 param |
1631 | - if (count($params) == 1) |
|
1632 | - $return[$row['id_member']] = $row; |
|
1714 | + if (count($params) == 1) { |
|
1715 | + $return[$row['id_member']] = $row; |
|
1716 | + } |
|
1633 | 1717 | |
1634 | 1718 | // More than 1? knock yourself out... |
1635 | 1719 | else |
1636 | 1720 | { |
1637 | - if (!isset($return[$row['id_member']])) |
|
1638 | - $return[$row['id_member']] = array(); |
|
1721 | + if (!isset($return[$row['id_member']])) { |
|
1722 | + $return[$row['id_member']] = array(); |
|
1723 | + } |
|
1639 | 1724 | |
1640 | 1725 | $return[$row['id_member']][$row['variable']] = $row; |
1641 | 1726 | } |
@@ -1669,8 +1754,9 @@ discard block |
||
1669 | 1754 | global $context; |
1670 | 1755 | |
1671 | 1756 | // Don't know any browser! |
1672 | - if (empty($context['browser'])) |
|
1673 | - detectBrowser(); |
|
1757 | + if (empty($context['browser'])) { |
|
1758 | + detectBrowser(); |
|
1759 | + } |
|
1674 | 1760 | |
1675 | 1761 | return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false; |
1676 | 1762 | } |
@@ -1688,8 +1774,9 @@ discard block |
||
1688 | 1774 | global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled; |
1689 | 1775 | |
1690 | 1776 | // The theme was specified by parameter. |
1691 | - if (!empty($id_theme)) |
|
1692 | - $id_theme = (int) $id_theme; |
|
1777 | + if (!empty($id_theme)) { |
|
1778 | + $id_theme = (int) $id_theme; |
|
1779 | + } |
|
1693 | 1780 | // The theme was specified by REQUEST. |
1694 | 1781 | elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) |
1695 | 1782 | { |
@@ -1697,51 +1784,58 @@ discard block |
||
1697 | 1784 | $_SESSION['id_theme'] = $id_theme; |
1698 | 1785 | } |
1699 | 1786 | // The theme was specified by REQUEST... previously. |
1700 | - elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) |
|
1701 | - $id_theme = (int) $_SESSION['id_theme']; |
|
1787 | + elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) { |
|
1788 | + $id_theme = (int) $_SESSION['id_theme']; |
|
1789 | + } |
|
1702 | 1790 | // The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.) |
1703 | - elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) |
|
1704 | - $id_theme = $user_info['theme']; |
|
1791 | + elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) { |
|
1792 | + $id_theme = $user_info['theme']; |
|
1793 | + } |
|
1705 | 1794 | // The theme was specified by the board. |
1706 | - elseif (!empty($board_info['theme'])) |
|
1707 | - $id_theme = $board_info['theme']; |
|
1795 | + elseif (!empty($board_info['theme'])) { |
|
1796 | + $id_theme = $board_info['theme']; |
|
1797 | + } |
|
1708 | 1798 | // The theme is the forum's default. |
1709 | - else |
|
1710 | - $id_theme = $modSettings['theme_guests']; |
|
1799 | + else { |
|
1800 | + $id_theme = $modSettings['theme_guests']; |
|
1801 | + } |
|
1711 | 1802 | |
1712 | 1803 | // Verify the id_theme... no foul play. |
1713 | 1804 | // Always allow the board specific theme, if they are overriding. |
1714 | - if (!empty($board_info['theme']) && $board_info['override_theme']) |
|
1715 | - $id_theme = $board_info['theme']; |
|
1805 | + if (!empty($board_info['theme']) && $board_info['override_theme']) { |
|
1806 | + $id_theme = $board_info['theme']; |
|
1807 | + } |
|
1716 | 1808 | // If they have specified a particular theme to use with SSI allow it to be used. |
1717 | - elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) |
|
1718 | - $id_theme = (int) $id_theme; |
|
1719 | - elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum')) |
|
1809 | + elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) { |
|
1810 | + $id_theme = (int) $id_theme; |
|
1811 | + } elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum')) |
|
1720 | 1812 | { |
1721 | 1813 | $themes = explode(',', $modSettings['enableThemes']); |
1722 | - if (!in_array($id_theme, $themes)) |
|
1723 | - $id_theme = $modSettings['theme_guests']; |
|
1724 | - else |
|
1814 | + if (!in_array($id_theme, $themes)) { |
|
1815 | + $id_theme = $modSettings['theme_guests']; |
|
1816 | + } else { |
|
1817 | + $id_theme = (int) $id_theme; |
|
1818 | + } |
|
1819 | + } else { |
|
1725 | 1820 | $id_theme = (int) $id_theme; |
1726 | 1821 | } |
1727 | - else |
|
1728 | - $id_theme = (int) $id_theme; |
|
1729 | 1822 | |
1730 | 1823 | $member = empty($user_info['id']) ? -1 : $user_info['id']; |
1731 | 1824 | |
1732 | 1825 | // Disable image proxy if we don't have SSL enabled |
1733 | - if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2) |
|
1734 | - $image_proxy_enabled = false; |
|
1826 | + if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2) { |
|
1827 | + $image_proxy_enabled = false; |
|
1828 | + } |
|
1735 | 1829 | |
1736 | 1830 | if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && ($temp = cache_get_data('theme_settings-' . $id_theme . ':' . $member, 60)) != null && time() - 60 > $modSettings['settings_updated']) |
1737 | 1831 | { |
1738 | 1832 | $themeData = $temp; |
1739 | 1833 | $flag = true; |
1834 | + } elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) { |
|
1835 | + $themeData = $temp + array($member => array()); |
|
1836 | + } else { |
|
1837 | + $themeData = array(-1 => array(), 0 => array(), $member => array()); |
|
1740 | 1838 | } |
1741 | - elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) |
|
1742 | - $themeData = $temp + array($member => array()); |
|
1743 | - else |
|
1744 | - $themeData = array(-1 => array(), 0 => array(), $member => array()); |
|
1745 | 1839 | |
1746 | 1840 | if (empty($flag)) |
1747 | 1841 | { |
@@ -1760,31 +1854,37 @@ discard block |
||
1760 | 1854 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
1761 | 1855 | { |
1762 | 1856 | // There are just things we shouldn't be able to change as members. |
1763 | - if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url'))) |
|
1764 | - continue; |
|
1857 | + if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url'))) { |
|
1858 | + continue; |
|
1859 | + } |
|
1765 | 1860 | |
1766 | 1861 | // If this is the theme_dir of the default theme, store it. |
1767 | - if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) |
|
1768 | - $themeData[0]['default_' . $row['variable']] = $row['value']; |
|
1862 | + if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) { |
|
1863 | + $themeData[0]['default_' . $row['variable']] = $row['value']; |
|
1864 | + } |
|
1769 | 1865 | |
1770 | 1866 | // If this isn't set yet, is a theme option, or is not the default theme.. |
1771 | - if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') |
|
1772 | - $themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value']; |
|
1867 | + if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') { |
|
1868 | + $themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value']; |
|
1869 | + } |
|
1773 | 1870 | } |
1774 | 1871 | $smcFunc['db_free_result']($result); |
1775 | 1872 | |
1776 | - if (!empty($themeData[-1])) |
|
1777 | - foreach ($themeData[-1] as $k => $v) |
|
1873 | + if (!empty($themeData[-1])) { |
|
1874 | + foreach ($themeData[-1] as $k => $v) |
|
1778 | 1875 | { |
1779 | 1876 | if (!isset($themeData[$member][$k])) |
1780 | 1877 | $themeData[$member][$k] = $v; |
1878 | + } |
|
1781 | 1879 | } |
1782 | 1880 | |
1783 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
1784 | - cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60); |
|
1881 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
1882 | + cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60); |
|
1883 | + } |
|
1785 | 1884 | // Only if we didn't already load that part of the cache... |
1786 | - elseif (!isset($temp)) |
|
1787 | - cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90); |
|
1885 | + elseif (!isset($temp)) { |
|
1886 | + cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90); |
|
1887 | + } |
|
1788 | 1888 | } |
1789 | 1889 | |
1790 | 1890 | $settings = $themeData[0]; |
@@ -1801,20 +1901,24 @@ discard block |
||
1801 | 1901 | $settings['template_dirs'][] = $settings['theme_dir']; |
1802 | 1902 | |
1803 | 1903 | // Based on theme (if there is one). |
1804 | - if (!empty($settings['base_theme_dir'])) |
|
1805 | - $settings['template_dirs'][] = $settings['base_theme_dir']; |
|
1904 | + if (!empty($settings['base_theme_dir'])) { |
|
1905 | + $settings['template_dirs'][] = $settings['base_theme_dir']; |
|
1906 | + } |
|
1806 | 1907 | |
1807 | 1908 | // Lastly the default theme. |
1808 | - if ($settings['theme_dir'] != $settings['default_theme_dir']) |
|
1809 | - $settings['template_dirs'][] = $settings['default_theme_dir']; |
|
1909 | + if ($settings['theme_dir'] != $settings['default_theme_dir']) { |
|
1910 | + $settings['template_dirs'][] = $settings['default_theme_dir']; |
|
1911 | + } |
|
1810 | 1912 | |
1811 | - if (!$initialize) |
|
1812 | - return; |
|
1913 | + if (!$initialize) { |
|
1914 | + return; |
|
1915 | + } |
|
1813 | 1916 | |
1814 | 1917 | // Check to see if we're forcing SSL |
1815 | 1918 | if (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 && empty($maintenance) && |
1816 | - (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI') |
|
1817 | - redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://'))); |
|
1919 | + (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI') { |
|
1920 | + redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://'))); |
|
1921 | + } |
|
1818 | 1922 | |
1819 | 1923 | // Check to see if they're accessing it from the wrong place. |
1820 | 1924 | if (isset($_SERVER['HTTP_HOST']) || isset($_SERVER['SERVER_NAME'])) |
@@ -1822,8 +1926,9 @@ discard block |
||
1822 | 1926 | $detected_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https://' : 'http://'; |
1823 | 1927 | $detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST']; |
1824 | 1928 | $temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/')); |
1825 | - if ($temp != '/') |
|
1826 | - $detected_url .= $temp; |
|
1929 | + if ($temp != '/') { |
|
1930 | + $detected_url .= $temp; |
|
1931 | + } |
|
1827 | 1932 | } |
1828 | 1933 | if (isset($detected_url) && $detected_url != $boardurl) |
1829 | 1934 | { |
@@ -1835,8 +1940,9 @@ discard block |
||
1835 | 1940 | foreach ($aliases as $alias) |
1836 | 1941 | { |
1837 | 1942 | // Rip off all the boring parts, spaces, etc. |
1838 | - if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) |
|
1839 | - $do_fix = true; |
|
1943 | + if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) { |
|
1944 | + $do_fix = true; |
|
1945 | + } |
|
1840 | 1946 | } |
1841 | 1947 | } |
1842 | 1948 | |
@@ -1844,20 +1950,22 @@ discard block |
||
1844 | 1950 | if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI') |
1845 | 1951 | { |
1846 | 1952 | // Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;). |
1847 | - if (empty($_GET)) |
|
1848 | - redirectexit('wwwRedirect'); |
|
1849 | - else |
|
1953 | + if (empty($_GET)) { |
|
1954 | + redirectexit('wwwRedirect'); |
|
1955 | + } else |
|
1850 | 1956 | { |
1851 | 1957 | list ($k, $v) = each($_GET); |
1852 | 1958 | |
1853 | - if ($k != 'wwwRedirect') |
|
1854 | - redirectexit('wwwRedirect;' . $k . '=' . $v); |
|
1959 | + if ($k != 'wwwRedirect') { |
|
1960 | + redirectexit('wwwRedirect;' . $k . '=' . $v); |
|
1961 | + } |
|
1855 | 1962 | } |
1856 | 1963 | } |
1857 | 1964 | |
1858 | 1965 | // #3 is just a check for SSL... |
1859 | - if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) |
|
1860 | - $do_fix = true; |
|
1966 | + if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) { |
|
1967 | + $do_fix = true; |
|
1968 | + } |
|
1861 | 1969 | |
1862 | 1970 | // Okay, #4 - perhaps it's an IP address? We're gonna want to use that one, then. (assuming it's the IP or something...) |
1863 | 1971 | if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1) |
@@ -1891,8 +1999,9 @@ discard block |
||
1891 | 1999 | $board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl)); |
1892 | 2000 | } |
1893 | 2001 | } |
1894 | - foreach ($context['linktree'] as $k => $dummy) |
|
1895 | - $context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl)); |
|
2002 | + foreach ($context['linktree'] as $k => $dummy) { |
|
2003 | + $context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl)); |
|
2004 | + } |
|
1896 | 2005 | } |
1897 | 2006 | } |
1898 | 2007 | // Set up the contextual user array. |
@@ -1911,16 +2020,16 @@ discard block |
||
1911 | 2020 | 'email' => $user_info['email'], |
1912 | 2021 | 'ignoreusers' => $user_info['ignoreusers'], |
1913 | 2022 | ); |
1914 | - if (!$context['user']['is_guest']) |
|
1915 | - $context['user']['name'] = $user_info['name']; |
|
1916 | - elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) |
|
1917 | - $context['user']['name'] = $txt['guest_title']; |
|
2023 | + if (!$context['user']['is_guest']) { |
|
2024 | + $context['user']['name'] = $user_info['name']; |
|
2025 | + } elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) { |
|
2026 | + $context['user']['name'] = $txt['guest_title']; |
|
2027 | + } |
|
1918 | 2028 | |
1919 | 2029 | // Determine the current smiley set. |
1920 | 2030 | $user_info['smiley_set'] = (!in_array($user_info['smiley_set'], explode(',', $modSettings['smiley_sets_known'])) && $user_info['smiley_set'] != 'none') || empty($modSettings['smiley_sets_enable']) ? (!empty($settings['smiley_sets_default']) ? $settings['smiley_sets_default'] : $modSettings['smiley_sets_default']) : $user_info['smiley_set']; |
1921 | 2031 | $context['user']['smiley_set'] = $user_info['smiley_set']; |
1922 | - } |
|
1923 | - else |
|
2032 | + } else |
|
1924 | 2033 | { |
1925 | 2034 | $context['user'] = array( |
1926 | 2035 | 'id' => -1, |
@@ -1936,18 +2045,24 @@ discard block |
||
1936 | 2045 | } |
1937 | 2046 | |
1938 | 2047 | // Some basic information... |
1939 | - if (!isset($context['html_headers'])) |
|
1940 | - $context['html_headers'] = ''; |
|
1941 | - if (!isset($context['javascript_files'])) |
|
1942 | - $context['javascript_files'] = array(); |
|
1943 | - if (!isset($context['css_files'])) |
|
1944 | - $context['css_files'] = array(); |
|
1945 | - if (!isset($context['css_header'])) |
|
1946 | - $context['css_header'] = array(); |
|
1947 | - if (!isset($context['javascript_inline'])) |
|
1948 | - $context['javascript_inline'] = array('standard' => array(), 'defer' => array()); |
|
1949 | - if (!isset($context['javascript_vars'])) |
|
1950 | - $context['javascript_vars'] = array(); |
|
2048 | + if (!isset($context['html_headers'])) { |
|
2049 | + $context['html_headers'] = ''; |
|
2050 | + } |
|
2051 | + if (!isset($context['javascript_files'])) { |
|
2052 | + $context['javascript_files'] = array(); |
|
2053 | + } |
|
2054 | + if (!isset($context['css_files'])) { |
|
2055 | + $context['css_files'] = array(); |
|
2056 | + } |
|
2057 | + if (!isset($context['css_header'])) { |
|
2058 | + $context['css_header'] = array(); |
|
2059 | + } |
|
2060 | + if (!isset($context['javascript_inline'])) { |
|
2061 | + $context['javascript_inline'] = array('standard' => array(), 'defer' => array()); |
|
2062 | + } |
|
2063 | + if (!isset($context['javascript_vars'])) { |
|
2064 | + $context['javascript_vars'] = array(); |
|
2065 | + } |
|
1951 | 2066 | |
1952 | 2067 | $context['login_url'] = (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] < 2 ? strtr($scripturl, array('http://' => 'https://')) : $scripturl) . '?action=login2'; |
1953 | 2068 | $context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | '; |
@@ -1959,8 +2074,9 @@ discard block |
||
1959 | 2074 | $context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null; |
1960 | 2075 | $context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null; |
1961 | 2076 | $context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3; |
1962 | - if (isset($modSettings['load_average'])) |
|
1963 | - $context['load_average'] = $modSettings['load_average']; |
|
2077 | + if (isset($modSettings['load_average'])) { |
|
2078 | + $context['load_average'] = $modSettings['load_average']; |
|
2079 | + } |
|
1964 | 2080 | |
1965 | 2081 | // Detect the browser. This is separated out because it's also used in attachment downloads |
1966 | 2082 | detectBrowser(); |
@@ -1974,8 +2090,9 @@ discard block |
||
1974 | 2090 | // This allows sticking some HTML on the page output - useful for controls. |
1975 | 2091 | $context['insert_after_template'] = ''; |
1976 | 2092 | |
1977 | - if (!isset($txt)) |
|
1978 | - $txt = array(); |
|
2093 | + if (!isset($txt)) { |
|
2094 | + $txt = array(); |
|
2095 | + } |
|
1979 | 2096 | |
1980 | 2097 | $simpleActions = array( |
1981 | 2098 | 'findmember', |
@@ -2021,9 +2138,10 @@ discard block |
||
2021 | 2138 | |
2022 | 2139 | // See if theres any extra param to check. |
2023 | 2140 | $requiresXML = false; |
2024 | - foreach ($extraParams as $key => $extra) |
|
2025 | - if (isset($_REQUEST[$extra])) |
|
2141 | + foreach ($extraParams as $key => $extra) { |
|
2142 | + if (isset($_REQUEST[$extra])) |
|
2026 | 2143 | $requiresXML = true; |
2144 | + } |
|
2027 | 2145 | |
2028 | 2146 | // Output is fully XML, so no need for the index template. |
2029 | 2147 | if (isset($_REQUEST['xml']) && (in_array($context['current_action'], $xmlActions) || $requiresXML)) |
@@ -2038,37 +2156,39 @@ discard block |
||
2038 | 2156 | { |
2039 | 2157 | loadLanguage('index+Modifications'); |
2040 | 2158 | $context['template_layers'] = array(); |
2041 | - } |
|
2042 | - |
|
2043 | - else |
|
2159 | + } else |
|
2044 | 2160 | { |
2045 | 2161 | // Custom templates to load, or just default? |
2046 | - if (isset($settings['theme_templates'])) |
|
2047 | - $templates = explode(',', $settings['theme_templates']); |
|
2048 | - else |
|
2049 | - $templates = array('index'); |
|
2162 | + if (isset($settings['theme_templates'])) { |
|
2163 | + $templates = explode(',', $settings['theme_templates']); |
|
2164 | + } else { |
|
2165 | + $templates = array('index'); |
|
2166 | + } |
|
2050 | 2167 | |
2051 | 2168 | // Load each template... |
2052 | - foreach ($templates as $template) |
|
2053 | - loadTemplate($template); |
|
2169 | + foreach ($templates as $template) { |
|
2170 | + loadTemplate($template); |
|
2171 | + } |
|
2054 | 2172 | |
2055 | 2173 | // ...and attempt to load their associated language files. |
2056 | 2174 | $required_files = implode('+', array_merge($templates, array('Modifications'))); |
2057 | 2175 | loadLanguage($required_files, '', false); |
2058 | 2176 | |
2059 | 2177 | // Custom template layers? |
2060 | - if (isset($settings['theme_layers'])) |
|
2061 | - $context['template_layers'] = explode(',', $settings['theme_layers']); |
|
2062 | - else |
|
2063 | - $context['template_layers'] = array('html', 'body'); |
|
2178 | + if (isset($settings['theme_layers'])) { |
|
2179 | + $context['template_layers'] = explode(',', $settings['theme_layers']); |
|
2180 | + } else { |
|
2181 | + $context['template_layers'] = array('html', 'body'); |
|
2182 | + } |
|
2064 | 2183 | } |
2065 | 2184 | |
2066 | 2185 | // Initialize the theme. |
2067 | 2186 | loadSubTemplate('init', 'ignore'); |
2068 | 2187 | |
2069 | 2188 | // Allow overriding the board wide time/number formats. |
2070 | - if (empty($user_settings['time_format']) && !empty($txt['time_format'])) |
|
2071 | - $user_info['time_format'] = $txt['time_format']; |
|
2189 | + if (empty($user_settings['time_format']) && !empty($txt['time_format'])) { |
|
2190 | + $user_info['time_format'] = $txt['time_format']; |
|
2191 | + } |
|
2072 | 2192 | |
2073 | 2193 | // Set the character set from the template. |
2074 | 2194 | $context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']; |
@@ -2076,12 +2196,14 @@ discard block |
||
2076 | 2196 | $context['right_to_left'] = !empty($txt['lang_rtl']); |
2077 | 2197 | |
2078 | 2198 | // Guests may still need a name. |
2079 | - if ($context['user']['is_guest'] && empty($context['user']['name'])) |
|
2080 | - $context['user']['name'] = $txt['guest_title']; |
|
2199 | + if ($context['user']['is_guest'] && empty($context['user']['name'])) { |
|
2200 | + $context['user']['name'] = $txt['guest_title']; |
|
2201 | + } |
|
2081 | 2202 | |
2082 | 2203 | // Any theme-related strings that need to be loaded? |
2083 | - if (!empty($settings['require_theme_strings'])) |
|
2084 | - loadLanguage('ThemeStrings', '', false); |
|
2204 | + if (!empty($settings['require_theme_strings'])) { |
|
2205 | + loadLanguage('ThemeStrings', '', false); |
|
2206 | + } |
|
2085 | 2207 | |
2086 | 2208 | // Make a special URL for the language. |
2087 | 2209 | $settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']); |
@@ -2092,8 +2214,9 @@ discard block |
||
2092 | 2214 | // Here is my luvly Responsive CSS |
2093 | 2215 | loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true), 'smf_responsive'); |
2094 | 2216 | |
2095 | - if ($context['right_to_left']) |
|
2096 | - loadCSSFile('rtl.css', array(), 'smf_rtl'); |
|
2217 | + if ($context['right_to_left']) { |
|
2218 | + loadCSSFile('rtl.css', array(), 'smf_rtl'); |
|
2219 | + } |
|
2097 | 2220 | |
2098 | 2221 | // We allow theme variants, because we're cool. |
2099 | 2222 | $context['theme_variant'] = ''; |
@@ -2101,14 +2224,17 @@ discard block |
||
2101 | 2224 | if (!empty($settings['theme_variants'])) |
2102 | 2225 | { |
2103 | 2226 | // Overriding - for previews and that ilk. |
2104 | - if (!empty($_REQUEST['variant'])) |
|
2105 | - $_SESSION['id_variant'] = $_REQUEST['variant']; |
|
2227 | + if (!empty($_REQUEST['variant'])) { |
|
2228 | + $_SESSION['id_variant'] = $_REQUEST['variant']; |
|
2229 | + } |
|
2106 | 2230 | // User selection? |
2107 | - if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) |
|
2108 | - $context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : ''); |
|
2231 | + if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) { |
|
2232 | + $context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : ''); |
|
2233 | + } |
|
2109 | 2234 | // If not a user variant, select the default. |
2110 | - if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) |
|
2111 | - $context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0]; |
|
2235 | + if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) { |
|
2236 | + $context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0]; |
|
2237 | + } |
|
2112 | 2238 | |
2113 | 2239 | // Do this to keep things easier in the templates. |
2114 | 2240 | $context['theme_variant'] = '_' . $context['theme_variant']; |
@@ -2117,20 +2243,23 @@ discard block |
||
2117 | 2243 | if (!empty($context['theme_variant'])) |
2118 | 2244 | { |
2119 | 2245 | loadCSSFile('index' . $context['theme_variant'] . '.css', array(), 'smf_index' . $context['theme_variant']); |
2120 | - if ($context['right_to_left']) |
|
2121 | - loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']); |
|
2246 | + if ($context['right_to_left']) { |
|
2247 | + loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']); |
|
2248 | + } |
|
2122 | 2249 | } |
2123 | 2250 | } |
2124 | 2251 | |
2125 | 2252 | // Let's be compatible with old themes! |
2126 | - if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) |
|
2127 | - $context['template_layers'] = array('main'); |
|
2253 | + if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) { |
|
2254 | + $context['template_layers'] = array('main'); |
|
2255 | + } |
|
2128 | 2256 | |
2129 | 2257 | $context['tabindex'] = 1; |
2130 | 2258 | |
2131 | 2259 | // Compatibility. |
2132 | - if (!isset($settings['theme_version'])) |
|
2133 | - $modSettings['memberCount'] = $modSettings['totalMembers']; |
|
2260 | + if (!isset($settings['theme_version'])) { |
|
2261 | + $modSettings['memberCount'] = $modSettings['totalMembers']; |
|
2262 | + } |
|
2134 | 2263 | |
2135 | 2264 | // Default JS variables for use in every theme |
2136 | 2265 | $context['javascript_vars'] = array( |
@@ -2149,18 +2278,18 @@ discard block |
||
2149 | 2278 | ); |
2150 | 2279 | |
2151 | 2280 | // Add the JQuery library to the list of files to load. |
2152 | - if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') |
|
2153 | - loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
2154 | - |
|
2155 | - elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') |
|
2156 | - loadJavaScriptFile('jquery-3.1.1.min.js', array('seed' => false), 'smf_jquery'); |
|
2157 | - |
|
2158 | - elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') |
|
2159 | - loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery'); |
|
2281 | + if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') { |
|
2282 | + loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
2283 | + } elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') { |
|
2284 | + loadJavaScriptFile('jquery-3.1.1.min.js', array('seed' => false), 'smf_jquery'); |
|
2285 | + } elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') { |
|
2286 | + loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery'); |
|
2287 | + } |
|
2160 | 2288 | |
2161 | 2289 | // Auto loading? template_javascript() will take care of the local half of this. |
2162 | - else |
|
2163 | - loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
2290 | + else { |
|
2291 | + loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
2292 | + } |
|
2164 | 2293 | |
2165 | 2294 | // Queue our JQuery plugins! |
2166 | 2295 | loadJavaScriptFile('smf_jquery_plugins.js', array('minimize' => true), 'smf_jquery_plugins'); |
@@ -2183,12 +2312,12 @@ discard block |
||
2183 | 2312 | require_once($sourcedir . '/ScheduledTasks.php'); |
2184 | 2313 | |
2185 | 2314 | // What to do, what to do?! |
2186 | - if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) |
|
2187 | - AutoTask(); |
|
2188 | - else |
|
2189 | - ReduceMailQueue(); |
|
2190 | - } |
|
2191 | - else |
|
2315 | + if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) { |
|
2316 | + AutoTask(); |
|
2317 | + } else { |
|
2318 | + ReduceMailQueue(); |
|
2319 | + } |
|
2320 | + } else |
|
2192 | 2321 | { |
2193 | 2322 | $type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq'; |
2194 | 2323 | $ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time']; |
@@ -2239,8 +2368,9 @@ discard block |
||
2239 | 2368 | foreach ($theme_includes as $include) |
2240 | 2369 | { |
2241 | 2370 | $include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
2242 | - if (file_exists($include)) |
|
2243 | - require_once($include); |
|
2371 | + if (file_exists($include)) { |
|
2372 | + require_once($include); |
|
2373 | + } |
|
2244 | 2374 | } |
2245 | 2375 | } |
2246 | 2376 | |
@@ -2270,16 +2400,19 @@ discard block |
||
2270 | 2400 | // Do any style sheets first, cause we're easy with those. |
2271 | 2401 | if (!empty($style_sheets)) |
2272 | 2402 | { |
2273 | - if (!is_array($style_sheets)) |
|
2274 | - $style_sheets = array($style_sheets); |
|
2403 | + if (!is_array($style_sheets)) { |
|
2404 | + $style_sheets = array($style_sheets); |
|
2405 | + } |
|
2275 | 2406 | |
2276 | - foreach ($style_sheets as $sheet) |
|
2277 | - loadCSSFile($sheet . '.css', array(), $sheet); |
|
2407 | + foreach ($style_sheets as $sheet) { |
|
2408 | + loadCSSFile($sheet . '.css', array(), $sheet); |
|
2409 | + } |
|
2278 | 2410 | } |
2279 | 2411 | |
2280 | 2412 | // No template to load? |
2281 | - if ($template_name === false) |
|
2282 | - return true; |
|
2413 | + if ($template_name === false) { |
|
2414 | + return true; |
|
2415 | + } |
|
2283 | 2416 | |
2284 | 2417 | $loaded = false; |
2285 | 2418 | foreach ($settings['template_dirs'] as $template_dir) |
@@ -2294,12 +2427,14 @@ discard block |
||
2294 | 2427 | |
2295 | 2428 | if ($loaded) |
2296 | 2429 | { |
2297 | - if ($db_show_debug === true) |
|
2298 | - $context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')'; |
|
2430 | + if ($db_show_debug === true) { |
|
2431 | + $context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')'; |
|
2432 | + } |
|
2299 | 2433 | |
2300 | 2434 | // If they have specified an initialization function for this template, go ahead and call it now. |
2301 | - if (function_exists('template_' . $template_name . '_init')) |
|
2302 | - call_user_func('template_' . $template_name . '_init'); |
|
2435 | + if (function_exists('template_' . $template_name . '_init')) { |
|
2436 | + call_user_func('template_' . $template_name . '_init'); |
|
2437 | + } |
|
2303 | 2438 | } |
2304 | 2439 | // Hmmm... doesn't exist?! I don't suppose the directory is wrong, is it? |
2305 | 2440 | elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default')) |
@@ -2319,13 +2454,14 @@ discard block |
||
2319 | 2454 | loadTemplate($template_name); |
2320 | 2455 | } |
2321 | 2456 | // Cause an error otherwise. |
2322 | - elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) |
|
2323 | - fatal_lang_error('theme_template_error', 'template', array((string) $template_name)); |
|
2324 | - elseif ($fatal) |
|
2325 | - die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template')); |
|
2326 | - else |
|
2327 | - return false; |
|
2328 | -} |
|
2457 | + elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) { |
|
2458 | + fatal_lang_error('theme_template_error', 'template', array((string) $template_name)); |
|
2459 | + } elseif ($fatal) { |
|
2460 | + die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template')); |
|
2461 | + } else { |
|
2462 | + return false; |
|
2463 | + } |
|
2464 | + } |
|
2329 | 2465 | |
2330 | 2466 | /** |
2331 | 2467 | * Load a sub-template. |
@@ -2343,17 +2479,19 @@ discard block |
||
2343 | 2479 | { |
2344 | 2480 | global $context, $txt, $db_show_debug; |
2345 | 2481 | |
2346 | - if ($db_show_debug === true) |
|
2347 | - $context['debug']['sub_templates'][] = $sub_template_name; |
|
2482 | + if ($db_show_debug === true) { |
|
2483 | + $context['debug']['sub_templates'][] = $sub_template_name; |
|
2484 | + } |
|
2348 | 2485 | |
2349 | 2486 | // Figure out what the template function is named. |
2350 | 2487 | $theme_function = 'template_' . $sub_template_name; |
2351 | - if (function_exists($theme_function)) |
|
2352 | - $theme_function(); |
|
2353 | - elseif ($fatal === false) |
|
2354 | - fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name)); |
|
2355 | - elseif ($fatal !== 'ignore') |
|
2356 | - die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template')); |
|
2488 | + if (function_exists($theme_function)) { |
|
2489 | + $theme_function(); |
|
2490 | + } elseif ($fatal === false) { |
|
2491 | + fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name)); |
|
2492 | + } elseif ($fatal !== 'ignore') { |
|
2493 | + die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template')); |
|
2494 | + } |
|
2357 | 2495 | |
2358 | 2496 | // Are we showing debugging for templates? Just make sure not to do it before the doctype... |
2359 | 2497 | if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml'])) |
@@ -2390,8 +2528,9 @@ discard block |
||
2390 | 2528 | $params['validate'] = isset($params['validate']) ? $params['validate'] : true; |
2391 | 2529 | |
2392 | 2530 | // If this is an external file, automatically set this to false. |
2393 | - if (!empty($params['external'])) |
|
2394 | - $params['minimize'] = false; |
|
2531 | + if (!empty($params['external'])) { |
|
2532 | + $params['minimize'] = false; |
|
2533 | + } |
|
2395 | 2534 | |
2396 | 2535 | // Account for shorthand like admin.css?alp21 filenames |
2397 | 2536 | $has_seed = strpos($fileName, '.css?'); |
@@ -2408,13 +2547,10 @@ discard block |
||
2408 | 2547 | { |
2409 | 2548 | $fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
2410 | 2549 | $filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
2550 | + } else { |
|
2551 | + $fileUrl = false; |
|
2411 | 2552 | } |
2412 | - |
|
2413 | - else |
|
2414 | - $fileUrl = false; |
|
2415 | - } |
|
2416 | - |
|
2417 | - else |
|
2553 | + } else |
|
2418 | 2554 | { |
2419 | 2555 | $fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
2420 | 2556 | $filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
@@ -2429,12 +2565,14 @@ discard block |
||
2429 | 2565 | } |
2430 | 2566 | |
2431 | 2567 | // Add it to the array for use in the template |
2432 | - if (!empty($fileName)) |
|
2433 | - $context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params); |
|
2568 | + if (!empty($fileName)) { |
|
2569 | + $context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params); |
|
2570 | + } |
|
2434 | 2571 | |
2435 | - if (!empty($context['right_to_left']) && !empty($params['rtl'])) |
|
2436 | - loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0))); |
|
2437 | -} |
|
2572 | + if (!empty($context['right_to_left']) && !empty($params['rtl'])) { |
|
2573 | + loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0))); |
|
2574 | + } |
|
2575 | + } |
|
2438 | 2576 | |
2439 | 2577 | /** |
2440 | 2578 | * Add a block of inline css code to be executed later |
@@ -2451,8 +2589,9 @@ discard block |
||
2451 | 2589 | global $context; |
2452 | 2590 | |
2453 | 2591 | // Gotta add something... |
2454 | - if (empty($css)) |
|
2455 | - return false; |
|
2592 | + if (empty($css)) { |
|
2593 | + return false; |
|
2594 | + } |
|
2456 | 2595 | |
2457 | 2596 | $context['css_header'][] = $css; |
2458 | 2597 | } |
@@ -2487,8 +2626,9 @@ discard block |
||
2487 | 2626 | $params['validate'] = isset($params['validate']) ? $params['validate'] : true; |
2488 | 2627 | |
2489 | 2628 | // If this is an external file, automatically set this to false. |
2490 | - if (!empty($params['external'])) |
|
2491 | - $params['minimize'] = false; |
|
2629 | + if (!empty($params['external'])) { |
|
2630 | + $params['minimize'] = false; |
|
2631 | + } |
|
2492 | 2632 | |
2493 | 2633 | // Account for shorthand like admin.js?alp21 filenames |
2494 | 2634 | $has_seed = strpos($fileName, '.js?'); |
@@ -2505,16 +2645,12 @@ discard block |
||
2505 | 2645 | { |
2506 | 2646 | $fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
2507 | 2647 | $filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
2508 | - } |
|
2509 | - |
|
2510 | - else |
|
2648 | + } else |
|
2511 | 2649 | { |
2512 | 2650 | $fileUrl = false; |
2513 | 2651 | $filePath = false; |
2514 | 2652 | } |
2515 | - } |
|
2516 | - |
|
2517 | - else |
|
2653 | + } else |
|
2518 | 2654 | { |
2519 | 2655 | $fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
2520 | 2656 | $filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
@@ -2529,9 +2665,10 @@ discard block |
||
2529 | 2665 | } |
2530 | 2666 | |
2531 | 2667 | // Add it to the array for use in the template |
2532 | - if (!empty($fileName)) |
|
2533 | - $context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params); |
|
2534 | -} |
|
2668 | + if (!empty($fileName)) { |
|
2669 | + $context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params); |
|
2670 | + } |
|
2671 | + } |
|
2535 | 2672 | |
2536 | 2673 | /** |
2537 | 2674 | * Add a Javascript variable for output later (for feeding text strings and similar to JS) |
@@ -2545,9 +2682,10 @@ discard block |
||
2545 | 2682 | { |
2546 | 2683 | global $context; |
2547 | 2684 | |
2548 | - if (!empty($key) && (!empty($value) || $value === '0')) |
|
2549 | - $context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value; |
|
2550 | -} |
|
2685 | + if (!empty($key) && (!empty($value) || $value === '0')) { |
|
2686 | + $context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value; |
|
2687 | + } |
|
2688 | + } |
|
2551 | 2689 | |
2552 | 2690 | /** |
2553 | 2691 | * Add a block of inline Javascript code to be executed later |
@@ -2564,8 +2702,9 @@ discard block |
||
2564 | 2702 | { |
2565 | 2703 | global $context; |
2566 | 2704 | |
2567 | - if (empty($javascript)) |
|
2568 | - return false; |
|
2705 | + if (empty($javascript)) { |
|
2706 | + return false; |
|
2707 | + } |
|
2569 | 2708 | |
2570 | 2709 | $context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript; |
2571 | 2710 | } |
@@ -2586,15 +2725,18 @@ discard block |
||
2586 | 2725 | static $already_loaded = array(); |
2587 | 2726 | |
2588 | 2727 | // Default to the user's language. |
2589 | - if ($lang == '') |
|
2590 | - $lang = isset($user_info['language']) ? $user_info['language'] : $language; |
|
2728 | + if ($lang == '') { |
|
2729 | + $lang = isset($user_info['language']) ? $user_info['language'] : $language; |
|
2730 | + } |
|
2591 | 2731 | |
2592 | 2732 | // Do we want the English version of language file as fallback? |
2593 | - if (empty($modSettings['disable_language_fallback']) && $lang != 'english') |
|
2594 | - loadLanguage($template_name, 'english', false); |
|
2733 | + if (empty($modSettings['disable_language_fallback']) && $lang != 'english') { |
|
2734 | + loadLanguage($template_name, 'english', false); |
|
2735 | + } |
|
2595 | 2736 | |
2596 | - if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) |
|
2597 | - return $lang; |
|
2737 | + if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) { |
|
2738 | + return $lang; |
|
2739 | + } |
|
2598 | 2740 | |
2599 | 2741 | // Make sure we have $settings - if not we're in trouble and need to find it! |
2600 | 2742 | if (empty($settings['default_theme_dir'])) |
@@ -2605,8 +2747,9 @@ discard block |
||
2605 | 2747 | |
2606 | 2748 | // What theme are we in? |
2607 | 2749 | $theme_name = basename($settings['theme_url']); |
2608 | - if (empty($theme_name)) |
|
2609 | - $theme_name = 'unknown'; |
|
2750 | + if (empty($theme_name)) { |
|
2751 | + $theme_name = 'unknown'; |
|
2752 | + } |
|
2610 | 2753 | |
2611 | 2754 | // For each file open it up and write it out! |
2612 | 2755 | foreach (explode('+', $template_name) as $template) |
@@ -2648,8 +2791,9 @@ discard block |
||
2648 | 2791 | $found = true; |
2649 | 2792 | |
2650 | 2793 | // setlocale is required for basename() & pathinfo() to work properly on the selected language |
2651 | - if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set'])) |
|
2652 | - setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']); |
|
2794 | + if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set'])) { |
|
2795 | + setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']); |
|
2796 | + } |
|
2653 | 2797 | |
2654 | 2798 | break; |
2655 | 2799 | } |
@@ -2689,8 +2833,9 @@ discard block |
||
2689 | 2833 | } |
2690 | 2834 | |
2691 | 2835 | // Keep track of what we're up to soldier. |
2692 | - if ($db_show_debug === true) |
|
2693 | - $context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')'; |
|
2836 | + if ($db_show_debug === true) { |
|
2837 | + $context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')'; |
|
2838 | + } |
|
2694 | 2839 | |
2695 | 2840 | // Remember what we have loaded, and in which language. |
2696 | 2841 | $already_loaded[$template_name] = $lang; |
@@ -2736,8 +2881,9 @@ discard block |
||
2736 | 2881 | ) |
2737 | 2882 | ); |
2738 | 2883 | // In the EXTREMELY unlikely event this happens, give an error message. |
2739 | - if ($smcFunc['db_num_rows']($result) == 0) |
|
2740 | - fatal_lang_error('parent_not_found', 'critical'); |
|
2884 | + if ($smcFunc['db_num_rows']($result) == 0) { |
|
2885 | + fatal_lang_error('parent_not_found', 'critical'); |
|
2886 | + } |
|
2741 | 2887 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
2742 | 2888 | { |
2743 | 2889 | if (!isset($boards[$row['id_board']])) |
@@ -2754,8 +2900,8 @@ discard block |
||
2754 | 2900 | ); |
2755 | 2901 | } |
2756 | 2902 | // If a moderator exists for this board, add that moderator for all children too. |
2757 | - if (!empty($row['id_moderator'])) |
|
2758 | - foreach ($boards as $id => $dummy) |
|
2903 | + if (!empty($row['id_moderator'])) { |
|
2904 | + foreach ($boards as $id => $dummy) |
|
2759 | 2905 | { |
2760 | 2906 | $boards[$id]['moderators'][$row['id_moderator']] = array( |
2761 | 2907 | 'id' => $row['id_moderator'], |
@@ -2763,11 +2909,12 @@ discard block |
||
2763 | 2909 | 'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'], |
2764 | 2910 | 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>' |
2765 | 2911 | ); |
2912 | + } |
|
2766 | 2913 | } |
2767 | 2914 | |
2768 | 2915 | // If a moderator group exists for this board, add that moderator group for all children too |
2769 | - if (!empty($row['id_moderator_group'])) |
|
2770 | - foreach ($boards as $id => $dummy) |
|
2916 | + if (!empty($row['id_moderator_group'])) { |
|
2917 | + foreach ($boards as $id => $dummy) |
|
2771 | 2918 | { |
2772 | 2919 | $boards[$id]['moderator_groups'][$row['id_moderator_group']] = array( |
2773 | 2920 | 'id' => $row['id_moderator_group'], |
@@ -2775,6 +2922,7 @@ discard block |
||
2775 | 2922 | 'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'], |
2776 | 2923 | 'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>' |
2777 | 2924 | ); |
2925 | + } |
|
2778 | 2926 | } |
2779 | 2927 | } |
2780 | 2928 | $smcFunc['db_free_result']($result); |
@@ -2801,23 +2949,27 @@ discard block |
||
2801 | 2949 | if (!$use_cache || ($context['languages'] = cache_get_data('known_languages', !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null) |
2802 | 2950 | { |
2803 | 2951 | // If we don't have our ucwords function defined yet, let's load the settings data. |
2804 | - if (empty($smcFunc['ucwords'])) |
|
2805 | - reloadSettings(); |
|
2952 | + if (empty($smcFunc['ucwords'])) { |
|
2953 | + reloadSettings(); |
|
2954 | + } |
|
2806 | 2955 | |
2807 | 2956 | // If we don't have our theme information yet, let's get it. |
2808 | - if (empty($settings['default_theme_dir'])) |
|
2809 | - loadTheme(0, false); |
|
2957 | + if (empty($settings['default_theme_dir'])) { |
|
2958 | + loadTheme(0, false); |
|
2959 | + } |
|
2810 | 2960 | |
2811 | 2961 | // Default language directories to try. |
2812 | 2962 | $language_directories = array( |
2813 | 2963 | $settings['default_theme_dir'] . '/languages', |
2814 | 2964 | ); |
2815 | - if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) |
|
2816 | - $language_directories[] = $settings['actual_theme_dir'] . '/languages'; |
|
2965 | + if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) { |
|
2966 | + $language_directories[] = $settings['actual_theme_dir'] . '/languages'; |
|
2967 | + } |
|
2817 | 2968 | |
2818 | 2969 | // We possibly have a base theme directory. |
2819 | - if (!empty($settings['base_theme_dir'])) |
|
2820 | - $language_directories[] = $settings['base_theme_dir'] . '/languages'; |
|
2970 | + if (!empty($settings['base_theme_dir'])) { |
|
2971 | + $language_directories[] = $settings['base_theme_dir'] . '/languages'; |
|
2972 | + } |
|
2821 | 2973 | |
2822 | 2974 | // Remove any duplicates. |
2823 | 2975 | $language_directories = array_unique($language_directories); |
@@ -2831,20 +2983,21 @@ discard block |
||
2831 | 2983 | foreach ($language_directories as $language_dir) |
2832 | 2984 | { |
2833 | 2985 | // Can't look in here... doesn't exist! |
2834 | - if (!file_exists($language_dir)) |
|
2835 | - continue; |
|
2986 | + if (!file_exists($language_dir)) { |
|
2987 | + continue; |
|
2988 | + } |
|
2836 | 2989 | |
2837 | 2990 | $dir = dir($language_dir); |
2838 | 2991 | while ($entry = $dir->read()) |
2839 | 2992 | { |
2840 | 2993 | // Look for the index language file... For good measure skip any "index.language-utf8.php" files |
2841 | - if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) |
|
2842 | - continue; |
|
2843 | - |
|
2844 | - if (!empty($langList) && !empty($langList[$matches[1]])) |
|
2845 | - $langName = $langList[$matches[1]]; |
|
2994 | + if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) { |
|
2995 | + continue; |
|
2996 | + } |
|
2846 | 2997 | |
2847 | - else |
|
2998 | + if (!empty($langList) && !empty($langList[$matches[1]])) { |
|
2999 | + $langName = $langList[$matches[1]]; |
|
3000 | + } else |
|
2848 | 3001 | { |
2849 | 3002 | $langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' '))); |
2850 | 3003 | |
@@ -2885,12 +3038,14 @@ discard block |
||
2885 | 3038 | } |
2886 | 3039 | |
2887 | 3040 | // Do we need to store the lang list? |
2888 | - if (empty($langList)) |
|
2889 | - updateSettings(array('langList' => $smcFunc['json_encode']($catchLang))); |
|
3041 | + if (empty($langList)) { |
|
3042 | + updateSettings(array('langList' => $smcFunc['json_encode']($catchLang))); |
|
3043 | + } |
|
2890 | 3044 | |
2891 | 3045 | // Let's cash in on this deal. |
2892 | - if (!empty($modSettings['cache_enable'])) |
|
2893 | - cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600); |
|
3046 | + if (!empty($modSettings['cache_enable'])) { |
|
3047 | + cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600); |
|
3048 | + } |
|
2894 | 3049 | } |
2895 | 3050 | |
2896 | 3051 | return $context['languages']; |
@@ -2913,8 +3068,9 @@ discard block |
||
2913 | 3068 | global $modSettings, $options, $txt; |
2914 | 3069 | static $censor_vulgar = null, $censor_proper; |
2915 | 3070 | |
2916 | - if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') |
|
2917 | - return $text; |
|
3071 | + if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') { |
|
3072 | + return $text; |
|
3073 | + } |
|
2918 | 3074 | |
2919 | 3075 | // If they haven't yet been loaded, load them. |
2920 | 3076 | if ($censor_vulgar == null) |
@@ -2942,9 +3098,9 @@ discard block |
||
2942 | 3098 | { |
2943 | 3099 | $func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace'; |
2944 | 3100 | $text = $func($censor_vulgar, $censor_proper, $text); |
3101 | + } else { |
|
3102 | + $text = preg_replace($censor_vulgar, $censor_proper, $text); |
|
2945 | 3103 | } |
2946 | - else |
|
2947 | - $text = preg_replace($censor_vulgar, $censor_proper, $text); |
|
2948 | 3104 | |
2949 | 3105 | return $text; |
2950 | 3106 | } |
@@ -2970,38 +3126,42 @@ discard block |
||
2970 | 3126 | @ini_set('track_errors', '1'); |
2971 | 3127 | |
2972 | 3128 | // Don't include the file more than once, if $once is true. |
2973 | - if ($once && in_array($filename, $templates)) |
|
2974 | - return; |
|
3129 | + if ($once && in_array($filename, $templates)) { |
|
3130 | + return; |
|
3131 | + } |
|
2975 | 3132 | // Add this file to the include list, whether $once is true or not. |
2976 | - else |
|
2977 | - $templates[] = $filename; |
|
3133 | + else { |
|
3134 | + $templates[] = $filename; |
|
3135 | + } |
|
2978 | 3136 | |
2979 | 3137 | // Are we going to use eval? |
2980 | 3138 | if (empty($modSettings['disableTemplateEval'])) |
2981 | 3139 | { |
2982 | 3140 | $file_found = file_exists($filename) && eval('?' . '>' . rtrim(file_get_contents($filename))) !== false; |
2983 | 3141 | $settings['current_include_filename'] = $filename; |
2984 | - } |
|
2985 | - else |
|
3142 | + } else |
|
2986 | 3143 | { |
2987 | 3144 | $file_found = file_exists($filename); |
2988 | 3145 | |
2989 | - if ($once && $file_found) |
|
2990 | - require_once($filename); |
|
2991 | - elseif ($file_found) |
|
2992 | - require($filename); |
|
3146 | + if ($once && $file_found) { |
|
3147 | + require_once($filename); |
|
3148 | + } elseif ($file_found) { |
|
3149 | + require($filename); |
|
3150 | + } |
|
2993 | 3151 | } |
2994 | 3152 | |
2995 | 3153 | if ($file_found !== true) |
2996 | 3154 | { |
2997 | 3155 | ob_end_clean(); |
2998 | - if (!empty($modSettings['enableCompressedOutput'])) |
|
2999 | - @ob_start('ob_gzhandler'); |
|
3000 | - else |
|
3001 | - ob_start(); |
|
3156 | + if (!empty($modSettings['enableCompressedOutput'])) { |
|
3157 | + @ob_start('ob_gzhandler'); |
|
3158 | + } else { |
|
3159 | + ob_start(); |
|
3160 | + } |
|
3002 | 3161 | |
3003 | - if (isset($_GET['debug'])) |
|
3004 | - header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
3162 | + if (isset($_GET['debug'])) { |
|
3163 | + header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
3164 | + } |
|
3005 | 3165 | |
3006 | 3166 | // Don't cache error pages!! |
3007 | 3167 | header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); |
@@ -3020,12 +3180,13 @@ discard block |
||
3020 | 3180 | echo '<!DOCTYPE html> |
3021 | 3181 | <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '> |
3022 | 3182 | <head>'; |
3023 | - if (isset($context['character_set'])) |
|
3024 | - echo ' |
|
3183 | + if (isset($context['character_set'])) { |
|
3184 | + echo ' |
|
3025 | 3185 | <meta charset="', $context['character_set'], '">'; |
3186 | + } |
|
3026 | 3187 | |
3027 | - if (!empty($maintenance) && !allowedTo('admin_forum')) |
|
3028 | - echo ' |
|
3188 | + if (!empty($maintenance) && !allowedTo('admin_forum')) { |
|
3189 | + echo ' |
|
3029 | 3190 | <title>', $mtitle, '</title> |
3030 | 3191 | </head> |
3031 | 3192 | <body> |
@@ -3033,8 +3194,8 @@ discard block |
||
3033 | 3194 | ', $mmessage, ' |
3034 | 3195 | </body> |
3035 | 3196 | </html>'; |
3036 | - elseif (!allowedTo('admin_forum')) |
|
3037 | - echo ' |
|
3197 | + } elseif (!allowedTo('admin_forum')) { |
|
3198 | + echo ' |
|
3038 | 3199 | <title>', $txt['template_parse_error'], '</title> |
3039 | 3200 | </head> |
3040 | 3201 | <body> |
@@ -3042,16 +3203,18 @@ discard block |
||
3042 | 3203 | ', $txt['template_parse_error_message'], ' |
3043 | 3204 | </body> |
3044 | 3205 | </html>'; |
3045 | - else |
|
3206 | + } else |
|
3046 | 3207 | { |
3047 | 3208 | require_once($sourcedir . '/Subs-Package.php'); |
3048 | 3209 | |
3049 | 3210 | $error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => ''))); |
3050 | 3211 | $error_array = error_get_last(); |
3051 | - if (empty($error) && ini_get('track_errors') && !empty($error_array)) |
|
3052 | - $error = $error_array['message']; |
|
3053 | - if (empty($error)) |
|
3054 | - $error = $txt['template_parse_errmsg']; |
|
3212 | + if (empty($error) && ini_get('track_errors') && !empty($error_array)) { |
|
3213 | + $error = $error_array['message']; |
|
3214 | + } |
|
3215 | + if (empty($error)) { |
|
3216 | + $error = $txt['template_parse_errmsg']; |
|
3217 | + } |
|
3055 | 3218 | |
3056 | 3219 | $error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>')); |
3057 | 3220 | |
@@ -3062,11 +3225,12 @@ discard block |
||
3062 | 3225 | <h3>', $txt['template_parse_error'], '</h3> |
3063 | 3226 | ', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => ''))); |
3064 | 3227 | |
3065 | - if (!empty($error)) |
|
3066 | - echo ' |
|
3228 | + if (!empty($error)) { |
|
3229 | + echo ' |
|
3067 | 3230 | <hr> |
3068 | 3231 | |
3069 | 3232 | <div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>'; |
3233 | + } |
|
3070 | 3234 | |
3071 | 3235 | // I know, I know... this is VERY COMPLICATED. Still, it's good. |
3072 | 3236 | if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0) |
@@ -3076,10 +3240,11 @@ discard block |
||
3076 | 3240 | $data2 = preg_split('~\<br( /)?\>~', $data2); |
3077 | 3241 | |
3078 | 3242 | // Fix the PHP code stuff... |
3079 | - if (!isBrowser('gecko')) |
|
3080 | - $data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2); |
|
3081 | - else |
|
3082 | - $data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2); |
|
3243 | + if (!isBrowser('gecko')) { |
|
3244 | + $data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2); |
|
3245 | + } else { |
|
3246 | + $data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2); |
|
3247 | + } |
|
3083 | 3248 | |
3084 | 3249 | // Now we get to work around a bug in PHP where it doesn't escape <br>s! |
3085 | 3250 | $j = -1; |
@@ -3087,8 +3252,9 @@ discard block |
||
3087 | 3252 | { |
3088 | 3253 | $j++; |
3089 | 3254 | |
3090 | - if (substr_count($line, '<br>') == 0) |
|
3091 | - continue; |
|
3255 | + if (substr_count($line, '<br>') == 0) { |
|
3256 | + continue; |
|
3257 | + } |
|
3092 | 3258 | |
3093 | 3259 | $n = substr_count($line, '<br>'); |
3094 | 3260 | for ($i = 0; $i < $n; $i++) |
@@ -3107,38 +3273,42 @@ discard block |
||
3107 | 3273 | // Figure out what the color coding was before... |
3108 | 3274 | $line = max($match[1] - 9, 1); |
3109 | 3275 | $last_line = ''; |
3110 | - for ($line2 = $line - 1; $line2 > 1; $line2--) |
|
3111 | - if (strpos($data2[$line2], '<') !== false) |
|
3276 | + for ($line2 = $line - 1; $line2 > 1; $line2--) { |
|
3277 | + if (strpos($data2[$line2], '<') !== false) |
|
3112 | 3278 | { |
3113 | 3279 | if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0) |
3114 | 3280 | $last_line = $color_match[1]; |
3281 | + } |
|
3115 | 3282 | break; |
3116 | 3283 | } |
3117 | 3284 | |
3118 | 3285 | // Show the relevant lines... |
3119 | 3286 | for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++) |
3120 | 3287 | { |
3121 | - if ($line == $match[1]) |
|
3122 | - echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">'; |
|
3288 | + if ($line == $match[1]) { |
|
3289 | + echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">'; |
|
3290 | + } |
|
3123 | 3291 | |
3124 | 3292 | echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> '; |
3125 | - if (isset($data2[$line]) && $data2[$line] != '') |
|
3126 | - echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line]; |
|
3293 | + if (isset($data2[$line]) && $data2[$line] != '') { |
|
3294 | + echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line]; |
|
3295 | + } |
|
3127 | 3296 | |
3128 | 3297 | if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0) |
3129 | 3298 | { |
3130 | 3299 | $last_line = $color_match[1]; |
3131 | 3300 | echo '</', substr($last_line, 1, 4), '>'; |
3301 | + } elseif ($last_line != '' && strpos($data2[$line], '<') !== false) { |
|
3302 | + $last_line = ''; |
|
3303 | + } elseif ($last_line != '' && $data2[$line] != '') { |
|
3304 | + echo '</', substr($last_line, 1, 4), '>'; |
|
3132 | 3305 | } |
3133 | - elseif ($last_line != '' && strpos($data2[$line], '<') !== false) |
|
3134 | - $last_line = ''; |
|
3135 | - elseif ($last_line != '' && $data2[$line] != '') |
|
3136 | - echo '</', substr($last_line, 1, 4), '>'; |
|
3137 | 3306 | |
3138 | - if ($line == $match[1]) |
|
3139 | - echo '</pre></div><pre style="margin: 0;">'; |
|
3140 | - else |
|
3141 | - echo "\n"; |
|
3307 | + if ($line == $match[1]) { |
|
3308 | + echo '</pre></div><pre style="margin: 0;">'; |
|
3309 | + } else { |
|
3310 | + echo "\n"; |
|
3311 | + } |
|
3142 | 3312 | } |
3143 | 3313 | |
3144 | 3314 | echo '</pre></div>'; |
@@ -3162,8 +3332,9 @@ discard block |
||
3162 | 3332 | global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port; |
3163 | 3333 | |
3164 | 3334 | // Figure out what type of database we are using. |
3165 | - if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) |
|
3166 | - $db_type = 'mysql'; |
|
3335 | + if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) { |
|
3336 | + $db_type = 'mysql'; |
|
3337 | + } |
|
3167 | 3338 | |
3168 | 3339 | // Load the file for the database. |
3169 | 3340 | require_once($sourcedir . '/Subs-Db-' . $db_type . '.php'); |
@@ -3171,8 +3342,9 @@ discard block |
||
3171 | 3342 | $db_options = array(); |
3172 | 3343 | |
3173 | 3344 | // Add in the port if needed |
3174 | - if (!empty($db_port)) |
|
3175 | - $db_options['port'] = $db_port; |
|
3345 | + if (!empty($db_port)) { |
|
3346 | + $db_options['port'] = $db_port; |
|
3347 | + } |
|
3176 | 3348 | |
3177 | 3349 | // If we are in SSI try them first, but don't worry if it doesn't work, we have the normal username and password we can use. |
3178 | 3350 | if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd)) |
@@ -3191,13 +3363,15 @@ discard block |
||
3191 | 3363 | } |
3192 | 3364 | |
3193 | 3365 | // Safe guard here, if there isn't a valid connection lets put a stop to it. |
3194 | - if (!$db_connection) |
|
3195 | - display_db_error(); |
|
3366 | + if (!$db_connection) { |
|
3367 | + display_db_error(); |
|
3368 | + } |
|
3196 | 3369 | |
3197 | 3370 | // If in SSI mode fix up the prefix. |
3198 | - if (SMF == 'SSI') |
|
3199 | - db_fix_prefix($db_prefix, $db_name); |
|
3200 | -} |
|
3371 | + if (SMF == 'SSI') { |
|
3372 | + db_fix_prefix($db_prefix, $db_name); |
|
3373 | + } |
|
3374 | + } |
|
3201 | 3375 | |
3202 | 3376 | /** |
3203 | 3377 | * Try to load up a supported caching method. This is saved in $cacheAPI if we are not overriding it. |
@@ -3211,10 +3385,11 @@ discard block |
||
3211 | 3385 | global $sourcedir, $cacheAPI, $cache_accelerator; |
3212 | 3386 | |
3213 | 3387 | // Not overriding this and we have a cacheAPI, send it back. |
3214 | - if (empty($overrideCache) && is_object($cacheAPI)) |
|
3215 | - return $cacheAPI; |
|
3216 | - elseif (is_null($cacheAPI)) |
|
3217 | - $cacheAPI = false; |
|
3388 | + if (empty($overrideCache) && is_object($cacheAPI)) { |
|
3389 | + return $cacheAPI; |
|
3390 | + } elseif (is_null($cacheAPI)) { |
|
3391 | + $cacheAPI = false; |
|
3392 | + } |
|
3218 | 3393 | |
3219 | 3394 | // Make sure our class is in session. |
3220 | 3395 | require_once($sourcedir . '/Class-CacheAPI.php'); |
@@ -3235,8 +3410,9 @@ discard block |
||
3235 | 3410 | if (!$testAPI->isSupported()) |
3236 | 3411 | { |
3237 | 3412 | // Can we save ourselves? |
3238 | - if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') |
|
3239 | - return loadCacheAccelerator(null, false); |
|
3413 | + if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') { |
|
3414 | + return loadCacheAccelerator(null, false); |
|
3415 | + } |
|
3240 | 3416 | return false; |
3241 | 3417 | } |
3242 | 3418 | |
@@ -3248,9 +3424,9 @@ discard block |
||
3248 | 3424 | { |
3249 | 3425 | $cacheAPI = $testAPI; |
3250 | 3426 | return $cacheAPI; |
3427 | + } else { |
|
3428 | + return $testAPI; |
|
3251 | 3429 | } |
3252 | - else |
|
3253 | - return $testAPI; |
|
3254 | 3430 | } |
3255 | 3431 | } |
3256 | 3432 | |
@@ -3270,8 +3446,9 @@ discard block |
||
3270 | 3446 | |
3271 | 3447 | // @todo Why are we doing this if caching is disabled? |
3272 | 3448 | |
3273 | - if (function_exists('call_integration_hook')) |
|
3274 | - call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level)); |
|
3449 | + if (function_exists('call_integration_hook')) { |
|
3450 | + call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level)); |
|
3451 | + } |
|
3275 | 3452 | |
3276 | 3453 | /* Refresh the cache if either: |
3277 | 3454 | 1. Caching is disabled. |
@@ -3285,16 +3462,19 @@ discard block |
||
3285 | 3462 | require_once($sourcedir . '/' . $file); |
3286 | 3463 | $cache_block = call_user_func_array($function, $params); |
3287 | 3464 | |
3288 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) |
|
3289 | - cache_put_data($key, $cache_block, $cache_block['expires'] - time()); |
|
3465 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) { |
|
3466 | + cache_put_data($key, $cache_block, $cache_block['expires'] - time()); |
|
3467 | + } |
|
3290 | 3468 | } |
3291 | 3469 | |
3292 | 3470 | // Some cached data may need a freshening up after retrieval. |
3293 | - if (!empty($cache_block['post_retri_eval'])) |
|
3294 | - eval($cache_block['post_retri_eval']); |
|
3471 | + if (!empty($cache_block['post_retri_eval'])) { |
|
3472 | + eval($cache_block['post_retri_eval']); |
|
3473 | + } |
|
3295 | 3474 | |
3296 | - if (function_exists('call_integration_hook')) |
|
3297 | - call_integration_hook('post_cache_quick_get', array(&$cache_block)); |
|
3475 | + if (function_exists('call_integration_hook')) { |
|
3476 | + call_integration_hook('post_cache_quick_get', array(&$cache_block)); |
|
3477 | + } |
|
3298 | 3478 | |
3299 | 3479 | return $cache_block['data']; |
3300 | 3480 | } |
@@ -3321,8 +3501,9 @@ discard block |
||
3321 | 3501 | global $smcFunc, $cache_enable, $cacheAPI; |
3322 | 3502 | global $cache_hits, $cache_count, $db_show_debug; |
3323 | 3503 | |
3324 | - if (empty($cache_enable) || empty($cacheAPI)) |
|
3325 | - return; |
|
3504 | + if (empty($cache_enable) || empty($cacheAPI)) { |
|
3505 | + return; |
|
3506 | + } |
|
3326 | 3507 | |
3327 | 3508 | $cache_count = isset($cache_count) ? $cache_count + 1 : 1; |
3328 | 3509 | if (isset($db_show_debug) && $db_show_debug === true) |
@@ -3335,12 +3516,14 @@ discard block |
||
3335 | 3516 | $value = $value === null ? null : (isset($smcFunc['json_encode']) ? $smcFunc['json_encode']($value) : json_encode($value)); |
3336 | 3517 | $cacheAPI->putData($key, $value, $ttl); |
3337 | 3518 | |
3338 | - if (function_exists('call_integration_hook')) |
|
3339 | - call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl)); |
|
3519 | + if (function_exists('call_integration_hook')) { |
|
3520 | + call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl)); |
|
3521 | + } |
|
3340 | 3522 | |
3341 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
3342 | - $cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
3343 | -} |
|
3523 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
3524 | + $cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
3525 | + } |
|
3526 | + } |
|
3344 | 3527 | |
3345 | 3528 | /** |
3346 | 3529 | * Gets the value from the cache specified by key, so long as it is not older than ttl seconds. |
@@ -3356,8 +3539,9 @@ discard block |
||
3356 | 3539 | global $smcFunc, $cache_enable, $cacheAPI; |
3357 | 3540 | global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug; |
3358 | 3541 | |
3359 | - if (empty($cache_enable) || empty($cacheAPI)) |
|
3360 | - return; |
|
3542 | + if (empty($cache_enable) || empty($cacheAPI)) { |
|
3543 | + return; |
|
3544 | + } |
|
3361 | 3545 | |
3362 | 3546 | $cache_count = isset($cache_count) ? $cache_count + 1 : 1; |
3363 | 3547 | if (isset($db_show_debug) && $db_show_debug === true) |
@@ -3377,16 +3561,18 @@ discard block |
||
3377 | 3561 | |
3378 | 3562 | if (empty($value)) |
3379 | 3563 | { |
3380 | - if (!is_array($cache_misses)) |
|
3381 | - $cache_misses = array(); |
|
3564 | + if (!is_array($cache_misses)) { |
|
3565 | + $cache_misses = array(); |
|
3566 | + } |
|
3382 | 3567 | |
3383 | 3568 | $cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1; |
3384 | 3569 | $cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get'); |
3385 | 3570 | } |
3386 | 3571 | } |
3387 | 3572 | |
3388 | - if (function_exists('call_integration_hook') && isset($value)) |
|
3389 | - call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value)); |
|
3573 | + if (function_exists('call_integration_hook') && isset($value)) { |
|
3574 | + call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value)); |
|
3575 | + } |
|
3390 | 3576 | |
3391 | 3577 | return empty($value) ? null : (isset($smcFunc['json_encode']) ? $smcFunc['json_decode']($value, true) : smf_json_decode($value, true)); |
3392 | 3578 | } |
@@ -3408,8 +3594,9 @@ discard block |
||
3408 | 3594 | global $cacheAPI; |
3409 | 3595 | |
3410 | 3596 | // If we can't get to the API, can't do this. |
3411 | - if (empty($cacheAPI)) |
|
3412 | - return; |
|
3597 | + if (empty($cacheAPI)) { |
|
3598 | + return; |
|
3599 | + } |
|
3413 | 3600 | |
3414 | 3601 | // Ask the API to do the heavy lifting. cleanCache also calls invalidateCache to be sure. |
3415 | 3602 | $cacheAPI->cleanCache($type); |
@@ -3434,8 +3621,9 @@ discard block |
||
3434 | 3621 | global $modSettings, $boardurl, $smcFunc, $image_proxy_enabled, $image_proxy_secret; |
3435 | 3622 | |
3436 | 3623 | // Come on! |
3437 | - if (empty($data)) |
|
3438 | - return array(); |
|
3624 | + if (empty($data)) { |
|
3625 | + return array(); |
|
3626 | + } |
|
3439 | 3627 | |
3440 | 3628 | // Set a nice default var. |
3441 | 3629 | $image = ''; |
@@ -3443,11 +3631,11 @@ discard block |
||
3443 | 3631 | // Gravatar has been set as mandatory! |
3444 | 3632 | if (!empty($modSettings['gravatarOverride'])) |
3445 | 3633 | { |
3446 | - if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) |
|
3447 | - $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
3448 | - |
|
3449 | - else if (!empty($data['email'])) |
|
3450 | - $image = get_gravatar_url($data['email']); |
|
3634 | + if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) { |
|
3635 | + $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
3636 | + } else if (!empty($data['email'])) { |
|
3637 | + $image = get_gravatar_url($data['email']); |
|
3638 | + } |
|
3451 | 3639 | } |
3452 | 3640 | |
3453 | 3641 | // Look if the user has a gravatar field or has set an external url as avatar. |
@@ -3459,54 +3647,60 @@ discard block |
||
3459 | 3647 | // Gravatar. |
3460 | 3648 | if (stristr($data['avatar'], 'gravatar://')) |
3461 | 3649 | { |
3462 | - if ($data['avatar'] == 'gravatar://') |
|
3463 | - $image = get_gravatar_url($data['email']); |
|
3464 | - |
|
3465 | - elseif (!empty($modSettings['gravatarAllowExtraEmail'])) |
|
3466 | - $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
3650 | + if ($data['avatar'] == 'gravatar://') { |
|
3651 | + $image = get_gravatar_url($data['email']); |
|
3652 | + } elseif (!empty($modSettings['gravatarAllowExtraEmail'])) { |
|
3653 | + $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
3654 | + } |
|
3467 | 3655 | } |
3468 | 3656 | |
3469 | 3657 | // External url. |
3470 | 3658 | else |
3471 | 3659 | { |
3472 | 3660 | // Using ssl? |
3473 | - if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false) |
|
3474 | - $image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret); |
|
3661 | + if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false) { |
|
3662 | + $image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret); |
|
3663 | + } |
|
3475 | 3664 | |
3476 | 3665 | // Just a plain external url. |
3477 | - else |
|
3478 | - $image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar']; |
|
3666 | + else { |
|
3667 | + $image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar']; |
|
3668 | + } |
|
3479 | 3669 | } |
3480 | 3670 | } |
3481 | 3671 | |
3482 | 3672 | // Perhaps this user has an attachment as avatar... |
3483 | - else if (!empty($data['filename'])) |
|
3484 | - $image = $modSettings['custom_avatar_url'] . '/' . $data['filename']; |
|
3673 | + else if (!empty($data['filename'])) { |
|
3674 | + $image = $modSettings['custom_avatar_url'] . '/' . $data['filename']; |
|
3675 | + } |
|
3485 | 3676 | |
3486 | 3677 | // Right... no avatar... use our default image. |
3487 | - else |
|
3488 | - $image = $modSettings['avatar_url'] . '/default.png'; |
|
3678 | + else { |
|
3679 | + $image = $modSettings['avatar_url'] . '/default.png'; |
|
3680 | + } |
|
3489 | 3681 | } |
3490 | 3682 | |
3491 | 3683 | call_integration_hook('integrate_set_avatar_data', array(&$image, &$data)); |
3492 | 3684 | |
3493 | 3685 | // At this point in time $image has to be filled unless you chose to force gravatar and the user doesn't have the needed data to retrieve it... thus a check for !empty() is still needed. |
3494 | - if (!empty($image)) |
|
3495 | - return array( |
|
3686 | + if (!empty($image)) { |
|
3687 | + return array( |
|
3496 | 3688 | 'name' => !empty($data['avatar']) ? $data['avatar'] : '', |
3497 | 3689 | 'image' => '<img class="avatar" src="' . $image . '" />', |
3498 | 3690 | 'href' => $image, |
3499 | 3691 | 'url' => $image, |
3500 | 3692 | ); |
3693 | + } |
|
3501 | 3694 | |
3502 | 3695 | // Fallback to make life easier for everyone... |
3503 | - else |
|
3504 | - return array( |
|
3696 | + else { |
|
3697 | + return array( |
|
3505 | 3698 | 'name' => '', |
3506 | 3699 | 'image' => '', |
3507 | 3700 | 'href' => '', |
3508 | 3701 | 'url' => '', |
3509 | 3702 | ); |
3510 | -} |
|
3703 | + } |
|
3704 | + } |
|
3511 | 3705 | |
3512 | 3706 | ?> |
3513 | 3707 | \ No newline at end of file |
@@ -41,37 +41,43 @@ discard block |
||
41 | 41 | define('TIME_START', microtime(true)); |
42 | 42 | |
43 | 43 | // Just being safe... |
44 | -foreach (array('db_character_set', 'cachedir') as $variable) |
|
44 | +foreach (array('db_character_set', 'cachedir') as $variable) { |
|
45 | 45 | if (isset($GLOBALS[$variable])) |
46 | 46 | unset($GLOBALS[$variable]); |
47 | +} |
|
47 | 48 | |
48 | 49 | // Get the forum's settings for database and file paths. |
49 | 50 | require_once(dirname(__FILE__) . '/Settings.php'); |
50 | 51 | |
51 | 52 | // Make absolutely sure the cache directory is defined. |
52 | -if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) |
|
53 | +if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) { |
|
53 | 54 | $cachedir = $boarddir . '/cache'; |
55 | +} |
|
54 | 56 | |
55 | 57 | // Don't do john didley if the forum's been shut down competely. |
56 | -if ($maintenance == 2) |
|
58 | +if ($maintenance == 2) { |
|
57 | 59 | die($mmessage); |
60 | +} |
|
58 | 61 | |
59 | 62 | // Fix for using the current directory as a path. |
60 | -if (substr($sourcedir, 0, 1) == '.' && substr($sourcedir, 1, 1) != '.') |
|
63 | +if (substr($sourcedir, 0, 1) == '.' && substr($sourcedir, 1, 1) != '.') { |
|
61 | 64 | $sourcedir = dirname(__FILE__) . substr($sourcedir, 1); |
65 | +} |
|
62 | 66 | |
63 | 67 | // Have we already turned this off? If so, exist gracefully. |
64 | -if (file_exists($cachedir . '/cron.lock')) |
|
68 | +if (file_exists($cachedir . '/cron.lock')) { |
|
65 | 69 | obExit_cron(); |
70 | +} |
|
66 | 71 | |
67 | 72 | // Before we go any further, if this is not a CLI request, we need to do some checking. |
68 | 73 | if (!FROM_CLI) |
69 | 74 | { |
70 | 75 | // We will clean up $_GET shortly. But we want to this ASAP. |
71 | 76 | $ts = isset($_GET['ts']) ? (int) $_GET['ts'] : 0; |
72 | - if ($ts <= 0 || $ts % 15 != 0 || time() - $ts < 0 || time() - $ts > 20) |
|
73 | - obExit_cron(); |
|
74 | -} |
|
77 | + if ($ts <= 0 || $ts % 15 != 0 || time() - $ts < 0 || time() - $ts > 20) { |
|
78 | + obExit_cron(); |
|
79 | + } |
|
80 | + } |
|
75 | 81 | |
76 | 82 | // Load the most important includes. In general, a background should be loading its own dependencies. |
77 | 83 | require_once($sourcedir . '/Errors.php'); |
@@ -123,8 +129,9 @@ discard block |
||
123 | 129 | global $smcFunc; |
124 | 130 | |
125 | 131 | // Check we haven't run over our time limit. |
126 | - if (microtime(true) - TIME_START > MAX_CRON_TIME) |
|
127 | - return false; |
|
132 | + if (microtime(true) - TIME_START > MAX_CRON_TIME) { |
|
133 | + return false; |
|
134 | + } |
|
128 | 135 | |
129 | 136 | // Try to find a task. Specifically, try to find one that hasn't been claimed previously, or failing that, |
130 | 137 | // a task that was claimed but failed for whatever reason and failed long enough ago. We should not care |
@@ -159,14 +166,12 @@ discard block |
||
159 | 166 | // Update the time and go back. |
160 | 167 | $row['claimed_time'] = time(); |
161 | 168 | return $row; |
162 | - } |
|
163 | - else |
|
169 | + } else |
|
164 | 170 | { |
165 | 171 | // Uh oh, we just missed it. Try to claim another one, and let it fall through if there aren't any. |
166 | 172 | return fetch_task(); |
167 | 173 | } |
168 | - } |
|
169 | - else |
|
174 | + } else |
|
170 | 175 | { |
171 | 176 | // No dice. Clean up and go home. |
172 | 177 | $smcFunc['db_free_result']($request); |
@@ -187,8 +192,9 @@ discard block |
||
187 | 192 | if (!empty($task_details['task_file'])) |
188 | 193 | { |
189 | 194 | $include = strtr(trim($task_details['task_file']), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
190 | - if (file_exists($include)) |
|
191 | - require_once($include); |
|
195 | + if (file_exists($include)) { |
|
196 | + require_once($include); |
|
197 | + } |
|
192 | 198 | } |
193 | 199 | |
194 | 200 | if (empty($task_details['task_class'])) |
@@ -204,8 +210,7 @@ discard block |
||
204 | 210 | $details = empty($task_details['task_data']) ? array() : $smcFunc['json_decode']($task_details['task_data'], true); |
205 | 211 | $bgtask = new $task_details['task_class']($details); |
206 | 212 | return $bgtask->execute(); |
207 | - } |
|
208 | - else |
|
213 | + } else |
|
209 | 214 | { |
210 | 215 | log_error('Invalid background task specified: (class: ' . $task_details['task_class'] . ', ' . (empty($task_details['task_file']) ? ' no file' : ' to load ' . $task_details['task_file']) . ')'); |
211 | 216 | return true; // So we clear it from the queue. |
@@ -224,8 +229,9 @@ discard block |
||
224 | 229 | $scripturl = $boardurl . '/index.php'; |
225 | 230 | |
226 | 231 | // These keys shouldn't be set...ever. |
227 | - if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS'])) |
|
228 | - die('Invalid request variable.'); |
|
232 | + if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS'])) { |
|
233 | + die('Invalid request variable.'); |
|
234 | + } |
|
229 | 235 | |
230 | 236 | // Save some memory.. (since we don't use these anyway.) |
231 | 237 | unset($GLOBALS['HTTP_POST_VARS'], $GLOBALS['HTTP_POST_VARS']); |
@@ -246,26 +252,28 @@ discard block |
||
246 | 252 | global $modSettings; |
247 | 253 | |
248 | 254 | // Ignore errors if we're ignoring them or they are strict notices from PHP 5 (which cannot be solved without breaking PHP 4.) |
249 | - if (error_reporting() == 0 || (defined('E_STRICT') && $error_level == E_STRICT && !empty($modSettings['enableErrorLogging']))) |
|
250 | - return; |
|
255 | + if (error_reporting() == 0 || (defined('E_STRICT') && $error_level == E_STRICT && !empty($modSettings['enableErrorLogging']))) { |
|
256 | + return; |
|
257 | + } |
|
251 | 258 | |
252 | 259 | $error_type = 'cron'; |
253 | 260 | |
254 | 261 | log_error($error_level . ': ' . $error_string, $error_type, $file, $line); |
255 | 262 | |
256 | 263 | // If this is an E_ERROR or E_USER_ERROR.... die. Violently so. |
257 | - if ($error_level % 255 == E_ERROR) |
|
258 | - die('No direct access...'); |
|
259 | -} |
|
264 | + if ($error_level % 255 == E_ERROR) { |
|
265 | + die('No direct access...'); |
|
266 | + } |
|
267 | + } |
|
260 | 268 | |
261 | 269 | /** |
262 | 270 | * The exit function |
263 | 271 | */ |
264 | 272 | function obExit_cron() |
265 | 273 | { |
266 | - if (FROM_CLI) |
|
267 | - die(0); |
|
268 | - else |
|
274 | + if (FROM_CLI) { |
|
275 | + die(0); |
|
276 | + } else |
|
269 | 277 | { |
270 | 278 | header('Content-Type: image/gif'); |
271 | 279 | die("\x47\x49\x46\x38\x39\x61\x01\x00\x01\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x21\xF9\x04\x01\x00\x00\x00\x00\x2C\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02\x44\x01\x00\x3B"); |