@@ -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,24 +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 | - |
|
195 | - else |
|
196 | + if ($parameter1 === true) { |
|
197 | + updateSettings(array('totalTopics' => true), true); |
|
198 | + } else |
|
196 | 199 | { |
197 | 200 | // Get the number of topics - a SUM is better for InnoDB tables. |
198 | 201 | // We also ignore the recycle bin here because there will probably be a bunch of one-post topics there. |
@@ -213,8 +216,9 @@ discard block |
||
213 | 216 | |
214 | 217 | case 'postgroups': |
215 | 218 | // Parameter two is the updated columns: we should check to see if we base groups off any of these. |
216 | - if ($parameter2 !== null && !in_array('posts', $parameter2)) |
|
217 | - return; |
|
219 | + if ($parameter2 !== null && !in_array('posts', $parameter2)) { |
|
220 | + return; |
|
221 | + } |
|
218 | 222 | |
219 | 223 | $postgroups = cache_get_data('updateStats:postgroups', 360); |
220 | 224 | if ($postgroups == null || $parameter1 == null) |
@@ -229,8 +233,9 @@ discard block |
||
229 | 233 | ) |
230 | 234 | ); |
231 | 235 | $postgroups = array(); |
232 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
233 | - $postgroups[$row['id_group']] = $row['min_posts']; |
|
236 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
237 | + $postgroups[$row['id_group']] = $row['min_posts']; |
|
238 | + } |
|
234 | 239 | |
235 | 240 | $smcFunc['db_free_result']($request); |
236 | 241 | |
@@ -241,8 +246,9 @@ discard block |
||
241 | 246 | } |
242 | 247 | |
243 | 248 | // Oh great, they've screwed their post groups. |
244 | - if (empty($postgroups)) |
|
245 | - return; |
|
249 | + if (empty($postgroups)) { |
|
250 | + return; |
|
251 | + } |
|
246 | 252 | |
247 | 253 | // Set all membergroups from most posts to least posts. |
248 | 254 | $conditions = ''; |
@@ -301,12 +307,9 @@ discard block |
||
301 | 307 | { |
302 | 308 | $condition = 'id_member IN ({array_int:members})'; |
303 | 309 | $parameters['members'] = $members; |
304 | - } |
|
305 | - |
|
306 | - elseif ($members === null) |
|
307 | - $condition = '1=1'; |
|
308 | - |
|
309 | - else |
|
310 | + } elseif ($members === null) { |
|
311 | + $condition = '1=1'; |
|
312 | + } else |
|
310 | 313 | { |
311 | 314 | $condition = 'id_member = {int:member}'; |
312 | 315 | $parameters['member'] = $members; |
@@ -346,9 +349,9 @@ discard block |
||
346 | 349 | if (count($vars_to_integrate) != 0) |
347 | 350 | { |
348 | 351 | // Fetch a list of member_names if necessary |
349 | - if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) |
|
350 | - $member_names = array($user_info['username']); |
|
351 | - else |
|
352 | + if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) { |
|
353 | + $member_names = array($user_info['username']); |
|
354 | + } else |
|
352 | 355 | { |
353 | 356 | $member_names = array(); |
354 | 357 | $request = $smcFunc['db_query']('', ' |
@@ -357,14 +360,16 @@ discard block |
||
357 | 360 | WHERE ' . $condition, |
358 | 361 | $parameters |
359 | 362 | ); |
360 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
361 | - $member_names[] = $row['member_name']; |
|
363 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
364 | + $member_names[] = $row['member_name']; |
|
365 | + } |
|
362 | 366 | $smcFunc['db_free_result']($request); |
363 | 367 | } |
364 | 368 | |
365 | - if (!empty($member_names)) |
|
366 | - foreach ($vars_to_integrate as $var) |
|
369 | + if (!empty($member_names)) { |
|
370 | + foreach ($vars_to_integrate as $var) |
|
367 | 371 | call_integration_hook('integrate_change_member_data', array($member_names, $var, &$data[$var], &$knownInts, &$knownFloats)); |
372 | + } |
|
368 | 373 | } |
369 | 374 | } |
370 | 375 | |
@@ -372,16 +377,17 @@ discard block |
||
372 | 377 | foreach ($data as $var => $val) |
373 | 378 | { |
374 | 379 | $type = 'string'; |
375 | - if (in_array($var, $knownInts)) |
|
376 | - $type = 'int'; |
|
377 | - elseif (in_array($var, $knownFloats)) |
|
378 | - $type = 'float'; |
|
379 | - elseif ($var == 'birthdate') |
|
380 | - $type = 'date'; |
|
381 | - elseif ($var == 'member_ip') |
|
382 | - $type = 'inet'; |
|
383 | - elseif ($var == 'member_ip2') |
|
384 | - $type = 'inet'; |
|
380 | + if (in_array($var, $knownInts)) { |
|
381 | + $type = 'int'; |
|
382 | + } elseif (in_array($var, $knownFloats)) { |
|
383 | + $type = 'float'; |
|
384 | + } elseif ($var == 'birthdate') { |
|
385 | + $type = 'date'; |
|
386 | + } elseif ($var == 'member_ip') { |
|
387 | + $type = 'inet'; |
|
388 | + } elseif ($var == 'member_ip2') { |
|
389 | + $type = 'inet'; |
|
390 | + } |
|
385 | 391 | |
386 | 392 | // Doing an increment? |
387 | 393 | if ($var == 'alerts' && ($val === '+' || $val === '-')) |
@@ -390,18 +396,17 @@ discard block |
||
390 | 396 | if (is_array($members)) |
391 | 397 | { |
392 | 398 | $val = 'CASE '; |
393 | - foreach ($members as $k => $v) |
|
394 | - $val .= 'WHEN id_member = ' . $v . ' THEN '. count(fetch_alerts($v, false, 0, array(), false)) . ' '; |
|
399 | + foreach ($members as $k => $v) { |
|
400 | + $val .= 'WHEN id_member = ' . $v . ' THEN '. count(fetch_alerts($v, false, 0, array(), false)) . ' '; |
|
401 | + } |
|
395 | 402 | $val = $val . ' END'; |
396 | 403 | $type = 'raw'; |
397 | - } |
|
398 | - else |
|
404 | + } else |
|
399 | 405 | { |
400 | 406 | $blub = fetch_alerts($members, false, 0, array(), false); |
401 | 407 | $val = count($blub); |
402 | 408 | } |
403 | - } |
|
404 | - else if ($type == 'int' && ($val === '+' || $val === '-')) |
|
409 | + } else if ($type == 'int' && ($val === '+' || $val === '-')) |
|
405 | 410 | { |
406 | 411 | $val = $var . ' ' . $val . ' 1'; |
407 | 412 | $type = 'raw'; |
@@ -412,8 +417,9 @@ discard block |
||
412 | 417 | { |
413 | 418 | if (preg_match('~^' . $var . ' (\+ |- |\+ -)([\d]+)~', $val, $match)) |
414 | 419 | { |
415 | - if ($match[1] != '+ ') |
|
416 | - $val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END'; |
|
420 | + if ($match[1] != '+ ') { |
|
421 | + $val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END'; |
|
422 | + } |
|
417 | 423 | $type = 'raw'; |
418 | 424 | } |
419 | 425 | } |
@@ -434,8 +440,9 @@ discard block |
||
434 | 440 | // Clear any caching? |
435 | 441 | if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && !empty($members)) |
436 | 442 | { |
437 | - if (!is_array($members)) |
|
438 | - $members = array($members); |
|
443 | + if (!is_array($members)) { |
|
444 | + $members = array($members); |
|
445 | + } |
|
439 | 446 | |
440 | 447 | foreach ($members as $member) |
441 | 448 | { |
@@ -468,29 +475,32 @@ discard block |
||
468 | 475 | { |
469 | 476 | global $modSettings, $smcFunc; |
470 | 477 | |
471 | - if (empty($changeArray) || !is_array($changeArray)) |
|
472 | - return; |
|
478 | + if (empty($changeArray) || !is_array($changeArray)) { |
|
479 | + return; |
|
480 | + } |
|
473 | 481 | |
474 | 482 | $toRemove = array(); |
475 | 483 | |
476 | 484 | // Go check if there is any setting to be removed. |
477 | - foreach ($changeArray as $k => $v) |
|
478 | - if ($v === null) |
|
485 | + foreach ($changeArray as $k => $v) { |
|
486 | + if ($v === null) |
|
479 | 487 | { |
480 | 488 | // Found some, remove them from the original array and add them to ours. |
481 | 489 | unset($changeArray[$k]); |
490 | + } |
|
482 | 491 | $toRemove[] = $k; |
483 | 492 | } |
484 | 493 | |
485 | 494 | // Proceed with the deletion. |
486 | - if (!empty($toRemove)) |
|
487 | - $smcFunc['db_query']('', ' |
|
495 | + if (!empty($toRemove)) { |
|
496 | + $smcFunc['db_query']('', ' |
|
488 | 497 | DELETE FROM {db_prefix}settings |
489 | 498 | WHERE variable IN ({array_string:remove})', |
490 | 499 | array( |
491 | 500 | 'remove' => $toRemove, |
492 | 501 | ) |
493 | 502 | ); |
503 | + } |
|
494 | 504 | |
495 | 505 | // In some cases, this may be better and faster, but for large sets we don't want so many UPDATEs. |
496 | 506 | if ($update) |
@@ -519,19 +529,22 @@ discard block |
||
519 | 529 | foreach ($changeArray as $variable => $value) |
520 | 530 | { |
521 | 531 | // Don't bother if it's already like that ;). |
522 | - if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) |
|
523 | - continue; |
|
532 | + if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) { |
|
533 | + continue; |
|
534 | + } |
|
524 | 535 | // If the variable isn't set, but would only be set to nothing'ness, then don't bother setting it. |
525 | - elseif (!isset($modSettings[$variable]) && empty($value)) |
|
526 | - continue; |
|
536 | + elseif (!isset($modSettings[$variable]) && empty($value)) { |
|
537 | + continue; |
|
538 | + } |
|
527 | 539 | |
528 | 540 | $replaceArray[] = array($variable, $value); |
529 | 541 | |
530 | 542 | $modSettings[$variable] = $value; |
531 | 543 | } |
532 | 544 | |
533 | - if (empty($replaceArray)) |
|
534 | - return; |
|
545 | + if (empty($replaceArray)) { |
|
546 | + return; |
|
547 | + } |
|
535 | 548 | |
536 | 549 | $smcFunc['db_insert']('replace', |
537 | 550 | '{db_prefix}settings', |
@@ -577,14 +590,17 @@ discard block |
||
577 | 590 | $start_invalid = $start < 0; |
578 | 591 | |
579 | 592 | // Make sure $start is a proper variable - not less than 0. |
580 | - if ($start_invalid) |
|
581 | - $start = 0; |
|
593 | + if ($start_invalid) { |
|
594 | + $start = 0; |
|
595 | + } |
|
582 | 596 | // Not greater than the upper bound. |
583 | - elseif ($start >= $max_value) |
|
584 | - $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 | + elseif ($start >= $max_value) { |
|
598 | + $start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page))); |
|
599 | + } |
|
585 | 600 | // And it has to be a multiple of $num_per_page! |
586 | - else |
|
587 | - $start = max(0, (int) $start - ((int) $start % (int) $num_per_page)); |
|
601 | + else { |
|
602 | + $start = max(0, (int) $start - ((int) $start % (int) $num_per_page)); |
|
603 | + } |
|
588 | 604 | |
589 | 605 | $context['current_page'] = $start / $num_per_page; |
590 | 606 | |
@@ -614,77 +630,87 @@ discard block |
||
614 | 630 | |
615 | 631 | // Show all the pages. |
616 | 632 | $display_page = 1; |
617 | - for ($counter = 0; $counter < $max_value; $counter += $num_per_page) |
|
618 | - $pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++); |
|
633 | + for ($counter = 0; $counter < $max_value; $counter += $num_per_page) { |
|
634 | + $pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++); |
|
635 | + } |
|
619 | 636 | |
620 | 637 | // Show the right arrow. |
621 | 638 | $display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page); |
622 | - if ($start != $counter - $max_value && !$start_invalid) |
|
623 | - $pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']); |
|
624 | - } |
|
625 | - else |
|
639 | + if ($start != $counter - $max_value && !$start_invalid) { |
|
640 | + $pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']); |
|
641 | + } |
|
642 | + } else |
|
626 | 643 | { |
627 | 644 | // If they didn't enter an odd value, pretend they did. |
628 | 645 | $PageContiguous = (int) ($modSettings['compactTopicPagesContiguous'] - ($modSettings['compactTopicPagesContiguous'] % 2)) / 2; |
629 | 646 | |
630 | 647 | // Show the "prev page" link. (>prev page< 1 ... 6 7 [8] 9 10 ... 15 next page) |
631 | - if (!empty($start) && $show_prevnext) |
|
632 | - $pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']); |
|
633 | - else |
|
634 | - $pageindex .= ''; |
|
648 | + if (!empty($start) && $show_prevnext) { |
|
649 | + $pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']); |
|
650 | + } else { |
|
651 | + $pageindex .= ''; |
|
652 | + } |
|
635 | 653 | |
636 | 654 | // Show the first page. (prev page >1< ... 6 7 [8] 9 10 ... 15) |
637 | - if ($start > $num_per_page * $PageContiguous) |
|
638 | - $pageindex .= sprintf($base_link, 0, '1'); |
|
655 | + if ($start > $num_per_page * $PageContiguous) { |
|
656 | + $pageindex .= sprintf($base_link, 0, '1'); |
|
657 | + } |
|
639 | 658 | |
640 | 659 | // Show the ... after the first page. (prev page 1 >...< 6 7 [8] 9 10 ... 15 next page) |
641 | - if ($start > $num_per_page * ($PageContiguous + 1)) |
|
642 | - $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
660 | + if ($start > $num_per_page * ($PageContiguous + 1)) { |
|
661 | + $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
643 | 662 | '{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)), |
644 | 663 | '{FIRST_PAGE}' => $num_per_page, |
645 | 664 | '{LAST_PAGE}' => $start - $num_per_page * $PageContiguous, |
646 | 665 | '{PER_PAGE}' => $num_per_page, |
647 | 666 | )); |
667 | + } |
|
648 | 668 | |
649 | 669 | // Show the pages before the current one. (prev page 1 ... >6 7< [8] 9 10 ... 15 next page) |
650 | - for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) |
|
651 | - if ($start >= $num_per_page * $nCont) |
|
670 | + for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) { |
|
671 | + if ($start >= $num_per_page * $nCont) |
|
652 | 672 | { |
653 | 673 | $tmpStart = $start - $num_per_page * $nCont; |
674 | + } |
|
654 | 675 | $pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1); |
655 | 676 | } |
656 | 677 | |
657 | 678 | // Show the current page. (prev page 1 ... 6 7 >[8]< 9 10 ... 15 next page) |
658 | - if (!$start_invalid) |
|
659 | - $pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1); |
|
660 | - else |
|
661 | - $pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1); |
|
679 | + if (!$start_invalid) { |
|
680 | + $pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1); |
|
681 | + } else { |
|
682 | + $pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1); |
|
683 | + } |
|
662 | 684 | |
663 | 685 | // Show the pages after the current one... (prev page 1 ... 6 7 [8] >9 10< ... 15 next page) |
664 | 686 | $tmpMaxPages = (int) (($max_value - 1) / $num_per_page) * $num_per_page; |
665 | - for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) |
|
666 | - if ($start + $num_per_page * $nCont <= $tmpMaxPages) |
|
687 | + for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) { |
|
688 | + if ($start + $num_per_page * $nCont <= $tmpMaxPages) |
|
667 | 689 | { |
668 | 690 | $tmpStart = $start + $num_per_page * $nCont; |
691 | + } |
|
669 | 692 | $pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1); |
670 | 693 | } |
671 | 694 | |
672 | 695 | // Show the '...' part near the end. (prev page 1 ... 6 7 [8] 9 10 >...< 15 next page) |
673 | - if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) |
|
674 | - $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
696 | + if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) { |
|
697 | + $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
675 | 698 | '{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)), |
676 | 699 | '{FIRST_PAGE}' => $start + $num_per_page * ($PageContiguous + 1), |
677 | 700 | '{LAST_PAGE}' => $tmpMaxPages, |
678 | 701 | '{PER_PAGE}' => $num_per_page, |
679 | 702 | )); |
703 | + } |
|
680 | 704 | |
681 | 705 | // Show the last number in the list. (prev page 1 ... 6 7 [8] 9 10 ... >15< next page) |
682 | - if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) |
|
683 | - $pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1); |
|
706 | + if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) { |
|
707 | + $pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1); |
|
708 | + } |
|
684 | 709 | |
685 | 710 | // Show the "next page" link. (prev page 1 ... 6 7 [8] 9 10 ... 15 >next page<) |
686 | - if ($start != $tmpMaxPages && $show_prevnext) |
|
687 | - $pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']); |
|
711 | + if ($start != $tmpMaxPages && $show_prevnext) { |
|
712 | + $pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']); |
|
713 | + } |
|
688 | 714 | } |
689 | 715 | $pageindex .= $settings['page_index']['extra_after']; |
690 | 716 | |
@@ -710,8 +736,9 @@ discard block |
||
710 | 736 | if ($decimal_separator === null) |
711 | 737 | { |
712 | 738 | // Not set for whatever reason? |
713 | - if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) |
|
714 | - return $number; |
|
739 | + if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) { |
|
740 | + return $number; |
|
741 | + } |
|
715 | 742 | |
716 | 743 | // Cache these each load... |
717 | 744 | $thousands_separator = $matches[1]; |
@@ -752,17 +779,20 @@ discard block |
||
752 | 779 | $user_info['time_format'] = !empty($user_info['time_format']) ? $user_info['time_format'] : (!empty($modSettings['time_format']) ? $modSettings['time_format'] : '%F %H:%M'); |
753 | 780 | |
754 | 781 | // Offset the time. |
755 | - if (!$offset_type) |
|
756 | - $time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600; |
|
782 | + if (!$offset_type) { |
|
783 | + $time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600; |
|
784 | + } |
|
757 | 785 | // Just the forum offset? |
758 | - elseif ($offset_type == 'forum') |
|
759 | - $time = $log_time + $modSettings['time_offset'] * 3600; |
|
760 | - else |
|
761 | - $time = $log_time; |
|
786 | + elseif ($offset_type == 'forum') { |
|
787 | + $time = $log_time + $modSettings['time_offset'] * 3600; |
|
788 | + } else { |
|
789 | + $time = $log_time; |
|
790 | + } |
|
762 | 791 | |
763 | 792 | // We can't have a negative date (on Windows, at least.) |
764 | - if ($log_time < 0) |
|
765 | - $log_time = 0; |
|
793 | + if ($log_time < 0) { |
|
794 | + $log_time = 0; |
|
795 | + } |
|
766 | 796 | |
767 | 797 | // Today and Yesterday? |
768 | 798 | if ($modSettings['todayMod'] >= 1 && $show_today === true) |
@@ -779,24 +809,27 @@ discard block |
||
779 | 809 | { |
780 | 810 | $h = strpos($user_info['time_format'], '%l') === false ? '%I' : '%l'; |
781 | 811 | $today_fmt = $h . ':%M' . $s . ' %p'; |
812 | + } else { |
|
813 | + $today_fmt = '%H:%M' . $s; |
|
782 | 814 | } |
783 | - else |
|
784 | - $today_fmt = '%H:%M' . $s; |
|
785 | 815 | |
786 | 816 | // Same day of the year, same year.... Today! |
787 | - if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) |
|
788 | - return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type); |
|
817 | + if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) { |
|
818 | + return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type); |
|
819 | + } |
|
789 | 820 | |
790 | 821 | // 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... |
791 | - 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)) |
|
792 | - return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type); |
|
822 | + 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)) { |
|
823 | + return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type); |
|
824 | + } |
|
793 | 825 | } |
794 | 826 | |
795 | 827 | $str = !is_bool($show_today) ? $show_today : $user_info['time_format']; |
796 | 828 | |
797 | 829 | // Use the cached formats if available |
798 | - if (is_null($finalizedFormats)) |
|
799 | - $finalizedFormats = (array) cache_get_data('timeformatstrings', 86400); |
|
830 | + if (is_null($finalizedFormats)) { |
|
831 | + $finalizedFormats = (array) cache_get_data('timeformatstrings', 86400); |
|
832 | + } |
|
800 | 833 | |
801 | 834 | // Make a supported version for this format if we don't already have one |
802 | 835 | if (empty($finalizedFormats[$str])) |
@@ -825,8 +858,9 @@ discard block |
||
825 | 858 | ); |
826 | 859 | |
827 | 860 | // No need to do this part again if we already did it once |
828 | - if (is_null($unsupportedFormats)) |
|
829 | - $unsupportedFormats = (array) cache_get_data('unsupportedtimeformats', 86400); |
|
861 | + if (is_null($unsupportedFormats)) { |
|
862 | + $unsupportedFormats = (array) cache_get_data('unsupportedtimeformats', 86400); |
|
863 | + } |
|
830 | 864 | if (empty($unsupportedFormats)) |
831 | 865 | { |
832 | 866 | foreach($strftimeFormatSubstitutions as $format => $substitution) |
@@ -842,20 +876,23 @@ discard block |
||
842 | 876 | |
843 | 877 | // Windows will return false for unsupported formats |
844 | 878 | // Other operating systems return the format string as a literal |
845 | - if ($value === false || $value === $format) |
|
846 | - $unsupportedFormats[] = $format; |
|
879 | + if ($value === false || $value === $format) { |
|
880 | + $unsupportedFormats[] = $format; |
|
881 | + } |
|
847 | 882 | } |
848 | 883 | cache_put_data('unsupportedtimeformats', $unsupportedFormats, 86400); |
849 | 884 | } |
850 | 885 | |
851 | 886 | // Windows needs extra help if $timeformat contains something completely invalid, e.g. '%Q' |
852 | - if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') |
|
853 | - $timeformat = preg_replace('~%(?!' . implode('|', array_keys($strftimeFormatSubstitutions)) . ')~', '%', $timeformat); |
|
887 | + if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') { |
|
888 | + $timeformat = preg_replace('~%(?!' . implode('|', array_keys($strftimeFormatSubstitutions)) . ')~', '%', $timeformat); |
|
889 | + } |
|
854 | 890 | |
855 | 891 | // Substitute unsupported formats with supported ones |
856 | - if (!empty($unsupportedFormats)) |
|
857 | - while (preg_match('~%(' . implode('|', $unsupportedFormats) . ')~', $timeformat, $matches)) |
|
892 | + if (!empty($unsupportedFormats)) { |
|
893 | + while (preg_match('~%(' . implode('|', $unsupportedFormats) . ')~', $timeformat, $matches)) |
|
858 | 894 | $timeformat = str_replace($matches[0], $strftimeFormatSubstitutions[$matches[1]], $timeformat); |
895 | + } |
|
859 | 896 | |
860 | 897 | // Remember this so we don't need to do it again |
861 | 898 | $finalizedFormats[$str] = $timeformat; |
@@ -864,33 +901,39 @@ discard block |
||
864 | 901 | |
865 | 902 | $str = $finalizedFormats[$str]; |
866 | 903 | |
867 | - if (!isset($locale_cache)) |
|
868 | - $locale_cache = setlocale(LC_TIME, $txt['lang_locale'] . !empty($modSettings['global_character_set']) ? '.' . $modSettings['global_character_set'] : ''); |
|
904 | + if (!isset($locale_cache)) { |
|
905 | + $locale_cache = setlocale(LC_TIME, $txt['lang_locale'] . !empty($modSettings['global_character_set']) ? '.' . $modSettings['global_character_set'] : ''); |
|
906 | + } |
|
869 | 907 | |
870 | 908 | if ($locale_cache !== false) |
871 | 909 | { |
872 | 910 | // Check if another process changed the locale |
873 | - if ($process_safe === true && setlocale(LC_TIME, '0') != $locale_cache) |
|
874 | - setlocale(LC_TIME, $txt['lang_locale'] . !empty($modSettings['global_character_set']) ? '.' . $modSettings['global_character_set'] : ''); |
|
911 | + if ($process_safe === true && setlocale(LC_TIME, '0') != $locale_cache) { |
|
912 | + setlocale(LC_TIME, $txt['lang_locale'] . !empty($modSettings['global_character_set']) ? '.' . $modSettings['global_character_set'] : ''); |
|
913 | + } |
|
875 | 914 | |
876 | - if (!isset($non_twelve_hour)) |
|
877 | - $non_twelve_hour = trim(strftime('%p')) === ''; |
|
878 | - if ($non_twelve_hour && strpos($str, '%p') !== false) |
|
879 | - $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
915 | + if (!isset($non_twelve_hour)) { |
|
916 | + $non_twelve_hour = trim(strftime('%p')) === ''; |
|
917 | + } |
|
918 | + if ($non_twelve_hour && strpos($str, '%p') !== false) { |
|
919 | + $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
920 | + } |
|
880 | 921 | |
881 | - foreach (array('%a', '%A', '%b', '%B') as $token) |
|
882 | - if (strpos($str, $token) !== false) |
|
922 | + foreach (array('%a', '%A', '%b', '%B') as $token) { |
|
923 | + if (strpos($str, $token) !== false) |
|
883 | 924 | $str = str_replace($token, strftime($token, $time), $str); |
884 | - } |
|
885 | - else |
|
925 | + } |
|
926 | + } else |
|
886 | 927 | { |
887 | 928 | // Do-it-yourself time localization. Fun. |
888 | - foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) |
|
889 | - if (strpos($str, $token) !== false) |
|
929 | + foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) { |
|
930 | + if (strpos($str, $token) !== false) |
|
890 | 931 | $str = str_replace($token, $txt[$text_label][(int) strftime($token === '%a' || $token === '%A' ? '%w' : '%m', $time)], $str); |
932 | + } |
|
891 | 933 | |
892 | - if (strpos($str, '%p') !== false) |
|
893 | - $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
934 | + if (strpos($str, '%p') !== false) { |
|
935 | + $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
936 | + } |
|
894 | 937 | } |
895 | 938 | |
896 | 939 | // Format the time and then restore any literal percent characters |
@@ -913,16 +956,19 @@ discard block |
||
913 | 956 | static $translation = array(); |
914 | 957 | |
915 | 958 | // Determine the character set... Default to UTF-8 |
916 | - if (empty($context['character_set'])) |
|
917 | - $charset = 'UTF-8'; |
|
959 | + if (empty($context['character_set'])) { |
|
960 | + $charset = 'UTF-8'; |
|
961 | + } |
|
918 | 962 | // Use ISO-8859-1 in place of non-supported ISO-8859 charsets... |
919 | - elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) |
|
920 | - $charset = 'ISO-8859-1'; |
|
921 | - else |
|
922 | - $charset = $context['character_set']; |
|
963 | + elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) { |
|
964 | + $charset = 'ISO-8859-1'; |
|
965 | + } else { |
|
966 | + $charset = $context['character_set']; |
|
967 | + } |
|
923 | 968 | |
924 | - if (empty($translation)) |
|
925 | - $translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array(''' => '\'', ''' => '\'', ' ' => ' '); |
|
969 | + if (empty($translation)) { |
|
970 | + $translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array(''' => '\'', ''' => '\'', ' ' => ' '); |
|
971 | + } |
|
926 | 972 | |
927 | 973 | return strtr($string, $translation); |
928 | 974 | } |
@@ -944,8 +990,9 @@ discard block |
||
944 | 990 | global $smcFunc; |
945 | 991 | |
946 | 992 | // It was already short enough! |
947 | - if ($smcFunc['strlen']($subject) <= $len) |
|
948 | - return $subject; |
|
993 | + if ($smcFunc['strlen']($subject) <= $len) { |
|
994 | + return $subject; |
|
995 | + } |
|
949 | 996 | |
950 | 997 | // Shorten it by the length it was too long, and strip off junk from the end. |
951 | 998 | return $smcFunc['substr']($subject, 0, $len) . '...'; |
@@ -964,10 +1011,11 @@ discard block |
||
964 | 1011 | { |
965 | 1012 | global $user_info, $modSettings; |
966 | 1013 | |
967 | - if ($timestamp === null) |
|
968 | - $timestamp = time(); |
|
969 | - elseif ($timestamp == 0) |
|
970 | - return 0; |
|
1014 | + if ($timestamp === null) { |
|
1015 | + $timestamp = time(); |
|
1016 | + } elseif ($timestamp == 0) { |
|
1017 | + return 0; |
|
1018 | + } |
|
971 | 1019 | |
972 | 1020 | return $timestamp + ($modSettings['time_offset'] + ($use_user_offset ? $user_info['time_offset'] : 0)) * 3600; |
973 | 1021 | } |
@@ -996,8 +1044,9 @@ discard block |
||
996 | 1044 | $array[$i] = $array[$j]; |
997 | 1045 | $array[$j] = $temp; |
998 | 1046 | |
999 | - for ($i = 1; $p[$i] == 0; $i++) |
|
1000 | - $p[$i] = 1; |
|
1047 | + for ($i = 1; $p[$i] == 0; $i++) { |
|
1048 | + $p[$i] = 1; |
|
1049 | + } |
|
1001 | 1050 | |
1002 | 1051 | $orders[] = $array; |
1003 | 1052 | } |
@@ -1029,12 +1078,14 @@ discard block |
||
1029 | 1078 | static $disabled; |
1030 | 1079 | |
1031 | 1080 | // Don't waste cycles |
1032 | - if ($message === '') |
|
1033 | - return ''; |
|
1081 | + if ($message === '') { |
|
1082 | + return ''; |
|
1083 | + } |
|
1034 | 1084 | |
1035 | 1085 | // Just in case it wasn't determined yet whether UTF-8 is enabled. |
1036 | - if (!isset($context['utf8'])) |
|
1037 | - $context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8'; |
|
1086 | + if (!isset($context['utf8'])) { |
|
1087 | + $context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8'; |
|
1088 | + } |
|
1038 | 1089 | |
1039 | 1090 | // Clean up any cut/paste issues we may have |
1040 | 1091 | $message = sanitizeMSCutPaste($message); |
@@ -1046,13 +1097,15 @@ discard block |
||
1046 | 1097 | return $message; |
1047 | 1098 | } |
1048 | 1099 | |
1049 | - if ($smileys !== null && ($smileys == '1' || $smileys == '0')) |
|
1050 | - $smileys = (bool) $smileys; |
|
1100 | + if ($smileys !== null && ($smileys == '1' || $smileys == '0')) { |
|
1101 | + $smileys = (bool) $smileys; |
|
1102 | + } |
|
1051 | 1103 | |
1052 | 1104 | if (empty($modSettings['enableBBC']) && $message !== false) |
1053 | 1105 | { |
1054 | - if ($smileys === true) |
|
1055 | - parsesmileys($message); |
|
1106 | + if ($smileys === true) { |
|
1107 | + parsesmileys($message); |
|
1108 | + } |
|
1056 | 1109 | |
1057 | 1110 | return $message; |
1058 | 1111 | } |
@@ -1065,8 +1118,9 @@ discard block |
||
1065 | 1118 | } |
1066 | 1119 | |
1067 | 1120 | // Ensure $modSettings['tld_regex'] contains a valid regex for the autolinker |
1068 | - if (!empty($modSettings['autoLinkUrls'])) |
|
1069 | - set_tld_regex(); |
|
1121 | + if (!empty($modSettings['autoLinkUrls'])) { |
|
1122 | + set_tld_regex(); |
|
1123 | + } |
|
1070 | 1124 | |
1071 | 1125 | // Allow mods access before entering the main parse_bbc loop |
1072 | 1126 | call_integration_hook('integrate_pre_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags)); |
@@ -1080,8 +1134,9 @@ discard block |
||
1080 | 1134 | |
1081 | 1135 | $temp = explode(',', strtolower($modSettings['disabledBBC'])); |
1082 | 1136 | |
1083 | - foreach ($temp as $tag) |
|
1084 | - $disabled[trim($tag)] = true; |
|
1137 | + foreach ($temp as $tag) { |
|
1138 | + $disabled[trim($tag)] = true; |
|
1139 | + } |
|
1085 | 1140 | } |
1086 | 1141 | |
1087 | 1142 | // The YouTube bbc needs this for its origin parameter |
@@ -1215,8 +1270,9 @@ discard block |
||
1215 | 1270 | $returnContext = ''; |
1216 | 1271 | |
1217 | 1272 | // BBC or the entire attachments feature is disabled |
1218 | - if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) |
|
1219 | - return $data; |
|
1273 | + if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) { |
|
1274 | + return $data; |
|
1275 | + } |
|
1220 | 1276 | |
1221 | 1277 | // Save the attach ID. |
1222 | 1278 | $attachID = $data; |
@@ -1227,8 +1283,9 @@ discard block |
||
1227 | 1283 | $currentAttachment = parseAttachBBC($attachID); |
1228 | 1284 | |
1229 | 1285 | // parseAttachBBC will return a string ($txt key) rather than dying with a fatal_error. Up to you to decide what to do. |
1230 | - if (is_string($currentAttachment)) |
|
1231 | - return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment; |
|
1286 | + if (is_string($currentAttachment)) { |
|
1287 | + return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment; |
|
1288 | + } |
|
1232 | 1289 | |
1233 | 1290 | if (!empty($currentAttachment['is_image'])) |
1234 | 1291 | { |
@@ -1244,15 +1301,17 @@ discard block |
||
1244 | 1301 | $height = ' height="' . $currentAttachment['height'] . '"'; |
1245 | 1302 | } |
1246 | 1303 | |
1247 | - if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) |
|
1248 | - $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>'; |
|
1249 | - else |
|
1250 | - $returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>'; |
|
1304 | + if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) { |
|
1305 | + $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>'; |
|
1306 | + } else { |
|
1307 | + $returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>'; |
|
1308 | + } |
|
1251 | 1309 | } |
1252 | 1310 | |
1253 | 1311 | // No image. Show a link. |
1254 | - else |
|
1255 | - $returnContext .= $currentAttachment['link']; |
|
1312 | + else { |
|
1313 | + $returnContext .= $currentAttachment['link']; |
|
1314 | + } |
|
1256 | 1315 | |
1257 | 1316 | // Gotta append what we just did. |
1258 | 1317 | $data = $returnContext; |
@@ -1306,8 +1365,9 @@ discard block |
||
1306 | 1365 | for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++) |
1307 | 1366 | { |
1308 | 1367 | // Do PHP code coloring? |
1309 | - if ($php_parts[$php_i] != '<?php') |
|
1310 | - continue; |
|
1368 | + if ($php_parts[$php_i] != '<?php') { |
|
1369 | + continue; |
|
1370 | + } |
|
1311 | 1371 | |
1312 | 1372 | $php_string = ''; |
1313 | 1373 | while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?>') |
@@ -1323,8 +1383,9 @@ discard block |
||
1323 | 1383 | $data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data); |
1324 | 1384 | |
1325 | 1385 | // Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection. |
1326 | - if ($context['browser']['is_opera']) |
|
1327 | - $data .= ' '; |
|
1386 | + if ($context['browser']['is_opera']) { |
|
1387 | + $data .= ' '; |
|
1388 | + } |
|
1328 | 1389 | } |
1329 | 1390 | }, |
1330 | 1391 | 'block_level' => true, |
@@ -1343,8 +1404,9 @@ discard block |
||
1343 | 1404 | for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++) |
1344 | 1405 | { |
1345 | 1406 | // Do PHP code coloring? |
1346 | - if ($php_parts[$php_i] != '<?php') |
|
1347 | - continue; |
|
1407 | + if ($php_parts[$php_i] != '<?php') { |
|
1408 | + continue; |
|
1409 | + } |
|
1348 | 1410 | |
1349 | 1411 | $php_string = ''; |
1350 | 1412 | while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?>') |
@@ -1360,8 +1422,9 @@ discard block |
||
1360 | 1422 | $data[0] = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data[0]); |
1361 | 1423 | |
1362 | 1424 | // Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection. |
1363 | - if ($context['browser']['is_opera']) |
|
1364 | - $data[0] .= ' '; |
|
1425 | + if ($context['browser']['is_opera']) { |
|
1426 | + $data[0] .= ' '; |
|
1427 | + } |
|
1365 | 1428 | } |
1366 | 1429 | }, |
1367 | 1430 | 'block_level' => true, |
@@ -1402,10 +1465,11 @@ discard block |
||
1402 | 1465 | { |
1403 | 1466 | $class = 'class="bbc_float float' . (strpos($data, 'left') === 0 ? 'left' : 'right') . '"'; |
1404 | 1467 | |
1405 | - if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches)) |
|
1406 | - $css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"'; |
|
1407 | - else |
|
1408 | - $css = ''; |
|
1468 | + if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches)) { |
|
1469 | + $css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"'; |
|
1470 | + } else { |
|
1471 | + $css = ''; |
|
1472 | + } |
|
1409 | 1473 | |
1410 | 1474 | $data = $class . $css; |
1411 | 1475 | }, |
@@ -1420,8 +1484,9 @@ discard block |
||
1420 | 1484 | { |
1421 | 1485 | $data = strtr($data, array('<br />' => '')); |
1422 | 1486 | |
1423 | - if (strpos($data, 'ftp://') !== 0 && strpos($data, 'ftps://') !== 0) |
|
1424 | - $data = 'ftp://' . $data; |
|
1487 | + if (strpos($data, 'ftp://') !== 0 && strpos($data, 'ftps://') !== 0) { |
|
1488 | + $data = 'ftp://' . $data; |
|
1489 | + } |
|
1425 | 1490 | }, |
1426 | 1491 | ), |
1427 | 1492 | array( |
@@ -1431,8 +1496,9 @@ discard block |
||
1431 | 1496 | 'after' => '</a>', |
1432 | 1497 | 'validate' => function(&$tag, &$data, $disabled) |
1433 | 1498 | { |
1434 | - if (strpos($data, 'ftp://') !== 0 && strpos($data, 'ftps://') !== 0) |
|
1435 | - $data = 'ftp://' . $data; |
|
1499 | + if (strpos($data, 'ftp://') !== 0 && strpos($data, 'ftps://') !== 0) { |
|
1500 | + $data = 'ftp://' . $data; |
|
1501 | + } |
|
1436 | 1502 | }, |
1437 | 1503 | 'disallow_children' => array('email', 'ftp', 'url', 'iurl'), |
1438 | 1504 | 'disabled_after' => ' ($1)', |
@@ -1492,17 +1558,20 @@ discard block |
||
1492 | 1558 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1493 | 1559 | if ($image_proxy_enabled) |
1494 | 1560 | { |
1495 | - if (!empty($user_info['possibly_robot'])) |
|
1496 | - return; |
|
1561 | + if (!empty($user_info['possibly_robot'])) { |
|
1562 | + return; |
|
1563 | + } |
|
1497 | 1564 | |
1498 | - if (empty($scheme)) |
|
1499 | - $data = 'http://' . ltrim($data, ':/'); |
|
1565 | + if (empty($scheme)) { |
|
1566 | + $data = 'http://' . ltrim($data, ':/'); |
|
1567 | + } |
|
1500 | 1568 | |
1501 | - if ($scheme != 'https') |
|
1502 | - $data = get_proxied_url($data); |
|
1569 | + if ($scheme != 'https') { |
|
1570 | + $data = get_proxied_url($data); |
|
1571 | + } |
|
1572 | + } elseif (empty($scheme)) { |
|
1573 | + $data = '//' . ltrim($data, ':/'); |
|
1503 | 1574 | } |
1504 | - elseif (empty($scheme)) |
|
1505 | - $data = '//' . ltrim($data, ':/'); |
|
1506 | 1575 | }, |
1507 | 1576 | 'disabled_content' => '($1)', |
1508 | 1577 | ), |
@@ -1518,17 +1587,20 @@ discard block |
||
1518 | 1587 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1519 | 1588 | if ($image_proxy_enabled) |
1520 | 1589 | { |
1521 | - if (!empty($user_info['possibly_robot'])) |
|
1522 | - return; |
|
1590 | + if (!empty($user_info['possibly_robot'])) { |
|
1591 | + return; |
|
1592 | + } |
|
1523 | 1593 | |
1524 | - if (empty($scheme)) |
|
1525 | - $data = 'http://' . ltrim($data, ':/'); |
|
1594 | + if (empty($scheme)) { |
|
1595 | + $data = 'http://' . ltrim($data, ':/'); |
|
1596 | + } |
|
1526 | 1597 | |
1527 | - if ($scheme != 'https') |
|
1528 | - $data = get_proxied_url($data); |
|
1598 | + if ($scheme != 'https') { |
|
1599 | + $data = get_proxied_url($data); |
|
1600 | + } |
|
1601 | + } elseif (empty($scheme)) { |
|
1602 | + $data = '//' . ltrim($data, ':/'); |
|
1529 | 1603 | } |
1530 | - elseif (empty($scheme)) |
|
1531 | - $data = '//' . ltrim($data, ':/'); |
|
1532 | 1604 | }, |
1533 | 1605 | 'disabled_content' => '($1)', |
1534 | 1606 | ), |
@@ -1540,8 +1612,9 @@ discard block |
||
1540 | 1612 | { |
1541 | 1613 | $data = strtr($data, array('<br>' => '')); |
1542 | 1614 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1543 | - if (empty($scheme)) |
|
1544 | - $data = '//' . ltrim($data, ':/'); |
|
1615 | + if (empty($scheme)) { |
|
1616 | + $data = '//' . ltrim($data, ':/'); |
|
1617 | + } |
|
1545 | 1618 | }, |
1546 | 1619 | ), |
1547 | 1620 | array( |
@@ -1552,13 +1625,14 @@ discard block |
||
1552 | 1625 | 'after' => '</a>', |
1553 | 1626 | 'validate' => function (&$tag, &$data, $disabled) |
1554 | 1627 | { |
1555 | - if (substr($data, 0, 1) == '#') |
|
1556 | - $data = '#post_' . substr($data, 1); |
|
1557 | - else |
|
1628 | + if (substr($data, 0, 1) == '#') { |
|
1629 | + $data = '#post_' . substr($data, 1); |
|
1630 | + } else |
|
1558 | 1631 | { |
1559 | 1632 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1560 | - if (empty($scheme)) |
|
1561 | - $data = '//' . ltrim($data, ':/'); |
|
1633 | + if (empty($scheme)) { |
|
1634 | + $data = '//' . ltrim($data, ':/'); |
|
1635 | + } |
|
1562 | 1636 | } |
1563 | 1637 | }, |
1564 | 1638 | 'disallow_children' => array('email', 'ftp', 'url', 'iurl'), |
@@ -1649,8 +1723,9 @@ discard block |
||
1649 | 1723 | { |
1650 | 1724 | $add_begin = substr(trim($data), 0, 5) != '<?'; |
1651 | 1725 | $data = highlight_php_code($add_begin ? '<?php ' . $data . '?>' : $data); |
1652 | - if ($add_begin) |
|
1653 | - $data = preg_replace(array('~^(.+?)<\?.{0,40}?php(?: |\s)~', '~\?>((?:</(font|span)>)*)$~'), '$1', $data, 2); |
|
1726 | + if ($add_begin) { |
|
1727 | + $data = preg_replace(array('~^(.+?)<\?.{0,40}?php(?: |\s)~', '~\?>((?:</(font|span)>)*)$~'), '$1', $data, 2); |
|
1728 | + } |
|
1654 | 1729 | } |
1655 | 1730 | }, |
1656 | 1731 | 'block_level' => false, |
@@ -1763,20 +1838,17 @@ discard block |
||
1763 | 1838 | : function(&$tag, &$data, $disabled) |
1764 | 1839 | { |
1765 | 1840 | |
1766 | - if ($data[1] == 'top' || (is_numeric($data[1]) && $data[1] < 50)) |
|
1767 | - $data[1] = '0 -2px 1px'; |
|
1768 | - |
|
1769 | - elseif ($data[1] == 'right' || (is_numeric($data[1]) && $data[1] < 100)) |
|
1770 | - $data[1] = '2px 0 1px'; |
|
1771 | - |
|
1772 | - elseif ($data[1] == 'bottom' || (is_numeric($data[1]) && $data[1] < 190)) |
|
1773 | - $data[1] = '0 2px 1px'; |
|
1774 | - |
|
1775 | - elseif ($data[1] == 'left' || (is_numeric($data[1]) && $data[1] < 280)) |
|
1776 | - $data[1] = '-2px 0 1px'; |
|
1777 | - |
|
1778 | - else |
|
1779 | - $data[1] = '1px 1px 1px'; |
|
1841 | + if ($data[1] == 'top' || (is_numeric($data[1]) && $data[1] < 50)) { |
|
1842 | + $data[1] = '0 -2px 1px'; |
|
1843 | + } elseif ($data[1] == 'right' || (is_numeric($data[1]) && $data[1] < 100)) { |
|
1844 | + $data[1] = '2px 0 1px'; |
|
1845 | + } elseif ($data[1] == 'bottom' || (is_numeric($data[1]) && $data[1] < 190)) { |
|
1846 | + $data[1] = '0 2px 1px'; |
|
1847 | + } elseif ($data[1] == 'left' || (is_numeric($data[1]) && $data[1] < 280)) { |
|
1848 | + $data[1] = '-2px 0 1px'; |
|
1849 | + } else { |
|
1850 | + $data[1] = '1px 1px 1px'; |
|
1851 | + } |
|
1780 | 1852 | }, |
1781 | 1853 | ), |
1782 | 1854 | array( |
@@ -1832,10 +1904,11 @@ discard block |
||
1832 | 1904 | 'content' => '$1', |
1833 | 1905 | 'validate' => function (&$tag, &$data, $disabled) |
1834 | 1906 | { |
1835 | - if (is_numeric($data)) |
|
1836 | - $data = timeformat($data); |
|
1837 | - else |
|
1838 | - $tag['content'] = '[time]$1[/time]'; |
|
1907 | + if (is_numeric($data)) { |
|
1908 | + $data = timeformat($data); |
|
1909 | + } else { |
|
1910 | + $tag['content'] = '[time]$1[/time]'; |
|
1911 | + } |
|
1839 | 1912 | }, |
1840 | 1913 | ), |
1841 | 1914 | array( |
@@ -1867,8 +1940,9 @@ discard block |
||
1867 | 1940 | { |
1868 | 1941 | $data = strtr($data, array('<br>' => '')); |
1869 | 1942 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1870 | - if (empty($scheme)) |
|
1871 | - $data = '//' . ltrim($data, ':/'); |
|
1943 | + if (empty($scheme)) { |
|
1944 | + $data = '//' . ltrim($data, ':/'); |
|
1945 | + } |
|
1872 | 1946 | }, |
1873 | 1947 | ), |
1874 | 1948 | array( |
@@ -1880,8 +1954,9 @@ discard block |
||
1880 | 1954 | 'validate' => function (&$tag, &$data, $disabled) |
1881 | 1955 | { |
1882 | 1956 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1883 | - if (empty($scheme)) |
|
1884 | - $data = '//' . ltrim($data, ':/'); |
|
1957 | + if (empty($scheme)) { |
|
1958 | + $data = '//' . ltrim($data, ':/'); |
|
1959 | + } |
|
1885 | 1960 | }, |
1886 | 1961 | 'disallow_children' => array('email', 'ftp', 'url', 'iurl'), |
1887 | 1962 | 'disabled_after' => ' ($1)', |
@@ -1908,12 +1983,13 @@ discard block |
||
1908 | 1983 | ); |
1909 | 1984 | |
1910 | 1985 | // Handle legacy bbc codes. |
1911 | - foreach ($context['legacy_bbc'] as $bbc) |
|
1912 | - $codes[] = array( |
|
1986 | + foreach ($context['legacy_bbc'] as $bbc) { |
|
1987 | + $codes[] = array( |
|
1913 | 1988 | 'tag' => $bbc, |
1914 | 1989 | 'before' => '', |
1915 | 1990 | 'after' => '', |
1916 | 1991 | ); |
1992 | + } |
|
1917 | 1993 | |
1918 | 1994 | // Let mods add new BBC without hassle. |
1919 | 1995 | call_integration_hook('integrate_bbc_codes', array(&$codes, &$no_autolink_tags)); |
@@ -1921,8 +1997,9 @@ discard block |
||
1921 | 1997 | // This is mainly for the bbc manager, so it's easy to add tags above. Custom BBC should be added above this line. |
1922 | 1998 | if ($message === false) |
1923 | 1999 | { |
1924 | - if (isset($temp_bbc)) |
|
1925 | - $bbc_codes = $temp_bbc; |
|
2000 | + if (isset($temp_bbc)) { |
|
2001 | + $bbc_codes = $temp_bbc; |
|
2002 | + } |
|
1926 | 2003 | usort($codes, function ($a, $b) { |
1927 | 2004 | return strcmp($a['tag'], $b['tag']); |
1928 | 2005 | }); |
@@ -1942,8 +2019,9 @@ discard block |
||
1942 | 2019 | ); |
1943 | 2020 | if (!isset($disabled['li']) && !isset($disabled['list'])) |
1944 | 2021 | { |
1945 | - foreach ($itemcodes as $c => $dummy) |
|
1946 | - $bbc_codes[$c] = array(); |
|
2022 | + foreach ($itemcodes as $c => $dummy) { |
|
2023 | + $bbc_codes[$c] = array(); |
|
2024 | + } |
|
1947 | 2025 | } |
1948 | 2026 | |
1949 | 2027 | // Shhhh! |
@@ -1964,12 +2042,14 @@ discard block |
||
1964 | 2042 | foreach ($codes as $code) |
1965 | 2043 | { |
1966 | 2044 | // Make it easier to process parameters later |
1967 | - if (!empty($code['parameters'])) |
|
1968 | - ksort($code['parameters'], SORT_STRING); |
|
2045 | + if (!empty($code['parameters'])) { |
|
2046 | + ksort($code['parameters'], SORT_STRING); |
|
2047 | + } |
|
1969 | 2048 | |
1970 | 2049 | // If we are not doing every tag only do ones we are interested in. |
1971 | - if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) |
|
1972 | - $bbc_codes[substr($code['tag'], 0, 1)][] = $code; |
|
2050 | + if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) { |
|
2051 | + $bbc_codes[substr($code['tag'], 0, 1)][] = $code; |
|
2052 | + } |
|
1973 | 2053 | } |
1974 | 2054 | $codes = null; |
1975 | 2055 | } |
@@ -1980,8 +2060,9 @@ discard block |
||
1980 | 2060 | // It's likely this will change if the message is modified. |
1981 | 2061 | $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']); |
1982 | 2062 | |
1983 | - if (($temp = cache_get_data($cache_key, 240)) != null) |
|
1984 | - return $temp; |
|
2063 | + if (($temp = cache_get_data($cache_key, 240)) != null) { |
|
2064 | + return $temp; |
|
2065 | + } |
|
1985 | 2066 | |
1986 | 2067 | $cache_t = microtime(); |
1987 | 2068 | } |
@@ -2013,8 +2094,9 @@ discard block |
||
2013 | 2094 | $disabled['flash'] = true; |
2014 | 2095 | |
2015 | 2096 | // @todo Change maybe? |
2016 | - if (!isset($_GET['images'])) |
|
2017 | - $disabled['img'] = true; |
|
2097 | + if (!isset($_GET['images'])) { |
|
2098 | + $disabled['img'] = true; |
|
2099 | + } |
|
2018 | 2100 | |
2019 | 2101 | // @todo Interface/setting to add more? |
2020 | 2102 | } |
@@ -2025,8 +2107,9 @@ discard block |
||
2025 | 2107 | $alltags = array(); |
2026 | 2108 | foreach ($bbc_codes as $section) |
2027 | 2109 | { |
2028 | - foreach ($section as $code) |
|
2029 | - $alltags[] = $code['tag']; |
|
2110 | + foreach ($section as $code) { |
|
2111 | + $alltags[] = $code['tag']; |
|
2112 | + } |
|
2030 | 2113 | } |
2031 | 2114 | $alltags_regex = '\b' . implode("\b|\b", array_unique($alltags)) . '\b'; |
2032 | 2115 | |
@@ -2038,8 +2121,9 @@ discard block |
||
2038 | 2121 | $pos = isset($matches[0][1]) ? $matches[0][1] : false; |
2039 | 2122 | |
2040 | 2123 | // Failsafe. |
2041 | - if ($pos === false || $last_pos > $pos) |
|
2042 | - $pos = strlen($message) + 1; |
|
2124 | + if ($pos === false || $last_pos > $pos) { |
|
2125 | + $pos = strlen($message) + 1; |
|
2126 | + } |
|
2043 | 2127 | |
2044 | 2128 | // Can't have a one letter smiley, URL, or email! (sorry.) |
2045 | 2129 | if ($last_pos < $pos - 1) |
@@ -2057,8 +2141,9 @@ discard block |
||
2057 | 2141 | |
2058 | 2142 | // <br> should be empty. |
2059 | 2143 | $empty_tags = array('br', 'hr'); |
2060 | - foreach ($empty_tags as $tag) |
|
2061 | - $data = str_replace(array('<' . $tag . '>', '<' . $tag . '/>', '<' . $tag . ' />'), '<' . $tag . '>', $data); |
|
2144 | + foreach ($empty_tags as $tag) { |
|
2145 | + $data = str_replace(array('<' . $tag . '>', '<' . $tag . '/>', '<' . $tag . ' />'), '<' . $tag . '>', $data); |
|
2146 | + } |
|
2062 | 2147 | |
2063 | 2148 | // b, u, i, s, pre... basic tags. |
2064 | 2149 | $closable_tags = array('b', 'u', 'i', 's', 'em', 'ins', 'del', 'pre', 'blockquote', 'strong'); |
@@ -2067,8 +2152,9 @@ discard block |
||
2067 | 2152 | $diff = substr_count($data, '<' . $tag . '>') - substr_count($data, '</' . $tag . '>'); |
2068 | 2153 | $data = strtr($data, array('<' . $tag . '>' => '<' . $tag . '>', '</' . $tag . '>' => '</' . $tag . '>')); |
2069 | 2154 | |
2070 | - if ($diff > 0) |
|
2071 | - $data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1); |
|
2155 | + if ($diff > 0) { |
|
2156 | + $data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1); |
|
2157 | + } |
|
2072 | 2158 | } |
2073 | 2159 | |
2074 | 2160 | // Do <img ...> - with security... action= -> action-. |
@@ -2081,8 +2167,9 @@ discard block |
||
2081 | 2167 | $alt = empty($matches[3][$match]) ? '' : ' alt=' . preg_replace('~^"|"$~', '', $matches[3][$match]); |
2082 | 2168 | |
2083 | 2169 | // Remove action= from the URL - no funny business, now. |
2084 | - if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) |
|
2085 | - $imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag); |
|
2170 | + if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) { |
|
2171 | + $imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag); |
|
2172 | + } |
|
2086 | 2173 | |
2087 | 2174 | $replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]'; |
2088 | 2175 | } |
@@ -2097,16 +2184,18 @@ discard block |
||
2097 | 2184 | $no_autolink_area = false; |
2098 | 2185 | if (!empty($open_tags)) |
2099 | 2186 | { |
2100 | - foreach ($open_tags as $open_tag) |
|
2101 | - if (in_array($open_tag['tag'], $no_autolink_tags)) |
|
2187 | + foreach ($open_tags as $open_tag) { |
|
2188 | + if (in_array($open_tag['tag'], $no_autolink_tags)) |
|
2102 | 2189 | $no_autolink_area = true; |
2190 | + } |
|
2103 | 2191 | } |
2104 | 2192 | |
2105 | 2193 | // Don't go backwards. |
2106 | 2194 | // @todo Don't think is the real solution.... |
2107 | 2195 | $lastAutoPos = isset($lastAutoPos) ? $lastAutoPos : 0; |
2108 | - if ($pos < $lastAutoPos) |
|
2109 | - $no_autolink_area = true; |
|
2196 | + if ($pos < $lastAutoPos) { |
|
2197 | + $no_autolink_area = true; |
|
2198 | + } |
|
2110 | 2199 | $lastAutoPos = $pos; |
2111 | 2200 | |
2112 | 2201 | if (!$no_autolink_area) |
@@ -2211,29 +2300,33 @@ discard block |
||
2211 | 2300 | $url = array_shift($matches); |
2212 | 2301 | |
2213 | 2302 | // If this isn't a clean URL, bail out |
2214 | - if ($url != sanitize_iri($url)) |
|
2215 | - return $url; |
|
2303 | + if ($url != sanitize_iri($url)) { |
|
2304 | + return $url; |
|
2305 | + } |
|
2216 | 2306 | |
2217 | 2307 | $scheme = parse_url($url, PHP_URL_SCHEME); |
2218 | 2308 | |
2219 | 2309 | if ($scheme == 'mailto') |
2220 | 2310 | { |
2221 | 2311 | $email_address = str_replace('mailto:', '', $url); |
2222 | - if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) |
|
2223 | - return '[email=' . $email_address . ']' . $url . '[/email]'; |
|
2224 | - else |
|
2225 | - return $url; |
|
2312 | + if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) { |
|
2313 | + return '[email=' . $email_address . ']' . $url . '[/email]'; |
|
2314 | + } else { |
|
2315 | + return $url; |
|
2316 | + } |
|
2226 | 2317 | } |
2227 | 2318 | |
2228 | 2319 | // Are we linking a schemeless URL or naked domain name (e.g. "example.com")? |
2229 | - if (empty($scheme)) |
|
2230 | - $fullUrl = '//' . ltrim($url, ':/'); |
|
2231 | - else |
|
2232 | - $fullUrl = $url; |
|
2320 | + if (empty($scheme)) { |
|
2321 | + $fullUrl = '//' . ltrim($url, ':/'); |
|
2322 | + } else { |
|
2323 | + $fullUrl = $url; |
|
2324 | + } |
|
2233 | 2325 | |
2234 | 2326 | // Make sure that $fullUrl really is valid |
2235 | - if (validate_iri((strpos($fullUrl, '//') === 0 ? 'http:' : '' ) . $fullUrl) === false) |
|
2236 | - return $url; |
|
2327 | + if (validate_iri((strpos($fullUrl, '//') === 0 ? 'http:' : '' ) . $fullUrl) === false) { |
|
2328 | + return $url; |
|
2329 | + } |
|
2237 | 2330 | |
2238 | 2331 | return '[url="' . str_replace(array('[', ']'), array('[', ']'), $fullUrl) . '"]' . $url . '[/url]'; |
2239 | 2332 | }, $data); |
@@ -2282,22 +2375,25 @@ discard block |
||
2282 | 2375 | } |
2283 | 2376 | |
2284 | 2377 | // Are we there yet? Are we there yet? |
2285 | - if ($pos >= strlen($message) - 1) |
|
2286 | - break; |
|
2378 | + if ($pos >= strlen($message) - 1) { |
|
2379 | + break; |
|
2380 | + } |
|
2287 | 2381 | |
2288 | 2382 | $tags = strtolower($message[$pos + 1]); |
2289 | 2383 | |
2290 | 2384 | if ($tags == '/' && !empty($open_tags)) |
2291 | 2385 | { |
2292 | 2386 | $pos2 = strpos($message, ']', $pos + 1); |
2293 | - if ($pos2 == $pos + 2) |
|
2294 | - continue; |
|
2387 | + if ($pos2 == $pos + 2) { |
|
2388 | + continue; |
|
2389 | + } |
|
2295 | 2390 | |
2296 | 2391 | $look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2)); |
2297 | 2392 | |
2298 | 2393 | // A closing tag that doesn't match any open tags? Skip it. |
2299 | - if (!in_array($look_for, array_map(function($code){return $code['tag'];}, $open_tags))) |
|
2300 | - continue; |
|
2394 | + if (!in_array($look_for, array_map(function($code){return $code['tag'];}, $open_tags))) { |
|
2395 | + continue; |
|
2396 | + } |
|
2301 | 2397 | |
2302 | 2398 | $to_close = array(); |
2303 | 2399 | $block_level = null; |
@@ -2305,8 +2401,9 @@ discard block |
||
2305 | 2401 | do |
2306 | 2402 | { |
2307 | 2403 | $tag = array_pop($open_tags); |
2308 | - if (!$tag) |
|
2309 | - break; |
|
2404 | + if (!$tag) { |
|
2405 | + break; |
|
2406 | + } |
|
2310 | 2407 | |
2311 | 2408 | if (!empty($tag['block_level'])) |
2312 | 2409 | { |
@@ -2320,10 +2417,11 @@ discard block |
||
2320 | 2417 | // The idea is, if we are LOOKING for a block level tag, we can close them on the way. |
2321 | 2418 | if (strlen($look_for) > 0 && isset($bbc_codes[$look_for[0]])) |
2322 | 2419 | { |
2323 | - foreach ($bbc_codes[$look_for[0]] as $temp) |
|
2324 | - if ($temp['tag'] == $look_for) |
|
2420 | + foreach ($bbc_codes[$look_for[0]] as $temp) { |
|
2421 | + if ($temp['tag'] == $look_for) |
|
2325 | 2422 | { |
2326 | 2423 | $block_level = !empty($temp['block_level']); |
2424 | + } |
|
2327 | 2425 | break; |
2328 | 2426 | } |
2329 | 2427 | } |
@@ -2345,15 +2443,15 @@ discard block |
||
2345 | 2443 | { |
2346 | 2444 | $open_tags = $to_close; |
2347 | 2445 | continue; |
2348 | - } |
|
2349 | - elseif (!empty($to_close) && $tag['tag'] != $look_for) |
|
2446 | + } elseif (!empty($to_close) && $tag['tag'] != $look_for) |
|
2350 | 2447 | { |
2351 | 2448 | if ($block_level === null && isset($look_for[0], $bbc_codes[$look_for[0]])) |
2352 | 2449 | { |
2353 | - foreach ($bbc_codes[$look_for[0]] as $temp) |
|
2354 | - if ($temp['tag'] == $look_for) |
|
2450 | + foreach ($bbc_codes[$look_for[0]] as $temp) { |
|
2451 | + if ($temp['tag'] == $look_for) |
|
2355 | 2452 | { |
2356 | 2453 | $block_level = !empty($temp['block_level']); |
2454 | + } |
|
2357 | 2455 | break; |
2358 | 2456 | } |
2359 | 2457 | } |
@@ -2361,8 +2459,9 @@ discard block |
||
2361 | 2459 | // We're not looking for a block level tag (or maybe even a tag that exists...) |
2362 | 2460 | if (!$block_level) |
2363 | 2461 | { |
2364 | - foreach ($to_close as $tag) |
|
2365 | - array_push($open_tags, $tag); |
|
2462 | + foreach ($to_close as $tag) { |
|
2463 | + array_push($open_tags, $tag); |
|
2464 | + } |
|
2366 | 2465 | continue; |
2367 | 2466 | } |
2368 | 2467 | } |
@@ -2375,14 +2474,17 @@ discard block |
||
2375 | 2474 | |
2376 | 2475 | // See the comment at the end of the big loop - just eating whitespace ;). |
2377 | 2476 | $whitespace_regex = ''; |
2378 | - if (!empty($tag['block_level'])) |
|
2379 | - $whitespace_regex .= '( |\s)*(<br>)?'; |
|
2477 | + if (!empty($tag['block_level'])) { |
|
2478 | + $whitespace_regex .= '( |\s)*(<br>)?'; |
|
2479 | + } |
|
2380 | 2480 | // Trim one line of whitespace after unnested tags, but all of it after nested ones |
2381 | - if (!empty($tag['trim']) && $tag['trim'] != 'inside') |
|
2382 | - $whitespace_regex .= empty($tag['require_parents']) ? '( |\s)*' : '(<br>| |\s)*'; |
|
2481 | + if (!empty($tag['trim']) && $tag['trim'] != 'inside') { |
|
2482 | + $whitespace_regex .= empty($tag['require_parents']) ? '( |\s)*' : '(<br>| |\s)*'; |
|
2483 | + } |
|
2383 | 2484 | |
2384 | - if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) |
|
2385 | - $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
2485 | + if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) { |
|
2486 | + $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
2487 | + } |
|
2386 | 2488 | } |
2387 | 2489 | |
2388 | 2490 | if (!empty($to_close)) |
@@ -2395,8 +2497,9 @@ discard block |
||
2395 | 2497 | } |
2396 | 2498 | |
2397 | 2499 | // No tags for this character, so just keep going (fastest possible course.) |
2398 | - if (!isset($bbc_codes[$tags])) |
|
2399 | - continue; |
|
2500 | + if (!isset($bbc_codes[$tags])) { |
|
2501 | + continue; |
|
2502 | + } |
|
2400 | 2503 | |
2401 | 2504 | $inside = empty($open_tags) ? null : $open_tags[count($open_tags) - 1]; |
2402 | 2505 | $tag = null; |
@@ -2405,48 +2508,57 @@ discard block |
||
2405 | 2508 | $pt_strlen = strlen($possible['tag']); |
2406 | 2509 | |
2407 | 2510 | // Not a match? |
2408 | - if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) |
|
2409 | - continue; |
|
2511 | + if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) { |
|
2512 | + continue; |
|
2513 | + } |
|
2410 | 2514 | |
2411 | 2515 | $next_c = isset($message[$pos + 1 + $pt_strlen]) ? $message[$pos + 1 + $pt_strlen] : ''; |
2412 | 2516 | |
2413 | 2517 | // A tag is the last char maybe |
2414 | - if ($next_c == '') |
|
2415 | - break; |
|
2518 | + if ($next_c == '') { |
|
2519 | + break; |
|
2520 | + } |
|
2416 | 2521 | |
2417 | 2522 | // A test validation? |
2418 | - if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) |
|
2419 | - continue; |
|
2523 | + if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) { |
|
2524 | + continue; |
|
2525 | + } |
|
2420 | 2526 | // Do we want parameters? |
2421 | 2527 | elseif (!empty($possible['parameters'])) |
2422 | 2528 | { |
2423 | - if ($next_c != ' ') |
|
2424 | - continue; |
|
2425 | - } |
|
2426 | - elseif (isset($possible['type'])) |
|
2529 | + if ($next_c != ' ') { |
|
2530 | + continue; |
|
2531 | + } |
|
2532 | + } elseif (isset($possible['type'])) |
|
2427 | 2533 | { |
2428 | 2534 | // Do we need an equal sign? |
2429 | - if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') |
|
2430 | - continue; |
|
2535 | + if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') { |
|
2536 | + continue; |
|
2537 | + } |
|
2431 | 2538 | // Maybe we just want a /... |
2432 | - if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') |
|
2433 | - continue; |
|
2539 | + if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') { |
|
2540 | + continue; |
|
2541 | + } |
|
2434 | 2542 | // An immediate ]? |
2435 | - if ($possible['type'] == 'unparsed_content' && $next_c != ']') |
|
2436 | - continue; |
|
2543 | + if ($possible['type'] == 'unparsed_content' && $next_c != ']') { |
|
2544 | + continue; |
|
2545 | + } |
|
2437 | 2546 | } |
2438 | 2547 | // No type means 'parsed_content', which demands an immediate ] without parameters! |
2439 | - elseif ($next_c != ']') |
|
2440 | - continue; |
|
2548 | + elseif ($next_c != ']') { |
|
2549 | + continue; |
|
2550 | + } |
|
2441 | 2551 | |
2442 | 2552 | // Check allowed tree? |
2443 | - if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) |
|
2444 | - continue; |
|
2445 | - elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) |
|
2446 | - continue; |
|
2553 | + if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) { |
|
2554 | + continue; |
|
2555 | + } elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) { |
|
2556 | + continue; |
|
2557 | + } |
|
2447 | 2558 | // If this is in the list of disallowed child tags, don't parse it. |
2448 | - elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) |
|
2449 | - continue; |
|
2559 | + elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) { |
|
2560 | + continue; |
|
2561 | + } |
|
2450 | 2562 | |
2451 | 2563 | $pos1 = $pos + 1 + $pt_strlen + 1; |
2452 | 2564 | |
@@ -2458,8 +2570,9 @@ discard block |
||
2458 | 2570 | foreach ($open_tags as $open_quote) |
2459 | 2571 | { |
2460 | 2572 | // Every parent quote this quote has flips the styling |
2461 | - if ($open_quote['tag'] == 'quote') |
|
2462 | - $quote_alt = !$quote_alt; |
|
2573 | + if ($open_quote['tag'] == 'quote') { |
|
2574 | + $quote_alt = !$quote_alt; |
|
2575 | + } |
|
2463 | 2576 | } |
2464 | 2577 | // Add a class to the quote to style alternating blockquotes |
2465 | 2578 | $possible['before'] = strtr($possible['before'], array('<blockquote>' => '<blockquote class="bbc_' . ($quote_alt ? 'alternate' : 'standard') . '_quote">')); |
@@ -2470,8 +2583,9 @@ discard block |
||
2470 | 2583 | { |
2471 | 2584 | // Build a regular expression for each parameter for the current tag. |
2472 | 2585 | $preg = array(); |
2473 | - foreach ($possible['parameters'] as $p => $info) |
|
2474 | - $preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '"') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '"') . '\s*)' . (empty($info['optional']) ? '' : '?'); |
|
2586 | + foreach ($possible['parameters'] as $p => $info) { |
|
2587 | + $preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '"') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '"') . '\s*)' . (empty($info['optional']) ? '' : '?'); |
|
2588 | + } |
|
2475 | 2589 | |
2476 | 2590 | // Extract the string that potentially holds our parameters. |
2477 | 2591 | $blob = preg_split('~\[/?(?:' . $alltags_regex . ')~i', substr($message, $pos)); |
@@ -2490,24 +2604,27 @@ discard block |
||
2490 | 2604 | |
2491 | 2605 | $match = preg_match('~^' . implode('', $preg) . '$~i', implode(' ', $given_params), $matches) !== 0; |
2492 | 2606 | |
2493 | - if ($match) |
|
2494 | - $blob_counter = count($blobs) + 1; |
|
2607 | + if ($match) { |
|
2608 | + $blob_counter = count($blobs) + 1; |
|
2609 | + } |
|
2495 | 2610 | } |
2496 | 2611 | |
2497 | 2612 | // Didn't match our parameter list, try the next possible. |
2498 | - if (!$match) |
|
2499 | - continue; |
|
2613 | + if (!$match) { |
|
2614 | + continue; |
|
2615 | + } |
|
2500 | 2616 | |
2501 | 2617 | $params = array(); |
2502 | 2618 | for ($i = 1, $n = count($matches); $i < $n; $i += 2) |
2503 | 2619 | { |
2504 | 2620 | $key = strtok(ltrim($matches[$i]), '='); |
2505 | - if (isset($possible['parameters'][$key]['value'])) |
|
2506 | - $params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1])); |
|
2507 | - elseif (isset($possible['parameters'][$key]['validate'])) |
|
2508 | - $params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]); |
|
2509 | - else |
|
2510 | - $params['{' . $key . '}'] = $matches[$i + 1]; |
|
2621 | + if (isset($possible['parameters'][$key]['value'])) { |
|
2622 | + $params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1])); |
|
2623 | + } elseif (isset($possible['parameters'][$key]['validate'])) { |
|
2624 | + $params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]); |
|
2625 | + } else { |
|
2626 | + $params['{' . $key . '}'] = $matches[$i + 1]; |
|
2627 | + } |
|
2511 | 2628 | |
2512 | 2629 | // Just to make sure: replace any $ or { so they can't interpolate wrongly. |
2513 | 2630 | $params['{' . $key . '}'] = strtr($params['{' . $key . '}'], array('$' => '$', '{' => '{')); |
@@ -2515,23 +2632,26 @@ discard block |
||
2515 | 2632 | |
2516 | 2633 | foreach ($possible['parameters'] as $p => $info) |
2517 | 2634 | { |
2518 | - if (!isset($params['{' . $p . '}'])) |
|
2519 | - $params['{' . $p . '}'] = ''; |
|
2635 | + if (!isset($params['{' . $p . '}'])) { |
|
2636 | + $params['{' . $p . '}'] = ''; |
|
2637 | + } |
|
2520 | 2638 | } |
2521 | 2639 | |
2522 | 2640 | $tag = $possible; |
2523 | 2641 | |
2524 | 2642 | // Put the parameters into the string. |
2525 | - if (isset($tag['before'])) |
|
2526 | - $tag['before'] = strtr($tag['before'], $params); |
|
2527 | - if (isset($tag['after'])) |
|
2528 | - $tag['after'] = strtr($tag['after'], $params); |
|
2529 | - if (isset($tag['content'])) |
|
2530 | - $tag['content'] = strtr($tag['content'], $params); |
|
2643 | + if (isset($tag['before'])) { |
|
2644 | + $tag['before'] = strtr($tag['before'], $params); |
|
2645 | + } |
|
2646 | + if (isset($tag['after'])) { |
|
2647 | + $tag['after'] = strtr($tag['after'], $params); |
|
2648 | + } |
|
2649 | + if (isset($tag['content'])) { |
|
2650 | + $tag['content'] = strtr($tag['content'], $params); |
|
2651 | + } |
|
2531 | 2652 | |
2532 | 2653 | $pos1 += strlen($given_param_string); |
2533 | - } |
|
2534 | - else |
|
2654 | + } else |
|
2535 | 2655 | { |
2536 | 2656 | $tag = $possible; |
2537 | 2657 | $params = array(); |
@@ -2542,8 +2662,9 @@ discard block |
||
2542 | 2662 | // Item codes are complicated buggers... they are implicit [li]s and can make [list]s! |
2543 | 2663 | if ($smileys !== false && $tag === null && isset($itemcodes[$message[$pos + 1]]) && $message[$pos + 2] == ']' && !isset($disabled['list']) && !isset($disabled['li'])) |
2544 | 2664 | { |
2545 | - if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) |
|
2546 | - continue; |
|
2665 | + if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) { |
|
2666 | + continue; |
|
2667 | + } |
|
2547 | 2668 | |
2548 | 2669 | $tag = $itemcodes[$message[$pos + 1]]; |
2549 | 2670 | |
@@ -2564,9 +2685,9 @@ discard block |
||
2564 | 2685 | { |
2565 | 2686 | array_pop($open_tags); |
2566 | 2687 | $code = '</li>'; |
2688 | + } else { |
|
2689 | + $code = ''; |
|
2567 | 2690 | } |
2568 | - else |
|
2569 | - $code = ''; |
|
2570 | 2691 | |
2571 | 2692 | // Now we open a new tag. |
2572 | 2693 | $open_tags[] = array( |
@@ -2613,12 +2734,14 @@ discard block |
||
2613 | 2734 | } |
2614 | 2735 | |
2615 | 2736 | // No tag? Keep looking, then. Silly people using brackets without actual tags. |
2616 | - if ($tag === null) |
|
2617 | - continue; |
|
2737 | + if ($tag === null) { |
|
2738 | + continue; |
|
2739 | + } |
|
2618 | 2740 | |
2619 | 2741 | // Propagate the list to the child (so wrapping the disallowed tag won't work either.) |
2620 | - if (isset($inside['disallow_children'])) |
|
2621 | - $tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children']; |
|
2742 | + if (isset($inside['disallow_children'])) { |
|
2743 | + $tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children']; |
|
2744 | + } |
|
2622 | 2745 | |
2623 | 2746 | // Is this tag disabled? |
2624 | 2747 | if (isset($disabled[$tag['tag']])) |
@@ -2628,14 +2751,13 @@ discard block |
||
2628 | 2751 | $tag['before'] = !empty($tag['block_level']) ? '<div>' : ''; |
2629 | 2752 | $tag['after'] = !empty($tag['block_level']) ? '</div>' : ''; |
2630 | 2753 | $tag['content'] = isset($tag['type']) && $tag['type'] == 'closed' ? '' : (!empty($tag['block_level']) ? '<div>$1</div>' : '$1'); |
2631 | - } |
|
2632 | - elseif (isset($tag['disabled_before']) || isset($tag['disabled_after'])) |
|
2754 | + } elseif (isset($tag['disabled_before']) || isset($tag['disabled_after'])) |
|
2633 | 2755 | { |
2634 | 2756 | $tag['before'] = isset($tag['disabled_before']) ? $tag['disabled_before'] : (!empty($tag['block_level']) ? '<div>' : ''); |
2635 | 2757 | $tag['after'] = isset($tag['disabled_after']) ? $tag['disabled_after'] : (!empty($tag['block_level']) ? '</div>' : ''); |
2758 | + } else { |
|
2759 | + $tag['content'] = $tag['disabled_content']; |
|
2636 | 2760 | } |
2637 | - else |
|
2638 | - $tag['content'] = $tag['disabled_content']; |
|
2639 | 2761 | } |
2640 | 2762 | |
2641 | 2763 | // we use this a lot |
@@ -2645,8 +2767,9 @@ discard block |
||
2645 | 2767 | if (!empty($tag['block_level']) && $tag['tag'] != 'html' && empty($inside['block_level'])) |
2646 | 2768 | { |
2647 | 2769 | $n = count($open_tags) - 1; |
2648 | - while (empty($open_tags[$n]['block_level']) && $n >= 0) |
|
2649 | - $n--; |
|
2770 | + while (empty($open_tags[$n]['block_level']) && $n >= 0) { |
|
2771 | + $n--; |
|
2772 | + } |
|
2650 | 2773 | |
2651 | 2774 | // Close all the non block level tags so this tag isn't surrounded by them. |
2652 | 2775 | for ($i = count($open_tags) - 1; $i > $n; $i--) |
@@ -2658,12 +2781,15 @@ discard block |
||
2658 | 2781 | |
2659 | 2782 | // Trim or eat trailing stuff... see comment at the end of the big loop. |
2660 | 2783 | $whitespace_regex = ''; |
2661 | - if (!empty($tag['block_level'])) |
|
2662 | - $whitespace_regex .= '( |\s)*(<br>)?'; |
|
2663 | - if (!empty($tag['trim']) && $tag['trim'] != 'inside') |
|
2664 | - $whitespace_regex .= empty($tag['require_parents']) ? '( |\s)*' : '(<br>| |\s)*'; |
|
2665 | - if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) |
|
2666 | - $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
2784 | + if (!empty($tag['block_level'])) { |
|
2785 | + $whitespace_regex .= '( |\s)*(<br>)?'; |
|
2786 | + } |
|
2787 | + if (!empty($tag['trim']) && $tag['trim'] != 'inside') { |
|
2788 | + $whitespace_regex .= empty($tag['require_parents']) ? '( |\s)*' : '(<br>| |\s)*'; |
|
2789 | + } |
|
2790 | + if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) { |
|
2791 | + $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
2792 | + } |
|
2667 | 2793 | |
2668 | 2794 | array_pop($open_tags); |
2669 | 2795 | } |
@@ -2684,16 +2810,19 @@ discard block |
||
2684 | 2810 | elseif ($tag['type'] == 'unparsed_content') |
2685 | 2811 | { |
2686 | 2812 | $pos2 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos1); |
2687 | - if ($pos2 === false) |
|
2688 | - continue; |
|
2813 | + if ($pos2 === false) { |
|
2814 | + continue; |
|
2815 | + } |
|
2689 | 2816 | |
2690 | 2817 | $data = substr($message, $pos1, $pos2 - $pos1); |
2691 | 2818 | |
2692 | - if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') |
|
2693 | - $data = substr($data, 4); |
|
2819 | + if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') { |
|
2820 | + $data = substr($data, 4); |
|
2821 | + } |
|
2694 | 2822 | |
2695 | - if (isset($tag['validate'])) |
|
2696 | - $tag['validate']($tag, $data, $disabled, $params); |
|
2823 | + if (isset($tag['validate'])) { |
|
2824 | + $tag['validate']($tag, $data, $disabled, $params); |
|
2825 | + } |
|
2697 | 2826 | |
2698 | 2827 | $code = strtr($tag['content'], array('$1' => $data)); |
2699 | 2828 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 3 + $tag_strlen); |
@@ -2708,34 +2837,40 @@ discard block |
||
2708 | 2837 | if (isset($tag['quoted'])) |
2709 | 2838 | { |
2710 | 2839 | $quoted = substr($message, $pos1, 6) == '"'; |
2711 | - if ($tag['quoted'] != 'optional' && !$quoted) |
|
2712 | - continue; |
|
2840 | + if ($tag['quoted'] != 'optional' && !$quoted) { |
|
2841 | + continue; |
|
2842 | + } |
|
2713 | 2843 | |
2714 | - if ($quoted) |
|
2715 | - $pos1 += 6; |
|
2844 | + if ($quoted) { |
|
2845 | + $pos1 += 6; |
|
2846 | + } |
|
2847 | + } else { |
|
2848 | + $quoted = false; |
|
2716 | 2849 | } |
2717 | - else |
|
2718 | - $quoted = false; |
|
2719 | 2850 | |
2720 | 2851 | $pos2 = strpos($message, $quoted == false ? ']' : '"]', $pos1); |
2721 | - if ($pos2 === false) |
|
2722 | - continue; |
|
2852 | + if ($pos2 === false) { |
|
2853 | + continue; |
|
2854 | + } |
|
2723 | 2855 | |
2724 | 2856 | $pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2); |
2725 | - if ($pos3 === false) |
|
2726 | - continue; |
|
2857 | + if ($pos3 === false) { |
|
2858 | + continue; |
|
2859 | + } |
|
2727 | 2860 | |
2728 | 2861 | $data = array( |
2729 | 2862 | substr($message, $pos2 + ($quoted == false ? 1 : 7), $pos3 - ($pos2 + ($quoted == false ? 1 : 7))), |
2730 | 2863 | substr($message, $pos1, $pos2 - $pos1) |
2731 | 2864 | ); |
2732 | 2865 | |
2733 | - if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') |
|
2734 | - $data[0] = substr($data[0], 4); |
|
2866 | + if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') { |
|
2867 | + $data[0] = substr($data[0], 4); |
|
2868 | + } |
|
2735 | 2869 | |
2736 | 2870 | // Validation for my parking, please! |
2737 | - if (isset($tag['validate'])) |
|
2738 | - $tag['validate']($tag, $data, $disabled, $params); |
|
2871 | + if (isset($tag['validate'])) { |
|
2872 | + $tag['validate']($tag, $data, $disabled, $params); |
|
2873 | + } |
|
2739 | 2874 | |
2740 | 2875 | $code = strtr($tag['content'], array('$1' => $data[0], '$2' => $data[1])); |
2741 | 2876 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen); |
@@ -2752,23 +2887,27 @@ discard block |
||
2752 | 2887 | elseif ($tag['type'] == 'unparsed_commas_content') |
2753 | 2888 | { |
2754 | 2889 | $pos2 = strpos($message, ']', $pos1); |
2755 | - if ($pos2 === false) |
|
2756 | - continue; |
|
2890 | + if ($pos2 === false) { |
|
2891 | + continue; |
|
2892 | + } |
|
2757 | 2893 | |
2758 | 2894 | $pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2); |
2759 | - if ($pos3 === false) |
|
2760 | - continue; |
|
2895 | + if ($pos3 === false) { |
|
2896 | + continue; |
|
2897 | + } |
|
2761 | 2898 | |
2762 | 2899 | // We want $1 to be the content, and the rest to be csv. |
2763 | 2900 | $data = explode(',', ',' . substr($message, $pos1, $pos2 - $pos1)); |
2764 | 2901 | $data[0] = substr($message, $pos2 + 1, $pos3 - $pos2 - 1); |
2765 | 2902 | |
2766 | - if (isset($tag['validate'])) |
|
2767 | - $tag['validate']($tag, $data, $disabled, $params); |
|
2903 | + if (isset($tag['validate'])) { |
|
2904 | + $tag['validate']($tag, $data, $disabled, $params); |
|
2905 | + } |
|
2768 | 2906 | |
2769 | 2907 | $code = $tag['content']; |
2770 | - foreach ($data as $k => $d) |
|
2771 | - $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
2908 | + foreach ($data as $k => $d) { |
|
2909 | + $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
2910 | + } |
|
2772 | 2911 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen); |
2773 | 2912 | $pos += strlen($code) - 1 + 2; |
2774 | 2913 | } |
@@ -2776,24 +2915,28 @@ discard block |
||
2776 | 2915 | elseif ($tag['type'] == 'unparsed_commas') |
2777 | 2916 | { |
2778 | 2917 | $pos2 = strpos($message, ']', $pos1); |
2779 | - if ($pos2 === false) |
|
2780 | - continue; |
|
2918 | + if ($pos2 === false) { |
|
2919 | + continue; |
|
2920 | + } |
|
2781 | 2921 | |
2782 | 2922 | $data = explode(',', substr($message, $pos1, $pos2 - $pos1)); |
2783 | 2923 | |
2784 | - if (isset($tag['validate'])) |
|
2785 | - $tag['validate']($tag, $data, $disabled, $params); |
|
2924 | + if (isset($tag['validate'])) { |
|
2925 | + $tag['validate']($tag, $data, $disabled, $params); |
|
2926 | + } |
|
2786 | 2927 | |
2787 | 2928 | // Fix after, for disabled code mainly. |
2788 | - foreach ($data as $k => $d) |
|
2789 | - $tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d))); |
|
2929 | + foreach ($data as $k => $d) { |
|
2930 | + $tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d))); |
|
2931 | + } |
|
2790 | 2932 | |
2791 | 2933 | $open_tags[] = $tag; |
2792 | 2934 | |
2793 | 2935 | // Replace them out, $1, $2, $3, $4, etc. |
2794 | 2936 | $code = $tag['before']; |
2795 | - foreach ($data as $k => $d) |
|
2796 | - $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
2937 | + foreach ($data as $k => $d) { |
|
2938 | + $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
2939 | + } |
|
2797 | 2940 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 1); |
2798 | 2941 | $pos += strlen($code) - 1 + 2; |
2799 | 2942 | } |
@@ -2804,28 +2947,33 @@ discard block |
||
2804 | 2947 | if (isset($tag['quoted'])) |
2805 | 2948 | { |
2806 | 2949 | $quoted = substr($message, $pos1, 6) == '"'; |
2807 | - if ($tag['quoted'] != 'optional' && !$quoted) |
|
2808 | - continue; |
|
2950 | + if ($tag['quoted'] != 'optional' && !$quoted) { |
|
2951 | + continue; |
|
2952 | + } |
|
2809 | 2953 | |
2810 | - if ($quoted) |
|
2811 | - $pos1 += 6; |
|
2954 | + if ($quoted) { |
|
2955 | + $pos1 += 6; |
|
2956 | + } |
|
2957 | + } else { |
|
2958 | + $quoted = false; |
|
2812 | 2959 | } |
2813 | - else |
|
2814 | - $quoted = false; |
|
2815 | 2960 | |
2816 | 2961 | $pos2 = strpos($message, $quoted == false ? ']' : '"]', $pos1); |
2817 | - if ($pos2 === false) |
|
2818 | - continue; |
|
2962 | + if ($pos2 === false) { |
|
2963 | + continue; |
|
2964 | + } |
|
2819 | 2965 | |
2820 | 2966 | $data = substr($message, $pos1, $pos2 - $pos1); |
2821 | 2967 | |
2822 | 2968 | // Validation for my parking, please! |
2823 | - if (isset($tag['validate'])) |
|
2824 | - $tag['validate']($tag, $data, $disabled, $params); |
|
2969 | + if (isset($tag['validate'])) { |
|
2970 | + $tag['validate']($tag, $data, $disabled, $params); |
|
2971 | + } |
|
2825 | 2972 | |
2826 | 2973 | // For parsed content, we must recurse to avoid security problems. |
2827 | - if ($tag['type'] != 'unparsed_equals') |
|
2828 | - $data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array()); |
|
2974 | + if ($tag['type'] != 'unparsed_equals') { |
|
2975 | + $data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array()); |
|
2976 | + } |
|
2829 | 2977 | |
2830 | 2978 | $tag['after'] = strtr($tag['after'], array('$1' => $data)); |
2831 | 2979 | |
@@ -2837,34 +2985,40 @@ discard block |
||
2837 | 2985 | } |
2838 | 2986 | |
2839 | 2987 | // If this is block level, eat any breaks after it. |
2840 | - if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') |
|
2841 | - $message = substr($message, 0, $pos + 1) . substr($message, $pos + 5); |
|
2988 | + if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') { |
|
2989 | + $message = substr($message, 0, $pos + 1) . substr($message, $pos + 5); |
|
2990 | + } |
|
2842 | 2991 | |
2843 | 2992 | // Are we trimming outside this tag? |
2844 | - if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>| |\s)*~', substr($message, $pos + 1), $matches) != 0) |
|
2845 | - $message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0])); |
|
2993 | + if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>| |\s)*~', substr($message, $pos + 1), $matches) != 0) { |
|
2994 | + $message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0])); |
|
2995 | + } |
|
2846 | 2996 | } |
2847 | 2997 | |
2848 | 2998 | // Close any remaining tags. |
2849 | - while ($tag = array_pop($open_tags)) |
|
2850 | - $message .= "\n" . $tag['after'] . "\n"; |
|
2999 | + while ($tag = array_pop($open_tags)) { |
|
3000 | + $message .= "\n" . $tag['after'] . "\n"; |
|
3001 | + } |
|
2851 | 3002 | |
2852 | 3003 | // Parse the smileys within the parts where it can be done safely. |
2853 | 3004 | if ($smileys === true) |
2854 | 3005 | { |
2855 | 3006 | $message_parts = explode("\n", $message); |
2856 | - for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) |
|
2857 | - parsesmileys($message_parts[$i]); |
|
3007 | + for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) { |
|
3008 | + parsesmileys($message_parts[$i]); |
|
3009 | + } |
|
2858 | 3010 | |
2859 | 3011 | $message = implode('', $message_parts); |
2860 | 3012 | } |
2861 | 3013 | |
2862 | 3014 | // No smileys, just get rid of the markers. |
2863 | - else |
|
2864 | - $message = strtr($message, array("\n" => '')); |
|
3015 | + else { |
|
3016 | + $message = strtr($message, array("\n" => '')); |
|
3017 | + } |
|
2865 | 3018 | |
2866 | - if ($message !== '' && $message[0] === ' ') |
|
2867 | - $message = ' ' . substr($message, 1); |
|
3019 | + if ($message !== '' && $message[0] === ' ') { |
|
3020 | + $message = ' ' . substr($message, 1); |
|
3021 | + } |
|
2868 | 3022 | |
2869 | 3023 | // Cleanup whitespace. |
2870 | 3024 | $message = strtr($message, array(' ' => ' ', "\r" => '', "\n" => '<br>', '<br> ' => '<br> ', ' ' => "\n")); |
@@ -2873,15 +3027,16 @@ discard block |
||
2873 | 3027 | call_integration_hook('integrate_post_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags)); |
2874 | 3028 | |
2875 | 3029 | // Cache the output if it took some time... |
2876 | - if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) |
|
2877 | - cache_put_data($cache_key, $message, 240); |
|
3030 | + if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) { |
|
3031 | + cache_put_data($cache_key, $message, 240); |
|
3032 | + } |
|
2878 | 3033 | |
2879 | 3034 | // If this was a force parse revert if needed. |
2880 | 3035 | if (!empty($parse_tags)) |
2881 | 3036 | { |
2882 | - if (empty($temp_bbc)) |
|
2883 | - $bbc_codes = array(); |
|
2884 | - else |
|
3037 | + if (empty($temp_bbc)) { |
|
3038 | + $bbc_codes = array(); |
|
3039 | + } else |
|
2885 | 3040 | { |
2886 | 3041 | $bbc_codes = $temp_bbc; |
2887 | 3042 | unset($temp_bbc); |
@@ -2908,8 +3063,9 @@ discard block |
||
2908 | 3063 | static $smileyPregSearch = null, $smileyPregReplacements = array(); |
2909 | 3064 | |
2910 | 3065 | // No smiley set at all?! |
2911 | - if ($user_info['smiley_set'] == 'none' || trim($message) == '') |
|
2912 | - return; |
|
3066 | + if ($user_info['smiley_set'] == 'none' || trim($message) == '') { |
|
3067 | + return; |
|
3068 | + } |
|
2913 | 3069 | |
2914 | 3070 | // Maybe a mod wants to implement an alternative method (e.g. emojis instead of images) |
2915 | 3071 | call_integration_hook('integrate_smileys', array(&$smileyPregSearch, &$smileyPregReplacements)); |
@@ -2923,8 +3079,7 @@ discard block |
||
2923 | 3079 | $smileysfrom = array('>:D', ':D', '::)', '>:(', ':))', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', 'O:-)'); |
2924 | 3080 | $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'); |
2925 | 3081 | $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'], '', '', '', ''); |
2926 | - } |
|
2927 | - else |
|
3082 | + } else |
|
2928 | 3083 | { |
2929 | 3084 | // Load the smileys in reverse order by length so they don't get parsed wrong. |
2930 | 3085 | if (($temp = cache_get_data('parsing_smileys', 480)) == null) |
@@ -2948,9 +3103,9 @@ discard block |
||
2948 | 3103 | $smcFunc['db_free_result']($result); |
2949 | 3104 | |
2950 | 3105 | cache_put_data('parsing_smileys', array($smileysfrom, $smileysto, $smileysdescs), 480); |
3106 | + } else { |
|
3107 | + list ($smileysfrom, $smileysto, $smileysdescs) = $temp; |
|
2951 | 3108 | } |
2952 | - else |
|
2953 | - list ($smileysfrom, $smileysto, $smileysdescs) = $temp; |
|
2954 | 3109 | } |
2955 | 3110 | |
2956 | 3111 | // The non-breaking-space is a complex thing... |
@@ -2972,16 +3127,18 @@ discard block |
||
2972 | 3127 | $alt_images = glob($smileys_dir . $fname . '.{' . (implode(',', $exts)) . '}', GLOB_BRACE); |
2973 | 3128 | if (!empty($alt_images)) |
2974 | 3129 | { |
2975 | - foreach ($exts as $ext) |
|
2976 | - if (in_array($smileys_dir . $fname . '.' . $ext, $alt_images)) |
|
3130 | + foreach ($exts as $ext) { |
|
3131 | + if (in_array($smileys_dir . $fname . '.' . $ext, $alt_images)) |
|
2977 | 3132 | { |
2978 | 3133 | $smileysto[$i] = $fname . '.' . $ext; |
3134 | + } |
|
2979 | 3135 | break; |
2980 | 3136 | } |
2981 | 3137 | } |
2982 | 3138 | // If we have no image, just leave the text version in place |
2983 | - else |
|
2984 | - continue; |
|
3139 | + else { |
|
3140 | + continue; |
|
3141 | + } |
|
2985 | 3142 | } |
2986 | 3143 | |
2987 | 3144 | $specialChars = $smcFunc['htmlspecialchars']($smileysfrom[$i], ENT_QUOTES); |
@@ -3057,12 +3214,14 @@ discard block |
||
3057 | 3214 | global $boardurl, $image_proxy_enabled, $image_proxy_secret; |
3058 | 3215 | |
3059 | 3216 | // Only use the proxy if enabled and necessary |
3060 | - if (empty($image_proxy_enabled) || parse_url($url, PHP_URL_SCHEME) === 'https') |
|
3061 | - return $url; |
|
3217 | + if (empty($image_proxy_enabled) || parse_url($url, PHP_URL_SCHEME) === 'https') { |
|
3218 | + return $url; |
|
3219 | + } |
|
3062 | 3220 | |
3063 | 3221 | // We don't need to proxy our own resources |
3064 | - if (strpos(strtr($url, array('http://' => 'https://')), strtr($boardurl, array('http://' => 'https://'))) === 0) |
|
3065 | - return strtr($url, array('http://' => 'https://')); |
|
3222 | + if (strpos(strtr($url, array('http://' => 'https://')), strtr($boardurl, array('http://' => 'https://'))) === 0) { |
|
3223 | + return strtr($url, array('http://' => 'https://')); |
|
3224 | + } |
|
3066 | 3225 | |
3067 | 3226 | // By default, use SMF's own image proxy script |
3068 | 3227 | $proxied_url = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($url) . '&hash=' . md5($url . $image_proxy_secret); |
@@ -3087,35 +3246,41 @@ discard block |
||
3087 | 3246 | global $scripturl, $context, $modSettings, $db_show_debug, $db_cache; |
3088 | 3247 | |
3089 | 3248 | // In case we have mail to send, better do that - as obExit doesn't always quite make it... |
3090 | - if (!empty($context['flush_mail'])) |
|
3091 | - // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
3249 | + if (!empty($context['flush_mail'])) { |
|
3250 | + // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
3092 | 3251 | AddMailQueue(true); |
3252 | + } |
|
3093 | 3253 | |
3094 | 3254 | $add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && substr($setLocation, 0, 6) != 'about:'; |
3095 | 3255 | |
3096 | - if ($add) |
|
3097 | - $setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : ''); |
|
3256 | + if ($add) { |
|
3257 | + $setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : ''); |
|
3258 | + } |
|
3098 | 3259 | |
3099 | 3260 | // Put the session ID in. |
3100 | - if (defined('SID') && SID != '') |
|
3101 | - $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation); |
|
3261 | + if (defined('SID') && SID != '') { |
|
3262 | + $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation); |
|
3263 | + } |
|
3102 | 3264 | // Keep that debug in their for template debugging! |
3103 | - elseif (isset($_GET['debug'])) |
|
3104 | - $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation); |
|
3265 | + elseif (isset($_GET['debug'])) { |
|
3266 | + $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation); |
|
3267 | + } |
|
3105 | 3268 | |
3106 | 3269 | 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']))) |
3107 | 3270 | { |
3108 | - if (defined('SID') && SID != '') |
|
3109 | - $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#]+?)(#[^"]*?)?$~', |
|
3271 | + if (defined('SID') && SID != '') { |
|
3272 | + $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#]+?)(#[^"]*?)?$~', |
|
3110 | 3273 | function ($m) use ($scripturl) |
3111 | 3274 | { |
3112 | 3275 | return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : ""); |
3276 | + } |
|
3113 | 3277 | }, $setLocation); |
3114 | - else |
|
3115 | - $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~', |
|
3278 | + else { |
|
3279 | + $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~', |
|
3116 | 3280 | function ($m) use ($scripturl) |
3117 | 3281 | { |
3118 | 3282 | return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : ""); |
3283 | + } |
|
3119 | 3284 | }, $setLocation); |
3120 | 3285 | } |
3121 | 3286 | |
@@ -3126,8 +3291,9 @@ discard block |
||
3126 | 3291 | header('location: ' . str_replace(' ', '%20', $setLocation), true, $permanent ? 301 : 302); |
3127 | 3292 | |
3128 | 3293 | // Debugging. |
3129 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
3130 | - $_SESSION['debug_redirect'] = $db_cache; |
|
3294 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
3295 | + $_SESSION['debug_redirect'] = $db_cache; |
|
3296 | + } |
|
3131 | 3297 | |
3132 | 3298 | obExit(false); |
3133 | 3299 | } |
@@ -3146,51 +3312,60 @@ discard block |
||
3146 | 3312 | |
3147 | 3313 | // Attempt to prevent a recursive loop. |
3148 | 3314 | ++$level; |
3149 | - if ($level > 1 && !$from_fatal_error && !$has_fatal_error) |
|
3150 | - exit; |
|
3151 | - if ($from_fatal_error) |
|
3152 | - $has_fatal_error = true; |
|
3315 | + if ($level > 1 && !$from_fatal_error && !$has_fatal_error) { |
|
3316 | + exit; |
|
3317 | + } |
|
3318 | + if ($from_fatal_error) { |
|
3319 | + $has_fatal_error = true; |
|
3320 | + } |
|
3153 | 3321 | |
3154 | 3322 | // Clear out the stat cache. |
3155 | 3323 | trackStats(); |
3156 | 3324 | |
3157 | 3325 | // If we have mail to send, send it. |
3158 | - if (!empty($context['flush_mail'])) |
|
3159 | - // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
3326 | + if (!empty($context['flush_mail'])) { |
|
3327 | + // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
3160 | 3328 | AddMailQueue(true); |
3329 | + } |
|
3161 | 3330 | |
3162 | 3331 | $do_header = $header === null ? !$header_done : $header; |
3163 | - if ($do_footer === null) |
|
3164 | - $do_footer = $do_header; |
|
3332 | + if ($do_footer === null) { |
|
3333 | + $do_footer = $do_header; |
|
3334 | + } |
|
3165 | 3335 | |
3166 | 3336 | // Has the template/header been done yet? |
3167 | 3337 | if ($do_header) |
3168 | 3338 | { |
3169 | 3339 | // Was the page title set last minute? Also update the HTML safe one. |
3170 | - if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) |
|
3171 | - $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); |
|
3340 | + if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) { |
|
3341 | + $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); |
|
3342 | + } |
|
3172 | 3343 | |
3173 | 3344 | // Start up the session URL fixer. |
3174 | 3345 | ob_start('ob_sessrewrite'); |
3175 | 3346 | |
3176 | - if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) |
|
3177 | - $buffers = explode(',', $settings['output_buffers']); |
|
3178 | - elseif (!empty($settings['output_buffers'])) |
|
3179 | - $buffers = $settings['output_buffers']; |
|
3180 | - else |
|
3181 | - $buffers = array(); |
|
3347 | + if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) { |
|
3348 | + $buffers = explode(',', $settings['output_buffers']); |
|
3349 | + } elseif (!empty($settings['output_buffers'])) { |
|
3350 | + $buffers = $settings['output_buffers']; |
|
3351 | + } else { |
|
3352 | + $buffers = array(); |
|
3353 | + } |
|
3182 | 3354 | |
3183 | - if (isset($modSettings['integrate_buffer'])) |
|
3184 | - $buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers); |
|
3355 | + if (isset($modSettings['integrate_buffer'])) { |
|
3356 | + $buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers); |
|
3357 | + } |
|
3185 | 3358 | |
3186 | - if (!empty($buffers)) |
|
3187 | - foreach ($buffers as $function) |
|
3359 | + if (!empty($buffers)) { |
|
3360 | + foreach ($buffers as $function) |
|
3188 | 3361 | { |
3189 | 3362 | $call = call_helper($function, true); |
3363 | + } |
|
3190 | 3364 | |
3191 | 3365 | // Is it valid? |
3192 | - if (!empty($call)) |
|
3193 | - ob_start($call); |
|
3366 | + if (!empty($call)) { |
|
3367 | + ob_start($call); |
|
3368 | + } |
|
3194 | 3369 | } |
3195 | 3370 | |
3196 | 3371 | // Display the screen in the logical order. |
@@ -3202,8 +3377,9 @@ discard block |
||
3202 | 3377 | loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main'); |
3203 | 3378 | |
3204 | 3379 | // Anything special to put out? |
3205 | - if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) |
|
3206 | - echo $context['insert_after_template']; |
|
3380 | + if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) { |
|
3381 | + echo $context['insert_after_template']; |
|
3382 | + } |
|
3207 | 3383 | |
3208 | 3384 | // Just so we don't get caught in an endless loop of errors from the footer... |
3209 | 3385 | if (!$footer_done) |
@@ -3212,14 +3388,16 @@ discard block |
||
3212 | 3388 | template_footer(); |
3213 | 3389 | |
3214 | 3390 | // (since this is just debugging... it's okay that it's after </html>.) |
3215 | - if (!isset($_REQUEST['xml'])) |
|
3216 | - displayDebug(); |
|
3391 | + if (!isset($_REQUEST['xml'])) { |
|
3392 | + displayDebug(); |
|
3393 | + } |
|
3217 | 3394 | } |
3218 | 3395 | } |
3219 | 3396 | |
3220 | 3397 | // Remember this URL in case someone doesn't like sending HTTP_REFERER. |
3221 | - if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) |
|
3222 | - $_SESSION['old_url'] = $_SERVER['REQUEST_URL']; |
|
3398 | + if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) { |
|
3399 | + $_SESSION['old_url'] = $_SERVER['REQUEST_URL']; |
|
3400 | + } |
|
3223 | 3401 | |
3224 | 3402 | // For session check verification.... don't switch browsers... |
3225 | 3403 | $_SESSION['USER_AGENT'] = empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT']; |
@@ -3228,9 +3406,10 @@ discard block |
||
3228 | 3406 | call_integration_hook('integrate_exit', array($do_footer)); |
3229 | 3407 | |
3230 | 3408 | // Don't exit if we're coming from index.php; that will pass through normally. |
3231 | - if (!$from_index) |
|
3232 | - exit; |
|
3233 | -} |
|
3409 | + if (!$from_index) { |
|
3410 | + exit; |
|
3411 | + } |
|
3412 | + } |
|
3234 | 3413 | |
3235 | 3414 | /** |
3236 | 3415 | * Get the size of a specified image with better error handling. |
@@ -3249,8 +3428,9 @@ discard block |
||
3249 | 3428 | $url = str_replace(' ', '%20', $url); |
3250 | 3429 | |
3251 | 3430 | // Can we pull this from the cache... please please? |
3252 | - if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) |
|
3253 | - return $temp; |
|
3431 | + if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) { |
|
3432 | + return $temp; |
|
3433 | + } |
|
3254 | 3434 | $t = microtime(); |
3255 | 3435 | |
3256 | 3436 | // Get the host to pester... |
@@ -3260,12 +3440,10 @@ discard block |
||
3260 | 3440 | if ($url == '' || $url == 'http://' || $url == 'https://') |
3261 | 3441 | { |
3262 | 3442 | return false; |
3263 | - } |
|
3264 | - elseif (!isset($match[1])) |
|
3443 | + } elseif (!isset($match[1])) |
|
3265 | 3444 | { |
3266 | 3445 | $size = @getimagesize($url); |
3267 | - } |
|
3268 | - else |
|
3446 | + } else |
|
3269 | 3447 | { |
3270 | 3448 | // Try to connect to the server... give it half a second. |
3271 | 3449 | $temp = 0; |
@@ -3302,12 +3480,14 @@ discard block |
||
3302 | 3480 | } |
3303 | 3481 | |
3304 | 3482 | // If we didn't get it, we failed. |
3305 | - if (!isset($size)) |
|
3306 | - $size = false; |
|
3483 | + if (!isset($size)) { |
|
3484 | + $size = false; |
|
3485 | + } |
|
3307 | 3486 | |
3308 | 3487 | // If this took a long time, we may never have to do it again, but then again we might... |
3309 | - if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) |
|
3310 | - cache_put_data('url_image_size-' . md5($url), $size, 240); |
|
3488 | + if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) { |
|
3489 | + cache_put_data('url_image_size-' . md5($url), $size, 240); |
|
3490 | + } |
|
3311 | 3491 | |
3312 | 3492 | // Didn't work. |
3313 | 3493 | return $size; |
@@ -3325,8 +3505,9 @@ discard block |
||
3325 | 3505 | |
3326 | 3506 | // Under SSI this function can be called more then once. That can cause some problems. |
3327 | 3507 | // So only run the function once unless we are forced to run it again. |
3328 | - if ($loaded && !$forceload) |
|
3329 | - return; |
|
3508 | + if ($loaded && !$forceload) { |
|
3509 | + return; |
|
3510 | + } |
|
3330 | 3511 | |
3331 | 3512 | $loaded = true; |
3332 | 3513 | |
@@ -3338,14 +3519,16 @@ discard block |
||
3338 | 3519 | $context['news_lines'] = array_filter(explode("\n", str_replace("\r", '', trim(addslashes($modSettings['news']))))); |
3339 | 3520 | for ($i = 0, $n = count($context['news_lines']); $i < $n; $i++) |
3340 | 3521 | { |
3341 | - if (trim($context['news_lines'][$i]) == '') |
|
3342 | - continue; |
|
3522 | + if (trim($context['news_lines'][$i]) == '') { |
|
3523 | + continue; |
|
3524 | + } |
|
3343 | 3525 | |
3344 | 3526 | // Clean it up for presentation ;). |
3345 | 3527 | $context['news_lines'][$i] = parse_bbc(stripslashes(trim($context['news_lines'][$i])), true, 'news' . $i); |
3346 | 3528 | } |
3347 | - if (!empty($context['news_lines'])) |
|
3348 | - $context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)]; |
|
3529 | + if (!empty($context['news_lines'])) { |
|
3530 | + $context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)]; |
|
3531 | + } |
|
3349 | 3532 | |
3350 | 3533 | if (!$user_info['is_guest']) |
3351 | 3534 | { |
@@ -3354,40 +3537,48 @@ discard block |
||
3354 | 3537 | $context['user']['alerts'] = &$user_info['alerts']; |
3355 | 3538 | |
3356 | 3539 | // Personal message popup... |
3357 | - if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) |
|
3358 | - $context['user']['popup_messages'] = true; |
|
3359 | - else |
|
3360 | - $context['user']['popup_messages'] = false; |
|
3540 | + if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) { |
|
3541 | + $context['user']['popup_messages'] = true; |
|
3542 | + } else { |
|
3543 | + $context['user']['popup_messages'] = false; |
|
3544 | + } |
|
3361 | 3545 | $_SESSION['unread_messages'] = $user_info['unread_messages']; |
3362 | 3546 | |
3363 | - if (allowedTo('moderate_forum')) |
|
3364 | - $context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0; |
|
3547 | + if (allowedTo('moderate_forum')) { |
|
3548 | + $context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0; |
|
3549 | + } |
|
3365 | 3550 | |
3366 | 3551 | $context['user']['avatar'] = array(); |
3367 | 3552 | |
3368 | 3553 | // Check for gravatar first since we might be forcing them... |
3369 | 3554 | if (($modSettings['gravatarEnabled'] && substr($user_info['avatar']['url'], 0, 11) == 'gravatar://') || !empty($modSettings['gravatarOverride'])) |
3370 | 3555 | { |
3371 | - if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) |
|
3372 | - $context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11)); |
|
3373 | - else |
|
3374 | - $context['user']['avatar']['href'] = get_gravatar_url($user_info['email']); |
|
3556 | + if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) { |
|
3557 | + $context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11)); |
|
3558 | + } else { |
|
3559 | + $context['user']['avatar']['href'] = get_gravatar_url($user_info['email']); |
|
3560 | + } |
|
3375 | 3561 | } |
3376 | 3562 | // Uploaded? |
3377 | - elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) |
|
3378 | - $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'; |
|
3563 | + elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) { |
|
3564 | + $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'; |
|
3565 | + } |
|
3379 | 3566 | // Full 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']; |
|
3567 | + elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) { |
|
3568 | + $context['user']['avatar']['href'] = $user_info['avatar']['url']; |
|
3569 | + } |
|
3382 | 3570 | // Otherwise we assume it's server stored. |
3383 | - elseif ($user_info['avatar']['url'] != '') |
|
3384 | - $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']); |
|
3571 | + elseif ($user_info['avatar']['url'] != '') { |
|
3572 | + $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']); |
|
3573 | + } |
|
3385 | 3574 | // No avatar at all? Fine, we have a big fat default avatar ;) |
3386 | - else |
|
3387 | - $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png'; |
|
3575 | + else { |
|
3576 | + $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png'; |
|
3577 | + } |
|
3388 | 3578 | |
3389 | - if (!empty($context['user']['avatar'])) |
|
3390 | - $context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">'; |
|
3579 | + if (!empty($context['user']['avatar'])) { |
|
3580 | + $context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">'; |
|
3581 | + } |
|
3391 | 3582 | |
3392 | 3583 | // Figure out how long they've been logged in. |
3393 | 3584 | $context['user']['total_time_logged_in'] = array( |
@@ -3395,8 +3586,7 @@ discard block |
||
3395 | 3586 | 'hours' => floor(($user_info['total_time_logged_in'] % 86400) / 3600), |
3396 | 3587 | 'minutes' => floor(($user_info['total_time_logged_in'] % 3600) / 60) |
3397 | 3588 | ); |
3398 | - } |
|
3399 | - else |
|
3589 | + } else |
|
3400 | 3590 | { |
3401 | 3591 | $context['user']['messages'] = 0; |
3402 | 3592 | $context['user']['unread_messages'] = 0; |
@@ -3404,12 +3594,14 @@ discard block |
||
3404 | 3594 | $context['user']['total_time_logged_in'] = array('days' => 0, 'hours' => 0, 'minutes' => 0); |
3405 | 3595 | $context['user']['popup_messages'] = false; |
3406 | 3596 | |
3407 | - if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) |
|
3408 | - $txt['welcome_guest'] .= $txt['welcome_guest_activate']; |
|
3597 | + if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) { |
|
3598 | + $txt['welcome_guest'] .= $txt['welcome_guest_activate']; |
|
3599 | + } |
|
3409 | 3600 | |
3410 | 3601 | // If we've upgraded recently, go easy on the passwords. |
3411 | - if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) |
|
3412 | - $context['disable_login_hashing'] = true; |
|
3602 | + if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) { |
|
3603 | + $context['disable_login_hashing'] = true; |
|
3604 | + } |
|
3413 | 3605 | } |
3414 | 3606 | |
3415 | 3607 | // Setup the main menu items. |
@@ -3422,8 +3614,8 @@ discard block |
||
3422 | 3614 | $context['show_pm_popup'] = $context['user']['popup_messages'] && !empty($options['popup_messages']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'pm'); |
3423 | 3615 | |
3424 | 3616 | // 2.1+: Add the PM popup here instead. Theme authors can still override it simply by editing/removing the 'fPmPopup' in the array. |
3425 | - if ($context['show_pm_popup']) |
|
3426 | - addInlineJavaScript(' |
|
3617 | + if ($context['show_pm_popup']) { |
|
3618 | + addInlineJavaScript(' |
|
3427 | 3619 | jQuery(document).ready(function($) { |
3428 | 3620 | new smc_Popup({ |
3429 | 3621 | heading: ' . JavaScriptEscape($txt['show_personal_messages_heading']) . ', |
@@ -3431,24 +3623,28 @@ discard block |
||
3431 | 3623 | icon_class: \'generic_icons mail_new\' |
3432 | 3624 | }); |
3433 | 3625 | });'); |
3626 | + } |
|
3434 | 3627 | |
3435 | 3628 | // Add a generic "Are you sure?" confirmation message. |
3436 | 3629 | addInlineJavaScript(' |
3437 | 3630 | var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';'); |
3438 | 3631 | |
3439 | 3632 | // Now add the capping code for avatars. |
3440 | - 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') |
|
3441 | - addInlineCss(' |
|
3633 | + 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') { |
|
3634 | + addInlineCss(' |
|
3442 | 3635 | img.avatar { max-width: ' . $modSettings['avatar_max_width_external'] . 'px; max-height: ' . $modSettings['avatar_max_height_external'] . 'px; }'); |
3636 | + } |
|
3443 | 3637 | |
3444 | 3638 | // Add max image limits |
3445 | - if (!empty($modSettings['max_image_width'])) |
|
3446 | - addInlineCss(' |
|
3639 | + if (!empty($modSettings['max_image_width'])) { |
|
3640 | + addInlineCss(' |
|
3447 | 3641 | .postarea .bbc_img { max-width: ' . $modSettings['max_image_width'] . 'px; }'); |
3642 | + } |
|
3448 | 3643 | |
3449 | - if (!empty($modSettings['max_image_height'])) |
|
3450 | - addInlineCss(' |
|
3644 | + if (!empty($modSettings['max_image_height'])) { |
|
3645 | + addInlineCss(' |
|
3451 | 3646 | .postarea .bbc_img { max-height: ' . $modSettings['max_image_height'] . 'px; }'); |
3647 | + } |
|
3452 | 3648 | |
3453 | 3649 | // This looks weird, but it's because BoardIndex.php references the variable. |
3454 | 3650 | $context['common_stats']['latest_member'] = array( |
@@ -3465,11 +3661,13 @@ discard block |
||
3465 | 3661 | ); |
3466 | 3662 | $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']); |
3467 | 3663 | |
3468 | - if (empty($settings['theme_version'])) |
|
3469 | - addJavaScriptVar('smf_scripturl', $scripturl); |
|
3664 | + if (empty($settings['theme_version'])) { |
|
3665 | + addJavaScriptVar('smf_scripturl', $scripturl); |
|
3666 | + } |
|
3470 | 3667 | |
3471 | - if (!isset($context['page_title'])) |
|
3472 | - $context['page_title'] = ''; |
|
3668 | + if (!isset($context['page_title'])) { |
|
3669 | + $context['page_title'] = ''; |
|
3670 | + } |
|
3473 | 3671 | |
3474 | 3672 | // Set some specific vars. |
3475 | 3673 | $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); |
@@ -3479,21 +3677,23 @@ discard block |
||
3479 | 3677 | $context['meta_tags'][] = array('property' => 'og:site_name', 'content' => $context['forum_name']); |
3480 | 3678 | $context['meta_tags'][] = array('property' => 'og:title', 'content' => $context['page_title_html_safe']); |
3481 | 3679 | |
3482 | - if (!empty($context['meta_keywords'])) |
|
3483 | - $context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']); |
|
3680 | + if (!empty($context['meta_keywords'])) { |
|
3681 | + $context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']); |
|
3682 | + } |
|
3484 | 3683 | |
3485 | - if (!empty($context['canonical_url'])) |
|
3486 | - $context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']); |
|
3684 | + if (!empty($context['canonical_url'])) { |
|
3685 | + $context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']); |
|
3686 | + } |
|
3487 | 3687 | |
3488 | - if (!empty($settings['og_image'])) |
|
3489 | - $context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']); |
|
3688 | + if (!empty($settings['og_image'])) { |
|
3689 | + $context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']); |
|
3690 | + } |
|
3490 | 3691 | |
3491 | 3692 | if (!empty($context['meta_description'])) |
3492 | 3693 | { |
3493 | 3694 | $context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['meta_description']); |
3494 | 3695 | $context['meta_tags'][] = array('name' => 'description', 'content' => $context['meta_description']); |
3495 | - } |
|
3496 | - else |
|
3696 | + } else |
|
3497 | 3697 | { |
3498 | 3698 | $context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['page_title_html_safe']); |
3499 | 3699 | $context['meta_tags'][] = array('name' => 'description', 'content' => $context['page_title_html_safe']); |
@@ -3518,8 +3718,9 @@ discard block |
||
3518 | 3718 | $memory_needed = memoryReturnBytes($needed); |
3519 | 3719 | |
3520 | 3720 | // should we account for how much is currently being used? |
3521 | - if ($in_use) |
|
3522 | - $memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576); |
|
3721 | + if ($in_use) { |
|
3722 | + $memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576); |
|
3723 | + } |
|
3523 | 3724 | |
3524 | 3725 | // if more is needed, request it |
3525 | 3726 | if ($memory_current < $memory_needed) |
@@ -3542,8 +3743,9 @@ discard block |
||
3542 | 3743 | */ |
3543 | 3744 | function memoryReturnBytes($val) |
3544 | 3745 | { |
3545 | - if (is_integer($val)) |
|
3546 | - return $val; |
|
3746 | + if (is_integer($val)) { |
|
3747 | + return $val; |
|
3748 | + } |
|
3547 | 3749 | |
3548 | 3750 | // Separate the number from the designator |
3549 | 3751 | $val = trim($val); |
@@ -3579,10 +3781,11 @@ discard block |
||
3579 | 3781 | header('last-modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); |
3580 | 3782 | |
3581 | 3783 | // Are we debugging the template/html content? |
3582 | - if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) |
|
3583 | - header('content-type: application/xhtml+xml'); |
|
3584 | - elseif (!isset($_REQUEST['xml'])) |
|
3585 | - header('content-type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
3784 | + if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) { |
|
3785 | + header('content-type: application/xhtml+xml'); |
|
3786 | + } elseif (!isset($_REQUEST['xml'])) { |
|
3787 | + header('content-type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
3788 | + } |
|
3586 | 3789 | } |
3587 | 3790 | |
3588 | 3791 | header('content-type: text/' . (isset($_REQUEST['xml']) ? 'xml' : 'html') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
@@ -3591,8 +3794,9 @@ discard block |
||
3591 | 3794 | if ($context['in_maintenance'] && $context['user']['is_admin']) |
3592 | 3795 | { |
3593 | 3796 | $position = array_search('body', $context['template_layers']); |
3594 | - if ($position === false) |
|
3595 | - $position = array_search('main', $context['template_layers']); |
|
3797 | + if ($position === false) { |
|
3798 | + $position = array_search('main', $context['template_layers']); |
|
3799 | + } |
|
3596 | 3800 | |
3597 | 3801 | if ($position !== false) |
3598 | 3802 | { |
@@ -3620,23 +3824,25 @@ discard block |
||
3620 | 3824 | |
3621 | 3825 | foreach ($securityFiles as $i => $securityFile) |
3622 | 3826 | { |
3623 | - if (!file_exists($boarddir . '/' . $securityFile)) |
|
3624 | - unset($securityFiles[$i]); |
|
3827 | + if (!file_exists($boarddir . '/' . $securityFile)) { |
|
3828 | + unset($securityFiles[$i]); |
|
3829 | + } |
|
3625 | 3830 | } |
3626 | 3831 | |
3627 | 3832 | // We are already checking so many files...just few more doesn't make any difference! :P |
3628 | - if (!empty($modSettings['currentAttachmentUploadDir'])) |
|
3629 | - $path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; |
|
3630 | - |
|
3631 | - else |
|
3632 | - $path = $modSettings['attachmentUploadDir']; |
|
3833 | + if (!empty($modSettings['currentAttachmentUploadDir'])) { |
|
3834 | + $path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; |
|
3835 | + } else { |
|
3836 | + $path = $modSettings['attachmentUploadDir']; |
|
3837 | + } |
|
3633 | 3838 | |
3634 | 3839 | secureDirectory($path, true); |
3635 | 3840 | secureDirectory($cachedir); |
3636 | 3841 | |
3637 | 3842 | // If agreement is enabled, at least the english version shall exists |
3638 | - if ($modSettings['requireAgreement']) |
|
3639 | - $agreement = !file_exists($boarddir . '/agreement.txt'); |
|
3843 | + if ($modSettings['requireAgreement']) { |
|
3844 | + $agreement = !file_exists($boarddir . '/agreement.txt'); |
|
3845 | + } |
|
3640 | 3846 | |
3641 | 3847 | if (!empty($securityFiles) || (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) || !empty($agreement)) |
3642 | 3848 | { |
@@ -3651,18 +3857,21 @@ discard block |
||
3651 | 3857 | echo ' |
3652 | 3858 | ', $txt['not_removed'], '<strong>', $securityFile, '</strong>!<br>'; |
3653 | 3859 | |
3654 | - if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') |
|
3655 | - echo ' |
|
3860 | + if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') { |
|
3861 | + echo ' |
|
3656 | 3862 | ', sprintf($txt['not_removed_extra'], $securityFile, substr($securityFile, 0, -1)), '<br>'; |
3863 | + } |
|
3657 | 3864 | } |
3658 | 3865 | |
3659 | - if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) |
|
3660 | - echo ' |
|
3866 | + if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) { |
|
3867 | + echo ' |
|
3661 | 3868 | <strong>', $txt['cache_writable'], '</strong><br>'; |
3869 | + } |
|
3662 | 3870 | |
3663 | - if (!empty($agreement)) |
|
3664 | - echo ' |
|
3871 | + if (!empty($agreement)) { |
|
3872 | + echo ' |
|
3665 | 3873 | <strong>', $txt['agreement_missing'], '</strong><br>'; |
3874 | + } |
|
3666 | 3875 | |
3667 | 3876 | echo ' |
3668 | 3877 | </p> |
@@ -3677,16 +3886,18 @@ discard block |
||
3677 | 3886 | <div class="windowbg alert" style="margin: 2ex; padding: 2ex; border: 2px dashed red;"> |
3678 | 3887 | ', sprintf($txt['you_are_post_banned'], $user_info['is_guest'] ? $txt['guest_title'] : $user_info['name']); |
3679 | 3888 | |
3680 | - if (!empty($_SESSION['ban']['cannot_post']['reason'])) |
|
3681 | - echo ' |
|
3889 | + if (!empty($_SESSION['ban']['cannot_post']['reason'])) { |
|
3890 | + echo ' |
|
3682 | 3891 | <div style="padding-left: 4ex; padding-top: 1ex;">', $_SESSION['ban']['cannot_post']['reason'], '</div>'; |
3892 | + } |
|
3683 | 3893 | |
3684 | - if (!empty($_SESSION['ban']['expire_time'])) |
|
3685 | - echo ' |
|
3894 | + if (!empty($_SESSION['ban']['expire_time'])) { |
|
3895 | + echo ' |
|
3686 | 3896 | <div>', sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)), '</div>'; |
3687 | - else |
|
3688 | - echo ' |
|
3897 | + } else { |
|
3898 | + echo ' |
|
3689 | 3899 | <div>', $txt['your_ban_expires_never'], '</div>'; |
3900 | + } |
|
3690 | 3901 | |
3691 | 3902 | echo ' |
3692 | 3903 | </div>'; |
@@ -3702,8 +3913,9 @@ discard block |
||
3702 | 3913 | global $forum_copyright, $software_year, $forum_version; |
3703 | 3914 | |
3704 | 3915 | // Don't display copyright for things like SSI. |
3705 | - if (!isset($forum_version) || !isset($software_year)) |
|
3706 | - return; |
|
3916 | + if (!isset($forum_version) || !isset($software_year)) { |
|
3917 | + return; |
|
3918 | + } |
|
3707 | 3919 | |
3708 | 3920 | // Put in the version... |
3709 | 3921 | printf($forum_copyright, $forum_version, $software_year); |
@@ -3721,9 +3933,10 @@ discard block |
||
3721 | 3933 | $context['load_time'] = round(microtime(true) - $time_start, 3); |
3722 | 3934 | $context['load_queries'] = $db_count; |
3723 | 3935 | |
3724 | - foreach (array_reverse($context['template_layers']) as $layer) |
|
3725 | - loadSubTemplate($layer . '_below', true); |
|
3726 | -} |
|
3936 | + foreach (array_reverse($context['template_layers']) as $layer) { |
|
3937 | + loadSubTemplate($layer . '_below', true); |
|
3938 | + } |
|
3939 | + } |
|
3727 | 3940 | |
3728 | 3941 | /** |
3729 | 3942 | * Output the Javascript files |
@@ -3757,8 +3970,7 @@ discard block |
||
3757 | 3970 | { |
3758 | 3971 | echo ' |
3759 | 3972 | var ', $key, ';'; |
3760 | - } |
|
3761 | - else |
|
3973 | + } else |
|
3762 | 3974 | { |
3763 | 3975 | echo ' |
3764 | 3976 | var ', $key, ' = ', $value, ';'; |
@@ -3777,27 +3989,29 @@ discard block |
||
3777 | 3989 | foreach ($context['javascript_files'] as $id => $js_file) |
3778 | 3990 | { |
3779 | 3991 | // Last minute call! allow theme authors to disable single files. |
3780 | - if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) |
|
3781 | - continue; |
|
3992 | + if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) { |
|
3993 | + continue; |
|
3994 | + } |
|
3782 | 3995 | |
3783 | 3996 | // By default files don't get minimized unless the file explicitly says so! |
3784 | 3997 | if (!empty($js_file['options']['minimize']) && !empty($modSettings['minimize_files'])) |
3785 | 3998 | { |
3786 | - if (!empty($js_file['options']['async'])) |
|
3787 | - $toMinify['async'][] = $js_file; |
|
3788 | - elseif (!empty($js_file['options']['defer'])) |
|
3789 | - $toMinify['defer'][] = $js_file; |
|
3790 | - else |
|
3791 | - $toMinify['standard'][] = $js_file; |
|
3999 | + if (!empty($js_file['options']['async'])) { |
|
4000 | + $toMinify['async'][] = $js_file; |
|
4001 | + } elseif (!empty($js_file['options']['defer'])) { |
|
4002 | + $toMinify['defer'][] = $js_file; |
|
4003 | + } else { |
|
4004 | + $toMinify['standard'][] = $js_file; |
|
4005 | + } |
|
3792 | 4006 | |
3793 | 4007 | // Grab a random seed. |
3794 | - if (!isset($minSeed) && isset($js_file['options']['seed'])) |
|
3795 | - $minSeed = $js_file['options']['seed']; |
|
3796 | - } |
|
3797 | - |
|
3798 | - else |
|
3799 | - echo ' |
|
4008 | + if (!isset($minSeed) && isset($js_file['options']['seed'])) { |
|
4009 | + $minSeed = $js_file['options']['seed']; |
|
4010 | + } |
|
4011 | + } else { |
|
4012 | + echo ' |
|
3800 | 4013 | <script src="', $js_file['fileUrl'], '"', !empty($js_file['options']['async']) ? ' async' : '', !empty($js_file['options']['defer']) ? ' defer' : '', '></script>'; |
4014 | + } |
|
3801 | 4015 | } |
3802 | 4016 | |
3803 | 4017 | foreach ($toMinify as $js_files) |
@@ -3808,9 +4022,10 @@ discard block |
||
3808 | 4022 | |
3809 | 4023 | $minSuccessful = array_keys($result) === array('smf_minified'); |
3810 | 4024 | |
3811 | - foreach ($result as $minFile) |
|
3812 | - echo ' |
|
4025 | + foreach ($result as $minFile) { |
|
4026 | + echo ' |
|
3813 | 4027 | <script src="', $minFile['fileUrl'], $minSuccessful && isset($minSeed) ? $minSeed : '', '"', !empty($minFile['options']['async']) ? ' async' : '', !empty($minFile['options']['defer']) ? ' defer' : '', '></script>'; |
4028 | + } |
|
3814 | 4029 | } |
3815 | 4030 | } |
3816 | 4031 | } |
@@ -3824,8 +4039,9 @@ discard block |
||
3824 | 4039 | <script> |
3825 | 4040 | window.addEventListener("DOMContentLoaded", function() {'; |
3826 | 4041 | |
3827 | - foreach ($context['javascript_inline']['defer'] as $js_code) |
|
3828 | - echo $js_code; |
|
4042 | + foreach ($context['javascript_inline']['defer'] as $js_code) { |
|
4043 | + echo $js_code; |
|
4044 | + } |
|
3829 | 4045 | |
3830 | 4046 | echo ' |
3831 | 4047 | }); |
@@ -3837,8 +4053,9 @@ discard block |
||
3837 | 4053 | echo ' |
3838 | 4054 | <script>'; |
3839 | 4055 | |
3840 | - foreach ($context['javascript_inline']['standard'] as $js_code) |
|
3841 | - echo $js_code; |
|
4056 | + foreach ($context['javascript_inline']['standard'] as $js_code) { |
|
4057 | + echo $js_code; |
|
4058 | + } |
|
3842 | 4059 | |
3843 | 4060 | echo ' |
3844 | 4061 | </script>'; |
@@ -3866,23 +4083,26 @@ discard block |
||
3866 | 4083 | foreach ($context['css_files'] as $id => $file) |
3867 | 4084 | { |
3868 | 4085 | // Last minute call! allow theme authors to disable single files. |
3869 | - if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) |
|
3870 | - continue; |
|
4086 | + if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) { |
|
4087 | + continue; |
|
4088 | + } |
|
3871 | 4089 | |
3872 | 4090 | // Files are minimized unless they explicitly opt out. |
3873 | - if (!isset($file['options']['minimize'])) |
|
3874 | - $file['options']['minimize'] = true; |
|
4091 | + if (!isset($file['options']['minimize'])) { |
|
4092 | + $file['options']['minimize'] = true; |
|
4093 | + } |
|
3875 | 4094 | |
3876 | 4095 | if (!empty($file['options']['minimize']) && !empty($modSettings['minimize_files']) && !isset($_REQUEST['normalcss'])) |
3877 | 4096 | { |
3878 | 4097 | $toMinify[] = $file; |
3879 | 4098 | |
3880 | 4099 | // Grab a random seed. |
3881 | - if (!isset($minSeed) && isset($file['options']['seed'])) |
|
3882 | - $minSeed = $file['options']['seed']; |
|
4100 | + if (!isset($minSeed) && isset($file['options']['seed'])) { |
|
4101 | + $minSeed = $file['options']['seed']; |
|
4102 | + } |
|
4103 | + } else { |
|
4104 | + $normal[] = $file['fileUrl']; |
|
3883 | 4105 | } |
3884 | - else |
|
3885 | - $normal[] = $file['fileUrl']; |
|
3886 | 4106 | } |
3887 | 4107 | |
3888 | 4108 | if (!empty($toMinify)) |
@@ -3891,23 +4111,26 @@ discard block |
||
3891 | 4111 | |
3892 | 4112 | $minSuccessful = array_keys($result) === array('smf_minified'); |
3893 | 4113 | |
3894 | - foreach ($result as $minFile) |
|
3895 | - echo ' |
|
4114 | + foreach ($result as $minFile) { |
|
4115 | + echo ' |
|
3896 | 4116 | <link rel="stylesheet" href="', $minFile['fileUrl'], $minSuccessful && isset($minSeed) ? $minSeed : '', '">'; |
4117 | + } |
|
3897 | 4118 | } |
3898 | 4119 | |
3899 | 4120 | // Print the rest after the minified files. |
3900 | - if (!empty($normal)) |
|
3901 | - foreach ($normal as $nf) |
|
4121 | + if (!empty($normal)) { |
|
4122 | + foreach ($normal as $nf) |
|
3902 | 4123 | echo ' |
3903 | 4124 | <link rel="stylesheet" href="', $nf ,'">'; |
4125 | + } |
|
3904 | 4126 | |
3905 | 4127 | if ($db_show_debug === true) |
3906 | 4128 | { |
3907 | 4129 | // Try to keep only what's useful. |
3908 | 4130 | $repl = array($boardurl . '/Themes/' => '', $boardurl . '/' => ''); |
3909 | - foreach ($context['css_files'] as $file) |
|
3910 | - $context['debug']['sheets'][] = strtr($file['fileName'], $repl); |
|
4131 | + foreach ($context['css_files'] as $file) { |
|
4132 | + $context['debug']['sheets'][] = strtr($file['fileName'], $repl); |
|
4133 | + } |
|
3911 | 4134 | } |
3912 | 4135 | |
3913 | 4136 | if (!empty($context['css_header'])) |
@@ -3915,9 +4138,10 @@ discard block |
||
3915 | 4138 | echo ' |
3916 | 4139 | <style>'; |
3917 | 4140 | |
3918 | - foreach ($context['css_header'] as $css) |
|
3919 | - echo $css .' |
|
4141 | + foreach ($context['css_header'] as $css) { |
|
4142 | + echo $css .' |
|
3920 | 4143 | '; |
4144 | + } |
|
3921 | 4145 | |
3922 | 4146 | echo' |
3923 | 4147 | </style>'; |
@@ -3940,8 +4164,9 @@ discard block |
||
3940 | 4164 | $type = !empty($type) && in_array($type, $types) ? $type : false; |
3941 | 4165 | $data = is_array($data) ? $data : array(); |
3942 | 4166 | |
3943 | - if (empty($type) || empty($data)) |
|
3944 | - return $data; |
|
4167 | + if (empty($type) || empty($data)) { |
|
4168 | + return $data; |
|
4169 | + } |
|
3945 | 4170 | |
3946 | 4171 | // Different pages include different files, so we use a hash to label the different combinations |
3947 | 4172 | $hash = md5(implode(' ', array_map(function($file) { return $file['filePath'] . (int) @filesize($file['filePath']) . (int) @filemtime($file['filePath']); }, $data))); |
@@ -3950,13 +4175,14 @@ discard block |
||
3950 | 4175 | list($toCache, $async, $defer) = array_pad((array) cache_get_data('minimized_' . $settings['theme_id'] . '_' . $type . '_' . $hash, 86400), 3, null); |
3951 | 4176 | |
3952 | 4177 | // Already done? |
3953 | - if (!empty($toCache)) |
|
3954 | - return array('smf_minified' => array( |
|
4178 | + if (!empty($toCache)) { |
|
4179 | + return array('smf_minified' => array( |
|
3955 | 4180 | 'fileUrl' => $settings['theme_url'] . '/' . ($type == 'css' ? 'css' : 'scripts') . '/' . basename($toCache), |
3956 | 4181 | 'filePath' => $toCache, |
3957 | 4182 | 'fileName' => basename($toCache), |
3958 | 4183 | 'options' => array('async' => !empty($async), 'defer' => !empty($defer)), |
3959 | 4184 | )); |
4185 | + } |
|
3960 | 4186 | |
3961 | 4187 | |
3962 | 4188 | // No namespaces, sorry! |
@@ -3986,9 +4212,9 @@ discard block |
||
3986 | 4212 | |
3987 | 4213 | foreach ($data as $id => $file) |
3988 | 4214 | { |
3989 | - if (empty($file['filePath'])) |
|
3990 | - $toAdd = false; |
|
3991 | - else |
|
4215 | + if (empty($file['filePath'])) { |
|
4216 | + $toAdd = false; |
|
4217 | + } else |
|
3992 | 4218 | { |
3993 | 4219 | $seed = isset($file['options']['seed']) ? $file['options']['seed'] : ''; |
3994 | 4220 | $tempFile = str_replace($seed, '', $file['filePath']); |
@@ -3996,12 +4222,14 @@ discard block |
||
3996 | 4222 | } |
3997 | 4223 | |
3998 | 4224 | // A minified script should only be loaded asynchronously if all its components wanted to be. |
3999 | - if (empty($file['options']['async'])) |
|
4000 | - $async = false; |
|
4225 | + if (empty($file['options']['async'])) { |
|
4226 | + $async = false; |
|
4227 | + } |
|
4001 | 4228 | |
4002 | 4229 | // A minified script should only be deferred if all its components wanted to be. |
4003 | - if (empty($file['options']['defer'])) |
|
4004 | - $defer = false; |
|
4230 | + if (empty($file['options']['defer'])) { |
|
4231 | + $defer = false; |
|
4232 | + } |
|
4005 | 4233 | |
4006 | 4234 | // The file couldn't be located so it won't be added. Log this error. |
4007 | 4235 | if (empty($toAdd)) |
@@ -4067,12 +4295,14 @@ discard block |
||
4067 | 4295 | foreach (glob(rtrim($theme['dir'], '/') . '/' . ($type == 'css' ? 'css' : 'scripts') . '/minified*.' . $type) as $filename) |
4068 | 4296 | { |
4069 | 4297 | // Remove the cache entry |
4070 | - if (preg_match('~([a-zA-Z0-9]+)\.' . $type . '$~', $filename, $matches)) |
|
4071 | - cache_put_data('minimized_' . $theme['id'] . '_' . $type . '_' . $matches[1], null); |
|
4298 | + if (preg_match('~([a-zA-Z0-9]+)\.' . $type . '$~', $filename, $matches)) { |
|
4299 | + cache_put_data('minimized_' . $theme['id'] . '_' . $type . '_' . $matches[1], null); |
|
4300 | + } |
|
4072 | 4301 | |
4073 | 4302 | // Try to delete the file. Add it to our error list if it fails. |
4074 | - if (!@unlink($filename)) |
|
4075 | - $not_deleted[] = $filename; |
|
4303 | + if (!@unlink($filename)) { |
|
4304 | + $not_deleted[] = $filename; |
|
4305 | + } |
|
4076 | 4306 | } |
4077 | 4307 | } |
4078 | 4308 | } |
@@ -4104,8 +4334,9 @@ discard block |
||
4104 | 4334 | global $modSettings, $smcFunc; |
4105 | 4335 | |
4106 | 4336 | // Just make up a nice hash... |
4107 | - if ($new) |
|
4108 | - return sha1(md5($filename . time()) . mt_rand()); |
|
4337 | + if ($new) { |
|
4338 | + return sha1(md5($filename . time()) . mt_rand()); |
|
4339 | + } |
|
4109 | 4340 | |
4110 | 4341 | // Just make sure that attachment id is only a int |
4111 | 4342 | $attachment_id = (int) $attachment_id; |
@@ -4122,23 +4353,25 @@ discard block |
||
4122 | 4353 | 'id_attach' => $attachment_id, |
4123 | 4354 | )); |
4124 | 4355 | |
4125 | - if ($smcFunc['db_num_rows']($request) === 0) |
|
4126 | - return false; |
|
4356 | + if ($smcFunc['db_num_rows']($request) === 0) { |
|
4357 | + return false; |
|
4358 | + } |
|
4127 | 4359 | |
4128 | 4360 | list ($file_hash) = $smcFunc['db_fetch_row']($request); |
4129 | 4361 | $smcFunc['db_free_result']($request); |
4130 | 4362 | } |
4131 | 4363 | |
4132 | 4364 | // Still no hash? mmm... |
4133 | - if (empty($file_hash)) |
|
4134 | - $file_hash = sha1(md5($filename . time()) . mt_rand()); |
|
4365 | + if (empty($file_hash)) { |
|
4366 | + $file_hash = sha1(md5($filename . time()) . mt_rand()); |
|
4367 | + } |
|
4135 | 4368 | |
4136 | 4369 | // Are we using multiple directories? |
4137 | - if (is_array($modSettings['attachmentUploadDir'])) |
|
4138 | - $path = $modSettings['attachmentUploadDir'][$dir]; |
|
4139 | - |
|
4140 | - else |
|
4141 | - $path = $modSettings['attachmentUploadDir']; |
|
4370 | + if (is_array($modSettings['attachmentUploadDir'])) { |
|
4371 | + $path = $modSettings['attachmentUploadDir'][$dir]; |
|
4372 | + } else { |
|
4373 | + $path = $modSettings['attachmentUploadDir']; |
|
4374 | + } |
|
4142 | 4375 | |
4143 | 4376 | return $path . '/' . $attachment_id . '_' . $file_hash .'.dat'; |
4144 | 4377 | } |
@@ -4153,8 +4386,9 @@ discard block |
||
4153 | 4386 | function ip2range($fullip) |
4154 | 4387 | { |
4155 | 4388 | // Pretend that 'unknown' is 255.255.255.255. (since that can't be an IP anyway.) |
4156 | - if ($fullip == 'unknown') |
|
4157 | - $fullip = '255.255.255.255'; |
|
4389 | + if ($fullip == 'unknown') { |
|
4390 | + $fullip = '255.255.255.255'; |
|
4391 | + } |
|
4158 | 4392 | |
4159 | 4393 | $ip_parts = explode('-', $fullip); |
4160 | 4394 | $ip_array = array(); |
@@ -4178,10 +4412,11 @@ discard block |
||
4178 | 4412 | $ip_array['low'] = $ip_parts[0]; |
4179 | 4413 | $ip_array['high'] = $ip_parts[1]; |
4180 | 4414 | return $ip_array; |
4181 | - } |
|
4182 | - elseif (count($ip_parts) == 2) // if ip 22.22.*-22.22.* |
|
4415 | + } elseif (count($ip_parts) == 2) { |
|
4416 | + // if ip 22.22.*-22.22.* |
|
4183 | 4417 | { |
4184 | 4418 | $valid_low = isValidIP($ip_parts[0]); |
4419 | + } |
|
4185 | 4420 | $valid_high = isValidIP($ip_parts[1]); |
4186 | 4421 | $count = 0; |
4187 | 4422 | $mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.'); |
@@ -4196,7 +4431,9 @@ discard block |
||
4196 | 4431 | $ip_parts[0] .= $mode . $min; |
4197 | 4432 | $valid_low = isValidIP($ip_parts[0]); |
4198 | 4433 | $count++; |
4199 | - if ($count > 9) break; |
|
4434 | + if ($count > 9) { |
|
4435 | + break; |
|
4436 | + } |
|
4200 | 4437 | } |
4201 | 4438 | } |
4202 | 4439 | |
@@ -4210,7 +4447,9 @@ discard block |
||
4210 | 4447 | $ip_parts[1] .= $mode . $max; |
4211 | 4448 | $valid_high = isValidIP($ip_parts[1]); |
4212 | 4449 | $count++; |
4213 | - if ($count > 9) break; |
|
4450 | + if ($count > 9) { |
|
4451 | + break; |
|
4452 | + } |
|
4214 | 4453 | } |
4215 | 4454 | } |
4216 | 4455 | |
@@ -4234,46 +4473,54 @@ discard block |
||
4234 | 4473 | { |
4235 | 4474 | global $modSettings; |
4236 | 4475 | |
4237 | - if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) |
|
4238 | - return $host; |
|
4476 | + if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) { |
|
4477 | + return $host; |
|
4478 | + } |
|
4239 | 4479 | $t = microtime(); |
4240 | 4480 | |
4241 | 4481 | // Try the Linux host command, perhaps? |
4242 | 4482 | if (!isset($host) && (strpos(strtolower(PHP_OS), 'win') === false || strpos(strtolower(PHP_OS), 'darwin') !== false) && mt_rand(0, 1) == 1) |
4243 | 4483 | { |
4244 | - if (!isset($modSettings['host_to_dis'])) |
|
4245 | - $test = @shell_exec('host -W 1 ' . @escapeshellarg($ip)); |
|
4246 | - else |
|
4247 | - $test = @shell_exec('host ' . @escapeshellarg($ip)); |
|
4484 | + if (!isset($modSettings['host_to_dis'])) { |
|
4485 | + $test = @shell_exec('host -W 1 ' . @escapeshellarg($ip)); |
|
4486 | + } else { |
|
4487 | + $test = @shell_exec('host ' . @escapeshellarg($ip)); |
|
4488 | + } |
|
4248 | 4489 | |
4249 | 4490 | // Did host say it didn't find anything? |
4250 | - if (strpos($test, 'not found') !== false) |
|
4251 | - $host = ''; |
|
4491 | + if (strpos($test, 'not found') !== false) { |
|
4492 | + $host = ''; |
|
4493 | + } |
|
4252 | 4494 | // Invalid server option? |
4253 | - elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) |
|
4254 | - updateSettings(array('host_to_dis' => 1)); |
|
4495 | + elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) { |
|
4496 | + updateSettings(array('host_to_dis' => 1)); |
|
4497 | + } |
|
4255 | 4498 | // Maybe it found something, after all? |
4256 | - elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) |
|
4257 | - $host = $match[1]; |
|
4499 | + elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) { |
|
4500 | + $host = $match[1]; |
|
4501 | + } |
|
4258 | 4502 | } |
4259 | 4503 | |
4260 | 4504 | // This is nslookup; usually only Windows, but possibly some Unix? |
4261 | 4505 | if (!isset($host) && stripos(PHP_OS, 'win') !== false && strpos(strtolower(PHP_OS), 'darwin') === false && mt_rand(0, 1) == 1) |
4262 | 4506 | { |
4263 | 4507 | $test = @shell_exec('nslookup -timeout=1 ' . @escapeshellarg($ip)); |
4264 | - if (strpos($test, 'Non-existent domain') !== false) |
|
4265 | - $host = ''; |
|
4266 | - elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) |
|
4267 | - $host = $match[1]; |
|
4508 | + if (strpos($test, 'Non-existent domain') !== false) { |
|
4509 | + $host = ''; |
|
4510 | + } elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) { |
|
4511 | + $host = $match[1]; |
|
4512 | + } |
|
4268 | 4513 | } |
4269 | 4514 | |
4270 | 4515 | // This is the last try :/. |
4271 | - if (!isset($host) || $host === false) |
|
4272 | - $host = @gethostbyaddr($ip); |
|
4516 | + if (!isset($host) || $host === false) { |
|
4517 | + $host = @gethostbyaddr($ip); |
|
4518 | + } |
|
4273 | 4519 | |
4274 | 4520 | // It took a long time, so let's cache it! |
4275 | - if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) |
|
4276 | - cache_put_data('hostlookup-' . $ip, $host, 600); |
|
4521 | + if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) { |
|
4522 | + cache_put_data('hostlookup-' . $ip, $host, 600); |
|
4523 | + } |
|
4277 | 4524 | |
4278 | 4525 | return $host; |
4279 | 4526 | } |
@@ -4309,20 +4556,21 @@ discard block |
||
4309 | 4556 | { |
4310 | 4557 | $encrypted = substr(crypt($word, 'uk'), 2, $max_chars); |
4311 | 4558 | $total = 0; |
4312 | - for ($i = 0; $i < $max_chars; $i++) |
|
4313 | - $total += $possible_chars[ord($encrypted{$i})] * pow(63, $i); |
|
4559 | + for ($i = 0; $i < $max_chars; $i++) { |
|
4560 | + $total += $possible_chars[ord($encrypted{$i})] * pow(63, $i); |
|
4561 | + } |
|
4314 | 4562 | $returned_ints[] = $max_chars == 4 ? min($total, 16777215) : $total; |
4315 | 4563 | } |
4316 | 4564 | } |
4317 | 4565 | return array_unique($returned_ints); |
4318 | - } |
|
4319 | - else |
|
4566 | + } else |
|
4320 | 4567 | { |
4321 | 4568 | // Trim characters before and after and add slashes for database insertion. |
4322 | 4569 | $returned_words = array(); |
4323 | - foreach ($words as $word) |
|
4324 | - if (($word = trim($word, '-_\'')) !== '') |
|
4570 | + foreach ($words as $word) { |
|
4571 | + if (($word = trim($word, '-_\'')) !== '') |
|
4325 | 4572 | $returned_words[] = $max_chars === null ? $word : substr($word, 0, $max_chars); |
4573 | + } |
|
4326 | 4574 | |
4327 | 4575 | // Filter out all words that occur more than once. |
4328 | 4576 | return array_unique($returned_words); |
@@ -4344,16 +4592,18 @@ discard block |
||
4344 | 4592 | global $settings, $txt; |
4345 | 4593 | |
4346 | 4594 | // Does the current loaded theme have this and we are not forcing the usage of this function? |
4347 | - if (function_exists('template_create_button') && !$force_use) |
|
4348 | - return template_create_button($name, $alt, $label = '', $custom = ''); |
|
4595 | + if (function_exists('template_create_button') && !$force_use) { |
|
4596 | + return template_create_button($name, $alt, $label = '', $custom = ''); |
|
4597 | + } |
|
4349 | 4598 | |
4350 | - if (!$settings['use_image_buttons']) |
|
4351 | - return $txt[$alt]; |
|
4352 | - elseif (!empty($settings['use_buttons'])) |
|
4353 | - return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? ' <strong>' . $txt[$label] . '</strong>' : ''); |
|
4354 | - else |
|
4355 | - return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>'; |
|
4356 | -} |
|
4599 | + if (!$settings['use_image_buttons']) { |
|
4600 | + return $txt[$alt]; |
|
4601 | + } elseif (!empty($settings['use_buttons'])) { |
|
4602 | + return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? ' <strong>' . $txt[$label] . '</strong>' : ''); |
|
4603 | + } else { |
|
4604 | + return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>'; |
|
4605 | + } |
|
4606 | + } |
|
4357 | 4607 | |
4358 | 4608 | /** |
4359 | 4609 | * Sets up all of the top menu buttons |
@@ -4396,9 +4646,10 @@ discard block |
||
4396 | 4646 | var user_menus = new smc_PopupMenu(); |
4397 | 4647 | user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup"); |
4398 | 4648 | user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true); |
4399 | - if ($context['allow_pm']) |
|
4400 | - addInlineJavaScript(' |
|
4649 | + if ($context['allow_pm']) { |
|
4650 | + addInlineJavaScript(' |
|
4401 | 4651 | user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true); |
4652 | + } |
|
4402 | 4653 | |
4403 | 4654 | if (!empty($modSettings['enable_ajax_alerts'])) |
4404 | 4655 | { |
@@ -4558,88 +4809,96 @@ discard block |
||
4558 | 4809 | |
4559 | 4810 | // Now we put the buttons in the context so the theme can use them. |
4560 | 4811 | $menu_buttons = array(); |
4561 | - foreach ($buttons as $act => $button) |
|
4562 | - if (!empty($button['show'])) |
|
4812 | + foreach ($buttons as $act => $button) { |
|
4813 | + if (!empty($button['show'])) |
|
4563 | 4814 | { |
4564 | 4815 | $button['active_button'] = false; |
4816 | + } |
|
4565 | 4817 | |
4566 | 4818 | // This button needs some action. |
4567 | - if (isset($button['action_hook'])) |
|
4568 | - $needs_action_hook = true; |
|
4819 | + if (isset($button['action_hook'])) { |
|
4820 | + $needs_action_hook = true; |
|
4821 | + } |
|
4569 | 4822 | |
4570 | 4823 | // Make sure the last button truly is the last button. |
4571 | 4824 | if (!empty($button['is_last'])) |
4572 | 4825 | { |
4573 | - if (isset($last_button)) |
|
4574 | - unset($menu_buttons[$last_button]['is_last']); |
|
4826 | + if (isset($last_button)) { |
|
4827 | + unset($menu_buttons[$last_button]['is_last']); |
|
4828 | + } |
|
4575 | 4829 | $last_button = $act; |
4576 | 4830 | } |
4577 | 4831 | |
4578 | 4832 | // Go through the sub buttons if there are any. |
4579 | - if (!empty($button['sub_buttons'])) |
|
4580 | - foreach ($button['sub_buttons'] as $key => $subbutton) |
|
4833 | + if (!empty($button['sub_buttons'])) { |
|
4834 | + foreach ($button['sub_buttons'] as $key => $subbutton) |
|
4581 | 4835 | { |
4582 | 4836 | if (empty($subbutton['show'])) |
4583 | 4837 | unset($button['sub_buttons'][$key]); |
4838 | + } |
|
4584 | 4839 | |
4585 | 4840 | // 2nd level sub buttons next... |
4586 | 4841 | if (!empty($subbutton['sub_buttons'])) |
4587 | 4842 | { |
4588 | 4843 | foreach ($subbutton['sub_buttons'] as $key2 => $sub_button2) |
4589 | 4844 | { |
4590 | - if (empty($sub_button2['show'])) |
|
4591 | - unset($button['sub_buttons'][$key]['sub_buttons'][$key2]); |
|
4845 | + if (empty($sub_button2['show'])) { |
|
4846 | + unset($button['sub_buttons'][$key]['sub_buttons'][$key2]); |
|
4847 | + } |
|
4592 | 4848 | } |
4593 | 4849 | } |
4594 | 4850 | } |
4595 | 4851 | |
4596 | 4852 | // Does this button have its own icon? |
4597 | - if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) |
|
4598 | - $button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
4599 | - elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) |
|
4600 | - $button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
4601 | - elseif (isset($button['icon'])) |
|
4602 | - $button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>'; |
|
4603 | - else |
|
4604 | - $button['icon'] = '<span class="generic_icons ' . $act . '"></span>'; |
|
4853 | + if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) { |
|
4854 | + $button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
4855 | + } elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) { |
|
4856 | + $button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
4857 | + } elseif (isset($button['icon'])) { |
|
4858 | + $button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>'; |
|
4859 | + } else { |
|
4860 | + $button['icon'] = '<span class="generic_icons ' . $act . '"></span>'; |
|
4861 | + } |
|
4605 | 4862 | |
4606 | 4863 | $menu_buttons[$act] = $button; |
4607 | 4864 | } |
4608 | 4865 | |
4609 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
4610 | - cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime); |
|
4866 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
4867 | + cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime); |
|
4868 | + } |
|
4611 | 4869 | } |
4612 | 4870 | |
4613 | 4871 | $context['menu_buttons'] = $menu_buttons; |
4614 | 4872 | |
4615 | 4873 | // Logging out requires the session id in the url. |
4616 | - if (isset($context['menu_buttons']['logout'])) |
|
4617 | - $context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']); |
|
4874 | + if (isset($context['menu_buttons']['logout'])) { |
|
4875 | + $context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']); |
|
4876 | + } |
|
4618 | 4877 | |
4619 | 4878 | // Figure out which action we are doing so we can set the active tab. |
4620 | 4879 | // Default to home. |
4621 | 4880 | $current_action = 'home'; |
4622 | 4881 | |
4623 | - if (isset($context['menu_buttons'][$context['current_action']])) |
|
4624 | - $current_action = $context['current_action']; |
|
4625 | - elseif ($context['current_action'] == 'search2') |
|
4626 | - $current_action = 'search'; |
|
4627 | - elseif ($context['current_action'] == 'theme') |
|
4628 | - $current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin'; |
|
4629 | - elseif ($context['current_action'] == 'register2') |
|
4630 | - $current_action = 'register'; |
|
4631 | - elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) |
|
4632 | - $current_action = 'login'; |
|
4633 | - elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) |
|
4634 | - $current_action = 'moderate'; |
|
4882 | + if (isset($context['menu_buttons'][$context['current_action']])) { |
|
4883 | + $current_action = $context['current_action']; |
|
4884 | + } elseif ($context['current_action'] == 'search2') { |
|
4885 | + $current_action = 'search'; |
|
4886 | + } elseif ($context['current_action'] == 'theme') { |
|
4887 | + $current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin'; |
|
4888 | + } elseif ($context['current_action'] == 'register2') { |
|
4889 | + $current_action = 'register'; |
|
4890 | + } elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) { |
|
4891 | + $current_action = 'login'; |
|
4892 | + } elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) { |
|
4893 | + $current_action = 'moderate'; |
|
4894 | + } |
|
4635 | 4895 | |
4636 | 4896 | // There are certain exceptions to the above where we don't want anything on the menu highlighted. |
4637 | 4897 | if ($context['current_action'] == 'profile' && !empty($context['user']['is_owner'])) |
4638 | 4898 | { |
4639 | 4899 | $current_action = !empty($_GET['area']) && $_GET['area'] == 'showalerts' ? 'self_alerts' : 'self_profile'; |
4640 | 4900 | $context[$current_action] = true; |
4641 | - } |
|
4642 | - elseif ($context['current_action'] == 'pm') |
|
4901 | + } elseif ($context['current_action'] == 'pm') |
|
4643 | 4902 | { |
4644 | 4903 | $current_action = 'self_pm'; |
4645 | 4904 | $context['self_pm'] = true; |
@@ -4702,12 +4961,14 @@ discard block |
||
4702 | 4961 | } |
4703 | 4962 | |
4704 | 4963 | // Not all actions are simple. |
4705 | - if (!empty($needs_action_hook)) |
|
4706 | - call_integration_hook('integrate_current_action', array(&$current_action)); |
|
4964 | + if (!empty($needs_action_hook)) { |
|
4965 | + call_integration_hook('integrate_current_action', array(&$current_action)); |
|
4966 | + } |
|
4707 | 4967 | |
4708 | - if (isset($context['menu_buttons'][$current_action])) |
|
4709 | - $context['menu_buttons'][$current_action]['active_button'] = true; |
|
4710 | -} |
|
4968 | + if (isset($context['menu_buttons'][$current_action])) { |
|
4969 | + $context['menu_buttons'][$current_action]['active_button'] = true; |
|
4970 | + } |
|
4971 | + } |
|
4711 | 4972 | |
4712 | 4973 | /** |
4713 | 4974 | * Generate a random seed and ensure it's stored in settings. |
@@ -4731,30 +4992,35 @@ discard block |
||
4731 | 4992 | global $modSettings, $settings, $boarddir, $sourcedir, $db_show_debug; |
4732 | 4993 | global $context, $txt; |
4733 | 4994 | |
4734 | - if ($db_show_debug === true) |
|
4735 | - $context['debug']['hooks'][] = $hook; |
|
4995 | + if ($db_show_debug === true) { |
|
4996 | + $context['debug']['hooks'][] = $hook; |
|
4997 | + } |
|
4736 | 4998 | |
4737 | 4999 | // Need to have some control. |
4738 | - if (!isset($context['instances'])) |
|
4739 | - $context['instances'] = array(); |
|
5000 | + if (!isset($context['instances'])) { |
|
5001 | + $context['instances'] = array(); |
|
5002 | + } |
|
4740 | 5003 | |
4741 | 5004 | $results = array(); |
4742 | - if (empty($modSettings[$hook])) |
|
4743 | - return $results; |
|
5005 | + if (empty($modSettings[$hook])) { |
|
5006 | + return $results; |
|
5007 | + } |
|
4744 | 5008 | |
4745 | 5009 | $functions = explode(',', $modSettings[$hook]); |
4746 | 5010 | // Loop through each function. |
4747 | 5011 | foreach ($functions as $function) |
4748 | 5012 | { |
4749 | 5013 | // Hook has been marked as "disabled". Skip it! |
4750 | - if (strpos($function, '!') !== false) |
|
4751 | - continue; |
|
5014 | + if (strpos($function, '!') !== false) { |
|
5015 | + continue; |
|
5016 | + } |
|
4752 | 5017 | |
4753 | 5018 | $call = call_helper($function, true); |
4754 | 5019 | |
4755 | 5020 | // Is it valid? |
4756 | - if (!empty($call)) |
|
4757 | - $results[$function] = call_user_func_array($call, $parameters); |
|
5021 | + if (!empty($call)) { |
|
5022 | + $results[$function] = call_user_func_array($call, $parameters); |
|
5023 | + } |
|
4758 | 5024 | |
4759 | 5025 | // Whatever it was suppose to call, it failed :( |
4760 | 5026 | elseif (!empty($function)) |
@@ -4770,8 +5036,9 @@ discard block |
||
4770 | 5036 | } |
4771 | 5037 | |
4772 | 5038 | // "Assume" the file resides on $boarddir somewhere... |
4773 | - else |
|
4774 | - log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general'); |
|
5039 | + else { |
|
5040 | + log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general'); |
|
5041 | + } |
|
4775 | 5042 | } |
4776 | 5043 | } |
4777 | 5044 | |
@@ -4793,12 +5060,14 @@ discard block |
||
4793 | 5060 | global $smcFunc, $modSettings; |
4794 | 5061 | |
4795 | 5062 | // Any objects? |
4796 | - if ($object) |
|
4797 | - $function = $function . '#'; |
|
5063 | + if ($object) { |
|
5064 | + $function = $function . '#'; |
|
5065 | + } |
|
4798 | 5066 | |
4799 | 5067 | // Any files to load? |
4800 | - if (!empty($file) && is_string($file)) |
|
4801 | - $function = $file . (!empty($function) ? '|' . $function : ''); |
|
5068 | + if (!empty($file) && is_string($file)) { |
|
5069 | + $function = $file . (!empty($function) ? '|' . $function : ''); |
|
5070 | + } |
|
4802 | 5071 | |
4803 | 5072 | // Get the correct string. |
4804 | 5073 | $integration_call = $function; |
@@ -4820,13 +5089,14 @@ discard block |
||
4820 | 5089 | if (!empty($current_functions)) |
4821 | 5090 | { |
4822 | 5091 | $current_functions = explode(',', $current_functions); |
4823 | - if (in_array($integration_call, $current_functions)) |
|
4824 | - return; |
|
5092 | + if (in_array($integration_call, $current_functions)) { |
|
5093 | + return; |
|
5094 | + } |
|
4825 | 5095 | |
4826 | 5096 | $permanent_functions = array_merge($current_functions, array($integration_call)); |
5097 | + } else { |
|
5098 | + $permanent_functions = array($integration_call); |
|
4827 | 5099 | } |
4828 | - else |
|
4829 | - $permanent_functions = array($integration_call); |
|
4830 | 5100 | |
4831 | 5101 | updateSettings(array($hook => implode(',', $permanent_functions))); |
4832 | 5102 | } |
@@ -4835,8 +5105,9 @@ discard block |
||
4835 | 5105 | $functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]); |
4836 | 5106 | |
4837 | 5107 | // Do nothing, if it's already there. |
4838 | - if (in_array($integration_call, $functions)) |
|
4839 | - return; |
|
5108 | + if (in_array($integration_call, $functions)) { |
|
5109 | + return; |
|
5110 | + } |
|
4840 | 5111 | |
4841 | 5112 | $functions[] = $integration_call; |
4842 | 5113 | $modSettings[$hook] = implode(',', $functions); |
@@ -4859,12 +5130,14 @@ discard block |
||
4859 | 5130 | global $smcFunc, $modSettings; |
4860 | 5131 | |
4861 | 5132 | // Any objects? |
4862 | - if ($object) |
|
4863 | - $function = $function . '#'; |
|
5133 | + if ($object) { |
|
5134 | + $function = $function . '#'; |
|
5135 | + } |
|
4864 | 5136 | |
4865 | 5137 | // Any files to load? |
4866 | - if (!empty($file) && is_string($file)) |
|
4867 | - $function = $file . '|' . $function; |
|
5138 | + if (!empty($file) && is_string($file)) { |
|
5139 | + $function = $file . '|' . $function; |
|
5140 | + } |
|
4868 | 5141 | |
4869 | 5142 | // Get the correct string. |
4870 | 5143 | $integration_call = $function; |
@@ -4885,16 +5158,18 @@ discard block |
||
4885 | 5158 | { |
4886 | 5159 | $current_functions = explode(',', $current_functions); |
4887 | 5160 | |
4888 | - if (in_array($integration_call, $current_functions)) |
|
4889 | - updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call))))); |
|
5161 | + if (in_array($integration_call, $current_functions)) { |
|
5162 | + updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call))))); |
|
5163 | + } |
|
4890 | 5164 | } |
4891 | 5165 | |
4892 | 5166 | // Turn the function list into something usable. |
4893 | 5167 | $functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]); |
4894 | 5168 | |
4895 | 5169 | // You can only remove it if it's available. |
4896 | - if (!in_array($integration_call, $functions)) |
|
4897 | - return; |
|
5170 | + if (!in_array($integration_call, $functions)) { |
|
5171 | + return; |
|
5172 | + } |
|
4898 | 5173 | |
4899 | 5174 | $functions = array_diff($functions, array($integration_call)); |
4900 | 5175 | $modSettings[$hook] = implode(',', $functions); |
@@ -4915,17 +5190,20 @@ discard block |
||
4915 | 5190 | global $context, $smcFunc, $txt, $db_show_debug; |
4916 | 5191 | |
4917 | 5192 | // Really? |
4918 | - if (empty($string)) |
|
4919 | - return false; |
|
5193 | + if (empty($string)) { |
|
5194 | + return false; |
|
5195 | + } |
|
4920 | 5196 | |
4921 | 5197 | // An array? should be a "callable" array IE array(object/class, valid_callable). |
4922 | 5198 | // A closure? should be a callable one. |
4923 | - if (is_array($string) || $string instanceof Closure) |
|
4924 | - return $return ? $string : (is_callable($string) ? call_user_func($string) : false); |
|
5199 | + if (is_array($string) || $string instanceof Closure) { |
|
5200 | + return $return ? $string : (is_callable($string) ? call_user_func($string) : false); |
|
5201 | + } |
|
4925 | 5202 | |
4926 | 5203 | // No full objects, sorry! pass a method or a property instead! |
4927 | - if (is_object($string)) |
|
4928 | - return false; |
|
5204 | + if (is_object($string)) { |
|
5205 | + return false; |
|
5206 | + } |
|
4929 | 5207 | |
4930 | 5208 | // Stay vitaminized my friends... |
4931 | 5209 | $string = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($string)); |
@@ -4934,8 +5212,9 @@ discard block |
||
4934 | 5212 | $string = load_file($string); |
4935 | 5213 | |
4936 | 5214 | // Loaded file failed |
4937 | - if (empty($string)) |
|
4938 | - return false; |
|
5215 | + if (empty($string)) { |
|
5216 | + return false; |
|
5217 | + } |
|
4939 | 5218 | |
4940 | 5219 | // Found a method. |
4941 | 5220 | if (strpos($string, '::') !== false) |
@@ -4956,8 +5235,9 @@ discard block |
||
4956 | 5235 | // Add another one to the list. |
4957 | 5236 | if ($db_show_debug === true) |
4958 | 5237 | { |
4959 | - if (!isset($context['debug']['instances'])) |
|
4960 | - $context['debug']['instances'] = array(); |
|
5238 | + if (!isset($context['debug']['instances'])) { |
|
5239 | + $context['debug']['instances'] = array(); |
|
5240 | + } |
|
4961 | 5241 | |
4962 | 5242 | $context['debug']['instances'][$class] = $class; |
4963 | 5243 | } |
@@ -4967,13 +5247,15 @@ discard block |
||
4967 | 5247 | } |
4968 | 5248 | |
4969 | 5249 | // Right then. This is a call to a static method. |
4970 | - else |
|
4971 | - $func = array($class, $method); |
|
5250 | + else { |
|
5251 | + $func = array($class, $method); |
|
5252 | + } |
|
4972 | 5253 | } |
4973 | 5254 | |
4974 | 5255 | // Nope! just a plain regular function. |
4975 | - else |
|
4976 | - $func = $string; |
|
5256 | + else { |
|
5257 | + $func = $string; |
|
5258 | + } |
|
4977 | 5259 | |
4978 | 5260 | // Right, we got what we need, time to do some checks. |
4979 | 5261 | if (!is_callable($func, false, $callable_name)) |
@@ -4989,17 +5271,18 @@ discard block |
||
4989 | 5271 | else |
4990 | 5272 | { |
4991 | 5273 | // What are we gonna do about it? |
4992 | - if ($return) |
|
4993 | - return $func; |
|
5274 | + if ($return) { |
|
5275 | + return $func; |
|
5276 | + } |
|
4994 | 5277 | |
4995 | 5278 | // If this is a plain function, avoid the heat of calling call_user_func(). |
4996 | 5279 | else |
4997 | 5280 | { |
4998 | - if (is_array($func)) |
|
4999 | - call_user_func($func); |
|
5000 | - |
|
5001 | - else |
|
5002 | - $func(); |
|
5281 | + if (is_array($func)) { |
|
5282 | + call_user_func($func); |
|
5283 | + } else { |
|
5284 | + $func(); |
|
5285 | + } |
|
5003 | 5286 | } |
5004 | 5287 | } |
5005 | 5288 | } |
@@ -5016,31 +5299,34 @@ discard block |
||
5016 | 5299 | { |
5017 | 5300 | global $sourcedir, $txt, $boarddir, $settings; |
5018 | 5301 | |
5019 | - if (empty($string)) |
|
5020 | - return false; |
|
5302 | + if (empty($string)) { |
|
5303 | + return false; |
|
5304 | + } |
|
5021 | 5305 | |
5022 | 5306 | if (strpos($string, '|') !== false) |
5023 | 5307 | { |
5024 | 5308 | list ($file, $string) = explode('|', $string); |
5025 | 5309 | |
5026 | 5310 | // Match the wildcards to their regular vars. |
5027 | - if (empty($settings['theme_dir'])) |
|
5028 | - $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
|
5029 | - |
|
5030 | - else |
|
5031 | - $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
|
5311 | + if (empty($settings['theme_dir'])) { |
|
5312 | + $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
|
5313 | + } else { |
|
5314 | + $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
|
5315 | + } |
|
5032 | 5316 | |
5033 | 5317 | // Load the file if it can be loaded. |
5034 | - if (file_exists($absPath)) |
|
5035 | - require_once($absPath); |
|
5318 | + if (file_exists($absPath)) { |
|
5319 | + require_once($absPath); |
|
5320 | + } |
|
5036 | 5321 | |
5037 | 5322 | // No? try a fallback to $sourcedir |
5038 | 5323 | else |
5039 | 5324 | { |
5040 | 5325 | $absPath = $sourcedir .'/'. $file; |
5041 | 5326 | |
5042 | - if (file_exists($absPath)) |
|
5043 | - require_once($absPath); |
|
5327 | + if (file_exists($absPath)) { |
|
5328 | + require_once($absPath); |
|
5329 | + } |
|
5044 | 5330 | |
5045 | 5331 | // Sorry, can't do much for you at this point. |
5046 | 5332 | else |
@@ -5079,8 +5365,9 @@ discard block |
||
5079 | 5365 | preg_match('~^(http|ftp)(s)?://([^/:]+)(:(\d+))?(.+)$~', $url, $match); |
5080 | 5366 | |
5081 | 5367 | // No scheme? No data for you! |
5082 | - if (empty($match[1])) |
|
5083 | - return false; |
|
5368 | + if (empty($match[1])) { |
|
5369 | + return false; |
|
5370 | + } |
|
5084 | 5371 | |
5085 | 5372 | // An FTP url. We should try connecting and RETRieving it... |
5086 | 5373 | elseif ($match[1] == 'ftp') |
@@ -5090,23 +5377,26 @@ discard block |
||
5090 | 5377 | |
5091 | 5378 | // Establish a connection and attempt to enable passive mode. |
5092 | 5379 | $ftp = new ftp_connection(($match[2] ? 'ssl://' : '') . $match[3], empty($match[5]) ? 21 : $match[5], 'anonymous', $webmaster_email); |
5093 | - if ($ftp->error !== false || !$ftp->passive()) |
|
5094 | - return false; |
|
5380 | + if ($ftp->error !== false || !$ftp->passive()) { |
|
5381 | + return false; |
|
5382 | + } |
|
5095 | 5383 | |
5096 | 5384 | // I want that one *points*! |
5097 | 5385 | fwrite($ftp->connection, 'RETR ' . $match[6] . "\r\n"); |
5098 | 5386 | |
5099 | 5387 | // Since passive mode worked (or we would have returned already!) open the connection. |
5100 | 5388 | $fp = @fsockopen($ftp->pasv['ip'], $ftp->pasv['port'], $err, $err, 5); |
5101 | - if (!$fp) |
|
5102 | - return false; |
|
5389 | + if (!$fp) { |
|
5390 | + return false; |
|
5391 | + } |
|
5103 | 5392 | |
5104 | 5393 | // The server should now say something in acknowledgement. |
5105 | 5394 | $ftp->check_response(150); |
5106 | 5395 | |
5107 | 5396 | $data = ''; |
5108 | - while (!feof($fp)) |
|
5109 | - $data .= fread($fp, 4096); |
|
5397 | + while (!feof($fp)) { |
|
5398 | + $data .= fread($fp, 4096); |
|
5399 | + } |
|
5110 | 5400 | fclose($fp); |
5111 | 5401 | |
5112 | 5402 | // All done, right? Good. |
@@ -5118,8 +5408,9 @@ discard block |
||
5118 | 5408 | elseif (isset($match[1]) && $match[1] == 'http') |
5119 | 5409 | { |
5120 | 5410 | // First try to use fsockopen, because it is fastest. |
5121 | - if ($keep_alive && $match[3] == $keep_alive_dom) |
|
5122 | - $fp = $keep_alive_fp; |
|
5411 | + if ($keep_alive && $match[3] == $keep_alive_dom) { |
|
5412 | + $fp = $keep_alive_fp; |
|
5413 | + } |
|
5123 | 5414 | if (empty($fp)) |
5124 | 5415 | { |
5125 | 5416 | // Open the socket on the port we want... |
@@ -5139,20 +5430,21 @@ discard block |
||
5139 | 5430 | fwrite($fp, 'GET ' . ($match[6] !== '/' ? str_replace(' ', '%20', $match[6]) : '') . ' HTTP/1.0' . "\r\n"); |
5140 | 5431 | fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n"); |
5141 | 5432 | fwrite($fp, 'user-agent: PHP/SMF' . "\r\n"); |
5142 | - if ($keep_alive) |
|
5143 | - fwrite($fp, 'connection: Keep-Alive' . "\r\n\r\n"); |
|
5144 | - else |
|
5145 | - fwrite($fp, 'connection: close' . "\r\n\r\n"); |
|
5146 | - } |
|
5147 | - else |
|
5433 | + if ($keep_alive) { |
|
5434 | + fwrite($fp, 'connection: Keep-Alive' . "\r\n\r\n"); |
|
5435 | + } else { |
|
5436 | + fwrite($fp, 'connection: close' . "\r\n\r\n"); |
|
5437 | + } |
|
5438 | + } else |
|
5148 | 5439 | { |
5149 | 5440 | fwrite($fp, 'POST ' . ($match[6] !== '/' ? $match[6] : '') . ' HTTP/1.0' . "\r\n"); |
5150 | 5441 | fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n"); |
5151 | 5442 | fwrite($fp, 'user-agent: PHP/SMF' . "\r\n"); |
5152 | - if ($keep_alive) |
|
5153 | - fwrite($fp, 'connection: Keep-Alive' . "\r\n"); |
|
5154 | - else |
|
5155 | - fwrite($fp, 'connection: close' . "\r\n"); |
|
5443 | + if ($keep_alive) { |
|
5444 | + fwrite($fp, 'connection: Keep-Alive' . "\r\n"); |
|
5445 | + } else { |
|
5446 | + fwrite($fp, 'connection: close' . "\r\n"); |
|
5447 | + } |
|
5156 | 5448 | fwrite($fp, 'content-type: application/x-www-form-urlencoded' . "\r\n"); |
5157 | 5449 | fwrite($fp, 'content-length: ' . strlen($post_data) . "\r\n\r\n"); |
5158 | 5450 | fwrite($fp, $post_data); |
@@ -5165,30 +5457,33 @@ discard block |
||
5165 | 5457 | { |
5166 | 5458 | $header = ''; |
5167 | 5459 | $location = ''; |
5168 | - while (!feof($fp) && trim($header = fgets($fp, 4096)) != '') |
|
5169 | - if (strpos($header, 'location:') !== false) |
|
5460 | + while (!feof($fp) && trim($header = fgets($fp, 4096)) != '') { |
|
5461 | + if (strpos($header, 'location:') !== false) |
|
5170 | 5462 | $location = trim(substr($header, strpos($header, ':') + 1)); |
5463 | + } |
|
5171 | 5464 | |
5172 | - if (empty($location)) |
|
5173 | - return false; |
|
5174 | - else |
|
5465 | + if (empty($location)) { |
|
5466 | + return false; |
|
5467 | + } else |
|
5175 | 5468 | { |
5176 | - if (!$keep_alive) |
|
5177 | - fclose($fp); |
|
5469 | + if (!$keep_alive) { |
|
5470 | + fclose($fp); |
|
5471 | + } |
|
5178 | 5472 | return fetch_web_data($location, $post_data, $keep_alive, $redirection_level + 1); |
5179 | 5473 | } |
5180 | 5474 | } |
5181 | 5475 | |
5182 | 5476 | // Make sure we get a 200 OK. |
5183 | - elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0) |
|
5184 | - return false; |
|
5477 | + elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0) { |
|
5478 | + return false; |
|
5479 | + } |
|
5185 | 5480 | |
5186 | 5481 | // Skip the headers... |
5187 | 5482 | while (!feof($fp) && trim($header = fgets($fp, 4096)) != '') |
5188 | 5483 | { |
5189 | - if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0) |
|
5190 | - $content_length = $match[1]; |
|
5191 | - elseif (preg_match('~connection:\s*close~i', $header) != 0) |
|
5484 | + if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0) { |
|
5485 | + $content_length = $match[1]; |
|
5486 | + } elseif (preg_match('~connection:\s*close~i', $header) != 0) |
|
5192 | 5487 | { |
5193 | 5488 | $keep_alive_dom = null; |
5194 | 5489 | $keep_alive = false; |
@@ -5200,17 +5495,19 @@ discard block |
||
5200 | 5495 | $data = ''; |
5201 | 5496 | if (isset($content_length)) |
5202 | 5497 | { |
5203 | - while (!feof($fp) && strlen($data) < $content_length) |
|
5204 | - $data .= fread($fp, $content_length - strlen($data)); |
|
5205 | - } |
|
5206 | - else |
|
5498 | + while (!feof($fp) && strlen($data) < $content_length) { |
|
5499 | + $data .= fread($fp, $content_length - strlen($data)); |
|
5500 | + } |
|
5501 | + } else |
|
5207 | 5502 | { |
5208 | - while (!feof($fp)) |
|
5209 | - $data .= fread($fp, 4096); |
|
5503 | + while (!feof($fp)) { |
|
5504 | + $data .= fread($fp, 4096); |
|
5505 | + } |
|
5210 | 5506 | } |
5211 | 5507 | |
5212 | - if (!$keep_alive) |
|
5213 | - fclose($fp); |
|
5508 | + if (!$keep_alive) { |
|
5509 | + fclose($fp); |
|
5510 | + } |
|
5214 | 5511 | } |
5215 | 5512 | |
5216 | 5513 | // If using fsockopen didn't work, try to use cURL if available. |
@@ -5223,17 +5520,18 @@ discard block |
||
5223 | 5520 | $fetch_data->get_url_data($url, $post_data); |
5224 | 5521 | |
5225 | 5522 | // no errors and a 200 result, then we have a good dataset, well we at least have data. ;) |
5226 | - if ($fetch_data->result('code') == 200 && !$fetch_data->result('error')) |
|
5227 | - $data = $fetch_data->result('body'); |
|
5228 | - else |
|
5229 | - return false; |
|
5523 | + if ($fetch_data->result('code') == 200 && !$fetch_data->result('error')) { |
|
5524 | + $data = $fetch_data->result('body'); |
|
5525 | + } else { |
|
5526 | + return false; |
|
5527 | + } |
|
5230 | 5528 | } |
5231 | 5529 | |
5232 | 5530 | // Neither fsockopen nor curl are available. Well, phooey. |
5233 | - else |
|
5234 | - return false; |
|
5235 | - } |
|
5236 | - else |
|
5531 | + else { |
|
5532 | + return false; |
|
5533 | + } |
|
5534 | + } else |
|
5237 | 5535 | { |
5238 | 5536 | // Umm, this shouldn't happen? |
5239 | 5537 | trigger_error('fetch_web_data(): Bad URL', E_USER_NOTICE); |
@@ -5253,8 +5551,9 @@ discard block |
||
5253 | 5551 | global $user_info, $smcFunc; |
5254 | 5552 | |
5255 | 5553 | // Make sure we have something to work with. |
5256 | - if (empty($topic)) |
|
5257 | - return array(); |
|
5554 | + if (empty($topic)) { |
|
5555 | + return array(); |
|
5556 | + } |
|
5258 | 5557 | |
5259 | 5558 | |
5260 | 5559 | // We already know the number of likes per message, we just want to know whether the current user liked it or not. |
@@ -5277,8 +5576,9 @@ discard block |
||
5277 | 5576 | 'topic' => $topic, |
5278 | 5577 | ) |
5279 | 5578 | ); |
5280 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
5281 | - $temp[] = (int) $row['content_id']; |
|
5579 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
5580 | + $temp[] = (int) $row['content_id']; |
|
5581 | + } |
|
5282 | 5582 | |
5283 | 5583 | cache_put_data($cache_key, $temp, $ttl); |
5284 | 5584 | } |
@@ -5299,8 +5599,9 @@ discard block |
||
5299 | 5599 | { |
5300 | 5600 | global $context; |
5301 | 5601 | |
5302 | - if (empty($string)) |
|
5303 | - return $string; |
|
5602 | + if (empty($string)) { |
|
5603 | + return $string; |
|
5604 | + } |
|
5304 | 5605 | |
5305 | 5606 | // UTF-8 occurences of MS special characters |
5306 | 5607 | $findchars_utf8 = array( |
@@ -5341,10 +5642,11 @@ discard block |
||
5341 | 5642 | '--', // — |
5342 | 5643 | ); |
5343 | 5644 | |
5344 | - if ($context['utf8']) |
|
5345 | - $string = str_replace($findchars_utf8, $replacechars, $string); |
|
5346 | - else |
|
5347 | - $string = str_replace($findchars_iso, $replacechars, $string); |
|
5645 | + if ($context['utf8']) { |
|
5646 | + $string = str_replace($findchars_utf8, $replacechars, $string); |
|
5647 | + } else { |
|
5648 | + $string = str_replace($findchars_iso, $replacechars, $string); |
|
5649 | + } |
|
5348 | 5650 | |
5349 | 5651 | return $string; |
5350 | 5652 | } |
@@ -5363,49 +5665,59 @@ discard block |
||
5363 | 5665 | { |
5364 | 5666 | global $context; |
5365 | 5667 | |
5366 | - if (!isset($matches[2])) |
|
5367 | - return ''; |
|
5668 | + if (!isset($matches[2])) { |
|
5669 | + return ''; |
|
5670 | + } |
|
5368 | 5671 | |
5369 | 5672 | $num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2]; |
5370 | 5673 | |
5371 | 5674 | // remove left to right / right to left overrides |
5372 | - if ($num === 0x202D || $num === 0x202E) |
|
5373 | - return ''; |
|
5675 | + if ($num === 0x202D || $num === 0x202E) { |
|
5676 | + return ''; |
|
5677 | + } |
|
5374 | 5678 | |
5375 | 5679 | // Quote, Ampersand, Apostrophe, Less/Greater Than get html replaced |
5376 | - if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) |
|
5377 | - return '&#' . $num . ';'; |
|
5680 | + if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) { |
|
5681 | + return '&#' . $num . ';'; |
|
5682 | + } |
|
5378 | 5683 | |
5379 | 5684 | if (empty($context['utf8'])) |
5380 | 5685 | { |
5381 | 5686 | // no control characters |
5382 | - if ($num < 0x20) |
|
5383 | - return ''; |
|
5687 | + if ($num < 0x20) { |
|
5688 | + return ''; |
|
5689 | + } |
|
5384 | 5690 | // text is text |
5385 | - elseif ($num < 0x80) |
|
5386 | - return chr($num); |
|
5691 | + elseif ($num < 0x80) { |
|
5692 | + return chr($num); |
|
5693 | + } |
|
5387 | 5694 | // all others get html-ised |
5388 | - else |
|
5389 | - return '&#' . $matches[2] . ';'; |
|
5390 | - } |
|
5391 | - else |
|
5695 | + else { |
|
5696 | + return '&#' . $matches[2] . ';'; |
|
5697 | + } |
|
5698 | + } else |
|
5392 | 5699 | { |
5393 | 5700 | // <0x20 are control characters, 0x20 is a space, > 0x10FFFF is past the end of the utf8 character set |
5394 | 5701 | // 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text) |
5395 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) |
|
5396 | - return ''; |
|
5702 | + if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) { |
|
5703 | + return ''; |
|
5704 | + } |
|
5397 | 5705 | // <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation |
5398 | - elseif ($num < 0x80) |
|
5399 | - return chr($num); |
|
5706 | + elseif ($num < 0x80) { |
|
5707 | + return chr($num); |
|
5708 | + } |
|
5400 | 5709 | // <0x800 (2048) |
5401 | - elseif ($num < 0x800) |
|
5402 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
5710 | + elseif ($num < 0x800) { |
|
5711 | + return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
5712 | + } |
|
5403 | 5713 | // < 0x10000 (65536) |
5404 | - elseif ($num < 0x10000) |
|
5405 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5714 | + elseif ($num < 0x10000) { |
|
5715 | + return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5716 | + } |
|
5406 | 5717 | // <= 0x10FFFF (1114111) |
5407 | - else |
|
5408 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5718 | + else { |
|
5719 | + return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5720 | + } |
|
5409 | 5721 | } |
5410 | 5722 | } |
5411 | 5723 | |
@@ -5421,28 +5733,34 @@ discard block |
||
5421 | 5733 | */ |
5422 | 5734 | function fixchar__callback($matches) |
5423 | 5735 | { |
5424 | - if (!isset($matches[1])) |
|
5425 | - return ''; |
|
5736 | + if (!isset($matches[1])) { |
|
5737 | + return ''; |
|
5738 | + } |
|
5426 | 5739 | |
5427 | 5740 | $num = $matches[1][0] === 'x' ? hexdec(substr($matches[1], 1)) : (int) $matches[1]; |
5428 | 5741 | |
5429 | 5742 | // <0x20 are control characters, > 0x10FFFF is past the end of the utf8 character set |
5430 | 5743 | // 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text), 0x202D-E are left to right overrides |
5431 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) |
|
5432 | - return ''; |
|
5744 | + if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) { |
|
5745 | + return ''; |
|
5746 | + } |
|
5433 | 5747 | // <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation |
5434 | - elseif ($num < 0x80) |
|
5435 | - return chr($num); |
|
5748 | + elseif ($num < 0x80) { |
|
5749 | + return chr($num); |
|
5750 | + } |
|
5436 | 5751 | // <0x800 (2048) |
5437 | - elseif ($num < 0x800) |
|
5438 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
5752 | + elseif ($num < 0x800) { |
|
5753 | + return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
5754 | + } |
|
5439 | 5755 | // < 0x10000 (65536) |
5440 | - elseif ($num < 0x10000) |
|
5441 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5756 | + elseif ($num < 0x10000) { |
|
5757 | + return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5758 | + } |
|
5442 | 5759 | // <= 0x10FFFF (1114111) |
5443 | - else |
|
5444 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5445 | -} |
|
5760 | + else { |
|
5761 | + return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5762 | + } |
|
5763 | + } |
|
5446 | 5764 | |
5447 | 5765 | /** |
5448 | 5766 | * Strips out invalid html entities, replaces others with html style { codes |
@@ -5455,17 +5773,19 @@ discard block |
||
5455 | 5773 | */ |
5456 | 5774 | function entity_fix__callback($matches) |
5457 | 5775 | { |
5458 | - if (!isset($matches[2])) |
|
5459 | - return ''; |
|
5776 | + if (!isset($matches[2])) { |
|
5777 | + return ''; |
|
5778 | + } |
|
5460 | 5779 | |
5461 | 5780 | $num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2]; |
5462 | 5781 | |
5463 | 5782 | // we don't allow control characters, characters out of range, byte markers, etc |
5464 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) |
|
5465 | - return ''; |
|
5466 | - else |
|
5467 | - return '&#' . $num . ';'; |
|
5468 | -} |
|
5783 | + if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) { |
|
5784 | + return ''; |
|
5785 | + } else { |
|
5786 | + return '&#' . $num . ';'; |
|
5787 | + } |
|
5788 | + } |
|
5469 | 5789 | |
5470 | 5790 | /** |
5471 | 5791 | * Return a Gravatar URL based on |
@@ -5489,18 +5809,23 @@ discard block |
||
5489 | 5809 | $ratings = array('G', 'PG', 'R', 'X'); |
5490 | 5810 | $defaults = array('mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank'); |
5491 | 5811 | $url_params = array(); |
5492 | - if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) |
|
5493 | - $url_params[] = 'rating=' . $modSettings['gravatarMaxRating']; |
|
5494 | - if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) |
|
5495 | - $url_params[] = 'default=' . $modSettings['gravatarDefault']; |
|
5496 | - if (!empty($modSettings['avatar_max_width_external'])) |
|
5497 | - $size_string = (int) $modSettings['avatar_max_width_external']; |
|
5498 | - if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) |
|
5499 | - if ((int) $modSettings['avatar_max_height_external'] < $size_string) |
|
5812 | + if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) { |
|
5813 | + $url_params[] = 'rating=' . $modSettings['gravatarMaxRating']; |
|
5814 | + } |
|
5815 | + if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) { |
|
5816 | + $url_params[] = 'default=' . $modSettings['gravatarDefault']; |
|
5817 | + } |
|
5818 | + if (!empty($modSettings['avatar_max_width_external'])) { |
|
5819 | + $size_string = (int) $modSettings['avatar_max_width_external']; |
|
5820 | + } |
|
5821 | + if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) { |
|
5822 | + if ((int) $modSettings['avatar_max_height_external'] < $size_string) |
|
5500 | 5823 | $size_string = $modSettings['avatar_max_height_external']; |
5824 | + } |
|
5501 | 5825 | |
5502 | - if (!empty($size_string)) |
|
5503 | - $url_params[] = 's=' . $size_string; |
|
5826 | + if (!empty($size_string)) { |
|
5827 | + $url_params[] = 's=' . $size_string; |
|
5828 | + } |
|
5504 | 5829 | } |
5505 | 5830 | $http_method = !empty($modSettings['force_ssl']) ? 'https://secure' : 'http://www'; |
5506 | 5831 | |
@@ -5519,22 +5844,26 @@ discard block |
||
5519 | 5844 | static $timezones = null, $lastwhen = null; |
5520 | 5845 | |
5521 | 5846 | // No point doing this over if we already did it once |
5522 | - if (!empty($timezones) && $when == $lastwhen) |
|
5523 | - return $timezones; |
|
5524 | - else |
|
5525 | - $lastwhen = $when; |
|
5847 | + if (!empty($timezones) && $when == $lastwhen) { |
|
5848 | + return $timezones; |
|
5849 | + } else { |
|
5850 | + $lastwhen = $when; |
|
5851 | + } |
|
5526 | 5852 | |
5527 | 5853 | // Parseable datetime string? |
5528 | - if (is_int($timestamp = strtotime($when))) |
|
5529 | - $when = $timestamp; |
|
5854 | + if (is_int($timestamp = strtotime($when))) { |
|
5855 | + $when = $timestamp; |
|
5856 | + } |
|
5530 | 5857 | |
5531 | 5858 | // A Unix timestamp? |
5532 | - elseif (is_numeric($when)) |
|
5533 | - $when = intval($when); |
|
5859 | + elseif (is_numeric($when)) { |
|
5860 | + $when = intval($when); |
|
5861 | + } |
|
5534 | 5862 | |
5535 | 5863 | // Invalid value? Just get current Unix timestamp. |
5536 | - else |
|
5537 | - $when = time(); |
|
5864 | + else { |
|
5865 | + $when = time(); |
|
5866 | + } |
|
5538 | 5867 | |
5539 | 5868 | // We'll need these too |
5540 | 5869 | $date_when = date_create('@' . $when); |
@@ -5549,8 +5878,9 @@ discard block |
||
5549 | 5878 | foreach ($priority_countries as $country) |
5550 | 5879 | { |
5551 | 5880 | $country_tzids = @timezone_identifiers_list(DateTimeZone::PER_COUNTRY, strtoupper(trim($country))); |
5552 | - if (!empty($country_tzids)) |
|
5553 | - $priority_tzids = array_merge($priority_tzids, $country_tzids); |
|
5881 | + if (!empty($country_tzids)) { |
|
5882 | + $priority_tzids = array_merge($priority_tzids, $country_tzids); |
|
5883 | + } |
|
5554 | 5884 | } |
5555 | 5885 | |
5556 | 5886 | // Antarctic research stations should be listed last, unless you're running a penguin forum |
@@ -5564,8 +5894,9 @@ discard block |
||
5564 | 5894 | foreach ($tzids as $tzid) |
5565 | 5895 | { |
5566 | 5896 | // We don't want UTC right now |
5567 | - if ($tzid == 'UTC') |
|
5568 | - continue; |
|
5897 | + if ($tzid == 'UTC') { |
|
5898 | + continue; |
|
5899 | + } |
|
5569 | 5900 | |
5570 | 5901 | $tz = timezone_open($tzid); |
5571 | 5902 | |
@@ -5586,13 +5917,14 @@ discard block |
||
5586 | 5917 | } |
5587 | 5918 | |
5588 | 5919 | // A time zone from a prioritized country? |
5589 | - if (in_array($tzid, $priority_tzids)) |
|
5590 | - $priority_zones[$tzkey] = true; |
|
5920 | + if (in_array($tzid, $priority_tzids)) { |
|
5921 | + $priority_zones[$tzkey] = true; |
|
5922 | + } |
|
5591 | 5923 | |
5592 | 5924 | // Keep track of the location and offset for this tzid |
5593 | - if (!empty($txt[$tzid])) |
|
5594 | - $zones[$tzkey]['locations'][] = $txt[$tzid]; |
|
5595 | - else |
|
5925 | + if (!empty($txt[$tzid])) { |
|
5926 | + $zones[$tzkey]['locations'][] = $txt[$tzid]; |
|
5927 | + } else |
|
5596 | 5928 | { |
5597 | 5929 | $tzid_parts = explode('/', $tzid); |
5598 | 5930 | $zones[$tzkey]['locations'][] = str_replace(array('St_', '_'), array('St. ', ' '), array_pop($tzid_parts)); |
@@ -5612,23 +5944,27 @@ discard block |
||
5612 | 5944 | date_timezone_set($date_when, timezone_open($tzvalue['tzid'])); |
5613 | 5945 | |
5614 | 5946 | // Use the custom description, if there is one |
5615 | - if (!empty($tztxt[$tzvalue['tzid']])) |
|
5616 | - $desc = $tztxt[$tzvalue['tzid']]; |
|
5947 | + if (!empty($tztxt[$tzvalue['tzid']])) { |
|
5948 | + $desc = $tztxt[$tzvalue['tzid']]; |
|
5949 | + } |
|
5617 | 5950 | // Otherwise, use the list of locations (max 5, so things don't get silly) |
5618 | - else |
|
5619 | - $desc = implode(', ', array_slice(array_unique($tzvalue['locations']), 0, 5)) . (count($tzvalue['locations']) > 5 ? ', ' . $txt['etc'] : ''); |
|
5951 | + else { |
|
5952 | + $desc = implode(', ', array_slice(array_unique($tzvalue['locations']), 0, 5)) . (count($tzvalue['locations']) > 5 ? ', ' . $txt['etc'] : ''); |
|
5953 | + } |
|
5620 | 5954 | |
5621 | 5955 | // Show the UTC offset and the abbreviation, if it's something like 'MST' and not '-06' |
5622 | 5956 | $desc = '[UTC' . date_format($date_when, 'P') . '] - ' . (!strspn($tzvalue['abbr'], '+-') ? $tzvalue['abbr'] . ' - ' : '') . $desc; |
5623 | 5957 | |
5624 | - if (isset($priority_zones[$tzkey])) |
|
5625 | - $priority_timezones[$tzvalue['tzid']] = $desc; |
|
5626 | - else |
|
5627 | - $timezones[$tzvalue['tzid']] = $desc; |
|
5958 | + if (isset($priority_zones[$tzkey])) { |
|
5959 | + $priority_timezones[$tzvalue['tzid']] = $desc; |
|
5960 | + } else { |
|
5961 | + $timezones[$tzvalue['tzid']] = $desc; |
|
5962 | + } |
|
5628 | 5963 | } |
5629 | 5964 | |
5630 | - if (!empty($priority_timezones)) |
|
5631 | - $priority_timezones[] = '-----'; |
|
5965 | + if (!empty($priority_timezones)) { |
|
5966 | + $priority_timezones[] = '-----'; |
|
5967 | + } |
|
5632 | 5968 | |
5633 | 5969 | $timezones = array_merge( |
5634 | 5970 | $priority_timezones, |
@@ -5645,8 +5981,9 @@ discard block |
||
5645 | 5981 | */ |
5646 | 5982 | function inet_ptod($ip_address) |
5647 | 5983 | { |
5648 | - if (!isValidIP($ip_address)) |
|
5649 | - return $ip_address; |
|
5984 | + if (!isValidIP($ip_address)) { |
|
5985 | + return $ip_address; |
|
5986 | + } |
|
5650 | 5987 | |
5651 | 5988 | $bin = inet_pton($ip_address); |
5652 | 5989 | return $bin; |
@@ -5658,13 +5995,15 @@ discard block |
||
5658 | 5995 | */ |
5659 | 5996 | function inet_dtop($bin) |
5660 | 5997 | { |
5661 | - if(empty($bin)) |
|
5662 | - return ''; |
|
5998 | + if(empty($bin)) { |
|
5999 | + return ''; |
|
6000 | + } |
|
5663 | 6001 | |
5664 | 6002 | global $db_type; |
5665 | 6003 | |
5666 | - if ($db_type == 'postgresql') |
|
5667 | - return $bin; |
|
6004 | + if ($db_type == 'postgresql') { |
|
6005 | + return $bin; |
|
6006 | + } |
|
5668 | 6007 | |
5669 | 6008 | $ip_address = inet_ntop($bin); |
5670 | 6009 | |
@@ -5689,26 +6028,32 @@ discard block |
||
5689 | 6028 | */ |
5690 | 6029 | function _safe_serialize($value) |
5691 | 6030 | { |
5692 | - if(is_null($value)) |
|
5693 | - return 'N;'; |
|
6031 | + if(is_null($value)) { |
|
6032 | + return 'N;'; |
|
6033 | + } |
|
5694 | 6034 | |
5695 | - if(is_bool($value)) |
|
5696 | - return 'b:'. (int) $value .';'; |
|
6035 | + if(is_bool($value)) { |
|
6036 | + return 'b:'. (int) $value .';'; |
|
6037 | + } |
|
5697 | 6038 | |
5698 | - if(is_int($value)) |
|
5699 | - return 'i:'. $value .';'; |
|
6039 | + if(is_int($value)) { |
|
6040 | + return 'i:'. $value .';'; |
|
6041 | + } |
|
5700 | 6042 | |
5701 | - if(is_float($value)) |
|
5702 | - return 'd:'. str_replace(',', '.', $value) .';'; |
|
6043 | + if(is_float($value)) { |
|
6044 | + return 'd:'. str_replace(',', '.', $value) .';'; |
|
6045 | + } |
|
5703 | 6046 | |
5704 | - if(is_string($value)) |
|
5705 | - return 's:'. strlen($value) .':"'. $value .'";'; |
|
6047 | + if(is_string($value)) { |
|
6048 | + return 's:'. strlen($value) .':"'. $value .'";'; |
|
6049 | + } |
|
5706 | 6050 | |
5707 | 6051 | if(is_array($value)) |
5708 | 6052 | { |
5709 | 6053 | $out = ''; |
5710 | - foreach($value as $k => $v) |
|
5711 | - $out .= _safe_serialize($k) . _safe_serialize($v); |
|
6054 | + foreach($value as $k => $v) { |
|
6055 | + $out .= _safe_serialize($k) . _safe_serialize($v); |
|
6056 | + } |
|
5712 | 6057 | |
5713 | 6058 | return 'a:'. count($value) .':{'. $out .'}'; |
5714 | 6059 | } |
@@ -5734,8 +6079,9 @@ discard block |
||
5734 | 6079 | |
5735 | 6080 | $out = _safe_serialize($value); |
5736 | 6081 | |
5737 | - if (isset($mbIntEnc)) |
|
5738 | - mb_internal_encoding($mbIntEnc); |
|
6082 | + if (isset($mbIntEnc)) { |
|
6083 | + mb_internal_encoding($mbIntEnc); |
|
6084 | + } |
|
5739 | 6085 | |
5740 | 6086 | return $out; |
5741 | 6087 | } |
@@ -5752,8 +6098,9 @@ discard block |
||
5752 | 6098 | function _safe_unserialize($str) |
5753 | 6099 | { |
5754 | 6100 | // Input is not a string. |
5755 | - if(empty($str) || !is_string($str)) |
|
5756 | - return false; |
|
6101 | + if(empty($str) || !is_string($str)) { |
|
6102 | + return false; |
|
6103 | + } |
|
5757 | 6104 | |
5758 | 6105 | $stack = array(); |
5759 | 6106 | $expected = array(); |
@@ -5769,43 +6116,38 @@ discard block |
||
5769 | 6116 | while($state != 1) |
5770 | 6117 | { |
5771 | 6118 | $type = isset($str[0]) ? $str[0] : ''; |
5772 | - if($type == '}') |
|
5773 | - $str = substr($str, 1); |
|
5774 | - |
|
5775 | - else if($type == 'N' && $str[1] == ';') |
|
6119 | + if($type == '}') { |
|
6120 | + $str = substr($str, 1); |
|
6121 | + } else if($type == 'N' && $str[1] == ';') |
|
5776 | 6122 | { |
5777 | 6123 | $value = null; |
5778 | 6124 | $str = substr($str, 2); |
5779 | - } |
|
5780 | - else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches)) |
|
6125 | + } else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches)) |
|
5781 | 6126 | { |
5782 | 6127 | $value = $matches[1] == '1' ? true : false; |
5783 | 6128 | $str = substr($str, 4); |
5784 | - } |
|
5785 | - else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches)) |
|
6129 | + } else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches)) |
|
5786 | 6130 | { |
5787 | 6131 | $value = (int)$matches[1]; |
5788 | 6132 | $str = $matches[2]; |
5789 | - } |
|
5790 | - else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches)) |
|
6133 | + } else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches)) |
|
5791 | 6134 | { |
5792 | 6135 | $value = (float)$matches[1]; |
5793 | 6136 | $str = $matches[3]; |
5794 | - } |
|
5795 | - else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";') |
|
6137 | + } else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";') |
|
5796 | 6138 | { |
5797 | 6139 | $value = substr($matches[2], 0, (int)$matches[1]); |
5798 | 6140 | $str = substr($matches[2], (int)$matches[1] + 2); |
5799 | - } |
|
5800 | - else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches)) |
|
6141 | + } else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches)) |
|
5801 | 6142 | { |
5802 | 6143 | $expectedLength = (int)$matches[1]; |
5803 | 6144 | $str = $matches[2]; |
5804 | 6145 | } |
5805 | 6146 | |
5806 | 6147 | // Object or unknown/malformed type. |
5807 | - else |
|
5808 | - return false; |
|
6148 | + else { |
|
6149 | + return false; |
|
6150 | + } |
|
5809 | 6151 | |
5810 | 6152 | switch($state) |
5811 | 6153 | { |
@@ -5833,8 +6175,9 @@ discard block |
||
5833 | 6175 | if($type == '}') |
5834 | 6176 | { |
5835 | 6177 | // Array size is less than expected. |
5836 | - if(count($list) < end($expected)) |
|
5837 | - return false; |
|
6178 | + if(count($list) < end($expected)) { |
|
6179 | + return false; |
|
6180 | + } |
|
5838 | 6181 | |
5839 | 6182 | unset($list); |
5840 | 6183 | $list = &$stack[count($stack)-1]; |
@@ -5843,8 +6186,9 @@ discard block |
||
5843 | 6186 | // Go to terminal state if we're at the end of the root array. |
5844 | 6187 | array_pop($expected); |
5845 | 6188 | |
5846 | - if(count($expected) == 0) |
|
5847 | - $state = 1; |
|
6189 | + if(count($expected) == 0) { |
|
6190 | + $state = 1; |
|
6191 | + } |
|
5848 | 6192 | |
5849 | 6193 | break; |
5850 | 6194 | } |
@@ -5852,8 +6196,9 @@ discard block |
||
5852 | 6196 | if($type == 'i' || $type == 's') |
5853 | 6197 | { |
5854 | 6198 | // Array size exceeds expected length. |
5855 | - if(count($list) >= end($expected)) |
|
5856 | - return false; |
|
6199 | + if(count($list) >= end($expected)) { |
|
6200 | + return false; |
|
6201 | + } |
|
5857 | 6202 | |
5858 | 6203 | $key = $value; |
5859 | 6204 | $state = 3; |
@@ -5887,8 +6232,9 @@ discard block |
||
5887 | 6232 | } |
5888 | 6233 | |
5889 | 6234 | // Trailing data in input. |
5890 | - if(!empty($str)) |
|
5891 | - return false; |
|
6235 | + if(!empty($str)) { |
|
6236 | + return false; |
|
6237 | + } |
|
5892 | 6238 | |
5893 | 6239 | return $data; |
5894 | 6240 | } |
@@ -5911,8 +6257,9 @@ discard block |
||
5911 | 6257 | |
5912 | 6258 | $out = _safe_unserialize($str); |
5913 | 6259 | |
5914 | - if (isset($mbIntEnc)) |
|
5915 | - mb_internal_encoding($mbIntEnc); |
|
6260 | + if (isset($mbIntEnc)) { |
|
6261 | + mb_internal_encoding($mbIntEnc); |
|
6262 | + } |
|
5916 | 6263 | |
5917 | 6264 | return $out; |
5918 | 6265 | } |
@@ -5927,12 +6274,14 @@ discard block |
||
5927 | 6274 | function smf_chmod($file, $value = 0) |
5928 | 6275 | { |
5929 | 6276 | // No file? no checks! |
5930 | - if (empty($file)) |
|
5931 | - return false; |
|
6277 | + if (empty($file)) { |
|
6278 | + return false; |
|
6279 | + } |
|
5932 | 6280 | |
5933 | 6281 | // Already writable? |
5934 | - if (is_writable($file)) |
|
5935 | - return true; |
|
6282 | + if (is_writable($file)) { |
|
6283 | + return true; |
|
6284 | + } |
|
5936 | 6285 | |
5937 | 6286 | // Do we have a file or a dir? |
5938 | 6287 | $isDir = is_dir($file); |
@@ -5948,10 +6297,9 @@ discard block |
||
5948 | 6297 | { |
5949 | 6298 | $isWritable = true; |
5950 | 6299 | break; |
6300 | + } else { |
|
6301 | + @chmod($file, $val); |
|
5951 | 6302 | } |
5952 | - |
|
5953 | - else |
|
5954 | - @chmod($file, $val); |
|
5955 | 6303 | } |
5956 | 6304 | |
5957 | 6305 | return $isWritable; |
@@ -5970,8 +6318,9 @@ discard block |
||
5970 | 6318 | global $txt; |
5971 | 6319 | |
5972 | 6320 | // Come on... |
5973 | - if (empty($json) || !is_string($json)) |
|
5974 | - return array(); |
|
6321 | + if (empty($json) || !is_string($json)) { |
|
6322 | + return array(); |
|
6323 | + } |
|
5975 | 6324 | |
5976 | 6325 | $returnArray = @json_decode($json, $returnAsArray); |
5977 | 6326 | |
@@ -6009,11 +6358,11 @@ discard block |
||
6009 | 6358 | $jsonDebug = $jsonDebug[0]; |
6010 | 6359 | loadLanguage('Errors'); |
6011 | 6360 | |
6012 | - if (!empty($jsonDebug)) |
|
6013 | - log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']); |
|
6014 | - |
|
6015 | - else |
|
6016 | - log_error($txt['json_'. $jsonError], 'critical'); |
|
6361 | + if (!empty($jsonDebug)) { |
|
6362 | + log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']); |
|
6363 | + } else { |
|
6364 | + log_error($txt['json_'. $jsonError], 'critical'); |
|
6365 | + } |
|
6017 | 6366 | |
6018 | 6367 | // Everyone expects an array. |
6019 | 6368 | return array(); |
@@ -6047,8 +6396,9 @@ discard block |
||
6047 | 6396 | global $db_show_debug, $modSettings; |
6048 | 6397 | |
6049 | 6398 | // Defensive programming anyone? |
6050 | - if (empty($data)) |
|
6051 | - return false; |
|
6399 | + if (empty($data)) { |
|
6400 | + return false; |
|
6401 | + } |
|
6052 | 6402 | |
6053 | 6403 | // Don't need extra stuff... |
6054 | 6404 | $db_show_debug = false; |
@@ -6056,11 +6406,11 @@ discard block |
||
6056 | 6406 | // Kill anything else. |
6057 | 6407 | ob_end_clean(); |
6058 | 6408 | |
6059 | - if (!empty($modSettings['CompressedOutput'])) |
|
6060 | - @ob_start('ob_gzhandler'); |
|
6061 | - |
|
6062 | - else |
|
6063 | - ob_start(); |
|
6409 | + if (!empty($modSettings['CompressedOutput'])) { |
|
6410 | + @ob_start('ob_gzhandler'); |
|
6411 | + } else { |
|
6412 | + ob_start(); |
|
6413 | + } |
|
6064 | 6414 | |
6065 | 6415 | // Set the header. |
6066 | 6416 | header($type); |
@@ -6092,8 +6442,9 @@ discard block |
||
6092 | 6442 | static $done = false; |
6093 | 6443 | |
6094 | 6444 | // If we don't need to do anything, don't |
6095 | - if (!$update && $done) |
|
6096 | - return; |
|
6445 | + if (!$update && $done) { |
|
6446 | + return; |
|
6447 | + } |
|
6097 | 6448 | |
6098 | 6449 | // Should we get a new copy of the official list of TLDs? |
6099 | 6450 | if ($update) |
@@ -6105,8 +6456,9 @@ discard block |
||
6105 | 6456 | // marauding bandits roaming on the surface. We don't want to waste precious electricity on |
6106 | 6457 | // pointlessly repeating background tasks, so we'll wait until the next regularly scheduled |
6107 | 6458 | // update to see if civilization has been restored. |
6108 | - if ($tlds === false) |
|
6109 | - $postapocalypticNightmare = true; |
|
6459 | + if ($tlds === false) { |
|
6460 | + $postapocalypticNightmare = true; |
|
6461 | + } |
|
6110 | 6462 | } |
6111 | 6463 | // If we aren't updating and the regex is valid, we're done |
6112 | 6464 | elseif (!empty($modSettings['tld_regex']) && @preg_match('~' . $modSettings['tld_regex'] . '~', null) !== false) |
@@ -6121,10 +6473,11 @@ discard block |
||
6121 | 6473 | // Clean $tlds and convert it to an array |
6122 | 6474 | $tlds = array_filter(explode("\n", strtolower($tlds)), function($line) { |
6123 | 6475 | $line = trim($line); |
6124 | - if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) |
|
6125 | - return false; |
|
6126 | - else |
|
6127 | - return true; |
|
6476 | + if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) { |
|
6477 | + return false; |
|
6478 | + } else { |
|
6479 | + return true; |
|
6480 | + } |
|
6128 | 6481 | }); |
6129 | 6482 | |
6130 | 6483 | // Convert Punycode to Unicode |
@@ -6216,8 +6569,7 @@ discard block |
||
6216 | 6569 | |
6217 | 6570 | $strlen = 'mb_strlen'; |
6218 | 6571 | $substr = 'mb_substr'; |
6219 | - } |
|
6220 | - else |
|
6572 | + } else |
|
6221 | 6573 | { |
6222 | 6574 | $strlen = $smcFunc['strlen']; |
6223 | 6575 | $substr = $smcFunc['substr']; |
@@ -6231,20 +6583,21 @@ discard block |
||
6231 | 6583 | |
6232 | 6584 | $first = $substr($string, 0, 1); |
6233 | 6585 | |
6234 | - if (empty($index[$first])) |
|
6235 | - $index[$first] = array(); |
|
6586 | + if (empty($index[$first])) { |
|
6587 | + $index[$first] = array(); |
|
6588 | + } |
|
6236 | 6589 | |
6237 | 6590 | if ($strlen($string) > 1) |
6238 | 6591 | { |
6239 | 6592 | // Sanity check on recursion |
6240 | - if ($depth > 99) |
|
6241 | - $index[$first][$substr($string, 1)] = ''; |
|
6242 | - |
|
6243 | - else |
|
6244 | - $index[$first] = $add_string_to_index($substr($string, 1), $index[$first]); |
|
6593 | + if ($depth > 99) { |
|
6594 | + $index[$first][$substr($string, 1)] = ''; |
|
6595 | + } else { |
|
6596 | + $index[$first] = $add_string_to_index($substr($string, 1), $index[$first]); |
|
6597 | + } |
|
6598 | + } else { |
|
6599 | + $index[$first][''] = ''; |
|
6245 | 6600 | } |
6246 | - else |
|
6247 | - $index[$first][''] = ''; |
|
6248 | 6601 | |
6249 | 6602 | $depth--; |
6250 | 6603 | return $index; |
@@ -6267,9 +6620,9 @@ discard block |
||
6267 | 6620 | $key_regex = preg_quote($key, $delim); |
6268 | 6621 | $new_key = $key; |
6269 | 6622 | |
6270 | - if (empty($value)) |
|
6271 | - $sub_regex = ''; |
|
6272 | - else |
|
6623 | + if (empty($value)) { |
|
6624 | + $sub_regex = ''; |
|
6625 | + } else |
|
6273 | 6626 | { |
6274 | 6627 | $sub_regex = $index_to_regex($value, $delim); |
6275 | 6628 | |
@@ -6277,22 +6630,22 @@ discard block |
||
6277 | 6630 | { |
6278 | 6631 | $new_key_array = explode('(?'.'>', $sub_regex); |
6279 | 6632 | $new_key .= $new_key_array[0]; |
6633 | + } else { |
|
6634 | + $sub_regex = '(?'.'>' . $sub_regex . ')'; |
|
6280 | 6635 | } |
6281 | - else |
|
6282 | - $sub_regex = '(?'.'>' . $sub_regex . ')'; |
|
6283 | 6636 | } |
6284 | 6637 | |
6285 | - if ($depth > 1) |
|
6286 | - $regex[$new_key] = $key_regex . $sub_regex; |
|
6287 | - else |
|
6638 | + if ($depth > 1) { |
|
6639 | + $regex[$new_key] = $key_regex . $sub_regex; |
|
6640 | + } else |
|
6288 | 6641 | { |
6289 | 6642 | if (($length += strlen($key_regex) + 1) < $max_length || empty($regex)) |
6290 | 6643 | { |
6291 | 6644 | $regex[$new_key] = $key_regex . $sub_regex; |
6292 | 6645 | unset($index[$key]); |
6646 | + } else { |
|
6647 | + break; |
|
6293 | 6648 | } |
6294 | - else |
|
6295 | - break; |
|
6296 | 6649 | } |
6297 | 6650 | } |
6298 | 6651 | |
@@ -6301,10 +6654,11 @@ discard block |
||
6301 | 6654 | $l1 = $strlen($k1); |
6302 | 6655 | $l2 = $strlen($k2); |
6303 | 6656 | |
6304 | - if ($l1 == $l2) |
|
6305 | - return strcmp($k1, $k2) > 0 ? 1 : -1; |
|
6306 | - else |
|
6307 | - return $l1 > $l2 ? -1 : 1; |
|
6657 | + if ($l1 == $l2) { |
|
6658 | + return strcmp($k1, $k2) > 0 ? 1 : -1; |
|
6659 | + } else { |
|
6660 | + return $l1 > $l2 ? -1 : 1; |
|
6661 | + } |
|
6308 | 6662 | }); |
6309 | 6663 | |
6310 | 6664 | $depth--; |
@@ -6315,21 +6669,24 @@ discard block |
||
6315 | 6669 | $index = array(); |
6316 | 6670 | $regex = ''; |
6317 | 6671 | |
6318 | - foreach ($strings as $string) |
|
6319 | - $index = $add_string_to_index($string, $index); |
|
6672 | + foreach ($strings as $string) { |
|
6673 | + $index = $add_string_to_index($string, $index); |
|
6674 | + } |
|
6320 | 6675 | |
6321 | 6676 | if ($returnArray === true) |
6322 | 6677 | { |
6323 | 6678 | $regex = array(); |
6324 | - while (!empty($index)) |
|
6325 | - $regex[] = '(?'.'>' . $index_to_regex($index, $delim) . ')'; |
|
6679 | + while (!empty($index)) { |
|
6680 | + $regex[] = '(?'.'>' . $index_to_regex($index, $delim) . ')'; |
|
6681 | + } |
|
6682 | + } else { |
|
6683 | + $regex = '(?'.'>' . $index_to_regex($index, $delim) . ')'; |
|
6326 | 6684 | } |
6327 | - else |
|
6328 | - $regex = '(?'.'>' . $index_to_regex($index, $delim) . ')'; |
|
6329 | 6685 | |
6330 | 6686 | // Restore PHP's internal character encoding to whatever it was originally |
6331 | - if (!empty($current_encoding)) |
|
6332 | - mb_internal_encoding($current_encoding); |
|
6687 | + if (!empty($current_encoding)) { |
|
6688 | + mb_internal_encoding($current_encoding); |
|
6689 | + } |
|
6333 | 6690 | |
6334 | 6691 | return $regex; |
6335 | 6692 | } |
@@ -6372,13 +6729,15 @@ discard block |
||
6372 | 6729 | // Need to add the trailing slash, or it puts it there & thinks there's a redirect when there isn't... |
6373 | 6730 | $url = str_ireplace('https://', 'http://', $url) . '/'; |
6374 | 6731 | $headers = @get_headers($url); |
6375 | - if ($headers === false) |
|
6376 | - return false; |
|
6732 | + if ($headers === false) { |
|
6733 | + return false; |
|
6734 | + } |
|
6377 | 6735 | |
6378 | 6736 | // Now to see if it came back https... |
6379 | 6737 | // First check for a redirect status code in first row (301, 302, 307) |
6380 | - if (strstr($headers[0], '301') === false && strstr($headers[0], '302') === false && strstr($headers[0], '307') === false) |
|
6381 | - return false; |
|
6738 | + if (strstr($headers[0], '301') === false && strstr($headers[0], '302') === false && strstr($headers[0], '307') === false) { |
|
6739 | + return false; |
|
6740 | + } |
|
6382 | 6741 | |
6383 | 6742 | // Search for the location entry to confirm https |
6384 | 6743 | $result = false; |
@@ -6416,8 +6775,7 @@ discard block |
||
6416 | 6775 | $is_admin = $user_info['is_admin']; |
6417 | 6776 | $mod_cache = !empty($user_info['mod_cache']) ? $user_info['mod_cache'] : null; |
6418 | 6777 | $ignoreboards = !empty($user_info['ignoreboards']) ? $user_info['ignoreboards'] : null; |
6419 | - } |
|
6420 | - else |
|
6778 | + } else |
|
6421 | 6779 | { |
6422 | 6780 | $request = $smcFunc['db_query']('', ' |
6423 | 6781 | SELECT mem.ignore_boards, mem.id_group, mem.additional_groups, mem.id_post_group |
@@ -6431,17 +6789,19 @@ discard block |
||
6431 | 6789 | |
6432 | 6790 | $row = $smcFunc['db_fetch_assoc']($request); |
6433 | 6791 | |
6434 | - if (empty($row['additional_groups'])) |
|
6435 | - $groups = array($row['id_group'], $row['id_post_group']); |
|
6436 | - else |
|
6437 | - $groups = array_merge( |
|
6792 | + if (empty($row['additional_groups'])) { |
|
6793 | + $groups = array($row['id_group'], $row['id_post_group']); |
|
6794 | + } else { |
|
6795 | + $groups = array_merge( |
|
6438 | 6796 | array($row['id_group'], $row['id_post_group']), |
6439 | 6797 | explode(',', $row['additional_groups']) |
6440 | 6798 | ); |
6799 | + } |
|
6441 | 6800 | |
6442 | 6801 | // Because history has proven that it is possible for groups to go bad - clean up in case. |
6443 | - foreach ($groups as $k => $v) |
|
6444 | - $groups[$k] = (int) $v; |
|
6802 | + foreach ($groups as $k => $v) { |
|
6803 | + $groups[$k] = (int) $v; |
|
6804 | + } |
|
6445 | 6805 | |
6446 | 6806 | $is_admin = in_array(1, $groups); |
6447 | 6807 | |
@@ -6458,8 +6818,9 @@ discard block |
||
6458 | 6818 | 'current_member' => $userid, |
6459 | 6819 | ) |
6460 | 6820 | ); |
6461 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
6462 | - $boards_mod[] = $row['id_board']; |
|
6821 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
6822 | + $boards_mod[] = $row['id_board']; |
|
6823 | + } |
|
6463 | 6824 | $smcFunc['db_free_result']($request); |
6464 | 6825 | |
6465 | 6826 | // Can any of the groups they're in moderate any of the boards? |
@@ -6471,8 +6832,9 @@ discard block |
||
6471 | 6832 | 'groups' => $groups, |
6472 | 6833 | ) |
6473 | 6834 | ); |
6474 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
6475 | - $boards_mod[] = $row['id_board']; |
|
6835 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
6836 | + $boards_mod[] = $row['id_board']; |
|
6837 | + } |
|
6476 | 6838 | $smcFunc['db_free_result']($request); |
6477 | 6839 | |
6478 | 6840 | // Just in case we've got duplicates here... |
@@ -6482,21 +6844,25 @@ discard block |
||
6482 | 6844 | } |
6483 | 6845 | |
6484 | 6846 | // Just build this here, it makes it easier to change/use - administrators can see all boards. |
6485 | - if ($is_admin) |
|
6486 | - $query_part['query_see_board'] = '1=1'; |
|
6847 | + if ($is_admin) { |
|
6848 | + $query_part['query_see_board'] = '1=1'; |
|
6849 | + } |
|
6487 | 6850 | // Otherwise just the groups in $user_info['groups']. |
6488 | - else |
|
6489 | - $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'] : '') . ')'; |
|
6851 | + else { |
|
6852 | + $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'] : '') . ')'; |
|
6853 | + } |
|
6490 | 6854 | |
6491 | 6855 | // Build the list of boards they WANT to see. |
6492 | 6856 | // This will take the place of query_see_boards in certain spots, so it better include the boards they can see also |
6493 | 6857 | |
6494 | 6858 | // If they aren't ignoring any boards then they want to see all the boards they can see |
6495 | - if (empty($ignoreboards)) |
|
6496 | - $query_part['query_wanna_see_board'] = $query_part['query_see_board']; |
|
6859 | + if (empty($ignoreboards)) { |
|
6860 | + $query_part['query_wanna_see_board'] = $query_part['query_see_board']; |
|
6861 | + } |
|
6497 | 6862 | // Ok I guess they don't want to see all the boards |
6498 | - else |
|
6499 | - $query_part['query_wanna_see_board'] = '(' . $query_part['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $ignoreboards) . '))'; |
|
6863 | + else { |
|
6864 | + $query_part['query_wanna_see_board'] = '(' . $query_part['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $ignoreboards) . '))'; |
|
6865 | + } |
|
6500 | 6866 | |
6501 | 6867 | return $query_part; |
6502 | 6868 | } |
@@ -6510,10 +6876,11 @@ discard block |
||
6510 | 6876 | { |
6511 | 6877 | $secure = false; |
6512 | 6878 | |
6513 | - if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') |
|
6514 | - $secure = true; |
|
6515 | - 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') |
|
6516 | - $secure = true; |
|
6879 | + if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { |
|
6880 | + $secure = true; |
|
6881 | + } 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') { |
|
6882 | + $secure = true; |
|
6883 | + } |
|
6517 | 6884 | |
6518 | 6885 | return $secure; |
6519 | 6886 | } |
@@ -6530,11 +6897,12 @@ discard block |
||
6530 | 6897 | { |
6531 | 6898 | $url = iri_to_url($iri); |
6532 | 6899 | |
6533 | - if (filter_var($url, FILTER_VALIDATE_URL, $flags) !== false) |
|
6534 | - return $iri; |
|
6535 | - else |
|
6536 | - return false; |
|
6537 | -} |
|
6900 | + if (filter_var($url, FILTER_VALIDATE_URL, $flags) !== false) { |
|
6901 | + return $iri; |
|
6902 | + } else { |
|
6903 | + return false; |
|
6904 | + } |
|
6905 | + } |
|
6538 | 6906 | |
6539 | 6907 | /** |
6540 | 6908 | * A wrapper for `filter_var($url, FILTER_SANITIZE_URL)` that can handle URLs |
@@ -6577,8 +6945,9 @@ discard block |
||
6577 | 6945 | |
6578 | 6946 | $host = parse_url((strpos($iri, '://') === false ? 'http://' : '') . ltrim($iri, ':/'), PHP_URL_HOST); |
6579 | 6947 | |
6580 | - if (empty($host)) |
|
6581 | - return $iri; |
|
6948 | + if (empty($host)) { |
|
6949 | + return $iri; |
|
6950 | + } |
|
6582 | 6951 | |
6583 | 6952 | // Convert the domain using the Punycode algorithm |
6584 | 6953 | require_once($sourcedir . '/Class-Punycode.php'); |
@@ -6614,8 +6983,9 @@ discard block |
||
6614 | 6983 | |
6615 | 6984 | $host = parse_url((strpos($url, '://') === false ? 'http://' : '') . ltrim($url, ':/'), PHP_URL_HOST); |
6616 | 6985 | |
6617 | - if (empty($host)) |
|
6618 | - return $url; |
|
6986 | + if (empty($host)) { |
|
6987 | + return $url; |
|
6988 | + } |
|
6619 | 6989 | |
6620 | 6990 | // Decode the domain from Punycode |
6621 | 6991 | require_once($sourcedir . '/Class-Punycode.php'); |
@@ -6641,8 +7011,9 @@ discard block |
||
6641 | 7011 | { |
6642 | 7012 | global $user_info, $modSettings, $smcFunc, $txt; |
6643 | 7013 | |
6644 | - if (empty($modSettings['cron_last_checked'])) |
|
6645 | - $modSettings['cron_last_checked'] = 0; |
|
7014 | + if (empty($modSettings['cron_last_checked'])) { |
|
7015 | + $modSettings['cron_last_checked'] = 0; |
|
7016 | + } |
|
6646 | 7017 | |
6647 | 7018 | if (!empty($modSettings['cron_is_real_cron']) && time() - $modSettings['cron_last_checked'] > 84600) |
6648 | 7019 | { |
@@ -6662,9 +7033,9 @@ discard block |
||
6662 | 7033 | loadLanguage('ManageScheduledTasks'); |
6663 | 7034 | log_error($txt['cron_not_working']); |
6664 | 7035 | updateSettings(array('cron_is_real_cron' => 0)); |
7036 | + } else { |
|
7037 | + updateSettings(array('cron_last_checked' => time())); |
|
6665 | 7038 | } |
6666 | - else |
|
6667 | - updateSettings(array('cron_last_checked' => time())); |
|
6668 | 7039 | } |
6669 | 7040 | } |
6670 | 7041 | |
@@ -6688,10 +7059,11 @@ discard block |
||
6688 | 7059 | |
6689 | 7060 | $protocol = preg_match('~^\s*(HTTP/[12]\.\d)\s*$~i', $_SERVER['SERVER_PROTOCOL'], $matches) ? $matches[1] : 'HTTP/1.0'; |
6690 | 7061 | |
6691 | - if (!isset($statuses[$code]) && empty($status)) |
|
6692 | - header($protocol . ' 500 Internal Server Error'); |
|
6693 | - else |
|
6694 | - header($protocol . ' ' . $code . ' ' . (!empty($status) ? $status : $statuses[$code])); |
|
6695 | -} |
|
7062 | + if (!isset($statuses[$code]) && empty($status)) { |
|
7063 | + header($protocol . ' 500 Internal Server Error'); |
|
7064 | + } else { |
|
7065 | + header($protocol . ' ' . $code . ' ' . (!empty($status) ? $status : $statuses[$code])); |
|
7066 | + } |
|
7067 | + } |
|
6696 | 7068 | |
6697 | 7069 | ?> |
6698 | 7070 | \ No newline at end of file |