@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 3 |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF')) |
|
16 | +if (!defined('SMF')) { |
|
17 | 17 | die('No direct access...'); |
18 | +} |
|
18 | 19 | |
19 | 20 | /** |
20 | 21 | * Update some basic statistics. |
@@ -122,10 +123,11 @@ discard block |
||
122 | 123 | $smcFunc['db_free_result']($result); |
123 | 124 | |
124 | 125 | // Add this to the number of unapproved members |
125 | - if (!empty($changes['unapprovedMembers'])) |
|
126 | - $changes['unapprovedMembers'] += $coppa_approvals; |
|
127 | - else |
|
128 | - $changes['unapprovedMembers'] = $coppa_approvals; |
|
126 | + if (!empty($changes['unapprovedMembers'])) { |
|
127 | + $changes['unapprovedMembers'] += $coppa_approvals; |
|
128 | + } else { |
|
129 | + $changes['unapprovedMembers'] = $coppa_approvals; |
|
130 | + } |
|
129 | 131 | } |
130 | 132 | } |
131 | 133 | } |
@@ -133,9 +135,9 @@ discard block |
||
133 | 135 | break; |
134 | 136 | |
135 | 137 | case 'message': |
136 | - if ($parameter1 === true && $parameter2 !== null) |
|
137 | - updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true); |
|
138 | - else |
|
138 | + if ($parameter1 === true && $parameter2 !== null) { |
|
139 | + updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true); |
|
140 | + } else |
|
139 | 141 | { |
140 | 142 | // SUM and MAX on a smaller table is better for InnoDB tables. |
141 | 143 | $result = $smcFunc['db_query']('', ' |
@@ -175,23 +177,25 @@ discard block |
||
175 | 177 | $parameter2 = text2words($parameter2); |
176 | 178 | |
177 | 179 | $inserts = array(); |
178 | - foreach ($parameter2 as $word) |
|
179 | - $inserts[] = array($word, $parameter1); |
|
180 | + foreach ($parameter2 as $word) { |
|
181 | + $inserts[] = array($word, $parameter1); |
|
182 | + } |
|
180 | 183 | |
181 | - if (!empty($inserts)) |
|
182 | - $smcFunc['db_insert']('ignore', |
|
184 | + if (!empty($inserts)) { |
|
185 | + $smcFunc['db_insert']('ignore', |
|
183 | 186 | '{db_prefix}log_search_subjects', |
184 | 187 | array('word' => 'string', 'id_topic' => 'int'), |
185 | 188 | $inserts, |
186 | 189 | array('word', 'id_topic') |
187 | 190 | ); |
191 | + } |
|
188 | 192 | } |
189 | 193 | break; |
190 | 194 | |
191 | 195 | case 'topic': |
192 | - if ($parameter1 === true) |
|
193 | - updateSettings(array('totalTopics' => true), true); |
|
194 | - else |
|
196 | + if ($parameter1 === true) { |
|
197 | + updateSettings(array('totalTopics' => true), true); |
|
198 | + } else |
|
195 | 199 | { |
196 | 200 | // Get the number of topics - a SUM is better for InnoDB tables. |
197 | 201 | // We also ignore the recycle bin here because there will probably be a bunch of one-post topics there. |
@@ -212,8 +216,9 @@ discard block |
||
212 | 216 | |
213 | 217 | case 'postgroups': |
214 | 218 | // Parameter two is the updated columns: we should check to see if we base groups off any of these. |
215 | - if ($parameter2 !== null && !in_array('posts', $parameter2)) |
|
216 | - return; |
|
219 | + if ($parameter2 !== null && !in_array('posts', $parameter2)) { |
|
220 | + return; |
|
221 | + } |
|
217 | 222 | |
218 | 223 | $postgroups = cache_get_data('updateStats:postgroups', 360); |
219 | 224 | if ($postgroups == null || $parameter1 == null) |
@@ -228,8 +233,9 @@ discard block |
||
228 | 233 | ) |
229 | 234 | ); |
230 | 235 | $postgroups = array(); |
231 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
232 | - $postgroups[$row['id_group']] = $row['min_posts']; |
|
236 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
237 | + $postgroups[$row['id_group']] = $row['min_posts']; |
|
238 | + } |
|
233 | 239 | $smcFunc['db_free_result']($request); |
234 | 240 | |
235 | 241 | // Sort them this way because if it's done with MySQL it causes a filesort :(. |
@@ -239,8 +245,9 @@ discard block |
||
239 | 245 | } |
240 | 246 | |
241 | 247 | // Oh great, they've screwed their post groups. |
242 | - if (empty($postgroups)) |
|
243 | - return; |
|
248 | + if (empty($postgroups)) { |
|
249 | + return; |
|
250 | + } |
|
244 | 251 | |
245 | 252 | // Set all membergroups from most posts to least posts. |
246 | 253 | $conditions = ''; |
@@ -298,10 +305,9 @@ discard block |
||
298 | 305 | { |
299 | 306 | $condition = 'id_member IN ({array_int:members})'; |
300 | 307 | $parameters['members'] = $members; |
301 | - } |
|
302 | - elseif ($members === null) |
|
303 | - $condition = '1=1'; |
|
304 | - else |
|
308 | + } elseif ($members === null) { |
|
309 | + $condition = '1=1'; |
|
310 | + } else |
|
305 | 311 | { |
306 | 312 | $condition = 'id_member = {int:member}'; |
307 | 313 | $parameters['member'] = $members; |
@@ -341,9 +347,9 @@ discard block |
||
341 | 347 | if (count($vars_to_integrate) != 0) |
342 | 348 | { |
343 | 349 | // Fetch a list of member_names if necessary |
344 | - if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) |
|
345 | - $member_names = array($user_info['username']); |
|
346 | - else |
|
350 | + if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) { |
|
351 | + $member_names = array($user_info['username']); |
|
352 | + } else |
|
347 | 353 | { |
348 | 354 | $member_names = array(); |
349 | 355 | $request = $smcFunc['db_query']('', ' |
@@ -352,14 +358,16 @@ discard block |
||
352 | 358 | WHERE ' . $condition, |
353 | 359 | $parameters |
354 | 360 | ); |
355 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
356 | - $member_names[] = $row['member_name']; |
|
361 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
362 | + $member_names[] = $row['member_name']; |
|
363 | + } |
|
357 | 364 | $smcFunc['db_free_result']($request); |
358 | 365 | } |
359 | 366 | |
360 | - if (!empty($member_names)) |
|
361 | - foreach ($vars_to_integrate as $var) |
|
367 | + if (!empty($member_names)) { |
|
368 | + foreach ($vars_to_integrate as $var) |
|
362 | 369 | call_integration_hook('integrate_change_member_data', array($member_names, $var, &$data[$var], &$knownInts, &$knownFloats)); |
370 | + } |
|
363 | 371 | } |
364 | 372 | } |
365 | 373 | |
@@ -367,16 +375,17 @@ discard block |
||
367 | 375 | foreach ($data as $var => $val) |
368 | 376 | { |
369 | 377 | $type = 'string'; |
370 | - if (in_array($var, $knownInts)) |
|
371 | - $type = 'int'; |
|
372 | - elseif (in_array($var, $knownFloats)) |
|
373 | - $type = 'float'; |
|
374 | - elseif ($var == 'birthdate') |
|
375 | - $type = 'date'; |
|
376 | - elseif ($var == 'member_ip') |
|
377 | - $type = 'inet'; |
|
378 | - elseif ($var == 'member_ip2') |
|
379 | - $type = 'inet'; |
|
378 | + if (in_array($var, $knownInts)) { |
|
379 | + $type = 'int'; |
|
380 | + } elseif (in_array($var, $knownFloats)) { |
|
381 | + $type = 'float'; |
|
382 | + } elseif ($var == 'birthdate') { |
|
383 | + $type = 'date'; |
|
384 | + } elseif ($var == 'member_ip') { |
|
385 | + $type = 'inet'; |
|
386 | + } elseif ($var == 'member_ip2') { |
|
387 | + $type = 'inet'; |
|
388 | + } |
|
380 | 389 | |
381 | 390 | // Doing an increment? |
382 | 391 | if ($type == 'int' && ($val === '+' || $val === '-')) |
@@ -390,8 +399,9 @@ discard block |
||
390 | 399 | { |
391 | 400 | if (preg_match('~^' . $var . ' (\+ |- |\+ -)([\d]+)~', $val, $match)) |
392 | 401 | { |
393 | - if ($match[1] != '+ ') |
|
394 | - $val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END'; |
|
402 | + if ($match[1] != '+ ') { |
|
403 | + $val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END'; |
|
404 | + } |
|
395 | 405 | $type = 'raw'; |
396 | 406 | } |
397 | 407 | } |
@@ -412,8 +422,9 @@ discard block |
||
412 | 422 | // Clear any caching? |
413 | 423 | if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && !empty($members)) |
414 | 424 | { |
415 | - if (!is_array($members)) |
|
416 | - $members = array($members); |
|
425 | + if (!is_array($members)) { |
|
426 | + $members = array($members); |
|
427 | + } |
|
417 | 428 | |
418 | 429 | foreach ($members as $member) |
419 | 430 | { |
@@ -446,29 +457,32 @@ discard block |
||
446 | 457 | { |
447 | 458 | global $modSettings, $smcFunc; |
448 | 459 | |
449 | - if (empty($changeArray) || !is_array($changeArray)) |
|
450 | - return; |
|
460 | + if (empty($changeArray) || !is_array($changeArray)) { |
|
461 | + return; |
|
462 | + } |
|
451 | 463 | |
452 | 464 | $toRemove = array(); |
453 | 465 | |
454 | 466 | // Go check if there is any setting to be removed. |
455 | - foreach ($changeArray as $k => $v) |
|
456 | - if ($v === null) |
|
467 | + foreach ($changeArray as $k => $v) { |
|
468 | + if ($v === null) |
|
457 | 469 | { |
458 | 470 | // Found some, remove them from the original array and add them to ours. |
459 | 471 | unset($changeArray[$k]); |
472 | + } |
|
460 | 473 | $toRemove[] = $k; |
461 | 474 | } |
462 | 475 | |
463 | 476 | // Proceed with the deletion. |
464 | - if (!empty($toRemove)) |
|
465 | - $smcFunc['db_query']('', ' |
|
477 | + if (!empty($toRemove)) { |
|
478 | + $smcFunc['db_query']('', ' |
|
466 | 479 | DELETE FROM {db_prefix}settings |
467 | 480 | WHERE variable IN ({array_string:remove})', |
468 | 481 | array( |
469 | 482 | 'remove' => $toRemove, |
470 | 483 | ) |
471 | 484 | ); |
485 | + } |
|
472 | 486 | |
473 | 487 | // In some cases, this may be better and faster, but for large sets we don't want so many UPDATEs. |
474 | 488 | if ($update) |
@@ -497,19 +511,22 @@ discard block |
||
497 | 511 | foreach ($changeArray as $variable => $value) |
498 | 512 | { |
499 | 513 | // Don't bother if it's already like that ;). |
500 | - if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) |
|
501 | - continue; |
|
514 | + if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) { |
|
515 | + continue; |
|
516 | + } |
|
502 | 517 | // If the variable isn't set, but would only be set to nothing'ness, then don't bother setting it. |
503 | - elseif (!isset($modSettings[$variable]) && empty($value)) |
|
504 | - continue; |
|
518 | + elseif (!isset($modSettings[$variable]) && empty($value)) { |
|
519 | + continue; |
|
520 | + } |
|
505 | 521 | |
506 | 522 | $replaceArray[] = array($variable, $value); |
507 | 523 | |
508 | 524 | $modSettings[$variable] = $value; |
509 | 525 | } |
510 | 526 | |
511 | - if (empty($replaceArray)) |
|
512 | - return; |
|
527 | + if (empty($replaceArray)) { |
|
528 | + return; |
|
529 | + } |
|
513 | 530 | |
514 | 531 | $smcFunc['db_insert']('replace', |
515 | 532 | '{db_prefix}settings', |
@@ -555,14 +572,17 @@ discard block |
||
555 | 572 | $start_invalid = $start < 0; |
556 | 573 | |
557 | 574 | // Make sure $start is a proper variable - not less than 0. |
558 | - if ($start_invalid) |
|
559 | - $start = 0; |
|
575 | + if ($start_invalid) { |
|
576 | + $start = 0; |
|
577 | + } |
|
560 | 578 | // Not greater than the upper bound. |
561 | - elseif ($start >= $max_value) |
|
562 | - $start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page))); |
|
579 | + elseif ($start >= $max_value) { |
|
580 | + $start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page))); |
|
581 | + } |
|
563 | 582 | // And it has to be a multiple of $num_per_page! |
564 | - else |
|
565 | - $start = max(0, (int) $start - ((int) $start % (int) $num_per_page)); |
|
583 | + else { |
|
584 | + $start = max(0, (int) $start - ((int) $start % (int) $num_per_page)); |
|
585 | + } |
|
566 | 586 | |
567 | 587 | $context['current_page'] = $start / $num_per_page; |
568 | 588 | |
@@ -592,77 +612,87 @@ discard block |
||
592 | 612 | |
593 | 613 | // Show all the pages. |
594 | 614 | $display_page = 1; |
595 | - for ($counter = 0; $counter < $max_value; $counter += $num_per_page) |
|
596 | - $pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++); |
|
615 | + for ($counter = 0; $counter < $max_value; $counter += $num_per_page) { |
|
616 | + $pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++); |
|
617 | + } |
|
597 | 618 | |
598 | 619 | // Show the right arrow. |
599 | 620 | $display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page); |
600 | - if ($start != $counter - $max_value && !$start_invalid) |
|
601 | - $pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']); |
|
602 | - } |
|
603 | - else |
|
621 | + if ($start != $counter - $max_value && !$start_invalid) { |
|
622 | + $pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']); |
|
623 | + } |
|
624 | + } else |
|
604 | 625 | { |
605 | 626 | // If they didn't enter an odd value, pretend they did. |
606 | 627 | $PageContiguous = (int) ($modSettings['compactTopicPagesContiguous'] - ($modSettings['compactTopicPagesContiguous'] % 2)) / 2; |
607 | 628 | |
608 | 629 | // Show the "prev page" link. (>prev page< 1 ... 6 7 [8] 9 10 ... 15 next page) |
609 | - if (!empty($start) && $show_prevnext) |
|
610 | - $pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']); |
|
611 | - else |
|
612 | - $pageindex .= ''; |
|
630 | + if (!empty($start) && $show_prevnext) { |
|
631 | + $pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']); |
|
632 | + } else { |
|
633 | + $pageindex .= ''; |
|
634 | + } |
|
613 | 635 | |
614 | 636 | // Show the first page. (prev page >1< ... 6 7 [8] 9 10 ... 15) |
615 | - if ($start > $num_per_page * $PageContiguous) |
|
616 | - $pageindex .= sprintf($base_link, 0, '1'); |
|
637 | + if ($start > $num_per_page * $PageContiguous) { |
|
638 | + $pageindex .= sprintf($base_link, 0, '1'); |
|
639 | + } |
|
617 | 640 | |
618 | 641 | // Show the ... after the first page. (prev page 1 >...< 6 7 [8] 9 10 ... 15 next page) |
619 | - if ($start > $num_per_page * ($PageContiguous + 1)) |
|
620 | - $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
642 | + if ($start > $num_per_page * ($PageContiguous + 1)) { |
|
643 | + $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
621 | 644 | '{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)), |
622 | 645 | '{FIRST_PAGE}' => $num_per_page, |
623 | 646 | '{LAST_PAGE}' => $start - $num_per_page * $PageContiguous, |
624 | 647 | '{PER_PAGE}' => $num_per_page, |
625 | 648 | )); |
649 | + } |
|
626 | 650 | |
627 | 651 | // Show the pages before the current one. (prev page 1 ... >6 7< [8] 9 10 ... 15 next page) |
628 | - for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) |
|
629 | - if ($start >= $num_per_page * $nCont) |
|
652 | + for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) { |
|
653 | + if ($start >= $num_per_page * $nCont) |
|
630 | 654 | { |
631 | 655 | $tmpStart = $start - $num_per_page * $nCont; |
656 | + } |
|
632 | 657 | $pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1); |
633 | 658 | } |
634 | 659 | |
635 | 660 | // Show the current page. (prev page 1 ... 6 7 >[8]< 9 10 ... 15 next page) |
636 | - if (!$start_invalid) |
|
637 | - $pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1); |
|
638 | - else |
|
639 | - $pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1); |
|
661 | + if (!$start_invalid) { |
|
662 | + $pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1); |
|
663 | + } else { |
|
664 | + $pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1); |
|
665 | + } |
|
640 | 666 | |
641 | 667 | // Show the pages after the current one... (prev page 1 ... 6 7 [8] >9 10< ... 15 next page) |
642 | 668 | $tmpMaxPages = (int) (($max_value - 1) / $num_per_page) * $num_per_page; |
643 | - for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) |
|
644 | - if ($start + $num_per_page * $nCont <= $tmpMaxPages) |
|
669 | + for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) { |
|
670 | + if ($start + $num_per_page * $nCont <= $tmpMaxPages) |
|
645 | 671 | { |
646 | 672 | $tmpStart = $start + $num_per_page * $nCont; |
673 | + } |
|
647 | 674 | $pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1); |
648 | 675 | } |
649 | 676 | |
650 | 677 | // Show the '...' part near the end. (prev page 1 ... 6 7 [8] 9 10 >...< 15 next page) |
651 | - if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) |
|
652 | - $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
678 | + if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) { |
|
679 | + $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
653 | 680 | '{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)), |
654 | 681 | '{FIRST_PAGE}' => $start + $num_per_page * ($PageContiguous + 1), |
655 | 682 | '{LAST_PAGE}' => $tmpMaxPages, |
656 | 683 | '{PER_PAGE}' => $num_per_page, |
657 | 684 | )); |
685 | + } |
|
658 | 686 | |
659 | 687 | // Show the last number in the list. (prev page 1 ... 6 7 [8] 9 10 ... >15< next page) |
660 | - if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) |
|
661 | - $pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1); |
|
688 | + if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) { |
|
689 | + $pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1); |
|
690 | + } |
|
662 | 691 | |
663 | 692 | // Show the "next page" link. (prev page 1 ... 6 7 [8] 9 10 ... 15 >next page<) |
664 | - if ($start != $tmpMaxPages && $show_prevnext) |
|
665 | - $pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']); |
|
693 | + if ($start != $tmpMaxPages && $show_prevnext) { |
|
694 | + $pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']); |
|
695 | + } |
|
666 | 696 | } |
667 | 697 | $pageindex .= $settings['page_index']['extra_after']; |
668 | 698 | |
@@ -688,8 +718,9 @@ discard block |
||
688 | 718 | if ($decimal_separator === null) |
689 | 719 | { |
690 | 720 | // Not set for whatever reason? |
691 | - if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) |
|
692 | - return $number; |
|
721 | + if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) { |
|
722 | + return $number; |
|
723 | + } |
|
693 | 724 | |
694 | 725 | // Cache these each load... |
695 | 726 | $thousands_separator = $matches[1]; |
@@ -721,17 +752,20 @@ discard block |
||
721 | 752 | static $non_twelve_hour; |
722 | 753 | |
723 | 754 | // Offset the time. |
724 | - if (!$offset_type) |
|
725 | - $time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600; |
|
755 | + if (!$offset_type) { |
|
756 | + $time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600; |
|
757 | + } |
|
726 | 758 | // Just the forum offset? |
727 | - elseif ($offset_type == 'forum') |
|
728 | - $time = $log_time + $modSettings['time_offset'] * 3600; |
|
729 | - else |
|
730 | - $time = $log_time; |
|
759 | + elseif ($offset_type == 'forum') { |
|
760 | + $time = $log_time + $modSettings['time_offset'] * 3600; |
|
761 | + } else { |
|
762 | + $time = $log_time; |
|
763 | + } |
|
731 | 764 | |
732 | 765 | // We can't have a negative date (on Windows, at least.) |
733 | - if ($log_time < 0) |
|
734 | - $log_time = 0; |
|
766 | + if ($log_time < 0) { |
|
767 | + $log_time = 0; |
|
768 | + } |
|
735 | 769 | |
736 | 770 | // Today and Yesterday? |
737 | 771 | if ($modSettings['todayMod'] >= 1 && $show_today === true) |
@@ -748,46 +782,53 @@ discard block |
||
748 | 782 | { |
749 | 783 | $h = strpos($user_info['time_format'], '%l') === false ? '%I' : '%l'; |
750 | 784 | $today_fmt = $h . ':%M' . $s . ' %p'; |
785 | + } else { |
|
786 | + $today_fmt = '%H:%M' . $s; |
|
751 | 787 | } |
752 | - else |
|
753 | - $today_fmt = '%H:%M' . $s; |
|
754 | 788 | |
755 | 789 | // Same day of the year, same year.... Today! |
756 | - if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) |
|
757 | - return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type); |
|
790 | + if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) { |
|
791 | + return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type); |
|
792 | + } |
|
758 | 793 | |
759 | 794 | // Day-of-year is one less and same year, or it's the first of the year and that's the last of the year... |
760 | - if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31)) |
|
761 | - return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type); |
|
795 | + if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31)) { |
|
796 | + return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type); |
|
797 | + } |
|
762 | 798 | } |
763 | 799 | |
764 | 800 | $str = !is_bool($show_today) ? $show_today : $user_info['time_format']; |
765 | 801 | |
766 | 802 | if (setlocale(LC_TIME, $txt['lang_locale'])) |
767 | 803 | { |
768 | - if (!isset($non_twelve_hour)) |
|
769 | - $non_twelve_hour = trim(strftime('%p')) === ''; |
|
770 | - if ($non_twelve_hour && strpos($str, '%p') !== false) |
|
771 | - $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
804 | + if (!isset($non_twelve_hour)) { |
|
805 | + $non_twelve_hour = trim(strftime('%p')) === ''; |
|
806 | + } |
|
807 | + if ($non_twelve_hour && strpos($str, '%p') !== false) { |
|
808 | + $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
809 | + } |
|
772 | 810 | |
773 | - foreach (array('%a', '%A', '%b', '%B') as $token) |
|
774 | - if (strpos($str, $token) !== false) |
|
811 | + foreach (array('%a', '%A', '%b', '%B') as $token) { |
|
812 | + if (strpos($str, $token) !== false) |
|
775 | 813 | $str = str_replace($token, strftime($token, $time), $str); |
776 | - } |
|
777 | - else |
|
814 | + } |
|
815 | + } else |
|
778 | 816 | { |
779 | 817 | // Do-it-yourself time localization. Fun. |
780 | - foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) |
|
781 | - if (strpos($str, $token) !== false) |
|
818 | + foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) { |
|
819 | + if (strpos($str, $token) !== false) |
|
782 | 820 | $str = str_replace($token, $txt[$text_label][(int) strftime($token === '%a' || $token === '%A' ? '%w' : '%m', $time)], $str); |
821 | + } |
|
783 | 822 | |
784 | - if (strpos($str, '%p') !== false) |
|
785 | - $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
823 | + if (strpos($str, '%p') !== false) { |
|
824 | + $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
825 | + } |
|
786 | 826 | } |
787 | 827 | |
788 | 828 | // Windows doesn't support %e; on some versions, strftime fails altogether if used, so let's prevent that. |
789 | - if ($context['server']['is_windows'] && strpos($str, '%e') !== false) |
|
790 | - $str = str_replace('%e', ltrim(strftime('%d', $time), '0'), $str); |
|
829 | + if ($context['server']['is_windows'] && strpos($str, '%e') !== false) { |
|
830 | + $str = str_replace('%e', ltrim(strftime('%d', $time), '0'), $str); |
|
831 | + } |
|
791 | 832 | |
792 | 833 | // Format any other characters.. |
793 | 834 | return strftime($str, $time); |
@@ -809,16 +850,19 @@ discard block |
||
809 | 850 | static $translation = array(); |
810 | 851 | |
811 | 852 | // Determine the character set... Default to UTF-8 |
812 | - if (empty($context['character_set'])) |
|
813 | - $charset = 'UTF-8'; |
|
853 | + if (empty($context['character_set'])) { |
|
854 | + $charset = 'UTF-8'; |
|
855 | + } |
|
814 | 856 | // Use ISO-8859-1 in place of non-supported ISO-8859 charsets... |
815 | - elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) |
|
816 | - $charset = 'ISO-8859-1'; |
|
817 | - else |
|
818 | - $charset = $context['character_set']; |
|
857 | + elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) { |
|
858 | + $charset = 'ISO-8859-1'; |
|
859 | + } else { |
|
860 | + $charset = $context['character_set']; |
|
861 | + } |
|
819 | 862 | |
820 | - if (empty($translation)) |
|
821 | - $translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array(''' => '\'', ''' => '\'', ' ' => ' '); |
|
863 | + if (empty($translation)) { |
|
864 | + $translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array(''' => '\'', ''' => '\'', ' ' => ' '); |
|
865 | + } |
|
822 | 866 | |
823 | 867 | return strtr($string, $translation); |
824 | 868 | } |
@@ -840,8 +884,9 @@ discard block |
||
840 | 884 | global $smcFunc; |
841 | 885 | |
842 | 886 | // It was already short enough! |
843 | - if ($smcFunc['strlen']($subject) <= $len) |
|
844 | - return $subject; |
|
887 | + if ($smcFunc['strlen']($subject) <= $len) { |
|
888 | + return $subject; |
|
889 | + } |
|
845 | 890 | |
846 | 891 | // Shorten it by the length it was too long, and strip off junk from the end. |
847 | 892 | return $smcFunc['substr']($subject, 0, $len) . '...'; |
@@ -860,10 +905,11 @@ discard block |
||
860 | 905 | { |
861 | 906 | global $user_info, $modSettings; |
862 | 907 | |
863 | - if ($timestamp === null) |
|
864 | - $timestamp = time(); |
|
865 | - elseif ($timestamp == 0) |
|
866 | - return 0; |
|
908 | + if ($timestamp === null) { |
|
909 | + $timestamp = time(); |
|
910 | + } elseif ($timestamp == 0) { |
|
911 | + return 0; |
|
912 | + } |
|
867 | 913 | |
868 | 914 | return $timestamp + ($modSettings['time_offset'] + ($use_user_offset ? $user_info['time_offset'] : 0)) * 3600; |
869 | 915 | } |
@@ -892,8 +938,9 @@ discard block |
||
892 | 938 | $array[$i] = $array[$j]; |
893 | 939 | $array[$j] = $temp; |
894 | 940 | |
895 | - for ($i = 1; $p[$i] == 0; $i++) |
|
896 | - $p[$i] = 1; |
|
941 | + for ($i = 1; $p[$i] == 0; $i++) { |
|
942 | + $p[$i] = 1; |
|
943 | + } |
|
897 | 944 | |
898 | 945 | $orders[] = $array; |
899 | 946 | } |
@@ -925,12 +972,14 @@ discard block |
||
925 | 972 | static $disabled; |
926 | 973 | |
927 | 974 | // Don't waste cycles |
928 | - if ($message === '') |
|
929 | - return ''; |
|
975 | + if ($message === '') { |
|
976 | + return ''; |
|
977 | + } |
|
930 | 978 | |
931 | 979 | // Just in case it wasn't determined yet whether UTF-8 is enabled. |
932 | - if (!isset($context['utf8'])) |
|
933 | - $context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8'; |
|
980 | + if (!isset($context['utf8'])) { |
|
981 | + $context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8'; |
|
982 | + } |
|
934 | 983 | |
935 | 984 | // Clean up any cut/paste issues we may have |
936 | 985 | $message = sanitizeMSCutPaste($message); |
@@ -942,13 +991,15 @@ discard block |
||
942 | 991 | return $message; |
943 | 992 | } |
944 | 993 | |
945 | - if ($smileys !== null && ($smileys == '1' || $smileys == '0')) |
|
946 | - $smileys = (bool) $smileys; |
|
994 | + if ($smileys !== null && ($smileys == '1' || $smileys == '0')) { |
|
995 | + $smileys = (bool) $smileys; |
|
996 | + } |
|
947 | 997 | |
948 | 998 | if (empty($modSettings['enableBBC']) && $message !== false) |
949 | 999 | { |
950 | - if ($smileys === true) |
|
951 | - parsesmileys($message); |
|
1000 | + if ($smileys === true) { |
|
1001 | + parsesmileys($message); |
|
1002 | + } |
|
952 | 1003 | |
953 | 1004 | return $message; |
954 | 1005 | } |
@@ -961,8 +1012,9 @@ discard block |
||
961 | 1012 | } |
962 | 1013 | |
963 | 1014 | // Ensure $modSettings['tld_regex'] contains a valid regex for the autolinker |
964 | - if (!empty($modSettings['autoLinkUrls'])) |
|
965 | - set_tld_regex(); |
|
1015 | + if (!empty($modSettings['autoLinkUrls'])) { |
|
1016 | + set_tld_regex(); |
|
1017 | + } |
|
966 | 1018 | |
967 | 1019 | // Allow mods access before entering the main parse_bbc loop |
968 | 1020 | call_integration_hook('integrate_pre_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags)); |
@@ -976,12 +1028,14 @@ discard block |
||
976 | 1028 | |
977 | 1029 | $temp = explode(',', strtolower($modSettings['disabledBBC'])); |
978 | 1030 | |
979 | - foreach ($temp as $tag) |
|
980 | - $disabled[trim($tag)] = true; |
|
1031 | + foreach ($temp as $tag) { |
|
1032 | + $disabled[trim($tag)] = true; |
|
1033 | + } |
|
981 | 1034 | } |
982 | 1035 | |
983 | - if (empty($modSettings['enableEmbeddedFlash'])) |
|
984 | - $disabled['flash'] = true; |
|
1036 | + if (empty($modSettings['enableEmbeddedFlash'])) { |
|
1037 | + $disabled['flash'] = true; |
|
1038 | + } |
|
985 | 1039 | |
986 | 1040 | /* The following bbc are formatted as an array, with keys as follows: |
987 | 1041 | |
@@ -1102,8 +1156,9 @@ discard block |
||
1102 | 1156 | $returnContext = ''; |
1103 | 1157 | |
1104 | 1158 | // BBC or the entire attachments feature is disabled |
1105 | - if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) |
|
1106 | - return $data; |
|
1159 | + if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) { |
|
1160 | + return $data; |
|
1161 | + } |
|
1107 | 1162 | |
1108 | 1163 | // Save the attach ID. |
1109 | 1164 | $attachID = $data; |
@@ -1114,8 +1169,9 @@ discard block |
||
1114 | 1169 | $currentAttachment = parseAttachBBC($attachID); |
1115 | 1170 | |
1116 | 1171 | // parseAttachBBC will return a string ($txt key) rather than diying with a fatal_error. Up to you to decide what to do. |
1117 | - if (is_string($currentAttachment)) |
|
1118 | - return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment; |
|
1172 | + if (is_string($currentAttachment)) { |
|
1173 | + return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment; |
|
1174 | + } |
|
1119 | 1175 | |
1120 | 1176 | if (!empty($currentAttachment['is_image'])) |
1121 | 1177 | { |
@@ -1128,15 +1184,17 @@ discard block |
||
1128 | 1184 | $height = ' height="' . $currentAttachment['height'] . '"'; |
1129 | 1185 | } |
1130 | 1186 | |
1131 | - if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) |
|
1132 | - $returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '" alt="' . $currentAttachment['name'] . '" id="thumb_'. $currentAttachment['id']. '"></a>'; |
|
1133 | - else |
|
1134 | - $returnContext .= '<img src="' . $currentAttachment['href'] . ';image" alt="' . $currentAttachment['name'] . '"' . $width . $height . '/>'; |
|
1187 | + if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) { |
|
1188 | + $returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '" alt="' . $currentAttachment['name'] . '" id="thumb_'. $currentAttachment['id']. '"></a>'; |
|
1189 | + } else { |
|
1190 | + $returnContext .= '<img src="' . $currentAttachment['href'] . ';image" alt="' . $currentAttachment['name'] . '"' . $width . $height . '/>'; |
|
1191 | + } |
|
1135 | 1192 | } |
1136 | 1193 | |
1137 | 1194 | // No image. Show a link. |
1138 | - else |
|
1139 | - $returnContext .= $currentAttachment['link']; |
|
1195 | + else { |
|
1196 | + $returnContext .= $currentAttachment['link']; |
|
1197 | + } |
|
1140 | 1198 | |
1141 | 1199 | // Gotta append what we just did. |
1142 | 1200 | $data = $returnContext; |
@@ -1167,8 +1225,9 @@ discard block |
||
1167 | 1225 | for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++) |
1168 | 1226 | { |
1169 | 1227 | // Do PHP code coloring? |
1170 | - if ($php_parts[$php_i] != '<?php') |
|
1171 | - continue; |
|
1228 | + if ($php_parts[$php_i] != '<?php') { |
|
1229 | + continue; |
|
1230 | + } |
|
1172 | 1231 | |
1173 | 1232 | $php_string = ''; |
1174 | 1233 | while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?>') |
@@ -1184,8 +1243,9 @@ discard block |
||
1184 | 1243 | $data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data); |
1185 | 1244 | |
1186 | 1245 | // Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection. |
1187 | - if ($context['browser']['is_opera']) |
|
1188 | - $data .= ' '; |
|
1246 | + if ($context['browser']['is_opera']) { |
|
1247 | + $data .= ' '; |
|
1248 | + } |
|
1189 | 1249 | } |
1190 | 1250 | }, |
1191 | 1251 | 'block_level' => true, |
@@ -1204,8 +1264,9 @@ discard block |
||
1204 | 1264 | for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++) |
1205 | 1265 | { |
1206 | 1266 | // Do PHP code coloring? |
1207 | - if ($php_parts[$php_i] != '<?php') |
|
1208 | - continue; |
|
1267 | + if ($php_parts[$php_i] != '<?php') { |
|
1268 | + continue; |
|
1269 | + } |
|
1209 | 1270 | |
1210 | 1271 | $php_string = ''; |
1211 | 1272 | while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?>') |
@@ -1221,8 +1282,9 @@ discard block |
||
1221 | 1282 | $data[0] = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data[0]); |
1222 | 1283 | |
1223 | 1284 | // Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection. |
1224 | - if ($context['browser']['is_opera']) |
|
1225 | - $data[0] .= ' '; |
|
1285 | + if ($context['browser']['is_opera']) { |
|
1286 | + $data[0] .= ' '; |
|
1287 | + } |
|
1226 | 1288 | } |
1227 | 1289 | }, |
1228 | 1290 | 'block_level' => true, |
@@ -1260,11 +1322,13 @@ discard block |
||
1260 | 1322 | 'content' => '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never">', |
1261 | 1323 | 'validate' => function (&$tag, &$data, $disabled) |
1262 | 1324 | { |
1263 | - if (isset($disabled['url'])) |
|
1264 | - $tag['content'] = '$1'; |
|
1325 | + if (isset($disabled['url'])) { |
|
1326 | + $tag['content'] = '$1'; |
|
1327 | + } |
|
1265 | 1328 | $scheme = parse_url($data[0], PHP_URL_SCHEME); |
1266 | - if (empty($scheme)) |
|
1267 | - $data[0] = '//' . ltrim($data[0], ':/'); |
|
1329 | + if (empty($scheme)) { |
|
1330 | + $data[0] = '//' . ltrim($data[0], ':/'); |
|
1331 | + } |
|
1268 | 1332 | }, |
1269 | 1333 | 'disabled_content' => '<a href="$1" target="_blank" class="new_win">$1</a>', |
1270 | 1334 | ), |
@@ -1311,14 +1375,16 @@ discard block |
||
1311 | 1375 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1312 | 1376 | if ($image_proxy_enabled) |
1313 | 1377 | { |
1314 | - if (empty($scheme)) |
|
1315 | - $data = 'http://' . ltrim($data, ':/'); |
|
1378 | + if (empty($scheme)) { |
|
1379 | + $data = 'http://' . ltrim($data, ':/'); |
|
1380 | + } |
|
1316 | 1381 | |
1317 | - if ($scheme != 'https') |
|
1318 | - $data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret); |
|
1382 | + if ($scheme != 'https') { |
|
1383 | + $data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret); |
|
1384 | + } |
|
1385 | + } elseif (empty($scheme)) { |
|
1386 | + $data = '//' . ltrim($data, ':/'); |
|
1319 | 1387 | } |
1320 | - elseif (empty($scheme)) |
|
1321 | - $data = '//' . ltrim($data, ':/'); |
|
1322 | 1388 | }, |
1323 | 1389 | 'disabled_content' => '($1)', |
1324 | 1390 | ), |
@@ -1334,14 +1400,16 @@ discard block |
||
1334 | 1400 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1335 | 1401 | if ($image_proxy_enabled) |
1336 | 1402 | { |
1337 | - if (empty($scheme)) |
|
1338 | - $data = 'http://' . ltrim($data, ':/'); |
|
1403 | + if (empty($scheme)) { |
|
1404 | + $data = 'http://' . ltrim($data, ':/'); |
|
1405 | + } |
|
1339 | 1406 | |
1340 | - if ($scheme != 'https') |
|
1341 | - $data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret); |
|
1407 | + if ($scheme != 'https') { |
|
1408 | + $data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret); |
|
1409 | + } |
|
1410 | + } elseif (empty($scheme)) { |
|
1411 | + $data = '//' . ltrim($data, ':/'); |
|
1342 | 1412 | } |
1343 | - elseif (empty($scheme)) |
|
1344 | - $data = '//' . ltrim($data, ':/'); |
|
1345 | 1413 | }, |
1346 | 1414 | 'disabled_content' => '($1)', |
1347 | 1415 | ), |
@@ -1353,8 +1421,9 @@ discard block |
||
1353 | 1421 | { |
1354 | 1422 | $data = strtr($data, array('<br>' => '')); |
1355 | 1423 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1356 | - if (empty($scheme)) |
|
1357 | - $data = '//' . ltrim($data, ':/'); |
|
1424 | + if (empty($scheme)) { |
|
1425 | + $data = '//' . ltrim($data, ':/'); |
|
1426 | + } |
|
1358 | 1427 | }, |
1359 | 1428 | ), |
1360 | 1429 | array( |
@@ -1365,13 +1434,14 @@ discard block |
||
1365 | 1434 | 'after' => '</a>', |
1366 | 1435 | 'validate' => function (&$tag, &$data, $disabled) |
1367 | 1436 | { |
1368 | - if (substr($data, 0, 1) == '#') |
|
1369 | - $data = '#post_' . substr($data, 1); |
|
1370 | - else |
|
1437 | + if (substr($data, 0, 1) == '#') { |
|
1438 | + $data = '#post_' . substr($data, 1); |
|
1439 | + } else |
|
1371 | 1440 | { |
1372 | 1441 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1373 | - if (empty($scheme)) |
|
1374 | - $data = '//' . ltrim($data, ':/'); |
|
1442 | + if (empty($scheme)) { |
|
1443 | + $data = '//' . ltrim($data, ':/'); |
|
1444 | + } |
|
1375 | 1445 | } |
1376 | 1446 | }, |
1377 | 1447 | 'disallow_children' => array('email', 'ftp', 'url', 'iurl'), |
@@ -1449,8 +1519,9 @@ discard block |
||
1449 | 1519 | { |
1450 | 1520 | $add_begin = substr(trim($data), 0, 5) != '<?'; |
1451 | 1521 | $data = highlight_php_code($add_begin ? '<?php ' . $data . '?>' : $data); |
1452 | - if ($add_begin) |
|
1453 | - $data = preg_replace(array('~^(.+?)<\?.{0,40}?php(?: |\s)~', '~\?>((?:</(font|span)>)*)$~'), '$1', $data, 2); |
|
1522 | + if ($add_begin) { |
|
1523 | + $data = preg_replace(array('~^(.+?)<\?.{0,40}?php(?: |\s)~', '~\?>((?:</(font|span)>)*)$~'), '$1', $data, 2); |
|
1524 | + } |
|
1454 | 1525 | } |
1455 | 1526 | }, |
1456 | 1527 | 'block_level' => false, |
@@ -1581,10 +1652,11 @@ discard block |
||
1581 | 1652 | 'content' => '$1', |
1582 | 1653 | 'validate' => function (&$tag, &$data, $disabled) |
1583 | 1654 | { |
1584 | - if (is_numeric($data)) |
|
1585 | - $data = timeformat($data); |
|
1586 | - else |
|
1587 | - $tag['content'] = '[time]$1[/time]'; |
|
1655 | + if (is_numeric($data)) { |
|
1656 | + $data = timeformat($data); |
|
1657 | + } else { |
|
1658 | + $tag['content'] = '[time]$1[/time]'; |
|
1659 | + } |
|
1588 | 1660 | }, |
1589 | 1661 | ), |
1590 | 1662 | array( |
@@ -1611,8 +1683,9 @@ discard block |
||
1611 | 1683 | { |
1612 | 1684 | $data = strtr($data, array('<br>' => '')); |
1613 | 1685 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1614 | - if (empty($scheme)) |
|
1615 | - $data = '//' . ltrim($data, ':/'); |
|
1686 | + if (empty($scheme)) { |
|
1687 | + $data = '//' . ltrim($data, ':/'); |
|
1688 | + } |
|
1616 | 1689 | }, |
1617 | 1690 | ), |
1618 | 1691 | array( |
@@ -1624,8 +1697,9 @@ discard block |
||
1624 | 1697 | 'validate' => function (&$tag, &$data, $disabled) |
1625 | 1698 | { |
1626 | 1699 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1627 | - if (empty($scheme)) |
|
1628 | - $data = '//' . ltrim($data, ':/'); |
|
1700 | + if (empty($scheme)) { |
|
1701 | + $data = '//' . ltrim($data, ':/'); |
|
1702 | + } |
|
1629 | 1703 | }, |
1630 | 1704 | 'disallow_children' => array('email', 'ftp', 'url', 'iurl'), |
1631 | 1705 | 'disabled_after' => ' ($1)', |
@@ -1645,8 +1719,9 @@ discard block |
||
1645 | 1719 | // This is mainly for the bbc manager, so it's easy to add tags above. Custom BBC should be added above this line. |
1646 | 1720 | if ($message === false) |
1647 | 1721 | { |
1648 | - if (isset($temp_bbc)) |
|
1649 | - $bbc_codes = $temp_bbc; |
|
1722 | + if (isset($temp_bbc)) { |
|
1723 | + $bbc_codes = $temp_bbc; |
|
1724 | + } |
|
1650 | 1725 | usort($codes, function ($a, $b) { |
1651 | 1726 | return strcmp($a['tag'], $b['tag']); |
1652 | 1727 | }); |
@@ -1666,8 +1741,9 @@ discard block |
||
1666 | 1741 | ); |
1667 | 1742 | if (!isset($disabled['li']) && !isset($disabled['list'])) |
1668 | 1743 | { |
1669 | - foreach ($itemcodes as $c => $dummy) |
|
1670 | - $bbc_codes[$c] = array(); |
|
1744 | + foreach ($itemcodes as $c => $dummy) { |
|
1745 | + $bbc_codes[$c] = array(); |
|
1746 | + } |
|
1671 | 1747 | } |
1672 | 1748 | |
1673 | 1749 | // Shhhh! |
@@ -1688,12 +1764,14 @@ discard block |
||
1688 | 1764 | foreach ($codes as $code) |
1689 | 1765 | { |
1690 | 1766 | // Make it easier to process parameters later |
1691 | - if (!empty($code['parameters'])) |
|
1692 | - ksort($code['parameters'], SORT_STRING); |
|
1767 | + if (!empty($code['parameters'])) { |
|
1768 | + ksort($code['parameters'], SORT_STRING); |
|
1769 | + } |
|
1693 | 1770 | |
1694 | 1771 | // If we are not doing every tag only do ones we are interested in. |
1695 | - if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) |
|
1696 | - $bbc_codes[substr($code['tag'], 0, 1)][] = $code; |
|
1772 | + if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) { |
|
1773 | + $bbc_codes[substr($code['tag'], 0, 1)][] = $code; |
|
1774 | + } |
|
1697 | 1775 | } |
1698 | 1776 | $codes = null; |
1699 | 1777 | } |
@@ -1704,8 +1782,9 @@ discard block |
||
1704 | 1782 | // It's likely this will change if the message is modified. |
1705 | 1783 | $cache_key = 'parse:' . $cache_id . '-' . md5(md5($message) . '-' . $smileys . (empty($disabled) ? '' : implode(',', array_keys($disabled))) . json_encode($context['browser']) . $txt['lang_locale'] . $user_info['time_offset'] . $user_info['time_format']); |
1706 | 1784 | |
1707 | - if (($temp = cache_get_data($cache_key, 240)) != null) |
|
1708 | - return $temp; |
|
1785 | + if (($temp = cache_get_data($cache_key, 240)) != null) { |
|
1786 | + return $temp; |
|
1787 | + } |
|
1709 | 1788 | |
1710 | 1789 | $cache_t = microtime(); |
1711 | 1790 | } |
@@ -1737,8 +1816,9 @@ discard block |
||
1737 | 1816 | $disabled['flash'] = true; |
1738 | 1817 | |
1739 | 1818 | // @todo Change maybe? |
1740 | - if (!isset($_GET['images'])) |
|
1741 | - $disabled['img'] = true; |
|
1819 | + if (!isset($_GET['images'])) { |
|
1820 | + $disabled['img'] = true; |
|
1821 | + } |
|
1742 | 1822 | |
1743 | 1823 | // @todo Interface/setting to add more? |
1744 | 1824 | } |
@@ -1762,8 +1842,9 @@ discard block |
||
1762 | 1842 | $pos = isset($matches[0][1]) ? $matches[0][1] : false; |
1763 | 1843 | |
1764 | 1844 | // Failsafe. |
1765 | - if ($pos === false || $last_pos > $pos) |
|
1766 | - $pos = strlen($message) + 1; |
|
1845 | + if ($pos === false || $last_pos > $pos) { |
|
1846 | + $pos = strlen($message) + 1; |
|
1847 | + } |
|
1767 | 1848 | |
1768 | 1849 | // Can't have a one letter smiley, URL, or email! (sorry.) |
1769 | 1850 | if ($last_pos < $pos - 1) |
@@ -1782,8 +1863,9 @@ discard block |
||
1782 | 1863 | |
1783 | 1864 | // <br> should be empty. |
1784 | 1865 | $empty_tags = array('br', 'hr'); |
1785 | - foreach ($empty_tags as $tag) |
|
1786 | - $data = str_replace(array('<' . $tag . '>', '<' . $tag . '/>', '<' . $tag . ' />'), '[' . $tag . ' /]', $data); |
|
1866 | + foreach ($empty_tags as $tag) { |
|
1867 | + $data = str_replace(array('<' . $tag . '>', '<' . $tag . '/>', '<' . $tag . ' />'), '[' . $tag . ' /]', $data); |
|
1868 | + } |
|
1787 | 1869 | |
1788 | 1870 | // b, u, i, s, pre... basic tags. |
1789 | 1871 | $closable_tags = array('b', 'u', 'i', 's', 'em', 'ins', 'del', 'pre', 'blockquote'); |
@@ -1792,8 +1874,9 @@ discard block |
||
1792 | 1874 | $diff = substr_count($data, '<' . $tag . '>') - substr_count($data, '</' . $tag . '>'); |
1793 | 1875 | $data = strtr($data, array('<' . $tag . '>' => '<' . $tag . '>', '</' . $tag . '>' => '</' . $tag . '>')); |
1794 | 1876 | |
1795 | - if ($diff > 0) |
|
1796 | - $data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1); |
|
1877 | + if ($diff > 0) { |
|
1878 | + $data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1); |
|
1879 | + } |
|
1797 | 1880 | } |
1798 | 1881 | |
1799 | 1882 | // Do <img ...> - with security... action= -> action-. |
@@ -1806,8 +1889,9 @@ discard block |
||
1806 | 1889 | $alt = empty($matches[3][$match]) ? '' : ' alt=' . preg_replace('~^"|"$~', '', $matches[3][$match]); |
1807 | 1890 | |
1808 | 1891 | // Remove action= from the URL - no funny business, now. |
1809 | - if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) |
|
1810 | - $imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag); |
|
1892 | + if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) { |
|
1893 | + $imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag); |
|
1894 | + } |
|
1811 | 1895 | |
1812 | 1896 | // Check if the image is larger than allowed. |
1813 | 1897 | if (!empty($modSettings['max_image_width']) && !empty($modSettings['max_image_height'])) |
@@ -1828,9 +1912,9 @@ discard block |
||
1828 | 1912 | |
1829 | 1913 | // Set the new image tag. |
1830 | 1914 | $replaces[$matches[0][$match]] = '[img width=' . $width . ' height=' . $height . $alt . ']' . $imgtag . '[/img]'; |
1915 | + } else { |
|
1916 | + $replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]'; |
|
1831 | 1917 | } |
1832 | - else |
|
1833 | - $replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]'; |
|
1834 | 1918 | } |
1835 | 1919 | |
1836 | 1920 | $data = strtr($data, $replaces); |
@@ -1843,16 +1927,18 @@ discard block |
||
1843 | 1927 | $no_autolink_area = false; |
1844 | 1928 | if (!empty($open_tags)) |
1845 | 1929 | { |
1846 | - foreach ($open_tags as $open_tag) |
|
1847 | - if (in_array($open_tag['tag'], $no_autolink_tags)) |
|
1930 | + foreach ($open_tags as $open_tag) { |
|
1931 | + if (in_array($open_tag['tag'], $no_autolink_tags)) |
|
1848 | 1932 | $no_autolink_area = true; |
1933 | + } |
|
1849 | 1934 | } |
1850 | 1935 | |
1851 | 1936 | // Don't go backwards. |
1852 | 1937 | // @todo Don't think is the real solution.... |
1853 | 1938 | $lastAutoPos = isset($lastAutoPos) ? $lastAutoPos : 0; |
1854 | - if ($pos < $lastAutoPos) |
|
1855 | - $no_autolink_area = true; |
|
1939 | + if ($pos < $lastAutoPos) { |
|
1940 | + $no_autolink_area = true; |
|
1941 | + } |
|
1856 | 1942 | $lastAutoPos = $pos; |
1857 | 1943 | |
1858 | 1944 | if (!$no_autolink_area) |
@@ -1961,17 +2047,19 @@ discard block |
||
1961 | 2047 | if ($scheme == 'mailto') |
1962 | 2048 | { |
1963 | 2049 | $email_address = str_replace('mailto:', '', $url); |
1964 | - if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) |
|
1965 | - return '[email=' . $email_address . ']' . $url . '[/email]'; |
|
1966 | - else |
|
1967 | - return $url; |
|
2050 | + if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) { |
|
2051 | + return '[email=' . $email_address . ']' . $url . '[/email]'; |
|
2052 | + } else { |
|
2053 | + return $url; |
|
2054 | + } |
|
1968 | 2055 | } |
1969 | 2056 | |
1970 | 2057 | // Are we linking a schemeless URL or naked domain name (e.g. "example.com")? |
1971 | - if (empty($scheme)) |
|
1972 | - $fullUrl = '//' . ltrim($url, ':/'); |
|
1973 | - else |
|
1974 | - $fullUrl = $url; |
|
2058 | + if (empty($scheme)) { |
|
2059 | + $fullUrl = '//' . ltrim($url, ':/'); |
|
2060 | + } else { |
|
2061 | + $fullUrl = $url; |
|
2062 | + } |
|
1975 | 2063 | |
1976 | 2064 | return '[url="' . str_replace(array('[', ']'), array('[', ']'), $fullUrl) . '"]' . $url . '[/url]'; |
1977 | 2065 | }, $data); |
@@ -2020,16 +2108,18 @@ discard block |
||
2020 | 2108 | } |
2021 | 2109 | |
2022 | 2110 | // Are we there yet? Are we there yet? |
2023 | - if ($pos >= strlen($message) - 1) |
|
2024 | - break; |
|
2111 | + if ($pos >= strlen($message) - 1) { |
|
2112 | + break; |
|
2113 | + } |
|
2025 | 2114 | |
2026 | 2115 | $tags = strtolower($message[$pos + 1]); |
2027 | 2116 | |
2028 | 2117 | if ($tags == '/' && !empty($open_tags)) |
2029 | 2118 | { |
2030 | 2119 | $pos2 = strpos($message, ']', $pos + 1); |
2031 | - if ($pos2 == $pos + 2) |
|
2032 | - continue; |
|
2120 | + if ($pos2 == $pos + 2) { |
|
2121 | + continue; |
|
2122 | + } |
|
2033 | 2123 | |
2034 | 2124 | $look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2)); |
2035 | 2125 | |
@@ -2039,8 +2129,9 @@ discard block |
||
2039 | 2129 | do |
2040 | 2130 | { |
2041 | 2131 | $tag = array_pop($open_tags); |
2042 | - if (!$tag) |
|
2043 | - break; |
|
2132 | + if (!$tag) { |
|
2133 | + break; |
|
2134 | + } |
|
2044 | 2135 | |
2045 | 2136 | if (!empty($tag['block_level'])) |
2046 | 2137 | { |
@@ -2054,10 +2145,11 @@ discard block |
||
2054 | 2145 | // The idea is, if we are LOOKING for a block level tag, we can close them on the way. |
2055 | 2146 | if (strlen($look_for) > 0 && isset($bbc_codes[$look_for[0]])) |
2056 | 2147 | { |
2057 | - foreach ($bbc_codes[$look_for[0]] as $temp) |
|
2058 | - if ($temp['tag'] == $look_for) |
|
2148 | + foreach ($bbc_codes[$look_for[0]] as $temp) { |
|
2149 | + if ($temp['tag'] == $look_for) |
|
2059 | 2150 | { |
2060 | 2151 | $block_level = !empty($temp['block_level']); |
2152 | + } |
|
2061 | 2153 | break; |
2062 | 2154 | } |
2063 | 2155 | } |
@@ -2079,15 +2171,15 @@ discard block |
||
2079 | 2171 | { |
2080 | 2172 | $open_tags = $to_close; |
2081 | 2173 | continue; |
2082 | - } |
|
2083 | - elseif (!empty($to_close) && $tag['tag'] != $look_for) |
|
2174 | + } elseif (!empty($to_close) && $tag['tag'] != $look_for) |
|
2084 | 2175 | { |
2085 | 2176 | if ($block_level === null && isset($look_for[0], $bbc_codes[$look_for[0]])) |
2086 | 2177 | { |
2087 | - foreach ($bbc_codes[$look_for[0]] as $temp) |
|
2088 | - if ($temp['tag'] == $look_for) |
|
2178 | + foreach ($bbc_codes[$look_for[0]] as $temp) { |
|
2179 | + if ($temp['tag'] == $look_for) |
|
2089 | 2180 | { |
2090 | 2181 | $block_level = !empty($temp['block_level']); |
2182 | + } |
|
2091 | 2183 | break; |
2092 | 2184 | } |
2093 | 2185 | } |
@@ -2095,8 +2187,9 @@ discard block |
||
2095 | 2187 | // We're not looking for a block level tag (or maybe even a tag that exists...) |
2096 | 2188 | if (!$block_level) |
2097 | 2189 | { |
2098 | - foreach ($to_close as $tag) |
|
2099 | - array_push($open_tags, $tag); |
|
2190 | + foreach ($to_close as $tag) { |
|
2191 | + array_push($open_tags, $tag); |
|
2192 | + } |
|
2100 | 2193 | continue; |
2101 | 2194 | } |
2102 | 2195 | } |
@@ -2108,10 +2201,12 @@ discard block |
||
2108 | 2201 | $pos2 = $pos - 1; |
2109 | 2202 | |
2110 | 2203 | // See the comment at the end of the big loop - just eating whitespace ;). |
2111 | - if (!empty($tag['block_level']) && substr($message, $pos, 4) == '<br>') |
|
2112 | - $message = substr($message, 0, $pos) . substr($message, $pos + 4); |
|
2113 | - if (!empty($tag['trim']) && $tag['trim'] != 'inside' && preg_match('~(<br>| |\s)*~', substr($message, $pos), $matches) != 0) |
|
2114 | - $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
2204 | + if (!empty($tag['block_level']) && substr($message, $pos, 4) == '<br>') { |
|
2205 | + $message = substr($message, 0, $pos) . substr($message, $pos + 4); |
|
2206 | + } |
|
2207 | + if (!empty($tag['trim']) && $tag['trim'] != 'inside' && preg_match('~(<br>| |\s)*~', substr($message, $pos), $matches) != 0) { |
|
2208 | + $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
2209 | + } |
|
2115 | 2210 | } |
2116 | 2211 | |
2117 | 2212 | if (!empty($to_close)) |
@@ -2124,8 +2219,9 @@ discard block |
||
2124 | 2219 | } |
2125 | 2220 | |
2126 | 2221 | // No tags for this character, so just keep going (fastest possible course.) |
2127 | - if (!isset($bbc_codes[$tags])) |
|
2128 | - continue; |
|
2222 | + if (!isset($bbc_codes[$tags])) { |
|
2223 | + continue; |
|
2224 | + } |
|
2129 | 2225 | |
2130 | 2226 | $inside = empty($open_tags) ? null : $open_tags[count($open_tags) - 1]; |
2131 | 2227 | $tag = null; |
@@ -2134,44 +2230,52 @@ discard block |
||
2134 | 2230 | $pt_strlen = strlen($possible['tag']); |
2135 | 2231 | |
2136 | 2232 | // Not a match? |
2137 | - if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) |
|
2138 | - continue; |
|
2233 | + if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) { |
|
2234 | + continue; |
|
2235 | + } |
|
2139 | 2236 | |
2140 | 2237 | $next_c = $message[$pos + 1 + $pt_strlen]; |
2141 | 2238 | |
2142 | 2239 | // A test validation? |
2143 | - if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) |
|
2144 | - continue; |
|
2240 | + if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) { |
|
2241 | + continue; |
|
2242 | + } |
|
2145 | 2243 | // Do we want parameters? |
2146 | 2244 | elseif (!empty($possible['parameters'])) |
2147 | 2245 | { |
2148 | - if ($next_c != ' ') |
|
2149 | - continue; |
|
2150 | - } |
|
2151 | - elseif (isset($possible['type'])) |
|
2246 | + if ($next_c != ' ') { |
|
2247 | + continue; |
|
2248 | + } |
|
2249 | + } elseif (isset($possible['type'])) |
|
2152 | 2250 | { |
2153 | 2251 | // Do we need an equal sign? |
2154 | - if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') |
|
2155 | - continue; |
|
2252 | + if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') { |
|
2253 | + continue; |
|
2254 | + } |
|
2156 | 2255 | // Maybe we just want a /... |
2157 | - if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') |
|
2158 | - continue; |
|
2256 | + if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') { |
|
2257 | + continue; |
|
2258 | + } |
|
2159 | 2259 | // An immediate ]? |
2160 | - if ($possible['type'] == 'unparsed_content' && $next_c != ']') |
|
2161 | - continue; |
|
2260 | + if ($possible['type'] == 'unparsed_content' && $next_c != ']') { |
|
2261 | + continue; |
|
2262 | + } |
|
2162 | 2263 | } |
2163 | 2264 | // No type means 'parsed_content', which demands an immediate ] without parameters! |
2164 | - elseif ($next_c != ']') |
|
2165 | - continue; |
|
2265 | + elseif ($next_c != ']') { |
|
2266 | + continue; |
|
2267 | + } |
|
2166 | 2268 | |
2167 | 2269 | // Check allowed tree? |
2168 | - if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) |
|
2169 | - continue; |
|
2170 | - elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) |
|
2171 | - continue; |
|
2270 | + if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) { |
|
2271 | + continue; |
|
2272 | + } elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) { |
|
2273 | + continue; |
|
2274 | + } |
|
2172 | 2275 | // If this is in the list of disallowed child tags, don't parse it. |
2173 | - elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) |
|
2174 | - continue; |
|
2276 | + elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) { |
|
2277 | + continue; |
|
2278 | + } |
|
2175 | 2279 | |
2176 | 2280 | $pos1 = $pos + 1 + $pt_strlen + 1; |
2177 | 2281 | |
@@ -2183,8 +2287,9 @@ discard block |
||
2183 | 2287 | foreach ($open_tags as $open_quote) |
2184 | 2288 | { |
2185 | 2289 | // Every parent quote this quote has flips the styling |
2186 | - if ($open_quote['tag'] == 'quote') |
|
2187 | - $quote_alt = !$quote_alt; |
|
2290 | + if ($open_quote['tag'] == 'quote') { |
|
2291 | + $quote_alt = !$quote_alt; |
|
2292 | + } |
|
2188 | 2293 | } |
2189 | 2294 | // Add a class to the quote to style alternating blockquotes |
2190 | 2295 | $possible['before'] = strtr($possible['before'], array('<blockquote>' => '<blockquote class="bbc_' . ($quote_alt ? 'alternate' : 'standard') . '_quote">')); |
@@ -2195,8 +2300,9 @@ discard block |
||
2195 | 2300 | { |
2196 | 2301 | // Build a regular expression for each parameter for the current tag. |
2197 | 2302 | $preg = array(); |
2198 | - foreach ($possible['parameters'] as $p => $info) |
|
2199 | - $preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '"') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '"') . '\s*)' . (empty($info['optional']) ? '' : '?'); |
|
2303 | + foreach ($possible['parameters'] as $p => $info) { |
|
2304 | + $preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '"') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '"') . '\s*)' . (empty($info['optional']) ? '' : '?'); |
|
2305 | + } |
|
2200 | 2306 | |
2201 | 2307 | // Extract the string that potentially holds our parameters. |
2202 | 2308 | $blob = preg_split('~\[/?(?:' . $alltags_regex . ')~i', substr($message, $pos)); |
@@ -2216,24 +2322,27 @@ discard block |
||
2216 | 2322 | |
2217 | 2323 | $match = preg_match('~^' . implode('', $preg) . '$~i', implode(' ', $given_params), $matches) !== 0; |
2218 | 2324 | |
2219 | - if ($match) |
|
2220 | - $blob_counter = count($blobs) + 1; |
|
2325 | + if ($match) { |
|
2326 | + $blob_counter = count($blobs) + 1; |
|
2327 | + } |
|
2221 | 2328 | } |
2222 | 2329 | |
2223 | 2330 | // Didn't match our parameter list, try the next possible. |
2224 | - if (!$match) |
|
2225 | - continue; |
|
2331 | + if (!$match) { |
|
2332 | + continue; |
|
2333 | + } |
|
2226 | 2334 | |
2227 | 2335 | $params = array(); |
2228 | 2336 | for ($i = 1, $n = count($matches); $i < $n; $i += 2) |
2229 | 2337 | { |
2230 | 2338 | $key = strtok(ltrim($matches[$i]), '='); |
2231 | - if (isset($possible['parameters'][$key]['value'])) |
|
2232 | - $params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1])); |
|
2233 | - elseif (isset($possible['parameters'][$key]['validate'])) |
|
2234 | - $params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]); |
|
2235 | - else |
|
2236 | - $params['{' . $key . '}'] = $matches[$i + 1]; |
|
2339 | + if (isset($possible['parameters'][$key]['value'])) { |
|
2340 | + $params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1])); |
|
2341 | + } elseif (isset($possible['parameters'][$key]['validate'])) { |
|
2342 | + $params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]); |
|
2343 | + } else { |
|
2344 | + $params['{' . $key . '}'] = $matches[$i + 1]; |
|
2345 | + } |
|
2237 | 2346 | |
2238 | 2347 | // Just to make sure: replace any $ or { so they can't interpolate wrongly. |
2239 | 2348 | $params['{' . $key . '}'] = strtr($params['{' . $key . '}'], array('$' => '$', '{' => '{')); |
@@ -2241,23 +2350,26 @@ discard block |
||
2241 | 2350 | |
2242 | 2351 | foreach ($possible['parameters'] as $p => $info) |
2243 | 2352 | { |
2244 | - if (!isset($params['{' . $p . '}'])) |
|
2245 | - $params['{' . $p . '}'] = ''; |
|
2353 | + if (!isset($params['{' . $p . '}'])) { |
|
2354 | + $params['{' . $p . '}'] = ''; |
|
2355 | + } |
|
2246 | 2356 | } |
2247 | 2357 | |
2248 | 2358 | $tag = $possible; |
2249 | 2359 | |
2250 | 2360 | // Put the parameters into the string. |
2251 | - if (isset($tag['before'])) |
|
2252 | - $tag['before'] = strtr($tag['before'], $params); |
|
2253 | - if (isset($tag['after'])) |
|
2254 | - $tag['after'] = strtr($tag['after'], $params); |
|
2255 | - if (isset($tag['content'])) |
|
2256 | - $tag['content'] = strtr($tag['content'], $params); |
|
2361 | + if (isset($tag['before'])) { |
|
2362 | + $tag['before'] = strtr($tag['before'], $params); |
|
2363 | + } |
|
2364 | + if (isset($tag['after'])) { |
|
2365 | + $tag['after'] = strtr($tag['after'], $params); |
|
2366 | + } |
|
2367 | + if (isset($tag['content'])) { |
|
2368 | + $tag['content'] = strtr($tag['content'], $params); |
|
2369 | + } |
|
2257 | 2370 | |
2258 | 2371 | $pos1 += strlen($given_param_string); |
2259 | - } |
|
2260 | - else |
|
2372 | + } else |
|
2261 | 2373 | { |
2262 | 2374 | $tag = $possible; |
2263 | 2375 | $params = array(); |
@@ -2268,8 +2380,9 @@ discard block |
||
2268 | 2380 | // Item codes are complicated buggers... they are implicit [li]s and can make [list]s! |
2269 | 2381 | if ($smileys !== false && $tag === null && isset($itemcodes[$message[$pos + 1]]) && $message[$pos + 2] == ']' && !isset($disabled['list']) && !isset($disabled['li'])) |
2270 | 2382 | { |
2271 | - if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) |
|
2272 | - continue; |
|
2383 | + if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) { |
|
2384 | + continue; |
|
2385 | + } |
|
2273 | 2386 | |
2274 | 2387 | $tag = $itemcodes[$message[$pos + 1]]; |
2275 | 2388 | |
@@ -2290,9 +2403,9 @@ discard block |
||
2290 | 2403 | { |
2291 | 2404 | array_pop($open_tags); |
2292 | 2405 | $code = '</li>'; |
2406 | + } else { |
|
2407 | + $code = ''; |
|
2293 | 2408 | } |
2294 | - else |
|
2295 | - $code = ''; |
|
2296 | 2409 | |
2297 | 2410 | // Now we open a new tag. |
2298 | 2411 | $open_tags[] = array( |
@@ -2339,12 +2452,14 @@ discard block |
||
2339 | 2452 | } |
2340 | 2453 | |
2341 | 2454 | // No tag? Keep looking, then. Silly people using brackets without actual tags. |
2342 | - if ($tag === null) |
|
2343 | - continue; |
|
2455 | + if ($tag === null) { |
|
2456 | + continue; |
|
2457 | + } |
|
2344 | 2458 | |
2345 | 2459 | // Propagate the list to the child (so wrapping the disallowed tag won't work either.) |
2346 | - if (isset($inside['disallow_children'])) |
|
2347 | - $tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children']; |
|
2460 | + if (isset($inside['disallow_children'])) { |
|
2461 | + $tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children']; |
|
2462 | + } |
|
2348 | 2463 | |
2349 | 2464 | // Is this tag disabled? |
2350 | 2465 | if (isset($disabled[$tag['tag']])) |
@@ -2354,14 +2469,13 @@ discard block |
||
2354 | 2469 | $tag['before'] = !empty($tag['block_level']) ? '<div>' : ''; |
2355 | 2470 | $tag['after'] = !empty($tag['block_level']) ? '</div>' : ''; |
2356 | 2471 | $tag['content'] = isset($tag['type']) && $tag['type'] == 'closed' ? '' : (!empty($tag['block_level']) ? '<div>$1</div>' : '$1'); |
2357 | - } |
|
2358 | - elseif (isset($tag['disabled_before']) || isset($tag['disabled_after'])) |
|
2472 | + } elseif (isset($tag['disabled_before']) || isset($tag['disabled_after'])) |
|
2359 | 2473 | { |
2360 | 2474 | $tag['before'] = isset($tag['disabled_before']) ? $tag['disabled_before'] : (!empty($tag['block_level']) ? '<div>' : ''); |
2361 | 2475 | $tag['after'] = isset($tag['disabled_after']) ? $tag['disabled_after'] : (!empty($tag['block_level']) ? '</div>' : ''); |
2476 | + } else { |
|
2477 | + $tag['content'] = $tag['disabled_content']; |
|
2362 | 2478 | } |
2363 | - else |
|
2364 | - $tag['content'] = $tag['disabled_content']; |
|
2365 | 2479 | } |
2366 | 2480 | |
2367 | 2481 | // we use this a lot |
@@ -2371,8 +2485,9 @@ discard block |
||
2371 | 2485 | if (!empty($tag['block_level']) && $tag['tag'] != 'html' && empty($inside['block_level'])) |
2372 | 2486 | { |
2373 | 2487 | $n = count($open_tags) - 1; |
2374 | - while (empty($open_tags[$n]['block_level']) && $n >= 0) |
|
2375 | - $n--; |
|
2488 | + while (empty($open_tags[$n]['block_level']) && $n >= 0) { |
|
2489 | + $n--; |
|
2490 | + } |
|
2376 | 2491 | |
2377 | 2492 | // Close all the non block level tags so this tag isn't surrounded by them. |
2378 | 2493 | for ($i = count($open_tags) - 1; $i > $n; $i--) |
@@ -2383,10 +2498,12 @@ discard block |
||
2383 | 2498 | $pos1 += $ot_strlen + 2; |
2384 | 2499 | |
2385 | 2500 | // Trim or eat trailing stuff... see comment at the end of the big loop. |
2386 | - if (!empty($open_tags[$i]['block_level']) && substr($message, $pos, 4) == '<br>') |
|
2387 | - $message = substr($message, 0, $pos) . substr($message, $pos + 4); |
|
2388 | - if (!empty($open_tags[$i]['trim']) && $tag['trim'] != 'inside' && preg_match('~(<br>| |\s)*~', substr($message, $pos), $matches) != 0) |
|
2389 | - $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
2501 | + if (!empty($open_tags[$i]['block_level']) && substr($message, $pos, 4) == '<br>') { |
|
2502 | + $message = substr($message, 0, $pos) . substr($message, $pos + 4); |
|
2503 | + } |
|
2504 | + if (!empty($open_tags[$i]['trim']) && $tag['trim'] != 'inside' && preg_match('~(<br>| |\s)*~', substr($message, $pos), $matches) != 0) { |
|
2505 | + $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
2506 | + } |
|
2390 | 2507 | |
2391 | 2508 | array_pop($open_tags); |
2392 | 2509 | } |
@@ -2404,16 +2521,19 @@ discard block |
||
2404 | 2521 | elseif ($tag['type'] == 'unparsed_content') |
2405 | 2522 | { |
2406 | 2523 | $pos2 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos1); |
2407 | - if ($pos2 === false) |
|
2408 | - continue; |
|
2524 | + if ($pos2 === false) { |
|
2525 | + continue; |
|
2526 | + } |
|
2409 | 2527 | |
2410 | 2528 | $data = substr($message, $pos1, $pos2 - $pos1); |
2411 | 2529 | |
2412 | - if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') |
|
2413 | - $data = substr($data, 4); |
|
2530 | + if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') { |
|
2531 | + $data = substr($data, 4); |
|
2532 | + } |
|
2414 | 2533 | |
2415 | - if (isset($tag['validate'])) |
|
2416 | - $tag['validate']($tag, $data, $disabled, $params); |
|
2534 | + if (isset($tag['validate'])) { |
|
2535 | + $tag['validate']($tag, $data, $disabled, $params); |
|
2536 | + } |
|
2417 | 2537 | |
2418 | 2538 | $code = strtr($tag['content'], array('$1' => $data)); |
2419 | 2539 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 3 + $tag_strlen); |
@@ -2429,34 +2549,40 @@ discard block |
||
2429 | 2549 | if (isset($tag['quoted'])) |
2430 | 2550 | { |
2431 | 2551 | $quoted = substr($message, $pos1, 6) == '"'; |
2432 | - if ($tag['quoted'] != 'optional' && !$quoted) |
|
2433 | - continue; |
|
2552 | + if ($tag['quoted'] != 'optional' && !$quoted) { |
|
2553 | + continue; |
|
2554 | + } |
|
2434 | 2555 | |
2435 | - if ($quoted) |
|
2436 | - $pos1 += 6; |
|
2556 | + if ($quoted) { |
|
2557 | + $pos1 += 6; |
|
2558 | + } |
|
2559 | + } else { |
|
2560 | + $quoted = false; |
|
2437 | 2561 | } |
2438 | - else |
|
2439 | - $quoted = false; |
|
2440 | 2562 | |
2441 | 2563 | $pos2 = strpos($message, $quoted == false ? ']' : '"]', $pos1); |
2442 | - if ($pos2 === false) |
|
2443 | - continue; |
|
2564 | + if ($pos2 === false) { |
|
2565 | + continue; |
|
2566 | + } |
|
2444 | 2567 | |
2445 | 2568 | $pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2); |
2446 | - if ($pos3 === false) |
|
2447 | - continue; |
|
2569 | + if ($pos3 === false) { |
|
2570 | + continue; |
|
2571 | + } |
|
2448 | 2572 | |
2449 | 2573 | $data = array( |
2450 | 2574 | substr($message, $pos2 + ($quoted == false ? 1 : 7), $pos3 - ($pos2 + ($quoted == false ? 1 : 7))), |
2451 | 2575 | substr($message, $pos1, $pos2 - $pos1) |
2452 | 2576 | ); |
2453 | 2577 | |
2454 | - if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') |
|
2455 | - $data[0] = substr($data[0], 4); |
|
2578 | + if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') { |
|
2579 | + $data[0] = substr($data[0], 4); |
|
2580 | + } |
|
2456 | 2581 | |
2457 | 2582 | // Validation for my parking, please! |
2458 | - if (isset($tag['validate'])) |
|
2459 | - $tag['validate']($tag, $data, $disabled, $params); |
|
2583 | + if (isset($tag['validate'])) { |
|
2584 | + $tag['validate']($tag, $data, $disabled, $params); |
|
2585 | + } |
|
2460 | 2586 | |
2461 | 2587 | $code = strtr($tag['content'], array('$1' => $data[0], '$2' => $data[1])); |
2462 | 2588 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen); |
@@ -2473,23 +2599,27 @@ discard block |
||
2473 | 2599 | elseif ($tag['type'] == 'unparsed_commas_content') |
2474 | 2600 | { |
2475 | 2601 | $pos2 = strpos($message, ']', $pos1); |
2476 | - if ($pos2 === false) |
|
2477 | - continue; |
|
2602 | + if ($pos2 === false) { |
|
2603 | + continue; |
|
2604 | + } |
|
2478 | 2605 | |
2479 | 2606 | $pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2); |
2480 | - if ($pos3 === false) |
|
2481 | - continue; |
|
2607 | + if ($pos3 === false) { |
|
2608 | + continue; |
|
2609 | + } |
|
2482 | 2610 | |
2483 | 2611 | // We want $1 to be the content, and the rest to be csv. |
2484 | 2612 | $data = explode(',', ',' . substr($message, $pos1, $pos2 - $pos1)); |
2485 | 2613 | $data[0] = substr($message, $pos2 + 1, $pos3 - $pos2 - 1); |
2486 | 2614 | |
2487 | - if (isset($tag['validate'])) |
|
2488 | - $tag['validate']($tag, $data, $disabled, $params); |
|
2615 | + if (isset($tag['validate'])) { |
|
2616 | + $tag['validate']($tag, $data, $disabled, $params); |
|
2617 | + } |
|
2489 | 2618 | |
2490 | 2619 | $code = $tag['content']; |
2491 | - foreach ($data as $k => $d) |
|
2492 | - $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
2620 | + foreach ($data as $k => $d) { |
|
2621 | + $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
2622 | + } |
|
2493 | 2623 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen); |
2494 | 2624 | $pos += strlen($code) - 1 + 2; |
2495 | 2625 | } |
@@ -2497,24 +2627,28 @@ discard block |
||
2497 | 2627 | elseif ($tag['type'] == 'unparsed_commas') |
2498 | 2628 | { |
2499 | 2629 | $pos2 = strpos($message, ']', $pos1); |
2500 | - if ($pos2 === false) |
|
2501 | - continue; |
|
2630 | + if ($pos2 === false) { |
|
2631 | + continue; |
|
2632 | + } |
|
2502 | 2633 | |
2503 | 2634 | $data = explode(',', substr($message, $pos1, $pos2 - $pos1)); |
2504 | 2635 | |
2505 | - if (isset($tag['validate'])) |
|
2506 | - $tag['validate']($tag, $data, $disabled, $params); |
|
2636 | + if (isset($tag['validate'])) { |
|
2637 | + $tag['validate']($tag, $data, $disabled, $params); |
|
2638 | + } |
|
2507 | 2639 | |
2508 | 2640 | // Fix after, for disabled code mainly. |
2509 | - foreach ($data as $k => $d) |
|
2510 | - $tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d))); |
|
2641 | + foreach ($data as $k => $d) { |
|
2642 | + $tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d))); |
|
2643 | + } |
|
2511 | 2644 | |
2512 | 2645 | $open_tags[] = $tag; |
2513 | 2646 | |
2514 | 2647 | // Replace them out, $1, $2, $3, $4, etc. |
2515 | 2648 | $code = $tag['before']; |
2516 | - foreach ($data as $k => $d) |
|
2517 | - $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
2649 | + foreach ($data as $k => $d) { |
|
2650 | + $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
2651 | + } |
|
2518 | 2652 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 1); |
2519 | 2653 | $pos += strlen($code) - 1 + 2; |
2520 | 2654 | } |
@@ -2525,28 +2659,33 @@ discard block |
||
2525 | 2659 | if (isset($tag['quoted'])) |
2526 | 2660 | { |
2527 | 2661 | $quoted = substr($message, $pos1, 6) == '"'; |
2528 | - if ($tag['quoted'] != 'optional' && !$quoted) |
|
2529 | - continue; |
|
2662 | + if ($tag['quoted'] != 'optional' && !$quoted) { |
|
2663 | + continue; |
|
2664 | + } |
|
2530 | 2665 | |
2531 | - if ($quoted) |
|
2532 | - $pos1 += 6; |
|
2666 | + if ($quoted) { |
|
2667 | + $pos1 += 6; |
|
2668 | + } |
|
2669 | + } else { |
|
2670 | + $quoted = false; |
|
2533 | 2671 | } |
2534 | - else |
|
2535 | - $quoted = false; |
|
2536 | 2672 | |
2537 | 2673 | $pos2 = strpos($message, $quoted == false ? ']' : '"]', $pos1); |
2538 | - if ($pos2 === false) |
|
2539 | - continue; |
|
2674 | + if ($pos2 === false) { |
|
2675 | + continue; |
|
2676 | + } |
|
2540 | 2677 | |
2541 | 2678 | $data = substr($message, $pos1, $pos2 - $pos1); |
2542 | 2679 | |
2543 | 2680 | // Validation for my parking, please! |
2544 | - if (isset($tag['validate'])) |
|
2545 | - $tag['validate']($tag, $data, $disabled, $params); |
|
2681 | + if (isset($tag['validate'])) { |
|
2682 | + $tag['validate']($tag, $data, $disabled, $params); |
|
2683 | + } |
|
2546 | 2684 | |
2547 | 2685 | // For parsed content, we must recurse to avoid security problems. |
2548 | - if ($tag['type'] != 'unparsed_equals') |
|
2549 | - $data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array()); |
|
2686 | + if ($tag['type'] != 'unparsed_equals') { |
|
2687 | + $data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array()); |
|
2688 | + } |
|
2550 | 2689 | |
2551 | 2690 | $tag['after'] = strtr($tag['after'], array('$1' => $data)); |
2552 | 2691 | |
@@ -2558,34 +2697,40 @@ discard block |
||
2558 | 2697 | } |
2559 | 2698 | |
2560 | 2699 | // If this is block level, eat any breaks after it. |
2561 | - if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') |
|
2562 | - $message = substr($message, 0, $pos + 1) . substr($message, $pos + 5); |
|
2700 | + if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') { |
|
2701 | + $message = substr($message, 0, $pos + 1) . substr($message, $pos + 5); |
|
2702 | + } |
|
2563 | 2703 | |
2564 | 2704 | // Are we trimming outside this tag? |
2565 | - if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>| |\s)*~', substr($message, $pos + 1), $matches) != 0) |
|
2566 | - $message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0])); |
|
2705 | + if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>| |\s)*~', substr($message, $pos + 1), $matches) != 0) { |
|
2706 | + $message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0])); |
|
2707 | + } |
|
2567 | 2708 | } |
2568 | 2709 | |
2569 | 2710 | // Close any remaining tags. |
2570 | - while ($tag = array_pop($open_tags)) |
|
2571 | - $message .= "\n" . $tag['after'] . "\n"; |
|
2711 | + while ($tag = array_pop($open_tags)) { |
|
2712 | + $message .= "\n" . $tag['after'] . "\n"; |
|
2713 | + } |
|
2572 | 2714 | |
2573 | 2715 | // Parse the smileys within the parts where it can be done safely. |
2574 | 2716 | if ($smileys === true) |
2575 | 2717 | { |
2576 | 2718 | $message_parts = explode("\n", $message); |
2577 | - for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) |
|
2578 | - parsesmileys($message_parts[$i]); |
|
2719 | + for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) { |
|
2720 | + parsesmileys($message_parts[$i]); |
|
2721 | + } |
|
2579 | 2722 | |
2580 | 2723 | $message = implode('', $message_parts); |
2581 | 2724 | } |
2582 | 2725 | |
2583 | 2726 | // No smileys, just get rid of the markers. |
2584 | - else |
|
2585 | - $message = strtr($message, array("\n" => '')); |
|
2727 | + else { |
|
2728 | + $message = strtr($message, array("\n" => '')); |
|
2729 | + } |
|
2586 | 2730 | |
2587 | - if ($message !== '' && $message[0] === ' ') |
|
2588 | - $message = ' ' . substr($message, 1); |
|
2731 | + if ($message !== '' && $message[0] === ' ') { |
|
2732 | + $message = ' ' . substr($message, 1); |
|
2733 | + } |
|
2589 | 2734 | |
2590 | 2735 | // Cleanup whitespace. |
2591 | 2736 | $message = strtr($message, array(' ' => ' ', "\r" => '', "\n" => '<br>', '<br> ' => '<br> ', ' ' => "\n")); |
@@ -2594,15 +2739,16 @@ discard block |
||
2594 | 2739 | call_integration_hook('integrate_post_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags)); |
2595 | 2740 | |
2596 | 2741 | // Cache the output if it took some time... |
2597 | - if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) |
|
2598 | - cache_put_data($cache_key, $message, 240); |
|
2742 | + if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) { |
|
2743 | + cache_put_data($cache_key, $message, 240); |
|
2744 | + } |
|
2599 | 2745 | |
2600 | 2746 | // If this was a force parse revert if needed. |
2601 | 2747 | if (!empty($parse_tags)) |
2602 | 2748 | { |
2603 | - if (empty($temp_bbc)) |
|
2604 | - $bbc_codes = array(); |
|
2605 | - else |
|
2749 | + if (empty($temp_bbc)) { |
|
2750 | + $bbc_codes = array(); |
|
2751 | + } else |
|
2606 | 2752 | { |
2607 | 2753 | $bbc_codes = $temp_bbc; |
2608 | 2754 | unset($temp_bbc); |
@@ -2629,8 +2775,9 @@ discard block |
||
2629 | 2775 | static $smileyPregSearch = null, $smileyPregReplacements = array(); |
2630 | 2776 | |
2631 | 2777 | // No smiley set at all?! |
2632 | - if ($user_info['smiley_set'] == 'none' || trim($message) == '') |
|
2633 | - return; |
|
2778 | + if ($user_info['smiley_set'] == 'none' || trim($message) == '') { |
|
2779 | + return; |
|
2780 | + } |
|
2634 | 2781 | |
2635 | 2782 | // If smileyPregSearch hasn't been set, do it now. |
2636 | 2783 | if (empty($smileyPregSearch)) |
@@ -2641,8 +2788,7 @@ discard block |
||
2641 | 2788 | $smileysfrom = array('>:D', ':D', '::)', '>:(', ':))', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', '0:)'); |
2642 | 2789 | $smileysto = array('evil.gif', 'cheesy.gif', 'rolleyes.gif', 'angry.gif', 'laugh.gif', 'smiley.gif', 'wink.gif', 'grin.gif', 'sad.gif', 'shocked.gif', 'cool.gif', 'tongue.gif', 'huh.gif', 'embarrassed.gif', 'lipsrsealed.gif', 'kiss.gif', 'cry.gif', 'undecided.gif', 'azn.gif', 'afro.gif', 'police.gif', 'angel.gif'); |
2643 | 2790 | $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'], '', '', '', ''); |
2644 | - } |
|
2645 | - else |
|
2791 | + } else |
|
2646 | 2792 | { |
2647 | 2793 | // Load the smileys in reverse order by length so they don't get parsed wrong. |
2648 | 2794 | if (($temp = cache_get_data('parsing_smileys', 480)) == null) |
@@ -2666,9 +2812,9 @@ discard block |
||
2666 | 2812 | $smcFunc['db_free_result']($result); |
2667 | 2813 | |
2668 | 2814 | cache_put_data('parsing_smileys', array($smileysfrom, $smileysto, $smileysdescs), 480); |
2815 | + } else { |
|
2816 | + list ($smileysfrom, $smileysto, $smileysdescs) = $temp; |
|
2669 | 2817 | } |
2670 | - else |
|
2671 | - list ($smileysfrom, $smileysto, $smileysdescs) = $temp; |
|
2672 | 2818 | } |
2673 | 2819 | |
2674 | 2820 | // The non-breaking-space is a complex thing... |
@@ -2745,35 +2891,41 @@ discard block |
||
2745 | 2891 | global $scripturl, $context, $modSettings, $db_show_debug, $db_cache; |
2746 | 2892 | |
2747 | 2893 | // In case we have mail to send, better do that - as obExit doesn't always quite make it... |
2748 | - if (!empty($context['flush_mail'])) |
|
2749 | - // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
2894 | + if (!empty($context['flush_mail'])) { |
|
2895 | + // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
2750 | 2896 | AddMailQueue(true); |
2897 | + } |
|
2751 | 2898 | |
2752 | 2899 | $add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && substr($setLocation, 0, 6) != 'about:'; |
2753 | 2900 | |
2754 | - if ($add) |
|
2755 | - $setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : ''); |
|
2901 | + if ($add) { |
|
2902 | + $setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : ''); |
|
2903 | + } |
|
2756 | 2904 | |
2757 | 2905 | // Put the session ID in. |
2758 | - if (defined('SID') && SID != '') |
|
2759 | - $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation); |
|
2906 | + if (defined('SID') && SID != '') { |
|
2907 | + $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation); |
|
2908 | + } |
|
2760 | 2909 | // Keep that debug in their for template debugging! |
2761 | - elseif (isset($_GET['debug'])) |
|
2762 | - $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation); |
|
2910 | + elseif (isset($_GET['debug'])) { |
|
2911 | + $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation); |
|
2912 | + } |
|
2763 | 2913 | |
2764 | 2914 | 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']))) |
2765 | 2915 | { |
2766 | - if (defined('SID') && SID != '') |
|
2767 | - $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#]+?)(#[^"]*?)?$~', |
|
2916 | + if (defined('SID') && SID != '') { |
|
2917 | + $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#]+?)(#[^"]*?)?$~', |
|
2768 | 2918 | function ($m) use ($scripturl) |
2769 | 2919 | { |
2770 | 2920 | return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : ""); |
2921 | + } |
|
2771 | 2922 | }, $setLocation); |
2772 | - else |
|
2773 | - $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~', |
|
2923 | + else { |
|
2924 | + $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~', |
|
2774 | 2925 | function ($m) use ($scripturl) |
2775 | 2926 | { |
2776 | 2927 | return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : ""); |
2928 | + } |
|
2777 | 2929 | }, $setLocation); |
2778 | 2930 | } |
2779 | 2931 | |
@@ -2784,8 +2936,9 @@ discard block |
||
2784 | 2936 | header('Location: ' . str_replace(' ', '%20', $setLocation), true, $permanent ? 301 : 302); |
2785 | 2937 | |
2786 | 2938 | // Debugging. |
2787 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
2788 | - $_SESSION['debug_redirect'] = $db_cache; |
|
2939 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
2940 | + $_SESSION['debug_redirect'] = $db_cache; |
|
2941 | + } |
|
2789 | 2942 | |
2790 | 2943 | obExit(false); |
2791 | 2944 | } |
@@ -2804,51 +2957,60 @@ discard block |
||
2804 | 2957 | |
2805 | 2958 | // Attempt to prevent a recursive loop. |
2806 | 2959 | ++$level; |
2807 | - if ($level > 1 && !$from_fatal_error && !$has_fatal_error) |
|
2808 | - exit; |
|
2809 | - if ($from_fatal_error) |
|
2810 | - $has_fatal_error = true; |
|
2960 | + if ($level > 1 && !$from_fatal_error && !$has_fatal_error) { |
|
2961 | + exit; |
|
2962 | + } |
|
2963 | + if ($from_fatal_error) { |
|
2964 | + $has_fatal_error = true; |
|
2965 | + } |
|
2811 | 2966 | |
2812 | 2967 | // Clear out the stat cache. |
2813 | 2968 | trackStats(); |
2814 | 2969 | |
2815 | 2970 | // If we have mail to send, send it. |
2816 | - if (!empty($context['flush_mail'])) |
|
2817 | - // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
2971 | + if (!empty($context['flush_mail'])) { |
|
2972 | + // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
2818 | 2973 | AddMailQueue(true); |
2974 | + } |
|
2819 | 2975 | |
2820 | 2976 | $do_header = $header === null ? !$header_done : $header; |
2821 | - if ($do_footer === null) |
|
2822 | - $do_footer = $do_header; |
|
2977 | + if ($do_footer === null) { |
|
2978 | + $do_footer = $do_header; |
|
2979 | + } |
|
2823 | 2980 | |
2824 | 2981 | // Has the template/header been done yet? |
2825 | 2982 | if ($do_header) |
2826 | 2983 | { |
2827 | 2984 | // Was the page title set last minute? Also update the HTML safe one. |
2828 | - if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) |
|
2829 | - $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); |
|
2985 | + if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) { |
|
2986 | + $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); |
|
2987 | + } |
|
2830 | 2988 | |
2831 | 2989 | // Start up the session URL fixer. |
2832 | 2990 | ob_start('ob_sessrewrite'); |
2833 | 2991 | |
2834 | - if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) |
|
2835 | - $buffers = explode(',', $settings['output_buffers']); |
|
2836 | - elseif (!empty($settings['output_buffers'])) |
|
2837 | - $buffers = $settings['output_buffers']; |
|
2838 | - else |
|
2839 | - $buffers = array(); |
|
2992 | + if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) { |
|
2993 | + $buffers = explode(',', $settings['output_buffers']); |
|
2994 | + } elseif (!empty($settings['output_buffers'])) { |
|
2995 | + $buffers = $settings['output_buffers']; |
|
2996 | + } else { |
|
2997 | + $buffers = array(); |
|
2998 | + } |
|
2840 | 2999 | |
2841 | - if (isset($modSettings['integrate_buffer'])) |
|
2842 | - $buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers); |
|
3000 | + if (isset($modSettings['integrate_buffer'])) { |
|
3001 | + $buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers); |
|
3002 | + } |
|
2843 | 3003 | |
2844 | - if (!empty($buffers)) |
|
2845 | - foreach ($buffers as $function) |
|
3004 | + if (!empty($buffers)) { |
|
3005 | + foreach ($buffers as $function) |
|
2846 | 3006 | { |
2847 | 3007 | $call = call_helper($function, true); |
3008 | + } |
|
2848 | 3009 | |
2849 | 3010 | // Is it valid? |
2850 | - if (!empty($call)) |
|
2851 | - ob_start($call); |
|
3011 | + if (!empty($call)) { |
|
3012 | + ob_start($call); |
|
3013 | + } |
|
2852 | 3014 | } |
2853 | 3015 | |
2854 | 3016 | // Display the screen in the logical order. |
@@ -2860,8 +3022,9 @@ discard block |
||
2860 | 3022 | loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main'); |
2861 | 3023 | |
2862 | 3024 | // Anything special to put out? |
2863 | - if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) |
|
2864 | - echo $context['insert_after_template']; |
|
3025 | + if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) { |
|
3026 | + echo $context['insert_after_template']; |
|
3027 | + } |
|
2865 | 3028 | |
2866 | 3029 | // Just so we don't get caught in an endless loop of errors from the footer... |
2867 | 3030 | if (!$footer_done) |
@@ -2870,14 +3033,16 @@ discard block |
||
2870 | 3033 | template_footer(); |
2871 | 3034 | |
2872 | 3035 | // (since this is just debugging... it's okay that it's after </html>.) |
2873 | - if (!isset($_REQUEST['xml'])) |
|
2874 | - displayDebug(); |
|
3036 | + if (!isset($_REQUEST['xml'])) { |
|
3037 | + displayDebug(); |
|
3038 | + } |
|
2875 | 3039 | } |
2876 | 3040 | } |
2877 | 3041 | |
2878 | 3042 | // Remember this URL in case someone doesn't like sending HTTP_REFERER. |
2879 | - if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) |
|
2880 | - $_SESSION['old_url'] = $_SERVER['REQUEST_URL']; |
|
3043 | + if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) { |
|
3044 | + $_SESSION['old_url'] = $_SERVER['REQUEST_URL']; |
|
3045 | + } |
|
2881 | 3046 | |
2882 | 3047 | // For session check verification.... don't switch browsers... |
2883 | 3048 | $_SESSION['USER_AGENT'] = empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT']; |
@@ -2886,9 +3051,10 @@ discard block |
||
2886 | 3051 | call_integration_hook('integrate_exit', array($do_footer)); |
2887 | 3052 | |
2888 | 3053 | // Don't exit if we're coming from index.php; that will pass through normally. |
2889 | - if (!$from_index) |
|
2890 | - exit; |
|
2891 | -} |
|
3054 | + if (!$from_index) { |
|
3055 | + exit; |
|
3056 | + } |
|
3057 | + } |
|
2892 | 3058 | |
2893 | 3059 | /** |
2894 | 3060 | * Get the size of a specified image with better error handling. |
@@ -2907,8 +3073,9 @@ discard block |
||
2907 | 3073 | $url = str_replace(' ', '%20', $url); |
2908 | 3074 | |
2909 | 3075 | // Can we pull this from the cache... please please? |
2910 | - if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) |
|
2911 | - return $temp; |
|
3076 | + if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) { |
|
3077 | + return $temp; |
|
3078 | + } |
|
2912 | 3079 | $t = microtime(); |
2913 | 3080 | |
2914 | 3081 | // Get the host to pester... |
@@ -2918,12 +3085,10 @@ discard block |
||
2918 | 3085 | if ($url == '' || $url == 'http://' || $url == 'https://') |
2919 | 3086 | { |
2920 | 3087 | return false; |
2921 | - } |
|
2922 | - elseif (!isset($match[1])) |
|
3088 | + } elseif (!isset($match[1])) |
|
2923 | 3089 | { |
2924 | 3090 | $size = @getimagesize($url); |
2925 | - } |
|
2926 | - else |
|
3091 | + } else |
|
2927 | 3092 | { |
2928 | 3093 | // Try to connect to the server... give it half a second. |
2929 | 3094 | $temp = 0; |
@@ -2962,12 +3127,14 @@ discard block |
||
2962 | 3127 | } |
2963 | 3128 | |
2964 | 3129 | // If we didn't get it, we failed. |
2965 | - if (!isset($size)) |
|
2966 | - $size = false; |
|
3130 | + if (!isset($size)) { |
|
3131 | + $size = false; |
|
3132 | + } |
|
2967 | 3133 | |
2968 | 3134 | // If this took a long time, we may never have to do it again, but then again we might... |
2969 | - if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) |
|
2970 | - cache_put_data('url_image_size-' . md5($url), $size, 240); |
|
3135 | + if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) { |
|
3136 | + cache_put_data('url_image_size-' . md5($url), $size, 240); |
|
3137 | + } |
|
2971 | 3138 | |
2972 | 3139 | // Didn't work. |
2973 | 3140 | return $size; |
@@ -2985,8 +3152,9 @@ discard block |
||
2985 | 3152 | |
2986 | 3153 | // Under SSI this function can be called more then once. That can cause some problems. |
2987 | 3154 | // So only run the function once unless we are forced to run it again. |
2988 | - if ($loaded && !$forceload) |
|
2989 | - return; |
|
3155 | + if ($loaded && !$forceload) { |
|
3156 | + return; |
|
3157 | + } |
|
2990 | 3158 | |
2991 | 3159 | $loaded = true; |
2992 | 3160 | |
@@ -2998,14 +3166,16 @@ discard block |
||
2998 | 3166 | $context['news_lines'] = array_filter(explode("\n", str_replace("\r", '', trim(addslashes($modSettings['news']))))); |
2999 | 3167 | for ($i = 0, $n = count($context['news_lines']); $i < $n; $i++) |
3000 | 3168 | { |
3001 | - if (trim($context['news_lines'][$i]) == '') |
|
3002 | - continue; |
|
3169 | + if (trim($context['news_lines'][$i]) == '') { |
|
3170 | + continue; |
|
3171 | + } |
|
3003 | 3172 | |
3004 | 3173 | // Clean it up for presentation ;). |
3005 | 3174 | $context['news_lines'][$i] = parse_bbc(stripslashes(trim($context['news_lines'][$i])), true, 'news' . $i); |
3006 | 3175 | } |
3007 | - if (!empty($context['news_lines'])) |
|
3008 | - $context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)]; |
|
3176 | + if (!empty($context['news_lines'])) { |
|
3177 | + $context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)]; |
|
3178 | + } |
|
3009 | 3179 | |
3010 | 3180 | if (!$user_info['is_guest']) |
3011 | 3181 | { |
@@ -3014,40 +3184,48 @@ discard block |
||
3014 | 3184 | $context['user']['alerts'] = &$user_info['alerts']; |
3015 | 3185 | |
3016 | 3186 | // Personal message popup... |
3017 | - if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) |
|
3018 | - $context['user']['popup_messages'] = true; |
|
3019 | - else |
|
3020 | - $context['user']['popup_messages'] = false; |
|
3187 | + if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) { |
|
3188 | + $context['user']['popup_messages'] = true; |
|
3189 | + } else { |
|
3190 | + $context['user']['popup_messages'] = false; |
|
3191 | + } |
|
3021 | 3192 | $_SESSION['unread_messages'] = $user_info['unread_messages']; |
3022 | 3193 | |
3023 | - if (allowedTo('moderate_forum')) |
|
3024 | - $context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0; |
|
3194 | + if (allowedTo('moderate_forum')) { |
|
3195 | + $context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0; |
|
3196 | + } |
|
3025 | 3197 | |
3026 | 3198 | $context['user']['avatar'] = array(); |
3027 | 3199 | |
3028 | 3200 | // Check for gravatar first since we might be forcing them... |
3029 | 3201 | if (($modSettings['gravatarEnabled'] && substr($user_info['avatar']['url'], 0, 11) == 'gravatar://') || !empty($modSettings['gravatarOverride'])) |
3030 | 3202 | { |
3031 | - if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) |
|
3032 | - $context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11)); |
|
3033 | - else |
|
3034 | - $context['user']['avatar']['href'] = get_gravatar_url($user_info['email']); |
|
3203 | + if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) { |
|
3204 | + $context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11)); |
|
3205 | + } else { |
|
3206 | + $context['user']['avatar']['href'] = get_gravatar_url($user_info['email']); |
|
3207 | + } |
|
3035 | 3208 | } |
3036 | 3209 | // Uploaded? |
3037 | - elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) |
|
3038 | - $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'; |
|
3210 | + elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) { |
|
3211 | + $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'; |
|
3212 | + } |
|
3039 | 3213 | // Full URL? |
3040 | - elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) |
|
3041 | - $context['user']['avatar']['href'] = $user_info['avatar']['url']; |
|
3214 | + elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) { |
|
3215 | + $context['user']['avatar']['href'] = $user_info['avatar']['url']; |
|
3216 | + } |
|
3042 | 3217 | // Otherwise we assume it's server stored. |
3043 | - elseif ($user_info['avatar']['url'] != '') |
|
3044 | - $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']); |
|
3218 | + elseif ($user_info['avatar']['url'] != '') { |
|
3219 | + $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']); |
|
3220 | + } |
|
3045 | 3221 | // No avatar at all? Fine, we have a big fat default avatar ;) |
3046 | - else |
|
3047 | - $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png'; |
|
3222 | + else { |
|
3223 | + $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png'; |
|
3224 | + } |
|
3048 | 3225 | |
3049 | - if (!empty($context['user']['avatar'])) |
|
3050 | - $context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">'; |
|
3226 | + if (!empty($context['user']['avatar'])) { |
|
3227 | + $context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">'; |
|
3228 | + } |
|
3051 | 3229 | |
3052 | 3230 | // Figure out how long they've been logged in. |
3053 | 3231 | $context['user']['total_time_logged_in'] = array( |
@@ -3055,8 +3233,7 @@ discard block |
||
3055 | 3233 | 'hours' => floor(($user_info['total_time_logged_in'] % 86400) / 3600), |
3056 | 3234 | 'minutes' => floor(($user_info['total_time_logged_in'] % 3600) / 60) |
3057 | 3235 | ); |
3058 | - } |
|
3059 | - else |
|
3236 | + } else |
|
3060 | 3237 | { |
3061 | 3238 | $context['user']['messages'] = 0; |
3062 | 3239 | $context['user']['unread_messages'] = 0; |
@@ -3064,12 +3241,14 @@ discard block |
||
3064 | 3241 | $context['user']['total_time_logged_in'] = array('days' => 0, 'hours' => 0, 'minutes' => 0); |
3065 | 3242 | $context['user']['popup_messages'] = false; |
3066 | 3243 | |
3067 | - if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) |
|
3068 | - $txt['welcome_guest'] .= $txt['welcome_guest_activate']; |
|
3244 | + if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) { |
|
3245 | + $txt['welcome_guest'] .= $txt['welcome_guest_activate']; |
|
3246 | + } |
|
3069 | 3247 | |
3070 | 3248 | // If we've upgraded recently, go easy on the passwords. |
3071 | - if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) |
|
3072 | - $context['disable_login_hashing'] = true; |
|
3249 | + if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) { |
|
3250 | + $context['disable_login_hashing'] = true; |
|
3251 | + } |
|
3073 | 3252 | } |
3074 | 3253 | |
3075 | 3254 | // Setup the main menu items. |
@@ -3082,8 +3261,8 @@ discard block |
||
3082 | 3261 | $context['show_pm_popup'] = $context['user']['popup_messages'] && !empty($options['popup_messages']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'pm'); |
3083 | 3262 | |
3084 | 3263 | // 2.1+: Add the PM popup here instead. Theme authors can still override it simply by editing/removing the 'fPmPopup' in the array. |
3085 | - if ($context['show_pm_popup']) |
|
3086 | - addInlineJavaScript(' |
|
3264 | + if ($context['show_pm_popup']) { |
|
3265 | + addInlineJavaScript(' |
|
3087 | 3266 | jQuery(document).ready(function($) { |
3088 | 3267 | new smc_Popup({ |
3089 | 3268 | heading: ' . JavaScriptEscape($txt['show_personal_messages_heading']) . ', |
@@ -3091,15 +3270,17 @@ discard block |
||
3091 | 3270 | icon_class: \'generic_icons mail_new\' |
3092 | 3271 | }); |
3093 | 3272 | });'); |
3273 | + } |
|
3094 | 3274 | |
3095 | 3275 | // Add a generic "Are you sure?" confirmation message. |
3096 | 3276 | addInlineJavaScript(' |
3097 | 3277 | var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';'); |
3098 | 3278 | |
3099 | 3279 | // Now add the capping code for avatars. |
3100 | - 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') |
|
3101 | - addInlineCss(' |
|
3280 | + 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') { |
|
3281 | + addInlineCss(' |
|
3102 | 3282 | img.avatar { max-width: ' . $modSettings['avatar_max_width_external'] . 'px; max-height: ' . $modSettings['avatar_max_height_external'] . 'px; }'); |
3283 | + } |
|
3103 | 3284 | |
3104 | 3285 | // This looks weird, but it's because BoardIndex.php references the variable. |
3105 | 3286 | $context['common_stats']['latest_member'] = array( |
@@ -3116,11 +3297,13 @@ discard block |
||
3116 | 3297 | ); |
3117 | 3298 | $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']); |
3118 | 3299 | |
3119 | - if (empty($settings['theme_version'])) |
|
3120 | - addJavaScriptVar('smf_scripturl', $scripturl); |
|
3300 | + if (empty($settings['theme_version'])) { |
|
3301 | + addJavaScriptVar('smf_scripturl', $scripturl); |
|
3302 | + } |
|
3121 | 3303 | |
3122 | - if (!isset($context['page_title'])) |
|
3123 | - $context['page_title'] = ''; |
|
3304 | + if (!isset($context['page_title'])) { |
|
3305 | + $context['page_title'] = ''; |
|
3306 | + } |
|
3124 | 3307 | |
3125 | 3308 | // Set some specific vars. |
3126 | 3309 | $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); |
@@ -3130,21 +3313,23 @@ discard block |
||
3130 | 3313 | $context['meta_tags'][] = array('property' => 'og:site_name', 'content' => $context['forum_name']); |
3131 | 3314 | $context['meta_tags'][] = array('property' => 'og:title', 'content' => $context['page_title_html_safe']); |
3132 | 3315 | |
3133 | - if (!empty($context['meta_keywords'])) |
|
3134 | - $context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']); |
|
3316 | + if (!empty($context['meta_keywords'])) { |
|
3317 | + $context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']); |
|
3318 | + } |
|
3135 | 3319 | |
3136 | - if (!empty($context['canonical_url'])) |
|
3137 | - $context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']); |
|
3320 | + if (!empty($context['canonical_url'])) { |
|
3321 | + $context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']); |
|
3322 | + } |
|
3138 | 3323 | |
3139 | - if (!empty($settings['og_image'])) |
|
3140 | - $context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']); |
|
3324 | + if (!empty($settings['og_image'])) { |
|
3325 | + $context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']); |
|
3326 | + } |
|
3141 | 3327 | |
3142 | 3328 | if (!empty($context['meta_description'])) |
3143 | 3329 | { |
3144 | 3330 | $context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['meta_description']); |
3145 | 3331 | $context['meta_tags'][] = array('name' => 'description', 'content' => $context['meta_description']); |
3146 | - } |
|
3147 | - else |
|
3332 | + } else |
|
3148 | 3333 | { |
3149 | 3334 | $context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['page_title_html_safe']); |
3150 | 3335 | $context['meta_tags'][] = array('name' => 'description', 'content' => $context['page_title_html_safe']); |
@@ -3169,8 +3354,9 @@ discard block |
||
3169 | 3354 | $memory_needed = memoryReturnBytes($needed); |
3170 | 3355 | |
3171 | 3356 | // should we account for how much is currently being used? |
3172 | - if ($in_use) |
|
3173 | - $memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576); |
|
3357 | + if ($in_use) { |
|
3358 | + $memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576); |
|
3359 | + } |
|
3174 | 3360 | |
3175 | 3361 | // if more is needed, request it |
3176 | 3362 | if ($memory_current < $memory_needed) |
@@ -3193,8 +3379,9 @@ discard block |
||
3193 | 3379 | */ |
3194 | 3380 | function memoryReturnBytes($val) |
3195 | 3381 | { |
3196 | - if (is_integer($val)) |
|
3197 | - return $val; |
|
3382 | + if (is_integer($val)) { |
|
3383 | + return $val; |
|
3384 | + } |
|
3198 | 3385 | |
3199 | 3386 | // Separate the number from the designator |
3200 | 3387 | $val = trim($val); |
@@ -3230,10 +3417,11 @@ discard block |
||
3230 | 3417 | header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); |
3231 | 3418 | |
3232 | 3419 | // Are we debugging the template/html content? |
3233 | - if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) |
|
3234 | - header('Content-Type: application/xhtml+xml'); |
|
3235 | - elseif (!isset($_REQUEST['xml'])) |
|
3236 | - header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
3420 | + if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) { |
|
3421 | + header('Content-Type: application/xhtml+xml'); |
|
3422 | + } elseif (!isset($_REQUEST['xml'])) { |
|
3423 | + header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
3424 | + } |
|
3237 | 3425 | } |
3238 | 3426 | |
3239 | 3427 | header('Content-Type: text/' . (isset($_REQUEST['xml']) ? 'xml' : 'html') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
@@ -3242,8 +3430,9 @@ discard block |
||
3242 | 3430 | if ($context['in_maintenance'] && $context['user']['is_admin']) |
3243 | 3431 | { |
3244 | 3432 | $position = array_search('body', $context['template_layers']); |
3245 | - if ($position === false) |
|
3246 | - $position = array_search('main', $context['template_layers']); |
|
3433 | + if ($position === false) { |
|
3434 | + $position = array_search('main', $context['template_layers']); |
|
3435 | + } |
|
3247 | 3436 | |
3248 | 3437 | if ($position !== false) |
3249 | 3438 | { |
@@ -3271,23 +3460,25 @@ discard block |
||
3271 | 3460 | |
3272 | 3461 | foreach ($securityFiles as $i => $securityFile) |
3273 | 3462 | { |
3274 | - if (!file_exists($boarddir . '/' . $securityFile)) |
|
3275 | - unset($securityFiles[$i]); |
|
3463 | + if (!file_exists($boarddir . '/' . $securityFile)) { |
|
3464 | + unset($securityFiles[$i]); |
|
3465 | + } |
|
3276 | 3466 | } |
3277 | 3467 | |
3278 | 3468 | // We are already checking so many files...just few more doesn't make any difference! :P |
3279 | - if (!empty($modSettings['currentAttachmentUploadDir'])) |
|
3280 | - $path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; |
|
3281 | - |
|
3282 | - else |
|
3283 | - $path = $modSettings['attachmentUploadDir']; |
|
3469 | + if (!empty($modSettings['currentAttachmentUploadDir'])) { |
|
3470 | + $path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; |
|
3471 | + } else { |
|
3472 | + $path = $modSettings['attachmentUploadDir']; |
|
3473 | + } |
|
3284 | 3474 | |
3285 | 3475 | secureDirectory($path, true); |
3286 | 3476 | secureDirectory($cachedir); |
3287 | 3477 | |
3288 | 3478 | // If agreement is enabled, at least the english version shall exists |
3289 | - if ($modSettings['requireAgreement']) |
|
3290 | - $agreement = !file_exists($boarddir . '/agreement.txt'); |
|
3479 | + if ($modSettings['requireAgreement']) { |
|
3480 | + $agreement = !file_exists($boarddir . '/agreement.txt'); |
|
3481 | + } |
|
3291 | 3482 | |
3292 | 3483 | if (!empty($securityFiles) || (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) || !empty($agreement)) |
3293 | 3484 | { |
@@ -3302,18 +3493,21 @@ discard block |
||
3302 | 3493 | echo ' |
3303 | 3494 | ', $txt['not_removed'], '<strong>', $securityFile, '</strong>!<br>'; |
3304 | 3495 | |
3305 | - if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') |
|
3306 | - echo ' |
|
3496 | + if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') { |
|
3497 | + echo ' |
|
3307 | 3498 | ', sprintf($txt['not_removed_extra'], $securityFile, substr($securityFile, 0, -1)), '<br>'; |
3499 | + } |
|
3308 | 3500 | } |
3309 | 3501 | |
3310 | - if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) |
|
3311 | - echo ' |
|
3502 | + if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) { |
|
3503 | + echo ' |
|
3312 | 3504 | <strong>', $txt['cache_writable'], '</strong><br>'; |
3505 | + } |
|
3313 | 3506 | |
3314 | - if (!empty($agreement)) |
|
3315 | - echo ' |
|
3507 | + if (!empty($agreement)) { |
|
3508 | + echo ' |
|
3316 | 3509 | <strong>', $txt['agreement_missing'], '</strong><br>'; |
3510 | + } |
|
3317 | 3511 | |
3318 | 3512 | echo ' |
3319 | 3513 | </p> |
@@ -3328,16 +3522,18 @@ discard block |
||
3328 | 3522 | <div class="windowbg alert" style="margin: 2ex; padding: 2ex; border: 2px dashed red;"> |
3329 | 3523 | ', sprintf($txt['you_are_post_banned'], $user_info['is_guest'] ? $txt['guest_title'] : $user_info['name']); |
3330 | 3524 | |
3331 | - if (!empty($_SESSION['ban']['cannot_post']['reason'])) |
|
3332 | - echo ' |
|
3525 | + if (!empty($_SESSION['ban']['cannot_post']['reason'])) { |
|
3526 | + echo ' |
|
3333 | 3527 | <div style="padding-left: 4ex; padding-top: 1ex;">', $_SESSION['ban']['cannot_post']['reason'], '</div>'; |
3528 | + } |
|
3334 | 3529 | |
3335 | - if (!empty($_SESSION['ban']['expire_time'])) |
|
3336 | - echo ' |
|
3530 | + if (!empty($_SESSION['ban']['expire_time'])) { |
|
3531 | + echo ' |
|
3337 | 3532 | <div>', sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)), '</div>'; |
3338 | - else |
|
3339 | - echo ' |
|
3533 | + } else { |
|
3534 | + echo ' |
|
3340 | 3535 | <div>', $txt['your_ban_expires_never'], '</div>'; |
3536 | + } |
|
3341 | 3537 | |
3342 | 3538 | echo ' |
3343 | 3539 | </div>'; |
@@ -3353,8 +3549,9 @@ discard block |
||
3353 | 3549 | global $forum_copyright, $software_year, $forum_version; |
3354 | 3550 | |
3355 | 3551 | // Don't display copyright for things like SSI. |
3356 | - if (!isset($forum_version) || !isset($software_year)) |
|
3357 | - return; |
|
3552 | + if (!isset($forum_version) || !isset($software_year)) { |
|
3553 | + return; |
|
3554 | + } |
|
3358 | 3555 | |
3359 | 3556 | // Put in the version... |
3360 | 3557 | printf($forum_copyright, $forum_version, $software_year); |
@@ -3372,9 +3569,10 @@ discard block |
||
3372 | 3569 | $context['load_time'] = comma_format(round(array_sum(explode(' ', microtime())) - array_sum(explode(' ', $time_start)), 3)); |
3373 | 3570 | $context['load_queries'] = $db_count; |
3374 | 3571 | |
3375 | - foreach (array_reverse($context['template_layers']) as $layer) |
|
3376 | - loadSubTemplate($layer . '_below', true); |
|
3377 | -} |
|
3572 | + foreach (array_reverse($context['template_layers']) as $layer) { |
|
3573 | + loadSubTemplate($layer . '_below', true); |
|
3574 | + } |
|
3575 | + } |
|
3378 | 3576 | |
3379 | 3577 | /** |
3380 | 3578 | * Output the Javascript files |
@@ -3405,8 +3603,7 @@ discard block |
||
3405 | 3603 | { |
3406 | 3604 | echo ' |
3407 | 3605 | var ', $key, ';'; |
3408 | - } |
|
3409 | - else |
|
3606 | + } else |
|
3410 | 3607 | { |
3411 | 3608 | echo ' |
3412 | 3609 | var ', $key, ' = ', $value, ';'; |
@@ -3421,26 +3618,27 @@ discard block |
||
3421 | 3618 | foreach ($context['javascript_files'] as $id => $js_file) |
3422 | 3619 | { |
3423 | 3620 | // Last minute call! allow theme authors to disable single files. |
3424 | - if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) |
|
3425 | - continue; |
|
3621 | + if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) { |
|
3622 | + continue; |
|
3623 | + } |
|
3426 | 3624 | |
3427 | 3625 | // By default all files don't get minimized unless the file explicitly says so! |
3428 | 3626 | if (!empty($js_file['options']['minimize']) && !empty($modSettings['minimize_files'])) |
3429 | 3627 | { |
3430 | - if ($do_deferred && !empty($js_file['options']['defer'])) |
|
3431 | - $toMinifyDefer[] = $js_file; |
|
3432 | - |
|
3433 | - elseif (!$do_deferred && empty($js_file['options']['defer'])) |
|
3434 | - $toMinify[] = $js_file; |
|
3628 | + if ($do_deferred && !empty($js_file['options']['defer'])) { |
|
3629 | + $toMinifyDefer[] = $js_file; |
|
3630 | + } elseif (!$do_deferred && empty($js_file['options']['defer'])) { |
|
3631 | + $toMinify[] = $js_file; |
|
3632 | + } |
|
3435 | 3633 | |
3436 | 3634 | // Grab a random seed. |
3437 | - if (!isset($minSeed)) |
|
3438 | - $minSeed = $js_file['options']['seed']; |
|
3439 | - } |
|
3440 | - |
|
3441 | - elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer']))) |
|
3442 | - echo ' |
|
3635 | + if (!isset($minSeed)) { |
|
3636 | + $minSeed = $js_file['options']['seed']; |
|
3637 | + } |
|
3638 | + } elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer']))) { |
|
3639 | + echo ' |
|
3443 | 3640 | <script src="', $js_file['fileUrl'], '"', !empty($js_file['options']['async']) ? ' async="async"' : '', '></script>'; |
3641 | + } |
|
3444 | 3642 | } |
3445 | 3643 | |
3446 | 3644 | if ((!$do_deferred && !empty($toMinify)) || ($do_deferred && !empty($toMinifyDefer))) |
@@ -3448,14 +3646,14 @@ discard block |
||
3448 | 3646 | $result = custMinify(($do_deferred ? $toMinifyDefer : $toMinify), 'js', $do_deferred); |
3449 | 3647 | |
3450 | 3648 | // Minify process couldn't work, print each individual files. |
3451 | - if (!empty($result) && is_array($result)) |
|
3452 | - foreach ($result as $minFailedFile) |
|
3649 | + if (!empty($result) && is_array($result)) { |
|
3650 | + foreach ($result as $minFailedFile) |
|
3453 | 3651 | echo ' |
3454 | 3652 | <script src="', $minFailedFile['fileUrl'], '"', !empty($minFailedFile['options']['async']) ? ' async="async"' : '', '></script>'; |
3455 | - |
|
3456 | - else |
|
3457 | - echo ' |
|
3653 | + } else { |
|
3654 | + echo ' |
|
3458 | 3655 | <script src="', $settings['theme_url'] ,'/scripts/minified', ($do_deferred ? '_deferred' : '') ,'.js', $minSeed ,'"></script>'; |
3656 | + } |
|
3459 | 3657 | } |
3460 | 3658 | |
3461 | 3659 | // Inline JavaScript - Actually useful some times! |
@@ -3466,8 +3664,9 @@ discard block |
||
3466 | 3664 | echo ' |
3467 | 3665 | <script>'; |
3468 | 3666 | |
3469 | - foreach ($context['javascript_inline']['defer'] as $js_code) |
|
3470 | - echo $js_code; |
|
3667 | + foreach ($context['javascript_inline']['defer'] as $js_code) { |
|
3668 | + echo $js_code; |
|
3669 | + } |
|
3471 | 3670 | |
3472 | 3671 | echo ' |
3473 | 3672 | </script>'; |
@@ -3478,8 +3677,9 @@ discard block |
||
3478 | 3677 | echo ' |
3479 | 3678 | <script>'; |
3480 | 3679 | |
3481 | - foreach ($context['javascript_inline']['standard'] as $js_code) |
|
3482 | - echo $js_code; |
|
3680 | + foreach ($context['javascript_inline']['standard'] as $js_code) { |
|
3681 | + echo $js_code; |
|
3682 | + } |
|
3483 | 3683 | |
3484 | 3684 | echo ' |
3485 | 3685 | </script>'; |
@@ -3504,8 +3704,9 @@ discard block |
||
3504 | 3704 | foreach ($context['css_files'] as $id => $file) |
3505 | 3705 | { |
3506 | 3706 | // Last minute call! allow theme authors to disable single files. |
3507 | - if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) |
|
3508 | - continue; |
|
3707 | + if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) { |
|
3708 | + continue; |
|
3709 | + } |
|
3509 | 3710 | |
3510 | 3711 | // By default all files don't get minimized unless the file explicitly says so! |
3511 | 3712 | if (!empty($file['options']['minimize']) && !empty($modSettings['minimize_files'])) |
@@ -3513,12 +3714,12 @@ discard block |
||
3513 | 3714 | $toMinify[] = $file; |
3514 | 3715 | |
3515 | 3716 | // Grab a random seed. |
3516 | - if (!isset($minSeed)) |
|
3517 | - $minSeed = $file['options']['seed']; |
|
3717 | + if (!isset($minSeed)) { |
|
3718 | + $minSeed = $file['options']['seed']; |
|
3719 | + } |
|
3720 | + } else { |
|
3721 | + $normal[] = $file['fileUrl']; |
|
3518 | 3722 | } |
3519 | - |
|
3520 | - else |
|
3521 | - $normal[] = $file['fileUrl']; |
|
3522 | 3723 | } |
3523 | 3724 | |
3524 | 3725 | if (!empty($toMinify)) |
@@ -3526,28 +3727,30 @@ discard block |
||
3526 | 3727 | $result = custMinify($toMinify, 'css'); |
3527 | 3728 | |
3528 | 3729 | // Minify process couldn't work, print each individual files. |
3529 | - if (!empty($result) && is_array($result)) |
|
3530 | - foreach ($result as $minFailedFile) |
|
3730 | + if (!empty($result) && is_array($result)) { |
|
3731 | + foreach ($result as $minFailedFile) |
|
3531 | 3732 | echo ' |
3532 | 3733 | <link rel="stylesheet" href="', $minFailedFile['fileUrl'], '">'; |
3533 | - |
|
3534 | - else |
|
3535 | - echo ' |
|
3734 | + } else { |
|
3735 | + echo ' |
|
3536 | 3736 | <link rel="stylesheet" href="', $settings['theme_url'] ,'/css/minified.css', $minSeed ,'">'; |
3737 | + } |
|
3537 | 3738 | } |
3538 | 3739 | |
3539 | 3740 | // Print the rest after the minified files. |
3540 | - if (!empty($normal)) |
|
3541 | - foreach ($normal as $nf) |
|
3741 | + if (!empty($normal)) { |
|
3742 | + foreach ($normal as $nf) |
|
3542 | 3743 | echo ' |
3543 | 3744 | <link rel="stylesheet" href="', $nf ,'">'; |
3745 | + } |
|
3544 | 3746 | |
3545 | 3747 | if ($db_show_debug === true) |
3546 | 3748 | { |
3547 | 3749 | // Try to keep only what's useful. |
3548 | 3750 | $repl = array($boardurl . '/Themes/' => '', $boardurl . '/' => ''); |
3549 | - foreach ($context['css_files'] as $file) |
|
3550 | - $context['debug']['sheets'][] = strtr($file['fileName'], $repl); |
|
3751 | + foreach ($context['css_files'] as $file) { |
|
3752 | + $context['debug']['sheets'][] = strtr($file['fileName'], $repl); |
|
3753 | + } |
|
3551 | 3754 | } |
3552 | 3755 | |
3553 | 3756 | if (!empty($context['css_header'])) |
@@ -3555,9 +3758,10 @@ discard block |
||
3555 | 3758 | echo ' |
3556 | 3759 | <style>'; |
3557 | 3760 | |
3558 | - foreach ($context['css_header'] as $css) |
|
3559 | - echo $css .' |
|
3761 | + foreach ($context['css_header'] as $css) { |
|
3762 | + echo $css .' |
|
3560 | 3763 | '; |
3764 | + } |
|
3561 | 3765 | |
3562 | 3766 | echo' |
3563 | 3767 | </style>'; |
@@ -3581,15 +3785,17 @@ discard block |
||
3581 | 3785 | $type = !empty($type) && in_array($type, $types) ? $type : false; |
3582 | 3786 | $data = !empty($data) ? $data : false; |
3583 | 3787 | |
3584 | - if (empty($type) || empty($data)) |
|
3585 | - return false; |
|
3788 | + if (empty($type) || empty($data)) { |
|
3789 | + return false; |
|
3790 | + } |
|
3586 | 3791 | |
3587 | 3792 | // Did we already did this? |
3588 | 3793 | $toCache = cache_get_data('minimized_'. $settings['theme_id'] .'_'. $type, 86400); |
3589 | 3794 | |
3590 | 3795 | // Already done? |
3591 | - if (!empty($toCache)) |
|
3592 | - return true; |
|
3796 | + if (!empty($toCache)) { |
|
3797 | + return true; |
|
3798 | + } |
|
3593 | 3799 | |
3594 | 3800 | // Yep, need a bunch of files. |
3595 | 3801 | require_once($sourcedir . '/minify/src/Minify.php'); |
@@ -3677,8 +3883,9 @@ discard block |
||
3677 | 3883 | global $modSettings, $smcFunc; |
3678 | 3884 | |
3679 | 3885 | // Just make up a nice hash... |
3680 | - if ($new) |
|
3681 | - return sha1(md5($filename . time()) . mt_rand()); |
|
3886 | + if ($new) { |
|
3887 | + return sha1(md5($filename . time()) . mt_rand()); |
|
3888 | + } |
|
3682 | 3889 | |
3683 | 3890 | // Grab the file hash if it wasn't added. |
3684 | 3891 | // Left this for legacy. |
@@ -3692,23 +3899,25 @@ discard block |
||
3692 | 3899 | 'id_attach' => $attachment_id, |
3693 | 3900 | )); |
3694 | 3901 | |
3695 | - if ($smcFunc['db_num_rows']($request) === 0) |
|
3696 | - return false; |
|
3902 | + if ($smcFunc['db_num_rows']($request) === 0) { |
|
3903 | + return false; |
|
3904 | + } |
|
3697 | 3905 | |
3698 | 3906 | list ($file_hash) = $smcFunc['db_fetch_row']($request); |
3699 | 3907 | $smcFunc['db_free_result']($request); |
3700 | 3908 | } |
3701 | 3909 | |
3702 | 3910 | // Still no hash? mmm... |
3703 | - if (empty($file_hash)) |
|
3704 | - $file_hash = sha1(md5($filename . time()) . mt_rand()); |
|
3911 | + if (empty($file_hash)) { |
|
3912 | + $file_hash = sha1(md5($filename . time()) . mt_rand()); |
|
3913 | + } |
|
3705 | 3914 | |
3706 | 3915 | // Are we using multiple directories? |
3707 | - if (!empty($modSettings['currentAttachmentUploadDir'])) |
|
3708 | - $path = $modSettings['attachmentUploadDir'][$dir]; |
|
3709 | - |
|
3710 | - else |
|
3711 | - $path = $modSettings['attachmentUploadDir']; |
|
3916 | + if (!empty($modSettings['currentAttachmentUploadDir'])) { |
|
3917 | + $path = $modSettings['attachmentUploadDir'][$dir]; |
|
3918 | + } else { |
|
3919 | + $path = $modSettings['attachmentUploadDir']; |
|
3920 | + } |
|
3712 | 3921 | |
3713 | 3922 | return $path . '/' . $attachment_id . '_' . $file_hash .'.dat'; |
3714 | 3923 | } |
@@ -3723,8 +3932,9 @@ discard block |
||
3723 | 3932 | function ip2range($fullip) |
3724 | 3933 | { |
3725 | 3934 | // Pretend that 'unknown' is 255.255.255.255. (since that can't be an IP anyway.) |
3726 | - if ($fullip == 'unknown') |
|
3727 | - $fullip = '255.255.255.255'; |
|
3935 | + if ($fullip == 'unknown') { |
|
3936 | + $fullip = '255.255.255.255'; |
|
3937 | + } |
|
3728 | 3938 | |
3729 | 3939 | $ip_parts = explode('-', $fullip); |
3730 | 3940 | $ip_array = array(); |
@@ -3748,10 +3958,11 @@ discard block |
||
3748 | 3958 | $ip_array['low'] = $ip_parts[0]; |
3749 | 3959 | $ip_array['high'] = $ip_parts[1]; |
3750 | 3960 | return $ip_array; |
3751 | - } |
|
3752 | - elseif (count($ip_parts) == 2) // if ip 22.22.*-22.22.* |
|
3961 | + } elseif (count($ip_parts) == 2) { |
|
3962 | + // if ip 22.22.*-22.22.* |
|
3753 | 3963 | { |
3754 | 3964 | $valid_low = isValidIP($ip_parts[0]); |
3965 | + } |
|
3755 | 3966 | $valid_high = isValidIP($ip_parts[1]); |
3756 | 3967 | $count = 0; |
3757 | 3968 | $mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.'); |
@@ -3766,7 +3977,9 @@ discard block |
||
3766 | 3977 | $ip_parts[0] .= $mode . $min; |
3767 | 3978 | $valid_low = isValidIP($ip_parts[0]); |
3768 | 3979 | $count++; |
3769 | - if ($count > 9) break; |
|
3980 | + if ($count > 9) { |
|
3981 | + break; |
|
3982 | + } |
|
3770 | 3983 | } |
3771 | 3984 | } |
3772 | 3985 | |
@@ -3780,7 +3993,9 @@ discard block |
||
3780 | 3993 | $ip_parts[1] .= $mode . $max; |
3781 | 3994 | $valid_high = isValidIP($ip_parts[1]); |
3782 | 3995 | $count++; |
3783 | - if ($count > 9) break; |
|
3996 | + if ($count > 9) { |
|
3997 | + break; |
|
3998 | + } |
|
3784 | 3999 | } |
3785 | 4000 | } |
3786 | 4001 | |
@@ -3805,46 +4020,54 @@ discard block |
||
3805 | 4020 | { |
3806 | 4021 | global $modSettings; |
3807 | 4022 | |
3808 | - if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) |
|
3809 | - return $host; |
|
4023 | + if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) { |
|
4024 | + return $host; |
|
4025 | + } |
|
3810 | 4026 | $t = microtime(); |
3811 | 4027 | |
3812 | 4028 | // Try the Linux host command, perhaps? |
3813 | 4029 | if (!isset($host) && (strpos(strtolower(PHP_OS), 'win') === false || strpos(strtolower(PHP_OS), 'darwin') !== false) && mt_rand(0, 1) == 1) |
3814 | 4030 | { |
3815 | - if (!isset($modSettings['host_to_dis'])) |
|
3816 | - $test = @shell_exec('host -W 1 ' . @escapeshellarg($ip)); |
|
3817 | - else |
|
3818 | - $test = @shell_exec('host ' . @escapeshellarg($ip)); |
|
4031 | + if (!isset($modSettings['host_to_dis'])) { |
|
4032 | + $test = @shell_exec('host -W 1 ' . @escapeshellarg($ip)); |
|
4033 | + } else { |
|
4034 | + $test = @shell_exec('host ' . @escapeshellarg($ip)); |
|
4035 | + } |
|
3819 | 4036 | |
3820 | 4037 | // Did host say it didn't find anything? |
3821 | - if (strpos($test, 'not found') !== false) |
|
3822 | - $host = ''; |
|
4038 | + if (strpos($test, 'not found') !== false) { |
|
4039 | + $host = ''; |
|
4040 | + } |
|
3823 | 4041 | // Invalid server option? |
3824 | - elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) |
|
3825 | - updateSettings(array('host_to_dis' => 1)); |
|
4042 | + elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) { |
|
4043 | + updateSettings(array('host_to_dis' => 1)); |
|
4044 | + } |
|
3826 | 4045 | // Maybe it found something, after all? |
3827 | - elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) |
|
3828 | - $host = $match[1]; |
|
4046 | + elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) { |
|
4047 | + $host = $match[1]; |
|
4048 | + } |
|
3829 | 4049 | } |
3830 | 4050 | |
3831 | 4051 | // This is nslookup; usually only Windows, but possibly some Unix? |
3832 | 4052 | if (!isset($host) && stripos(PHP_OS, 'win') !== false && strpos(strtolower(PHP_OS), 'darwin') === false && mt_rand(0, 1) == 1) |
3833 | 4053 | { |
3834 | 4054 | $test = @shell_exec('nslookup -timeout=1 ' . @escapeshellarg($ip)); |
3835 | - if (strpos($test, 'Non-existent domain') !== false) |
|
3836 | - $host = ''; |
|
3837 | - elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) |
|
3838 | - $host = $match[1]; |
|
4055 | + if (strpos($test, 'Non-existent domain') !== false) { |
|
4056 | + $host = ''; |
|
4057 | + } elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) { |
|
4058 | + $host = $match[1]; |
|
4059 | + } |
|
3839 | 4060 | } |
3840 | 4061 | |
3841 | 4062 | // This is the last try :/. |
3842 | - if (!isset($host) || $host === false) |
|
3843 | - $host = @gethostbyaddr($ip); |
|
4063 | + if (!isset($host) || $host === false) { |
|
4064 | + $host = @gethostbyaddr($ip); |
|
4065 | + } |
|
3844 | 4066 | |
3845 | 4067 | // It took a long time, so let's cache it! |
3846 | - if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) |
|
3847 | - cache_put_data('hostlookup-' . $ip, $host, 600); |
|
4068 | + if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) { |
|
4069 | + cache_put_data('hostlookup-' . $ip, $host, 600); |
|
4070 | + } |
|
3848 | 4071 | |
3849 | 4072 | return $host; |
3850 | 4073 | } |
@@ -3880,20 +4103,21 @@ discard block |
||
3880 | 4103 | { |
3881 | 4104 | $encrypted = substr(crypt($word, 'uk'), 2, $max_chars); |
3882 | 4105 | $total = 0; |
3883 | - for ($i = 0; $i < $max_chars; $i++) |
|
3884 | - $total += $possible_chars[ord($encrypted{$i})] * pow(63, $i); |
|
4106 | + for ($i = 0; $i < $max_chars; $i++) { |
|
4107 | + $total += $possible_chars[ord($encrypted{$i})] * pow(63, $i); |
|
4108 | + } |
|
3885 | 4109 | $returned_ints[] = $max_chars == 4 ? min($total, 16777215) : $total; |
3886 | 4110 | } |
3887 | 4111 | } |
3888 | 4112 | return array_unique($returned_ints); |
3889 | - } |
|
3890 | - else |
|
4113 | + } else |
|
3891 | 4114 | { |
3892 | 4115 | // Trim characters before and after and add slashes for database insertion. |
3893 | 4116 | $returned_words = array(); |
3894 | - foreach ($words as $word) |
|
3895 | - if (($word = trim($word, '-_\'')) !== '') |
|
4117 | + foreach ($words as $word) { |
|
4118 | + if (($word = trim($word, '-_\'')) !== '') |
|
3896 | 4119 | $returned_words[] = $max_chars === null ? $word : substr($word, 0, $max_chars); |
4120 | + } |
|
3897 | 4121 | |
3898 | 4122 | // Filter out all words that occur more than once. |
3899 | 4123 | return array_unique($returned_words); |
@@ -3915,16 +4139,18 @@ discard block |
||
3915 | 4139 | global $settings, $txt; |
3916 | 4140 | |
3917 | 4141 | // Does the current loaded theme have this and we are not forcing the usage of this function? |
3918 | - if (function_exists('template_create_button') && !$force_use) |
|
3919 | - return template_create_button($name, $alt, $label = '', $custom = ''); |
|
4142 | + if (function_exists('template_create_button') && !$force_use) { |
|
4143 | + return template_create_button($name, $alt, $label = '', $custom = ''); |
|
4144 | + } |
|
3920 | 4145 | |
3921 | - if (!$settings['use_image_buttons']) |
|
3922 | - return $txt[$alt]; |
|
3923 | - elseif (!empty($settings['use_buttons'])) |
|
3924 | - return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? ' <strong>' . $txt[$label] . '</strong>' : ''); |
|
3925 | - else |
|
3926 | - return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>'; |
|
3927 | -} |
|
4146 | + if (!$settings['use_image_buttons']) { |
|
4147 | + return $txt[$alt]; |
|
4148 | + } elseif (!empty($settings['use_buttons'])) { |
|
4149 | + return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? ' <strong>' . $txt[$label] . '</strong>' : ''); |
|
4150 | + } else { |
|
4151 | + return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>'; |
|
4152 | + } |
|
4153 | + } |
|
3928 | 4154 | |
3929 | 4155 | /** |
3930 | 4156 | * Sets up all of the top menu buttons |
@@ -3967,9 +4193,10 @@ discard block |
||
3967 | 4193 | var user_menus = new smc_PopupMenu(); |
3968 | 4194 | user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup"); |
3969 | 4195 | user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true); |
3970 | - if ($context['allow_pm']) |
|
3971 | - addInlineJavaScript(' |
|
4196 | + if ($context['allow_pm']) { |
|
4197 | + addInlineJavaScript(' |
|
3972 | 4198 | user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true); |
4199 | + } |
|
3973 | 4200 | |
3974 | 4201 | if (!empty($modSettings['enable_ajax_alerts'])) |
3975 | 4202 | { |
@@ -4129,88 +4356,96 @@ discard block |
||
4129 | 4356 | |
4130 | 4357 | // Now we put the buttons in the context so the theme can use them. |
4131 | 4358 | $menu_buttons = array(); |
4132 | - foreach ($buttons as $act => $button) |
|
4133 | - if (!empty($button['show'])) |
|
4359 | + foreach ($buttons as $act => $button) { |
|
4360 | + if (!empty($button['show'])) |
|
4134 | 4361 | { |
4135 | 4362 | $button['active_button'] = false; |
4363 | + } |
|
4136 | 4364 | |
4137 | 4365 | // This button needs some action. |
4138 | - if (isset($button['action_hook'])) |
|
4139 | - $needs_action_hook = true; |
|
4366 | + if (isset($button['action_hook'])) { |
|
4367 | + $needs_action_hook = true; |
|
4368 | + } |
|
4140 | 4369 | |
4141 | 4370 | // Make sure the last button truly is the last button. |
4142 | 4371 | if (!empty($button['is_last'])) |
4143 | 4372 | { |
4144 | - if (isset($last_button)) |
|
4145 | - unset($menu_buttons[$last_button]['is_last']); |
|
4373 | + if (isset($last_button)) { |
|
4374 | + unset($menu_buttons[$last_button]['is_last']); |
|
4375 | + } |
|
4146 | 4376 | $last_button = $act; |
4147 | 4377 | } |
4148 | 4378 | |
4149 | 4379 | // Go through the sub buttons if there are any. |
4150 | - if (!empty($button['sub_buttons'])) |
|
4151 | - foreach ($button['sub_buttons'] as $key => $subbutton) |
|
4380 | + if (!empty($button['sub_buttons'])) { |
|
4381 | + foreach ($button['sub_buttons'] as $key => $subbutton) |
|
4152 | 4382 | { |
4153 | 4383 | if (empty($subbutton['show'])) |
4154 | 4384 | unset($button['sub_buttons'][$key]); |
4385 | + } |
|
4155 | 4386 | |
4156 | 4387 | // 2nd level sub buttons next... |
4157 | 4388 | if (!empty($subbutton['sub_buttons'])) |
4158 | 4389 | { |
4159 | 4390 | foreach ($subbutton['sub_buttons'] as $key2 => $sub_button2) |
4160 | 4391 | { |
4161 | - if (empty($sub_button2['show'])) |
|
4162 | - unset($button['sub_buttons'][$key]['sub_buttons'][$key2]); |
|
4392 | + if (empty($sub_button2['show'])) { |
|
4393 | + unset($button['sub_buttons'][$key]['sub_buttons'][$key2]); |
|
4394 | + } |
|
4163 | 4395 | } |
4164 | 4396 | } |
4165 | 4397 | } |
4166 | 4398 | |
4167 | 4399 | // Does this button have its own icon? |
4168 | - if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) |
|
4169 | - $button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
4170 | - elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) |
|
4171 | - $button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
4172 | - elseif (isset($button['icon'])) |
|
4173 | - $button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>'; |
|
4174 | - else |
|
4175 | - $button['icon'] = '<span class="generic_icons ' . $act . '"></span>'; |
|
4400 | + if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) { |
|
4401 | + $button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
4402 | + } elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) { |
|
4403 | + $button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
4404 | + } elseif (isset($button['icon'])) { |
|
4405 | + $button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>'; |
|
4406 | + } else { |
|
4407 | + $button['icon'] = '<span class="generic_icons ' . $act . '"></span>'; |
|
4408 | + } |
|
4176 | 4409 | |
4177 | 4410 | $menu_buttons[$act] = $button; |
4178 | 4411 | } |
4179 | 4412 | |
4180 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
4181 | - cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime); |
|
4413 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
4414 | + cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime); |
|
4415 | + } |
|
4182 | 4416 | } |
4183 | 4417 | |
4184 | 4418 | $context['menu_buttons'] = $menu_buttons; |
4185 | 4419 | |
4186 | 4420 | // Logging out requires the session id in the url. |
4187 | - if (isset($context['menu_buttons']['logout'])) |
|
4188 | - $context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']); |
|
4421 | + if (isset($context['menu_buttons']['logout'])) { |
|
4422 | + $context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']); |
|
4423 | + } |
|
4189 | 4424 | |
4190 | 4425 | // Figure out which action we are doing so we can set the active tab. |
4191 | 4426 | // Default to home. |
4192 | 4427 | $current_action = 'home'; |
4193 | 4428 | |
4194 | - if (isset($context['menu_buttons'][$context['current_action']])) |
|
4195 | - $current_action = $context['current_action']; |
|
4196 | - elseif ($context['current_action'] == 'search2') |
|
4197 | - $current_action = 'search'; |
|
4198 | - elseif ($context['current_action'] == 'theme') |
|
4199 | - $current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin'; |
|
4200 | - elseif ($context['current_action'] == 'register2') |
|
4201 | - $current_action = 'register'; |
|
4202 | - elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) |
|
4203 | - $current_action = 'login'; |
|
4204 | - elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) |
|
4205 | - $current_action = 'moderate'; |
|
4429 | + if (isset($context['menu_buttons'][$context['current_action']])) { |
|
4430 | + $current_action = $context['current_action']; |
|
4431 | + } elseif ($context['current_action'] == 'search2') { |
|
4432 | + $current_action = 'search'; |
|
4433 | + } elseif ($context['current_action'] == 'theme') { |
|
4434 | + $current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin'; |
|
4435 | + } elseif ($context['current_action'] == 'register2') { |
|
4436 | + $current_action = 'register'; |
|
4437 | + } elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) { |
|
4438 | + $current_action = 'login'; |
|
4439 | + } elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) { |
|
4440 | + $current_action = 'moderate'; |
|
4441 | + } |
|
4206 | 4442 | |
4207 | 4443 | // There are certain exceptions to the above where we don't want anything on the menu highlighted. |
4208 | 4444 | if ($context['current_action'] == 'profile' && !empty($context['user']['is_owner'])) |
4209 | 4445 | { |
4210 | 4446 | $current_action = !empty($_GET['area']) && $_GET['area'] == 'showalerts' ? 'self_alerts' : 'self_profile'; |
4211 | 4447 | $context[$current_action] = true; |
4212 | - } |
|
4213 | - elseif ($context['current_action'] == 'pm') |
|
4448 | + } elseif ($context['current_action'] == 'pm') |
|
4214 | 4449 | { |
4215 | 4450 | $current_action = 'self_pm'; |
4216 | 4451 | $context['self_pm'] = true; |
@@ -4253,12 +4488,14 @@ discard block |
||
4253 | 4488 | } |
4254 | 4489 | |
4255 | 4490 | // Not all actions are simple. |
4256 | - if (!empty($needs_action_hook)) |
|
4257 | - call_integration_hook('integrate_current_action', array(&$current_action)); |
|
4491 | + if (!empty($needs_action_hook)) { |
|
4492 | + call_integration_hook('integrate_current_action', array(&$current_action)); |
|
4493 | + } |
|
4258 | 4494 | |
4259 | - if (isset($context['menu_buttons'][$current_action])) |
|
4260 | - $context['menu_buttons'][$current_action]['active_button'] = true; |
|
4261 | -} |
|
4495 | + if (isset($context['menu_buttons'][$current_action])) { |
|
4496 | + $context['menu_buttons'][$current_action]['active_button'] = true; |
|
4497 | + } |
|
4498 | + } |
|
4262 | 4499 | |
4263 | 4500 | /** |
4264 | 4501 | * Generate a random seed and ensure it's stored in settings. |
@@ -4282,16 +4519,19 @@ discard block |
||
4282 | 4519 | global $modSettings, $settings, $boarddir, $sourcedir, $db_show_debug; |
4283 | 4520 | global $context, $txt; |
4284 | 4521 | |
4285 | - if ($db_show_debug === true) |
|
4286 | - $context['debug']['hooks'][] = $hook; |
|
4522 | + if ($db_show_debug === true) { |
|
4523 | + $context['debug']['hooks'][] = $hook; |
|
4524 | + } |
|
4287 | 4525 | |
4288 | 4526 | // Need to have some control. |
4289 | - if (!isset($context['instances'])) |
|
4290 | - $context['instances'] = array(); |
|
4527 | + if (!isset($context['instances'])) { |
|
4528 | + $context['instances'] = array(); |
|
4529 | + } |
|
4291 | 4530 | |
4292 | 4531 | $results = array(); |
4293 | - if (empty($modSettings[$hook])) |
|
4294 | - return $results; |
|
4532 | + if (empty($modSettings[$hook])) { |
|
4533 | + return $results; |
|
4534 | + } |
|
4295 | 4535 | |
4296 | 4536 | // Define some needed vars. |
4297 | 4537 | $function = false; |
@@ -4301,14 +4541,16 @@ discard block |
||
4301 | 4541 | foreach ($functions as $function) |
4302 | 4542 | { |
4303 | 4543 | // Hook has been marked as "disabled". Skip it! |
4304 | - if (strpos($function, '!') !== false) |
|
4305 | - continue; |
|
4544 | + if (strpos($function, '!') !== false) { |
|
4545 | + continue; |
|
4546 | + } |
|
4306 | 4547 | |
4307 | 4548 | $call = call_helper($function, true); |
4308 | 4549 | |
4309 | 4550 | // Is it valid? |
4310 | - if (!empty($call)) |
|
4311 | - $results[$function] = call_user_func_array($call, $parameters); |
|
4551 | + if (!empty($call)) { |
|
4552 | + $results[$function] = call_user_func_array($call, $parameters); |
|
4553 | + } |
|
4312 | 4554 | |
4313 | 4555 | // Whatever it was suppose to call, it failed :( |
4314 | 4556 | elseif (!empty($function)) |
@@ -4324,8 +4566,9 @@ discard block |
||
4324 | 4566 | } |
4325 | 4567 | |
4326 | 4568 | // "Assume" the file resides on $boarddir somewhere... |
4327 | - else |
|
4328 | - log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general'); |
|
4569 | + else { |
|
4570 | + log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general'); |
|
4571 | + } |
|
4329 | 4572 | } |
4330 | 4573 | } |
4331 | 4574 | |
@@ -4347,12 +4590,14 @@ discard block |
||
4347 | 4590 | global $smcFunc, $modSettings; |
4348 | 4591 | |
4349 | 4592 | // Any objects? |
4350 | - if ($object) |
|
4351 | - $function = $function . '#'; |
|
4593 | + if ($object) { |
|
4594 | + $function = $function . '#'; |
|
4595 | + } |
|
4352 | 4596 | |
4353 | 4597 | // Any files to load? |
4354 | - if (!empty($file) && is_string($file)) |
|
4355 | - $function = $file . (!empty($function) ? '|' . $function : ''); |
|
4598 | + if (!empty($file) && is_string($file)) { |
|
4599 | + $function = $file . (!empty($function) ? '|' . $function : ''); |
|
4600 | + } |
|
4356 | 4601 | |
4357 | 4602 | // Get the correct string. |
4358 | 4603 | $integration_call = $function; |
@@ -4374,13 +4619,14 @@ discard block |
||
4374 | 4619 | if (!empty($current_functions)) |
4375 | 4620 | { |
4376 | 4621 | $current_functions = explode(',', $current_functions); |
4377 | - if (in_array($integration_call, $current_functions)) |
|
4378 | - return; |
|
4622 | + if (in_array($integration_call, $current_functions)) { |
|
4623 | + return; |
|
4624 | + } |
|
4379 | 4625 | |
4380 | 4626 | $permanent_functions = array_merge($current_functions, array($integration_call)); |
4627 | + } else { |
|
4628 | + $permanent_functions = array($integration_call); |
|
4381 | 4629 | } |
4382 | - else |
|
4383 | - $permanent_functions = array($integration_call); |
|
4384 | 4630 | |
4385 | 4631 | updateSettings(array($hook => implode(',', $permanent_functions))); |
4386 | 4632 | } |
@@ -4389,8 +4635,9 @@ discard block |
||
4389 | 4635 | $functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]); |
4390 | 4636 | |
4391 | 4637 | // Do nothing, if it's already there. |
4392 | - if (in_array($integration_call, $functions)) |
|
4393 | - return; |
|
4638 | + if (in_array($integration_call, $functions)) { |
|
4639 | + return; |
|
4640 | + } |
|
4394 | 4641 | |
4395 | 4642 | $functions[] = $integration_call; |
4396 | 4643 | $modSettings[$hook] = implode(',', $functions); |
@@ -4413,12 +4660,14 @@ discard block |
||
4413 | 4660 | global $smcFunc, $modSettings; |
4414 | 4661 | |
4415 | 4662 | // Any objects? |
4416 | - if ($object) |
|
4417 | - $function = $function . '#'; |
|
4663 | + if ($object) { |
|
4664 | + $function = $function . '#'; |
|
4665 | + } |
|
4418 | 4666 | |
4419 | 4667 | // Any files to load? |
4420 | - if (!empty($file) && is_string($file)) |
|
4421 | - $function = $file . '|' . $function; |
|
4668 | + if (!empty($file) && is_string($file)) { |
|
4669 | + $function = $file . '|' . $function; |
|
4670 | + } |
|
4422 | 4671 | |
4423 | 4672 | // Get the correct string. |
4424 | 4673 | $integration_call = $function; |
@@ -4439,16 +4688,18 @@ discard block |
||
4439 | 4688 | { |
4440 | 4689 | $current_functions = explode(',', $current_functions); |
4441 | 4690 | |
4442 | - if (in_array($integration_call, $current_functions)) |
|
4443 | - updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call))))); |
|
4691 | + if (in_array($integration_call, $current_functions)) { |
|
4692 | + updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call))))); |
|
4693 | + } |
|
4444 | 4694 | } |
4445 | 4695 | |
4446 | 4696 | // Turn the function list into something usable. |
4447 | 4697 | $functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]); |
4448 | 4698 | |
4449 | 4699 | // You can only remove it if it's available. |
4450 | - if (!in_array($integration_call, $functions)) |
|
4451 | - return; |
|
4700 | + if (!in_array($integration_call, $functions)) { |
|
4701 | + return; |
|
4702 | + } |
|
4452 | 4703 | |
4453 | 4704 | $functions = array_diff($functions, array($integration_call)); |
4454 | 4705 | $modSettings[$hook] = implode(',', $functions); |
@@ -4469,17 +4720,20 @@ discard block |
||
4469 | 4720 | global $context, $smcFunc, $txt, $db_show_debug; |
4470 | 4721 | |
4471 | 4722 | // Really? |
4472 | - if (empty($string)) |
|
4473 | - return false; |
|
4723 | + if (empty($string)) { |
|
4724 | + return false; |
|
4725 | + } |
|
4474 | 4726 | |
4475 | 4727 | // An array? should be a "callable" array IE array(object/class, valid_callable). |
4476 | 4728 | // A closure? should be a callable one. |
4477 | - if (is_array($string) || $string instanceof Closure) |
|
4478 | - return $return ? $string : (is_callable($string) ? call_user_func($string) : false); |
|
4729 | + if (is_array($string) || $string instanceof Closure) { |
|
4730 | + return $return ? $string : (is_callable($string) ? call_user_func($string) : false); |
|
4731 | + } |
|
4479 | 4732 | |
4480 | 4733 | // No full objects, sorry! pass a method or a property instead! |
4481 | - if (is_object($string)) |
|
4482 | - return false; |
|
4734 | + if (is_object($string)) { |
|
4735 | + return false; |
|
4736 | + } |
|
4483 | 4737 | |
4484 | 4738 | // Stay vitaminized my friends... |
4485 | 4739 | $string = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($string)); |
@@ -4488,8 +4742,9 @@ discard block |
||
4488 | 4742 | $string = load_file($string); |
4489 | 4743 | |
4490 | 4744 | // Loaded file failed |
4491 | - if (empty($string)) |
|
4492 | - return false; |
|
4745 | + if (empty($string)) { |
|
4746 | + return false; |
|
4747 | + } |
|
4493 | 4748 | |
4494 | 4749 | // Found a method. |
4495 | 4750 | if (strpos($string, '::') !== false) |
@@ -4510,8 +4765,9 @@ discard block |
||
4510 | 4765 | // Add another one to the list. |
4511 | 4766 | if ($db_show_debug === true) |
4512 | 4767 | { |
4513 | - if (!isset($context['debug']['instances'])) |
|
4514 | - $context['debug']['instances'] = array(); |
|
4768 | + if (!isset($context['debug']['instances'])) { |
|
4769 | + $context['debug']['instances'] = array(); |
|
4770 | + } |
|
4515 | 4771 | |
4516 | 4772 | $context['debug']['instances'][$class] = $class; |
4517 | 4773 | } |
@@ -4521,13 +4777,15 @@ discard block |
||
4521 | 4777 | } |
4522 | 4778 | |
4523 | 4779 | // Right then. This is a call to a static method. |
4524 | - else |
|
4525 | - $func = array($class, $method); |
|
4780 | + else { |
|
4781 | + $func = array($class, $method); |
|
4782 | + } |
|
4526 | 4783 | } |
4527 | 4784 | |
4528 | 4785 | // Nope! just a plain regular function. |
4529 | - else |
|
4530 | - $func = $string; |
|
4786 | + else { |
|
4787 | + $func = $string; |
|
4788 | + } |
|
4531 | 4789 | |
4532 | 4790 | // Right, we got what we need, time to do some checks. |
4533 | 4791 | if (!is_callable($func, false, $callable_name)) |
@@ -4543,17 +4801,18 @@ discard block |
||
4543 | 4801 | else |
4544 | 4802 | { |
4545 | 4803 | // What are we gonna do about it? |
4546 | - if ($return) |
|
4547 | - return $func; |
|
4804 | + if ($return) { |
|
4805 | + return $func; |
|
4806 | + } |
|
4548 | 4807 | |
4549 | 4808 | // If this is a plain function, avoid the heat of calling call_user_func(). |
4550 | 4809 | else |
4551 | 4810 | { |
4552 | - if (is_array($func)) |
|
4553 | - call_user_func($func); |
|
4554 | - |
|
4555 | - else |
|
4556 | - $func(); |
|
4811 | + if (is_array($func)) { |
|
4812 | + call_user_func($func); |
|
4813 | + } else { |
|
4814 | + $func(); |
|
4815 | + } |
|
4557 | 4816 | } |
4558 | 4817 | } |
4559 | 4818 | } |
@@ -4570,31 +4829,34 @@ discard block |
||
4570 | 4829 | { |
4571 | 4830 | global $sourcedir, $txt, $boarddir, $settings; |
4572 | 4831 | |
4573 | - if (empty($string)) |
|
4574 | - return false; |
|
4832 | + if (empty($string)) { |
|
4833 | + return false; |
|
4834 | + } |
|
4575 | 4835 | |
4576 | 4836 | if (strpos($string, '|') !== false) |
4577 | 4837 | { |
4578 | 4838 | list ($file, $string) = explode('|', $string); |
4579 | 4839 | |
4580 | 4840 | // Match the wildcards to their regular vars. |
4581 | - if (empty($settings['theme_dir'])) |
|
4582 | - $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
|
4583 | - |
|
4584 | - else |
|
4585 | - $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
|
4841 | + if (empty($settings['theme_dir'])) { |
|
4842 | + $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
|
4843 | + } else { |
|
4844 | + $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
|
4845 | + } |
|
4586 | 4846 | |
4587 | 4847 | // Load the file if it can be loaded. |
4588 | - if (file_exists($absPath)) |
|
4589 | - require_once($absPath); |
|
4848 | + if (file_exists($absPath)) { |
|
4849 | + require_once($absPath); |
|
4850 | + } |
|
4590 | 4851 | |
4591 | 4852 | // No? try a fallback to $sourcedir |
4592 | 4853 | else |
4593 | 4854 | { |
4594 | 4855 | $absPath = $sourcedir .'/'. $file; |
4595 | 4856 | |
4596 | - if (file_exists($absPath)) |
|
4597 | - require_once($absPath); |
|
4857 | + if (file_exists($absPath)) { |
|
4858 | + require_once($absPath); |
|
4859 | + } |
|
4598 | 4860 | |
4599 | 4861 | // Sorry, can't do much for you at this point. |
4600 | 4862 | else |
@@ -4621,8 +4883,9 @@ discard block |
||
4621 | 4883 | global $user_info, $smcFunc; |
4622 | 4884 | |
4623 | 4885 | // Make sure we have something to work with. |
4624 | - if (empty($topic)) |
|
4625 | - return array(); |
|
4886 | + if (empty($topic)) { |
|
4887 | + return array(); |
|
4888 | + } |
|
4626 | 4889 | |
4627 | 4890 | |
4628 | 4891 | // We already know the number of likes per message, we just want to know whether the current user liked it or not. |
@@ -4645,8 +4908,9 @@ discard block |
||
4645 | 4908 | 'topic' => $topic, |
4646 | 4909 | ) |
4647 | 4910 | ); |
4648 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
4649 | - $temp[] = (int) $row['content_id']; |
|
4911 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
4912 | + $temp[] = (int) $row['content_id']; |
|
4913 | + } |
|
4650 | 4914 | |
4651 | 4915 | cache_put_data($cache_key, $temp, $ttl); |
4652 | 4916 | } |
@@ -4667,8 +4931,9 @@ discard block |
||
4667 | 4931 | { |
4668 | 4932 | global $context; |
4669 | 4933 | |
4670 | - if (empty($string)) |
|
4671 | - return $string; |
|
4934 | + if (empty($string)) { |
|
4935 | + return $string; |
|
4936 | + } |
|
4672 | 4937 | |
4673 | 4938 | // UTF-8 occurences of MS special characters |
4674 | 4939 | $findchars_utf8 = array( |
@@ -4709,10 +4974,11 @@ discard block |
||
4709 | 4974 | '--', // — |
4710 | 4975 | ); |
4711 | 4976 | |
4712 | - if ($context['utf8']) |
|
4713 | - $string = str_replace($findchars_utf8, $replacechars, $string); |
|
4714 | - else |
|
4715 | - $string = str_replace($findchars_iso, $replacechars, $string); |
|
4977 | + if ($context['utf8']) { |
|
4978 | + $string = str_replace($findchars_utf8, $replacechars, $string); |
|
4979 | + } else { |
|
4980 | + $string = str_replace($findchars_iso, $replacechars, $string); |
|
4981 | + } |
|
4716 | 4982 | |
4717 | 4983 | return $string; |
4718 | 4984 | } |
@@ -4731,49 +4997,59 @@ discard block |
||
4731 | 4997 | { |
4732 | 4998 | global $context; |
4733 | 4999 | |
4734 | - if (!isset($matches[2])) |
|
4735 | - return ''; |
|
5000 | + if (!isset($matches[2])) { |
|
5001 | + return ''; |
|
5002 | + } |
|
4736 | 5003 | |
4737 | 5004 | $num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2]; |
4738 | 5005 | |
4739 | 5006 | // remove left to right / right to left overrides |
4740 | - if ($num === 0x202D || $num === 0x202E) |
|
4741 | - return ''; |
|
5007 | + if ($num === 0x202D || $num === 0x202E) { |
|
5008 | + return ''; |
|
5009 | + } |
|
4742 | 5010 | |
4743 | 5011 | // Quote, Ampersand, Apostrophe, Less/Greater Than get html replaced |
4744 | - if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) |
|
4745 | - return '&#' . $num . ';'; |
|
5012 | + if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) { |
|
5013 | + return '&#' . $num . ';'; |
|
5014 | + } |
|
4746 | 5015 | |
4747 | 5016 | if (empty($context['utf8'])) |
4748 | 5017 | { |
4749 | 5018 | // no control characters |
4750 | - if ($num < 0x20) |
|
4751 | - return ''; |
|
5019 | + if ($num < 0x20) { |
|
5020 | + return ''; |
|
5021 | + } |
|
4752 | 5022 | // text is text |
4753 | - elseif ($num < 0x80) |
|
4754 | - return chr($num); |
|
5023 | + elseif ($num < 0x80) { |
|
5024 | + return chr($num); |
|
5025 | + } |
|
4755 | 5026 | // all others get html-ised |
4756 | - else |
|
4757 | - return '&#' . $matches[2] . ';'; |
|
4758 | - } |
|
4759 | - else |
|
5027 | + else { |
|
5028 | + return '&#' . $matches[2] . ';'; |
|
5029 | + } |
|
5030 | + } else |
|
4760 | 5031 | { |
4761 | 5032 | // <0x20 are control characters, 0x20 is a space, > 0x10FFFF is past the end of the utf8 character set |
4762 | 5033 | // 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text) |
4763 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) |
|
4764 | - return ''; |
|
5034 | + if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) { |
|
5035 | + return ''; |
|
5036 | + } |
|
4765 | 5037 | // <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation |
4766 | - elseif ($num < 0x80) |
|
4767 | - return chr($num); |
|
5038 | + elseif ($num < 0x80) { |
|
5039 | + return chr($num); |
|
5040 | + } |
|
4768 | 5041 | // <0x800 (2048) |
4769 | - elseif ($num < 0x800) |
|
4770 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
5042 | + elseif ($num < 0x800) { |
|
5043 | + return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
5044 | + } |
|
4771 | 5045 | // < 0x10000 (65536) |
4772 | - elseif ($num < 0x10000) |
|
4773 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5046 | + elseif ($num < 0x10000) { |
|
5047 | + return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5048 | + } |
|
4774 | 5049 | // <= 0x10FFFF (1114111) |
4775 | - else |
|
4776 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5050 | + else { |
|
5051 | + return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5052 | + } |
|
4777 | 5053 | } |
4778 | 5054 | } |
4779 | 5055 | |
@@ -4789,28 +5065,34 @@ discard block |
||
4789 | 5065 | */ |
4790 | 5066 | function fixchar__callback($matches) |
4791 | 5067 | { |
4792 | - if (!isset($matches[1])) |
|
4793 | - return ''; |
|
5068 | + if (!isset($matches[1])) { |
|
5069 | + return ''; |
|
5070 | + } |
|
4794 | 5071 | |
4795 | 5072 | $num = $matches[1][0] === 'x' ? hexdec(substr($matches[1], 1)) : (int) $matches[1]; |
4796 | 5073 | |
4797 | 5074 | // <0x20 are control characters, > 0x10FFFF is past the end of the utf8 character set |
4798 | 5075 | // 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text), 0x202D-E are left to right overrides |
4799 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) |
|
4800 | - return ''; |
|
5076 | + if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) { |
|
5077 | + return ''; |
|
5078 | + } |
|
4801 | 5079 | // <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation |
4802 | - elseif ($num < 0x80) |
|
4803 | - return chr($num); |
|
5080 | + elseif ($num < 0x80) { |
|
5081 | + return chr($num); |
|
5082 | + } |
|
4804 | 5083 | // <0x800 (2048) |
4805 | - elseif ($num < 0x800) |
|
4806 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
5084 | + elseif ($num < 0x800) { |
|
5085 | + return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
5086 | + } |
|
4807 | 5087 | // < 0x10000 (65536) |
4808 | - elseif ($num < 0x10000) |
|
4809 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5088 | + elseif ($num < 0x10000) { |
|
5089 | + return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5090 | + } |
|
4810 | 5091 | // <= 0x10FFFF (1114111) |
4811 | - else |
|
4812 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
4813 | -} |
|
5092 | + else { |
|
5093 | + return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5094 | + } |
|
5095 | + } |
|
4814 | 5096 | |
4815 | 5097 | /** |
4816 | 5098 | * Strips out invalid html entities, replaces others with html style { codes |
@@ -4823,17 +5105,19 @@ discard block |
||
4823 | 5105 | */ |
4824 | 5106 | function entity_fix__callback($matches) |
4825 | 5107 | { |
4826 | - if (!isset($matches[2])) |
|
4827 | - return ''; |
|
5108 | + if (!isset($matches[2])) { |
|
5109 | + return ''; |
|
5110 | + } |
|
4828 | 5111 | |
4829 | 5112 | $num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2]; |
4830 | 5113 | |
4831 | 5114 | // we don't allow control characters, characters out of range, byte markers, etc |
4832 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) |
|
4833 | - return ''; |
|
4834 | - else |
|
4835 | - return '&#' . $num . ';'; |
|
4836 | -} |
|
5115 | + if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) { |
|
5116 | + return ''; |
|
5117 | + } else { |
|
5118 | + return '&#' . $num . ';'; |
|
5119 | + } |
|
5120 | + } |
|
4837 | 5121 | |
4838 | 5122 | /** |
4839 | 5123 | * Return a Gravatar URL based on |
@@ -4857,18 +5141,23 @@ discard block |
||
4857 | 5141 | $ratings = array('G', 'PG', 'R', 'X'); |
4858 | 5142 | $defaults = array('mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank'); |
4859 | 5143 | $url_params = array(); |
4860 | - if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) |
|
4861 | - $url_params[] = 'rating=' . $modSettings['gravatarMaxRating']; |
|
4862 | - if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) |
|
4863 | - $url_params[] = 'default=' . $modSettings['gravatarDefault']; |
|
4864 | - if (!empty($modSettings['avatar_max_width_external'])) |
|
4865 | - $size_string = (int) $modSettings['avatar_max_width_external']; |
|
4866 | - if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) |
|
4867 | - if ((int) $modSettings['avatar_max_height_external'] < $size_string) |
|
5144 | + if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) { |
|
5145 | + $url_params[] = 'rating=' . $modSettings['gravatarMaxRating']; |
|
5146 | + } |
|
5147 | + if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) { |
|
5148 | + $url_params[] = 'default=' . $modSettings['gravatarDefault']; |
|
5149 | + } |
|
5150 | + if (!empty($modSettings['avatar_max_width_external'])) { |
|
5151 | + $size_string = (int) $modSettings['avatar_max_width_external']; |
|
5152 | + } |
|
5153 | + if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) { |
|
5154 | + if ((int) $modSettings['avatar_max_height_external'] < $size_string) |
|
4868 | 5155 | $size_string = $modSettings['avatar_max_height_external']; |
5156 | + } |
|
4869 | 5157 | |
4870 | - if (!empty($size_string)) |
|
4871 | - $url_params[] = 's=' . $size_string; |
|
5158 | + if (!empty($size_string)) { |
|
5159 | + $url_params[] = 's=' . $size_string; |
|
5160 | + } |
|
4872 | 5161 | } |
4873 | 5162 | $http_method = !empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 ? 'https://secure' : 'http://www'; |
4874 | 5163 | |
@@ -4887,22 +5176,26 @@ discard block |
||
4887 | 5176 | static $timezones = null, $lastwhen = null; |
4888 | 5177 | |
4889 | 5178 | // No point doing this over if we already did it once |
4890 | - if (!empty($timezones) && $when == $lastwhen) |
|
4891 | - return $timezones; |
|
4892 | - else |
|
4893 | - $lastwhen = $when; |
|
5179 | + if (!empty($timezones) && $when == $lastwhen) { |
|
5180 | + return $timezones; |
|
5181 | + } else { |
|
5182 | + $lastwhen = $when; |
|
5183 | + } |
|
4894 | 5184 | |
4895 | 5185 | // Parseable datetime string? |
4896 | - if (is_int($timestamp = strtotime($when))) |
|
4897 | - $when = $timestamp; |
|
5186 | + if (is_int($timestamp = strtotime($when))) { |
|
5187 | + $when = $timestamp; |
|
5188 | + } |
|
4898 | 5189 | |
4899 | 5190 | // A Unix timestamp? |
4900 | - elseif (is_numeric($when)) |
|
4901 | - $when = intval($when); |
|
5191 | + elseif (is_numeric($when)) { |
|
5192 | + $when = intval($when); |
|
5193 | + } |
|
4902 | 5194 | |
4903 | 5195 | // Invalid value? Just get current Unix timestamp. |
4904 | - else |
|
4905 | - $when = time(); |
|
5196 | + else { |
|
5197 | + $when = time(); |
|
5198 | + } |
|
4906 | 5199 | |
4907 | 5200 | // We'll need this too |
4908 | 5201 | $later = (int) date_format(date_add(date_create('@' . $when), date_interval_create_from_date_string('1 year')), 'U'); |
@@ -4965,8 +5258,9 @@ discard block |
||
4965 | 5258 | foreach ($priority_countries as $country) |
4966 | 5259 | { |
4967 | 5260 | $country_tzids = @timezone_identifiers_list(DateTimeZone::PER_COUNTRY, strtoupper(trim($country))); |
4968 | - if (!empty($country_tzids)) |
|
4969 | - $priority_tzids = array_merge($priority_tzids, $country_tzids); |
|
5261 | + if (!empty($country_tzids)) { |
|
5262 | + $priority_tzids = array_merge($priority_tzids, $country_tzids); |
|
5263 | + } |
|
4970 | 5264 | } |
4971 | 5265 | |
4972 | 5266 | // Process the preferred timezones first, then the rest. |
@@ -4976,8 +5270,9 @@ discard block |
||
4976 | 5270 | foreach ($tzids as $tzid) |
4977 | 5271 | { |
4978 | 5272 | // We don't want UTC right now |
4979 | - if ($tzid == 'UTC') |
|
4980 | - continue; |
|
5273 | + if ($tzid == 'UTC') { |
|
5274 | + continue; |
|
5275 | + } |
|
4981 | 5276 | |
4982 | 5277 | // First, get the set of transition rules for this tzid |
4983 | 5278 | $tzinfo = timezone_transitions_get(timezone_open($tzid), $when, $later); |
@@ -4988,8 +5283,9 @@ discard block |
||
4988 | 5283 | $tz_location = timezone_location_get(timezone_open($tzid)); |
4989 | 5284 | |
4990 | 5285 | // Kazakstan |
4991 | - if ($tz_location['country_code'] == 'KZ') |
|
4992 | - $tzinfo[0]['abbr'] = str_replace(array('+05', '+06'), array('AQTT', 'ALMT'), $tzinfo[0]['abbr']); |
|
5286 | + if ($tz_location['country_code'] == 'KZ') { |
|
5287 | + $tzinfo[0]['abbr'] = str_replace(array('+05', '+06'), array('AQTT', 'ALMT'), $tzinfo[0]['abbr']); |
|
5288 | + } |
|
4993 | 5289 | |
4994 | 5290 | // Russia likes to experiment with time zones |
4995 | 5291 | if ($tz_location['country_code'] == 'RU') |
@@ -5000,19 +5296,22 @@ discard block |
||
5000 | 5296 | } |
5001 | 5297 | |
5002 | 5298 | // Still no good? We'll just mark it as a UTC offset |
5003 | - if (strspn($tzinfo[0]['abbr'], '+-') > 0) |
|
5004 | - $tzinfo[0]['abbr'] = 'UTC' . $tzinfo[0]['abbr']; |
|
5299 | + if (strspn($tzinfo[0]['abbr'], '+-') > 0) { |
|
5300 | + $tzinfo[0]['abbr'] = 'UTC' . $tzinfo[0]['abbr']; |
|
5301 | + } |
|
5005 | 5302 | } |
5006 | 5303 | |
5007 | 5304 | $tzkey = serialize($tzinfo); |
5008 | 5305 | |
5009 | 5306 | // Don't overwrite our preferred tzids |
5010 | - if (empty($zones[$tzkey]['tzid'])) |
|
5011 | - $zones[$tzkey]['tzid'] = $tzid; |
|
5307 | + if (empty($zones[$tzkey]['tzid'])) { |
|
5308 | + $zones[$tzkey]['tzid'] = $tzid; |
|
5309 | + } |
|
5012 | 5310 | |
5013 | 5311 | // A time zone from a prioritized country? |
5014 | - if (in_array($tzid, $priority_tzids)) |
|
5015 | - $priority_zones[$tzkey] = true; |
|
5312 | + if (in_array($tzid, $priority_tzids)) { |
|
5313 | + $priority_zones[$tzkey] = true; |
|
5314 | + } |
|
5016 | 5315 | |
5017 | 5316 | // Keep track of the location and offset for this tzid |
5018 | 5317 | $tzid_parts = explode('/', $tzid); |
@@ -5030,15 +5329,17 @@ discard block |
||
5030 | 5329 | { |
5031 | 5330 | $tzinfo = unserialize($tzkey); |
5032 | 5331 | |
5033 | - if (!empty($timezone_descriptions[$tzvalue['tzid']])) |
|
5034 | - $desc = $timezone_descriptions[$tzvalue['tzid']]; |
|
5035 | - else |
|
5036 | - $desc = implode(', ', array_unique($tzvalue['locations'])); |
|
5332 | + if (!empty($timezone_descriptions[$tzvalue['tzid']])) { |
|
5333 | + $desc = $timezone_descriptions[$tzvalue['tzid']]; |
|
5334 | + } else { |
|
5335 | + $desc = implode(', ', array_unique($tzvalue['locations'])); |
|
5336 | + } |
|
5037 | 5337 | |
5038 | - if (isset($priority_zones[$tzkey])) |
|
5039 | - $priority_timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format(date_create($tzvalue['tzid']), 'P') . ']'; |
|
5040 | - else |
|
5041 | - $timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format(date_create($tzvalue['tzid']), 'P') . ']'; |
|
5338 | + if (isset($priority_zones[$tzkey])) { |
|
5339 | + $priority_timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format(date_create($tzvalue['tzid']), 'P') . ']'; |
|
5340 | + } else { |
|
5341 | + $timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format(date_create($tzvalue['tzid']), 'P') . ']'; |
|
5342 | + } |
|
5042 | 5343 | } |
5043 | 5344 | |
5044 | 5345 | $timezones = array_merge( |
@@ -5056,8 +5357,9 @@ discard block |
||
5056 | 5357 | */ |
5057 | 5358 | function inet_ptod($ip_address) |
5058 | 5359 | { |
5059 | - if (!isValidIP($ip_address)) |
|
5060 | - return $ip_address; |
|
5360 | + if (!isValidIP($ip_address)) { |
|
5361 | + return $ip_address; |
|
5362 | + } |
|
5061 | 5363 | |
5062 | 5364 | $bin = inet_pton($ip_address); |
5063 | 5365 | return $bin; |
@@ -5069,13 +5371,15 @@ discard block |
||
5069 | 5371 | */ |
5070 | 5372 | function inet_dtop($bin) |
5071 | 5373 | { |
5072 | - if(empty($bin)) |
|
5073 | - return ''; |
|
5374 | + if(empty($bin)) { |
|
5375 | + return ''; |
|
5376 | + } |
|
5074 | 5377 | |
5075 | 5378 | global $db_type; |
5076 | 5379 | |
5077 | - if ($db_type == 'postgresql') |
|
5078 | - return $bin; |
|
5380 | + if ($db_type == 'postgresql') { |
|
5381 | + return $bin; |
|
5382 | + } |
|
5079 | 5383 | |
5080 | 5384 | $ip_address = inet_ntop($bin); |
5081 | 5385 | |
@@ -5100,26 +5404,32 @@ discard block |
||
5100 | 5404 | */ |
5101 | 5405 | function _safe_serialize($value) |
5102 | 5406 | { |
5103 | - if(is_null($value)) |
|
5104 | - return 'N;'; |
|
5407 | + if(is_null($value)) { |
|
5408 | + return 'N;'; |
|
5409 | + } |
|
5105 | 5410 | |
5106 | - if(is_bool($value)) |
|
5107 | - return 'b:'. (int) $value .';'; |
|
5411 | + if(is_bool($value)) { |
|
5412 | + return 'b:'. (int) $value .';'; |
|
5413 | + } |
|
5108 | 5414 | |
5109 | - if(is_int($value)) |
|
5110 | - return 'i:'. $value .';'; |
|
5415 | + if(is_int($value)) { |
|
5416 | + return 'i:'. $value .';'; |
|
5417 | + } |
|
5111 | 5418 | |
5112 | - if(is_float($value)) |
|
5113 | - return 'd:'. str_replace(',', '.', $value) .';'; |
|
5419 | + if(is_float($value)) { |
|
5420 | + return 'd:'. str_replace(',', '.', $value) .';'; |
|
5421 | + } |
|
5114 | 5422 | |
5115 | - if(is_string($value)) |
|
5116 | - return 's:'. strlen($value) .':"'. $value .'";'; |
|
5423 | + if(is_string($value)) { |
|
5424 | + return 's:'. strlen($value) .':"'. $value .'";'; |
|
5425 | + } |
|
5117 | 5426 | |
5118 | 5427 | if(is_array($value)) |
5119 | 5428 | { |
5120 | 5429 | $out = ''; |
5121 | - foreach($value as $k => $v) |
|
5122 | - $out .= _safe_serialize($k) . _safe_serialize($v); |
|
5430 | + foreach($value as $k => $v) { |
|
5431 | + $out .= _safe_serialize($k) . _safe_serialize($v); |
|
5432 | + } |
|
5123 | 5433 | |
5124 | 5434 | return 'a:'. count($value) .':{'. $out .'}'; |
5125 | 5435 | } |
@@ -5145,8 +5455,9 @@ discard block |
||
5145 | 5455 | |
5146 | 5456 | $out = _safe_serialize($value); |
5147 | 5457 | |
5148 | - if (isset($mbIntEnc)) |
|
5149 | - mb_internal_encoding($mbIntEnc); |
|
5458 | + if (isset($mbIntEnc)) { |
|
5459 | + mb_internal_encoding($mbIntEnc); |
|
5460 | + } |
|
5150 | 5461 | |
5151 | 5462 | return $out; |
5152 | 5463 | } |
@@ -5163,8 +5474,9 @@ discard block |
||
5163 | 5474 | function _safe_unserialize($str) |
5164 | 5475 | { |
5165 | 5476 | // Input is not a string. |
5166 | - if(empty($str) || !is_string($str)) |
|
5167 | - return false; |
|
5477 | + if(empty($str) || !is_string($str)) { |
|
5478 | + return false; |
|
5479 | + } |
|
5168 | 5480 | |
5169 | 5481 | $stack = array(); |
5170 | 5482 | $expected = array(); |
@@ -5180,43 +5492,38 @@ discard block |
||
5180 | 5492 | while($state != 1) |
5181 | 5493 | { |
5182 | 5494 | $type = isset($str[0]) ? $str[0] : ''; |
5183 | - if($type == '}') |
|
5184 | - $str = substr($str, 1); |
|
5185 | - |
|
5186 | - else if($type == 'N' && $str[1] == ';') |
|
5495 | + if($type == '}') { |
|
5496 | + $str = substr($str, 1); |
|
5497 | + } else if($type == 'N' && $str[1] == ';') |
|
5187 | 5498 | { |
5188 | 5499 | $value = null; |
5189 | 5500 | $str = substr($str, 2); |
5190 | - } |
|
5191 | - else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches)) |
|
5501 | + } else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches)) |
|
5192 | 5502 | { |
5193 | 5503 | $value = $matches[1] == '1' ? true : false; |
5194 | 5504 | $str = substr($str, 4); |
5195 | - } |
|
5196 | - else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches)) |
|
5505 | + } else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches)) |
|
5197 | 5506 | { |
5198 | 5507 | $value = (int)$matches[1]; |
5199 | 5508 | $str = $matches[2]; |
5200 | - } |
|
5201 | - else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches)) |
|
5509 | + } else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches)) |
|
5202 | 5510 | { |
5203 | 5511 | $value = (float)$matches[1]; |
5204 | 5512 | $str = $matches[3]; |
5205 | - } |
|
5206 | - else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";') |
|
5513 | + } else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";') |
|
5207 | 5514 | { |
5208 | 5515 | $value = substr($matches[2], 0, (int)$matches[1]); |
5209 | 5516 | $str = substr($matches[2], (int)$matches[1] + 2); |
5210 | - } |
|
5211 | - else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches)) |
|
5517 | + } else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches)) |
|
5212 | 5518 | { |
5213 | 5519 | $expectedLength = (int)$matches[1]; |
5214 | 5520 | $str = $matches[2]; |
5215 | 5521 | } |
5216 | 5522 | |
5217 | 5523 | // Object or unknown/malformed type. |
5218 | - else |
|
5219 | - return false; |
|
5524 | + else { |
|
5525 | + return false; |
|
5526 | + } |
|
5220 | 5527 | |
5221 | 5528 | switch($state) |
5222 | 5529 | { |
@@ -5244,8 +5551,9 @@ discard block |
||
5244 | 5551 | if($type == '}') |
5245 | 5552 | { |
5246 | 5553 | // Array size is less than expected. |
5247 | - if(count($list) < end($expected)) |
|
5248 | - return false; |
|
5554 | + if(count($list) < end($expected)) { |
|
5555 | + return false; |
|
5556 | + } |
|
5249 | 5557 | |
5250 | 5558 | unset($list); |
5251 | 5559 | $list = &$stack[count($stack)-1]; |
@@ -5254,8 +5562,9 @@ discard block |
||
5254 | 5562 | // Go to terminal state if we're at the end of the root array. |
5255 | 5563 | array_pop($expected); |
5256 | 5564 | |
5257 | - if(count($expected) == 0) |
|
5258 | - $state = 1; |
|
5565 | + if(count($expected) == 0) { |
|
5566 | + $state = 1; |
|
5567 | + } |
|
5259 | 5568 | |
5260 | 5569 | break; |
5261 | 5570 | } |
@@ -5263,8 +5572,9 @@ discard block |
||
5263 | 5572 | if($type == 'i' || $type == 's') |
5264 | 5573 | { |
5265 | 5574 | // Array size exceeds expected length. |
5266 | - if(count($list) >= end($expected)) |
|
5267 | - return false; |
|
5575 | + if(count($list) >= end($expected)) { |
|
5576 | + return false; |
|
5577 | + } |
|
5268 | 5578 | |
5269 | 5579 | $key = $value; |
5270 | 5580 | $state = 3; |
@@ -5298,8 +5608,9 @@ discard block |
||
5298 | 5608 | } |
5299 | 5609 | |
5300 | 5610 | // Trailing data in input. |
5301 | - if(!empty($str)) |
|
5302 | - return false; |
|
5611 | + if(!empty($str)) { |
|
5612 | + return false; |
|
5613 | + } |
|
5303 | 5614 | |
5304 | 5615 | return $data; |
5305 | 5616 | } |
@@ -5322,8 +5633,9 @@ discard block |
||
5322 | 5633 | |
5323 | 5634 | $out = _safe_unserialize($str); |
5324 | 5635 | |
5325 | - if (isset($mbIntEnc)) |
|
5326 | - mb_internal_encoding($mbIntEnc); |
|
5636 | + if (isset($mbIntEnc)) { |
|
5637 | + mb_internal_encoding($mbIntEnc); |
|
5638 | + } |
|
5327 | 5639 | |
5328 | 5640 | return $out; |
5329 | 5641 | } |
@@ -5338,12 +5650,14 @@ discard block |
||
5338 | 5650 | function smf_chmod($file, $value = 0) |
5339 | 5651 | { |
5340 | 5652 | // No file? no checks! |
5341 | - if (empty($file)) |
|
5342 | - return false; |
|
5653 | + if (empty($file)) { |
|
5654 | + return false; |
|
5655 | + } |
|
5343 | 5656 | |
5344 | 5657 | // Already writable? |
5345 | - if (is_writable($file)) |
|
5346 | - return true; |
|
5658 | + if (is_writable($file)) { |
|
5659 | + return true; |
|
5660 | + } |
|
5347 | 5661 | |
5348 | 5662 | // Do we have a file or a dir? |
5349 | 5663 | $isDir = is_dir($file); |
@@ -5359,10 +5673,9 @@ discard block |
||
5359 | 5673 | { |
5360 | 5674 | $isWritable = true; |
5361 | 5675 | break; |
5676 | + } else { |
|
5677 | + @chmod($file, $val); |
|
5362 | 5678 | } |
5363 | - |
|
5364 | - else |
|
5365 | - @chmod($file, $val); |
|
5366 | 5679 | } |
5367 | 5680 | |
5368 | 5681 | return $isWritable; |
@@ -5381,8 +5694,9 @@ discard block |
||
5381 | 5694 | global $txt; |
5382 | 5695 | |
5383 | 5696 | // Come on... |
5384 | - if (empty($json) || !is_string($json)) |
|
5385 | - return array(); |
|
5697 | + if (empty($json) || !is_string($json)) { |
|
5698 | + return array(); |
|
5699 | + } |
|
5386 | 5700 | |
5387 | 5701 | $returnArray = @json_decode($json, $returnAsArray); |
5388 | 5702 | |
@@ -5420,11 +5734,11 @@ discard block |
||
5420 | 5734 | $jsonDebug = $jsonDebug[0]; |
5421 | 5735 | loadLanguage('Errors'); |
5422 | 5736 | |
5423 | - if (!empty($jsonDebug)) |
|
5424 | - log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']); |
|
5425 | - |
|
5426 | - else |
|
5427 | - log_error($txt['json_'. $jsonError], 'critical'); |
|
5737 | + if (!empty($jsonDebug)) { |
|
5738 | + log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']); |
|
5739 | + } else { |
|
5740 | + log_error($txt['json_'. $jsonError], 'critical'); |
|
5741 | + } |
|
5428 | 5742 | |
5429 | 5743 | // Everyone expects an array. |
5430 | 5744 | return array(); |
@@ -5454,8 +5768,9 @@ discard block |
||
5454 | 5768 | global $db_show_debug, $modSettings; |
5455 | 5769 | |
5456 | 5770 | // Defensive programming anyone? |
5457 | - if (empty($data)) |
|
5458 | - return false; |
|
5771 | + if (empty($data)) { |
|
5772 | + return false; |
|
5773 | + } |
|
5459 | 5774 | |
5460 | 5775 | // Don't need extra stuff... |
5461 | 5776 | $db_show_debug = false; |
@@ -5463,11 +5778,11 @@ discard block |
||
5463 | 5778 | // Kill anything else. |
5464 | 5779 | ob_end_clean(); |
5465 | 5780 | |
5466 | - if (!empty($modSettings['CompressedOutput'])) |
|
5467 | - @ob_start('ob_gzhandler'); |
|
5468 | - |
|
5469 | - else |
|
5470 | - ob_start(); |
|
5781 | + if (!empty($modSettings['CompressedOutput'])) { |
|
5782 | + @ob_start('ob_gzhandler'); |
|
5783 | + } else { |
|
5784 | + ob_start(); |
|
5785 | + } |
|
5471 | 5786 | |
5472 | 5787 | // Set the header. |
5473 | 5788 | header($type); |
@@ -5499,8 +5814,9 @@ discard block |
||
5499 | 5814 | static $done = false; |
5500 | 5815 | |
5501 | 5816 | // If we don't need to do anything, don't |
5502 | - if (!$update && $done) |
|
5503 | - return; |
|
5817 | + if (!$update && $done) { |
|
5818 | + return; |
|
5819 | + } |
|
5504 | 5820 | |
5505 | 5821 | // Should we get a new copy of the official list of TLDs? |
5506 | 5822 | if ($update) |
@@ -5521,10 +5837,11 @@ discard block |
||
5521 | 5837 | // Clean $tlds and convert it to an array |
5522 | 5838 | $tlds = array_filter(explode("\n", strtolower($tlds)), function($line) { |
5523 | 5839 | $line = trim($line); |
5524 | - if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) |
|
5525 | - return false; |
|
5526 | - else |
|
5527 | - return true; |
|
5840 | + if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) { |
|
5841 | + return false; |
|
5842 | + } else { |
|
5843 | + return true; |
|
5844 | + } |
|
5528 | 5845 | }); |
5529 | 5846 | |
5530 | 5847 | // Convert Punycode to Unicode |
@@ -5578,8 +5895,9 @@ discard block |
||
5578 | 5895 | $idx += $digit * $w; |
5579 | 5896 | $t = ($k <= $bias) ? $tmin : (($k >= $bias + $tmax) ? $tmax : ($k - $bias)); |
5580 | 5897 | |
5581 | - if ($digit < $t) |
|
5582 | - break; |
|
5898 | + if ($digit < $t) { |
|
5899 | + break; |
|
5900 | + } |
|
5583 | 5901 | |
5584 | 5902 | $w = (int) ($w * ($base - $t)); |
5585 | 5903 | } |
@@ -5588,8 +5906,9 @@ discard block |
||
5588 | 5906 | $delta = intval($is_first ? ($delta / $damp) : ($delta / 2)); |
5589 | 5907 | $delta += intval($delta / ($deco_len + 1)); |
5590 | 5908 | |
5591 | - for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base) |
|
5592 | - $delta = intval($delta / ($base - $tmin)); |
|
5909 | + for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base) { |
|
5910 | + $delta = intval($delta / ($base - $tmin)); |
|
5911 | + } |
|
5593 | 5912 | |
5594 | 5913 | $bias = intval($k + ($base - $tmin + 1) * $delta / ($delta + $skew)); |
5595 | 5914 | $is_first = false; |
@@ -5598,8 +5917,9 @@ discard block |
||
5598 | 5917 | |
5599 | 5918 | if ($deco_len > 0) |
5600 | 5919 | { |
5601 | - for ($i = $deco_len; $i > $idx; $i--) |
|
5602 | - $decoded[$i] = $decoded[($i - 1)]; |
|
5920 | + for ($i = $deco_len; $i > $idx; $i--) { |
|
5921 | + $decoded[$i] = $decoded[($i - 1)]; |
|
5922 | + } |
|
5603 | 5923 | } |
5604 | 5924 | $decoded[$idx++] = $char; |
5605 | 5925 | } |
@@ -5607,24 +5927,29 @@ discard block |
||
5607 | 5927 | foreach ($decoded as $k => $v) |
5608 | 5928 | { |
5609 | 5929 | // 7bit are transferred literally |
5610 | - if ($v < 128) |
|
5611 | - $output .= chr($v); |
|
5930 | + if ($v < 128) { |
|
5931 | + $output .= chr($v); |
|
5932 | + } |
|
5612 | 5933 | |
5613 | 5934 | // 2 bytes |
5614 | - elseif ($v < (1 << 11)) |
|
5615 | - $output .= chr(192+($v >> 6)) . chr(128+($v & 63)); |
|
5935 | + elseif ($v < (1 << 11)) { |
|
5936 | + $output .= chr(192+($v >> 6)) . chr(128+($v & 63)); |
|
5937 | + } |
|
5616 | 5938 | |
5617 | 5939 | // 3 bytes |
5618 | - elseif ($v < (1 << 16)) |
|
5619 | - $output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
5940 | + elseif ($v < (1 << 16)) { |
|
5941 | + $output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
5942 | + } |
|
5620 | 5943 | |
5621 | 5944 | // 4 bytes |
5622 | - elseif ($v < (1 << 21)) |
|
5623 | - $output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
5945 | + elseif ($v < (1 << 21)) { |
|
5946 | + $output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
5947 | + } |
|
5624 | 5948 | |
5625 | 5949 | // 'Conversion from UCS-4 to UTF-8 failed: malformed input at byte '.$k |
5626 | - else |
|
5627 | - $output .= $safe_char; |
|
5950 | + else { |
|
5951 | + $output .= $safe_char; |
|
5952 | + } |
|
5628 | 5953 | } |
5629 | 5954 | |
5630 | 5955 | $output_parts[] = $output; |
@@ -5719,8 +6044,7 @@ discard block |
||
5719 | 6044 | |
5720 | 6045 | $strlen = 'mb_strlen'; |
5721 | 6046 | $substr = 'mb_substr'; |
5722 | - } |
|
5723 | - else |
|
6047 | + } else |
|
5724 | 6048 | { |
5725 | 6049 | $strlen = $smcFunc['strlen']; |
5726 | 6050 | $substr = $smcFunc['substr']; |
@@ -5734,20 +6058,21 @@ discard block |
||
5734 | 6058 | |
5735 | 6059 | $first = $substr($string, 0, 1); |
5736 | 6060 | |
5737 | - if (empty($index[$first])) |
|
5738 | - $index[$first] = array(); |
|
6061 | + if (empty($index[$first])) { |
|
6062 | + $index[$first] = array(); |
|
6063 | + } |
|
5739 | 6064 | |
5740 | 6065 | if ($strlen($string) > 1) |
5741 | 6066 | { |
5742 | 6067 | // Sanity check on recursion |
5743 | - if ($depth > 99) |
|
5744 | - $index[$first][$substr($string, 1)] = ''; |
|
5745 | - |
|
5746 | - else |
|
5747 | - $index[$first] = $add_string_to_index($substr($string, 1), $index[$first]); |
|
6068 | + if ($depth > 99) { |
|
6069 | + $index[$first][$substr($string, 1)] = ''; |
|
6070 | + } else { |
|
6071 | + $index[$first] = $add_string_to_index($substr($string, 1), $index[$first]); |
|
6072 | + } |
|
6073 | + } else { |
|
6074 | + $index[$first][''] = ''; |
|
5748 | 6075 | } |
5749 | - else |
|
5750 | - $index[$first][''] = ''; |
|
5751 | 6076 | |
5752 | 6077 | $depth--; |
5753 | 6078 | return $index; |
@@ -5770,9 +6095,9 @@ discard block |
||
5770 | 6095 | $key_regex = preg_quote($key, $delim); |
5771 | 6096 | $new_key = $key; |
5772 | 6097 | |
5773 | - if (empty($value)) |
|
5774 | - $sub_regex = ''; |
|
5775 | - else |
|
6098 | + if (empty($value)) { |
|
6099 | + $sub_regex = ''; |
|
6100 | + } else |
|
5776 | 6101 | { |
5777 | 6102 | $sub_regex = $index_to_regex($value, $delim); |
5778 | 6103 | |
@@ -5780,22 +6105,22 @@ discard block |
||
5780 | 6105 | { |
5781 | 6106 | $new_key_array = explode('(?'.'>', $sub_regex); |
5782 | 6107 | $new_key .= $new_key_array[0]; |
6108 | + } else { |
|
6109 | + $sub_regex = '(?'.'>' . $sub_regex . ')'; |
|
5783 | 6110 | } |
5784 | - else |
|
5785 | - $sub_regex = '(?'.'>' . $sub_regex . ')'; |
|
5786 | 6111 | } |
5787 | 6112 | |
5788 | - if ($depth > 1) |
|
5789 | - $regex[$new_key] = $key_regex . $sub_regex; |
|
5790 | - else |
|
6113 | + if ($depth > 1) { |
|
6114 | + $regex[$new_key] = $key_regex . $sub_regex; |
|
6115 | + } else |
|
5791 | 6116 | { |
5792 | 6117 | if (($length += strlen($key_regex) + 1) < $max_length || empty($regex)) |
5793 | 6118 | { |
5794 | 6119 | $regex[$new_key] = $key_regex . $sub_regex; |
5795 | 6120 | unset($index[$key]); |
6121 | + } else { |
|
6122 | + break; |
|
5796 | 6123 | } |
5797 | - else |
|
5798 | - break; |
|
5799 | 6124 | } |
5800 | 6125 | } |
5801 | 6126 | |
@@ -5804,10 +6129,11 @@ discard block |
||
5804 | 6129 | $l1 = $strlen($k1); |
5805 | 6130 | $l2 = $strlen($k2); |
5806 | 6131 | |
5807 | - if ($l1 == $l2) |
|
5808 | - return strcmp($k1, $k2) > 0 ? 1 : -1; |
|
5809 | - else |
|
5810 | - return $l1 > $l2 ? -1 : 1; |
|
6132 | + if ($l1 == $l2) { |
|
6133 | + return strcmp($k1, $k2) > 0 ? 1 : -1; |
|
6134 | + } else { |
|
6135 | + return $l1 > $l2 ? -1 : 1; |
|
6136 | + } |
|
5811 | 6137 | }); |
5812 | 6138 | |
5813 | 6139 | $depth--; |
@@ -5818,15 +6144,18 @@ discard block |
||
5818 | 6144 | $index = array(); |
5819 | 6145 | $regexes = array(); |
5820 | 6146 | |
5821 | - foreach ($strings as $string) |
|
5822 | - $index = $add_string_to_index($string, $index); |
|
6147 | + foreach ($strings as $string) { |
|
6148 | + $index = $add_string_to_index($string, $index); |
|
6149 | + } |
|
5823 | 6150 | |
5824 | - while (!empty($index)) |
|
5825 | - $regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')'; |
|
6151 | + while (!empty($index)) { |
|
6152 | + $regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')'; |
|
6153 | + } |
|
5826 | 6154 | |
5827 | 6155 | // Restore PHP's internal character encoding to whatever it was originally |
5828 | - if (!empty($current_encoding)) |
|
5829 | - mb_internal_encoding($current_encoding); |
|
6156 | + if (!empty($current_encoding)) { |
|
6157 | + mb_internal_encoding($current_encoding); |
|
6158 | + } |
|
5830 | 6159 | |
5831 | 6160 | return $regexes; |
5832 | 6161 | } |