@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 4 |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF')) |
|
16 | +if (!defined('SMF')) { |
|
17 | 17 | die('No direct access...'); |
18 | +} |
|
18 | 19 | |
19 | 20 | /** |
20 | 21 | * 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 ($var == 'alerts' && ($val === '+' || $val === '-')) |
@@ -385,18 +394,17 @@ discard block |
||
385 | 394 | if (is_array($members)) |
386 | 395 | { |
387 | 396 | $val = 'CASE '; |
388 | - foreach ($members as $k => $v) |
|
389 | - $val .= 'WHEN id_member = ' . $v . ' THEN '. count(fetch_alerts($v, false, 0, array(), false)) . ' '; |
|
397 | + foreach ($members as $k => $v) { |
|
398 | + $val .= 'WHEN id_member = ' . $v . ' THEN '. count(fetch_alerts($v, false, 0, array(), false)) . ' '; |
|
399 | + } |
|
390 | 400 | $val = $val . ' END'; |
391 | 401 | $type = 'raw'; |
392 | - } |
|
393 | - else |
|
402 | + } else |
|
394 | 403 | { |
395 | 404 | $blub = fetch_alerts($members, false, 0, array(), false); |
396 | 405 | $val = count($blub); |
397 | 406 | } |
398 | - } |
|
399 | - else if ($type == 'int' && ($val === '+' || $val === '-')) |
|
407 | + } else if ($type == 'int' && ($val === '+' || $val === '-')) |
|
400 | 408 | { |
401 | 409 | $val = $var . ' ' . $val . ' 1'; |
402 | 410 | $type = 'raw'; |
@@ -407,8 +415,9 @@ discard block |
||
407 | 415 | { |
408 | 416 | if (preg_match('~^' . $var . ' (\+ |- |\+ -)([\d]+)~', $val, $match)) |
409 | 417 | { |
410 | - if ($match[1] != '+ ') |
|
411 | - $val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END'; |
|
418 | + if ($match[1] != '+ ') { |
|
419 | + $val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END'; |
|
420 | + } |
|
412 | 421 | $type = 'raw'; |
413 | 422 | } |
414 | 423 | } |
@@ -429,8 +438,9 @@ discard block |
||
429 | 438 | // Clear any caching? |
430 | 439 | if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && !empty($members)) |
431 | 440 | { |
432 | - if (!is_array($members)) |
|
433 | - $members = array($members); |
|
441 | + if (!is_array($members)) { |
|
442 | + $members = array($members); |
|
443 | + } |
|
434 | 444 | |
435 | 445 | foreach ($members as $member) |
436 | 446 | { |
@@ -463,29 +473,32 @@ discard block |
||
463 | 473 | { |
464 | 474 | global $modSettings, $smcFunc; |
465 | 475 | |
466 | - if (empty($changeArray) || !is_array($changeArray)) |
|
467 | - return; |
|
476 | + if (empty($changeArray) || !is_array($changeArray)) { |
|
477 | + return; |
|
478 | + } |
|
468 | 479 | |
469 | 480 | $toRemove = array(); |
470 | 481 | |
471 | 482 | // Go check if there is any setting to be removed. |
472 | - foreach ($changeArray as $k => $v) |
|
473 | - if ($v === null) |
|
483 | + foreach ($changeArray as $k => $v) { |
|
484 | + if ($v === null) |
|
474 | 485 | { |
475 | 486 | // Found some, remove them from the original array and add them to ours. |
476 | 487 | unset($changeArray[$k]); |
488 | + } |
|
477 | 489 | $toRemove[] = $k; |
478 | 490 | } |
479 | 491 | |
480 | 492 | // Proceed with the deletion. |
481 | - if (!empty($toRemove)) |
|
482 | - $smcFunc['db_query']('', ' |
|
493 | + if (!empty($toRemove)) { |
|
494 | + $smcFunc['db_query']('', ' |
|
483 | 495 | DELETE FROM {db_prefix}settings |
484 | 496 | WHERE variable IN ({array_string:remove})', |
485 | 497 | array( |
486 | 498 | 'remove' => $toRemove, |
487 | 499 | ) |
488 | 500 | ); |
501 | + } |
|
489 | 502 | |
490 | 503 | // In some cases, this may be better and faster, but for large sets we don't want so many UPDATEs. |
491 | 504 | if ($update) |
@@ -514,19 +527,22 @@ discard block |
||
514 | 527 | foreach ($changeArray as $variable => $value) |
515 | 528 | { |
516 | 529 | // Don't bother if it's already like that ;). |
517 | - if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) |
|
518 | - continue; |
|
530 | + if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) { |
|
531 | + continue; |
|
532 | + } |
|
519 | 533 | // If the variable isn't set, but would only be set to nothing'ness, then don't bother setting it. |
520 | - elseif (!isset($modSettings[$variable]) && empty($value)) |
|
521 | - continue; |
|
534 | + elseif (!isset($modSettings[$variable]) && empty($value)) { |
|
535 | + continue; |
|
536 | + } |
|
522 | 537 | |
523 | 538 | $replaceArray[] = array($variable, $value); |
524 | 539 | |
525 | 540 | $modSettings[$variable] = $value; |
526 | 541 | } |
527 | 542 | |
528 | - if (empty($replaceArray)) |
|
529 | - return; |
|
543 | + if (empty($replaceArray)) { |
|
544 | + return; |
|
545 | + } |
|
530 | 546 | |
531 | 547 | $smcFunc['db_insert']('replace', |
532 | 548 | '{db_prefix}settings', |
@@ -572,14 +588,17 @@ discard block |
||
572 | 588 | $start_invalid = $start < 0; |
573 | 589 | |
574 | 590 | // Make sure $start is a proper variable - not less than 0. |
575 | - if ($start_invalid) |
|
576 | - $start = 0; |
|
591 | + if ($start_invalid) { |
|
592 | + $start = 0; |
|
593 | + } |
|
577 | 594 | // Not greater than the upper bound. |
578 | - elseif ($start >= $max_value) |
|
579 | - $start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page))); |
|
595 | + elseif ($start >= $max_value) { |
|
596 | + $start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page))); |
|
597 | + } |
|
580 | 598 | // And it has to be a multiple of $num_per_page! |
581 | - else |
|
582 | - $start = max(0, (int) $start - ((int) $start % (int) $num_per_page)); |
|
599 | + else { |
|
600 | + $start = max(0, (int) $start - ((int) $start % (int) $num_per_page)); |
|
601 | + } |
|
583 | 602 | |
584 | 603 | $context['current_page'] = $start / $num_per_page; |
585 | 604 | |
@@ -609,77 +628,87 @@ discard block |
||
609 | 628 | |
610 | 629 | // Show all the pages. |
611 | 630 | $display_page = 1; |
612 | - for ($counter = 0; $counter < $max_value; $counter += $num_per_page) |
|
613 | - $pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++); |
|
631 | + for ($counter = 0; $counter < $max_value; $counter += $num_per_page) { |
|
632 | + $pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++); |
|
633 | + } |
|
614 | 634 | |
615 | 635 | // Show the right arrow. |
616 | 636 | $display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page); |
617 | - if ($start != $counter - $max_value && !$start_invalid) |
|
618 | - $pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']); |
|
619 | - } |
|
620 | - else |
|
637 | + if ($start != $counter - $max_value && !$start_invalid) { |
|
638 | + $pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']); |
|
639 | + } |
|
640 | + } else |
|
621 | 641 | { |
622 | 642 | // If they didn't enter an odd value, pretend they did. |
623 | 643 | $PageContiguous = (int) ($modSettings['compactTopicPagesContiguous'] - ($modSettings['compactTopicPagesContiguous'] % 2)) / 2; |
624 | 644 | |
625 | 645 | // Show the "prev page" link. (>prev page< 1 ... 6 7 [8] 9 10 ... 15 next page) |
626 | - if (!empty($start) && $show_prevnext) |
|
627 | - $pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']); |
|
628 | - else |
|
629 | - $pageindex .= ''; |
|
646 | + if (!empty($start) && $show_prevnext) { |
|
647 | + $pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']); |
|
648 | + } else { |
|
649 | + $pageindex .= ''; |
|
650 | + } |
|
630 | 651 | |
631 | 652 | // Show the first page. (prev page >1< ... 6 7 [8] 9 10 ... 15) |
632 | - if ($start > $num_per_page * $PageContiguous) |
|
633 | - $pageindex .= sprintf($base_link, 0, '1'); |
|
653 | + if ($start > $num_per_page * $PageContiguous) { |
|
654 | + $pageindex .= sprintf($base_link, 0, '1'); |
|
655 | + } |
|
634 | 656 | |
635 | 657 | // Show the ... after the first page. (prev page 1 >...< 6 7 [8] 9 10 ... 15 next page) |
636 | - if ($start > $num_per_page * ($PageContiguous + 1)) |
|
637 | - $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
658 | + if ($start > $num_per_page * ($PageContiguous + 1)) { |
|
659 | + $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
638 | 660 | '{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)), |
639 | 661 | '{FIRST_PAGE}' => $num_per_page, |
640 | 662 | '{LAST_PAGE}' => $start - $num_per_page * $PageContiguous, |
641 | 663 | '{PER_PAGE}' => $num_per_page, |
642 | 664 | )); |
665 | + } |
|
643 | 666 | |
644 | 667 | // Show the pages before the current one. (prev page 1 ... >6 7< [8] 9 10 ... 15 next page) |
645 | - for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) |
|
646 | - if ($start >= $num_per_page * $nCont) |
|
668 | + for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) { |
|
669 | + if ($start >= $num_per_page * $nCont) |
|
647 | 670 | { |
648 | 671 | $tmpStart = $start - $num_per_page * $nCont; |
672 | + } |
|
649 | 673 | $pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1); |
650 | 674 | } |
651 | 675 | |
652 | 676 | // Show the current page. (prev page 1 ... 6 7 >[8]< 9 10 ... 15 next page) |
653 | - if (!$start_invalid) |
|
654 | - $pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1); |
|
655 | - else |
|
656 | - $pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1); |
|
677 | + if (!$start_invalid) { |
|
678 | + $pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1); |
|
679 | + } else { |
|
680 | + $pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1); |
|
681 | + } |
|
657 | 682 | |
658 | 683 | // Show the pages after the current one... (prev page 1 ... 6 7 [8] >9 10< ... 15 next page) |
659 | 684 | $tmpMaxPages = (int) (($max_value - 1) / $num_per_page) * $num_per_page; |
660 | - for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) |
|
661 | - if ($start + $num_per_page * $nCont <= $tmpMaxPages) |
|
685 | + for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) { |
|
686 | + if ($start + $num_per_page * $nCont <= $tmpMaxPages) |
|
662 | 687 | { |
663 | 688 | $tmpStart = $start + $num_per_page * $nCont; |
689 | + } |
|
664 | 690 | $pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1); |
665 | 691 | } |
666 | 692 | |
667 | 693 | // Show the '...' part near the end. (prev page 1 ... 6 7 [8] 9 10 >...< 15 next page) |
668 | - if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) |
|
669 | - $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
694 | + if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) { |
|
695 | + $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
670 | 696 | '{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)), |
671 | 697 | '{FIRST_PAGE}' => $start + $num_per_page * ($PageContiguous + 1), |
672 | 698 | '{LAST_PAGE}' => $tmpMaxPages, |
673 | 699 | '{PER_PAGE}' => $num_per_page, |
674 | 700 | )); |
701 | + } |
|
675 | 702 | |
676 | 703 | // Show the last number in the list. (prev page 1 ... 6 7 [8] 9 10 ... >15< next page) |
677 | - if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) |
|
678 | - $pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1); |
|
704 | + if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) { |
|
705 | + $pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1); |
|
706 | + } |
|
679 | 707 | |
680 | 708 | // Show the "next page" link. (prev page 1 ... 6 7 [8] 9 10 ... 15 >next page<) |
681 | - if ($start != $tmpMaxPages && $show_prevnext) |
|
682 | - $pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']); |
|
709 | + if ($start != $tmpMaxPages && $show_prevnext) { |
|
710 | + $pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']); |
|
711 | + } |
|
683 | 712 | } |
684 | 713 | $pageindex .= $settings['page_index']['extra_after']; |
685 | 714 | |
@@ -705,8 +734,9 @@ discard block |
||
705 | 734 | if ($decimal_separator === null) |
706 | 735 | { |
707 | 736 | // Not set for whatever reason? |
708 | - if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) |
|
709 | - return $number; |
|
737 | + if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) { |
|
738 | + return $number; |
|
739 | + } |
|
710 | 740 | |
711 | 741 | // Cache these each load... |
712 | 742 | $thousands_separator = $matches[1]; |
@@ -740,17 +770,20 @@ discard block |
||
740 | 770 | static $unsupportedFormats, $finalizedFormats; |
741 | 771 | |
742 | 772 | // Offset the time. |
743 | - if (!$offset_type) |
|
744 | - $time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600; |
|
773 | + if (!$offset_type) { |
|
774 | + $time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600; |
|
775 | + } |
|
745 | 776 | // Just the forum offset? |
746 | - elseif ($offset_type == 'forum') |
|
747 | - $time = $log_time + $modSettings['time_offset'] * 3600; |
|
748 | - else |
|
749 | - $time = $log_time; |
|
777 | + elseif ($offset_type == 'forum') { |
|
778 | + $time = $log_time + $modSettings['time_offset'] * 3600; |
|
779 | + } else { |
|
780 | + $time = $log_time; |
|
781 | + } |
|
750 | 782 | |
751 | 783 | // We can't have a negative date (on Windows, at least.) |
752 | - if ($log_time < 0) |
|
753 | - $log_time = 0; |
|
784 | + if ($log_time < 0) { |
|
785 | + $log_time = 0; |
|
786 | + } |
|
754 | 787 | |
755 | 788 | // Today and Yesterday? |
756 | 789 | if ($modSettings['todayMod'] >= 1 && $show_today === true) |
@@ -767,24 +800,27 @@ discard block |
||
767 | 800 | { |
768 | 801 | $h = strpos($user_info['time_format'], '%l') === false ? '%I' : '%l'; |
769 | 802 | $today_fmt = $h . ':%M' . $s . ' %p'; |
803 | + } else { |
|
804 | + $today_fmt = '%H:%M' . $s; |
|
770 | 805 | } |
771 | - else |
|
772 | - $today_fmt = '%H:%M' . $s; |
|
773 | 806 | |
774 | 807 | // Same day of the year, same year.... Today! |
775 | - if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) |
|
776 | - return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type); |
|
808 | + if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) { |
|
809 | + return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type); |
|
810 | + } |
|
777 | 811 | |
778 | 812 | // 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... |
779 | - 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)) |
|
780 | - return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type); |
|
813 | + 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)) { |
|
814 | + return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type); |
|
815 | + } |
|
781 | 816 | } |
782 | 817 | |
783 | 818 | $str = !is_bool($show_today) ? $show_today : $user_info['time_format']; |
784 | 819 | |
785 | 820 | // Use the cached formats if available |
786 | - if (is_null($finalizedFormats)) |
|
787 | - $finalizedFormats = (array) cache_get_data('timeformatstrings', 86400); |
|
821 | + if (is_null($finalizedFormats)) { |
|
822 | + $finalizedFormats = (array) cache_get_data('timeformatstrings', 86400); |
|
823 | + } |
|
788 | 824 | |
789 | 825 | // Make a supported version for this format if we don't already have one |
790 | 826 | if (empty($finalizedFormats[$str])) |
@@ -813,8 +849,9 @@ discard block |
||
813 | 849 | ); |
814 | 850 | |
815 | 851 | // No need to do this part again if we already did it once |
816 | - if (is_null($unsupportedFormats)) |
|
817 | - $unsupportedFormats = (array) cache_get_data('unsupportedtimeformats', 86400); |
|
852 | + if (is_null($unsupportedFormats)) { |
|
853 | + $unsupportedFormats = (array) cache_get_data('unsupportedtimeformats', 86400); |
|
854 | + } |
|
818 | 855 | if (empty($unsupportedFormats)) |
819 | 856 | { |
820 | 857 | foreach($strftimeFormatSubstitutions as $format => $substitution) |
@@ -823,20 +860,23 @@ discard block |
||
823 | 860 | |
824 | 861 | // Windows will return false for unsupported formats |
825 | 862 | // Other operating systems return the format string as a literal |
826 | - if ($value === false || $value === $format) |
|
827 | - $unsupportedFormats[] = $format; |
|
863 | + if ($value === false || $value === $format) { |
|
864 | + $unsupportedFormats[] = $format; |
|
865 | + } |
|
828 | 866 | } |
829 | 867 | cache_put_data('unsupportedtimeformats', $unsupportedFormats, 86400); |
830 | 868 | } |
831 | 869 | |
832 | 870 | // Windows needs extra help if $timeformat contains something completely invalid, e.g. '%Q' |
833 | - if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') |
|
834 | - $timeformat = preg_replace('~%(?!' . implode('|', array_keys($strftimeFormatSubstitutions)) . ')~', '%', $timeformat); |
|
871 | + if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') { |
|
872 | + $timeformat = preg_replace('~%(?!' . implode('|', array_keys($strftimeFormatSubstitutions)) . ')~', '%', $timeformat); |
|
873 | + } |
|
835 | 874 | |
836 | 875 | // Substitute unsupported formats with supported ones |
837 | - if (!empty($unsupportedFormats)) |
|
838 | - while (preg_match('~%(' . implode('|', $unsupportedFormats) . ')~', $timeformat, $matches)) |
|
876 | + if (!empty($unsupportedFormats)) { |
|
877 | + while (preg_match('~%(' . implode('|', $unsupportedFormats) . ')~', $timeformat, $matches)) |
|
839 | 878 | $timeformat = str_replace($matches[0], $strftimeFormatSubstitutions[$matches[1]], $timeformat); |
879 | + } |
|
840 | 880 | |
841 | 881 | // Remember this so we don't need to do it again |
842 | 882 | $finalizedFormats[$str] = $timeformat; |
@@ -845,33 +885,39 @@ discard block |
||
845 | 885 | |
846 | 886 | $str = $finalizedFormats[$str]; |
847 | 887 | |
848 | - if (!isset($locale_cache)) |
|
849 | - $locale_cache = setlocale(LC_TIME, $txt['lang_locale']); |
|
888 | + if (!isset($locale_cache)) { |
|
889 | + $locale_cache = setlocale(LC_TIME, $txt['lang_locale']); |
|
890 | + } |
|
850 | 891 | |
851 | 892 | if ($locale_cache !== false) |
852 | 893 | { |
853 | 894 | // Check if another process changed the locale |
854 | - if ($process_safe === true && setlocale(LC_TIME, '0') != $locale_cache) |
|
855 | - setlocale(LC_TIME, $txt['lang_locale']); |
|
895 | + if ($process_safe === true && setlocale(LC_TIME, '0') != $locale_cache) { |
|
896 | + setlocale(LC_TIME, $txt['lang_locale']); |
|
897 | + } |
|
856 | 898 | |
857 | - if (!isset($non_twelve_hour)) |
|
858 | - $non_twelve_hour = trim(strftime('%p')) === ''; |
|
859 | - if ($non_twelve_hour && strpos($str, '%p') !== false) |
|
860 | - $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
899 | + if (!isset($non_twelve_hour)) { |
|
900 | + $non_twelve_hour = trim(strftime('%p')) === ''; |
|
901 | + } |
|
902 | + if ($non_twelve_hour && strpos($str, '%p') !== false) { |
|
903 | + $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
904 | + } |
|
861 | 905 | |
862 | - foreach (array('%a', '%A', '%b', '%B') as $token) |
|
863 | - if (strpos($str, $token) !== false) |
|
906 | + foreach (array('%a', '%A', '%b', '%B') as $token) { |
|
907 | + if (strpos($str, $token) !== false) |
|
864 | 908 | $str = str_replace($token, strftime($token, $time), $str); |
865 | - } |
|
866 | - else |
|
909 | + } |
|
910 | + } else |
|
867 | 911 | { |
868 | 912 | // Do-it-yourself time localization. Fun. |
869 | - foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) |
|
870 | - if (strpos($str, $token) !== false) |
|
913 | + foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) { |
|
914 | + if (strpos($str, $token) !== false) |
|
871 | 915 | $str = str_replace($token, $txt[$text_label][(int) strftime($token === '%a' || $token === '%A' ? '%w' : '%m', $time)], $str); |
916 | + } |
|
872 | 917 | |
873 | - if (strpos($str, '%p') !== false) |
|
874 | - $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
918 | + if (strpos($str, '%p') !== false) { |
|
919 | + $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
920 | + } |
|
875 | 921 | } |
876 | 922 | |
877 | 923 | // Format the time and then restore any literal percent characters |
@@ -894,16 +940,19 @@ discard block |
||
894 | 940 | static $translation = array(); |
895 | 941 | |
896 | 942 | // Determine the character set... Default to UTF-8 |
897 | - if (empty($context['character_set'])) |
|
898 | - $charset = 'UTF-8'; |
|
943 | + if (empty($context['character_set'])) { |
|
944 | + $charset = 'UTF-8'; |
|
945 | + } |
|
899 | 946 | // Use ISO-8859-1 in place of non-supported ISO-8859 charsets... |
900 | - elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) |
|
901 | - $charset = 'ISO-8859-1'; |
|
902 | - else |
|
903 | - $charset = $context['character_set']; |
|
947 | + elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) { |
|
948 | + $charset = 'ISO-8859-1'; |
|
949 | + } else { |
|
950 | + $charset = $context['character_set']; |
|
951 | + } |
|
904 | 952 | |
905 | - if (empty($translation)) |
|
906 | - $translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array(''' => '\'', ''' => '\'', ' ' => ' '); |
|
953 | + if (empty($translation)) { |
|
954 | + $translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array(''' => '\'', ''' => '\'', ' ' => ' '); |
|
955 | + } |
|
907 | 956 | |
908 | 957 | return strtr($string, $translation); |
909 | 958 | } |
@@ -925,8 +974,9 @@ discard block |
||
925 | 974 | global $smcFunc; |
926 | 975 | |
927 | 976 | // It was already short enough! |
928 | - if ($smcFunc['strlen']($subject) <= $len) |
|
929 | - return $subject; |
|
977 | + if ($smcFunc['strlen']($subject) <= $len) { |
|
978 | + return $subject; |
|
979 | + } |
|
930 | 980 | |
931 | 981 | // Shorten it by the length it was too long, and strip off junk from the end. |
932 | 982 | return $smcFunc['substr']($subject, 0, $len) . '...'; |
@@ -945,10 +995,11 @@ discard block |
||
945 | 995 | { |
946 | 996 | global $user_info, $modSettings; |
947 | 997 | |
948 | - if ($timestamp === null) |
|
949 | - $timestamp = time(); |
|
950 | - elseif ($timestamp == 0) |
|
951 | - return 0; |
|
998 | + if ($timestamp === null) { |
|
999 | + $timestamp = time(); |
|
1000 | + } elseif ($timestamp == 0) { |
|
1001 | + return 0; |
|
1002 | + } |
|
952 | 1003 | |
953 | 1004 | return $timestamp + ($modSettings['time_offset'] + ($use_user_offset ? $user_info['time_offset'] : 0)) * 3600; |
954 | 1005 | } |
@@ -977,8 +1028,9 @@ discard block |
||
977 | 1028 | $array[$i] = $array[$j]; |
978 | 1029 | $array[$j] = $temp; |
979 | 1030 | |
980 | - for ($i = 1; $p[$i] == 0; $i++) |
|
981 | - $p[$i] = 1; |
|
1031 | + for ($i = 1; $p[$i] == 0; $i++) { |
|
1032 | + $p[$i] = 1; |
|
1033 | + } |
|
982 | 1034 | |
983 | 1035 | $orders[] = $array; |
984 | 1036 | } |
@@ -1010,12 +1062,14 @@ discard block |
||
1010 | 1062 | static $disabled; |
1011 | 1063 | |
1012 | 1064 | // Don't waste cycles |
1013 | - if ($message === '') |
|
1014 | - return ''; |
|
1065 | + if ($message === '') { |
|
1066 | + return ''; |
|
1067 | + } |
|
1015 | 1068 | |
1016 | 1069 | // Just in case it wasn't determined yet whether UTF-8 is enabled. |
1017 | - if (!isset($context['utf8'])) |
|
1018 | - $context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8'; |
|
1070 | + if (!isset($context['utf8'])) { |
|
1071 | + $context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8'; |
|
1072 | + } |
|
1019 | 1073 | |
1020 | 1074 | // Clean up any cut/paste issues we may have |
1021 | 1075 | $message = sanitizeMSCutPaste($message); |
@@ -1027,13 +1081,15 @@ discard block |
||
1027 | 1081 | return $message; |
1028 | 1082 | } |
1029 | 1083 | |
1030 | - if ($smileys !== null && ($smileys == '1' || $smileys == '0')) |
|
1031 | - $smileys = (bool) $smileys; |
|
1084 | + if ($smileys !== null && ($smileys == '1' || $smileys == '0')) { |
|
1085 | + $smileys = (bool) $smileys; |
|
1086 | + } |
|
1032 | 1087 | |
1033 | 1088 | if (empty($modSettings['enableBBC']) && $message !== false) |
1034 | 1089 | { |
1035 | - if ($smileys === true) |
|
1036 | - parsesmileys($message); |
|
1090 | + if ($smileys === true) { |
|
1091 | + parsesmileys($message); |
|
1092 | + } |
|
1037 | 1093 | |
1038 | 1094 | return $message; |
1039 | 1095 | } |
@@ -1046,8 +1102,9 @@ discard block |
||
1046 | 1102 | } |
1047 | 1103 | |
1048 | 1104 | // Ensure $modSettings['tld_regex'] contains a valid regex for the autolinker |
1049 | - if (!empty($modSettings['autoLinkUrls'])) |
|
1050 | - set_tld_regex(); |
|
1105 | + if (!empty($modSettings['autoLinkUrls'])) { |
|
1106 | + set_tld_regex(); |
|
1107 | + } |
|
1051 | 1108 | |
1052 | 1109 | // Allow mods access before entering the main parse_bbc loop |
1053 | 1110 | call_integration_hook('integrate_pre_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags)); |
@@ -1061,12 +1118,14 @@ discard block |
||
1061 | 1118 | |
1062 | 1119 | $temp = explode(',', strtolower($modSettings['disabledBBC'])); |
1063 | 1120 | |
1064 | - foreach ($temp as $tag) |
|
1065 | - $disabled[trim($tag)] = true; |
|
1121 | + foreach ($temp as $tag) { |
|
1122 | + $disabled[trim($tag)] = true; |
|
1123 | + } |
|
1066 | 1124 | } |
1067 | 1125 | |
1068 | - if (empty($modSettings['enableEmbeddedFlash'])) |
|
1069 | - $disabled['flash'] = true; |
|
1126 | + if (empty($modSettings['enableEmbeddedFlash'])) { |
|
1127 | + $disabled['flash'] = true; |
|
1128 | + } |
|
1070 | 1129 | |
1071 | 1130 | /* The following bbc are formatted as an array, with keys as follows: |
1072 | 1131 | |
@@ -1187,8 +1246,9 @@ discard block |
||
1187 | 1246 | $returnContext = ''; |
1188 | 1247 | |
1189 | 1248 | // BBC or the entire attachments feature is disabled |
1190 | - if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) |
|
1191 | - return $data; |
|
1249 | + if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) { |
|
1250 | + return $data; |
|
1251 | + } |
|
1192 | 1252 | |
1193 | 1253 | // Save the attach ID. |
1194 | 1254 | $attachID = $data; |
@@ -1199,8 +1259,9 @@ discard block |
||
1199 | 1259 | $currentAttachment = parseAttachBBC($attachID); |
1200 | 1260 | |
1201 | 1261 | // parseAttachBBC will return a string ($txt key) rather than diying with a fatal_error. Up to you to decide what to do. |
1202 | - if (is_string($currentAttachment)) |
|
1203 | - return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment; |
|
1262 | + if (is_string($currentAttachment)) { |
|
1263 | + return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment; |
|
1264 | + } |
|
1204 | 1265 | |
1205 | 1266 | if (!empty($currentAttachment['is_image'])) |
1206 | 1267 | { |
@@ -1216,15 +1277,17 @@ discard block |
||
1216 | 1277 | $height = ' height="' . $currentAttachment['height'] . '"'; |
1217 | 1278 | } |
1218 | 1279 | |
1219 | - if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) |
|
1220 | - $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']. '" class="atc_img"></a>'; |
|
1221 | - else |
|
1222 | - $returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>'; |
|
1280 | + if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) { |
|
1281 | + $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']. '" class="atc_img"></a>'; |
|
1282 | + } else { |
|
1283 | + $returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>'; |
|
1284 | + } |
|
1223 | 1285 | } |
1224 | 1286 | |
1225 | 1287 | // No image. Show a link. |
1226 | - else |
|
1227 | - $returnContext .= $currentAttachment['link']; |
|
1288 | + else { |
|
1289 | + $returnContext .= $currentAttachment['link']; |
|
1290 | + } |
|
1228 | 1291 | |
1229 | 1292 | // Gotta append what we just did. |
1230 | 1293 | $data = $returnContext; |
@@ -1255,8 +1318,9 @@ discard block |
||
1255 | 1318 | for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++) |
1256 | 1319 | { |
1257 | 1320 | // Do PHP code coloring? |
1258 | - if ($php_parts[$php_i] != '<?php') |
|
1259 | - continue; |
|
1321 | + if ($php_parts[$php_i] != '<?php') { |
|
1322 | + continue; |
|
1323 | + } |
|
1260 | 1324 | |
1261 | 1325 | $php_string = ''; |
1262 | 1326 | while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?>') |
@@ -1272,8 +1336,9 @@ discard block |
||
1272 | 1336 | $data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data); |
1273 | 1337 | |
1274 | 1338 | // Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection. |
1275 | - if ($context['browser']['is_opera']) |
|
1276 | - $data .= ' '; |
|
1339 | + if ($context['browser']['is_opera']) { |
|
1340 | + $data .= ' '; |
|
1341 | + } |
|
1277 | 1342 | } |
1278 | 1343 | }, |
1279 | 1344 | 'block_level' => true, |
@@ -1292,8 +1357,9 @@ discard block |
||
1292 | 1357 | for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++) |
1293 | 1358 | { |
1294 | 1359 | // Do PHP code coloring? |
1295 | - if ($php_parts[$php_i] != '<?php') |
|
1296 | - continue; |
|
1360 | + if ($php_parts[$php_i] != '<?php') { |
|
1361 | + continue; |
|
1362 | + } |
|
1297 | 1363 | |
1298 | 1364 | $php_string = ''; |
1299 | 1365 | while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?>') |
@@ -1309,8 +1375,9 @@ discard block |
||
1309 | 1375 | $data[0] = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data[0]); |
1310 | 1376 | |
1311 | 1377 | // Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection. |
1312 | - if ($context['browser']['is_opera']) |
|
1313 | - $data[0] .= ' '; |
|
1378 | + if ($context['browser']['is_opera']) { |
|
1379 | + $data[0] .= ' '; |
|
1380 | + } |
|
1314 | 1381 | } |
1315 | 1382 | }, |
1316 | 1383 | 'block_level' => true, |
@@ -1348,11 +1415,13 @@ discard block |
||
1348 | 1415 | 'content' => '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never">', |
1349 | 1416 | 'validate' => function (&$tag, &$data, $disabled) |
1350 | 1417 | { |
1351 | - if (isset($disabled['url'])) |
|
1352 | - $tag['content'] = '$1'; |
|
1418 | + if (isset($disabled['url'])) { |
|
1419 | + $tag['content'] = '$1'; |
|
1420 | + } |
|
1353 | 1421 | $scheme = parse_url($data[0], PHP_URL_SCHEME); |
1354 | - if (empty($scheme)) |
|
1355 | - $data[0] = '//' . ltrim($data[0], ':/'); |
|
1422 | + if (empty($scheme)) { |
|
1423 | + $data[0] = '//' . ltrim($data[0], ':/'); |
|
1424 | + } |
|
1356 | 1425 | }, |
1357 | 1426 | 'disabled_content' => '<a href="$1" target="_blank" rel="noopener">$1</a>', |
1358 | 1427 | ), |
@@ -1366,10 +1435,11 @@ discard block |
||
1366 | 1435 | { |
1367 | 1436 | $class = 'class="bbc_float float' . (strpos($data, 'left') === 0 ? 'left' : 'right') . '"'; |
1368 | 1437 | |
1369 | - if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches)) |
|
1370 | - $css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"'; |
|
1371 | - else |
|
1372 | - $css = ''; |
|
1438 | + if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches)) { |
|
1439 | + $css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"'; |
|
1440 | + } else { |
|
1441 | + $css = ''; |
|
1442 | + } |
|
1373 | 1443 | |
1374 | 1444 | $data = $class . $css; |
1375 | 1445 | }, |
@@ -1419,17 +1489,20 @@ discard block |
||
1419 | 1489 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1420 | 1490 | if ($image_proxy_enabled) |
1421 | 1491 | { |
1422 | - if (!empty($user_info['possibly_robot'])) |
|
1423 | - return; |
|
1492 | + if (!empty($user_info['possibly_robot'])) { |
|
1493 | + return; |
|
1494 | + } |
|
1424 | 1495 | |
1425 | - if (empty($scheme)) |
|
1426 | - $data = 'http://' . ltrim($data, ':/'); |
|
1496 | + if (empty($scheme)) { |
|
1497 | + $data = 'http://' . ltrim($data, ':/'); |
|
1498 | + } |
|
1427 | 1499 | |
1428 | - if ($scheme != 'https') |
|
1429 | - $data = get_proxied_url($data); |
|
1500 | + if ($scheme != 'https') { |
|
1501 | + $data = get_proxied_url($data); |
|
1502 | + } |
|
1503 | + } elseif (empty($scheme)) { |
|
1504 | + $data = '//' . ltrim($data, ':/'); |
|
1430 | 1505 | } |
1431 | - elseif (empty($scheme)) |
|
1432 | - $data = '//' . ltrim($data, ':/'); |
|
1433 | 1506 | }, |
1434 | 1507 | 'disabled_content' => '($1)', |
1435 | 1508 | ), |
@@ -1445,17 +1518,20 @@ discard block |
||
1445 | 1518 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1446 | 1519 | if ($image_proxy_enabled) |
1447 | 1520 | { |
1448 | - if (!empty($user_info['possibly_robot'])) |
|
1449 | - return; |
|
1521 | + if (!empty($user_info['possibly_robot'])) { |
|
1522 | + return; |
|
1523 | + } |
|
1450 | 1524 | |
1451 | - if (empty($scheme)) |
|
1452 | - $data = 'http://' . ltrim($data, ':/'); |
|
1525 | + if (empty($scheme)) { |
|
1526 | + $data = 'http://' . ltrim($data, ':/'); |
|
1527 | + } |
|
1453 | 1528 | |
1454 | - if ($scheme != 'https') |
|
1455 | - $data = get_proxied_url($data); |
|
1529 | + if ($scheme != 'https') { |
|
1530 | + $data = get_proxied_url($data); |
|
1531 | + } |
|
1532 | + } elseif (empty($scheme)) { |
|
1533 | + $data = '//' . ltrim($data, ':/'); |
|
1456 | 1534 | } |
1457 | - elseif (empty($scheme)) |
|
1458 | - $data = '//' . ltrim($data, ':/'); |
|
1459 | 1535 | }, |
1460 | 1536 | 'disabled_content' => '($1)', |
1461 | 1537 | ), |
@@ -1467,8 +1543,9 @@ discard block |
||
1467 | 1543 | { |
1468 | 1544 | $data = strtr($data, array('<br>' => '')); |
1469 | 1545 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1470 | - if (empty($scheme)) |
|
1471 | - $data = '//' . ltrim($data, ':/'); |
|
1546 | + if (empty($scheme)) { |
|
1547 | + $data = '//' . ltrim($data, ':/'); |
|
1548 | + } |
|
1472 | 1549 | }, |
1473 | 1550 | ), |
1474 | 1551 | array( |
@@ -1479,13 +1556,14 @@ discard block |
||
1479 | 1556 | 'after' => '</a>', |
1480 | 1557 | 'validate' => function (&$tag, &$data, $disabled) |
1481 | 1558 | { |
1482 | - if (substr($data, 0, 1) == '#') |
|
1483 | - $data = '#post_' . substr($data, 1); |
|
1484 | - else |
|
1559 | + if (substr($data, 0, 1) == '#') { |
|
1560 | + $data = '#post_' . substr($data, 1); |
|
1561 | + } else |
|
1485 | 1562 | { |
1486 | 1563 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1487 | - if (empty($scheme)) |
|
1488 | - $data = '//' . ltrim($data, ':/'); |
|
1564 | + if (empty($scheme)) { |
|
1565 | + $data = '//' . ltrim($data, ':/'); |
|
1566 | + } |
|
1489 | 1567 | } |
1490 | 1568 | }, |
1491 | 1569 | 'disallow_children' => array('email', 'ftp', 'url', 'iurl'), |
@@ -1569,8 +1647,9 @@ discard block |
||
1569 | 1647 | { |
1570 | 1648 | $add_begin = substr(trim($data), 0, 5) != '<?'; |
1571 | 1649 | $data = highlight_php_code($add_begin ? '<?php ' . $data . '?>' : $data); |
1572 | - if ($add_begin) |
|
1573 | - $data = preg_replace(array('~^(.+?)<\?.{0,40}?php(?: |\s)~', '~\?>((?:</(font|span)>)*)$~'), '$1', $data, 2); |
|
1650 | + if ($add_begin) { |
|
1651 | + $data = preg_replace(array('~^(.+?)<\?.{0,40}?php(?: |\s)~', '~\?>((?:</(font|span)>)*)$~'), '$1', $data, 2); |
|
1652 | + } |
|
1574 | 1653 | } |
1575 | 1654 | }, |
1576 | 1655 | 'block_level' => false, |
@@ -1701,10 +1780,11 @@ discard block |
||
1701 | 1780 | 'content' => '$1', |
1702 | 1781 | 'validate' => function (&$tag, &$data, $disabled) |
1703 | 1782 | { |
1704 | - if (is_numeric($data)) |
|
1705 | - $data = timeformat($data); |
|
1706 | - else |
|
1707 | - $tag['content'] = '[time]$1[/time]'; |
|
1783 | + if (is_numeric($data)) { |
|
1784 | + $data = timeformat($data); |
|
1785 | + } else { |
|
1786 | + $tag['content'] = '[time]$1[/time]'; |
|
1787 | + } |
|
1708 | 1788 | }, |
1709 | 1789 | ), |
1710 | 1790 | array( |
@@ -1731,8 +1811,9 @@ discard block |
||
1731 | 1811 | { |
1732 | 1812 | $data = strtr($data, array('<br>' => '')); |
1733 | 1813 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1734 | - if (empty($scheme)) |
|
1735 | - $data = '//' . ltrim($data, ':/'); |
|
1814 | + if (empty($scheme)) { |
|
1815 | + $data = '//' . ltrim($data, ':/'); |
|
1816 | + } |
|
1736 | 1817 | }, |
1737 | 1818 | ), |
1738 | 1819 | array( |
@@ -1744,8 +1825,9 @@ discard block |
||
1744 | 1825 | 'validate' => function (&$tag, &$data, $disabled) |
1745 | 1826 | { |
1746 | 1827 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1747 | - if (empty($scheme)) |
|
1748 | - $data = '//' . ltrim($data, ':/'); |
|
1828 | + if (empty($scheme)) { |
|
1829 | + $data = '//' . ltrim($data, ':/'); |
|
1830 | + } |
|
1749 | 1831 | }, |
1750 | 1832 | 'disallow_children' => array('email', 'ftp', 'url', 'iurl'), |
1751 | 1833 | 'disabled_after' => ' ($1)', |
@@ -1771,8 +1853,9 @@ discard block |
||
1771 | 1853 | // This is mainly for the bbc manager, so it's easy to add tags above. Custom BBC should be added above this line. |
1772 | 1854 | if ($message === false) |
1773 | 1855 | { |
1774 | - if (isset($temp_bbc)) |
|
1775 | - $bbc_codes = $temp_bbc; |
|
1856 | + if (isset($temp_bbc)) { |
|
1857 | + $bbc_codes = $temp_bbc; |
|
1858 | + } |
|
1776 | 1859 | usort($codes, function ($a, $b) { |
1777 | 1860 | return strcmp($a['tag'], $b['tag']); |
1778 | 1861 | }); |
@@ -1792,8 +1875,9 @@ discard block |
||
1792 | 1875 | ); |
1793 | 1876 | if (!isset($disabled['li']) && !isset($disabled['list'])) |
1794 | 1877 | { |
1795 | - foreach ($itemcodes as $c => $dummy) |
|
1796 | - $bbc_codes[$c] = array(); |
|
1878 | + foreach ($itemcodes as $c => $dummy) { |
|
1879 | + $bbc_codes[$c] = array(); |
|
1880 | + } |
|
1797 | 1881 | } |
1798 | 1882 | |
1799 | 1883 | // Shhhh! |
@@ -1814,12 +1898,14 @@ discard block |
||
1814 | 1898 | foreach ($codes as $code) |
1815 | 1899 | { |
1816 | 1900 | // Make it easier to process parameters later |
1817 | - if (!empty($code['parameters'])) |
|
1818 | - ksort($code['parameters'], SORT_STRING); |
|
1901 | + if (!empty($code['parameters'])) { |
|
1902 | + ksort($code['parameters'], SORT_STRING); |
|
1903 | + } |
|
1819 | 1904 | |
1820 | 1905 | // If we are not doing every tag only do ones we are interested in. |
1821 | - if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) |
|
1822 | - $bbc_codes[substr($code['tag'], 0, 1)][] = $code; |
|
1906 | + if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) { |
|
1907 | + $bbc_codes[substr($code['tag'], 0, 1)][] = $code; |
|
1908 | + } |
|
1823 | 1909 | } |
1824 | 1910 | $codes = null; |
1825 | 1911 | } |
@@ -1830,8 +1916,9 @@ discard block |
||
1830 | 1916 | // It's likely this will change if the message is modified. |
1831 | 1917 | $cache_key = 'parse:' . $cache_id . '-' . md5(md5($message) . '-' . $smileys . (empty($disabled) ? '' : implode(',', array_keys($disabled))) . $smcFunc['json_encode']($context['browser']) . $txt['lang_locale'] . $user_info['time_offset'] . $user_info['time_format']); |
1832 | 1918 | |
1833 | - if (($temp = cache_get_data($cache_key, 240)) != null) |
|
1834 | - return $temp; |
|
1919 | + if (($temp = cache_get_data($cache_key, 240)) != null) { |
|
1920 | + return $temp; |
|
1921 | + } |
|
1835 | 1922 | |
1836 | 1923 | $cache_t = microtime(); |
1837 | 1924 | } |
@@ -1863,8 +1950,9 @@ discard block |
||
1863 | 1950 | $disabled['flash'] = true; |
1864 | 1951 | |
1865 | 1952 | // @todo Change maybe? |
1866 | - if (!isset($_GET['images'])) |
|
1867 | - $disabled['img'] = true; |
|
1953 | + if (!isset($_GET['images'])) { |
|
1954 | + $disabled['img'] = true; |
|
1955 | + } |
|
1868 | 1956 | |
1869 | 1957 | // @todo Interface/setting to add more? |
1870 | 1958 | } |
@@ -1888,8 +1976,9 @@ discard block |
||
1888 | 1976 | $pos = isset($matches[0][1]) ? $matches[0][1] : false; |
1889 | 1977 | |
1890 | 1978 | // Failsafe. |
1891 | - if ($pos === false || $last_pos > $pos) |
|
1892 | - $pos = strlen($message) + 1; |
|
1979 | + if ($pos === false || $last_pos > $pos) { |
|
1980 | + $pos = strlen($message) + 1; |
|
1981 | + } |
|
1893 | 1982 | |
1894 | 1983 | // Can't have a one letter smiley, URL, or email! (sorry.) |
1895 | 1984 | if ($last_pos < $pos - 1) |
@@ -1907,8 +1996,9 @@ discard block |
||
1907 | 1996 | |
1908 | 1997 | // <br> should be empty. |
1909 | 1998 | $empty_tags = array('br', 'hr'); |
1910 | - foreach ($empty_tags as $tag) |
|
1911 | - $data = str_replace(array('<' . $tag . '>', '<' . $tag . '/>', '<' . $tag . ' />'), '<' . $tag . '>', $data); |
|
1999 | + foreach ($empty_tags as $tag) { |
|
2000 | + $data = str_replace(array('<' . $tag . '>', '<' . $tag . '/>', '<' . $tag . ' />'), '<' . $tag . '>', $data); |
|
2001 | + } |
|
1912 | 2002 | |
1913 | 2003 | // b, u, i, s, pre... basic tags. |
1914 | 2004 | $closable_tags = array('b', 'u', 'i', 's', 'em', 'ins', 'del', 'pre', 'blockquote', 'strong'); |
@@ -1917,8 +2007,9 @@ discard block |
||
1917 | 2007 | $diff = substr_count($data, '<' . $tag . '>') - substr_count($data, '</' . $tag . '>'); |
1918 | 2008 | $data = strtr($data, array('<' . $tag . '>' => '<' . $tag . '>', '</' . $tag . '>' => '</' . $tag . '>')); |
1919 | 2009 | |
1920 | - if ($diff > 0) |
|
1921 | - $data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1); |
|
2010 | + if ($diff > 0) { |
|
2011 | + $data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1); |
|
2012 | + } |
|
1922 | 2013 | } |
1923 | 2014 | |
1924 | 2015 | // Do <img ...> - with security... action= -> action-. |
@@ -1931,8 +2022,9 @@ discard block |
||
1931 | 2022 | $alt = empty($matches[3][$match]) ? '' : ' alt=' . preg_replace('~^"|"$~', '', $matches[3][$match]); |
1932 | 2023 | |
1933 | 2024 | // Remove action= from the URL - no funny business, now. |
1934 | - if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) |
|
1935 | - $imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag); |
|
2025 | + if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) { |
|
2026 | + $imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag); |
|
2027 | + } |
|
1936 | 2028 | |
1937 | 2029 | $replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]'; |
1938 | 2030 | } |
@@ -1947,16 +2039,18 @@ discard block |
||
1947 | 2039 | $no_autolink_area = false; |
1948 | 2040 | if (!empty($open_tags)) |
1949 | 2041 | { |
1950 | - foreach ($open_tags as $open_tag) |
|
1951 | - if (in_array($open_tag['tag'], $no_autolink_tags)) |
|
2042 | + foreach ($open_tags as $open_tag) { |
|
2043 | + if (in_array($open_tag['tag'], $no_autolink_tags)) |
|
1952 | 2044 | $no_autolink_area = true; |
2045 | + } |
|
1953 | 2046 | } |
1954 | 2047 | |
1955 | 2048 | // Don't go backwards. |
1956 | 2049 | // @todo Don't think is the real solution.... |
1957 | 2050 | $lastAutoPos = isset($lastAutoPos) ? $lastAutoPos : 0; |
1958 | - if ($pos < $lastAutoPos) |
|
1959 | - $no_autolink_area = true; |
|
2051 | + if ($pos < $lastAutoPos) { |
|
2052 | + $no_autolink_area = true; |
|
2053 | + } |
|
1960 | 2054 | $lastAutoPos = $pos; |
1961 | 2055 | |
1962 | 2056 | if (!$no_autolink_area) |
@@ -2065,17 +2159,19 @@ discard block |
||
2065 | 2159 | if ($scheme == 'mailto') |
2066 | 2160 | { |
2067 | 2161 | $email_address = str_replace('mailto:', '', $url); |
2068 | - if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) |
|
2069 | - return '[email=' . $email_address . ']' . $url . '[/email]'; |
|
2070 | - else |
|
2071 | - return $url; |
|
2162 | + if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) { |
|
2163 | + return '[email=' . $email_address . ']' . $url . '[/email]'; |
|
2164 | + } else { |
|
2165 | + return $url; |
|
2166 | + } |
|
2072 | 2167 | } |
2073 | 2168 | |
2074 | 2169 | // Are we linking a schemeless URL or naked domain name (e.g. "example.com")? |
2075 | - if (empty($scheme)) |
|
2076 | - $fullUrl = '//' . ltrim($url, ':/'); |
|
2077 | - else |
|
2078 | - $fullUrl = $url; |
|
2170 | + if (empty($scheme)) { |
|
2171 | + $fullUrl = '//' . ltrim($url, ':/'); |
|
2172 | + } else { |
|
2173 | + $fullUrl = $url; |
|
2174 | + } |
|
2079 | 2175 | |
2080 | 2176 | return '[url="' . str_replace(array('[', ']'), array('[', ']'), $fullUrl) . '"]' . $url . '[/url]'; |
2081 | 2177 | }, $data); |
@@ -2124,22 +2220,25 @@ discard block |
||
2124 | 2220 | } |
2125 | 2221 | |
2126 | 2222 | // Are we there yet? Are we there yet? |
2127 | - if ($pos >= strlen($message) - 1) |
|
2128 | - break; |
|
2223 | + if ($pos >= strlen($message) - 1) { |
|
2224 | + break; |
|
2225 | + } |
|
2129 | 2226 | |
2130 | 2227 | $tags = strtolower($message[$pos + 1]); |
2131 | 2228 | |
2132 | 2229 | if ($tags == '/' && !empty($open_tags)) |
2133 | 2230 | { |
2134 | 2231 | $pos2 = strpos($message, ']', $pos + 1); |
2135 | - if ($pos2 == $pos + 2) |
|
2136 | - continue; |
|
2232 | + if ($pos2 == $pos + 2) { |
|
2233 | + continue; |
|
2234 | + } |
|
2137 | 2235 | |
2138 | 2236 | $look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2)); |
2139 | 2237 | |
2140 | 2238 | // A closing tag that doesn't match any open tags? Skip it. |
2141 | - if (!in_array($look_for, array_map(function($code){return $code['tag'];}, $open_tags))) |
|
2142 | - continue; |
|
2239 | + if (!in_array($look_for, array_map(function($code){return $code['tag'];}, $open_tags))) { |
|
2240 | + continue; |
|
2241 | + } |
|
2143 | 2242 | |
2144 | 2243 | $to_close = array(); |
2145 | 2244 | $block_level = null; |
@@ -2147,8 +2246,9 @@ discard block |
||
2147 | 2246 | do |
2148 | 2247 | { |
2149 | 2248 | $tag = array_pop($open_tags); |
2150 | - if (!$tag) |
|
2151 | - break; |
|
2249 | + if (!$tag) { |
|
2250 | + break; |
|
2251 | + } |
|
2152 | 2252 | |
2153 | 2253 | if (!empty($tag['block_level'])) |
2154 | 2254 | { |
@@ -2162,10 +2262,11 @@ discard block |
||
2162 | 2262 | // The idea is, if we are LOOKING for a block level tag, we can close them on the way. |
2163 | 2263 | if (strlen($look_for) > 0 && isset($bbc_codes[$look_for[0]])) |
2164 | 2264 | { |
2165 | - foreach ($bbc_codes[$look_for[0]] as $temp) |
|
2166 | - if ($temp['tag'] == $look_for) |
|
2265 | + foreach ($bbc_codes[$look_for[0]] as $temp) { |
|
2266 | + if ($temp['tag'] == $look_for) |
|
2167 | 2267 | { |
2168 | 2268 | $block_level = !empty($temp['block_level']); |
2269 | + } |
|
2169 | 2270 | break; |
2170 | 2271 | } |
2171 | 2272 | } |
@@ -2187,15 +2288,15 @@ discard block |
||
2187 | 2288 | { |
2188 | 2289 | $open_tags = $to_close; |
2189 | 2290 | continue; |
2190 | - } |
|
2191 | - elseif (!empty($to_close) && $tag['tag'] != $look_for) |
|
2291 | + } elseif (!empty($to_close) && $tag['tag'] != $look_for) |
|
2192 | 2292 | { |
2193 | 2293 | if ($block_level === null && isset($look_for[0], $bbc_codes[$look_for[0]])) |
2194 | 2294 | { |
2195 | - foreach ($bbc_codes[$look_for[0]] as $temp) |
|
2196 | - if ($temp['tag'] == $look_for) |
|
2295 | + foreach ($bbc_codes[$look_for[0]] as $temp) { |
|
2296 | + if ($temp['tag'] == $look_for) |
|
2197 | 2297 | { |
2198 | 2298 | $block_level = !empty($temp['block_level']); |
2299 | + } |
|
2199 | 2300 | break; |
2200 | 2301 | } |
2201 | 2302 | } |
@@ -2203,8 +2304,9 @@ discard block |
||
2203 | 2304 | // We're not looking for a block level tag (or maybe even a tag that exists...) |
2204 | 2305 | if (!$block_level) |
2205 | 2306 | { |
2206 | - foreach ($to_close as $tag) |
|
2207 | - array_push($open_tags, $tag); |
|
2307 | + foreach ($to_close as $tag) { |
|
2308 | + array_push($open_tags, $tag); |
|
2309 | + } |
|
2208 | 2310 | continue; |
2209 | 2311 | } |
2210 | 2312 | } |
@@ -2217,14 +2319,17 @@ discard block |
||
2217 | 2319 | |
2218 | 2320 | // See the comment at the end of the big loop - just eating whitespace ;). |
2219 | 2321 | $whitespace_regex = ''; |
2220 | - if (!empty($tag['block_level'])) |
|
2221 | - $whitespace_regex .= '( |\s)*(<br>)?'; |
|
2322 | + if (!empty($tag['block_level'])) { |
|
2323 | + $whitespace_regex .= '( |\s)*(<br>)?'; |
|
2324 | + } |
|
2222 | 2325 | // Trim one line of whitespace after unnested tags, but all of it after nested ones |
2223 | - if (!empty($tag['trim']) && $tag['trim'] != 'inside') |
|
2224 | - $whitespace_regex .= empty($tag['require_parents']) ? '( |\s)*' : '(<br>| |\s)*'; |
|
2326 | + if (!empty($tag['trim']) && $tag['trim'] != 'inside') { |
|
2327 | + $whitespace_regex .= empty($tag['require_parents']) ? '( |\s)*' : '(<br>| |\s)*'; |
|
2328 | + } |
|
2225 | 2329 | |
2226 | - if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) |
|
2227 | - $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
2330 | + if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) { |
|
2331 | + $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
2332 | + } |
|
2228 | 2333 | } |
2229 | 2334 | |
2230 | 2335 | if (!empty($to_close)) |
@@ -2237,8 +2342,9 @@ discard block |
||
2237 | 2342 | } |
2238 | 2343 | |
2239 | 2344 | // No tags for this character, so just keep going (fastest possible course.) |
2240 | - if (!isset($bbc_codes[$tags])) |
|
2241 | - continue; |
|
2345 | + if (!isset($bbc_codes[$tags])) { |
|
2346 | + continue; |
|
2347 | + } |
|
2242 | 2348 | |
2243 | 2349 | $inside = empty($open_tags) ? null : $open_tags[count($open_tags) - 1]; |
2244 | 2350 | $tag = null; |
@@ -2247,48 +2353,57 @@ discard block |
||
2247 | 2353 | $pt_strlen = strlen($possible['tag']); |
2248 | 2354 | |
2249 | 2355 | // Not a match? |
2250 | - if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) |
|
2251 | - continue; |
|
2356 | + if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) { |
|
2357 | + continue; |
|
2358 | + } |
|
2252 | 2359 | |
2253 | 2360 | $next_c = isset($message[$pos + 1 + $pt_strlen]) ? $message[$pos + 1 + $pt_strlen] : ''; |
2254 | 2361 | |
2255 | 2362 | // A tag is the last char maybe |
2256 | - if ($next_c == '') |
|
2257 | - break; |
|
2363 | + if ($next_c == '') { |
|
2364 | + break; |
|
2365 | + } |
|
2258 | 2366 | |
2259 | 2367 | // A test validation? |
2260 | - if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) |
|
2261 | - continue; |
|
2368 | + if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) { |
|
2369 | + continue; |
|
2370 | + } |
|
2262 | 2371 | // Do we want parameters? |
2263 | 2372 | elseif (!empty($possible['parameters'])) |
2264 | 2373 | { |
2265 | - if ($next_c != ' ') |
|
2266 | - continue; |
|
2267 | - } |
|
2268 | - elseif (isset($possible['type'])) |
|
2374 | + if ($next_c != ' ') { |
|
2375 | + continue; |
|
2376 | + } |
|
2377 | + } elseif (isset($possible['type'])) |
|
2269 | 2378 | { |
2270 | 2379 | // Do we need an equal sign? |
2271 | - if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') |
|
2272 | - continue; |
|
2380 | + if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') { |
|
2381 | + continue; |
|
2382 | + } |
|
2273 | 2383 | // Maybe we just want a /... |
2274 | - if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') |
|
2275 | - continue; |
|
2384 | + if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') { |
|
2385 | + continue; |
|
2386 | + } |
|
2276 | 2387 | // An immediate ]? |
2277 | - if ($possible['type'] == 'unparsed_content' && $next_c != ']') |
|
2278 | - continue; |
|
2388 | + if ($possible['type'] == 'unparsed_content' && $next_c != ']') { |
|
2389 | + continue; |
|
2390 | + } |
|
2279 | 2391 | } |
2280 | 2392 | // No type means 'parsed_content', which demands an immediate ] without parameters! |
2281 | - elseif ($next_c != ']') |
|
2282 | - continue; |
|
2393 | + elseif ($next_c != ']') { |
|
2394 | + continue; |
|
2395 | + } |
|
2283 | 2396 | |
2284 | 2397 | // Check allowed tree? |
2285 | - if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) |
|
2286 | - continue; |
|
2287 | - elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) |
|
2288 | - continue; |
|
2398 | + if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) { |
|
2399 | + continue; |
|
2400 | + } elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) { |
|
2401 | + continue; |
|
2402 | + } |
|
2289 | 2403 | // If this is in the list of disallowed child tags, don't parse it. |
2290 | - elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) |
|
2291 | - continue; |
|
2404 | + elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) { |
|
2405 | + continue; |
|
2406 | + } |
|
2292 | 2407 | |
2293 | 2408 | $pos1 = $pos + 1 + $pt_strlen + 1; |
2294 | 2409 | |
@@ -2300,8 +2415,9 @@ discard block |
||
2300 | 2415 | foreach ($open_tags as $open_quote) |
2301 | 2416 | { |
2302 | 2417 | // Every parent quote this quote has flips the styling |
2303 | - if ($open_quote['tag'] == 'quote') |
|
2304 | - $quote_alt = !$quote_alt; |
|
2418 | + if ($open_quote['tag'] == 'quote') { |
|
2419 | + $quote_alt = !$quote_alt; |
|
2420 | + } |
|
2305 | 2421 | } |
2306 | 2422 | // Add a class to the quote to style alternating blockquotes |
2307 | 2423 | $possible['before'] = strtr($possible['before'], array('<blockquote>' => '<blockquote class="bbc_' . ($quote_alt ? 'alternate' : 'standard') . '_quote">')); |
@@ -2312,8 +2428,9 @@ discard block |
||
2312 | 2428 | { |
2313 | 2429 | // Build a regular expression for each parameter for the current tag. |
2314 | 2430 | $preg = array(); |
2315 | - foreach ($possible['parameters'] as $p => $info) |
|
2316 | - $preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '"') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '"') . '\s*)' . (empty($info['optional']) ? '' : '?'); |
|
2431 | + foreach ($possible['parameters'] as $p => $info) { |
|
2432 | + $preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '"') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '"') . '\s*)' . (empty($info['optional']) ? '' : '?'); |
|
2433 | + } |
|
2317 | 2434 | |
2318 | 2435 | // Extract the string that potentially holds our parameters. |
2319 | 2436 | $blob = preg_split('~\[/?(?:' . $alltags_regex . ')~i', substr($message, $pos)); |
@@ -2333,24 +2450,27 @@ discard block |
||
2333 | 2450 | |
2334 | 2451 | $match = preg_match('~^' . implode('', $preg) . '$~i', implode(' ', $given_params), $matches) !== 0; |
2335 | 2452 | |
2336 | - if ($match) |
|
2337 | - $blob_counter = count($blobs) + 1; |
|
2453 | + if ($match) { |
|
2454 | + $blob_counter = count($blobs) + 1; |
|
2455 | + } |
|
2338 | 2456 | } |
2339 | 2457 | |
2340 | 2458 | // Didn't match our parameter list, try the next possible. |
2341 | - if (!$match) |
|
2342 | - continue; |
|
2459 | + if (!$match) { |
|
2460 | + continue; |
|
2461 | + } |
|
2343 | 2462 | |
2344 | 2463 | $params = array(); |
2345 | 2464 | for ($i = 1, $n = count($matches); $i < $n; $i += 2) |
2346 | 2465 | { |
2347 | 2466 | $key = strtok(ltrim($matches[$i]), '='); |
2348 | - if (isset($possible['parameters'][$key]['value'])) |
|
2349 | - $params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1])); |
|
2350 | - elseif (isset($possible['parameters'][$key]['validate'])) |
|
2351 | - $params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]); |
|
2352 | - else |
|
2353 | - $params['{' . $key . '}'] = $matches[$i + 1]; |
|
2467 | + if (isset($possible['parameters'][$key]['value'])) { |
|
2468 | + $params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1])); |
|
2469 | + } elseif (isset($possible['parameters'][$key]['validate'])) { |
|
2470 | + $params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]); |
|
2471 | + } else { |
|
2472 | + $params['{' . $key . '}'] = $matches[$i + 1]; |
|
2473 | + } |
|
2354 | 2474 | |
2355 | 2475 | // Just to make sure: replace any $ or { so they can't interpolate wrongly. |
2356 | 2476 | $params['{' . $key . '}'] = strtr($params['{' . $key . '}'], array('$' => '$', '{' => '{')); |
@@ -2358,23 +2478,26 @@ discard block |
||
2358 | 2478 | |
2359 | 2479 | foreach ($possible['parameters'] as $p => $info) |
2360 | 2480 | { |
2361 | - if (!isset($params['{' . $p . '}'])) |
|
2362 | - $params['{' . $p . '}'] = ''; |
|
2481 | + if (!isset($params['{' . $p . '}'])) { |
|
2482 | + $params['{' . $p . '}'] = ''; |
|
2483 | + } |
|
2363 | 2484 | } |
2364 | 2485 | |
2365 | 2486 | $tag = $possible; |
2366 | 2487 | |
2367 | 2488 | // Put the parameters into the string. |
2368 | - if (isset($tag['before'])) |
|
2369 | - $tag['before'] = strtr($tag['before'], $params); |
|
2370 | - if (isset($tag['after'])) |
|
2371 | - $tag['after'] = strtr($tag['after'], $params); |
|
2372 | - if (isset($tag['content'])) |
|
2373 | - $tag['content'] = strtr($tag['content'], $params); |
|
2489 | + if (isset($tag['before'])) { |
|
2490 | + $tag['before'] = strtr($tag['before'], $params); |
|
2491 | + } |
|
2492 | + if (isset($tag['after'])) { |
|
2493 | + $tag['after'] = strtr($tag['after'], $params); |
|
2494 | + } |
|
2495 | + if (isset($tag['content'])) { |
|
2496 | + $tag['content'] = strtr($tag['content'], $params); |
|
2497 | + } |
|
2374 | 2498 | |
2375 | 2499 | $pos1 += strlen($given_param_string); |
2376 | - } |
|
2377 | - else |
|
2500 | + } else |
|
2378 | 2501 | { |
2379 | 2502 | $tag = $possible; |
2380 | 2503 | $params = array(); |
@@ -2385,8 +2508,9 @@ discard block |
||
2385 | 2508 | // Item codes are complicated buggers... they are implicit [li]s and can make [list]s! |
2386 | 2509 | if ($smileys !== false && $tag === null && isset($itemcodes[$message[$pos + 1]]) && $message[$pos + 2] == ']' && !isset($disabled['list']) && !isset($disabled['li'])) |
2387 | 2510 | { |
2388 | - if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) |
|
2389 | - continue; |
|
2511 | + if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) { |
|
2512 | + continue; |
|
2513 | + } |
|
2390 | 2514 | |
2391 | 2515 | $tag = $itemcodes[$message[$pos + 1]]; |
2392 | 2516 | |
@@ -2407,9 +2531,9 @@ discard block |
||
2407 | 2531 | { |
2408 | 2532 | array_pop($open_tags); |
2409 | 2533 | $code = '</li>'; |
2534 | + } else { |
|
2535 | + $code = ''; |
|
2410 | 2536 | } |
2411 | - else |
|
2412 | - $code = ''; |
|
2413 | 2537 | |
2414 | 2538 | // Now we open a new tag. |
2415 | 2539 | $open_tags[] = array( |
@@ -2456,12 +2580,14 @@ discard block |
||
2456 | 2580 | } |
2457 | 2581 | |
2458 | 2582 | // No tag? Keep looking, then. Silly people using brackets without actual tags. |
2459 | - if ($tag === null) |
|
2460 | - continue; |
|
2583 | + if ($tag === null) { |
|
2584 | + continue; |
|
2585 | + } |
|
2461 | 2586 | |
2462 | 2587 | // Propagate the list to the child (so wrapping the disallowed tag won't work either.) |
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']; |
|
2588 | + if (isset($inside['disallow_children'])) { |
|
2589 | + $tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children']; |
|
2590 | + } |
|
2465 | 2591 | |
2466 | 2592 | // Is this tag disabled? |
2467 | 2593 | if (isset($disabled[$tag['tag']])) |
@@ -2471,14 +2597,13 @@ discard block |
||
2471 | 2597 | $tag['before'] = !empty($tag['block_level']) ? '<div>' : ''; |
2472 | 2598 | $tag['after'] = !empty($tag['block_level']) ? '</div>' : ''; |
2473 | 2599 | $tag['content'] = isset($tag['type']) && $tag['type'] == 'closed' ? '' : (!empty($tag['block_level']) ? '<div>$1</div>' : '$1'); |
2474 | - } |
|
2475 | - elseif (isset($tag['disabled_before']) || isset($tag['disabled_after'])) |
|
2600 | + } elseif (isset($tag['disabled_before']) || isset($tag['disabled_after'])) |
|
2476 | 2601 | { |
2477 | 2602 | $tag['before'] = isset($tag['disabled_before']) ? $tag['disabled_before'] : (!empty($tag['block_level']) ? '<div>' : ''); |
2478 | 2603 | $tag['after'] = isset($tag['disabled_after']) ? $tag['disabled_after'] : (!empty($tag['block_level']) ? '</div>' : ''); |
2604 | + } else { |
|
2605 | + $tag['content'] = $tag['disabled_content']; |
|
2479 | 2606 | } |
2480 | - else |
|
2481 | - $tag['content'] = $tag['disabled_content']; |
|
2482 | 2607 | } |
2483 | 2608 | |
2484 | 2609 | // we use this a lot |
@@ -2488,8 +2613,9 @@ discard block |
||
2488 | 2613 | if (!empty($tag['block_level']) && $tag['tag'] != 'html' && empty($inside['block_level'])) |
2489 | 2614 | { |
2490 | 2615 | $n = count($open_tags) - 1; |
2491 | - while (empty($open_tags[$n]['block_level']) && $n >= 0) |
|
2492 | - $n--; |
|
2616 | + while (empty($open_tags[$n]['block_level']) && $n >= 0) { |
|
2617 | + $n--; |
|
2618 | + } |
|
2493 | 2619 | |
2494 | 2620 | // Close all the non block level tags so this tag isn't surrounded by them. |
2495 | 2621 | for ($i = count($open_tags) - 1; $i > $n; $i--) |
@@ -2501,12 +2627,15 @@ discard block |
||
2501 | 2627 | |
2502 | 2628 | // Trim or eat trailing stuff... see comment at the end of the big loop. |
2503 | 2629 | $whitespace_regex = ''; |
2504 | - if (!empty($tag['block_level'])) |
|
2505 | - $whitespace_regex .= '( |\s)*(<br>)?'; |
|
2506 | - if (!empty($tag['trim']) && $tag['trim'] != 'inside') |
|
2507 | - $whitespace_regex .= empty($tag['require_parents']) ? '( |\s)*' : '(<br>| |\s)*'; |
|
2508 | - if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) |
|
2509 | - $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
2630 | + if (!empty($tag['block_level'])) { |
|
2631 | + $whitespace_regex .= '( |\s)*(<br>)?'; |
|
2632 | + } |
|
2633 | + if (!empty($tag['trim']) && $tag['trim'] != 'inside') { |
|
2634 | + $whitespace_regex .= empty($tag['require_parents']) ? '( |\s)*' : '(<br>| |\s)*'; |
|
2635 | + } |
|
2636 | + if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) { |
|
2637 | + $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
2638 | + } |
|
2510 | 2639 | |
2511 | 2640 | array_pop($open_tags); |
2512 | 2641 | } |
@@ -2527,16 +2656,19 @@ discard block |
||
2527 | 2656 | elseif ($tag['type'] == 'unparsed_content') |
2528 | 2657 | { |
2529 | 2658 | $pos2 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos1); |
2530 | - if ($pos2 === false) |
|
2531 | - continue; |
|
2659 | + if ($pos2 === false) { |
|
2660 | + continue; |
|
2661 | + } |
|
2532 | 2662 | |
2533 | 2663 | $data = substr($message, $pos1, $pos2 - $pos1); |
2534 | 2664 | |
2535 | - if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') |
|
2536 | - $data = substr($data, 4); |
|
2665 | + if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') { |
|
2666 | + $data = substr($data, 4); |
|
2667 | + } |
|
2537 | 2668 | |
2538 | - if (isset($tag['validate'])) |
|
2539 | - $tag['validate']($tag, $data, $disabled, $params); |
|
2669 | + if (isset($tag['validate'])) { |
|
2670 | + $tag['validate']($tag, $data, $disabled, $params); |
|
2671 | + } |
|
2540 | 2672 | |
2541 | 2673 | $code = strtr($tag['content'], array('$1' => $data)); |
2542 | 2674 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 3 + $tag_strlen); |
@@ -2552,34 +2684,40 @@ discard block |
||
2552 | 2684 | if (isset($tag['quoted'])) |
2553 | 2685 | { |
2554 | 2686 | $quoted = substr($message, $pos1, 6) == '"'; |
2555 | - if ($tag['quoted'] != 'optional' && !$quoted) |
|
2556 | - continue; |
|
2687 | + if ($tag['quoted'] != 'optional' && !$quoted) { |
|
2688 | + continue; |
|
2689 | + } |
|
2557 | 2690 | |
2558 | - if ($quoted) |
|
2559 | - $pos1 += 6; |
|
2691 | + if ($quoted) { |
|
2692 | + $pos1 += 6; |
|
2693 | + } |
|
2694 | + } else { |
|
2695 | + $quoted = false; |
|
2560 | 2696 | } |
2561 | - else |
|
2562 | - $quoted = false; |
|
2563 | 2697 | |
2564 | 2698 | $pos2 = strpos($message, $quoted == false ? ']' : '"]', $pos1); |
2565 | - if ($pos2 === false) |
|
2566 | - continue; |
|
2699 | + if ($pos2 === false) { |
|
2700 | + continue; |
|
2701 | + } |
|
2567 | 2702 | |
2568 | 2703 | $pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2); |
2569 | - if ($pos3 === false) |
|
2570 | - continue; |
|
2704 | + if ($pos3 === false) { |
|
2705 | + continue; |
|
2706 | + } |
|
2571 | 2707 | |
2572 | 2708 | $data = array( |
2573 | 2709 | substr($message, $pos2 + ($quoted == false ? 1 : 7), $pos3 - ($pos2 + ($quoted == false ? 1 : 7))), |
2574 | 2710 | substr($message, $pos1, $pos2 - $pos1) |
2575 | 2711 | ); |
2576 | 2712 | |
2577 | - if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') |
|
2578 | - $data[0] = substr($data[0], 4); |
|
2713 | + if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') { |
|
2714 | + $data[0] = substr($data[0], 4); |
|
2715 | + } |
|
2579 | 2716 | |
2580 | 2717 | // Validation for my parking, please! |
2581 | - if (isset($tag['validate'])) |
|
2582 | - $tag['validate']($tag, $data, $disabled, $params); |
|
2718 | + if (isset($tag['validate'])) { |
|
2719 | + $tag['validate']($tag, $data, $disabled, $params); |
|
2720 | + } |
|
2583 | 2721 | |
2584 | 2722 | $code = strtr($tag['content'], array('$1' => $data[0], '$2' => $data[1])); |
2585 | 2723 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen); |
@@ -2596,23 +2734,27 @@ discard block |
||
2596 | 2734 | elseif ($tag['type'] == 'unparsed_commas_content') |
2597 | 2735 | { |
2598 | 2736 | $pos2 = strpos($message, ']', $pos1); |
2599 | - if ($pos2 === false) |
|
2600 | - continue; |
|
2737 | + if ($pos2 === false) { |
|
2738 | + continue; |
|
2739 | + } |
|
2601 | 2740 | |
2602 | 2741 | $pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2); |
2603 | - if ($pos3 === false) |
|
2604 | - continue; |
|
2742 | + if ($pos3 === false) { |
|
2743 | + continue; |
|
2744 | + } |
|
2605 | 2745 | |
2606 | 2746 | // We want $1 to be the content, and the rest to be csv. |
2607 | 2747 | $data = explode(',', ',' . substr($message, $pos1, $pos2 - $pos1)); |
2608 | 2748 | $data[0] = substr($message, $pos2 + 1, $pos3 - $pos2 - 1); |
2609 | 2749 | |
2610 | - if (isset($tag['validate'])) |
|
2611 | - $tag['validate']($tag, $data, $disabled, $params); |
|
2750 | + if (isset($tag['validate'])) { |
|
2751 | + $tag['validate']($tag, $data, $disabled, $params); |
|
2752 | + } |
|
2612 | 2753 | |
2613 | 2754 | $code = $tag['content']; |
2614 | - foreach ($data as $k => $d) |
|
2615 | - $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
2755 | + foreach ($data as $k => $d) { |
|
2756 | + $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
2757 | + } |
|
2616 | 2758 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen); |
2617 | 2759 | $pos += strlen($code) - 1 + 2; |
2618 | 2760 | } |
@@ -2620,24 +2762,28 @@ discard block |
||
2620 | 2762 | elseif ($tag['type'] == 'unparsed_commas') |
2621 | 2763 | { |
2622 | 2764 | $pos2 = strpos($message, ']', $pos1); |
2623 | - if ($pos2 === false) |
|
2624 | - continue; |
|
2765 | + if ($pos2 === false) { |
|
2766 | + continue; |
|
2767 | + } |
|
2625 | 2768 | |
2626 | 2769 | $data = explode(',', substr($message, $pos1, $pos2 - $pos1)); |
2627 | 2770 | |
2628 | - if (isset($tag['validate'])) |
|
2629 | - $tag['validate']($tag, $data, $disabled, $params); |
|
2771 | + if (isset($tag['validate'])) { |
|
2772 | + $tag['validate']($tag, $data, $disabled, $params); |
|
2773 | + } |
|
2630 | 2774 | |
2631 | 2775 | // Fix after, for disabled code mainly. |
2632 | - foreach ($data as $k => $d) |
|
2633 | - $tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d))); |
|
2776 | + foreach ($data as $k => $d) { |
|
2777 | + $tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d))); |
|
2778 | + } |
|
2634 | 2779 | |
2635 | 2780 | $open_tags[] = $tag; |
2636 | 2781 | |
2637 | 2782 | // Replace them out, $1, $2, $3, $4, etc. |
2638 | 2783 | $code = $tag['before']; |
2639 | - foreach ($data as $k => $d) |
|
2640 | - $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
2784 | + foreach ($data as $k => $d) { |
|
2785 | + $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
2786 | + } |
|
2641 | 2787 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 1); |
2642 | 2788 | $pos += strlen($code) - 1 + 2; |
2643 | 2789 | } |
@@ -2648,28 +2794,33 @@ discard block |
||
2648 | 2794 | if (isset($tag['quoted'])) |
2649 | 2795 | { |
2650 | 2796 | $quoted = substr($message, $pos1, 6) == '"'; |
2651 | - if ($tag['quoted'] != 'optional' && !$quoted) |
|
2652 | - continue; |
|
2797 | + if ($tag['quoted'] != 'optional' && !$quoted) { |
|
2798 | + continue; |
|
2799 | + } |
|
2653 | 2800 | |
2654 | - if ($quoted) |
|
2655 | - $pos1 += 6; |
|
2801 | + if ($quoted) { |
|
2802 | + $pos1 += 6; |
|
2803 | + } |
|
2804 | + } else { |
|
2805 | + $quoted = false; |
|
2656 | 2806 | } |
2657 | - else |
|
2658 | - $quoted = false; |
|
2659 | 2807 | |
2660 | 2808 | $pos2 = strpos($message, $quoted == false ? ']' : '"]', $pos1); |
2661 | - if ($pos2 === false) |
|
2662 | - continue; |
|
2809 | + if ($pos2 === false) { |
|
2810 | + continue; |
|
2811 | + } |
|
2663 | 2812 | |
2664 | 2813 | $data = substr($message, $pos1, $pos2 - $pos1); |
2665 | 2814 | |
2666 | 2815 | // Validation for my parking, please! |
2667 | - if (isset($tag['validate'])) |
|
2668 | - $tag['validate']($tag, $data, $disabled, $params); |
|
2816 | + if (isset($tag['validate'])) { |
|
2817 | + $tag['validate']($tag, $data, $disabled, $params); |
|
2818 | + } |
|
2669 | 2819 | |
2670 | 2820 | // For parsed content, we must recurse to avoid security problems. |
2671 | - if ($tag['type'] != 'unparsed_equals') |
|
2672 | - $data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array()); |
|
2821 | + if ($tag['type'] != 'unparsed_equals') { |
|
2822 | + $data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array()); |
|
2823 | + } |
|
2673 | 2824 | |
2674 | 2825 | $tag['after'] = strtr($tag['after'], array('$1' => $data)); |
2675 | 2826 | |
@@ -2681,34 +2832,40 @@ discard block |
||
2681 | 2832 | } |
2682 | 2833 | |
2683 | 2834 | // If this is block level, eat any breaks after it. |
2684 | - if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') |
|
2685 | - $message = substr($message, 0, $pos + 1) . substr($message, $pos + 5); |
|
2835 | + if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') { |
|
2836 | + $message = substr($message, 0, $pos + 1) . substr($message, $pos + 5); |
|
2837 | + } |
|
2686 | 2838 | |
2687 | 2839 | // Are we trimming outside this tag? |
2688 | - if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>| |\s)*~', substr($message, $pos + 1), $matches) != 0) |
|
2689 | - $message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0])); |
|
2840 | + if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>| |\s)*~', substr($message, $pos + 1), $matches) != 0) { |
|
2841 | + $message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0])); |
|
2842 | + } |
|
2690 | 2843 | } |
2691 | 2844 | |
2692 | 2845 | // Close any remaining tags. |
2693 | - while ($tag = array_pop($open_tags)) |
|
2694 | - $message .= "\n" . $tag['after'] . "\n"; |
|
2846 | + while ($tag = array_pop($open_tags)) { |
|
2847 | + $message .= "\n" . $tag['after'] . "\n"; |
|
2848 | + } |
|
2695 | 2849 | |
2696 | 2850 | // Parse the smileys within the parts where it can be done safely. |
2697 | 2851 | if ($smileys === true) |
2698 | 2852 | { |
2699 | 2853 | $message_parts = explode("\n", $message); |
2700 | - for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) |
|
2701 | - parsesmileys($message_parts[$i]); |
|
2854 | + for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) { |
|
2855 | + parsesmileys($message_parts[$i]); |
|
2856 | + } |
|
2702 | 2857 | |
2703 | 2858 | $message = implode('', $message_parts); |
2704 | 2859 | } |
2705 | 2860 | |
2706 | 2861 | // No smileys, just get rid of the markers. |
2707 | - else |
|
2708 | - $message = strtr($message, array("\n" => '')); |
|
2862 | + else { |
|
2863 | + $message = strtr($message, array("\n" => '')); |
|
2864 | + } |
|
2709 | 2865 | |
2710 | - if ($message !== '' && $message[0] === ' ') |
|
2711 | - $message = ' ' . substr($message, 1); |
|
2866 | + if ($message !== '' && $message[0] === ' ') { |
|
2867 | + $message = ' ' . substr($message, 1); |
|
2868 | + } |
|
2712 | 2869 | |
2713 | 2870 | // Cleanup whitespace. |
2714 | 2871 | $message = strtr($message, array(' ' => ' ', "\r" => '', "\n" => '<br>', '<br> ' => '<br> ', ' ' => "\n")); |
@@ -2717,15 +2874,16 @@ discard block |
||
2717 | 2874 | call_integration_hook('integrate_post_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags)); |
2718 | 2875 | |
2719 | 2876 | // Cache the output if it took some time... |
2720 | - if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) |
|
2721 | - cache_put_data($cache_key, $message, 240); |
|
2877 | + if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) { |
|
2878 | + cache_put_data($cache_key, $message, 240); |
|
2879 | + } |
|
2722 | 2880 | |
2723 | 2881 | // If this was a force parse revert if needed. |
2724 | 2882 | if (!empty($parse_tags)) |
2725 | 2883 | { |
2726 | - if (empty($temp_bbc)) |
|
2727 | - $bbc_codes = array(); |
|
2728 | - else |
|
2884 | + if (empty($temp_bbc)) { |
|
2885 | + $bbc_codes = array(); |
|
2886 | + } else |
|
2729 | 2887 | { |
2730 | 2888 | $bbc_codes = $temp_bbc; |
2731 | 2889 | unset($temp_bbc); |
@@ -2752,8 +2910,9 @@ discard block |
||
2752 | 2910 | static $smileyPregSearch = null, $smileyPregReplacements = array(); |
2753 | 2911 | |
2754 | 2912 | // No smiley set at all?! |
2755 | - if ($user_info['smiley_set'] == 'none' || trim($message) == '') |
|
2756 | - return; |
|
2913 | + if ($user_info['smiley_set'] == 'none' || trim($message) == '') { |
|
2914 | + return; |
|
2915 | + } |
|
2757 | 2916 | |
2758 | 2917 | // If smileyPregSearch hasn't been set, do it now. |
2759 | 2918 | if (empty($smileyPregSearch)) |
@@ -2764,8 +2923,7 @@ discard block |
||
2764 | 2923 | $smileysfrom = array('>:D', ':D', '::)', '>:(', ':))', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', '0:)'); |
2765 | 2924 | $smileysto = array('evil.png', 'cheesy.png', 'rolleyes.png', 'angry.png', 'laugh.png', 'smiley.png', 'wink.png', 'grin.png', 'sad.png', 'shocked.png', 'cool.png', 'tongue.png', 'huh.png', 'embarrassed.png', 'lipsrsealed.png', 'kiss.png', 'cry.png', 'undecided.png', 'azn.png', 'afro.png', 'police.png', 'angel.png'); |
2766 | 2925 | $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'], '', '', '', ''); |
2767 | - } |
|
2768 | - else |
|
2926 | + } else |
|
2769 | 2927 | { |
2770 | 2928 | // Load the smileys in reverse order by length so they don't get parsed wrong. |
2771 | 2929 | if (($temp = cache_get_data('parsing_smileys', 480)) == null) |
@@ -2789,9 +2947,9 @@ discard block |
||
2789 | 2947 | $smcFunc['db_free_result']($result); |
2790 | 2948 | |
2791 | 2949 | cache_put_data('parsing_smileys', array($smileysfrom, $smileysto, $smileysdescs), 480); |
2950 | + } else { |
|
2951 | + list ($smileysfrom, $smileysto, $smileysdescs) = $temp; |
|
2792 | 2952 | } |
2793 | - else |
|
2794 | - list ($smileysfrom, $smileysto, $smileysdescs) = $temp; |
|
2795 | 2953 | } |
2796 | 2954 | |
2797 | 2955 | // The non-breaking-space is a complex thing... |
@@ -2869,12 +3027,14 @@ discard block |
||
2869 | 3027 | global $boardurl, $image_proxy_enabled, $image_proxy_secret; |
2870 | 3028 | |
2871 | 3029 | // Only use the proxy if enabled and necessary |
2872 | - if (empty($image_proxy_enabled) || parse_url($url, PHP_URL_SCHEME) === 'https') |
|
2873 | - return $url; |
|
3030 | + if (empty($image_proxy_enabled) || parse_url($url, PHP_URL_SCHEME) === 'https') { |
|
3031 | + return $url; |
|
3032 | + } |
|
2874 | 3033 | |
2875 | 3034 | // We don't need to proxy our own resources |
2876 | - if (strpos(strtr($url, array('http://' => 'https://')), strtr($boardurl, array('http://' => 'https://'))) === 0) |
|
2877 | - return strtr($url, array('http://' => 'https://')); |
|
3035 | + if (strpos(strtr($url, array('http://' => 'https://')), strtr($boardurl, array('http://' => 'https://'))) === 0) { |
|
3036 | + return strtr($url, array('http://' => 'https://')); |
|
3037 | + } |
|
2878 | 3038 | |
2879 | 3039 | // By default, use SMF's own image proxy script |
2880 | 3040 | $proxied_url = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($url) . '&hash=' . md5($url . $image_proxy_secret); |
@@ -2899,35 +3059,41 @@ discard block |
||
2899 | 3059 | global $scripturl, $context, $modSettings, $db_show_debug, $db_cache; |
2900 | 3060 | |
2901 | 3061 | // In case we have mail to send, better do that - as obExit doesn't always quite make it... |
2902 | - if (!empty($context['flush_mail'])) |
|
2903 | - // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
3062 | + if (!empty($context['flush_mail'])) { |
|
3063 | + // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
2904 | 3064 | AddMailQueue(true); |
3065 | + } |
|
2905 | 3066 | |
2906 | 3067 | $add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && substr($setLocation, 0, 6) != 'about:'; |
2907 | 3068 | |
2908 | - if ($add) |
|
2909 | - $setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : ''); |
|
3069 | + if ($add) { |
|
3070 | + $setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : ''); |
|
3071 | + } |
|
2910 | 3072 | |
2911 | 3073 | // Put the session ID in. |
2912 | - if (defined('SID') && SID != '') |
|
2913 | - $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation); |
|
3074 | + if (defined('SID') && SID != '') { |
|
3075 | + $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation); |
|
3076 | + } |
|
2914 | 3077 | // Keep that debug in their for template debugging! |
2915 | - elseif (isset($_GET['debug'])) |
|
2916 | - $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation); |
|
3078 | + elseif (isset($_GET['debug'])) { |
|
3079 | + $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation); |
|
3080 | + } |
|
2917 | 3081 | |
2918 | 3082 | 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']))) |
2919 | 3083 | { |
2920 | - if (defined('SID') && SID != '') |
|
2921 | - $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#]+?)(#[^"]*?)?$~', |
|
3084 | + if (defined('SID') && SID != '') { |
|
3085 | + $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#]+?)(#[^"]*?)?$~', |
|
2922 | 3086 | function ($m) use ($scripturl) |
2923 | 3087 | { |
2924 | 3088 | return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : ""); |
3089 | + } |
|
2925 | 3090 | }, $setLocation); |
2926 | - else |
|
2927 | - $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~', |
|
3091 | + else { |
|
3092 | + $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~', |
|
2928 | 3093 | function ($m) use ($scripturl) |
2929 | 3094 | { |
2930 | 3095 | return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : ""); |
3096 | + } |
|
2931 | 3097 | }, $setLocation); |
2932 | 3098 | } |
2933 | 3099 | |
@@ -2938,8 +3104,9 @@ discard block |
||
2938 | 3104 | header('location: ' . str_replace(' ', '%20', $setLocation), true, $permanent ? 301 : 302); |
2939 | 3105 | |
2940 | 3106 | // Debugging. |
2941 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
2942 | - $_SESSION['debug_redirect'] = $db_cache; |
|
3107 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
3108 | + $_SESSION['debug_redirect'] = $db_cache; |
|
3109 | + } |
|
2943 | 3110 | |
2944 | 3111 | obExit(false); |
2945 | 3112 | } |
@@ -2958,51 +3125,60 @@ discard block |
||
2958 | 3125 | |
2959 | 3126 | // Attempt to prevent a recursive loop. |
2960 | 3127 | ++$level; |
2961 | - if ($level > 1 && !$from_fatal_error && !$has_fatal_error) |
|
2962 | - exit; |
|
2963 | - if ($from_fatal_error) |
|
2964 | - $has_fatal_error = true; |
|
3128 | + if ($level > 1 && !$from_fatal_error && !$has_fatal_error) { |
|
3129 | + exit; |
|
3130 | + } |
|
3131 | + if ($from_fatal_error) { |
|
3132 | + $has_fatal_error = true; |
|
3133 | + } |
|
2965 | 3134 | |
2966 | 3135 | // Clear out the stat cache. |
2967 | 3136 | trackStats(); |
2968 | 3137 | |
2969 | 3138 | // If we have mail to send, send it. |
2970 | - if (!empty($context['flush_mail'])) |
|
2971 | - // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
3139 | + if (!empty($context['flush_mail'])) { |
|
3140 | + // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
2972 | 3141 | AddMailQueue(true); |
3142 | + } |
|
2973 | 3143 | |
2974 | 3144 | $do_header = $header === null ? !$header_done : $header; |
2975 | - if ($do_footer === null) |
|
2976 | - $do_footer = $do_header; |
|
3145 | + if ($do_footer === null) { |
|
3146 | + $do_footer = $do_header; |
|
3147 | + } |
|
2977 | 3148 | |
2978 | 3149 | // Has the template/header been done yet? |
2979 | 3150 | if ($do_header) |
2980 | 3151 | { |
2981 | 3152 | // Was the page title set last minute? Also update the HTML safe one. |
2982 | - if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) |
|
2983 | - $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); |
|
3153 | + if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) { |
|
3154 | + $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); |
|
3155 | + } |
|
2984 | 3156 | |
2985 | 3157 | // Start up the session URL fixer. |
2986 | 3158 | ob_start('ob_sessrewrite'); |
2987 | 3159 | |
2988 | - if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) |
|
2989 | - $buffers = explode(',', $settings['output_buffers']); |
|
2990 | - elseif (!empty($settings['output_buffers'])) |
|
2991 | - $buffers = $settings['output_buffers']; |
|
2992 | - else |
|
2993 | - $buffers = array(); |
|
3160 | + if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) { |
|
3161 | + $buffers = explode(',', $settings['output_buffers']); |
|
3162 | + } elseif (!empty($settings['output_buffers'])) { |
|
3163 | + $buffers = $settings['output_buffers']; |
|
3164 | + } else { |
|
3165 | + $buffers = array(); |
|
3166 | + } |
|
2994 | 3167 | |
2995 | - if (isset($modSettings['integrate_buffer'])) |
|
2996 | - $buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers); |
|
3168 | + if (isset($modSettings['integrate_buffer'])) { |
|
3169 | + $buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers); |
|
3170 | + } |
|
2997 | 3171 | |
2998 | - if (!empty($buffers)) |
|
2999 | - foreach ($buffers as $function) |
|
3172 | + if (!empty($buffers)) { |
|
3173 | + foreach ($buffers as $function) |
|
3000 | 3174 | { |
3001 | 3175 | $call = call_helper($function, true); |
3176 | + } |
|
3002 | 3177 | |
3003 | 3178 | // Is it valid? |
3004 | - if (!empty($call)) |
|
3005 | - ob_start($call); |
|
3179 | + if (!empty($call)) { |
|
3180 | + ob_start($call); |
|
3181 | + } |
|
3006 | 3182 | } |
3007 | 3183 | |
3008 | 3184 | // Display the screen in the logical order. |
@@ -3014,8 +3190,9 @@ discard block |
||
3014 | 3190 | loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main'); |
3015 | 3191 | |
3016 | 3192 | // Anything special to put out? |
3017 | - if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) |
|
3018 | - echo $context['insert_after_template']; |
|
3193 | + if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) { |
|
3194 | + echo $context['insert_after_template']; |
|
3195 | + } |
|
3019 | 3196 | |
3020 | 3197 | // Just so we don't get caught in an endless loop of errors from the footer... |
3021 | 3198 | if (!$footer_done) |
@@ -3024,14 +3201,16 @@ discard block |
||
3024 | 3201 | template_footer(); |
3025 | 3202 | |
3026 | 3203 | // (since this is just debugging... it's okay that it's after </html>.) |
3027 | - if (!isset($_REQUEST['xml'])) |
|
3028 | - displayDebug(); |
|
3204 | + if (!isset($_REQUEST['xml'])) { |
|
3205 | + displayDebug(); |
|
3206 | + } |
|
3029 | 3207 | } |
3030 | 3208 | } |
3031 | 3209 | |
3032 | 3210 | // Remember this URL in case someone doesn't like sending HTTP_REFERER. |
3033 | - if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) |
|
3034 | - $_SESSION['old_url'] = $_SERVER['REQUEST_URL']; |
|
3211 | + if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) { |
|
3212 | + $_SESSION['old_url'] = $_SERVER['REQUEST_URL']; |
|
3213 | + } |
|
3035 | 3214 | |
3036 | 3215 | // For session check verification.... don't switch browsers... |
3037 | 3216 | $_SESSION['USER_AGENT'] = empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT']; |
@@ -3040,9 +3219,10 @@ discard block |
||
3040 | 3219 | call_integration_hook('integrate_exit', array($do_footer)); |
3041 | 3220 | |
3042 | 3221 | // Don't exit if we're coming from index.php; that will pass through normally. |
3043 | - if (!$from_index) |
|
3044 | - exit; |
|
3045 | -} |
|
3222 | + if (!$from_index) { |
|
3223 | + exit; |
|
3224 | + } |
|
3225 | + } |
|
3046 | 3226 | |
3047 | 3227 | /** |
3048 | 3228 | * Get the size of a specified image with better error handling. |
@@ -3061,8 +3241,9 @@ discard block |
||
3061 | 3241 | $url = str_replace(' ', '%20', $url); |
3062 | 3242 | |
3063 | 3243 | // Can we pull this from the cache... please please? |
3064 | - if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) |
|
3065 | - return $temp; |
|
3244 | + if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) { |
|
3245 | + return $temp; |
|
3246 | + } |
|
3066 | 3247 | $t = microtime(); |
3067 | 3248 | |
3068 | 3249 | // Get the host to pester... |
@@ -3072,12 +3253,10 @@ discard block |
||
3072 | 3253 | if ($url == '' || $url == 'http://' || $url == 'https://') |
3073 | 3254 | { |
3074 | 3255 | return false; |
3075 | - } |
|
3076 | - elseif (!isset($match[1])) |
|
3256 | + } elseif (!isset($match[1])) |
|
3077 | 3257 | { |
3078 | 3258 | $size = @getimagesize($url); |
3079 | - } |
|
3080 | - else |
|
3259 | + } else |
|
3081 | 3260 | { |
3082 | 3261 | // Try to connect to the server... give it half a second. |
3083 | 3262 | $temp = 0; |
@@ -3114,12 +3293,14 @@ discard block |
||
3114 | 3293 | } |
3115 | 3294 | |
3116 | 3295 | // If we didn't get it, we failed. |
3117 | - if (!isset($size)) |
|
3118 | - $size = false; |
|
3296 | + if (!isset($size)) { |
|
3297 | + $size = false; |
|
3298 | + } |
|
3119 | 3299 | |
3120 | 3300 | // If this took a long time, we may never have to do it again, but then again we might... |
3121 | - if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) |
|
3122 | - cache_put_data('url_image_size-' . md5($url), $size, 240); |
|
3301 | + if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) { |
|
3302 | + cache_put_data('url_image_size-' . md5($url), $size, 240); |
|
3303 | + } |
|
3123 | 3304 | |
3124 | 3305 | // Didn't work. |
3125 | 3306 | return $size; |
@@ -3137,8 +3318,9 @@ discard block |
||
3137 | 3318 | |
3138 | 3319 | // Under SSI this function can be called more then once. That can cause some problems. |
3139 | 3320 | // So only run the function once unless we are forced to run it again. |
3140 | - if ($loaded && !$forceload) |
|
3141 | - return; |
|
3321 | + if ($loaded && !$forceload) { |
|
3322 | + return; |
|
3323 | + } |
|
3142 | 3324 | |
3143 | 3325 | $loaded = true; |
3144 | 3326 | |
@@ -3150,14 +3332,16 @@ discard block |
||
3150 | 3332 | $context['news_lines'] = array_filter(explode("\n", str_replace("\r", '', trim(addslashes($modSettings['news']))))); |
3151 | 3333 | for ($i = 0, $n = count($context['news_lines']); $i < $n; $i++) |
3152 | 3334 | { |
3153 | - if (trim($context['news_lines'][$i]) == '') |
|
3154 | - continue; |
|
3335 | + if (trim($context['news_lines'][$i]) == '') { |
|
3336 | + continue; |
|
3337 | + } |
|
3155 | 3338 | |
3156 | 3339 | // Clean it up for presentation ;). |
3157 | 3340 | $context['news_lines'][$i] = parse_bbc(stripslashes(trim($context['news_lines'][$i])), true, 'news' . $i); |
3158 | 3341 | } |
3159 | - if (!empty($context['news_lines'])) |
|
3160 | - $context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)]; |
|
3342 | + if (!empty($context['news_lines'])) { |
|
3343 | + $context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)]; |
|
3344 | + } |
|
3161 | 3345 | |
3162 | 3346 | if (!$user_info['is_guest']) |
3163 | 3347 | { |
@@ -3166,40 +3350,48 @@ discard block |
||
3166 | 3350 | $context['user']['alerts'] = &$user_info['alerts']; |
3167 | 3351 | |
3168 | 3352 | // Personal message popup... |
3169 | - if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) |
|
3170 | - $context['user']['popup_messages'] = true; |
|
3171 | - else |
|
3172 | - $context['user']['popup_messages'] = false; |
|
3353 | + if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) { |
|
3354 | + $context['user']['popup_messages'] = true; |
|
3355 | + } else { |
|
3356 | + $context['user']['popup_messages'] = false; |
|
3357 | + } |
|
3173 | 3358 | $_SESSION['unread_messages'] = $user_info['unread_messages']; |
3174 | 3359 | |
3175 | - if (allowedTo('moderate_forum')) |
|
3176 | - $context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0; |
|
3360 | + if (allowedTo('moderate_forum')) { |
|
3361 | + $context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0; |
|
3362 | + } |
|
3177 | 3363 | |
3178 | 3364 | $context['user']['avatar'] = array(); |
3179 | 3365 | |
3180 | 3366 | // Check for gravatar first since we might be forcing them... |
3181 | 3367 | if (($modSettings['gravatarEnabled'] && substr($user_info['avatar']['url'], 0, 11) == 'gravatar://') || !empty($modSettings['gravatarOverride'])) |
3182 | 3368 | { |
3183 | - if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) |
|
3184 | - $context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11)); |
|
3185 | - else |
|
3186 | - $context['user']['avatar']['href'] = get_gravatar_url($user_info['email']); |
|
3369 | + if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) { |
|
3370 | + $context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11)); |
|
3371 | + } else { |
|
3372 | + $context['user']['avatar']['href'] = get_gravatar_url($user_info['email']); |
|
3373 | + } |
|
3187 | 3374 | } |
3188 | 3375 | // Uploaded? |
3189 | - elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) |
|
3190 | - $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'; |
|
3376 | + elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) { |
|
3377 | + $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'; |
|
3378 | + } |
|
3191 | 3379 | // Full URL? |
3192 | - elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) |
|
3193 | - $context['user']['avatar']['href'] = $user_info['avatar']['url']; |
|
3380 | + elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) { |
|
3381 | + $context['user']['avatar']['href'] = $user_info['avatar']['url']; |
|
3382 | + } |
|
3194 | 3383 | // Otherwise we assume it's server stored. |
3195 | - elseif ($user_info['avatar']['url'] != '') |
|
3196 | - $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']); |
|
3384 | + elseif ($user_info['avatar']['url'] != '') { |
|
3385 | + $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']); |
|
3386 | + } |
|
3197 | 3387 | // No avatar at all? Fine, we have a big fat default avatar ;) |
3198 | - else |
|
3199 | - $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png'; |
|
3388 | + else { |
|
3389 | + $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png'; |
|
3390 | + } |
|
3200 | 3391 | |
3201 | - if (!empty($context['user']['avatar'])) |
|
3202 | - $context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">'; |
|
3392 | + if (!empty($context['user']['avatar'])) { |
|
3393 | + $context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">'; |
|
3394 | + } |
|
3203 | 3395 | |
3204 | 3396 | // Figure out how long they've been logged in. |
3205 | 3397 | $context['user']['total_time_logged_in'] = array( |
@@ -3207,8 +3399,7 @@ discard block |
||
3207 | 3399 | 'hours' => floor(($user_info['total_time_logged_in'] % 86400) / 3600), |
3208 | 3400 | 'minutes' => floor(($user_info['total_time_logged_in'] % 3600) / 60) |
3209 | 3401 | ); |
3210 | - } |
|
3211 | - else |
|
3402 | + } else |
|
3212 | 3403 | { |
3213 | 3404 | $context['user']['messages'] = 0; |
3214 | 3405 | $context['user']['unread_messages'] = 0; |
@@ -3216,12 +3407,14 @@ discard block |
||
3216 | 3407 | $context['user']['total_time_logged_in'] = array('days' => 0, 'hours' => 0, 'minutes' => 0); |
3217 | 3408 | $context['user']['popup_messages'] = false; |
3218 | 3409 | |
3219 | - if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) |
|
3220 | - $txt['welcome_guest'] .= $txt['welcome_guest_activate']; |
|
3410 | + if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) { |
|
3411 | + $txt['welcome_guest'] .= $txt['welcome_guest_activate']; |
|
3412 | + } |
|
3221 | 3413 | |
3222 | 3414 | // If we've upgraded recently, go easy on the passwords. |
3223 | - if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) |
|
3224 | - $context['disable_login_hashing'] = true; |
|
3415 | + if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) { |
|
3416 | + $context['disable_login_hashing'] = true; |
|
3417 | + } |
|
3225 | 3418 | } |
3226 | 3419 | |
3227 | 3420 | // Setup the main menu items. |
@@ -3234,8 +3427,8 @@ discard block |
||
3234 | 3427 | $context['show_pm_popup'] = $context['user']['popup_messages'] && !empty($options['popup_messages']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'pm'); |
3235 | 3428 | |
3236 | 3429 | // 2.1+: Add the PM popup here instead. Theme authors can still override it simply by editing/removing the 'fPmPopup' in the array. |
3237 | - if ($context['show_pm_popup']) |
|
3238 | - addInlineJavaScript(' |
|
3430 | + if ($context['show_pm_popup']) { |
|
3431 | + addInlineJavaScript(' |
|
3239 | 3432 | jQuery(document).ready(function($) { |
3240 | 3433 | new smc_Popup({ |
3241 | 3434 | heading: ' . JavaScriptEscape($txt['show_personal_messages_heading']) . ', |
@@ -3243,24 +3436,28 @@ discard block |
||
3243 | 3436 | icon_class: \'generic_icons mail_new\' |
3244 | 3437 | }); |
3245 | 3438 | });'); |
3439 | + } |
|
3246 | 3440 | |
3247 | 3441 | // Add a generic "Are you sure?" confirmation message. |
3248 | 3442 | addInlineJavaScript(' |
3249 | 3443 | var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';'); |
3250 | 3444 | |
3251 | 3445 | // Now add the capping code for avatars. |
3252 | - 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') |
|
3253 | - addInlineCss(' |
|
3446 | + 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') { |
|
3447 | + addInlineCss(' |
|
3254 | 3448 | img.avatar { max-width: ' . $modSettings['avatar_max_width_external'] . 'px; max-height: ' . $modSettings['avatar_max_height_external'] . 'px; }'); |
3449 | + } |
|
3255 | 3450 | |
3256 | 3451 | // Add max image limits |
3257 | - if (!empty($modSettings['max_image_width'])) |
|
3258 | - addInlineCss(' |
|
3452 | + if (!empty($modSettings['max_image_width'])) { |
|
3453 | + addInlineCss(' |
|
3259 | 3454 | .postarea .bbc_img { max-width: ' . $modSettings['max_image_width'] . 'px; }'); |
3455 | + } |
|
3260 | 3456 | |
3261 | - if (!empty($modSettings['max_image_height'])) |
|
3262 | - addInlineCss(' |
|
3457 | + if (!empty($modSettings['max_image_height'])) { |
|
3458 | + addInlineCss(' |
|
3263 | 3459 | .postarea .bbc_img { max-height: ' . $modSettings['max_image_height'] . 'px; }'); |
3460 | + } |
|
3264 | 3461 | |
3265 | 3462 | // This looks weird, but it's because BoardIndex.php references the variable. |
3266 | 3463 | $context['common_stats']['latest_member'] = array( |
@@ -3277,11 +3474,13 @@ discard block |
||
3277 | 3474 | ); |
3278 | 3475 | $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']); |
3279 | 3476 | |
3280 | - if (empty($settings['theme_version'])) |
|
3281 | - addJavaScriptVar('smf_scripturl', $scripturl); |
|
3477 | + if (empty($settings['theme_version'])) { |
|
3478 | + addJavaScriptVar('smf_scripturl', $scripturl); |
|
3479 | + } |
|
3282 | 3480 | |
3283 | - if (!isset($context['page_title'])) |
|
3284 | - $context['page_title'] = ''; |
|
3481 | + if (!isset($context['page_title'])) { |
|
3482 | + $context['page_title'] = ''; |
|
3483 | + } |
|
3285 | 3484 | |
3286 | 3485 | // Set some specific vars. |
3287 | 3486 | $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); |
@@ -3291,21 +3490,23 @@ discard block |
||
3291 | 3490 | $context['meta_tags'][] = array('property' => 'og:site_name', 'content' => $context['forum_name']); |
3292 | 3491 | $context['meta_tags'][] = array('property' => 'og:title', 'content' => $context['page_title_html_safe']); |
3293 | 3492 | |
3294 | - if (!empty($context['meta_keywords'])) |
|
3295 | - $context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']); |
|
3493 | + if (!empty($context['meta_keywords'])) { |
|
3494 | + $context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']); |
|
3495 | + } |
|
3296 | 3496 | |
3297 | - if (!empty($context['canonical_url'])) |
|
3298 | - $context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']); |
|
3497 | + if (!empty($context['canonical_url'])) { |
|
3498 | + $context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']); |
|
3499 | + } |
|
3299 | 3500 | |
3300 | - if (!empty($settings['og_image'])) |
|
3301 | - $context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']); |
|
3501 | + if (!empty($settings['og_image'])) { |
|
3502 | + $context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']); |
|
3503 | + } |
|
3302 | 3504 | |
3303 | 3505 | if (!empty($context['meta_description'])) |
3304 | 3506 | { |
3305 | 3507 | $context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['meta_description']); |
3306 | 3508 | $context['meta_tags'][] = array('name' => 'description', 'content' => $context['meta_description']); |
3307 | - } |
|
3308 | - else |
|
3509 | + } else |
|
3309 | 3510 | { |
3310 | 3511 | $context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['page_title_html_safe']); |
3311 | 3512 | $context['meta_tags'][] = array('name' => 'description', 'content' => $context['page_title_html_safe']); |
@@ -3330,8 +3531,9 @@ discard block |
||
3330 | 3531 | $memory_needed = memoryReturnBytes($needed); |
3331 | 3532 | |
3332 | 3533 | // should we account for how much is currently being used? |
3333 | - if ($in_use) |
|
3334 | - $memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576); |
|
3534 | + if ($in_use) { |
|
3535 | + $memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576); |
|
3536 | + } |
|
3335 | 3537 | |
3336 | 3538 | // if more is needed, request it |
3337 | 3539 | if ($memory_current < $memory_needed) |
@@ -3354,8 +3556,9 @@ discard block |
||
3354 | 3556 | */ |
3355 | 3557 | function memoryReturnBytes($val) |
3356 | 3558 | { |
3357 | - if (is_integer($val)) |
|
3358 | - return $val; |
|
3559 | + if (is_integer($val)) { |
|
3560 | + return $val; |
|
3561 | + } |
|
3359 | 3562 | |
3360 | 3563 | // Separate the number from the designator |
3361 | 3564 | $val = trim($val); |
@@ -3391,10 +3594,11 @@ discard block |
||
3391 | 3594 | header('last-modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); |
3392 | 3595 | |
3393 | 3596 | // Are we debugging the template/html content? |
3394 | - if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) |
|
3395 | - header('content-type: application/xhtml+xml'); |
|
3396 | - elseif (!isset($_REQUEST['xml'])) |
|
3397 | - header('content-type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
3597 | + if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) { |
|
3598 | + header('content-type: application/xhtml+xml'); |
|
3599 | + } elseif (!isset($_REQUEST['xml'])) { |
|
3600 | + header('content-type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
3601 | + } |
|
3398 | 3602 | } |
3399 | 3603 | |
3400 | 3604 | header('content-type: text/' . (isset($_REQUEST['xml']) ? 'xml' : 'html') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
@@ -3403,8 +3607,9 @@ discard block |
||
3403 | 3607 | if ($context['in_maintenance'] && $context['user']['is_admin']) |
3404 | 3608 | { |
3405 | 3609 | $position = array_search('body', $context['template_layers']); |
3406 | - if ($position === false) |
|
3407 | - $position = array_search('main', $context['template_layers']); |
|
3610 | + if ($position === false) { |
|
3611 | + $position = array_search('main', $context['template_layers']); |
|
3612 | + } |
|
3408 | 3613 | |
3409 | 3614 | if ($position !== false) |
3410 | 3615 | { |
@@ -3432,23 +3637,25 @@ discard block |
||
3432 | 3637 | |
3433 | 3638 | foreach ($securityFiles as $i => $securityFile) |
3434 | 3639 | { |
3435 | - if (!file_exists($boarddir . '/' . $securityFile)) |
|
3436 | - unset($securityFiles[$i]); |
|
3640 | + if (!file_exists($boarddir . '/' . $securityFile)) { |
|
3641 | + unset($securityFiles[$i]); |
|
3642 | + } |
|
3437 | 3643 | } |
3438 | 3644 | |
3439 | 3645 | // We are already checking so many files...just few more doesn't make any difference! :P |
3440 | - if (!empty($modSettings['currentAttachmentUploadDir'])) |
|
3441 | - $path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; |
|
3442 | - |
|
3443 | - else |
|
3444 | - $path = $modSettings['attachmentUploadDir']; |
|
3646 | + if (!empty($modSettings['currentAttachmentUploadDir'])) { |
|
3647 | + $path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; |
|
3648 | + } else { |
|
3649 | + $path = $modSettings['attachmentUploadDir']; |
|
3650 | + } |
|
3445 | 3651 | |
3446 | 3652 | secureDirectory($path, true); |
3447 | 3653 | secureDirectory($cachedir); |
3448 | 3654 | |
3449 | 3655 | // If agreement is enabled, at least the english version shall exists |
3450 | - if ($modSettings['requireAgreement']) |
|
3451 | - $agreement = !file_exists($boarddir . '/agreement.txt'); |
|
3656 | + if ($modSettings['requireAgreement']) { |
|
3657 | + $agreement = !file_exists($boarddir . '/agreement.txt'); |
|
3658 | + } |
|
3452 | 3659 | |
3453 | 3660 | if (!empty($securityFiles) || (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) || !empty($agreement)) |
3454 | 3661 | { |
@@ -3463,18 +3670,21 @@ discard block |
||
3463 | 3670 | echo ' |
3464 | 3671 | ', $txt['not_removed'], '<strong>', $securityFile, '</strong>!<br>'; |
3465 | 3672 | |
3466 | - if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') |
|
3467 | - echo ' |
|
3673 | + if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') { |
|
3674 | + echo ' |
|
3468 | 3675 | ', sprintf($txt['not_removed_extra'], $securityFile, substr($securityFile, 0, -1)), '<br>'; |
3676 | + } |
|
3469 | 3677 | } |
3470 | 3678 | |
3471 | - if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) |
|
3472 | - echo ' |
|
3679 | + if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) { |
|
3680 | + echo ' |
|
3473 | 3681 | <strong>', $txt['cache_writable'], '</strong><br>'; |
3682 | + } |
|
3474 | 3683 | |
3475 | - if (!empty($agreement)) |
|
3476 | - echo ' |
|
3684 | + if (!empty($agreement)) { |
|
3685 | + echo ' |
|
3477 | 3686 | <strong>', $txt['agreement_missing'], '</strong><br>'; |
3687 | + } |
|
3478 | 3688 | |
3479 | 3689 | echo ' |
3480 | 3690 | </p> |
@@ -3489,16 +3699,18 @@ discard block |
||
3489 | 3699 | <div class="windowbg alert" style="margin: 2ex; padding: 2ex; border: 2px dashed red;"> |
3490 | 3700 | ', sprintf($txt['you_are_post_banned'], $user_info['is_guest'] ? $txt['guest_title'] : $user_info['name']); |
3491 | 3701 | |
3492 | - if (!empty($_SESSION['ban']['cannot_post']['reason'])) |
|
3493 | - echo ' |
|
3702 | + if (!empty($_SESSION['ban']['cannot_post']['reason'])) { |
|
3703 | + echo ' |
|
3494 | 3704 | <div style="padding-left: 4ex; padding-top: 1ex;">', $_SESSION['ban']['cannot_post']['reason'], '</div>'; |
3705 | + } |
|
3495 | 3706 | |
3496 | - if (!empty($_SESSION['ban']['expire_time'])) |
|
3497 | - echo ' |
|
3707 | + if (!empty($_SESSION['ban']['expire_time'])) { |
|
3708 | + echo ' |
|
3498 | 3709 | <div>', sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)), '</div>'; |
3499 | - else |
|
3500 | - echo ' |
|
3710 | + } else { |
|
3711 | + echo ' |
|
3501 | 3712 | <div>', $txt['your_ban_expires_never'], '</div>'; |
3713 | + } |
|
3502 | 3714 | |
3503 | 3715 | echo ' |
3504 | 3716 | </div>'; |
@@ -3514,8 +3726,9 @@ discard block |
||
3514 | 3726 | global $forum_copyright, $software_year, $forum_version; |
3515 | 3727 | |
3516 | 3728 | // Don't display copyright for things like SSI. |
3517 | - if (!isset($forum_version) || !isset($software_year)) |
|
3518 | - return; |
|
3729 | + if (!isset($forum_version) || !isset($software_year)) { |
|
3730 | + return; |
|
3731 | + } |
|
3519 | 3732 | |
3520 | 3733 | // Put in the version... |
3521 | 3734 | printf($forum_copyright, $forum_version, $software_year); |
@@ -3533,9 +3746,10 @@ discard block |
||
3533 | 3746 | $context['load_time'] = round(microtime(true) - $time_start, 3); |
3534 | 3747 | $context['load_queries'] = $db_count; |
3535 | 3748 | |
3536 | - foreach (array_reverse($context['template_layers']) as $layer) |
|
3537 | - loadSubTemplate($layer . '_below', true); |
|
3538 | -} |
|
3749 | + foreach (array_reverse($context['template_layers']) as $layer) { |
|
3750 | + loadSubTemplate($layer . '_below', true); |
|
3751 | + } |
|
3752 | + } |
|
3539 | 3753 | |
3540 | 3754 | /** |
3541 | 3755 | * Output the Javascript files |
@@ -3566,8 +3780,7 @@ discard block |
||
3566 | 3780 | { |
3567 | 3781 | echo ' |
3568 | 3782 | var ', $key, ';'; |
3569 | - } |
|
3570 | - else |
|
3783 | + } else |
|
3571 | 3784 | { |
3572 | 3785 | echo ' |
3573 | 3786 | var ', $key, ' = ', $value, ';'; |
@@ -3582,26 +3795,27 @@ discard block |
||
3582 | 3795 | foreach ($context['javascript_files'] as $id => $js_file) |
3583 | 3796 | { |
3584 | 3797 | // Last minute call! allow theme authors to disable single files. |
3585 | - if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) |
|
3586 | - continue; |
|
3798 | + if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) { |
|
3799 | + continue; |
|
3800 | + } |
|
3587 | 3801 | |
3588 | 3802 | // By default all files don't get minimized unless the file explicitly says so! |
3589 | 3803 | if (!empty($js_file['options']['minimize']) && !empty($modSettings['minimize_files'])) |
3590 | 3804 | { |
3591 | - if ($do_deferred && !empty($js_file['options']['defer'])) |
|
3592 | - $toMinifyDefer[] = $js_file; |
|
3593 | - |
|
3594 | - elseif (!$do_deferred && empty($js_file['options']['defer'])) |
|
3595 | - $toMinify[] = $js_file; |
|
3805 | + if ($do_deferred && !empty($js_file['options']['defer'])) { |
|
3806 | + $toMinifyDefer[] = $js_file; |
|
3807 | + } elseif (!$do_deferred && empty($js_file['options']['defer'])) { |
|
3808 | + $toMinify[] = $js_file; |
|
3809 | + } |
|
3596 | 3810 | |
3597 | 3811 | // Grab a random seed. |
3598 | - if (!isset($minSeed) && isset($js_file['options']['seed'])) |
|
3599 | - $minSeed = $js_file['options']['seed']; |
|
3600 | - } |
|
3601 | - |
|
3602 | - elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer']))) |
|
3603 | - echo ' |
|
3812 | + if (!isset($minSeed) && isset($js_file['options']['seed'])) { |
|
3813 | + $minSeed = $js_file['options']['seed']; |
|
3814 | + } |
|
3815 | + } elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer']))) { |
|
3816 | + echo ' |
|
3604 | 3817 | <script src="', $js_file['fileUrl'], '"', !empty($js_file['options']['async']) ? ' async="async"' : '', '></script>'; |
3818 | + } |
|
3605 | 3819 | } |
3606 | 3820 | |
3607 | 3821 | if ((!$do_deferred && !empty($toMinify)) || ($do_deferred && !empty($toMinifyDefer))) |
@@ -3610,9 +3824,10 @@ discard block |
||
3610 | 3824 | |
3611 | 3825 | $minSuccessful = array_keys($result) === array('smf_minified'); |
3612 | 3826 | |
3613 | - foreach ($result as $minFile) |
|
3614 | - echo ' |
|
3827 | + foreach ($result as $minFile) { |
|
3828 | + echo ' |
|
3615 | 3829 | <script src="', $minFile['fileUrl'], $minSuccessful && isset($minSeed) ? $minSeed : '', '"', !empty($minFile['options']['async']) ? ' async="async"' : '', '></script>'; |
3830 | + } |
|
3616 | 3831 | |
3617 | 3832 | } |
3618 | 3833 | |
@@ -3624,8 +3839,9 @@ discard block |
||
3624 | 3839 | echo ' |
3625 | 3840 | <script>'; |
3626 | 3841 | |
3627 | - foreach ($context['javascript_inline']['defer'] as $js_code) |
|
3628 | - echo $js_code; |
|
3842 | + foreach ($context['javascript_inline']['defer'] as $js_code) { |
|
3843 | + echo $js_code; |
|
3844 | + } |
|
3629 | 3845 | |
3630 | 3846 | echo ' |
3631 | 3847 | </script>'; |
@@ -3636,8 +3852,9 @@ discard block |
||
3636 | 3852 | echo ' |
3637 | 3853 | <script>'; |
3638 | 3854 | |
3639 | - foreach ($context['javascript_inline']['standard'] as $js_code) |
|
3640 | - echo $js_code; |
|
3855 | + foreach ($context['javascript_inline']['standard'] as $js_code) { |
|
3856 | + echo $js_code; |
|
3857 | + } |
|
3641 | 3858 | |
3642 | 3859 | echo ' |
3643 | 3860 | </script>'; |
@@ -3665,23 +3882,26 @@ discard block |
||
3665 | 3882 | foreach ($context['css_files'] as $id => $file) |
3666 | 3883 | { |
3667 | 3884 | // Last minute call! allow theme authors to disable single files. |
3668 | - if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) |
|
3669 | - continue; |
|
3885 | + if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) { |
|
3886 | + continue; |
|
3887 | + } |
|
3670 | 3888 | |
3671 | 3889 | // Files are minimized unless they explicitly opt out. |
3672 | - if (!isset($file['options']['minimize'])) |
|
3673 | - $file['options']['minimize'] = true; |
|
3890 | + if (!isset($file['options']['minimize'])) { |
|
3891 | + $file['options']['minimize'] = true; |
|
3892 | + } |
|
3674 | 3893 | |
3675 | 3894 | if (!empty($file['options']['minimize']) && !empty($modSettings['minimize_files'])) |
3676 | 3895 | { |
3677 | 3896 | $toMinify[] = $file; |
3678 | 3897 | |
3679 | 3898 | // Grab a random seed. |
3680 | - if (!isset($minSeed) && isset($file['options']['seed'])) |
|
3681 | - $minSeed = $file['options']['seed']; |
|
3899 | + if (!isset($minSeed) && isset($file['options']['seed'])) { |
|
3900 | + $minSeed = $file['options']['seed']; |
|
3901 | + } |
|
3902 | + } else { |
|
3903 | + $normal[] = $file['fileUrl']; |
|
3682 | 3904 | } |
3683 | - else |
|
3684 | - $normal[] = $file['fileUrl']; |
|
3685 | 3905 | } |
3686 | 3906 | |
3687 | 3907 | if (!empty($toMinify)) |
@@ -3690,23 +3910,26 @@ discard block |
||
3690 | 3910 | |
3691 | 3911 | $minSuccessful = array_keys($result) === array('smf_minified'); |
3692 | 3912 | |
3693 | - foreach ($result as $minFile) |
|
3694 | - echo ' |
|
3913 | + foreach ($result as $minFile) { |
|
3914 | + echo ' |
|
3695 | 3915 | <link rel="stylesheet" href="', $minFile['fileUrl'], $minSuccessful && isset($minSeed) ? $minSeed : '', '">'; |
3916 | + } |
|
3696 | 3917 | } |
3697 | 3918 | |
3698 | 3919 | // Print the rest after the minified files. |
3699 | - if (!empty($normal)) |
|
3700 | - foreach ($normal as $nf) |
|
3920 | + if (!empty($normal)) { |
|
3921 | + foreach ($normal as $nf) |
|
3701 | 3922 | echo ' |
3702 | 3923 | <link rel="stylesheet" href="', $nf ,'">'; |
3924 | + } |
|
3703 | 3925 | |
3704 | 3926 | if ($db_show_debug === true) |
3705 | 3927 | { |
3706 | 3928 | // Try to keep only what's useful. |
3707 | 3929 | $repl = array($boardurl . '/Themes/' => '', $boardurl . '/' => ''); |
3708 | - foreach ($context['css_files'] as $file) |
|
3709 | - $context['debug']['sheets'][] = strtr($file['fileName'], $repl); |
|
3930 | + foreach ($context['css_files'] as $file) { |
|
3931 | + $context['debug']['sheets'][] = strtr($file['fileName'], $repl); |
|
3932 | + } |
|
3710 | 3933 | } |
3711 | 3934 | |
3712 | 3935 | if (!empty($context['css_header'])) |
@@ -3714,9 +3937,10 @@ discard block |
||
3714 | 3937 | echo ' |
3715 | 3938 | <style>'; |
3716 | 3939 | |
3717 | - foreach ($context['css_header'] as $css) |
|
3718 | - echo $css .' |
|
3940 | + foreach ($context['css_header'] as $css) { |
|
3941 | + echo $css .' |
|
3719 | 3942 | '; |
3943 | + } |
|
3720 | 3944 | |
3721 | 3945 | echo' |
3722 | 3946 | </style>'; |
@@ -3740,8 +3964,9 @@ discard block |
||
3740 | 3964 | $type = !empty($type) && in_array($type, $types) ? $type : false; |
3741 | 3965 | $data = !empty($data) ? $data : false; |
3742 | 3966 | |
3743 | - if (empty($type) || empty($data)) |
|
3744 | - return (array) $data; |
|
3967 | + if (empty($type) || empty($data)) { |
|
3968 | + return (array) $data; |
|
3969 | + } |
|
3745 | 3970 | |
3746 | 3971 | // Different pages include different files, so we use a hash to label the different combinations |
3747 | 3972 | $hash = md5(implode(' ', array_map(function($file) { return $file['filePath'] . md5_file($file['filePath']); }, $data))); |
@@ -3750,13 +3975,14 @@ discard block |
||
3750 | 3975 | list($toCache, $async) = array_pad((array) cache_get_data('minimized_' . $settings['theme_id'] . '_' . $type . '_' . $hash, 86400), 2, null); |
3751 | 3976 | |
3752 | 3977 | // Already done? |
3753 | - if (!empty($toCache)) |
|
3754 | - return array('smf_minified' => array( |
|
3978 | + if (!empty($toCache)) { |
|
3979 | + return array('smf_minified' => array( |
|
3755 | 3980 | 'fileUrl' => $settings['theme_url'] . '/' . ($type == 'css' ? 'css' : 'scripts') . '/' . basename($toCache), |
3756 | 3981 | 'filePath' => $toCache, |
3757 | 3982 | 'fileName' => basename($toCache), |
3758 | 3983 | 'options' => array('async' => !empty($async)), |
3759 | 3984 | )); |
3985 | + } |
|
3760 | 3986 | |
3761 | 3987 | |
3762 | 3988 | // No namespaces, sorry! |
@@ -3789,8 +4015,9 @@ discard block |
||
3789 | 4015 | $toAdd = file_exists($tempFile) ? $tempFile : false; |
3790 | 4016 | |
3791 | 4017 | // A minified script should only be loaded asynchronously if all its components wanted to be. |
3792 | - if (empty($file['options']['async'])) |
|
3793 | - $async = false; |
|
4018 | + if (empty($file['options']['async'])) { |
|
4019 | + $async = false; |
|
4020 | + } |
|
3794 | 4021 | |
3795 | 4022 | // The file couldn't be located so it won't be added. Log this error. |
3796 | 4023 | if (empty($toAdd)) |
@@ -3856,12 +4083,14 @@ discard block |
||
3856 | 4083 | foreach (glob(rtrim($theme['dir'], '/') . '/' . ($type == 'css' ? 'css' : 'scripts') . '/minified*.' . $type) as $filename) |
3857 | 4084 | { |
3858 | 4085 | // Remove the cache entry |
3859 | - if (preg_match('~([a-zA-Z0-9]+)\.' . $type . '$~', $filename, $matches)) |
|
3860 | - cache_put_data('minimized_' . $theme['id'] . '_' . $type . '_' . $matches[1], null); |
|
4086 | + if (preg_match('~([a-zA-Z0-9]+)\.' . $type . '$~', $filename, $matches)) { |
|
4087 | + cache_put_data('minimized_' . $theme['id'] . '_' . $type . '_' . $matches[1], null); |
|
4088 | + } |
|
3861 | 4089 | |
3862 | 4090 | // Try to delete the file. Add it to our error list if it fails. |
3863 | - if (!@unlink($filename)) |
|
3864 | - $not_deleted[] = $filename; |
|
4091 | + if (!@unlink($filename)) { |
|
4092 | + $not_deleted[] = $filename; |
|
4093 | + } |
|
3865 | 4094 | } |
3866 | 4095 | } |
3867 | 4096 | } |
@@ -3893,8 +4122,9 @@ discard block |
||
3893 | 4122 | global $modSettings, $smcFunc; |
3894 | 4123 | |
3895 | 4124 | // Just make up a nice hash... |
3896 | - if ($new) |
|
3897 | - return sha1(md5($filename . time()) . mt_rand()); |
|
4125 | + if ($new) { |
|
4126 | + return sha1(md5($filename . time()) . mt_rand()); |
|
4127 | + } |
|
3898 | 4128 | |
3899 | 4129 | // Just make sure that attachment id is only a int |
3900 | 4130 | $attachment_id = (int) $attachment_id; |
@@ -3911,23 +4141,25 @@ discard block |
||
3911 | 4141 | 'id_attach' => $attachment_id, |
3912 | 4142 | )); |
3913 | 4143 | |
3914 | - if ($smcFunc['db_num_rows']($request) === 0) |
|
3915 | - return false; |
|
4144 | + if ($smcFunc['db_num_rows']($request) === 0) { |
|
4145 | + return false; |
|
4146 | + } |
|
3916 | 4147 | |
3917 | 4148 | list ($file_hash) = $smcFunc['db_fetch_row']($request); |
3918 | 4149 | $smcFunc['db_free_result']($request); |
3919 | 4150 | } |
3920 | 4151 | |
3921 | 4152 | // Still no hash? mmm... |
3922 | - if (empty($file_hash)) |
|
3923 | - $file_hash = sha1(md5($filename . time()) . mt_rand()); |
|
4153 | + if (empty($file_hash)) { |
|
4154 | + $file_hash = sha1(md5($filename . time()) . mt_rand()); |
|
4155 | + } |
|
3924 | 4156 | |
3925 | 4157 | // Are we using multiple directories? |
3926 | - if (is_array($modSettings['attachmentUploadDir'])) |
|
3927 | - $path = $modSettings['attachmentUploadDir'][$dir]; |
|
3928 | - |
|
3929 | - else |
|
3930 | - $path = $modSettings['attachmentUploadDir']; |
|
4158 | + if (is_array($modSettings['attachmentUploadDir'])) { |
|
4159 | + $path = $modSettings['attachmentUploadDir'][$dir]; |
|
4160 | + } else { |
|
4161 | + $path = $modSettings['attachmentUploadDir']; |
|
4162 | + } |
|
3931 | 4163 | |
3932 | 4164 | return $path . '/' . $attachment_id . '_' . $file_hash .'.dat'; |
3933 | 4165 | } |
@@ -3942,8 +4174,9 @@ discard block |
||
3942 | 4174 | function ip2range($fullip) |
3943 | 4175 | { |
3944 | 4176 | // Pretend that 'unknown' is 255.255.255.255. (since that can't be an IP anyway.) |
3945 | - if ($fullip == 'unknown') |
|
3946 | - $fullip = '255.255.255.255'; |
|
4177 | + if ($fullip == 'unknown') { |
|
4178 | + $fullip = '255.255.255.255'; |
|
4179 | + } |
|
3947 | 4180 | |
3948 | 4181 | $ip_parts = explode('-', $fullip); |
3949 | 4182 | $ip_array = array(); |
@@ -3967,10 +4200,11 @@ discard block |
||
3967 | 4200 | $ip_array['low'] = $ip_parts[0]; |
3968 | 4201 | $ip_array['high'] = $ip_parts[1]; |
3969 | 4202 | return $ip_array; |
3970 | - } |
|
3971 | - elseif (count($ip_parts) == 2) // if ip 22.22.*-22.22.* |
|
4203 | + } elseif (count($ip_parts) == 2) { |
|
4204 | + // if ip 22.22.*-22.22.* |
|
3972 | 4205 | { |
3973 | 4206 | $valid_low = isValidIP($ip_parts[0]); |
4207 | + } |
|
3974 | 4208 | $valid_high = isValidIP($ip_parts[1]); |
3975 | 4209 | $count = 0; |
3976 | 4210 | $mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.'); |
@@ -3985,7 +4219,9 @@ discard block |
||
3985 | 4219 | $ip_parts[0] .= $mode . $min; |
3986 | 4220 | $valid_low = isValidIP($ip_parts[0]); |
3987 | 4221 | $count++; |
3988 | - if ($count > 9) break; |
|
4222 | + if ($count > 9) { |
|
4223 | + break; |
|
4224 | + } |
|
3989 | 4225 | } |
3990 | 4226 | } |
3991 | 4227 | |
@@ -3999,7 +4235,9 @@ discard block |
||
3999 | 4235 | $ip_parts[1] .= $mode . $max; |
4000 | 4236 | $valid_high = isValidIP($ip_parts[1]); |
4001 | 4237 | $count++; |
4002 | - if ($count > 9) break; |
|
4238 | + if ($count > 9) { |
|
4239 | + break; |
|
4240 | + } |
|
4003 | 4241 | } |
4004 | 4242 | } |
4005 | 4243 | |
@@ -4024,46 +4262,54 @@ discard block |
||
4024 | 4262 | { |
4025 | 4263 | global $modSettings; |
4026 | 4264 | |
4027 | - if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) |
|
4028 | - return $host; |
|
4265 | + if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) { |
|
4266 | + return $host; |
|
4267 | + } |
|
4029 | 4268 | $t = microtime(); |
4030 | 4269 | |
4031 | 4270 | // Try the Linux host command, perhaps? |
4032 | 4271 | if (!isset($host) && (strpos(strtolower(PHP_OS), 'win') === false || strpos(strtolower(PHP_OS), 'darwin') !== false) && mt_rand(0, 1) == 1) |
4033 | 4272 | { |
4034 | - if (!isset($modSettings['host_to_dis'])) |
|
4035 | - $test = @shell_exec('host -W 1 ' . @escapeshellarg($ip)); |
|
4036 | - else |
|
4037 | - $test = @shell_exec('host ' . @escapeshellarg($ip)); |
|
4273 | + if (!isset($modSettings['host_to_dis'])) { |
|
4274 | + $test = @shell_exec('host -W 1 ' . @escapeshellarg($ip)); |
|
4275 | + } else { |
|
4276 | + $test = @shell_exec('host ' . @escapeshellarg($ip)); |
|
4277 | + } |
|
4038 | 4278 | |
4039 | 4279 | // Did host say it didn't find anything? |
4040 | - if (strpos($test, 'not found') !== false) |
|
4041 | - $host = ''; |
|
4280 | + if (strpos($test, 'not found') !== false) { |
|
4281 | + $host = ''; |
|
4282 | + } |
|
4042 | 4283 | // Invalid server option? |
4043 | - elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) |
|
4044 | - updateSettings(array('host_to_dis' => 1)); |
|
4284 | + elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) { |
|
4285 | + updateSettings(array('host_to_dis' => 1)); |
|
4286 | + } |
|
4045 | 4287 | // Maybe it found something, after all? |
4046 | - elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) |
|
4047 | - $host = $match[1]; |
|
4288 | + elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) { |
|
4289 | + $host = $match[1]; |
|
4290 | + } |
|
4048 | 4291 | } |
4049 | 4292 | |
4050 | 4293 | // This is nslookup; usually only Windows, but possibly some Unix? |
4051 | 4294 | if (!isset($host) && stripos(PHP_OS, 'win') !== false && strpos(strtolower(PHP_OS), 'darwin') === false && mt_rand(0, 1) == 1) |
4052 | 4295 | { |
4053 | 4296 | $test = @shell_exec('nslookup -timeout=1 ' . @escapeshellarg($ip)); |
4054 | - if (strpos($test, 'Non-existent domain') !== false) |
|
4055 | - $host = ''; |
|
4056 | - elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) |
|
4057 | - $host = $match[1]; |
|
4297 | + if (strpos($test, 'Non-existent domain') !== false) { |
|
4298 | + $host = ''; |
|
4299 | + } elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) { |
|
4300 | + $host = $match[1]; |
|
4301 | + } |
|
4058 | 4302 | } |
4059 | 4303 | |
4060 | 4304 | // This is the last try :/. |
4061 | - if (!isset($host) || $host === false) |
|
4062 | - $host = @gethostbyaddr($ip); |
|
4305 | + if (!isset($host) || $host === false) { |
|
4306 | + $host = @gethostbyaddr($ip); |
|
4307 | + } |
|
4063 | 4308 | |
4064 | 4309 | // It took a long time, so let's cache it! |
4065 | - if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) |
|
4066 | - cache_put_data('hostlookup-' . $ip, $host, 600); |
|
4310 | + if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) { |
|
4311 | + cache_put_data('hostlookup-' . $ip, $host, 600); |
|
4312 | + } |
|
4067 | 4313 | |
4068 | 4314 | return $host; |
4069 | 4315 | } |
@@ -4099,20 +4345,21 @@ discard block |
||
4099 | 4345 | { |
4100 | 4346 | $encrypted = substr(crypt($word, 'uk'), 2, $max_chars); |
4101 | 4347 | $total = 0; |
4102 | - for ($i = 0; $i < $max_chars; $i++) |
|
4103 | - $total += $possible_chars[ord($encrypted{$i})] * pow(63, $i); |
|
4348 | + for ($i = 0; $i < $max_chars; $i++) { |
|
4349 | + $total += $possible_chars[ord($encrypted{$i})] * pow(63, $i); |
|
4350 | + } |
|
4104 | 4351 | $returned_ints[] = $max_chars == 4 ? min($total, 16777215) : $total; |
4105 | 4352 | } |
4106 | 4353 | } |
4107 | 4354 | return array_unique($returned_ints); |
4108 | - } |
|
4109 | - else |
|
4355 | + } else |
|
4110 | 4356 | { |
4111 | 4357 | // Trim characters before and after and add slashes for database insertion. |
4112 | 4358 | $returned_words = array(); |
4113 | - foreach ($words as $word) |
|
4114 | - if (($word = trim($word, '-_\'')) !== '') |
|
4359 | + foreach ($words as $word) { |
|
4360 | + if (($word = trim($word, '-_\'')) !== '') |
|
4115 | 4361 | $returned_words[] = $max_chars === null ? $word : substr($word, 0, $max_chars); |
4362 | + } |
|
4116 | 4363 | |
4117 | 4364 | // Filter out all words that occur more than once. |
4118 | 4365 | return array_unique($returned_words); |
@@ -4134,16 +4381,18 @@ discard block |
||
4134 | 4381 | global $settings, $txt; |
4135 | 4382 | |
4136 | 4383 | // Does the current loaded theme have this and we are not forcing the usage of this function? |
4137 | - if (function_exists('template_create_button') && !$force_use) |
|
4138 | - return template_create_button($name, $alt, $label = '', $custom = ''); |
|
4384 | + if (function_exists('template_create_button') && !$force_use) { |
|
4385 | + return template_create_button($name, $alt, $label = '', $custom = ''); |
|
4386 | + } |
|
4139 | 4387 | |
4140 | - if (!$settings['use_image_buttons']) |
|
4141 | - return $txt[$alt]; |
|
4142 | - elseif (!empty($settings['use_buttons'])) |
|
4143 | - return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? ' <strong>' . $txt[$label] . '</strong>' : ''); |
|
4144 | - else |
|
4145 | - return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>'; |
|
4146 | -} |
|
4388 | + if (!$settings['use_image_buttons']) { |
|
4389 | + return $txt[$alt]; |
|
4390 | + } elseif (!empty($settings['use_buttons'])) { |
|
4391 | + return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? ' <strong>' . $txt[$label] . '</strong>' : ''); |
|
4392 | + } else { |
|
4393 | + return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>'; |
|
4394 | + } |
|
4395 | + } |
|
4147 | 4396 | |
4148 | 4397 | /** |
4149 | 4398 | * Sets up all of the top menu buttons |
@@ -4186,9 +4435,10 @@ discard block |
||
4186 | 4435 | var user_menus = new smc_PopupMenu(); |
4187 | 4436 | user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup"); |
4188 | 4437 | user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true); |
4189 | - if ($context['allow_pm']) |
|
4190 | - addInlineJavaScript(' |
|
4438 | + if ($context['allow_pm']) { |
|
4439 | + addInlineJavaScript(' |
|
4191 | 4440 | user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true); |
4441 | + } |
|
4192 | 4442 | |
4193 | 4443 | if (!empty($modSettings['enable_ajax_alerts'])) |
4194 | 4444 | { |
@@ -4348,88 +4598,96 @@ discard block |
||
4348 | 4598 | |
4349 | 4599 | // Now we put the buttons in the context so the theme can use them. |
4350 | 4600 | $menu_buttons = array(); |
4351 | - foreach ($buttons as $act => $button) |
|
4352 | - if (!empty($button['show'])) |
|
4601 | + foreach ($buttons as $act => $button) { |
|
4602 | + if (!empty($button['show'])) |
|
4353 | 4603 | { |
4354 | 4604 | $button['active_button'] = false; |
4605 | + } |
|
4355 | 4606 | |
4356 | 4607 | // This button needs some action. |
4357 | - if (isset($button['action_hook'])) |
|
4358 | - $needs_action_hook = true; |
|
4608 | + if (isset($button['action_hook'])) { |
|
4609 | + $needs_action_hook = true; |
|
4610 | + } |
|
4359 | 4611 | |
4360 | 4612 | // Make sure the last button truly is the last button. |
4361 | 4613 | if (!empty($button['is_last'])) |
4362 | 4614 | { |
4363 | - if (isset($last_button)) |
|
4364 | - unset($menu_buttons[$last_button]['is_last']); |
|
4615 | + if (isset($last_button)) { |
|
4616 | + unset($menu_buttons[$last_button]['is_last']); |
|
4617 | + } |
|
4365 | 4618 | $last_button = $act; |
4366 | 4619 | } |
4367 | 4620 | |
4368 | 4621 | // Go through the sub buttons if there are any. |
4369 | - if (!empty($button['sub_buttons'])) |
|
4370 | - foreach ($button['sub_buttons'] as $key => $subbutton) |
|
4622 | + if (!empty($button['sub_buttons'])) { |
|
4623 | + foreach ($button['sub_buttons'] as $key => $subbutton) |
|
4371 | 4624 | { |
4372 | 4625 | if (empty($subbutton['show'])) |
4373 | 4626 | unset($button['sub_buttons'][$key]); |
4627 | + } |
|
4374 | 4628 | |
4375 | 4629 | // 2nd level sub buttons next... |
4376 | 4630 | if (!empty($subbutton['sub_buttons'])) |
4377 | 4631 | { |
4378 | 4632 | foreach ($subbutton['sub_buttons'] as $key2 => $sub_button2) |
4379 | 4633 | { |
4380 | - if (empty($sub_button2['show'])) |
|
4381 | - unset($button['sub_buttons'][$key]['sub_buttons'][$key2]); |
|
4634 | + if (empty($sub_button2['show'])) { |
|
4635 | + unset($button['sub_buttons'][$key]['sub_buttons'][$key2]); |
|
4636 | + } |
|
4382 | 4637 | } |
4383 | 4638 | } |
4384 | 4639 | } |
4385 | 4640 | |
4386 | 4641 | // Does this button have its own icon? |
4387 | - if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) |
|
4388 | - $button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
4389 | - elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) |
|
4390 | - $button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
4391 | - elseif (isset($button['icon'])) |
|
4392 | - $button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>'; |
|
4393 | - else |
|
4394 | - $button['icon'] = '<span class="generic_icons ' . $act . '"></span>'; |
|
4642 | + if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) { |
|
4643 | + $button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
4644 | + } elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) { |
|
4645 | + $button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
4646 | + } elseif (isset($button['icon'])) { |
|
4647 | + $button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>'; |
|
4648 | + } else { |
|
4649 | + $button['icon'] = '<span class="generic_icons ' . $act . '"></span>'; |
|
4650 | + } |
|
4395 | 4651 | |
4396 | 4652 | $menu_buttons[$act] = $button; |
4397 | 4653 | } |
4398 | 4654 | |
4399 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
4400 | - cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime); |
|
4655 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
4656 | + cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime); |
|
4657 | + } |
|
4401 | 4658 | } |
4402 | 4659 | |
4403 | 4660 | $context['menu_buttons'] = $menu_buttons; |
4404 | 4661 | |
4405 | 4662 | // Logging out requires the session id in the url. |
4406 | - if (isset($context['menu_buttons']['logout'])) |
|
4407 | - $context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']); |
|
4663 | + if (isset($context['menu_buttons']['logout'])) { |
|
4664 | + $context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']); |
|
4665 | + } |
|
4408 | 4666 | |
4409 | 4667 | // Figure out which action we are doing so we can set the active tab. |
4410 | 4668 | // Default to home. |
4411 | 4669 | $current_action = 'home'; |
4412 | 4670 | |
4413 | - if (isset($context['menu_buttons'][$context['current_action']])) |
|
4414 | - $current_action = $context['current_action']; |
|
4415 | - elseif ($context['current_action'] == 'search2') |
|
4416 | - $current_action = 'search'; |
|
4417 | - elseif ($context['current_action'] == 'theme') |
|
4418 | - $current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin'; |
|
4419 | - elseif ($context['current_action'] == 'register2') |
|
4420 | - $current_action = 'register'; |
|
4421 | - elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) |
|
4422 | - $current_action = 'login'; |
|
4423 | - elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) |
|
4424 | - $current_action = 'moderate'; |
|
4671 | + if (isset($context['menu_buttons'][$context['current_action']])) { |
|
4672 | + $current_action = $context['current_action']; |
|
4673 | + } elseif ($context['current_action'] == 'search2') { |
|
4674 | + $current_action = 'search'; |
|
4675 | + } elseif ($context['current_action'] == 'theme') { |
|
4676 | + $current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin'; |
|
4677 | + } elseif ($context['current_action'] == 'register2') { |
|
4678 | + $current_action = 'register'; |
|
4679 | + } elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) { |
|
4680 | + $current_action = 'login'; |
|
4681 | + } elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) { |
|
4682 | + $current_action = 'moderate'; |
|
4683 | + } |
|
4425 | 4684 | |
4426 | 4685 | // There are certain exceptions to the above where we don't want anything on the menu highlighted. |
4427 | 4686 | if ($context['current_action'] == 'profile' && !empty($context['user']['is_owner'])) |
4428 | 4687 | { |
4429 | 4688 | $current_action = !empty($_GET['area']) && $_GET['area'] == 'showalerts' ? 'self_alerts' : 'self_profile'; |
4430 | 4689 | $context[$current_action] = true; |
4431 | - } |
|
4432 | - elseif ($context['current_action'] == 'pm') |
|
4690 | + } elseif ($context['current_action'] == 'pm') |
|
4433 | 4691 | { |
4434 | 4692 | $current_action = 'self_pm'; |
4435 | 4693 | $context['self_pm'] = true; |
@@ -4486,12 +4744,14 @@ discard block |
||
4486 | 4744 | } |
4487 | 4745 | |
4488 | 4746 | // Not all actions are simple. |
4489 | - if (!empty($needs_action_hook)) |
|
4490 | - call_integration_hook('integrate_current_action', array(&$current_action)); |
|
4747 | + if (!empty($needs_action_hook)) { |
|
4748 | + call_integration_hook('integrate_current_action', array(&$current_action)); |
|
4749 | + } |
|
4491 | 4750 | |
4492 | - if (isset($context['menu_buttons'][$current_action])) |
|
4493 | - $context['menu_buttons'][$current_action]['active_button'] = true; |
|
4494 | -} |
|
4751 | + if (isset($context['menu_buttons'][$current_action])) { |
|
4752 | + $context['menu_buttons'][$current_action]['active_button'] = true; |
|
4753 | + } |
|
4754 | + } |
|
4495 | 4755 | |
4496 | 4756 | /** |
4497 | 4757 | * Generate a random seed and ensure it's stored in settings. |
@@ -4515,30 +4775,35 @@ discard block |
||
4515 | 4775 | global $modSettings, $settings, $boarddir, $sourcedir, $db_show_debug; |
4516 | 4776 | global $context, $txt; |
4517 | 4777 | |
4518 | - if ($db_show_debug === true) |
|
4519 | - $context['debug']['hooks'][] = $hook; |
|
4778 | + if ($db_show_debug === true) { |
|
4779 | + $context['debug']['hooks'][] = $hook; |
|
4780 | + } |
|
4520 | 4781 | |
4521 | 4782 | // Need to have some control. |
4522 | - if (!isset($context['instances'])) |
|
4523 | - $context['instances'] = array(); |
|
4783 | + if (!isset($context['instances'])) { |
|
4784 | + $context['instances'] = array(); |
|
4785 | + } |
|
4524 | 4786 | |
4525 | 4787 | $results = array(); |
4526 | - if (empty($modSettings[$hook])) |
|
4527 | - return $results; |
|
4788 | + if (empty($modSettings[$hook])) { |
|
4789 | + return $results; |
|
4790 | + } |
|
4528 | 4791 | |
4529 | 4792 | $functions = explode(',', $modSettings[$hook]); |
4530 | 4793 | // Loop through each function. |
4531 | 4794 | foreach ($functions as $function) |
4532 | 4795 | { |
4533 | 4796 | // Hook has been marked as "disabled". Skip it! |
4534 | - if (strpos($function, '!') !== false) |
|
4535 | - continue; |
|
4797 | + if (strpos($function, '!') !== false) { |
|
4798 | + continue; |
|
4799 | + } |
|
4536 | 4800 | |
4537 | 4801 | $call = call_helper($function, true); |
4538 | 4802 | |
4539 | 4803 | // Is it valid? |
4540 | - if (!empty($call)) |
|
4541 | - $results[$function] = call_user_func_array($call, $parameters); |
|
4804 | + if (!empty($call)) { |
|
4805 | + $results[$function] = call_user_func_array($call, $parameters); |
|
4806 | + } |
|
4542 | 4807 | |
4543 | 4808 | // Whatever it was suppose to call, it failed :( |
4544 | 4809 | elseif (!empty($function)) |
@@ -4554,8 +4819,9 @@ discard block |
||
4554 | 4819 | } |
4555 | 4820 | |
4556 | 4821 | // "Assume" the file resides on $boarddir somewhere... |
4557 | - else |
|
4558 | - log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general'); |
|
4822 | + else { |
|
4823 | + log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general'); |
|
4824 | + } |
|
4559 | 4825 | } |
4560 | 4826 | } |
4561 | 4827 | |
@@ -4577,12 +4843,14 @@ discard block |
||
4577 | 4843 | global $smcFunc, $modSettings; |
4578 | 4844 | |
4579 | 4845 | // Any objects? |
4580 | - if ($object) |
|
4581 | - $function = $function . '#'; |
|
4846 | + if ($object) { |
|
4847 | + $function = $function . '#'; |
|
4848 | + } |
|
4582 | 4849 | |
4583 | 4850 | // Any files to load? |
4584 | - if (!empty($file) && is_string($file)) |
|
4585 | - $function = $file . (!empty($function) ? '|' . $function : ''); |
|
4851 | + if (!empty($file) && is_string($file)) { |
|
4852 | + $function = $file . (!empty($function) ? '|' . $function : ''); |
|
4853 | + } |
|
4586 | 4854 | |
4587 | 4855 | // Get the correct string. |
4588 | 4856 | $integration_call = $function; |
@@ -4604,13 +4872,14 @@ discard block |
||
4604 | 4872 | if (!empty($current_functions)) |
4605 | 4873 | { |
4606 | 4874 | $current_functions = explode(',', $current_functions); |
4607 | - if (in_array($integration_call, $current_functions)) |
|
4608 | - return; |
|
4875 | + if (in_array($integration_call, $current_functions)) { |
|
4876 | + return; |
|
4877 | + } |
|
4609 | 4878 | |
4610 | 4879 | $permanent_functions = array_merge($current_functions, array($integration_call)); |
4880 | + } else { |
|
4881 | + $permanent_functions = array($integration_call); |
|
4611 | 4882 | } |
4612 | - else |
|
4613 | - $permanent_functions = array($integration_call); |
|
4614 | 4883 | |
4615 | 4884 | updateSettings(array($hook => implode(',', $permanent_functions))); |
4616 | 4885 | } |
@@ -4619,8 +4888,9 @@ discard block |
||
4619 | 4888 | $functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]); |
4620 | 4889 | |
4621 | 4890 | // Do nothing, if it's already there. |
4622 | - if (in_array($integration_call, $functions)) |
|
4623 | - return; |
|
4891 | + if (in_array($integration_call, $functions)) { |
|
4892 | + return; |
|
4893 | + } |
|
4624 | 4894 | |
4625 | 4895 | $functions[] = $integration_call; |
4626 | 4896 | $modSettings[$hook] = implode(',', $functions); |
@@ -4643,12 +4913,14 @@ discard block |
||
4643 | 4913 | global $smcFunc, $modSettings; |
4644 | 4914 | |
4645 | 4915 | // Any objects? |
4646 | - if ($object) |
|
4647 | - $function = $function . '#'; |
|
4916 | + if ($object) { |
|
4917 | + $function = $function . '#'; |
|
4918 | + } |
|
4648 | 4919 | |
4649 | 4920 | // Any files to load? |
4650 | - if (!empty($file) && is_string($file)) |
|
4651 | - $function = $file . '|' . $function; |
|
4921 | + if (!empty($file) && is_string($file)) { |
|
4922 | + $function = $file . '|' . $function; |
|
4923 | + } |
|
4652 | 4924 | |
4653 | 4925 | // Get the correct string. |
4654 | 4926 | $integration_call = $function; |
@@ -4669,16 +4941,18 @@ discard block |
||
4669 | 4941 | { |
4670 | 4942 | $current_functions = explode(',', $current_functions); |
4671 | 4943 | |
4672 | - if (in_array($integration_call, $current_functions)) |
|
4673 | - updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call))))); |
|
4944 | + if (in_array($integration_call, $current_functions)) { |
|
4945 | + updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call))))); |
|
4946 | + } |
|
4674 | 4947 | } |
4675 | 4948 | |
4676 | 4949 | // Turn the function list into something usable. |
4677 | 4950 | $functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]); |
4678 | 4951 | |
4679 | 4952 | // You can only remove it if it's available. |
4680 | - if (!in_array($integration_call, $functions)) |
|
4681 | - return; |
|
4953 | + if (!in_array($integration_call, $functions)) { |
|
4954 | + return; |
|
4955 | + } |
|
4682 | 4956 | |
4683 | 4957 | $functions = array_diff($functions, array($integration_call)); |
4684 | 4958 | $modSettings[$hook] = implode(',', $functions); |
@@ -4699,17 +4973,20 @@ discard block |
||
4699 | 4973 | global $context, $smcFunc, $txt, $db_show_debug; |
4700 | 4974 | |
4701 | 4975 | // Really? |
4702 | - if (empty($string)) |
|
4703 | - return false; |
|
4976 | + if (empty($string)) { |
|
4977 | + return false; |
|
4978 | + } |
|
4704 | 4979 | |
4705 | 4980 | // An array? should be a "callable" array IE array(object/class, valid_callable). |
4706 | 4981 | // A closure? should be a callable one. |
4707 | - if (is_array($string) || $string instanceof Closure) |
|
4708 | - return $return ? $string : (is_callable($string) ? call_user_func($string) : false); |
|
4982 | + if (is_array($string) || $string instanceof Closure) { |
|
4983 | + return $return ? $string : (is_callable($string) ? call_user_func($string) : false); |
|
4984 | + } |
|
4709 | 4985 | |
4710 | 4986 | // No full objects, sorry! pass a method or a property instead! |
4711 | - if (is_object($string)) |
|
4712 | - return false; |
|
4987 | + if (is_object($string)) { |
|
4988 | + return false; |
|
4989 | + } |
|
4713 | 4990 | |
4714 | 4991 | // Stay vitaminized my friends... |
4715 | 4992 | $string = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($string)); |
@@ -4718,8 +4995,9 @@ discard block |
||
4718 | 4995 | $string = load_file($string); |
4719 | 4996 | |
4720 | 4997 | // Loaded file failed |
4721 | - if (empty($string)) |
|
4722 | - return false; |
|
4998 | + if (empty($string)) { |
|
4999 | + return false; |
|
5000 | + } |
|
4723 | 5001 | |
4724 | 5002 | // Found a method. |
4725 | 5003 | if (strpos($string, '::') !== false) |
@@ -4740,8 +5018,9 @@ discard block |
||
4740 | 5018 | // Add another one to the list. |
4741 | 5019 | if ($db_show_debug === true) |
4742 | 5020 | { |
4743 | - if (!isset($context['debug']['instances'])) |
|
4744 | - $context['debug']['instances'] = array(); |
|
5021 | + if (!isset($context['debug']['instances'])) { |
|
5022 | + $context['debug']['instances'] = array(); |
|
5023 | + } |
|
4745 | 5024 | |
4746 | 5025 | $context['debug']['instances'][$class] = $class; |
4747 | 5026 | } |
@@ -4751,13 +5030,15 @@ discard block |
||
4751 | 5030 | } |
4752 | 5031 | |
4753 | 5032 | // Right then. This is a call to a static method. |
4754 | - else |
|
4755 | - $func = array($class, $method); |
|
5033 | + else { |
|
5034 | + $func = array($class, $method); |
|
5035 | + } |
|
4756 | 5036 | } |
4757 | 5037 | |
4758 | 5038 | // Nope! just a plain regular function. |
4759 | - else |
|
4760 | - $func = $string; |
|
5039 | + else { |
|
5040 | + $func = $string; |
|
5041 | + } |
|
4761 | 5042 | |
4762 | 5043 | // Right, we got what we need, time to do some checks. |
4763 | 5044 | if (!is_callable($func, false, $callable_name)) |
@@ -4773,17 +5054,18 @@ discard block |
||
4773 | 5054 | else |
4774 | 5055 | { |
4775 | 5056 | // What are we gonna do about it? |
4776 | - if ($return) |
|
4777 | - return $func; |
|
5057 | + if ($return) { |
|
5058 | + return $func; |
|
5059 | + } |
|
4778 | 5060 | |
4779 | 5061 | // If this is a plain function, avoid the heat of calling call_user_func(). |
4780 | 5062 | else |
4781 | 5063 | { |
4782 | - if (is_array($func)) |
|
4783 | - call_user_func($func); |
|
4784 | - |
|
4785 | - else |
|
4786 | - $func(); |
|
5064 | + if (is_array($func)) { |
|
5065 | + call_user_func($func); |
|
5066 | + } else { |
|
5067 | + $func(); |
|
5068 | + } |
|
4787 | 5069 | } |
4788 | 5070 | } |
4789 | 5071 | } |
@@ -4800,31 +5082,34 @@ discard block |
||
4800 | 5082 | { |
4801 | 5083 | global $sourcedir, $txt, $boarddir, $settings; |
4802 | 5084 | |
4803 | - if (empty($string)) |
|
4804 | - return false; |
|
5085 | + if (empty($string)) { |
|
5086 | + return false; |
|
5087 | + } |
|
4805 | 5088 | |
4806 | 5089 | if (strpos($string, '|') !== false) |
4807 | 5090 | { |
4808 | 5091 | list ($file, $string) = explode('|', $string); |
4809 | 5092 | |
4810 | 5093 | // Match the wildcards to their regular vars. |
4811 | - if (empty($settings['theme_dir'])) |
|
4812 | - $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
|
4813 | - |
|
4814 | - else |
|
4815 | - $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
|
5094 | + if (empty($settings['theme_dir'])) { |
|
5095 | + $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
|
5096 | + } else { |
|
5097 | + $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
|
5098 | + } |
|
4816 | 5099 | |
4817 | 5100 | // Load the file if it can be loaded. |
4818 | - if (file_exists($absPath)) |
|
4819 | - require_once($absPath); |
|
5101 | + if (file_exists($absPath)) { |
|
5102 | + require_once($absPath); |
|
5103 | + } |
|
4820 | 5104 | |
4821 | 5105 | // No? try a fallback to $sourcedir |
4822 | 5106 | else |
4823 | 5107 | { |
4824 | 5108 | $absPath = $sourcedir .'/'. $file; |
4825 | 5109 | |
4826 | - if (file_exists($absPath)) |
|
4827 | - require_once($absPath); |
|
5110 | + if (file_exists($absPath)) { |
|
5111 | + require_once($absPath); |
|
5112 | + } |
|
4828 | 5113 | |
4829 | 5114 | // Sorry, can't do much for you at this point. |
4830 | 5115 | else |
@@ -4863,8 +5148,9 @@ discard block |
||
4863 | 5148 | preg_match('~^(http|ftp)(s)?://([^/:]+)(:(\d+))?(.+)$~', $url, $match); |
4864 | 5149 | |
4865 | 5150 | // No scheme? No data for you! |
4866 | - if (empty($match[1])) |
|
4867 | - return false; |
|
5151 | + if (empty($match[1])) { |
|
5152 | + return false; |
|
5153 | + } |
|
4868 | 5154 | |
4869 | 5155 | // An FTP url. We should try connecting and RETRieving it... |
4870 | 5156 | elseif ($match[1] == 'ftp') |
@@ -4874,23 +5160,26 @@ discard block |
||
4874 | 5160 | |
4875 | 5161 | // Establish a connection and attempt to enable passive mode. |
4876 | 5162 | $ftp = new ftp_connection(($match[2] ? 'ssl://' : '') . $match[3], empty($match[5]) ? 21 : $match[5], 'anonymous', $webmaster_email); |
4877 | - if ($ftp->error !== false || !$ftp->passive()) |
|
4878 | - return false; |
|
5163 | + if ($ftp->error !== false || !$ftp->passive()) { |
|
5164 | + return false; |
|
5165 | + } |
|
4879 | 5166 | |
4880 | 5167 | // I want that one *points*! |
4881 | 5168 | fwrite($ftp->connection, 'RETR ' . $match[6] . "\r\n"); |
4882 | 5169 | |
4883 | 5170 | // Since passive mode worked (or we would have returned already!) open the connection. |
4884 | 5171 | $fp = @fsockopen($ftp->pasv['ip'], $ftp->pasv['port'], $err, $err, 5); |
4885 | - if (!$fp) |
|
4886 | - return false; |
|
5172 | + if (!$fp) { |
|
5173 | + return false; |
|
5174 | + } |
|
4887 | 5175 | |
4888 | 5176 | // The server should now say something in acknowledgement. |
4889 | 5177 | $ftp->check_response(150); |
4890 | 5178 | |
4891 | 5179 | $data = ''; |
4892 | - while (!feof($fp)) |
|
4893 | - $data .= fread($fp, 4096); |
|
5180 | + while (!feof($fp)) { |
|
5181 | + $data .= fread($fp, 4096); |
|
5182 | + } |
|
4894 | 5183 | fclose($fp); |
4895 | 5184 | |
4896 | 5185 | // All done, right? Good. |
@@ -4902,8 +5191,9 @@ discard block |
||
4902 | 5191 | elseif (isset($match[1]) && $match[1] == 'http') |
4903 | 5192 | { |
4904 | 5193 | // First try to use fsockopen, because it is fastest. |
4905 | - if ($keep_alive && $match[3] == $keep_alive_dom) |
|
4906 | - $fp = $keep_alive_fp; |
|
5194 | + if ($keep_alive && $match[3] == $keep_alive_dom) { |
|
5195 | + $fp = $keep_alive_fp; |
|
5196 | + } |
|
4907 | 5197 | if (empty($fp)) |
4908 | 5198 | { |
4909 | 5199 | // Open the socket on the port we want... |
@@ -4923,20 +5213,21 @@ discard block |
||
4923 | 5213 | fwrite($fp, 'GET ' . ($match[6] !== '/' ? str_replace(' ', '%20', $match[6]) : '') . ' HTTP/1.0' . "\r\n"); |
4924 | 5214 | fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n"); |
4925 | 5215 | fwrite($fp, 'user-agent: PHP/SMF' . "\r\n"); |
4926 | - if ($keep_alive) |
|
4927 | - fwrite($fp, 'connection: Keep-Alive' . "\r\n\r\n"); |
|
4928 | - else |
|
4929 | - fwrite($fp, 'connection: close' . "\r\n\r\n"); |
|
4930 | - } |
|
4931 | - else |
|
5216 | + if ($keep_alive) { |
|
5217 | + fwrite($fp, 'connection: Keep-Alive' . "\r\n\r\n"); |
|
5218 | + } else { |
|
5219 | + fwrite($fp, 'connection: close' . "\r\n\r\n"); |
|
5220 | + } |
|
5221 | + } else |
|
4932 | 5222 | { |
4933 | 5223 | fwrite($fp, 'POST ' . ($match[6] !== '/' ? $match[6] : '') . ' HTTP/1.0' . "\r\n"); |
4934 | 5224 | fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n"); |
4935 | 5225 | fwrite($fp, 'user-agent: PHP/SMF' . "\r\n"); |
4936 | - if ($keep_alive) |
|
4937 | - fwrite($fp, 'connection: Keep-Alive' . "\r\n"); |
|
4938 | - else |
|
4939 | - fwrite($fp, 'connection: close' . "\r\n"); |
|
5226 | + if ($keep_alive) { |
|
5227 | + fwrite($fp, 'connection: Keep-Alive' . "\r\n"); |
|
5228 | + } else { |
|
5229 | + fwrite($fp, 'connection: close' . "\r\n"); |
|
5230 | + } |
|
4940 | 5231 | fwrite($fp, 'content-type: application/x-www-form-urlencoded' . "\r\n"); |
4941 | 5232 | fwrite($fp, 'content-length: ' . strlen($post_data) . "\r\n\r\n"); |
4942 | 5233 | fwrite($fp, $post_data); |
@@ -4949,30 +5240,33 @@ discard block |
||
4949 | 5240 | { |
4950 | 5241 | $header = ''; |
4951 | 5242 | $location = ''; |
4952 | - while (!feof($fp) && trim($header = fgets($fp, 4096)) != '') |
|
4953 | - if (strpos($header, 'location:') !== false) |
|
5243 | + while (!feof($fp) && trim($header = fgets($fp, 4096)) != '') { |
|
5244 | + if (strpos($header, 'location:') !== false) |
|
4954 | 5245 | $location = trim(substr($header, strpos($header, ':') + 1)); |
5246 | + } |
|
4955 | 5247 | |
4956 | - if (empty($location)) |
|
4957 | - return false; |
|
4958 | - else |
|
5248 | + if (empty($location)) { |
|
5249 | + return false; |
|
5250 | + } else |
|
4959 | 5251 | { |
4960 | - if (!$keep_alive) |
|
4961 | - fclose($fp); |
|
5252 | + if (!$keep_alive) { |
|
5253 | + fclose($fp); |
|
5254 | + } |
|
4962 | 5255 | return fetch_web_data($location, $post_data, $keep_alive, $redirection_level + 1); |
4963 | 5256 | } |
4964 | 5257 | } |
4965 | 5258 | |
4966 | 5259 | // Make sure we get a 200 OK. |
4967 | - elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0) |
|
4968 | - return false; |
|
5260 | + elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0) { |
|
5261 | + return false; |
|
5262 | + } |
|
4969 | 5263 | |
4970 | 5264 | // Skip the headers... |
4971 | 5265 | while (!feof($fp) && trim($header = fgets($fp, 4096)) != '') |
4972 | 5266 | { |
4973 | - if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0) |
|
4974 | - $content_length = $match[1]; |
|
4975 | - elseif (preg_match('~connection:\s*close~i', $header) != 0) |
|
5267 | + if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0) { |
|
5268 | + $content_length = $match[1]; |
|
5269 | + } elseif (preg_match('~connection:\s*close~i', $header) != 0) |
|
4976 | 5270 | { |
4977 | 5271 | $keep_alive_dom = null; |
4978 | 5272 | $keep_alive = false; |
@@ -4984,17 +5278,19 @@ discard block |
||
4984 | 5278 | $data = ''; |
4985 | 5279 | if (isset($content_length)) |
4986 | 5280 | { |
4987 | - while (!feof($fp) && strlen($data) < $content_length) |
|
4988 | - $data .= fread($fp, $content_length - strlen($data)); |
|
4989 | - } |
|
4990 | - else |
|
5281 | + while (!feof($fp) && strlen($data) < $content_length) { |
|
5282 | + $data .= fread($fp, $content_length - strlen($data)); |
|
5283 | + } |
|
5284 | + } else |
|
4991 | 5285 | { |
4992 | - while (!feof($fp)) |
|
4993 | - $data .= fread($fp, 4096); |
|
5286 | + while (!feof($fp)) { |
|
5287 | + $data .= fread($fp, 4096); |
|
5288 | + } |
|
4994 | 5289 | } |
4995 | 5290 | |
4996 | - if (!$keep_alive) |
|
4997 | - fclose($fp); |
|
5291 | + if (!$keep_alive) { |
|
5292 | + fclose($fp); |
|
5293 | + } |
|
4998 | 5294 | } |
4999 | 5295 | |
5000 | 5296 | // If using fsockopen didn't work, try to use cURL if available. |
@@ -5007,17 +5303,18 @@ discard block |
||
5007 | 5303 | $fetch_data->get_url_data($url, $post_data); |
5008 | 5304 | |
5009 | 5305 | // no errors and a 200 result, then we have a good dataset, well we at least have data. ;) |
5010 | - if ($fetch_data->result('code') == 200 && !$fetch_data->result('error')) |
|
5011 | - $data = $fetch_data->result('body'); |
|
5012 | - else |
|
5013 | - return false; |
|
5306 | + if ($fetch_data->result('code') == 200 && !$fetch_data->result('error')) { |
|
5307 | + $data = $fetch_data->result('body'); |
|
5308 | + } else { |
|
5309 | + return false; |
|
5310 | + } |
|
5014 | 5311 | } |
5015 | 5312 | |
5016 | 5313 | // Neither fsockopen nor curl are available. Well, phooey. |
5017 | - else |
|
5018 | - return false; |
|
5019 | - } |
|
5020 | - else |
|
5314 | + else { |
|
5315 | + return false; |
|
5316 | + } |
|
5317 | + } else |
|
5021 | 5318 | { |
5022 | 5319 | // Umm, this shouldn't happen? |
5023 | 5320 | trigger_error('fetch_web_data(): Bad URL', E_USER_NOTICE); |
@@ -5037,8 +5334,9 @@ discard block |
||
5037 | 5334 | global $user_info, $smcFunc; |
5038 | 5335 | |
5039 | 5336 | // Make sure we have something to work with. |
5040 | - if (empty($topic)) |
|
5041 | - return array(); |
|
5337 | + if (empty($topic)) { |
|
5338 | + return array(); |
|
5339 | + } |
|
5042 | 5340 | |
5043 | 5341 | |
5044 | 5342 | // We already know the number of likes per message, we just want to know whether the current user liked it or not. |
@@ -5061,8 +5359,9 @@ discard block |
||
5061 | 5359 | 'topic' => $topic, |
5062 | 5360 | ) |
5063 | 5361 | ); |
5064 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
5065 | - $temp[] = (int) $row['content_id']; |
|
5362 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
5363 | + $temp[] = (int) $row['content_id']; |
|
5364 | + } |
|
5066 | 5365 | |
5067 | 5366 | cache_put_data($cache_key, $temp, $ttl); |
5068 | 5367 | } |
@@ -5083,8 +5382,9 @@ discard block |
||
5083 | 5382 | { |
5084 | 5383 | global $context; |
5085 | 5384 | |
5086 | - if (empty($string)) |
|
5087 | - return $string; |
|
5385 | + if (empty($string)) { |
|
5386 | + return $string; |
|
5387 | + } |
|
5088 | 5388 | |
5089 | 5389 | // UTF-8 occurences of MS special characters |
5090 | 5390 | $findchars_utf8 = array( |
@@ -5125,10 +5425,11 @@ discard block |
||
5125 | 5425 | '--', // — |
5126 | 5426 | ); |
5127 | 5427 | |
5128 | - if ($context['utf8']) |
|
5129 | - $string = str_replace($findchars_utf8, $replacechars, $string); |
|
5130 | - else |
|
5131 | - $string = str_replace($findchars_iso, $replacechars, $string); |
|
5428 | + if ($context['utf8']) { |
|
5429 | + $string = str_replace($findchars_utf8, $replacechars, $string); |
|
5430 | + } else { |
|
5431 | + $string = str_replace($findchars_iso, $replacechars, $string); |
|
5432 | + } |
|
5132 | 5433 | |
5133 | 5434 | return $string; |
5134 | 5435 | } |
@@ -5147,49 +5448,59 @@ discard block |
||
5147 | 5448 | { |
5148 | 5449 | global $context; |
5149 | 5450 | |
5150 | - if (!isset($matches[2])) |
|
5151 | - return ''; |
|
5451 | + if (!isset($matches[2])) { |
|
5452 | + return ''; |
|
5453 | + } |
|
5152 | 5454 | |
5153 | 5455 | $num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2]; |
5154 | 5456 | |
5155 | 5457 | // remove left to right / right to left overrides |
5156 | - if ($num === 0x202D || $num === 0x202E) |
|
5157 | - return ''; |
|
5458 | + if ($num === 0x202D || $num === 0x202E) { |
|
5459 | + return ''; |
|
5460 | + } |
|
5158 | 5461 | |
5159 | 5462 | // Quote, Ampersand, Apostrophe, Less/Greater Than get html replaced |
5160 | - if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) |
|
5161 | - return '&#' . $num . ';'; |
|
5463 | + if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) { |
|
5464 | + return '&#' . $num . ';'; |
|
5465 | + } |
|
5162 | 5466 | |
5163 | 5467 | if (empty($context['utf8'])) |
5164 | 5468 | { |
5165 | 5469 | // no control characters |
5166 | - if ($num < 0x20) |
|
5167 | - return ''; |
|
5470 | + if ($num < 0x20) { |
|
5471 | + return ''; |
|
5472 | + } |
|
5168 | 5473 | // text is text |
5169 | - elseif ($num < 0x80) |
|
5170 | - return chr($num); |
|
5474 | + elseif ($num < 0x80) { |
|
5475 | + return chr($num); |
|
5476 | + } |
|
5171 | 5477 | // all others get html-ised |
5172 | - else |
|
5173 | - return '&#' . $matches[2] . ';'; |
|
5174 | - } |
|
5175 | - else |
|
5478 | + else { |
|
5479 | + return '&#' . $matches[2] . ';'; |
|
5480 | + } |
|
5481 | + } else |
|
5176 | 5482 | { |
5177 | 5483 | // <0x20 are control characters, 0x20 is a space, > 0x10FFFF is past the end of the utf8 character set |
5178 | 5484 | // 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text) |
5179 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) |
|
5180 | - return ''; |
|
5485 | + if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) { |
|
5486 | + return ''; |
|
5487 | + } |
|
5181 | 5488 | // <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation |
5182 | - elseif ($num < 0x80) |
|
5183 | - return chr($num); |
|
5489 | + elseif ($num < 0x80) { |
|
5490 | + return chr($num); |
|
5491 | + } |
|
5184 | 5492 | // <0x800 (2048) |
5185 | - elseif ($num < 0x800) |
|
5186 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
5493 | + elseif ($num < 0x800) { |
|
5494 | + return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
5495 | + } |
|
5187 | 5496 | // < 0x10000 (65536) |
5188 | - elseif ($num < 0x10000) |
|
5189 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5497 | + elseif ($num < 0x10000) { |
|
5498 | + return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5499 | + } |
|
5190 | 5500 | // <= 0x10FFFF (1114111) |
5191 | - else |
|
5192 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5501 | + else { |
|
5502 | + return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5503 | + } |
|
5193 | 5504 | } |
5194 | 5505 | } |
5195 | 5506 | |
@@ -5205,28 +5516,34 @@ discard block |
||
5205 | 5516 | */ |
5206 | 5517 | function fixchar__callback($matches) |
5207 | 5518 | { |
5208 | - if (!isset($matches[1])) |
|
5209 | - return ''; |
|
5519 | + if (!isset($matches[1])) { |
|
5520 | + return ''; |
|
5521 | + } |
|
5210 | 5522 | |
5211 | 5523 | $num = $matches[1][0] === 'x' ? hexdec(substr($matches[1], 1)) : (int) $matches[1]; |
5212 | 5524 | |
5213 | 5525 | // <0x20 are control characters, > 0x10FFFF is past the end of the utf8 character set |
5214 | 5526 | // 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text), 0x202D-E are left to right overrides |
5215 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) |
|
5216 | - return ''; |
|
5527 | + if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) { |
|
5528 | + return ''; |
|
5529 | + } |
|
5217 | 5530 | // <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation |
5218 | - elseif ($num < 0x80) |
|
5219 | - return chr($num); |
|
5531 | + elseif ($num < 0x80) { |
|
5532 | + return chr($num); |
|
5533 | + } |
|
5220 | 5534 | // <0x800 (2048) |
5221 | - elseif ($num < 0x800) |
|
5222 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
5535 | + elseif ($num < 0x800) { |
|
5536 | + return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
5537 | + } |
|
5223 | 5538 | // < 0x10000 (65536) |
5224 | - elseif ($num < 0x10000) |
|
5225 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5539 | + elseif ($num < 0x10000) { |
|
5540 | + return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5541 | + } |
|
5226 | 5542 | // <= 0x10FFFF (1114111) |
5227 | - else |
|
5228 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5229 | -} |
|
5543 | + else { |
|
5544 | + return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5545 | + } |
|
5546 | + } |
|
5230 | 5547 | |
5231 | 5548 | /** |
5232 | 5549 | * Strips out invalid html entities, replaces others with html style { codes |
@@ -5239,17 +5556,19 @@ discard block |
||
5239 | 5556 | */ |
5240 | 5557 | function entity_fix__callback($matches) |
5241 | 5558 | { |
5242 | - if (!isset($matches[2])) |
|
5243 | - return ''; |
|
5559 | + if (!isset($matches[2])) { |
|
5560 | + return ''; |
|
5561 | + } |
|
5244 | 5562 | |
5245 | 5563 | $num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2]; |
5246 | 5564 | |
5247 | 5565 | // we don't allow control characters, characters out of range, byte markers, etc |
5248 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) |
|
5249 | - return ''; |
|
5250 | - else |
|
5251 | - return '&#' . $num . ';'; |
|
5252 | -} |
|
5566 | + if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) { |
|
5567 | + return ''; |
|
5568 | + } else { |
|
5569 | + return '&#' . $num . ';'; |
|
5570 | + } |
|
5571 | + } |
|
5253 | 5572 | |
5254 | 5573 | /** |
5255 | 5574 | * Return a Gravatar URL based on |
@@ -5273,18 +5592,23 @@ discard block |
||
5273 | 5592 | $ratings = array('G', 'PG', 'R', 'X'); |
5274 | 5593 | $defaults = array('mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank'); |
5275 | 5594 | $url_params = array(); |
5276 | - if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) |
|
5277 | - $url_params[] = 'rating=' . $modSettings['gravatarMaxRating']; |
|
5278 | - if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) |
|
5279 | - $url_params[] = 'default=' . $modSettings['gravatarDefault']; |
|
5280 | - if (!empty($modSettings['avatar_max_width_external'])) |
|
5281 | - $size_string = (int) $modSettings['avatar_max_width_external']; |
|
5282 | - if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) |
|
5283 | - if ((int) $modSettings['avatar_max_height_external'] < $size_string) |
|
5595 | + if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) { |
|
5596 | + $url_params[] = 'rating=' . $modSettings['gravatarMaxRating']; |
|
5597 | + } |
|
5598 | + if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) { |
|
5599 | + $url_params[] = 'default=' . $modSettings['gravatarDefault']; |
|
5600 | + } |
|
5601 | + if (!empty($modSettings['avatar_max_width_external'])) { |
|
5602 | + $size_string = (int) $modSettings['avatar_max_width_external']; |
|
5603 | + } |
|
5604 | + if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) { |
|
5605 | + if ((int) $modSettings['avatar_max_height_external'] < $size_string) |
|
5284 | 5606 | $size_string = $modSettings['avatar_max_height_external']; |
5607 | + } |
|
5285 | 5608 | |
5286 | - if (!empty($size_string)) |
|
5287 | - $url_params[] = 's=' . $size_string; |
|
5609 | + if (!empty($size_string)) { |
|
5610 | + $url_params[] = 's=' . $size_string; |
|
5611 | + } |
|
5288 | 5612 | } |
5289 | 5613 | $http_method = !empty($modSettings['force_ssl']) ? 'https://secure' : 'http://www'; |
5290 | 5614 | |
@@ -5303,22 +5627,26 @@ discard block |
||
5303 | 5627 | static $timezones = null, $lastwhen = null; |
5304 | 5628 | |
5305 | 5629 | // No point doing this over if we already did it once |
5306 | - if (!empty($timezones) && $when == $lastwhen) |
|
5307 | - return $timezones; |
|
5308 | - else |
|
5309 | - $lastwhen = $when; |
|
5630 | + if (!empty($timezones) && $when == $lastwhen) { |
|
5631 | + return $timezones; |
|
5632 | + } else { |
|
5633 | + $lastwhen = $when; |
|
5634 | + } |
|
5310 | 5635 | |
5311 | 5636 | // Parseable datetime string? |
5312 | - if (is_int($timestamp = strtotime($when))) |
|
5313 | - $when = $timestamp; |
|
5637 | + if (is_int($timestamp = strtotime($when))) { |
|
5638 | + $when = $timestamp; |
|
5639 | + } |
|
5314 | 5640 | |
5315 | 5641 | // A Unix timestamp? |
5316 | - elseif (is_numeric($when)) |
|
5317 | - $when = intval($when); |
|
5642 | + elseif (is_numeric($when)) { |
|
5643 | + $when = intval($when); |
|
5644 | + } |
|
5318 | 5645 | |
5319 | 5646 | // Invalid value? Just get current Unix timestamp. |
5320 | - else |
|
5321 | - $when = time(); |
|
5647 | + else { |
|
5648 | + $when = time(); |
|
5649 | + } |
|
5322 | 5650 | |
5323 | 5651 | // We'll need these too |
5324 | 5652 | $date_when = date_create('@' . $when); |
@@ -5382,8 +5710,9 @@ discard block |
||
5382 | 5710 | foreach ($priority_countries as $country) |
5383 | 5711 | { |
5384 | 5712 | $country_tzids = @timezone_identifiers_list(DateTimeZone::PER_COUNTRY, strtoupper(trim($country))); |
5385 | - if (!empty($country_tzids)) |
|
5386 | - $priority_tzids = array_merge($priority_tzids, $country_tzids); |
|
5713 | + if (!empty($country_tzids)) { |
|
5714 | + $priority_tzids = array_merge($priority_tzids, $country_tzids); |
|
5715 | + } |
|
5387 | 5716 | } |
5388 | 5717 | |
5389 | 5718 | // Process the preferred timezones first, then the rest. |
@@ -5393,8 +5722,9 @@ discard block |
||
5393 | 5722 | foreach ($tzids as $tzid) |
5394 | 5723 | { |
5395 | 5724 | // We don't want UTC right now |
5396 | - if ($tzid == 'UTC') |
|
5397 | - continue; |
|
5725 | + if ($tzid == 'UTC') { |
|
5726 | + continue; |
|
5727 | + } |
|
5398 | 5728 | |
5399 | 5729 | $tz = timezone_open($tzid); |
5400 | 5730 | |
@@ -5415,8 +5745,9 @@ discard block |
||
5415 | 5745 | } |
5416 | 5746 | |
5417 | 5747 | // A time zone from a prioritized country? |
5418 | - if (in_array($tzid, $priority_tzids)) |
|
5419 | - $priority_zones[$tzkey] = true; |
|
5748 | + if (in_array($tzid, $priority_tzids)) { |
|
5749 | + $priority_zones[$tzkey] = true; |
|
5750 | + } |
|
5420 | 5751 | |
5421 | 5752 | // Keep track of the location and offset for this tzid |
5422 | 5753 | $tzid_parts = explode('/', $tzid); |
@@ -5435,15 +5766,17 @@ discard block |
||
5435 | 5766 | { |
5436 | 5767 | date_timezone_set($date_when, timezone_open($tzvalue['tzid'])); |
5437 | 5768 | |
5438 | - if (!empty($timezone_descriptions[$tzvalue['tzid']])) |
|
5439 | - $desc = $timezone_descriptions[$tzvalue['tzid']]; |
|
5440 | - else |
|
5441 | - $desc = implode(', ', array_unique($tzvalue['locations'])); |
|
5769 | + if (!empty($timezone_descriptions[$tzvalue['tzid']])) { |
|
5770 | + $desc = $timezone_descriptions[$tzvalue['tzid']]; |
|
5771 | + } else { |
|
5772 | + $desc = implode(', ', array_unique($tzvalue['locations'])); |
|
5773 | + } |
|
5442 | 5774 | |
5443 | - if (isset($priority_zones[$tzkey])) |
|
5444 | - $priority_timezones[$tzvalue['tzid']] = $tzvalue['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']'; |
|
5445 | - else |
|
5446 | - $timezones[$tzvalue['tzid']] = $tzvalue['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']'; |
|
5775 | + if (isset($priority_zones[$tzkey])) { |
|
5776 | + $priority_timezones[$tzvalue['tzid']] = $tzvalue['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']'; |
|
5777 | + } else { |
|
5778 | + $timezones[$tzvalue['tzid']] = $tzvalue['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']'; |
|
5779 | + } |
|
5447 | 5780 | } |
5448 | 5781 | |
5449 | 5782 | $timezones = array_merge( |
@@ -5497,9 +5830,9 @@ discard block |
||
5497 | 5830 | 'Indian/Kerguelen' => 'TFT', |
5498 | 5831 | ); |
5499 | 5832 | |
5500 | - if (!empty($missing_tz_abbrs[$tzid])) |
|
5501 | - $tz_abbrev = $missing_tz_abbrs[$tzid]; |
|
5502 | - else |
|
5833 | + if (!empty($missing_tz_abbrs[$tzid])) { |
|
5834 | + $tz_abbrev = $missing_tz_abbrs[$tzid]; |
|
5835 | + } else |
|
5503 | 5836 | { |
5504 | 5837 | // Russia likes to experiment with time zones often, and names them as offsets from Moscow |
5505 | 5838 | $tz_location = timezone_location_get(timezone_open($tzid)); |
@@ -5527,8 +5860,9 @@ discard block |
||
5527 | 5860 | */ |
5528 | 5861 | function inet_ptod($ip_address) |
5529 | 5862 | { |
5530 | - if (!isValidIP($ip_address)) |
|
5531 | - return $ip_address; |
|
5863 | + if (!isValidIP($ip_address)) { |
|
5864 | + return $ip_address; |
|
5865 | + } |
|
5532 | 5866 | |
5533 | 5867 | $bin = inet_pton($ip_address); |
5534 | 5868 | return $bin; |
@@ -5540,13 +5874,15 @@ discard block |
||
5540 | 5874 | */ |
5541 | 5875 | function inet_dtop($bin) |
5542 | 5876 | { |
5543 | - if(empty($bin)) |
|
5544 | - return ''; |
|
5877 | + if(empty($bin)) { |
|
5878 | + return ''; |
|
5879 | + } |
|
5545 | 5880 | |
5546 | 5881 | global $db_type; |
5547 | 5882 | |
5548 | - if ($db_type == 'postgresql') |
|
5549 | - return $bin; |
|
5883 | + if ($db_type == 'postgresql') { |
|
5884 | + return $bin; |
|
5885 | + } |
|
5550 | 5886 | |
5551 | 5887 | $ip_address = inet_ntop($bin); |
5552 | 5888 | |
@@ -5571,26 +5907,32 @@ discard block |
||
5571 | 5907 | */ |
5572 | 5908 | function _safe_serialize($value) |
5573 | 5909 | { |
5574 | - if(is_null($value)) |
|
5575 | - return 'N;'; |
|
5910 | + if(is_null($value)) { |
|
5911 | + return 'N;'; |
|
5912 | + } |
|
5576 | 5913 | |
5577 | - if(is_bool($value)) |
|
5578 | - return 'b:'. (int) $value .';'; |
|
5914 | + if(is_bool($value)) { |
|
5915 | + return 'b:'. (int) $value .';'; |
|
5916 | + } |
|
5579 | 5917 | |
5580 | - if(is_int($value)) |
|
5581 | - return 'i:'. $value .';'; |
|
5918 | + if(is_int($value)) { |
|
5919 | + return 'i:'. $value .';'; |
|
5920 | + } |
|
5582 | 5921 | |
5583 | - if(is_float($value)) |
|
5584 | - return 'd:'. str_replace(',', '.', $value) .';'; |
|
5922 | + if(is_float($value)) { |
|
5923 | + return 'd:'. str_replace(',', '.', $value) .';'; |
|
5924 | + } |
|
5585 | 5925 | |
5586 | - if(is_string($value)) |
|
5587 | - return 's:'. strlen($value) .':"'. $value .'";'; |
|
5926 | + if(is_string($value)) { |
|
5927 | + return 's:'. strlen($value) .':"'. $value .'";'; |
|
5928 | + } |
|
5588 | 5929 | |
5589 | 5930 | if(is_array($value)) |
5590 | 5931 | { |
5591 | 5932 | $out = ''; |
5592 | - foreach($value as $k => $v) |
|
5593 | - $out .= _safe_serialize($k) . _safe_serialize($v); |
|
5933 | + foreach($value as $k => $v) { |
|
5934 | + $out .= _safe_serialize($k) . _safe_serialize($v); |
|
5935 | + } |
|
5594 | 5936 | |
5595 | 5937 | return 'a:'. count($value) .':{'. $out .'}'; |
5596 | 5938 | } |
@@ -5616,8 +5958,9 @@ discard block |
||
5616 | 5958 | |
5617 | 5959 | $out = _safe_serialize($value); |
5618 | 5960 | |
5619 | - if (isset($mbIntEnc)) |
|
5620 | - mb_internal_encoding($mbIntEnc); |
|
5961 | + if (isset($mbIntEnc)) { |
|
5962 | + mb_internal_encoding($mbIntEnc); |
|
5963 | + } |
|
5621 | 5964 | |
5622 | 5965 | return $out; |
5623 | 5966 | } |
@@ -5634,8 +5977,9 @@ discard block |
||
5634 | 5977 | function _safe_unserialize($str) |
5635 | 5978 | { |
5636 | 5979 | // Input is not a string. |
5637 | - if(empty($str) || !is_string($str)) |
|
5638 | - return false; |
|
5980 | + if(empty($str) || !is_string($str)) { |
|
5981 | + return false; |
|
5982 | + } |
|
5639 | 5983 | |
5640 | 5984 | $stack = array(); |
5641 | 5985 | $expected = array(); |
@@ -5651,43 +5995,38 @@ discard block |
||
5651 | 5995 | while($state != 1) |
5652 | 5996 | { |
5653 | 5997 | $type = isset($str[0]) ? $str[0] : ''; |
5654 | - if($type == '}') |
|
5655 | - $str = substr($str, 1); |
|
5656 | - |
|
5657 | - else if($type == 'N' && $str[1] == ';') |
|
5998 | + if($type == '}') { |
|
5999 | + $str = substr($str, 1); |
|
6000 | + } else if($type == 'N' && $str[1] == ';') |
|
5658 | 6001 | { |
5659 | 6002 | $value = null; |
5660 | 6003 | $str = substr($str, 2); |
5661 | - } |
|
5662 | - else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches)) |
|
6004 | + } else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches)) |
|
5663 | 6005 | { |
5664 | 6006 | $value = $matches[1] == '1' ? true : false; |
5665 | 6007 | $str = substr($str, 4); |
5666 | - } |
|
5667 | - else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches)) |
|
6008 | + } else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches)) |
|
5668 | 6009 | { |
5669 | 6010 | $value = (int)$matches[1]; |
5670 | 6011 | $str = $matches[2]; |
5671 | - } |
|
5672 | - else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches)) |
|
6012 | + } else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches)) |
|
5673 | 6013 | { |
5674 | 6014 | $value = (float)$matches[1]; |
5675 | 6015 | $str = $matches[3]; |
5676 | - } |
|
5677 | - else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";') |
|
6016 | + } else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";') |
|
5678 | 6017 | { |
5679 | 6018 | $value = substr($matches[2], 0, (int)$matches[1]); |
5680 | 6019 | $str = substr($matches[2], (int)$matches[1] + 2); |
5681 | - } |
|
5682 | - else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches)) |
|
6020 | + } else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches)) |
|
5683 | 6021 | { |
5684 | 6022 | $expectedLength = (int)$matches[1]; |
5685 | 6023 | $str = $matches[2]; |
5686 | 6024 | } |
5687 | 6025 | |
5688 | 6026 | // Object or unknown/malformed type. |
5689 | - else |
|
5690 | - return false; |
|
6027 | + else { |
|
6028 | + return false; |
|
6029 | + } |
|
5691 | 6030 | |
5692 | 6031 | switch($state) |
5693 | 6032 | { |
@@ -5715,8 +6054,9 @@ discard block |
||
5715 | 6054 | if($type == '}') |
5716 | 6055 | { |
5717 | 6056 | // Array size is less than expected. |
5718 | - if(count($list) < end($expected)) |
|
5719 | - return false; |
|
6057 | + if(count($list) < end($expected)) { |
|
6058 | + return false; |
|
6059 | + } |
|
5720 | 6060 | |
5721 | 6061 | unset($list); |
5722 | 6062 | $list = &$stack[count($stack)-1]; |
@@ -5725,8 +6065,9 @@ discard block |
||
5725 | 6065 | // Go to terminal state if we're at the end of the root array. |
5726 | 6066 | array_pop($expected); |
5727 | 6067 | |
5728 | - if(count($expected) == 0) |
|
5729 | - $state = 1; |
|
6068 | + if(count($expected) == 0) { |
|
6069 | + $state = 1; |
|
6070 | + } |
|
5730 | 6071 | |
5731 | 6072 | break; |
5732 | 6073 | } |
@@ -5734,8 +6075,9 @@ discard block |
||
5734 | 6075 | if($type == 'i' || $type == 's') |
5735 | 6076 | { |
5736 | 6077 | // Array size exceeds expected length. |
5737 | - if(count($list) >= end($expected)) |
|
5738 | - return false; |
|
6078 | + if(count($list) >= end($expected)) { |
|
6079 | + return false; |
|
6080 | + } |
|
5739 | 6081 | |
5740 | 6082 | $key = $value; |
5741 | 6083 | $state = 3; |
@@ -5769,8 +6111,9 @@ discard block |
||
5769 | 6111 | } |
5770 | 6112 | |
5771 | 6113 | // Trailing data in input. |
5772 | - if(!empty($str)) |
|
5773 | - return false; |
|
6114 | + if(!empty($str)) { |
|
6115 | + return false; |
|
6116 | + } |
|
5774 | 6117 | |
5775 | 6118 | return $data; |
5776 | 6119 | } |
@@ -5793,8 +6136,9 @@ discard block |
||
5793 | 6136 | |
5794 | 6137 | $out = _safe_unserialize($str); |
5795 | 6138 | |
5796 | - if (isset($mbIntEnc)) |
|
5797 | - mb_internal_encoding($mbIntEnc); |
|
6139 | + if (isset($mbIntEnc)) { |
|
6140 | + mb_internal_encoding($mbIntEnc); |
|
6141 | + } |
|
5798 | 6142 | |
5799 | 6143 | return $out; |
5800 | 6144 | } |
@@ -5809,12 +6153,14 @@ discard block |
||
5809 | 6153 | function smf_chmod($file, $value = 0) |
5810 | 6154 | { |
5811 | 6155 | // No file? no checks! |
5812 | - if (empty($file)) |
|
5813 | - return false; |
|
6156 | + if (empty($file)) { |
|
6157 | + return false; |
|
6158 | + } |
|
5814 | 6159 | |
5815 | 6160 | // Already writable? |
5816 | - if (is_writable($file)) |
|
5817 | - return true; |
|
6161 | + if (is_writable($file)) { |
|
6162 | + return true; |
|
6163 | + } |
|
5818 | 6164 | |
5819 | 6165 | // Do we have a file or a dir? |
5820 | 6166 | $isDir = is_dir($file); |
@@ -5830,10 +6176,9 @@ discard block |
||
5830 | 6176 | { |
5831 | 6177 | $isWritable = true; |
5832 | 6178 | break; |
6179 | + } else { |
|
6180 | + @chmod($file, $val); |
|
5833 | 6181 | } |
5834 | - |
|
5835 | - else |
|
5836 | - @chmod($file, $val); |
|
5837 | 6182 | } |
5838 | 6183 | |
5839 | 6184 | return $isWritable; |
@@ -5852,8 +6197,9 @@ discard block |
||
5852 | 6197 | global $txt; |
5853 | 6198 | |
5854 | 6199 | // Come on... |
5855 | - if (empty($json) || !is_string($json)) |
|
5856 | - return array(); |
|
6200 | + if (empty($json) || !is_string($json)) { |
|
6201 | + return array(); |
|
6202 | + } |
|
5857 | 6203 | |
5858 | 6204 | $returnArray = @json_decode($json, $returnAsArray); |
5859 | 6205 | |
@@ -5891,11 +6237,11 @@ discard block |
||
5891 | 6237 | $jsonDebug = $jsonDebug[0]; |
5892 | 6238 | loadLanguage('Errors'); |
5893 | 6239 | |
5894 | - if (!empty($jsonDebug)) |
|
5895 | - log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']); |
|
5896 | - |
|
5897 | - else |
|
5898 | - log_error($txt['json_'. $jsonError], 'critical'); |
|
6240 | + if (!empty($jsonDebug)) { |
|
6241 | + log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']); |
|
6242 | + } else { |
|
6243 | + log_error($txt['json_'. $jsonError], 'critical'); |
|
6244 | + } |
|
5899 | 6245 | |
5900 | 6246 | // Everyone expects an array. |
5901 | 6247 | return array(); |
@@ -5929,8 +6275,9 @@ discard block |
||
5929 | 6275 | global $db_show_debug, $modSettings; |
5930 | 6276 | |
5931 | 6277 | // Defensive programming anyone? |
5932 | - if (empty($data)) |
|
5933 | - return false; |
|
6278 | + if (empty($data)) { |
|
6279 | + return false; |
|
6280 | + } |
|
5934 | 6281 | |
5935 | 6282 | // Don't need extra stuff... |
5936 | 6283 | $db_show_debug = false; |
@@ -5938,11 +6285,11 @@ discard block |
||
5938 | 6285 | // Kill anything else. |
5939 | 6286 | ob_end_clean(); |
5940 | 6287 | |
5941 | - if (!empty($modSettings['CompressedOutput'])) |
|
5942 | - @ob_start('ob_gzhandler'); |
|
5943 | - |
|
5944 | - else |
|
5945 | - ob_start(); |
|
6288 | + if (!empty($modSettings['CompressedOutput'])) { |
|
6289 | + @ob_start('ob_gzhandler'); |
|
6290 | + } else { |
|
6291 | + ob_start(); |
|
6292 | + } |
|
5946 | 6293 | |
5947 | 6294 | // Set the header. |
5948 | 6295 | header($type); |
@@ -5974,8 +6321,9 @@ discard block |
||
5974 | 6321 | static $done = false; |
5975 | 6322 | |
5976 | 6323 | // If we don't need to do anything, don't |
5977 | - if (!$update && $done) |
|
5978 | - return; |
|
6324 | + if (!$update && $done) { |
|
6325 | + return; |
|
6326 | + } |
|
5979 | 6327 | |
5980 | 6328 | // Should we get a new copy of the official list of TLDs? |
5981 | 6329 | if ($update) |
@@ -5983,8 +6331,9 @@ discard block |
||
5983 | 6331 | $tlds = fetch_web_data('https://data.iana.org/TLD/tlds-alpha-by-domain.txt'); |
5984 | 6332 | |
5985 | 6333 | // If the Internet Assigned Numbers Authority can't be reached, the Internet is gone. We're probably running on a server hidden in a bunker deep underground to protect it from marauding bandits roaming on the surface. We don't want to waste precious electricity on pointlessly repeating background tasks, so we'll wait until the next regularly scheduled update to see if civilization has been restored. |
5986 | - if ($tlds === false) |
|
5987 | - $postapocalypticNightmare = true; |
|
6334 | + if ($tlds === false) { |
|
6335 | + $postapocalypticNightmare = true; |
|
6336 | + } |
|
5988 | 6337 | } |
5989 | 6338 | // If we aren't updating and the regex is valid, we're done |
5990 | 6339 | elseif (!empty($modSettings['tld_regex']) && @preg_match('~' . $modSettings['tld_regex'] . '~', null) !== false) |
@@ -5999,10 +6348,11 @@ discard block |
||
5999 | 6348 | // Clean $tlds and convert it to an array |
6000 | 6349 | $tlds = array_filter(explode("\n", strtolower($tlds)), function($line) { |
6001 | 6350 | $line = trim($line); |
6002 | - if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) |
|
6003 | - return false; |
|
6004 | - else |
|
6005 | - return true; |
|
6351 | + if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) { |
|
6352 | + return false; |
|
6353 | + } else { |
|
6354 | + return true; |
|
6355 | + } |
|
6006 | 6356 | }); |
6007 | 6357 | |
6008 | 6358 | // Convert Punycode to Unicode |
@@ -6056,8 +6406,9 @@ discard block |
||
6056 | 6406 | $idx += $digit * $w; |
6057 | 6407 | $t = ($k <= $bias) ? $tmin : (($k >= $bias + $tmax) ? $tmax : ($k - $bias)); |
6058 | 6408 | |
6059 | - if ($digit < $t) |
|
6060 | - break; |
|
6409 | + if ($digit < $t) { |
|
6410 | + break; |
|
6411 | + } |
|
6061 | 6412 | |
6062 | 6413 | $w = (int) ($w * ($base - $t)); |
6063 | 6414 | } |
@@ -6066,8 +6417,9 @@ discard block |
||
6066 | 6417 | $delta = intval($is_first ? ($delta / $damp) : ($delta / 2)); |
6067 | 6418 | $delta += intval($delta / ($deco_len + 1)); |
6068 | 6419 | |
6069 | - for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base) |
|
6070 | - $delta = intval($delta / ($base - $tmin)); |
|
6420 | + for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base) { |
|
6421 | + $delta = intval($delta / ($base - $tmin)); |
|
6422 | + } |
|
6071 | 6423 | |
6072 | 6424 | $bias = intval($k + ($base - $tmin + 1) * $delta / ($delta + $skew)); |
6073 | 6425 | $is_first = false; |
@@ -6076,8 +6428,9 @@ discard block |
||
6076 | 6428 | |
6077 | 6429 | if ($deco_len > 0) |
6078 | 6430 | { |
6079 | - for ($i = $deco_len; $i > $idx; $i--) |
|
6080 | - $decoded[$i] = $decoded[($i - 1)]; |
|
6431 | + for ($i = $deco_len; $i > $idx; $i--) { |
|
6432 | + $decoded[$i] = $decoded[($i - 1)]; |
|
6433 | + } |
|
6081 | 6434 | } |
6082 | 6435 | $decoded[$idx++] = $char; |
6083 | 6436 | } |
@@ -6085,24 +6438,29 @@ discard block |
||
6085 | 6438 | foreach ($decoded as $k => $v) |
6086 | 6439 | { |
6087 | 6440 | // 7bit are transferred literally |
6088 | - if ($v < 128) |
|
6089 | - $output .= chr($v); |
|
6441 | + if ($v < 128) { |
|
6442 | + $output .= chr($v); |
|
6443 | + } |
|
6090 | 6444 | |
6091 | 6445 | // 2 bytes |
6092 | - elseif ($v < (1 << 11)) |
|
6093 | - $output .= chr(192+($v >> 6)) . chr(128+($v & 63)); |
|
6446 | + elseif ($v < (1 << 11)) { |
|
6447 | + $output .= chr(192+($v >> 6)) . chr(128+($v & 63)); |
|
6448 | + } |
|
6094 | 6449 | |
6095 | 6450 | // 3 bytes |
6096 | - elseif ($v < (1 << 16)) |
|
6097 | - $output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
6451 | + elseif ($v < (1 << 16)) { |
|
6452 | + $output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
6453 | + } |
|
6098 | 6454 | |
6099 | 6455 | // 4 bytes |
6100 | - elseif ($v < (1 << 21)) |
|
6101 | - $output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
6456 | + elseif ($v < (1 << 21)) { |
|
6457 | + $output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
6458 | + } |
|
6102 | 6459 | |
6103 | 6460 | // 'Conversion from UCS-4 to UTF-8 failed: malformed input at byte '.$k |
6104 | - else |
|
6105 | - $output .= $safe_char; |
|
6461 | + else { |
|
6462 | + $output .= $safe_char; |
|
6463 | + } |
|
6106 | 6464 | } |
6107 | 6465 | |
6108 | 6466 | $output_parts[] = $output; |
@@ -6195,8 +6553,7 @@ discard block |
||
6195 | 6553 | |
6196 | 6554 | $strlen = 'mb_strlen'; |
6197 | 6555 | $substr = 'mb_substr'; |
6198 | - } |
|
6199 | - else |
|
6556 | + } else |
|
6200 | 6557 | { |
6201 | 6558 | $strlen = $smcFunc['strlen']; |
6202 | 6559 | $substr = $smcFunc['substr']; |
@@ -6210,20 +6567,21 @@ discard block |
||
6210 | 6567 | |
6211 | 6568 | $first = $substr($string, 0, 1); |
6212 | 6569 | |
6213 | - if (empty($index[$first])) |
|
6214 | - $index[$first] = array(); |
|
6570 | + if (empty($index[$first])) { |
|
6571 | + $index[$first] = array(); |
|
6572 | + } |
|
6215 | 6573 | |
6216 | 6574 | if ($strlen($string) > 1) |
6217 | 6575 | { |
6218 | 6576 | // Sanity check on recursion |
6219 | - if ($depth > 99) |
|
6220 | - $index[$first][$substr($string, 1)] = ''; |
|
6221 | - |
|
6222 | - else |
|
6223 | - $index[$first] = $add_string_to_index($substr($string, 1), $index[$first]); |
|
6577 | + if ($depth > 99) { |
|
6578 | + $index[$first][$substr($string, 1)] = ''; |
|
6579 | + } else { |
|
6580 | + $index[$first] = $add_string_to_index($substr($string, 1), $index[$first]); |
|
6581 | + } |
|
6582 | + } else { |
|
6583 | + $index[$first][''] = ''; |
|
6224 | 6584 | } |
6225 | - else |
|
6226 | - $index[$first][''] = ''; |
|
6227 | 6585 | |
6228 | 6586 | $depth--; |
6229 | 6587 | return $index; |
@@ -6246,9 +6604,9 @@ discard block |
||
6246 | 6604 | $key_regex = preg_quote($key, $delim); |
6247 | 6605 | $new_key = $key; |
6248 | 6606 | |
6249 | - if (empty($value)) |
|
6250 | - $sub_regex = ''; |
|
6251 | - else |
|
6607 | + if (empty($value)) { |
|
6608 | + $sub_regex = ''; |
|
6609 | + } else |
|
6252 | 6610 | { |
6253 | 6611 | $sub_regex = $index_to_regex($value, $delim); |
6254 | 6612 | |
@@ -6256,22 +6614,22 @@ discard block |
||
6256 | 6614 | { |
6257 | 6615 | $new_key_array = explode('(?'.'>', $sub_regex); |
6258 | 6616 | $new_key .= $new_key_array[0]; |
6617 | + } else { |
|
6618 | + $sub_regex = '(?'.'>' . $sub_regex . ')'; |
|
6259 | 6619 | } |
6260 | - else |
|
6261 | - $sub_regex = '(?'.'>' . $sub_regex . ')'; |
|
6262 | 6620 | } |
6263 | 6621 | |
6264 | - if ($depth > 1) |
|
6265 | - $regex[$new_key] = $key_regex . $sub_regex; |
|
6266 | - else |
|
6622 | + if ($depth > 1) { |
|
6623 | + $regex[$new_key] = $key_regex . $sub_regex; |
|
6624 | + } else |
|
6267 | 6625 | { |
6268 | 6626 | if (($length += strlen($key_regex) + 1) < $max_length || empty($regex)) |
6269 | 6627 | { |
6270 | 6628 | $regex[$new_key] = $key_regex . $sub_regex; |
6271 | 6629 | unset($index[$key]); |
6630 | + } else { |
|
6631 | + break; |
|
6272 | 6632 | } |
6273 | - else |
|
6274 | - break; |
|
6275 | 6633 | } |
6276 | 6634 | } |
6277 | 6635 | |
@@ -6280,10 +6638,11 @@ discard block |
||
6280 | 6638 | $l1 = $strlen($k1); |
6281 | 6639 | $l2 = $strlen($k2); |
6282 | 6640 | |
6283 | - if ($l1 == $l2) |
|
6284 | - return strcmp($k1, $k2) > 0 ? 1 : -1; |
|
6285 | - else |
|
6286 | - return $l1 > $l2 ? -1 : 1; |
|
6641 | + if ($l1 == $l2) { |
|
6642 | + return strcmp($k1, $k2) > 0 ? 1 : -1; |
|
6643 | + } else { |
|
6644 | + return $l1 > $l2 ? -1 : 1; |
|
6645 | + } |
|
6287 | 6646 | }); |
6288 | 6647 | |
6289 | 6648 | $depth--; |
@@ -6294,21 +6653,24 @@ discard block |
||
6294 | 6653 | $index = array(); |
6295 | 6654 | $regex = ''; |
6296 | 6655 | |
6297 | - foreach ($strings as $string) |
|
6298 | - $index = $add_string_to_index($string, $index); |
|
6656 | + foreach ($strings as $string) { |
|
6657 | + $index = $add_string_to_index($string, $index); |
|
6658 | + } |
|
6299 | 6659 | |
6300 | 6660 | if ($returnArray === true) |
6301 | 6661 | { |
6302 | 6662 | $regex = array(); |
6303 | - while (!empty($index)) |
|
6304 | - $regex[] = '(?'.'>' . $index_to_regex($index, $delim) . ')'; |
|
6663 | + while (!empty($index)) { |
|
6664 | + $regex[] = '(?'.'>' . $index_to_regex($index, $delim) . ')'; |
|
6665 | + } |
|
6666 | + } else { |
|
6667 | + $regex = '(?'.'>' . $index_to_regex($index, $delim) . ')'; |
|
6305 | 6668 | } |
6306 | - else |
|
6307 | - $regex = '(?'.'>' . $index_to_regex($index, $delim) . ')'; |
|
6308 | 6669 | |
6309 | 6670 | // Restore PHP's internal character encoding to whatever it was originally |
6310 | - if (!empty($current_encoding)) |
|
6311 | - mb_internal_encoding($current_encoding); |
|
6671 | + if (!empty($current_encoding)) { |
|
6672 | + mb_internal_encoding($current_encoding); |
|
6673 | + } |
|
6312 | 6674 | |
6313 | 6675 | return $regex; |
6314 | 6676 | } |
@@ -6351,13 +6713,15 @@ discard block |
||
6351 | 6713 | // Need to add the trailing slash, or it puts it there & thinks there's a redirect when there isn't... |
6352 | 6714 | $url = str_ireplace('https://', 'http://', $url) . '/'; |
6353 | 6715 | $headers = @get_headers($url); |
6354 | - if ($headers === false) |
|
6355 | - return false; |
|
6716 | + if ($headers === false) { |
|
6717 | + return false; |
|
6718 | + } |
|
6356 | 6719 | |
6357 | 6720 | // Now to see if it came back https... |
6358 | 6721 | // First check for a redirect status code in first row (301, 302, 307) |
6359 | - if (strstr($headers[0], '301') === false && strstr($headers[0], '302') === false && strstr($headers[0], '307') === false) |
|
6360 | - return false; |
|
6722 | + if (strstr($headers[0], '301') === false && strstr($headers[0], '302') === false && strstr($headers[0], '307') === false) { |
|
6723 | + return false; |
|
6724 | + } |
|
6361 | 6725 | |
6362 | 6726 | // Search for the location entry to confirm https |
6363 | 6727 | $result = false; |
@@ -6393,8 +6757,7 @@ discard block |
||
6393 | 6757 | $is_admin = $user_info['is_admin']; |
6394 | 6758 | $mod_cache = !empty($user_info['mod_cache']) ? $user_info['mod_cache'] : null; |
6395 | 6759 | $ignoreboards = !empty($user_info['ignoreboards']) ? $user_info['ignoreboards'] : null; |
6396 | - } |
|
6397 | - else |
|
6760 | + } else |
|
6398 | 6761 | { |
6399 | 6762 | $request = $smcFunc['db_query']('', ' |
6400 | 6763 | SELECT mem.ignore_boards, mem.id_group, mem.additional_groups, mem.id_post_group |
@@ -6408,17 +6771,19 @@ discard block |
||
6408 | 6771 | |
6409 | 6772 | $row = $smcFunc['db_fetch_assoc']($request); |
6410 | 6773 | |
6411 | - if (empty($row['additional_groups'])) |
|
6412 | - $groups = array($row['id_group'], $row['id_post_group']); |
|
6413 | - else |
|
6414 | - $groups = array_merge( |
|
6774 | + if (empty($row['additional_groups'])) { |
|
6775 | + $groups = array($row['id_group'], $row['id_post_group']); |
|
6776 | + } else { |
|
6777 | + $groups = array_merge( |
|
6415 | 6778 | array($row['id_group'], $row['id_post_group']), |
6416 | 6779 | explode(',', $row['additional_groups']) |
6417 | 6780 | ); |
6781 | + } |
|
6418 | 6782 | |
6419 | 6783 | // Because history has proven that it is possible for groups to go bad - clean up in case. |
6420 | - foreach ($groups as $k => $v) |
|
6421 | - $groups[$k] = (int) $v; |
|
6784 | + foreach ($groups as $k => $v) { |
|
6785 | + $groups[$k] = (int) $v; |
|
6786 | + } |
|
6422 | 6787 | |
6423 | 6788 | $is_admin = in_array(1, $groups); |
6424 | 6789 | |
@@ -6435,8 +6800,9 @@ discard block |
||
6435 | 6800 | 'current_member' => $userid, |
6436 | 6801 | ) |
6437 | 6802 | ); |
6438 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
6439 | - $boards_mod[] = $row['id_board']; |
|
6803 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
6804 | + $boards_mod[] = $row['id_board']; |
|
6805 | + } |
|
6440 | 6806 | $smcFunc['db_free_result']($request); |
6441 | 6807 | |
6442 | 6808 | // Can any of the groups they're in moderate any of the boards? |
@@ -6448,8 +6814,9 @@ discard block |
||
6448 | 6814 | 'groups' => $groups, |
6449 | 6815 | ) |
6450 | 6816 | ); |
6451 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
6452 | - $boards_mod[] = $row['id_board']; |
|
6817 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
6818 | + $boards_mod[] = $row['id_board']; |
|
6819 | + } |
|
6453 | 6820 | $smcFunc['db_free_result']($request); |
6454 | 6821 | |
6455 | 6822 | // Just in case we've got duplicates here... |
@@ -6459,21 +6826,25 @@ discard block |
||
6459 | 6826 | } |
6460 | 6827 | |
6461 | 6828 | // Just build this here, it makes it easier to change/use - administrators can see all boards. |
6462 | - if ($is_admin) |
|
6463 | - $query_part['query_see_board'] = '1=1'; |
|
6829 | + if ($is_admin) { |
|
6830 | + $query_part['query_see_board'] = '1=1'; |
|
6831 | + } |
|
6464 | 6832 | // Otherwise just the groups in $user_info['groups']. |
6465 | - else |
|
6466 | - $query_part['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $groups) . ', b.member_groups) != 0)' . (!empty($deny_boards_access) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $groups) . ', b.deny_member_groups) = 0)' : '') . (isset($mod_cache) ? ' OR ' . $mod_cache['mq'] : '') . ')'; |
|
6833 | + else { |
|
6834 | + $query_part['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $groups) . ', b.member_groups) != 0)' . (!empty($deny_boards_access) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $groups) . ', b.deny_member_groups) = 0)' : '') . (isset($mod_cache) ? ' OR ' . $mod_cache['mq'] : '') . ')'; |
|
6835 | + } |
|
6467 | 6836 | |
6468 | 6837 | // Build the list of boards they WANT to see. |
6469 | 6838 | // This will take the place of query_see_boards in certain spots, so it better include the boards they can see also |
6470 | 6839 | |
6471 | 6840 | // If they aren't ignoring any boards then they want to see all the boards they can see |
6472 | - if (empty($ignoreboards)) |
|
6473 | - $query_part['query_wanna_see_board'] = $query_part['query_see_board']; |
|
6841 | + if (empty($ignoreboards)) { |
|
6842 | + $query_part['query_wanna_see_board'] = $query_part['query_see_board']; |
|
6843 | + } |
|
6474 | 6844 | // Ok I guess they don't want to see all the boards |
6475 | - else |
|
6476 | - $query_part['query_wanna_see_board'] = '(' . $query_part['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $ignoreboards) . '))'; |
|
6845 | + else { |
|
6846 | + $query_part['query_wanna_see_board'] = '(' . $query_part['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $ignoreboards) . '))'; |
|
6847 | + } |
|
6477 | 6848 | |
6478 | 6849 | return $query_part; |
6479 | 6850 | } |
@@ -6487,10 +6858,11 @@ discard block |
||
6487 | 6858 | { |
6488 | 6859 | $secure = false; |
6489 | 6860 | |
6490 | - if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') |
|
6491 | - $secure = true; |
|
6492 | - elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') |
|
6493 | - $secure = true; |
|
6861 | + if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { |
|
6862 | + $secure = true; |
|
6863 | + } elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') { |
|
6864 | + $secure = true; |
|
6865 | + } |
|
6494 | 6866 | |
6495 | 6867 | return $secure; |
6496 | 6868 | } |