@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 4 |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF')) |
|
16 | +if (!defined('SMF')) { |
|
17 | 17 | die('No direct access...'); |
18 | +} |
|
18 | 19 | |
19 | 20 | /** |
20 | 21 | * Update some basic statistics. |
@@ -122,10 +123,11 @@ discard block |
||
122 | 123 | $smcFunc['db_free_result']($result); |
123 | 124 | |
124 | 125 | // Add this to the number of unapproved members |
125 | - if (!empty($changes['unapprovedMembers'])) |
|
126 | - $changes['unapprovedMembers'] += $coppa_approvals; |
|
127 | - else |
|
128 | - $changes['unapprovedMembers'] = $coppa_approvals; |
|
126 | + if (!empty($changes['unapprovedMembers'])) { |
|
127 | + $changes['unapprovedMembers'] += $coppa_approvals; |
|
128 | + } else { |
|
129 | + $changes['unapprovedMembers'] = $coppa_approvals; |
|
130 | + } |
|
129 | 131 | } |
130 | 132 | } |
131 | 133 | } |
@@ -133,9 +135,9 @@ discard block |
||
133 | 135 | break; |
134 | 136 | |
135 | 137 | case 'message': |
136 | - if ($parameter1 === true && $parameter2 !== null) |
|
137 | - updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true); |
|
138 | - else |
|
138 | + if ($parameter1 === true && $parameter2 !== null) { |
|
139 | + updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true); |
|
140 | + } else |
|
139 | 141 | { |
140 | 142 | // SUM and MAX on a smaller table is better for InnoDB tables. |
141 | 143 | $result = $smcFunc['db_query']('', ' |
@@ -175,23 +177,25 @@ discard block |
||
175 | 177 | $parameter2 = text2words($parameter2); |
176 | 178 | |
177 | 179 | $inserts = array(); |
178 | - foreach ($parameter2 as $word) |
|
179 | - $inserts[] = array($word, $parameter1); |
|
180 | + foreach ($parameter2 as $word) { |
|
181 | + $inserts[] = array($word, $parameter1); |
|
182 | + } |
|
180 | 183 | |
181 | - if (!empty($inserts)) |
|
182 | - $smcFunc['db_insert']('ignore', |
|
184 | + if (!empty($inserts)) { |
|
185 | + $smcFunc['db_insert']('ignore', |
|
183 | 186 | '{db_prefix}log_search_subjects', |
184 | 187 | array('word' => 'string', 'id_topic' => 'int'), |
185 | 188 | $inserts, |
186 | 189 | array('word', 'id_topic') |
187 | 190 | ); |
191 | + } |
|
188 | 192 | } |
189 | 193 | break; |
190 | 194 | |
191 | 195 | case 'topic': |
192 | - if ($parameter1 === true) |
|
193 | - updateSettings(array('totalTopics' => true), true); |
|
194 | - else |
|
196 | + if ($parameter1 === true) { |
|
197 | + updateSettings(array('totalTopics' => true), true); |
|
198 | + } else |
|
195 | 199 | { |
196 | 200 | // Get the number of topics - a SUM is better for InnoDB tables. |
197 | 201 | // We also ignore the recycle bin here because there will probably be a bunch of one-post topics there. |
@@ -212,8 +216,9 @@ discard block |
||
212 | 216 | |
213 | 217 | case 'postgroups': |
214 | 218 | // Parameter two is the updated columns: we should check to see if we base groups off any of these. |
215 | - if ($parameter2 !== null && !in_array('posts', $parameter2)) |
|
216 | - return; |
|
219 | + if ($parameter2 !== null && !in_array('posts', $parameter2)) { |
|
220 | + return; |
|
221 | + } |
|
217 | 222 | |
218 | 223 | $postgroups = cache_get_data('updateStats:postgroups', 360); |
219 | 224 | if ($postgroups == null || $parameter1 == null) |
@@ -228,8 +233,9 @@ discard block |
||
228 | 233 | ) |
229 | 234 | ); |
230 | 235 | $postgroups = array(); |
231 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
232 | - $postgroups[$row['id_group']] = $row['min_posts']; |
|
236 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
237 | + $postgroups[$row['id_group']] = $row['min_posts']; |
|
238 | + } |
|
233 | 239 | $smcFunc['db_free_result']($request); |
234 | 240 | |
235 | 241 | // Sort them this way because if it's done with MySQL it causes a filesort :(. |
@@ -239,8 +245,9 @@ discard block |
||
239 | 245 | } |
240 | 246 | |
241 | 247 | // Oh great, they've screwed their post groups. |
242 | - if (empty($postgroups)) |
|
243 | - return; |
|
248 | + if (empty($postgroups)) { |
|
249 | + return; |
|
250 | + } |
|
244 | 251 | |
245 | 252 | // Set all membergroups from most posts to least posts. |
246 | 253 | $conditions = ''; |
@@ -298,10 +305,9 @@ discard block |
||
298 | 305 | { |
299 | 306 | $condition = 'id_member IN ({array_int:members})'; |
300 | 307 | $parameters['members'] = $members; |
301 | - } |
|
302 | - elseif ($members === null) |
|
303 | - $condition = '1=1'; |
|
304 | - else |
|
308 | + } elseif ($members === null) { |
|
309 | + $condition = '1=1'; |
|
310 | + } else |
|
305 | 311 | { |
306 | 312 | $condition = 'id_member = {int:member}'; |
307 | 313 | $parameters['member'] = $members; |
@@ -341,9 +347,9 @@ discard block |
||
341 | 347 | if (count($vars_to_integrate) != 0) |
342 | 348 | { |
343 | 349 | // Fetch a list of member_names if necessary |
344 | - if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) |
|
345 | - $member_names = array($user_info['username']); |
|
346 | - else |
|
350 | + if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) { |
|
351 | + $member_names = array($user_info['username']); |
|
352 | + } else |
|
347 | 353 | { |
348 | 354 | $member_names = array(); |
349 | 355 | $request = $smcFunc['db_query']('', ' |
@@ -352,14 +358,16 @@ discard block |
||
352 | 358 | WHERE ' . $condition, |
353 | 359 | $parameters |
354 | 360 | ); |
355 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
356 | - $member_names[] = $row['member_name']; |
|
361 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
362 | + $member_names[] = $row['member_name']; |
|
363 | + } |
|
357 | 364 | $smcFunc['db_free_result']($request); |
358 | 365 | } |
359 | 366 | |
360 | - if (!empty($member_names)) |
|
361 | - foreach ($vars_to_integrate as $var) |
|
367 | + if (!empty($member_names)) { |
|
368 | + foreach ($vars_to_integrate as $var) |
|
362 | 369 | call_integration_hook('integrate_change_member_data', array($member_names, $var, &$data[$var], &$knownInts, &$knownFloats)); |
370 | + } |
|
363 | 371 | } |
364 | 372 | } |
365 | 373 | |
@@ -367,16 +375,17 @@ discard block |
||
367 | 375 | foreach ($data as $var => $val) |
368 | 376 | { |
369 | 377 | $type = 'string'; |
370 | - if (in_array($var, $knownInts)) |
|
371 | - $type = 'int'; |
|
372 | - elseif (in_array($var, $knownFloats)) |
|
373 | - $type = 'float'; |
|
374 | - elseif ($var == 'birthdate') |
|
375 | - $type = 'date'; |
|
376 | - elseif ($var == 'member_ip') |
|
377 | - $type = 'inet'; |
|
378 | - elseif ($var == 'member_ip2') |
|
379 | - $type = 'inet'; |
|
378 | + if (in_array($var, $knownInts)) { |
|
379 | + $type = 'int'; |
|
380 | + } elseif (in_array($var, $knownFloats)) { |
|
381 | + $type = 'float'; |
|
382 | + } elseif ($var == 'birthdate') { |
|
383 | + $type = 'date'; |
|
384 | + } elseif ($var == 'member_ip') { |
|
385 | + $type = 'inet'; |
|
386 | + } elseif ($var == 'member_ip2') { |
|
387 | + $type = 'inet'; |
|
388 | + } |
|
380 | 389 | |
381 | 390 | // Doing an increment? |
382 | 391 | if ($var == 'alerts' && ($val === '+' || $val === '-')) |
@@ -385,18 +394,17 @@ discard block |
||
385 | 394 | if (is_array($members)) |
386 | 395 | { |
387 | 396 | $val = 'CASE '; |
388 | - foreach ($members as $k => $v) |
|
389 | - $val .= 'WHEN id_member = ' . $v . ' THEN '. count(fetch_alerts($v, false, 0, array(), false)) . ' '; |
|
397 | + foreach ($members as $k => $v) { |
|
398 | + $val .= 'WHEN id_member = ' . $v . ' THEN '. count(fetch_alerts($v, false, 0, array(), false)) . ' '; |
|
399 | + } |
|
390 | 400 | $val = $val . ' END'; |
391 | 401 | $type = 'raw'; |
392 | - } |
|
393 | - else |
|
402 | + } else |
|
394 | 403 | { |
395 | 404 | $blub = fetch_alerts($members, false, 0, array(), false); |
396 | 405 | $val = count($blub); |
397 | 406 | } |
398 | - } |
|
399 | - else if ($type == 'int' && ($val === '+' || $val === '-')) |
|
407 | + } else if ($type == 'int' && ($val === '+' || $val === '-')) |
|
400 | 408 | { |
401 | 409 | $val = $var . ' ' . $val . ' 1'; |
402 | 410 | $type = 'raw'; |
@@ -407,8 +415,9 @@ discard block |
||
407 | 415 | { |
408 | 416 | if (preg_match('~^' . $var . ' (\+ |- |\+ -)([\d]+)~', $val, $match)) |
409 | 417 | { |
410 | - if ($match[1] != '+ ') |
|
411 | - $val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END'; |
|
418 | + if ($match[1] != '+ ') { |
|
419 | + $val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END'; |
|
420 | + } |
|
412 | 421 | $type = 'raw'; |
413 | 422 | } |
414 | 423 | } |
@@ -429,8 +438,9 @@ discard block |
||
429 | 438 | // Clear any caching? |
430 | 439 | if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && !empty($members)) |
431 | 440 | { |
432 | - if (!is_array($members)) |
|
433 | - $members = array($members); |
|
441 | + if (!is_array($members)) { |
|
442 | + $members = array($members); |
|
443 | + } |
|
434 | 444 | |
435 | 445 | foreach ($members as $member) |
436 | 446 | { |
@@ -463,29 +473,32 @@ discard block |
||
463 | 473 | { |
464 | 474 | global $modSettings, $smcFunc; |
465 | 475 | |
466 | - if (empty($changeArray) || !is_array($changeArray)) |
|
467 | - return; |
|
476 | + if (empty($changeArray) || !is_array($changeArray)) { |
|
477 | + return; |
|
478 | + } |
|
468 | 479 | |
469 | 480 | $toRemove = array(); |
470 | 481 | |
471 | 482 | // Go check if there is any setting to be removed. |
472 | - foreach ($changeArray as $k => $v) |
|
473 | - if ($v === null) |
|
483 | + foreach ($changeArray as $k => $v) { |
|
484 | + if ($v === null) |
|
474 | 485 | { |
475 | 486 | // Found some, remove them from the original array and add them to ours. |
476 | 487 | unset($changeArray[$k]); |
488 | + } |
|
477 | 489 | $toRemove[] = $k; |
478 | 490 | } |
479 | 491 | |
480 | 492 | // Proceed with the deletion. |
481 | - if (!empty($toRemove)) |
|
482 | - $smcFunc['db_query']('', ' |
|
493 | + if (!empty($toRemove)) { |
|
494 | + $smcFunc['db_query']('', ' |
|
483 | 495 | DELETE FROM {db_prefix}settings |
484 | 496 | WHERE variable IN ({array_string:remove})', |
485 | 497 | array( |
486 | 498 | 'remove' => $toRemove, |
487 | 499 | ) |
488 | 500 | ); |
501 | + } |
|
489 | 502 | |
490 | 503 | // In some cases, this may be better and faster, but for large sets we don't want so many UPDATEs. |
491 | 504 | if ($update) |
@@ -514,19 +527,22 @@ discard block |
||
514 | 527 | foreach ($changeArray as $variable => $value) |
515 | 528 | { |
516 | 529 | // Don't bother if it's already like that ;). |
517 | - if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) |
|
518 | - continue; |
|
530 | + if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) { |
|
531 | + continue; |
|
532 | + } |
|
519 | 533 | // If the variable isn't set, but would only be set to nothing'ness, then don't bother setting it. |
520 | - elseif (!isset($modSettings[$variable]) && empty($value)) |
|
521 | - continue; |
|
534 | + elseif (!isset($modSettings[$variable]) && empty($value)) { |
|
535 | + continue; |
|
536 | + } |
|
522 | 537 | |
523 | 538 | $replaceArray[] = array($variable, $value); |
524 | 539 | |
525 | 540 | $modSettings[$variable] = $value; |
526 | 541 | } |
527 | 542 | |
528 | - if (empty($replaceArray)) |
|
529 | - return; |
|
543 | + if (empty($replaceArray)) { |
|
544 | + return; |
|
545 | + } |
|
530 | 546 | |
531 | 547 | $smcFunc['db_insert']('replace', |
532 | 548 | '{db_prefix}settings', |
@@ -572,14 +588,17 @@ discard block |
||
572 | 588 | $start_invalid = $start < 0; |
573 | 589 | |
574 | 590 | // Make sure $start is a proper variable - not less than 0. |
575 | - if ($start_invalid) |
|
576 | - $start = 0; |
|
591 | + if ($start_invalid) { |
|
592 | + $start = 0; |
|
593 | + } |
|
577 | 594 | // Not greater than the upper bound. |
578 | - elseif ($start >= $max_value) |
|
579 | - $start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page))); |
|
595 | + elseif ($start >= $max_value) { |
|
596 | + $start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page))); |
|
597 | + } |
|
580 | 598 | // And it has to be a multiple of $num_per_page! |
581 | - else |
|
582 | - $start = max(0, (int) $start - ((int) $start % (int) $num_per_page)); |
|
599 | + else { |
|
600 | + $start = max(0, (int) $start - ((int) $start % (int) $num_per_page)); |
|
601 | + } |
|
583 | 602 | |
584 | 603 | $context['current_page'] = $start / $num_per_page; |
585 | 604 | |
@@ -609,77 +628,87 @@ discard block |
||
609 | 628 | |
610 | 629 | // Show all the pages. |
611 | 630 | $display_page = 1; |
612 | - for ($counter = 0; $counter < $max_value; $counter += $num_per_page) |
|
613 | - $pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++); |
|
631 | + for ($counter = 0; $counter < $max_value; $counter += $num_per_page) { |
|
632 | + $pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++); |
|
633 | + } |
|
614 | 634 | |
615 | 635 | // Show the right arrow. |
616 | 636 | $display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page); |
617 | - if ($start != $counter - $max_value && !$start_invalid) |
|
618 | - $pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']); |
|
619 | - } |
|
620 | - else |
|
637 | + if ($start != $counter - $max_value && !$start_invalid) { |
|
638 | + $pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']); |
|
639 | + } |
|
640 | + } else |
|
621 | 641 | { |
622 | 642 | // If they didn't enter an odd value, pretend they did. |
623 | 643 | $PageContiguous = (int) ($modSettings['compactTopicPagesContiguous'] - ($modSettings['compactTopicPagesContiguous'] % 2)) / 2; |
624 | 644 | |
625 | 645 | // Show the "prev page" link. (>prev page< 1 ... 6 7 [8] 9 10 ... 15 next page) |
626 | - if (!empty($start) && $show_prevnext) |
|
627 | - $pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']); |
|
628 | - else |
|
629 | - $pageindex .= ''; |
|
646 | + if (!empty($start) && $show_prevnext) { |
|
647 | + $pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']); |
|
648 | + } else { |
|
649 | + $pageindex .= ''; |
|
650 | + } |
|
630 | 651 | |
631 | 652 | // Show the first page. (prev page >1< ... 6 7 [8] 9 10 ... 15) |
632 | - if ($start > $num_per_page * $PageContiguous) |
|
633 | - $pageindex .= sprintf($base_link, 0, '1'); |
|
653 | + if ($start > $num_per_page * $PageContiguous) { |
|
654 | + $pageindex .= sprintf($base_link, 0, '1'); |
|
655 | + } |
|
634 | 656 | |
635 | 657 | // Show the ... after the first page. (prev page 1 >...< 6 7 [8] 9 10 ... 15 next page) |
636 | - if ($start > $num_per_page * ($PageContiguous + 1)) |
|
637 | - $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
658 | + if ($start > $num_per_page * ($PageContiguous + 1)) { |
|
659 | + $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
638 | 660 | '{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)), |
639 | 661 | '{FIRST_PAGE}' => $num_per_page, |
640 | 662 | '{LAST_PAGE}' => $start - $num_per_page * $PageContiguous, |
641 | 663 | '{PER_PAGE}' => $num_per_page, |
642 | 664 | )); |
665 | + } |
|
643 | 666 | |
644 | 667 | // Show the pages before the current one. (prev page 1 ... >6 7< [8] 9 10 ... 15 next page) |
645 | - for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) |
|
646 | - if ($start >= $num_per_page * $nCont) |
|
668 | + for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) { |
|
669 | + if ($start >= $num_per_page * $nCont) |
|
647 | 670 | { |
648 | 671 | $tmpStart = $start - $num_per_page * $nCont; |
672 | + } |
|
649 | 673 | $pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1); |
650 | 674 | } |
651 | 675 | |
652 | 676 | // Show the current page. (prev page 1 ... 6 7 >[8]< 9 10 ... 15 next page) |
653 | - if (!$start_invalid) |
|
654 | - $pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1); |
|
655 | - else |
|
656 | - $pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1); |
|
677 | + if (!$start_invalid) { |
|
678 | + $pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1); |
|
679 | + } else { |
|
680 | + $pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1); |
|
681 | + } |
|
657 | 682 | |
658 | 683 | // Show the pages after the current one... (prev page 1 ... 6 7 [8] >9 10< ... 15 next page) |
659 | 684 | $tmpMaxPages = (int) (($max_value - 1) / $num_per_page) * $num_per_page; |
660 | - for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) |
|
661 | - if ($start + $num_per_page * $nCont <= $tmpMaxPages) |
|
685 | + for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) { |
|
686 | + if ($start + $num_per_page * $nCont <= $tmpMaxPages) |
|
662 | 687 | { |
663 | 688 | $tmpStart = $start + $num_per_page * $nCont; |
689 | + } |
|
664 | 690 | $pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1); |
665 | 691 | } |
666 | 692 | |
667 | 693 | // Show the '...' part near the end. (prev page 1 ... 6 7 [8] 9 10 >...< 15 next page) |
668 | - if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) |
|
669 | - $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
694 | + if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) { |
|
695 | + $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
670 | 696 | '{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)), |
671 | 697 | '{FIRST_PAGE}' => $start + $num_per_page * ($PageContiguous + 1), |
672 | 698 | '{LAST_PAGE}' => $tmpMaxPages, |
673 | 699 | '{PER_PAGE}' => $num_per_page, |
674 | 700 | )); |
701 | + } |
|
675 | 702 | |
676 | 703 | // Show the last number in the list. (prev page 1 ... 6 7 [8] 9 10 ... >15< next page) |
677 | - if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) |
|
678 | - $pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1); |
|
704 | + if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) { |
|
705 | + $pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1); |
|
706 | + } |
|
679 | 707 | |
680 | 708 | // Show the "next page" link. (prev page 1 ... 6 7 [8] 9 10 ... 15 >next page<) |
681 | - if ($start != $tmpMaxPages && $show_prevnext) |
|
682 | - $pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']); |
|
709 | + if ($start != $tmpMaxPages && $show_prevnext) { |
|
710 | + $pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']); |
|
711 | + } |
|
683 | 712 | } |
684 | 713 | $pageindex .= $settings['page_index']['extra_after']; |
685 | 714 | |
@@ -705,8 +734,9 @@ discard block |
||
705 | 734 | if ($decimal_separator === null) |
706 | 735 | { |
707 | 736 | // Not set for whatever reason? |
708 | - if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) |
|
709 | - return $number; |
|
737 | + if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) { |
|
738 | + return $number; |
|
739 | + } |
|
710 | 740 | |
711 | 741 | // Cache these each load... |
712 | 742 | $thousands_separator = $matches[1]; |
@@ -740,17 +770,20 @@ discard block |
||
740 | 770 | static $unsupportedFormats, $finalizedFormats; |
741 | 771 | |
742 | 772 | // Offset the time. |
743 | - if (!$offset_type) |
|
744 | - $time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600; |
|
773 | + if (!$offset_type) { |
|
774 | + $time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600; |
|
775 | + } |
|
745 | 776 | // Just the forum offset? |
746 | - elseif ($offset_type == 'forum') |
|
747 | - $time = $log_time + $modSettings['time_offset'] * 3600; |
|
748 | - else |
|
749 | - $time = $log_time; |
|
777 | + elseif ($offset_type == 'forum') { |
|
778 | + $time = $log_time + $modSettings['time_offset'] * 3600; |
|
779 | + } else { |
|
780 | + $time = $log_time; |
|
781 | + } |
|
750 | 782 | |
751 | 783 | // We can't have a negative date (on Windows, at least.) |
752 | - if ($log_time < 0) |
|
753 | - $log_time = 0; |
|
784 | + if ($log_time < 0) { |
|
785 | + $log_time = 0; |
|
786 | + } |
|
754 | 787 | |
755 | 788 | // Today and Yesterday? |
756 | 789 | if ($modSettings['todayMod'] >= 1 && $show_today === true) |
@@ -767,24 +800,27 @@ discard block |
||
767 | 800 | { |
768 | 801 | $h = strpos($user_info['time_format'], '%l') === false ? '%I' : '%l'; |
769 | 802 | $today_fmt = $h . ':%M' . $s . ' %p'; |
803 | + } else { |
|
804 | + $today_fmt = '%H:%M' . $s; |
|
770 | 805 | } |
771 | - else |
|
772 | - $today_fmt = '%H:%M' . $s; |
|
773 | 806 | |
774 | 807 | // Same day of the year, same year.... Today! |
775 | - if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) |
|
776 | - return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type); |
|
808 | + if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) { |
|
809 | + return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type); |
|
810 | + } |
|
777 | 811 | |
778 | 812 | // Day-of-year is one less and same year, or it's the first of the year and that's the last of the year... |
779 | - if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31)) |
|
780 | - return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type); |
|
813 | + if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31)) { |
|
814 | + return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type); |
|
815 | + } |
|
781 | 816 | } |
782 | 817 | |
783 | 818 | $str = !is_bool($show_today) ? $show_today : $user_info['time_format']; |
784 | 819 | |
785 | 820 | // Use the cached formats if available |
786 | - if (is_null($finalizedFormats)) |
|
787 | - $finalizedFormats = (array) cache_get_data('timeformatstrings', 86400); |
|
821 | + if (is_null($finalizedFormats)) { |
|
822 | + $finalizedFormats = (array) cache_get_data('timeformatstrings', 86400); |
|
823 | + } |
|
788 | 824 | |
789 | 825 | // Make a supported version for this format if we don't already have one |
790 | 826 | if (empty($finalizedFormats[$str])) |
@@ -813,8 +849,9 @@ discard block |
||
813 | 849 | ); |
814 | 850 | |
815 | 851 | // No need to do this part again if we already did it once |
816 | - if (is_null($unsupportedFormats)) |
|
817 | - $unsupportedFormats = (array) cache_get_data('unsupportedtimeformats', 86400); |
|
852 | + if (is_null($unsupportedFormats)) { |
|
853 | + $unsupportedFormats = (array) cache_get_data('unsupportedtimeformats', 86400); |
|
854 | + } |
|
818 | 855 | if (empty($unsupportedFormats)) |
819 | 856 | { |
820 | 857 | foreach($strftimeFormatSubstitutions as $format => $substitution) |
@@ -823,20 +860,23 @@ discard block |
||
823 | 860 | |
824 | 861 | // Windows will return false for unsupported formats |
825 | 862 | // Other operating systems return the format string as a literal |
826 | - if ($value === false || $value === $format) |
|
827 | - $unsupportedFormats[] = $format; |
|
863 | + if ($value === false || $value === $format) { |
|
864 | + $unsupportedFormats[] = $format; |
|
865 | + } |
|
828 | 866 | } |
829 | 867 | cache_put_data('unsupportedtimeformats', $unsupportedFormats, 86400); |
830 | 868 | } |
831 | 869 | |
832 | 870 | // Windows needs extra help if $timeformat contains something completely invalid, e.g. '%Q' |
833 | - if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') |
|
834 | - $timeformat = preg_replace('~%(?!' . implode('|', array_keys($strftimeFormatSubstitutions)) . ')~', '%', $timeformat); |
|
871 | + if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') { |
|
872 | + $timeformat = preg_replace('~%(?!' . implode('|', array_keys($strftimeFormatSubstitutions)) . ')~', '%', $timeformat); |
|
873 | + } |
|
835 | 874 | |
836 | 875 | // Substitute unsupported formats with supported ones |
837 | - if (!empty($unsupportedFormats)) |
|
838 | - while (preg_match('~%(' . implode('|', $unsupportedFormats) . ')~', $timeformat, $matches)) |
|
876 | + if (!empty($unsupportedFormats)) { |
|
877 | + while (preg_match('~%(' . implode('|', $unsupportedFormats) . ')~', $timeformat, $matches)) |
|
839 | 878 | $timeformat = str_replace($matches[0], $strftimeFormatSubstitutions[$matches[1]], $timeformat); |
879 | + } |
|
840 | 880 | |
841 | 881 | // Remember this so we don't need to do it again |
842 | 882 | $finalizedFormats[$str] = $timeformat; |
@@ -845,33 +885,39 @@ discard block |
||
845 | 885 | |
846 | 886 | $str = $finalizedFormats[$str]; |
847 | 887 | |
848 | - if (!isset($locale_cache)) |
|
849 | - $locale_cache = setlocale(LC_TIME, $txt['lang_locale']); |
|
888 | + if (!isset($locale_cache)) { |
|
889 | + $locale_cache = setlocale(LC_TIME, $txt['lang_locale']); |
|
890 | + } |
|
850 | 891 | |
851 | 892 | if ($locale_cache !== false) |
852 | 893 | { |
853 | 894 | // Check if another process changed the locale |
854 | - if ($process_safe === true && setlocale(LC_TIME, '0') != $locale_cache) |
|
855 | - setlocale(LC_TIME, $txt['lang_locale']); |
|
895 | + if ($process_safe === true && setlocale(LC_TIME, '0') != $locale_cache) { |
|
896 | + setlocale(LC_TIME, $txt['lang_locale']); |
|
897 | + } |
|
856 | 898 | |
857 | - if (!isset($non_twelve_hour)) |
|
858 | - $non_twelve_hour = trim(strftime('%p')) === ''; |
|
859 | - if ($non_twelve_hour && strpos($str, '%p') !== false) |
|
860 | - $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
899 | + if (!isset($non_twelve_hour)) { |
|
900 | + $non_twelve_hour = trim(strftime('%p')) === ''; |
|
901 | + } |
|
902 | + if ($non_twelve_hour && strpos($str, '%p') !== false) { |
|
903 | + $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
904 | + } |
|
861 | 905 | |
862 | - foreach (array('%a', '%A', '%b', '%B') as $token) |
|
863 | - if (strpos($str, $token) !== false) |
|
906 | + foreach (array('%a', '%A', '%b', '%B') as $token) { |
|
907 | + if (strpos($str, $token) !== false) |
|
864 | 908 | $str = str_replace($token, strftime($token, $time), $str); |
865 | - } |
|
866 | - else |
|
909 | + } |
|
910 | + } else |
|
867 | 911 | { |
868 | 912 | // Do-it-yourself time localization. Fun. |
869 | - foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) |
|
870 | - if (strpos($str, $token) !== false) |
|
913 | + foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) { |
|
914 | + if (strpos($str, $token) !== false) |
|
871 | 915 | $str = str_replace($token, $txt[$text_label][(int) strftime($token === '%a' || $token === '%A' ? '%w' : '%m', $time)], $str); |
916 | + } |
|
872 | 917 | |
873 | - if (strpos($str, '%p') !== false) |
|
874 | - $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
918 | + if (strpos($str, '%p') !== false) { |
|
919 | + $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
920 | + } |
|
875 | 921 | } |
876 | 922 | |
877 | 923 | // Format the time and then restore any literal percent characters |
@@ -894,16 +940,19 @@ discard block |
||
894 | 940 | static $translation = array(); |
895 | 941 | |
896 | 942 | // Determine the character set... Default to UTF-8 |
897 | - if (empty($context['character_set'])) |
|
898 | - $charset = 'UTF-8'; |
|
943 | + if (empty($context['character_set'])) { |
|
944 | + $charset = 'UTF-8'; |
|
945 | + } |
|
899 | 946 | // Use ISO-8859-1 in place of non-supported ISO-8859 charsets... |
900 | - elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) |
|
901 | - $charset = 'ISO-8859-1'; |
|
902 | - else |
|
903 | - $charset = $context['character_set']; |
|
947 | + elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) { |
|
948 | + $charset = 'ISO-8859-1'; |
|
949 | + } else { |
|
950 | + $charset = $context['character_set']; |
|
951 | + } |
|
904 | 952 | |
905 | - if (empty($translation)) |
|
906 | - $translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array(''' => '\'', ''' => '\'', ' ' => ' '); |
|
953 | + if (empty($translation)) { |
|
954 | + $translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array(''' => '\'', ''' => '\'', ' ' => ' '); |
|
955 | + } |
|
907 | 956 | |
908 | 957 | return strtr($string, $translation); |
909 | 958 | } |
@@ -925,8 +974,9 @@ discard block |
||
925 | 974 | global $smcFunc; |
926 | 975 | |
927 | 976 | // It was already short enough! |
928 | - if ($smcFunc['strlen']($subject) <= $len) |
|
929 | - return $subject; |
|
977 | + if ($smcFunc['strlen']($subject) <= $len) { |
|
978 | + return $subject; |
|
979 | + } |
|
930 | 980 | |
931 | 981 | // Shorten it by the length it was too long, and strip off junk from the end. |
932 | 982 | return $smcFunc['substr']($subject, 0, $len) . '...'; |
@@ -945,10 +995,11 @@ discard block |
||
945 | 995 | { |
946 | 996 | global $user_info, $modSettings; |
947 | 997 | |
948 | - if ($timestamp === null) |
|
949 | - $timestamp = time(); |
|
950 | - elseif ($timestamp == 0) |
|
951 | - return 0; |
|
998 | + if ($timestamp === null) { |
|
999 | + $timestamp = time(); |
|
1000 | + } elseif ($timestamp == 0) { |
|
1001 | + return 0; |
|
1002 | + } |
|
952 | 1003 | |
953 | 1004 | return $timestamp + ($modSettings['time_offset'] + ($use_user_offset ? $user_info['time_offset'] : 0)) * 3600; |
954 | 1005 | } |
@@ -977,8 +1028,9 @@ discard block |
||
977 | 1028 | $array[$i] = $array[$j]; |
978 | 1029 | $array[$j] = $temp; |
979 | 1030 | |
980 | - for ($i = 1; $p[$i] == 0; $i++) |
|
981 | - $p[$i] = 1; |
|
1031 | + for ($i = 1; $p[$i] == 0; $i++) { |
|
1032 | + $p[$i] = 1; |
|
1033 | + } |
|
982 | 1034 | |
983 | 1035 | $orders[] = $array; |
984 | 1036 | } |
@@ -1010,12 +1062,14 @@ discard block |
||
1010 | 1062 | static $disabled; |
1011 | 1063 | |
1012 | 1064 | // Don't waste cycles |
1013 | - if ($message === '') |
|
1014 | - return ''; |
|
1065 | + if ($message === '') { |
|
1066 | + return ''; |
|
1067 | + } |
|
1015 | 1068 | |
1016 | 1069 | // Just in case it wasn't determined yet whether UTF-8 is enabled. |
1017 | - if (!isset($context['utf8'])) |
|
1018 | - $context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8'; |
|
1070 | + if (!isset($context['utf8'])) { |
|
1071 | + $context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8'; |
|
1072 | + } |
|
1019 | 1073 | |
1020 | 1074 | // Clean up any cut/paste issues we may have |
1021 | 1075 | $message = sanitizeMSCutPaste($message); |
@@ -1027,13 +1081,15 @@ discard block |
||
1027 | 1081 | return $message; |
1028 | 1082 | } |
1029 | 1083 | |
1030 | - if ($smileys !== null && ($smileys == '1' || $smileys == '0')) |
|
1031 | - $smileys = (bool) $smileys; |
|
1084 | + if ($smileys !== null && ($smileys == '1' || $smileys == '0')) { |
|
1085 | + $smileys = (bool) $smileys; |
|
1086 | + } |
|
1032 | 1087 | |
1033 | 1088 | if (empty($modSettings['enableBBC']) && $message !== false) |
1034 | 1089 | { |
1035 | - if ($smileys === true) |
|
1036 | - parsesmileys($message); |
|
1090 | + if ($smileys === true) { |
|
1091 | + parsesmileys($message); |
|
1092 | + } |
|
1037 | 1093 | |
1038 | 1094 | return $message; |
1039 | 1095 | } |
@@ -1046,8 +1102,9 @@ discard block |
||
1046 | 1102 | } |
1047 | 1103 | |
1048 | 1104 | // Ensure $modSettings['tld_regex'] contains a valid regex for the autolinker |
1049 | - if (!empty($modSettings['autoLinkUrls'])) |
|
1050 | - set_tld_regex(); |
|
1105 | + if (!empty($modSettings['autoLinkUrls'])) { |
|
1106 | + set_tld_regex(); |
|
1107 | + } |
|
1051 | 1108 | |
1052 | 1109 | // Allow mods access before entering the main parse_bbc loop |
1053 | 1110 | call_integration_hook('integrate_pre_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags)); |
@@ -1061,12 +1118,14 @@ discard block |
||
1061 | 1118 | |
1062 | 1119 | $temp = explode(',', strtolower($modSettings['disabledBBC'])); |
1063 | 1120 | |
1064 | - foreach ($temp as $tag) |
|
1065 | - $disabled[trim($tag)] = true; |
|
1121 | + foreach ($temp as $tag) { |
|
1122 | + $disabled[trim($tag)] = true; |
|
1123 | + } |
|
1066 | 1124 | } |
1067 | 1125 | |
1068 | - if (empty($modSettings['enableEmbeddedFlash'])) |
|
1069 | - $disabled['flash'] = true; |
|
1126 | + if (empty($modSettings['enableEmbeddedFlash'])) { |
|
1127 | + $disabled['flash'] = true; |
|
1128 | + } |
|
1070 | 1129 | |
1071 | 1130 | /* The following bbc are formatted as an array, with keys as follows: |
1072 | 1131 | |
@@ -1187,8 +1246,9 @@ discard block |
||
1187 | 1246 | $returnContext = ''; |
1188 | 1247 | |
1189 | 1248 | // BBC or the entire attachments feature is disabled |
1190 | - if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) |
|
1191 | - return $data; |
|
1249 | + if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) { |
|
1250 | + return $data; |
|
1251 | + } |
|
1192 | 1252 | |
1193 | 1253 | // Save the attach ID. |
1194 | 1254 | $attachID = $data; |
@@ -1199,8 +1259,9 @@ discard block |
||
1199 | 1259 | $currentAttachment = parseAttachBBC($attachID); |
1200 | 1260 | |
1201 | 1261 | // parseAttachBBC will return a string ($txt key) rather than diying with a fatal_error. Up to you to decide what to do. |
1202 | - if (is_string($currentAttachment)) |
|
1203 | - return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment; |
|
1262 | + if (is_string($currentAttachment)) { |
|
1263 | + return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment; |
|
1264 | + } |
|
1204 | 1265 | |
1205 | 1266 | if (!empty($currentAttachment['is_image'])) |
1206 | 1267 | { |
@@ -1216,15 +1277,17 @@ discard block |
||
1216 | 1277 | $height = ' height="' . $currentAttachment['height'] . '"'; |
1217 | 1278 | } |
1218 | 1279 | |
1219 | - if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) |
|
1220 | - $returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>'; |
|
1221 | - else |
|
1222 | - $returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>'; |
|
1280 | + if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) { |
|
1281 | + $returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>'; |
|
1282 | + } else { |
|
1283 | + $returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>'; |
|
1284 | + } |
|
1223 | 1285 | } |
1224 | 1286 | |
1225 | 1287 | // No image. Show a link. |
1226 | - else |
|
1227 | - $returnContext .= $currentAttachment['link']; |
|
1288 | + else { |
|
1289 | + $returnContext .= $currentAttachment['link']; |
|
1290 | + } |
|
1228 | 1291 | |
1229 | 1292 | // Gotta append what we just did. |
1230 | 1293 | $data = $returnContext; |
@@ -1255,8 +1318,9 @@ discard block |
||
1255 | 1318 | for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++) |
1256 | 1319 | { |
1257 | 1320 | // Do PHP code coloring? |
1258 | - if ($php_parts[$php_i] != '<?php') |
|
1259 | - continue; |
|
1321 | + if ($php_parts[$php_i] != '<?php') { |
|
1322 | + continue; |
|
1323 | + } |
|
1260 | 1324 | |
1261 | 1325 | $php_string = ''; |
1262 | 1326 | while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?>') |
@@ -1272,8 +1336,9 @@ discard block |
||
1272 | 1336 | $data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data); |
1273 | 1337 | |
1274 | 1338 | // Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection. |
1275 | - if ($context['browser']['is_opera']) |
|
1276 | - $data .= ' '; |
|
1339 | + if ($context['browser']['is_opera']) { |
|
1340 | + $data .= ' '; |
|
1341 | + } |
|
1277 | 1342 | } |
1278 | 1343 | }, |
1279 | 1344 | 'block_level' => true, |
@@ -1292,8 +1357,9 @@ discard block |
||
1292 | 1357 | for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++) |
1293 | 1358 | { |
1294 | 1359 | // Do PHP code coloring? |
1295 | - if ($php_parts[$php_i] != '<?php') |
|
1296 | - continue; |
|
1360 | + if ($php_parts[$php_i] != '<?php') { |
|
1361 | + continue; |
|
1362 | + } |
|
1297 | 1363 | |
1298 | 1364 | $php_string = ''; |
1299 | 1365 | while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?>') |
@@ -1309,8 +1375,9 @@ discard block |
||
1309 | 1375 | $data[0] = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data[0]); |
1310 | 1376 | |
1311 | 1377 | // Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection. |
1312 | - if ($context['browser']['is_opera']) |
|
1313 | - $data[0] .= ' '; |
|
1378 | + if ($context['browser']['is_opera']) { |
|
1379 | + $data[0] .= ' '; |
|
1380 | + } |
|
1314 | 1381 | } |
1315 | 1382 | }, |
1316 | 1383 | 'block_level' => true, |
@@ -1348,11 +1415,13 @@ discard block |
||
1348 | 1415 | 'content' => '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never">', |
1349 | 1416 | 'validate' => function (&$tag, &$data, $disabled) |
1350 | 1417 | { |
1351 | - if (isset($disabled['url'])) |
|
1352 | - $tag['content'] = '$1'; |
|
1418 | + if (isset($disabled['url'])) { |
|
1419 | + $tag['content'] = '$1'; |
|
1420 | + } |
|
1353 | 1421 | $scheme = parse_url($data[0], PHP_URL_SCHEME); |
1354 | - if (empty($scheme)) |
|
1355 | - $data[0] = '//' . ltrim($data[0], ':/'); |
|
1422 | + if (empty($scheme)) { |
|
1423 | + $data[0] = '//' . ltrim($data[0], ':/'); |
|
1424 | + } |
|
1356 | 1425 | }, |
1357 | 1426 | 'disabled_content' => '<a href="$1" target="_blank" rel="noopener">$1</a>', |
1358 | 1427 | ), |
@@ -1366,10 +1435,11 @@ discard block |
||
1366 | 1435 | { |
1367 | 1436 | $class = 'class="bbc_float float' . (strpos($data, 'left') === 0 ? 'left' : 'right') . '"'; |
1368 | 1437 | |
1369 | - if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches)) |
|
1370 | - $css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"'; |
|
1371 | - else |
|
1372 | - $css = ''; |
|
1438 | + if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches)) { |
|
1439 | + $css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"'; |
|
1440 | + } else { |
|
1441 | + $css = ''; |
|
1442 | + } |
|
1373 | 1443 | |
1374 | 1444 | $data = $class . $css; |
1375 | 1445 | }, |
@@ -1419,17 +1489,20 @@ discard block |
||
1419 | 1489 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1420 | 1490 | if ($image_proxy_enabled) |
1421 | 1491 | { |
1422 | - if (!empty($user_info['possibly_robot'])) |
|
1423 | - return; |
|
1492 | + if (!empty($user_info['possibly_robot'])) { |
|
1493 | + return; |
|
1494 | + } |
|
1424 | 1495 | |
1425 | - if (empty($scheme)) |
|
1426 | - $data = 'http://' . ltrim($data, ':/'); |
|
1496 | + if (empty($scheme)) { |
|
1497 | + $data = 'http://' . ltrim($data, ':/'); |
|
1498 | + } |
|
1427 | 1499 | |
1428 | - if ($scheme != 'https') |
|
1429 | - $data = get_proxied_url($data); |
|
1500 | + if ($scheme != 'https') { |
|
1501 | + $data = get_proxied_url($data); |
|
1502 | + } |
|
1503 | + } elseif (empty($scheme)) { |
|
1504 | + $data = '//' . ltrim($data, ':/'); |
|
1430 | 1505 | } |
1431 | - elseif (empty($scheme)) |
|
1432 | - $data = '//' . ltrim($data, ':/'); |
|
1433 | 1506 | }, |
1434 | 1507 | 'disabled_content' => '($1)', |
1435 | 1508 | ), |
@@ -1445,17 +1518,20 @@ discard block |
||
1445 | 1518 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1446 | 1519 | if ($image_proxy_enabled) |
1447 | 1520 | { |
1448 | - if (!empty($user_info['possibly_robot'])) |
|
1449 | - return; |
|
1521 | + if (!empty($user_info['possibly_robot'])) { |
|
1522 | + return; |
|
1523 | + } |
|
1450 | 1524 | |
1451 | - if (empty($scheme)) |
|
1452 | - $data = 'http://' . ltrim($data, ':/'); |
|
1525 | + if (empty($scheme)) { |
|
1526 | + $data = 'http://' . ltrim($data, ':/'); |
|
1527 | + } |
|
1453 | 1528 | |
1454 | - if ($scheme != 'https') |
|
1455 | - $data = get_proxied_url($data); |
|
1529 | + if ($scheme != 'https') { |
|
1530 | + $data = get_proxied_url($data); |
|
1531 | + } |
|
1532 | + } elseif (empty($scheme)) { |
|
1533 | + $data = '//' . ltrim($data, ':/'); |
|
1456 | 1534 | } |
1457 | - elseif (empty($scheme)) |
|
1458 | - $data = '//' . ltrim($data, ':/'); |
|
1459 | 1535 | }, |
1460 | 1536 | 'disabled_content' => '($1)', |
1461 | 1537 | ), |
@@ -1467,8 +1543,9 @@ discard block |
||
1467 | 1543 | { |
1468 | 1544 | $data = strtr($data, array('<br>' => '')); |
1469 | 1545 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1470 | - if (empty($scheme)) |
|
1471 | - $data = '//' . ltrim($data, ':/'); |
|
1546 | + if (empty($scheme)) { |
|
1547 | + $data = '//' . ltrim($data, ':/'); |
|
1548 | + } |
|
1472 | 1549 | }, |
1473 | 1550 | ), |
1474 | 1551 | array( |
@@ -1479,13 +1556,14 @@ discard block |
||
1479 | 1556 | 'after' => '</a>', |
1480 | 1557 | 'validate' => function (&$tag, &$data, $disabled) |
1481 | 1558 | { |
1482 | - if (substr($data, 0, 1) == '#') |
|
1483 | - $data = '#post_' . substr($data, 1); |
|
1484 | - else |
|
1559 | + if (substr($data, 0, 1) == '#') { |
|
1560 | + $data = '#post_' . substr($data, 1); |
|
1561 | + } else |
|
1485 | 1562 | { |
1486 | 1563 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1487 | - if (empty($scheme)) |
|
1488 | - $data = '//' . ltrim($data, ':/'); |
|
1564 | + if (empty($scheme)) { |
|
1565 | + $data = '//' . ltrim($data, ':/'); |
|
1566 | + } |
|
1489 | 1567 | } |
1490 | 1568 | }, |
1491 | 1569 | 'disallow_children' => array('email', 'ftp', 'url', 'iurl'), |
@@ -1569,8 +1647,9 @@ discard block |
||
1569 | 1647 | { |
1570 | 1648 | $add_begin = substr(trim($data), 0, 5) != '<?'; |
1571 | 1649 | $data = highlight_php_code($add_begin ? '<?php ' . $data . '?>' : $data); |
1572 | - if ($add_begin) |
|
1573 | - $data = preg_replace(array('~^(.+?)<\?.{0,40}?php(?: |\s)~', '~\?>((?:</(font|span)>)*)$~'), '$1', $data, 2); |
|
1650 | + if ($add_begin) { |
|
1651 | + $data = preg_replace(array('~^(.+?)<\?.{0,40}?php(?: |\s)~', '~\?>((?:</(font|span)>)*)$~'), '$1', $data, 2); |
|
1652 | + } |
|
1574 | 1653 | } |
1575 | 1654 | }, |
1576 | 1655 | 'block_level' => false, |
@@ -1701,10 +1780,11 @@ discard block |
||
1701 | 1780 | 'content' => '$1', |
1702 | 1781 | 'validate' => function (&$tag, &$data, $disabled) |
1703 | 1782 | { |
1704 | - if (is_numeric($data)) |
|
1705 | - $data = timeformat($data); |
|
1706 | - else |
|
1707 | - $tag['content'] = '[time]$1[/time]'; |
|
1783 | + if (is_numeric($data)) { |
|
1784 | + $data = timeformat($data); |
|
1785 | + } else { |
|
1786 | + $tag['content'] = '[time]$1[/time]'; |
|
1787 | + } |
|
1708 | 1788 | }, |
1709 | 1789 | ), |
1710 | 1790 | array( |
@@ -1731,8 +1811,9 @@ discard block |
||
1731 | 1811 | { |
1732 | 1812 | $data = strtr($data, array('<br>' => '')); |
1733 | 1813 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1734 | - if (empty($scheme)) |
|
1735 | - $data = '//' . ltrim($data, ':/'); |
|
1814 | + if (empty($scheme)) { |
|
1815 | + $data = '//' . ltrim($data, ':/'); |
|
1816 | + } |
|
1736 | 1817 | }, |
1737 | 1818 | ), |
1738 | 1819 | array( |
@@ -1744,8 +1825,9 @@ discard block |
||
1744 | 1825 | 'validate' => function (&$tag, &$data, $disabled) |
1745 | 1826 | { |
1746 | 1827 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1747 | - if (empty($scheme)) |
|
1748 | - $data = '//' . ltrim($data, ':/'); |
|
1828 | + if (empty($scheme)) { |
|
1829 | + $data = '//' . ltrim($data, ':/'); |
|
1830 | + } |
|
1749 | 1831 | }, |
1750 | 1832 | 'disallow_children' => array('email', 'ftp', 'url', 'iurl'), |
1751 | 1833 | 'disabled_after' => ' ($1)', |
@@ -1771,8 +1853,9 @@ discard block |
||
1771 | 1853 | // This is mainly for the bbc manager, so it's easy to add tags above. Custom BBC should be added above this line. |
1772 | 1854 | if ($message === false) |
1773 | 1855 | { |
1774 | - if (isset($temp_bbc)) |
|
1775 | - $bbc_codes = $temp_bbc; |
|
1856 | + if (isset($temp_bbc)) { |
|
1857 | + $bbc_codes = $temp_bbc; |
|
1858 | + } |
|
1776 | 1859 | usort($codes, function ($a, $b) { |
1777 | 1860 | return strcmp($a['tag'], $b['tag']); |
1778 | 1861 | }); |
@@ -1792,8 +1875,9 @@ discard block |
||
1792 | 1875 | ); |
1793 | 1876 | if (!isset($disabled['li']) && !isset($disabled['list'])) |
1794 | 1877 | { |
1795 | - foreach ($itemcodes as $c => $dummy) |
|
1796 | - $bbc_codes[$c] = array(); |
|
1878 | + foreach ($itemcodes as $c => $dummy) { |
|
1879 | + $bbc_codes[$c] = array(); |
|
1880 | + } |
|
1797 | 1881 | } |
1798 | 1882 | |
1799 | 1883 | // Shhhh! |
@@ -1814,12 +1898,14 @@ discard block |
||
1814 | 1898 | foreach ($codes as $code) |
1815 | 1899 | { |
1816 | 1900 | // Make it easier to process parameters later |
1817 | - if (!empty($code['parameters'])) |
|
1818 | - ksort($code['parameters'], SORT_STRING); |
|
1901 | + if (!empty($code['parameters'])) { |
|
1902 | + ksort($code['parameters'], SORT_STRING); |
|
1903 | + } |
|
1819 | 1904 | |
1820 | 1905 | // If we are not doing every tag only do ones we are interested in. |
1821 | - if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) |
|
1822 | - $bbc_codes[substr($code['tag'], 0, 1)][] = $code; |
|
1906 | + if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) { |
|
1907 | + $bbc_codes[substr($code['tag'], 0, 1)][] = $code; |
|
1908 | + } |
|
1823 | 1909 | } |
1824 | 1910 | $codes = null; |
1825 | 1911 | } |
@@ -1830,8 +1916,9 @@ discard block |
||
1830 | 1916 | // It's likely this will change if the message is modified. |
1831 | 1917 | $cache_key = 'parse:' . $cache_id . '-' . md5(md5($message) . '-' . $smileys . (empty($disabled) ? '' : implode(',', array_keys($disabled))) . $smcFunc['json_encode']($context['browser']) . $txt['lang_locale'] . $user_info['time_offset'] . $user_info['time_format']); |
1832 | 1918 | |
1833 | - if (($temp = cache_get_data($cache_key, 240)) != null) |
|
1834 | - return $temp; |
|
1919 | + if (($temp = cache_get_data($cache_key, 240)) != null) { |
|
1920 | + return $temp; |
|
1921 | + } |
|
1835 | 1922 | |
1836 | 1923 | $cache_t = microtime(); |
1837 | 1924 | } |
@@ -1863,8 +1950,9 @@ discard block |
||
1863 | 1950 | $disabled['flash'] = true; |
1864 | 1951 | |
1865 | 1952 | // @todo Change maybe? |
1866 | - if (!isset($_GET['images'])) |
|
1867 | - $disabled['img'] = true; |
|
1953 | + if (!isset($_GET['images'])) { |
|
1954 | + $disabled['img'] = true; |
|
1955 | + } |
|
1868 | 1956 | |
1869 | 1957 | // @todo Interface/setting to add more? |
1870 | 1958 | } |
@@ -1888,8 +1976,9 @@ discard block |
||
1888 | 1976 | $pos = isset($matches[0][1]) ? $matches[0][1] : false; |
1889 | 1977 | |
1890 | 1978 | // Failsafe. |
1891 | - if ($pos === false || $last_pos > $pos) |
|
1892 | - $pos = strlen($message) + 1; |
|
1979 | + if ($pos === false || $last_pos > $pos) { |
|
1980 | + $pos = strlen($message) + 1; |
|
1981 | + } |
|
1893 | 1982 | |
1894 | 1983 | // Can't have a one letter smiley, URL, or email! (sorry.) |
1895 | 1984 | if ($last_pos < $pos - 1) |
@@ -1907,8 +1996,9 @@ discard block |
||
1907 | 1996 | |
1908 | 1997 | // <br> should be empty. |
1909 | 1998 | $empty_tags = array('br', 'hr'); |
1910 | - foreach ($empty_tags as $tag) |
|
1911 | - $data = str_replace(array('<' . $tag . '>', '<' . $tag . '/>', '<' . $tag . ' />'), '<' . $tag . '>', $data); |
|
1999 | + foreach ($empty_tags as $tag) { |
|
2000 | + $data = str_replace(array('<' . $tag . '>', '<' . $tag . '/>', '<' . $tag . ' />'), '<' . $tag . '>', $data); |
|
2001 | + } |
|
1912 | 2002 | |
1913 | 2003 | // b, u, i, s, pre... basic tags. |
1914 | 2004 | $closable_tags = array('b', 'u', 'i', 's', 'em', 'ins', 'del', 'pre', 'blockquote', 'strong'); |
@@ -1917,8 +2007,9 @@ discard block |
||
1917 | 2007 | $diff = substr_count($data, '<' . $tag . '>') - substr_count($data, '</' . $tag . '>'); |
1918 | 2008 | $data = strtr($data, array('<' . $tag . '>' => '<' . $tag . '>', '</' . $tag . '>' => '</' . $tag . '>')); |
1919 | 2009 | |
1920 | - if ($diff > 0) |
|
1921 | - $data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1); |
|
2010 | + if ($diff > 0) { |
|
2011 | + $data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1); |
|
2012 | + } |
|
1922 | 2013 | } |
1923 | 2014 | |
1924 | 2015 | // Do <img ...> - with security... action= -> action-. |
@@ -1931,8 +2022,9 @@ discard block |
||
1931 | 2022 | $alt = empty($matches[3][$match]) ? '' : ' alt=' . preg_replace('~^"|"$~', '', $matches[3][$match]); |
1932 | 2023 | |
1933 | 2024 | // Remove action= from the URL - no funny business, now. |
1934 | - if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) |
|
1935 | - $imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag); |
|
2025 | + if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) { |
|
2026 | + $imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag); |
|
2027 | + } |
|
1936 | 2028 | |
1937 | 2029 | $replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]'; |
1938 | 2030 | } |
@@ -1947,16 +2039,18 @@ discard block |
||
1947 | 2039 | $no_autolink_area = false; |
1948 | 2040 | if (!empty($open_tags)) |
1949 | 2041 | { |
1950 | - foreach ($open_tags as $open_tag) |
|
1951 | - if (in_array($open_tag['tag'], $no_autolink_tags)) |
|
2042 | + foreach ($open_tags as $open_tag) { |
|
2043 | + if (in_array($open_tag['tag'], $no_autolink_tags)) |
|
1952 | 2044 | $no_autolink_area = true; |
2045 | + } |
|
1953 | 2046 | } |
1954 | 2047 | |
1955 | 2048 | // Don't go backwards. |
1956 | 2049 | // @todo Don't think is the real solution.... |
1957 | 2050 | $lastAutoPos = isset($lastAutoPos) ? $lastAutoPos : 0; |
1958 | - if ($pos < $lastAutoPos) |
|
1959 | - $no_autolink_area = true; |
|
2051 | + if ($pos < $lastAutoPos) { |
|
2052 | + $no_autolink_area = true; |
|
2053 | + } |
|
1960 | 2054 | $lastAutoPos = $pos; |
1961 | 2055 | |
1962 | 2056 | if (!$no_autolink_area) |
@@ -2061,29 +2155,33 @@ discard block |
||
2061 | 2155 | $url = array_shift($matches); |
2062 | 2156 | |
2063 | 2157 | // If this isn't a clean URL, bail out |
2064 | - if ($url != sanitize_iri($url)) |
|
2065 | - return $url; |
|
2158 | + if ($url != sanitize_iri($url)) { |
|
2159 | + return $url; |
|
2160 | + } |
|
2066 | 2161 | |
2067 | 2162 | $scheme = parse_url($url, PHP_URL_SCHEME); |
2068 | 2163 | |
2069 | 2164 | if ($scheme == 'mailto') |
2070 | 2165 | { |
2071 | 2166 | $email_address = str_replace('mailto:', '', $url); |
2072 | - if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) |
|
2073 | - return '[email=' . $email_address . ']' . $url . '[/email]'; |
|
2074 | - else |
|
2075 | - return $url; |
|
2167 | + if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) { |
|
2168 | + return '[email=' . $email_address . ']' . $url . '[/email]'; |
|
2169 | + } else { |
|
2170 | + return $url; |
|
2171 | + } |
|
2076 | 2172 | } |
2077 | 2173 | |
2078 | 2174 | // Are we linking a schemeless URL or naked domain name (e.g. "example.com")? |
2079 | - if (empty($scheme)) |
|
2080 | - $fullUrl = '//' . ltrim($url, ':/'); |
|
2081 | - else |
|
2082 | - $fullUrl = $url; |
|
2175 | + if (empty($scheme)) { |
|
2176 | + $fullUrl = '//' . ltrim($url, ':/'); |
|
2177 | + } else { |
|
2178 | + $fullUrl = $url; |
|
2179 | + } |
|
2083 | 2180 | |
2084 | 2181 | // Make sure that $fullUrl really is valid |
2085 | - if (validate_iri((strpos($fullUrl, '//') === 0 ? 'http:' : '' ) . $fullUrl) === false) |
|
2086 | - return $url; |
|
2182 | + if (validate_iri((strpos($fullUrl, '//') === 0 ? 'http:' : '' ) . $fullUrl) === false) { |
|
2183 | + return $url; |
|
2184 | + } |
|
2087 | 2185 | |
2088 | 2186 | return '[url="' . str_replace(array('[', ']'), array('[', ']'), $fullUrl) . '"]' . $url . '[/url]'; |
2089 | 2187 | }, $data); |
@@ -2132,22 +2230,25 @@ discard block |
||
2132 | 2230 | } |
2133 | 2231 | |
2134 | 2232 | // Are we there yet? Are we there yet? |
2135 | - if ($pos >= strlen($message) - 1) |
|
2136 | - break; |
|
2233 | + if ($pos >= strlen($message) - 1) { |
|
2234 | + break; |
|
2235 | + } |
|
2137 | 2236 | |
2138 | 2237 | $tags = strtolower($message[$pos + 1]); |
2139 | 2238 | |
2140 | 2239 | if ($tags == '/' && !empty($open_tags)) |
2141 | 2240 | { |
2142 | 2241 | $pos2 = strpos($message, ']', $pos + 1); |
2143 | - if ($pos2 == $pos + 2) |
|
2144 | - continue; |
|
2242 | + if ($pos2 == $pos + 2) { |
|
2243 | + continue; |
|
2244 | + } |
|
2145 | 2245 | |
2146 | 2246 | $look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2)); |
2147 | 2247 | |
2148 | 2248 | // A closing tag that doesn't match any open tags? Skip it. |
2149 | - if (!in_array($look_for, array_map(function($code){return $code['tag'];}, $open_tags))) |
|
2150 | - continue; |
|
2249 | + if (!in_array($look_for, array_map(function($code){return $code['tag'];}, $open_tags))) { |
|
2250 | + continue; |
|
2251 | + } |
|
2151 | 2252 | |
2152 | 2253 | $to_close = array(); |
2153 | 2254 | $block_level = null; |
@@ -2155,8 +2256,9 @@ discard block |
||
2155 | 2256 | do |
2156 | 2257 | { |
2157 | 2258 | $tag = array_pop($open_tags); |
2158 | - if (!$tag) |
|
2159 | - break; |
|
2259 | + if (!$tag) { |
|
2260 | + break; |
|
2261 | + } |
|
2160 | 2262 | |
2161 | 2263 | if (!empty($tag['block_level'])) |
2162 | 2264 | { |
@@ -2170,10 +2272,11 @@ discard block |
||
2170 | 2272 | // The idea is, if we are LOOKING for a block level tag, we can close them on the way. |
2171 | 2273 | if (strlen($look_for) > 0 && isset($bbc_codes[$look_for[0]])) |
2172 | 2274 | { |
2173 | - foreach ($bbc_codes[$look_for[0]] as $temp) |
|
2174 | - if ($temp['tag'] == $look_for) |
|
2275 | + foreach ($bbc_codes[$look_for[0]] as $temp) { |
|
2276 | + if ($temp['tag'] == $look_for) |
|
2175 | 2277 | { |
2176 | 2278 | $block_level = !empty($temp['block_level']); |
2279 | + } |
|
2177 | 2280 | break; |
2178 | 2281 | } |
2179 | 2282 | } |
@@ -2195,15 +2298,15 @@ discard block |
||
2195 | 2298 | { |
2196 | 2299 | $open_tags = $to_close; |
2197 | 2300 | continue; |
2198 | - } |
|
2199 | - elseif (!empty($to_close) && $tag['tag'] != $look_for) |
|
2301 | + } elseif (!empty($to_close) && $tag['tag'] != $look_for) |
|
2200 | 2302 | { |
2201 | 2303 | if ($block_level === null && isset($look_for[0], $bbc_codes[$look_for[0]])) |
2202 | 2304 | { |
2203 | - foreach ($bbc_codes[$look_for[0]] as $temp) |
|
2204 | - if ($temp['tag'] == $look_for) |
|
2305 | + foreach ($bbc_codes[$look_for[0]] as $temp) { |
|
2306 | + if ($temp['tag'] == $look_for) |
|
2205 | 2307 | { |
2206 | 2308 | $block_level = !empty($temp['block_level']); |
2309 | + } |
|
2207 | 2310 | break; |
2208 | 2311 | } |
2209 | 2312 | } |
@@ -2211,8 +2314,9 @@ discard block |
||
2211 | 2314 | // We're not looking for a block level tag (or maybe even a tag that exists...) |
2212 | 2315 | if (!$block_level) |
2213 | 2316 | { |
2214 | - foreach ($to_close as $tag) |
|
2215 | - array_push($open_tags, $tag); |
|
2317 | + foreach ($to_close as $tag) { |
|
2318 | + array_push($open_tags, $tag); |
|
2319 | + } |
|
2216 | 2320 | continue; |
2217 | 2321 | } |
2218 | 2322 | } |
@@ -2225,14 +2329,17 @@ discard block |
||
2225 | 2329 | |
2226 | 2330 | // See the comment at the end of the big loop - just eating whitespace ;). |
2227 | 2331 | $whitespace_regex = ''; |
2228 | - if (!empty($tag['block_level'])) |
|
2229 | - $whitespace_regex .= '( |\s)*(<br>)?'; |
|
2332 | + if (!empty($tag['block_level'])) { |
|
2333 | + $whitespace_regex .= '( |\s)*(<br>)?'; |
|
2334 | + } |
|
2230 | 2335 | // Trim one line of whitespace after unnested tags, but all of it after nested ones |
2231 | - if (!empty($tag['trim']) && $tag['trim'] != 'inside') |
|
2232 | - $whitespace_regex .= empty($tag['require_parents']) ? '( |\s)*' : '(<br>| |\s)*'; |
|
2336 | + if (!empty($tag['trim']) && $tag['trim'] != 'inside') { |
|
2337 | + $whitespace_regex .= empty($tag['require_parents']) ? '( |\s)*' : '(<br>| |\s)*'; |
|
2338 | + } |
|
2233 | 2339 | |
2234 | - if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) |
|
2235 | - $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
2340 | + if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) { |
|
2341 | + $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
2342 | + } |
|
2236 | 2343 | } |
2237 | 2344 | |
2238 | 2345 | if (!empty($to_close)) |
@@ -2245,8 +2352,9 @@ discard block |
||
2245 | 2352 | } |
2246 | 2353 | |
2247 | 2354 | // No tags for this character, so just keep going (fastest possible course.) |
2248 | - if (!isset($bbc_codes[$tags])) |
|
2249 | - continue; |
|
2355 | + if (!isset($bbc_codes[$tags])) { |
|
2356 | + continue; |
|
2357 | + } |
|
2250 | 2358 | |
2251 | 2359 | $inside = empty($open_tags) ? null : $open_tags[count($open_tags) - 1]; |
2252 | 2360 | $tag = null; |
@@ -2255,48 +2363,57 @@ discard block |
||
2255 | 2363 | $pt_strlen = strlen($possible['tag']); |
2256 | 2364 | |
2257 | 2365 | // Not a match? |
2258 | - if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) |
|
2259 | - continue; |
|
2366 | + if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) { |
|
2367 | + continue; |
|
2368 | + } |
|
2260 | 2369 | |
2261 | 2370 | $next_c = isset($message[$pos + 1 + $pt_strlen]) ? $message[$pos + 1 + $pt_strlen] : ''; |
2262 | 2371 | |
2263 | 2372 | // A tag is the last char maybe |
2264 | - if ($next_c == '') |
|
2265 | - break; |
|
2373 | + if ($next_c == '') { |
|
2374 | + break; |
|
2375 | + } |
|
2266 | 2376 | |
2267 | 2377 | // A test validation? |
2268 | - if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) |
|
2269 | - continue; |
|
2378 | + if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) { |
|
2379 | + continue; |
|
2380 | + } |
|
2270 | 2381 | // Do we want parameters? |
2271 | 2382 | elseif (!empty($possible['parameters'])) |
2272 | 2383 | { |
2273 | - if ($next_c != ' ') |
|
2274 | - continue; |
|
2275 | - } |
|
2276 | - elseif (isset($possible['type'])) |
|
2384 | + if ($next_c != ' ') { |
|
2385 | + continue; |
|
2386 | + } |
|
2387 | + } elseif (isset($possible['type'])) |
|
2277 | 2388 | { |
2278 | 2389 | // Do we need an equal sign? |
2279 | - if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') |
|
2280 | - continue; |
|
2390 | + if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') { |
|
2391 | + continue; |
|
2392 | + } |
|
2281 | 2393 | // Maybe we just want a /... |
2282 | - if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') |
|
2283 | - continue; |
|
2394 | + if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') { |
|
2395 | + continue; |
|
2396 | + } |
|
2284 | 2397 | // An immediate ]? |
2285 | - if ($possible['type'] == 'unparsed_content' && $next_c != ']') |
|
2286 | - continue; |
|
2398 | + if ($possible['type'] == 'unparsed_content' && $next_c != ']') { |
|
2399 | + continue; |
|
2400 | + } |
|
2287 | 2401 | } |
2288 | 2402 | // No type means 'parsed_content', which demands an immediate ] without parameters! |
2289 | - elseif ($next_c != ']') |
|
2290 | - continue; |
|
2403 | + elseif ($next_c != ']') { |
|
2404 | + continue; |
|
2405 | + } |
|
2291 | 2406 | |
2292 | 2407 | // Check allowed tree? |
2293 | - if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) |
|
2294 | - continue; |
|
2295 | - elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) |
|
2296 | - continue; |
|
2408 | + if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) { |
|
2409 | + continue; |
|
2410 | + } elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) { |
|
2411 | + continue; |
|
2412 | + } |
|
2297 | 2413 | // If this is in the list of disallowed child tags, don't parse it. |
2298 | - elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) |
|
2299 | - continue; |
|
2414 | + elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) { |
|
2415 | + continue; |
|
2416 | + } |
|
2300 | 2417 | |
2301 | 2418 | $pos1 = $pos + 1 + $pt_strlen + 1; |
2302 | 2419 | |
@@ -2308,8 +2425,9 @@ discard block |
||
2308 | 2425 | foreach ($open_tags as $open_quote) |
2309 | 2426 | { |
2310 | 2427 | // Every parent quote this quote has flips the styling |
2311 | - if ($open_quote['tag'] == 'quote') |
|
2312 | - $quote_alt = !$quote_alt; |
|
2428 | + if ($open_quote['tag'] == 'quote') { |
|
2429 | + $quote_alt = !$quote_alt; |
|
2430 | + } |
|
2313 | 2431 | } |
2314 | 2432 | // Add a class to the quote to style alternating blockquotes |
2315 | 2433 | $possible['before'] = strtr($possible['before'], array('<blockquote>' => '<blockquote class="bbc_' . ($quote_alt ? 'alternate' : 'standard') . '_quote">')); |
@@ -2320,8 +2438,9 @@ discard block |
||
2320 | 2438 | { |
2321 | 2439 | // Build a regular expression for each parameter for the current tag. |
2322 | 2440 | $preg = array(); |
2323 | - foreach ($possible['parameters'] as $p => $info) |
|
2324 | - $preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '"') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '"') . '\s*)' . (empty($info['optional']) ? '' : '?'); |
|
2441 | + foreach ($possible['parameters'] as $p => $info) { |
|
2442 | + $preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '"') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '"') . '\s*)' . (empty($info['optional']) ? '' : '?'); |
|
2443 | + } |
|
2325 | 2444 | |
2326 | 2445 | // Extract the string that potentially holds our parameters. |
2327 | 2446 | $blob = preg_split('~\[/?(?:' . $alltags_regex . ')~i', substr($message, $pos)); |
@@ -2341,24 +2460,27 @@ discard block |
||
2341 | 2460 | |
2342 | 2461 | $match = preg_match('~^' . implode('', $preg) . '$~i', implode(' ', $given_params), $matches) !== 0; |
2343 | 2462 | |
2344 | - if ($match) |
|
2345 | - $blob_counter = count($blobs) + 1; |
|
2463 | + if ($match) { |
|
2464 | + $blob_counter = count($blobs) + 1; |
|
2465 | + } |
|
2346 | 2466 | } |
2347 | 2467 | |
2348 | 2468 | // Didn't match our parameter list, try the next possible. |
2349 | - if (!$match) |
|
2350 | - continue; |
|
2469 | + if (!$match) { |
|
2470 | + continue; |
|
2471 | + } |
|
2351 | 2472 | |
2352 | 2473 | $params = array(); |
2353 | 2474 | for ($i = 1, $n = count($matches); $i < $n; $i += 2) |
2354 | 2475 | { |
2355 | 2476 | $key = strtok(ltrim($matches[$i]), '='); |
2356 | - if (isset($possible['parameters'][$key]['value'])) |
|
2357 | - $params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1])); |
|
2358 | - elseif (isset($possible['parameters'][$key]['validate'])) |
|
2359 | - $params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]); |
|
2360 | - else |
|
2361 | - $params['{' . $key . '}'] = $matches[$i + 1]; |
|
2477 | + if (isset($possible['parameters'][$key]['value'])) { |
|
2478 | + $params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1])); |
|
2479 | + } elseif (isset($possible['parameters'][$key]['validate'])) { |
|
2480 | + $params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]); |
|
2481 | + } else { |
|
2482 | + $params['{' . $key . '}'] = $matches[$i + 1]; |
|
2483 | + } |
|
2362 | 2484 | |
2363 | 2485 | // Just to make sure: replace any $ or { so they can't interpolate wrongly. |
2364 | 2486 | $params['{' . $key . '}'] = strtr($params['{' . $key . '}'], array('$' => '$', '{' => '{')); |
@@ -2366,23 +2488,26 @@ discard block |
||
2366 | 2488 | |
2367 | 2489 | foreach ($possible['parameters'] as $p => $info) |
2368 | 2490 | { |
2369 | - if (!isset($params['{' . $p . '}'])) |
|
2370 | - $params['{' . $p . '}'] = ''; |
|
2491 | + if (!isset($params['{' . $p . '}'])) { |
|
2492 | + $params['{' . $p . '}'] = ''; |
|
2493 | + } |
|
2371 | 2494 | } |
2372 | 2495 | |
2373 | 2496 | $tag = $possible; |
2374 | 2497 | |
2375 | 2498 | // Put the parameters into the string. |
2376 | - if (isset($tag['before'])) |
|
2377 | - $tag['before'] = strtr($tag['before'], $params); |
|
2378 | - if (isset($tag['after'])) |
|
2379 | - $tag['after'] = strtr($tag['after'], $params); |
|
2380 | - if (isset($tag['content'])) |
|
2381 | - $tag['content'] = strtr($tag['content'], $params); |
|
2499 | + if (isset($tag['before'])) { |
|
2500 | + $tag['before'] = strtr($tag['before'], $params); |
|
2501 | + } |
|
2502 | + if (isset($tag['after'])) { |
|
2503 | + $tag['after'] = strtr($tag['after'], $params); |
|
2504 | + } |
|
2505 | + if (isset($tag['content'])) { |
|
2506 | + $tag['content'] = strtr($tag['content'], $params); |
|
2507 | + } |
|
2382 | 2508 | |
2383 | 2509 | $pos1 += strlen($given_param_string); |
2384 | - } |
|
2385 | - else |
|
2510 | + } else |
|
2386 | 2511 | { |
2387 | 2512 | $tag = $possible; |
2388 | 2513 | $params = array(); |
@@ -2393,8 +2518,9 @@ discard block |
||
2393 | 2518 | // Item codes are complicated buggers... they are implicit [li]s and can make [list]s! |
2394 | 2519 | if ($smileys !== false && $tag === null && isset($itemcodes[$message[$pos + 1]]) && $message[$pos + 2] == ']' && !isset($disabled['list']) && !isset($disabled['li'])) |
2395 | 2520 | { |
2396 | - if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) |
|
2397 | - continue; |
|
2521 | + if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) { |
|
2522 | + continue; |
|
2523 | + } |
|
2398 | 2524 | |
2399 | 2525 | $tag = $itemcodes[$message[$pos + 1]]; |
2400 | 2526 | |
@@ -2415,9 +2541,9 @@ discard block |
||
2415 | 2541 | { |
2416 | 2542 | array_pop($open_tags); |
2417 | 2543 | $code = '</li>'; |
2544 | + } else { |
|
2545 | + $code = ''; |
|
2418 | 2546 | } |
2419 | - else |
|
2420 | - $code = ''; |
|
2421 | 2547 | |
2422 | 2548 | // Now we open a new tag. |
2423 | 2549 | $open_tags[] = array( |
@@ -2464,12 +2590,14 @@ discard block |
||
2464 | 2590 | } |
2465 | 2591 | |
2466 | 2592 | // No tag? Keep looking, then. Silly people using brackets without actual tags. |
2467 | - if ($tag === null) |
|
2468 | - continue; |
|
2593 | + if ($tag === null) { |
|
2594 | + continue; |
|
2595 | + } |
|
2469 | 2596 | |
2470 | 2597 | // Propagate the list to the child (so wrapping the disallowed tag won't work either.) |
2471 | - if (isset($inside['disallow_children'])) |
|
2472 | - $tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children']; |
|
2598 | + if (isset($inside['disallow_children'])) { |
|
2599 | + $tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children']; |
|
2600 | + } |
|
2473 | 2601 | |
2474 | 2602 | // Is this tag disabled? |
2475 | 2603 | if (isset($disabled[$tag['tag']])) |
@@ -2479,14 +2607,13 @@ discard block |
||
2479 | 2607 | $tag['before'] = !empty($tag['block_level']) ? '<div>' : ''; |
2480 | 2608 | $tag['after'] = !empty($tag['block_level']) ? '</div>' : ''; |
2481 | 2609 | $tag['content'] = isset($tag['type']) && $tag['type'] == 'closed' ? '' : (!empty($tag['block_level']) ? '<div>$1</div>' : '$1'); |
2482 | - } |
|
2483 | - elseif (isset($tag['disabled_before']) || isset($tag['disabled_after'])) |
|
2610 | + } elseif (isset($tag['disabled_before']) || isset($tag['disabled_after'])) |
|
2484 | 2611 | { |
2485 | 2612 | $tag['before'] = isset($tag['disabled_before']) ? $tag['disabled_before'] : (!empty($tag['block_level']) ? '<div>' : ''); |
2486 | 2613 | $tag['after'] = isset($tag['disabled_after']) ? $tag['disabled_after'] : (!empty($tag['block_level']) ? '</div>' : ''); |
2614 | + } else { |
|
2615 | + $tag['content'] = $tag['disabled_content']; |
|
2487 | 2616 | } |
2488 | - else |
|
2489 | - $tag['content'] = $tag['disabled_content']; |
|
2490 | 2617 | } |
2491 | 2618 | |
2492 | 2619 | // we use this a lot |
@@ -2496,8 +2623,9 @@ discard block |
||
2496 | 2623 | if (!empty($tag['block_level']) && $tag['tag'] != 'html' && empty($inside['block_level'])) |
2497 | 2624 | { |
2498 | 2625 | $n = count($open_tags) - 1; |
2499 | - while (empty($open_tags[$n]['block_level']) && $n >= 0) |
|
2500 | - $n--; |
|
2626 | + while (empty($open_tags[$n]['block_level']) && $n >= 0) { |
|
2627 | + $n--; |
|
2628 | + } |
|
2501 | 2629 | |
2502 | 2630 | // Close all the non block level tags so this tag isn't surrounded by them. |
2503 | 2631 | for ($i = count($open_tags) - 1; $i > $n; $i--) |
@@ -2509,12 +2637,15 @@ discard block |
||
2509 | 2637 | |
2510 | 2638 | // Trim or eat trailing stuff... see comment at the end of the big loop. |
2511 | 2639 | $whitespace_regex = ''; |
2512 | - if (!empty($tag['block_level'])) |
|
2513 | - $whitespace_regex .= '( |\s)*(<br>)?'; |
|
2514 | - if (!empty($tag['trim']) && $tag['trim'] != 'inside') |
|
2515 | - $whitespace_regex .= empty($tag['require_parents']) ? '( |\s)*' : '(<br>| |\s)*'; |
|
2516 | - if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) |
|
2517 | - $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
2640 | + if (!empty($tag['block_level'])) { |
|
2641 | + $whitespace_regex .= '( |\s)*(<br>)?'; |
|
2642 | + } |
|
2643 | + if (!empty($tag['trim']) && $tag['trim'] != 'inside') { |
|
2644 | + $whitespace_regex .= empty($tag['require_parents']) ? '( |\s)*' : '(<br>| |\s)*'; |
|
2645 | + } |
|
2646 | + if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) { |
|
2647 | + $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
2648 | + } |
|
2518 | 2649 | |
2519 | 2650 | array_pop($open_tags); |
2520 | 2651 | } |
@@ -2535,16 +2666,19 @@ discard block |
||
2535 | 2666 | elseif ($tag['type'] == 'unparsed_content') |
2536 | 2667 | { |
2537 | 2668 | $pos2 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos1); |
2538 | - if ($pos2 === false) |
|
2539 | - continue; |
|
2669 | + if ($pos2 === false) { |
|
2670 | + continue; |
|
2671 | + } |
|
2540 | 2672 | |
2541 | 2673 | $data = substr($message, $pos1, $pos2 - $pos1); |
2542 | 2674 | |
2543 | - if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') |
|
2544 | - $data = substr($data, 4); |
|
2675 | + if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') { |
|
2676 | + $data = substr($data, 4); |
|
2677 | + } |
|
2545 | 2678 | |
2546 | - if (isset($tag['validate'])) |
|
2547 | - $tag['validate']($tag, $data, $disabled, $params); |
|
2679 | + if (isset($tag['validate'])) { |
|
2680 | + $tag['validate']($tag, $data, $disabled, $params); |
|
2681 | + } |
|
2548 | 2682 | |
2549 | 2683 | $code = strtr($tag['content'], array('$1' => $data)); |
2550 | 2684 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 3 + $tag_strlen); |
@@ -2560,34 +2694,40 @@ discard block |
||
2560 | 2694 | if (isset($tag['quoted'])) |
2561 | 2695 | { |
2562 | 2696 | $quoted = substr($message, $pos1, 6) == '"'; |
2563 | - if ($tag['quoted'] != 'optional' && !$quoted) |
|
2564 | - continue; |
|
2697 | + if ($tag['quoted'] != 'optional' && !$quoted) { |
|
2698 | + continue; |
|
2699 | + } |
|
2565 | 2700 | |
2566 | - if ($quoted) |
|
2567 | - $pos1 += 6; |
|
2701 | + if ($quoted) { |
|
2702 | + $pos1 += 6; |
|
2703 | + } |
|
2704 | + } else { |
|
2705 | + $quoted = false; |
|
2568 | 2706 | } |
2569 | - else |
|
2570 | - $quoted = false; |
|
2571 | 2707 | |
2572 | 2708 | $pos2 = strpos($message, $quoted == false ? ']' : '"]', $pos1); |
2573 | - if ($pos2 === false) |
|
2574 | - continue; |
|
2709 | + if ($pos2 === false) { |
|
2710 | + continue; |
|
2711 | + } |
|
2575 | 2712 | |
2576 | 2713 | $pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2); |
2577 | - if ($pos3 === false) |
|
2578 | - continue; |
|
2714 | + if ($pos3 === false) { |
|
2715 | + continue; |
|
2716 | + } |
|
2579 | 2717 | |
2580 | 2718 | $data = array( |
2581 | 2719 | substr($message, $pos2 + ($quoted == false ? 1 : 7), $pos3 - ($pos2 + ($quoted == false ? 1 : 7))), |
2582 | 2720 | substr($message, $pos1, $pos2 - $pos1) |
2583 | 2721 | ); |
2584 | 2722 | |
2585 | - if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') |
|
2586 | - $data[0] = substr($data[0], 4); |
|
2723 | + if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') { |
|
2724 | + $data[0] = substr($data[0], 4); |
|
2725 | + } |
|
2587 | 2726 | |
2588 | 2727 | // Validation for my parking, please! |
2589 | - if (isset($tag['validate'])) |
|
2590 | - $tag['validate']($tag, $data, $disabled, $params); |
|
2728 | + if (isset($tag['validate'])) { |
|
2729 | + $tag['validate']($tag, $data, $disabled, $params); |
|
2730 | + } |
|
2591 | 2731 | |
2592 | 2732 | $code = strtr($tag['content'], array('$1' => $data[0], '$2' => $data[1])); |
2593 | 2733 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen); |
@@ -2604,23 +2744,27 @@ discard block |
||
2604 | 2744 | elseif ($tag['type'] == 'unparsed_commas_content') |
2605 | 2745 | { |
2606 | 2746 | $pos2 = strpos($message, ']', $pos1); |
2607 | - if ($pos2 === false) |
|
2608 | - continue; |
|
2747 | + if ($pos2 === false) { |
|
2748 | + continue; |
|
2749 | + } |
|
2609 | 2750 | |
2610 | 2751 | $pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2); |
2611 | - if ($pos3 === false) |
|
2612 | - continue; |
|
2752 | + if ($pos3 === false) { |
|
2753 | + continue; |
|
2754 | + } |
|
2613 | 2755 | |
2614 | 2756 | // We want $1 to be the content, and the rest to be csv. |
2615 | 2757 | $data = explode(',', ',' . substr($message, $pos1, $pos2 - $pos1)); |
2616 | 2758 | $data[0] = substr($message, $pos2 + 1, $pos3 - $pos2 - 1); |
2617 | 2759 | |
2618 | - if (isset($tag['validate'])) |
|
2619 | - $tag['validate']($tag, $data, $disabled, $params); |
|
2760 | + if (isset($tag['validate'])) { |
|
2761 | + $tag['validate']($tag, $data, $disabled, $params); |
|
2762 | + } |
|
2620 | 2763 | |
2621 | 2764 | $code = $tag['content']; |
2622 | - foreach ($data as $k => $d) |
|
2623 | - $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
2765 | + foreach ($data as $k => $d) { |
|
2766 | + $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
2767 | + } |
|
2624 | 2768 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen); |
2625 | 2769 | $pos += strlen($code) - 1 + 2; |
2626 | 2770 | } |
@@ -2628,24 +2772,28 @@ discard block |
||
2628 | 2772 | elseif ($tag['type'] == 'unparsed_commas') |
2629 | 2773 | { |
2630 | 2774 | $pos2 = strpos($message, ']', $pos1); |
2631 | - if ($pos2 === false) |
|
2632 | - continue; |
|
2775 | + if ($pos2 === false) { |
|
2776 | + continue; |
|
2777 | + } |
|
2633 | 2778 | |
2634 | 2779 | $data = explode(',', substr($message, $pos1, $pos2 - $pos1)); |
2635 | 2780 | |
2636 | - if (isset($tag['validate'])) |
|
2637 | - $tag['validate']($tag, $data, $disabled, $params); |
|
2781 | + if (isset($tag['validate'])) { |
|
2782 | + $tag['validate']($tag, $data, $disabled, $params); |
|
2783 | + } |
|
2638 | 2784 | |
2639 | 2785 | // Fix after, for disabled code mainly. |
2640 | - foreach ($data as $k => $d) |
|
2641 | - $tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d))); |
|
2786 | + foreach ($data as $k => $d) { |
|
2787 | + $tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d))); |
|
2788 | + } |
|
2642 | 2789 | |
2643 | 2790 | $open_tags[] = $tag; |
2644 | 2791 | |
2645 | 2792 | // Replace them out, $1, $2, $3, $4, etc. |
2646 | 2793 | $code = $tag['before']; |
2647 | - foreach ($data as $k => $d) |
|
2648 | - $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
2794 | + foreach ($data as $k => $d) { |
|
2795 | + $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
2796 | + } |
|
2649 | 2797 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 1); |
2650 | 2798 | $pos += strlen($code) - 1 + 2; |
2651 | 2799 | } |
@@ -2656,28 +2804,33 @@ discard block |
||
2656 | 2804 | if (isset($tag['quoted'])) |
2657 | 2805 | { |
2658 | 2806 | $quoted = substr($message, $pos1, 6) == '"'; |
2659 | - if ($tag['quoted'] != 'optional' && !$quoted) |
|
2660 | - continue; |
|
2807 | + if ($tag['quoted'] != 'optional' && !$quoted) { |
|
2808 | + continue; |
|
2809 | + } |
|
2661 | 2810 | |
2662 | - if ($quoted) |
|
2663 | - $pos1 += 6; |
|
2811 | + if ($quoted) { |
|
2812 | + $pos1 += 6; |
|
2813 | + } |
|
2814 | + } else { |
|
2815 | + $quoted = false; |
|
2664 | 2816 | } |
2665 | - else |
|
2666 | - $quoted = false; |
|
2667 | 2817 | |
2668 | 2818 | $pos2 = strpos($message, $quoted == false ? ']' : '"]', $pos1); |
2669 | - if ($pos2 === false) |
|
2670 | - continue; |
|
2819 | + if ($pos2 === false) { |
|
2820 | + continue; |
|
2821 | + } |
|
2671 | 2822 | |
2672 | 2823 | $data = substr($message, $pos1, $pos2 - $pos1); |
2673 | 2824 | |
2674 | 2825 | // Validation for my parking, please! |
2675 | - if (isset($tag['validate'])) |
|
2676 | - $tag['validate']($tag, $data, $disabled, $params); |
|
2826 | + if (isset($tag['validate'])) { |
|
2827 | + $tag['validate']($tag, $data, $disabled, $params); |
|
2828 | + } |
|
2677 | 2829 | |
2678 | 2830 | // For parsed content, we must recurse to avoid security problems. |
2679 | - if ($tag['type'] != 'unparsed_equals') |
|
2680 | - $data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array()); |
|
2831 | + if ($tag['type'] != 'unparsed_equals') { |
|
2832 | + $data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array()); |
|
2833 | + } |
|
2681 | 2834 | |
2682 | 2835 | $tag['after'] = strtr($tag['after'], array('$1' => $data)); |
2683 | 2836 | |
@@ -2689,34 +2842,40 @@ discard block |
||
2689 | 2842 | } |
2690 | 2843 | |
2691 | 2844 | // If this is block level, eat any breaks after it. |
2692 | - if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') |
|
2693 | - $message = substr($message, 0, $pos + 1) . substr($message, $pos + 5); |
|
2845 | + if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') { |
|
2846 | + $message = substr($message, 0, $pos + 1) . substr($message, $pos + 5); |
|
2847 | + } |
|
2694 | 2848 | |
2695 | 2849 | // Are we trimming outside this tag? |
2696 | - if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>| |\s)*~', substr($message, $pos + 1), $matches) != 0) |
|
2697 | - $message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0])); |
|
2850 | + if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>| |\s)*~', substr($message, $pos + 1), $matches) != 0) { |
|
2851 | + $message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0])); |
|
2852 | + } |
|
2698 | 2853 | } |
2699 | 2854 | |
2700 | 2855 | // Close any remaining tags. |
2701 | - while ($tag = array_pop($open_tags)) |
|
2702 | - $message .= "\n" . $tag['after'] . "\n"; |
|
2856 | + while ($tag = array_pop($open_tags)) { |
|
2857 | + $message .= "\n" . $tag['after'] . "\n"; |
|
2858 | + } |
|
2703 | 2859 | |
2704 | 2860 | // Parse the smileys within the parts where it can be done safely. |
2705 | 2861 | if ($smileys === true) |
2706 | 2862 | { |
2707 | 2863 | $message_parts = explode("\n", $message); |
2708 | - for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) |
|
2709 | - parsesmileys($message_parts[$i]); |
|
2864 | + for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) { |
|
2865 | + parsesmileys($message_parts[$i]); |
|
2866 | + } |
|
2710 | 2867 | |
2711 | 2868 | $message = implode('', $message_parts); |
2712 | 2869 | } |
2713 | 2870 | |
2714 | 2871 | // No smileys, just get rid of the markers. |
2715 | - else |
|
2716 | - $message = strtr($message, array("\n" => '')); |
|
2872 | + else { |
|
2873 | + $message = strtr($message, array("\n" => '')); |
|
2874 | + } |
|
2717 | 2875 | |
2718 | - if ($message !== '' && $message[0] === ' ') |
|
2719 | - $message = ' ' . substr($message, 1); |
|
2876 | + if ($message !== '' && $message[0] === ' ') { |
|
2877 | + $message = ' ' . substr($message, 1); |
|
2878 | + } |
|
2720 | 2879 | |
2721 | 2880 | // Cleanup whitespace. |
2722 | 2881 | $message = strtr($message, array(' ' => ' ', "\r" => '', "\n" => '<br>', '<br> ' => '<br> ', ' ' => "\n")); |
@@ -2725,15 +2884,16 @@ discard block |
||
2725 | 2884 | call_integration_hook('integrate_post_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags)); |
2726 | 2885 | |
2727 | 2886 | // Cache the output if it took some time... |
2728 | - if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) |
|
2729 | - cache_put_data($cache_key, $message, 240); |
|
2887 | + if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) { |
|
2888 | + cache_put_data($cache_key, $message, 240); |
|
2889 | + } |
|
2730 | 2890 | |
2731 | 2891 | // If this was a force parse revert if needed. |
2732 | 2892 | if (!empty($parse_tags)) |
2733 | 2893 | { |
2734 | - if (empty($temp_bbc)) |
|
2735 | - $bbc_codes = array(); |
|
2736 | - else |
|
2894 | + if (empty($temp_bbc)) { |
|
2895 | + $bbc_codes = array(); |
|
2896 | + } else |
|
2737 | 2897 | { |
2738 | 2898 | $bbc_codes = $temp_bbc; |
2739 | 2899 | unset($temp_bbc); |
@@ -2760,8 +2920,9 @@ discard block |
||
2760 | 2920 | static $smileyPregSearch = null, $smileyPregReplacements = array(); |
2761 | 2921 | |
2762 | 2922 | // No smiley set at all?! |
2763 | - if ($user_info['smiley_set'] == 'none' || trim($message) == '') |
|
2764 | - return; |
|
2923 | + if ($user_info['smiley_set'] == 'none' || trim($message) == '') { |
|
2924 | + return; |
|
2925 | + } |
|
2765 | 2926 | |
2766 | 2927 | // If smileyPregSearch hasn't been set, do it now. |
2767 | 2928 | if (empty($smileyPregSearch)) |
@@ -2772,8 +2933,7 @@ discard block |
||
2772 | 2933 | $smileysfrom = array('>:D', ':D', '::)', '>:(', ':))', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', '0:)'); |
2773 | 2934 | $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'); |
2774 | 2935 | $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'], '', '', '', ''); |
2775 | - } |
|
2776 | - else |
|
2936 | + } else |
|
2777 | 2937 | { |
2778 | 2938 | // Load the smileys in reverse order by length so they don't get parsed wrong. |
2779 | 2939 | if (($temp = cache_get_data('parsing_smileys', 480)) == null) |
@@ -2797,9 +2957,9 @@ discard block |
||
2797 | 2957 | $smcFunc['db_free_result']($result); |
2798 | 2958 | |
2799 | 2959 | cache_put_data('parsing_smileys', array($smileysfrom, $smileysto, $smileysdescs), 480); |
2960 | + } else { |
|
2961 | + list ($smileysfrom, $smileysto, $smileysdescs) = $temp; |
|
2800 | 2962 | } |
2801 | - else |
|
2802 | - list ($smileysfrom, $smileysto, $smileysdescs) = $temp; |
|
2803 | 2963 | } |
2804 | 2964 | |
2805 | 2965 | // The non-breaking-space is a complex thing... |
@@ -2877,12 +3037,14 @@ discard block |
||
2877 | 3037 | global $boardurl, $image_proxy_enabled, $image_proxy_secret; |
2878 | 3038 | |
2879 | 3039 | // Only use the proxy if enabled and necessary |
2880 | - if (empty($image_proxy_enabled) || parse_url($url, PHP_URL_SCHEME) === 'https') |
|
2881 | - return $url; |
|
3040 | + if (empty($image_proxy_enabled) || parse_url($url, PHP_URL_SCHEME) === 'https') { |
|
3041 | + return $url; |
|
3042 | + } |
|
2882 | 3043 | |
2883 | 3044 | // We don't need to proxy our own resources |
2884 | - if (strpos(strtr($url, array('http://' => 'https://')), strtr($boardurl, array('http://' => 'https://'))) === 0) |
|
2885 | - return strtr($url, array('http://' => 'https://')); |
|
3045 | + if (strpos(strtr($url, array('http://' => 'https://')), strtr($boardurl, array('http://' => 'https://'))) === 0) { |
|
3046 | + return strtr($url, array('http://' => 'https://')); |
|
3047 | + } |
|
2886 | 3048 | |
2887 | 3049 | // By default, use SMF's own image proxy script |
2888 | 3050 | $proxied_url = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($url) . '&hash=' . md5($url . $image_proxy_secret); |
@@ -2907,35 +3069,41 @@ discard block |
||
2907 | 3069 | global $scripturl, $context, $modSettings, $db_show_debug, $db_cache; |
2908 | 3070 | |
2909 | 3071 | // In case we have mail to send, better do that - as obExit doesn't always quite make it... |
2910 | - if (!empty($context['flush_mail'])) |
|
2911 | - // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
3072 | + if (!empty($context['flush_mail'])) { |
|
3073 | + // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
2912 | 3074 | AddMailQueue(true); |
3075 | + } |
|
2913 | 3076 | |
2914 | 3077 | $add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && substr($setLocation, 0, 6) != 'about:'; |
2915 | 3078 | |
2916 | - if ($add) |
|
2917 | - $setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : ''); |
|
3079 | + if ($add) { |
|
3080 | + $setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : ''); |
|
3081 | + } |
|
2918 | 3082 | |
2919 | 3083 | // Put the session ID in. |
2920 | - if (defined('SID') && SID != '') |
|
2921 | - $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation); |
|
3084 | + if (defined('SID') && SID != '') { |
|
3085 | + $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation); |
|
3086 | + } |
|
2922 | 3087 | // Keep that debug in their for template debugging! |
2923 | - elseif (isset($_GET['debug'])) |
|
2924 | - $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation); |
|
3088 | + elseif (isset($_GET['debug'])) { |
|
3089 | + $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation); |
|
3090 | + } |
|
2925 | 3091 | |
2926 | 3092 | 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']))) |
2927 | 3093 | { |
2928 | - if (defined('SID') && SID != '') |
|
2929 | - $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#]+?)(#[^"]*?)?$~', |
|
3094 | + if (defined('SID') && SID != '') { |
|
3095 | + $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#]+?)(#[^"]*?)?$~', |
|
2930 | 3096 | function ($m) use ($scripturl) |
2931 | 3097 | { |
2932 | 3098 | return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : ""); |
3099 | + } |
|
2933 | 3100 | }, $setLocation); |
2934 | - else |
|
2935 | - $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~', |
|
3101 | + else { |
|
3102 | + $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~', |
|
2936 | 3103 | function ($m) use ($scripturl) |
2937 | 3104 | { |
2938 | 3105 | return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : ""); |
3106 | + } |
|
2939 | 3107 | }, $setLocation); |
2940 | 3108 | } |
2941 | 3109 | |
@@ -2946,8 +3114,9 @@ discard block |
||
2946 | 3114 | header('location: ' . str_replace(' ', '%20', $setLocation), true, $permanent ? 301 : 302); |
2947 | 3115 | |
2948 | 3116 | // Debugging. |
2949 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
2950 | - $_SESSION['debug_redirect'] = $db_cache; |
|
3117 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
3118 | + $_SESSION['debug_redirect'] = $db_cache; |
|
3119 | + } |
|
2951 | 3120 | |
2952 | 3121 | obExit(false); |
2953 | 3122 | } |
@@ -2966,51 +3135,60 @@ discard block |
||
2966 | 3135 | |
2967 | 3136 | // Attempt to prevent a recursive loop. |
2968 | 3137 | ++$level; |
2969 | - if ($level > 1 && !$from_fatal_error && !$has_fatal_error) |
|
2970 | - exit; |
|
2971 | - if ($from_fatal_error) |
|
2972 | - $has_fatal_error = true; |
|
3138 | + if ($level > 1 && !$from_fatal_error && !$has_fatal_error) { |
|
3139 | + exit; |
|
3140 | + } |
|
3141 | + if ($from_fatal_error) { |
|
3142 | + $has_fatal_error = true; |
|
3143 | + } |
|
2973 | 3144 | |
2974 | 3145 | // Clear out the stat cache. |
2975 | 3146 | trackStats(); |
2976 | 3147 | |
2977 | 3148 | // If we have mail to send, send it. |
2978 | - if (!empty($context['flush_mail'])) |
|
2979 | - // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
3149 | + if (!empty($context['flush_mail'])) { |
|
3150 | + // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
2980 | 3151 | AddMailQueue(true); |
3152 | + } |
|
2981 | 3153 | |
2982 | 3154 | $do_header = $header === null ? !$header_done : $header; |
2983 | - if ($do_footer === null) |
|
2984 | - $do_footer = $do_header; |
|
3155 | + if ($do_footer === null) { |
|
3156 | + $do_footer = $do_header; |
|
3157 | + } |
|
2985 | 3158 | |
2986 | 3159 | // Has the template/header been done yet? |
2987 | 3160 | if ($do_header) |
2988 | 3161 | { |
2989 | 3162 | // Was the page title set last minute? Also update the HTML safe one. |
2990 | - if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) |
|
2991 | - $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); |
|
3163 | + if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) { |
|
3164 | + $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); |
|
3165 | + } |
|
2992 | 3166 | |
2993 | 3167 | // Start up the session URL fixer. |
2994 | 3168 | ob_start('ob_sessrewrite'); |
2995 | 3169 | |
2996 | - if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) |
|
2997 | - $buffers = explode(',', $settings['output_buffers']); |
|
2998 | - elseif (!empty($settings['output_buffers'])) |
|
2999 | - $buffers = $settings['output_buffers']; |
|
3000 | - else |
|
3001 | - $buffers = array(); |
|
3170 | + if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) { |
|
3171 | + $buffers = explode(',', $settings['output_buffers']); |
|
3172 | + } elseif (!empty($settings['output_buffers'])) { |
|
3173 | + $buffers = $settings['output_buffers']; |
|
3174 | + } else { |
|
3175 | + $buffers = array(); |
|
3176 | + } |
|
3002 | 3177 | |
3003 | - if (isset($modSettings['integrate_buffer'])) |
|
3004 | - $buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers); |
|
3178 | + if (isset($modSettings['integrate_buffer'])) { |
|
3179 | + $buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers); |
|
3180 | + } |
|
3005 | 3181 | |
3006 | - if (!empty($buffers)) |
|
3007 | - foreach ($buffers as $function) |
|
3182 | + if (!empty($buffers)) { |
|
3183 | + foreach ($buffers as $function) |
|
3008 | 3184 | { |
3009 | 3185 | $call = call_helper($function, true); |
3186 | + } |
|
3010 | 3187 | |
3011 | 3188 | // Is it valid? |
3012 | - if (!empty($call)) |
|
3013 | - ob_start($call); |
|
3189 | + if (!empty($call)) { |
|
3190 | + ob_start($call); |
|
3191 | + } |
|
3014 | 3192 | } |
3015 | 3193 | |
3016 | 3194 | // Display the screen in the logical order. |
@@ -3022,8 +3200,9 @@ discard block |
||
3022 | 3200 | loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main'); |
3023 | 3201 | |
3024 | 3202 | // Anything special to put out? |
3025 | - if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) |
|
3026 | - echo $context['insert_after_template']; |
|
3203 | + if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) { |
|
3204 | + echo $context['insert_after_template']; |
|
3205 | + } |
|
3027 | 3206 | |
3028 | 3207 | // Just so we don't get caught in an endless loop of errors from the footer... |
3029 | 3208 | if (!$footer_done) |
@@ -3032,14 +3211,16 @@ discard block |
||
3032 | 3211 | template_footer(); |
3033 | 3212 | |
3034 | 3213 | // (since this is just debugging... it's okay that it's after </html>.) |
3035 | - if (!isset($_REQUEST['xml'])) |
|
3036 | - displayDebug(); |
|
3214 | + if (!isset($_REQUEST['xml'])) { |
|
3215 | + displayDebug(); |
|
3216 | + } |
|
3037 | 3217 | } |
3038 | 3218 | } |
3039 | 3219 | |
3040 | 3220 | // Remember this URL in case someone doesn't like sending HTTP_REFERER. |
3041 | - if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) |
|
3042 | - $_SESSION['old_url'] = $_SERVER['REQUEST_URL']; |
|
3221 | + if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) { |
|
3222 | + $_SESSION['old_url'] = $_SERVER['REQUEST_URL']; |
|
3223 | + } |
|
3043 | 3224 | |
3044 | 3225 | // For session check verification.... don't switch browsers... |
3045 | 3226 | $_SESSION['USER_AGENT'] = empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT']; |
@@ -3048,9 +3229,10 @@ discard block |
||
3048 | 3229 | call_integration_hook('integrate_exit', array($do_footer)); |
3049 | 3230 | |
3050 | 3231 | // Don't exit if we're coming from index.php; that will pass through normally. |
3051 | - if (!$from_index) |
|
3052 | - exit; |
|
3053 | -} |
|
3232 | + if (!$from_index) { |
|
3233 | + exit; |
|
3234 | + } |
|
3235 | + } |
|
3054 | 3236 | |
3055 | 3237 | /** |
3056 | 3238 | * Get the size of a specified image with better error handling. |
@@ -3069,8 +3251,9 @@ discard block |
||
3069 | 3251 | $url = str_replace(' ', '%20', $url); |
3070 | 3252 | |
3071 | 3253 | // Can we pull this from the cache... please please? |
3072 | - if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) |
|
3073 | - return $temp; |
|
3254 | + if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) { |
|
3255 | + return $temp; |
|
3256 | + } |
|
3074 | 3257 | $t = microtime(); |
3075 | 3258 | |
3076 | 3259 | // Get the host to pester... |
@@ -3080,12 +3263,10 @@ discard block |
||
3080 | 3263 | if ($url == '' || $url == 'http://' || $url == 'https://') |
3081 | 3264 | { |
3082 | 3265 | return false; |
3083 | - } |
|
3084 | - elseif (!isset($match[1])) |
|
3266 | + } elseif (!isset($match[1])) |
|
3085 | 3267 | { |
3086 | 3268 | $size = @getimagesize($url); |
3087 | - } |
|
3088 | - else |
|
3269 | + } else |
|
3089 | 3270 | { |
3090 | 3271 | // Try to connect to the server... give it half a second. |
3091 | 3272 | $temp = 0; |
@@ -3122,12 +3303,14 @@ discard block |
||
3122 | 3303 | } |
3123 | 3304 | |
3124 | 3305 | // If we didn't get it, we failed. |
3125 | - if (!isset($size)) |
|
3126 | - $size = false; |
|
3306 | + if (!isset($size)) { |
|
3307 | + $size = false; |
|
3308 | + } |
|
3127 | 3309 | |
3128 | 3310 | // If this took a long time, we may never have to do it again, but then again we might... |
3129 | - if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) |
|
3130 | - cache_put_data('url_image_size-' . md5($url), $size, 240); |
|
3311 | + if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) { |
|
3312 | + cache_put_data('url_image_size-' . md5($url), $size, 240); |
|
3313 | + } |
|
3131 | 3314 | |
3132 | 3315 | // Didn't work. |
3133 | 3316 | return $size; |
@@ -3145,8 +3328,9 @@ discard block |
||
3145 | 3328 | |
3146 | 3329 | // Under SSI this function can be called more then once. That can cause some problems. |
3147 | 3330 | // So only run the function once unless we are forced to run it again. |
3148 | - if ($loaded && !$forceload) |
|
3149 | - return; |
|
3331 | + if ($loaded && !$forceload) { |
|
3332 | + return; |
|
3333 | + } |
|
3150 | 3334 | |
3151 | 3335 | $loaded = true; |
3152 | 3336 | |
@@ -3158,14 +3342,16 @@ discard block |
||
3158 | 3342 | $context['news_lines'] = array_filter(explode("\n", str_replace("\r", '', trim(addslashes($modSettings['news']))))); |
3159 | 3343 | for ($i = 0, $n = count($context['news_lines']); $i < $n; $i++) |
3160 | 3344 | { |
3161 | - if (trim($context['news_lines'][$i]) == '') |
|
3162 | - continue; |
|
3345 | + if (trim($context['news_lines'][$i]) == '') { |
|
3346 | + continue; |
|
3347 | + } |
|
3163 | 3348 | |
3164 | 3349 | // Clean it up for presentation ;). |
3165 | 3350 | $context['news_lines'][$i] = parse_bbc(stripslashes(trim($context['news_lines'][$i])), true, 'news' . $i); |
3166 | 3351 | } |
3167 | - if (!empty($context['news_lines'])) |
|
3168 | - $context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)]; |
|
3352 | + if (!empty($context['news_lines'])) { |
|
3353 | + $context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)]; |
|
3354 | + } |
|
3169 | 3355 | |
3170 | 3356 | if (!$user_info['is_guest']) |
3171 | 3357 | { |
@@ -3174,40 +3360,48 @@ discard block |
||
3174 | 3360 | $context['user']['alerts'] = &$user_info['alerts']; |
3175 | 3361 | |
3176 | 3362 | // Personal message popup... |
3177 | - if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) |
|
3178 | - $context['user']['popup_messages'] = true; |
|
3179 | - else |
|
3180 | - $context['user']['popup_messages'] = false; |
|
3363 | + if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) { |
|
3364 | + $context['user']['popup_messages'] = true; |
|
3365 | + } else { |
|
3366 | + $context['user']['popup_messages'] = false; |
|
3367 | + } |
|
3181 | 3368 | $_SESSION['unread_messages'] = $user_info['unread_messages']; |
3182 | 3369 | |
3183 | - if (allowedTo('moderate_forum')) |
|
3184 | - $context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0; |
|
3370 | + if (allowedTo('moderate_forum')) { |
|
3371 | + $context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0; |
|
3372 | + } |
|
3185 | 3373 | |
3186 | 3374 | $context['user']['avatar'] = array(); |
3187 | 3375 | |
3188 | 3376 | // Check for gravatar first since we might be forcing them... |
3189 | 3377 | if (($modSettings['gravatarEnabled'] && substr($user_info['avatar']['url'], 0, 11) == 'gravatar://') || !empty($modSettings['gravatarOverride'])) |
3190 | 3378 | { |
3191 | - if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) |
|
3192 | - $context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11)); |
|
3193 | - else |
|
3194 | - $context['user']['avatar']['href'] = get_gravatar_url($user_info['email']); |
|
3379 | + if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) { |
|
3380 | + $context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11)); |
|
3381 | + } else { |
|
3382 | + $context['user']['avatar']['href'] = get_gravatar_url($user_info['email']); |
|
3383 | + } |
|
3195 | 3384 | } |
3196 | 3385 | // Uploaded? |
3197 | - elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) |
|
3198 | - $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'; |
|
3386 | + elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) { |
|
3387 | + $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'; |
|
3388 | + } |
|
3199 | 3389 | // Full URL? |
3200 | - elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) |
|
3201 | - $context['user']['avatar']['href'] = $user_info['avatar']['url']; |
|
3390 | + elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) { |
|
3391 | + $context['user']['avatar']['href'] = $user_info['avatar']['url']; |
|
3392 | + } |
|
3202 | 3393 | // Otherwise we assume it's server stored. |
3203 | - elseif ($user_info['avatar']['url'] != '') |
|
3204 | - $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']); |
|
3394 | + elseif ($user_info['avatar']['url'] != '') { |
|
3395 | + $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']); |
|
3396 | + } |
|
3205 | 3397 | // No avatar at all? Fine, we have a big fat default avatar ;) |
3206 | - else |
|
3207 | - $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png'; |
|
3398 | + else { |
|
3399 | + $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png'; |
|
3400 | + } |
|
3208 | 3401 | |
3209 | - if (!empty($context['user']['avatar'])) |
|
3210 | - $context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">'; |
|
3402 | + if (!empty($context['user']['avatar'])) { |
|
3403 | + $context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">'; |
|
3404 | + } |
|
3211 | 3405 | |
3212 | 3406 | // Figure out how long they've been logged in. |
3213 | 3407 | $context['user']['total_time_logged_in'] = array( |
@@ -3215,8 +3409,7 @@ discard block |
||
3215 | 3409 | 'hours' => floor(($user_info['total_time_logged_in'] % 86400) / 3600), |
3216 | 3410 | 'minutes' => floor(($user_info['total_time_logged_in'] % 3600) / 60) |
3217 | 3411 | ); |
3218 | - } |
|
3219 | - else |
|
3412 | + } else |
|
3220 | 3413 | { |
3221 | 3414 | $context['user']['messages'] = 0; |
3222 | 3415 | $context['user']['unread_messages'] = 0; |
@@ -3224,12 +3417,14 @@ discard block |
||
3224 | 3417 | $context['user']['total_time_logged_in'] = array('days' => 0, 'hours' => 0, 'minutes' => 0); |
3225 | 3418 | $context['user']['popup_messages'] = false; |
3226 | 3419 | |
3227 | - if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) |
|
3228 | - $txt['welcome_guest'] .= $txt['welcome_guest_activate']; |
|
3420 | + if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) { |
|
3421 | + $txt['welcome_guest'] .= $txt['welcome_guest_activate']; |
|
3422 | + } |
|
3229 | 3423 | |
3230 | 3424 | // If we've upgraded recently, go easy on the passwords. |
3231 | - if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) |
|
3232 | - $context['disable_login_hashing'] = true; |
|
3425 | + if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) { |
|
3426 | + $context['disable_login_hashing'] = true; |
|
3427 | + } |
|
3233 | 3428 | } |
3234 | 3429 | |
3235 | 3430 | // Setup the main menu items. |
@@ -3242,8 +3437,8 @@ discard block |
||
3242 | 3437 | $context['show_pm_popup'] = $context['user']['popup_messages'] && !empty($options['popup_messages']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'pm'); |
3243 | 3438 | |
3244 | 3439 | // 2.1+: Add the PM popup here instead. Theme authors can still override it simply by editing/removing the 'fPmPopup' in the array. |
3245 | - if ($context['show_pm_popup']) |
|
3246 | - addInlineJavaScript(' |
|
3440 | + if ($context['show_pm_popup']) { |
|
3441 | + addInlineJavaScript(' |
|
3247 | 3442 | jQuery(document).ready(function($) { |
3248 | 3443 | new smc_Popup({ |
3249 | 3444 | heading: ' . JavaScriptEscape($txt['show_personal_messages_heading']) . ', |
@@ -3251,24 +3446,28 @@ discard block |
||
3251 | 3446 | icon_class: \'generic_icons mail_new\' |
3252 | 3447 | }); |
3253 | 3448 | });'); |
3449 | + } |
|
3254 | 3450 | |
3255 | 3451 | // Add a generic "Are you sure?" confirmation message. |
3256 | 3452 | addInlineJavaScript(' |
3257 | 3453 | var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';'); |
3258 | 3454 | |
3259 | 3455 | // Now add the capping code for avatars. |
3260 | - 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') |
|
3261 | - addInlineCss(' |
|
3456 | + 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') { |
|
3457 | + addInlineCss(' |
|
3262 | 3458 | img.avatar { max-width: ' . $modSettings['avatar_max_width_external'] . 'px; max-height: ' . $modSettings['avatar_max_height_external'] . 'px; }'); |
3459 | + } |
|
3263 | 3460 | |
3264 | 3461 | // Add max image limits |
3265 | - if (!empty($modSettings['max_image_width'])) |
|
3266 | - addInlineCss(' |
|
3462 | + if (!empty($modSettings['max_image_width'])) { |
|
3463 | + addInlineCss(' |
|
3267 | 3464 | .postarea .bbc_img { max-width: ' . $modSettings['max_image_width'] . 'px; }'); |
3465 | + } |
|
3268 | 3466 | |
3269 | - if (!empty($modSettings['max_image_height'])) |
|
3270 | - addInlineCss(' |
|
3467 | + if (!empty($modSettings['max_image_height'])) { |
|
3468 | + addInlineCss(' |
|
3271 | 3469 | .postarea .bbc_img { max-height: ' . $modSettings['max_image_height'] . 'px; }'); |
3470 | + } |
|
3272 | 3471 | |
3273 | 3472 | // This looks weird, but it's because BoardIndex.php references the variable. |
3274 | 3473 | $context['common_stats']['latest_member'] = array( |
@@ -3285,11 +3484,13 @@ discard block |
||
3285 | 3484 | ); |
3286 | 3485 | $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']); |
3287 | 3486 | |
3288 | - if (empty($settings['theme_version'])) |
|
3289 | - addJavaScriptVar('smf_scripturl', $scripturl); |
|
3487 | + if (empty($settings['theme_version'])) { |
|
3488 | + addJavaScriptVar('smf_scripturl', $scripturl); |
|
3489 | + } |
|
3290 | 3490 | |
3291 | - if (!isset($context['page_title'])) |
|
3292 | - $context['page_title'] = ''; |
|
3491 | + if (!isset($context['page_title'])) { |
|
3492 | + $context['page_title'] = ''; |
|
3493 | + } |
|
3293 | 3494 | |
3294 | 3495 | // Set some specific vars. |
3295 | 3496 | $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); |
@@ -3299,21 +3500,23 @@ discard block |
||
3299 | 3500 | $context['meta_tags'][] = array('property' => 'og:site_name', 'content' => $context['forum_name']); |
3300 | 3501 | $context['meta_tags'][] = array('property' => 'og:title', 'content' => $context['page_title_html_safe']); |
3301 | 3502 | |
3302 | - if (!empty($context['meta_keywords'])) |
|
3303 | - $context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']); |
|
3503 | + if (!empty($context['meta_keywords'])) { |
|
3504 | + $context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']); |
|
3505 | + } |
|
3304 | 3506 | |
3305 | - if (!empty($context['canonical_url'])) |
|
3306 | - $context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']); |
|
3507 | + if (!empty($context['canonical_url'])) { |
|
3508 | + $context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']); |
|
3509 | + } |
|
3307 | 3510 | |
3308 | - if (!empty($settings['og_image'])) |
|
3309 | - $context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']); |
|
3511 | + if (!empty($settings['og_image'])) { |
|
3512 | + $context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']); |
|
3513 | + } |
|
3310 | 3514 | |
3311 | 3515 | if (!empty($context['meta_description'])) |
3312 | 3516 | { |
3313 | 3517 | $context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['meta_description']); |
3314 | 3518 | $context['meta_tags'][] = array('name' => 'description', 'content' => $context['meta_description']); |
3315 | - } |
|
3316 | - else |
|
3519 | + } else |
|
3317 | 3520 | { |
3318 | 3521 | $context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['page_title_html_safe']); |
3319 | 3522 | $context['meta_tags'][] = array('name' => 'description', 'content' => $context['page_title_html_safe']); |
@@ -3338,8 +3541,9 @@ discard block |
||
3338 | 3541 | $memory_needed = memoryReturnBytes($needed); |
3339 | 3542 | |
3340 | 3543 | // should we account for how much is currently being used? |
3341 | - if ($in_use) |
|
3342 | - $memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576); |
|
3544 | + if ($in_use) { |
|
3545 | + $memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576); |
|
3546 | + } |
|
3343 | 3547 | |
3344 | 3548 | // if more is needed, request it |
3345 | 3549 | if ($memory_current < $memory_needed) |
@@ -3362,8 +3566,9 @@ discard block |
||
3362 | 3566 | */ |
3363 | 3567 | function memoryReturnBytes($val) |
3364 | 3568 | { |
3365 | - if (is_integer($val)) |
|
3366 | - return $val; |
|
3569 | + if (is_integer($val)) { |
|
3570 | + return $val; |
|
3571 | + } |
|
3367 | 3572 | |
3368 | 3573 | // Separate the number from the designator |
3369 | 3574 | $val = trim($val); |
@@ -3399,10 +3604,11 @@ discard block |
||
3399 | 3604 | header('last-modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); |
3400 | 3605 | |
3401 | 3606 | // Are we debugging the template/html content? |
3402 | - if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) |
|
3403 | - header('content-type: application/xhtml+xml'); |
|
3404 | - elseif (!isset($_REQUEST['xml'])) |
|
3405 | - header('content-type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
3607 | + if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) { |
|
3608 | + header('content-type: application/xhtml+xml'); |
|
3609 | + } elseif (!isset($_REQUEST['xml'])) { |
|
3610 | + header('content-type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
3611 | + } |
|
3406 | 3612 | } |
3407 | 3613 | |
3408 | 3614 | header('content-type: text/' . (isset($_REQUEST['xml']) ? 'xml' : 'html') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
@@ -3411,8 +3617,9 @@ discard block |
||
3411 | 3617 | if ($context['in_maintenance'] && $context['user']['is_admin']) |
3412 | 3618 | { |
3413 | 3619 | $position = array_search('body', $context['template_layers']); |
3414 | - if ($position === false) |
|
3415 | - $position = array_search('main', $context['template_layers']); |
|
3620 | + if ($position === false) { |
|
3621 | + $position = array_search('main', $context['template_layers']); |
|
3622 | + } |
|
3416 | 3623 | |
3417 | 3624 | if ($position !== false) |
3418 | 3625 | { |
@@ -3440,23 +3647,25 @@ discard block |
||
3440 | 3647 | |
3441 | 3648 | foreach ($securityFiles as $i => $securityFile) |
3442 | 3649 | { |
3443 | - if (!file_exists($boarddir . '/' . $securityFile)) |
|
3444 | - unset($securityFiles[$i]); |
|
3650 | + if (!file_exists($boarddir . '/' . $securityFile)) { |
|
3651 | + unset($securityFiles[$i]); |
|
3652 | + } |
|
3445 | 3653 | } |
3446 | 3654 | |
3447 | 3655 | // We are already checking so many files...just few more doesn't make any difference! :P |
3448 | - if (!empty($modSettings['currentAttachmentUploadDir'])) |
|
3449 | - $path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; |
|
3450 | - |
|
3451 | - else |
|
3452 | - $path = $modSettings['attachmentUploadDir']; |
|
3656 | + if (!empty($modSettings['currentAttachmentUploadDir'])) { |
|
3657 | + $path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; |
|
3658 | + } else { |
|
3659 | + $path = $modSettings['attachmentUploadDir']; |
|
3660 | + } |
|
3453 | 3661 | |
3454 | 3662 | secureDirectory($path, true); |
3455 | 3663 | secureDirectory($cachedir); |
3456 | 3664 | |
3457 | 3665 | // If agreement is enabled, at least the english version shall exists |
3458 | - if ($modSettings['requireAgreement']) |
|
3459 | - $agreement = !file_exists($boarddir . '/agreement.txt'); |
|
3666 | + if ($modSettings['requireAgreement']) { |
|
3667 | + $agreement = !file_exists($boarddir . '/agreement.txt'); |
|
3668 | + } |
|
3460 | 3669 | |
3461 | 3670 | if (!empty($securityFiles) || (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) || !empty($agreement)) |
3462 | 3671 | { |
@@ -3471,18 +3680,21 @@ discard block |
||
3471 | 3680 | echo ' |
3472 | 3681 | ', $txt['not_removed'], '<strong>', $securityFile, '</strong>!<br>'; |
3473 | 3682 | |
3474 | - if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') |
|
3475 | - echo ' |
|
3683 | + if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') { |
|
3684 | + echo ' |
|
3476 | 3685 | ', sprintf($txt['not_removed_extra'], $securityFile, substr($securityFile, 0, -1)), '<br>'; |
3686 | + } |
|
3477 | 3687 | } |
3478 | 3688 | |
3479 | - if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) |
|
3480 | - echo ' |
|
3689 | + if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) { |
|
3690 | + echo ' |
|
3481 | 3691 | <strong>', $txt['cache_writable'], '</strong><br>'; |
3692 | + } |
|
3482 | 3693 | |
3483 | - if (!empty($agreement)) |
|
3484 | - echo ' |
|
3694 | + if (!empty($agreement)) { |
|
3695 | + echo ' |
|
3485 | 3696 | <strong>', $txt['agreement_missing'], '</strong><br>'; |
3697 | + } |
|
3486 | 3698 | |
3487 | 3699 | echo ' |
3488 | 3700 | </p> |
@@ -3497,16 +3709,18 @@ discard block |
||
3497 | 3709 | <div class="windowbg alert" style="margin: 2ex; padding: 2ex; border: 2px dashed red;"> |
3498 | 3710 | ', sprintf($txt['you_are_post_banned'], $user_info['is_guest'] ? $txt['guest_title'] : $user_info['name']); |
3499 | 3711 | |
3500 | - if (!empty($_SESSION['ban']['cannot_post']['reason'])) |
|
3501 | - echo ' |
|
3712 | + if (!empty($_SESSION['ban']['cannot_post']['reason'])) { |
|
3713 | + echo ' |
|
3502 | 3714 | <div style="padding-left: 4ex; padding-top: 1ex;">', $_SESSION['ban']['cannot_post']['reason'], '</div>'; |
3715 | + } |
|
3503 | 3716 | |
3504 | - if (!empty($_SESSION['ban']['expire_time'])) |
|
3505 | - echo ' |
|
3717 | + if (!empty($_SESSION['ban']['expire_time'])) { |
|
3718 | + echo ' |
|
3506 | 3719 | <div>', sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)), '</div>'; |
3507 | - else |
|
3508 | - echo ' |
|
3720 | + } else { |
|
3721 | + echo ' |
|
3509 | 3722 | <div>', $txt['your_ban_expires_never'], '</div>'; |
3723 | + } |
|
3510 | 3724 | |
3511 | 3725 | echo ' |
3512 | 3726 | </div>'; |
@@ -3522,8 +3736,9 @@ discard block |
||
3522 | 3736 | global $forum_copyright, $software_year, $forum_version; |
3523 | 3737 | |
3524 | 3738 | // Don't display copyright for things like SSI. |
3525 | - if (!isset($forum_version) || !isset($software_year)) |
|
3526 | - return; |
|
3739 | + if (!isset($forum_version) || !isset($software_year)) { |
|
3740 | + return; |
|
3741 | + } |
|
3527 | 3742 | |
3528 | 3743 | // Put in the version... |
3529 | 3744 | printf($forum_copyright, $forum_version, $software_year); |
@@ -3541,9 +3756,10 @@ discard block |
||
3541 | 3756 | $context['load_time'] = round(microtime(true) - $time_start, 3); |
3542 | 3757 | $context['load_queries'] = $db_count; |
3543 | 3758 | |
3544 | - foreach (array_reverse($context['template_layers']) as $layer) |
|
3545 | - loadSubTemplate($layer . '_below', true); |
|
3546 | -} |
|
3759 | + foreach (array_reverse($context['template_layers']) as $layer) { |
|
3760 | + loadSubTemplate($layer . '_below', true); |
|
3761 | + } |
|
3762 | + } |
|
3547 | 3763 | |
3548 | 3764 | /** |
3549 | 3765 | * Output the Javascript files |
@@ -3577,8 +3793,7 @@ discard block |
||
3577 | 3793 | { |
3578 | 3794 | echo ' |
3579 | 3795 | var ', $key, ';'; |
3580 | - } |
|
3581 | - else |
|
3796 | + } else |
|
3582 | 3797 | { |
3583 | 3798 | echo ' |
3584 | 3799 | var ', $key, ' = ', $value, ';'; |
@@ -3597,27 +3812,29 @@ discard block |
||
3597 | 3812 | foreach ($context['javascript_files'] as $id => $js_file) |
3598 | 3813 | { |
3599 | 3814 | // Last minute call! allow theme authors to disable single files. |
3600 | - if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) |
|
3601 | - continue; |
|
3815 | + if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) { |
|
3816 | + continue; |
|
3817 | + } |
|
3602 | 3818 | |
3603 | 3819 | // By default files don't get minimized unless the file explicitly says so! |
3604 | 3820 | if (!empty($js_file['options']['minimize']) && !empty($modSettings['minimize_files'])) |
3605 | 3821 | { |
3606 | - if (!empty($js_file['options']['async'])) |
|
3607 | - $toMinify['async'][] = $js_file; |
|
3608 | - elseif (!empty($js_file['options']['defer'])) |
|
3609 | - $toMinify['defer'][] = $js_file; |
|
3610 | - else |
|
3611 | - $toMinify['standard'][] = $js_file; |
|
3822 | + if (!empty($js_file['options']['async'])) { |
|
3823 | + $toMinify['async'][] = $js_file; |
|
3824 | + } elseif (!empty($js_file['options']['defer'])) { |
|
3825 | + $toMinify['defer'][] = $js_file; |
|
3826 | + } else { |
|
3827 | + $toMinify['standard'][] = $js_file; |
|
3828 | + } |
|
3612 | 3829 | |
3613 | 3830 | // Grab a random seed. |
3614 | - if (!isset($minSeed) && isset($js_file['options']['seed'])) |
|
3615 | - $minSeed = $js_file['options']['seed']; |
|
3616 | - } |
|
3617 | - |
|
3618 | - else |
|
3619 | - echo ' |
|
3831 | + if (!isset($minSeed) && isset($js_file['options']['seed'])) { |
|
3832 | + $minSeed = $js_file['options']['seed']; |
|
3833 | + } |
|
3834 | + } else { |
|
3835 | + echo ' |
|
3620 | 3836 | <script src="', $js_file['fileUrl'], '"', !empty($js_file['options']['async']) ? ' async' : '', !empty($js_file['options']['defer']) ? ' defer' : '', '></script>'; |
3837 | + } |
|
3621 | 3838 | } |
3622 | 3839 | |
3623 | 3840 | foreach ($toMinify as $js_files) |
@@ -3628,9 +3845,10 @@ discard block |
||
3628 | 3845 | |
3629 | 3846 | $minSuccessful = array_keys($result) === array('smf_minified'); |
3630 | 3847 | |
3631 | - foreach ($result as $minFile) |
|
3632 | - echo ' |
|
3848 | + foreach ($result as $minFile) { |
|
3849 | + echo ' |
|
3633 | 3850 | <script src="', $minFile['fileUrl'], $minSuccessful && isset($minSeed) ? $minSeed : '', '"', !empty($minFile['options']['async']) ? ' async' : '', !empty($minFile['options']['defer']) ? ' defer' : '', '></script>'; |
3851 | + } |
|
3634 | 3852 | |
3635 | 3853 | } |
3636 | 3854 | } |
@@ -3645,8 +3863,9 @@ discard block |
||
3645 | 3863 | <script> |
3646 | 3864 | window.addEventListener("DOMContentLoaded", function() {'; |
3647 | 3865 | |
3648 | - foreach ($context['javascript_inline']['defer'] as $js_code) |
|
3649 | - echo $js_code; |
|
3866 | + foreach ($context['javascript_inline']['defer'] as $js_code) { |
|
3867 | + echo $js_code; |
|
3868 | + } |
|
3650 | 3869 | |
3651 | 3870 | echo ' |
3652 | 3871 | }); |
@@ -3658,8 +3877,9 @@ discard block |
||
3658 | 3877 | echo ' |
3659 | 3878 | <script>'; |
3660 | 3879 | |
3661 | - foreach ($context['javascript_inline']['standard'] as $js_code) |
|
3662 | - echo $js_code; |
|
3880 | + foreach ($context['javascript_inline']['standard'] as $js_code) { |
|
3881 | + echo $js_code; |
|
3882 | + } |
|
3663 | 3883 | |
3664 | 3884 | echo ' |
3665 | 3885 | </script>'; |
@@ -3687,23 +3907,26 @@ discard block |
||
3687 | 3907 | foreach ($context['css_files'] as $id => $file) |
3688 | 3908 | { |
3689 | 3909 | // Last minute call! allow theme authors to disable single files. |
3690 | - if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) |
|
3691 | - continue; |
|
3910 | + if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) { |
|
3911 | + continue; |
|
3912 | + } |
|
3692 | 3913 | |
3693 | 3914 | // Files are minimized unless they explicitly opt out. |
3694 | - if (!isset($file['options']['minimize'])) |
|
3695 | - $file['options']['minimize'] = true; |
|
3915 | + if (!isset($file['options']['minimize'])) { |
|
3916 | + $file['options']['minimize'] = true; |
|
3917 | + } |
|
3696 | 3918 | |
3697 | 3919 | if (!empty($file['options']['minimize']) && !empty($modSettings['minimize_files'])) |
3698 | 3920 | { |
3699 | 3921 | $toMinify[] = $file; |
3700 | 3922 | |
3701 | 3923 | // Grab a random seed. |
3702 | - if (!isset($minSeed) && isset($file['options']['seed'])) |
|
3703 | - $minSeed = $file['options']['seed']; |
|
3924 | + if (!isset($minSeed) && isset($file['options']['seed'])) { |
|
3925 | + $minSeed = $file['options']['seed']; |
|
3926 | + } |
|
3927 | + } else { |
|
3928 | + $normal[] = $file['fileUrl']; |
|
3704 | 3929 | } |
3705 | - else |
|
3706 | - $normal[] = $file['fileUrl']; |
|
3707 | 3930 | } |
3708 | 3931 | |
3709 | 3932 | if (!empty($toMinify)) |
@@ -3712,23 +3935,26 @@ discard block |
||
3712 | 3935 | |
3713 | 3936 | $minSuccessful = array_keys($result) === array('smf_minified'); |
3714 | 3937 | |
3715 | - foreach ($result as $minFile) |
|
3716 | - echo ' |
|
3938 | + foreach ($result as $minFile) { |
|
3939 | + echo ' |
|
3717 | 3940 | <link rel="stylesheet" href="', $minFile['fileUrl'], $minSuccessful && isset($minSeed) ? $minSeed : '', '">'; |
3941 | + } |
|
3718 | 3942 | } |
3719 | 3943 | |
3720 | 3944 | // Print the rest after the minified files. |
3721 | - if (!empty($normal)) |
|
3722 | - foreach ($normal as $nf) |
|
3945 | + if (!empty($normal)) { |
|
3946 | + foreach ($normal as $nf) |
|
3723 | 3947 | echo ' |
3724 | 3948 | <link rel="stylesheet" href="', $nf ,'">'; |
3949 | + } |
|
3725 | 3950 | |
3726 | 3951 | if ($db_show_debug === true) |
3727 | 3952 | { |
3728 | 3953 | // Try to keep only what's useful. |
3729 | 3954 | $repl = array($boardurl . '/Themes/' => '', $boardurl . '/' => ''); |
3730 | - foreach ($context['css_files'] as $file) |
|
3731 | - $context['debug']['sheets'][] = strtr($file['fileName'], $repl); |
|
3955 | + foreach ($context['css_files'] as $file) { |
|
3956 | + $context['debug']['sheets'][] = strtr($file['fileName'], $repl); |
|
3957 | + } |
|
3732 | 3958 | } |
3733 | 3959 | |
3734 | 3960 | if (!empty($context['css_header'])) |
@@ -3736,9 +3962,10 @@ discard block |
||
3736 | 3962 | echo ' |
3737 | 3963 | <style>'; |
3738 | 3964 | |
3739 | - foreach ($context['css_header'] as $css) |
|
3740 | - echo $css .' |
|
3965 | + foreach ($context['css_header'] as $css) { |
|
3966 | + echo $css .' |
|
3741 | 3967 | '; |
3968 | + } |
|
3742 | 3969 | |
3743 | 3970 | echo' |
3744 | 3971 | </style>'; |
@@ -3761,8 +3988,9 @@ discard block |
||
3761 | 3988 | $type = !empty($type) && in_array($type, $types) ? $type : false; |
3762 | 3989 | $data = is_array($data) ? $data : array(); |
3763 | 3990 | |
3764 | - if (empty($type) || empty($data)) |
|
3765 | - return $data; |
|
3991 | + if (empty($type) || empty($data)) { |
|
3992 | + return $data; |
|
3993 | + } |
|
3766 | 3994 | |
3767 | 3995 | // Different pages include different files, so we use a hash to label the different combinations |
3768 | 3996 | $hash = md5(implode(' ', array_map(function($file) { return $file['filePath'] . (int) @filesize($file['filePath']) . (int) @filemtime($file['filePath']); }, $data))); |
@@ -3771,13 +3999,14 @@ discard block |
||
3771 | 3999 | list($toCache, $async, $defer) = array_pad((array) cache_get_data('minimized_' . $settings['theme_id'] . '_' . $type . '_' . $hash, 86400), 3, null); |
3772 | 4000 | |
3773 | 4001 | // Already done? |
3774 | - if (!empty($toCache)) |
|
3775 | - return array('smf_minified' => array( |
|
4002 | + if (!empty($toCache)) { |
|
4003 | + return array('smf_minified' => array( |
|
3776 | 4004 | 'fileUrl' => $settings['theme_url'] . '/' . ($type == 'css' ? 'css' : 'scripts') . '/' . basename($toCache), |
3777 | 4005 | 'filePath' => $toCache, |
3778 | 4006 | 'fileName' => basename($toCache), |
3779 | 4007 | 'options' => array('async' => !empty($async), 'defer' => !empty($defer)), |
3780 | 4008 | )); |
4009 | + } |
|
3781 | 4010 | |
3782 | 4011 | |
3783 | 4012 | // No namespaces, sorry! |
@@ -3807,9 +4036,9 @@ discard block |
||
3807 | 4036 | |
3808 | 4037 | foreach ($data as $id => $file) |
3809 | 4038 | { |
3810 | - if (empty($file['filePath'])) |
|
3811 | - $toAdd = false; |
|
3812 | - else |
|
4039 | + if (empty($file['filePath'])) { |
|
4040 | + $toAdd = false; |
|
4041 | + } else |
|
3813 | 4042 | { |
3814 | 4043 | $seed = isset($file['options']['seed']) ? $file['options']['seed'] : ''; |
3815 | 4044 | $tempFile = str_replace($seed, '', $file['filePath']); |
@@ -3817,12 +4046,14 @@ discard block |
||
3817 | 4046 | } |
3818 | 4047 | |
3819 | 4048 | // A minified script should only be loaded asynchronously if all its components wanted to be. |
3820 | - if (empty($file['options']['async'])) |
|
3821 | - $async = false; |
|
4049 | + if (empty($file['options']['async'])) { |
|
4050 | + $async = false; |
|
4051 | + } |
|
3822 | 4052 | |
3823 | 4053 | // A minified script should only be deferred if all its components wanted to be. |
3824 | - if (empty($file['options']['defer'])) |
|
3825 | - $defer = false; |
|
4054 | + if (empty($file['options']['defer'])) { |
|
4055 | + $defer = false; |
|
4056 | + } |
|
3826 | 4057 | |
3827 | 4058 | // The file couldn't be located so it won't be added. Log this error. |
3828 | 4059 | if (empty($toAdd)) |
@@ -3888,12 +4119,14 @@ discard block |
||
3888 | 4119 | foreach (glob(rtrim($theme['dir'], '/') . '/' . ($type == 'css' ? 'css' : 'scripts') . '/minified*.' . $type) as $filename) |
3889 | 4120 | { |
3890 | 4121 | // Remove the cache entry |
3891 | - if (preg_match('~([a-zA-Z0-9]+)\.' . $type . '$~', $filename, $matches)) |
|
3892 | - cache_put_data('minimized_' . $theme['id'] . '_' . $type . '_' . $matches[1], null); |
|
4122 | + if (preg_match('~([a-zA-Z0-9]+)\.' . $type . '$~', $filename, $matches)) { |
|
4123 | + cache_put_data('minimized_' . $theme['id'] . '_' . $type . '_' . $matches[1], null); |
|
4124 | + } |
|
3893 | 4125 | |
3894 | 4126 | // Try to delete the file. Add it to our error list if it fails. |
3895 | - if (!@unlink($filename)) |
|
3896 | - $not_deleted[] = $filename; |
|
4127 | + if (!@unlink($filename)) { |
|
4128 | + $not_deleted[] = $filename; |
|
4129 | + } |
|
3897 | 4130 | } |
3898 | 4131 | } |
3899 | 4132 | } |
@@ -3925,8 +4158,9 @@ discard block |
||
3925 | 4158 | global $modSettings, $smcFunc; |
3926 | 4159 | |
3927 | 4160 | // Just make up a nice hash... |
3928 | - if ($new) |
|
3929 | - return sha1(md5($filename . time()) . mt_rand()); |
|
4161 | + if ($new) { |
|
4162 | + return sha1(md5($filename . time()) . mt_rand()); |
|
4163 | + } |
|
3930 | 4164 | |
3931 | 4165 | // Just make sure that attachment id is only a int |
3932 | 4166 | $attachment_id = (int) $attachment_id; |
@@ -3943,23 +4177,25 @@ discard block |
||
3943 | 4177 | 'id_attach' => $attachment_id, |
3944 | 4178 | )); |
3945 | 4179 | |
3946 | - if ($smcFunc['db_num_rows']($request) === 0) |
|
3947 | - return false; |
|
4180 | + if ($smcFunc['db_num_rows']($request) === 0) { |
|
4181 | + return false; |
|
4182 | + } |
|
3948 | 4183 | |
3949 | 4184 | list ($file_hash) = $smcFunc['db_fetch_row']($request); |
3950 | 4185 | $smcFunc['db_free_result']($request); |
3951 | 4186 | } |
3952 | 4187 | |
3953 | 4188 | // Still no hash? mmm... |
3954 | - if (empty($file_hash)) |
|
3955 | - $file_hash = sha1(md5($filename . time()) . mt_rand()); |
|
4189 | + if (empty($file_hash)) { |
|
4190 | + $file_hash = sha1(md5($filename . time()) . mt_rand()); |
|
4191 | + } |
|
3956 | 4192 | |
3957 | 4193 | // Are we using multiple directories? |
3958 | - if (is_array($modSettings['attachmentUploadDir'])) |
|
3959 | - $path = $modSettings['attachmentUploadDir'][$dir]; |
|
3960 | - |
|
3961 | - else |
|
3962 | - $path = $modSettings['attachmentUploadDir']; |
|
4194 | + if (is_array($modSettings['attachmentUploadDir'])) { |
|
4195 | + $path = $modSettings['attachmentUploadDir'][$dir]; |
|
4196 | + } else { |
|
4197 | + $path = $modSettings['attachmentUploadDir']; |
|
4198 | + } |
|
3963 | 4199 | |
3964 | 4200 | return $path . '/' . $attachment_id . '_' . $file_hash .'.dat'; |
3965 | 4201 | } |
@@ -3974,8 +4210,9 @@ discard block |
||
3974 | 4210 | function ip2range($fullip) |
3975 | 4211 | { |
3976 | 4212 | // Pretend that 'unknown' is 255.255.255.255. (since that can't be an IP anyway.) |
3977 | - if ($fullip == 'unknown') |
|
3978 | - $fullip = '255.255.255.255'; |
|
4213 | + if ($fullip == 'unknown') { |
|
4214 | + $fullip = '255.255.255.255'; |
|
4215 | + } |
|
3979 | 4216 | |
3980 | 4217 | $ip_parts = explode('-', $fullip); |
3981 | 4218 | $ip_array = array(); |
@@ -3999,10 +4236,11 @@ discard block |
||
3999 | 4236 | $ip_array['low'] = $ip_parts[0]; |
4000 | 4237 | $ip_array['high'] = $ip_parts[1]; |
4001 | 4238 | return $ip_array; |
4002 | - } |
|
4003 | - elseif (count($ip_parts) == 2) // if ip 22.22.*-22.22.* |
|
4239 | + } elseif (count($ip_parts) == 2) { |
|
4240 | + // if ip 22.22.*-22.22.* |
|
4004 | 4241 | { |
4005 | 4242 | $valid_low = isValidIP($ip_parts[0]); |
4243 | + } |
|
4006 | 4244 | $valid_high = isValidIP($ip_parts[1]); |
4007 | 4245 | $count = 0; |
4008 | 4246 | $mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.'); |
@@ -4017,7 +4255,9 @@ discard block |
||
4017 | 4255 | $ip_parts[0] .= $mode . $min; |
4018 | 4256 | $valid_low = isValidIP($ip_parts[0]); |
4019 | 4257 | $count++; |
4020 | - if ($count > 9) break; |
|
4258 | + if ($count > 9) { |
|
4259 | + break; |
|
4260 | + } |
|
4021 | 4261 | } |
4022 | 4262 | } |
4023 | 4263 | |
@@ -4031,7 +4271,9 @@ discard block |
||
4031 | 4271 | $ip_parts[1] .= $mode . $max; |
4032 | 4272 | $valid_high = isValidIP($ip_parts[1]); |
4033 | 4273 | $count++; |
4034 | - if ($count > 9) break; |
|
4274 | + if ($count > 9) { |
|
4275 | + break; |
|
4276 | + } |
|
4035 | 4277 | } |
4036 | 4278 | } |
4037 | 4279 | |
@@ -4056,46 +4298,54 @@ discard block |
||
4056 | 4298 | { |
4057 | 4299 | global $modSettings; |
4058 | 4300 | |
4059 | - if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) |
|
4060 | - return $host; |
|
4301 | + if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) { |
|
4302 | + return $host; |
|
4303 | + } |
|
4061 | 4304 | $t = microtime(); |
4062 | 4305 | |
4063 | 4306 | // Try the Linux host command, perhaps? |
4064 | 4307 | if (!isset($host) && (strpos(strtolower(PHP_OS), 'win') === false || strpos(strtolower(PHP_OS), 'darwin') !== false) && mt_rand(0, 1) == 1) |
4065 | 4308 | { |
4066 | - if (!isset($modSettings['host_to_dis'])) |
|
4067 | - $test = @shell_exec('host -W 1 ' . @escapeshellarg($ip)); |
|
4068 | - else |
|
4069 | - $test = @shell_exec('host ' . @escapeshellarg($ip)); |
|
4309 | + if (!isset($modSettings['host_to_dis'])) { |
|
4310 | + $test = @shell_exec('host -W 1 ' . @escapeshellarg($ip)); |
|
4311 | + } else { |
|
4312 | + $test = @shell_exec('host ' . @escapeshellarg($ip)); |
|
4313 | + } |
|
4070 | 4314 | |
4071 | 4315 | // Did host say it didn't find anything? |
4072 | - if (strpos($test, 'not found') !== false) |
|
4073 | - $host = ''; |
|
4316 | + if (strpos($test, 'not found') !== false) { |
|
4317 | + $host = ''; |
|
4318 | + } |
|
4074 | 4319 | // Invalid server option? |
4075 | - elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) |
|
4076 | - updateSettings(array('host_to_dis' => 1)); |
|
4320 | + elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) { |
|
4321 | + updateSettings(array('host_to_dis' => 1)); |
|
4322 | + } |
|
4077 | 4323 | // Maybe it found something, after all? |
4078 | - elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) |
|
4079 | - $host = $match[1]; |
|
4324 | + elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) { |
|
4325 | + $host = $match[1]; |
|
4326 | + } |
|
4080 | 4327 | } |
4081 | 4328 | |
4082 | 4329 | // This is nslookup; usually only Windows, but possibly some Unix? |
4083 | 4330 | if (!isset($host) && stripos(PHP_OS, 'win') !== false && strpos(strtolower(PHP_OS), 'darwin') === false && mt_rand(0, 1) == 1) |
4084 | 4331 | { |
4085 | 4332 | $test = @shell_exec('nslookup -timeout=1 ' . @escapeshellarg($ip)); |
4086 | - if (strpos($test, 'Non-existent domain') !== false) |
|
4087 | - $host = ''; |
|
4088 | - elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) |
|
4089 | - $host = $match[1]; |
|
4333 | + if (strpos($test, 'Non-existent domain') !== false) { |
|
4334 | + $host = ''; |
|
4335 | + } elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) { |
|
4336 | + $host = $match[1]; |
|
4337 | + } |
|
4090 | 4338 | } |
4091 | 4339 | |
4092 | 4340 | // This is the last try :/. |
4093 | - if (!isset($host) || $host === false) |
|
4094 | - $host = @gethostbyaddr($ip); |
|
4341 | + if (!isset($host) || $host === false) { |
|
4342 | + $host = @gethostbyaddr($ip); |
|
4343 | + } |
|
4095 | 4344 | |
4096 | 4345 | // It took a long time, so let's cache it! |
4097 | - if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) |
|
4098 | - cache_put_data('hostlookup-' . $ip, $host, 600); |
|
4346 | + if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) { |
|
4347 | + cache_put_data('hostlookup-' . $ip, $host, 600); |
|
4348 | + } |
|
4099 | 4349 | |
4100 | 4350 | return $host; |
4101 | 4351 | } |
@@ -4131,20 +4381,21 @@ discard block |
||
4131 | 4381 | { |
4132 | 4382 | $encrypted = substr(crypt($word, 'uk'), 2, $max_chars); |
4133 | 4383 | $total = 0; |
4134 | - for ($i = 0; $i < $max_chars; $i++) |
|
4135 | - $total += $possible_chars[ord($encrypted{$i})] * pow(63, $i); |
|
4384 | + for ($i = 0; $i < $max_chars; $i++) { |
|
4385 | + $total += $possible_chars[ord($encrypted{$i})] * pow(63, $i); |
|
4386 | + } |
|
4136 | 4387 | $returned_ints[] = $max_chars == 4 ? min($total, 16777215) : $total; |
4137 | 4388 | } |
4138 | 4389 | } |
4139 | 4390 | return array_unique($returned_ints); |
4140 | - } |
|
4141 | - else |
|
4391 | + } else |
|
4142 | 4392 | { |
4143 | 4393 | // Trim characters before and after and add slashes for database insertion. |
4144 | 4394 | $returned_words = array(); |
4145 | - foreach ($words as $word) |
|
4146 | - if (($word = trim($word, '-_\'')) !== '') |
|
4395 | + foreach ($words as $word) { |
|
4396 | + if (($word = trim($word, '-_\'')) !== '') |
|
4147 | 4397 | $returned_words[] = $max_chars === null ? $word : substr($word, 0, $max_chars); |
4398 | + } |
|
4148 | 4399 | |
4149 | 4400 | // Filter out all words that occur more than once. |
4150 | 4401 | return array_unique($returned_words); |
@@ -4166,16 +4417,18 @@ discard block |
||
4166 | 4417 | global $settings, $txt; |
4167 | 4418 | |
4168 | 4419 | // Does the current loaded theme have this and we are not forcing the usage of this function? |
4169 | - if (function_exists('template_create_button') && !$force_use) |
|
4170 | - return template_create_button($name, $alt, $label = '', $custom = ''); |
|
4420 | + if (function_exists('template_create_button') && !$force_use) { |
|
4421 | + return template_create_button($name, $alt, $label = '', $custom = ''); |
|
4422 | + } |
|
4171 | 4423 | |
4172 | - if (!$settings['use_image_buttons']) |
|
4173 | - return $txt[$alt]; |
|
4174 | - elseif (!empty($settings['use_buttons'])) |
|
4175 | - return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? ' <strong>' . $txt[$label] . '</strong>' : ''); |
|
4176 | - else |
|
4177 | - return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>'; |
|
4178 | -} |
|
4424 | + if (!$settings['use_image_buttons']) { |
|
4425 | + return $txt[$alt]; |
|
4426 | + } elseif (!empty($settings['use_buttons'])) { |
|
4427 | + return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? ' <strong>' . $txt[$label] . '</strong>' : ''); |
|
4428 | + } else { |
|
4429 | + return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>'; |
|
4430 | + } |
|
4431 | + } |
|
4179 | 4432 | |
4180 | 4433 | /** |
4181 | 4434 | * Sets up all of the top menu buttons |
@@ -4218,9 +4471,10 @@ discard block |
||
4218 | 4471 | var user_menus = new smc_PopupMenu(); |
4219 | 4472 | user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup"); |
4220 | 4473 | user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true); |
4221 | - if ($context['allow_pm']) |
|
4222 | - addInlineJavaScript(' |
|
4474 | + if ($context['allow_pm']) { |
|
4475 | + addInlineJavaScript(' |
|
4223 | 4476 | user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true); |
4477 | + } |
|
4224 | 4478 | |
4225 | 4479 | if (!empty($modSettings['enable_ajax_alerts'])) |
4226 | 4480 | { |
@@ -4380,88 +4634,96 @@ discard block |
||
4380 | 4634 | |
4381 | 4635 | // Now we put the buttons in the context so the theme can use them. |
4382 | 4636 | $menu_buttons = array(); |
4383 | - foreach ($buttons as $act => $button) |
|
4384 | - if (!empty($button['show'])) |
|
4637 | + foreach ($buttons as $act => $button) { |
|
4638 | + if (!empty($button['show'])) |
|
4385 | 4639 | { |
4386 | 4640 | $button['active_button'] = false; |
4641 | + } |
|
4387 | 4642 | |
4388 | 4643 | // This button needs some action. |
4389 | - if (isset($button['action_hook'])) |
|
4390 | - $needs_action_hook = true; |
|
4644 | + if (isset($button['action_hook'])) { |
|
4645 | + $needs_action_hook = true; |
|
4646 | + } |
|
4391 | 4647 | |
4392 | 4648 | // Make sure the last button truly is the last button. |
4393 | 4649 | if (!empty($button['is_last'])) |
4394 | 4650 | { |
4395 | - if (isset($last_button)) |
|
4396 | - unset($menu_buttons[$last_button]['is_last']); |
|
4651 | + if (isset($last_button)) { |
|
4652 | + unset($menu_buttons[$last_button]['is_last']); |
|
4653 | + } |
|
4397 | 4654 | $last_button = $act; |
4398 | 4655 | } |
4399 | 4656 | |
4400 | 4657 | // Go through the sub buttons if there are any. |
4401 | - if (!empty($button['sub_buttons'])) |
|
4402 | - foreach ($button['sub_buttons'] as $key => $subbutton) |
|
4658 | + if (!empty($button['sub_buttons'])) { |
|
4659 | + foreach ($button['sub_buttons'] as $key => $subbutton) |
|
4403 | 4660 | { |
4404 | 4661 | if (empty($subbutton['show'])) |
4405 | 4662 | unset($button['sub_buttons'][$key]); |
4663 | + } |
|
4406 | 4664 | |
4407 | 4665 | // 2nd level sub buttons next... |
4408 | 4666 | if (!empty($subbutton['sub_buttons'])) |
4409 | 4667 | { |
4410 | 4668 | foreach ($subbutton['sub_buttons'] as $key2 => $sub_button2) |
4411 | 4669 | { |
4412 | - if (empty($sub_button2['show'])) |
|
4413 | - unset($button['sub_buttons'][$key]['sub_buttons'][$key2]); |
|
4670 | + if (empty($sub_button2['show'])) { |
|
4671 | + unset($button['sub_buttons'][$key]['sub_buttons'][$key2]); |
|
4672 | + } |
|
4414 | 4673 | } |
4415 | 4674 | } |
4416 | 4675 | } |
4417 | 4676 | |
4418 | 4677 | // Does this button have its own icon? |
4419 | - if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) |
|
4420 | - $button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
4421 | - elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) |
|
4422 | - $button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
4423 | - elseif (isset($button['icon'])) |
|
4424 | - $button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>'; |
|
4425 | - else |
|
4426 | - $button['icon'] = '<span class="generic_icons ' . $act . '"></span>'; |
|
4678 | + if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) { |
|
4679 | + $button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
4680 | + } elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) { |
|
4681 | + $button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
4682 | + } elseif (isset($button['icon'])) { |
|
4683 | + $button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>'; |
|
4684 | + } else { |
|
4685 | + $button['icon'] = '<span class="generic_icons ' . $act . '"></span>'; |
|
4686 | + } |
|
4427 | 4687 | |
4428 | 4688 | $menu_buttons[$act] = $button; |
4429 | 4689 | } |
4430 | 4690 | |
4431 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
4432 | - cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime); |
|
4691 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
4692 | + cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime); |
|
4693 | + } |
|
4433 | 4694 | } |
4434 | 4695 | |
4435 | 4696 | $context['menu_buttons'] = $menu_buttons; |
4436 | 4697 | |
4437 | 4698 | // Logging out requires the session id in the url. |
4438 | - if (isset($context['menu_buttons']['logout'])) |
|
4439 | - $context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']); |
|
4699 | + if (isset($context['menu_buttons']['logout'])) { |
|
4700 | + $context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']); |
|
4701 | + } |
|
4440 | 4702 | |
4441 | 4703 | // Figure out which action we are doing so we can set the active tab. |
4442 | 4704 | // Default to home. |
4443 | 4705 | $current_action = 'home'; |
4444 | 4706 | |
4445 | - if (isset($context['menu_buttons'][$context['current_action']])) |
|
4446 | - $current_action = $context['current_action']; |
|
4447 | - elseif ($context['current_action'] == 'search2') |
|
4448 | - $current_action = 'search'; |
|
4449 | - elseif ($context['current_action'] == 'theme') |
|
4450 | - $current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin'; |
|
4451 | - elseif ($context['current_action'] == 'register2') |
|
4452 | - $current_action = 'register'; |
|
4453 | - elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) |
|
4454 | - $current_action = 'login'; |
|
4455 | - elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) |
|
4456 | - $current_action = 'moderate'; |
|
4707 | + if (isset($context['menu_buttons'][$context['current_action']])) { |
|
4708 | + $current_action = $context['current_action']; |
|
4709 | + } elseif ($context['current_action'] == 'search2') { |
|
4710 | + $current_action = 'search'; |
|
4711 | + } elseif ($context['current_action'] == 'theme') { |
|
4712 | + $current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin'; |
|
4713 | + } elseif ($context['current_action'] == 'register2') { |
|
4714 | + $current_action = 'register'; |
|
4715 | + } elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) { |
|
4716 | + $current_action = 'login'; |
|
4717 | + } elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) { |
|
4718 | + $current_action = 'moderate'; |
|
4719 | + } |
|
4457 | 4720 | |
4458 | 4721 | // There are certain exceptions to the above where we don't want anything on the menu highlighted. |
4459 | 4722 | if ($context['current_action'] == 'profile' && !empty($context['user']['is_owner'])) |
4460 | 4723 | { |
4461 | 4724 | $current_action = !empty($_GET['area']) && $_GET['area'] == 'showalerts' ? 'self_alerts' : 'self_profile'; |
4462 | 4725 | $context[$current_action] = true; |
4463 | - } |
|
4464 | - elseif ($context['current_action'] == 'pm') |
|
4726 | + } elseif ($context['current_action'] == 'pm') |
|
4465 | 4727 | { |
4466 | 4728 | $current_action = 'self_pm'; |
4467 | 4729 | $context['self_pm'] = true; |
@@ -4518,12 +4780,14 @@ discard block |
||
4518 | 4780 | } |
4519 | 4781 | |
4520 | 4782 | // Not all actions are simple. |
4521 | - if (!empty($needs_action_hook)) |
|
4522 | - call_integration_hook('integrate_current_action', array(&$current_action)); |
|
4783 | + if (!empty($needs_action_hook)) { |
|
4784 | + call_integration_hook('integrate_current_action', array(&$current_action)); |
|
4785 | + } |
|
4523 | 4786 | |
4524 | - if (isset($context['menu_buttons'][$current_action])) |
|
4525 | - $context['menu_buttons'][$current_action]['active_button'] = true; |
|
4526 | -} |
|
4787 | + if (isset($context['menu_buttons'][$current_action])) { |
|
4788 | + $context['menu_buttons'][$current_action]['active_button'] = true; |
|
4789 | + } |
|
4790 | + } |
|
4527 | 4791 | |
4528 | 4792 | /** |
4529 | 4793 | * Generate a random seed and ensure it's stored in settings. |
@@ -4547,30 +4811,35 @@ discard block |
||
4547 | 4811 | global $modSettings, $settings, $boarddir, $sourcedir, $db_show_debug; |
4548 | 4812 | global $context, $txt; |
4549 | 4813 | |
4550 | - if ($db_show_debug === true) |
|
4551 | - $context['debug']['hooks'][] = $hook; |
|
4814 | + if ($db_show_debug === true) { |
|
4815 | + $context['debug']['hooks'][] = $hook; |
|
4816 | + } |
|
4552 | 4817 | |
4553 | 4818 | // Need to have some control. |
4554 | - if (!isset($context['instances'])) |
|
4555 | - $context['instances'] = array(); |
|
4819 | + if (!isset($context['instances'])) { |
|
4820 | + $context['instances'] = array(); |
|
4821 | + } |
|
4556 | 4822 | |
4557 | 4823 | $results = array(); |
4558 | - if (empty($modSettings[$hook])) |
|
4559 | - return $results; |
|
4824 | + if (empty($modSettings[$hook])) { |
|
4825 | + return $results; |
|
4826 | + } |
|
4560 | 4827 | |
4561 | 4828 | $functions = explode(',', $modSettings[$hook]); |
4562 | 4829 | // Loop through each function. |
4563 | 4830 | foreach ($functions as $function) |
4564 | 4831 | { |
4565 | 4832 | // Hook has been marked as "disabled". Skip it! |
4566 | - if (strpos($function, '!') !== false) |
|
4567 | - continue; |
|
4833 | + if (strpos($function, '!') !== false) { |
|
4834 | + continue; |
|
4835 | + } |
|
4568 | 4836 | |
4569 | 4837 | $call = call_helper($function, true); |
4570 | 4838 | |
4571 | 4839 | // Is it valid? |
4572 | - if (!empty($call)) |
|
4573 | - $results[$function] = call_user_func_array($call, $parameters); |
|
4840 | + if (!empty($call)) { |
|
4841 | + $results[$function] = call_user_func_array($call, $parameters); |
|
4842 | + } |
|
4574 | 4843 | |
4575 | 4844 | // Whatever it was suppose to call, it failed :( |
4576 | 4845 | elseif (!empty($function)) |
@@ -4586,8 +4855,9 @@ discard block |
||
4586 | 4855 | } |
4587 | 4856 | |
4588 | 4857 | // "Assume" the file resides on $boarddir somewhere... |
4589 | - else |
|
4590 | - log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general'); |
|
4858 | + else { |
|
4859 | + log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general'); |
|
4860 | + } |
|
4591 | 4861 | } |
4592 | 4862 | } |
4593 | 4863 | |
@@ -4609,12 +4879,14 @@ discard block |
||
4609 | 4879 | global $smcFunc, $modSettings; |
4610 | 4880 | |
4611 | 4881 | // Any objects? |
4612 | - if ($object) |
|
4613 | - $function = $function . '#'; |
|
4882 | + if ($object) { |
|
4883 | + $function = $function . '#'; |
|
4884 | + } |
|
4614 | 4885 | |
4615 | 4886 | // Any files to load? |
4616 | - if (!empty($file) && is_string($file)) |
|
4617 | - $function = $file . (!empty($function) ? '|' . $function : ''); |
|
4887 | + if (!empty($file) && is_string($file)) { |
|
4888 | + $function = $file . (!empty($function) ? '|' . $function : ''); |
|
4889 | + } |
|
4618 | 4890 | |
4619 | 4891 | // Get the correct string. |
4620 | 4892 | $integration_call = $function; |
@@ -4636,13 +4908,14 @@ discard block |
||
4636 | 4908 | if (!empty($current_functions)) |
4637 | 4909 | { |
4638 | 4910 | $current_functions = explode(',', $current_functions); |
4639 | - if (in_array($integration_call, $current_functions)) |
|
4640 | - return; |
|
4911 | + if (in_array($integration_call, $current_functions)) { |
|
4912 | + return; |
|
4913 | + } |
|
4641 | 4914 | |
4642 | 4915 | $permanent_functions = array_merge($current_functions, array($integration_call)); |
4916 | + } else { |
|
4917 | + $permanent_functions = array($integration_call); |
|
4643 | 4918 | } |
4644 | - else |
|
4645 | - $permanent_functions = array($integration_call); |
|
4646 | 4919 | |
4647 | 4920 | updateSettings(array($hook => implode(',', $permanent_functions))); |
4648 | 4921 | } |
@@ -4651,8 +4924,9 @@ discard block |
||
4651 | 4924 | $functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]); |
4652 | 4925 | |
4653 | 4926 | // Do nothing, if it's already there. |
4654 | - if (in_array($integration_call, $functions)) |
|
4655 | - return; |
|
4927 | + if (in_array($integration_call, $functions)) { |
|
4928 | + return; |
|
4929 | + } |
|
4656 | 4930 | |
4657 | 4931 | $functions[] = $integration_call; |
4658 | 4932 | $modSettings[$hook] = implode(',', $functions); |
@@ -4675,12 +4949,14 @@ discard block |
||
4675 | 4949 | global $smcFunc, $modSettings; |
4676 | 4950 | |
4677 | 4951 | // Any objects? |
4678 | - if ($object) |
|
4679 | - $function = $function . '#'; |
|
4952 | + if ($object) { |
|
4953 | + $function = $function . '#'; |
|
4954 | + } |
|
4680 | 4955 | |
4681 | 4956 | // Any files to load? |
4682 | - if (!empty($file) && is_string($file)) |
|
4683 | - $function = $file . '|' . $function; |
|
4957 | + if (!empty($file) && is_string($file)) { |
|
4958 | + $function = $file . '|' . $function; |
|
4959 | + } |
|
4684 | 4960 | |
4685 | 4961 | // Get the correct string. |
4686 | 4962 | $integration_call = $function; |
@@ -4701,16 +4977,18 @@ discard block |
||
4701 | 4977 | { |
4702 | 4978 | $current_functions = explode(',', $current_functions); |
4703 | 4979 | |
4704 | - if (in_array($integration_call, $current_functions)) |
|
4705 | - updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call))))); |
|
4980 | + if (in_array($integration_call, $current_functions)) { |
|
4981 | + updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call))))); |
|
4982 | + } |
|
4706 | 4983 | } |
4707 | 4984 | |
4708 | 4985 | // Turn the function list into something usable. |
4709 | 4986 | $functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]); |
4710 | 4987 | |
4711 | 4988 | // You can only remove it if it's available. |
4712 | - if (!in_array($integration_call, $functions)) |
|
4713 | - return; |
|
4989 | + if (!in_array($integration_call, $functions)) { |
|
4990 | + return; |
|
4991 | + } |
|
4714 | 4992 | |
4715 | 4993 | $functions = array_diff($functions, array($integration_call)); |
4716 | 4994 | $modSettings[$hook] = implode(',', $functions); |
@@ -4731,17 +5009,20 @@ discard block |
||
4731 | 5009 | global $context, $smcFunc, $txt, $db_show_debug; |
4732 | 5010 | |
4733 | 5011 | // Really? |
4734 | - if (empty($string)) |
|
4735 | - return false; |
|
5012 | + if (empty($string)) { |
|
5013 | + return false; |
|
5014 | + } |
|
4736 | 5015 | |
4737 | 5016 | // An array? should be a "callable" array IE array(object/class, valid_callable). |
4738 | 5017 | // A closure? should be a callable one. |
4739 | - if (is_array($string) || $string instanceof Closure) |
|
4740 | - return $return ? $string : (is_callable($string) ? call_user_func($string) : false); |
|
5018 | + if (is_array($string) || $string instanceof Closure) { |
|
5019 | + return $return ? $string : (is_callable($string) ? call_user_func($string) : false); |
|
5020 | + } |
|
4741 | 5021 | |
4742 | 5022 | // No full objects, sorry! pass a method or a property instead! |
4743 | - if (is_object($string)) |
|
4744 | - return false; |
|
5023 | + if (is_object($string)) { |
|
5024 | + return false; |
|
5025 | + } |
|
4745 | 5026 | |
4746 | 5027 | // Stay vitaminized my friends... |
4747 | 5028 | $string = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($string)); |
@@ -4750,8 +5031,9 @@ discard block |
||
4750 | 5031 | $string = load_file($string); |
4751 | 5032 | |
4752 | 5033 | // Loaded file failed |
4753 | - if (empty($string)) |
|
4754 | - return false; |
|
5034 | + if (empty($string)) { |
|
5035 | + return false; |
|
5036 | + } |
|
4755 | 5037 | |
4756 | 5038 | // Found a method. |
4757 | 5039 | if (strpos($string, '::') !== false) |
@@ -4772,8 +5054,9 @@ discard block |
||
4772 | 5054 | // Add another one to the list. |
4773 | 5055 | if ($db_show_debug === true) |
4774 | 5056 | { |
4775 | - if (!isset($context['debug']['instances'])) |
|
4776 | - $context['debug']['instances'] = array(); |
|
5057 | + if (!isset($context['debug']['instances'])) { |
|
5058 | + $context['debug']['instances'] = array(); |
|
5059 | + } |
|
4777 | 5060 | |
4778 | 5061 | $context['debug']['instances'][$class] = $class; |
4779 | 5062 | } |
@@ -4783,13 +5066,15 @@ discard block |
||
4783 | 5066 | } |
4784 | 5067 | |
4785 | 5068 | // Right then. This is a call to a static method. |
4786 | - else |
|
4787 | - $func = array($class, $method); |
|
5069 | + else { |
|
5070 | + $func = array($class, $method); |
|
5071 | + } |
|
4788 | 5072 | } |
4789 | 5073 | |
4790 | 5074 | // Nope! just a plain regular function. |
4791 | - else |
|
4792 | - $func = $string; |
|
5075 | + else { |
|
5076 | + $func = $string; |
|
5077 | + } |
|
4793 | 5078 | |
4794 | 5079 | // Right, we got what we need, time to do some checks. |
4795 | 5080 | if (!is_callable($func, false, $callable_name)) |
@@ -4805,17 +5090,18 @@ discard block |
||
4805 | 5090 | else |
4806 | 5091 | { |
4807 | 5092 | // What are we gonna do about it? |
4808 | - if ($return) |
|
4809 | - return $func; |
|
5093 | + if ($return) { |
|
5094 | + return $func; |
|
5095 | + } |
|
4810 | 5096 | |
4811 | 5097 | // If this is a plain function, avoid the heat of calling call_user_func(). |
4812 | 5098 | else |
4813 | 5099 | { |
4814 | - if (is_array($func)) |
|
4815 | - call_user_func($func); |
|
4816 | - |
|
4817 | - else |
|
4818 | - $func(); |
|
5100 | + if (is_array($func)) { |
|
5101 | + call_user_func($func); |
|
5102 | + } else { |
|
5103 | + $func(); |
|
5104 | + } |
|
4819 | 5105 | } |
4820 | 5106 | } |
4821 | 5107 | } |
@@ -4832,31 +5118,34 @@ discard block |
||
4832 | 5118 | { |
4833 | 5119 | global $sourcedir, $txt, $boarddir, $settings; |
4834 | 5120 | |
4835 | - if (empty($string)) |
|
4836 | - return false; |
|
5121 | + if (empty($string)) { |
|
5122 | + return false; |
|
5123 | + } |
|
4837 | 5124 | |
4838 | 5125 | if (strpos($string, '|') !== false) |
4839 | 5126 | { |
4840 | 5127 | list ($file, $string) = explode('|', $string); |
4841 | 5128 | |
4842 | 5129 | // Match the wildcards to their regular vars. |
4843 | - if (empty($settings['theme_dir'])) |
|
4844 | - $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
|
4845 | - |
|
4846 | - else |
|
4847 | - $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
|
5130 | + if (empty($settings['theme_dir'])) { |
|
5131 | + $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
|
5132 | + } else { |
|
5133 | + $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
|
5134 | + } |
|
4848 | 5135 | |
4849 | 5136 | // Load the file if it can be loaded. |
4850 | - if (file_exists($absPath)) |
|
4851 | - require_once($absPath); |
|
5137 | + if (file_exists($absPath)) { |
|
5138 | + require_once($absPath); |
|
5139 | + } |
|
4852 | 5140 | |
4853 | 5141 | // No? try a fallback to $sourcedir |
4854 | 5142 | else |
4855 | 5143 | { |
4856 | 5144 | $absPath = $sourcedir .'/'. $file; |
4857 | 5145 | |
4858 | - if (file_exists($absPath)) |
|
4859 | - require_once($absPath); |
|
5146 | + if (file_exists($absPath)) { |
|
5147 | + require_once($absPath); |
|
5148 | + } |
|
4860 | 5149 | |
4861 | 5150 | // Sorry, can't do much for you at this point. |
4862 | 5151 | else |
@@ -4895,8 +5184,9 @@ discard block |
||
4895 | 5184 | preg_match('~^(http|ftp)(s)?://([^/:]+)(:(\d+))?(.+)$~', $url, $match); |
4896 | 5185 | |
4897 | 5186 | // No scheme? No data for you! |
4898 | - if (empty($match[1])) |
|
4899 | - return false; |
|
5187 | + if (empty($match[1])) { |
|
5188 | + return false; |
|
5189 | + } |
|
4900 | 5190 | |
4901 | 5191 | // An FTP url. We should try connecting and RETRieving it... |
4902 | 5192 | elseif ($match[1] == 'ftp') |
@@ -4906,23 +5196,26 @@ discard block |
||
4906 | 5196 | |
4907 | 5197 | // Establish a connection and attempt to enable passive mode. |
4908 | 5198 | $ftp = new ftp_connection(($match[2] ? 'ssl://' : '') . $match[3], empty($match[5]) ? 21 : $match[5], 'anonymous', $webmaster_email); |
4909 | - if ($ftp->error !== false || !$ftp->passive()) |
|
4910 | - return false; |
|
5199 | + if ($ftp->error !== false || !$ftp->passive()) { |
|
5200 | + return false; |
|
5201 | + } |
|
4911 | 5202 | |
4912 | 5203 | // I want that one *points*! |
4913 | 5204 | fwrite($ftp->connection, 'RETR ' . $match[6] . "\r\n"); |
4914 | 5205 | |
4915 | 5206 | // Since passive mode worked (or we would have returned already!) open the connection. |
4916 | 5207 | $fp = @fsockopen($ftp->pasv['ip'], $ftp->pasv['port'], $err, $err, 5); |
4917 | - if (!$fp) |
|
4918 | - return false; |
|
5208 | + if (!$fp) { |
|
5209 | + return false; |
|
5210 | + } |
|
4919 | 5211 | |
4920 | 5212 | // The server should now say something in acknowledgement. |
4921 | 5213 | $ftp->check_response(150); |
4922 | 5214 | |
4923 | 5215 | $data = ''; |
4924 | - while (!feof($fp)) |
|
4925 | - $data .= fread($fp, 4096); |
|
5216 | + while (!feof($fp)) { |
|
5217 | + $data .= fread($fp, 4096); |
|
5218 | + } |
|
4926 | 5219 | fclose($fp); |
4927 | 5220 | |
4928 | 5221 | // All done, right? Good. |
@@ -4934,8 +5227,9 @@ discard block |
||
4934 | 5227 | elseif (isset($match[1]) && $match[1] == 'http') |
4935 | 5228 | { |
4936 | 5229 | // First try to use fsockopen, because it is fastest. |
4937 | - if ($keep_alive && $match[3] == $keep_alive_dom) |
|
4938 | - $fp = $keep_alive_fp; |
|
5230 | + if ($keep_alive && $match[3] == $keep_alive_dom) { |
|
5231 | + $fp = $keep_alive_fp; |
|
5232 | + } |
|
4939 | 5233 | if (empty($fp)) |
4940 | 5234 | { |
4941 | 5235 | // Open the socket on the port we want... |
@@ -4955,20 +5249,21 @@ discard block |
||
4955 | 5249 | fwrite($fp, 'GET ' . ($match[6] !== '/' ? str_replace(' ', '%20', $match[6]) : '') . ' HTTP/1.0' . "\r\n"); |
4956 | 5250 | fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n"); |
4957 | 5251 | fwrite($fp, 'user-agent: PHP/SMF' . "\r\n"); |
4958 | - if ($keep_alive) |
|
4959 | - fwrite($fp, 'connection: Keep-Alive' . "\r\n\r\n"); |
|
4960 | - else |
|
4961 | - fwrite($fp, 'connection: close' . "\r\n\r\n"); |
|
4962 | - } |
|
4963 | - else |
|
5252 | + if ($keep_alive) { |
|
5253 | + fwrite($fp, 'connection: Keep-Alive' . "\r\n\r\n"); |
|
5254 | + } else { |
|
5255 | + fwrite($fp, 'connection: close' . "\r\n\r\n"); |
|
5256 | + } |
|
5257 | + } else |
|
4964 | 5258 | { |
4965 | 5259 | fwrite($fp, 'POST ' . ($match[6] !== '/' ? $match[6] : '') . ' HTTP/1.0' . "\r\n"); |
4966 | 5260 | fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n"); |
4967 | 5261 | fwrite($fp, 'user-agent: PHP/SMF' . "\r\n"); |
4968 | - if ($keep_alive) |
|
4969 | - fwrite($fp, 'connection: Keep-Alive' . "\r\n"); |
|
4970 | - else |
|
4971 | - fwrite($fp, 'connection: close' . "\r\n"); |
|
5262 | + if ($keep_alive) { |
|
5263 | + fwrite($fp, 'connection: Keep-Alive' . "\r\n"); |
|
5264 | + } else { |
|
5265 | + fwrite($fp, 'connection: close' . "\r\n"); |
|
5266 | + } |
|
4972 | 5267 | fwrite($fp, 'content-type: application/x-www-form-urlencoded' . "\r\n"); |
4973 | 5268 | fwrite($fp, 'content-length: ' . strlen($post_data) . "\r\n\r\n"); |
4974 | 5269 | fwrite($fp, $post_data); |
@@ -4981,30 +5276,33 @@ discard block |
||
4981 | 5276 | { |
4982 | 5277 | $header = ''; |
4983 | 5278 | $location = ''; |
4984 | - while (!feof($fp) && trim($header = fgets($fp, 4096)) != '') |
|
4985 | - if (strpos($header, 'location:') !== false) |
|
5279 | + while (!feof($fp) && trim($header = fgets($fp, 4096)) != '') { |
|
5280 | + if (strpos($header, 'location:') !== false) |
|
4986 | 5281 | $location = trim(substr($header, strpos($header, ':') + 1)); |
5282 | + } |
|
4987 | 5283 | |
4988 | - if (empty($location)) |
|
4989 | - return false; |
|
4990 | - else |
|
5284 | + if (empty($location)) { |
|
5285 | + return false; |
|
5286 | + } else |
|
4991 | 5287 | { |
4992 | - if (!$keep_alive) |
|
4993 | - fclose($fp); |
|
5288 | + if (!$keep_alive) { |
|
5289 | + fclose($fp); |
|
5290 | + } |
|
4994 | 5291 | return fetch_web_data($location, $post_data, $keep_alive, $redirection_level + 1); |
4995 | 5292 | } |
4996 | 5293 | } |
4997 | 5294 | |
4998 | 5295 | // Make sure we get a 200 OK. |
4999 | - elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0) |
|
5000 | - return false; |
|
5296 | + elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0) { |
|
5297 | + return false; |
|
5298 | + } |
|
5001 | 5299 | |
5002 | 5300 | // Skip the headers... |
5003 | 5301 | while (!feof($fp) && trim($header = fgets($fp, 4096)) != '') |
5004 | 5302 | { |
5005 | - if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0) |
|
5006 | - $content_length = $match[1]; |
|
5007 | - elseif (preg_match('~connection:\s*close~i', $header) != 0) |
|
5303 | + if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0) { |
|
5304 | + $content_length = $match[1]; |
|
5305 | + } elseif (preg_match('~connection:\s*close~i', $header) != 0) |
|
5008 | 5306 | { |
5009 | 5307 | $keep_alive_dom = null; |
5010 | 5308 | $keep_alive = false; |
@@ -5016,17 +5314,19 @@ discard block |
||
5016 | 5314 | $data = ''; |
5017 | 5315 | if (isset($content_length)) |
5018 | 5316 | { |
5019 | - while (!feof($fp) && strlen($data) < $content_length) |
|
5020 | - $data .= fread($fp, $content_length - strlen($data)); |
|
5021 | - } |
|
5022 | - else |
|
5317 | + while (!feof($fp) && strlen($data) < $content_length) { |
|
5318 | + $data .= fread($fp, $content_length - strlen($data)); |
|
5319 | + } |
|
5320 | + } else |
|
5023 | 5321 | { |
5024 | - while (!feof($fp)) |
|
5025 | - $data .= fread($fp, 4096); |
|
5322 | + while (!feof($fp)) { |
|
5323 | + $data .= fread($fp, 4096); |
|
5324 | + } |
|
5026 | 5325 | } |
5027 | 5326 | |
5028 | - if (!$keep_alive) |
|
5029 | - fclose($fp); |
|
5327 | + if (!$keep_alive) { |
|
5328 | + fclose($fp); |
|
5329 | + } |
|
5030 | 5330 | } |
5031 | 5331 | |
5032 | 5332 | // If using fsockopen didn't work, try to use cURL if available. |
@@ -5039,17 +5339,18 @@ discard block |
||
5039 | 5339 | $fetch_data->get_url_data($url, $post_data); |
5040 | 5340 | |
5041 | 5341 | // no errors and a 200 result, then we have a good dataset, well we at least have data. ;) |
5042 | - if ($fetch_data->result('code') == 200 && !$fetch_data->result('error')) |
|
5043 | - $data = $fetch_data->result('body'); |
|
5044 | - else |
|
5045 | - return false; |
|
5342 | + if ($fetch_data->result('code') == 200 && !$fetch_data->result('error')) { |
|
5343 | + $data = $fetch_data->result('body'); |
|
5344 | + } else { |
|
5345 | + return false; |
|
5346 | + } |
|
5046 | 5347 | } |
5047 | 5348 | |
5048 | 5349 | // Neither fsockopen nor curl are available. Well, phooey. |
5049 | - else |
|
5050 | - return false; |
|
5051 | - } |
|
5052 | - else |
|
5350 | + else { |
|
5351 | + return false; |
|
5352 | + } |
|
5353 | + } else |
|
5053 | 5354 | { |
5054 | 5355 | // Umm, this shouldn't happen? |
5055 | 5356 | trigger_error('fetch_web_data(): Bad URL', E_USER_NOTICE); |
@@ -5069,8 +5370,9 @@ discard block |
||
5069 | 5370 | global $user_info, $smcFunc; |
5070 | 5371 | |
5071 | 5372 | // Make sure we have something to work with. |
5072 | - if (empty($topic)) |
|
5073 | - return array(); |
|
5373 | + if (empty($topic)) { |
|
5374 | + return array(); |
|
5375 | + } |
|
5074 | 5376 | |
5075 | 5377 | |
5076 | 5378 | // We already know the number of likes per message, we just want to know whether the current user liked it or not. |
@@ -5093,8 +5395,9 @@ discard block |
||
5093 | 5395 | 'topic' => $topic, |
5094 | 5396 | ) |
5095 | 5397 | ); |
5096 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
5097 | - $temp[] = (int) $row['content_id']; |
|
5398 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
5399 | + $temp[] = (int) $row['content_id']; |
|
5400 | + } |
|
5098 | 5401 | |
5099 | 5402 | cache_put_data($cache_key, $temp, $ttl); |
5100 | 5403 | } |
@@ -5115,8 +5418,9 @@ discard block |
||
5115 | 5418 | { |
5116 | 5419 | global $context; |
5117 | 5420 | |
5118 | - if (empty($string)) |
|
5119 | - return $string; |
|
5421 | + if (empty($string)) { |
|
5422 | + return $string; |
|
5423 | + } |
|
5120 | 5424 | |
5121 | 5425 | // UTF-8 occurences of MS special characters |
5122 | 5426 | $findchars_utf8 = array( |
@@ -5157,10 +5461,11 @@ discard block |
||
5157 | 5461 | '--', // — |
5158 | 5462 | ); |
5159 | 5463 | |
5160 | - if ($context['utf8']) |
|
5161 | - $string = str_replace($findchars_utf8, $replacechars, $string); |
|
5162 | - else |
|
5163 | - $string = str_replace($findchars_iso, $replacechars, $string); |
|
5464 | + if ($context['utf8']) { |
|
5465 | + $string = str_replace($findchars_utf8, $replacechars, $string); |
|
5466 | + } else { |
|
5467 | + $string = str_replace($findchars_iso, $replacechars, $string); |
|
5468 | + } |
|
5164 | 5469 | |
5165 | 5470 | return $string; |
5166 | 5471 | } |
@@ -5179,49 +5484,59 @@ discard block |
||
5179 | 5484 | { |
5180 | 5485 | global $context; |
5181 | 5486 | |
5182 | - if (!isset($matches[2])) |
|
5183 | - return ''; |
|
5487 | + if (!isset($matches[2])) { |
|
5488 | + return ''; |
|
5489 | + } |
|
5184 | 5490 | |
5185 | 5491 | $num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2]; |
5186 | 5492 | |
5187 | 5493 | // remove left to right / right to left overrides |
5188 | - if ($num === 0x202D || $num === 0x202E) |
|
5189 | - return ''; |
|
5494 | + if ($num === 0x202D || $num === 0x202E) { |
|
5495 | + return ''; |
|
5496 | + } |
|
5190 | 5497 | |
5191 | 5498 | // Quote, Ampersand, Apostrophe, Less/Greater Than get html replaced |
5192 | - if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) |
|
5193 | - return '&#' . $num . ';'; |
|
5499 | + if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) { |
|
5500 | + return '&#' . $num . ';'; |
|
5501 | + } |
|
5194 | 5502 | |
5195 | 5503 | if (empty($context['utf8'])) |
5196 | 5504 | { |
5197 | 5505 | // no control characters |
5198 | - if ($num < 0x20) |
|
5199 | - return ''; |
|
5506 | + if ($num < 0x20) { |
|
5507 | + return ''; |
|
5508 | + } |
|
5200 | 5509 | // text is text |
5201 | - elseif ($num < 0x80) |
|
5202 | - return chr($num); |
|
5510 | + elseif ($num < 0x80) { |
|
5511 | + return chr($num); |
|
5512 | + } |
|
5203 | 5513 | // all others get html-ised |
5204 | - else |
|
5205 | - return '&#' . $matches[2] . ';'; |
|
5206 | - } |
|
5207 | - else |
|
5514 | + else { |
|
5515 | + return '&#' . $matches[2] . ';'; |
|
5516 | + } |
|
5517 | + } else |
|
5208 | 5518 | { |
5209 | 5519 | // <0x20 are control characters, 0x20 is a space, > 0x10FFFF is past the end of the utf8 character set |
5210 | 5520 | // 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text) |
5211 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) |
|
5212 | - return ''; |
|
5521 | + if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) { |
|
5522 | + return ''; |
|
5523 | + } |
|
5213 | 5524 | // <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation |
5214 | - elseif ($num < 0x80) |
|
5215 | - return chr($num); |
|
5525 | + elseif ($num < 0x80) { |
|
5526 | + return chr($num); |
|
5527 | + } |
|
5216 | 5528 | // <0x800 (2048) |
5217 | - elseif ($num < 0x800) |
|
5218 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
5529 | + elseif ($num < 0x800) { |
|
5530 | + return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
5531 | + } |
|
5219 | 5532 | // < 0x10000 (65536) |
5220 | - elseif ($num < 0x10000) |
|
5221 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5533 | + elseif ($num < 0x10000) { |
|
5534 | + return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5535 | + } |
|
5222 | 5536 | // <= 0x10FFFF (1114111) |
5223 | - else |
|
5224 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5537 | + else { |
|
5538 | + return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5539 | + } |
|
5225 | 5540 | } |
5226 | 5541 | } |
5227 | 5542 | |
@@ -5237,28 +5552,34 @@ discard block |
||
5237 | 5552 | */ |
5238 | 5553 | function fixchar__callback($matches) |
5239 | 5554 | { |
5240 | - if (!isset($matches[1])) |
|
5241 | - return ''; |
|
5555 | + if (!isset($matches[1])) { |
|
5556 | + return ''; |
|
5557 | + } |
|
5242 | 5558 | |
5243 | 5559 | $num = $matches[1][0] === 'x' ? hexdec(substr($matches[1], 1)) : (int) $matches[1]; |
5244 | 5560 | |
5245 | 5561 | // <0x20 are control characters, > 0x10FFFF is past the end of the utf8 character set |
5246 | 5562 | // 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text), 0x202D-E are left to right overrides |
5247 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) |
|
5248 | - return ''; |
|
5563 | + if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) { |
|
5564 | + return ''; |
|
5565 | + } |
|
5249 | 5566 | // <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation |
5250 | - elseif ($num < 0x80) |
|
5251 | - return chr($num); |
|
5567 | + elseif ($num < 0x80) { |
|
5568 | + return chr($num); |
|
5569 | + } |
|
5252 | 5570 | // <0x800 (2048) |
5253 | - elseif ($num < 0x800) |
|
5254 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
5571 | + elseif ($num < 0x800) { |
|
5572 | + return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
5573 | + } |
|
5255 | 5574 | // < 0x10000 (65536) |
5256 | - elseif ($num < 0x10000) |
|
5257 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5575 | + elseif ($num < 0x10000) { |
|
5576 | + return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5577 | + } |
|
5258 | 5578 | // <= 0x10FFFF (1114111) |
5259 | - else |
|
5260 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5261 | -} |
|
5579 | + else { |
|
5580 | + return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5581 | + } |
|
5582 | + } |
|
5262 | 5583 | |
5263 | 5584 | /** |
5264 | 5585 | * Strips out invalid html entities, replaces others with html style { codes |
@@ -5271,17 +5592,19 @@ discard block |
||
5271 | 5592 | */ |
5272 | 5593 | function entity_fix__callback($matches) |
5273 | 5594 | { |
5274 | - if (!isset($matches[2])) |
|
5275 | - return ''; |
|
5595 | + if (!isset($matches[2])) { |
|
5596 | + return ''; |
|
5597 | + } |
|
5276 | 5598 | |
5277 | 5599 | $num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2]; |
5278 | 5600 | |
5279 | 5601 | // we don't allow control characters, characters out of range, byte markers, etc |
5280 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) |
|
5281 | - return ''; |
|
5282 | - else |
|
5283 | - return '&#' . $num . ';'; |
|
5284 | -} |
|
5602 | + if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) { |
|
5603 | + return ''; |
|
5604 | + } else { |
|
5605 | + return '&#' . $num . ';'; |
|
5606 | + } |
|
5607 | + } |
|
5285 | 5608 | |
5286 | 5609 | /** |
5287 | 5610 | * Return a Gravatar URL based on |
@@ -5305,18 +5628,23 @@ discard block |
||
5305 | 5628 | $ratings = array('G', 'PG', 'R', 'X'); |
5306 | 5629 | $defaults = array('mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank'); |
5307 | 5630 | $url_params = array(); |
5308 | - if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) |
|
5309 | - $url_params[] = 'rating=' . $modSettings['gravatarMaxRating']; |
|
5310 | - if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) |
|
5311 | - $url_params[] = 'default=' . $modSettings['gravatarDefault']; |
|
5312 | - if (!empty($modSettings['avatar_max_width_external'])) |
|
5313 | - $size_string = (int) $modSettings['avatar_max_width_external']; |
|
5314 | - if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) |
|
5315 | - if ((int) $modSettings['avatar_max_height_external'] < $size_string) |
|
5631 | + if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) { |
|
5632 | + $url_params[] = 'rating=' . $modSettings['gravatarMaxRating']; |
|
5633 | + } |
|
5634 | + if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) { |
|
5635 | + $url_params[] = 'default=' . $modSettings['gravatarDefault']; |
|
5636 | + } |
|
5637 | + if (!empty($modSettings['avatar_max_width_external'])) { |
|
5638 | + $size_string = (int) $modSettings['avatar_max_width_external']; |
|
5639 | + } |
|
5640 | + if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) { |
|
5641 | + if ((int) $modSettings['avatar_max_height_external'] < $size_string) |
|
5316 | 5642 | $size_string = $modSettings['avatar_max_height_external']; |
5643 | + } |
|
5317 | 5644 | |
5318 | - if (!empty($size_string)) |
|
5319 | - $url_params[] = 's=' . $size_string; |
|
5645 | + if (!empty($size_string)) { |
|
5646 | + $url_params[] = 's=' . $size_string; |
|
5647 | + } |
|
5320 | 5648 | } |
5321 | 5649 | $http_method = !empty($modSettings['force_ssl']) ? 'https://secure' : 'http://www'; |
5322 | 5650 | |
@@ -5335,22 +5663,26 @@ discard block |
||
5335 | 5663 | static $timezones = null, $lastwhen = null; |
5336 | 5664 | |
5337 | 5665 | // No point doing this over if we already did it once |
5338 | - if (!empty($timezones) && $when == $lastwhen) |
|
5339 | - return $timezones; |
|
5340 | - else |
|
5341 | - $lastwhen = $when; |
|
5666 | + if (!empty($timezones) && $when == $lastwhen) { |
|
5667 | + return $timezones; |
|
5668 | + } else { |
|
5669 | + $lastwhen = $when; |
|
5670 | + } |
|
5342 | 5671 | |
5343 | 5672 | // Parseable datetime string? |
5344 | - if (is_int($timestamp = strtotime($when))) |
|
5345 | - $when = $timestamp; |
|
5673 | + if (is_int($timestamp = strtotime($when))) { |
|
5674 | + $when = $timestamp; |
|
5675 | + } |
|
5346 | 5676 | |
5347 | 5677 | // A Unix timestamp? |
5348 | - elseif (is_numeric($when)) |
|
5349 | - $when = intval($when); |
|
5678 | + elseif (is_numeric($when)) { |
|
5679 | + $when = intval($when); |
|
5680 | + } |
|
5350 | 5681 | |
5351 | 5682 | // Invalid value? Just get current Unix timestamp. |
5352 | - else |
|
5353 | - $when = time(); |
|
5683 | + else { |
|
5684 | + $when = time(); |
|
5685 | + } |
|
5354 | 5686 | |
5355 | 5687 | // We'll need these too |
5356 | 5688 | $date_when = date_create('@' . $when); |
@@ -5414,8 +5746,9 @@ discard block |
||
5414 | 5746 | foreach ($priority_countries as $country) |
5415 | 5747 | { |
5416 | 5748 | $country_tzids = @timezone_identifiers_list(DateTimeZone::PER_COUNTRY, strtoupper(trim($country))); |
5417 | - if (!empty($country_tzids)) |
|
5418 | - $priority_tzids = array_merge($priority_tzids, $country_tzids); |
|
5749 | + if (!empty($country_tzids)) { |
|
5750 | + $priority_tzids = array_merge($priority_tzids, $country_tzids); |
|
5751 | + } |
|
5419 | 5752 | } |
5420 | 5753 | |
5421 | 5754 | // Process the preferred timezones first, then the rest. |
@@ -5425,8 +5758,9 @@ discard block |
||
5425 | 5758 | foreach ($tzids as $tzid) |
5426 | 5759 | { |
5427 | 5760 | // We don't want UTC right now |
5428 | - if ($tzid == 'UTC') |
|
5429 | - continue; |
|
5761 | + if ($tzid == 'UTC') { |
|
5762 | + continue; |
|
5763 | + } |
|
5430 | 5764 | |
5431 | 5765 | $tz = timezone_open($tzid); |
5432 | 5766 | |
@@ -5447,8 +5781,9 @@ discard block |
||
5447 | 5781 | } |
5448 | 5782 | |
5449 | 5783 | // A time zone from a prioritized country? |
5450 | - if (in_array($tzid, $priority_tzids)) |
|
5451 | - $priority_zones[$tzkey] = true; |
|
5784 | + if (in_array($tzid, $priority_tzids)) { |
|
5785 | + $priority_zones[$tzkey] = true; |
|
5786 | + } |
|
5452 | 5787 | |
5453 | 5788 | // Keep track of the location and offset for this tzid |
5454 | 5789 | $tzid_parts = explode('/', $tzid); |
@@ -5467,15 +5802,17 @@ discard block |
||
5467 | 5802 | { |
5468 | 5803 | date_timezone_set($date_when, timezone_open($tzvalue['tzid'])); |
5469 | 5804 | |
5470 | - if (!empty($timezone_descriptions[$tzvalue['tzid']])) |
|
5471 | - $desc = $timezone_descriptions[$tzvalue['tzid']]; |
|
5472 | - else |
|
5473 | - $desc = implode(', ', array_unique($tzvalue['locations'])); |
|
5805 | + if (!empty($timezone_descriptions[$tzvalue['tzid']])) { |
|
5806 | + $desc = $timezone_descriptions[$tzvalue['tzid']]; |
|
5807 | + } else { |
|
5808 | + $desc = implode(', ', array_unique($tzvalue['locations'])); |
|
5809 | + } |
|
5474 | 5810 | |
5475 | - if (isset($priority_zones[$tzkey])) |
|
5476 | - $priority_timezones[$tzvalue['tzid']] = $tzvalue['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']'; |
|
5477 | - else |
|
5478 | - $timezones[$tzvalue['tzid']] = $tzvalue['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']'; |
|
5811 | + if (isset($priority_zones[$tzkey])) { |
|
5812 | + $priority_timezones[$tzvalue['tzid']] = $tzvalue['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']'; |
|
5813 | + } else { |
|
5814 | + $timezones[$tzvalue['tzid']] = $tzvalue['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']'; |
|
5815 | + } |
|
5479 | 5816 | } |
5480 | 5817 | |
5481 | 5818 | $timezones = array_merge( |
@@ -5529,9 +5866,9 @@ discard block |
||
5529 | 5866 | 'Indian/Kerguelen' => 'TFT', |
5530 | 5867 | ); |
5531 | 5868 | |
5532 | - if (!empty($missing_tz_abbrs[$tzid])) |
|
5533 | - $tz_abbrev = $missing_tz_abbrs[$tzid]; |
|
5534 | - else |
|
5869 | + if (!empty($missing_tz_abbrs[$tzid])) { |
|
5870 | + $tz_abbrev = $missing_tz_abbrs[$tzid]; |
|
5871 | + } else |
|
5535 | 5872 | { |
5536 | 5873 | // Russia likes to experiment with time zones often, and names them as offsets from Moscow |
5537 | 5874 | $tz_location = timezone_location_get(timezone_open($tzid)); |
@@ -5559,8 +5896,9 @@ discard block |
||
5559 | 5896 | */ |
5560 | 5897 | function inet_ptod($ip_address) |
5561 | 5898 | { |
5562 | - if (!isValidIP($ip_address)) |
|
5563 | - return $ip_address; |
|
5899 | + if (!isValidIP($ip_address)) { |
|
5900 | + return $ip_address; |
|
5901 | + } |
|
5564 | 5902 | |
5565 | 5903 | $bin = inet_pton($ip_address); |
5566 | 5904 | return $bin; |
@@ -5572,13 +5910,15 @@ discard block |
||
5572 | 5910 | */ |
5573 | 5911 | function inet_dtop($bin) |
5574 | 5912 | { |
5575 | - if(empty($bin)) |
|
5576 | - return ''; |
|
5913 | + if(empty($bin)) { |
|
5914 | + return ''; |
|
5915 | + } |
|
5577 | 5916 | |
5578 | 5917 | global $db_type; |
5579 | 5918 | |
5580 | - if ($db_type == 'postgresql') |
|
5581 | - return $bin; |
|
5919 | + if ($db_type == 'postgresql') { |
|
5920 | + return $bin; |
|
5921 | + } |
|
5582 | 5922 | |
5583 | 5923 | $ip_address = inet_ntop($bin); |
5584 | 5924 | |
@@ -5603,26 +5943,32 @@ discard block |
||
5603 | 5943 | */ |
5604 | 5944 | function _safe_serialize($value) |
5605 | 5945 | { |
5606 | - if(is_null($value)) |
|
5607 | - return 'N;'; |
|
5946 | + if(is_null($value)) { |
|
5947 | + return 'N;'; |
|
5948 | + } |
|
5608 | 5949 | |
5609 | - if(is_bool($value)) |
|
5610 | - return 'b:'. (int) $value .';'; |
|
5950 | + if(is_bool($value)) { |
|
5951 | + return 'b:'. (int) $value .';'; |
|
5952 | + } |
|
5611 | 5953 | |
5612 | - if(is_int($value)) |
|
5613 | - return 'i:'. $value .';'; |
|
5954 | + if(is_int($value)) { |
|
5955 | + return 'i:'. $value .';'; |
|
5956 | + } |
|
5614 | 5957 | |
5615 | - if(is_float($value)) |
|
5616 | - return 'd:'. str_replace(',', '.', $value) .';'; |
|
5958 | + if(is_float($value)) { |
|
5959 | + return 'd:'. str_replace(',', '.', $value) .';'; |
|
5960 | + } |
|
5617 | 5961 | |
5618 | - if(is_string($value)) |
|
5619 | - return 's:'. strlen($value) .':"'. $value .'";'; |
|
5962 | + if(is_string($value)) { |
|
5963 | + return 's:'. strlen($value) .':"'. $value .'";'; |
|
5964 | + } |
|
5620 | 5965 | |
5621 | 5966 | if(is_array($value)) |
5622 | 5967 | { |
5623 | 5968 | $out = ''; |
5624 | - foreach($value as $k => $v) |
|
5625 | - $out .= _safe_serialize($k) . _safe_serialize($v); |
|
5969 | + foreach($value as $k => $v) { |
|
5970 | + $out .= _safe_serialize($k) . _safe_serialize($v); |
|
5971 | + } |
|
5626 | 5972 | |
5627 | 5973 | return 'a:'. count($value) .':{'. $out .'}'; |
5628 | 5974 | } |
@@ -5648,8 +5994,9 @@ discard block |
||
5648 | 5994 | |
5649 | 5995 | $out = _safe_serialize($value); |
5650 | 5996 | |
5651 | - if (isset($mbIntEnc)) |
|
5652 | - mb_internal_encoding($mbIntEnc); |
|
5997 | + if (isset($mbIntEnc)) { |
|
5998 | + mb_internal_encoding($mbIntEnc); |
|
5999 | + } |
|
5653 | 6000 | |
5654 | 6001 | return $out; |
5655 | 6002 | } |
@@ -5666,8 +6013,9 @@ discard block |
||
5666 | 6013 | function _safe_unserialize($str) |
5667 | 6014 | { |
5668 | 6015 | // Input is not a string. |
5669 | - if(empty($str) || !is_string($str)) |
|
5670 | - return false; |
|
6016 | + if(empty($str) || !is_string($str)) { |
|
6017 | + return false; |
|
6018 | + } |
|
5671 | 6019 | |
5672 | 6020 | $stack = array(); |
5673 | 6021 | $expected = array(); |
@@ -5683,43 +6031,38 @@ discard block |
||
5683 | 6031 | while($state != 1) |
5684 | 6032 | { |
5685 | 6033 | $type = isset($str[0]) ? $str[0] : ''; |
5686 | - if($type == '}') |
|
5687 | - $str = substr($str, 1); |
|
5688 | - |
|
5689 | - else if($type == 'N' && $str[1] == ';') |
|
6034 | + if($type == '}') { |
|
6035 | + $str = substr($str, 1); |
|
6036 | + } else if($type == 'N' && $str[1] == ';') |
|
5690 | 6037 | { |
5691 | 6038 | $value = null; |
5692 | 6039 | $str = substr($str, 2); |
5693 | - } |
|
5694 | - else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches)) |
|
6040 | + } else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches)) |
|
5695 | 6041 | { |
5696 | 6042 | $value = $matches[1] == '1' ? true : false; |
5697 | 6043 | $str = substr($str, 4); |
5698 | - } |
|
5699 | - else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches)) |
|
6044 | + } else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches)) |
|
5700 | 6045 | { |
5701 | 6046 | $value = (int)$matches[1]; |
5702 | 6047 | $str = $matches[2]; |
5703 | - } |
|
5704 | - else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches)) |
|
6048 | + } else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches)) |
|
5705 | 6049 | { |
5706 | 6050 | $value = (float)$matches[1]; |
5707 | 6051 | $str = $matches[3]; |
5708 | - } |
|
5709 | - else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";') |
|
6052 | + } else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";') |
|
5710 | 6053 | { |
5711 | 6054 | $value = substr($matches[2], 0, (int)$matches[1]); |
5712 | 6055 | $str = substr($matches[2], (int)$matches[1] + 2); |
5713 | - } |
|
5714 | - else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches)) |
|
6056 | + } else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches)) |
|
5715 | 6057 | { |
5716 | 6058 | $expectedLength = (int)$matches[1]; |
5717 | 6059 | $str = $matches[2]; |
5718 | 6060 | } |
5719 | 6061 | |
5720 | 6062 | // Object or unknown/malformed type. |
5721 | - else |
|
5722 | - return false; |
|
6063 | + else { |
|
6064 | + return false; |
|
6065 | + } |
|
5723 | 6066 | |
5724 | 6067 | switch($state) |
5725 | 6068 | { |
@@ -5747,8 +6090,9 @@ discard block |
||
5747 | 6090 | if($type == '}') |
5748 | 6091 | { |
5749 | 6092 | // Array size is less than expected. |
5750 | - if(count($list) < end($expected)) |
|
5751 | - return false; |
|
6093 | + if(count($list) < end($expected)) { |
|
6094 | + return false; |
|
6095 | + } |
|
5752 | 6096 | |
5753 | 6097 | unset($list); |
5754 | 6098 | $list = &$stack[count($stack)-1]; |
@@ -5757,8 +6101,9 @@ discard block |
||
5757 | 6101 | // Go to terminal state if we're at the end of the root array. |
5758 | 6102 | array_pop($expected); |
5759 | 6103 | |
5760 | - if(count($expected) == 0) |
|
5761 | - $state = 1; |
|
6104 | + if(count($expected) == 0) { |
|
6105 | + $state = 1; |
|
6106 | + } |
|
5762 | 6107 | |
5763 | 6108 | break; |
5764 | 6109 | } |
@@ -5766,8 +6111,9 @@ discard block |
||
5766 | 6111 | if($type == 'i' || $type == 's') |
5767 | 6112 | { |
5768 | 6113 | // Array size exceeds expected length. |
5769 | - if(count($list) >= end($expected)) |
|
5770 | - return false; |
|
6114 | + if(count($list) >= end($expected)) { |
|
6115 | + return false; |
|
6116 | + } |
|
5771 | 6117 | |
5772 | 6118 | $key = $value; |
5773 | 6119 | $state = 3; |
@@ -5801,8 +6147,9 @@ discard block |
||
5801 | 6147 | } |
5802 | 6148 | |
5803 | 6149 | // Trailing data in input. |
5804 | - if(!empty($str)) |
|
5805 | - return false; |
|
6150 | + if(!empty($str)) { |
|
6151 | + return false; |
|
6152 | + } |
|
5806 | 6153 | |
5807 | 6154 | return $data; |
5808 | 6155 | } |
@@ -5825,8 +6172,9 @@ discard block |
||
5825 | 6172 | |
5826 | 6173 | $out = _safe_unserialize($str); |
5827 | 6174 | |
5828 | - if (isset($mbIntEnc)) |
|
5829 | - mb_internal_encoding($mbIntEnc); |
|
6175 | + if (isset($mbIntEnc)) { |
|
6176 | + mb_internal_encoding($mbIntEnc); |
|
6177 | + } |
|
5830 | 6178 | |
5831 | 6179 | return $out; |
5832 | 6180 | } |
@@ -5841,12 +6189,14 @@ discard block |
||
5841 | 6189 | function smf_chmod($file, $value = 0) |
5842 | 6190 | { |
5843 | 6191 | // No file? no checks! |
5844 | - if (empty($file)) |
|
5845 | - return false; |
|
6192 | + if (empty($file)) { |
|
6193 | + return false; |
|
6194 | + } |
|
5846 | 6195 | |
5847 | 6196 | // Already writable? |
5848 | - if (is_writable($file)) |
|
5849 | - return true; |
|
6197 | + if (is_writable($file)) { |
|
6198 | + return true; |
|
6199 | + } |
|
5850 | 6200 | |
5851 | 6201 | // Do we have a file or a dir? |
5852 | 6202 | $isDir = is_dir($file); |
@@ -5862,10 +6212,9 @@ discard block |
||
5862 | 6212 | { |
5863 | 6213 | $isWritable = true; |
5864 | 6214 | break; |
6215 | + } else { |
|
6216 | + @chmod($file, $val); |
|
5865 | 6217 | } |
5866 | - |
|
5867 | - else |
|
5868 | - @chmod($file, $val); |
|
5869 | 6218 | } |
5870 | 6219 | |
5871 | 6220 | return $isWritable; |
@@ -5884,8 +6233,9 @@ discard block |
||
5884 | 6233 | global $txt; |
5885 | 6234 | |
5886 | 6235 | // Come on... |
5887 | - if (empty($json) || !is_string($json)) |
|
5888 | - return array(); |
|
6236 | + if (empty($json) || !is_string($json)) { |
|
6237 | + return array(); |
|
6238 | + } |
|
5889 | 6239 | |
5890 | 6240 | $returnArray = @json_decode($json, $returnAsArray); |
5891 | 6241 | |
@@ -5923,11 +6273,11 @@ discard block |
||
5923 | 6273 | $jsonDebug = $jsonDebug[0]; |
5924 | 6274 | loadLanguage('Errors'); |
5925 | 6275 | |
5926 | - if (!empty($jsonDebug)) |
|
5927 | - log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']); |
|
5928 | - |
|
5929 | - else |
|
5930 | - log_error($txt['json_'. $jsonError], 'critical'); |
|
6276 | + if (!empty($jsonDebug)) { |
|
6277 | + log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']); |
|
6278 | + } else { |
|
6279 | + log_error($txt['json_'. $jsonError], 'critical'); |
|
6280 | + } |
|
5931 | 6281 | |
5932 | 6282 | // Everyone expects an array. |
5933 | 6283 | return array(); |
@@ -5961,8 +6311,9 @@ discard block |
||
5961 | 6311 | global $db_show_debug, $modSettings; |
5962 | 6312 | |
5963 | 6313 | // Defensive programming anyone? |
5964 | - if (empty($data)) |
|
5965 | - return false; |
|
6314 | + if (empty($data)) { |
|
6315 | + return false; |
|
6316 | + } |
|
5966 | 6317 | |
5967 | 6318 | // Don't need extra stuff... |
5968 | 6319 | $db_show_debug = false; |
@@ -5970,11 +6321,11 @@ discard block |
||
5970 | 6321 | // Kill anything else. |
5971 | 6322 | ob_end_clean(); |
5972 | 6323 | |
5973 | - if (!empty($modSettings['CompressedOutput'])) |
|
5974 | - @ob_start('ob_gzhandler'); |
|
5975 | - |
|
5976 | - else |
|
5977 | - ob_start(); |
|
6324 | + if (!empty($modSettings['CompressedOutput'])) { |
|
6325 | + @ob_start('ob_gzhandler'); |
|
6326 | + } else { |
|
6327 | + ob_start(); |
|
6328 | + } |
|
5978 | 6329 | |
5979 | 6330 | // Set the header. |
5980 | 6331 | header($type); |
@@ -6006,8 +6357,9 @@ discard block |
||
6006 | 6357 | static $done = false; |
6007 | 6358 | |
6008 | 6359 | // If we don't need to do anything, don't |
6009 | - if (!$update && $done) |
|
6010 | - return; |
|
6360 | + if (!$update && $done) { |
|
6361 | + return; |
|
6362 | + } |
|
6011 | 6363 | |
6012 | 6364 | // Should we get a new copy of the official list of TLDs? |
6013 | 6365 | if ($update) |
@@ -6019,8 +6371,9 @@ discard block |
||
6019 | 6371 | // marauding bandits roaming on the surface. We don't want to waste precious electricity on |
6020 | 6372 | // pointlessly repeating background tasks, so we'll wait until the next regularly scheduled |
6021 | 6373 | // update to see if civilization has been restored. |
6022 | - if ($tlds === false) |
|
6023 | - $postapocalypticNightmare = true; |
|
6374 | + if ($tlds === false) { |
|
6375 | + $postapocalypticNightmare = true; |
|
6376 | + } |
|
6024 | 6377 | } |
6025 | 6378 | // If we aren't updating and the regex is valid, we're done |
6026 | 6379 | elseif (!empty($modSettings['tld_regex']) && @preg_match('~' . $modSettings['tld_regex'] . '~', null) !== false) |
@@ -6035,10 +6388,11 @@ discard block |
||
6035 | 6388 | // Clean $tlds and convert it to an array |
6036 | 6389 | $tlds = array_filter(explode("\n", strtolower($tlds)), function($line) { |
6037 | 6390 | $line = trim($line); |
6038 | - if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) |
|
6039 | - return false; |
|
6040 | - else |
|
6041 | - return true; |
|
6391 | + if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) { |
|
6392 | + return false; |
|
6393 | + } else { |
|
6394 | + return true; |
|
6395 | + } |
|
6042 | 6396 | }); |
6043 | 6397 | |
6044 | 6398 | // Convert Punycode to Unicode |
@@ -6130,8 +6484,7 @@ discard block |
||
6130 | 6484 | |
6131 | 6485 | $strlen = 'mb_strlen'; |
6132 | 6486 | $substr = 'mb_substr'; |
6133 | - } |
|
6134 | - else |
|
6487 | + } else |
|
6135 | 6488 | { |
6136 | 6489 | $strlen = $smcFunc['strlen']; |
6137 | 6490 | $substr = $smcFunc['substr']; |
@@ -6145,20 +6498,21 @@ discard block |
||
6145 | 6498 | |
6146 | 6499 | $first = $substr($string, 0, 1); |
6147 | 6500 | |
6148 | - if (empty($index[$first])) |
|
6149 | - $index[$first] = array(); |
|
6501 | + if (empty($index[$first])) { |
|
6502 | + $index[$first] = array(); |
|
6503 | + } |
|
6150 | 6504 | |
6151 | 6505 | if ($strlen($string) > 1) |
6152 | 6506 | { |
6153 | 6507 | // Sanity check on recursion |
6154 | - if ($depth > 99) |
|
6155 | - $index[$first][$substr($string, 1)] = ''; |
|
6156 | - |
|
6157 | - else |
|
6158 | - $index[$first] = $add_string_to_index($substr($string, 1), $index[$first]); |
|
6508 | + if ($depth > 99) { |
|
6509 | + $index[$first][$substr($string, 1)] = ''; |
|
6510 | + } else { |
|
6511 | + $index[$first] = $add_string_to_index($substr($string, 1), $index[$first]); |
|
6512 | + } |
|
6513 | + } else { |
|
6514 | + $index[$first][''] = ''; |
|
6159 | 6515 | } |
6160 | - else |
|
6161 | - $index[$first][''] = ''; |
|
6162 | 6516 | |
6163 | 6517 | $depth--; |
6164 | 6518 | return $index; |
@@ -6181,9 +6535,9 @@ discard block |
||
6181 | 6535 | $key_regex = preg_quote($key, $delim); |
6182 | 6536 | $new_key = $key; |
6183 | 6537 | |
6184 | - if (empty($value)) |
|
6185 | - $sub_regex = ''; |
|
6186 | - else |
|
6538 | + if (empty($value)) { |
|
6539 | + $sub_regex = ''; |
|
6540 | + } else |
|
6187 | 6541 | { |
6188 | 6542 | $sub_regex = $index_to_regex($value, $delim); |
6189 | 6543 | |
@@ -6191,22 +6545,22 @@ discard block |
||
6191 | 6545 | { |
6192 | 6546 | $new_key_array = explode('(?'.'>', $sub_regex); |
6193 | 6547 | $new_key .= $new_key_array[0]; |
6548 | + } else { |
|
6549 | + $sub_regex = '(?'.'>' . $sub_regex . ')'; |
|
6194 | 6550 | } |
6195 | - else |
|
6196 | - $sub_regex = '(?'.'>' . $sub_regex . ')'; |
|
6197 | 6551 | } |
6198 | 6552 | |
6199 | - if ($depth > 1) |
|
6200 | - $regex[$new_key] = $key_regex . $sub_regex; |
|
6201 | - else |
|
6553 | + if ($depth > 1) { |
|
6554 | + $regex[$new_key] = $key_regex . $sub_regex; |
|
6555 | + } else |
|
6202 | 6556 | { |
6203 | 6557 | if (($length += strlen($key_regex) + 1) < $max_length || empty($regex)) |
6204 | 6558 | { |
6205 | 6559 | $regex[$new_key] = $key_regex . $sub_regex; |
6206 | 6560 | unset($index[$key]); |
6561 | + } else { |
|
6562 | + break; |
|
6207 | 6563 | } |
6208 | - else |
|
6209 | - break; |
|
6210 | 6564 | } |
6211 | 6565 | } |
6212 | 6566 | |
@@ -6215,10 +6569,11 @@ discard block |
||
6215 | 6569 | $l1 = $strlen($k1); |
6216 | 6570 | $l2 = $strlen($k2); |
6217 | 6571 | |
6218 | - if ($l1 == $l2) |
|
6219 | - return strcmp($k1, $k2) > 0 ? 1 : -1; |
|
6220 | - else |
|
6221 | - return $l1 > $l2 ? -1 : 1; |
|
6572 | + if ($l1 == $l2) { |
|
6573 | + return strcmp($k1, $k2) > 0 ? 1 : -1; |
|
6574 | + } else { |
|
6575 | + return $l1 > $l2 ? -1 : 1; |
|
6576 | + } |
|
6222 | 6577 | }); |
6223 | 6578 | |
6224 | 6579 | $depth--; |
@@ -6229,21 +6584,24 @@ discard block |
||
6229 | 6584 | $index = array(); |
6230 | 6585 | $regex = ''; |
6231 | 6586 | |
6232 | - foreach ($strings as $string) |
|
6233 | - $index = $add_string_to_index($string, $index); |
|
6587 | + foreach ($strings as $string) { |
|
6588 | + $index = $add_string_to_index($string, $index); |
|
6589 | + } |
|
6234 | 6590 | |
6235 | 6591 | if ($returnArray === true) |
6236 | 6592 | { |
6237 | 6593 | $regex = array(); |
6238 | - while (!empty($index)) |
|
6239 | - $regex[] = '(?'.'>' . $index_to_regex($index, $delim) . ')'; |
|
6594 | + while (!empty($index)) { |
|
6595 | + $regex[] = '(?'.'>' . $index_to_regex($index, $delim) . ')'; |
|
6596 | + } |
|
6597 | + } else { |
|
6598 | + $regex = '(?'.'>' . $index_to_regex($index, $delim) . ')'; |
|
6240 | 6599 | } |
6241 | - else |
|
6242 | - $regex = '(?'.'>' . $index_to_regex($index, $delim) . ')'; |
|
6243 | 6600 | |
6244 | 6601 | // Restore PHP's internal character encoding to whatever it was originally |
6245 | - if (!empty($current_encoding)) |
|
6246 | - mb_internal_encoding($current_encoding); |
|
6602 | + if (!empty($current_encoding)) { |
|
6603 | + mb_internal_encoding($current_encoding); |
|
6604 | + } |
|
6247 | 6605 | |
6248 | 6606 | return $regex; |
6249 | 6607 | } |
@@ -6286,13 +6644,15 @@ discard block |
||
6286 | 6644 | // Need to add the trailing slash, or it puts it there & thinks there's a redirect when there isn't... |
6287 | 6645 | $url = str_ireplace('https://', 'http://', $url) . '/'; |
6288 | 6646 | $headers = @get_headers($url); |
6289 | - if ($headers === false) |
|
6290 | - return false; |
|
6647 | + if ($headers === false) { |
|
6648 | + return false; |
|
6649 | + } |
|
6291 | 6650 | |
6292 | 6651 | // Now to see if it came back https... |
6293 | 6652 | // First check for a redirect status code in first row (301, 302, 307) |
6294 | - if (strstr($headers[0], '301') === false && strstr($headers[0], '302') === false && strstr($headers[0], '307') === false) |
|
6295 | - return false; |
|
6653 | + if (strstr($headers[0], '301') === false && strstr($headers[0], '302') === false && strstr($headers[0], '307') === false) { |
|
6654 | + return false; |
|
6655 | + } |
|
6296 | 6656 | |
6297 | 6657 | // Search for the location entry to confirm https |
6298 | 6658 | $result = false; |
@@ -6328,8 +6688,7 @@ discard block |
||
6328 | 6688 | $is_admin = $user_info['is_admin']; |
6329 | 6689 | $mod_cache = !empty($user_info['mod_cache']) ? $user_info['mod_cache'] : null; |
6330 | 6690 | $ignoreboards = !empty($user_info['ignoreboards']) ? $user_info['ignoreboards'] : null; |
6331 | - } |
|
6332 | - else |
|
6691 | + } else |
|
6333 | 6692 | { |
6334 | 6693 | $request = $smcFunc['db_query']('', ' |
6335 | 6694 | SELECT mem.ignore_boards, mem.id_group, mem.additional_groups, mem.id_post_group |
@@ -6343,17 +6702,19 @@ discard block |
||
6343 | 6702 | |
6344 | 6703 | $row = $smcFunc['db_fetch_assoc']($request); |
6345 | 6704 | |
6346 | - if (empty($row['additional_groups'])) |
|
6347 | - $groups = array($row['id_group'], $row['id_post_group']); |
|
6348 | - else |
|
6349 | - $groups = array_merge( |
|
6705 | + if (empty($row['additional_groups'])) { |
|
6706 | + $groups = array($row['id_group'], $row['id_post_group']); |
|
6707 | + } else { |
|
6708 | + $groups = array_merge( |
|
6350 | 6709 | array($row['id_group'], $row['id_post_group']), |
6351 | 6710 | explode(',', $row['additional_groups']) |
6352 | 6711 | ); |
6712 | + } |
|
6353 | 6713 | |
6354 | 6714 | // Because history has proven that it is possible for groups to go bad - clean up in case. |
6355 | - foreach ($groups as $k => $v) |
|
6356 | - $groups[$k] = (int) $v; |
|
6715 | + foreach ($groups as $k => $v) { |
|
6716 | + $groups[$k] = (int) $v; |
|
6717 | + } |
|
6357 | 6718 | |
6358 | 6719 | $is_admin = in_array(1, $groups); |
6359 | 6720 | |
@@ -6370,8 +6731,9 @@ discard block |
||
6370 | 6731 | 'current_member' => $userid, |
6371 | 6732 | ) |
6372 | 6733 | ); |
6373 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
6374 | - $boards_mod[] = $row['id_board']; |
|
6734 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
6735 | + $boards_mod[] = $row['id_board']; |
|
6736 | + } |
|
6375 | 6737 | $smcFunc['db_free_result']($request); |
6376 | 6738 | |
6377 | 6739 | // Can any of the groups they're in moderate any of the boards? |
@@ -6383,8 +6745,9 @@ discard block |
||
6383 | 6745 | 'groups' => $groups, |
6384 | 6746 | ) |
6385 | 6747 | ); |
6386 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
6387 | - $boards_mod[] = $row['id_board']; |
|
6748 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
6749 | + $boards_mod[] = $row['id_board']; |
|
6750 | + } |
|
6388 | 6751 | $smcFunc['db_free_result']($request); |
6389 | 6752 | |
6390 | 6753 | // Just in case we've got duplicates here... |
@@ -6394,21 +6757,25 @@ discard block |
||
6394 | 6757 | } |
6395 | 6758 | |
6396 | 6759 | // Just build this here, it makes it easier to change/use - administrators can see all boards. |
6397 | - if ($is_admin) |
|
6398 | - $query_part['query_see_board'] = '1=1'; |
|
6760 | + if ($is_admin) { |
|
6761 | + $query_part['query_see_board'] = '1=1'; |
|
6762 | + } |
|
6399 | 6763 | // Otherwise just the groups in $user_info['groups']. |
6400 | - else |
|
6401 | - $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'] : '') . ')'; |
|
6764 | + else { |
|
6765 | + $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'] : '') . ')'; |
|
6766 | + } |
|
6402 | 6767 | |
6403 | 6768 | // Build the list of boards they WANT to see. |
6404 | 6769 | // This will take the place of query_see_boards in certain spots, so it better include the boards they can see also |
6405 | 6770 | |
6406 | 6771 | // If they aren't ignoring any boards then they want to see all the boards they can see |
6407 | - if (empty($ignoreboards)) |
|
6408 | - $query_part['query_wanna_see_board'] = $query_part['query_see_board']; |
|
6772 | + if (empty($ignoreboards)) { |
|
6773 | + $query_part['query_wanna_see_board'] = $query_part['query_see_board']; |
|
6774 | + } |
|
6409 | 6775 | // Ok I guess they don't want to see all the boards |
6410 | - else |
|
6411 | - $query_part['query_wanna_see_board'] = '(' . $query_part['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $ignoreboards) . '))'; |
|
6776 | + else { |
|
6777 | + $query_part['query_wanna_see_board'] = '(' . $query_part['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $ignoreboards) . '))'; |
|
6778 | + } |
|
6412 | 6779 | |
6413 | 6780 | return $query_part; |
6414 | 6781 | } |
@@ -6422,10 +6789,11 @@ discard block |
||
6422 | 6789 | { |
6423 | 6790 | $secure = false; |
6424 | 6791 | |
6425 | - if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') |
|
6426 | - $secure = true; |
|
6427 | - 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') |
|
6428 | - $secure = true; |
|
6792 | + if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { |
|
6793 | + $secure = true; |
|
6794 | + } 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') { |
|
6795 | + $secure = true; |
|
6796 | + } |
|
6429 | 6797 | |
6430 | 6798 | return $secure; |
6431 | 6799 | } |
@@ -6442,11 +6810,12 @@ discard block |
||
6442 | 6810 | { |
6443 | 6811 | $url = iri_to_url($iri); |
6444 | 6812 | |
6445 | - if (filter_var($url, FILTER_VALIDATE_URL, $flags) !== false) |
|
6446 | - return $iri; |
|
6447 | - else |
|
6448 | - return false; |
|
6449 | -} |
|
6813 | + if (filter_var($url, FILTER_VALIDATE_URL, $flags) !== false) { |
|
6814 | + return $iri; |
|
6815 | + } else { |
|
6816 | + return false; |
|
6817 | + } |
|
6818 | + } |
|
6450 | 6819 | |
6451 | 6820 | /** |
6452 | 6821 | * A wrapper for `filter_var($url, FILTER_SANITIZE_URL)` that can handle URLs |
@@ -6489,8 +6858,9 @@ discard block |
||
6489 | 6858 | |
6490 | 6859 | $host = parse_url((strpos($iri, '://') === false ? 'http://' : '') . ltrim($iri, ':/'), PHP_URL_HOST); |
6491 | 6860 | |
6492 | - if (empty($host)) |
|
6493 | - return $iri; |
|
6861 | + if (empty($host)) { |
|
6862 | + return $iri; |
|
6863 | + } |
|
6494 | 6864 | |
6495 | 6865 | // Convert the domain using the Punycode algorithm |
6496 | 6866 | require_once($sourcedir . '/punycode/Punycode.php'); |
@@ -6526,8 +6896,9 @@ discard block |
||
6526 | 6896 | |
6527 | 6897 | $host = parse_url((strpos($url, '://') === false ? 'http://' : '') . ltrim($url, ':/'), PHP_URL_HOST); |
6528 | 6898 | |
6529 | - if (empty($host)) |
|
6530 | - return $url; |
|
6899 | + if (empty($host)) { |
|
6900 | + return $url; |
|
6901 | + } |
|
6531 | 6902 | |
6532 | 6903 | // Decode the domain from Punycode |
6533 | 6904 | require_once($sourcedir . '/punycode/Punycode.php'); |
@@ -14,8 +14,9 @@ discard block |
||
14 | 14 | * @version 2.1 Beta 4 |
15 | 15 | */ |
16 | 16 | |
17 | -if (!defined('SMF')) |
|
17 | +if (!defined('SMF')) { |
|
18 | 18 | die('No direct access...'); |
19 | +} |
|
19 | 20 | |
20 | 21 | /** |
21 | 22 | * Clean the request variables - add html entities to GET and slashes if magic_quotes_gpc is Off. |
@@ -44,22 +45,26 @@ discard block |
||
44 | 45 | unset($GLOBALS['HTTP_POST_FILES'], $GLOBALS['HTTP_POST_FILES']); |
45 | 46 | |
46 | 47 | // These keys shouldn't be set...ever. |
47 | - if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS'])) |
|
48 | - die('Invalid request variable.'); |
|
48 | + if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS'])) { |
|
49 | + die('Invalid request variable.'); |
|
50 | + } |
|
49 | 51 | |
50 | 52 | // Same goes for numeric keys. |
51 | - foreach (array_merge(array_keys($_POST), array_keys($_GET), array_keys($_FILES)) as $key) |
|
52 | - if (is_numeric($key)) |
|
53 | + foreach (array_merge(array_keys($_POST), array_keys($_GET), array_keys($_FILES)) as $key) { |
|
54 | + if (is_numeric($key)) |
|
53 | 55 | die('Numeric request keys are invalid.'); |
56 | + } |
|
54 | 57 | |
55 | 58 | // Numeric keys in cookies are less of a problem. Just unset those. |
56 | - foreach ($_COOKIE as $key => $value) |
|
57 | - if (is_numeric($key)) |
|
59 | + foreach ($_COOKIE as $key => $value) { |
|
60 | + if (is_numeric($key)) |
|
58 | 61 | unset($_COOKIE[$key]); |
62 | + } |
|
59 | 63 | |
60 | 64 | // Get the correct query string. It may be in an environment variable... |
61 | - if (!isset($_SERVER['QUERY_STRING'])) |
|
62 | - $_SERVER['QUERY_STRING'] = getenv('QUERY_STRING'); |
|
65 | + if (!isset($_SERVER['QUERY_STRING'])) { |
|
66 | + $_SERVER['QUERY_STRING'] = getenv('QUERY_STRING'); |
|
67 | + } |
|
63 | 68 | |
64 | 69 | // It seems that sticking a URL after the query string is mighty common, well, it's evil - don't. |
65 | 70 | if (strpos($_SERVER['QUERY_STRING'], 'http') === 0) |
@@ -83,13 +88,14 @@ discard block |
||
83 | 88 | parse_str(preg_replace('/&(\w+)(?=&|$)/', '&$1=', strtr($_SERVER['QUERY_STRING'], array(';?' => '&', ';' => '&', '%00' => '', "\0" => ''))), $_GET); |
84 | 89 | |
85 | 90 | // Magic quotes still applies with parse_str - so clean it up. |
86 | - if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes'])) |
|
87 | - $_GET = $removeMagicQuoteFunction($_GET); |
|
88 | - } |
|
89 | - elseif (strpos(ini_get('arg_separator.input'), ';') !== false) |
|
91 | + if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes'])) { |
|
92 | + $_GET = $removeMagicQuoteFunction($_GET); |
|
93 | + } |
|
94 | + } elseif (strpos(ini_get('arg_separator.input'), ';') !== false) |
|
90 | 95 | { |
91 | - if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes'])) |
|
92 | - $_GET = $removeMagicQuoteFunction($_GET); |
|
96 | + if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes'])) { |
|
97 | + $_GET = $removeMagicQuoteFunction($_GET); |
|
98 | + } |
|
93 | 99 | |
94 | 100 | // Search engines will send action=profile%3Bu=1, which confuses PHP. |
95 | 101 | foreach ($_GET as $k => $v) |
@@ -102,8 +108,9 @@ discard block |
||
102 | 108 | for ($i = 1, $n = count($temp); $i < $n; $i++) |
103 | 109 | { |
104 | 110 | @list ($key, $val) = @explode('=', $temp[$i], 2); |
105 | - if (!isset($_GET[$key])) |
|
106 | - $_GET[$key] = $val; |
|
111 | + if (!isset($_GET[$key])) { |
|
112 | + $_GET[$key] = $val; |
|
113 | + } |
|
107 | 114 | } |
108 | 115 | } |
109 | 116 | |
@@ -120,18 +127,20 @@ discard block |
||
120 | 127 | if (!empty($_SERVER['REQUEST_URI'])) |
121 | 128 | { |
122 | 129 | // Remove the .html, assuming there is one. |
123 | - if (substr($_SERVER['REQUEST_URI'], strrpos($_SERVER['REQUEST_URI'], '.'), 4) == '.htm') |
|
124 | - $request = substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], '.')); |
|
125 | - else |
|
126 | - $request = $_SERVER['REQUEST_URI']; |
|
130 | + if (substr($_SERVER['REQUEST_URI'], strrpos($_SERVER['REQUEST_URI'], '.'), 4) == '.htm') { |
|
131 | + $request = substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], '.')); |
|
132 | + } else { |
|
133 | + $request = $_SERVER['REQUEST_URI']; |
|
134 | + } |
|
127 | 135 | |
128 | 136 | // @todo smflib. |
129 | 137 | // Replace 'index.php/a,b,c/d/e,f' with 'a=b,c&d=&e=f' and parse it into $_GET. |
130 | 138 | if (strpos($request, basename($scripturl) . '/') !== false) |
131 | 139 | { |
132 | 140 | parse_str(substr(preg_replace('/&(\w+)(?=&|$)/', '&$1=', strtr(preg_replace('~/([^,/]+),~', '/$1=', substr($request, strpos($request, basename($scripturl)) + strlen(basename($scripturl)))), '/', '&')), 1), $temp); |
133 | - if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes'])) |
|
134 | - $temp = $removeMagicQuoteFunction($temp); |
|
141 | + if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes'])) { |
|
142 | + $temp = $removeMagicQuoteFunction($temp); |
|
143 | + } |
|
135 | 144 | $_GET += $temp; |
136 | 145 | } |
137 | 146 | } |
@@ -142,9 +151,10 @@ discard block |
||
142 | 151 | $_ENV = $removeMagicQuoteFunction($_ENV); |
143 | 152 | $_POST = $removeMagicQuoteFunction($_POST); |
144 | 153 | $_COOKIE = $removeMagicQuoteFunction($_COOKIE); |
145 | - foreach ($_FILES as $k => $dummy) |
|
146 | - if (isset($_FILES[$k]['name'])) |
|
154 | + foreach ($_FILES as $k => $dummy) { |
|
155 | + if (isset($_FILES[$k]['name'])) |
|
147 | 156 | $_FILES[$k]['name'] = $removeMagicQuoteFunction($_FILES[$k]['name']); |
157 | + } |
|
148 | 158 | } |
149 | 159 | |
150 | 160 | // Add entities to GET. This is kinda like the slashes on everything else. |
@@ -160,11 +170,13 @@ discard block |
||
160 | 170 | $_REQUEST['board'] = (string) $_REQUEST['board']; |
161 | 171 | |
162 | 172 | // If there's a slash in it, we've got a start value! (old, compatible links.) |
163 | - if (strpos($_REQUEST['board'], '/') !== false) |
|
164 | - list ($_REQUEST['board'], $_REQUEST['start']) = explode('/', $_REQUEST['board']); |
|
173 | + if (strpos($_REQUEST['board'], '/') !== false) { |
|
174 | + list ($_REQUEST['board'], $_REQUEST['start']) = explode('/', $_REQUEST['board']); |
|
175 | + } |
|
165 | 176 | // Same idea, but dots. This is the currently used format - ?board=1.0... |
166 | - elseif (strpos($_REQUEST['board'], '.') !== false) |
|
167 | - list ($_REQUEST['board'], $_REQUEST['start']) = explode('.', $_REQUEST['board']); |
|
177 | + elseif (strpos($_REQUEST['board'], '.') !== false) { |
|
178 | + list ($_REQUEST['board'], $_REQUEST['start']) = explode('.', $_REQUEST['board']); |
|
179 | + } |
|
168 | 180 | // Now make absolutely sure it's a number. |
169 | 181 | $board = (int) $_REQUEST['board']; |
170 | 182 | $_REQUEST['start'] = isset($_REQUEST['start']) ? (int) $_REQUEST['start'] : 0; |
@@ -173,12 +185,14 @@ discard block |
||
173 | 185 | $_GET['board'] = $board; |
174 | 186 | } |
175 | 187 | // Well, $board is going to be a number no matter what. |
176 | - else |
|
177 | - $board = 0; |
|
188 | + else { |
|
189 | + $board = 0; |
|
190 | + } |
|
178 | 191 | |
179 | 192 | // If there's a threadid, it's probably an old YaBB SE link. Flow with it. |
180 | - if (isset($_REQUEST['threadid']) && !isset($_REQUEST['topic'])) |
|
181 | - $_REQUEST['topic'] = $_REQUEST['threadid']; |
|
193 | + if (isset($_REQUEST['threadid']) && !isset($_REQUEST['topic'])) { |
|
194 | + $_REQUEST['topic'] = $_REQUEST['threadid']; |
|
195 | + } |
|
182 | 196 | |
183 | 197 | // We've got topic! |
184 | 198 | if (isset($_REQUEST['topic'])) |
@@ -187,11 +201,13 @@ discard block |
||
187 | 201 | $_REQUEST['topic'] = (string) $_REQUEST['topic']; |
188 | 202 | |
189 | 203 | // Slash means old, beta style, formatting. That's okay though, the link should still work. |
190 | - if (strpos($_REQUEST['topic'], '/') !== false) |
|
191 | - list ($_REQUEST['topic'], $_REQUEST['start']) = explode('/', $_REQUEST['topic']); |
|
204 | + if (strpos($_REQUEST['topic'], '/') !== false) { |
|
205 | + list ($_REQUEST['topic'], $_REQUEST['start']) = explode('/', $_REQUEST['topic']); |
|
206 | + } |
|
192 | 207 | // Dots are useful and fun ;). This is ?topic=1.15. |
193 | - elseif (strpos($_REQUEST['topic'], '.') !== false) |
|
194 | - list ($_REQUEST['topic'], $_REQUEST['start']) = explode('.', $_REQUEST['topic']); |
|
208 | + elseif (strpos($_REQUEST['topic'], '.') !== false) { |
|
209 | + list ($_REQUEST['topic'], $_REQUEST['start']) = explode('.', $_REQUEST['topic']); |
|
210 | + } |
|
195 | 211 | |
196 | 212 | // Topic should always be an integer |
197 | 213 | $topic = $_GET['topic'] = $_REQUEST['topic'] = (int) $_REQUEST['topic']; |
@@ -225,21 +241,25 @@ discard block |
||
225 | 241 | $_REQUEST['start'] = $timestamp === 0 ? 0 : 'from' . $timestamp; |
226 | 242 | } |
227 | 243 | // ... or something invalid, in which case we reset it to 0. |
228 | - else |
|
229 | - $_REQUEST['start'] = 0; |
|
244 | + else { |
|
245 | + $_REQUEST['start'] = 0; |
|
246 | + } |
|
247 | + } else { |
|
248 | + $topic = 0; |
|
230 | 249 | } |
231 | - else |
|
232 | - $topic = 0; |
|
233 | 250 | |
234 | 251 | // There should be a $_REQUEST['start'], some at least. If you need to default to other than 0, use $_GET['start']. |
235 | - if (empty($_REQUEST['start']) || $_REQUEST['start'] < 0 || (int) $_REQUEST['start'] > 2147473647) |
|
236 | - $_REQUEST['start'] = 0; |
|
252 | + if (empty($_REQUEST['start']) || $_REQUEST['start'] < 0 || (int) $_REQUEST['start'] > 2147473647) { |
|
253 | + $_REQUEST['start'] = 0; |
|
254 | + } |
|
237 | 255 | |
238 | 256 | // The action needs to be a string and not an array or anything else |
239 | - if (isset($_REQUEST['action'])) |
|
240 | - $_REQUEST['action'] = (string) $_REQUEST['action']; |
|
241 | - if (isset($_GET['action'])) |
|
242 | - $_GET['action'] = (string) $_GET['action']; |
|
257 | + if (isset($_REQUEST['action'])) { |
|
258 | + $_REQUEST['action'] = (string) $_REQUEST['action']; |
|
259 | + } |
|
260 | + if (isset($_GET['action'])) { |
|
261 | + $_GET['action'] = (string) $_GET['action']; |
|
262 | + } |
|
243 | 263 | |
244 | 264 | // Some mail providers like to encode semicolons in activation URLs... |
245 | 265 | if (!empty($_REQUEST['action']) && substr($_SERVER['QUERY_STRING'], 0, 18) == 'action=activate%3b') |
@@ -265,29 +285,33 @@ discard block |
||
265 | 285 | $_SERVER['BAN_CHECK_IP'] = $_SERVER['REMOTE_ADDR']; |
266 | 286 | |
267 | 287 | // If we haven't specified how to handle Reverse Proxy IP headers, lets do what we always used to do. |
268 | - if (!isset($modSettings['proxy_ip_header'])) |
|
269 | - $modSettings['proxy_ip_header'] = 'autodetect'; |
|
288 | + if (!isset($modSettings['proxy_ip_header'])) { |
|
289 | + $modSettings['proxy_ip_header'] = 'autodetect'; |
|
290 | + } |
|
270 | 291 | |
271 | 292 | // Which headers are we going to check for Reverse Proxy IP headers? |
272 | - if ($modSettings['proxy_ip_header'] == 'disabled') |
|
273 | - $reverseIPheaders = array(); |
|
274 | - elseif ($modSettings['proxy_ip_header'] == 'autodetect') |
|
275 | - $reverseIPheaders = array('HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP'); |
|
276 | - else |
|
277 | - $reverseIPheaders = array($modSettings['proxy_ip_header']); |
|
293 | + if ($modSettings['proxy_ip_header'] == 'disabled') { |
|
294 | + $reverseIPheaders = array(); |
|
295 | + } elseif ($modSettings['proxy_ip_header'] == 'autodetect') { |
|
296 | + $reverseIPheaders = array('HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP'); |
|
297 | + } else { |
|
298 | + $reverseIPheaders = array($modSettings['proxy_ip_header']); |
|
299 | + } |
|
278 | 300 | |
279 | 301 | // Find the user's IP address. (but don't let it give you 'unknown'!) |
280 | 302 | foreach ($reverseIPheaders as $proxyIPheader) |
281 | 303 | { |
282 | 304 | // Ignore if this is not set. |
283 | - if (!isset($_SERVER[$proxyIPheader])) |
|
284 | - continue; |
|
305 | + if (!isset($_SERVER[$proxyIPheader])) { |
|
306 | + continue; |
|
307 | + } |
|
285 | 308 | |
286 | 309 | if (!empty($modSettings['proxy_ip_servers'])) |
287 | 310 | { |
288 | - foreach (explode(',', $modSettings['proxy_ip_servers']) as $proxy) |
|
289 | - if ($proxy == $_SERVER['REMOTE_ADDR'] || matchIPtoCIDR($_SERVER['REMOTE_ADDR'], $proxy)) |
|
311 | + foreach (explode(',', $modSettings['proxy_ip_servers']) as $proxy) { |
|
312 | + if ($proxy == $_SERVER['REMOTE_ADDR'] || matchIPtoCIDR($_SERVER['REMOTE_ADDR'], $proxy)) |
|
290 | 313 | continue; |
314 | + } |
|
291 | 315 | } |
292 | 316 | |
293 | 317 | // If there are commas, get the last one.. probably. |
@@ -307,8 +331,9 @@ discard block |
||
307 | 331 | |
308 | 332 | // Just incase we have a legacy IPv4 address. |
309 | 333 | // @ TODO: Convert to IPv6. |
310 | - if (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER[$proxyIPheader]) === 0) |
|
311 | - continue; |
|
334 | + if (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER[$proxyIPheader]) === 0) { |
|
335 | + continue; |
|
336 | + } |
|
312 | 337 | } |
313 | 338 | |
314 | 339 | continue; |
@@ -320,36 +345,40 @@ discard block |
||
320 | 345 | } |
321 | 346 | } |
322 | 347 | // Otherwise just use the only one. |
323 | - elseif (preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown|::1|fe80::|fc00::)~', $_SERVER[$proxyIPheader]) == 0 || preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown|::1|fe80::|fc00::)~', $_SERVER['REMOTE_ADDR']) != 0) |
|
324 | - $_SERVER['BAN_CHECK_IP'] = $_SERVER[$proxyIPheader]; |
|
325 | - elseif (!isValidIPv6($_SERVER[$proxyIPheader]) || preg_match('~::ffff:\d+\.\d+\.\d+\.\d+~', $_SERVER[$proxyIPheader]) !== 0) |
|
348 | + elseif (preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown|::1|fe80::|fc00::)~', $_SERVER[$proxyIPheader]) == 0 || preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown|::1|fe80::|fc00::)~', $_SERVER['REMOTE_ADDR']) != 0) { |
|
349 | + $_SERVER['BAN_CHECK_IP'] = $_SERVER[$proxyIPheader]; |
|
350 | + } elseif (!isValidIPv6($_SERVER[$proxyIPheader]) || preg_match('~::ffff:\d+\.\d+\.\d+\.\d+~', $_SERVER[$proxyIPheader]) !== 0) |
|
326 | 351 | { |
327 | 352 | $_SERVER[$proxyIPheader] = preg_replace('~^::ffff:(\d+\.\d+\.\d+\.\d+)~', '\1', $_SERVER[$proxyIPheader]); |
328 | 353 | |
329 | 354 | // Just incase we have a legacy IPv4 address. |
330 | 355 | // @ TODO: Convert to IPv6. |
331 | - if (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER[$proxyIPheader]) === 0) |
|
332 | - continue; |
|
356 | + if (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER[$proxyIPheader]) === 0) { |
|
357 | + continue; |
|
358 | + } |
|
333 | 359 | } |
334 | 360 | } |
335 | 361 | |
336 | 362 | // Make sure we know the URL of the current request. |
337 | - if (empty($_SERVER['REQUEST_URI'])) |
|
338 | - $_SERVER['REQUEST_URL'] = $scripturl . (!empty($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : ''); |
|
339 | - elseif (preg_match('~^([^/]+//[^/]+)~', $scripturl, $match) == 1) |
|
340 | - $_SERVER['REQUEST_URL'] = $match[1] . $_SERVER['REQUEST_URI']; |
|
341 | - else |
|
342 | - $_SERVER['REQUEST_URL'] = $_SERVER['REQUEST_URI']; |
|
363 | + if (empty($_SERVER['REQUEST_URI'])) { |
|
364 | + $_SERVER['REQUEST_URL'] = $scripturl . (!empty($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : ''); |
|
365 | + } elseif (preg_match('~^([^/]+//[^/]+)~', $scripturl, $match) == 1) { |
|
366 | + $_SERVER['REQUEST_URL'] = $match[1] . $_SERVER['REQUEST_URI']; |
|
367 | + } else { |
|
368 | + $_SERVER['REQUEST_URL'] = $_SERVER['REQUEST_URI']; |
|
369 | + } |
|
343 | 370 | |
344 | 371 | // And make sure HTTP_USER_AGENT is set. |
345 | 372 | $_SERVER['HTTP_USER_AGENT'] = isset($_SERVER['HTTP_USER_AGENT']) ? (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($smcFunc['db_unescape_string']($_SERVER['HTTP_USER_AGENT']), ENT_QUOTES) : htmlspecialchars($smcFunc['db_unescape_string']($_SERVER['HTTP_USER_AGENT']), ENT_QUOTES)) : ''; |
346 | 373 | |
347 | 374 | // Some final checking. |
348 | - if (!isValidIP($_SERVER['BAN_CHECK_IP'])) |
|
349 | - $_SERVER['BAN_CHECK_IP'] = ''; |
|
350 | - if ($_SERVER['REMOTE_ADDR'] == 'unknown') |
|
351 | - $_SERVER['REMOTE_ADDR'] = ''; |
|
352 | -} |
|
375 | + if (!isValidIP($_SERVER['BAN_CHECK_IP'])) { |
|
376 | + $_SERVER['BAN_CHECK_IP'] = ''; |
|
377 | + } |
|
378 | + if ($_SERVER['REMOTE_ADDR'] == 'unknown') { |
|
379 | + $_SERVER['REMOTE_ADDR'] = ''; |
|
380 | + } |
|
381 | + } |
|
353 | 382 | |
354 | 383 | /** |
355 | 384 | * Validates a IPv6 address. returns true if it is ipv6. |
@@ -360,8 +389,9 @@ discard block |
||
360 | 389 | function isValidIPv6($ip) |
361 | 390 | { |
362 | 391 | //looking for : |
363 | - if (strpos($ip, ':') === false) |
|
364 | - return false; |
|
392 | + if (strpos($ip, ':') === false) { |
|
393 | + return false; |
|
394 | + } |
|
365 | 395 | |
366 | 396 | //check valid address |
367 | 397 | return inet_pton($ip); |
@@ -378,15 +408,17 @@ discard block |
||
378 | 408 | static $expanded = array(); |
379 | 409 | |
380 | 410 | // Check if we have done this already. |
381 | - if (isset($expanded[$ip])) |
|
382 | - return $expanded[$ip]; |
|
411 | + if (isset($expanded[$ip])) { |
|
412 | + return $expanded[$ip]; |
|
413 | + } |
|
383 | 414 | |
384 | 415 | // Expand the IP out. |
385 | 416 | $expanded_ip = explode(':', expandIPv6($ip)); |
386 | 417 | |
387 | 418 | $new_ip = array(); |
388 | - foreach ($expanded_ip as $int) |
|
389 | - $new_ip[] = hexdec($int); |
|
419 | + foreach ($expanded_ip as $int) { |
|
420 | + $new_ip[] = hexdec($int); |
|
421 | + } |
|
390 | 422 | |
391 | 423 | // Save this incase of repeated use. |
392 | 424 | $expanded[$ip] = $new_ip; |
@@ -406,8 +438,9 @@ discard block |
||
406 | 438 | static $converted = array(); |
407 | 439 | |
408 | 440 | // Check if we have done this already. |
409 | - if (isset($converted[$addr])) |
|
410 | - return $converted[$addr]; |
|
441 | + if (isset($converted[$addr])) { |
|
442 | + return $converted[$addr]; |
|
443 | + } |
|
411 | 444 | |
412 | 445 | // Check if there are segments missing, insert if necessary. |
413 | 446 | if (strpos($addr, '::') !== false) |
@@ -417,18 +450,20 @@ discard block |
||
417 | 450 | $part[1] = explode(':', $part[1]); |
418 | 451 | $missing = array(); |
419 | 452 | |
420 | - for ($i = 0; $i < (8 - (count($part[0]) + count($part[1]))); $i++) |
|
421 | - array_push($missing, '0000'); |
|
453 | + for ($i = 0; $i < (8 - (count($part[0]) + count($part[1]))); $i++) { |
|
454 | + array_push($missing, '0000'); |
|
455 | + } |
|
422 | 456 | |
423 | 457 | $part = array_merge($part[0], $missing, $part[1]); |
458 | + } else { |
|
459 | + $part = explode(':', $addr); |
|
424 | 460 | } |
425 | - else |
|
426 | - $part = explode(':', $addr); |
|
427 | 461 | |
428 | 462 | // Pad each segment until it has 4 digits. |
429 | - foreach ($part as &$p) |
|
430 | - while (strlen($p) < 4) |
|
463 | + foreach ($part as &$p) { |
|
464 | + while (strlen($p) < 4) |
|
431 | 465 | $p = '0' . $p; |
466 | + } |
|
432 | 467 | |
433 | 468 | unset($p); |
434 | 469 | |
@@ -439,11 +474,12 @@ discard block |
||
439 | 474 | $converted[$addr] = $result; |
440 | 475 | |
441 | 476 | // Quick check to make sure the length is as expected. |
442 | - if (!$strict_check || strlen($result) == 39) |
|
443 | - return $result; |
|
444 | - else |
|
445 | - return false; |
|
446 | -} |
|
477 | + if (!$strict_check || strlen($result) == 39) { |
|
478 | + return $result; |
|
479 | + } else { |
|
480 | + return false; |
|
481 | + } |
|
482 | + } |
|
447 | 483 | |
448 | 484 | |
449 | 485 | /** |
@@ -474,15 +510,17 @@ discard block |
||
474 | 510 | { |
475 | 511 | global $smcFunc; |
476 | 512 | |
477 | - if (!is_array($var)) |
|
478 | - return $smcFunc['db_escape_string']($var); |
|
513 | + if (!is_array($var)) { |
|
514 | + return $smcFunc['db_escape_string']($var); |
|
515 | + } |
|
479 | 516 | |
480 | 517 | // Reindex the array with slashes. |
481 | 518 | $new_var = array(); |
482 | 519 | |
483 | 520 | // Add slashes to every element, even the indexes! |
484 | - foreach ($var as $k => $v) |
|
485 | - $new_var[$smcFunc['db_escape_string']($k)] = escapestring__recursive($v); |
|
521 | + foreach ($var as $k => $v) { |
|
522 | + $new_var[$smcFunc['db_escape_string']($k)] = escapestring__recursive($v); |
|
523 | + } |
|
486 | 524 | |
487 | 525 | return $new_var; |
488 | 526 | } |
@@ -502,12 +540,14 @@ discard block |
||
502 | 540 | { |
503 | 541 | global $smcFunc; |
504 | 542 | |
505 | - if (!is_array($var)) |
|
506 | - return isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($var, ENT_QUOTES) : htmlspecialchars($var, ENT_QUOTES); |
|
543 | + if (!is_array($var)) { |
|
544 | + return isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($var, ENT_QUOTES) : htmlspecialchars($var, ENT_QUOTES); |
|
545 | + } |
|
507 | 546 | |
508 | 547 | // Add the htmlspecialchars to every element. |
509 | - foreach ($var as $k => $v) |
|
510 | - $var[$k] = $level > 25 ? null : htmlspecialchars__recursive($v, $level + 1); |
|
548 | + foreach ($var as $k => $v) { |
|
549 | + $var[$k] = $level > 25 ? null : htmlspecialchars__recursive($v, $level + 1); |
|
550 | + } |
|
511 | 551 | |
512 | 552 | return $var; |
513 | 553 | } |
@@ -525,15 +565,17 @@ discard block |
||
525 | 565 | */ |
526 | 566 | function urldecode__recursive($var, $level = 0) |
527 | 567 | { |
528 | - if (!is_array($var)) |
|
529 | - return urldecode($var); |
|
568 | + if (!is_array($var)) { |
|
569 | + return urldecode($var); |
|
570 | + } |
|
530 | 571 | |
531 | 572 | // Reindex the array... |
532 | 573 | $new_var = array(); |
533 | 574 | |
534 | 575 | // Add the htmlspecialchars to every element. |
535 | - foreach ($var as $k => $v) |
|
536 | - $new_var[urldecode($k)] = $level > 25 ? null : urldecode__recursive($v, $level + 1); |
|
576 | + foreach ($var as $k => $v) { |
|
577 | + $new_var[urldecode($k)] = $level > 25 ? null : urldecode__recursive($v, $level + 1); |
|
578 | + } |
|
537 | 579 | |
538 | 580 | return $new_var; |
539 | 581 | } |
@@ -551,15 +593,17 @@ discard block |
||
551 | 593 | { |
552 | 594 | global $smcFunc; |
553 | 595 | |
554 | - if (!is_array($var)) |
|
555 | - return $smcFunc['db_unescape_string']($var); |
|
596 | + if (!is_array($var)) { |
|
597 | + return $smcFunc['db_unescape_string']($var); |
|
598 | + } |
|
556 | 599 | |
557 | 600 | // Reindex the array without slashes, this time. |
558 | 601 | $new_var = array(); |
559 | 602 | |
560 | 603 | // Strip the slashes from every element. |
561 | - foreach ($var as $k => $v) |
|
562 | - $new_var[$smcFunc['db_unescape_string']($k)] = unescapestring__recursive($v); |
|
604 | + foreach ($var as $k => $v) { |
|
605 | + $new_var[$smcFunc['db_unescape_string']($k)] = unescapestring__recursive($v); |
|
606 | + } |
|
563 | 607 | |
564 | 608 | return $new_var; |
565 | 609 | } |
@@ -577,15 +621,17 @@ discard block |
||
577 | 621 | */ |
578 | 622 | function stripslashes__recursive($var, $level = 0) |
579 | 623 | { |
580 | - if (!is_array($var)) |
|
581 | - return stripslashes($var); |
|
624 | + if (!is_array($var)) { |
|
625 | + return stripslashes($var); |
|
626 | + } |
|
582 | 627 | |
583 | 628 | // Reindex the array without slashes, this time. |
584 | 629 | $new_var = array(); |
585 | 630 | |
586 | 631 | // Strip the slashes from every element. |
587 | - foreach ($var as $k => $v) |
|
588 | - $new_var[stripslashes($k)] = $level > 25 ? null : stripslashes__recursive($v, $level + 1); |
|
632 | + foreach ($var as $k => $v) { |
|
633 | + $new_var[stripslashes($k)] = $level > 25 ? null : stripslashes__recursive($v, $level + 1); |
|
634 | + } |
|
589 | 635 | |
590 | 636 | return $new_var; |
591 | 637 | } |
@@ -606,12 +652,14 @@ discard block |
||
606 | 652 | global $smcFunc; |
607 | 653 | |
608 | 654 | // Remove spaces (32), tabs (9), returns (13, 10, and 11), nulls (0), and hard spaces. (160) |
609 | - if (!is_array($var)) |
|
610 | - return isset($smcFunc) ? $smcFunc['htmltrim']($var) : trim($var, ' ' . "\t\n\r\x0B" . '\0' . "\xA0"); |
|
655 | + if (!is_array($var)) { |
|
656 | + return isset($smcFunc) ? $smcFunc['htmltrim']($var) : trim($var, ' ' . "\t\n\r\x0B" . '\0' . "\xA0"); |
|
657 | + } |
|
611 | 658 | |
612 | 659 | // Go through all the elements and remove the whitespace. |
613 | - foreach ($var as $k => $v) |
|
614 | - $var[$k] = $level > 25 ? null : htmltrim__recursive($v, $level + 1); |
|
660 | + foreach ($var as $k => $v) { |
|
661 | + $var[$k] = $level > 25 ? null : htmltrim__recursive($v, $level + 1); |
|
662 | + } |
|
615 | 663 | |
616 | 664 | return $var; |
617 | 665 | } |
@@ -676,30 +724,37 @@ discard block |
||
676 | 724 | global $scripturl, $modSettings, $context; |
677 | 725 | |
678 | 726 | // If $scripturl is set to nothing, or the SID is not defined (SSI?) just quit. |
679 | - if ($scripturl == '' || !defined('SID')) |
|
680 | - return $buffer; |
|
727 | + if ($scripturl == '' || !defined('SID')) { |
|
728 | + return $buffer; |
|
729 | + } |
|
681 | 730 | |
682 | 731 | // Do nothing if the session is cookied, or they are a crawler - guests are caught by redirectexit(). This doesn't work below PHP 4.3.0, because it makes the output buffer bigger. |
683 | 732 | // @todo smflib |
684 | - if (empty($_COOKIE) && SID != '' && !isBrowser('possibly_robot')) |
|
685 | - $buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', '"' . $scripturl . '?' . SID . '&', $buffer); |
|
733 | + if (empty($_COOKIE) && SID != '' && !isBrowser('possibly_robot')) { |
|
734 | + $buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', '"' . $scripturl . '?' . SID . '&', $buffer); |
|
735 | + } |
|
686 | 736 | // Debugging templates, are we? |
687 | - elseif (isset($_GET['debug'])) |
|
688 | - $buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '\\??/', '"' . $scripturl . '?debug;', $buffer); |
|
737 | + elseif (isset($_GET['debug'])) { |
|
738 | + $buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '\\??/', '"' . $scripturl . '?debug;', $buffer); |
|
739 | + } |
|
689 | 740 | |
690 | 741 | // This should work even in 4.2.x, just not CGI without cgi.fix_pathinfo. |
691 | 742 | if (!empty($modSettings['queryless_urls']) && (!$context['server']['is_cgi'] || ini_get('cgi.fix_pathinfo') == 1 || @get_cfg_var('cgi.fix_pathinfo') == 1) && ($context['server']['is_apache'] || $context['server']['is_lighttpd'] || $context['server']['is_litespeed'])) |
692 | 743 | { |
693 | 744 | // Let's do something special for session ids! |
694 | - if (defined('SID') && SID != '') |
|
695 | - $buffer = preg_replace_callback('~"' . preg_quote($scripturl, '~') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m) |
|
745 | + if (defined('SID') && SID != '') { |
|
746 | + $buffer = preg_replace_callback('~"' . preg_quote($scripturl, '~') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m) |
|
696 | 747 | { |
697 | - global $scripturl; return '"' . $scripturl . "/" . strtr("$m[1]", '&;=', '//,') . ".html?" . SID . (isset($m[2]) ? $m[2] : "") . '"'; |
|
748 | + global $scripturl; |
|
749 | + } |
|
750 | + return '"' . $scripturl . "/" . strtr("$m[1]", '&;=', '//,') . ".html?" . SID . (isset($m[2]) ? $m[2] : "") . '"'; |
|
698 | 751 | }, $buffer); |
699 | - else |
|
700 | - $buffer = preg_replace_callback('~"' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m) |
|
752 | + else { |
|
753 | + $buffer = preg_replace_callback('~"' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m) |
|
701 | 754 | { |
702 | - global $scripturl; return '"' . $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? $m[2] : "") . '"'; |
|
755 | + global $scripturl; |
|
756 | + } |
|
757 | + return '"' . $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? $m[2] : "") . '"'; |
|
703 | 758 | }, $buffer); |
704 | 759 | } |
705 | 760 |