@@ -1,9 +1,10 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | // Try to handle it with the upper level index.php. (it should know what to do.) |
4 | -if (file_exists(dirname(dirname(__FILE__)) . '/index.php')) |
|
4 | +if (file_exists(dirname(dirname(__FILE__)) . '/index.php')) { |
|
5 | 5 | include (dirname(dirname(__FILE__)) . '/index.php'); |
6 | -else |
|
6 | +} else { |
|
7 | 7 | exit; |
8 | +} |
|
8 | 9 | |
9 | 10 | ?> |
10 | 11 | \ No newline at end of file |
@@ -1,9 +1,10 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | // Try to handle it with the upper level index.php. (it should know what to do.) |
4 | -if (file_exists(dirname(dirname(__FILE__)) . '/index.php')) |
|
4 | +if (file_exists(dirname(dirname(__FILE__)) . '/index.php')) { |
|
5 | 5 | include (dirname(dirname(__FILE__)) . '/index.php'); |
6 | -else |
|
6 | +} else { |
|
7 | 7 | exit; |
8 | +} |
|
8 | 9 | |
9 | 10 | ?> |
10 | 11 | \ No newline at end of file |
@@ -1,9 +1,10 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | // Try to handle it with the upper level index.php. (it should know what to do.) |
4 | -if (file_exists(dirname(dirname(__FILE__)) . '/index.php')) |
|
4 | +if (file_exists(dirname(dirname(__FILE__)) . '/index.php')) { |
|
5 | 5 | include (dirname(dirname(__FILE__)) . '/index.php'); |
6 | -else |
|
6 | +} else { |
|
7 | 7 | exit; |
8 | +} |
|
8 | 9 | |
9 | 10 | ?> |
10 | 11 | \ No newline at end of file |
@@ -1,9 +1,10 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | // Try to handle it with the upper level index.php. (it should know what to do.) |
4 | -if (file_exists(dirname(dirname(__FILE__)) . '/index.php')) |
|
4 | +if (file_exists(dirname(dirname(__FILE__)) . '/index.php')) { |
|
5 | 5 | include (dirname(dirname(__FILE__)) . '/index.php'); |
6 | -else |
|
6 | +} else { |
|
7 | 7 | exit; |
8 | +} |
|
8 | 9 | |
9 | 10 | ?> |
10 | 11 | \ No newline at end of file |
@@ -1,9 +1,10 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | // Try to handle it with the upper level index.php. (it should know what to do.) |
4 | -if (file_exists(dirname(dirname(__FILE__)) . '/index.php')) |
|
4 | +if (file_exists(dirname(dirname(__FILE__)) . '/index.php')) { |
|
5 | 5 | include (dirname(dirname(__FILE__)) . '/index.php'); |
6 | -else |
|
6 | +} else { |
|
7 | 7 | exit; |
8 | +} |
|
8 | 9 | |
9 | 10 | ?> |
10 | 11 | \ No newline at end of file |
@@ -1,9 +1,10 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | // Try to handle it with the upper level index.php. (it should know what to do.) |
4 | -if (file_exists(dirname(dirname(__FILE__)) . '/index.php')) |
|
4 | +if (file_exists(dirname(dirname(__FILE__)) . '/index.php')) { |
|
5 | 5 | include (dirname(dirname(__FILE__)) . '/index.php'); |
6 | -else |
|
6 | +} else { |
|
7 | 7 | exit; |
8 | +} |
|
8 | 9 | |
9 | 10 | ?> |
10 | 11 | \ No newline at end of file |
@@ -14,8 +14,9 @@ discard block |
||
14 | 14 | * @version 2.1 Beta 3 |
15 | 15 | */ |
16 | 16 | |
17 | -if (!defined('SMF')) |
|
17 | +if (!defined('SMF')) { |
|
18 | 18 | die('No direct access...'); |
19 | +} |
|
19 | 20 | |
20 | 21 | /** |
21 | 22 | * Shows a listing of registered members. |
@@ -110,8 +111,9 @@ discard block |
||
110 | 111 | |
111 | 112 | $context['custom_profile_fields'] = getCustFieldsMList(); |
112 | 113 | |
113 | - if (!empty($context['custom_profile_fields']['columns'])) |
|
114 | - $context['columns'] += $context['custom_profile_fields']['columns']; |
|
114 | + if (!empty($context['custom_profile_fields']['columns'])) { |
|
115 | + $context['columns'] += $context['custom_profile_fields']['columns']; |
|
116 | + } |
|
115 | 117 | |
116 | 118 | $context['colspan'] = 0; |
117 | 119 | $context['disabled_fields'] = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array(); |
@@ -147,12 +149,12 @@ discard block |
||
147 | 149 | call_integration_hook('integrate_memberlist_buttons'); |
148 | 150 | |
149 | 151 | // Jump to the sub action. |
150 | - if (isset($subActions[$context['listing_by']])) |
|
151 | - call_helper($subActions[$context['listing_by']][1]); |
|
152 | - |
|
153 | - else |
|
154 | - call_helper($subActions['all'][1]); |
|
155 | -} |
|
152 | + if (isset($subActions[$context['listing_by']])) { |
|
153 | + call_helper($subActions[$context['listing_by']][1]); |
|
154 | + } else { |
|
155 | + call_helper($subActions['all'][1]); |
|
156 | + } |
|
157 | + } |
|
156 | 158 | |
157 | 159 | /** |
158 | 160 | * List all members, page by page, with sorting. |
@@ -177,8 +179,9 @@ discard block |
||
177 | 179 | if ($use_cache) |
178 | 180 | { |
179 | 181 | // Maybe there's something cached already. |
180 | - if (!empty($modSettings['memberlist_cache'])) |
|
181 | - $memberlist_cache = smf_json_decode($modSettings['memberlist_cache'], true); |
|
182 | + if (!empty($modSettings['memberlist_cache'])) { |
|
183 | + $memberlist_cache = smf_json_decode($modSettings['memberlist_cache'], true); |
|
184 | + } |
|
182 | 185 | |
183 | 186 | // The chunk size for the cached index. |
184 | 187 | $cache_step_size = 500; |
@@ -234,13 +237,15 @@ discard block |
||
234 | 237 | } |
235 | 238 | |
236 | 239 | // Set defaults for sort (real_name) and start. (0) |
237 | - if (!isset($_REQUEST['sort']) || !isset($context['columns'][$_REQUEST['sort']])) |
|
238 | - $_REQUEST['sort'] = 'real_name'; |
|
240 | + if (!isset($_REQUEST['sort']) || !isset($context['columns'][$_REQUEST['sort']])) { |
|
241 | + $_REQUEST['sort'] = 'real_name'; |
|
242 | + } |
|
239 | 243 | |
240 | 244 | if (!is_numeric($_REQUEST['start'])) |
241 | 245 | { |
242 | - if (preg_match('~^[^\'\\\\/]~' . ($context['utf8'] ? 'u' : ''), $smcFunc['strtolower']($_REQUEST['start']), $match) === 0) |
|
243 | - fatal_error('Hacker?', false); |
|
246 | + if (preg_match('~^[^\'\\\\/]~' . ($context['utf8'] ? 'u' : ''), $smcFunc['strtolower']($_REQUEST['start']), $match) === 0) { |
|
247 | + fatal_error('Hacker?', false); |
|
248 | + } |
|
244 | 249 | |
245 | 250 | $_REQUEST['start'] = $match[0]; |
246 | 251 | |
@@ -259,16 +264,18 @@ discard block |
||
259 | 264 | } |
260 | 265 | |
261 | 266 | $context['letter_links'] = ''; |
262 | - for ($i = 97; $i < 123; $i++) |
|
263 | - $context['letter_links'] .= '<a href="' . $scripturl . '?action=mlist;sa=all;start=' . chr($i) . '#letter' . chr($i) . '">' . strtoupper(chr($i)) . '</a> '; |
|
267 | + for ($i = 97; $i < 123; $i++) { |
|
268 | + $context['letter_links'] .= '<a href="' . $scripturl . '?action=mlist;sa=all;start=' . chr($i) . '#letter' . chr($i) . '">' . strtoupper(chr($i)) . '</a> '; |
|
269 | + } |
|
264 | 270 | |
265 | 271 | // Sort out the column information. |
266 | 272 | foreach ($context['columns'] as $col => $column_details) |
267 | 273 | { |
268 | 274 | $context['columns'][$col]['href'] = $scripturl . '?action=mlist;sort=' . $col . ';start=0'; |
269 | 275 | |
270 | - if ((!isset($_REQUEST['desc']) && $col == $_REQUEST['sort']) || ($col != $_REQUEST['sort'] && !empty($column_details['default_sort_rev']))) |
|
271 | - $context['columns'][$col]['href'] .= ';desc'; |
|
276 | + if ((!isset($_REQUEST['desc']) && $col == $_REQUEST['sort']) || ($col != $_REQUEST['sort'] && !empty($column_details['default_sort_rev']))) { |
|
277 | + $context['columns'][$col]['href'] .= ';desc'; |
|
278 | + } |
|
272 | 279 | |
273 | 280 | $context['columns'][$col]['link'] = '<a href="' . $context['columns'][$col]['href'] . '" rel="nofollow">' . $context['columns'][$col]['label'] . '</a>'; |
274 | 281 | $context['columns'][$col]['selected'] = $_REQUEST['sort'] == $col; |
@@ -317,8 +324,9 @@ discard block |
||
317 | 324 | elseif ($use_cache && $_REQUEST['sort'] === 'real_name') |
318 | 325 | { |
319 | 326 | $first_offset = floor(($memberlist_cache['num_members'] - $modSettings['defaultMaxMembers'] - $_REQUEST['start']) / $cache_step_size) * $cache_step_size; |
320 | - if ($first_offset < 0) |
|
321 | - $first_offset = 0; |
|
327 | + if ($first_offset < 0) { |
|
328 | + $first_offset = 0; |
|
329 | + } |
|
322 | 330 | $second_offset = ceil(($memberlist_cache['num_members'] - $_REQUEST['start']) / $cache_step_size) * $cache_step_size; |
323 | 331 | |
324 | 332 | $where = 'mem.real_name BETWEEN {string:real_name_low} AND {string:real_name_high}'; |
@@ -395,12 +403,13 @@ discard block |
||
395 | 403 | ) |
396 | 404 | ); |
397 | 405 | $context['custom_search_fields'] = array(); |
398 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
399 | - $context['custom_search_fields'][$row['col_name']] = array( |
|
406 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
407 | + $context['custom_search_fields'][$row['col_name']] = array( |
|
400 | 408 | 'colname' => $row['col_name'], |
401 | 409 | 'name' => $row['field_name'], |
402 | 410 | 'desc' => $row['field_desc'], |
403 | 411 | ); |
412 | + } |
|
404 | 413 | $smcFunc['db_free_result']($request); |
405 | 414 | |
406 | 415 | // They're searching.. |
@@ -413,23 +422,27 @@ discard block |
||
413 | 422 | $context['old_search_value'] = urlencode($_REQUEST['search']); |
414 | 423 | |
415 | 424 | // No fields? Use default... |
416 | - if (empty($_POST['fields'])) |
|
417 | - $_POST['fields'] = array('name'); |
|
425 | + if (empty($_POST['fields'])) { |
|
426 | + $_POST['fields'] = array('name'); |
|
427 | + } |
|
418 | 428 | |
419 | 429 | // Set defaults for how the results are sorted |
420 | - if (!isset($_REQUEST['sort']) || !isset($context['columns'][$_REQUEST['sort']])) |
|
421 | - $_REQUEST['sort'] = 'real_name'; |
|
430 | + if (!isset($_REQUEST['sort']) || !isset($context['columns'][$_REQUEST['sort']])) { |
|
431 | + $_REQUEST['sort'] = 'real_name'; |
|
432 | + } |
|
422 | 433 | |
423 | 434 | // Build the column link / sort information. |
424 | 435 | foreach ($context['columns'] as $col => $column_details) |
425 | 436 | { |
426 | 437 | $context['columns'][$col]['href'] = $scripturl . '?action=mlist;sa=search;start=0;sort=' . $col; |
427 | 438 | |
428 | - if ((!isset($_REQUEST['desc']) && $col == $_REQUEST['sort']) || ($col != $_REQUEST['sort'] && !empty($column_details['default_sort_rev']))) |
|
429 | - $context['columns'][$col]['href'] .= ';desc'; |
|
439 | + if ((!isset($_REQUEST['desc']) && $col == $_REQUEST['sort']) || ($col != $_REQUEST['sort'] && !empty($column_details['default_sort_rev']))) { |
|
440 | + $context['columns'][$col]['href'] .= ';desc'; |
|
441 | + } |
|
430 | 442 | |
431 | - if (isset($_POST['search']) && isset($_POST['fields'])) |
|
432 | - $context['columns'][$col]['href'] .= ';search=' . $_POST['search'] . ';fields=' . implode(',', $_POST['fields']); |
|
443 | + if (isset($_POST['search']) && isset($_POST['fields'])) { |
|
444 | + $context['columns'][$col]['href'] .= ';search=' . $_POST['search'] . ';fields=' . implode(',', $_POST['fields']); |
|
445 | + } |
|
433 | 446 | |
434 | 447 | $context['columns'][$col]['link'] = '<a href="' . $context['columns'][$col]['href'] . '" rel="nofollow">' . $context['columns'][$col]['label'] . '</a>'; |
435 | 448 | $context['columns'][$col]['selected'] = $_REQUEST['sort'] == $col; |
@@ -452,8 +465,7 @@ discard block |
||
452 | 465 | { |
453 | 466 | $fields = allowedTo('moderate_forum') ? array('member_name', 'real_name') : array('real_name'); |
454 | 467 | $search_fields[] = 'name'; |
455 | - } |
|
456 | - else |
|
468 | + } else |
|
457 | 469 | { |
458 | 470 | $fields = array(); |
459 | 471 | $search_fields = array(); |
@@ -478,9 +490,10 @@ discard block |
||
478 | 490 | $search_fields[] = 'email'; |
479 | 491 | } |
480 | 492 | |
481 | - if ($smcFunc['db_case_sensitive']) |
|
482 | - foreach ($fields as $key => $field) |
|
493 | + if ($smcFunc['db_case_sensitive']) { |
|
494 | + foreach ($fields as $key => $field) |
|
483 | 495 | $fields[$key] = 'LOWER(' . $field . ')'; |
496 | + } |
|
484 | 497 | |
485 | 498 | $customJoin = array(); |
486 | 499 | $customCount = 10; |
@@ -499,8 +512,9 @@ discard block |
||
499 | 512 | } |
500 | 513 | |
501 | 514 | // No search fields? That means you're trying to hack things |
502 | - if (empty($search_fields)) |
|
503 | - fatal_lang_error('invalid_search_string', false); |
|
515 | + if (empty($search_fields)) { |
|
516 | + fatal_lang_error('invalid_search_string', false); |
|
517 | + } |
|
504 | 518 | |
505 | 519 | $query = $_POST['search'] == '' ? '= {string:blank_string}' : ($smcFunc['db_case_sensitive'] ? 'LIKE LOWER({string:search})' : 'LIKE {string:search}'); |
506 | 520 | |
@@ -538,8 +552,7 @@ discard block |
||
538 | 552 | ); |
539 | 553 | printMemberListRows($request); |
540 | 554 | $smcFunc['db_free_result']($request); |
541 | - } |
|
542 | - else |
|
555 | + } else |
|
543 | 556 | { |
544 | 557 | // These are all the possible fields. |
545 | 558 | $context['search_fields'] = array( |
@@ -554,14 +567,14 @@ discard block |
||
554 | 567 | { |
555 | 568 | unset($context['search_fields']['email']); |
556 | 569 | $context['search_defaults'] = array('name'); |
557 | - } |
|
558 | - else |
|
570 | + } else |
|
559 | 571 | { |
560 | 572 | $context['search_defaults'] = array('name', 'email'); |
561 | 573 | } |
562 | 574 | |
563 | - foreach ($context['custom_search_fields'] as $field) |
|
564 | - $context['search_fields']['cust_' . $field['colname']] = sprintf($txt['mlist_search_by'], $field['name']); |
|
575 | + foreach ($context['custom_search_fields'] as $field) { |
|
576 | + $context['search_fields']['cust_' . $field['colname']] = sprintf($txt['mlist_search_by'], $field['name']); |
|
577 | + } |
|
565 | 578 | |
566 | 579 | $context['sub_template'] = 'search'; |
567 | 580 | $context['old_search'] = isset($_GET['search']) ? $_GET['search'] : (isset($_POST['search']) ? $smcFunc['htmlspecialchars']($_POST['search']) : ''); |
@@ -603,12 +616,14 @@ discard block |
||
603 | 616 | $smcFunc['db_free_result']($result); |
604 | 617 | |
605 | 618 | // Avoid division by zero... |
606 | - if ($most_posts == 0) |
|
607 | - $most_posts = 1; |
|
619 | + if ($most_posts == 0) { |
|
620 | + $most_posts = 1; |
|
621 | + } |
|
608 | 622 | |
609 | 623 | $members = array(); |
610 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
611 | - $members[] = $row['id_member']; |
|
624 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
625 | + $members[] = $row['id_member']; |
|
626 | + } |
|
612 | 627 | |
613 | 628 | // Load all the members for display. |
614 | 629 | loadMemberData($members); |
@@ -616,8 +631,9 @@ discard block |
||
616 | 631 | $context['members'] = array(); |
617 | 632 | foreach ($members as $member) |
618 | 633 | { |
619 | - if (!loadMemberContext($member)) |
|
620 | - continue; |
|
634 | + if (!loadMemberContext($member)) { |
|
635 | + continue; |
|
636 | + } |
|
621 | 637 | |
622 | 638 | $context['members'][$member] = $memberContext[$member]; |
623 | 639 | $context['members'][$member]['post_percent'] = round(($context['members'][$member]['real_posts'] * 100) / $most_posts); |
@@ -634,20 +650,21 @@ discard block |
||
634 | 650 | continue; |
635 | 651 | } |
636 | 652 | |
637 | - if ($column['bbc'] && !empty($context['members'][$member]['options'][$key])) |
|
638 | - $context['members'][$member]['options'][$key] = strip_tags(parse_bbc($context['members'][$member]['options'][$key])); |
|
639 | - |
|
640 | - elseif ($column['type'] == 'check') |
|
641 | - $context['members'][$member]['options'][$key] = $context['members'][$member]['options'][$key] == 0 ? $txt['no'] : $txt['yes']; |
|
653 | + if ($column['bbc'] && !empty($context['members'][$member]['options'][$key])) { |
|
654 | + $context['members'][$member]['options'][$key] = strip_tags(parse_bbc($context['members'][$member]['options'][$key])); |
|
655 | + } elseif ($column['type'] == 'check') { |
|
656 | + $context['members'][$member]['options'][$key] = $context['members'][$member]['options'][$key] == 0 ? $txt['no'] : $txt['yes']; |
|
657 | + } |
|
642 | 658 | |
643 | 659 | // Enclosing the user input within some other text? |
644 | - if (!empty($column['enclose'])) |
|
645 | - $context['members'][$member]['options'][$key] = strtr($column['enclose'], array( |
|
660 | + if (!empty($column['enclose'])) { |
|
661 | + $context['members'][$member]['options'][$key] = strtr($column['enclose'], array( |
|
646 | 662 | '{SCRIPTURL}' => $scripturl, |
647 | 663 | '{IMAGES_URL}' => $settings['images_url'], |
648 | 664 | '{DEFAULT_IMAGES_URL}' => $settings['default_images_url'], |
649 | 665 | '{INPUT}' => $context['members'][$member]['options'][$key], |
650 | 666 | )); |
667 | + } |
|
651 | 668 | } |
652 | 669 | } |
653 | 670 | } |
@@ -688,17 +705,17 @@ discard block |
||
688 | 705 | ); |
689 | 706 | |
690 | 707 | // Get the right sort method depending on the cust field type. |
691 | - if ($row['field_type'] != 'check') |
|
692 | - $cpf['columns'][$row['col_name']]['sort'] = array( |
|
708 | + if ($row['field_type'] != 'check') { |
|
709 | + $cpf['columns'][$row['col_name']]['sort'] = array( |
|
693 | 710 | 'down' => 'LENGTH(t' . $row['col_name'] . '.value) > 0 ASC, COALESCE(t' . $row['col_name'] . '.value, "") DESC', |
694 | 711 | 'up' => 'LENGTH(t' . $row['col_name'] . '.value) > 0 DESC, COALESCE(t' . $row['col_name'] . '.value, "") ASC' |
695 | 712 | ); |
696 | - |
|
697 | - else |
|
698 | - $cpf['columns'][$row['col_name']]['sort'] = array( |
|
713 | + } else { |
|
714 | + $cpf['columns'][$row['col_name']]['sort'] = array( |
|
699 | 715 | 'down' => 't' . $row['col_name'] . '.value DESC', |
700 | 716 | 'up' => 't' . $row['col_name'] . '.value ASC' |
701 | 717 | ); |
718 | + } |
|
702 | 719 | |
703 | 720 | $cpf['join'][$row['col_name']] = 'LEFT JOIN {db_prefix}themes AS t' . $row['col_name'] . ' ON (t' . $row['col_name'] . '.variable = {literal:' . $row['col_name'] . '} AND t' . $row['col_name'] . '.id_theme = 1 AND t' . $row['col_name'] . '.id_member = mem.id_member)'; |
704 | 721 | } |
@@ -14,8 +14,9 @@ discard block |
||
14 | 14 | * @version 2.1 Beta 3 |
15 | 15 | */ |
16 | 16 | |
17 | -if (!defined('SMF')) |
|
17 | +if (!defined('SMF')) { |
|
18 | 18 | die('No direct access...'); |
19 | +} |
|
19 | 20 | |
20 | 21 | /** |
21 | 22 | * The central part of the board - topic display. |
@@ -34,8 +35,9 @@ discard block |
||
34 | 35 | global $attachments, $messages_request, $language, $smcFunc; |
35 | 36 | |
36 | 37 | // What are you gonna display if these are empty?! |
37 | - if (empty($topic)) |
|
38 | - fatal_lang_error('no_board', false); |
|
38 | + if (empty($topic)) { |
|
39 | + fatal_lang_error('no_board', false); |
|
40 | + } |
|
39 | 41 | |
40 | 42 | // Load the proper template. |
41 | 43 | loadTemplate('Display'); |
@@ -52,15 +54,17 @@ discard block |
||
52 | 54 | $context['messages_per_page'] = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages']; |
53 | 55 | |
54 | 56 | // Let's do some work on what to search index. |
55 | - if (count($_GET) > 2) |
|
56 | - foreach ($_GET as $k => $v) |
|
57 | + if (count($_GET) > 2) { |
|
58 | + foreach ($_GET as $k => $v) |
|
57 | 59 | { |
58 | 60 | if (!in_array($k, array('topic', 'board', 'start', session_name()))) |
59 | 61 | $context['robot_no_index'] = true; |
62 | + } |
|
60 | 63 | } |
61 | 64 | |
62 | - if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0)) |
|
63 | - $context['robot_no_index'] = true; |
|
65 | + if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0)) { |
|
66 | + $context['robot_no_index'] = true; |
|
67 | + } |
|
64 | 68 | |
65 | 69 | // Find the previous or next topic. Make a fuss if there are no more. |
66 | 70 | if (isset($_REQUEST['prev_next']) && ($_REQUEST['prev_next'] == 'prev' || $_REQUEST['prev_next'] == 'next')) |
@@ -172,8 +176,9 @@ discard block |
||
172 | 176 | $topic_parameters |
173 | 177 | ); |
174 | 178 | |
175 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
176 | - fatal_lang_error('not_a_topic', false, 404); |
|
179 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
180 | + fatal_lang_error('not_a_topic', false, 404); |
|
181 | + } |
|
177 | 182 | $context['topicinfo'] = $smcFunc['db_fetch_assoc']($request); |
178 | 183 | $smcFunc['db_free_result']($request); |
179 | 184 | |
@@ -210,8 +215,9 @@ discard block |
||
210 | 215 | $context['topic_unwatched'] = isset($context['topicinfo']['unwatched']) ? $context['topicinfo']['unwatched'] : 0; |
211 | 216 | |
212 | 217 | // Add up unapproved replies to get real number of replies... |
213 | - if ($modSettings['postmod_active'] && $approve_posts) |
|
214 | - $context['real_num_replies'] += $context['topicinfo']['unapproved_posts'] - ($context['topicinfo']['approved'] ? 0 : 1); |
|
218 | + if ($modSettings['postmod_active'] && $approve_posts) { |
|
219 | + $context['real_num_replies'] += $context['topicinfo']['unapproved_posts'] - ($context['topicinfo']['approved'] ? 0 : 1); |
|
220 | + } |
|
215 | 221 | |
216 | 222 | // If this topic has unapproved posts, we need to work out how many posts the user can see, for page indexing. |
217 | 223 | if ($modSettings['postmod_active'] && $context['topicinfo']['unapproved_posts'] && !$user_info['is_guest'] && !$approve_posts) |
@@ -231,11 +237,11 @@ discard block |
||
231 | 237 | $smcFunc['db_free_result']($request); |
232 | 238 | |
233 | 239 | $context['total_visible_posts'] = $context['num_replies'] + $myUnapprovedPosts + ($context['topicinfo']['approved'] ? 1 : 0); |
240 | + } elseif ($user_info['is_guest']) { |
|
241 | + $context['total_visible_posts'] = $context['num_replies'] + ($context['topicinfo']['approved'] ? 1 : 0); |
|
242 | + } else { |
|
243 | + $context['total_visible_posts'] = $context['num_replies'] + $context['topicinfo']['unapproved_posts'] + ($context['topicinfo']['approved'] ? 1 : 0); |
|
234 | 244 | } |
235 | - elseif ($user_info['is_guest']) |
|
236 | - $context['total_visible_posts'] = $context['num_replies'] + ($context['topicinfo']['approved'] ? 1 : 0); |
|
237 | - else |
|
238 | - $context['total_visible_posts'] = $context['num_replies'] + $context['topicinfo']['unapproved_posts'] + ($context['topicinfo']['approved'] ? 1 : 0); |
|
239 | 245 | |
240 | 246 | // The start isn't a number; it's information about what to do, where to go. |
241 | 247 | if (!is_numeric($_REQUEST['start'])) |
@@ -248,8 +254,7 @@ discard block |
||
248 | 254 | { |
249 | 255 | $context['start_from'] = $context['total_visible_posts'] - 1; |
250 | 256 | $_REQUEST['start'] = empty($options['view_newest_first']) ? $context['start_from'] : 0; |
251 | - } |
|
252 | - else |
|
257 | + } else |
|
253 | 258 | { |
254 | 259 | // Find the earliest unread message in the topic. (the use of topics here is just for both tables.) |
255 | 260 | $request = $smcFunc['db_query']('', ' |
@@ -277,9 +282,9 @@ discard block |
||
277 | 282 | if (substr($_REQUEST['start'], 0, 4) == 'from') |
278 | 283 | { |
279 | 284 | $timestamp = (int) substr($_REQUEST['start'], 4); |
280 | - if ($timestamp === 0) |
|
281 | - $_REQUEST['start'] = 0; |
|
282 | - else |
|
285 | + if ($timestamp === 0) { |
|
286 | + $_REQUEST['start'] = 0; |
|
287 | + } else |
|
283 | 288 | { |
284 | 289 | // Find the number of messages posted before said time... |
285 | 290 | $request = $smcFunc['db_query']('', ' |
@@ -307,11 +312,11 @@ discard block |
||
307 | 312 | elseif (substr($_REQUEST['start'], 0, 3) == 'msg') |
308 | 313 | { |
309 | 314 | $virtual_msg = (int) substr($_REQUEST['start'], 3); |
310 | - if (!$context['topicinfo']['unapproved_posts'] && $virtual_msg >= $context['topicinfo']['id_last_msg']) |
|
311 | - $context['start_from'] = $context['total_visible_posts'] - 1; |
|
312 | - elseif (!$context['topicinfo']['unapproved_posts'] && $virtual_msg <= $context['topicinfo']['id_first_msg']) |
|
313 | - $context['start_from'] = 0; |
|
314 | - else |
|
315 | + if (!$context['topicinfo']['unapproved_posts'] && $virtual_msg >= $context['topicinfo']['id_last_msg']) { |
|
316 | + $context['start_from'] = $context['total_visible_posts'] - 1; |
|
317 | + } elseif (!$context['topicinfo']['unapproved_posts'] && $virtual_msg <= $context['topicinfo']['id_first_msg']) { |
|
318 | + $context['start_from'] = 0; |
|
319 | + } else |
|
315 | 320 | { |
316 | 321 | // Find the start value for that message...... |
317 | 322 | $request = $smcFunc['db_query']('', ' |
@@ -394,21 +399,25 @@ discard block |
||
394 | 399 | ); |
395 | 400 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
396 | 401 | { |
397 | - if (empty($row['id_member'])) |
|
398 | - continue; |
|
402 | + if (empty($row['id_member'])) { |
|
403 | + continue; |
|
404 | + } |
|
399 | 405 | |
400 | - if (!empty($row['online_color'])) |
|
401 | - $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>'; |
|
402 | - else |
|
403 | - $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
406 | + if (!empty($row['online_color'])) { |
|
407 | + $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>'; |
|
408 | + } else { |
|
409 | + $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
410 | + } |
|
404 | 411 | |
405 | 412 | $is_buddy = in_array($row['id_member'], $user_info['buddies']); |
406 | - if ($is_buddy) |
|
407 | - $link = '<strong>' . $link . '</strong>'; |
|
413 | + if ($is_buddy) { |
|
414 | + $link = '<strong>' . $link . '</strong>'; |
|
415 | + } |
|
408 | 416 | |
409 | 417 | // Add them both to the list and to the more detailed list. |
410 | - if (!empty($row['show_online']) || allowedTo('moderate_forum')) |
|
411 | - $context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link; |
|
418 | + if (!empty($row['show_online']) || allowedTo('moderate_forum')) { |
|
419 | + $context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link; |
|
420 | + } |
|
412 | 421 | $context['view_members'][$row['log_time'] . $row['member_name']] = array( |
413 | 422 | 'id' => $row['id_member'], |
414 | 423 | 'username' => $row['member_name'], |
@@ -420,8 +429,9 @@ discard block |
||
420 | 429 | 'hidden' => empty($row['show_online']), |
421 | 430 | ); |
422 | 431 | |
423 | - if (empty($row['show_online'])) |
|
424 | - $context['view_num_hidden']++; |
|
432 | + if (empty($row['show_online'])) { |
|
433 | + $context['view_num_hidden']++; |
|
434 | + } |
|
425 | 435 | } |
426 | 436 | |
427 | 437 | // The number of guests is equal to the rows minus the ones we actually used ;). |
@@ -435,11 +445,13 @@ discard block |
||
435 | 445 | |
436 | 446 | // If all is set, but not allowed... just unset it. |
437 | 447 | $can_show_all = !empty($modSettings['enableAllMessages']) && $context['total_visible_posts'] > $context['messages_per_page'] && $context['total_visible_posts'] < $modSettings['enableAllMessages']; |
438 | - if (isset($_REQUEST['all']) && !$can_show_all) |
|
439 | - unset($_REQUEST['all']); |
|
448 | + if (isset($_REQUEST['all']) && !$can_show_all) { |
|
449 | + unset($_REQUEST['all']); |
|
450 | + } |
|
440 | 451 | // Otherwise, it must be allowed... so pretend start was -1. |
441 | - elseif (isset($_REQUEST['all'])) |
|
442 | - $_REQUEST['start'] = -1; |
|
452 | + elseif (isset($_REQUEST['all'])) { |
|
453 | + $_REQUEST['start'] = -1; |
|
454 | + } |
|
443 | 455 | |
444 | 456 | // Construct the page index, allowing for the .START method... |
445 | 457 | $context['page_index'] = constructPageIndex($scripturl . '?topic=' . $topic . '.%1$d', $_REQUEST['start'], $context['total_visible_posts'], $context['messages_per_page'], true); |
@@ -476,8 +488,9 @@ discard block |
||
476 | 488 | $_REQUEST['start'] = 0; |
477 | 489 | } |
478 | 490 | // They aren't using it, but the *option* is there, at least. |
479 | - else |
|
480 | - $context['page_index'] .= ' <a href="' . $scripturl . '?topic=' . $topic . '.0;all">' . $txt['all'] . '</a> '; |
|
491 | + else { |
|
492 | + $context['page_index'] .= ' <a href="' . $scripturl . '?topic=' . $topic . '.0;all">' . $txt['all'] . '</a> '; |
|
493 | + } |
|
481 | 494 | } |
482 | 495 | |
483 | 496 | // Build the link tree. |
@@ -493,14 +506,16 @@ discard block |
||
493 | 506 | if (!empty($board_info['moderators'])) |
494 | 507 | { |
495 | 508 | // Add a link for each moderator... |
496 | - foreach ($board_info['moderators'] as $mod) |
|
497 | - $context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>'; |
|
509 | + foreach ($board_info['moderators'] as $mod) { |
|
510 | + $context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>'; |
|
511 | + } |
|
498 | 512 | } |
499 | 513 | if (!empty($board_info['moderator_groups'])) |
500 | 514 | { |
501 | 515 | // Add a link for each moderator group as well... |
502 | - foreach ($board_info['moderator_groups'] as $mod_group) |
|
503 | - $context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=viewmemberes;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>'; |
|
516 | + foreach ($board_info['moderator_groups'] as $mod_group) { |
|
517 | + $context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=viewmemberes;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>'; |
|
518 | + } |
|
504 | 519 | } |
505 | 520 | |
506 | 521 | if (!empty($context['link_moderators'])) |
@@ -531,9 +546,9 @@ discard block |
||
531 | 546 | // For quick reply we need a response prefix in the default forum language. |
532 | 547 | if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix', 600))) |
533 | 548 | { |
534 | - if ($language === $user_info['language']) |
|
535 | - $context['response_prefix'] = $txt['response_prefix']; |
|
536 | - else |
|
549 | + if ($language === $user_info['language']) { |
|
550 | + $context['response_prefix'] = $txt['response_prefix']; |
|
551 | + } else |
|
537 | 552 | { |
538 | 553 | loadLanguage('index', $language, false); |
539 | 554 | $context['response_prefix'] = $txt['response_prefix']; |
@@ -565,8 +580,9 @@ discard block |
||
565 | 580 | list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row); |
566 | 581 | |
567 | 582 | // Sanity check |
568 | - if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) |
|
569 | - continue; |
|
583 | + if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) { |
|
584 | + continue; |
|
585 | + } |
|
570 | 586 | |
571 | 587 | $linked_calendar_event = array( |
572 | 588 | 'id' => $row['id_event'], |
@@ -615,8 +631,9 @@ discard block |
||
615 | 631 | } |
616 | 632 | $smcFunc['db_free_result']($request); |
617 | 633 | |
618 | - if (!empty($context['linked_calendar_events'])) |
|
619 | - $context['linked_calendar_events'][count($context['linked_calendar_events']) - 1]['is_last'] = true; |
|
634 | + if (!empty($context['linked_calendar_events'])) { |
|
635 | + $context['linked_calendar_events'][count($context['linked_calendar_events']) - 1]['is_last'] = true; |
|
636 | + } |
|
620 | 637 | } |
621 | 638 | |
622 | 639 | // Create the poll info if it exists. |
@@ -689,20 +706,21 @@ discard block |
||
689 | 706 | foreach ($guestinfo as $i => $guestvoted) |
690 | 707 | { |
691 | 708 | $guestvoted = explode(',', $guestvoted); |
692 | - if ($guestvoted[0] == $context['topicinfo']['id_poll']) |
|
693 | - break; |
|
709 | + if ($guestvoted[0] == $context['topicinfo']['id_poll']) { |
|
710 | + break; |
|
711 | + } |
|
694 | 712 | } |
695 | 713 | // Has the poll been reset since guest voted? |
696 | 714 | if ($pollinfo['reset_poll'] > $guestvoted[1]) |
697 | 715 | { |
698 | 716 | // Remove the poll info from the cookie to allow guest to vote again |
699 | 717 | unset($guestinfo[$i]); |
700 | - if (!empty($guestinfo)) |
|
701 | - $_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo); |
|
702 | - else |
|
703 | - unset($_COOKIE['guest_poll_vote']); |
|
704 | - } |
|
705 | - else |
|
718 | + if (!empty($guestinfo)) { |
|
719 | + $_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo); |
|
720 | + } else { |
|
721 | + unset($_COOKIE['guest_poll_vote']); |
|
722 | + } |
|
723 | + } else |
|
706 | 724 | { |
707 | 725 | // What did they vote for? |
708 | 726 | unset($guestvoted[0], $guestvoted[1]); |
@@ -816,23 +834,29 @@ discard block |
||
816 | 834 | // Build the poll moderation button array. |
817 | 835 | $context['poll_buttons'] = array(); |
818 | 836 | |
819 | - if ($context['allow_return_vote']) |
|
820 | - $context['poll_buttons']['vote'] = array('text' => 'poll_return_vote', 'image' => 'poll_options.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start']); |
|
837 | + if ($context['allow_return_vote']) { |
|
838 | + $context['poll_buttons']['vote'] = array('text' => 'poll_return_vote', 'image' => 'poll_options.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start']); |
|
839 | + } |
|
821 | 840 | |
822 | - if ($context['show_view_results_button']) |
|
823 | - $context['poll_buttons']['results'] = array('text' => 'poll_results', 'image' => 'poll_results.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start'] . ';viewresults'); |
|
841 | + if ($context['show_view_results_button']) { |
|
842 | + $context['poll_buttons']['results'] = array('text' => 'poll_results', 'image' => 'poll_results.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start'] . ';viewresults'); |
|
843 | + } |
|
824 | 844 | |
825 | - if ($context['allow_change_vote']) |
|
826 | - $context['poll_buttons']['change_vote'] = array('text' => 'poll_change_vote', 'image' => 'poll_change_vote.png', 'url' => $scripturl . '?action=vote;topic=' . $context['current_topic'] . '.' . $context['start'] . ';poll=' . $context['poll']['id'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
845 | + if ($context['allow_change_vote']) { |
|
846 | + $context['poll_buttons']['change_vote'] = array('text' => 'poll_change_vote', 'image' => 'poll_change_vote.png', 'url' => $scripturl . '?action=vote;topic=' . $context['current_topic'] . '.' . $context['start'] . ';poll=' . $context['poll']['id'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
847 | + } |
|
827 | 848 | |
828 | - if ($context['allow_lock_poll']) |
|
829 | - $context['poll_buttons']['lock'] = array('text' => (!$context['poll']['is_locked'] ? 'poll_lock' : 'poll_unlock'), 'image' => 'poll_lock.png', 'url' => $scripturl . '?action=lockvoting;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
849 | + if ($context['allow_lock_poll']) { |
|
850 | + $context['poll_buttons']['lock'] = array('text' => (!$context['poll']['is_locked'] ? 'poll_lock' : 'poll_unlock'), 'image' => 'poll_lock.png', 'url' => $scripturl . '?action=lockvoting;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
851 | + } |
|
830 | 852 | |
831 | - if ($context['allow_edit_poll']) |
|
832 | - $context['poll_buttons']['edit'] = array('text' => 'poll_edit', 'image' => 'poll_edit.png', 'url' => $scripturl . '?action=editpoll;topic=' . $context['current_topic'] . '.' . $context['start']); |
|
853 | + if ($context['allow_edit_poll']) { |
|
854 | + $context['poll_buttons']['edit'] = array('text' => 'poll_edit', 'image' => 'poll_edit.png', 'url' => $scripturl . '?action=editpoll;topic=' . $context['current_topic'] . '.' . $context['start']); |
|
855 | + } |
|
833 | 856 | |
834 | - if ($context['can_remove_poll']) |
|
835 | - $context['poll_buttons']['remove_poll'] = array('text' => 'poll_remove', 'image' => 'admin_remove_poll.png', 'custom' => 'data-confirm="' . $txt['poll_remove_warn'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removepoll;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
857 | + if ($context['can_remove_poll']) { |
|
858 | + $context['poll_buttons']['remove_poll'] = array('text' => 'poll_remove', 'image' => 'admin_remove_poll.png', 'custom' => 'data-confirm="' . $txt['poll_remove_warn'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removepoll;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
859 | + } |
|
836 | 860 | |
837 | 861 | // Allow mods to add additional buttons here |
838 | 862 | call_integration_hook('integrate_poll_buttons'); |
@@ -873,8 +897,9 @@ discard block |
||
873 | 897 | $all_posters = array(); |
874 | 898 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
875 | 899 | { |
876 | - if (!empty($row['id_member'])) |
|
877 | - $all_posters[$row['id_msg']] = $row['id_member']; |
|
900 | + if (!empty($row['id_member'])) { |
|
901 | + $all_posters[$row['id_msg']] = $row['id_member']; |
|
902 | + } |
|
878 | 903 | $messages[] = $row['id_msg']; |
879 | 904 | } |
880 | 905 | $smcFunc['db_free_result']($request); |
@@ -886,8 +911,9 @@ discard block |
||
886 | 911 | if (!$user_info['is_guest'] && !empty($messages)) |
887 | 912 | { |
888 | 913 | $mark_at_msg = max($messages); |
889 | - if ($mark_at_msg >= $context['topicinfo']['id_last_msg']) |
|
890 | - $mark_at_msg = $modSettings['maxMsgID']; |
|
914 | + if ($mark_at_msg >= $context['topicinfo']['id_last_msg']) { |
|
915 | + $mark_at_msg = $modSettings['maxMsgID']; |
|
916 | + } |
|
891 | 917 | if ($mark_at_msg >= $context['topicinfo']['new_from']) |
892 | 918 | { |
893 | 919 | $smcFunc['db_insert']($context['topicinfo']['new_from'] == 0 ? 'ignore' : 'replace', |
@@ -919,8 +945,9 @@ discard block |
||
919 | 945 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
920 | 946 | { |
921 | 947 | // Find if this topic is marked for notification... |
922 | - if (!empty($row['id_topic'])) |
|
923 | - $context['is_marked_notify'] = true; |
|
948 | + if (!empty($row['id_topic'])) { |
|
949 | + $context['is_marked_notify'] = true; |
|
950 | + } |
|
924 | 951 | |
925 | 952 | // Only do this once, but mark the notifications as "not sent yet" for next time. |
926 | 953 | if (!empty($row['sent']) && $do_once) |
@@ -942,8 +969,9 @@ discard block |
||
942 | 969 | } |
943 | 970 | |
944 | 971 | // Have we recently cached the number of new topics in this board, and it's still a lot? |
945 | - if (isset($_REQUEST['topicseen']) && isset($_SESSION['topicseen_cache'][$board]) && $_SESSION['topicseen_cache'][$board] > 5) |
|
946 | - $_SESSION['topicseen_cache'][$board]--; |
|
972 | + if (isset($_REQUEST['topicseen']) && isset($_SESSION['topicseen_cache'][$board]) && $_SESSION['topicseen_cache'][$board] > 5) { |
|
973 | + $_SESSION['topicseen_cache'][$board]--; |
|
974 | + } |
|
947 | 975 | // Mark board as seen if this is the only new topic. |
948 | 976 | elseif (isset($_REQUEST['topicseen'])) |
949 | 977 | { |
@@ -967,14 +995,16 @@ discard block |
||
967 | 995 | $smcFunc['db_free_result']($request); |
968 | 996 | |
969 | 997 | // If there're no real new topics in this board, mark the board as seen. |
970 | - if (empty($numNewTopics)) |
|
971 | - $_REQUEST['boardseen'] = true; |
|
972 | - else |
|
973 | - $_SESSION['topicseen_cache'][$board] = $numNewTopics; |
|
998 | + if (empty($numNewTopics)) { |
|
999 | + $_REQUEST['boardseen'] = true; |
|
1000 | + } else { |
|
1001 | + $_SESSION['topicseen_cache'][$board] = $numNewTopics; |
|
1002 | + } |
|
974 | 1003 | } |
975 | 1004 | // Probably one less topic - maybe not, but even if we decrease this too fast it will only make us look more often. |
976 | - elseif (isset($_SESSION['topicseen_cache'][$board])) |
|
977 | - $_SESSION['topicseen_cache'][$board]--; |
|
1005 | + elseif (isset($_SESSION['topicseen_cache'][$board])) { |
|
1006 | + $_SESSION['topicseen_cache'][$board]--; |
|
1007 | + } |
|
978 | 1008 | |
979 | 1009 | // Mark board as seen if we came using last post link from BoardIndex. (or other places...) |
980 | 1010 | if (isset($_REQUEST['boardseen'])) |
@@ -1031,23 +1061,26 @@ discard block |
||
1031 | 1061 | $temp = array(); |
1032 | 1062 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1033 | 1063 | { |
1034 | - if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) |
|
1035 | - continue; |
|
1064 | + if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) { |
|
1065 | + continue; |
|
1066 | + } |
|
1036 | 1067 | |
1037 | 1068 | $temp[$row['id_attach']] = $row; |
1038 | 1069 | $temp[$row['id_attach']]['topic'] = $topic; |
1039 | 1070 | $temp[$row['id_attach']]['board'] = $board; |
1040 | 1071 | |
1041 | - if (!isset($context['loaded_attachments'][$row['id_msg']])) |
|
1042 | - $context['loaded_attachments'][$row['id_msg']] = array(); |
|
1072 | + if (!isset($context['loaded_attachments'][$row['id_msg']])) { |
|
1073 | + $context['loaded_attachments'][$row['id_msg']] = array(); |
|
1074 | + } |
|
1043 | 1075 | } |
1044 | 1076 | $smcFunc['db_free_result']($request); |
1045 | 1077 | |
1046 | 1078 | // This is better than sorting it with the query... |
1047 | 1079 | ksort($temp); |
1048 | 1080 | |
1049 | - foreach ($temp as $row) |
|
1050 | - $context['loaded_attachments'][$row['id_msg']][] = $row; |
|
1081 | + foreach ($temp as $row) { |
|
1082 | + $context['loaded_attachments'][$row['id_msg']][] = $row; |
|
1083 | + } |
|
1051 | 1084 | } |
1052 | 1085 | |
1053 | 1086 | $msg_parameters = array( |
@@ -1074,21 +1107,23 @@ discard block |
||
1074 | 1107 | ); |
1075 | 1108 | |
1076 | 1109 | // And the likes |
1077 | - if (!empty($modSettings['enable_likes'])) |
|
1078 | - $context['my_likes'] = $context['user']['is_guest'] ? array() : prepareLikesContext($topic); |
|
1110 | + if (!empty($modSettings['enable_likes'])) { |
|
1111 | + $context['my_likes'] = $context['user']['is_guest'] ? array() : prepareLikesContext($topic); |
|
1112 | + } |
|
1079 | 1113 | |
1080 | 1114 | // Go to the last message if the given time is beyond the time of the last message. |
1081 | - if (isset($context['start_from']) && $context['start_from'] >= $context['topicinfo']['num_replies']) |
|
1082 | - $context['start_from'] = $context['topicinfo']['num_replies']; |
|
1115 | + if (isset($context['start_from']) && $context['start_from'] >= $context['topicinfo']['num_replies']) { |
|
1116 | + $context['start_from'] = $context['topicinfo']['num_replies']; |
|
1117 | + } |
|
1083 | 1118 | |
1084 | 1119 | // Since the anchor information is needed on the top of the page we load these variables beforehand. |
1085 | 1120 | $context['first_message'] = isset($messages[$firstIndex]) ? $messages[$firstIndex] : $messages[0]; |
1086 | - if (empty($options['view_newest_first'])) |
|
1087 | - $context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['start_from']; |
|
1088 | - else |
|
1089 | - $context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['topicinfo']['num_replies'] - $context['start_from']; |
|
1090 | - } |
|
1091 | - else |
|
1121 | + if (empty($options['view_newest_first'])) { |
|
1122 | + $context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['start_from']; |
|
1123 | + } else { |
|
1124 | + $context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['topicinfo']['num_replies'] - $context['start_from']; |
|
1125 | + } |
|
1126 | + } else |
|
1092 | 1127 | { |
1093 | 1128 | $messages_request = false; |
1094 | 1129 | $context['first_message'] = 0; |
@@ -1124,8 +1159,9 @@ discard block |
||
1124 | 1159 | 'can_see_likes' => 'likes_view', |
1125 | 1160 | 'can_like' => 'likes_like', |
1126 | 1161 | ); |
1127 | - foreach ($common_permissions as $contextual => $perm) |
|
1128 | - $context[$contextual] = allowedTo($perm); |
|
1162 | + foreach ($common_permissions as $contextual => $perm) { |
|
1163 | + $context[$contextual] = allowedTo($perm); |
|
1164 | + } |
|
1129 | 1165 | |
1130 | 1166 | // Permissions with _any/_own versions. $context[YYY] => ZZZ_any/_own. |
1131 | 1167 | $anyown_permissions = array( |
@@ -1138,8 +1174,9 @@ discard block |
||
1138 | 1174 | 'can_reply_unapproved' => 'post_unapproved_replies', |
1139 | 1175 | 'can_view_warning' => 'profile_warning', |
1140 | 1176 | ); |
1141 | - foreach ($anyown_permissions as $contextual => $perm) |
|
1142 | - $context[$contextual] = allowedTo($perm . '_any') || ($context['user']['started'] && allowedTo($perm . '_own')); |
|
1177 | + foreach ($anyown_permissions as $contextual => $perm) { |
|
1178 | + $context[$contextual] = allowedTo($perm . '_any') || ($context['user']['started'] && allowedTo($perm . '_own')); |
|
1179 | + } |
|
1143 | 1180 | |
1144 | 1181 | if (!$user_info['is_admin'] && !$modSettings['topic_move_any']) |
1145 | 1182 | { |
@@ -1185,8 +1222,9 @@ discard block |
||
1185 | 1222 | // Check if the draft functions are enabled and that they have permission to use them (for quick reply.) |
1186 | 1223 | $context['drafts_save'] = !empty($modSettings['drafts_post_enabled']) && allowedTo('post_draft') && $context['can_reply']; |
1187 | 1224 | $context['drafts_autosave'] = !empty($context['drafts_save']) && !empty($modSettings['drafts_autosave_enabled']); |
1188 | - if (!empty($context['drafts_save'])) |
|
1189 | - loadLanguage('Drafts'); |
|
1225 | + if (!empty($context['drafts_save'])) { |
|
1226 | + loadLanguage('Drafts'); |
|
1227 | + } |
|
1190 | 1228 | |
1191 | 1229 | // When was the last time this topic was replied to? Should we warn them about it? |
1192 | 1230 | if (!empty($modSettings['oldTopicDays']) && ($context['can_reply'] || $context['can_reply_unapproved']) && empty($context['topicinfo']['is_sticky'])) |
@@ -1247,26 +1285,31 @@ discard block |
||
1247 | 1285 | // Message icons - customized icons are off? |
1248 | 1286 | $context['icons'] = getMessageIcons($board); |
1249 | 1287 | |
1250 | - if (!empty($context['icons'])) |
|
1251 | - $context['icons'][count($context['icons']) - 1]['is_last'] = true; |
|
1288 | + if (!empty($context['icons'])) { |
|
1289 | + $context['icons'][count($context['icons']) - 1]['is_last'] = true; |
|
1290 | + } |
|
1252 | 1291 | |
1253 | 1292 | // Build the normal button array. |
1254 | 1293 | $context['normal_buttons'] = array(); |
1255 | 1294 | |
1256 | - if ($context['can_reply']) |
|
1257 | - $context['normal_buttons']['reply'] = array('text' => 'reply', 'image' => 'reply.png', 'url' => $scripturl . '?action=post;topic=' . $context['current_topic'] . '.' . $context['start'] . ';last_msg=' . $context['topic_last_message'], 'active' => true); |
|
1295 | + if ($context['can_reply']) { |
|
1296 | + $context['normal_buttons']['reply'] = array('text' => 'reply', 'image' => 'reply.png', 'url' => $scripturl . '?action=post;topic=' . $context['current_topic'] . '.' . $context['start'] . ';last_msg=' . $context['topic_last_message'], 'active' => true); |
|
1297 | + } |
|
1258 | 1298 | |
1259 | - if ($context['can_add_poll']) |
|
1260 | - $context['normal_buttons']['add_poll'] = array('text' => 'add_poll', 'image' => 'add_poll.png', 'url' => $scripturl . '?action=editpoll;add;topic=' . $context['current_topic'] . '.' . $context['start']); |
|
1299 | + if ($context['can_add_poll']) { |
|
1300 | + $context['normal_buttons']['add_poll'] = array('text' => 'add_poll', 'image' => 'add_poll.png', 'url' => $scripturl . '?action=editpoll;add;topic=' . $context['current_topic'] . '.' . $context['start']); |
|
1301 | + } |
|
1261 | 1302 | |
1262 | - if ($context['can_mark_unread']) |
|
1263 | - $context['normal_buttons']['mark_unread'] = array('text' => 'mark_unread', 'image' => 'markunread.png', 'url' => $scripturl . '?action=markasread;sa=topic;t=' . $context['mark_unread_time'] . ';topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
1303 | + if ($context['can_mark_unread']) { |
|
1304 | + $context['normal_buttons']['mark_unread'] = array('text' => 'mark_unread', 'image' => 'markunread.png', 'url' => $scripturl . '?action=markasread;sa=topic;t=' . $context['mark_unread_time'] . ';topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
1305 | + } |
|
1264 | 1306 | |
1265 | - if ($context['can_print']) |
|
1266 | - $context['normal_buttons']['print'] = array('text' => 'print', 'image' => 'print.png', 'custom' => 'rel="nofollow"', 'url' => $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0'); |
|
1307 | + if ($context['can_print']) { |
|
1308 | + $context['normal_buttons']['print'] = array('text' => 'print', 'image' => 'print.png', 'custom' => 'rel="nofollow"', 'url' => $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0'); |
|
1309 | + } |
|
1267 | 1310 | |
1268 | - if ($context['can_set_notify']) |
|
1269 | - $context['normal_buttons']['notify'] = array( |
|
1311 | + if ($context['can_set_notify']) { |
|
1312 | + $context['normal_buttons']['notify'] = array( |
|
1270 | 1313 | 'text' => 'notify_topic_' . $context['topic_notification_mode'], |
1271 | 1314 | 'sub_buttons' => array( |
1272 | 1315 | array( |
@@ -1288,38 +1331,47 @@ discard block |
||
1288 | 1331 | ), |
1289 | 1332 | ), |
1290 | 1333 | ); |
1334 | + } |
|
1291 | 1335 | |
1292 | 1336 | // Build the mod button array |
1293 | 1337 | $context['mod_buttons'] = array(); |
1294 | 1338 | |
1295 | - if ($context['can_move']) |
|
1296 | - $context['mod_buttons']['move'] = array('text' => 'move_topic', 'image' => 'admin_move.png', 'url' => $scripturl . '?action=movetopic;current_board=' . $context['current_board'] . ';topic=' . $context['current_topic'] . '.0'); |
|
1339 | + if ($context['can_move']) { |
|
1340 | + $context['mod_buttons']['move'] = array('text' => 'move_topic', 'image' => 'admin_move.png', 'url' => $scripturl . '?action=movetopic;current_board=' . $context['current_board'] . ';topic=' . $context['current_topic'] . '.0'); |
|
1341 | + } |
|
1297 | 1342 | |
1298 | - if ($context['can_delete']) |
|
1299 | - $context['mod_buttons']['delete'] = array('text' => 'remove_topic', 'image' => 'admin_rem.png', 'custom' => 'data-confirm="' . $txt['are_sure_remove_topic'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removetopic2;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id']); |
|
1343 | + if ($context['can_delete']) { |
|
1344 | + $context['mod_buttons']['delete'] = array('text' => 'remove_topic', 'image' => 'admin_rem.png', 'custom' => 'data-confirm="' . $txt['are_sure_remove_topic'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removetopic2;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id']); |
|
1345 | + } |
|
1300 | 1346 | |
1301 | - if ($context['can_lock']) |
|
1302 | - $context['mod_buttons']['lock'] = array('text' => empty($context['is_locked']) ? 'set_lock' : 'set_unlock', 'image' => 'admin_lock.png', 'url' => $scripturl . '?action=lock;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
1347 | + if ($context['can_lock']) { |
|
1348 | + $context['mod_buttons']['lock'] = array('text' => empty($context['is_locked']) ? 'set_lock' : 'set_unlock', 'image' => 'admin_lock.png', 'url' => $scripturl . '?action=lock;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
1349 | + } |
|
1303 | 1350 | |
1304 | - if ($context['can_sticky']) |
|
1305 | - $context['mod_buttons']['sticky'] = array('text' => empty($context['is_sticky']) ? 'set_sticky' : 'set_nonsticky', 'image' => 'admin_sticky.png', 'url' => $scripturl . '?action=sticky;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
1351 | + if ($context['can_sticky']) { |
|
1352 | + $context['mod_buttons']['sticky'] = array('text' => empty($context['is_sticky']) ? 'set_sticky' : 'set_nonsticky', 'image' => 'admin_sticky.png', 'url' => $scripturl . '?action=sticky;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
1353 | + } |
|
1306 | 1354 | |
1307 | - if ($context['can_merge']) |
|
1308 | - $context['mod_buttons']['merge'] = array('text' => 'merge', 'image' => 'merge.png', 'url' => $scripturl . '?action=mergetopics;board=' . $context['current_board'] . '.0;from=' . $context['current_topic']); |
|
1355 | + if ($context['can_merge']) { |
|
1356 | + $context['mod_buttons']['merge'] = array('text' => 'merge', 'image' => 'merge.png', 'url' => $scripturl . '?action=mergetopics;board=' . $context['current_board'] . '.0;from=' . $context['current_topic']); |
|
1357 | + } |
|
1309 | 1358 | |
1310 | - if ($context['calendar_post']) |
|
1311 | - $context['mod_buttons']['calendar'] = array('text' => 'calendar_link', 'image' => 'linktocal.png', 'url' => $scripturl . '?action=post;calendar;msg=' . $context['topic_first_message'] . ';topic=' . $context['current_topic'] . '.0'); |
|
1359 | + if ($context['calendar_post']) { |
|
1360 | + $context['mod_buttons']['calendar'] = array('text' => 'calendar_link', 'image' => 'linktocal.png', 'url' => $scripturl . '?action=post;calendar;msg=' . $context['topic_first_message'] . ';topic=' . $context['current_topic'] . '.0'); |
|
1361 | + } |
|
1312 | 1362 | |
1313 | 1363 | // Restore topic. eh? No monkey business. |
1314 | - if ($context['can_restore_topic']) |
|
1315 | - $context['mod_buttons']['restore_topic'] = array('text' => 'restore_topic', 'image' => '', 'url' => $scripturl . '?action=restoretopic;topics=' . $context['current_topic'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
1364 | + if ($context['can_restore_topic']) { |
|
1365 | + $context['mod_buttons']['restore_topic'] = array('text' => 'restore_topic', 'image' => '', 'url' => $scripturl . '?action=restoretopic;topics=' . $context['current_topic'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
1366 | + } |
|
1316 | 1367 | |
1317 | 1368 | // Show a message in case a recently posted message became unapproved. |
1318 | 1369 | $context['becomesUnapproved'] = !empty($_SESSION['becomesUnapproved']) ? true : false; |
1319 | 1370 | |
1320 | 1371 | // Don't want to show this forever... |
1321 | - if ($context['becomesUnapproved']) |
|
1322 | - unset($_SESSION['becomesUnapproved']); |
|
1372 | + if ($context['becomesUnapproved']) { |
|
1373 | + unset($_SESSION['becomesUnapproved']); |
|
1374 | + } |
|
1323 | 1375 | |
1324 | 1376 | // Allow adding new mod buttons easily. |
1325 | 1377 | // Note: $context['normal_buttons'] and $context['mod_buttons'] are added for backward compatibility with 2.0, but are deprecated and should not be used |
@@ -1328,12 +1380,14 @@ discard block |
||
1328 | 1380 | call_integration_hook('integrate_mod_buttons', array(&$context['mod_buttons'])); |
1329 | 1381 | |
1330 | 1382 | // Load the drafts js file |
1331 | - if ($context['drafts_autosave']) |
|
1332 | - loadJavaScriptFile('drafts.js', array('defer' => false), 'smf_drafts'); |
|
1383 | + if ($context['drafts_autosave']) { |
|
1384 | + loadJavaScriptFile('drafts.js', array('defer' => false), 'smf_drafts'); |
|
1385 | + } |
|
1333 | 1386 | |
1334 | 1387 | // Spellcheck |
1335 | - if ($context['show_spellchecking']) |
|
1336 | - loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck'); |
|
1388 | + if ($context['show_spellchecking']) { |
|
1389 | + loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck'); |
|
1390 | + } |
|
1337 | 1391 | |
1338 | 1392 | // topic.js |
1339 | 1393 | loadJavaScriptFile('topic.js', array('defer' => false), 'smf_topic'); |
@@ -1367,16 +1421,19 @@ discard block |
||
1367 | 1421 | static $counter = null; |
1368 | 1422 | |
1369 | 1423 | // If the query returned false, bail. |
1370 | - if ($messages_request == false) |
|
1371 | - return false; |
|
1424 | + if ($messages_request == false) { |
|
1425 | + return false; |
|
1426 | + } |
|
1372 | 1427 | |
1373 | 1428 | // Remember which message this is. (ie. reply #83) |
1374 | - if ($counter === null || $reset) |
|
1375 | - $counter = empty($options['view_newest_first']) ? $context['start'] : $context['total_visible_posts'] - $context['start']; |
|
1429 | + if ($counter === null || $reset) { |
|
1430 | + $counter = empty($options['view_newest_first']) ? $context['start'] : $context['total_visible_posts'] - $context['start']; |
|
1431 | + } |
|
1376 | 1432 | |
1377 | 1433 | // Start from the beginning... |
1378 | - if ($reset) |
|
1379 | - return @$smcFunc['db_data_seek']($messages_request, 0); |
|
1434 | + if ($reset) { |
|
1435 | + return @$smcFunc['db_data_seek']($messages_request, 0); |
|
1436 | + } |
|
1380 | 1437 | |
1381 | 1438 | // Attempt to get the next message. |
1382 | 1439 | $message = $smcFunc['db_fetch_assoc']($messages_request); |
@@ -1390,19 +1447,21 @@ discard block |
||
1390 | 1447 | if (empty($context['icon_sources'])) |
1391 | 1448 | { |
1392 | 1449 | $context['icon_sources'] = array(); |
1393 | - foreach ($context['stable_icons'] as $icon) |
|
1394 | - $context['icon_sources'][$icon] = 'images_url'; |
|
1450 | + foreach ($context['stable_icons'] as $icon) { |
|
1451 | + $context['icon_sources'][$icon] = 'images_url'; |
|
1452 | + } |
|
1395 | 1453 | } |
1396 | 1454 | |
1397 | 1455 | // Message Icon Management... check the images exist. |
1398 | 1456 | if (empty($modSettings['messageIconChecks_disable'])) |
1399 | 1457 | { |
1400 | 1458 | // If the current icon isn't known, then we need to do something... |
1401 | - if (!isset($context['icon_sources'][$message['icon']])) |
|
1402 | - $context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
1459 | + if (!isset($context['icon_sources'][$message['icon']])) { |
|
1460 | + $context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
1461 | + } |
|
1462 | + } elseif (!isset($context['icon_sources'][$message['icon']])) { |
|
1463 | + $context['icon_sources'][$message['icon']] = 'images_url'; |
|
1403 | 1464 | } |
1404 | - elseif (!isset($context['icon_sources'][$message['icon']])) |
|
1405 | - $context['icon_sources'][$message['icon']] = 'images_url'; |
|
1406 | 1465 | |
1407 | 1466 | // If you're a lazy bum, you probably didn't give a subject... |
1408 | 1467 | $message['subject'] = $message['subject'] != '' ? $message['subject'] : $txt['no_subject']; |
@@ -1427,8 +1486,7 @@ discard block |
||
1427 | 1486 | $memberContext[$message['id_member']]['email'] = $message['poster_email']; |
1428 | 1487 | $memberContext[$message['id_member']]['show_email'] = allowedTo('moderate_forum'); |
1429 | 1488 | $memberContext[$message['id_member']]['is_guest'] = true; |
1430 | - } |
|
1431 | - else |
|
1489 | + } else |
|
1432 | 1490 | { |
1433 | 1491 | // Define this here to make things a bit more readable |
1434 | 1492 | $can_view_warning = $context['user']['can_mod'] || allowedTo('view_warning_any') || ($message['id_member'] == $user_info['id'] && allowedTo('view_warning_own')); |
@@ -1451,8 +1509,9 @@ discard block |
||
1451 | 1509 | $message['body'] = parse_bbc($message['body'], $message['smileys_enabled'], $message['id_msg']); |
1452 | 1510 | |
1453 | 1511 | // If it's in the recycle bin we need to override whatever icon we did have. |
1454 | - if (!empty($board_info['recycle'])) |
|
1455 | - $message['icon'] = 'recycled'; |
|
1512 | + if (!empty($board_info['recycle'])) { |
|
1513 | + $message['icon'] = 'recycled'; |
|
1514 | + } |
|
1456 | 1515 | |
1457 | 1516 | require_once($sourcedir . '/Subs-Attachments.php'); |
1458 | 1517 | |
@@ -1496,32 +1555,36 @@ discard block |
||
1496 | 1555 | } |
1497 | 1556 | |
1498 | 1557 | // Are likes enable? |
1499 | - if (!empty($modSettings['enable_likes'])) |
|
1500 | - $output['likes'] = array( |
|
1558 | + if (!empty($modSettings['enable_likes'])) { |
|
1559 | + $output['likes'] = array( |
|
1501 | 1560 | 'count' => $message['likes'], |
1502 | 1561 | 'you' => in_array($message['id_msg'], $context['my_likes']), |
1503 | 1562 | 'can_like' => !$context['user']['is_guest'] && $message['id_member'] != $context['user']['id'] && !empty($context['can_like']), |
1504 | 1563 | ); |
1564 | + } |
|
1505 | 1565 | |
1506 | 1566 | // Is this user the message author? |
1507 | 1567 | $output['is_message_author'] = $message['id_member'] == $user_info['id']; |
1508 | - if (!empty($output['modified']['name'])) |
|
1509 | - $output['modified']['last_edit_text'] = sprintf($txt['last_edit_by'], $output['modified']['time'], $output['modified']['name']); |
|
1568 | + if (!empty($output['modified']['name'])) { |
|
1569 | + $output['modified']['last_edit_text'] = sprintf($txt['last_edit_by'], $output['modified']['time'], $output['modified']['name']); |
|
1570 | + } |
|
1510 | 1571 | |
1511 | 1572 | // Did they give a reason for editing? |
1512 | - if (!empty($output['modified']['name']) && !empty($output['modified']['reason'])) |
|
1513 | - $output['modified']['last_edit_text'] .= ' ' . sprintf($txt['last_edit_reason'], $output['modified']['reason']); |
|
1573 | + if (!empty($output['modified']['name']) && !empty($output['modified']['reason'])) { |
|
1574 | + $output['modified']['last_edit_text'] .= ' ' . sprintf($txt['last_edit_reason'], $output['modified']['reason']); |
|
1575 | + } |
|
1514 | 1576 | |
1515 | 1577 | // Any custom profile fields? |
1516 | - if (!empty($memberContext[$message['id_member']]['custom_fields'])) |
|
1517 | - foreach ($memberContext[$message['id_member']]['custom_fields'] as $custom) |
|
1578 | + if (!empty($memberContext[$message['id_member']]['custom_fields'])) { |
|
1579 | + foreach ($memberContext[$message['id_member']]['custom_fields'] as $custom) |
|
1518 | 1580 | $output['custom_fields'][$context['cust_profile_fields_placement'][$custom['placement']]][] = $custom; |
1581 | + } |
|
1519 | 1582 | |
1520 | - if (empty($options['view_newest_first'])) |
|
1521 | - $counter++; |
|
1522 | - |
|
1523 | - else |
|
1524 | - $counter--; |
|
1583 | + if (empty($options['view_newest_first'])) { |
|
1584 | + $counter++; |
|
1585 | + } else { |
|
1586 | + $counter--; |
|
1587 | + } |
|
1525 | 1588 | |
1526 | 1589 | call_integration_hook('integrate_prepare_display_context', array(&$output, &$message, $counter)); |
1527 | 1590 | |
@@ -1547,21 +1610,23 @@ discard block |
||
1547 | 1610 | $context['no_last_modified'] = true; |
1548 | 1611 | |
1549 | 1612 | // Prevent a preview image from being displayed twice. |
1550 | - if (isset($_GET['action']) && $_GET['action'] == 'dlattach' && isset($_GET['type']) && ($_GET['type'] == 'avatar' || $_GET['type'] == 'preview')) |
|
1551 | - return; |
|
1613 | + if (isset($_GET['action']) && $_GET['action'] == 'dlattach' && isset($_GET['type']) && ($_GET['type'] == 'avatar' || $_GET['type'] == 'preview')) { |
|
1614 | + return; |
|
1615 | + } |
|
1552 | 1616 | |
1553 | 1617 | // Make sure some attachment was requested! |
1554 | - if (!isset($_REQUEST['attach']) && !isset($_REQUEST['id'])) |
|
1555 | - fatal_lang_error('no_access', false); |
|
1618 | + if (!isset($_REQUEST['attach']) && !isset($_REQUEST['id'])) { |
|
1619 | + fatal_lang_error('no_access', false); |
|
1620 | + } |
|
1556 | 1621 | |
1557 | 1622 | $_REQUEST['attach'] = isset($_REQUEST['attach']) ? (int) $_REQUEST['attach'] : (int) $_REQUEST['id']; |
1558 | 1623 | |
1559 | 1624 | // Do we have a hook wanting to use our attachment system? We use $attachRequest to prevent accidental usage of $request. |
1560 | 1625 | $attachRequest = null; |
1561 | 1626 | call_integration_hook('integrate_download_request', array(&$attachRequest)); |
1562 | - if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest)) |
|
1563 | - $request = $attachRequest; |
|
1564 | - else |
|
1627 | + if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest)) { |
|
1628 | + $request = $attachRequest; |
|
1629 | + } else |
|
1565 | 1630 | { |
1566 | 1631 | // This checks only the current board for $board/$topic's permissions. |
1567 | 1632 | isAllowedTo('view_attachments'); |
@@ -1582,19 +1647,21 @@ discard block |
||
1582 | 1647 | ); |
1583 | 1648 | } |
1584 | 1649 | |
1585 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
1586 | - fatal_lang_error('no_access', false); |
|
1650 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
1651 | + fatal_lang_error('no_access', false); |
|
1652 | + } |
|
1587 | 1653 | |
1588 | 1654 | list ($id_folder, $real_filename, $file_hash, $file_ext, $id_attach, $attachment_type, $mime_type, $is_approved, $id_member) = $smcFunc['db_fetch_row']($request); |
1589 | 1655 | $smcFunc['db_free_result']($request); |
1590 | 1656 | |
1591 | 1657 | // If it isn't yet approved, do they have permission to view it? |
1592 | - if (!$is_approved && ($id_member == 0 || $user_info['id'] != $id_member) && ($attachment_type == 0 || $attachment_type == 3)) |
|
1593 | - isAllowedTo('approve_posts'); |
|
1658 | + if (!$is_approved && ($id_member == 0 || $user_info['id'] != $id_member) && ($attachment_type == 0 || $attachment_type == 3)) { |
|
1659 | + isAllowedTo('approve_posts'); |
|
1660 | + } |
|
1594 | 1661 | |
1595 | 1662 | // Update the download counter (unless it's a thumbnail). |
1596 | - if ($attachment_type != 3) |
|
1597 | - $smcFunc['db_query']('attach_download_increase', ' |
|
1663 | + if ($attachment_type != 3) { |
|
1664 | + $smcFunc['db_query']('attach_download_increase', ' |
|
1598 | 1665 | UPDATE LOW_PRIORITY {db_prefix}attachments |
1599 | 1666 | SET downloads = downloads + 1 |
1600 | 1667 | WHERE id_attach = {int:id_attach}', |
@@ -1602,15 +1669,15 @@ discard block |
||
1602 | 1669 | 'id_attach' => $id_attach, |
1603 | 1670 | ) |
1604 | 1671 | ); |
1672 | + } |
|
1605 | 1673 | |
1606 | 1674 | $filename = getAttachmentFilename($real_filename, $_REQUEST['attach'], $id_folder, false, $file_hash); |
1607 | 1675 | |
1608 | 1676 | // This is done to clear any output that was made before now. |
1609 | 1677 | ob_end_clean(); |
1610 | - if (!empty($modSettings['enableCompressedOutput']) && @filesize($filename) <= 4194304 && in_array($file_ext, array('txt', 'html', 'htm', 'js', 'doc', 'docx', 'rtf', 'css', 'php', 'log', 'xml', 'sql', 'c', 'java'))) |
|
1611 | - @ob_start('ob_gzhandler'); |
|
1612 | - |
|
1613 | - else |
|
1678 | + if (!empty($modSettings['enableCompressedOutput']) && @filesize($filename) <= 4194304 && in_array($file_ext, array('txt', 'html', 'htm', 'js', 'doc', 'docx', 'rtf', 'css', 'php', 'log', 'xml', 'sql', 'c', 'java'))) { |
|
1679 | + @ob_start('ob_gzhandler'); |
|
1680 | + } else |
|
1614 | 1681 | { |
1615 | 1682 | ob_start(); |
1616 | 1683 | header('Content-Encoding: none'); |
@@ -1653,8 +1720,9 @@ discard block |
||
1653 | 1720 | // Send the attachment headers. |
1654 | 1721 | header('Pragma: '); |
1655 | 1722 | |
1656 | - if (!isBrowser('gecko')) |
|
1657 | - header('Content-Transfer-Encoding: binary'); |
|
1723 | + if (!isBrowser('gecko')) { |
|
1724 | + header('Content-Transfer-Encoding: binary'); |
|
1725 | + } |
|
1658 | 1726 | |
1659 | 1727 | header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 525600 * 60) . ' GMT'); |
1660 | 1728 | header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($filename)) . ' GMT'); |
@@ -1663,18 +1731,19 @@ discard block |
||
1663 | 1731 | header('ETag: ' . $eTag); |
1664 | 1732 | |
1665 | 1733 | // Make sure the mime type warrants an inline display. |
1666 | - if (isset($_REQUEST['image']) && !empty($mime_type) && strpos($mime_type, 'image/') !== 0) |
|
1667 | - unset($_REQUEST['image']); |
|
1734 | + if (isset($_REQUEST['image']) && !empty($mime_type) && strpos($mime_type, 'image/') !== 0) { |
|
1735 | + unset($_REQUEST['image']); |
|
1736 | + } |
|
1668 | 1737 | |
1669 | 1738 | // Does this have a mime type? |
1670 | - elseif (!empty($mime_type) && (isset($_REQUEST['image']) || !in_array($file_ext, array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff')))) |
|
1671 | - header('Content-Type: ' . strtr($mime_type, array('image/bmp' => 'image/x-ms-bmp'))); |
|
1672 | - |
|
1673 | - else |
|
1739 | + elseif (!empty($mime_type) && (isset($_REQUEST['image']) || !in_array($file_ext, array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff')))) { |
|
1740 | + header('Content-Type: ' . strtr($mime_type, array('image/bmp' => 'image/x-ms-bmp'))); |
|
1741 | + } else |
|
1674 | 1742 | { |
1675 | 1743 | header('Content-Type: ' . (isBrowser('ie') || isBrowser('opera') ? 'application/octetstream' : 'application/octet-stream')); |
1676 | - if (isset($_REQUEST['image'])) |
|
1677 | - unset($_REQUEST['image']); |
|
1744 | + if (isset($_REQUEST['image'])) { |
|
1745 | + unset($_REQUEST['image']); |
|
1746 | + } |
|
1678 | 1747 | } |
1679 | 1748 | |
1680 | 1749 | // Convert the file to UTF-8, cuz most browsers dig that. |
@@ -1682,23 +1751,22 @@ discard block |
||
1682 | 1751 | $disposition = !isset($_REQUEST['image']) ? 'attachment' : 'inline'; |
1683 | 1752 | |
1684 | 1753 | // Different browsers like different standards... |
1685 | - if (isBrowser('firefox')) |
|
1686 | - header('Content-Disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name))); |
|
1687 | - |
|
1688 | - elseif (isBrowser('opera')) |
|
1689 | - header('Content-Disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"'); |
|
1690 | - |
|
1691 | - elseif (isBrowser('ie')) |
|
1692 | - header('Content-Disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"'); |
|
1693 | - |
|
1694 | - else |
|
1695 | - header('Content-Disposition: ' . $disposition . '; filename="' . $utf8name . '"'); |
|
1754 | + if (isBrowser('firefox')) { |
|
1755 | + header('Content-Disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name))); |
|
1756 | + } elseif (isBrowser('opera')) { |
|
1757 | + header('Content-Disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"'); |
|
1758 | + } elseif (isBrowser('ie')) { |
|
1759 | + header('Content-Disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"'); |
|
1760 | + } else { |
|
1761 | + header('Content-Disposition: ' . $disposition . '; filename="' . $utf8name . '"'); |
|
1762 | + } |
|
1696 | 1763 | |
1697 | 1764 | // If this has an "image extension" - but isn't actually an image - then ensure it isn't cached cause of silly IE. |
1698 | - if (!isset($_REQUEST['image']) && in_array($file_ext, array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff'))) |
|
1699 | - header('Cache-Control: no-cache'); |
|
1700 | - else |
|
1701 | - header('Cache-Control: max-age=' . (525600 * 60) . ', private'); |
|
1765 | + if (!isset($_REQUEST['image']) && in_array($file_ext, array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff'))) { |
|
1766 | + header('Cache-Control: no-cache'); |
|
1767 | + } else { |
|
1768 | + header('Cache-Control: max-age=' . (525600 * 60) . ', private'); |
|
1769 | + } |
|
1702 | 1770 | |
1703 | 1771 | header('Content-Length: ' . filesize($filename)); |
1704 | 1772 | |
@@ -1708,20 +1776,23 @@ discard block |
||
1708 | 1776 | // Recode line endings for text files, if enabled. |
1709 | 1777 | if (!empty($modSettings['attachmentRecodeLineEndings']) && !isset($_REQUEST['image']) && in_array($file_ext, array('txt', 'css', 'htm', 'html', 'php', 'xml'))) |
1710 | 1778 | { |
1711 | - if (strpos($_SERVER['HTTP_USER_AGENT'], 'Windows') !== false) |
|
1712 | - $callback = function($buffer) |
|
1779 | + if (strpos($_SERVER['HTTP_USER_AGENT'], 'Windows') !== false) { |
|
1780 | + $callback = function($buffer) |
|
1713 | 1781 | { |
1714 | 1782 | return preg_replace('~[\r]?\n~', "\r\n", $buffer); |
1783 | + } |
|
1715 | 1784 | }; |
1716 | - elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false) |
|
1717 | - $callback = function($buffer) |
|
1785 | + elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false) { |
|
1786 | + $callback = function($buffer) |
|
1718 | 1787 | { |
1719 | 1788 | return preg_replace('~[\r]?\n~', "\r", $buffer); |
1789 | + } |
|
1720 | 1790 | }; |
1721 | - else |
|
1722 | - $callback = function($buffer) |
|
1791 | + else { |
|
1792 | + $callback = function($buffer) |
|
1723 | 1793 | { |
1724 | 1794 | return preg_replace('~[\r]?\n~', "\n", $buffer); |
1795 | + } |
|
1725 | 1796 | }; |
1726 | 1797 | } |
1727 | 1798 | |
@@ -1729,23 +1800,26 @@ discard block |
||
1729 | 1800 | if (filesize($filename) > 4194304) |
1730 | 1801 | { |
1731 | 1802 | // Forcibly end any output buffering going on. |
1732 | - while (@ob_get_level() > 0) |
|
1733 | - @ob_end_clean(); |
|
1803 | + while (@ob_get_level() > 0) { |
|
1804 | + @ob_end_clean(); |
|
1805 | + } |
|
1734 | 1806 | |
1735 | 1807 | $fp = fopen($filename, 'rb'); |
1736 | 1808 | while (!feof($fp)) |
1737 | 1809 | { |
1738 | - if (isset($callback)) |
|
1739 | - echo $callback(fread($fp, 8192)); |
|
1740 | - else |
|
1741 | - echo fread($fp, 8192); |
|
1810 | + if (isset($callback)) { |
|
1811 | + echo $callback(fread($fp, 8192)); |
|
1812 | + } else { |
|
1813 | + echo fread($fp, 8192); |
|
1814 | + } |
|
1742 | 1815 | flush(); |
1743 | 1816 | } |
1744 | 1817 | fclose($fp); |
1745 | 1818 | } |
1746 | 1819 | // On some of the less-bright hosts, readfile() is disabled. It's just a faster, more byte safe, version of what's in the if. |
1747 | - elseif (isset($callback) || @readfile($filename) === null) |
|
1748 | - echo isset($callback) ? $callback(file_get_contents($filename)) : file_get_contents($filename); |
|
1820 | + elseif (isset($callback) || @readfile($filename) === null) { |
|
1821 | + echo isset($callback) ? $callback(file_get_contents($filename)) : file_get_contents($filename); |
|
1822 | + } |
|
1749 | 1823 | |
1750 | 1824 | obExit(false); |
1751 | 1825 | } |
@@ -1758,8 +1832,9 @@ discard block |
||
1758 | 1832 | */ |
1759 | 1833 | function approved_attach_sort($a, $b) |
1760 | 1834 | { |
1761 | - if ($a['is_approved'] == $b['is_approved']) |
|
1762 | - return 0; |
|
1835 | + if ($a['is_approved'] == $b['is_approved']) { |
|
1836 | + return 0; |
|
1837 | + } |
|
1763 | 1838 | |
1764 | 1839 | return $a['is_approved'] > $b['is_approved'] ? -1 : 1; |
1765 | 1840 | } |
@@ -1776,16 +1851,19 @@ discard block |
||
1776 | 1851 | |
1777 | 1852 | require_once($sourcedir . '/RemoveTopic.php'); |
1778 | 1853 | |
1779 | - if (empty($_REQUEST['msgs'])) |
|
1780 | - redirectexit('topic=' . $topic . '.' . $_REQUEST['start']); |
|
1854 | + if (empty($_REQUEST['msgs'])) { |
|
1855 | + redirectexit('topic=' . $topic . '.' . $_REQUEST['start']); |
|
1856 | + } |
|
1781 | 1857 | |
1782 | 1858 | $messages = array(); |
1783 | - foreach ($_REQUEST['msgs'] as $dummy) |
|
1784 | - $messages[] = (int) $dummy; |
|
1859 | + foreach ($_REQUEST['msgs'] as $dummy) { |
|
1860 | + $messages[] = (int) $dummy; |
|
1861 | + } |
|
1785 | 1862 | |
1786 | 1863 | // We are restoring messages. We handle this in another place. |
1787 | - if (isset($_REQUEST['restore_selected'])) |
|
1788 | - redirectexit('action=restoretopic;msgs=' . implode(',', $messages) . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
1864 | + if (isset($_REQUEST['restore_selected'])) { |
|
1865 | + redirectexit('action=restoretopic;msgs=' . implode(',', $messages) . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
1866 | + } |
|
1789 | 1867 | if (isset($_REQUEST['split_selection'])) |
1790 | 1868 | { |
1791 | 1869 | $request = $smcFunc['db_query']('', ' |
@@ -1804,8 +1882,9 @@ discard block |
||
1804 | 1882 | } |
1805 | 1883 | |
1806 | 1884 | // Allowed to delete any message? |
1807 | - if (allowedTo('delete_any')) |
|
1808 | - $allowed_all = true; |
|
1885 | + if (allowedTo('delete_any')) { |
|
1886 | + $allowed_all = true; |
|
1887 | + } |
|
1809 | 1888 | // Allowed to delete replies to their messages? |
1810 | 1889 | elseif (allowedTo('delete_replies')) |
1811 | 1890 | { |
@@ -1822,13 +1901,14 @@ discard block |
||
1822 | 1901 | $smcFunc['db_free_result']($request); |
1823 | 1902 | |
1824 | 1903 | $allowed_all = $starter == $user_info['id']; |
1904 | + } else { |
|
1905 | + $allowed_all = false; |
|
1825 | 1906 | } |
1826 | - else |
|
1827 | - $allowed_all = false; |
|
1828 | 1907 | |
1829 | 1908 | // Make sure they're allowed to delete their own messages, if not any. |
1830 | - if (!$allowed_all) |
|
1831 | - isAllowedTo('delete_own'); |
|
1909 | + if (!$allowed_all) { |
|
1910 | + isAllowedTo('delete_own'); |
|
1911 | + } |
|
1832 | 1912 | |
1833 | 1913 | // Allowed to remove which messages? |
1834 | 1914 | $request = $smcFunc['db_query']('', ' |
@@ -1848,8 +1928,9 @@ discard block |
||
1848 | 1928 | $messages = array(); |
1849 | 1929 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1850 | 1930 | { |
1851 | - if (!$allowed_all && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) |
|
1852 | - continue; |
|
1931 | + if (!$allowed_all && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) { |
|
1932 | + continue; |
|
1933 | + } |
|
1853 | 1934 | |
1854 | 1935 | $messages[$row['id_msg']] = array($row['subject'], $row['id_member']); |
1855 | 1936 | } |
@@ -1872,17 +1953,20 @@ discard block |
||
1872 | 1953 | foreach ($messages as $message => $info) |
1873 | 1954 | { |
1874 | 1955 | // Just skip the first message - if it's not the last. |
1875 | - if ($message == $first_message && $message != $last_message) |
|
1876 | - continue; |
|
1956 | + if ($message == $first_message && $message != $last_message) { |
|
1957 | + continue; |
|
1958 | + } |
|
1877 | 1959 | // If the first message is going then don't bother going back to the topic as we're effectively deleting it. |
1878 | - elseif ($message == $first_message) |
|
1879 | - $topicGone = true; |
|
1960 | + elseif ($message == $first_message) { |
|
1961 | + $topicGone = true; |
|
1962 | + } |
|
1880 | 1963 | |
1881 | 1964 | removeMessage($message); |
1882 | 1965 | |
1883 | 1966 | // Log this moderation action ;). |
1884 | - if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id'])) |
|
1885 | - logAction('delete', array('topic' => $topic, 'subject' => $info[0], 'member' => $info[1], 'board' => $board)); |
|
1967 | + if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id'])) { |
|
1968 | + logAction('delete', array('topic' => $topic, 'subject' => $info[0], 'member' => $info[1], 'board' => $board)); |
|
1969 | + } |
|
1886 | 1970 | } |
1887 | 1971 | |
1888 | 1972 | redirectexit(!empty($topicGone) ? 'board=' . $board : 'topic=' . $topic . '.' . $_REQUEST['start']); |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 3 |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF')) |
|
16 | +if (!defined('SMF')) { |
|
17 | 17 | die('No direct access...'); |
18 | +} |
|
18 | 19 | |
19 | 20 | /** |
20 | 21 | * Update some basic statistics. |
@@ -122,10 +123,11 @@ discard block |
||
122 | 123 | $smcFunc['db_free_result']($result); |
123 | 124 | |
124 | 125 | // Add this to the number of unapproved members |
125 | - if (!empty($changes['unapprovedMembers'])) |
|
126 | - $changes['unapprovedMembers'] += $coppa_approvals; |
|
127 | - else |
|
128 | - $changes['unapprovedMembers'] = $coppa_approvals; |
|
126 | + if (!empty($changes['unapprovedMembers'])) { |
|
127 | + $changes['unapprovedMembers'] += $coppa_approvals; |
|
128 | + } else { |
|
129 | + $changes['unapprovedMembers'] = $coppa_approvals; |
|
130 | + } |
|
129 | 131 | } |
130 | 132 | } |
131 | 133 | } |
@@ -133,9 +135,9 @@ discard block |
||
133 | 135 | break; |
134 | 136 | |
135 | 137 | case 'message': |
136 | - if ($parameter1 === true && $parameter2 !== null) |
|
137 | - updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true); |
|
138 | - else |
|
138 | + if ($parameter1 === true && $parameter2 !== null) { |
|
139 | + updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true); |
|
140 | + } else |
|
139 | 141 | { |
140 | 142 | // SUM and MAX on a smaller table is better for InnoDB tables. |
141 | 143 | $result = $smcFunc['db_query']('', ' |
@@ -175,23 +177,25 @@ discard block |
||
175 | 177 | $parameter2 = text2words($parameter2); |
176 | 178 | |
177 | 179 | $inserts = array(); |
178 | - foreach ($parameter2 as $word) |
|
179 | - $inserts[] = array($word, $parameter1); |
|
180 | + foreach ($parameter2 as $word) { |
|
181 | + $inserts[] = array($word, $parameter1); |
|
182 | + } |
|
180 | 183 | |
181 | - if (!empty($inserts)) |
|
182 | - $smcFunc['db_insert']('ignore', |
|
184 | + if (!empty($inserts)) { |
|
185 | + $smcFunc['db_insert']('ignore', |
|
183 | 186 | '{db_prefix}log_search_subjects', |
184 | 187 | array('word' => 'string', 'id_topic' => 'int'), |
185 | 188 | $inserts, |
186 | 189 | array('word', 'id_topic') |
187 | 190 | ); |
191 | + } |
|
188 | 192 | } |
189 | 193 | break; |
190 | 194 | |
191 | 195 | case 'topic': |
192 | - if ($parameter1 === true) |
|
193 | - updateSettings(array('totalTopics' => true), true); |
|
194 | - else |
|
196 | + if ($parameter1 === true) { |
|
197 | + updateSettings(array('totalTopics' => true), true); |
|
198 | + } else |
|
195 | 199 | { |
196 | 200 | // Get the number of topics - a SUM is better for InnoDB tables. |
197 | 201 | // We also ignore the recycle bin here because there will probably be a bunch of one-post topics there. |
@@ -212,8 +216,9 @@ discard block |
||
212 | 216 | |
213 | 217 | case 'postgroups': |
214 | 218 | // Parameter two is the updated columns: we should check to see if we base groups off any of these. |
215 | - if ($parameter2 !== null && !in_array('posts', $parameter2)) |
|
216 | - return; |
|
219 | + if ($parameter2 !== null && !in_array('posts', $parameter2)) { |
|
220 | + return; |
|
221 | + } |
|
217 | 222 | |
218 | 223 | $postgroups = cache_get_data('updateStats:postgroups', 360); |
219 | 224 | if ($postgroups == null || $parameter1 == null) |
@@ -228,8 +233,9 @@ discard block |
||
228 | 233 | ) |
229 | 234 | ); |
230 | 235 | $postgroups = array(); |
231 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
232 | - $postgroups[$row['id_group']] = $row['min_posts']; |
|
236 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
237 | + $postgroups[$row['id_group']] = $row['min_posts']; |
|
238 | + } |
|
233 | 239 | $smcFunc['db_free_result']($request); |
234 | 240 | |
235 | 241 | // Sort them this way because if it's done with MySQL it causes a filesort :(. |
@@ -239,8 +245,9 @@ discard block |
||
239 | 245 | } |
240 | 246 | |
241 | 247 | // Oh great, they've screwed their post groups. |
242 | - if (empty($postgroups)) |
|
243 | - return; |
|
248 | + if (empty($postgroups)) { |
|
249 | + return; |
|
250 | + } |
|
244 | 251 | |
245 | 252 | // Set all membergroups from most posts to least posts. |
246 | 253 | $conditions = ''; |
@@ -298,10 +305,9 @@ discard block |
||
298 | 305 | { |
299 | 306 | $condition = 'id_member IN ({array_int:members})'; |
300 | 307 | $parameters['members'] = $members; |
301 | - } |
|
302 | - elseif ($members === null) |
|
303 | - $condition = '1=1'; |
|
304 | - else |
|
308 | + } elseif ($members === null) { |
|
309 | + $condition = '1=1'; |
|
310 | + } else |
|
305 | 311 | { |
306 | 312 | $condition = 'id_member = {int:member}'; |
307 | 313 | $parameters['member'] = $members; |
@@ -341,9 +347,9 @@ discard block |
||
341 | 347 | if (count($vars_to_integrate) != 0) |
342 | 348 | { |
343 | 349 | // Fetch a list of member_names if necessary |
344 | - if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) |
|
345 | - $member_names = array($user_info['username']); |
|
346 | - else |
|
350 | + if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) { |
|
351 | + $member_names = array($user_info['username']); |
|
352 | + } else |
|
347 | 353 | { |
348 | 354 | $member_names = array(); |
349 | 355 | $request = $smcFunc['db_query']('', ' |
@@ -352,14 +358,16 @@ discard block |
||
352 | 358 | WHERE ' . $condition, |
353 | 359 | $parameters |
354 | 360 | ); |
355 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
356 | - $member_names[] = $row['member_name']; |
|
361 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
362 | + $member_names[] = $row['member_name']; |
|
363 | + } |
|
357 | 364 | $smcFunc['db_free_result']($request); |
358 | 365 | } |
359 | 366 | |
360 | - if (!empty($member_names)) |
|
361 | - foreach ($vars_to_integrate as $var) |
|
367 | + if (!empty($member_names)) { |
|
368 | + foreach ($vars_to_integrate as $var) |
|
362 | 369 | call_integration_hook('integrate_change_member_data', array($member_names, $var, &$data[$var], &$knownInts, &$knownFloats)); |
370 | + } |
|
363 | 371 | } |
364 | 372 | } |
365 | 373 | |
@@ -367,16 +375,17 @@ discard block |
||
367 | 375 | foreach ($data as $var => $val) |
368 | 376 | { |
369 | 377 | $type = 'string'; |
370 | - if (in_array($var, $knownInts)) |
|
371 | - $type = 'int'; |
|
372 | - elseif (in_array($var, $knownFloats)) |
|
373 | - $type = 'float'; |
|
374 | - elseif ($var == 'birthdate') |
|
375 | - $type = 'date'; |
|
376 | - elseif ($var == 'member_ip') |
|
377 | - $type = 'inet'; |
|
378 | - elseif ($var == 'member_ip2') |
|
379 | - $type = 'inet'; |
|
378 | + if (in_array($var, $knownInts)) { |
|
379 | + $type = 'int'; |
|
380 | + } elseif (in_array($var, $knownFloats)) { |
|
381 | + $type = 'float'; |
|
382 | + } elseif ($var == 'birthdate') { |
|
383 | + $type = 'date'; |
|
384 | + } elseif ($var == 'member_ip') { |
|
385 | + $type = 'inet'; |
|
386 | + } elseif ($var == 'member_ip2') { |
|
387 | + $type = 'inet'; |
|
388 | + } |
|
380 | 389 | |
381 | 390 | // Doing an increment? |
382 | 391 | if ($type == 'int' && ($val === '+' || $val === '-')) |
@@ -390,8 +399,9 @@ discard block |
||
390 | 399 | { |
391 | 400 | if (preg_match('~^' . $var . ' (\+ |- |\+ -)([\d]+)~', $val, $match)) |
392 | 401 | { |
393 | - if ($match[1] != '+ ') |
|
394 | - $val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END'; |
|
402 | + if ($match[1] != '+ ') { |
|
403 | + $val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END'; |
|
404 | + } |
|
395 | 405 | $type = 'raw'; |
396 | 406 | } |
397 | 407 | } |
@@ -412,8 +422,9 @@ discard block |
||
412 | 422 | // Clear any caching? |
413 | 423 | if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && !empty($members)) |
414 | 424 | { |
415 | - if (!is_array($members)) |
|
416 | - $members = array($members); |
|
425 | + if (!is_array($members)) { |
|
426 | + $members = array($members); |
|
427 | + } |
|
417 | 428 | |
418 | 429 | foreach ($members as $member) |
419 | 430 | { |
@@ -446,29 +457,32 @@ discard block |
||
446 | 457 | { |
447 | 458 | global $modSettings, $smcFunc; |
448 | 459 | |
449 | - if (empty($changeArray) || !is_array($changeArray)) |
|
450 | - return; |
|
460 | + if (empty($changeArray) || !is_array($changeArray)) { |
|
461 | + return; |
|
462 | + } |
|
451 | 463 | |
452 | 464 | $toRemove = array(); |
453 | 465 | |
454 | 466 | // Go check if there is any setting to be removed. |
455 | - foreach ($changeArray as $k => $v) |
|
456 | - if ($v === null) |
|
467 | + foreach ($changeArray as $k => $v) { |
|
468 | + if ($v === null) |
|
457 | 469 | { |
458 | 470 | // Found some, remove them from the original array and add them to ours. |
459 | 471 | unset($changeArray[$k]); |
472 | + } |
|
460 | 473 | $toRemove[] = $k; |
461 | 474 | } |
462 | 475 | |
463 | 476 | // Proceed with the deletion. |
464 | - if (!empty($toRemove)) |
|
465 | - $smcFunc['db_query']('', ' |
|
477 | + if (!empty($toRemove)) { |
|
478 | + $smcFunc['db_query']('', ' |
|
466 | 479 | DELETE FROM {db_prefix}settings |
467 | 480 | WHERE variable IN ({array_string:remove})', |
468 | 481 | array( |
469 | 482 | 'remove' => $toRemove, |
470 | 483 | ) |
471 | 484 | ); |
485 | + } |
|
472 | 486 | |
473 | 487 | // In some cases, this may be better and faster, but for large sets we don't want so many UPDATEs. |
474 | 488 | if ($update) |
@@ -497,19 +511,22 @@ discard block |
||
497 | 511 | foreach ($changeArray as $variable => $value) |
498 | 512 | { |
499 | 513 | // Don't bother if it's already like that ;). |
500 | - if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) |
|
501 | - continue; |
|
514 | + if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) { |
|
515 | + continue; |
|
516 | + } |
|
502 | 517 | // If the variable isn't set, but would only be set to nothing'ness, then don't bother setting it. |
503 | - elseif (!isset($modSettings[$variable]) && empty($value)) |
|
504 | - continue; |
|
518 | + elseif (!isset($modSettings[$variable]) && empty($value)) { |
|
519 | + continue; |
|
520 | + } |
|
505 | 521 | |
506 | 522 | $replaceArray[] = array($variable, $value); |
507 | 523 | |
508 | 524 | $modSettings[$variable] = $value; |
509 | 525 | } |
510 | 526 | |
511 | - if (empty($replaceArray)) |
|
512 | - return; |
|
527 | + if (empty($replaceArray)) { |
|
528 | + return; |
|
529 | + } |
|
513 | 530 | |
514 | 531 | $smcFunc['db_insert']('replace', |
515 | 532 | '{db_prefix}settings', |
@@ -555,14 +572,17 @@ discard block |
||
555 | 572 | $start_invalid = $start < 0; |
556 | 573 | |
557 | 574 | // Make sure $start is a proper variable - not less than 0. |
558 | - if ($start_invalid) |
|
559 | - $start = 0; |
|
575 | + if ($start_invalid) { |
|
576 | + $start = 0; |
|
577 | + } |
|
560 | 578 | // Not greater than the upper bound. |
561 | - elseif ($start >= $max_value) |
|
562 | - $start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page))); |
|
579 | + elseif ($start >= $max_value) { |
|
580 | + $start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page))); |
|
581 | + } |
|
563 | 582 | // And it has to be a multiple of $num_per_page! |
564 | - else |
|
565 | - $start = max(0, (int) $start - ((int) $start % (int) $num_per_page)); |
|
583 | + else { |
|
584 | + $start = max(0, (int) $start - ((int) $start % (int) $num_per_page)); |
|
585 | + } |
|
566 | 586 | |
567 | 587 | $context['current_page'] = $start / $num_per_page; |
568 | 588 | |
@@ -592,77 +612,87 @@ discard block |
||
592 | 612 | |
593 | 613 | // Show all the pages. |
594 | 614 | $display_page = 1; |
595 | - for ($counter = 0; $counter < $max_value; $counter += $num_per_page) |
|
596 | - $pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++); |
|
615 | + for ($counter = 0; $counter < $max_value; $counter += $num_per_page) { |
|
616 | + $pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++); |
|
617 | + } |
|
597 | 618 | |
598 | 619 | // Show the right arrow. |
599 | 620 | $display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page); |
600 | - if ($start != $counter - $max_value && !$start_invalid) |
|
601 | - $pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']); |
|
602 | - } |
|
603 | - else |
|
621 | + if ($start != $counter - $max_value && !$start_invalid) { |
|
622 | + $pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']); |
|
623 | + } |
|
624 | + } else |
|
604 | 625 | { |
605 | 626 | // If they didn't enter an odd value, pretend they did. |
606 | 627 | $PageContiguous = (int) ($modSettings['compactTopicPagesContiguous'] - ($modSettings['compactTopicPagesContiguous'] % 2)) / 2; |
607 | 628 | |
608 | 629 | // Show the "prev page" link. (>prev page< 1 ... 6 7 [8] 9 10 ... 15 next page) |
609 | - if (!empty($start) && $show_prevnext) |
|
610 | - $pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']); |
|
611 | - else |
|
612 | - $pageindex .= ''; |
|
630 | + if (!empty($start) && $show_prevnext) { |
|
631 | + $pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']); |
|
632 | + } else { |
|
633 | + $pageindex .= ''; |
|
634 | + } |
|
613 | 635 | |
614 | 636 | // Show the first page. (prev page >1< ... 6 7 [8] 9 10 ... 15) |
615 | - if ($start > $num_per_page * $PageContiguous) |
|
616 | - $pageindex .= sprintf($base_link, 0, '1'); |
|
637 | + if ($start > $num_per_page * $PageContiguous) { |
|
638 | + $pageindex .= sprintf($base_link, 0, '1'); |
|
639 | + } |
|
617 | 640 | |
618 | 641 | // Show the ... after the first page. (prev page 1 >...< 6 7 [8] 9 10 ... 15 next page) |
619 | - if ($start > $num_per_page * ($PageContiguous + 1)) |
|
620 | - $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
642 | + if ($start > $num_per_page * ($PageContiguous + 1)) { |
|
643 | + $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
621 | 644 | '{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)), |
622 | 645 | '{FIRST_PAGE}' => $num_per_page, |
623 | 646 | '{LAST_PAGE}' => $start - $num_per_page * $PageContiguous, |
624 | 647 | '{PER_PAGE}' => $num_per_page, |
625 | 648 | )); |
649 | + } |
|
626 | 650 | |
627 | 651 | // Show the pages before the current one. (prev page 1 ... >6 7< [8] 9 10 ... 15 next page) |
628 | - for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) |
|
629 | - if ($start >= $num_per_page * $nCont) |
|
652 | + for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) { |
|
653 | + if ($start >= $num_per_page * $nCont) |
|
630 | 654 | { |
631 | 655 | $tmpStart = $start - $num_per_page * $nCont; |
656 | + } |
|
632 | 657 | $pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1); |
633 | 658 | } |
634 | 659 | |
635 | 660 | // Show the current page. (prev page 1 ... 6 7 >[8]< 9 10 ... 15 next page) |
636 | - if (!$start_invalid) |
|
637 | - $pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1); |
|
638 | - else |
|
639 | - $pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1); |
|
661 | + if (!$start_invalid) { |
|
662 | + $pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1); |
|
663 | + } else { |
|
664 | + $pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1); |
|
665 | + } |
|
640 | 666 | |
641 | 667 | // Show the pages after the current one... (prev page 1 ... 6 7 [8] >9 10< ... 15 next page) |
642 | 668 | $tmpMaxPages = (int) (($max_value - 1) / $num_per_page) * $num_per_page; |
643 | - for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) |
|
644 | - if ($start + $num_per_page * $nCont <= $tmpMaxPages) |
|
669 | + for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) { |
|
670 | + if ($start + $num_per_page * $nCont <= $tmpMaxPages) |
|
645 | 671 | { |
646 | 672 | $tmpStart = $start + $num_per_page * $nCont; |
673 | + } |
|
647 | 674 | $pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1); |
648 | 675 | } |
649 | 676 | |
650 | 677 | // Show the '...' part near the end. (prev page 1 ... 6 7 [8] 9 10 >...< 15 next page) |
651 | - if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) |
|
652 | - $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
678 | + if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) { |
|
679 | + $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
653 | 680 | '{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)), |
654 | 681 | '{FIRST_PAGE}' => $start + $num_per_page * ($PageContiguous + 1), |
655 | 682 | '{LAST_PAGE}' => $tmpMaxPages, |
656 | 683 | '{PER_PAGE}' => $num_per_page, |
657 | 684 | )); |
685 | + } |
|
658 | 686 | |
659 | 687 | // Show the last number in the list. (prev page 1 ... 6 7 [8] 9 10 ... >15< next page) |
660 | - if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) |
|
661 | - $pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1); |
|
688 | + if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) { |
|
689 | + $pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1); |
|
690 | + } |
|
662 | 691 | |
663 | 692 | // Show the "next page" link. (prev page 1 ... 6 7 [8] 9 10 ... 15 >next page<) |
664 | - if ($start != $tmpMaxPages && $show_prevnext) |
|
665 | - $pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']); |
|
693 | + if ($start != $tmpMaxPages && $show_prevnext) { |
|
694 | + $pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']); |
|
695 | + } |
|
666 | 696 | } |
667 | 697 | $pageindex .= $settings['page_index']['extra_after']; |
668 | 698 | |
@@ -688,8 +718,9 @@ discard block |
||
688 | 718 | if ($decimal_separator === null) |
689 | 719 | { |
690 | 720 | // Not set for whatever reason? |
691 | - if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) |
|
692 | - return $number; |
|
721 | + if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) { |
|
722 | + return $number; |
|
723 | + } |
|
693 | 724 | |
694 | 725 | // Cache these each load... |
695 | 726 | $thousands_separator = $matches[1]; |
@@ -721,17 +752,20 @@ discard block |
||
721 | 752 | static $non_twelve_hour; |
722 | 753 | |
723 | 754 | // Offset the time. |
724 | - if (!$offset_type) |
|
725 | - $time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600; |
|
755 | + if (!$offset_type) { |
|
756 | + $time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600; |
|
757 | + } |
|
726 | 758 | // Just the forum offset? |
727 | - elseif ($offset_type == 'forum') |
|
728 | - $time = $log_time + $modSettings['time_offset'] * 3600; |
|
729 | - else |
|
730 | - $time = $log_time; |
|
759 | + elseif ($offset_type == 'forum') { |
|
760 | + $time = $log_time + $modSettings['time_offset'] * 3600; |
|
761 | + } else { |
|
762 | + $time = $log_time; |
|
763 | + } |
|
731 | 764 | |
732 | 765 | // We can't have a negative date (on Windows, at least.) |
733 | - if ($log_time < 0) |
|
734 | - $log_time = 0; |
|
766 | + if ($log_time < 0) { |
|
767 | + $log_time = 0; |
|
768 | + } |
|
735 | 769 | |
736 | 770 | // Today and Yesterday? |
737 | 771 | if ($modSettings['todayMod'] >= 1 && $show_today === true) |
@@ -748,46 +782,53 @@ discard block |
||
748 | 782 | { |
749 | 783 | $h = strpos($user_info['time_format'], '%l') === false ? '%I' : '%l'; |
750 | 784 | $today_fmt = $h . ':%M' . $s . ' %p'; |
785 | + } else { |
|
786 | + $today_fmt = '%H:%M' . $s; |
|
751 | 787 | } |
752 | - else |
|
753 | - $today_fmt = '%H:%M' . $s; |
|
754 | 788 | |
755 | 789 | // Same day of the year, same year.... Today! |
756 | - if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) |
|
757 | - return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type); |
|
790 | + if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) { |
|
791 | + return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type); |
|
792 | + } |
|
758 | 793 | |
759 | 794 | // Day-of-year is one less and same year, or it's the first of the year and that's the last of the year... |
760 | - if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31)) |
|
761 | - return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type); |
|
795 | + if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31)) { |
|
796 | + return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type); |
|
797 | + } |
|
762 | 798 | } |
763 | 799 | |
764 | 800 | $str = !is_bool($show_today) ? $show_today : $user_info['time_format']; |
765 | 801 | |
766 | 802 | if (setlocale(LC_TIME, $txt['lang_locale'])) |
767 | 803 | { |
768 | - if (!isset($non_twelve_hour)) |
|
769 | - $non_twelve_hour = trim(strftime('%p')) === ''; |
|
770 | - if ($non_twelve_hour && strpos($str, '%p') !== false) |
|
771 | - $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
804 | + if (!isset($non_twelve_hour)) { |
|
805 | + $non_twelve_hour = trim(strftime('%p')) === ''; |
|
806 | + } |
|
807 | + if ($non_twelve_hour && strpos($str, '%p') !== false) { |
|
808 | + $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
809 | + } |
|
772 | 810 | |
773 | - foreach (array('%a', '%A', '%b', '%B') as $token) |
|
774 | - if (strpos($str, $token) !== false) |
|
811 | + foreach (array('%a', '%A', '%b', '%B') as $token) { |
|
812 | + if (strpos($str, $token) !== false) |
|
775 | 813 | $str = str_replace($token, strftime($token, $time), $str); |
776 | - } |
|
777 | - else |
|
814 | + } |
|
815 | + } else |
|
778 | 816 | { |
779 | 817 | // Do-it-yourself time localization. Fun. |
780 | - foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) |
|
781 | - if (strpos($str, $token) !== false) |
|
818 | + foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) { |
|
819 | + if (strpos($str, $token) !== false) |
|
782 | 820 | $str = str_replace($token, $txt[$text_label][(int) strftime($token === '%a' || $token === '%A' ? '%w' : '%m', $time)], $str); |
821 | + } |
|
783 | 822 | |
784 | - if (strpos($str, '%p') !== false) |
|
785 | - $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
823 | + if (strpos($str, '%p') !== false) { |
|
824 | + $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
825 | + } |
|
786 | 826 | } |
787 | 827 | |
788 | 828 | // Windows doesn't support %e; on some versions, strftime fails altogether if used, so let's prevent that. |
789 | - if ($context['server']['is_windows'] && strpos($str, '%e') !== false) |
|
790 | - $str = str_replace('%e', ltrim(strftime('%d', $time), '0'), $str); |
|
829 | + if ($context['server']['is_windows'] && strpos($str, '%e') !== false) { |
|
830 | + $str = str_replace('%e', ltrim(strftime('%d', $time), '0'), $str); |
|
831 | + } |
|
791 | 832 | |
792 | 833 | // Format any other characters.. |
793 | 834 | return strftime($str, $time); |
@@ -809,16 +850,19 @@ discard block |
||
809 | 850 | static $translation = array(); |
810 | 851 | |
811 | 852 | // Determine the character set... Default to UTF-8 |
812 | - if (empty($context['character_set'])) |
|
813 | - $charset = 'UTF-8'; |
|
853 | + if (empty($context['character_set'])) { |
|
854 | + $charset = 'UTF-8'; |
|
855 | + } |
|
814 | 856 | // Use ISO-8859-1 in place of non-supported ISO-8859 charsets... |
815 | - elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) |
|
816 | - $charset = 'ISO-8859-1'; |
|
817 | - else |
|
818 | - $charset = $context['character_set']; |
|
857 | + elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) { |
|
858 | + $charset = 'ISO-8859-1'; |
|
859 | + } else { |
|
860 | + $charset = $context['character_set']; |
|
861 | + } |
|
819 | 862 | |
820 | - if (empty($translation)) |
|
821 | - $translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array(''' => '\'', ''' => '\'', ' ' => ' '); |
|
863 | + if (empty($translation)) { |
|
864 | + $translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array(''' => '\'', ''' => '\'', ' ' => ' '); |
|
865 | + } |
|
822 | 866 | |
823 | 867 | return strtr($string, $translation); |
824 | 868 | } |
@@ -840,8 +884,9 @@ discard block |
||
840 | 884 | global $smcFunc; |
841 | 885 | |
842 | 886 | // It was already short enough! |
843 | - if ($smcFunc['strlen']($subject) <= $len) |
|
844 | - return $subject; |
|
887 | + if ($smcFunc['strlen']($subject) <= $len) { |
|
888 | + return $subject; |
|
889 | + } |
|
845 | 890 | |
846 | 891 | // Shorten it by the length it was too long, and strip off junk from the end. |
847 | 892 | return $smcFunc['substr']($subject, 0, $len) . '...'; |
@@ -860,10 +905,11 @@ discard block |
||
860 | 905 | { |
861 | 906 | global $user_info, $modSettings; |
862 | 907 | |
863 | - if ($timestamp === null) |
|
864 | - $timestamp = time(); |
|
865 | - elseif ($timestamp == 0) |
|
866 | - return 0; |
|
908 | + if ($timestamp === null) { |
|
909 | + $timestamp = time(); |
|
910 | + } elseif ($timestamp == 0) { |
|
911 | + return 0; |
|
912 | + } |
|
867 | 913 | |
868 | 914 | return $timestamp + ($modSettings['time_offset'] + ($use_user_offset ? $user_info['time_offset'] : 0)) * 3600; |
869 | 915 | } |
@@ -892,8 +938,9 @@ discard block |
||
892 | 938 | $array[$i] = $array[$j]; |
893 | 939 | $array[$j] = $temp; |
894 | 940 | |
895 | - for ($i = 1; $p[$i] == 0; $i++) |
|
896 | - $p[$i] = 1; |
|
941 | + for ($i = 1; $p[$i] == 0; $i++) { |
|
942 | + $p[$i] = 1; |
|
943 | + } |
|
897 | 944 | |
898 | 945 | $orders[] = $array; |
899 | 946 | } |
@@ -925,12 +972,14 @@ discard block |
||
925 | 972 | static $disabled; |
926 | 973 | |
927 | 974 | // Don't waste cycles |
928 | - if ($message === '') |
|
929 | - return ''; |
|
975 | + if ($message === '') { |
|
976 | + return ''; |
|
977 | + } |
|
930 | 978 | |
931 | 979 | // Just in case it wasn't determined yet whether UTF-8 is enabled. |
932 | - if (!isset($context['utf8'])) |
|
933 | - $context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8'; |
|
980 | + if (!isset($context['utf8'])) { |
|
981 | + $context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8'; |
|
982 | + } |
|
934 | 983 | |
935 | 984 | // Clean up any cut/paste issues we may have |
936 | 985 | $message = sanitizeMSCutPaste($message); |
@@ -942,13 +991,15 @@ discard block |
||
942 | 991 | return $message; |
943 | 992 | } |
944 | 993 | |
945 | - if ($smileys !== null && ($smileys == '1' || $smileys == '0')) |
|
946 | - $smileys = (bool) $smileys; |
|
994 | + if ($smileys !== null && ($smileys == '1' || $smileys == '0')) { |
|
995 | + $smileys = (bool) $smileys; |
|
996 | + } |
|
947 | 997 | |
948 | 998 | if (empty($modSettings['enableBBC']) && $message !== false) |
949 | 999 | { |
950 | - if ($smileys === true) |
|
951 | - parsesmileys($message); |
|
1000 | + if ($smileys === true) { |
|
1001 | + parsesmileys($message); |
|
1002 | + } |
|
952 | 1003 | |
953 | 1004 | return $message; |
954 | 1005 | } |
@@ -961,8 +1012,9 @@ discard block |
||
961 | 1012 | } |
962 | 1013 | |
963 | 1014 | // Ensure $modSettings['tld_regex'] contains a valid regex for the autolinker |
964 | - if (!empty($modSettings['autoLinkUrls'])) |
|
965 | - set_tld_regex(); |
|
1015 | + if (!empty($modSettings['autoLinkUrls'])) { |
|
1016 | + set_tld_regex(); |
|
1017 | + } |
|
966 | 1018 | |
967 | 1019 | // Allow mods access before entering the main parse_bbc loop |
968 | 1020 | call_integration_hook('integrate_pre_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags)); |
@@ -976,12 +1028,14 @@ discard block |
||
976 | 1028 | |
977 | 1029 | $temp = explode(',', strtolower($modSettings['disabledBBC'])); |
978 | 1030 | |
979 | - foreach ($temp as $tag) |
|
980 | - $disabled[trim($tag)] = true; |
|
1031 | + foreach ($temp as $tag) { |
|
1032 | + $disabled[trim($tag)] = true; |
|
1033 | + } |
|
981 | 1034 | } |
982 | 1035 | |
983 | - if (empty($modSettings['enableEmbeddedFlash'])) |
|
984 | - $disabled['flash'] = true; |
|
1036 | + if (empty($modSettings['enableEmbeddedFlash'])) { |
|
1037 | + $disabled['flash'] = true; |
|
1038 | + } |
|
985 | 1039 | |
986 | 1040 | /* The following bbc are formatted as an array, with keys as follows: |
987 | 1041 | |
@@ -1102,8 +1156,9 @@ discard block |
||
1102 | 1156 | $returnContext = ''; |
1103 | 1157 | |
1104 | 1158 | // BBC or the entire attachments feature is disabled |
1105 | - if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) |
|
1106 | - return $data; |
|
1159 | + if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) { |
|
1160 | + return $data; |
|
1161 | + } |
|
1107 | 1162 | |
1108 | 1163 | // Save the attach ID. |
1109 | 1164 | $attachID = $data; |
@@ -1114,8 +1169,9 @@ discard block |
||
1114 | 1169 | $currentAttachment = parseAttachBBC($attachID); |
1115 | 1170 | |
1116 | 1171 | // parseAttachBBC will return a string ($txt key) rather than diying with a fatal_error. Up to you to decide what to do. |
1117 | - if (is_string($currentAttachment)) |
|
1118 | - return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment; |
|
1172 | + if (is_string($currentAttachment)) { |
|
1173 | + return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment; |
|
1174 | + } |
|
1119 | 1175 | |
1120 | 1176 | if (!empty($currentAttachment['is_image'])) |
1121 | 1177 | { |
@@ -1131,15 +1187,17 @@ discard block |
||
1131 | 1187 | $height = ' height="' . $currentAttachment['height'] . '"'; |
1132 | 1188 | } |
1133 | 1189 | |
1134 | - if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) |
|
1135 | - $returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '"></a>'; |
|
1136 | - else |
|
1137 | - $returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . '/>'; |
|
1190 | + if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) { |
|
1191 | + $returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '"></a>'; |
|
1192 | + } else { |
|
1193 | + $returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . '/>'; |
|
1194 | + } |
|
1138 | 1195 | } |
1139 | 1196 | |
1140 | 1197 | // No image. Show a link. |
1141 | - else |
|
1142 | - $returnContext .= $currentAttachment['link']; |
|
1198 | + else { |
|
1199 | + $returnContext .= $currentAttachment['link']; |
|
1200 | + } |
|
1143 | 1201 | |
1144 | 1202 | // Gotta append what we just did. |
1145 | 1203 | $data = $returnContext; |
@@ -1170,8 +1228,9 @@ discard block |
||
1170 | 1228 | for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++) |
1171 | 1229 | { |
1172 | 1230 | // Do PHP code coloring? |
1173 | - if ($php_parts[$php_i] != '<?php') |
|
1174 | - continue; |
|
1231 | + if ($php_parts[$php_i] != '<?php') { |
|
1232 | + continue; |
|
1233 | + } |
|
1175 | 1234 | |
1176 | 1235 | $php_string = ''; |
1177 | 1236 | while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?>') |
@@ -1187,8 +1246,9 @@ discard block |
||
1187 | 1246 | $data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data); |
1188 | 1247 | |
1189 | 1248 | // Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection. |
1190 | - if ($context['browser']['is_opera']) |
|
1191 | - $data .= ' '; |
|
1249 | + if ($context['browser']['is_opera']) { |
|
1250 | + $data .= ' '; |
|
1251 | + } |
|
1192 | 1252 | } |
1193 | 1253 | }, |
1194 | 1254 | 'block_level' => true, |
@@ -1207,8 +1267,9 @@ discard block |
||
1207 | 1267 | for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++) |
1208 | 1268 | { |
1209 | 1269 | // Do PHP code coloring? |
1210 | - if ($php_parts[$php_i] != '<?php') |
|
1211 | - continue; |
|
1270 | + if ($php_parts[$php_i] != '<?php') { |
|
1271 | + continue; |
|
1272 | + } |
|
1212 | 1273 | |
1213 | 1274 | $php_string = ''; |
1214 | 1275 | while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?>') |
@@ -1224,8 +1285,9 @@ discard block |
||
1224 | 1285 | $data[0] = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data[0]); |
1225 | 1286 | |
1226 | 1287 | // Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection. |
1227 | - if ($context['browser']['is_opera']) |
|
1228 | - $data[0] .= ' '; |
|
1288 | + if ($context['browser']['is_opera']) { |
|
1289 | + $data[0] .= ' '; |
|
1290 | + } |
|
1229 | 1291 | } |
1230 | 1292 | }, |
1231 | 1293 | 'block_level' => true, |
@@ -1263,11 +1325,13 @@ discard block |
||
1263 | 1325 | 'content' => '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never">', |
1264 | 1326 | 'validate' => function (&$tag, &$data, $disabled) |
1265 | 1327 | { |
1266 | - if (isset($disabled['url'])) |
|
1267 | - $tag['content'] = '$1'; |
|
1328 | + if (isset($disabled['url'])) { |
|
1329 | + $tag['content'] = '$1'; |
|
1330 | + } |
|
1268 | 1331 | $scheme = parse_url($data[0], PHP_URL_SCHEME); |
1269 | - if (empty($scheme)) |
|
1270 | - $data[0] = '//' . ltrim($data[0], ':/'); |
|
1332 | + if (empty($scheme)) { |
|
1333 | + $data[0] = '//' . ltrim($data[0], ':/'); |
|
1334 | + } |
|
1271 | 1335 | }, |
1272 | 1336 | 'disabled_content' => '<a href="$1" target="_blank" class="new_win">$1</a>', |
1273 | 1337 | ), |
@@ -1314,14 +1378,16 @@ discard block |
||
1314 | 1378 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1315 | 1379 | if ($image_proxy_enabled) |
1316 | 1380 | { |
1317 | - if (empty($scheme)) |
|
1318 | - $data = 'http://' . ltrim($data, ':/'); |
|
1381 | + if (empty($scheme)) { |
|
1382 | + $data = 'http://' . ltrim($data, ':/'); |
|
1383 | + } |
|
1319 | 1384 | |
1320 | - if ($scheme != 'https') |
|
1321 | - $data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret); |
|
1385 | + if ($scheme != 'https') { |
|
1386 | + $data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret); |
|
1387 | + } |
|
1388 | + } elseif (empty($scheme)) { |
|
1389 | + $data = '//' . ltrim($data, ':/'); |
|
1322 | 1390 | } |
1323 | - elseif (empty($scheme)) |
|
1324 | - $data = '//' . ltrim($data, ':/'); |
|
1325 | 1391 | }, |
1326 | 1392 | 'disabled_content' => '($1)', |
1327 | 1393 | ), |
@@ -1337,14 +1403,16 @@ discard block |
||
1337 | 1403 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1338 | 1404 | if ($image_proxy_enabled) |
1339 | 1405 | { |
1340 | - if (empty($scheme)) |
|
1341 | - $data = 'http://' . ltrim($data, ':/'); |
|
1406 | + if (empty($scheme)) { |
|
1407 | + $data = 'http://' . ltrim($data, ':/'); |
|
1408 | + } |
|
1342 | 1409 | |
1343 | - if ($scheme != 'https') |
|
1344 | - $data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret); |
|
1410 | + if ($scheme != 'https') { |
|
1411 | + $data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret); |
|
1412 | + } |
|
1413 | + } elseif (empty($scheme)) { |
|
1414 | + $data = '//' . ltrim($data, ':/'); |
|
1345 | 1415 | } |
1346 | - elseif (empty($scheme)) |
|
1347 | - $data = '//' . ltrim($data, ':/'); |
|
1348 | 1416 | }, |
1349 | 1417 | 'disabled_content' => '($1)', |
1350 | 1418 | ), |
@@ -1356,8 +1424,9 @@ discard block |
||
1356 | 1424 | { |
1357 | 1425 | $data = strtr($data, array('<br>' => '')); |
1358 | 1426 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1359 | - if (empty($scheme)) |
|
1360 | - $data = '//' . ltrim($data, ':/'); |
|
1427 | + if (empty($scheme)) { |
|
1428 | + $data = '//' . ltrim($data, ':/'); |
|
1429 | + } |
|
1361 | 1430 | }, |
1362 | 1431 | ), |
1363 | 1432 | array( |
@@ -1368,13 +1437,14 @@ discard block |
||
1368 | 1437 | 'after' => '</a>', |
1369 | 1438 | 'validate' => function (&$tag, &$data, $disabled) |
1370 | 1439 | { |
1371 | - if (substr($data, 0, 1) == '#') |
|
1372 | - $data = '#post_' . substr($data, 1); |
|
1373 | - else |
|
1440 | + if (substr($data, 0, 1) == '#') { |
|
1441 | + $data = '#post_' . substr($data, 1); |
|
1442 | + } else |
|
1374 | 1443 | { |
1375 | 1444 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1376 | - if (empty($scheme)) |
|
1377 | - $data = '//' . ltrim($data, ':/'); |
|
1445 | + if (empty($scheme)) { |
|
1446 | + $data = '//' . ltrim($data, ':/'); |
|
1447 | + } |
|
1378 | 1448 | } |
1379 | 1449 | }, |
1380 | 1450 | 'disallow_children' => array('email', 'ftp', 'url', 'iurl'), |
@@ -1452,8 +1522,9 @@ discard block |
||
1452 | 1522 | { |
1453 | 1523 | $add_begin = substr(trim($data), 0, 5) != '<?'; |
1454 | 1524 | $data = highlight_php_code($add_begin ? '<?php ' . $data . '?>' : $data); |
1455 | - if ($add_begin) |
|
1456 | - $data = preg_replace(array('~^(.+?)<\?.{0,40}?php(?: |\s)~', '~\?>((?:</(font|span)>)*)$~'), '$1', $data, 2); |
|
1525 | + if ($add_begin) { |
|
1526 | + $data = preg_replace(array('~^(.+?)<\?.{0,40}?php(?: |\s)~', '~\?>((?:</(font|span)>)*)$~'), '$1', $data, 2); |
|
1527 | + } |
|
1457 | 1528 | } |
1458 | 1529 | }, |
1459 | 1530 | 'block_level' => false, |
@@ -1584,10 +1655,11 @@ discard block |
||
1584 | 1655 | 'content' => '$1', |
1585 | 1656 | 'validate' => function (&$tag, &$data, $disabled) |
1586 | 1657 | { |
1587 | - if (is_numeric($data)) |
|
1588 | - $data = timeformat($data); |
|
1589 | - else |
|
1590 | - $tag['content'] = '[time]$1[/time]'; |
|
1658 | + if (is_numeric($data)) { |
|
1659 | + $data = timeformat($data); |
|
1660 | + } else { |
|
1661 | + $tag['content'] = '[time]$1[/time]'; |
|
1662 | + } |
|
1591 | 1663 | }, |
1592 | 1664 | ), |
1593 | 1665 | array( |
@@ -1614,8 +1686,9 @@ discard block |
||
1614 | 1686 | { |
1615 | 1687 | $data = strtr($data, array('<br>' => '')); |
1616 | 1688 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1617 | - if (empty($scheme)) |
|
1618 | - $data = '//' . ltrim($data, ':/'); |
|
1689 | + if (empty($scheme)) { |
|
1690 | + $data = '//' . ltrim($data, ':/'); |
|
1691 | + } |
|
1619 | 1692 | }, |
1620 | 1693 | ), |
1621 | 1694 | array( |
@@ -1627,8 +1700,9 @@ discard block |
||
1627 | 1700 | 'validate' => function (&$tag, &$data, $disabled) |
1628 | 1701 | { |
1629 | 1702 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1630 | - if (empty($scheme)) |
|
1631 | - $data = '//' . ltrim($data, ':/'); |
|
1703 | + if (empty($scheme)) { |
|
1704 | + $data = '//' . ltrim($data, ':/'); |
|
1705 | + } |
|
1632 | 1706 | }, |
1633 | 1707 | 'disallow_children' => array('email', 'ftp', 'url', 'iurl'), |
1634 | 1708 | 'disabled_after' => ' ($1)', |
@@ -1648,8 +1722,9 @@ discard block |
||
1648 | 1722 | // This is mainly for the bbc manager, so it's easy to add tags above. Custom BBC should be added above this line. |
1649 | 1723 | if ($message === false) |
1650 | 1724 | { |
1651 | - if (isset($temp_bbc)) |
|
1652 | - $bbc_codes = $temp_bbc; |
|
1725 | + if (isset($temp_bbc)) { |
|
1726 | + $bbc_codes = $temp_bbc; |
|
1727 | + } |
|
1653 | 1728 | usort($codes, function ($a, $b) { |
1654 | 1729 | return strcmp($a['tag'], $b['tag']); |
1655 | 1730 | }); |
@@ -1669,8 +1744,9 @@ discard block |
||
1669 | 1744 | ); |
1670 | 1745 | if (!isset($disabled['li']) && !isset($disabled['list'])) |
1671 | 1746 | { |
1672 | - foreach ($itemcodes as $c => $dummy) |
|
1673 | - $bbc_codes[$c] = array(); |
|
1747 | + foreach ($itemcodes as $c => $dummy) { |
|
1748 | + $bbc_codes[$c] = array(); |
|
1749 | + } |
|
1674 | 1750 | } |
1675 | 1751 | |
1676 | 1752 | // Shhhh! |
@@ -1691,12 +1767,14 @@ discard block |
||
1691 | 1767 | foreach ($codes as $code) |
1692 | 1768 | { |
1693 | 1769 | // Make it easier to process parameters later |
1694 | - if (!empty($code['parameters'])) |
|
1695 | - ksort($code['parameters'], SORT_STRING); |
|
1770 | + if (!empty($code['parameters'])) { |
|
1771 | + ksort($code['parameters'], SORT_STRING); |
|
1772 | + } |
|
1696 | 1773 | |
1697 | 1774 | // If we are not doing every tag only do ones we are interested in. |
1698 | - if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) |
|
1699 | - $bbc_codes[substr($code['tag'], 0, 1)][] = $code; |
|
1775 | + if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) { |
|
1776 | + $bbc_codes[substr($code['tag'], 0, 1)][] = $code; |
|
1777 | + } |
|
1700 | 1778 | } |
1701 | 1779 | $codes = null; |
1702 | 1780 | } |
@@ -1707,8 +1785,9 @@ discard block |
||
1707 | 1785 | // It's likely this will change if the message is modified. |
1708 | 1786 | $cache_key = 'parse:' . $cache_id . '-' . md5(md5($message) . '-' . $smileys . (empty($disabled) ? '' : implode(',', array_keys($disabled))) . json_encode($context['browser']) . $txt['lang_locale'] . $user_info['time_offset'] . $user_info['time_format']); |
1709 | 1787 | |
1710 | - if (($temp = cache_get_data($cache_key, 240)) != null) |
|
1711 | - return $temp; |
|
1788 | + if (($temp = cache_get_data($cache_key, 240)) != null) { |
|
1789 | + return $temp; |
|
1790 | + } |
|
1712 | 1791 | |
1713 | 1792 | $cache_t = microtime(); |
1714 | 1793 | } |
@@ -1740,8 +1819,9 @@ discard block |
||
1740 | 1819 | $disabled['flash'] = true; |
1741 | 1820 | |
1742 | 1821 | // @todo Change maybe? |
1743 | - if (!isset($_GET['images'])) |
|
1744 | - $disabled['img'] = true; |
|
1822 | + if (!isset($_GET['images'])) { |
|
1823 | + $disabled['img'] = true; |
|
1824 | + } |
|
1745 | 1825 | |
1746 | 1826 | // @todo Interface/setting to add more? |
1747 | 1827 | } |
@@ -1765,8 +1845,9 @@ discard block |
||
1765 | 1845 | $pos = isset($matches[0][1]) ? $matches[0][1] : false; |
1766 | 1846 | |
1767 | 1847 | // Failsafe. |
1768 | - if ($pos === false || $last_pos > $pos) |
|
1769 | - $pos = strlen($message) + 1; |
|
1848 | + if ($pos === false || $last_pos > $pos) { |
|
1849 | + $pos = strlen($message) + 1; |
|
1850 | + } |
|
1770 | 1851 | |
1771 | 1852 | // Can't have a one letter smiley, URL, or email! (sorry.) |
1772 | 1853 | if ($last_pos < $pos - 1) |
@@ -1785,8 +1866,9 @@ discard block |
||
1785 | 1866 | |
1786 | 1867 | // <br> should be empty. |
1787 | 1868 | $empty_tags = array('br', 'hr'); |
1788 | - foreach ($empty_tags as $tag) |
|
1789 | - $data = str_replace(array('<' . $tag . '>', '<' . $tag . '/>', '<' . $tag . ' />'), '[' . $tag . ' /]', $data); |
|
1869 | + foreach ($empty_tags as $tag) { |
|
1870 | + $data = str_replace(array('<' . $tag . '>', '<' . $tag . '/>', '<' . $tag . ' />'), '[' . $tag . ' /]', $data); |
|
1871 | + } |
|
1790 | 1872 | |
1791 | 1873 | // b, u, i, s, pre... basic tags. |
1792 | 1874 | $closable_tags = array('b', 'u', 'i', 's', 'em', 'ins', 'del', 'pre', 'blockquote'); |
@@ -1795,8 +1877,9 @@ discard block |
||
1795 | 1877 | $diff = substr_count($data, '<' . $tag . '>') - substr_count($data, '</' . $tag . '>'); |
1796 | 1878 | $data = strtr($data, array('<' . $tag . '>' => '<' . $tag . '>', '</' . $tag . '>' => '</' . $tag . '>')); |
1797 | 1879 | |
1798 | - if ($diff > 0) |
|
1799 | - $data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1); |
|
1880 | + if ($diff > 0) { |
|
1881 | + $data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1); |
|
1882 | + } |
|
1800 | 1883 | } |
1801 | 1884 | |
1802 | 1885 | // Do <img ...> - with security... action= -> action-. |
@@ -1809,8 +1892,9 @@ discard block |
||
1809 | 1892 | $alt = empty($matches[3][$match]) ? '' : ' alt=' . preg_replace('~^"|"$~', '', $matches[3][$match]); |
1810 | 1893 | |
1811 | 1894 | // Remove action= from the URL - no funny business, now. |
1812 | - if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) |
|
1813 | - $imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag); |
|
1895 | + if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) { |
|
1896 | + $imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag); |
|
1897 | + } |
|
1814 | 1898 | |
1815 | 1899 | // Check if the image is larger than allowed. |
1816 | 1900 | if (!empty($modSettings['max_image_width']) && !empty($modSettings['max_image_height'])) |
@@ -1831,9 +1915,9 @@ discard block |
||
1831 | 1915 | |
1832 | 1916 | // Set the new image tag. |
1833 | 1917 | $replaces[$matches[0][$match]] = '[img width=' . $width . ' height=' . $height . $alt . ']' . $imgtag . '[/img]'; |
1918 | + } else { |
|
1919 | + $replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]'; |
|
1834 | 1920 | } |
1835 | - else |
|
1836 | - $replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]'; |
|
1837 | 1921 | } |
1838 | 1922 | |
1839 | 1923 | $data = strtr($data, $replaces); |
@@ -1846,16 +1930,18 @@ discard block |
||
1846 | 1930 | $no_autolink_area = false; |
1847 | 1931 | if (!empty($open_tags)) |
1848 | 1932 | { |
1849 | - foreach ($open_tags as $open_tag) |
|
1850 | - if (in_array($open_tag['tag'], $no_autolink_tags)) |
|
1933 | + foreach ($open_tags as $open_tag) { |
|
1934 | + if (in_array($open_tag['tag'], $no_autolink_tags)) |
|
1851 | 1935 | $no_autolink_area = true; |
1936 | + } |
|
1852 | 1937 | } |
1853 | 1938 | |
1854 | 1939 | // Don't go backwards. |
1855 | 1940 | // @todo Don't think is the real solution.... |
1856 | 1941 | $lastAutoPos = isset($lastAutoPos) ? $lastAutoPos : 0; |
1857 | - if ($pos < $lastAutoPos) |
|
1858 | - $no_autolink_area = true; |
|
1942 | + if ($pos < $lastAutoPos) { |
|
1943 | + $no_autolink_area = true; |
|
1944 | + } |
|
1859 | 1945 | $lastAutoPos = $pos; |
1860 | 1946 | |
1861 | 1947 | if (!$no_autolink_area) |
@@ -1964,17 +2050,19 @@ discard block |
||
1964 | 2050 | if ($scheme == 'mailto') |
1965 | 2051 | { |
1966 | 2052 | $email_address = str_replace('mailto:', '', $url); |
1967 | - if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) |
|
1968 | - return '[email=' . $email_address . ']' . $url . '[/email]'; |
|
1969 | - else |
|
1970 | - return $url; |
|
2053 | + if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) { |
|
2054 | + return '[email=' . $email_address . ']' . $url . '[/email]'; |
|
2055 | + } else { |
|
2056 | + return $url; |
|
2057 | + } |
|
1971 | 2058 | } |
1972 | 2059 | |
1973 | 2060 | // Are we linking a schemeless URL or naked domain name (e.g. "example.com")? |
1974 | - if (empty($scheme)) |
|
1975 | - $fullUrl = '//' . ltrim($url, ':/'); |
|
1976 | - else |
|
1977 | - $fullUrl = $url; |
|
2061 | + if (empty($scheme)) { |
|
2062 | + $fullUrl = '//' . ltrim($url, ':/'); |
|
2063 | + } else { |
|
2064 | + $fullUrl = $url; |
|
2065 | + } |
|
1978 | 2066 | |
1979 | 2067 | return '[url="' . str_replace(array('[', ']'), array('[', ']'), $fullUrl) . '"]' . $url . '[/url]'; |
1980 | 2068 | }, $data); |
@@ -2023,16 +2111,18 @@ discard block |
||
2023 | 2111 | } |
2024 | 2112 | |
2025 | 2113 | // Are we there yet? Are we there yet? |
2026 | - if ($pos >= strlen($message) - 1) |
|
2027 | - break; |
|
2114 | + if ($pos >= strlen($message) - 1) { |
|
2115 | + break; |
|
2116 | + } |
|
2028 | 2117 | |
2029 | 2118 | $tags = strtolower($message[$pos + 1]); |
2030 | 2119 | |
2031 | 2120 | if ($tags == '/' && !empty($open_tags)) |
2032 | 2121 | { |
2033 | 2122 | $pos2 = strpos($message, ']', $pos + 1); |
2034 | - if ($pos2 == $pos + 2) |
|
2035 | - continue; |
|
2123 | + if ($pos2 == $pos + 2) { |
|
2124 | + continue; |
|
2125 | + } |
|
2036 | 2126 | |
2037 | 2127 | $look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2)); |
2038 | 2128 | |
@@ -2042,8 +2132,9 @@ discard block |
||
2042 | 2132 | do |
2043 | 2133 | { |
2044 | 2134 | $tag = array_pop($open_tags); |
2045 | - if (!$tag) |
|
2046 | - break; |
|
2135 | + if (!$tag) { |
|
2136 | + break; |
|
2137 | + } |
|
2047 | 2138 | |
2048 | 2139 | if (!empty($tag['block_level'])) |
2049 | 2140 | { |
@@ -2057,10 +2148,11 @@ discard block |
||
2057 | 2148 | // The idea is, if we are LOOKING for a block level tag, we can close them on the way. |
2058 | 2149 | if (strlen($look_for) > 0 && isset($bbc_codes[$look_for[0]])) |
2059 | 2150 | { |
2060 | - foreach ($bbc_codes[$look_for[0]] as $temp) |
|
2061 | - if ($temp['tag'] == $look_for) |
|
2151 | + foreach ($bbc_codes[$look_for[0]] as $temp) { |
|
2152 | + if ($temp['tag'] == $look_for) |
|
2062 | 2153 | { |
2063 | 2154 | $block_level = !empty($temp['block_level']); |
2155 | + } |
|
2064 | 2156 | break; |
2065 | 2157 | } |
2066 | 2158 | } |
@@ -2082,15 +2174,15 @@ discard block |
||
2082 | 2174 | { |
2083 | 2175 | $open_tags = $to_close; |
2084 | 2176 | continue; |
2085 | - } |
|
2086 | - elseif (!empty($to_close) && $tag['tag'] != $look_for) |
|
2177 | + } elseif (!empty($to_close) && $tag['tag'] != $look_for) |
|
2087 | 2178 | { |
2088 | 2179 | if ($block_level === null && isset($look_for[0], $bbc_codes[$look_for[0]])) |
2089 | 2180 | { |
2090 | - foreach ($bbc_codes[$look_for[0]] as $temp) |
|
2091 | - if ($temp['tag'] == $look_for) |
|
2181 | + foreach ($bbc_codes[$look_for[0]] as $temp) { |
|
2182 | + if ($temp['tag'] == $look_for) |
|
2092 | 2183 | { |
2093 | 2184 | $block_level = !empty($temp['block_level']); |
2185 | + } |
|
2094 | 2186 | break; |
2095 | 2187 | } |
2096 | 2188 | } |
@@ -2098,8 +2190,9 @@ discard block |
||
2098 | 2190 | // We're not looking for a block level tag (or maybe even a tag that exists...) |
2099 | 2191 | if (!$block_level) |
2100 | 2192 | { |
2101 | - foreach ($to_close as $tag) |
|
2102 | - array_push($open_tags, $tag); |
|
2193 | + foreach ($to_close as $tag) { |
|
2194 | + array_push($open_tags, $tag); |
|
2195 | + } |
|
2103 | 2196 | continue; |
2104 | 2197 | } |
2105 | 2198 | } |
@@ -2111,10 +2204,12 @@ discard block |
||
2111 | 2204 | $pos2 = $pos - 1; |
2112 | 2205 | |
2113 | 2206 | // See the comment at the end of the big loop - just eating whitespace ;). |
2114 | - if (!empty($tag['block_level']) && substr($message, $pos, 4) == '<br>') |
|
2115 | - $message = substr($message, 0, $pos) . substr($message, $pos + 4); |
|
2116 | - if (!empty($tag['trim']) && $tag['trim'] != 'inside' && preg_match('~(<br>| |\s)*~', substr($message, $pos), $matches) != 0) |
|
2117 | - $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
2207 | + if (!empty($tag['block_level']) && substr($message, $pos, 4) == '<br>') { |
|
2208 | + $message = substr($message, 0, $pos) . substr($message, $pos + 4); |
|
2209 | + } |
|
2210 | + if (!empty($tag['trim']) && $tag['trim'] != 'inside' && preg_match('~(<br>| |\s)*~', substr($message, $pos), $matches) != 0) { |
|
2211 | + $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
2212 | + } |
|
2118 | 2213 | } |
2119 | 2214 | |
2120 | 2215 | if (!empty($to_close)) |
@@ -2127,8 +2222,9 @@ discard block |
||
2127 | 2222 | } |
2128 | 2223 | |
2129 | 2224 | // No tags for this character, so just keep going (fastest possible course.) |
2130 | - if (!isset($bbc_codes[$tags])) |
|
2131 | - continue; |
|
2225 | + if (!isset($bbc_codes[$tags])) { |
|
2226 | + continue; |
|
2227 | + } |
|
2132 | 2228 | |
2133 | 2229 | $inside = empty($open_tags) ? null : $open_tags[count($open_tags) - 1]; |
2134 | 2230 | $tag = null; |
@@ -2137,44 +2233,52 @@ discard block |
||
2137 | 2233 | $pt_strlen = strlen($possible['tag']); |
2138 | 2234 | |
2139 | 2235 | // Not a match? |
2140 | - if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) |
|
2141 | - continue; |
|
2236 | + if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) { |
|
2237 | + continue; |
|
2238 | + } |
|
2142 | 2239 | |
2143 | 2240 | $next_c = $message[$pos + 1 + $pt_strlen]; |
2144 | 2241 | |
2145 | 2242 | // A test validation? |
2146 | - if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) |
|
2147 | - continue; |
|
2243 | + if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) { |
|
2244 | + continue; |
|
2245 | + } |
|
2148 | 2246 | // Do we want parameters? |
2149 | 2247 | elseif (!empty($possible['parameters'])) |
2150 | 2248 | { |
2151 | - if ($next_c != ' ') |
|
2152 | - continue; |
|
2153 | - } |
|
2154 | - elseif (isset($possible['type'])) |
|
2249 | + if ($next_c != ' ') { |
|
2250 | + continue; |
|
2251 | + } |
|
2252 | + } elseif (isset($possible['type'])) |
|
2155 | 2253 | { |
2156 | 2254 | // Do we need an equal sign? |
2157 | - if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') |
|
2158 | - continue; |
|
2255 | + if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') { |
|
2256 | + continue; |
|
2257 | + } |
|
2159 | 2258 | // Maybe we just want a /... |
2160 | - if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') |
|
2161 | - continue; |
|
2259 | + if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') { |
|
2260 | + continue; |
|
2261 | + } |
|
2162 | 2262 | // An immediate ]? |
2163 | - if ($possible['type'] == 'unparsed_content' && $next_c != ']') |
|
2164 | - continue; |
|
2263 | + if ($possible['type'] == 'unparsed_content' && $next_c != ']') { |
|
2264 | + continue; |
|
2265 | + } |
|
2165 | 2266 | } |
2166 | 2267 | // No type means 'parsed_content', which demands an immediate ] without parameters! |
2167 | - elseif ($next_c != ']') |
|
2168 | - continue; |
|
2268 | + elseif ($next_c != ']') { |
|
2269 | + continue; |
|
2270 | + } |
|
2169 | 2271 | |
2170 | 2272 | // Check allowed tree? |
2171 | - if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) |
|
2172 | - continue; |
|
2173 | - elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) |
|
2174 | - continue; |
|
2273 | + if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) { |
|
2274 | + continue; |
|
2275 | + } elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) { |
|
2276 | + continue; |
|
2277 | + } |
|
2175 | 2278 | // If this is in the list of disallowed child tags, don't parse it. |
2176 | - elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) |
|
2177 | - continue; |
|
2279 | + elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) { |
|
2280 | + continue; |
|
2281 | + } |
|
2178 | 2282 | |
2179 | 2283 | $pos1 = $pos + 1 + $pt_strlen + 1; |
2180 | 2284 | |
@@ -2186,8 +2290,9 @@ discard block |
||
2186 | 2290 | foreach ($open_tags as $open_quote) |
2187 | 2291 | { |
2188 | 2292 | // Every parent quote this quote has flips the styling |
2189 | - if ($open_quote['tag'] == 'quote') |
|
2190 | - $quote_alt = !$quote_alt; |
|
2293 | + if ($open_quote['tag'] == 'quote') { |
|
2294 | + $quote_alt = !$quote_alt; |
|
2295 | + } |
|
2191 | 2296 | } |
2192 | 2297 | // Add a class to the quote to style alternating blockquotes |
2193 | 2298 | $possible['before'] = strtr($possible['before'], array('<blockquote>' => '<blockquote class="bbc_' . ($quote_alt ? 'alternate' : 'standard') . '_quote">')); |
@@ -2198,8 +2303,9 @@ discard block |
||
2198 | 2303 | { |
2199 | 2304 | // Build a regular expression for each parameter for the current tag. |
2200 | 2305 | $preg = array(); |
2201 | - foreach ($possible['parameters'] as $p => $info) |
|
2202 | - $preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '"') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '"') . '\s*)' . (empty($info['optional']) ? '' : '?'); |
|
2306 | + foreach ($possible['parameters'] as $p => $info) { |
|
2307 | + $preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '"') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '"') . '\s*)' . (empty($info['optional']) ? '' : '?'); |
|
2308 | + } |
|
2203 | 2309 | |
2204 | 2310 | // Extract the string that potentially holds our parameters. |
2205 | 2311 | $blob = preg_split('~\[/?(?:' . $alltags_regex . ')~i', substr($message, $pos)); |
@@ -2219,24 +2325,27 @@ discard block |
||
2219 | 2325 | |
2220 | 2326 | $match = preg_match('~^' . implode('', $preg) . '$~i', implode(' ', $given_params), $matches) !== 0; |
2221 | 2327 | |
2222 | - if ($match) |
|
2223 | - $blob_counter = count($blobs) + 1; |
|
2328 | + if ($match) { |
|
2329 | + $blob_counter = count($blobs) + 1; |
|
2330 | + } |
|
2224 | 2331 | } |
2225 | 2332 | |
2226 | 2333 | // Didn't match our parameter list, try the next possible. |
2227 | - if (!$match) |
|
2228 | - continue; |
|
2334 | + if (!$match) { |
|
2335 | + continue; |
|
2336 | + } |
|
2229 | 2337 | |
2230 | 2338 | $params = array(); |
2231 | 2339 | for ($i = 1, $n = count($matches); $i < $n; $i += 2) |
2232 | 2340 | { |
2233 | 2341 | $key = strtok(ltrim($matches[$i]), '='); |
2234 | - if (isset($possible['parameters'][$key]['value'])) |
|
2235 | - $params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1])); |
|
2236 | - elseif (isset($possible['parameters'][$key]['validate'])) |
|
2237 | - $params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]); |
|
2238 | - else |
|
2239 | - $params['{' . $key . '}'] = $matches[$i + 1]; |
|
2342 | + if (isset($possible['parameters'][$key]['value'])) { |
|
2343 | + $params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1])); |
|
2344 | + } elseif (isset($possible['parameters'][$key]['validate'])) { |
|
2345 | + $params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]); |
|
2346 | + } else { |
|
2347 | + $params['{' . $key . '}'] = $matches[$i + 1]; |
|
2348 | + } |
|
2240 | 2349 | |
2241 | 2350 | // Just to make sure: replace any $ or { so they can't interpolate wrongly. |
2242 | 2351 | $params['{' . $key . '}'] = strtr($params['{' . $key . '}'], array('$' => '$', '{' => '{')); |
@@ -2244,23 +2353,26 @@ discard block |
||
2244 | 2353 | |
2245 | 2354 | foreach ($possible['parameters'] as $p => $info) |
2246 | 2355 | { |
2247 | - if (!isset($params['{' . $p . '}'])) |
|
2248 | - $params['{' . $p . '}'] = ''; |
|
2356 | + if (!isset($params['{' . $p . '}'])) { |
|
2357 | + $params['{' . $p . '}'] = ''; |
|
2358 | + } |
|
2249 | 2359 | } |
2250 | 2360 | |
2251 | 2361 | $tag = $possible; |
2252 | 2362 | |
2253 | 2363 | // Put the parameters into the string. |
2254 | - if (isset($tag['before'])) |
|
2255 | - $tag['before'] = strtr($tag['before'], $params); |
|
2256 | - if (isset($tag['after'])) |
|
2257 | - $tag['after'] = strtr($tag['after'], $params); |
|
2258 | - if (isset($tag['content'])) |
|
2259 | - $tag['content'] = strtr($tag['content'], $params); |
|
2364 | + if (isset($tag['before'])) { |
|
2365 | + $tag['before'] = strtr($tag['before'], $params); |
|
2366 | + } |
|
2367 | + if (isset($tag['after'])) { |
|
2368 | + $tag['after'] = strtr($tag['after'], $params); |
|
2369 | + } |
|
2370 | + if (isset($tag['content'])) { |
|
2371 | + $tag['content'] = strtr($tag['content'], $params); |
|
2372 | + } |
|
2260 | 2373 | |
2261 | 2374 | $pos1 += strlen($given_param_string); |
2262 | - } |
|
2263 | - else |
|
2375 | + } else |
|
2264 | 2376 | { |
2265 | 2377 | $tag = $possible; |
2266 | 2378 | $params = array(); |
@@ -2271,8 +2383,9 @@ discard block |
||
2271 | 2383 | // Item codes are complicated buggers... they are implicit [li]s and can make [list]s! |
2272 | 2384 | if ($smileys !== false && $tag === null && isset($itemcodes[$message[$pos + 1]]) && $message[$pos + 2] == ']' && !isset($disabled['list']) && !isset($disabled['li'])) |
2273 | 2385 | { |
2274 | - if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) |
|
2275 | - continue; |
|
2386 | + if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) { |
|
2387 | + continue; |
|
2388 | + } |
|
2276 | 2389 | |
2277 | 2390 | $tag = $itemcodes[$message[$pos + 1]]; |
2278 | 2391 | |
@@ -2293,9 +2406,9 @@ discard block |
||
2293 | 2406 | { |
2294 | 2407 | array_pop($open_tags); |
2295 | 2408 | $code = '</li>'; |
2409 | + } else { |
|
2410 | + $code = ''; |
|
2296 | 2411 | } |
2297 | - else |
|
2298 | - $code = ''; |
|
2299 | 2412 | |
2300 | 2413 | // Now we open a new tag. |
2301 | 2414 | $open_tags[] = array( |
@@ -2342,12 +2455,14 @@ discard block |
||
2342 | 2455 | } |
2343 | 2456 | |
2344 | 2457 | // No tag? Keep looking, then. Silly people using brackets without actual tags. |
2345 | - if ($tag === null) |
|
2346 | - continue; |
|
2458 | + if ($tag === null) { |
|
2459 | + continue; |
|
2460 | + } |
|
2347 | 2461 | |
2348 | 2462 | // Propagate the list to the child (so wrapping the disallowed tag won't work either.) |
2349 | - if (isset($inside['disallow_children'])) |
|
2350 | - $tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children']; |
|
2463 | + if (isset($inside['disallow_children'])) { |
|
2464 | + $tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children']; |
|
2465 | + } |
|
2351 | 2466 | |
2352 | 2467 | // Is this tag disabled? |
2353 | 2468 | if (isset($disabled[$tag['tag']])) |
@@ -2357,14 +2472,13 @@ discard block |
||
2357 | 2472 | $tag['before'] = !empty($tag['block_level']) ? '<div>' : ''; |
2358 | 2473 | $tag['after'] = !empty($tag['block_level']) ? '</div>' : ''; |
2359 | 2474 | $tag['content'] = isset($tag['type']) && $tag['type'] == 'closed' ? '' : (!empty($tag['block_level']) ? '<div>$1</div>' : '$1'); |
2360 | - } |
|
2361 | - elseif (isset($tag['disabled_before']) || isset($tag['disabled_after'])) |
|
2475 | + } elseif (isset($tag['disabled_before']) || isset($tag['disabled_after'])) |
|
2362 | 2476 | { |
2363 | 2477 | $tag['before'] = isset($tag['disabled_before']) ? $tag['disabled_before'] : (!empty($tag['block_level']) ? '<div>' : ''); |
2364 | 2478 | $tag['after'] = isset($tag['disabled_after']) ? $tag['disabled_after'] : (!empty($tag['block_level']) ? '</div>' : ''); |
2479 | + } else { |
|
2480 | + $tag['content'] = $tag['disabled_content']; |
|
2365 | 2481 | } |
2366 | - else |
|
2367 | - $tag['content'] = $tag['disabled_content']; |
|
2368 | 2482 | } |
2369 | 2483 | |
2370 | 2484 | // we use this a lot |
@@ -2374,8 +2488,9 @@ discard block |
||
2374 | 2488 | if (!empty($tag['block_level']) && $tag['tag'] != 'html' && empty($inside['block_level'])) |
2375 | 2489 | { |
2376 | 2490 | $n = count($open_tags) - 1; |
2377 | - while (empty($open_tags[$n]['block_level']) && $n >= 0) |
|
2378 | - $n--; |
|
2491 | + while (empty($open_tags[$n]['block_level']) && $n >= 0) { |
|
2492 | + $n--; |
|
2493 | + } |
|
2379 | 2494 | |
2380 | 2495 | // Close all the non block level tags so this tag isn't surrounded by them. |
2381 | 2496 | for ($i = count($open_tags) - 1; $i > $n; $i--) |
@@ -2386,10 +2501,12 @@ discard block |
||
2386 | 2501 | $pos1 += $ot_strlen + 2; |
2387 | 2502 | |
2388 | 2503 | // Trim or eat trailing stuff... see comment at the end of the big loop. |
2389 | - if (!empty($open_tags[$i]['block_level']) && substr($message, $pos, 4) == '<br>') |
|
2390 | - $message = substr($message, 0, $pos) . substr($message, $pos + 4); |
|
2391 | - if (!empty($open_tags[$i]['trim']) && $tag['trim'] != 'inside' && preg_match('~(<br>| |\s)*~', substr($message, $pos), $matches) != 0) |
|
2392 | - $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
2504 | + if (!empty($open_tags[$i]['block_level']) && substr($message, $pos, 4) == '<br>') { |
|
2505 | + $message = substr($message, 0, $pos) . substr($message, $pos + 4); |
|
2506 | + } |
|
2507 | + if (!empty($open_tags[$i]['trim']) && $tag['trim'] != 'inside' && preg_match('~(<br>| |\s)*~', substr($message, $pos), $matches) != 0) { |
|
2508 | + $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
2509 | + } |
|
2393 | 2510 | |
2394 | 2511 | array_pop($open_tags); |
2395 | 2512 | } |
@@ -2407,16 +2524,19 @@ discard block |
||
2407 | 2524 | elseif ($tag['type'] == 'unparsed_content') |
2408 | 2525 | { |
2409 | 2526 | $pos2 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos1); |
2410 | - if ($pos2 === false) |
|
2411 | - continue; |
|
2527 | + if ($pos2 === false) { |
|
2528 | + continue; |
|
2529 | + } |
|
2412 | 2530 | |
2413 | 2531 | $data = substr($message, $pos1, $pos2 - $pos1); |
2414 | 2532 | |
2415 | - if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') |
|
2416 | - $data = substr($data, 4); |
|
2533 | + if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') { |
|
2534 | + $data = substr($data, 4); |
|
2535 | + } |
|
2417 | 2536 | |
2418 | - if (isset($tag['validate'])) |
|
2419 | - $tag['validate']($tag, $data, $disabled, $params); |
|
2537 | + if (isset($tag['validate'])) { |
|
2538 | + $tag['validate']($tag, $data, $disabled, $params); |
|
2539 | + } |
|
2420 | 2540 | |
2421 | 2541 | $code = strtr($tag['content'], array('$1' => $data)); |
2422 | 2542 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 3 + $tag_strlen); |
@@ -2432,34 +2552,40 @@ discard block |
||
2432 | 2552 | if (isset($tag['quoted'])) |
2433 | 2553 | { |
2434 | 2554 | $quoted = substr($message, $pos1, 6) == '"'; |
2435 | - if ($tag['quoted'] != 'optional' && !$quoted) |
|
2436 | - continue; |
|
2555 | + if ($tag['quoted'] != 'optional' && !$quoted) { |
|
2556 | + continue; |
|
2557 | + } |
|
2437 | 2558 | |
2438 | - if ($quoted) |
|
2439 | - $pos1 += 6; |
|
2559 | + if ($quoted) { |
|
2560 | + $pos1 += 6; |
|
2561 | + } |
|
2562 | + } else { |
|
2563 | + $quoted = false; |
|
2440 | 2564 | } |
2441 | - else |
|
2442 | - $quoted = false; |
|
2443 | 2565 | |
2444 | 2566 | $pos2 = strpos($message, $quoted == false ? ']' : '"]', $pos1); |
2445 | - if ($pos2 === false) |
|
2446 | - continue; |
|
2567 | + if ($pos2 === false) { |
|
2568 | + continue; |
|
2569 | + } |
|
2447 | 2570 | |
2448 | 2571 | $pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2); |
2449 | - if ($pos3 === false) |
|
2450 | - continue; |
|
2572 | + if ($pos3 === false) { |
|
2573 | + continue; |
|
2574 | + } |
|
2451 | 2575 | |
2452 | 2576 | $data = array( |
2453 | 2577 | substr($message, $pos2 + ($quoted == false ? 1 : 7), $pos3 - ($pos2 + ($quoted == false ? 1 : 7))), |
2454 | 2578 | substr($message, $pos1, $pos2 - $pos1) |
2455 | 2579 | ); |
2456 | 2580 | |
2457 | - if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') |
|
2458 | - $data[0] = substr($data[0], 4); |
|
2581 | + if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') { |
|
2582 | + $data[0] = substr($data[0], 4); |
|
2583 | + } |
|
2459 | 2584 | |
2460 | 2585 | // Validation for my parking, please! |
2461 | - if (isset($tag['validate'])) |
|
2462 | - $tag['validate']($tag, $data, $disabled, $params); |
|
2586 | + if (isset($tag['validate'])) { |
|
2587 | + $tag['validate']($tag, $data, $disabled, $params); |
|
2588 | + } |
|
2463 | 2589 | |
2464 | 2590 | $code = strtr($tag['content'], array('$1' => $data[0], '$2' => $data[1])); |
2465 | 2591 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen); |
@@ -2476,23 +2602,27 @@ discard block |
||
2476 | 2602 | elseif ($tag['type'] == 'unparsed_commas_content') |
2477 | 2603 | { |
2478 | 2604 | $pos2 = strpos($message, ']', $pos1); |
2479 | - if ($pos2 === false) |
|
2480 | - continue; |
|
2605 | + if ($pos2 === false) { |
|
2606 | + continue; |
|
2607 | + } |
|
2481 | 2608 | |
2482 | 2609 | $pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2); |
2483 | - if ($pos3 === false) |
|
2484 | - continue; |
|
2610 | + if ($pos3 === false) { |
|
2611 | + continue; |
|
2612 | + } |
|
2485 | 2613 | |
2486 | 2614 | // We want $1 to be the content, and the rest to be csv. |
2487 | 2615 | $data = explode(',', ',' . substr($message, $pos1, $pos2 - $pos1)); |
2488 | 2616 | $data[0] = substr($message, $pos2 + 1, $pos3 - $pos2 - 1); |
2489 | 2617 | |
2490 | - if (isset($tag['validate'])) |
|
2491 | - $tag['validate']($tag, $data, $disabled, $params); |
|
2618 | + if (isset($tag['validate'])) { |
|
2619 | + $tag['validate']($tag, $data, $disabled, $params); |
|
2620 | + } |
|
2492 | 2621 | |
2493 | 2622 | $code = $tag['content']; |
2494 | - foreach ($data as $k => $d) |
|
2495 | - $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
2623 | + foreach ($data as $k => $d) { |
|
2624 | + $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
2625 | + } |
|
2496 | 2626 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen); |
2497 | 2627 | $pos += strlen($code) - 1 + 2; |
2498 | 2628 | } |
@@ -2500,24 +2630,28 @@ discard block |
||
2500 | 2630 | elseif ($tag['type'] == 'unparsed_commas') |
2501 | 2631 | { |
2502 | 2632 | $pos2 = strpos($message, ']', $pos1); |
2503 | - if ($pos2 === false) |
|
2504 | - continue; |
|
2633 | + if ($pos2 === false) { |
|
2634 | + continue; |
|
2635 | + } |
|
2505 | 2636 | |
2506 | 2637 | $data = explode(',', substr($message, $pos1, $pos2 - $pos1)); |
2507 | 2638 | |
2508 | - if (isset($tag['validate'])) |
|
2509 | - $tag['validate']($tag, $data, $disabled, $params); |
|
2639 | + if (isset($tag['validate'])) { |
|
2640 | + $tag['validate']($tag, $data, $disabled, $params); |
|
2641 | + } |
|
2510 | 2642 | |
2511 | 2643 | // Fix after, for disabled code mainly. |
2512 | - foreach ($data as $k => $d) |
|
2513 | - $tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d))); |
|
2644 | + foreach ($data as $k => $d) { |
|
2645 | + $tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d))); |
|
2646 | + } |
|
2514 | 2647 | |
2515 | 2648 | $open_tags[] = $tag; |
2516 | 2649 | |
2517 | 2650 | // Replace them out, $1, $2, $3, $4, etc. |
2518 | 2651 | $code = $tag['before']; |
2519 | - foreach ($data as $k => $d) |
|
2520 | - $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
2652 | + foreach ($data as $k => $d) { |
|
2653 | + $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
2654 | + } |
|
2521 | 2655 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 1); |
2522 | 2656 | $pos += strlen($code) - 1 + 2; |
2523 | 2657 | } |
@@ -2528,28 +2662,33 @@ discard block |
||
2528 | 2662 | if (isset($tag['quoted'])) |
2529 | 2663 | { |
2530 | 2664 | $quoted = substr($message, $pos1, 6) == '"'; |
2531 | - if ($tag['quoted'] != 'optional' && !$quoted) |
|
2532 | - continue; |
|
2665 | + if ($tag['quoted'] != 'optional' && !$quoted) { |
|
2666 | + continue; |
|
2667 | + } |
|
2533 | 2668 | |
2534 | - if ($quoted) |
|
2535 | - $pos1 += 6; |
|
2669 | + if ($quoted) { |
|
2670 | + $pos1 += 6; |
|
2671 | + } |
|
2672 | + } else { |
|
2673 | + $quoted = false; |
|
2536 | 2674 | } |
2537 | - else |
|
2538 | - $quoted = false; |
|
2539 | 2675 | |
2540 | 2676 | $pos2 = strpos($message, $quoted == false ? ']' : '"]', $pos1); |
2541 | - if ($pos2 === false) |
|
2542 | - continue; |
|
2677 | + if ($pos2 === false) { |
|
2678 | + continue; |
|
2679 | + } |
|
2543 | 2680 | |
2544 | 2681 | $data = substr($message, $pos1, $pos2 - $pos1); |
2545 | 2682 | |
2546 | 2683 | // Validation for my parking, please! |
2547 | - if (isset($tag['validate'])) |
|
2548 | - $tag['validate']($tag, $data, $disabled, $params); |
|
2684 | + if (isset($tag['validate'])) { |
|
2685 | + $tag['validate']($tag, $data, $disabled, $params); |
|
2686 | + } |
|
2549 | 2687 | |
2550 | 2688 | // For parsed content, we must recurse to avoid security problems. |
2551 | - if ($tag['type'] != 'unparsed_equals') |
|
2552 | - $data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array()); |
|
2689 | + if ($tag['type'] != 'unparsed_equals') { |
|
2690 | + $data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array()); |
|
2691 | + } |
|
2553 | 2692 | |
2554 | 2693 | $tag['after'] = strtr($tag['after'], array('$1' => $data)); |
2555 | 2694 | |
@@ -2561,34 +2700,40 @@ discard block |
||
2561 | 2700 | } |
2562 | 2701 | |
2563 | 2702 | // If this is block level, eat any breaks after it. |
2564 | - if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') |
|
2565 | - $message = substr($message, 0, $pos + 1) . substr($message, $pos + 5); |
|
2703 | + if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') { |
|
2704 | + $message = substr($message, 0, $pos + 1) . substr($message, $pos + 5); |
|
2705 | + } |
|
2566 | 2706 | |
2567 | 2707 | // Are we trimming outside this tag? |
2568 | - if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>| |\s)*~', substr($message, $pos + 1), $matches) != 0) |
|
2569 | - $message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0])); |
|
2708 | + if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>| |\s)*~', substr($message, $pos + 1), $matches) != 0) { |
|
2709 | + $message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0])); |
|
2710 | + } |
|
2570 | 2711 | } |
2571 | 2712 | |
2572 | 2713 | // Close any remaining tags. |
2573 | - while ($tag = array_pop($open_tags)) |
|
2574 | - $message .= "\n" . $tag['after'] . "\n"; |
|
2714 | + while ($tag = array_pop($open_tags)) { |
|
2715 | + $message .= "\n" . $tag['after'] . "\n"; |
|
2716 | + } |
|
2575 | 2717 | |
2576 | 2718 | // Parse the smileys within the parts where it can be done safely. |
2577 | 2719 | if ($smileys === true) |
2578 | 2720 | { |
2579 | 2721 | $message_parts = explode("\n", $message); |
2580 | - for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) |
|
2581 | - parsesmileys($message_parts[$i]); |
|
2722 | + for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) { |
|
2723 | + parsesmileys($message_parts[$i]); |
|
2724 | + } |
|
2582 | 2725 | |
2583 | 2726 | $message = implode('', $message_parts); |
2584 | 2727 | } |
2585 | 2728 | |
2586 | 2729 | // No smileys, just get rid of the markers. |
2587 | - else |
|
2588 | - $message = strtr($message, array("\n" => '')); |
|
2730 | + else { |
|
2731 | + $message = strtr($message, array("\n" => '')); |
|
2732 | + } |
|
2589 | 2733 | |
2590 | - if ($message !== '' && $message[0] === ' ') |
|
2591 | - $message = ' ' . substr($message, 1); |
|
2734 | + if ($message !== '' && $message[0] === ' ') { |
|
2735 | + $message = ' ' . substr($message, 1); |
|
2736 | + } |
|
2592 | 2737 | |
2593 | 2738 | // Cleanup whitespace. |
2594 | 2739 | $message = strtr($message, array(' ' => ' ', "\r" => '', "\n" => '<br>', '<br> ' => '<br> ', ' ' => "\n")); |
@@ -2597,15 +2742,16 @@ discard block |
||
2597 | 2742 | call_integration_hook('integrate_post_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags)); |
2598 | 2743 | |
2599 | 2744 | // Cache the output if it took some time... |
2600 | - if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) |
|
2601 | - cache_put_data($cache_key, $message, 240); |
|
2745 | + if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) { |
|
2746 | + cache_put_data($cache_key, $message, 240); |
|
2747 | + } |
|
2602 | 2748 | |
2603 | 2749 | // If this was a force parse revert if needed. |
2604 | 2750 | if (!empty($parse_tags)) |
2605 | 2751 | { |
2606 | - if (empty($temp_bbc)) |
|
2607 | - $bbc_codes = array(); |
|
2608 | - else |
|
2752 | + if (empty($temp_bbc)) { |
|
2753 | + $bbc_codes = array(); |
|
2754 | + } else |
|
2609 | 2755 | { |
2610 | 2756 | $bbc_codes = $temp_bbc; |
2611 | 2757 | unset($temp_bbc); |
@@ -2632,8 +2778,9 @@ discard block |
||
2632 | 2778 | static $smileyPregSearch = null, $smileyPregReplacements = array(); |
2633 | 2779 | |
2634 | 2780 | // No smiley set at all?! |
2635 | - if ($user_info['smiley_set'] == 'none' || trim($message) == '') |
|
2636 | - return; |
|
2781 | + if ($user_info['smiley_set'] == 'none' || trim($message) == '') { |
|
2782 | + return; |
|
2783 | + } |
|
2637 | 2784 | |
2638 | 2785 | // If smileyPregSearch hasn't been set, do it now. |
2639 | 2786 | if (empty($smileyPregSearch)) |
@@ -2644,8 +2791,7 @@ discard block |
||
2644 | 2791 | $smileysfrom = array('>:D', ':D', '::)', '>:(', ':))', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', '0:)'); |
2645 | 2792 | $smileysto = array('evil.gif', 'cheesy.gif', 'rolleyes.gif', 'angry.gif', 'laugh.gif', 'smiley.gif', 'wink.gif', 'grin.gif', 'sad.gif', 'shocked.gif', 'cool.gif', 'tongue.gif', 'huh.gif', 'embarrassed.gif', 'lipsrsealed.gif', 'kiss.gif', 'cry.gif', 'undecided.gif', 'azn.gif', 'afro.gif', 'police.gif', 'angel.gif'); |
2646 | 2793 | $smileysdescs = array('', $txt['icon_cheesy'], $txt['icon_rolleyes'], $txt['icon_angry'], '', $txt['icon_smiley'], $txt['icon_wink'], $txt['icon_grin'], $txt['icon_sad'], $txt['icon_shocked'], $txt['icon_cool'], $txt['icon_tongue'], $txt['icon_huh'], $txt['icon_embarrassed'], $txt['icon_lips'], $txt['icon_kiss'], $txt['icon_cry'], $txt['icon_undecided'], '', '', '', ''); |
2647 | - } |
|
2648 | - else |
|
2794 | + } else |
|
2649 | 2795 | { |
2650 | 2796 | // Load the smileys in reverse order by length so they don't get parsed wrong. |
2651 | 2797 | if (($temp = cache_get_data('parsing_smileys', 480)) == null) |
@@ -2669,9 +2815,9 @@ discard block |
||
2669 | 2815 | $smcFunc['db_free_result']($result); |
2670 | 2816 | |
2671 | 2817 | cache_put_data('parsing_smileys', array($smileysfrom, $smileysto, $smileysdescs), 480); |
2818 | + } else { |
|
2819 | + list ($smileysfrom, $smileysto, $smileysdescs) = $temp; |
|
2672 | 2820 | } |
2673 | - else |
|
2674 | - list ($smileysfrom, $smileysto, $smileysdescs) = $temp; |
|
2675 | 2821 | } |
2676 | 2822 | |
2677 | 2823 | // The non-breaking-space is a complex thing... |
@@ -2748,35 +2894,41 @@ discard block |
||
2748 | 2894 | global $scripturl, $context, $modSettings, $db_show_debug, $db_cache; |
2749 | 2895 | |
2750 | 2896 | // In case we have mail to send, better do that - as obExit doesn't always quite make it... |
2751 | - if (!empty($context['flush_mail'])) |
|
2752 | - // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
2897 | + if (!empty($context['flush_mail'])) { |
|
2898 | + // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
2753 | 2899 | AddMailQueue(true); |
2900 | + } |
|
2754 | 2901 | |
2755 | 2902 | $add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && substr($setLocation, 0, 6) != 'about:'; |
2756 | 2903 | |
2757 | - if ($add) |
|
2758 | - $setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : ''); |
|
2904 | + if ($add) { |
|
2905 | + $setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : ''); |
|
2906 | + } |
|
2759 | 2907 | |
2760 | 2908 | // Put the session ID in. |
2761 | - if (defined('SID') && SID != '') |
|
2762 | - $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation); |
|
2909 | + if (defined('SID') && SID != '') { |
|
2910 | + $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation); |
|
2911 | + } |
|
2763 | 2912 | // Keep that debug in their for template debugging! |
2764 | - elseif (isset($_GET['debug'])) |
|
2765 | - $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation); |
|
2913 | + elseif (isset($_GET['debug'])) { |
|
2914 | + $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation); |
|
2915 | + } |
|
2766 | 2916 | |
2767 | 2917 | if (!empty($modSettings['queryless_urls']) && (empty($context['server']['is_cgi']) || ini_get('cgi.fix_pathinfo') == 1 || @get_cfg_var('cgi.fix_pathinfo') == 1) && (!empty($context['server']['is_apache']) || !empty($context['server']['is_lighttpd']) || !empty($context['server']['is_litespeed']))) |
2768 | 2918 | { |
2769 | - if (defined('SID') && SID != '') |
|
2770 | - $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#]+?)(#[^"]*?)?$~', |
|
2919 | + if (defined('SID') && SID != '') { |
|
2920 | + $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#]+?)(#[^"]*?)?$~', |
|
2771 | 2921 | function ($m) use ($scripturl) |
2772 | 2922 | { |
2773 | 2923 | return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : ""); |
2924 | + } |
|
2774 | 2925 | }, $setLocation); |
2775 | - else |
|
2776 | - $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~', |
|
2926 | + else { |
|
2927 | + $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~', |
|
2777 | 2928 | function ($m) use ($scripturl) |
2778 | 2929 | { |
2779 | 2930 | return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : ""); |
2931 | + } |
|
2780 | 2932 | }, $setLocation); |
2781 | 2933 | } |
2782 | 2934 | |
@@ -2787,8 +2939,9 @@ discard block |
||
2787 | 2939 | header('Location: ' . str_replace(' ', '%20', $setLocation), true, $permanent ? 301 : 302); |
2788 | 2940 | |
2789 | 2941 | // Debugging. |
2790 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
2791 | - $_SESSION['debug_redirect'] = $db_cache; |
|
2942 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
2943 | + $_SESSION['debug_redirect'] = $db_cache; |
|
2944 | + } |
|
2792 | 2945 | |
2793 | 2946 | obExit(false); |
2794 | 2947 | } |
@@ -2807,51 +2960,60 @@ discard block |
||
2807 | 2960 | |
2808 | 2961 | // Attempt to prevent a recursive loop. |
2809 | 2962 | ++$level; |
2810 | - if ($level > 1 && !$from_fatal_error && !$has_fatal_error) |
|
2811 | - exit; |
|
2812 | - if ($from_fatal_error) |
|
2813 | - $has_fatal_error = true; |
|
2963 | + if ($level > 1 && !$from_fatal_error && !$has_fatal_error) { |
|
2964 | + exit; |
|
2965 | + } |
|
2966 | + if ($from_fatal_error) { |
|
2967 | + $has_fatal_error = true; |
|
2968 | + } |
|
2814 | 2969 | |
2815 | 2970 | // Clear out the stat cache. |
2816 | 2971 | trackStats(); |
2817 | 2972 | |
2818 | 2973 | // If we have mail to send, send it. |
2819 | - if (!empty($context['flush_mail'])) |
|
2820 | - // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
2974 | + if (!empty($context['flush_mail'])) { |
|
2975 | + // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
2821 | 2976 | AddMailQueue(true); |
2977 | + } |
|
2822 | 2978 | |
2823 | 2979 | $do_header = $header === null ? !$header_done : $header; |
2824 | - if ($do_footer === null) |
|
2825 | - $do_footer = $do_header; |
|
2980 | + if ($do_footer === null) { |
|
2981 | + $do_footer = $do_header; |
|
2982 | + } |
|
2826 | 2983 | |
2827 | 2984 | // Has the template/header been done yet? |
2828 | 2985 | if ($do_header) |
2829 | 2986 | { |
2830 | 2987 | // Was the page title set last minute? Also update the HTML safe one. |
2831 | - if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) |
|
2832 | - $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); |
|
2988 | + if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) { |
|
2989 | + $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); |
|
2990 | + } |
|
2833 | 2991 | |
2834 | 2992 | // Start up the session URL fixer. |
2835 | 2993 | ob_start('ob_sessrewrite'); |
2836 | 2994 | |
2837 | - if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) |
|
2838 | - $buffers = explode(',', $settings['output_buffers']); |
|
2839 | - elseif (!empty($settings['output_buffers'])) |
|
2840 | - $buffers = $settings['output_buffers']; |
|
2841 | - else |
|
2842 | - $buffers = array(); |
|
2995 | + if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) { |
|
2996 | + $buffers = explode(',', $settings['output_buffers']); |
|
2997 | + } elseif (!empty($settings['output_buffers'])) { |
|
2998 | + $buffers = $settings['output_buffers']; |
|
2999 | + } else { |
|
3000 | + $buffers = array(); |
|
3001 | + } |
|
2843 | 3002 | |
2844 | - if (isset($modSettings['integrate_buffer'])) |
|
2845 | - $buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers); |
|
3003 | + if (isset($modSettings['integrate_buffer'])) { |
|
3004 | + $buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers); |
|
3005 | + } |
|
2846 | 3006 | |
2847 | - if (!empty($buffers)) |
|
2848 | - foreach ($buffers as $function) |
|
3007 | + if (!empty($buffers)) { |
|
3008 | + foreach ($buffers as $function) |
|
2849 | 3009 | { |
2850 | 3010 | $call = call_helper($function, true); |
3011 | + } |
|
2851 | 3012 | |
2852 | 3013 | // Is it valid? |
2853 | - if (!empty($call)) |
|
2854 | - ob_start($call); |
|
3014 | + if (!empty($call)) { |
|
3015 | + ob_start($call); |
|
3016 | + } |
|
2855 | 3017 | } |
2856 | 3018 | |
2857 | 3019 | // Display the screen in the logical order. |
@@ -2863,8 +3025,9 @@ discard block |
||
2863 | 3025 | loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main'); |
2864 | 3026 | |
2865 | 3027 | // Anything special to put out? |
2866 | - if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) |
|
2867 | - echo $context['insert_after_template']; |
|
3028 | + if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) { |
|
3029 | + echo $context['insert_after_template']; |
|
3030 | + } |
|
2868 | 3031 | |
2869 | 3032 | // Just so we don't get caught in an endless loop of errors from the footer... |
2870 | 3033 | if (!$footer_done) |
@@ -2873,14 +3036,16 @@ discard block |
||
2873 | 3036 | template_footer(); |
2874 | 3037 | |
2875 | 3038 | // (since this is just debugging... it's okay that it's after </html>.) |
2876 | - if (!isset($_REQUEST['xml'])) |
|
2877 | - displayDebug(); |
|
3039 | + if (!isset($_REQUEST['xml'])) { |
|
3040 | + displayDebug(); |
|
3041 | + } |
|
2878 | 3042 | } |
2879 | 3043 | } |
2880 | 3044 | |
2881 | 3045 | // Remember this URL in case someone doesn't like sending HTTP_REFERER. |
2882 | - if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) |
|
2883 | - $_SESSION['old_url'] = $_SERVER['REQUEST_URL']; |
|
3046 | + if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) { |
|
3047 | + $_SESSION['old_url'] = $_SERVER['REQUEST_URL']; |
|
3048 | + } |
|
2884 | 3049 | |
2885 | 3050 | // For session check verification.... don't switch browsers... |
2886 | 3051 | $_SESSION['USER_AGENT'] = empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT']; |
@@ -2889,9 +3054,10 @@ discard block |
||
2889 | 3054 | call_integration_hook('integrate_exit', array($do_footer)); |
2890 | 3055 | |
2891 | 3056 | // Don't exit if we're coming from index.php; that will pass through normally. |
2892 | - if (!$from_index) |
|
2893 | - exit; |
|
2894 | -} |
|
3057 | + if (!$from_index) { |
|
3058 | + exit; |
|
3059 | + } |
|
3060 | + } |
|
2895 | 3061 | |
2896 | 3062 | /** |
2897 | 3063 | * Get the size of a specified image with better error handling. |
@@ -2910,8 +3076,9 @@ discard block |
||
2910 | 3076 | $url = str_replace(' ', '%20', $url); |
2911 | 3077 | |
2912 | 3078 | // Can we pull this from the cache... please please? |
2913 | - if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) |
|
2914 | - return $temp; |
|
3079 | + if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) { |
|
3080 | + return $temp; |
|
3081 | + } |
|
2915 | 3082 | $t = microtime(); |
2916 | 3083 | |
2917 | 3084 | // Get the host to pester... |
@@ -2921,12 +3088,10 @@ discard block |
||
2921 | 3088 | if ($url == '' || $url == 'http://' || $url == 'https://') |
2922 | 3089 | { |
2923 | 3090 | return false; |
2924 | - } |
|
2925 | - elseif (!isset($match[1])) |
|
3091 | + } elseif (!isset($match[1])) |
|
2926 | 3092 | { |
2927 | 3093 | $size = @getimagesize($url); |
2928 | - } |
|
2929 | - else |
|
3094 | + } else |
|
2930 | 3095 | { |
2931 | 3096 | // Try to connect to the server... give it half a second. |
2932 | 3097 | $temp = 0; |
@@ -2965,12 +3130,14 @@ discard block |
||
2965 | 3130 | } |
2966 | 3131 | |
2967 | 3132 | // If we didn't get it, we failed. |
2968 | - if (!isset($size)) |
|
2969 | - $size = false; |
|
3133 | + if (!isset($size)) { |
|
3134 | + $size = false; |
|
3135 | + } |
|
2970 | 3136 | |
2971 | 3137 | // If this took a long time, we may never have to do it again, but then again we might... |
2972 | - if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) |
|
2973 | - cache_put_data('url_image_size-' . md5($url), $size, 240); |
|
3138 | + if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) { |
|
3139 | + cache_put_data('url_image_size-' . md5($url), $size, 240); |
|
3140 | + } |
|
2974 | 3141 | |
2975 | 3142 | // Didn't work. |
2976 | 3143 | return $size; |
@@ -2988,8 +3155,9 @@ discard block |
||
2988 | 3155 | |
2989 | 3156 | // Under SSI this function can be called more then once. That can cause some problems. |
2990 | 3157 | // So only run the function once unless we are forced to run it again. |
2991 | - if ($loaded && !$forceload) |
|
2992 | - return; |
|
3158 | + if ($loaded && !$forceload) { |
|
3159 | + return; |
|
3160 | + } |
|
2993 | 3161 | |
2994 | 3162 | $loaded = true; |
2995 | 3163 | |
@@ -3001,14 +3169,16 @@ discard block |
||
3001 | 3169 | $context['news_lines'] = array_filter(explode("\n", str_replace("\r", '', trim(addslashes($modSettings['news']))))); |
3002 | 3170 | for ($i = 0, $n = count($context['news_lines']); $i < $n; $i++) |
3003 | 3171 | { |
3004 | - if (trim($context['news_lines'][$i]) == '') |
|
3005 | - continue; |
|
3172 | + if (trim($context['news_lines'][$i]) == '') { |
|
3173 | + continue; |
|
3174 | + } |
|
3006 | 3175 | |
3007 | 3176 | // Clean it up for presentation ;). |
3008 | 3177 | $context['news_lines'][$i] = parse_bbc(stripslashes(trim($context['news_lines'][$i])), true, 'news' . $i); |
3009 | 3178 | } |
3010 | - if (!empty($context['news_lines'])) |
|
3011 | - $context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)]; |
|
3179 | + if (!empty($context['news_lines'])) { |
|
3180 | + $context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)]; |
|
3181 | + } |
|
3012 | 3182 | |
3013 | 3183 | if (!$user_info['is_guest']) |
3014 | 3184 | { |
@@ -3017,40 +3187,48 @@ discard block |
||
3017 | 3187 | $context['user']['alerts'] = &$user_info['alerts']; |
3018 | 3188 | |
3019 | 3189 | // Personal message popup... |
3020 | - if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) |
|
3021 | - $context['user']['popup_messages'] = true; |
|
3022 | - else |
|
3023 | - $context['user']['popup_messages'] = false; |
|
3190 | + if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) { |
|
3191 | + $context['user']['popup_messages'] = true; |
|
3192 | + } else { |
|
3193 | + $context['user']['popup_messages'] = false; |
|
3194 | + } |
|
3024 | 3195 | $_SESSION['unread_messages'] = $user_info['unread_messages']; |
3025 | 3196 | |
3026 | - if (allowedTo('moderate_forum')) |
|
3027 | - $context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0; |
|
3197 | + if (allowedTo('moderate_forum')) { |
|
3198 | + $context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0; |
|
3199 | + } |
|
3028 | 3200 | |
3029 | 3201 | $context['user']['avatar'] = array(); |
3030 | 3202 | |
3031 | 3203 | // Check for gravatar first since we might be forcing them... |
3032 | 3204 | if (($modSettings['gravatarEnabled'] && substr($user_info['avatar']['url'], 0, 11) == 'gravatar://') || !empty($modSettings['gravatarOverride'])) |
3033 | 3205 | { |
3034 | - if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) |
|
3035 | - $context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11)); |
|
3036 | - else |
|
3037 | - $context['user']['avatar']['href'] = get_gravatar_url($user_info['email']); |
|
3206 | + if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) { |
|
3207 | + $context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11)); |
|
3208 | + } else { |
|
3209 | + $context['user']['avatar']['href'] = get_gravatar_url($user_info['email']); |
|
3210 | + } |
|
3038 | 3211 | } |
3039 | 3212 | // Uploaded? |
3040 | - elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) |
|
3041 | - $context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar'; |
|
3213 | + elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) { |
|
3214 | + $context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar'; |
|
3215 | + } |
|
3042 | 3216 | // Full URL? |
3043 | - elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) |
|
3044 | - $context['user']['avatar']['href'] = $user_info['avatar']['url']; |
|
3217 | + elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) { |
|
3218 | + $context['user']['avatar']['href'] = $user_info['avatar']['url']; |
|
3219 | + } |
|
3045 | 3220 | // Otherwise we assume it's server stored. |
3046 | - elseif ($user_info['avatar']['url'] != '') |
|
3047 | - $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']); |
|
3221 | + elseif ($user_info['avatar']['url'] != '') { |
|
3222 | + $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']); |
|
3223 | + } |
|
3048 | 3224 | // No avatar at all? Fine, we have a big fat default avatar ;) |
3049 | - else |
|
3050 | - $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png'; |
|
3225 | + else { |
|
3226 | + $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png'; |
|
3227 | + } |
|
3051 | 3228 | |
3052 | - if (!empty($context['user']['avatar'])) |
|
3053 | - $context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">'; |
|
3229 | + if (!empty($context['user']['avatar'])) { |
|
3230 | + $context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">'; |
|
3231 | + } |
|
3054 | 3232 | |
3055 | 3233 | // Figure out how long they've been logged in. |
3056 | 3234 | $context['user']['total_time_logged_in'] = array( |
@@ -3058,8 +3236,7 @@ discard block |
||
3058 | 3236 | 'hours' => floor(($user_info['total_time_logged_in'] % 86400) / 3600), |
3059 | 3237 | 'minutes' => floor(($user_info['total_time_logged_in'] % 3600) / 60) |
3060 | 3238 | ); |
3061 | - } |
|
3062 | - else |
|
3239 | + } else |
|
3063 | 3240 | { |
3064 | 3241 | $context['user']['messages'] = 0; |
3065 | 3242 | $context['user']['unread_messages'] = 0; |
@@ -3067,12 +3244,14 @@ discard block |
||
3067 | 3244 | $context['user']['total_time_logged_in'] = array('days' => 0, 'hours' => 0, 'minutes' => 0); |
3068 | 3245 | $context['user']['popup_messages'] = false; |
3069 | 3246 | |
3070 | - if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) |
|
3071 | - $txt['welcome_guest'] .= $txt['welcome_guest_activate']; |
|
3247 | + if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) { |
|
3248 | + $txt['welcome_guest'] .= $txt['welcome_guest_activate']; |
|
3249 | + } |
|
3072 | 3250 | |
3073 | 3251 | // If we've upgraded recently, go easy on the passwords. |
3074 | - if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) |
|
3075 | - $context['disable_login_hashing'] = true; |
|
3252 | + if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) { |
|
3253 | + $context['disable_login_hashing'] = true; |
|
3254 | + } |
|
3076 | 3255 | } |
3077 | 3256 | |
3078 | 3257 | // Setup the main menu items. |
@@ -3085,8 +3264,8 @@ discard block |
||
3085 | 3264 | $context['show_pm_popup'] = $context['user']['popup_messages'] && !empty($options['popup_messages']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'pm'); |
3086 | 3265 | |
3087 | 3266 | // 2.1+: Add the PM popup here instead. Theme authors can still override it simply by editing/removing the 'fPmPopup' in the array. |
3088 | - if ($context['show_pm_popup']) |
|
3089 | - addInlineJavaScript(' |
|
3267 | + if ($context['show_pm_popup']) { |
|
3268 | + addInlineJavaScript(' |
|
3090 | 3269 | jQuery(document).ready(function($) { |
3091 | 3270 | new smc_Popup({ |
3092 | 3271 | heading: ' . JavaScriptEscape($txt['show_personal_messages_heading']) . ', |
@@ -3094,15 +3273,17 @@ discard block |
||
3094 | 3273 | icon_class: \'generic_icons mail_new\' |
3095 | 3274 | }); |
3096 | 3275 | });'); |
3276 | + } |
|
3097 | 3277 | |
3098 | 3278 | // Add a generic "Are you sure?" confirmation message. |
3099 | 3279 | addInlineJavaScript(' |
3100 | 3280 | var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';'); |
3101 | 3281 | |
3102 | 3282 | // Now add the capping code for avatars. |
3103 | - if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize') |
|
3104 | - addInlineCss(' |
|
3283 | + if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize') { |
|
3284 | + addInlineCss(' |
|
3105 | 3285 | img.avatar { max-width: ' . $modSettings['avatar_max_width_external'] . 'px; max-height: ' . $modSettings['avatar_max_height_external'] . 'px; }'); |
3286 | + } |
|
3106 | 3287 | |
3107 | 3288 | // This looks weird, but it's because BoardIndex.php references the variable. |
3108 | 3289 | $context['common_stats']['latest_member'] = array( |
@@ -3119,11 +3300,13 @@ discard block |
||
3119 | 3300 | ); |
3120 | 3301 | $context['common_stats']['boardindex_total_posts'] = sprintf($txt['boardindex_total_posts'], $context['common_stats']['total_posts'], $context['common_stats']['total_topics'], $context['common_stats']['total_members']); |
3121 | 3302 | |
3122 | - if (empty($settings['theme_version'])) |
|
3123 | - addJavaScriptVar('smf_scripturl', $scripturl); |
|
3303 | + if (empty($settings['theme_version'])) { |
|
3304 | + addJavaScriptVar('smf_scripturl', $scripturl); |
|
3305 | + } |
|
3124 | 3306 | |
3125 | - if (!isset($context['page_title'])) |
|
3126 | - $context['page_title'] = ''; |
|
3307 | + if (!isset($context['page_title'])) { |
|
3308 | + $context['page_title'] = ''; |
|
3309 | + } |
|
3127 | 3310 | |
3128 | 3311 | // Set some specific vars. |
3129 | 3312 | $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); |
@@ -3133,21 +3316,23 @@ discard block |
||
3133 | 3316 | $context['meta_tags'][] = array('property' => 'og:site_name', 'content' => $context['forum_name']); |
3134 | 3317 | $context['meta_tags'][] = array('property' => 'og:title', 'content' => $context['page_title_html_safe']); |
3135 | 3318 | |
3136 | - if (!empty($context['meta_keywords'])) |
|
3137 | - $context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']); |
|
3319 | + if (!empty($context['meta_keywords'])) { |
|
3320 | + $context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']); |
|
3321 | + } |
|
3138 | 3322 | |
3139 | - if (!empty($context['canonical_url'])) |
|
3140 | - $context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']); |
|
3323 | + if (!empty($context['canonical_url'])) { |
|
3324 | + $context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']); |
|
3325 | + } |
|
3141 | 3326 | |
3142 | - if (!empty($settings['og_image'])) |
|
3143 | - $context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']); |
|
3327 | + if (!empty($settings['og_image'])) { |
|
3328 | + $context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']); |
|
3329 | + } |
|
3144 | 3330 | |
3145 | 3331 | if (!empty($context['meta_description'])) |
3146 | 3332 | { |
3147 | 3333 | $context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['meta_description']); |
3148 | 3334 | $context['meta_tags'][] = array('name' => 'description', 'content' => $context['meta_description']); |
3149 | - } |
|
3150 | - else |
|
3335 | + } else |
|
3151 | 3336 | { |
3152 | 3337 | $context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['page_title_html_safe']); |
3153 | 3338 | $context['meta_tags'][] = array('name' => 'description', 'content' => $context['page_title_html_safe']); |
@@ -3172,8 +3357,9 @@ discard block |
||
3172 | 3357 | $memory_needed = memoryReturnBytes($needed); |
3173 | 3358 | |
3174 | 3359 | // should we account for how much is currently being used? |
3175 | - if ($in_use) |
|
3176 | - $memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576); |
|
3360 | + if ($in_use) { |
|
3361 | + $memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576); |
|
3362 | + } |
|
3177 | 3363 | |
3178 | 3364 | // if more is needed, request it |
3179 | 3365 | if ($memory_current < $memory_needed) |
@@ -3196,8 +3382,9 @@ discard block |
||
3196 | 3382 | */ |
3197 | 3383 | function memoryReturnBytes($val) |
3198 | 3384 | { |
3199 | - if (is_integer($val)) |
|
3200 | - return $val; |
|
3385 | + if (is_integer($val)) { |
|
3386 | + return $val; |
|
3387 | + } |
|
3201 | 3388 | |
3202 | 3389 | // Separate the number from the designator |
3203 | 3390 | $val = trim($val); |
@@ -3233,10 +3420,11 @@ discard block |
||
3233 | 3420 | header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); |
3234 | 3421 | |
3235 | 3422 | // Are we debugging the template/html content? |
3236 | - if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) |
|
3237 | - header('Content-Type: application/xhtml+xml'); |
|
3238 | - elseif (!isset($_REQUEST['xml'])) |
|
3239 | - header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
3423 | + if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) { |
|
3424 | + header('Content-Type: application/xhtml+xml'); |
|
3425 | + } elseif (!isset($_REQUEST['xml'])) { |
|
3426 | + header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
3427 | + } |
|
3240 | 3428 | } |
3241 | 3429 | |
3242 | 3430 | header('Content-Type: text/' . (isset($_REQUEST['xml']) ? 'xml' : 'html') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
@@ -3245,8 +3433,9 @@ discard block |
||
3245 | 3433 | if ($context['in_maintenance'] && $context['user']['is_admin']) |
3246 | 3434 | { |
3247 | 3435 | $position = array_search('body', $context['template_layers']); |
3248 | - if ($position === false) |
|
3249 | - $position = array_search('main', $context['template_layers']); |
|
3436 | + if ($position === false) { |
|
3437 | + $position = array_search('main', $context['template_layers']); |
|
3438 | + } |
|
3250 | 3439 | |
3251 | 3440 | if ($position !== false) |
3252 | 3441 | { |
@@ -3274,23 +3463,25 @@ discard block |
||
3274 | 3463 | |
3275 | 3464 | foreach ($securityFiles as $i => $securityFile) |
3276 | 3465 | { |
3277 | - if (!file_exists($boarddir . '/' . $securityFile)) |
|
3278 | - unset($securityFiles[$i]); |
|
3466 | + if (!file_exists($boarddir . '/' . $securityFile)) { |
|
3467 | + unset($securityFiles[$i]); |
|
3468 | + } |
|
3279 | 3469 | } |
3280 | 3470 | |
3281 | 3471 | // We are already checking so many files...just few more doesn't make any difference! :P |
3282 | - if (!empty($modSettings['currentAttachmentUploadDir'])) |
|
3283 | - $path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; |
|
3284 | - |
|
3285 | - else |
|
3286 | - $path = $modSettings['attachmentUploadDir']; |
|
3472 | + if (!empty($modSettings['currentAttachmentUploadDir'])) { |
|
3473 | + $path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; |
|
3474 | + } else { |
|
3475 | + $path = $modSettings['attachmentUploadDir']; |
|
3476 | + } |
|
3287 | 3477 | |
3288 | 3478 | secureDirectory($path, true); |
3289 | 3479 | secureDirectory($cachedir); |
3290 | 3480 | |
3291 | 3481 | // If agreement is enabled, at least the english version shall exists |
3292 | - if ($modSettings['requireAgreement']) |
|
3293 | - $agreement = !file_exists($boarddir . '/agreement.txt'); |
|
3482 | + if ($modSettings['requireAgreement']) { |
|
3483 | + $agreement = !file_exists($boarddir . '/agreement.txt'); |
|
3484 | + } |
|
3294 | 3485 | |
3295 | 3486 | if (!empty($securityFiles) || (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) || !empty($agreement)) |
3296 | 3487 | { |
@@ -3305,18 +3496,21 @@ discard block |
||
3305 | 3496 | echo ' |
3306 | 3497 | ', $txt['not_removed'], '<strong>', $securityFile, '</strong>!<br>'; |
3307 | 3498 | |
3308 | - if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') |
|
3309 | - echo ' |
|
3499 | + if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') { |
|
3500 | + echo ' |
|
3310 | 3501 | ', sprintf($txt['not_removed_extra'], $securityFile, substr($securityFile, 0, -1)), '<br>'; |
3502 | + } |
|
3311 | 3503 | } |
3312 | 3504 | |
3313 | - if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) |
|
3314 | - echo ' |
|
3505 | + if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) { |
|
3506 | + echo ' |
|
3315 | 3507 | <strong>', $txt['cache_writable'], '</strong><br>'; |
3508 | + } |
|
3316 | 3509 | |
3317 | - if (!empty($agreement)) |
|
3318 | - echo ' |
|
3510 | + if (!empty($agreement)) { |
|
3511 | + echo ' |
|
3319 | 3512 | <strong>', $txt['agreement_missing'], '</strong><br>'; |
3513 | + } |
|
3320 | 3514 | |
3321 | 3515 | echo ' |
3322 | 3516 | </p> |
@@ -3331,16 +3525,18 @@ discard block |
||
3331 | 3525 | <div class="windowbg alert" style="margin: 2ex; padding: 2ex; border: 2px dashed red;"> |
3332 | 3526 | ', sprintf($txt['you_are_post_banned'], $user_info['is_guest'] ? $txt['guest_title'] : $user_info['name']); |
3333 | 3527 | |
3334 | - if (!empty($_SESSION['ban']['cannot_post']['reason'])) |
|
3335 | - echo ' |
|
3528 | + if (!empty($_SESSION['ban']['cannot_post']['reason'])) { |
|
3529 | + echo ' |
|
3336 | 3530 | <div style="padding-left: 4ex; padding-top: 1ex;">', $_SESSION['ban']['cannot_post']['reason'], '</div>'; |
3531 | + } |
|
3337 | 3532 | |
3338 | - if (!empty($_SESSION['ban']['expire_time'])) |
|
3339 | - echo ' |
|
3533 | + if (!empty($_SESSION['ban']['expire_time'])) { |
|
3534 | + echo ' |
|
3340 | 3535 | <div>', sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)), '</div>'; |
3341 | - else |
|
3342 | - echo ' |
|
3536 | + } else { |
|
3537 | + echo ' |
|
3343 | 3538 | <div>', $txt['your_ban_expires_never'], '</div>'; |
3539 | + } |
|
3344 | 3540 | |
3345 | 3541 | echo ' |
3346 | 3542 | </div>'; |
@@ -3356,8 +3552,9 @@ discard block |
||
3356 | 3552 | global $forum_copyright, $software_year, $forum_version; |
3357 | 3553 | |
3358 | 3554 | // Don't display copyright for things like SSI. |
3359 | - if (!isset($forum_version) || !isset($software_year)) |
|
3360 | - return; |
|
3555 | + if (!isset($forum_version) || !isset($software_year)) { |
|
3556 | + return; |
|
3557 | + } |
|
3361 | 3558 | |
3362 | 3559 | // Put in the version... |
3363 | 3560 | printf($forum_copyright, $forum_version, $software_year); |
@@ -3375,9 +3572,10 @@ discard block |
||
3375 | 3572 | $context['load_time'] = comma_format(round(array_sum(explode(' ', microtime())) - array_sum(explode(' ', $time_start)), 3)); |
3376 | 3573 | $context['load_queries'] = $db_count; |
3377 | 3574 | |
3378 | - foreach (array_reverse($context['template_layers']) as $layer) |
|
3379 | - loadSubTemplate($layer . '_below', true); |
|
3380 | -} |
|
3575 | + foreach (array_reverse($context['template_layers']) as $layer) { |
|
3576 | + loadSubTemplate($layer . '_below', true); |
|
3577 | + } |
|
3578 | + } |
|
3381 | 3579 | |
3382 | 3580 | /** |
3383 | 3581 | * Output the Javascript files |
@@ -3408,8 +3606,7 @@ discard block |
||
3408 | 3606 | { |
3409 | 3607 | echo ' |
3410 | 3608 | var ', $key, ';'; |
3411 | - } |
|
3412 | - else |
|
3609 | + } else |
|
3413 | 3610 | { |
3414 | 3611 | echo ' |
3415 | 3612 | var ', $key, ' = ', $value, ';'; |
@@ -3424,26 +3621,27 @@ discard block |
||
3424 | 3621 | foreach ($context['javascript_files'] as $id => $js_file) |
3425 | 3622 | { |
3426 | 3623 | // Last minute call! allow theme authors to disable single files. |
3427 | - if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) |
|
3428 | - continue; |
|
3624 | + if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) { |
|
3625 | + continue; |
|
3626 | + } |
|
3429 | 3627 | |
3430 | 3628 | // By default all files don't get minimized unless the file explicitly says so! |
3431 | 3629 | if (!empty($js_file['options']['minimize']) && !empty($modSettings['minimize_files'])) |
3432 | 3630 | { |
3433 | - if ($do_deferred && !empty($js_file['options']['defer'])) |
|
3434 | - $toMinifyDefer[] = $js_file; |
|
3435 | - |
|
3436 | - elseif (!$do_deferred && empty($js_file['options']['defer'])) |
|
3437 | - $toMinify[] = $js_file; |
|
3631 | + if ($do_deferred && !empty($js_file['options']['defer'])) { |
|
3632 | + $toMinifyDefer[] = $js_file; |
|
3633 | + } elseif (!$do_deferred && empty($js_file['options']['defer'])) { |
|
3634 | + $toMinify[] = $js_file; |
|
3635 | + } |
|
3438 | 3636 | |
3439 | 3637 | // Grab a random seed. |
3440 | - if (!isset($minSeed)) |
|
3441 | - $minSeed = $js_file['options']['seed']; |
|
3442 | - } |
|
3443 | - |
|
3444 | - elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer']))) |
|
3445 | - echo ' |
|
3638 | + if (!isset($minSeed)) { |
|
3639 | + $minSeed = $js_file['options']['seed']; |
|
3640 | + } |
|
3641 | + } elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer']))) { |
|
3642 | + echo ' |
|
3446 | 3643 | <script src="', $js_file['fileUrl'], '"', !empty($js_file['options']['async']) ? ' async="async"' : '', '></script>'; |
3644 | + } |
|
3447 | 3645 | } |
3448 | 3646 | |
3449 | 3647 | if ((!$do_deferred && !empty($toMinify)) || ($do_deferred && !empty($toMinifyDefer))) |
@@ -3451,14 +3649,14 @@ discard block |
||
3451 | 3649 | $result = custMinify(($do_deferred ? $toMinifyDefer : $toMinify), 'js', $do_deferred); |
3452 | 3650 | |
3453 | 3651 | // Minify process couldn't work, print each individual files. |
3454 | - if (!empty($result) && is_array($result)) |
|
3455 | - foreach ($result as $minFailedFile) |
|
3652 | + if (!empty($result) && is_array($result)) { |
|
3653 | + foreach ($result as $minFailedFile) |
|
3456 | 3654 | echo ' |
3457 | 3655 | <script src="', $minFailedFile['fileUrl'], '"', !empty($minFailedFile['options']['async']) ? ' async="async"' : '', '></script>'; |
3458 | - |
|
3459 | - else |
|
3460 | - echo ' |
|
3656 | + } else { |
|
3657 | + echo ' |
|
3461 | 3658 | <script src="', $settings['theme_url'] ,'/scripts/minified', ($do_deferred ? '_deferred' : '') ,'.js', $minSeed ,'"></script>'; |
3659 | + } |
|
3462 | 3660 | } |
3463 | 3661 | |
3464 | 3662 | // Inline JavaScript - Actually useful some times! |
@@ -3469,8 +3667,9 @@ discard block |
||
3469 | 3667 | echo ' |
3470 | 3668 | <script>'; |
3471 | 3669 | |
3472 | - foreach ($context['javascript_inline']['defer'] as $js_code) |
|
3473 | - echo $js_code; |
|
3670 | + foreach ($context['javascript_inline']['defer'] as $js_code) { |
|
3671 | + echo $js_code; |
|
3672 | + } |
|
3474 | 3673 | |
3475 | 3674 | echo ' |
3476 | 3675 | </script>'; |
@@ -3481,8 +3680,9 @@ discard block |
||
3481 | 3680 | echo ' |
3482 | 3681 | <script>'; |
3483 | 3682 | |
3484 | - foreach ($context['javascript_inline']['standard'] as $js_code) |
|
3485 | - echo $js_code; |
|
3683 | + foreach ($context['javascript_inline']['standard'] as $js_code) { |
|
3684 | + echo $js_code; |
|
3685 | + } |
|
3486 | 3686 | |
3487 | 3687 | echo ' |
3488 | 3688 | </script>'; |
@@ -3507,8 +3707,9 @@ discard block |
||
3507 | 3707 | foreach ($context['css_files'] as $id => $file) |
3508 | 3708 | { |
3509 | 3709 | // Last minute call! allow theme authors to disable single files. |
3510 | - if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) |
|
3511 | - continue; |
|
3710 | + if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) { |
|
3711 | + continue; |
|
3712 | + } |
|
3512 | 3713 | |
3513 | 3714 | // By default all files don't get minimized unless the file explicitly says so! |
3514 | 3715 | if (!empty($file['options']['minimize']) && !empty($modSettings['minimize_files'])) |
@@ -3516,12 +3717,12 @@ discard block |
||
3516 | 3717 | $toMinify[] = $file; |
3517 | 3718 | |
3518 | 3719 | // Grab a random seed. |
3519 | - if (!isset($minSeed)) |
|
3520 | - $minSeed = $file['options']['seed']; |
|
3720 | + if (!isset($minSeed)) { |
|
3721 | + $minSeed = $file['options']['seed']; |
|
3722 | + } |
|
3723 | + } else { |
|
3724 | + $normal[] = $file['fileUrl']; |
|
3521 | 3725 | } |
3522 | - |
|
3523 | - else |
|
3524 | - $normal[] = $file['fileUrl']; |
|
3525 | 3726 | } |
3526 | 3727 | |
3527 | 3728 | if (!empty($toMinify)) |
@@ -3529,28 +3730,30 @@ discard block |
||
3529 | 3730 | $result = custMinify($toMinify, 'css'); |
3530 | 3731 | |
3531 | 3732 | // Minify process couldn't work, print each individual files. |
3532 | - if (!empty($result) && is_array($result)) |
|
3533 | - foreach ($result as $minFailedFile) |
|
3733 | + if (!empty($result) && is_array($result)) { |
|
3734 | + foreach ($result as $minFailedFile) |
|
3534 | 3735 | echo ' |
3535 | 3736 | <link rel="stylesheet" href="', $minFailedFile['fileUrl'], '">'; |
3536 | - |
|
3537 | - else |
|
3538 | - echo ' |
|
3737 | + } else { |
|
3738 | + echo ' |
|
3539 | 3739 | <link rel="stylesheet" href="', $settings['theme_url'] ,'/css/minified.css', $minSeed ,'">'; |
3740 | + } |
|
3540 | 3741 | } |
3541 | 3742 | |
3542 | 3743 | // Print the rest after the minified files. |
3543 | - if (!empty($normal)) |
|
3544 | - foreach ($normal as $nf) |
|
3744 | + if (!empty($normal)) { |
|
3745 | + foreach ($normal as $nf) |
|
3545 | 3746 | echo ' |
3546 | 3747 | <link rel="stylesheet" href="', $nf ,'">'; |
3748 | + } |
|
3547 | 3749 | |
3548 | 3750 | if ($db_show_debug === true) |
3549 | 3751 | { |
3550 | 3752 | // Try to keep only what's useful. |
3551 | 3753 | $repl = array($boardurl . '/Themes/' => '', $boardurl . '/' => ''); |
3552 | - foreach ($context['css_files'] as $file) |
|
3553 | - $context['debug']['sheets'][] = strtr($file['fileName'], $repl); |
|
3754 | + foreach ($context['css_files'] as $file) { |
|
3755 | + $context['debug']['sheets'][] = strtr($file['fileName'], $repl); |
|
3756 | + } |
|
3554 | 3757 | } |
3555 | 3758 | |
3556 | 3759 | if (!empty($context['css_header'])) |
@@ -3558,9 +3761,10 @@ discard block |
||
3558 | 3761 | echo ' |
3559 | 3762 | <style>'; |
3560 | 3763 | |
3561 | - foreach ($context['css_header'] as $css) |
|
3562 | - echo $css .' |
|
3764 | + foreach ($context['css_header'] as $css) { |
|
3765 | + echo $css .' |
|
3563 | 3766 | '; |
3767 | + } |
|
3564 | 3768 | |
3565 | 3769 | echo' |
3566 | 3770 | </style>'; |
@@ -3584,15 +3788,17 @@ discard block |
||
3584 | 3788 | $type = !empty($type) && in_array($type, $types) ? $type : false; |
3585 | 3789 | $data = !empty($data) ? $data : false; |
3586 | 3790 | |
3587 | - if (empty($type) || empty($data)) |
|
3588 | - return false; |
|
3791 | + if (empty($type) || empty($data)) { |
|
3792 | + return false; |
|
3793 | + } |
|
3589 | 3794 | |
3590 | 3795 | // Did we already did this? |
3591 | 3796 | $toCache = cache_get_data('minimized_'. $settings['theme_id'] .'_'. $type, 86400); |
3592 | 3797 | |
3593 | 3798 | // Already done? |
3594 | - if (!empty($toCache)) |
|
3595 | - return true; |
|
3799 | + if (!empty($toCache)) { |
|
3800 | + return true; |
|
3801 | + } |
|
3596 | 3802 | |
3597 | 3803 | // No namespaces, sorry! |
3598 | 3804 | $classType = 'MatthiasMullie\\Minify\\'. strtoupper($type); |
@@ -3674,8 +3880,9 @@ discard block |
||
3674 | 3880 | global $modSettings, $smcFunc; |
3675 | 3881 | |
3676 | 3882 | // Just make up a nice hash... |
3677 | - if ($new) |
|
3678 | - return sha1(md5($filename . time()) . mt_rand()); |
|
3883 | + if ($new) { |
|
3884 | + return sha1(md5($filename . time()) . mt_rand()); |
|
3885 | + } |
|
3679 | 3886 | |
3680 | 3887 | // Grab the file hash if it wasn't added. |
3681 | 3888 | // Left this for legacy. |
@@ -3689,23 +3896,25 @@ discard block |
||
3689 | 3896 | 'id_attach' => $attachment_id, |
3690 | 3897 | )); |
3691 | 3898 | |
3692 | - if ($smcFunc['db_num_rows']($request) === 0) |
|
3693 | - return false; |
|
3899 | + if ($smcFunc['db_num_rows']($request) === 0) { |
|
3900 | + return false; |
|
3901 | + } |
|
3694 | 3902 | |
3695 | 3903 | list ($file_hash) = $smcFunc['db_fetch_row']($request); |
3696 | 3904 | $smcFunc['db_free_result']($request); |
3697 | 3905 | } |
3698 | 3906 | |
3699 | 3907 | // Still no hash? mmm... |
3700 | - if (empty($file_hash)) |
|
3701 | - $file_hash = sha1(md5($filename . time()) . mt_rand()); |
|
3908 | + if (empty($file_hash)) { |
|
3909 | + $file_hash = sha1(md5($filename . time()) . mt_rand()); |
|
3910 | + } |
|
3702 | 3911 | |
3703 | 3912 | // Are we using multiple directories? |
3704 | - if (!empty($modSettings['currentAttachmentUploadDir'])) |
|
3705 | - $path = $modSettings['attachmentUploadDir'][$dir]; |
|
3706 | - |
|
3707 | - else |
|
3708 | - $path = $modSettings['attachmentUploadDir']; |
|
3913 | + if (!empty($modSettings['currentAttachmentUploadDir'])) { |
|
3914 | + $path = $modSettings['attachmentUploadDir'][$dir]; |
|
3915 | + } else { |
|
3916 | + $path = $modSettings['attachmentUploadDir']; |
|
3917 | + } |
|
3709 | 3918 | |
3710 | 3919 | return $path . '/' . $attachment_id . '_' . $file_hash .'.dat'; |
3711 | 3920 | } |
@@ -3720,8 +3929,9 @@ discard block |
||
3720 | 3929 | function ip2range($fullip) |
3721 | 3930 | { |
3722 | 3931 | // Pretend that 'unknown' is 255.255.255.255. (since that can't be an IP anyway.) |
3723 | - if ($fullip == 'unknown') |
|
3724 | - $fullip = '255.255.255.255'; |
|
3932 | + if ($fullip == 'unknown') { |
|
3933 | + $fullip = '255.255.255.255'; |
|
3934 | + } |
|
3725 | 3935 | |
3726 | 3936 | $ip_parts = explode('-', $fullip); |
3727 | 3937 | $ip_array = array(); |
@@ -3745,10 +3955,11 @@ discard block |
||
3745 | 3955 | $ip_array['low'] = $ip_parts[0]; |
3746 | 3956 | $ip_array['high'] = $ip_parts[1]; |
3747 | 3957 | return $ip_array; |
3748 | - } |
|
3749 | - elseif (count($ip_parts) == 2) // if ip 22.22.*-22.22.* |
|
3958 | + } elseif (count($ip_parts) == 2) { |
|
3959 | + // if ip 22.22.*-22.22.* |
|
3750 | 3960 | { |
3751 | 3961 | $valid_low = isValidIP($ip_parts[0]); |
3962 | + } |
|
3752 | 3963 | $valid_high = isValidIP($ip_parts[1]); |
3753 | 3964 | $count = 0; |
3754 | 3965 | $mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.'); |
@@ -3763,7 +3974,9 @@ discard block |
||
3763 | 3974 | $ip_parts[0] .= $mode . $min; |
3764 | 3975 | $valid_low = isValidIP($ip_parts[0]); |
3765 | 3976 | $count++; |
3766 | - if ($count > 9) break; |
|
3977 | + if ($count > 9) { |
|
3978 | + break; |
|
3979 | + } |
|
3767 | 3980 | } |
3768 | 3981 | } |
3769 | 3982 | |
@@ -3777,7 +3990,9 @@ discard block |
||
3777 | 3990 | $ip_parts[1] .= $mode . $max; |
3778 | 3991 | $valid_high = isValidIP($ip_parts[1]); |
3779 | 3992 | $count++; |
3780 | - if ($count > 9) break; |
|
3993 | + if ($count > 9) { |
|
3994 | + break; |
|
3995 | + } |
|
3781 | 3996 | } |
3782 | 3997 | } |
3783 | 3998 | |
@@ -3802,46 +4017,54 @@ discard block |
||
3802 | 4017 | { |
3803 | 4018 | global $modSettings; |
3804 | 4019 | |
3805 | - if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) |
|
3806 | - return $host; |
|
4020 | + if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) { |
|
4021 | + return $host; |
|
4022 | + } |
|
3807 | 4023 | $t = microtime(); |
3808 | 4024 | |
3809 | 4025 | // Try the Linux host command, perhaps? |
3810 | 4026 | if (!isset($host) && (strpos(strtolower(PHP_OS), 'win') === false || strpos(strtolower(PHP_OS), 'darwin') !== false) && mt_rand(0, 1) == 1) |
3811 | 4027 | { |
3812 | - if (!isset($modSettings['host_to_dis'])) |
|
3813 | - $test = @shell_exec('host -W 1 ' . @escapeshellarg($ip)); |
|
3814 | - else |
|
3815 | - $test = @shell_exec('host ' . @escapeshellarg($ip)); |
|
4028 | + if (!isset($modSettings['host_to_dis'])) { |
|
4029 | + $test = @shell_exec('host -W 1 ' . @escapeshellarg($ip)); |
|
4030 | + } else { |
|
4031 | + $test = @shell_exec('host ' . @escapeshellarg($ip)); |
|
4032 | + } |
|
3816 | 4033 | |
3817 | 4034 | // Did host say it didn't find anything? |
3818 | - if (strpos($test, 'not found') !== false) |
|
3819 | - $host = ''; |
|
4035 | + if (strpos($test, 'not found') !== false) { |
|
4036 | + $host = ''; |
|
4037 | + } |
|
3820 | 4038 | // Invalid server option? |
3821 | - elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) |
|
3822 | - updateSettings(array('host_to_dis' => 1)); |
|
4039 | + elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) { |
|
4040 | + updateSettings(array('host_to_dis' => 1)); |
|
4041 | + } |
|
3823 | 4042 | // Maybe it found something, after all? |
3824 | - elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) |
|
3825 | - $host = $match[1]; |
|
4043 | + elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) { |
|
4044 | + $host = $match[1]; |
|
4045 | + } |
|
3826 | 4046 | } |
3827 | 4047 | |
3828 | 4048 | // This is nslookup; usually only Windows, but possibly some Unix? |
3829 | 4049 | if (!isset($host) && stripos(PHP_OS, 'win') !== false && strpos(strtolower(PHP_OS), 'darwin') === false && mt_rand(0, 1) == 1) |
3830 | 4050 | { |
3831 | 4051 | $test = @shell_exec('nslookup -timeout=1 ' . @escapeshellarg($ip)); |
3832 | - if (strpos($test, 'Non-existent domain') !== false) |
|
3833 | - $host = ''; |
|
3834 | - elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) |
|
3835 | - $host = $match[1]; |
|
4052 | + if (strpos($test, 'Non-existent domain') !== false) { |
|
4053 | + $host = ''; |
|
4054 | + } elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) { |
|
4055 | + $host = $match[1]; |
|
4056 | + } |
|
3836 | 4057 | } |
3837 | 4058 | |
3838 | 4059 | // This is the last try :/. |
3839 | - if (!isset($host) || $host === false) |
|
3840 | - $host = @gethostbyaddr($ip); |
|
4060 | + if (!isset($host) || $host === false) { |
|
4061 | + $host = @gethostbyaddr($ip); |
|
4062 | + } |
|
3841 | 4063 | |
3842 | 4064 | // It took a long time, so let's cache it! |
3843 | - if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) |
|
3844 | - cache_put_data('hostlookup-' . $ip, $host, 600); |
|
4065 | + if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) { |
|
4066 | + cache_put_data('hostlookup-' . $ip, $host, 600); |
|
4067 | + } |
|
3845 | 4068 | |
3846 | 4069 | return $host; |
3847 | 4070 | } |
@@ -3877,20 +4100,21 @@ discard block |
||
3877 | 4100 | { |
3878 | 4101 | $encrypted = substr(crypt($word, 'uk'), 2, $max_chars); |
3879 | 4102 | $total = 0; |
3880 | - for ($i = 0; $i < $max_chars; $i++) |
|
3881 | - $total += $possible_chars[ord($encrypted{$i})] * pow(63, $i); |
|
4103 | + for ($i = 0; $i < $max_chars; $i++) { |
|
4104 | + $total += $possible_chars[ord($encrypted{$i})] * pow(63, $i); |
|
4105 | + } |
|
3882 | 4106 | $returned_ints[] = $max_chars == 4 ? min($total, 16777215) : $total; |
3883 | 4107 | } |
3884 | 4108 | } |
3885 | 4109 | return array_unique($returned_ints); |
3886 | - } |
|
3887 | - else |
|
4110 | + } else |
|
3888 | 4111 | { |
3889 | 4112 | // Trim characters before and after and add slashes for database insertion. |
3890 | 4113 | $returned_words = array(); |
3891 | - foreach ($words as $word) |
|
3892 | - if (($word = trim($word, '-_\'')) !== '') |
|
4114 | + foreach ($words as $word) { |
|
4115 | + if (($word = trim($word, '-_\'')) !== '') |
|
3893 | 4116 | $returned_words[] = $max_chars === null ? $word : substr($word, 0, $max_chars); |
4117 | + } |
|
3894 | 4118 | |
3895 | 4119 | // Filter out all words that occur more than once. |
3896 | 4120 | return array_unique($returned_words); |
@@ -3912,16 +4136,18 @@ discard block |
||
3912 | 4136 | global $settings, $txt; |
3913 | 4137 | |
3914 | 4138 | // Does the current loaded theme have this and we are not forcing the usage of this function? |
3915 | - if (function_exists('template_create_button') && !$force_use) |
|
3916 | - return template_create_button($name, $alt, $label = '', $custom = ''); |
|
4139 | + if (function_exists('template_create_button') && !$force_use) { |
|
4140 | + return template_create_button($name, $alt, $label = '', $custom = ''); |
|
4141 | + } |
|
3917 | 4142 | |
3918 | - if (!$settings['use_image_buttons']) |
|
3919 | - return $txt[$alt]; |
|
3920 | - elseif (!empty($settings['use_buttons'])) |
|
3921 | - return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? ' <strong>' . $txt[$label] . '</strong>' : ''); |
|
3922 | - else |
|
3923 | - return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>'; |
|
3924 | -} |
|
4143 | + if (!$settings['use_image_buttons']) { |
|
4144 | + return $txt[$alt]; |
|
4145 | + } elseif (!empty($settings['use_buttons'])) { |
|
4146 | + return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? ' <strong>' . $txt[$label] . '</strong>' : ''); |
|
4147 | + } else { |
|
4148 | + return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>'; |
|
4149 | + } |
|
4150 | + } |
|
3925 | 4151 | |
3926 | 4152 | /** |
3927 | 4153 | * Sets up all of the top menu buttons |
@@ -3964,9 +4190,10 @@ discard block |
||
3964 | 4190 | var user_menus = new smc_PopupMenu(); |
3965 | 4191 | user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup"); |
3966 | 4192 | user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true); |
3967 | - if ($context['allow_pm']) |
|
3968 | - addInlineJavaScript(' |
|
4193 | + if ($context['allow_pm']) { |
|
4194 | + addInlineJavaScript(' |
|
3969 | 4195 | user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true); |
4196 | + } |
|
3970 | 4197 | |
3971 | 4198 | if (!empty($modSettings['enable_ajax_alerts'])) |
3972 | 4199 | { |
@@ -4126,88 +4353,96 @@ discard block |
||
4126 | 4353 | |
4127 | 4354 | // Now we put the buttons in the context so the theme can use them. |
4128 | 4355 | $menu_buttons = array(); |
4129 | - foreach ($buttons as $act => $button) |
|
4130 | - if (!empty($button['show'])) |
|
4356 | + foreach ($buttons as $act => $button) { |
|
4357 | + if (!empty($button['show'])) |
|
4131 | 4358 | { |
4132 | 4359 | $button['active_button'] = false; |
4360 | + } |
|
4133 | 4361 | |
4134 | 4362 | // This button needs some action. |
4135 | - if (isset($button['action_hook'])) |
|
4136 | - $needs_action_hook = true; |
|
4363 | + if (isset($button['action_hook'])) { |
|
4364 | + $needs_action_hook = true; |
|
4365 | + } |
|
4137 | 4366 | |
4138 | 4367 | // Make sure the last button truly is the last button. |
4139 | 4368 | if (!empty($button['is_last'])) |
4140 | 4369 | { |
4141 | - if (isset($last_button)) |
|
4142 | - unset($menu_buttons[$last_button]['is_last']); |
|
4370 | + if (isset($last_button)) { |
|
4371 | + unset($menu_buttons[$last_button]['is_last']); |
|
4372 | + } |
|
4143 | 4373 | $last_button = $act; |
4144 | 4374 | } |
4145 | 4375 | |
4146 | 4376 | // Go through the sub buttons if there are any. |
4147 | - if (!empty($button['sub_buttons'])) |
|
4148 | - foreach ($button['sub_buttons'] as $key => $subbutton) |
|
4377 | + if (!empty($button['sub_buttons'])) { |
|
4378 | + foreach ($button['sub_buttons'] as $key => $subbutton) |
|
4149 | 4379 | { |
4150 | 4380 | if (empty($subbutton['show'])) |
4151 | 4381 | unset($button['sub_buttons'][$key]); |
4382 | + } |
|
4152 | 4383 | |
4153 | 4384 | // 2nd level sub buttons next... |
4154 | 4385 | if (!empty($subbutton['sub_buttons'])) |
4155 | 4386 | { |
4156 | 4387 | foreach ($subbutton['sub_buttons'] as $key2 => $sub_button2) |
4157 | 4388 | { |
4158 | - if (empty($sub_button2['show'])) |
|
4159 | - unset($button['sub_buttons'][$key]['sub_buttons'][$key2]); |
|
4389 | + if (empty($sub_button2['show'])) { |
|
4390 | + unset($button['sub_buttons'][$key]['sub_buttons'][$key2]); |
|
4391 | + } |
|
4160 | 4392 | } |
4161 | 4393 | } |
4162 | 4394 | } |
4163 | 4395 | |
4164 | 4396 | // Does this button have its own icon? |
4165 | - if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) |
|
4166 | - $button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
4167 | - elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) |
|
4168 | - $button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
4169 | - elseif (isset($button['icon'])) |
|
4170 | - $button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>'; |
|
4171 | - else |
|
4172 | - $button['icon'] = '<span class="generic_icons ' . $act . '"></span>'; |
|
4397 | + if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) { |
|
4398 | + $button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
4399 | + } elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) { |
|
4400 | + $button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
4401 | + } elseif (isset($button['icon'])) { |
|
4402 | + $button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>'; |
|
4403 | + } else { |
|
4404 | + $button['icon'] = '<span class="generic_icons ' . $act . '"></span>'; |
|
4405 | + } |
|
4173 | 4406 | |
4174 | 4407 | $menu_buttons[$act] = $button; |
4175 | 4408 | } |
4176 | 4409 | |
4177 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
4178 | - cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime); |
|
4410 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
4411 | + cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime); |
|
4412 | + } |
|
4179 | 4413 | } |
4180 | 4414 | |
4181 | 4415 | $context['menu_buttons'] = $menu_buttons; |
4182 | 4416 | |
4183 | 4417 | // Logging out requires the session id in the url. |
4184 | - if (isset($context['menu_buttons']['logout'])) |
|
4185 | - $context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']); |
|
4418 | + if (isset($context['menu_buttons']['logout'])) { |
|
4419 | + $context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']); |
|
4420 | + } |
|
4186 | 4421 | |
4187 | 4422 | // Figure out which action we are doing so we can set the active tab. |
4188 | 4423 | // Default to home. |
4189 | 4424 | $current_action = 'home'; |
4190 | 4425 | |
4191 | - if (isset($context['menu_buttons'][$context['current_action']])) |
|
4192 | - $current_action = $context['current_action']; |
|
4193 | - elseif ($context['current_action'] == 'search2') |
|
4194 | - $current_action = 'search'; |
|
4195 | - elseif ($context['current_action'] == 'theme') |
|
4196 | - $current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin'; |
|
4197 | - elseif ($context['current_action'] == 'register2') |
|
4198 | - $current_action = 'register'; |
|
4199 | - elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) |
|
4200 | - $current_action = 'login'; |
|
4201 | - elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) |
|
4202 | - $current_action = 'moderate'; |
|
4426 | + if (isset($context['menu_buttons'][$context['current_action']])) { |
|
4427 | + $current_action = $context['current_action']; |
|
4428 | + } elseif ($context['current_action'] == 'search2') { |
|
4429 | + $current_action = 'search'; |
|
4430 | + } elseif ($context['current_action'] == 'theme') { |
|
4431 | + $current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin'; |
|
4432 | + } elseif ($context['current_action'] == 'register2') { |
|
4433 | + $current_action = 'register'; |
|
4434 | + } elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) { |
|
4435 | + $current_action = 'login'; |
|
4436 | + } elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) { |
|
4437 | + $current_action = 'moderate'; |
|
4438 | + } |
|
4203 | 4439 | |
4204 | 4440 | // There are certain exceptions to the above where we don't want anything on the menu highlighted. |
4205 | 4441 | if ($context['current_action'] == 'profile' && !empty($context['user']['is_owner'])) |
4206 | 4442 | { |
4207 | 4443 | $current_action = !empty($_GET['area']) && $_GET['area'] == 'showalerts' ? 'self_alerts' : 'self_profile'; |
4208 | 4444 | $context[$current_action] = true; |
4209 | - } |
|
4210 | - elseif ($context['current_action'] == 'pm') |
|
4445 | + } elseif ($context['current_action'] == 'pm') |
|
4211 | 4446 | { |
4212 | 4447 | $current_action = 'self_pm'; |
4213 | 4448 | $context['self_pm'] = true; |
@@ -4250,12 +4485,14 @@ discard block |
||
4250 | 4485 | } |
4251 | 4486 | |
4252 | 4487 | // Not all actions are simple. |
4253 | - if (!empty($needs_action_hook)) |
|
4254 | - call_integration_hook('integrate_current_action', array(&$current_action)); |
|
4488 | + if (!empty($needs_action_hook)) { |
|
4489 | + call_integration_hook('integrate_current_action', array(&$current_action)); |
|
4490 | + } |
|
4255 | 4491 | |
4256 | - if (isset($context['menu_buttons'][$current_action])) |
|
4257 | - $context['menu_buttons'][$current_action]['active_button'] = true; |
|
4258 | -} |
|
4492 | + if (isset($context['menu_buttons'][$current_action])) { |
|
4493 | + $context['menu_buttons'][$current_action]['active_button'] = true; |
|
4494 | + } |
|
4495 | + } |
|
4259 | 4496 | |
4260 | 4497 | /** |
4261 | 4498 | * Generate a random seed and ensure it's stored in settings. |
@@ -4279,16 +4516,19 @@ discard block |
||
4279 | 4516 | global $modSettings, $settings, $boarddir, $sourcedir, $db_show_debug; |
4280 | 4517 | global $context, $txt; |
4281 | 4518 | |
4282 | - if ($db_show_debug === true) |
|
4283 | - $context['debug']['hooks'][] = $hook; |
|
4519 | + if ($db_show_debug === true) { |
|
4520 | + $context['debug']['hooks'][] = $hook; |
|
4521 | + } |
|
4284 | 4522 | |
4285 | 4523 | // Need to have some control. |
4286 | - if (!isset($context['instances'])) |
|
4287 | - $context['instances'] = array(); |
|
4524 | + if (!isset($context['instances'])) { |
|
4525 | + $context['instances'] = array(); |
|
4526 | + } |
|
4288 | 4527 | |
4289 | 4528 | $results = array(); |
4290 | - if (empty($modSettings[$hook])) |
|
4291 | - return $results; |
|
4529 | + if (empty($modSettings[$hook])) { |
|
4530 | + return $results; |
|
4531 | + } |
|
4292 | 4532 | |
4293 | 4533 | // Define some needed vars. |
4294 | 4534 | $function = false; |
@@ -4298,14 +4538,16 @@ discard block |
||
4298 | 4538 | foreach ($functions as $function) |
4299 | 4539 | { |
4300 | 4540 | // Hook has been marked as "disabled". Skip it! |
4301 | - if (strpos($function, '!') !== false) |
|
4302 | - continue; |
|
4541 | + if (strpos($function, '!') !== false) { |
|
4542 | + continue; |
|
4543 | + } |
|
4303 | 4544 | |
4304 | 4545 | $call = call_helper($function, true); |
4305 | 4546 | |
4306 | 4547 | // Is it valid? |
4307 | - if (!empty($call)) |
|
4308 | - $results[$function] = call_user_func_array($call, $parameters); |
|
4548 | + if (!empty($call)) { |
|
4549 | + $results[$function] = call_user_func_array($call, $parameters); |
|
4550 | + } |
|
4309 | 4551 | |
4310 | 4552 | // Whatever it was suppose to call, it failed :( |
4311 | 4553 | elseif (!empty($function)) |
@@ -4321,8 +4563,9 @@ discard block |
||
4321 | 4563 | } |
4322 | 4564 | |
4323 | 4565 | // "Assume" the file resides on $boarddir somewhere... |
4324 | - else |
|
4325 | - log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general'); |
|
4566 | + else { |
|
4567 | + log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general'); |
|
4568 | + } |
|
4326 | 4569 | } |
4327 | 4570 | } |
4328 | 4571 | |
@@ -4344,12 +4587,14 @@ discard block |
||
4344 | 4587 | global $smcFunc, $modSettings; |
4345 | 4588 | |
4346 | 4589 | // Any objects? |
4347 | - if ($object) |
|
4348 | - $function = $function . '#'; |
|
4590 | + if ($object) { |
|
4591 | + $function = $function . '#'; |
|
4592 | + } |
|
4349 | 4593 | |
4350 | 4594 | // Any files to load? |
4351 | - if (!empty($file) && is_string($file)) |
|
4352 | - $function = $file . (!empty($function) ? '|' . $function : ''); |
|
4595 | + if (!empty($file) && is_string($file)) { |
|
4596 | + $function = $file . (!empty($function) ? '|' . $function : ''); |
|
4597 | + } |
|
4353 | 4598 | |
4354 | 4599 | // Get the correct string. |
4355 | 4600 | $integration_call = $function; |
@@ -4371,13 +4616,14 @@ discard block |
||
4371 | 4616 | if (!empty($current_functions)) |
4372 | 4617 | { |
4373 | 4618 | $current_functions = explode(',', $current_functions); |
4374 | - if (in_array($integration_call, $current_functions)) |
|
4375 | - return; |
|
4619 | + if (in_array($integration_call, $current_functions)) { |
|
4620 | + return; |
|
4621 | + } |
|
4376 | 4622 | |
4377 | 4623 | $permanent_functions = array_merge($current_functions, array($integration_call)); |
4624 | + } else { |
|
4625 | + $permanent_functions = array($integration_call); |
|
4378 | 4626 | } |
4379 | - else |
|
4380 | - $permanent_functions = array($integration_call); |
|
4381 | 4627 | |
4382 | 4628 | updateSettings(array($hook => implode(',', $permanent_functions))); |
4383 | 4629 | } |
@@ -4386,8 +4632,9 @@ discard block |
||
4386 | 4632 | $functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]); |
4387 | 4633 | |
4388 | 4634 | // Do nothing, if it's already there. |
4389 | - if (in_array($integration_call, $functions)) |
|
4390 | - return; |
|
4635 | + if (in_array($integration_call, $functions)) { |
|
4636 | + return; |
|
4637 | + } |
|
4391 | 4638 | |
4392 | 4639 | $functions[] = $integration_call; |
4393 | 4640 | $modSettings[$hook] = implode(',', $functions); |
@@ -4410,12 +4657,14 @@ discard block |
||
4410 | 4657 | global $smcFunc, $modSettings; |
4411 | 4658 | |
4412 | 4659 | // Any objects? |
4413 | - if ($object) |
|
4414 | - $function = $function . '#'; |
|
4660 | + if ($object) { |
|
4661 | + $function = $function . '#'; |
|
4662 | + } |
|
4415 | 4663 | |
4416 | 4664 | // Any files to load? |
4417 | - if (!empty($file) && is_string($file)) |
|
4418 | - $function = $file . '|' . $function; |
|
4665 | + if (!empty($file) && is_string($file)) { |
|
4666 | + $function = $file . '|' . $function; |
|
4667 | + } |
|
4419 | 4668 | |
4420 | 4669 | // Get the correct string. |
4421 | 4670 | $integration_call = $function; |
@@ -4436,16 +4685,18 @@ discard block |
||
4436 | 4685 | { |
4437 | 4686 | $current_functions = explode(',', $current_functions); |
4438 | 4687 | |
4439 | - if (in_array($integration_call, $current_functions)) |
|
4440 | - updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call))))); |
|
4688 | + if (in_array($integration_call, $current_functions)) { |
|
4689 | + updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call))))); |
|
4690 | + } |
|
4441 | 4691 | } |
4442 | 4692 | |
4443 | 4693 | // Turn the function list into something usable. |
4444 | 4694 | $functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]); |
4445 | 4695 | |
4446 | 4696 | // You can only remove it if it's available. |
4447 | - if (!in_array($integration_call, $functions)) |
|
4448 | - return; |
|
4697 | + if (!in_array($integration_call, $functions)) { |
|
4698 | + return; |
|
4699 | + } |
|
4449 | 4700 | |
4450 | 4701 | $functions = array_diff($functions, array($integration_call)); |
4451 | 4702 | $modSettings[$hook] = implode(',', $functions); |
@@ -4466,17 +4717,20 @@ discard block |
||
4466 | 4717 | global $context, $smcFunc, $txt, $db_show_debug; |
4467 | 4718 | |
4468 | 4719 | // Really? |
4469 | - if (empty($string)) |
|
4470 | - return false; |
|
4720 | + if (empty($string)) { |
|
4721 | + return false; |
|
4722 | + } |
|
4471 | 4723 | |
4472 | 4724 | // An array? should be a "callable" array IE array(object/class, valid_callable). |
4473 | 4725 | // A closure? should be a callable one. |
4474 | - if (is_array($string) || $string instanceof Closure) |
|
4475 | - return $return ? $string : (is_callable($string) ? call_user_func($string) : false); |
|
4726 | + if (is_array($string) || $string instanceof Closure) { |
|
4727 | + return $return ? $string : (is_callable($string) ? call_user_func($string) : false); |
|
4728 | + } |
|
4476 | 4729 | |
4477 | 4730 | // No full objects, sorry! pass a method or a property instead! |
4478 | - if (is_object($string)) |
|
4479 | - return false; |
|
4731 | + if (is_object($string)) { |
|
4732 | + return false; |
|
4733 | + } |
|
4480 | 4734 | |
4481 | 4735 | // Stay vitaminized my friends... |
4482 | 4736 | $string = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($string)); |
@@ -4485,8 +4739,9 @@ discard block |
||
4485 | 4739 | $string = load_file($string); |
4486 | 4740 | |
4487 | 4741 | // Loaded file failed |
4488 | - if (empty($string)) |
|
4489 | - return false; |
|
4742 | + if (empty($string)) { |
|
4743 | + return false; |
|
4744 | + } |
|
4490 | 4745 | |
4491 | 4746 | // Found a method. |
4492 | 4747 | if (strpos($string, '::') !== false) |
@@ -4507,8 +4762,9 @@ discard block |
||
4507 | 4762 | // Add another one to the list. |
4508 | 4763 | if ($db_show_debug === true) |
4509 | 4764 | { |
4510 | - if (!isset($context['debug']['instances'])) |
|
4511 | - $context['debug']['instances'] = array(); |
|
4765 | + if (!isset($context['debug']['instances'])) { |
|
4766 | + $context['debug']['instances'] = array(); |
|
4767 | + } |
|
4512 | 4768 | |
4513 | 4769 | $context['debug']['instances'][$class] = $class; |
4514 | 4770 | } |
@@ -4518,13 +4774,15 @@ discard block |
||
4518 | 4774 | } |
4519 | 4775 | |
4520 | 4776 | // Right then. This is a call to a static method. |
4521 | - else |
|
4522 | - $func = array($class, $method); |
|
4777 | + else { |
|
4778 | + $func = array($class, $method); |
|
4779 | + } |
|
4523 | 4780 | } |
4524 | 4781 | |
4525 | 4782 | // Nope! just a plain regular function. |
4526 | - else |
|
4527 | - $func = $string; |
|
4783 | + else { |
|
4784 | + $func = $string; |
|
4785 | + } |
|
4528 | 4786 | |
4529 | 4787 | // Right, we got what we need, time to do some checks. |
4530 | 4788 | if (!is_callable($func, false, $callable_name)) |
@@ -4540,17 +4798,18 @@ discard block |
||
4540 | 4798 | else |
4541 | 4799 | { |
4542 | 4800 | // What are we gonna do about it? |
4543 | - if ($return) |
|
4544 | - return $func; |
|
4801 | + if ($return) { |
|
4802 | + return $func; |
|
4803 | + } |
|
4545 | 4804 | |
4546 | 4805 | // If this is a plain function, avoid the heat of calling call_user_func(). |
4547 | 4806 | else |
4548 | 4807 | { |
4549 | - if (is_array($func)) |
|
4550 | - call_user_func($func); |
|
4551 | - |
|
4552 | - else |
|
4553 | - $func(); |
|
4808 | + if (is_array($func)) { |
|
4809 | + call_user_func($func); |
|
4810 | + } else { |
|
4811 | + $func(); |
|
4812 | + } |
|
4554 | 4813 | } |
4555 | 4814 | } |
4556 | 4815 | } |
@@ -4567,31 +4826,34 @@ discard block |
||
4567 | 4826 | { |
4568 | 4827 | global $sourcedir, $txt, $boarddir, $settings; |
4569 | 4828 | |
4570 | - if (empty($string)) |
|
4571 | - return false; |
|
4829 | + if (empty($string)) { |
|
4830 | + return false; |
|
4831 | + } |
|
4572 | 4832 | |
4573 | 4833 | if (strpos($string, '|') !== false) |
4574 | 4834 | { |
4575 | 4835 | list ($file, $string) = explode('|', $string); |
4576 | 4836 | |
4577 | 4837 | // Match the wildcards to their regular vars. |
4578 | - if (empty($settings['theme_dir'])) |
|
4579 | - $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
|
4580 | - |
|
4581 | - else |
|
4582 | - $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
|
4838 | + if (empty($settings['theme_dir'])) { |
|
4839 | + $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
|
4840 | + } else { |
|
4841 | + $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
|
4842 | + } |
|
4583 | 4843 | |
4584 | 4844 | // Load the file if it can be loaded. |
4585 | - if (file_exists($absPath)) |
|
4586 | - require_once($absPath); |
|
4845 | + if (file_exists($absPath)) { |
|
4846 | + require_once($absPath); |
|
4847 | + } |
|
4587 | 4848 | |
4588 | 4849 | // No? try a fallback to $sourcedir |
4589 | 4850 | else |
4590 | 4851 | { |
4591 | 4852 | $absPath = $sourcedir .'/'. $file; |
4592 | 4853 | |
4593 | - if (file_exists($absPath)) |
|
4594 | - require_once($absPath); |
|
4854 | + if (file_exists($absPath)) { |
|
4855 | + require_once($absPath); |
|
4856 | + } |
|
4595 | 4857 | |
4596 | 4858 | // Sorry, can't do much for you at this point. |
4597 | 4859 | else |
@@ -4618,8 +4880,9 @@ discard block |
||
4618 | 4880 | global $user_info, $smcFunc; |
4619 | 4881 | |
4620 | 4882 | // Make sure we have something to work with. |
4621 | - if (empty($topic)) |
|
4622 | - return array(); |
|
4883 | + if (empty($topic)) { |
|
4884 | + return array(); |
|
4885 | + } |
|
4623 | 4886 | |
4624 | 4887 | |
4625 | 4888 | // We already know the number of likes per message, we just want to know whether the current user liked it or not. |
@@ -4642,8 +4905,9 @@ discard block |
||
4642 | 4905 | 'topic' => $topic, |
4643 | 4906 | ) |
4644 | 4907 | ); |
4645 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
4646 | - $temp[] = (int) $row['content_id']; |
|
4908 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
4909 | + $temp[] = (int) $row['content_id']; |
|
4910 | + } |
|
4647 | 4911 | |
4648 | 4912 | cache_put_data($cache_key, $temp, $ttl); |
4649 | 4913 | } |
@@ -4664,8 +4928,9 @@ discard block |
||
4664 | 4928 | { |
4665 | 4929 | global $context; |
4666 | 4930 | |
4667 | - if (empty($string)) |
|
4668 | - return $string; |
|
4931 | + if (empty($string)) { |
|
4932 | + return $string; |
|
4933 | + } |
|
4669 | 4934 | |
4670 | 4935 | // UTF-8 occurences of MS special characters |
4671 | 4936 | $findchars_utf8 = array( |
@@ -4706,10 +4971,11 @@ discard block |
||
4706 | 4971 | '--', // — |
4707 | 4972 | ); |
4708 | 4973 | |
4709 | - if ($context['utf8']) |
|
4710 | - $string = str_replace($findchars_utf8, $replacechars, $string); |
|
4711 | - else |
|
4712 | - $string = str_replace($findchars_iso, $replacechars, $string); |
|
4974 | + if ($context['utf8']) { |
|
4975 | + $string = str_replace($findchars_utf8, $replacechars, $string); |
|
4976 | + } else { |
|
4977 | + $string = str_replace($findchars_iso, $replacechars, $string); |
|
4978 | + } |
|
4713 | 4979 | |
4714 | 4980 | return $string; |
4715 | 4981 | } |
@@ -4728,49 +4994,59 @@ discard block |
||
4728 | 4994 | { |
4729 | 4995 | global $context; |
4730 | 4996 | |
4731 | - if (!isset($matches[2])) |
|
4732 | - return ''; |
|
4997 | + if (!isset($matches[2])) { |
|
4998 | + return ''; |
|
4999 | + } |
|
4733 | 5000 | |
4734 | 5001 | $num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2]; |
4735 | 5002 | |
4736 | 5003 | // remove left to right / right to left overrides |
4737 | - if ($num === 0x202D || $num === 0x202E) |
|
4738 | - return ''; |
|
5004 | + if ($num === 0x202D || $num === 0x202E) { |
|
5005 | + return ''; |
|
5006 | + } |
|
4739 | 5007 | |
4740 | 5008 | // Quote, Ampersand, Apostrophe, Less/Greater Than get html replaced |
4741 | - if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) |
|
4742 | - return '&#' . $num . ';'; |
|
5009 | + if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) { |
|
5010 | + return '&#' . $num . ';'; |
|
5011 | + } |
|
4743 | 5012 | |
4744 | 5013 | if (empty($context['utf8'])) |
4745 | 5014 | { |
4746 | 5015 | // no control characters |
4747 | - if ($num < 0x20) |
|
4748 | - return ''; |
|
5016 | + if ($num < 0x20) { |
|
5017 | + return ''; |
|
5018 | + } |
|
4749 | 5019 | // text is text |
4750 | - elseif ($num < 0x80) |
|
4751 | - return chr($num); |
|
5020 | + elseif ($num < 0x80) { |
|
5021 | + return chr($num); |
|
5022 | + } |
|
4752 | 5023 | // all others get html-ised |
4753 | - else |
|
4754 | - return '&#' . $matches[2] . ';'; |
|
4755 | - } |
|
4756 | - else |
|
5024 | + else { |
|
5025 | + return '&#' . $matches[2] . ';'; |
|
5026 | + } |
|
5027 | + } else |
|
4757 | 5028 | { |
4758 | 5029 | // <0x20 are control characters, 0x20 is a space, > 0x10FFFF is past the end of the utf8 character set |
4759 | 5030 | // 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text) |
4760 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) |
|
4761 | - return ''; |
|
5031 | + if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) { |
|
5032 | + return ''; |
|
5033 | + } |
|
4762 | 5034 | // <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation |
4763 | - elseif ($num < 0x80) |
|
4764 | - return chr($num); |
|
5035 | + elseif ($num < 0x80) { |
|
5036 | + return chr($num); |
|
5037 | + } |
|
4765 | 5038 | // <0x800 (2048) |
4766 | - elseif ($num < 0x800) |
|
4767 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
5039 | + elseif ($num < 0x800) { |
|
5040 | + return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
5041 | + } |
|
4768 | 5042 | // < 0x10000 (65536) |
4769 | - elseif ($num < 0x10000) |
|
4770 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5043 | + elseif ($num < 0x10000) { |
|
5044 | + return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5045 | + } |
|
4771 | 5046 | // <= 0x10FFFF (1114111) |
4772 | - else |
|
4773 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5047 | + else { |
|
5048 | + return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5049 | + } |
|
4774 | 5050 | } |
4775 | 5051 | } |
4776 | 5052 | |
@@ -4786,28 +5062,34 @@ discard block |
||
4786 | 5062 | */ |
4787 | 5063 | function fixchar__callback($matches) |
4788 | 5064 | { |
4789 | - if (!isset($matches[1])) |
|
4790 | - return ''; |
|
5065 | + if (!isset($matches[1])) { |
|
5066 | + return ''; |
|
5067 | + } |
|
4791 | 5068 | |
4792 | 5069 | $num = $matches[1][0] === 'x' ? hexdec(substr($matches[1], 1)) : (int) $matches[1]; |
4793 | 5070 | |
4794 | 5071 | // <0x20 are control characters, > 0x10FFFF is past the end of the utf8 character set |
4795 | 5072 | // 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text), 0x202D-E are left to right overrides |
4796 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) |
|
4797 | - return ''; |
|
5073 | + if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) { |
|
5074 | + return ''; |
|
5075 | + } |
|
4798 | 5076 | // <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation |
4799 | - elseif ($num < 0x80) |
|
4800 | - return chr($num); |
|
5077 | + elseif ($num < 0x80) { |
|
5078 | + return chr($num); |
|
5079 | + } |
|
4801 | 5080 | // <0x800 (2048) |
4802 | - elseif ($num < 0x800) |
|
4803 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
5081 | + elseif ($num < 0x800) { |
|
5082 | + return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
5083 | + } |
|
4804 | 5084 | // < 0x10000 (65536) |
4805 | - elseif ($num < 0x10000) |
|
4806 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5085 | + elseif ($num < 0x10000) { |
|
5086 | + return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5087 | + } |
|
4807 | 5088 | // <= 0x10FFFF (1114111) |
4808 | - else |
|
4809 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
4810 | -} |
|
5089 | + else { |
|
5090 | + return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5091 | + } |
|
5092 | + } |
|
4811 | 5093 | |
4812 | 5094 | /** |
4813 | 5095 | * Strips out invalid html entities, replaces others with html style { codes |
@@ -4820,17 +5102,19 @@ discard block |
||
4820 | 5102 | */ |
4821 | 5103 | function entity_fix__callback($matches) |
4822 | 5104 | { |
4823 | - if (!isset($matches[2])) |
|
4824 | - return ''; |
|
5105 | + if (!isset($matches[2])) { |
|
5106 | + return ''; |
|
5107 | + } |
|
4825 | 5108 | |
4826 | 5109 | $num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2]; |
4827 | 5110 | |
4828 | 5111 | // we don't allow control characters, characters out of range, byte markers, etc |
4829 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) |
|
4830 | - return ''; |
|
4831 | - else |
|
4832 | - return '&#' . $num . ';'; |
|
4833 | -} |
|
5112 | + if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) { |
|
5113 | + return ''; |
|
5114 | + } else { |
|
5115 | + return '&#' . $num . ';'; |
|
5116 | + } |
|
5117 | + } |
|
4834 | 5118 | |
4835 | 5119 | /** |
4836 | 5120 | * Return a Gravatar URL based on |
@@ -4854,18 +5138,23 @@ discard block |
||
4854 | 5138 | $ratings = array('G', 'PG', 'R', 'X'); |
4855 | 5139 | $defaults = array('mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank'); |
4856 | 5140 | $url_params = array(); |
4857 | - if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) |
|
4858 | - $url_params[] = 'rating=' . $modSettings['gravatarMaxRating']; |
|
4859 | - if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) |
|
4860 | - $url_params[] = 'default=' . $modSettings['gravatarDefault']; |
|
4861 | - if (!empty($modSettings['avatar_max_width_external'])) |
|
4862 | - $size_string = (int) $modSettings['avatar_max_width_external']; |
|
4863 | - if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) |
|
4864 | - if ((int) $modSettings['avatar_max_height_external'] < $size_string) |
|
5141 | + if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) { |
|
5142 | + $url_params[] = 'rating=' . $modSettings['gravatarMaxRating']; |
|
5143 | + } |
|
5144 | + if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) { |
|
5145 | + $url_params[] = 'default=' . $modSettings['gravatarDefault']; |
|
5146 | + } |
|
5147 | + if (!empty($modSettings['avatar_max_width_external'])) { |
|
5148 | + $size_string = (int) $modSettings['avatar_max_width_external']; |
|
5149 | + } |
|
5150 | + if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) { |
|
5151 | + if ((int) $modSettings['avatar_max_height_external'] < $size_string) |
|
4865 | 5152 | $size_string = $modSettings['avatar_max_height_external']; |
5153 | + } |
|
4866 | 5154 | |
4867 | - if (!empty($size_string)) |
|
4868 | - $url_params[] = 's=' . $size_string; |
|
5155 | + if (!empty($size_string)) { |
|
5156 | + $url_params[] = 's=' . $size_string; |
|
5157 | + } |
|
4869 | 5158 | } |
4870 | 5159 | $http_method = !empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 ? 'https://secure' : 'http://www'; |
4871 | 5160 | |
@@ -4884,22 +5173,26 @@ discard block |
||
4884 | 5173 | static $timezones = null, $lastwhen = null; |
4885 | 5174 | |
4886 | 5175 | // No point doing this over if we already did it once |
4887 | - if (!empty($timezones) && $when == $lastwhen) |
|
4888 | - return $timezones; |
|
4889 | - else |
|
4890 | - $lastwhen = $when; |
|
5176 | + if (!empty($timezones) && $when == $lastwhen) { |
|
5177 | + return $timezones; |
|
5178 | + } else { |
|
5179 | + $lastwhen = $when; |
|
5180 | + } |
|
4891 | 5181 | |
4892 | 5182 | // Parseable datetime string? |
4893 | - if (is_int($timestamp = strtotime($when))) |
|
4894 | - $when = $timestamp; |
|
5183 | + if (is_int($timestamp = strtotime($when))) { |
|
5184 | + $when = $timestamp; |
|
5185 | + } |
|
4895 | 5186 | |
4896 | 5187 | // A Unix timestamp? |
4897 | - elseif (is_numeric($when)) |
|
4898 | - $when = intval($when); |
|
5188 | + elseif (is_numeric($when)) { |
|
5189 | + $when = intval($when); |
|
5190 | + } |
|
4899 | 5191 | |
4900 | 5192 | // Invalid value? Just get current Unix timestamp. |
4901 | - else |
|
4902 | - $when = time(); |
|
5193 | + else { |
|
5194 | + $when = time(); |
|
5195 | + } |
|
4903 | 5196 | |
4904 | 5197 | // We'll need this too |
4905 | 5198 | $later = (int) date_format(date_add(date_create('@' . $when), date_interval_create_from_date_string('1 year')), 'U'); |
@@ -4962,8 +5255,9 @@ discard block |
||
4962 | 5255 | foreach ($priority_countries as $country) |
4963 | 5256 | { |
4964 | 5257 | $country_tzids = @timezone_identifiers_list(DateTimeZone::PER_COUNTRY, strtoupper(trim($country))); |
4965 | - if (!empty($country_tzids)) |
|
4966 | - $priority_tzids = array_merge($priority_tzids, $country_tzids); |
|
5258 | + if (!empty($country_tzids)) { |
|
5259 | + $priority_tzids = array_merge($priority_tzids, $country_tzids); |
|
5260 | + } |
|
4967 | 5261 | } |
4968 | 5262 | |
4969 | 5263 | // Process the preferred timezones first, then the rest. |
@@ -4973,8 +5267,9 @@ discard block |
||
4973 | 5267 | foreach ($tzids as $tzid) |
4974 | 5268 | { |
4975 | 5269 | // We don't want UTC right now |
4976 | - if ($tzid == 'UTC') |
|
4977 | - continue; |
|
5270 | + if ($tzid == 'UTC') { |
|
5271 | + continue; |
|
5272 | + } |
|
4978 | 5273 | |
4979 | 5274 | // First, get the set of transition rules for this tzid |
4980 | 5275 | $tzinfo = timezone_transitions_get(timezone_open($tzid), $when, $later); |
@@ -4985,8 +5280,9 @@ discard block |
||
4985 | 5280 | $tz_location = timezone_location_get(timezone_open($tzid)); |
4986 | 5281 | |
4987 | 5282 | // Kazakstan |
4988 | - if ($tz_location['country_code'] == 'KZ') |
|
4989 | - $tzinfo[0]['abbr'] = str_replace(array('+05', '+06'), array('AQTT', 'ALMT'), $tzinfo[0]['abbr']); |
|
5283 | + if ($tz_location['country_code'] == 'KZ') { |
|
5284 | + $tzinfo[0]['abbr'] = str_replace(array('+05', '+06'), array('AQTT', 'ALMT'), $tzinfo[0]['abbr']); |
|
5285 | + } |
|
4990 | 5286 | |
4991 | 5287 | // Russia likes to experiment with time zones |
4992 | 5288 | if ($tz_location['country_code'] == 'RU') |
@@ -4997,19 +5293,22 @@ discard block |
||
4997 | 5293 | } |
4998 | 5294 | |
4999 | 5295 | // Still no good? We'll just mark it as a UTC offset |
5000 | - if (strspn($tzinfo[0]['abbr'], '+-') > 0) |
|
5001 | - $tzinfo[0]['abbr'] = 'UTC' . $tzinfo[0]['abbr']; |
|
5296 | + if (strspn($tzinfo[0]['abbr'], '+-') > 0) { |
|
5297 | + $tzinfo[0]['abbr'] = 'UTC' . $tzinfo[0]['abbr']; |
|
5298 | + } |
|
5002 | 5299 | } |
5003 | 5300 | |
5004 | 5301 | $tzkey = serialize($tzinfo); |
5005 | 5302 | |
5006 | 5303 | // Don't overwrite our preferred tzids |
5007 | - if (empty($zones[$tzkey]['tzid'])) |
|
5008 | - $zones[$tzkey]['tzid'] = $tzid; |
|
5304 | + if (empty($zones[$tzkey]['tzid'])) { |
|
5305 | + $zones[$tzkey]['tzid'] = $tzid; |
|
5306 | + } |
|
5009 | 5307 | |
5010 | 5308 | // A time zone from a prioritized country? |
5011 | - if (in_array($tzid, $priority_tzids)) |
|
5012 | - $priority_zones[$tzkey] = true; |
|
5309 | + if (in_array($tzid, $priority_tzids)) { |
|
5310 | + $priority_zones[$tzkey] = true; |
|
5311 | + } |
|
5013 | 5312 | |
5014 | 5313 | // Keep track of the location and offset for this tzid |
5015 | 5314 | $tzid_parts = explode('/', $tzid); |
@@ -5027,15 +5326,17 @@ discard block |
||
5027 | 5326 | { |
5028 | 5327 | $tzinfo = unserialize($tzkey); |
5029 | 5328 | |
5030 | - if (!empty($timezone_descriptions[$tzvalue['tzid']])) |
|
5031 | - $desc = $timezone_descriptions[$tzvalue['tzid']]; |
|
5032 | - else |
|
5033 | - $desc = implode(', ', array_unique($tzvalue['locations'])); |
|
5329 | + if (!empty($timezone_descriptions[$tzvalue['tzid']])) { |
|
5330 | + $desc = $timezone_descriptions[$tzvalue['tzid']]; |
|
5331 | + } else { |
|
5332 | + $desc = implode(', ', array_unique($tzvalue['locations'])); |
|
5333 | + } |
|
5034 | 5334 | |
5035 | - if (isset($priority_zones[$tzkey])) |
|
5036 | - $priority_timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format(date_create($tzvalue['tzid']), 'P') . ']'; |
|
5037 | - else |
|
5038 | - $timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format(date_create($tzvalue['tzid']), 'P') . ']'; |
|
5335 | + if (isset($priority_zones[$tzkey])) { |
|
5336 | + $priority_timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format(date_create($tzvalue['tzid']), 'P') . ']'; |
|
5337 | + } else { |
|
5338 | + $timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format(date_create($tzvalue['tzid']), 'P') . ']'; |
|
5339 | + } |
|
5039 | 5340 | } |
5040 | 5341 | |
5041 | 5342 | $timezones = array_merge( |
@@ -5053,8 +5354,9 @@ discard block |
||
5053 | 5354 | */ |
5054 | 5355 | function inet_ptod($ip_address) |
5055 | 5356 | { |
5056 | - if (!isValidIP($ip_address)) |
|
5057 | - return $ip_address; |
|
5357 | + if (!isValidIP($ip_address)) { |
|
5358 | + return $ip_address; |
|
5359 | + } |
|
5058 | 5360 | |
5059 | 5361 | $bin = inet_pton($ip_address); |
5060 | 5362 | return $bin; |
@@ -5066,13 +5368,15 @@ discard block |
||
5066 | 5368 | */ |
5067 | 5369 | function inet_dtop($bin) |
5068 | 5370 | { |
5069 | - if(empty($bin)) |
|
5070 | - return ''; |
|
5371 | + if(empty($bin)) { |
|
5372 | + return ''; |
|
5373 | + } |
|
5071 | 5374 | |
5072 | 5375 | global $db_type; |
5073 | 5376 | |
5074 | - if ($db_type == 'postgresql') |
|
5075 | - return $bin; |
|
5377 | + if ($db_type == 'postgresql') { |
|
5378 | + return $bin; |
|
5379 | + } |
|
5076 | 5380 | |
5077 | 5381 | $ip_address = inet_ntop($bin); |
5078 | 5382 | |
@@ -5097,26 +5401,32 @@ discard block |
||
5097 | 5401 | */ |
5098 | 5402 | function _safe_serialize($value) |
5099 | 5403 | { |
5100 | - if(is_null($value)) |
|
5101 | - return 'N;'; |
|
5404 | + if(is_null($value)) { |
|
5405 | + return 'N;'; |
|
5406 | + } |
|
5102 | 5407 | |
5103 | - if(is_bool($value)) |
|
5104 | - return 'b:'. (int) $value .';'; |
|
5408 | + if(is_bool($value)) { |
|
5409 | + return 'b:'. (int) $value .';'; |
|
5410 | + } |
|
5105 | 5411 | |
5106 | - if(is_int($value)) |
|
5107 | - return 'i:'. $value .';'; |
|
5412 | + if(is_int($value)) { |
|
5413 | + return 'i:'. $value .';'; |
|
5414 | + } |
|
5108 | 5415 | |
5109 | - if(is_float($value)) |
|
5110 | - return 'd:'. str_replace(',', '.', $value) .';'; |
|
5416 | + if(is_float($value)) { |
|
5417 | + return 'd:'. str_replace(',', '.', $value) .';'; |
|
5418 | + } |
|
5111 | 5419 | |
5112 | - if(is_string($value)) |
|
5113 | - return 's:'. strlen($value) .':"'. $value .'";'; |
|
5420 | + if(is_string($value)) { |
|
5421 | + return 's:'. strlen($value) .':"'. $value .'";'; |
|
5422 | + } |
|
5114 | 5423 | |
5115 | 5424 | if(is_array($value)) |
5116 | 5425 | { |
5117 | 5426 | $out = ''; |
5118 | - foreach($value as $k => $v) |
|
5119 | - $out .= _safe_serialize($k) . _safe_serialize($v); |
|
5427 | + foreach($value as $k => $v) { |
|
5428 | + $out .= _safe_serialize($k) . _safe_serialize($v); |
|
5429 | + } |
|
5120 | 5430 | |
5121 | 5431 | return 'a:'. count($value) .':{'. $out .'}'; |
5122 | 5432 | } |
@@ -5142,8 +5452,9 @@ discard block |
||
5142 | 5452 | |
5143 | 5453 | $out = _safe_serialize($value); |
5144 | 5454 | |
5145 | - if (isset($mbIntEnc)) |
|
5146 | - mb_internal_encoding($mbIntEnc); |
|
5455 | + if (isset($mbIntEnc)) { |
|
5456 | + mb_internal_encoding($mbIntEnc); |
|
5457 | + } |
|
5147 | 5458 | |
5148 | 5459 | return $out; |
5149 | 5460 | } |
@@ -5160,8 +5471,9 @@ discard block |
||
5160 | 5471 | function _safe_unserialize($str) |
5161 | 5472 | { |
5162 | 5473 | // Input is not a string. |
5163 | - if(empty($str) || !is_string($str)) |
|
5164 | - return false; |
|
5474 | + if(empty($str) || !is_string($str)) { |
|
5475 | + return false; |
|
5476 | + } |
|
5165 | 5477 | |
5166 | 5478 | $stack = array(); |
5167 | 5479 | $expected = array(); |
@@ -5177,43 +5489,38 @@ discard block |
||
5177 | 5489 | while($state != 1) |
5178 | 5490 | { |
5179 | 5491 | $type = isset($str[0]) ? $str[0] : ''; |
5180 | - if($type == '}') |
|
5181 | - $str = substr($str, 1); |
|
5182 | - |
|
5183 | - else if($type == 'N' && $str[1] == ';') |
|
5492 | + if($type == '}') { |
|
5493 | + $str = substr($str, 1); |
|
5494 | + } else if($type == 'N' && $str[1] == ';') |
|
5184 | 5495 | { |
5185 | 5496 | $value = null; |
5186 | 5497 | $str = substr($str, 2); |
5187 | - } |
|
5188 | - else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches)) |
|
5498 | + } else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches)) |
|
5189 | 5499 | { |
5190 | 5500 | $value = $matches[1] == '1' ? true : false; |
5191 | 5501 | $str = substr($str, 4); |
5192 | - } |
|
5193 | - else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches)) |
|
5502 | + } else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches)) |
|
5194 | 5503 | { |
5195 | 5504 | $value = (int)$matches[1]; |
5196 | 5505 | $str = $matches[2]; |
5197 | - } |
|
5198 | - else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches)) |
|
5506 | + } else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches)) |
|
5199 | 5507 | { |
5200 | 5508 | $value = (float)$matches[1]; |
5201 | 5509 | $str = $matches[3]; |
5202 | - } |
|
5203 | - else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";') |
|
5510 | + } else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";') |
|
5204 | 5511 | { |
5205 | 5512 | $value = substr($matches[2], 0, (int)$matches[1]); |
5206 | 5513 | $str = substr($matches[2], (int)$matches[1] + 2); |
5207 | - } |
|
5208 | - else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches)) |
|
5514 | + } else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches)) |
|
5209 | 5515 | { |
5210 | 5516 | $expectedLength = (int)$matches[1]; |
5211 | 5517 | $str = $matches[2]; |
5212 | 5518 | } |
5213 | 5519 | |
5214 | 5520 | // Object or unknown/malformed type. |
5215 | - else |
|
5216 | - return false; |
|
5521 | + else { |
|
5522 | + return false; |
|
5523 | + } |
|
5217 | 5524 | |
5218 | 5525 | switch($state) |
5219 | 5526 | { |
@@ -5241,8 +5548,9 @@ discard block |
||
5241 | 5548 | if($type == '}') |
5242 | 5549 | { |
5243 | 5550 | // Array size is less than expected. |
5244 | - if(count($list) < end($expected)) |
|
5245 | - return false; |
|
5551 | + if(count($list) < end($expected)) { |
|
5552 | + return false; |
|
5553 | + } |
|
5246 | 5554 | |
5247 | 5555 | unset($list); |
5248 | 5556 | $list = &$stack[count($stack)-1]; |
@@ -5251,8 +5559,9 @@ discard block |
||
5251 | 5559 | // Go to terminal state if we're at the end of the root array. |
5252 | 5560 | array_pop($expected); |
5253 | 5561 | |
5254 | - if(count($expected) == 0) |
|
5255 | - $state = 1; |
|
5562 | + if(count($expected) == 0) { |
|
5563 | + $state = 1; |
|
5564 | + } |
|
5256 | 5565 | |
5257 | 5566 | break; |
5258 | 5567 | } |
@@ -5260,8 +5569,9 @@ discard block |
||
5260 | 5569 | if($type == 'i' || $type == 's') |
5261 | 5570 | { |
5262 | 5571 | // Array size exceeds expected length. |
5263 | - if(count($list) >= end($expected)) |
|
5264 | - return false; |
|
5572 | + if(count($list) >= end($expected)) { |
|
5573 | + return false; |
|
5574 | + } |
|
5265 | 5575 | |
5266 | 5576 | $key = $value; |
5267 | 5577 | $state = 3; |
@@ -5295,8 +5605,9 @@ discard block |
||
5295 | 5605 | } |
5296 | 5606 | |
5297 | 5607 | // Trailing data in input. |
5298 | - if(!empty($str)) |
|
5299 | - return false; |
|
5608 | + if(!empty($str)) { |
|
5609 | + return false; |
|
5610 | + } |
|
5300 | 5611 | |
5301 | 5612 | return $data; |
5302 | 5613 | } |
@@ -5319,8 +5630,9 @@ discard block |
||
5319 | 5630 | |
5320 | 5631 | $out = _safe_unserialize($str); |
5321 | 5632 | |
5322 | - if (isset($mbIntEnc)) |
|
5323 | - mb_internal_encoding($mbIntEnc); |
|
5633 | + if (isset($mbIntEnc)) { |
|
5634 | + mb_internal_encoding($mbIntEnc); |
|
5635 | + } |
|
5324 | 5636 | |
5325 | 5637 | return $out; |
5326 | 5638 | } |
@@ -5335,12 +5647,14 @@ discard block |
||
5335 | 5647 | function smf_chmod($file, $value = 0) |
5336 | 5648 | { |
5337 | 5649 | // No file? no checks! |
5338 | - if (empty($file)) |
|
5339 | - return false; |
|
5650 | + if (empty($file)) { |
|
5651 | + return false; |
|
5652 | + } |
|
5340 | 5653 | |
5341 | 5654 | // Already writable? |
5342 | - if (is_writable($file)) |
|
5343 | - return true; |
|
5655 | + if (is_writable($file)) { |
|
5656 | + return true; |
|
5657 | + } |
|
5344 | 5658 | |
5345 | 5659 | // Do we have a file or a dir? |
5346 | 5660 | $isDir = is_dir($file); |
@@ -5356,10 +5670,9 @@ discard block |
||
5356 | 5670 | { |
5357 | 5671 | $isWritable = true; |
5358 | 5672 | break; |
5673 | + } else { |
|
5674 | + @chmod($file, $val); |
|
5359 | 5675 | } |
5360 | - |
|
5361 | - else |
|
5362 | - @chmod($file, $val); |
|
5363 | 5676 | } |
5364 | 5677 | |
5365 | 5678 | return $isWritable; |
@@ -5378,8 +5691,9 @@ discard block |
||
5378 | 5691 | global $txt; |
5379 | 5692 | |
5380 | 5693 | // Come on... |
5381 | - if (empty($json) || !is_string($json)) |
|
5382 | - return array(); |
|
5694 | + if (empty($json) || !is_string($json)) { |
|
5695 | + return array(); |
|
5696 | + } |
|
5383 | 5697 | |
5384 | 5698 | $returnArray = @json_decode($json, $returnAsArray); |
5385 | 5699 | |
@@ -5417,11 +5731,11 @@ discard block |
||
5417 | 5731 | $jsonDebug = $jsonDebug[0]; |
5418 | 5732 | loadLanguage('Errors'); |
5419 | 5733 | |
5420 | - if (!empty($jsonDebug)) |
|
5421 | - log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']); |
|
5422 | - |
|
5423 | - else |
|
5424 | - log_error($txt['json_'. $jsonError], 'critical'); |
|
5734 | + if (!empty($jsonDebug)) { |
|
5735 | + log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']); |
|
5736 | + } else { |
|
5737 | + log_error($txt['json_'. $jsonError], 'critical'); |
|
5738 | + } |
|
5425 | 5739 | |
5426 | 5740 | // Everyone expects an array. |
5427 | 5741 | return array(); |
@@ -5451,8 +5765,9 @@ discard block |
||
5451 | 5765 | global $db_show_debug, $modSettings; |
5452 | 5766 | |
5453 | 5767 | // Defensive programming anyone? |
5454 | - if (empty($data)) |
|
5455 | - return false; |
|
5768 | + if (empty($data)) { |
|
5769 | + return false; |
|
5770 | + } |
|
5456 | 5771 | |
5457 | 5772 | // Don't need extra stuff... |
5458 | 5773 | $db_show_debug = false; |
@@ -5460,11 +5775,11 @@ discard block |
||
5460 | 5775 | // Kill anything else. |
5461 | 5776 | ob_end_clean(); |
5462 | 5777 | |
5463 | - if (!empty($modSettings['CompressedOutput'])) |
|
5464 | - @ob_start('ob_gzhandler'); |
|
5465 | - |
|
5466 | - else |
|
5467 | - ob_start(); |
|
5778 | + if (!empty($modSettings['CompressedOutput'])) { |
|
5779 | + @ob_start('ob_gzhandler'); |
|
5780 | + } else { |
|
5781 | + ob_start(); |
|
5782 | + } |
|
5468 | 5783 | |
5469 | 5784 | // Set the header. |
5470 | 5785 | header($type); |
@@ -5496,8 +5811,9 @@ discard block |
||
5496 | 5811 | static $done = false; |
5497 | 5812 | |
5498 | 5813 | // If we don't need to do anything, don't |
5499 | - if (!$update && $done) |
|
5500 | - return; |
|
5814 | + if (!$update && $done) { |
|
5815 | + return; |
|
5816 | + } |
|
5501 | 5817 | |
5502 | 5818 | // Should we get a new copy of the official list of TLDs? |
5503 | 5819 | if ($update) |
@@ -5518,10 +5834,11 @@ discard block |
||
5518 | 5834 | // Clean $tlds and convert it to an array |
5519 | 5835 | $tlds = array_filter(explode("\n", strtolower($tlds)), function($line) { |
5520 | 5836 | $line = trim($line); |
5521 | - if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) |
|
5522 | - return false; |
|
5523 | - else |
|
5524 | - return true; |
|
5837 | + if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) { |
|
5838 | + return false; |
|
5839 | + } else { |
|
5840 | + return true; |
|
5841 | + } |
|
5525 | 5842 | }); |
5526 | 5843 | |
5527 | 5844 | // Convert Punycode to Unicode |
@@ -5575,8 +5892,9 @@ discard block |
||
5575 | 5892 | $idx += $digit * $w; |
5576 | 5893 | $t = ($k <= $bias) ? $tmin : (($k >= $bias + $tmax) ? $tmax : ($k - $bias)); |
5577 | 5894 | |
5578 | - if ($digit < $t) |
|
5579 | - break; |
|
5895 | + if ($digit < $t) { |
|
5896 | + break; |
|
5897 | + } |
|
5580 | 5898 | |
5581 | 5899 | $w = (int) ($w * ($base - $t)); |
5582 | 5900 | } |
@@ -5585,8 +5903,9 @@ discard block |
||
5585 | 5903 | $delta = intval($is_first ? ($delta / $damp) : ($delta / 2)); |
5586 | 5904 | $delta += intval($delta / ($deco_len + 1)); |
5587 | 5905 | |
5588 | - for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base) |
|
5589 | - $delta = intval($delta / ($base - $tmin)); |
|
5906 | + for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base) { |
|
5907 | + $delta = intval($delta / ($base - $tmin)); |
|
5908 | + } |
|
5590 | 5909 | |
5591 | 5910 | $bias = intval($k + ($base - $tmin + 1) * $delta / ($delta + $skew)); |
5592 | 5911 | $is_first = false; |
@@ -5595,8 +5914,9 @@ discard block |
||
5595 | 5914 | |
5596 | 5915 | if ($deco_len > 0) |
5597 | 5916 | { |
5598 | - for ($i = $deco_len; $i > $idx; $i--) |
|
5599 | - $decoded[$i] = $decoded[($i - 1)]; |
|
5917 | + for ($i = $deco_len; $i > $idx; $i--) { |
|
5918 | + $decoded[$i] = $decoded[($i - 1)]; |
|
5919 | + } |
|
5600 | 5920 | } |
5601 | 5921 | $decoded[$idx++] = $char; |
5602 | 5922 | } |
@@ -5604,24 +5924,29 @@ discard block |
||
5604 | 5924 | foreach ($decoded as $k => $v) |
5605 | 5925 | { |
5606 | 5926 | // 7bit are transferred literally |
5607 | - if ($v < 128) |
|
5608 | - $output .= chr($v); |
|
5927 | + if ($v < 128) { |
|
5928 | + $output .= chr($v); |
|
5929 | + } |
|
5609 | 5930 | |
5610 | 5931 | // 2 bytes |
5611 | - elseif ($v < (1 << 11)) |
|
5612 | - $output .= chr(192+($v >> 6)) . chr(128+($v & 63)); |
|
5932 | + elseif ($v < (1 << 11)) { |
|
5933 | + $output .= chr(192+($v >> 6)) . chr(128+($v & 63)); |
|
5934 | + } |
|
5613 | 5935 | |
5614 | 5936 | // 3 bytes |
5615 | - elseif ($v < (1 << 16)) |
|
5616 | - $output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
5937 | + elseif ($v < (1 << 16)) { |
|
5938 | + $output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
5939 | + } |
|
5617 | 5940 | |
5618 | 5941 | // 4 bytes |
5619 | - elseif ($v < (1 << 21)) |
|
5620 | - $output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
5942 | + elseif ($v < (1 << 21)) { |
|
5943 | + $output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
5944 | + } |
|
5621 | 5945 | |
5622 | 5946 | // 'Conversion from UCS-4 to UTF-8 failed: malformed input at byte '.$k |
5623 | - else |
|
5624 | - $output .= $safe_char; |
|
5947 | + else { |
|
5948 | + $output .= $safe_char; |
|
5949 | + } |
|
5625 | 5950 | } |
5626 | 5951 | |
5627 | 5952 | $output_parts[] = $output; |
@@ -5716,8 +6041,7 @@ discard block |
||
5716 | 6041 | |
5717 | 6042 | $strlen = 'mb_strlen'; |
5718 | 6043 | $substr = 'mb_substr'; |
5719 | - } |
|
5720 | - else |
|
6044 | + } else |
|
5721 | 6045 | { |
5722 | 6046 | $strlen = $smcFunc['strlen']; |
5723 | 6047 | $substr = $smcFunc['substr']; |
@@ -5731,20 +6055,21 @@ discard block |
||
5731 | 6055 | |
5732 | 6056 | $first = $substr($string, 0, 1); |
5733 | 6057 | |
5734 | - if (empty($index[$first])) |
|
5735 | - $index[$first] = array(); |
|
6058 | + if (empty($index[$first])) { |
|
6059 | + $index[$first] = array(); |
|
6060 | + } |
|
5736 | 6061 | |
5737 | 6062 | if ($strlen($string) > 1) |
5738 | 6063 | { |
5739 | 6064 | // Sanity check on recursion |
5740 | - if ($depth > 99) |
|
5741 | - $index[$first][$substr($string, 1)] = ''; |
|
5742 | - |
|
5743 | - else |
|
5744 | - $index[$first] = $add_string_to_index($substr($string, 1), $index[$first]); |
|
6065 | + if ($depth > 99) { |
|
6066 | + $index[$first][$substr($string, 1)] = ''; |
|
6067 | + } else { |
|
6068 | + $index[$first] = $add_string_to_index($substr($string, 1), $index[$first]); |
|
6069 | + } |
|
6070 | + } else { |
|
6071 | + $index[$first][''] = ''; |
|
5745 | 6072 | } |
5746 | - else |
|
5747 | - $index[$first][''] = ''; |
|
5748 | 6073 | |
5749 | 6074 | $depth--; |
5750 | 6075 | return $index; |
@@ -5767,9 +6092,9 @@ discard block |
||
5767 | 6092 | $key_regex = preg_quote($key, $delim); |
5768 | 6093 | $new_key = $key; |
5769 | 6094 | |
5770 | - if (empty($value)) |
|
5771 | - $sub_regex = ''; |
|
5772 | - else |
|
6095 | + if (empty($value)) { |
|
6096 | + $sub_regex = ''; |
|
6097 | + } else |
|
5773 | 6098 | { |
5774 | 6099 | $sub_regex = $index_to_regex($value, $delim); |
5775 | 6100 | |
@@ -5777,22 +6102,22 @@ discard block |
||
5777 | 6102 | { |
5778 | 6103 | $new_key_array = explode('(?'.'>', $sub_regex); |
5779 | 6104 | $new_key .= $new_key_array[0]; |
6105 | + } else { |
|
6106 | + $sub_regex = '(?'.'>' . $sub_regex . ')'; |
|
5780 | 6107 | } |
5781 | - else |
|
5782 | - $sub_regex = '(?'.'>' . $sub_regex . ')'; |
|
5783 | 6108 | } |
5784 | 6109 | |
5785 | - if ($depth > 1) |
|
5786 | - $regex[$new_key] = $key_regex . $sub_regex; |
|
5787 | - else |
|
6110 | + if ($depth > 1) { |
|
6111 | + $regex[$new_key] = $key_regex . $sub_regex; |
|
6112 | + } else |
|
5788 | 6113 | { |
5789 | 6114 | if (($length += strlen($key_regex) + 1) < $max_length || empty($regex)) |
5790 | 6115 | { |
5791 | 6116 | $regex[$new_key] = $key_regex . $sub_regex; |
5792 | 6117 | unset($index[$key]); |
6118 | + } else { |
|
6119 | + break; |
|
5793 | 6120 | } |
5794 | - else |
|
5795 | - break; |
|
5796 | 6121 | } |
5797 | 6122 | } |
5798 | 6123 | |
@@ -5801,10 +6126,11 @@ discard block |
||
5801 | 6126 | $l1 = $strlen($k1); |
5802 | 6127 | $l2 = $strlen($k2); |
5803 | 6128 | |
5804 | - if ($l1 == $l2) |
|
5805 | - return strcmp($k1, $k2) > 0 ? 1 : -1; |
|
5806 | - else |
|
5807 | - return $l1 > $l2 ? -1 : 1; |
|
6129 | + if ($l1 == $l2) { |
|
6130 | + return strcmp($k1, $k2) > 0 ? 1 : -1; |
|
6131 | + } else { |
|
6132 | + return $l1 > $l2 ? -1 : 1; |
|
6133 | + } |
|
5808 | 6134 | }); |
5809 | 6135 | |
5810 | 6136 | $depth--; |
@@ -5815,15 +6141,18 @@ discard block |
||
5815 | 6141 | $index = array(); |
5816 | 6142 | $regexes = array(); |
5817 | 6143 | |
5818 | - foreach ($strings as $string) |
|
5819 | - $index = $add_string_to_index($string, $index); |
|
6144 | + foreach ($strings as $string) { |
|
6145 | + $index = $add_string_to_index($string, $index); |
|
6146 | + } |
|
5820 | 6147 | |
5821 | - while (!empty($index)) |
|
5822 | - $regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')'; |
|
6148 | + while (!empty($index)) { |
|
6149 | + $regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')'; |
|
6150 | + } |
|
5823 | 6151 | |
5824 | 6152 | // Restore PHP's internal character encoding to whatever it was originally |
5825 | - if (!empty($current_encoding)) |
|
5826 | - mb_internal_encoding($current_encoding); |
|
6153 | + if (!empty($current_encoding)) { |
|
6154 | + mb_internal_encoding($current_encoding); |
|
6155 | + } |
|
5827 | 6156 | |
5828 | 6157 | return $regexes; |
5829 | 6158 | } |