@@ -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 | * The main admin handling function.<br> |
@@ -444,8 +445,9 @@ discard block |
||
| 444 | 445 | foreach ($admin_includes as $include) |
| 445 | 446 | { |
| 446 | 447 | $include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
| 447 | - if (file_exists($include)) |
|
| 448 | - require_once($include); |
|
| 448 | + if (file_exists($include)) { |
|
| 449 | + require_once($include); |
|
| 450 | + } |
|
| 449 | 451 | } |
| 450 | 452 | } |
| 451 | 453 | |
@@ -457,24 +459,27 @@ discard block |
||
| 457 | 459 | unset($admin_areas); |
| 458 | 460 | |
| 459 | 461 | // Nothing valid? |
| 460 | - if ($admin_include_data == false) |
|
| 461 | - fatal_lang_error('no_access', false); |
|
| 462 | + if ($admin_include_data == false) { |
|
| 463 | + fatal_lang_error('no_access', false); |
|
| 464 | + } |
|
| 462 | 465 | |
| 463 | 466 | // Build the link tree. |
| 464 | 467 | $context['linktree'][] = array( |
| 465 | 468 | 'url' => $scripturl . '?action=admin', |
| 466 | 469 | 'name' => $txt['admin_center'], |
| 467 | 470 | ); |
| 468 | - if (isset($admin_include_data['current_area']) && $admin_include_data['current_area'] != 'index') |
|
| 469 | - $context['linktree'][] = array( |
|
| 471 | + if (isset($admin_include_data['current_area']) && $admin_include_data['current_area'] != 'index') { |
|
| 472 | + $context['linktree'][] = array( |
|
| 470 | 473 | 'url' => $scripturl . '?action=admin;area=' . $admin_include_data['current_area'] . ';' . $context['session_var'] . '=' . $context['session_id'], |
| 471 | 474 | 'name' => $admin_include_data['label'], |
| 472 | 475 | ); |
| 473 | - if (!empty($admin_include_data['current_subsection']) && $admin_include_data['subsections'][$admin_include_data['current_subsection']][0] != $admin_include_data['label']) |
|
| 474 | - $context['linktree'][] = array( |
|
| 476 | + } |
|
| 477 | + if (!empty($admin_include_data['current_subsection']) && $admin_include_data['subsections'][$admin_include_data['current_subsection']][0] != $admin_include_data['label']) { |
|
| 478 | + $context['linktree'][] = array( |
|
| 475 | 479 | 'url' => $scripturl . '?action=admin;area=' . $admin_include_data['current_area'] . ';sa=' . $admin_include_data['current_subsection'] . ';' . $context['session_var'] . '=' . $context['session_id'], |
| 476 | 480 | 'name' => $admin_include_data['subsections'][$admin_include_data['current_subsection']][0], |
| 477 | 481 | ); |
| 482 | + } |
|
| 478 | 483 | |
| 479 | 484 | // Make a note of the Unique ID for this menu. |
| 480 | 485 | $context['admin_menu_id'] = $context['max_menu_id']; |
@@ -484,16 +489,18 @@ discard block |
||
| 484 | 489 | $context['admin_area'] = $admin_include_data['current_area']; |
| 485 | 490 | |
| 486 | 491 | // Now - finally - call the right place! |
| 487 | - if (isset($admin_include_data['file'])) |
|
| 488 | - require_once($sourcedir . '/' . $admin_include_data['file']); |
|
| 492 | + if (isset($admin_include_data['file'])) { |
|
| 493 | + require_once($sourcedir . '/' . $admin_include_data['file']); |
|
| 494 | + } |
|
| 489 | 495 | |
| 490 | 496 | // Get the right callable. |
| 491 | 497 | $call = call_helper($admin_include_data['function'], true); |
| 492 | 498 | |
| 493 | 499 | // Is it valid? |
| 494 | - if (!empty($call)) |
|
| 495 | - call_user_func($call); |
|
| 496 | -} |
|
| 500 | + if (!empty($call)) { |
|
| 501 | + call_user_func($call); |
|
| 502 | + } |
|
| 503 | + } |
|
| 497 | 504 | |
| 498 | 505 | /** |
| 499 | 506 | * The main administration section. |
@@ -547,13 +554,14 @@ discard block |
||
| 547 | 554 | |
| 548 | 555 | $context['sub_template'] = $context['admin_area'] == 'credits' ? 'credits' : 'admin'; |
| 549 | 556 | $context['page_title'] = $context['admin_area'] == 'credits' ? $txt['support_credits_title'] : $txt['admin_center']; |
| 550 | - if ($context['admin_area'] != 'credits') |
|
| 551 | - $context[$context['admin_menu_name']]['tab_data'] = array( |
|
| 557 | + if ($context['admin_area'] != 'credits') { |
|
| 558 | + $context[$context['admin_menu_name']]['tab_data'] = array( |
|
| 552 | 559 | 'title' => $txt['admin_center'], |
| 553 | 560 | 'help' => '', |
| 554 | 561 | 'description' => '<strong>' . $txt['hello_guest'] . ' ' . $context['user']['name'] . '!</strong> |
| 555 | 562 | ' . sprintf($txt['admin_main_welcome'], $txt['admin_center'], $txt['help'], $txt['help']), |
| 556 | 563 | ); |
| 564 | + } |
|
| 557 | 565 | |
| 558 | 566 | // Lastly, fill in the blanks in the support resources paragraphs. |
| 559 | 567 | $txt['support_resources_p1'] = sprintf($txt['support_resources_p1'], |
@@ -571,9 +579,10 @@ discard block |
||
| 571 | 579 | 'https://www.simplemachines.org/redirect/customize_support' |
| 572 | 580 | ); |
| 573 | 581 | |
| 574 | - if ($context['admin_area'] == 'admin') |
|
| 575 | - loadJavaScriptFile('admin.js', array('defer' => false), 'smf_admin'); |
|
| 576 | -} |
|
| 582 | + if ($context['admin_area'] == 'admin') { |
|
| 583 | + loadJavaScriptFile('admin.js', array('defer' => false), 'smf_admin'); |
|
| 584 | + } |
|
| 585 | + } |
|
| 577 | 586 | |
| 578 | 587 | /** |
| 579 | 588 | * Get one of the admin information files from Simple Machines. |
@@ -584,8 +593,9 @@ discard block |
||
| 584 | 593 | |
| 585 | 594 | setMemoryLimit('32M'); |
| 586 | 595 | |
| 587 | - if (empty($_REQUEST['filename']) || !is_string($_REQUEST['filename'])) |
|
| 588 | - fatal_lang_error('no_access', false); |
|
| 596 | + if (empty($_REQUEST['filename']) || !is_string($_REQUEST['filename'])) { |
|
| 597 | + fatal_lang_error('no_access', false); |
|
| 598 | + } |
|
| 589 | 599 | |
| 590 | 600 | // Strip off the forum cache part or we won't find it... |
| 591 | 601 | $_REQUEST['filename'] = str_replace($modSettings['browser_cache'], '', $_REQUEST['filename']); |
@@ -600,27 +610,30 @@ discard block |
||
| 600 | 610 | ) |
| 601 | 611 | ); |
| 602 | 612 | |
| 603 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 604 | - fatal_lang_error('admin_file_not_found', true, array($_REQUEST['filename']), 404); |
|
| 613 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 614 | + fatal_lang_error('admin_file_not_found', true, array($_REQUEST['filename']), 404); |
|
| 615 | + } |
|
| 605 | 616 | |
| 606 | 617 | list ($file_data, $filetype) = $smcFunc['db_fetch_row']($request); |
| 607 | 618 | $smcFunc['db_free_result']($request); |
| 608 | 619 | |
| 609 | 620 | // @todo Temp |
| 610 | 621 | // Figure out if sesc is still being used. |
| 611 | - if (strpos($file_data, ';sesc=') !== false && $filetype == 'text/javascript') |
|
| 612 | - $file_data = ' |
|
| 622 | + if (strpos($file_data, ';sesc=') !== false && $filetype == 'text/javascript') { |
|
| 623 | + $file_data = ' |
|
| 613 | 624 | if (!(\'smfForum_sessionvar\' in window)) |
| 614 | 625 | window.smfForum_sessionvar = \'sesc\'; |
| 615 | 626 | ' . strtr($file_data, array(';sesc=' => ';\' + window.smfForum_sessionvar + \'=')); |
| 627 | + } |
|
| 616 | 628 | |
| 617 | 629 | $context['template_layers'] = array(); |
| 618 | 630 | // Lets make sure we aren't going to output anything nasty. |
| 619 | 631 | @ob_end_clean(); |
| 620 | - if (!empty($modSettings['enableCompressedOutput'])) |
|
| 621 | - @ob_start('ob_gzhandler'); |
|
| 622 | - else |
|
| 623 | - @ob_start(); |
|
| 632 | + if (!empty($modSettings['enableCompressedOutput'])) { |
|
| 633 | + @ob_start('ob_gzhandler'); |
|
| 634 | + } else { |
|
| 635 | + @ob_start(); |
|
| 636 | + } |
|
| 624 | 637 | |
| 625 | 638 | // Make sure they know what type of file we are. |
| 626 | 639 | header('Content-Type: ' . $filetype); |
@@ -660,11 +673,12 @@ discard block |
||
| 660 | 673 | updateAdminPreferences(); |
| 661 | 674 | } |
| 662 | 675 | |
| 663 | - if (trim($context['search_term']) == '') |
|
| 664 | - $context['search_results'] = array(); |
|
| 665 | - else |
|
| 666 | - call_helper($subActions[$context['search_type']]); |
|
| 667 | -} |
|
| 676 | + if (trim($context['search_term']) == '') { |
|
| 677 | + $context['search_results'] = array(); |
|
| 678 | + } else { |
|
| 679 | + call_helper($subActions[$context['search_type']]); |
|
| 680 | + } |
|
| 681 | + } |
|
| 668 | 682 | |
| 669 | 683 | /** |
| 670 | 684 | * A complicated but relatively quick internal search. |
@@ -728,8 +742,9 @@ discard block |
||
| 728 | 742 | |
| 729 | 743 | loadLanguage(implode('+', $language_files)); |
| 730 | 744 | |
| 731 | - foreach ($include_files as $file) |
|
| 732 | - require_once($sourcedir . '/' . $file . '.php'); |
|
| 745 | + foreach ($include_files as $file) { |
|
| 746 | + require_once($sourcedir . '/' . $file . '.php'); |
|
| 747 | + } |
|
| 733 | 748 | |
| 734 | 749 | /* This is the huge array that defines everything... it's a huge array of items formatted as follows: |
| 735 | 750 | 0 = Language index (Can be array of indexes) to search through for this setting. |
@@ -753,11 +768,12 @@ discard block |
||
| 753 | 768 | foreach ($section['areas'] as $menu_key => $menu_item) |
| 754 | 769 | { |
| 755 | 770 | $search_data['sections'][] = array($menu_item['label'], 'area=' . $menu_key); |
| 756 | - if (!empty($menu_item['subsections'])) |
|
| 757 | - foreach ($menu_item['subsections'] as $key => $sublabel) |
|
| 771 | + if (!empty($menu_item['subsections'])) { |
|
| 772 | + foreach ($menu_item['subsections'] as $key => $sublabel) |
|
| 758 | 773 | { |
| 759 | 774 | if (isset($sublabel['label'])) |
| 760 | 775 | $search_data['sections'][] = array($sublabel['label'], 'area=' . $menu_key . ';sa=' . $key); |
| 776 | + } |
|
| 761 | 777 | } |
| 762 | 778 | } |
| 763 | 779 | } |
@@ -767,9 +783,10 @@ discard block |
||
| 767 | 783 | // Get a list of their variables. |
| 768 | 784 | $config_vars = $setting_area[0](true); |
| 769 | 785 | |
| 770 | - foreach ($config_vars as $var) |
|
| 771 | - if (!empty($var[1]) && !in_array($var[0], array('permissions', 'switch', 'desc'))) |
|
| 786 | + foreach ($config_vars as $var) { |
|
| 787 | + if (!empty($var[1]) && !in_array($var[0], array('permissions', 'switch', 'desc'))) |
|
| 772 | 788 | $search_data['settings'][] = array($var[(isset($var[2]) && in_array($var[2], array('file', 'db'))) ? 0 : 1], $setting_area[1]); |
| 789 | + } |
|
| 773 | 790 | } |
| 774 | 791 | |
| 775 | 792 | $context['page_title'] = $txt['admin_search_results']; |
@@ -782,8 +799,9 @@ discard block |
||
| 782 | 799 | foreach ($data as $item) |
| 783 | 800 | { |
| 784 | 801 | $found = false; |
| 785 | - if (!is_array($item[0])) |
|
| 786 | - $item[0] = array($item[0]); |
|
| 802 | + if (!is_array($item[0])) { |
|
| 803 | + $item[0] = array($item[0]); |
|
| 804 | + } |
|
| 787 | 805 | foreach ($item[0] as $term) |
| 788 | 806 | { |
| 789 | 807 | if (stripos($term, $search_term) !== false || (isset($txt[$term]) && stripos($txt[$term], $search_term) !== false) || (isset($txt['setting_' . $term]) && stripos($txt['setting_' . $term], $search_term) !== false)) |
@@ -841,8 +859,9 @@ discard block |
||
| 841 | 859 | $postVars = explode(' ', $context['search_term']); |
| 842 | 860 | |
| 843 | 861 | // Encode the search data. |
| 844 | - foreach ($postVars as $k => $v) |
|
| 845 | - $postVars[$k] = urlencode($v); |
|
| 862 | + foreach ($postVars as $k => $v) { |
|
| 863 | + $postVars[$k] = urlencode($v); |
|
| 864 | + } |
|
| 846 | 865 | |
| 847 | 866 | // This is what we will send. |
| 848 | 867 | $postVars = implode('+', $postVars); |
@@ -854,8 +873,9 @@ discard block |
||
| 854 | 873 | $search_results = fetch_web_data($context['doc_apiurl'] . '?action=query&list=search&srprop=timestamp|snippet&format=xml&srwhat=text&srsearch=' . $postVars); |
| 855 | 874 | |
| 856 | 875 | // If we didn't get any xml back we are in trouble - perhaps the doc site is overloaded? |
| 857 | - if (!$search_results || preg_match('~<' . '\?xml\sversion="\d+\.\d+"\?' . '>\s*(<api>.+?</api>)~is', $search_results, $matches) != true) |
|
| 858 | - fatal_lang_error('cannot_connect_doc_site'); |
|
| 876 | + if (!$search_results || preg_match('~<' . '\?xml\sversion="\d+\.\d+"\?' . '>\s*(<api>.+?</api>)~is', $search_results, $matches) != true) { |
|
| 877 | + fatal_lang_error('cannot_connect_doc_site'); |
|
| 878 | + } |
|
| 859 | 879 | |
| 860 | 880 | $search_results = $matches[1]; |
| 861 | 881 | |
@@ -867,8 +887,9 @@ discard block |
||
| 867 | 887 | $results = new xmlArray($search_results, false); |
| 868 | 888 | |
| 869 | 889 | // Move through the api layer. |
| 870 | - if (!$results->exists('api')) |
|
| 871 | - fatal_lang_error('cannot_connect_doc_site'); |
|
| 890 | + if (!$results->exists('api')) { |
|
| 891 | + fatal_lang_error('cannot_connect_doc_site'); |
|
| 892 | + } |
|
| 872 | 893 | |
| 873 | 894 | // Are there actually some results? |
| 874 | 895 | if ($results->exists('api/query/search/p')) |
@@ -904,8 +925,9 @@ discard block |
||
| 904 | 925 | ); |
| 905 | 926 | |
| 906 | 927 | // If it's not got a sa set it must have come here for first time, pretend error log should be reversed. |
| 907 | - if (!isset($_REQUEST['sa'])) |
|
| 908 | - $_REQUEST['desc'] = true; |
|
| 928 | + if (!isset($_REQUEST['sa'])) { |
|
| 929 | + $_REQUEST['desc'] = true; |
|
| 930 | + } |
|
| 909 | 931 | |
| 910 | 932 | // Setup some tab stuff. |
| 911 | 933 | $context[$context['admin_menu_name']]['tab_data'] = array( |
@@ -955,9 +977,10 @@ discard block |
||
| 955 | 977 | unset($_SESSION['admin_time']); |
| 956 | 978 | |
| 957 | 979 | // Clean any admin tokens as well. |
| 958 | - foreach ($_SESSION['token'] as $key => $token) |
|
| 959 | - if (strpos($key, '-admin') !== false) |
|
| 980 | + foreach ($_SESSION['token'] as $key => $token) { |
|
| 981 | + if (strpos($key, '-admin') !== false) |
|
| 960 | 982 | unset($_SESSION['token'][$key]); |
| 983 | + } |
|
| 961 | 984 | |
| 962 | 985 | redirectexit(); |
| 963 | 986 | } |
@@ -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 | * This is the dispatcher of smileys administration. |
@@ -91,8 +92,9 @@ discard block |
||
| 91 | 92 | ); |
| 92 | 93 | |
| 93 | 94 | // Some settings may not be enabled, disallow these from the tabs as appropriate. |
| 94 | - if (empty($modSettings['messageIcons_enable'])) |
|
| 95 | - $context[$context['admin_menu_name']]['tab_data']['tabs']['editicons']['disabled'] = true; |
|
| 95 | + if (empty($modSettings['messageIcons_enable'])) { |
|
| 96 | + $context[$context['admin_menu_name']]['tab_data']['tabs']['editicons']['disabled'] = true; |
|
| 97 | + } |
|
| 96 | 98 | if (empty($modSettings['smiley_enable'])) |
| 97 | 99 | { |
| 98 | 100 | $context[$context['admin_menu_name']]['tab_data']['tabs']['addsmiley']['disabled'] = true; |
@@ -125,8 +127,9 @@ discard block |
||
| 125 | 127 | $set_names = explode("\n", $modSettings['smiley_sets_names']); |
| 126 | 128 | |
| 127 | 129 | $smiley_context = array(); |
| 128 | - foreach ($smiley_sets as $i => $set) |
|
| 129 | - $smiley_context[$set] = $set_names[$i]; |
|
| 130 | + foreach ($smiley_sets as $i => $set) { |
|
| 131 | + $smiley_context[$set] = $set_names[$i]; |
|
| 132 | + } |
|
| 130 | 133 | |
| 131 | 134 | // All the settings for the page... |
| 132 | 135 | $config_vars = array( |
@@ -147,8 +150,9 @@ discard block |
||
| 147 | 150 | |
| 148 | 151 | call_integration_hook('integrate_modify_smiley_settings', array(&$config_vars)); |
| 149 | 152 | |
| 150 | - if ($return_config) |
|
| 151 | - return $config_vars; |
|
| 153 | + if ($return_config) { |
|
| 154 | + return $config_vars; |
|
| 155 | + } |
|
| 152 | 156 | |
| 153 | 157 | // Setup the basics of the settings template. |
| 154 | 158 | require_once($sourcedir . '/ManageServer.php'); |
@@ -207,8 +211,9 @@ discard block |
||
| 207 | 211 | foreach ($_POST['smiley_set'] as $id => $val) |
| 208 | 212 | { |
| 209 | 213 | // If this is the set you've marked as default, or the only one remaining, you can't delete it |
| 210 | - if ($modSettings['smiley_sets_default'] != $set_paths[$id] && count($set_paths) != 1 && isset($set_paths[$id], $set_names[$id])) |
|
| 211 | - unset($set_paths[$id], $set_names[$id]); |
|
| 214 | + if ($modSettings['smiley_sets_default'] != $set_paths[$id] && count($set_paths) != 1 && isset($set_paths[$id], $set_names[$id])) { |
|
| 215 | + unset($set_paths[$id], $set_names[$id]); |
|
| 216 | + } |
|
| 212 | 217 | } |
| 213 | 218 | |
| 214 | 219 | // Shortcut... array_merge() on a single array resets the numeric keys |
@@ -222,8 +227,9 @@ discard block |
||
| 222 | 227 | )); |
| 223 | 228 | } |
| 224 | 229 | // Add a new smiley set. |
| 225 | - elseif (!empty($_POST['add'])) |
|
| 226 | - $context['sub_action'] = 'modifyset'; |
|
| 230 | + elseif (!empty($_POST['add'])) { |
|
| 231 | + $context['sub_action'] = 'modifyset'; |
|
| 232 | + } |
|
| 227 | 233 | // Create or modify a smiley set. |
| 228 | 234 | elseif (isset($_POST['set'])) |
| 229 | 235 | { |
@@ -233,8 +239,9 @@ discard block |
||
| 233 | 239 | // Create a new smiley set. |
| 234 | 240 | if ($_POST['set'] == -1 && isset($_POST['smiley_sets_path'])) |
| 235 | 241 | { |
| 236 | - if (in_array($_POST['smiley_sets_path'], $set_paths)) |
|
| 237 | - fatal_lang_error('smiley_set_already_exists'); |
|
| 242 | + if (in_array($_POST['smiley_sets_path'], $set_paths)) { |
|
| 243 | + fatal_lang_error('smiley_set_already_exists'); |
|
| 244 | + } |
|
| 238 | 245 | |
| 239 | 246 | updateSettings(array( |
| 240 | 247 | 'smiley_sets_known' => $modSettings['smiley_sets_known'] . ',' . $_POST['smiley_sets_path'], |
@@ -246,12 +253,14 @@ discard block |
||
| 246 | 253 | else |
| 247 | 254 | { |
| 248 | 255 | // Make sure the smiley set exists. |
| 249 | - if (!isset($set_paths[$_POST['set']]) || !isset($set_names[$_POST['set']])) |
|
| 250 | - fatal_lang_error('smiley_set_not_found'); |
|
| 256 | + if (!isset($set_paths[$_POST['set']]) || !isset($set_names[$_POST['set']])) { |
|
| 257 | + fatal_lang_error('smiley_set_not_found'); |
|
| 258 | + } |
|
| 251 | 259 | |
| 252 | 260 | // Make sure the path is not yet used by another smileyset. |
| 253 | - if (in_array($_POST['smiley_sets_path'], $set_paths) && $_POST['smiley_sets_path'] != $set_paths[$_POST['set']]) |
|
| 254 | - fatal_lang_error('smiley_set_path_already_used'); |
|
| 261 | + if (in_array($_POST['smiley_sets_path'], $set_paths) && $_POST['smiley_sets_path'] != $set_paths[$_POST['set']]) { |
|
| 262 | + fatal_lang_error('smiley_set_path_already_used'); |
|
| 263 | + } |
|
| 255 | 264 | |
| 256 | 265 | $set_paths[$_POST['set']] = $_POST['smiley_sets_path']; |
| 257 | 266 | $set_names[$_POST['set']] = $_POST['smiley_sets_name']; |
@@ -263,8 +272,9 @@ discard block |
||
| 263 | 272 | } |
| 264 | 273 | |
| 265 | 274 | // The user might have checked to also import smileys. |
| 266 | - if (!empty($_POST['smiley_sets_import'])) |
|
| 267 | - ImportSmileys($_POST['smiley_sets_path']); |
|
| 275 | + if (!empty($_POST['smiley_sets_import'])) { |
|
| 276 | + ImportSmileys($_POST['smiley_sets_path']); |
|
| 277 | + } |
|
| 268 | 278 | } |
| 269 | 279 | cache_put_data('parsing_smileys', null, 480); |
| 270 | 280 | cache_put_data('posting_smileys', null, 480); |
@@ -273,13 +283,14 @@ discard block |
||
| 273 | 283 | // Load all available smileysets... |
| 274 | 284 | $context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']); |
| 275 | 285 | $set_names = explode("\n", $modSettings['smiley_sets_names']); |
| 276 | - foreach ($context['smiley_sets'] as $i => $set) |
|
| 277 | - $context['smiley_sets'][$i] = array( |
|
| 286 | + foreach ($context['smiley_sets'] as $i => $set) { |
|
| 287 | + $context['smiley_sets'][$i] = array( |
|
| 278 | 288 | 'id' => $i, |
| 279 | 289 | 'path' => $smcFunc['htmlspecialchars']($set), |
| 280 | 290 | 'name' => $smcFunc['htmlspecialchars']($set_names[$i]), |
| 281 | 291 | 'selected' => $set == $modSettings['smiley_sets_default'] |
| 282 | 292 | ); |
| 293 | + } |
|
| 283 | 294 | |
| 284 | 295 | // Importing any smileys from an existing set? |
| 285 | 296 | if ($context['sub_action'] == 'import') |
@@ -290,8 +301,9 @@ discard block |
||
| 290 | 301 | $_GET['set'] = (int) $_GET['set']; |
| 291 | 302 | |
| 292 | 303 | // Sanity check - then import. |
| 293 | - if (isset($context['smiley_sets'][$_GET['set']])) |
|
| 294 | - ImportSmileys(un_htmlspecialchars($context['smiley_sets'][$_GET['set']]['path'])); |
|
| 304 | + if (isset($context['smiley_sets'][$_GET['set']])) { |
|
| 305 | + ImportSmileys(un_htmlspecialchars($context['smiley_sets'][$_GET['set']]['path'])); |
|
| 306 | + } |
|
| 295 | 307 | |
| 296 | 308 | // Force the process to continue. |
| 297 | 309 | $context['sub_action'] = 'modifyset'; |
@@ -301,15 +313,15 @@ discard block |
||
| 301 | 313 | if ($context['sub_action'] == 'modifyset') |
| 302 | 314 | { |
| 303 | 315 | $_GET['set'] = !isset($_GET['set']) ? -1 : (int) $_GET['set']; |
| 304 | - if ($_GET['set'] == -1 || !isset($context['smiley_sets'][$_GET['set']])) |
|
| 305 | - $context['current_set'] = array( |
|
| 316 | + if ($_GET['set'] == -1 || !isset($context['smiley_sets'][$_GET['set']])) { |
|
| 317 | + $context['current_set'] = array( |
|
| 306 | 318 | 'id' => '-1', |
| 307 | 319 | 'path' => '', |
| 308 | 320 | 'name' => '', |
| 309 | 321 | 'selected' => false, |
| 310 | 322 | 'is_new' => true, |
| 311 | 323 | ); |
| 312 | - else |
|
| 324 | + } else |
|
| 313 | 325 | { |
| 314 | 326 | $context['current_set'] = &$context['smiley_sets'][$_GET['set']]; |
| 315 | 327 | $context['current_set']['is_new'] = false; |
@@ -321,13 +333,15 @@ discard block |
||
| 321 | 333 | $dir = dir($modSettings['smileys_dir'] . '/' . $context['current_set']['path']); |
| 322 | 334 | while ($entry = $dir->read()) |
| 323 | 335 | { |
| 324 | - if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) |
|
| 325 | - $smileys[strtolower($entry)] = $entry; |
|
| 336 | + if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) { |
|
| 337 | + $smileys[strtolower($entry)] = $entry; |
|
| 338 | + } |
|
| 326 | 339 | } |
| 327 | 340 | $dir->close(); |
| 328 | 341 | |
| 329 | - if (empty($smileys)) |
|
| 330 | - fatal_lang_error('smiley_set_dir_not_found', false, array($context['current_set']['name'])); |
|
| 342 | + if (empty($smileys)) { |
|
| 343 | + fatal_lang_error('smiley_set_dir_not_found', false, array($context['current_set']['name'])); |
|
| 344 | + } |
|
| 331 | 345 | |
| 332 | 346 | // Exclude the smileys that are already in the database. |
| 333 | 347 | $request = $smcFunc['db_query']('', ' |
@@ -338,9 +352,10 @@ discard block |
||
| 338 | 352 | 'smiley_list' => $smileys, |
| 339 | 353 | ) |
| 340 | 354 | ); |
| 341 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 342 | - if (isset($smileys[strtolower($row['filename'])])) |
|
| 355 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 356 | + if (isset($smileys[strtolower($row['filename'])])) |
|
| 343 | 357 | unset($smileys[strtolower($row['filename'])]); |
| 358 | + } |
|
| 344 | 359 | $smcFunc['db_free_result']($request); |
| 345 | 360 | |
| 346 | 361 | $context['current_set']['can_import'] = count($smileys); |
@@ -355,13 +370,14 @@ discard block |
||
| 355 | 370 | $dir = dir($modSettings['smileys_dir']); |
| 356 | 371 | while ($entry = $dir->read()) |
| 357 | 372 | { |
| 358 | - if (!in_array($entry, array('.', '..')) && is_dir($modSettings['smileys_dir'] . '/' . $entry)) |
|
| 359 | - $context['smiley_set_dirs'][] = array( |
|
| 373 | + if (!in_array($entry, array('.', '..')) && is_dir($modSettings['smileys_dir'] . '/' . $entry)) { |
|
| 374 | + $context['smiley_set_dirs'][] = array( |
|
| 360 | 375 | 'id' => $entry, |
| 361 | 376 | 'path' => $modSettings['smileys_dir'] . '/' . $entry, |
| 362 | 377 | 'selectable' => $entry == $context['current_set']['path'] || !in_array($entry, explode(',', $modSettings['smiley_sets_known'])), |
| 363 | 378 | 'current' => $entry == $context['current_set']['path'], |
| 364 | 379 | ); |
| 380 | + } |
|
| 365 | 381 | } |
| 366 | 382 | $dir->close(); |
| 367 | 383 | } |
@@ -371,8 +387,9 @@ discard block |
||
| 371 | 387 | createToken('admin-mss', 'request'); |
| 372 | 388 | |
| 373 | 389 | // In case we need to import smileys, we need to add the token in now. |
| 374 | - if (isset($context['current_set']['import_url'])) |
|
| 375 | - $context['current_set']['import_url'] .= ';' . $context['admin-mss_token_var'] . '=' . $context['admin-mss_token']; |
|
| 390 | + if (isset($context['current_set']['import_url'])) { |
|
| 391 | + $context['current_set']['import_url'] .= ';' . $context['admin-mss_token_var'] . '=' . $context['admin-mss_token']; |
|
| 392 | + } |
|
| 376 | 393 | |
| 377 | 394 | $listOptions = array( |
| 378 | 395 | 'id' => 'smiley_set_list', |
@@ -510,21 +527,23 @@ discard block |
||
| 510 | 527 | $cols['name'][] = $set_names[$i]; |
| 511 | 528 | } |
| 512 | 529 | $sort_flag = strpos($sort, 'DESC') === false ? SORT_ASC : SORT_DESC; |
| 513 | - if (substr($sort, 0, 4) === 'name') |
|
| 514 | - array_multisort($cols['name'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['selected'], $cols['id']); |
|
| 515 | - elseif (substr($sort, 0, 4) === 'path') |
|
| 516 | - array_multisort($cols['path'], $sort_flag, SORT_REGULAR, $cols['name'], $cols['selected'], $cols['id']); |
|
| 517 | - else |
|
| 518 | - array_multisort($cols['selected'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['name'], $cols['id']); |
|
| 530 | + if (substr($sort, 0, 4) === 'name') { |
|
| 531 | + array_multisort($cols['name'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['selected'], $cols['id']); |
|
| 532 | + } elseif (substr($sort, 0, 4) === 'path') { |
|
| 533 | + array_multisort($cols['path'], $sort_flag, SORT_REGULAR, $cols['name'], $cols['selected'], $cols['id']); |
|
| 534 | + } else { |
|
| 535 | + array_multisort($cols['selected'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['name'], $cols['id']); |
|
| 536 | + } |
|
| 519 | 537 | |
| 520 | 538 | $smiley_sets = array(); |
| 521 | - foreach ($cols['id'] as $i => $id) |
|
| 522 | - $smiley_sets[] = array( |
|
| 539 | + foreach ($cols['id'] as $i => $id) { |
|
| 540 | + $smiley_sets[] = array( |
|
| 523 | 541 | 'id' => $id, |
| 524 | 542 | 'path' => $cols['path'][$i], |
| 525 | 543 | 'name' => $cols['name'][$i], |
| 526 | 544 | 'selected' => $cols['path'][$i] == $modSettings['smiley_sets_default'] |
| 527 | 545 | ); |
| 546 | + } |
|
| 528 | 547 | |
| 529 | 548 | return $smiley_sets; |
| 530 | 549 | } |
@@ -553,13 +572,14 @@ discard block |
||
| 553 | 572 | $context['smileys_dir_found'] = is_dir($context['smileys_dir']); |
| 554 | 573 | $context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']); |
| 555 | 574 | $set_names = explode("\n", $modSettings['smiley_sets_names']); |
| 556 | - foreach ($context['smiley_sets'] as $i => $set) |
|
| 557 | - $context['smiley_sets'][$i] = array( |
|
| 575 | + foreach ($context['smiley_sets'] as $i => $set) { |
|
| 576 | + $context['smiley_sets'][$i] = array( |
|
| 558 | 577 | 'id' => $i, |
| 559 | 578 | 'path' => $smcFunc['htmlspecialchars']($set), |
| 560 | 579 | 'name' => $smcFunc['htmlspecialchars']($set_names[$i]), |
| 561 | 580 | 'selected' => $set == $modSettings['smiley_sets_default'] |
| 562 | 581 | ); |
| 582 | + } |
|
| 563 | 583 | |
| 564 | 584 | // Submitting a form? |
| 565 | 585 | if (isset($_POST[$context['session_var']], $_POST['smiley_code'])) |
@@ -575,8 +595,9 @@ discard block |
||
| 575 | 595 | $_POST['smiley_filename'] = htmltrim__recursive($_POST['smiley_filename']); |
| 576 | 596 | |
| 577 | 597 | // Make sure some code was entered. |
| 578 | - if (empty($_POST['smiley_code'])) |
|
| 579 | - fatal_lang_error('smiley_has_no_code'); |
|
| 598 | + if (empty($_POST['smiley_code'])) { |
|
| 599 | + fatal_lang_error('smiley_has_no_code'); |
|
| 600 | + } |
|
| 580 | 601 | |
| 581 | 602 | // Check whether the new code has duplicates. It should be unique. |
| 582 | 603 | $request = $smcFunc['db_query']('', ' |
@@ -588,8 +609,9 @@ discard block |
||
| 588 | 609 | 'smiley_code' => $_POST['smiley_code'], |
| 589 | 610 | ) |
| 590 | 611 | ); |
| 591 | - if ($smcFunc['db_num_rows']($request) > 0) |
|
| 592 | - fatal_lang_error('smiley_not_unique'); |
|
| 612 | + if ($smcFunc['db_num_rows']($request) > 0) { |
|
| 613 | + fatal_lang_error('smiley_not_unique'); |
|
| 614 | + } |
|
| 593 | 615 | $smcFunc['db_free_result']($request); |
| 594 | 616 | |
| 595 | 617 | // If we are uploading - check all the smiley sets are writable! |
@@ -598,38 +620,44 @@ discard block |
||
| 598 | 620 | $writeErrors = array(); |
| 599 | 621 | foreach ($context['smiley_sets'] as $set) |
| 600 | 622 | { |
| 601 | - if (!is_writable($context['smileys_dir'] . '/' . un_htmlspecialchars($set['path']))) |
|
| 602 | - $writeErrors[] = $set['path']; |
|
| 623 | + if (!is_writable($context['smileys_dir'] . '/' . un_htmlspecialchars($set['path']))) { |
|
| 624 | + $writeErrors[] = $set['path']; |
|
| 625 | + } |
|
| 626 | + } |
|
| 627 | + if (!empty($writeErrors)) { |
|
| 628 | + fatal_lang_error('smileys_upload_error_notwritable', true, array(implode(', ', $writeErrors))); |
|
| 603 | 629 | } |
| 604 | - if (!empty($writeErrors)) |
|
| 605 | - fatal_lang_error('smileys_upload_error_notwritable', true, array(implode(', ', $writeErrors))); |
|
| 606 | 630 | } |
| 607 | 631 | |
| 608 | 632 | // Uploading just one smiley for all of them? |
| 609 | 633 | if (isset($_POST['sameall']) && isset($_FILES['uploadSmiley']['name']) && $_FILES['uploadSmiley']['name'] != '') |
| 610 | 634 | { |
| 611 | - if (!is_uploaded_file($_FILES['uploadSmiley']['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['uploadSmiley']['tmp_name']))) |
|
| 612 | - fatal_lang_error('smileys_upload_error'); |
|
| 635 | + if (!is_uploaded_file($_FILES['uploadSmiley']['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['uploadSmiley']['tmp_name']))) { |
|
| 636 | + fatal_lang_error('smileys_upload_error'); |
|
| 637 | + } |
|
| 613 | 638 | |
| 614 | 639 | // Sorry, no spaces, dots, or anything else but letters allowed. |
| 615 | 640 | $_FILES['uploadSmiley']['name'] = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $_FILES['uploadSmiley']['name']); |
| 616 | 641 | |
| 617 | 642 | // We only allow image files - it's THAT simple - no messing around here... |
| 618 | - if (!in_array(strtolower(substr(strrchr($_FILES['uploadSmiley']['name'], '.'), 1)), $allowedTypes)) |
|
| 619 | - fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes))); |
|
| 643 | + if (!in_array(strtolower(substr(strrchr($_FILES['uploadSmiley']['name'], '.'), 1)), $allowedTypes)) { |
|
| 644 | + fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes))); |
|
| 645 | + } |
|
| 620 | 646 | |
| 621 | 647 | // We only need the filename... |
| 622 | 648 | $destName = basename($_FILES['uploadSmiley']['name']); |
| 623 | 649 | |
| 624 | 650 | // Make sure they aren't trying to upload a nasty file - for their own good here! |
| 625 | - if (in_array(strtolower($destName), $disabledFiles)) |
|
| 626 | - fatal_lang_error('smileys_upload_error_illegal'); |
|
| 651 | + if (in_array(strtolower($destName), $disabledFiles)) { |
|
| 652 | + fatal_lang_error('smileys_upload_error_illegal'); |
|
| 653 | + } |
|
| 627 | 654 | |
| 628 | 655 | // Check if the file already exists... and if not move it to EVERY smiley set directory. |
| 629 | 656 | $i = 0; |
| 630 | 657 | // Keep going until we find a set the file doesn't exist in. (or maybe it exists in all of them?) |
| 631 | - while (isset($context['smiley_sets'][$i]) && file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($context['smiley_sets'][$i]['path']) . '/' . $destName)) |
|
| 632 | - $i++; |
|
| 658 | + while (isset($context['smiley_sets'][$i]) && file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($context['smiley_sets'][$i]['path']) . '/' . $destName)) { |
|
| 659 | + $i++; |
|
| 660 | + } |
|
| 633 | 661 | |
| 634 | 662 | // Okay, we're going to put the smiley right here, since it's not there yet! |
| 635 | 663 | if (isset($context['smiley_sets'][$i]['path'])) |
@@ -644,8 +672,9 @@ discard block |
||
| 644 | 672 | $currentPath = $context['smileys_dir'] . '/' . un_htmlspecialchars($context['smiley_sets'][$i]['path']) . '/' . $destName; |
| 645 | 673 | |
| 646 | 674 | // The file is already there! Don't overwrite it! |
| 647 | - if (file_exists($currentPath)) |
|
| 648 | - continue; |
|
| 675 | + if (file_exists($currentPath)) { |
|
| 676 | + continue; |
|
| 677 | + } |
|
| 649 | 678 | |
| 650 | 679 | // Okay, so copy the first one we made to here. |
| 651 | 680 | copy($smileyLocation, $currentPath); |
@@ -662,13 +691,15 @@ discard block |
||
| 662 | 691 | $newName = ''; |
| 663 | 692 | foreach ($_FILES as $name => $data) |
| 664 | 693 | { |
| 665 | - if ($_FILES[$name]['name'] == '') |
|
| 666 | - fatal_lang_error('smileys_upload_error_blank'); |
|
| 694 | + if ($_FILES[$name]['name'] == '') { |
|
| 695 | + fatal_lang_error('smileys_upload_error_blank'); |
|
| 696 | + } |
|
| 667 | 697 | |
| 668 | - if (empty($newName)) |
|
| 669 | - $newName = basename($_FILES[$name]['name']); |
|
| 670 | - elseif (basename($_FILES[$name]['name']) != $newName) |
|
| 671 | - fatal_lang_error('smileys_upload_error_name'); |
|
| 698 | + if (empty($newName)) { |
|
| 699 | + $newName = basename($_FILES[$name]['name']); |
|
| 700 | + } elseif (basename($_FILES[$name]['name']) != $newName) { |
|
| 701 | + fatal_lang_error('smileys_upload_error_name'); |
|
| 702 | + } |
|
| 672 | 703 | } |
| 673 | 704 | |
| 674 | 705 | foreach ($context['smiley_sets'] as $i => $set) |
@@ -676,31 +707,36 @@ discard block |
||
| 676 | 707 | $set['name'] = un_htmlspecialchars($set['name']); |
| 677 | 708 | $set['path'] = un_htmlspecialchars($set['path']); |
| 678 | 709 | |
| 679 | - if (!isset($_FILES['individual_' . $set['name']]['name']) || $_FILES['individual_' . $set['name']]['name'] == '') |
|
| 680 | - continue; |
|
| 710 | + if (!isset($_FILES['individual_' . $set['name']]['name']) || $_FILES['individual_' . $set['name']]['name'] == '') { |
|
| 711 | + continue; |
|
| 712 | + } |
|
| 681 | 713 | |
| 682 | 714 | // Got one... |
| 683 | - if (!is_uploaded_file($_FILES['individual_' . $set['name']]['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['individual_' . $set['name']]['tmp_name']))) |
|
| 684 | - fatal_lang_error('smileys_upload_error'); |
|
| 715 | + if (!is_uploaded_file($_FILES['individual_' . $set['name']]['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['individual_' . $set['name']]['tmp_name']))) { |
|
| 716 | + fatal_lang_error('smileys_upload_error'); |
|
| 717 | + } |
|
| 685 | 718 | |
| 686 | 719 | // Sorry, no spaces, dots, or anything else but letters allowed. |
| 687 | 720 | $_FILES['individual_' . $set['name']]['name'] = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $_FILES['individual_' . $set['name']]['name']); |
| 688 | 721 | |
| 689 | 722 | // We only allow image files - it's THAT simple - no messing around here... |
| 690 | - if (!in_array(strtolower(substr(strrchr($_FILES['individual_' . $set['name']]['name'], '.'), 1)), $allowedTypes)) |
|
| 691 | - fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes))); |
|
| 723 | + if (!in_array(strtolower(substr(strrchr($_FILES['individual_' . $set['name']]['name'], '.'), 1)), $allowedTypes)) { |
|
| 724 | + fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes))); |
|
| 725 | + } |
|
| 692 | 726 | |
| 693 | 727 | // We only need the filename... |
| 694 | 728 | $destName = basename($_FILES['individual_' . $set['name']]['name']); |
| 695 | 729 | |
| 696 | 730 | // Make sure they aren't trying to upload a nasty file - for their own good here! |
| 697 | - if (in_array(strtolower($destName), $disabledFiles)) |
|
| 698 | - fatal_lang_error('smileys_upload_error_illegal'); |
|
| 731 | + if (in_array(strtolower($destName), $disabledFiles)) { |
|
| 732 | + fatal_lang_error('smileys_upload_error_illegal'); |
|
| 733 | + } |
|
| 699 | 734 | |
| 700 | 735 | // If the file exists - ignore it. |
| 701 | 736 | $smileyLocation = $context['smileys_dir'] . '/' . $set['path'] . '/' . $destName; |
| 702 | - if (file_exists($smileyLocation)) |
|
| 703 | - continue; |
|
| 737 | + if (file_exists($smileyLocation)) { |
|
| 738 | + continue; |
|
| 739 | + } |
|
| 704 | 740 | |
| 705 | 741 | // Finally - move the image! |
| 706 | 742 | move_uploaded_file($_FILES['individual_' . $set['name']]['tmp_name'], $smileyLocation); |
@@ -712,8 +748,9 @@ discard block |
||
| 712 | 748 | } |
| 713 | 749 | |
| 714 | 750 | // Also make sure a filename was given. |
| 715 | - if (empty($_POST['smiley_filename'])) |
|
| 716 | - fatal_lang_error('smiley_has_no_filename'); |
|
| 751 | + if (empty($_POST['smiley_filename'])) { |
|
| 752 | + fatal_lang_error('smiley_has_no_filename'); |
|
| 753 | + } |
|
| 717 | 754 | |
| 718 | 755 | // Find the position on the right. |
| 719 | 756 | $smiley_order = '0'; |
@@ -732,8 +769,9 @@ discard block |
||
| 732 | 769 | list ($smiley_order) = $smcFunc['db_fetch_row']($request); |
| 733 | 770 | $smcFunc['db_free_result']($request); |
| 734 | 771 | |
| 735 | - if (empty($smiley_order)) |
|
| 736 | - $smiley_order = '0'; |
|
| 772 | + if (empty($smiley_order)) { |
|
| 773 | + $smiley_order = '0'; |
|
| 774 | + } |
|
| 737 | 775 | } |
| 738 | 776 | $smcFunc['db_insert']('', |
| 739 | 777 | '{db_prefix}smileys', |
@@ -761,17 +799,19 @@ discard block |
||
| 761 | 799 | { |
| 762 | 800 | foreach ($context['smiley_sets'] as $smiley_set) |
| 763 | 801 | { |
| 764 | - if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']))) |
|
| 765 | - continue; |
|
| 802 | + if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']))) { |
|
| 803 | + continue; |
|
| 804 | + } |
|
| 766 | 805 | |
| 767 | 806 | $dir = dir($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path'])); |
| 768 | 807 | while ($entry = $dir->read()) |
| 769 | 808 | { |
| 770 | - if (!in_array($entry, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) |
|
| 771 | - $context['filenames'][strtolower($entry)] = array( |
|
| 809 | + if (!in_array($entry, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) { |
|
| 810 | + $context['filenames'][strtolower($entry)] = array( |
|
| 772 | 811 | 'id' => $smcFunc['htmlspecialchars']($entry), |
| 773 | 812 | 'selected' => false, |
| 774 | 813 | ); |
| 814 | + } |
|
| 775 | 815 | } |
| 776 | 816 | $dir->close(); |
| 777 | 817 | } |
@@ -809,17 +849,19 @@ discard block |
||
| 809 | 849 | // Changing the selected smileys? |
| 810 | 850 | if (isset($_POST['smiley_action']) && !empty($_POST['checked_smileys'])) |
| 811 | 851 | { |
| 812 | - foreach ($_POST['checked_smileys'] as $id => $smiley_id) |
|
| 813 | - $_POST['checked_smileys'][$id] = (int) $smiley_id; |
|
| 852 | + foreach ($_POST['checked_smileys'] as $id => $smiley_id) { |
|
| 853 | + $_POST['checked_smileys'][$id] = (int) $smiley_id; |
|
| 854 | + } |
|
| 814 | 855 | |
| 815 | - if ($_POST['smiley_action'] == 'delete') |
|
| 816 | - $smcFunc['db_query']('', ' |
|
| 856 | + if ($_POST['smiley_action'] == 'delete') { |
|
| 857 | + $smcFunc['db_query']('', ' |
|
| 817 | 858 | DELETE FROM {db_prefix}smileys |
| 818 | 859 | WHERE id_smiley IN ({array_int:checked_smileys})', |
| 819 | 860 | array( |
| 820 | 861 | 'checked_smileys' => $_POST['checked_smileys'], |
| 821 | 862 | ) |
| 822 | 863 | ); |
| 864 | + } |
|
| 823 | 865 | // Changing the status of the smiley? |
| 824 | 866 | else |
| 825 | 867 | { |
@@ -829,8 +871,8 @@ discard block |
||
| 829 | 871 | 'hidden' => 1, |
| 830 | 872 | 'popup' => 2 |
| 831 | 873 | ); |
| 832 | - if (isset($displayTypes[$_POST['smiley_action']])) |
|
| 833 | - $smcFunc['db_query']('', ' |
|
| 874 | + if (isset($displayTypes[$_POST['smiley_action']])) { |
|
| 875 | + $smcFunc['db_query']('', ' |
|
| 834 | 876 | UPDATE {db_prefix}smileys |
| 835 | 877 | SET hidden = {int:display_type} |
| 836 | 878 | WHERE id_smiley IN ({array_int:checked_smileys})', |
@@ -839,6 +881,7 @@ discard block |
||
| 839 | 881 | 'display_type' => $displayTypes[$_POST['smiley_action']], |
| 840 | 882 | ) |
| 841 | 883 | ); |
| 884 | + } |
|
| 842 | 885 | } |
| 843 | 886 | } |
| 844 | 887 | // Create/modify a smiley. |
@@ -864,12 +907,14 @@ discard block |
||
| 864 | 907 | $_POST['smiley_location'] = empty($_POST['smiley_location']) || $_POST['smiley_location'] > 2 || $_POST['smiley_location'] < 0 ? 0 : (int) $_POST['smiley_location']; |
| 865 | 908 | |
| 866 | 909 | // Make sure some code was entered. |
| 867 | - if (empty($_POST['smiley_code'])) |
|
| 868 | - fatal_lang_error('smiley_has_no_code'); |
|
| 910 | + if (empty($_POST['smiley_code'])) { |
|
| 911 | + fatal_lang_error('smiley_has_no_code'); |
|
| 912 | + } |
|
| 869 | 913 | |
| 870 | 914 | // Also make sure a filename was given. |
| 871 | - if (empty($_POST['smiley_filename'])) |
|
| 872 | - fatal_lang_error('smiley_has_no_filename'); |
|
| 915 | + if (empty($_POST['smiley_filename'])) { |
|
| 916 | + fatal_lang_error('smiley_has_no_filename'); |
|
| 917 | + } |
|
| 873 | 918 | |
| 874 | 919 | // Check whether the new code has duplicates. It should be unique. |
| 875 | 920 | $request = $smcFunc['db_query']('', ' |
@@ -883,8 +928,9 @@ discard block |
||
| 883 | 928 | 'smiley_code' => $_POST['smiley_code'], |
| 884 | 929 | ) |
| 885 | 930 | ); |
| 886 | - if ($smcFunc['db_num_rows']($request) > 0) |
|
| 887 | - fatal_lang_error('smiley_not_unique'); |
|
| 931 | + if ($smcFunc['db_num_rows']($request) > 0) { |
|
| 932 | + fatal_lang_error('smiley_not_unique'); |
|
| 933 | + } |
|
| 888 | 934 | $smcFunc['db_free_result']($request); |
| 889 | 935 | |
| 890 | 936 | $smcFunc['db_query']('', ' |
@@ -913,13 +959,14 @@ discard block |
||
| 913 | 959 | // Load all known smiley sets. |
| 914 | 960 | $context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']); |
| 915 | 961 | $set_names = explode("\n", $modSettings['smiley_sets_names']); |
| 916 | - foreach ($context['smiley_sets'] as $i => $set) |
|
| 917 | - $context['smiley_sets'][$i] = array( |
|
| 962 | + foreach ($context['smiley_sets'] as $i => $set) { |
|
| 963 | + $context['smiley_sets'][$i] = array( |
|
| 918 | 964 | 'id' => $i, |
| 919 | 965 | 'path' => $smcFunc['htmlspecialchars']($set), |
| 920 | 966 | 'name' => $smcFunc['htmlspecialchars']($set_names[$i]), |
| 921 | 967 | 'selected' => $set == $modSettings['smiley_sets_default'] |
| 922 | 968 | ); |
| 969 | + } |
|
| 923 | 970 | |
| 924 | 971 | // Prepare overview of all (custom) smileys. |
| 925 | 972 | if ($context['sub_action'] == 'editsmileys') |
@@ -935,9 +982,10 @@ discard block |
||
| 935 | 982 | // Create a list of options for selecting smiley sets. |
| 936 | 983 | $smileyset_option_list = ' |
| 937 | 984 | <select name="set" onchange="changeSet(this.options[this.selectedIndex].value);">'; |
| 938 | - foreach ($context['smiley_sets'] as $smiley_set) |
|
| 939 | - $smileyset_option_list .= ' |
|
| 985 | + foreach ($context['smiley_sets'] as $smiley_set) { |
|
| 986 | + $smileyset_option_list .= ' |
|
| 940 | 987 | <option value="' . $smiley_set['path'] . '"' . ($modSettings['smiley_sets_default'] == $smiley_set['path'] ? ' selected' : '') . '>' . $smiley_set['name'] . '</option>'; |
| 988 | + } |
|
| 941 | 989 | $smileyset_option_list .= ' |
| 942 | 990 | </select>'; |
| 943 | 991 | |
@@ -999,12 +1047,13 @@ discard block |
||
| 999 | 1047 | 'data' => array( |
| 1000 | 1048 | 'function' => function ($rowData) use ($txt) |
| 1001 | 1049 | { |
| 1002 | - if (empty($rowData['hidden'])) |
|
| 1003 | - return $txt['smileys_location_form']; |
|
| 1004 | - elseif ($rowData['hidden'] == 1) |
|
| 1005 | - return $txt['smileys_location_hidden']; |
|
| 1006 | - else |
|
| 1007 | - return $txt['smileys_location_popup']; |
|
| 1050 | + if (empty($rowData['hidden'])) { |
|
| 1051 | + return $txt['smileys_location_form']; |
|
| 1052 | + } elseif ($rowData['hidden'] == 1) { |
|
| 1053 | + return $txt['smileys_location_hidden']; |
|
| 1054 | + } else { |
|
| 1055 | + return $txt['smileys_location_popup']; |
|
| 1056 | + } |
|
| 1008 | 1057 | }, |
| 1009 | 1058 | ), |
| 1010 | 1059 | 'sort' => array( |
@@ -1019,19 +1068,22 @@ discard block |
||
| 1019 | 1068 | 'data' => array( |
| 1020 | 1069 | 'function' => function ($rowData) use ($context, $txt, $modSettings, $smcFunc) |
| 1021 | 1070 | { |
| 1022 | - if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'])) |
|
| 1023 | - return $smcFunc['htmlspecialchars']($rowData['description']); |
|
| 1071 | + if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'])) { |
|
| 1072 | + return $smcFunc['htmlspecialchars']($rowData['description']); |
|
| 1073 | + } |
|
| 1024 | 1074 | |
| 1025 | 1075 | // Check if there are smileys missing in some sets. |
| 1026 | 1076 | $missing_sets = array(); |
| 1027 | - foreach ($context['smiley_sets'] as $smiley_set) |
|
| 1028 | - if (!file_exists(sprintf('%1$s/%2$s/%3$s', $modSettings['smileys_dir'], $smiley_set['path'], $rowData['filename']))) |
|
| 1077 | + foreach ($context['smiley_sets'] as $smiley_set) { |
|
| 1078 | + if (!file_exists(sprintf('%1$s/%2$s/%3$s', $modSettings['smileys_dir'], $smiley_set['path'], $rowData['filename']))) |
|
| 1029 | 1079 | $missing_sets[] = $smiley_set['path']; |
| 1080 | + } |
|
| 1030 | 1081 | |
| 1031 | 1082 | $description = $smcFunc['htmlspecialchars']($rowData['description']); |
| 1032 | 1083 | |
| 1033 | - if (!empty($missing_sets)) |
|
| 1034 | - $description .= sprintf('<br><span class="smalltext"><strong>%1$s:</strong> %2$s</span>', $txt['smileys_not_found_in_set'], implode(', ', $missing_sets)); |
|
| 1084 | + if (!empty($missing_sets)) { |
|
| 1085 | + $description .= sprintf('<br><span class="smalltext"><strong>%1$s:</strong> %2$s</span>', $txt['smileys_not_found_in_set'], implode(', ', $missing_sets)); |
|
| 1086 | + } |
|
| 1035 | 1087 | |
| 1036 | 1088 | return $description; |
| 1037 | 1089 | }, |
@@ -1147,13 +1199,14 @@ discard block |
||
| 1147 | 1199 | $context['smileys_dir_found'] = is_dir($context['smileys_dir']); |
| 1148 | 1200 | $context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']); |
| 1149 | 1201 | $set_names = explode("\n", $modSettings['smiley_sets_names']); |
| 1150 | - foreach ($context['smiley_sets'] as $i => $set) |
|
| 1151 | - $context['smiley_sets'][$i] = array( |
|
| 1202 | + foreach ($context['smiley_sets'] as $i => $set) { |
|
| 1203 | + $context['smiley_sets'][$i] = array( |
|
| 1152 | 1204 | 'id' => $i, |
| 1153 | 1205 | 'path' => $smcFunc['htmlspecialchars']($set), |
| 1154 | 1206 | 'name' => $smcFunc['htmlspecialchars']($set_names[$i]), |
| 1155 | 1207 | 'selected' => $set == $modSettings['smiley_sets_default'] |
| 1156 | 1208 | ); |
| 1209 | + } |
|
| 1157 | 1210 | |
| 1158 | 1211 | $context['selected_set'] = $modSettings['smiley_sets_default']; |
| 1159 | 1212 | |
@@ -1163,17 +1216,19 @@ discard block |
||
| 1163 | 1216 | { |
| 1164 | 1217 | foreach ($context['smiley_sets'] as $smiley_set) |
| 1165 | 1218 | { |
| 1166 | - if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']))) |
|
| 1167 | - continue; |
|
| 1219 | + if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']))) { |
|
| 1220 | + continue; |
|
| 1221 | + } |
|
| 1168 | 1222 | |
| 1169 | 1223 | $dir = dir($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path'])); |
| 1170 | 1224 | while ($entry = $dir->read()) |
| 1171 | 1225 | { |
| 1172 | - if (!in_array($entry, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) |
|
| 1173 | - $context['filenames'][strtolower($entry)] = array( |
|
| 1226 | + if (!in_array($entry, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) { |
|
| 1227 | + $context['filenames'][strtolower($entry)] = array( |
|
| 1174 | 1228 | 'id' => $smcFunc['htmlspecialchars']($entry), |
| 1175 | 1229 | 'selected' => false, |
| 1176 | 1230 | ); |
| 1231 | + } |
|
| 1177 | 1232 | } |
| 1178 | 1233 | $dir->close(); |
| 1179 | 1234 | } |
@@ -1188,8 +1243,9 @@ discard block |
||
| 1188 | 1243 | 'current_smiley' => (int) $_REQUEST['smiley'], |
| 1189 | 1244 | ) |
| 1190 | 1245 | ); |
| 1191 | - if ($smcFunc['db_num_rows']($request) != 1) |
|
| 1192 | - fatal_lang_error('smiley_not_found'); |
|
| 1246 | + if ($smcFunc['db_num_rows']($request) != 1) { |
|
| 1247 | + fatal_lang_error('smiley_not_found'); |
|
| 1248 | + } |
|
| 1193 | 1249 | $context['current_smiley'] = $smcFunc['db_fetch_assoc']($request); |
| 1194 | 1250 | $smcFunc['db_free_result']($request); |
| 1195 | 1251 | |
@@ -1197,8 +1253,9 @@ discard block |
||
| 1197 | 1253 | $context['current_smiley']['filename'] = $smcFunc['htmlspecialchars']($context['current_smiley']['filename']); |
| 1198 | 1254 | $context['current_smiley']['description'] = $smcFunc['htmlspecialchars']($context['current_smiley']['description']); |
| 1199 | 1255 | |
| 1200 | - if (isset($context['filenames'][strtolower($context['current_smiley']['filename'])])) |
|
| 1201 | - $context['filenames'][strtolower($context['current_smiley']['filename'])]['selected'] = true; |
|
| 1256 | + if (isset($context['filenames'][strtolower($context['current_smiley']['filename'])])) { |
|
| 1257 | + $context['filenames'][strtolower($context['current_smiley']['filename'])]['selected'] = true; |
|
| 1258 | + } |
|
| 1202 | 1259 | } |
| 1203 | 1260 | } |
| 1204 | 1261 | |
@@ -1223,8 +1280,9 @@ discard block |
||
| 1223 | 1280 | ) |
| 1224 | 1281 | ); |
| 1225 | 1282 | $smileys = array(); |
| 1226 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1227 | - $smileys[] = $row; |
|
| 1283 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1284 | + $smileys[] = $row; |
|
| 1285 | + } |
|
| 1228 | 1286 | $smcFunc['db_free_result']($request); |
| 1229 | 1287 | |
| 1230 | 1288 | return $smileys; |
@@ -1264,8 +1322,9 @@ discard block |
||
| 1264 | 1322 | $_GET['location'] = empty($_GET['location']) || $_GET['location'] != 'popup' ? 0 : 2; |
| 1265 | 1323 | $_GET['source'] = empty($_GET['source']) ? 0 : (int) $_GET['source']; |
| 1266 | 1324 | |
| 1267 | - if (empty($_GET['source'])) |
|
| 1268 | - fatal_lang_error('smiley_not_found'); |
|
| 1325 | + if (empty($_GET['source'])) { |
|
| 1326 | + fatal_lang_error('smiley_not_found'); |
|
| 1327 | + } |
|
| 1269 | 1328 | |
| 1270 | 1329 | if (!empty($_GET['after'])) |
| 1271 | 1330 | { |
@@ -1281,12 +1340,12 @@ discard block |
||
| 1281 | 1340 | 'after_smiley' => $_GET['after'], |
| 1282 | 1341 | ) |
| 1283 | 1342 | ); |
| 1284 | - if ($smcFunc['db_num_rows']($request) != 1) |
|
| 1285 | - fatal_lang_error('smiley_not_found'); |
|
| 1343 | + if ($smcFunc['db_num_rows']($request) != 1) { |
|
| 1344 | + fatal_lang_error('smiley_not_found'); |
|
| 1345 | + } |
|
| 1286 | 1346 | list ($smiley_row, $smiley_order, $smileyLocation) = $smcFunc['db_fetch_row']($request); |
| 1287 | 1347 | $smcFunc['db_free_result']($request); |
| 1288 | - } |
|
| 1289 | - else |
|
| 1348 | + } else |
|
| 1290 | 1349 | { |
| 1291 | 1350 | $smiley_row = (int) $_GET['row']; |
| 1292 | 1351 | $smiley_order = -1; |
@@ -1360,14 +1419,15 @@ discard block |
||
| 1360 | 1419 | $context['move_smiley'] = empty($_REQUEST['move']) ? 0 : (int) $_REQUEST['move']; |
| 1361 | 1420 | |
| 1362 | 1421 | // Make sure all rows are sequential. |
| 1363 | - foreach (array_keys($context['smileys']) as $location) |
|
| 1364 | - $context['smileys'][$location] = array( |
|
| 1422 | + foreach (array_keys($context['smileys']) as $location) { |
|
| 1423 | + $context['smileys'][$location] = array( |
|
| 1365 | 1424 | 'id' => $location, |
| 1366 | 1425 | 'title' => $location == 'postform' ? $txt['smileys_location_form'] : $txt['smileys_location_popup'], |
| 1367 | 1426 | 'description' => $location == 'postform' ? $txt['smileys_location_form_description'] : $txt['smileys_location_popup_description'], |
| 1368 | 1427 | 'last_row' => count($context['smileys'][$location]['rows']), |
| 1369 | 1428 | 'rows' => array_values($context['smileys'][$location]['rows']), |
| 1370 | 1429 | ); |
| 1430 | + } |
|
| 1371 | 1431 | |
| 1372 | 1432 | // Check & fix smileys that are not ordered properly in the database. |
| 1373 | 1433 | foreach (array_keys($context['smileys']) as $location) |
@@ -1392,8 +1452,8 @@ discard block |
||
| 1392 | 1452 | $context['smileys'][$location]['rows'][$id][0]['row'] = $id; |
| 1393 | 1453 | } |
| 1394 | 1454 | // Make sure the smiley order is always sequential. |
| 1395 | - foreach ($smiley_row as $order_id => $smiley) |
|
| 1396 | - if ($order_id != $smiley['order']) |
|
| 1455 | + foreach ($smiley_row as $order_id => $smiley) { |
|
| 1456 | + if ($order_id != $smiley['order']) |
|
| 1397 | 1457 | $smcFunc['db_query']('', ' |
| 1398 | 1458 | UPDATE {db_prefix}smileys |
| 1399 | 1459 | SET smiley_order = {int:new_order} |
@@ -1403,6 +1463,7 @@ discard block |
||
| 1403 | 1463 | 'current_smiley' => $smiley['id'], |
| 1404 | 1464 | ) |
| 1405 | 1465 | ); |
| 1466 | + } |
|
| 1406 | 1467 | } |
| 1407 | 1468 | } |
| 1408 | 1469 | |
@@ -1436,19 +1497,20 @@ discard block |
||
| 1436 | 1497 | |
| 1437 | 1498 | // Check that the smiley is from simplemachines.org, for now... maybe add mirroring later. |
| 1438 | 1499 | // @ TODO: Our current xml files serve http links. Allowing both for now until we serve https. |
| 1439 | - if (preg_match('~^https?://[\w_\-]+\.simplemachines\.org/~', $_REQUEST['set_gz']) == 0 || strpos($_REQUEST['set_gz'], 'dlattach') !== false) |
|
| 1440 | - fatal_lang_error('not_on_simplemachines'); |
|
| 1500 | + if (preg_match('~^https?://[\w_\-]+\.simplemachines\.org/~', $_REQUEST['set_gz']) == 0 || strpos($_REQUEST['set_gz'], 'dlattach') !== false) { |
|
| 1501 | + fatal_lang_error('not_on_simplemachines'); |
|
| 1502 | + } |
|
| 1441 | 1503 | |
| 1442 | 1504 | $destination = $packagesdir . '/' . $base_name; |
| 1443 | 1505 | |
| 1444 | - if (file_exists($destination)) |
|
| 1445 | - fatal_lang_error('package_upload_error_exists'); |
|
| 1506 | + if (file_exists($destination)) { |
|
| 1507 | + fatal_lang_error('package_upload_error_exists'); |
|
| 1508 | + } |
|
| 1446 | 1509 | |
| 1447 | 1510 | // Let's copy it to the Packages directory |
| 1448 | 1511 | file_put_contents($destination, fetch_web_data($_REQUEST['set_gz'])); |
| 1449 | 1512 | $testing = true; |
| 1450 | - } |
|
| 1451 | - elseif (isset($_REQUEST['package'])) |
|
| 1513 | + } elseif (isset($_REQUEST['package'])) |
|
| 1452 | 1514 | { |
| 1453 | 1515 | $base_name = basename($_REQUEST['package']); |
| 1454 | 1516 | $name = $smcFunc['htmlspecialchars'](strtok(basename($_REQUEST['package']), '.')); |
@@ -1457,12 +1519,14 @@ discard block |
||
| 1457 | 1519 | $destination = $packagesdir . '/' . basename($_REQUEST['package']); |
| 1458 | 1520 | } |
| 1459 | 1521 | |
| 1460 | - if (empty($destination) || !file_exists($destination)) |
|
| 1461 | - fatal_lang_error('package_no_file', false); |
|
| 1522 | + if (empty($destination) || !file_exists($destination)) { |
|
| 1523 | + fatal_lang_error('package_no_file', false); |
|
| 1524 | + } |
|
| 1462 | 1525 | |
| 1463 | 1526 | // Make sure temp directory exists and is empty. |
| 1464 | - if (file_exists($packagesdir . '/temp')) |
|
| 1465 | - deltree($packagesdir . '/temp', false); |
|
| 1527 | + if (file_exists($packagesdir . '/temp')) { |
|
| 1528 | + deltree($packagesdir . '/temp', false); |
|
| 1529 | + } |
|
| 1466 | 1530 | |
| 1467 | 1531 | if (!mktree($packagesdir . '/temp', 0755)) |
| 1468 | 1532 | { |
@@ -1474,31 +1538,37 @@ discard block |
||
| 1474 | 1538 | create_chmod_control(array($packagesdir . '/temp/delme.tmp'), array('destination_url' => $scripturl . '?action=admin;area=smileys;sa=install;set_gz=' . $_REQUEST['set_gz'], 'crash_on_error' => true)); |
| 1475 | 1539 | |
| 1476 | 1540 | deltree($packagesdir . '/temp', false); |
| 1477 | - if (!mktree($packagesdir . '/temp', 0777)) |
|
| 1478 | - fatal_lang_error('package_cant_download', false); |
|
| 1541 | + if (!mktree($packagesdir . '/temp', 0777)) { |
|
| 1542 | + fatal_lang_error('package_cant_download', false); |
|
| 1543 | + } |
|
| 1479 | 1544 | } |
| 1480 | 1545 | } |
| 1481 | 1546 | |
| 1482 | 1547 | $extracted = read_tgz_file($destination, $packagesdir . '/temp'); |
| 1483 | - if (!$extracted) |
|
| 1484 | - fatal_lang_error('packageget_unable', false, array('https://custom.simplemachines.org/mods/index.php?action=search;type=12;basic_search=' . $name)); |
|
| 1485 | - if ($extracted && !file_exists($packagesdir . '/temp/package-info.xml')) |
|
| 1486 | - foreach ($extracted as $file) |
|
| 1548 | + if (!$extracted) { |
|
| 1549 | + fatal_lang_error('packageget_unable', false, array('https://custom.simplemachines.org/mods/index.php?action=search;type=12;basic_search=' . $name)); |
|
| 1550 | + } |
|
| 1551 | + if ($extracted && !file_exists($packagesdir . '/temp/package-info.xml')) { |
|
| 1552 | + foreach ($extracted as $file) |
|
| 1487 | 1553 | if (basename($file['filename']) == 'package-info.xml') |
| 1488 | 1554 | { |
| 1489 | 1555 | $base_path = dirname($file['filename']) . '/'; |
| 1556 | + } |
|
| 1490 | 1557 | break; |
| 1491 | 1558 | } |
| 1492 | 1559 | |
| 1493 | - if (!isset($base_path)) |
|
| 1494 | - $base_path = ''; |
|
| 1560 | + if (!isset($base_path)) { |
|
| 1561 | + $base_path = ''; |
|
| 1562 | + } |
|
| 1495 | 1563 | |
| 1496 | - if (!file_exists($packagesdir . '/temp/' . $base_path . 'package-info.xml')) |
|
| 1497 | - fatal_lang_error('package_get_error_missing_xml', false); |
|
| 1564 | + if (!file_exists($packagesdir . '/temp/' . $base_path . 'package-info.xml')) { |
|
| 1565 | + fatal_lang_error('package_get_error_missing_xml', false); |
|
| 1566 | + } |
|
| 1498 | 1567 | |
| 1499 | 1568 | $smileyInfo = getPackageInfo($context['filename']); |
| 1500 | - if (!is_array($smileyInfo)) |
|
| 1501 | - fatal_lang_error($smileyInfo); |
|
| 1569 | + if (!is_array($smileyInfo)) { |
|
| 1570 | + fatal_lang_error($smileyInfo); |
|
| 1571 | + } |
|
| 1502 | 1572 | |
| 1503 | 1573 | // See if it is installed? |
| 1504 | 1574 | $request = $smcFunc['db_query']('', ' |
@@ -1514,8 +1584,9 @@ discard block |
||
| 1514 | 1584 | ) |
| 1515 | 1585 | ); |
| 1516 | 1586 | |
| 1517 | - if ($smcFunc['db_num_rows']($request) > 0) |
|
| 1518 | - fata_lang_error('package_installed_warning1'); |
|
| 1587 | + if ($smcFunc['db_num_rows']($request) > 0) { |
|
| 1588 | + fata_lang_error('package_installed_warning1'); |
|
| 1589 | + } |
|
| 1519 | 1590 | |
| 1520 | 1591 | // Everything is fine, now it's time to do something |
| 1521 | 1592 | $actions = parsePackageInfo($smileyInfo['xml'], true, 'install'); |
@@ -1532,23 +1603,23 @@ discard block |
||
| 1532 | 1603 | { |
| 1533 | 1604 | $has_readme = true; |
| 1534 | 1605 | $type = 'package_' . $action['type']; |
| 1535 | - if (file_exists($packagesdir . '/temp/' . $base_path . $action['filename'])) |
|
| 1536 | - $context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($packagesdir . '/temp/' . $base_path . $action['filename']), "\n\r")); |
|
| 1537 | - elseif (file_exists($action['filename'])) |
|
| 1538 | - $context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($action['filename']), "\n\r")); |
|
| 1606 | + if (file_exists($packagesdir . '/temp/' . $base_path . $action['filename'])) { |
|
| 1607 | + $context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($packagesdir . '/temp/' . $base_path . $action['filename']), "\n\r")); |
|
| 1608 | + } elseif (file_exists($action['filename'])) { |
|
| 1609 | + $context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($action['filename']), "\n\r")); |
|
| 1610 | + } |
|
| 1539 | 1611 | |
| 1540 | 1612 | if (!empty($action['parse_bbc'])) |
| 1541 | 1613 | { |
| 1542 | 1614 | require_once($sourcedir . '/Subs-Post.php'); |
| 1543 | 1615 | preparsecode($context[$type]); |
| 1544 | 1616 | $context[$type] = parse_bbc($context[$type]); |
| 1617 | + } else { |
|
| 1618 | + $context[$type] = nl2br($context[$type]); |
|
| 1545 | 1619 | } |
| 1546 | - else |
|
| 1547 | - $context[$type] = nl2br($context[$type]); |
|
| 1548 | 1620 | |
| 1549 | 1621 | continue; |
| 1550 | - } |
|
| 1551 | - elseif ($action['type'] == 'require-dir') |
|
| 1622 | + } elseif ($action['type'] == 'require-dir') |
|
| 1552 | 1623 | { |
| 1553 | 1624 | // Do this one... |
| 1554 | 1625 | $thisAction = array( |
@@ -1567,12 +1638,12 @@ discard block |
||
| 1567 | 1638 | ); |
| 1568 | 1639 | } |
| 1569 | 1640 | // @todo None given? |
| 1570 | - if (empty($thisAction['description'])) |
|
| 1571 | - $thisAction['description'] = isset($action['description']) ? $action['description'] : ''; |
|
| 1641 | + if (empty($thisAction['description'])) { |
|
| 1642 | + $thisAction['description'] = isset($action['description']) ? $action['description'] : ''; |
|
| 1643 | + } |
|
| 1572 | 1644 | |
| 1573 | 1645 | $context['actions'][] = $thisAction; |
| 1574 | - } |
|
| 1575 | - elseif ($action['type'] == 'credits') |
|
| 1646 | + } elseif ($action['type'] == 'credits') |
|
| 1576 | 1647 | { |
| 1577 | 1648 | // Time to build the billboard |
| 1578 | 1649 | $credits_tag = array( |
@@ -1631,12 +1702,14 @@ discard block |
||
| 1631 | 1702 | cache_put_data('posting_smileys', null, 480); |
| 1632 | 1703 | } |
| 1633 | 1704 | |
| 1634 | - if (file_exists($packagesdir . '/temp')) |
|
| 1635 | - deltree($packagesdir . '/temp'); |
|
| 1705 | + if (file_exists($packagesdir . '/temp')) { |
|
| 1706 | + deltree($packagesdir . '/temp'); |
|
| 1707 | + } |
|
| 1636 | 1708 | |
| 1637 | - if (!$testing) |
|
| 1638 | - redirectexit('action=admin;area=smileys'); |
|
| 1639 | -} |
|
| 1709 | + if (!$testing) { |
|
| 1710 | + redirectexit('action=admin;area=smileys'); |
|
| 1711 | + } |
|
| 1712 | + } |
|
| 1640 | 1713 | |
| 1641 | 1714 | /** |
| 1642 | 1715 | * A function to import new smileys from an existing directory into the database. |
@@ -1647,15 +1720,17 @@ discard block |
||
| 1647 | 1720 | { |
| 1648 | 1721 | global $modSettings, $smcFunc; |
| 1649 | 1722 | |
| 1650 | - if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'] . '/' . $smileyPath)) |
|
| 1651 | - fatal_lang_error('smiley_set_unable_to_import'); |
|
| 1723 | + if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'] . '/' . $smileyPath)) { |
|
| 1724 | + fatal_lang_error('smiley_set_unable_to_import'); |
|
| 1725 | + } |
|
| 1652 | 1726 | |
| 1653 | 1727 | $smileys = array(); |
| 1654 | 1728 | $dir = dir($modSettings['smileys_dir'] . '/' . $smileyPath); |
| 1655 | 1729 | while ($entry = $dir->read()) |
| 1656 | 1730 | { |
| 1657 | - if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) |
|
| 1658 | - $smileys[strtolower($entry)] = $entry; |
|
| 1731 | + if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) { |
|
| 1732 | + $smileys[strtolower($entry)] = $entry; |
|
| 1733 | + } |
|
| 1659 | 1734 | } |
| 1660 | 1735 | $dir->close(); |
| 1661 | 1736 | |
@@ -1668,9 +1743,10 @@ discard block |
||
| 1668 | 1743 | 'smiley_list' => $smileys, |
| 1669 | 1744 | ) |
| 1670 | 1745 | ); |
| 1671 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1672 | - if (isset($smileys[strtolower($row['filename'])])) |
|
| 1746 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1747 | + if (isset($smileys[strtolower($row['filename'])])) |
|
| 1673 | 1748 | unset($smileys[strtolower($row['filename'])]); |
| 1749 | + } |
|
| 1674 | 1750 | $smcFunc['db_free_result']($request); |
| 1675 | 1751 | |
| 1676 | 1752 | $request = $smcFunc['db_query']('', ' |
@@ -1687,9 +1763,10 @@ discard block |
||
| 1687 | 1763 | $smcFunc['db_free_result']($request); |
| 1688 | 1764 | |
| 1689 | 1765 | $new_smileys = array(); |
| 1690 | - foreach ($smileys as $smiley) |
|
| 1691 | - if (strlen($smiley) <= 48) |
|
| 1766 | + foreach ($smileys as $smiley) { |
|
| 1767 | + if (strlen($smiley) <= 48) |
|
| 1692 | 1768 | $new_smileys[] = array(':' . strtok($smiley, '.') . ':', $smiley, strtok($smiley, '.'), 0, ++$smiley_order); |
| 1769 | + } |
|
| 1693 | 1770 | |
| 1694 | 1771 | if (!empty($new_smileys)) |
| 1695 | 1772 | { |
@@ -1754,8 +1831,9 @@ discard block |
||
| 1754 | 1831 | if (isset($_POST['delete']) && !empty($_POST['checked_icons'])) |
| 1755 | 1832 | { |
| 1756 | 1833 | $deleteIcons = array(); |
| 1757 | - foreach ($_POST['checked_icons'] as $icon) |
|
| 1758 | - $deleteIcons[] = (int) $icon; |
|
| 1834 | + foreach ($_POST['checked_icons'] as $icon) { |
|
| 1835 | + $deleteIcons[] = (int) $icon; |
|
| 1836 | + } |
|
| 1759 | 1837 | |
| 1760 | 1838 | // Do the actual delete! |
| 1761 | 1839 | $smcFunc['db_query']('', ' |
@@ -1772,35 +1850,41 @@ discard block |
||
| 1772 | 1850 | $_GET['icon'] = (int) $_GET['icon']; |
| 1773 | 1851 | |
| 1774 | 1852 | // Do some preperation with the data... like check the icon exists *somewhere* |
| 1775 | - if (strpos($_POST['icon_filename'], '.png') !== false) |
|
| 1776 | - $_POST['icon_filename'] = substr($_POST['icon_filename'], 0, -4); |
|
| 1777 | - if (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon_filename'] . '.png')) |
|
| 1778 | - fatal_lang_error('icon_not_found'); |
|
| 1853 | + if (strpos($_POST['icon_filename'], '.png') !== false) { |
|
| 1854 | + $_POST['icon_filename'] = substr($_POST['icon_filename'], 0, -4); |
|
| 1855 | + } |
|
| 1856 | + if (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon_filename'] . '.png')) { |
|
| 1857 | + fatal_lang_error('icon_not_found'); |
|
| 1858 | + } |
|
| 1779 | 1859 | // There is a 16 character limit on message icons... |
| 1780 | - elseif (strlen($_POST['icon_filename']) > 16) |
|
| 1781 | - fatal_lang_error('icon_name_too_long'); |
|
| 1782 | - elseif ($_POST['icon_location'] == $_GET['icon'] && !empty($_GET['icon'])) |
|
| 1783 | - fatal_lang_error('icon_after_itself'); |
|
| 1860 | + elseif (strlen($_POST['icon_filename']) > 16) { |
|
| 1861 | + fatal_lang_error('icon_name_too_long'); |
|
| 1862 | + } elseif ($_POST['icon_location'] == $_GET['icon'] && !empty($_GET['icon'])) { |
|
| 1863 | + fatal_lang_error('icon_after_itself'); |
|
| 1864 | + } |
|
| 1784 | 1865 | |
| 1785 | 1866 | // First do the sorting... if this is an edit reduce the order of everything after it by one ;) |
| 1786 | 1867 | if ($_GET['icon'] != 0) |
| 1787 | 1868 | { |
| 1788 | 1869 | $oldOrder = $context['icons'][$_GET['icon']]['true_order']; |
| 1789 | - foreach ($context['icons'] as $id => $data) |
|
| 1790 | - if ($data['true_order'] > $oldOrder) |
|
| 1870 | + foreach ($context['icons'] as $id => $data) { |
|
| 1871 | + if ($data['true_order'] > $oldOrder) |
|
| 1791 | 1872 | $context['icons'][$id]['true_order']--; |
| 1873 | + } |
|
| 1792 | 1874 | } |
| 1793 | 1875 | |
| 1794 | 1876 | // If there are no existing icons and this is a new one, set the id to 1 (mainly for non-mysql) |
| 1795 | - if (empty($_GET['icon']) && empty($context['icons'])) |
|
| 1796 | - $_GET['icon'] = 1; |
|
| 1877 | + if (empty($_GET['icon']) && empty($context['icons'])) { |
|
| 1878 | + $_GET['icon'] = 1; |
|
| 1879 | + } |
|
| 1797 | 1880 | |
| 1798 | 1881 | // Get the new order. |
| 1799 | 1882 | $newOrder = $_POST['icon_location'] == 0 ? 0 : $context['icons'][$_POST['icon_location']]['true_order'] + 1; |
| 1800 | 1883 | // Do the same, but with the one that used to be after this icon, done to avoid conflict. |
| 1801 | - foreach ($context['icons'] as $id => $data) |
|
| 1802 | - if ($data['true_order'] >= $newOrder) |
|
| 1884 | + foreach ($context['icons'] as $id => $data) { |
|
| 1885 | + if ($data['true_order'] >= $newOrder) |
|
| 1803 | 1886 | $context['icons'][$id]['true_order']++; |
| 1887 | + } |
|
| 1804 | 1888 | |
| 1805 | 1889 | // Finally set the current icon's position! |
| 1806 | 1890 | $context['icons'][$_GET['icon']]['true_order'] = $newOrder; |
@@ -1818,8 +1902,7 @@ discard block |
||
| 1818 | 1902 | if ($id != 0) |
| 1819 | 1903 | { |
| 1820 | 1904 | $iconInsert[] = array($id, $icon['board_id'], $icon['title'], $icon['filename'], $icon['true_order']); |
| 1821 | - } |
|
| 1822 | - else |
|
| 1905 | + } else |
|
| 1823 | 1906 | { |
| 1824 | 1907 | $iconInsert_new[] = array($icon['board_id'], $icon['title'], $icon['filename'], $icon['true_order']); |
| 1825 | 1908 | } |
@@ -1844,8 +1927,9 @@ discard block |
||
| 1844 | 1927 | } |
| 1845 | 1928 | |
| 1846 | 1929 | // Unless we're adding a new thing, we'll escape |
| 1847 | - if (!isset($_POST['add'])) |
|
| 1848 | - redirectexit('action=admin;area=smileys;sa=editicons'); |
|
| 1930 | + if (!isset($_POST['add'])) { |
|
| 1931 | + redirectexit('action=admin;area=smileys;sa=editicons'); |
|
| 1932 | + } |
|
| 1849 | 1933 | } |
| 1850 | 1934 | |
| 1851 | 1935 | $context[$context['admin_menu_name']]['current_subsection'] = 'editicons'; |
@@ -1955,8 +2039,9 @@ discard block |
||
| 1955 | 2039 | $context['new_icon'] = !isset($_GET['icon']); |
| 1956 | 2040 | |
| 1957 | 2041 | // Get the properties of the current icon from the icon list. |
| 1958 | - if (!$context['new_icon']) |
|
| 1959 | - $context['icon'] = $context['icons'][$_GET['icon']]; |
|
| 2042 | + if (!$context['new_icon']) { |
|
| 2043 | + $context['icon'] = $context['icons'][$_GET['icon']]; |
|
| 2044 | + } |
|
| 1960 | 2045 | |
| 1961 | 2046 | // Get a list of boards needed for assigning this icon to a specific board. |
| 1962 | 2047 | $boardListOptions = array( |
@@ -1990,8 +2075,9 @@ discard block |
||
| 1990 | 2075 | ); |
| 1991 | 2076 | |
| 1992 | 2077 | $message_icons = array(); |
| 1993 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1994 | - $message_icons[] = $row; |
|
| 2078 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 2079 | + $message_icons[] = $row; |
|
| 2080 | + } |
|
| 1995 | 2081 | $smcFunc['db_free_result']($request); |
| 1996 | 2082 | |
| 1997 | 2083 | return $message_icons; |
@@ -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 | * Browse the list of package servers, add servers... |
@@ -43,13 +44,15 @@ discard block |
||
| 43 | 44 | ); |
| 44 | 45 | |
| 45 | 46 | // Now let's decide where we are taking this... |
| 46 | - if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) |
|
| 47 | - $context['sub_action'] = $_REQUEST['sa']; |
|
| 47 | + if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) { |
|
| 48 | + $context['sub_action'] = $_REQUEST['sa']; |
|
| 49 | + } |
|
| 48 | 50 | // We need to support possible old javascript links... |
| 49 | - elseif (isset($_GET['pgdownload'])) |
|
| 50 | - $context['sub_action'] = 'download'; |
|
| 51 | - else |
|
| 52 | - $context['sub_action'] = 'servers'; |
|
| 51 | + elseif (isset($_GET['pgdownload'])) { |
|
| 52 | + $context['sub_action'] = 'download'; |
|
| 53 | + } else { |
|
| 54 | + $context['sub_action'] = 'servers'; |
|
| 55 | + } |
|
| 53 | 56 | |
| 54 | 57 | // We need to force the "Download" tab as selected. |
| 55 | 58 | $context['menu_data_' . $context['admin_menu_id']]['current_subsection'] = 'packageget'; |
@@ -141,17 +144,19 @@ discard block |
||
| 141 | 144 | { |
| 142 | 145 | require_once($sourcedir . '/Class-Package.php'); |
| 143 | 146 | $ftp = new ftp_connection(null); |
| 147 | + } elseif ($ftp->error !== false && !isset($ftp_error)) { |
|
| 148 | + $ftp_error = $ftp->last_message === null ? '' : $ftp->last_message; |
|
| 144 | 149 | } |
| 145 | - elseif ($ftp->error !== false && !isset($ftp_error)) |
|
| 146 | - $ftp_error = $ftp->last_message === null ? '' : $ftp->last_message; |
|
| 147 | 150 | |
| 148 | 151 | list ($username, $detect_path, $found_path) = $ftp->detect_path($packagesdir); |
| 149 | 152 | |
| 150 | - if ($found_path || !isset($_POST['ftp_path'])) |
|
| 151 | - $_POST['ftp_path'] = $detect_path; |
|
| 153 | + if ($found_path || !isset($_POST['ftp_path'])) { |
|
| 154 | + $_POST['ftp_path'] = $detect_path; |
|
| 155 | + } |
|
| 152 | 156 | |
| 153 | - if (!isset($_POST['ftp_username'])) |
|
| 154 | - $_POST['ftp_username'] = $username; |
|
| 157 | + if (!isset($_POST['ftp_username'])) { |
|
| 158 | + $_POST['ftp_username'] = $username; |
|
| 159 | + } |
|
| 155 | 160 | |
| 156 | 161 | $context['package_ftp'] = array( |
| 157 | 162 | 'server' => isset($_POST['ftp_server']) ? $_POST['ftp_server'] : (isset($modSettings['package_server']) ? $modSettings['package_server'] : 'localhost'), |
@@ -160,8 +165,7 @@ discard block |
||
| 160 | 165 | 'path' => $_POST['ftp_path'], |
| 161 | 166 | 'error' => empty($ftp_error) ? null : $ftp_error, |
| 162 | 167 | ); |
| 163 | - } |
|
| 164 | - else |
|
| 168 | + } else |
|
| 165 | 169 | { |
| 166 | 170 | $context['package_download_broken'] = false; |
| 167 | 171 | |
@@ -203,8 +207,9 @@ discard block |
||
| 203 | 207 | |
| 204 | 208 | if (isset($_GET['server'])) |
| 205 | 209 | { |
| 206 | - if ($_GET['server'] == '') |
|
| 207 | - redirectexit('action=admin;area=packages;get'); |
|
| 210 | + if ($_GET['server'] == '') { |
|
| 211 | + redirectexit('action=admin;area=packages;get'); |
|
| 212 | + } |
|
| 208 | 213 | |
| 209 | 214 | $server = (int) $_GET['server']; |
| 210 | 215 | |
@@ -222,17 +227,18 @@ discard block |
||
| 222 | 227 | $smcFunc['db_free_result']($request); |
| 223 | 228 | |
| 224 | 229 | // If the server does not exist, dump out. |
| 225 | - if (empty($url)) |
|
| 226 | - fatal_lang_error('couldnt_connect', false); |
|
| 230 | + if (empty($url)) { |
|
| 231 | + fatal_lang_error('couldnt_connect', false); |
|
| 232 | + } |
|
| 227 | 233 | |
| 228 | 234 | // If there is a relative link, append to the stored server url. |
| 229 | - if (isset($_GET['relative'])) |
|
| 230 | - $url = $url . (substr($url, -1) == '/' ? '' : '/') . $_GET['relative']; |
|
| 235 | + if (isset($_GET['relative'])) { |
|
| 236 | + $url = $url . (substr($url, -1) == '/' ? '' : '/') . $_GET['relative']; |
|
| 237 | + } |
|
| 231 | 238 | |
| 232 | 239 | // Clear any "absolute" URL. Since "server" is present, "absolute" is garbage. |
| 233 | 240 | unset($_GET['absolute']); |
| 234 | - } |
|
| 235 | - elseif (isset($_GET['absolute']) && $_GET['absolute'] != '') |
|
| 241 | + } elseif (isset($_GET['absolute']) && $_GET['absolute'] != '') |
|
| 236 | 242 | { |
| 237 | 243 | // Initialize the requried variables. |
| 238 | 244 | $server = ''; |
@@ -256,16 +262,19 @@ discard block |
||
| 256 | 262 | } |
| 257 | 263 | } |
| 258 | 264 | // Minimum required parameter did not exist so dump out. |
| 259 | - else |
|
| 260 | - fatal_lang_error('couldnt_connect', false); |
|
| 265 | + else { |
|
| 266 | + fatal_lang_error('couldnt_connect', false); |
|
| 267 | + } |
|
| 261 | 268 | |
| 262 | 269 | // Attempt to connect. If unsuccessful... try the URL. |
| 263 | - if (!isset($_GET['package']) || file_exists($_GET['package'])) |
|
| 264 | - $_GET['package'] = $url . '/packages.xml?language=' . $context['user']['language']; |
|
| 270 | + if (!isset($_GET['package']) || file_exists($_GET['package'])) { |
|
| 271 | + $_GET['package'] = $url . '/packages.xml?language=' . $context['user']['language']; |
|
| 272 | + } |
|
| 265 | 273 | |
| 266 | 274 | // Check to be sure the packages.xml file actually exists where it is should be... or dump out. |
| 267 | - if ((isset($_GET['absolute']) || isset($_GET['relative'])) && !url_exists($_GET['package'])) |
|
| 268 | - fatal_lang_error('packageget_unable', false, array($url . '/index.php')); |
|
| 275 | + if ((isset($_GET['absolute']) || isset($_GET['relative'])) && !url_exists($_GET['package'])) { |
|
| 276 | + fatal_lang_error('packageget_unable', false, array($url . '/index.php')); |
|
| 277 | + } |
|
| 269 | 278 | |
| 270 | 279 | // Might take some time. |
| 271 | 280 | @set_time_limit(600); |
@@ -275,8 +284,9 @@ discard block |
||
| 275 | 284 | $listing = new xmlArray(fetch_web_data($_GET['package']), true); |
| 276 | 285 | |
| 277 | 286 | // Errm.... empty file? Try the URL.... |
| 278 | - if (!$listing->exists('package-list')) |
|
| 279 | - fatal_lang_error('packageget_unable', false, array($url . '/index.php')); |
|
| 287 | + if (!$listing->exists('package-list')) { |
|
| 288 | + fatal_lang_error('packageget_unable', false, array($url . '/index.php')); |
|
| 289 | + } |
|
| 280 | 290 | |
| 281 | 291 | // List out the packages... |
| 282 | 292 | $context['package_list'] = array(); |
@@ -284,8 +294,9 @@ discard block |
||
| 284 | 294 | $listing = $listing->path('package-list[0]'); |
| 285 | 295 | |
| 286 | 296 | // Use the package list's name if it exists. |
| 287 | - if ($listing->exists('list-title')) |
|
| 288 | - $name = $smcFunc['htmlspecialchars']($listing->fetch('list-title')); |
|
| 297 | + if ($listing->exists('list-title')) { |
|
| 298 | + $name = $smcFunc['htmlspecialchars']($listing->fetch('list-title')); |
|
| 299 | + } |
|
| 289 | 300 | |
| 290 | 301 | // Pick the correct template. |
| 291 | 302 | $context['sub_template'] = 'package_list'; |
@@ -300,28 +311,32 @@ discard block |
||
| 300 | 311 | |
| 301 | 312 | $installed_mods = array(); |
| 302 | 313 | // Look through the list of installed mods... |
| 303 | - foreach ($instmods as $installed_mod) |
|
| 304 | - $installed_mods[$installed_mod['package_id']] = $installed_mod['version']; |
|
| 314 | + foreach ($instmods as $installed_mod) { |
|
| 315 | + $installed_mods[$installed_mod['package_id']] = $installed_mod['version']; |
|
| 316 | + } |
|
| 305 | 317 | |
| 306 | 318 | // Get default author and email if they exist. |
| 307 | 319 | if ($listing->exists('default-author')) |
| 308 | 320 | { |
| 309 | 321 | $default_author = $smcFunc['htmlspecialchars']($listing->fetch('default-author')); |
| 310 | - if ($listing->exists('default-author/@email') && filter_var($listing->fetch('default-author/@email'), FILTER_VALIDATE_EMAIL)) |
|
| 311 | - $default_email = $smcFunc['htmlspecialchars']($listing->fetch('default-author/@email')); |
|
| 322 | + if ($listing->exists('default-author/@email') && filter_var($listing->fetch('default-author/@email'), FILTER_VALIDATE_EMAIL)) { |
|
| 323 | + $default_email = $smcFunc['htmlspecialchars']($listing->fetch('default-author/@email')); |
|
| 324 | + } |
|
| 312 | 325 | } |
| 313 | 326 | |
| 314 | 327 | // Get default web site if it exists. |
| 315 | 328 | if ($listing->exists('default-website')) |
| 316 | 329 | { |
| 317 | 330 | $default_website = $smcFunc['htmlspecialchars']($listing->fetch('default-website')); |
| 318 | - if ($listing->exists('default-website/@title')) |
|
| 319 | - $default_title = $smcFunc['htmlspecialchars']($listing->fetch('default-website/@title')); |
|
| 331 | + if ($listing->exists('default-website/@title')) { |
|
| 332 | + $default_title = $smcFunc['htmlspecialchars']($listing->fetch('default-website/@title')); |
|
| 333 | + } |
|
| 320 | 334 | } |
| 321 | 335 | |
| 322 | 336 | $the_version = strtr($forum_version, array('SMF ' => '')); |
| 323 | - if (!empty($_SESSION['version_emulate'])) |
|
| 324 | - $the_version = $_SESSION['version_emulate']; |
|
| 337 | + if (!empty($_SESSION['version_emulate'])) { |
|
| 338 | + $the_version = $_SESSION['version_emulate']; |
|
| 339 | + } |
|
| 325 | 340 | |
| 326 | 341 | $packageNum = 0; |
| 327 | 342 | $packageSection = 0; |
@@ -342,11 +357,13 @@ discard block |
||
| 342 | 357 | 'type' => $thisPackage->name(), |
| 343 | 358 | ); |
| 344 | 359 | |
| 345 | - if (in_array($package['type'], array('title', 'text'))) |
|
| 346 | - $context['package_list'][$packageSection][$package['type']] = $smcFunc['htmlspecialchars']($thisPackage->fetch('.')); |
|
| 360 | + if (in_array($package['type'], array('title', 'text'))) { |
|
| 361 | + $context['package_list'][$packageSection][$package['type']] = $smcFunc['htmlspecialchars']($thisPackage->fetch('.')); |
|
| 362 | + } |
|
| 347 | 363 | // It's a Title, Heading, Rule or Text. |
| 348 | - elseif (in_array($package['type'], array('heading', 'rule'))) |
|
| 349 | - $package['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('.')); |
|
| 364 | + elseif (in_array($package['type'], array('heading', 'rule'))) { |
|
| 365 | + $package['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('.')); |
|
| 366 | + } |
|
| 350 | 367 | // It's a Remote link. |
| 351 | 368 | elseif ($package['type'] == 'remote') |
| 352 | 369 | { |
@@ -354,20 +371,21 @@ discard block |
||
| 354 | 371 | |
| 355 | 372 | if ($remote_type == 'relative' && substr($thisPackage->fetch('@href'), 0, 7) != 'http://' && substr($thisPackage->fetch('@href'), 0, 8) != 'https://') |
| 356 | 373 | { |
| 357 | - if (isset($_GET['absolute'])) |
|
| 358 | - $current_url = $_GET['absolute'] . '/'; |
|
| 359 | - elseif (isset($_GET['relative'])) |
|
| 360 | - $current_url = $_GET['relative'] . '/'; |
|
| 361 | - else |
|
| 362 | - $current_url = ''; |
|
| 374 | + if (isset($_GET['absolute'])) { |
|
| 375 | + $current_url = $_GET['absolute'] . '/'; |
|
| 376 | + } elseif (isset($_GET['relative'])) { |
|
| 377 | + $current_url = $_GET['relative'] . '/'; |
|
| 378 | + } else { |
|
| 379 | + $current_url = ''; |
|
| 380 | + } |
|
| 363 | 381 | |
| 364 | 382 | $current_url .= $thisPackage->fetch('@href'); |
| 365 | - if (isset($_GET['absolute'])) |
|
| 366 | - $package['href'] = $scripturl . '?action=admin;area=packages;get;sa=browse;absolute=' . $current_url; |
|
| 367 | - else |
|
| 368 | - $package['href'] = $scripturl . '?action=admin;area=packages;get;sa=browse;server=' . $context['package_server'] . ';relative=' . $current_url; |
|
| 369 | - } |
|
| 370 | - else |
|
| 383 | + if (isset($_GET['absolute'])) { |
|
| 384 | + $package['href'] = $scripturl . '?action=admin;area=packages;get;sa=browse;absolute=' . $current_url; |
|
| 385 | + } else { |
|
| 386 | + $package['href'] = $scripturl . '?action=admin;area=packages;get;sa=browse;server=' . $context['package_server'] . ';relative=' . $current_url; |
|
| 387 | + } |
|
| 388 | + } else |
|
| 371 | 389 | { |
| 372 | 390 | $current_url = $thisPackage->fetch('@href'); |
| 373 | 391 | $package['href'] = $scripturl . '?action=admin;area=packages;get;sa=browse;absolute=' . $current_url; |
@@ -379,25 +397,28 @@ discard block |
||
| 379 | 397 | // It's a package... |
| 380 | 398 | else |
| 381 | 399 | { |
| 382 | - if (isset($_GET['absolute'])) |
|
| 383 | - $current_url = $_GET['absolute'] . '/'; |
|
| 384 | - elseif (isset($_GET['relative'])) |
|
| 385 | - $current_url = $_GET['relative'] . '/'; |
|
| 386 | - else |
|
| 387 | - $current_url = ''; |
|
| 400 | + if (isset($_GET['absolute'])) { |
|
| 401 | + $current_url = $_GET['absolute'] . '/'; |
|
| 402 | + } elseif (isset($_GET['relative'])) { |
|
| 403 | + $current_url = $_GET['relative'] . '/'; |
|
| 404 | + } else { |
|
| 405 | + $current_url = ''; |
|
| 406 | + } |
|
| 388 | 407 | |
| 389 | 408 | $server_att = $server != '' ? ';server=' . $server : ''; |
| 390 | 409 | |
| 391 | 410 | $package += $thisPackage->to_array(); |
| 392 | 411 | |
| 393 | - if (isset($package['website'])) |
|
| 394 | - unset($package['website']); |
|
| 412 | + if (isset($package['website'])) { |
|
| 413 | + unset($package['website']); |
|
| 414 | + } |
|
| 395 | 415 | $package['author'] = array(); |
| 396 | 416 | |
| 397 | - if ($package['description'] == '') |
|
| 398 | - $package['description'] = $txt['package_no_description']; |
|
| 399 | - else |
|
| 400 | - $package['description'] = parse_bbc(preg_replace('~\[[/]?html\]~i', '', $smcFunc['htmlspecialchars']($package['description']))); |
|
| 417 | + if ($package['description'] == '') { |
|
| 418 | + $package['description'] = $txt['package_no_description']; |
|
| 419 | + } else { |
|
| 420 | + $package['description'] = parse_bbc(preg_replace('~\[[/]?html\]~i', '', $smcFunc['htmlspecialchars']($package['description']))); |
|
| 421 | + } |
|
| 401 | 422 | |
| 402 | 423 | $package['is_installed'] = isset($installed_mods[$package['id']]); |
| 403 | 424 | $package['is_current'] = $package['is_installed'] && ($installed_mods[$package['id']] == $package['version']); |
@@ -406,12 +427,14 @@ discard block |
||
| 406 | 427 | // This package is either not installed, or installed but old. Is it supported on this version of SMF? |
| 407 | 428 | if (!$package['is_installed'] || (!$package['is_current'] && !$package['is_newer'])) |
| 408 | 429 | { |
| 409 | - if ($thisPackage->exists('version/@for')) |
|
| 410 | - $package['can_install'] = matchPackageVersion($the_version, $thisPackage->fetch('version/@for')); |
|
| 430 | + if ($thisPackage->exists('version/@for')) { |
|
| 431 | + $package['can_install'] = matchPackageVersion($the_version, $thisPackage->fetch('version/@for')); |
|
| 432 | + } |
|
| 411 | 433 | } |
| 412 | 434 | // Okay, it's already installed AND up to date. |
| 413 | - else |
|
| 414 | - $package['can_install'] = false; |
|
| 435 | + else { |
|
| 436 | + $package['can_install'] = false; |
|
| 437 | + } |
|
| 415 | 438 | |
| 416 | 439 | $already_exists = getPackageInfo(basename($package['filename'])); |
| 417 | 440 | $package['download_conflict'] = is_array($already_exists) && $already_exists['id'] == $package['id'] && $already_exists['version'] != $package['version']; |
@@ -423,40 +446,44 @@ discard block |
||
| 423 | 446 | |
| 424 | 447 | if ($thisPackage->exists('author') || isset($default_author)) |
| 425 | 448 | { |
| 426 | - if ($thisPackage->exists('author/@email') && filter_var($thisPackage->fetch('author/@email'), FILTER_VALIDATE_EMAIL)) |
|
| 427 | - $package['author']['email'] = $thisPackage->fetch('author/@email'); |
|
| 428 | - elseif (isset($default_email)) |
|
| 429 | - $package['author']['email'] = $default_email; |
|
| 430 | - |
|
| 431 | - if ($thisPackage->exists('author') && $thisPackage->fetch('author') != '') |
|
| 432 | - $package['author']['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('author')); |
|
| 433 | - else |
|
| 434 | - $package['author']['name'] = $default_author; |
|
| 435 | - |
|
| 436 | - if (!empty($package['author']['email'])) |
|
| 437 | - $package['author']['link'] = '<a href="mailto:' . $package['author']['email'] . '">' . $package['author']['name'] . '</a>'; |
|
| 449 | + if ($thisPackage->exists('author/@email') && filter_var($thisPackage->fetch('author/@email'), FILTER_VALIDATE_EMAIL)) { |
|
| 450 | + $package['author']['email'] = $thisPackage->fetch('author/@email'); |
|
| 451 | + } elseif (isset($default_email)) { |
|
| 452 | + $package['author']['email'] = $default_email; |
|
| 453 | + } |
|
| 454 | + |
|
| 455 | + if ($thisPackage->exists('author') && $thisPackage->fetch('author') != '') { |
|
| 456 | + $package['author']['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('author')); |
|
| 457 | + } else { |
|
| 458 | + $package['author']['name'] = $default_author; |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + if (!empty($package['author']['email'])) { |
|
| 462 | + $package['author']['link'] = '<a href="mailto:' . $package['author']['email'] . '">' . $package['author']['name'] . '</a>'; |
|
| 463 | + } |
|
| 438 | 464 | } |
| 439 | 465 | |
| 440 | 466 | if ($thisPackage->exists('website') || isset($default_website)) |
| 441 | 467 | { |
| 442 | - if ($thisPackage->exists('website') && $thisPackage->exists('website/@title')) |
|
| 443 | - $package['author']['website']['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('website/@title')); |
|
| 444 | - elseif (isset($default_title)) |
|
| 445 | - $package['author']['website']['name'] = $default_title; |
|
| 446 | - elseif ($thisPackage->exists('website')) |
|
| 447 | - $package['author']['website']['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('website')); |
|
| 448 | - else |
|
| 449 | - $package['author']['website']['name'] = $default_website; |
|
| 450 | - |
|
| 451 | - if ($thisPackage->exists('website') && $thisPackage->fetch('website') != '') |
|
| 452 | - $authorhompage = $smcFunc['htmlspecialchars']($thisPackage->fetch('website')); |
|
| 453 | - else |
|
| 454 | - $authorhompage = $default_website; |
|
| 468 | + if ($thisPackage->exists('website') && $thisPackage->exists('website/@title')) { |
|
| 469 | + $package['author']['website']['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('website/@title')); |
|
| 470 | + } elseif (isset($default_title)) { |
|
| 471 | + $package['author']['website']['name'] = $default_title; |
|
| 472 | + } elseif ($thisPackage->exists('website')) { |
|
| 473 | + $package['author']['website']['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('website')); |
|
| 474 | + } else { |
|
| 475 | + $package['author']['website']['name'] = $default_website; |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + if ($thisPackage->exists('website') && $thisPackage->fetch('website') != '') { |
|
| 479 | + $authorhompage = $smcFunc['htmlspecialchars']($thisPackage->fetch('website')); |
|
| 480 | + } else { |
|
| 481 | + $authorhompage = $default_website; |
|
| 482 | + } |
|
| 455 | 483 | |
| 456 | 484 | $package['author']['website']['href'] = $authorhompage; |
| 457 | 485 | $package['author']['website']['link'] = '<a href="' . $authorhompage . '">' . $package['author']['website']['name'] . '</a>'; |
| 458 | - } |
|
| 459 | - else |
|
| 486 | + } else |
|
| 460 | 487 | { |
| 461 | 488 | $package['author']['website']['href'] = ''; |
| 462 | 489 | $package['author']['website']['link'] = ''; |
@@ -472,11 +499,13 @@ discard block |
||
| 472 | 499 | $packageNum = in_array($package['type'], array('title', 'heading', 'text', 'remote', 'rule')) ? 0 : $packageNum + 1; |
| 473 | 500 | $package['count'] = $packageNum; |
| 474 | 501 | |
| 475 | - if (!in_array($package['type'], array('title', 'text'))) |
|
| 476 | - $context['package_list'][$packageSection]['items'][] = $package; |
|
| 502 | + if (!in_array($package['type'], array('title', 'text'))) { |
|
| 503 | + $context['package_list'][$packageSection]['items'][] = $package; |
|
| 504 | + } |
|
| 477 | 505 | |
| 478 | - if ($package['count'] > 1) |
|
| 479 | - $context['list_type'] = 'ol'; |
|
| 506 | + if ($package['count'] > 1) { |
|
| 507 | + $context['list_type'] = 'ol'; |
|
| 508 | + } |
|
| 480 | 509 | } |
| 481 | 510 | |
| 482 | 511 | $packageSection++; |
@@ -489,8 +518,9 @@ discard block |
||
| 489 | 518 | { |
| 490 | 519 | foreach ($packageSection['items'] as $i => $package) |
| 491 | 520 | { |
| 492 | - if ($package['count'] == 0 || isset($package['can_install'])) |
|
| 493 | - continue; |
|
| 521 | + if ($package['count'] == 0 || isset($package['can_install'])) { |
|
| 522 | + continue; |
|
| 523 | + } |
|
| 494 | 524 | |
| 495 | 525 | $context['package_list'][$ps_id]['items'][$i]['can_install'] = false; |
| 496 | 526 | |
@@ -539,8 +569,9 @@ discard block |
||
| 539 | 569 | checkSession('get'); |
| 540 | 570 | |
| 541 | 571 | // To download something, we need a valid server or url. |
| 542 | - if (empty($_GET['server']) && (!empty($_GET['get']) && !empty($_REQUEST['package']))) |
|
| 543 | - fatal_lang_error('package_get_error_is_zero', false); |
|
| 572 | + if (empty($_GET['server']) && (!empty($_GET['get']) && !empty($_REQUEST['package']))) { |
|
| 573 | + fatal_lang_error('package_get_error_is_zero', false); |
|
| 574 | + } |
|
| 544 | 575 | |
| 545 | 576 | if (isset($_GET['server'])) |
| 546 | 577 | { |
@@ -560,22 +591,23 @@ discard block |
||
| 560 | 591 | $smcFunc['db_free_result']($request); |
| 561 | 592 | |
| 562 | 593 | // If server does not exist then dump out. |
| 563 | - if (empty($url)) |
|
| 564 | - fatal_lang_error('couldnt_connect', false); |
|
| 594 | + if (empty($url)) { |
|
| 595 | + fatal_lang_error('couldnt_connect', false); |
|
| 596 | + } |
|
| 565 | 597 | |
| 566 | 598 | $url = $url . '/'; |
| 567 | - } |
|
| 568 | - else |
|
| 599 | + } else |
|
| 569 | 600 | { |
| 570 | 601 | // Initialize the requried variables. |
| 571 | 602 | $server = ''; |
| 572 | 603 | $url = ''; |
| 573 | 604 | } |
| 574 | 605 | |
| 575 | - if (isset($_REQUEST['byurl']) && !empty($_POST['filename'])) |
|
| 576 | - $package_name = basename($_REQUEST['filename']); |
|
| 577 | - else |
|
| 578 | - $package_name = basename($_REQUEST['package']); |
|
| 606 | + if (isset($_REQUEST['byurl']) && !empty($_POST['filename'])) { |
|
| 607 | + $package_name = basename($_REQUEST['filename']); |
|
| 608 | + } else { |
|
| 609 | + $package_name = basename($_REQUEST['package']); |
|
| 610 | + } |
|
| 579 | 611 | |
| 580 | 612 | if (isset($_REQUEST['conflict']) || (isset($_REQUEST['auto']) && file_exists($packagesdir . '/' . $package_name))) |
| 581 | 613 | { |
@@ -584,14 +616,15 @@ discard block |
||
| 584 | 616 | { |
| 585 | 617 | $ext = substr($package_name, strrpos(substr($package_name, 0, -3), '.')); |
| 586 | 618 | $package_name = substr($package_name, 0, strrpos(substr($package_name, 0, -3), '.')) . '_'; |
| 619 | + } else { |
|
| 620 | + $ext = ''; |
|
| 587 | 621 | } |
| 588 | - else |
|
| 589 | - $ext = ''; |
|
| 590 | 622 | |
| 591 | 623 | // Find the first available. |
| 592 | 624 | $i = 1; |
| 593 | - while (file_exists($packagesdir . '/' . $package_name . $i . $ext)) |
|
| 594 | - $i++; |
|
| 625 | + while (file_exists($packagesdir . '/' . $package_name . $i . $ext)) { |
|
| 626 | + $i++; |
|
| 627 | + } |
|
| 595 | 628 | |
| 596 | 629 | $package_name = $package_name . $i . $ext; |
| 597 | 630 | } |
@@ -602,25 +635,28 @@ discard block |
||
| 602 | 635 | |
| 603 | 636 | // Done! Did we get this package automatically? |
| 604 | 637 | // @ TODO: These are usually update packages. Allowing both for now until more testing has been done. |
| 605 | - if (preg_match('~^https?://[\w_\-]+\.simplemachines\.org/~', $_REQUEST['package']) == 1 && strpos($_REQUEST['package'], 'dlattach') === false && isset($_REQUEST['auto'])) |
|
| 606 | - redirectexit('action=admin;area=packages;sa=install;package=' . $package_name); |
|
| 638 | + if (preg_match('~^https?://[\w_\-]+\.simplemachines\.org/~', $_REQUEST['package']) == 1 && strpos($_REQUEST['package'], 'dlattach') === false && isset($_REQUEST['auto'])) { |
|
| 639 | + redirectexit('action=admin;area=packages;sa=install;package=' . $package_name); |
|
| 640 | + } |
|
| 607 | 641 | |
| 608 | 642 | // You just downloaded a mod from SERVER_NAME_GOES_HERE. |
| 609 | 643 | $context['package_server'] = $server; |
| 610 | 644 | |
| 611 | 645 | $context['package'] = getPackageInfo($package_name); |
| 612 | 646 | |
| 613 | - if (!is_array($context['package'])) |
|
| 614 | - fatal_lang_error('package_cant_download', false); |
|
| 647 | + if (!is_array($context['package'])) { |
|
| 648 | + fatal_lang_error('package_cant_download', false); |
|
| 649 | + } |
|
| 615 | 650 | |
| 616 | - if ($context['package']['type'] == 'modification') |
|
| 617 | - $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['install_mod'] . ' ]</a>'; |
|
| 618 | - elseif ($context['package']['type'] == 'avatar') |
|
| 619 | - $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['use_avatars'] . ' ]</a>'; |
|
| 620 | - elseif ($context['package']['type'] == 'language') |
|
| 621 | - $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['add_languages'] . ' ]</a>'; |
|
| 622 | - else |
|
| 623 | - $context['package']['install']['link'] = ''; |
|
| 651 | + if ($context['package']['type'] == 'modification') { |
|
| 652 | + $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['install_mod'] . ' ]</a>'; |
|
| 653 | + } elseif ($context['package']['type'] == 'avatar') { |
|
| 654 | + $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['use_avatars'] . ' ]</a>'; |
|
| 655 | + } elseif ($context['package']['type'] == 'language') { |
|
| 656 | + $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['add_languages'] . ' ]</a>'; |
|
| 657 | + } else { |
|
| 658 | + $context['package']['install']['link'] = ''; |
|
| 659 | + } |
|
| 624 | 660 | |
| 625 | 661 | // Does a 3rd party hook want to do some additional changes? |
| 626 | 662 | call_integration_hook('integrate_package_download'); |
@@ -646,10 +682,11 @@ discard block |
||
| 646 | 682 | // @todo Use FTP if the Packages directory is not writable. |
| 647 | 683 | |
| 648 | 684 | // Check the file was even sent! |
| 649 | - if (!isset($_FILES['package']['name']) || $_FILES['package']['name'] == '') |
|
| 650 | - fatal_lang_error('package_upload_error_nofile'); |
|
| 651 | - elseif (!is_uploaded_file($_FILES['package']['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['package']['tmp_name']))) |
|
| 652 | - fatal_lang_error('package_upload_error_failed'); |
|
| 685 | + if (!isset($_FILES['package']['name']) || $_FILES['package']['name'] == '') { |
|
| 686 | + fatal_lang_error('package_upload_error_nofile'); |
|
| 687 | + } elseif (!is_uploaded_file($_FILES['package']['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['package']['tmp_name']))) { |
|
| 688 | + fatal_lang_error('package_upload_error_failed'); |
|
| 689 | + } |
|
| 653 | 690 | |
| 654 | 691 | // Make sure it has a sane filename. |
| 655 | 692 | $_FILES['package']['name'] = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $_FILES['package']['name']); |
@@ -666,8 +703,9 @@ discard block |
||
| 666 | 703 | // Setup the destination and throw an error if the file is already there! |
| 667 | 704 | $destination = $packagesdir . '/' . $packageName; |
| 668 | 705 | // @todo Maybe just roll it like we do for downloads? |
| 669 | - if (file_exists($destination)) |
|
| 670 | - fatal_lang_error('package_upload_error_exists'); |
|
| 706 | + if (file_exists($destination)) { |
|
| 707 | + fatal_lang_error('package_upload_error_exists'); |
|
| 708 | + } |
|
| 671 | 709 | |
| 672 | 710 | // Now move the file. |
| 673 | 711 | move_uploaded_file($_FILES['package']['tmp_name'], $destination); |
@@ -690,12 +728,14 @@ discard block |
||
| 690 | 728 | { |
| 691 | 729 | while ($package = readdir($dir)) |
| 692 | 730 | { |
| 693 | - if ($package == '.' || $package == '..' || $package == 'temp' || $package == $packageName || (!(is_dir($packagesdir . '/' . $package) && file_exists($packagesdir . '/' . $package . '/package-info.xml')) && substr(strtolower($package), -7) != '.tar.gz' && substr(strtolower($package), -4) != '.tgz' && substr(strtolower($package), -4) != '.zip')) |
|
| 694 | - continue; |
|
| 731 | + if ($package == '.' || $package == '..' || $package == 'temp' || $package == $packageName || (!(is_dir($packagesdir . '/' . $package) && file_exists($packagesdir . '/' . $package . '/package-info.xml')) && substr(strtolower($package), -7) != '.tar.gz' && substr(strtolower($package), -4) != '.tgz' && substr(strtolower($package), -4) != '.zip')) { |
|
| 732 | + continue; |
|
| 733 | + } |
|
| 695 | 734 | |
| 696 | 735 | $packageInfo = getPackageInfo($package); |
| 697 | - if (!is_array($packageInfo)) |
|
| 698 | - continue; |
|
| 736 | + if (!is_array($packageInfo)) { |
|
| 737 | + continue; |
|
| 738 | + } |
|
| 699 | 739 | |
| 700 | 740 | if ($packageInfo['id'] == $context['package']['id'] && $packageInfo['version'] == $context['package']['version']) |
| 701 | 741 | { |
@@ -707,14 +747,15 @@ discard block |
||
| 707 | 747 | closedir($dir); |
| 708 | 748 | } |
| 709 | 749 | |
| 710 | - if ($context['package']['type'] == 'modification') |
|
| 711 | - $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['install_mod'] . ' ]</a>'; |
|
| 712 | - elseif ($context['package']['type'] == 'avatar') |
|
| 713 | - $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['use_avatars'] . ' ]</a>'; |
|
| 714 | - elseif ($context['package']['type'] == 'language') |
|
| 715 | - $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['add_languages'] . ' ]</a>'; |
|
| 716 | - else |
|
| 717 | - $context['package']['install']['link'] = ''; |
|
| 750 | + if ($context['package']['type'] == 'modification') { |
|
| 751 | + $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['install_mod'] . ' ]</a>'; |
|
| 752 | + } elseif ($context['package']['type'] == 'avatar') { |
|
| 753 | + $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['use_avatars'] . ' ]</a>'; |
|
| 754 | + } elseif ($context['package']['type'] == 'language') { |
|
| 755 | + $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['add_languages'] . ' ]</a>'; |
|
| 756 | + } else { |
|
| 757 | + $context['package']['install']['link'] = ''; |
|
| 758 | + } |
|
| 718 | 759 | |
| 719 | 760 | // Does a 3rd party hook want to do some additional changes? |
| 720 | 761 | call_integration_hook('integrate_package_upload'); |
@@ -737,16 +778,18 @@ discard block |
||
| 737 | 778 | checkSession(); |
| 738 | 779 | |
| 739 | 780 | // If they put a slash on the end, get rid of it. |
| 740 | - if (substr($_POST['serverurl'], -1) == '/') |
|
| 741 | - $_POST['serverurl'] = substr($_POST['serverurl'], 0, -1); |
|
| 781 | + if (substr($_POST['serverurl'], -1) == '/') { |
|
| 782 | + $_POST['serverurl'] = substr($_POST['serverurl'], 0, -1); |
|
| 783 | + } |
|
| 742 | 784 | |
| 743 | 785 | // Are they both nice and clean? |
| 744 | 786 | $servername = trim($smcFunc['htmlspecialchars']($_POST['servername'])); |
| 745 | 787 | $serverurl = trim($smcFunc['htmlspecialchars']($_POST['serverurl'])); |
| 746 | 788 | |
| 747 | 789 | // Make sure the URL has the correct prefix. |
| 748 | - if (strpos($serverurl, 'http://') !== 0 && strpos($serverurl, 'https://') !== 0) |
|
| 749 | - $serverurl = 'http://' . $serverurl; |
|
| 790 | + if (strpos($serverurl, 'http://') !== 0 && strpos($serverurl, 'https://') !== 0) { |
|
| 791 | + $serverurl = 'http://' . $serverurl; |
|
| 792 | + } |
|
| 750 | 793 | |
| 751 | 794 | $smcFunc['db_insert']('', |
| 752 | 795 | '{db_prefix}package_servers', |
@@ -14,8 +14,9 @@ discard block |
||
| 14 | 14 | // This won't be dedicated without this - this must exist in each gateway! |
| 15 | 15 | // SMF Payment Gateway: paypal |
| 16 | 16 | |
| 17 | -if (!defined('SMF')) |
|
| 17 | +if (!defined('SMF')) { |
|
| 18 | 18 | die('No direct access...'); |
| 19 | +} |
|
| 19 | 20 | |
| 20 | 21 | /** |
| 21 | 22 | * Class for returning available form data for this gateway |
@@ -118,8 +119,7 @@ discard block |
||
| 118 | 119 | { |
| 119 | 120 | $return_data['hidden']['p3'] = 1; |
| 120 | 121 | $return_data['hidden']['t3'] = strtoupper(substr($period, 0, 1)); |
| 121 | - } |
|
| 122 | - else |
|
| 122 | + } else |
|
| 123 | 123 | { |
| 124 | 124 | preg_match('~(\d*)(\w)~', $sub_data['real_length'], $match); |
| 125 | 125 | $unit = $match[1]; |
@@ -130,14 +130,15 @@ discard block |
||
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | // If it's repeatable do some javascript to respect this idea. |
| 133 | - if (!empty($sub_data['repeatable'])) |
|
| 134 | - $return_data['javascript'] = ' |
|
| 133 | + if (!empty($sub_data['repeatable'])) { |
|
| 134 | + $return_data['javascript'] = ' |
|
| 135 | 135 | document.write(\'<label for="do_paypal_recur"><input type="checkbox" name="do_paypal_recur" id="do_paypal_recur" checked onclick="switchPaypalRecur();" class="input_check">' . $txt['paid_make_recurring'] . '</label><br>\'); |
| 136 | 136 | |
| 137 | 137 | function switchPaypalRecur() |
| 138 | 138 | { |
| 139 | 139 | document.getElementById("paypal_cmd").value = document.getElementById("do_paypal_recur").checked ? "_xclick-subscriptions" : "_xclick"; |
| 140 | 140 | }'; |
| 141 | + } |
|
| 141 | 142 | |
| 142 | 143 | return $return_data; |
| 143 | 144 | } |
@@ -160,20 +161,24 @@ discard block |
||
| 160 | 161 | global $modSettings; |
| 161 | 162 | |
| 162 | 163 | // Has the user set up an email address? |
| 163 | - if ((empty($modSettings['paidsubs_test']) && empty($modSettings['paypal_email'])) || (!empty($modSettings['paidsubs_test']) && empty($modSettings['paypal_sandbox_email']))) |
|
| 164 | - return false; |
|
| 164 | + if ((empty($modSettings['paidsubs_test']) && empty($modSettings['paypal_email'])) || (!empty($modSettings['paidsubs_test']) && empty($modSettings['paypal_sandbox_email']))) { |
|
| 165 | + return false; |
|
| 166 | + } |
|
| 165 | 167 | // Check the correct transaction types are even here. |
| 166 | - if ((!isset($_POST['txn_type']) && !isset($_POST['payment_status'])) || (!isset($_POST['business']) && !isset($_POST['receiver_email']))) |
|
| 167 | - return false; |
|
| 168 | + if ((!isset($_POST['txn_type']) && !isset($_POST['payment_status'])) || (!isset($_POST['business']) && !isset($_POST['receiver_email']))) { |
|
| 169 | + return false; |
|
| 170 | + } |
|
| 168 | 171 | // Correct email address? |
| 169 | - if (!isset($_POST['business'])) |
|
| 170 | - $_POST['business'] = $_POST['receiver_email']; |
|
| 172 | + if (!isset($_POST['business'])) { |
|
| 173 | + $_POST['business'] = $_POST['receiver_email']; |
|
| 174 | + } |
|
| 171 | 175 | |
| 172 | 176 | // Are we testing? |
| 173 | - if (empty($modSettings['paidsubs_test']) && strtolower($modSettings['paypal_sandbox_email']) != strtolower($_POST['business']) && (empty($modSettings['paypal_additional_emails']) || !in_array(strtolower($_POST['business']), explode(',', strtolower($modSettings['paypal_additional_emails']))))) |
|
| 174 | - return false; |
|
| 175 | - elseif (strtolower($modSettings['paypal_email']) != strtolower($_POST['business']) && (empty($modSettings['paypal_additional_emails']) || !in_array(strtolower($_POST['business']), explode(',', $modSettings['paypal_additional_emails'])))) |
|
| 176 | - return false; |
|
| 177 | + if (empty($modSettings['paidsubs_test']) && strtolower($modSettings['paypal_sandbox_email']) != strtolower($_POST['business']) && (empty($modSettings['paypal_additional_emails']) || !in_array(strtolower($_POST['business']), explode(',', strtolower($modSettings['paypal_additional_emails']))))) { |
|
| 178 | + return false; |
|
| 179 | + } elseif (strtolower($modSettings['paypal_email']) != strtolower($_POST['business']) && (empty($modSettings['paypal_additional_emails']) || !in_array(strtolower($_POST['business']), explode(',', $modSettings['paypal_additional_emails'])))) { |
|
| 180 | + return false; |
|
| 181 | + } |
|
| 177 | 182 | return true; |
| 178 | 183 | } |
| 179 | 184 | |
@@ -192,15 +197,17 @@ discard block |
||
| 192 | 197 | global $modSettings, $txt; |
| 193 | 198 | |
| 194 | 199 | // Put this to some default value. |
| 195 | - if (!isset($_POST['txn_type'])) |
|
| 196 | - $_POST['txn_type'] = ''; |
|
| 200 | + if (!isset($_POST['txn_type'])) { |
|
| 201 | + $_POST['txn_type'] = ''; |
|
| 202 | + } |
|
| 197 | 203 | |
| 198 | 204 | // Build the request string - starting with the minimum requirement. |
| 199 | 205 | $requestString = 'cmd=_notify-validate'; |
| 200 | 206 | |
| 201 | 207 | // Now my dear, add all the posted bits in the order we got them |
| 202 | - foreach ($_POST as $k => $v) |
|
| 203 | - $requestString .= '&' . $k . '=' . urlencode($v); |
|
| 208 | + foreach ($_POST as $k => $v) { |
|
| 209 | + $requestString .= '&' . $k . '=' . urlencode($v); |
|
| 210 | + } |
|
| 204 | 211 | |
| 205 | 212 | // Can we use curl? |
| 206 | 213 | if (function_exists('curl_init') && $curl = curl_init((!empty($modSettings['paidsubs_test']) ? 'https://www.sandbox.' : 'https://www.') . 'paypal.com/cgi-bin/webscr')) |
@@ -240,14 +247,16 @@ discard block |
||
| 240 | 247 | $header .= 'Connection: close' . "\r\n\r\n"; |
| 241 | 248 | |
| 242 | 249 | // Open the connection. |
| 243 | - if (!empty($modSettings['paidsubs_test'])) |
|
| 244 | - $fp = fsockopen('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30); |
|
| 245 | - else |
|
| 246 | - $fp = fsockopen('www.paypal.com', 80, $errno, $errstr, 30); |
|
| 250 | + if (!empty($modSettings['paidsubs_test'])) { |
|
| 251 | + $fp = fsockopen('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30); |
|
| 252 | + } else { |
|
| 253 | + $fp = fsockopen('www.paypal.com', 80, $errno, $errstr, 30); |
|
| 254 | + } |
|
| 247 | 255 | |
| 248 | 256 | // Did it work? |
| 249 | - if (!$fp) |
|
| 250 | - generateSubscriptionError($txt['paypal_could_not_connect']); |
|
| 257 | + if (!$fp) { |
|
| 258 | + generateSubscriptionError($txt['paypal_could_not_connect']); |
|
| 259 | + } |
|
| 251 | 260 | |
| 252 | 261 | // Put the data to the port. |
| 253 | 262 | fputs($fp, $header . $requestString); |
@@ -256,8 +265,9 @@ discard block |
||
| 256 | 265 | while (!feof($fp)) |
| 257 | 266 | { |
| 258 | 267 | $this->return_data = fgets($fp, 1024); |
| 259 | - if (strcmp(trim($this->return_data), 'VERIFIED') === 0) |
|
| 260 | - break; |
|
| 268 | + if (strcmp(trim($this->return_data), 'VERIFIED') === 0) { |
|
| 269 | + break; |
|
| 270 | + } |
|
| 261 | 271 | } |
| 262 | 272 | |
| 263 | 273 | // Clean up. |
@@ -265,28 +275,34 @@ discard block |
||
| 265 | 275 | } |
| 266 | 276 | |
| 267 | 277 | // If this isn't verified then give up... |
| 268 | - if (strcmp(trim($this->return_data), 'VERIFIED') !== 0) |
|
| 269 | - exit; |
|
| 278 | + if (strcmp(trim($this->return_data), 'VERIFIED') !== 0) { |
|
| 279 | + exit; |
|
| 280 | + } |
|
| 270 | 281 | |
| 271 | 282 | // Check that this is intended for us. |
| 272 | - if (strtolower($modSettings['paypal_email']) != strtolower($_POST['business']) && (empty($modSettings['paypal_additional_emails']) || !in_array(strtolower($_POST['business']), explode(',', strtolower($modSettings['paypal_additional_emails']))))) |
|
| 273 | - exit; |
|
| 283 | + if (strtolower($modSettings['paypal_email']) != strtolower($_POST['business']) && (empty($modSettings['paypal_additional_emails']) || !in_array(strtolower($_POST['business']), explode(',', strtolower($modSettings['paypal_additional_emails']))))) { |
|
| 284 | + exit; |
|
| 285 | + } |
|
| 274 | 286 | |
| 275 | 287 | // Is this a subscription - and if so is it a secondary payment that we need to process? |
| 276 | 288 | // If so, make sure we get it in the expected format. Seems PayPal sometimes sends it without urlencoding. |
| 277 | - if (!empty($_POST['item_number']) && strpos($_POST['item_number'], ' ') !== false) |
|
| 278 | - $_POST['item_number'] = str_replace(' ', '+', $_POST['item_number']); |
|
| 279 | - if ($this->isSubscription() && (empty($_POST['item_number']) || strpos($_POST['item_number'], '+') === false)) |
|
| 280 | - // Calculate the subscription it relates to! |
|
| 289 | + if (!empty($_POST['item_number']) && strpos($_POST['item_number'], ' ') !== false) { |
|
| 290 | + $_POST['item_number'] = str_replace(' ', '+', $_POST['item_number']); |
|
| 291 | + } |
|
| 292 | + if ($this->isSubscription() && (empty($_POST['item_number']) || strpos($_POST['item_number'], '+') === false)) { |
|
| 293 | + // Calculate the subscription it relates to! |
|
| 281 | 294 | $this->_findSubscription(); |
| 295 | + } |
|
| 282 | 296 | |
| 283 | 297 | // Verify the currency! |
| 284 | - if (strtolower($_POST['mc_currency']) !== strtolower($modSettings['paid_currency_code'])) |
|
| 285 | - exit; |
|
| 298 | + if (strtolower($_POST['mc_currency']) !== strtolower($modSettings['paid_currency_code'])) { |
|
| 299 | + exit; |
|
| 300 | + } |
|
| 286 | 301 | |
| 287 | 302 | // Can't exist if it doesn't contain anything. |
| 288 | - if (empty($_POST['item_number'])) |
|
| 289 | - exit; |
|
| 303 | + if (empty($_POST['item_number'])) { |
|
| 304 | + exit; |
|
| 305 | + } |
|
| 290 | 306 | |
| 291 | 307 | // Return the id_sub and id_member |
| 292 | 308 | return explode('+', $_POST['item_number']); |
@@ -299,10 +315,11 @@ discard block |
||
| 299 | 315 | */ |
| 300 | 316 | public function isRefund() |
| 301 | 317 | { |
| 302 | - if ($_POST['payment_status'] === 'Refunded' || $_POST['payment_status'] === 'Reversed' || $_POST['txn_type'] === 'Refunded' || ($_POST['txn_type'] === 'reversal' && $_POST['payment_status'] === 'Completed')) |
|
| 303 | - return true; |
|
| 304 | - else |
|
| 305 | - return false; |
|
| 318 | + if ($_POST['payment_status'] === 'Refunded' || $_POST['payment_status'] === 'Reversed' || $_POST['txn_type'] === 'Refunded' || ($_POST['txn_type'] === 'reversal' && $_POST['payment_status'] === 'Completed')) { |
|
| 319 | + return true; |
|
| 320 | + } else { |
|
| 321 | + return false; |
|
| 322 | + } |
|
| 306 | 323 | } |
| 307 | 324 | |
| 308 | 325 | /** |
@@ -312,10 +329,11 @@ discard block |
||
| 312 | 329 | */ |
| 313 | 330 | public function isSubscription() |
| 314 | 331 | { |
| 315 | - if (substr($_POST['txn_type'], 0, 14) === 'subscr_payment' && $_POST['payment_status'] === 'Completed') |
|
| 316 | - return true; |
|
| 317 | - else |
|
| 318 | - return false; |
|
| 332 | + if (substr($_POST['txn_type'], 0, 14) === 'subscr_payment' && $_POST['payment_status'] === 'Completed') { |
|
| 333 | + return true; |
|
| 334 | + } else { |
|
| 335 | + return false; |
|
| 336 | + } |
|
| 319 | 337 | } |
| 320 | 338 | |
| 321 | 339 | /** |
@@ -325,10 +343,11 @@ discard block |
||
| 325 | 343 | */ |
| 326 | 344 | public function isPayment() |
| 327 | 345 | { |
| 328 | - if ($_POST['payment_status'] === 'Completed' && $_POST['txn_type'] === 'web_accept') |
|
| 329 | - return true; |
|
| 330 | - else |
|
| 331 | - return false; |
|
| 346 | + if ($_POST['payment_status'] === 'Completed' && $_POST['txn_type'] === 'web_accept') { |
|
| 347 | + return true; |
|
| 348 | + } else { |
|
| 349 | + return false; |
|
| 350 | + } |
|
| 332 | 351 | } |
| 333 | 352 | |
| 334 | 353 | /** |
@@ -341,10 +360,11 @@ discard block |
||
| 341 | 360 | // subscr_cancel is sent when the user cancels, subscr_eot is sent when the subscription reaches final payment |
| 342 | 361 | // Neither require us to *do* anything as per performCancel(). |
| 343 | 362 | // subscr_eot, if sent, indicates an end of payments term. |
| 344 | - if (substr($_POST['txn_type'], 0, 13) === 'subscr_cancel' || substr($_POST['txn_type'], 0, 10) === 'subscr_eot') |
|
| 345 | - return true; |
|
| 346 | - else |
|
| 347 | - return false; |
|
| 363 | + if (substr($_POST['txn_type'], 0, 13) === 'subscr_cancel' || substr($_POST['txn_type'], 0, 10) === 'subscr_eot') { |
|
| 364 | + return true; |
|
| 365 | + } else { |
|
| 366 | + return false; |
|
| 367 | + } |
|
| 348 | 368 | } |
| 349 | 369 | |
| 350 | 370 | /** |
@@ -409,8 +429,9 @@ discard block |
||
| 409 | 429 | global $smcFunc; |
| 410 | 430 | |
| 411 | 431 | // Assume we have this? |
| 412 | - if (empty($_POST['subscr_id'])) |
|
| 413 | - return false; |
|
| 432 | + if (empty($_POST['subscr_id'])) { |
|
| 433 | + return false; |
|
| 434 | + } |
|
| 414 | 435 | |
| 415 | 436 | // Do we have this in the database? |
| 416 | 437 | $request = $smcFunc['db_query']('', ' |
@@ -439,11 +460,12 @@ discard block |
||
| 439 | 460 | 'payer_email' => $_POST['payer_email'], |
| 440 | 461 | ) |
| 441 | 462 | ); |
| 442 | - if ($smcFunc['db_num_rows']($request) === 0) |
|
| 443 | - return false; |
|
| 463 | + if ($smcFunc['db_num_rows']($request) === 0) { |
|
| 464 | + return false; |
|
| 465 | + } |
|
| 466 | + } else { |
|
| 467 | + return false; |
|
| 444 | 468 | } |
| 445 | - else |
|
| 446 | - return false; |
|
| 447 | 469 | } |
| 448 | 470 | list ($member_id, $subscription_id) = $smcFunc['db_fetch_row']($request); |
| 449 | 471 | $_POST['item_number'] = $member_id . '+' . $subscription_id; |
@@ -22,22 +22,24 @@ discard block |
||
| 22 | 22 | <script>'; |
| 23 | 23 | |
| 24 | 24 | // When using Go Back due to fatal_error, allow the form to be re-submitted with changes. |
| 25 | - if (isBrowser('is_firefox')) |
|
| 26 | - echo ' |
|
| 25 | + if (isBrowser('is_firefox')) { |
|
| 26 | + echo ' |
|
| 27 | 27 | window.addEventListener("pageshow", reActivate, false);'; |
| 28 | + } |
|
| 28 | 29 | |
| 29 | 30 | // Start with message icons - and any missing from this theme. |
| 30 | 31 | echo ' |
| 31 | 32 | var icon_urls = {'; |
| 32 | - foreach ($context['icons'] as $icon) |
|
| 33 | - echo ' |
|
| 33 | + foreach ($context['icons'] as $icon) { |
|
| 34 | + echo ' |
|
| 34 | 35 | \'', $icon['value'], '\': \'', $icon['url'], '\'', $icon['is_last'] ? '' : ','; |
| 36 | + } |
|
| 35 | 37 | echo ' |
| 36 | 38 | };'; |
| 37 | 39 | |
| 38 | 40 | // If this is a poll - use some javascript to ensure the user doesn't create a poll with illegal option combinations. |
| 39 | - if ($context['make_poll']) |
|
| 40 | - echo ' |
|
| 41 | + if ($context['make_poll']) { |
|
| 42 | + echo ' |
|
| 41 | 43 | var pollOptionNum = 0, pollTabIndex; |
| 42 | 44 | var pollOptionId = ', $context['last_choice_id'], '; |
| 43 | 45 | function addPollOption() |
@@ -56,11 +58,13 @@ discard block |
||
| 56 | 58 | |
| 57 | 59 | setOuterHTML(document.getElementById(\'pollMoreOptions\'), ', JavaScriptEscape('<dt><label for="options-'), ' + pollOptionId + ', JavaScriptEscape('">' . $txt['option'] . ' '), ' + pollOptionNum + ', JavaScriptEscape('</label>:</dt><dd><input type="text" name="options['), ' + pollOptionId + ', JavaScriptEscape(']" id="options-'), ' + pollOptionId + ', JavaScriptEscape('" value="" size="80" maxlength="255" tabindex="'), ' + pollTabIndex + ', JavaScriptEscape('" class="input_text"></dd><p id="pollMoreOptions"></p>'), '); |
| 58 | 60 | }'; |
| 61 | + } |
|
| 59 | 62 | |
| 60 | 63 | // If we are making a calendar event we want to ensure we show the current days in a month etc... this is done here. |
| 61 | - if ($context['make_event']) |
|
| 62 | - echo ' |
|
| 64 | + if ($context['make_event']) { |
|
| 65 | + echo ' |
|
| 63 | 66 | var monthLength = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];'; |
| 67 | + } |
|
| 64 | 68 | |
| 65 | 69 | // End of the javascript, start the form and display the link tree. |
| 66 | 70 | echo ' |
@@ -80,9 +84,10 @@ discard block |
||
| 80 | 84 | </div> |
| 81 | 85 | </div><br>'; |
| 82 | 86 | |
| 83 | - if ($context['make_event'] && (!$context['event']['new'] || !empty($context['current_board']))) |
|
| 84 | - echo ' |
|
| 87 | + if ($context['make_event'] && (!$context['event']['new'] || !empty($context['current_board']))) { |
|
| 88 | + echo ' |
|
| 85 | 89 | <input type="hidden" name="eventid" value="', $context['event']['id'], '">'; |
| 90 | + } |
|
| 86 | 91 | |
| 87 | 92 | // Start the main table. |
| 88 | 93 | echo ' |
@@ -117,18 +122,20 @@ discard block |
||
| 117 | 122 | } |
| 118 | 123 | |
| 119 | 124 | // If it's locked, show a message to warn the replier. |
| 120 | - if (!empty($context['locked'])) |
|
| 121 | - echo ' |
|
| 125 | + if (!empty($context['locked'])) { |
|
| 126 | + echo ' |
|
| 122 | 127 | <p class="errorbox"> |
| 123 | 128 | ', $txt['topic_locked_no_reply'], ' |
| 124 | 129 | </p>'; |
| 130 | + } |
|
| 125 | 131 | |
| 126 | - if (!empty($modSettings['drafts_post_enabled'])) |
|
| 127 | - echo ' |
|
| 132 | + if (!empty($modSettings['drafts_post_enabled'])) { |
|
| 133 | + echo ' |
|
| 128 | 134 | <div id="draft_section" class="infobox"', isset($context['draft_saved']) ? '' : ' style="display: none;"', '>', |
| 129 | 135 | sprintf($txt['draft_saved'], $scripturl . '?action=profile;u=' . $context['user']['id'] . ';area=showdrafts'), ' |
| 130 | 136 | ', (!empty($modSettings['drafts_keep_days']) ? ' <strong>' . sprintf($txt['draft_save_warning'], $modSettings['drafts_keep_days']) . '</strong>' : ''), ' |
| 131 | 137 | </div>'; |
| 138 | + } |
|
| 132 | 139 | |
| 133 | 140 | // The post header... important stuff |
| 134 | 141 | echo ' |
@@ -180,9 +187,10 @@ discard block |
||
| 180 | 187 | { |
| 181 | 188 | echo ' |
| 182 | 189 | <optgroup label="', $category['name'], '">'; |
| 183 | - foreach ($category['boards'] as $board) |
|
| 184 | - echo ' |
|
| 190 | + foreach ($category['boards'] as $board) { |
|
| 191 | + echo ' |
|
| 185 | 192 | <option value="', $board['id'], '"', $board['selected'] ? ' selected' : '', '>', $board['child_level'] > 0 ? str_repeat('==', $board['child_level'] - 1) . '=>' : '', ' ', $board['name'], ' </option>'; |
| 193 | + } |
|
| 186 | 194 | echo ' |
| 187 | 195 | </optgroup>'; |
| 188 | 196 | } |
@@ -218,9 +226,10 @@ discard block |
||
| 218 | 226 | <span class="label">', $txt['calendar_timezone'], '</span> |
| 219 | 227 | <select name="tz" id="tz"', !empty($context['event']['allday']) ? ' disabled' : '', '>'; |
| 220 | 228 | |
| 221 | - foreach ($context['all_timezones'] as $tz => $tzname) |
|
| 222 | - echo ' |
|
| 229 | + foreach ($context['all_timezones'] as $tz => $tzname) { |
|
| 230 | + echo ' |
|
| 223 | 231 | <option value="', $tz, '"', $tz == $context['event']['tz'] ? ' selected' : '', '>', $tzname, '</option>'; |
| 232 | + } |
|
| 224 | 233 | |
| 225 | 234 | echo ' |
| 226 | 235 | </select> |
@@ -286,14 +295,15 @@ discard block |
||
| 286 | 295 | <input type="checkbox" id="poll_change_vote" name="poll_change_vote"', !empty($context['poll']['change_vote']) ? ' checked' : '', ' class="input_check"> |
| 287 | 296 | </dd>'; |
| 288 | 297 | |
| 289 | - if ($context['poll_options']['guest_vote_enabled']) |
|
| 290 | - echo ' |
|
| 298 | + if ($context['poll_options']['guest_vote_enabled']) { |
|
| 299 | + echo ' |
|
| 291 | 300 | <dt> |
| 292 | 301 | <label for="poll_guest_vote">', $txt['poll_guest_vote'], ':</label> |
| 293 | 302 | </dt> |
| 294 | 303 | <dd> |
| 295 | 304 | <input type="checkbox" id="poll_guest_vote" name="poll_guest_vote"', !empty($context['poll_options']['guest_vote']) ? ' checked' : '', ' class="input_check"> |
| 296 | 305 | </dd>'; |
| 306 | + } |
|
| 297 | 307 | |
| 298 | 308 | echo ' |
| 299 | 309 | <dt> |
@@ -314,8 +324,8 @@ discard block |
||
| 314 | 324 | ', template_control_richedit($context['post_box_name'], 'smileyBox_message', 'bbcBox_message'); |
| 315 | 325 | |
| 316 | 326 | // If we're editing and displaying edit details, show a box where they can say why |
| 317 | - if (isset($context['editing']) && $modSettings['show_modify']) |
|
| 318 | - echo ' |
|
| 327 | + if (isset($context['editing']) && $modSettings['show_modify']) { |
|
| 328 | + echo ' |
|
| 319 | 329 | <dl> |
| 320 | 330 | <dt class="clear"> |
| 321 | 331 | <span id="caption_edit_reason">', $txt['reason_for_edit'], ':</span> |
@@ -324,20 +334,23 @@ discard block |
||
| 324 | 334 | <input type="text" name="modify_reason"', isset($context['last_modified_reason']) ? ' value="' . $context['last_modified_reason'] . '"' : '', ' tabindex="', $context['tabindex']++, '" size="80" maxlength="80" class="input_text"> |
| 325 | 335 | </dd> |
| 326 | 336 | </dl>'; |
| 337 | + } |
|
| 327 | 338 | |
| 328 | 339 | // If this message has been edited in the past - display when it was. |
| 329 | - if (isset($context['last_modified'])) |
|
| 330 | - echo ' |
|
| 340 | + if (isset($context['last_modified'])) { |
|
| 341 | + echo ' |
|
| 331 | 342 | <div class="padding smalltext"> |
| 332 | 343 | ', $context['last_modified_text'], ' |
| 333 | 344 | </div>'; |
| 345 | + } |
|
| 334 | 346 | |
| 335 | 347 | // If the admin has enabled the hiding of the additional options - show a link and image for it. |
| 336 | - if (!empty($modSettings['additional_options_collapsable'])) |
|
| 337 | - echo ' |
|
| 348 | + if (!empty($modSettings['additional_options_collapsable'])) { |
|
| 349 | + echo ' |
|
| 338 | 350 | <div id="postAdditionalOptionsHeader"> |
| 339 | 351 | <strong><a href="#" id="postMoreExpandLink"> ', $context['can_post_attachment'] ? $txt['post_additionalopt_attach'] : $txt['post_additionalopt'], '</a></strong> |
| 340 | 352 | </div>'; |
| 353 | + } |
|
| 341 | 354 | |
| 342 | 355 | echo ' |
| 343 | 356 | <div id="postAdditionalOptions">'; |
@@ -369,19 +382,21 @@ discard block |
||
| 369 | 382 | <input type="hidden" name="attach_del[]" value="0"> |
| 370 | 383 | ', $txt['uncheck_unwatchd_attach'], ': |
| 371 | 384 | </dd>'; |
| 372 | - foreach ($context['current_attachments'] as $attachment) |
|
| 373 | - echo ' |
|
| 385 | + foreach ($context['current_attachments'] as $attachment) { |
|
| 386 | + echo ' |
|
| 374 | 387 | <dd class="smalltext"> |
| 375 | 388 | <label for="attachment_', $attachment['attachID'], '"><input type="checkbox" id="attachment_', $attachment['attachID'], '" name="attach_del[]" value="', $attachment['attachID'], '"', empty($attachment['unchecked']) ? ' checked' : '', ' class="input_check"> ', $attachment['name'], (empty($attachment['approved']) ? ' (' . $txt['awaiting_approval'] . ')' : ''), |
| 376 | 389 | !empty($modSettings['attachmentPostLimit']) || !empty($modSettings['attachmentSizeLimit']) ? sprintf($txt['attach_kb'], comma_format(round(max($attachment['size'], 1028) / 1028), 0)) : '', '</label> |
| 377 | 390 | </dd>'; |
| 391 | + } |
|
| 378 | 392 | |
| 379 | 393 | echo ' |
| 380 | 394 | </dl>'; |
| 381 | 395 | |
| 382 | - if (!empty($context['files_in_session_warning'])) |
|
| 383 | - echo ' |
|
| 396 | + if (!empty($context['files_in_session_warning'])) { |
|
| 397 | + echo ' |
|
| 384 | 398 | <div class="smalltext">', $context['files_in_session_warning'], '</div>'; |
| 399 | + } |
|
| 385 | 400 | } |
| 386 | 401 | |
| 387 | 402 | // Is the user allowed to post any additional ones? If so give them the boxes to do it! |
@@ -434,8 +449,8 @@ discard block |
||
| 434 | 449 | ', empty($modSettings['attachmentSizeLimit']) ? '' : ('<input type="hidden" name="MAX_FILE_SIZE" value="' . $modSettings['attachmentSizeLimit'] * 1028 . '">'); |
| 435 | 450 | |
| 436 | 451 | // Show more boxes if they aren't approaching that limit. |
| 437 | - if ($context['num_allowed_attachments'] > 1) |
|
| 438 | - echo ' |
|
| 452 | + if ($context['num_allowed_attachments'] > 1) { |
|
| 453 | + echo ' |
|
| 439 | 454 | <script> |
| 440 | 455 | var allowed_attachments = ', $context['num_allowed_attachments'], '; |
| 441 | 456 | var current_attachment = 1; |
@@ -456,9 +471,10 @@ discard block |
||
| 456 | 471 | </div> |
| 457 | 472 | </div> |
| 458 | 473 | </dd>'; |
| 459 | - else |
|
| 460 | - echo ' |
|
| 474 | + } else { |
|
| 475 | + echo ' |
|
| 461 | 476 | </dd>'; |
| 477 | + } |
|
| 462 | 478 | |
| 463 | 479 | // Add any template changes for an alternative upload system here. |
| 464 | 480 | call_integration_hook('integrate_upload_template'); |
@@ -467,21 +483,25 @@ discard block |
||
| 467 | 483 | <dd class="smalltext">'; |
| 468 | 484 | |
| 469 | 485 | // Show some useful information such as allowed extensions, maximum size and amount of attachments allowed. |
| 470 | - if (!empty($modSettings['attachmentCheckExtensions'])) |
|
| 471 | - echo ' |
|
| 486 | + if (!empty($modSettings['attachmentCheckExtensions'])) { |
|
| 487 | + echo ' |
|
| 472 | 488 | ', $txt['allowed_types'], ': ', $context['allowed_extensions'], '<br>'; |
| 489 | + } |
|
| 473 | 490 | |
| 474 | - if (!empty($context['attachment_restrictions'])) |
|
| 475 | - echo ' |
|
| 491 | + if (!empty($context['attachment_restrictions'])) { |
|
| 492 | + echo ' |
|
| 476 | 493 | ', $txt['attach_restrictions'], ' ', implode(', ', $context['attachment_restrictions']), '<br>'; |
| 494 | + } |
|
| 477 | 495 | |
| 478 | - if ($context['num_allowed_attachments'] == 0) |
|
| 479 | - echo ' |
|
| 496 | + if ($context['num_allowed_attachments'] == 0) { |
|
| 497 | + echo ' |
|
| 480 | 498 | ', $txt['attach_limit_nag'], '<br>'; |
| 499 | + } |
|
| 481 | 500 | |
| 482 | - if (!$context['can_post_attachment_unapproved']) |
|
| 483 | - echo ' |
|
| 501 | + if (!$context['can_post_attachment_unapproved']) { |
|
| 502 | + echo ' |
|
| 484 | 503 | <span class="alert">', $txt['attachment_requires_approval'], '</span>', '<br>'; |
| 504 | + } |
|
| 485 | 505 | |
| 486 | 506 | echo ' |
| 487 | 507 | </dd> |
@@ -504,10 +524,11 @@ discard block |
||
| 504 | 524 | <dt><strong>', $txt['subject'], '</strong></dt> |
| 505 | 525 | <dd><strong>', $txt['draft_saved_on'], '</strong></dd>'; |
| 506 | 526 | |
| 507 | - foreach ($context['drafts'] as $draft) |
|
| 508 | - echo ' |
|
| 527 | + foreach ($context['drafts'] as $draft) { |
|
| 528 | + echo ' |
|
| 509 | 529 | <dt>', $draft['link'], '</dt> |
| 510 | 530 | <dd>', $draft['poster_time'], '</dd>'; |
| 531 | + } |
|
| 511 | 532 | echo ' |
| 512 | 533 | </dl> |
| 513 | 534 | </div>'; |
@@ -532,9 +553,10 @@ discard block |
||
| 532 | 553 | ', template_control_richedit_buttons($context['post_box_name']); |
| 533 | 554 | |
| 534 | 555 | // Option to delete an event if user is editing one. |
| 535 | - if ($context['make_event'] && !$context['event']['new']) |
|
| 536 | - echo ' |
|
| 556 | + if ($context['make_event'] && !$context['event']['new']) { |
|
| 557 | + echo ' |
|
| 537 | 558 | <input type="submit" name="deleteevent" value="', $txt['event_delete'], '" data-confirm="', $txt['event_delete_confirm'] ,'" class="button_submit you_sure">'; |
| 559 | + } |
|
| 538 | 560 | |
| 539 | 561 | echo ' |
| 540 | 562 | </span> |
@@ -543,9 +565,10 @@ discard block |
||
| 543 | 565 | <br class="clear">'; |
| 544 | 566 | |
| 545 | 567 | // Assuming this isn't a new topic pass across the last message id. |
| 546 | - if (isset($context['topic_last_message'])) |
|
| 547 | - echo ' |
|
| 568 | + if (isset($context['topic_last_message'])) { |
|
| 569 | + echo ' |
|
| 548 | 570 | <input type="hidden" name="last_msg" value="', $context['topic_last_message'], '">'; |
| 571 | + } |
|
| 549 | 572 | |
| 550 | 573 | echo ' |
| 551 | 574 | <input type="hidden" name="additional_options" id="additional_options" value="', $context['show_additional_options'] ? '1' : '0', '"> |
@@ -687,9 +710,10 @@ discard block |
||
| 687 | 710 | |
| 688 | 711 | newPostsHTML += \'<div class="windowbg\' + (++reply_counter % 2 == 0 ? \'2\' : \'\') + \'"><div id="msg\' + newPosts[i].getAttribute("id") + \'"><div class="floatleft"><h5>', $txt['posted_by'], ': \' + newPosts[i].getElementsByTagName("poster")[0].firstChild.nodeValue + \'</h5><span class="smalltext">« <strong>', $txt['on'], ':</strong> \' + newPosts[i].getElementsByTagName("time")[0].firstChild.nodeValue + \' »</span> <span class="new_posts" id="image_new_\' + newPosts[i].getAttribute("id") + \'">', $txt['new'], '</span></div>\';'; |
| 689 | 712 | |
| 690 | - if ($context['can_quote']) |
|
| 691 | - echo ' |
|
| 713 | + if ($context['can_quote']) { |
|
| 714 | + echo ' |
|
| 692 | 715 | newPostsHTML += \'<ul class="quickbuttons" id="msg_\' + newPosts[i].getAttribute("id") + \'_quote"><li><a href="#postmodify" onclick="return insertQuoteFast(\\\'\' + newPosts[i].getAttribute("id") + \'\\\');" class="quote_button"><span>', $txt['quote'], '</span><\' + \'/a></li></ul>\';'; |
| 716 | + } |
|
| 693 | 717 | |
| 694 | 718 | echo ' |
| 695 | 719 | newPostsHTML += \'<br class="clear">\'; |
@@ -732,8 +756,8 @@ discard block |
||
| 732 | 756 | }'; |
| 733 | 757 | |
| 734 | 758 | // Code for showing and hiding additional options. |
| 735 | - if (!empty($modSettings['additional_options_collapsable'])) |
|
| 736 | - echo ' |
|
| 759 | + if (!empty($modSettings['additional_options_collapsable'])) { |
|
| 760 | + echo ' |
|
| 737 | 761 | var oSwapAdditionalOptions = new smc_Toggle({ |
| 738 | 762 | bToggleEnabled: true, |
| 739 | 763 | bCurrentlyCollapsed: ', $context['show_additional_options'] ? 'false' : 'true', ', |
@@ -761,10 +785,11 @@ discard block |
||
| 761 | 785 | } |
| 762 | 786 | ] |
| 763 | 787 | });'; |
| 788 | + } |
|
| 764 | 789 | |
| 765 | 790 | // Code for showing and hiding drafts |
| 766 | - if (!empty($context['drafts'])) |
|
| 767 | - echo ' |
|
| 791 | + if (!empty($context['drafts'])) { |
|
| 792 | + echo ' |
|
| 768 | 793 | var oSwapDraftOptions = new smc_Toggle({ |
| 769 | 794 | bToggleEnabled: true, |
| 770 | 795 | bCurrentlyCollapsed: true, |
@@ -786,6 +811,7 @@ discard block |
||
| 786 | 811 | } |
| 787 | 812 | ] |
| 788 | 813 | });'; |
| 814 | + } |
|
| 789 | 815 | |
| 790 | 816 | echo ' |
| 791 | 817 | var oEditorID = "', $context['post_box_name'] ,'"; |
@@ -806,8 +832,9 @@ discard block |
||
| 806 | 832 | foreach ($context['previous_posts'] as $post) |
| 807 | 833 | { |
| 808 | 834 | $ignoring = false; |
| 809 | - if (!empty($post['is_ignored'])) |
|
| 810 | - $ignored_posts[] = $ignoring = $post['id']; |
|
| 835 | + if (!empty($post['is_ignored'])) { |
|
| 836 | + $ignored_posts[] = $ignoring = $post['id']; |
|
| 837 | + } |
|
| 811 | 838 | |
| 812 | 839 | echo ' |
| 813 | 840 | <div class="windowbg"> |
@@ -990,10 +1017,10 @@ discard block |
||
| 990 | 1017 | <div id="temporary_posting_area" style="display: none;"></div> |
| 991 | 1018 | <script>'; |
| 992 | 1019 | |
| 993 | - if ($context['close_window']) |
|
| 994 | - echo ' |
|
| 1020 | + if ($context['close_window']) { |
|
| 1021 | + echo ' |
|
| 995 | 1022 | window.close();'; |
| 996 | - else |
|
| 1023 | + } else |
|
| 997 | 1024 | { |
| 998 | 1025 | // Lucky for us, Internet Explorer has an "innerText" feature which basically converts entities <--> text. Use it if possible ;). |
| 999 | 1026 | echo ' |
@@ -1047,11 +1074,12 @@ discard block |
||
| 1047 | 1074 | </p> |
| 1048 | 1075 | <ul>'; |
| 1049 | 1076 | |
| 1050 | - foreach ($context['groups'] as $group) |
|
| 1051 | - echo ' |
|
| 1077 | + foreach ($context['groups'] as $group) { |
|
| 1078 | + echo ' |
|
| 1052 | 1079 | <li> |
| 1053 | 1080 | <label for="who_', $group['id'], '"><input type="checkbox" name="who[', $group['id'], ']" id="who_', $group['id'], '" value="', $group['id'], '" checked class="input_check"> ', $group['name'], '</label> <em>(', $group['member_count'], ')</em> |
| 1054 | 1081 | </li>'; |
| 1082 | + } |
|
| 1055 | 1083 | |
| 1056 | 1084 | echo ' |
| 1057 | 1085 | <li> |
@@ -12,8 +12,9 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | 14 | // Don't do anything if SMF is already loaded. |
| 15 | -if (defined('SMF')) |
|
| 15 | +if (defined('SMF')) { |
|
| 16 | 16 | return true; |
| 17 | +} |
|
| 17 | 18 | |
| 18 | 19 | define('SMF', 'SSI'); |
| 19 | 20 | |
@@ -26,21 +27,24 @@ discard block |
||
| 26 | 27 | |
| 27 | 28 | // Remember the current configuration so it can be set back. |
| 28 | 29 | $ssi_magic_quotes_runtime = function_exists('get_magic_quotes_gpc') && get_magic_quotes_runtime(); |
| 29 | -if (function_exists('set_magic_quotes_runtime')) |
|
| 30 | +if (function_exists('set_magic_quotes_runtime')) { |
|
| 30 | 31 | @set_magic_quotes_runtime(0); |
| 32 | +} |
|
| 31 | 33 | $time_start = microtime(); |
| 32 | 34 | |
| 33 | 35 | // Just being safe... |
| 34 | -foreach (array('db_character_set', 'cachedir') as $variable) |
|
| 36 | +foreach (array('db_character_set', 'cachedir') as $variable) { |
|
| 35 | 37 | if (isset($GLOBALS[$variable])) |
| 36 | 38 | unset($GLOBALS[$variable]); |
| 39 | +} |
|
| 37 | 40 | |
| 38 | 41 | // Get the forum's settings for database and file paths. |
| 39 | 42 | require_once(dirname(__FILE__) . '/Settings.php'); |
| 40 | 43 | |
| 41 | 44 | // Make absolutely sure the cache directory is defined. |
| 42 | -if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) |
|
| 45 | +if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) { |
|
| 43 | 46 | $cachedir = $boarddir . '/cache'; |
| 47 | +} |
|
| 44 | 48 | |
| 45 | 49 | $ssi_error_reporting = error_reporting(defined('E_STRICT') ? E_ALL | E_STRICT : E_ALL); |
| 46 | 50 | /* Set this to one of three values depending on what you want to happen in the case of a fatal error. |
@@ -51,12 +55,14 @@ discard block |
||
| 51 | 55 | $ssi_on_error_method = false; |
| 52 | 56 | |
| 53 | 57 | // Don't do john didley if the forum's been shut down completely. |
| 54 | -if ($maintenance == 2 && (!isset($ssi_maintenance_off) || $ssi_maintenance_off !== true)) |
|
| 58 | +if ($maintenance == 2 && (!isset($ssi_maintenance_off) || $ssi_maintenance_off !== true)) { |
|
| 55 | 59 | die($mmessage); |
| 60 | +} |
|
| 56 | 61 | |
| 57 | 62 | // Fix for using the current directory as a path. |
| 58 | -if (substr($sourcedir, 0, 1) == '.' && substr($sourcedir, 1, 1) != '.') |
|
| 63 | +if (substr($sourcedir, 0, 1) == '.' && substr($sourcedir, 1, 1) != '.') { |
|
| 59 | 64 | $sourcedir = dirname(__FILE__) . substr($sourcedir, 1); |
| 65 | +} |
|
| 60 | 66 | |
| 61 | 67 | // Load the important includes. |
| 62 | 68 | require_once($sourcedir . '/QueryString.php'); |
@@ -81,34 +87,38 @@ discard block |
||
| 81 | 87 | cleanRequest(); |
| 82 | 88 | |
| 83 | 89 | // Seed the random generator? |
| 84 | -if (empty($modSettings['rand_seed']) || mt_rand(1, 250) == 69) |
|
| 90 | +if (empty($modSettings['rand_seed']) || mt_rand(1, 250) == 69) { |
|
| 85 | 91 | smf_seed_generator(); |
| 92 | +} |
|
| 86 | 93 | |
| 87 | 94 | // Check on any hacking attempts. |
| 88 | -if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS'])) |
|
| 95 | +if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS'])) { |
|
| 89 | 96 | die('No direct access...'); |
| 90 | -elseif (isset($_REQUEST['ssi_theme']) && (int) $_REQUEST['ssi_theme'] == (int) $ssi_theme) |
|
| 97 | +} elseif (isset($_REQUEST['ssi_theme']) && (int) $_REQUEST['ssi_theme'] == (int) $ssi_theme) { |
|
| 91 | 98 | die('No direct access...'); |
| 92 | -elseif (isset($_COOKIE['ssi_theme']) && (int) $_COOKIE['ssi_theme'] == (int) $ssi_theme) |
|
| 99 | +} elseif (isset($_COOKIE['ssi_theme']) && (int) $_COOKIE['ssi_theme'] == (int) $ssi_theme) { |
|
| 93 | 100 | die('No direct access...'); |
| 94 | -elseif (isset($_REQUEST['ssi_layers'], $ssi_layers) && (@get_magic_quotes_gpc() ? stripslashes($_REQUEST['ssi_layers']) : $_REQUEST['ssi_layers']) == $ssi_layers) |
|
| 101 | +} elseif (isset($_REQUEST['ssi_layers'], $ssi_layers) && (@get_magic_quotes_gpc() ? stripslashes($_REQUEST['ssi_layers']) : $_REQUEST['ssi_layers']) == $ssi_layers) { |
|
| 95 | 102 | die('No direct access...'); |
| 96 | -if (isset($_REQUEST['context'])) |
|
| 103 | +} |
|
| 104 | +if (isset($_REQUEST['context'])) { |
|
| 97 | 105 | die('No direct access...'); |
| 106 | +} |
|
| 98 | 107 | |
| 99 | 108 | // Gzip output? (because it must be boolean and true, this can't be hacked.) |
| 100 | -if (isset($ssi_gzip) && $ssi_gzip === true && ini_get('zlib.output_compression') != '1' && ini_get('output_handler') != 'ob_gzhandler' && version_compare(PHP_VERSION, '4.2.0', '>=')) |
|
| 109 | +if (isset($ssi_gzip) && $ssi_gzip === true && ini_get('zlib.output_compression') != '1' && ini_get('output_handler') != 'ob_gzhandler' && version_compare(PHP_VERSION, '4.2.0', '>=')) { |
|
| 101 | 110 | ob_start('ob_gzhandler'); |
| 102 | -else |
|
| 111 | +} else { |
|
| 103 | 112 | $modSettings['enableCompressedOutput'] = '0'; |
| 113 | +} |
|
| 104 | 114 | |
| 105 | 115 | // Primarily, this is to fix the URLs... |
| 106 | 116 | ob_start('ob_sessrewrite'); |
| 107 | 117 | |
| 108 | 118 | // Start the session... known to scramble SSI includes in cases... |
| 109 | -if (!headers_sent()) |
|
| 119 | +if (!headers_sent()) { |
|
| 110 | 120 | loadSession(); |
| 111 | -else |
|
| 121 | +} else |
|
| 112 | 122 | { |
| 113 | 123 | if (isset($_COOKIE[session_name()]) || isset($_REQUEST[session_name()])) |
| 114 | 124 | { |
@@ -142,12 +152,14 @@ discard block |
||
| 142 | 152 | loadTheme(isset($ssi_theme) ? (int) $ssi_theme : 0); |
| 143 | 153 | |
| 144 | 154 | // @todo: probably not the best place, but somewhere it should be set... |
| 145 | -if (!headers_sent()) |
|
| 155 | +if (!headers_sent()) { |
|
| 146 | 156 | header('Content-Type: text/html; charset=' . (empty($modSettings['global_character_set']) ? (empty($txt['lang_character_set']) ? 'ISO-8859-1' : $txt['lang_character_set']) : $modSettings['global_character_set'])); |
| 157 | +} |
|
| 147 | 158 | |
| 148 | 159 | // Take care of any banning that needs to be done. |
| 149 | -if (isset($_REQUEST['ssi_ban']) || (isset($ssi_ban) && $ssi_ban === true)) |
|
| 160 | +if (isset($_REQUEST['ssi_ban']) || (isset($ssi_ban) && $ssi_ban === true)) { |
|
| 150 | 161 | is_not_banned(); |
| 162 | +} |
|
| 151 | 163 | |
| 152 | 164 | // Do we allow guests in here? |
| 153 | 165 | if (empty($ssi_guest_access) && empty($modSettings['allow_guestAccess']) && $user_info['is_guest'] && basename($_SERVER['PHP_SELF']) != 'SSI.php') |
@@ -162,17 +174,19 @@ discard block |
||
| 162 | 174 | { |
| 163 | 175 | $context['template_layers'] = $ssi_layers; |
| 164 | 176 | template_header(); |
| 165 | -} |
|
| 166 | -else |
|
| 177 | +} else { |
|
| 167 | 178 | setupThemeContext(); |
| 179 | +} |
|
| 168 | 180 | |
| 169 | 181 | // Make sure they didn't muss around with the settings... but only if it's not cli. |
| 170 | -if (isset($_SERVER['REMOTE_ADDR']) && !isset($_SERVER['is_cli']) && session_id() == '') |
|
| 182 | +if (isset($_SERVER['REMOTE_ADDR']) && !isset($_SERVER['is_cli']) && session_id() == '') { |
|
| 171 | 183 | trigger_error($txt['ssi_session_broken'], E_USER_NOTICE); |
| 184 | +} |
|
| 172 | 185 | |
| 173 | 186 | // Without visiting the forum this session variable might not be set on submit. |
| 174 | -if (!isset($_SESSION['USER_AGENT']) && (!isset($_GET['ssi_function']) || $_GET['ssi_function'] !== 'pollVote')) |
|
| 187 | +if (!isset($_SESSION['USER_AGENT']) && (!isset($_GET['ssi_function']) || $_GET['ssi_function'] !== 'pollVote')) { |
|
| 175 | 188 | $_SESSION['USER_AGENT'] = $_SERVER['HTTP_USER_AGENT']; |
| 189 | +} |
|
| 176 | 190 | |
| 177 | 191 | // Have the ability to easily add functions to SSI. |
| 178 | 192 | call_integration_hook('integrate_SSI'); |
@@ -181,11 +195,13 @@ discard block |
||
| 181 | 195 | if (basename($_SERVER['PHP_SELF']) == 'SSI.php') |
| 182 | 196 | { |
| 183 | 197 | // You shouldn't just access SSI.php directly by URL!! |
| 184 | - if (!isset($_GET['ssi_function'])) |
|
| 185 | - die(sprintf($txt['ssi_not_direct'], $user_info['is_admin'] ? '\'' . addslashes(__FILE__) . '\'' : '\'SSI.php\'')); |
|
| 198 | + if (!isset($_GET['ssi_function'])) { |
|
| 199 | + die(sprintf($txt['ssi_not_direct'], $user_info['is_admin'] ? '\'' . addslashes(__FILE__) . '\'' : '\'SSI.php\'')); |
|
| 200 | + } |
|
| 186 | 201 | // Call a function passed by GET. |
| 187 | - if (function_exists('ssi_' . $_GET['ssi_function']) && (!empty($modSettings['allow_guestAccess']) || !$user_info['is_guest'])) |
|
| 188 | - call_user_func('ssi_' . $_GET['ssi_function']); |
|
| 202 | + if (function_exists('ssi_' . $_GET['ssi_function']) && (!empty($modSettings['allow_guestAccess']) || !$user_info['is_guest'])) { |
|
| 203 | + call_user_func('ssi_' . $_GET['ssi_function']); |
|
| 204 | + } |
|
| 189 | 205 | exit; |
| 190 | 206 | } |
| 191 | 207 | |
@@ -193,8 +209,9 @@ discard block |
||
| 193 | 209 | unset($_GET['ssi_function']); |
| 194 | 210 | |
| 195 | 211 | error_reporting($ssi_error_reporting); |
| 196 | -if (function_exists('set_magic_quotes_runtime')) |
|
| 212 | +if (function_exists('set_magic_quotes_runtime')) { |
|
| 197 | 213 | @set_magic_quotes_runtime($ssi_magic_quotes_runtime); |
| 214 | +} |
|
| 198 | 215 | |
| 199 | 216 | return true; |
| 200 | 217 | |
@@ -204,9 +221,10 @@ discard block |
||
| 204 | 221 | */ |
| 205 | 222 | function ssi_shutdown() |
| 206 | 223 | { |
| 207 | - if (!isset($_GET['ssi_function']) || $_GET['ssi_function'] != 'shutdown') |
|
| 208 | - template_footer(); |
|
| 209 | -} |
|
| 224 | + if (!isset($_GET['ssi_function']) || $_GET['ssi_function'] != 'shutdown') { |
|
| 225 | + template_footer(); |
|
| 226 | + } |
|
| 227 | + } |
|
| 210 | 228 | |
| 211 | 229 | /** |
| 212 | 230 | * Display a welcome message, like: Hey, User, you have 0 messages, 0 are new. |
@@ -219,15 +237,17 @@ discard block |
||
| 219 | 237 | |
| 220 | 238 | if ($output_method == 'echo') |
| 221 | 239 | { |
| 222 | - if ($context['user']['is_guest']) |
|
| 223 | - echo sprintf($txt[$context['can_register'] ? 'welcome_guest_register' : 'welcome_guest'], $txt['guest_title'], $context['forum_name_html_safe'], $scripturl . '?action=login', 'return reqOverlayDiv(this.href, ' . JavaScriptEscape($txt['login']) . ');', $scripturl . '?action=signup'); |
|
| 224 | - else |
|
| 225 | - echo $txt['hello_member'], ' <strong>', $context['user']['name'], '</strong>', allowedTo('pm_read') ? ', ' . (empty($context['user']['messages']) ? $txt['msg_alert_no_messages'] : (($context['user']['messages'] == 1 ? sprintf($txt['msg_alert_one_message'], $scripturl . '?action=pm') : sprintf($txt['msg_alert_many_message'], $scripturl . '?action=pm', $context['user']['messages'])) . ', ' . ($context['user']['unread_messages'] == 1 ? $txt['msg_alert_one_new'] : sprintf($txt['msg_alert_many_new'], $context['user']['unread_messages'])))) : ''; |
|
| 240 | + if ($context['user']['is_guest']) { |
|
| 241 | + echo sprintf($txt[$context['can_register'] ? 'welcome_guest_register' : 'welcome_guest'], $txt['guest_title'], $context['forum_name_html_safe'], $scripturl . '?action=login', 'return reqOverlayDiv(this.href, ' . JavaScriptEscape($txt['login']) . ');', $scripturl . '?action=signup'); |
|
| 242 | + } else { |
|
| 243 | + echo $txt['hello_member'], ' <strong>', $context['user']['name'], '</strong>', allowedTo('pm_read') ? ', ' . (empty($context['user']['messages']) ? $txt['msg_alert_no_messages'] : (($context['user']['messages'] == 1 ? sprintf($txt['msg_alert_one_message'], $scripturl . '?action=pm') : sprintf($txt['msg_alert_many_message'], $scripturl . '?action=pm', $context['user']['messages'])) . ', ' . ($context['user']['unread_messages'] == 1 ? $txt['msg_alert_one_new'] : sprintf($txt['msg_alert_many_new'], $context['user']['unread_messages'])))) : ''; |
|
| 244 | + } |
|
| 226 | 245 | } |
| 227 | 246 | // Don't echo... then do what?! |
| 228 | - else |
|
| 229 | - return $context['user']; |
|
| 230 | -} |
|
| 247 | + else { |
|
| 248 | + return $context['user']; |
|
| 249 | + } |
|
| 250 | + } |
|
| 231 | 251 | |
| 232 | 252 | /** |
| 233 | 253 | * Display a menu bar, like is displayed at the top of the forum. |
@@ -238,12 +258,14 @@ discard block |
||
| 238 | 258 | { |
| 239 | 259 | global $context; |
| 240 | 260 | |
| 241 | - if ($output_method == 'echo') |
|
| 242 | - template_menu(); |
|
| 261 | + if ($output_method == 'echo') { |
|
| 262 | + template_menu(); |
|
| 263 | + } |
|
| 243 | 264 | // What else could this do? |
| 244 | - else |
|
| 245 | - return $context['menu_buttons']; |
|
| 246 | -} |
|
| 265 | + else { |
|
| 266 | + return $context['menu_buttons']; |
|
| 267 | + } |
|
| 268 | + } |
|
| 247 | 269 | |
| 248 | 270 | /** |
| 249 | 271 | * Show a logout link. |
@@ -255,20 +277,23 @@ discard block |
||
| 255 | 277 | { |
| 256 | 278 | global $context, $txt, $scripturl; |
| 257 | 279 | |
| 258 | - if ($redirect_to != '') |
|
| 259 | - $_SESSION['logout_url'] = $redirect_to; |
|
| 280 | + if ($redirect_to != '') { |
|
| 281 | + $_SESSION['logout_url'] = $redirect_to; |
|
| 282 | + } |
|
| 260 | 283 | |
| 261 | 284 | // Guests can't log out. |
| 262 | - if ($context['user']['is_guest']) |
|
| 263 | - return false; |
|
| 285 | + if ($context['user']['is_guest']) { |
|
| 286 | + return false; |
|
| 287 | + } |
|
| 264 | 288 | |
| 265 | 289 | $link = '<a href="' . $scripturl . '?action=logout;' . $context['session_var'] . '=' . $context['session_id'] . '">' . $txt['logout'] . '</a>'; |
| 266 | 290 | |
| 267 | - if ($output_method == 'echo') |
|
| 268 | - echo $link; |
|
| 269 | - else |
|
| 270 | - return $link; |
|
| 271 | -} |
|
| 291 | + if ($output_method == 'echo') { |
|
| 292 | + echo $link; |
|
| 293 | + } else { |
|
| 294 | + return $link; |
|
| 295 | + } |
|
| 296 | + } |
|
| 272 | 297 | |
| 273 | 298 | /** |
| 274 | 299 | * Recent post list: [board] Subject by Poster Date |
@@ -284,17 +309,17 @@ discard block |
||
| 284 | 309 | global $modSettings, $context; |
| 285 | 310 | |
| 286 | 311 | // Excluding certain boards... |
| 287 | - if ($exclude_boards === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0) |
|
| 288 | - $exclude_boards = array($modSettings['recycle_board']); |
|
| 289 | - else |
|
| 290 | - $exclude_boards = empty($exclude_boards) ? array() : (is_array($exclude_boards) ? $exclude_boards : array($exclude_boards)); |
|
| 312 | + if ($exclude_boards === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0) { |
|
| 313 | + $exclude_boards = array($modSettings['recycle_board']); |
|
| 314 | + } else { |
|
| 315 | + $exclude_boards = empty($exclude_boards) ? array() : (is_array($exclude_boards) ? $exclude_boards : array($exclude_boards)); |
|
| 316 | + } |
|
| 291 | 317 | |
| 292 | 318 | // What about including certain boards - note we do some protection here as pre-2.0 didn't have this parameter. |
| 293 | 319 | if (is_array($include_boards) || (int) $include_boards === $include_boards) |
| 294 | 320 | { |
| 295 | 321 | $include_boards = is_array($include_boards) ? $include_boards : array($include_boards); |
| 296 | - } |
|
| 297 | - elseif ($include_boards != null) |
|
| 322 | + } elseif ($include_boards != null) |
|
| 298 | 323 | { |
| 299 | 324 | $include_boards = array(); |
| 300 | 325 | } |
@@ -331,8 +356,9 @@ discard block |
||
| 331 | 356 | { |
| 332 | 357 | global $modSettings; |
| 333 | 358 | |
| 334 | - if (empty($post_ids)) |
|
| 335 | - return; |
|
| 359 | + if (empty($post_ids)) { |
|
| 360 | + return; |
|
| 361 | + } |
|
| 336 | 362 | |
| 337 | 363 | // Allow the user to request more than one - why not? |
| 338 | 364 | $post_ids = is_array($post_ids) ? $post_ids : array($post_ids); |
@@ -367,8 +393,9 @@ discard block |
||
| 367 | 393 | global $scripturl, $txt, $user_info; |
| 368 | 394 | global $modSettings, $smcFunc, $context; |
| 369 | 395 | |
| 370 | - if (!empty($modSettings['enable_likes'])) |
|
| 371 | - $context['can_like'] = allowedTo('likes_like'); |
|
| 396 | + if (!empty($modSettings['enable_likes'])) { |
|
| 397 | + $context['can_like'] = allowedTo('likes_like'); |
|
| 398 | + } |
|
| 372 | 399 | |
| 373 | 400 | // Find all the posts. Newer ones will have higher IDs. |
| 374 | 401 | $request = $smcFunc['db_query']('substring', ' |
@@ -434,12 +461,13 @@ discard block |
||
| 434 | 461 | ); |
| 435 | 462 | |
| 436 | 463 | // Get the likes for each message. |
| 437 | - if (!empty($modSettings['enable_likes'])) |
|
| 438 | - $posts[$row['id_msg']]['likes'] = array( |
|
| 464 | + if (!empty($modSettings['enable_likes'])) { |
|
| 465 | + $posts[$row['id_msg']]['likes'] = array( |
|
| 439 | 466 | 'count' => $row['likes'], |
| 440 | 467 | 'you' => in_array($row['id_msg'], prepareLikesContext($row['id_topic'])), |
| 441 | 468 | 'can_like' => !$context['user']['is_guest'] && $row['id_member'] != $context['user']['id'] && !empty($context['can_like']), |
| 442 | 469 | ); |
| 470 | + } |
|
| 443 | 471 | } |
| 444 | 472 | $smcFunc['db_free_result']($request); |
| 445 | 473 | |
@@ -447,13 +475,14 @@ discard block |
||
| 447 | 475 | call_integration_hook('integrate_ssi_queryPosts', array(&$posts)); |
| 448 | 476 | |
| 449 | 477 | // Just return it. |
| 450 | - if ($output_method != 'echo' || empty($posts)) |
|
| 451 | - return $posts; |
|
| 478 | + if ($output_method != 'echo' || empty($posts)) { |
|
| 479 | + return $posts; |
|
| 480 | + } |
|
| 452 | 481 | |
| 453 | 482 | echo ' |
| 454 | 483 | <table style="border: none" class="ssi_table">'; |
| 455 | - foreach ($posts as $post) |
|
| 456 | - echo ' |
|
| 484 | + foreach ($posts as $post) { |
|
| 485 | + echo ' |
|
| 457 | 486 | <tr> |
| 458 | 487 | <td style="text-align: right; vertical-align: top; white-space: nowrap"> |
| 459 | 488 | [', $post['board']['link'], '] |
@@ -467,6 +496,7 @@ discard block |
||
| 467 | 496 | ', $post['time'], ' |
| 468 | 497 | </td> |
| 469 | 498 | </tr>'; |
| 499 | + } |
|
| 470 | 500 | echo ' |
| 471 | 501 | </table>'; |
| 472 | 502 | } |
@@ -484,25 +514,26 @@ discard block |
||
| 484 | 514 | global $settings, $scripturl, $txt, $user_info; |
| 485 | 515 | global $modSettings, $smcFunc, $context; |
| 486 | 516 | |
| 487 | - if ($exclude_boards === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0) |
|
| 488 | - $exclude_boards = array($modSettings['recycle_board']); |
|
| 489 | - else |
|
| 490 | - $exclude_boards = empty($exclude_boards) ? array() : (is_array($exclude_boards) ? $exclude_boards : array($exclude_boards)); |
|
| 517 | + if ($exclude_boards === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0) { |
|
| 518 | + $exclude_boards = array($modSettings['recycle_board']); |
|
| 519 | + } else { |
|
| 520 | + $exclude_boards = empty($exclude_boards) ? array() : (is_array($exclude_boards) ? $exclude_boards : array($exclude_boards)); |
|
| 521 | + } |
|
| 491 | 522 | |
| 492 | 523 | // Only some boards?. |
| 493 | 524 | if (is_array($include_boards) || (int) $include_boards === $include_boards) |
| 494 | 525 | { |
| 495 | 526 | $include_boards = is_array($include_boards) ? $include_boards : array($include_boards); |
| 496 | - } |
|
| 497 | - elseif ($include_boards != null) |
|
| 527 | + } elseif ($include_boards != null) |
|
| 498 | 528 | { |
| 499 | 529 | $output_method = $include_boards; |
| 500 | 530 | $include_boards = array(); |
| 501 | 531 | } |
| 502 | 532 | |
| 503 | 533 | $icon_sources = array(); |
| 504 | - foreach ($context['stable_icons'] as $icon) |
|
| 505 | - $icon_sources[$icon] = 'images_url'; |
|
| 534 | + foreach ($context['stable_icons'] as $icon) { |
|
| 535 | + $icon_sources[$icon] = 'images_url'; |
|
| 536 | + } |
|
| 506 | 537 | |
| 507 | 538 | // Find all the posts in distinct topics. Newer ones will have higher IDs. |
| 508 | 539 | $request = $smcFunc['db_query']('substring', ' |
@@ -527,13 +558,15 @@ discard block |
||
| 527 | 558 | ) |
| 528 | 559 | ); |
| 529 | 560 | $topics = array(); |
| 530 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 531 | - $topics[$row['id_topic']] = $row; |
|
| 561 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 562 | + $topics[$row['id_topic']] = $row; |
|
| 563 | + } |
|
| 532 | 564 | $smcFunc['db_free_result']($request); |
| 533 | 565 | |
| 534 | 566 | // Did we find anything? If not, bail. |
| 535 | - if (empty($topics)) |
|
| 536 | - return array(); |
|
| 567 | + if (empty($topics)) { |
|
| 568 | + return array(); |
|
| 569 | + } |
|
| 537 | 570 | |
| 538 | 571 | $recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0; |
| 539 | 572 | |
@@ -561,19 +594,22 @@ discard block |
||
| 561 | 594 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 562 | 595 | { |
| 563 | 596 | $row['body'] = strip_tags(strtr(parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']), array('<br>' => ' '))); |
| 564 | - if ($smcFunc['strlen']($row['body']) > 128) |
|
| 565 | - $row['body'] = $smcFunc['substr']($row['body'], 0, 128) . '...'; |
|
| 597 | + if ($smcFunc['strlen']($row['body']) > 128) { |
|
| 598 | + $row['body'] = $smcFunc['substr']($row['body'], 0, 128) . '...'; |
|
| 599 | + } |
|
| 566 | 600 | |
| 567 | 601 | // Censor the subject. |
| 568 | 602 | censorText($row['subject']); |
| 569 | 603 | censorText($row['body']); |
| 570 | 604 | |
| 571 | 605 | // Recycled icon |
| 572 | - if (!empty($recycle_board) && $topics[$row['id_topic']]['id_board']) |
|
| 573 | - $row['icon'] = 'recycled'; |
|
| 606 | + if (!empty($recycle_board) && $topics[$row['id_topic']]['id_board']) { |
|
| 607 | + $row['icon'] = 'recycled'; |
|
| 608 | + } |
|
| 574 | 609 | |
| 575 | - if (!empty($modSettings['messageIconChecks_enable']) && !isset($icon_sources[$row['icon']])) |
|
| 576 | - $icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
| 610 | + if (!empty($modSettings['messageIconChecks_enable']) && !isset($icon_sources[$row['icon']])) { |
|
| 611 | + $icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
| 612 | + } |
|
| 577 | 613 | |
| 578 | 614 | // Build the array. |
| 579 | 615 | $posts[] = array( |
@@ -612,13 +648,14 @@ discard block |
||
| 612 | 648 | call_integration_hook('integrate_ssi_recentTopics', array(&$posts)); |
| 613 | 649 | |
| 614 | 650 | // Just return it. |
| 615 | - if ($output_method != 'echo' || empty($posts)) |
|
| 616 | - return $posts; |
|
| 651 | + if ($output_method != 'echo' || empty($posts)) { |
|
| 652 | + return $posts; |
|
| 653 | + } |
|
| 617 | 654 | |
| 618 | 655 | echo ' |
| 619 | 656 | <table style="border: none" class="ssi_table">'; |
| 620 | - foreach ($posts as $post) |
|
| 621 | - echo ' |
|
| 657 | + foreach ($posts as $post) { |
|
| 658 | + echo ' |
|
| 622 | 659 | <tr> |
| 623 | 660 | <td style="text-align: right; vertical-align: top; white-space: nowrap"> |
| 624 | 661 | [', $post['board']['link'], '] |
@@ -632,6 +669,7 @@ discard block |
||
| 632 | 669 | ', $post['time'], ' |
| 633 | 670 | </td> |
| 634 | 671 | </tr>'; |
| 672 | + } |
|
| 635 | 673 | echo ' |
| 636 | 674 | </table>'; |
| 637 | 675 | } |
@@ -656,27 +694,30 @@ discard block |
||
| 656 | 694 | ) |
| 657 | 695 | ); |
| 658 | 696 | $return = array(); |
| 659 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 660 | - $return[] = array( |
|
| 697 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 698 | + $return[] = array( |
|
| 661 | 699 | 'id' => $row['id_member'], |
| 662 | 700 | 'name' => $row['real_name'], |
| 663 | 701 | 'href' => $scripturl . '?action=profile;u=' . $row['id_member'], |
| 664 | 702 | 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>', |
| 665 | 703 | 'posts' => $row['posts'] |
| 666 | 704 | ); |
| 705 | + } |
|
| 667 | 706 | $smcFunc['db_free_result']($request); |
| 668 | 707 | |
| 669 | 708 | // If mods want to do somthing with this list of members, let them do that now. |
| 670 | 709 | call_integration_hook('integrate_ssi_topPoster', array(&$return)); |
| 671 | 710 | |
| 672 | 711 | // Just return all the top posters. |
| 673 | - if ($output_method != 'echo') |
|
| 674 | - return $return; |
|
| 712 | + if ($output_method != 'echo') { |
|
| 713 | + return $return; |
|
| 714 | + } |
|
| 675 | 715 | |
| 676 | 716 | // Make a quick array to list the links in. |
| 677 | 717 | $temp_array = array(); |
| 678 | - foreach ($return as $member) |
|
| 679 | - $temp_array[] = $member['link']; |
|
| 718 | + foreach ($return as $member) { |
|
| 719 | + $temp_array[] = $member['link']; |
|
| 720 | + } |
|
| 680 | 721 | |
| 681 | 722 | echo implode(', ', $temp_array); |
| 682 | 723 | } |
@@ -708,8 +749,8 @@ discard block |
||
| 708 | 749 | ) |
| 709 | 750 | ); |
| 710 | 751 | $boards = array(); |
| 711 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 712 | - $boards[] = array( |
|
| 752 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 753 | + $boards[] = array( |
|
| 713 | 754 | 'id' => $row['id_board'], |
| 714 | 755 | 'num_posts' => $row['num_posts'], |
| 715 | 756 | 'num_topics' => $row['num_topics'], |
@@ -718,14 +759,16 @@ discard block |
||
| 718 | 759 | 'href' => $scripturl . '?board=' . $row['id_board'] . '.0', |
| 719 | 760 | 'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>' |
| 720 | 761 | ); |
| 762 | + } |
|
| 721 | 763 | $smcFunc['db_free_result']($request); |
| 722 | 764 | |
| 723 | 765 | // If mods want to do somthing with this list of boards, let them do that now. |
| 724 | 766 | call_integration_hook('integrate_ssi_topBoards', array(&$boards)); |
| 725 | 767 | |
| 726 | 768 | // If we shouldn't output or have nothing to output, just jump out. |
| 727 | - if ($output_method != 'echo' || empty($boards)) |
|
| 728 | - return $boards; |
|
| 769 | + if ($output_method != 'echo' || empty($boards)) { |
|
| 770 | + return $boards; |
|
| 771 | + } |
|
| 729 | 772 | |
| 730 | 773 | echo ' |
| 731 | 774 | <table class="ssi_table"> |
@@ -734,13 +777,14 @@ discard block |
||
| 734 | 777 | <th style="text-align: left">', $txt['board_topics'], '</th> |
| 735 | 778 | <th style="text-align: left">', $txt['posts'], '</th> |
| 736 | 779 | </tr>'; |
| 737 | - foreach ($boards as $sBoard) |
|
| 738 | - echo ' |
|
| 780 | + foreach ($boards as $sBoard) { |
|
| 781 | + echo ' |
|
| 739 | 782 | <tr> |
| 740 | 783 | <td>', $sBoard['link'], $sBoard['new'] ? ' <a href="' . $sBoard['href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>' : '', '</td> |
| 741 | 784 | <td style="text-align: right">', comma_format($sBoard['num_topics']), '</td> |
| 742 | 785 | <td style="text-align: right">', comma_format($sBoard['num_posts']), '</td> |
| 743 | 786 | </tr>'; |
| 787 | + } |
|
| 744 | 788 | echo ' |
| 745 | 789 | </table>'; |
| 746 | 790 | } |
@@ -773,12 +817,13 @@ discard block |
||
| 773 | 817 | ) |
| 774 | 818 | ); |
| 775 | 819 | $topic_ids = array(); |
| 776 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 777 | - $topic_ids[] = $row['id_topic']; |
|
| 820 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 821 | + $topic_ids[] = $row['id_topic']; |
|
| 822 | + } |
|
| 778 | 823 | $smcFunc['db_free_result']($request); |
| 824 | + } else { |
|
| 825 | + $topic_ids = array(); |
|
| 779 | 826 | } |
| 780 | - else |
|
| 781 | - $topic_ids = array(); |
|
| 782 | 827 | |
| 783 | 828 | $request = $smcFunc['db_query']('', ' |
| 784 | 829 | SELECT m.subject, m.id_topic, t.num_views, t.num_replies |
@@ -817,8 +862,9 @@ discard block |
||
| 817 | 862 | // If mods want to do somthing with this list of topics, let them do that now. |
| 818 | 863 | call_integration_hook('integrate_ssi_topTopics', array(&$topics, $type)); |
| 819 | 864 | |
| 820 | - if ($output_method != 'echo' || empty($topics)) |
|
| 821 | - return $topics; |
|
| 865 | + if ($output_method != 'echo' || empty($topics)) { |
|
| 866 | + return $topics; |
|
| 867 | + } |
|
| 822 | 868 | |
| 823 | 869 | echo ' |
| 824 | 870 | <table class="ssi_table"> |
@@ -827,8 +873,8 @@ discard block |
||
| 827 | 873 | <th style="text-align: left">', $txt['views'], '</th> |
| 828 | 874 | <th style="text-align: left">', $txt['replies'], '</th> |
| 829 | 875 | </tr>'; |
| 830 | - foreach ($topics as $sTopic) |
|
| 831 | - echo ' |
|
| 876 | + foreach ($topics as $sTopic) { |
|
| 877 | + echo ' |
|
| 832 | 878 | <tr> |
| 833 | 879 | <td style="text-align: left"> |
| 834 | 880 | ', $sTopic['link'], ' |
@@ -836,6 +882,7 @@ discard block |
||
| 836 | 882 | <td style="text-align: right">', comma_format($sTopic['num_views']), '</td> |
| 837 | 883 | <td style="text-align: right">', comma_format($sTopic['num_replies']), '</td> |
| 838 | 884 | </tr>'; |
| 885 | + } |
|
| 839 | 886 | echo ' |
| 840 | 887 | </table>'; |
| 841 | 888 | } |
@@ -871,12 +918,13 @@ discard block |
||
| 871 | 918 | { |
| 872 | 919 | global $txt, $context; |
| 873 | 920 | |
| 874 | - if ($output_method == 'echo') |
|
| 875 | - echo ' |
|
| 921 | + if ($output_method == 'echo') { |
|
| 922 | + echo ' |
|
| 876 | 923 | ', sprintf($txt['welcome_newest_member'], $context['common_stats']['latest_member']['link']), '<br>'; |
| 877 | - else |
|
| 878 | - return $context['common_stats']['latest_member']; |
|
| 879 | -} |
|
| 924 | + } else { |
|
| 925 | + return $context['common_stats']['latest_member']; |
|
| 926 | + } |
|
| 927 | + } |
|
| 880 | 928 | |
| 881 | 929 | /** |
| 882 | 930 | * Fetches a random member. |
@@ -925,8 +973,9 @@ discard block |
||
| 925 | 973 | } |
| 926 | 974 | |
| 927 | 975 | // Just to be sure put the random generator back to something... random. |
| 928 | - if ($random_type != '') |
|
| 929 | - mt_srand(time()); |
|
| 976 | + if ($random_type != '') { |
|
| 977 | + mt_srand(time()); |
|
| 978 | + } |
|
| 930 | 979 | |
| 931 | 980 | return $result; |
| 932 | 981 | } |
@@ -939,8 +988,9 @@ discard block |
||
| 939 | 988 | */ |
| 940 | 989 | function ssi_fetchMember($member_ids = array(), $output_method = 'echo') |
| 941 | 990 | { |
| 942 | - if (empty($member_ids)) |
|
| 943 | - return; |
|
| 991 | + if (empty($member_ids)) { |
|
| 992 | + return; |
|
| 993 | + } |
|
| 944 | 994 | |
| 945 | 995 | // Can have more than one member if you really want... |
| 946 | 996 | $member_ids = is_array($member_ids) ? $member_ids : array($member_ids); |
@@ -965,8 +1015,9 @@ discard block |
||
| 965 | 1015 | */ |
| 966 | 1016 | function ssi_fetchGroupMembers($group_id = null, $output_method = 'echo') |
| 967 | 1017 | { |
| 968 | - if ($group_id === null) |
|
| 969 | - return; |
|
| 1018 | + if ($group_id === null) { |
|
| 1019 | + return; |
|
| 1020 | + } |
|
| 970 | 1021 | |
| 971 | 1022 | $query_where = ' |
| 972 | 1023 | id_group = {int:id_group} |
@@ -993,8 +1044,9 @@ discard block |
||
| 993 | 1044 | { |
| 994 | 1045 | global $smcFunc, $memberContext; |
| 995 | 1046 | |
| 996 | - if ($query_where === null) |
|
| 997 | - return; |
|
| 1047 | + if ($query_where === null) { |
|
| 1048 | + return; |
|
| 1049 | + } |
|
| 998 | 1050 | |
| 999 | 1051 | // Fetch the members in question. |
| 1000 | 1052 | $request = $smcFunc['db_query']('', ' |
@@ -1007,12 +1059,14 @@ discard block |
||
| 1007 | 1059 | )) |
| 1008 | 1060 | ); |
| 1009 | 1061 | $members = array(); |
| 1010 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1011 | - $members[] = $row['id_member']; |
|
| 1062 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1063 | + $members[] = $row['id_member']; |
|
| 1064 | + } |
|
| 1012 | 1065 | $smcFunc['db_free_result']($request); |
| 1013 | 1066 | |
| 1014 | - if (empty($members)) |
|
| 1015 | - return array(); |
|
| 1067 | + if (empty($members)) { |
|
| 1068 | + return array(); |
|
| 1069 | + } |
|
| 1016 | 1070 | |
| 1017 | 1071 | // If mods want to do somthing with this list of members, let them do that now. |
| 1018 | 1072 | call_integration_hook('integrate_ssi_queryMembers', array(&$members)); |
@@ -1021,23 +1075,25 @@ discard block |
||
| 1021 | 1075 | loadMemberData($members); |
| 1022 | 1076 | |
| 1023 | 1077 | // Draw the table! |
| 1024 | - if ($output_method == 'echo') |
|
| 1025 | - echo ' |
|
| 1078 | + if ($output_method == 'echo') { |
|
| 1079 | + echo ' |
|
| 1026 | 1080 | <table style="border: none" class="ssi_table">'; |
| 1081 | + } |
|
| 1027 | 1082 | |
| 1028 | 1083 | $query_members = array(); |
| 1029 | 1084 | foreach ($members as $member) |
| 1030 | 1085 | { |
| 1031 | 1086 | // Load their context data. |
| 1032 | - if (!loadMemberContext($member)) |
|
| 1033 | - continue; |
|
| 1087 | + if (!loadMemberContext($member)) { |
|
| 1088 | + continue; |
|
| 1089 | + } |
|
| 1034 | 1090 | |
| 1035 | 1091 | // Store this member's information. |
| 1036 | 1092 | $query_members[$member] = $memberContext[$member]; |
| 1037 | 1093 | |
| 1038 | 1094 | // Only do something if we're echo'ing. |
| 1039 | - if ($output_method == 'echo') |
|
| 1040 | - echo ' |
|
| 1095 | + if ($output_method == 'echo') { |
|
| 1096 | + echo ' |
|
| 1041 | 1097 | <tr> |
| 1042 | 1098 | <td style="text-align: right; vertical-align: top; white-space: nowrap"> |
| 1043 | 1099 | ', $query_members[$member]['link'], ' |
@@ -1045,12 +1101,14 @@ discard block |
||
| 1045 | 1101 | <br>', $query_members[$member]['avatar']['image'], ' |
| 1046 | 1102 | </td> |
| 1047 | 1103 | </tr>'; |
| 1104 | + } |
|
| 1048 | 1105 | } |
| 1049 | 1106 | |
| 1050 | 1107 | // End the table if appropriate. |
| 1051 | - if ($output_method == 'echo') |
|
| 1052 | - echo ' |
|
| 1108 | + if ($output_method == 'echo') { |
|
| 1109 | + echo ' |
|
| 1053 | 1110 | </table>'; |
| 1111 | + } |
|
| 1054 | 1112 | |
| 1055 | 1113 | // Send back the data. |
| 1056 | 1114 | return $query_members; |
@@ -1065,8 +1123,9 @@ discard block |
||
| 1065 | 1123 | { |
| 1066 | 1124 | global $txt, $scripturl, $modSettings, $smcFunc; |
| 1067 | 1125 | |
| 1068 | - if (!allowedTo('view_stats')) |
|
| 1069 | - return; |
|
| 1126 | + if (!allowedTo('view_stats')) { |
|
| 1127 | + return; |
|
| 1128 | + } |
|
| 1070 | 1129 | |
| 1071 | 1130 | $totals = array( |
| 1072 | 1131 | 'members' => $modSettings['totalMembers'], |
@@ -1095,8 +1154,9 @@ discard block |
||
| 1095 | 1154 | // If mods want to do somthing with the board stats, let them do that now. |
| 1096 | 1155 | call_integration_hook('integrate_ssi_boardStats', array(&$totals)); |
| 1097 | 1156 | |
| 1098 | - if ($output_method != 'echo') |
|
| 1099 | - return $totals; |
|
| 1157 | + if ($output_method != 'echo') { |
|
| 1158 | + return $totals; |
|
| 1159 | + } |
|
| 1100 | 1160 | |
| 1101 | 1161 | echo ' |
| 1102 | 1162 | ', $txt['total_members'], ': <a href="', $scripturl . '?action=mlist">', comma_format($totals['members']), '</a><br> |
@@ -1125,8 +1185,8 @@ discard block |
||
| 1125 | 1185 | call_integration_hook('integrate_ssi_whosOnline', array(&$return)); |
| 1126 | 1186 | |
| 1127 | 1187 | // Add some redundancy for backwards compatibility reasons. |
| 1128 | - if ($output_method != 'echo') |
|
| 1129 | - return $return + array( |
|
| 1188 | + if ($output_method != 'echo') { |
|
| 1189 | + return $return + array( |
|
| 1130 | 1190 | 'users' => $return['users_online'], |
| 1131 | 1191 | 'guests' => $return['num_guests'], |
| 1132 | 1192 | 'hidden' => $return['num_users_hidden'], |
@@ -1134,29 +1194,35 @@ discard block |
||
| 1134 | 1194 | 'num_users' => $return['num_users_online'], |
| 1135 | 1195 | 'total_users' => $return['num_users_online'] + $return['num_guests'], |
| 1136 | 1196 | ); |
| 1197 | + } |
|
| 1137 | 1198 | |
| 1138 | 1199 | echo ' |
| 1139 | 1200 | ', comma_format($return['num_guests']), ' ', $return['num_guests'] == 1 ? $txt['guest'] : $txt['guests'], ', ', comma_format($return['num_users_online']), ' ', $return['num_users_online'] == 1 ? $txt['user'] : $txt['users']; |
| 1140 | 1201 | |
| 1141 | 1202 | $bracketList = array(); |
| 1142 | - if (!empty($user_info['buddies'])) |
|
| 1143 | - $bracketList[] = comma_format($return['num_buddies']) . ' ' . ($return['num_buddies'] == 1 ? $txt['buddy'] : $txt['buddies']); |
|
| 1144 | - if (!empty($return['num_spiders'])) |
|
| 1145 | - $bracketList[] = comma_format($return['num_spiders']) . ' ' . ($return['num_spiders'] == 1 ? $txt['spider'] : $txt['spiders']); |
|
| 1146 | - if (!empty($return['num_users_hidden'])) |
|
| 1147 | - $bracketList[] = comma_format($return['num_users_hidden']) . ' ' . $txt['hidden']; |
|
| 1203 | + if (!empty($user_info['buddies'])) { |
|
| 1204 | + $bracketList[] = comma_format($return['num_buddies']) . ' ' . ($return['num_buddies'] == 1 ? $txt['buddy'] : $txt['buddies']); |
|
| 1205 | + } |
|
| 1206 | + if (!empty($return['num_spiders'])) { |
|
| 1207 | + $bracketList[] = comma_format($return['num_spiders']) . ' ' . ($return['num_spiders'] == 1 ? $txt['spider'] : $txt['spiders']); |
|
| 1208 | + } |
|
| 1209 | + if (!empty($return['num_users_hidden'])) { |
|
| 1210 | + $bracketList[] = comma_format($return['num_users_hidden']) . ' ' . $txt['hidden']; |
|
| 1211 | + } |
|
| 1148 | 1212 | |
| 1149 | - if (!empty($bracketList)) |
|
| 1150 | - echo ' (' . implode(', ', $bracketList) . ')'; |
|
| 1213 | + if (!empty($bracketList)) { |
|
| 1214 | + echo ' (' . implode(', ', $bracketList) . ')'; |
|
| 1215 | + } |
|
| 1151 | 1216 | |
| 1152 | 1217 | echo '<br> |
| 1153 | 1218 | ', implode(', ', $return['list_users_online']); |
| 1154 | 1219 | |
| 1155 | 1220 | // Showing membergroups? |
| 1156 | - if (!empty($settings['show_group_key']) && !empty($return['membergroups'])) |
|
| 1157 | - echo '<br> |
|
| 1221 | + if (!empty($settings['show_group_key']) && !empty($return['membergroups'])) { |
|
| 1222 | + echo '<br> |
|
| 1158 | 1223 | [' . implode('] [', $return['membergroups']) . ']'; |
| 1159 | -} |
|
| 1224 | + } |
|
| 1225 | + } |
|
| 1160 | 1226 | |
| 1161 | 1227 | /** |
| 1162 | 1228 | * Just like whosOnline except it also logs the online presence. |
@@ -1167,11 +1233,12 @@ discard block |
||
| 1167 | 1233 | { |
| 1168 | 1234 | writeLog(); |
| 1169 | 1235 | |
| 1170 | - if ($output_method != 'echo') |
|
| 1171 | - return ssi_whosOnline($output_method); |
|
| 1172 | - else |
|
| 1173 | - ssi_whosOnline($output_method); |
|
| 1174 | -} |
|
| 1236 | + if ($output_method != 'echo') { |
|
| 1237 | + return ssi_whosOnline($output_method); |
|
| 1238 | + } else { |
|
| 1239 | + ssi_whosOnline($output_method); |
|
| 1240 | + } |
|
| 1241 | + } |
|
| 1175 | 1242 | |
| 1176 | 1243 | // Shows a login box. |
| 1177 | 1244 | /** |
@@ -1184,11 +1251,13 @@ discard block |
||
| 1184 | 1251 | { |
| 1185 | 1252 | global $scripturl, $txt, $user_info, $context; |
| 1186 | 1253 | |
| 1187 | - if ($redirect_to != '') |
|
| 1188 | - $_SESSION['login_url'] = $redirect_to; |
|
| 1254 | + if ($redirect_to != '') { |
|
| 1255 | + $_SESSION['login_url'] = $redirect_to; |
|
| 1256 | + } |
|
| 1189 | 1257 | |
| 1190 | - if ($output_method != 'echo' || !$user_info['is_guest']) |
|
| 1191 | - return $user_info['is_guest']; |
|
| 1258 | + if ($output_method != 'echo' || !$user_info['is_guest']) { |
|
| 1259 | + return $user_info['is_guest']; |
|
| 1260 | + } |
|
| 1192 | 1261 | |
| 1193 | 1262 | // Create a login token |
| 1194 | 1263 | createToken('login'); |
@@ -1240,8 +1309,9 @@ discard block |
||
| 1240 | 1309 | |
| 1241 | 1310 | $boardsAllowed = array_intersect(boardsAllowedTo('poll_view'), boardsAllowedTo('poll_vote')); |
| 1242 | 1311 | |
| 1243 | - if (empty($boardsAllowed)) |
|
| 1244 | - return array(); |
|
| 1312 | + if (empty($boardsAllowed)) { |
|
| 1313 | + return array(); |
|
| 1314 | + } |
|
| 1245 | 1315 | |
| 1246 | 1316 | $request = $smcFunc['db_query']('', ' |
| 1247 | 1317 | SELECT p.id_poll, p.question, t.id_topic, p.max_votes, p.guest_vote, p.hide_results, p.expire_time |
@@ -1274,12 +1344,14 @@ discard block |
||
| 1274 | 1344 | $smcFunc['db_free_result']($request); |
| 1275 | 1345 | |
| 1276 | 1346 | // This user has voted on all the polls. |
| 1277 | - if (empty($row) || !is_array($row)) |
|
| 1278 | - return array(); |
|
| 1347 | + if (empty($row) || !is_array($row)) { |
|
| 1348 | + return array(); |
|
| 1349 | + } |
|
| 1279 | 1350 | |
| 1280 | 1351 | // If this is a guest who's voted we'll through ourselves to show poll to show the results. |
| 1281 | - if ($user_info['is_guest'] && (!$row['guest_vote'] || (isset($_COOKIE['guest_poll_vote']) && in_array($row['id_poll'], explode(',', $_COOKIE['guest_poll_vote']))))) |
|
| 1282 | - return ssi_showPoll($row['id_topic'], $output_method); |
|
| 1352 | + if ($user_info['is_guest'] && (!$row['guest_vote'] || (isset($_COOKIE['guest_poll_vote']) && in_array($row['id_poll'], explode(',', $_COOKIE['guest_poll_vote']))))) { |
|
| 1353 | + return ssi_showPoll($row['id_topic'], $output_method); |
|
| 1354 | + } |
|
| 1283 | 1355 | |
| 1284 | 1356 | $request = $smcFunc['db_query']('', ' |
| 1285 | 1357 | SELECT COUNT(DISTINCT id_member) |
@@ -1343,8 +1415,9 @@ discard block |
||
| 1343 | 1415 | // If mods want to do somthing with this list of polls, let them do that now. |
| 1344 | 1416 | call_integration_hook('integrate_ssi_recentPoll', array(&$return, $topPollInstead)); |
| 1345 | 1417 | |
| 1346 | - if ($output_method != 'echo') |
|
| 1347 | - return $return; |
|
| 1418 | + if ($output_method != 'echo') { |
|
| 1419 | + return $return; |
|
| 1420 | + } |
|
| 1348 | 1421 | |
| 1349 | 1422 | if ($allow_view_results) |
| 1350 | 1423 | { |
@@ -1353,19 +1426,20 @@ discard block |
||
| 1353 | 1426 | <strong>', $return['question'], '</strong><br> |
| 1354 | 1427 | ', !empty($return['allowed_warning']) ? $return['allowed_warning'] . '<br>' : ''; |
| 1355 | 1428 | |
| 1356 | - foreach ($return['options'] as $option) |
|
| 1357 | - echo ' |
|
| 1429 | + foreach ($return['options'] as $option) { |
|
| 1430 | + echo ' |
|
| 1358 | 1431 | <label for="', $option['id'], '">', $option['vote_button'], ' ', $option['option'], '</label><br>'; |
| 1432 | + } |
|
| 1359 | 1433 | |
| 1360 | 1434 | echo ' |
| 1361 | 1435 | <input type="submit" value="', $txt['poll_vote'], '" class="button_submit"> |
| 1362 | 1436 | <input type="hidden" name="poll" value="', $return['id'], '"> |
| 1363 | 1437 | <input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '"> |
| 1364 | 1438 | </form>'; |
| 1439 | + } else { |
|
| 1440 | + echo $txt['poll_cannot_see']; |
|
| 1441 | + } |
|
| 1365 | 1442 | } |
| 1366 | - else |
|
| 1367 | - echo $txt['poll_cannot_see']; |
|
| 1368 | -} |
|
| 1369 | 1443 | |
| 1370 | 1444 | /** |
| 1371 | 1445 | * Shows the poll from the specified topic |
@@ -1379,13 +1453,15 @@ discard block |
||
| 1379 | 1453 | |
| 1380 | 1454 | $boardsAllowed = boardsAllowedTo('poll_view'); |
| 1381 | 1455 | |
| 1382 | - if (empty($boardsAllowed)) |
|
| 1383 | - return array(); |
|
| 1456 | + if (empty($boardsAllowed)) { |
|
| 1457 | + return array(); |
|
| 1458 | + } |
|
| 1384 | 1459 | |
| 1385 | - if ($topic === null && isset($_REQUEST['ssi_topic'])) |
|
| 1386 | - $topic = (int) $_REQUEST['ssi_topic']; |
|
| 1387 | - else |
|
| 1388 | - $topic = (int) $topic; |
|
| 1460 | + if ($topic === null && isset($_REQUEST['ssi_topic'])) { |
|
| 1461 | + $topic = (int) $_REQUEST['ssi_topic']; |
|
| 1462 | + } else { |
|
| 1463 | + $topic = (int) $topic; |
|
| 1464 | + } |
|
| 1389 | 1465 | |
| 1390 | 1466 | $request = $smcFunc['db_query']('', ' |
| 1391 | 1467 | SELECT |
@@ -1406,17 +1482,18 @@ discard block |
||
| 1406 | 1482 | ); |
| 1407 | 1483 | |
| 1408 | 1484 | // Either this topic has no poll, or the user cannot view it. |
| 1409 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 1410 | - return array(); |
|
| 1485 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 1486 | + return array(); |
|
| 1487 | + } |
|
| 1411 | 1488 | |
| 1412 | 1489 | $row = $smcFunc['db_fetch_assoc']($request); |
| 1413 | 1490 | $smcFunc['db_free_result']($request); |
| 1414 | 1491 | |
| 1415 | 1492 | // Check if they can vote. |
| 1416 | 1493 | $already_voted = false; |
| 1417 | - if (!empty($row['expire_time']) && $row['expire_time'] < time()) |
|
| 1418 | - $allow_vote = false; |
|
| 1419 | - elseif ($user_info['is_guest']) |
|
| 1494 | + if (!empty($row['expire_time']) && $row['expire_time'] < time()) { |
|
| 1495 | + $allow_vote = false; |
|
| 1496 | + } elseif ($user_info['is_guest']) |
|
| 1420 | 1497 | { |
| 1421 | 1498 | // There's a difference between "allowed to vote" and "already voted"... |
| 1422 | 1499 | $allow_vote = $row['guest_vote']; |
@@ -1426,10 +1503,9 @@ discard block |
||
| 1426 | 1503 | { |
| 1427 | 1504 | $already_voted = true; |
| 1428 | 1505 | } |
| 1429 | - } |
|
| 1430 | - elseif (!empty($row['voting_locked']) || !allowedTo('poll_vote', $row['id_board'])) |
|
| 1431 | - $allow_vote = false; |
|
| 1432 | - else |
|
| 1506 | + } elseif (!empty($row['voting_locked']) || !allowedTo('poll_vote', $row['id_board'])) { |
|
| 1507 | + $allow_vote = false; |
|
| 1508 | + } else |
|
| 1433 | 1509 | { |
| 1434 | 1510 | $request = $smcFunc['db_query']('', ' |
| 1435 | 1511 | SELECT id_member |
@@ -1511,8 +1587,9 @@ discard block |
||
| 1511 | 1587 | // If mods want to do somthing with this poll, let them do that now. |
| 1512 | 1588 | call_integration_hook('integrate_ssi_showPoll', array(&$return)); |
| 1513 | 1589 | |
| 1514 | - if ($output_method != 'echo') |
|
| 1515 | - return $return; |
|
| 1590 | + if ($output_method != 'echo') { |
|
| 1591 | + return $return; |
|
| 1592 | + } |
|
| 1516 | 1593 | |
| 1517 | 1594 | if ($return['allow_vote']) |
| 1518 | 1595 | { |
@@ -1521,17 +1598,17 @@ discard block |
||
| 1521 | 1598 | <strong>', $return['question'], '</strong><br> |
| 1522 | 1599 | ', !empty($return['allowed_warning']) ? $return['allowed_warning'] . '<br>' : ''; |
| 1523 | 1600 | |
| 1524 | - foreach ($return['options'] as $option) |
|
| 1525 | - echo ' |
|
| 1601 | + foreach ($return['options'] as $option) { |
|
| 1602 | + echo ' |
|
| 1526 | 1603 | <label for="', $option['id'], '">', $option['vote_button'], ' ', $option['option'], '</label><br>'; |
| 1604 | + } |
|
| 1527 | 1605 | |
| 1528 | 1606 | echo ' |
| 1529 | 1607 | <input type="submit" value="', $txt['poll_vote'], '" class="button_submit"> |
| 1530 | 1608 | <input type="hidden" name="poll" value="', $return['id'], '"> |
| 1531 | 1609 | <input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '"> |
| 1532 | 1610 | </form>'; |
| 1533 | - } |
|
| 1534 | - else |
|
| 1611 | + } else |
|
| 1535 | 1612 | { |
| 1536 | 1613 | echo ' |
| 1537 | 1614 | <div class="ssi_poll"> |
@@ -1611,27 +1688,32 @@ discard block |
||
| 1611 | 1688 | 'is_approved' => 1, |
| 1612 | 1689 | ) |
| 1613 | 1690 | ); |
| 1614 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 1615 | - die; |
|
| 1691 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 1692 | + die; |
|
| 1693 | + } |
|
| 1616 | 1694 | $row = $smcFunc['db_fetch_assoc']($request); |
| 1617 | 1695 | $smcFunc['db_free_result']($request); |
| 1618 | 1696 | |
| 1619 | - if (!empty($row['voting_locked']) || ($row['selected'] != -1 && !$user_info['is_guest']) || (!empty($row['expire_time']) && time() > $row['expire_time'])) |
|
| 1620 | - redirectexit('topic=' . $row['id_topic'] . '.0'); |
|
| 1697 | + if (!empty($row['voting_locked']) || ($row['selected'] != -1 && !$user_info['is_guest']) || (!empty($row['expire_time']) && time() > $row['expire_time'])) { |
|
| 1698 | + redirectexit('topic=' . $row['id_topic'] . '.0'); |
|
| 1699 | + } |
|
| 1621 | 1700 | |
| 1622 | 1701 | // Too many options checked? |
| 1623 | - if (count($_REQUEST['options']) > $row['max_votes']) |
|
| 1624 | - redirectexit('topic=' . $row['id_topic'] . '.0'); |
|
| 1702 | + if (count($_REQUEST['options']) > $row['max_votes']) { |
|
| 1703 | + redirectexit('topic=' . $row['id_topic'] . '.0'); |
|
| 1704 | + } |
|
| 1625 | 1705 | |
| 1626 | 1706 | // It's a guest who has already voted? |
| 1627 | 1707 | if ($user_info['is_guest']) |
| 1628 | 1708 | { |
| 1629 | 1709 | // Guest voting disabled? |
| 1630 | - if (!$row['guest_vote']) |
|
| 1631 | - redirectexit('topic=' . $row['id_topic'] . '.0'); |
|
| 1710 | + if (!$row['guest_vote']) { |
|
| 1711 | + redirectexit('topic=' . $row['id_topic'] . '.0'); |
|
| 1712 | + } |
|
| 1632 | 1713 | // Already voted? |
| 1633 | - elseif (isset($_COOKIE['guest_poll_vote']) && in_array($row['id_poll'], explode(',', $_COOKIE['guest_poll_vote']))) |
|
| 1634 | - redirectexit('topic=' . $row['id_topic'] . '.0'); |
|
| 1714 | + elseif (isset($_COOKIE['guest_poll_vote']) && in_array($row['id_poll'], explode(',', $_COOKIE['guest_poll_vote']))) { |
|
| 1715 | + redirectexit('topic=' . $row['id_topic'] . '.0'); |
|
| 1716 | + } |
|
| 1635 | 1717 | } |
| 1636 | 1718 | |
| 1637 | 1719 | $sOptions = array(); |
@@ -1685,11 +1767,13 @@ discard block |
||
| 1685 | 1767 | { |
| 1686 | 1768 | global $scripturl, $txt, $context; |
| 1687 | 1769 | |
| 1688 | - if (!allowedTo('search_posts')) |
|
| 1689 | - return; |
|
| 1770 | + if (!allowedTo('search_posts')) { |
|
| 1771 | + return; |
|
| 1772 | + } |
|
| 1690 | 1773 | |
| 1691 | - if ($output_method != 'echo') |
|
| 1692 | - return $scripturl . '?action=search'; |
|
| 1774 | + if ($output_method != 'echo') { |
|
| 1775 | + return $scripturl . '?action=search'; |
|
| 1776 | + } |
|
| 1693 | 1777 | |
| 1694 | 1778 | echo ' |
| 1695 | 1779 | <form action="', $scripturl, '?action=search2" method="post" accept-charset="', $context['character_set'], '"> |
@@ -1711,8 +1795,9 @@ discard block |
||
| 1711 | 1795 | // If mods want to do somthing with the news, let them do that now. Don't need to pass the news line itself, since it is already in $context. |
| 1712 | 1796 | call_integration_hook('integrate_ssi_news'); |
| 1713 | 1797 | |
| 1714 | - if ($output_method != 'echo') |
|
| 1715 | - return $context['random_news_line']; |
|
| 1798 | + if ($output_method != 'echo') { |
|
| 1799 | + return $context['random_news_line']; |
|
| 1800 | + } |
|
| 1716 | 1801 | |
| 1717 | 1802 | echo $context['random_news_line']; |
| 1718 | 1803 | } |
@@ -1726,8 +1811,9 @@ discard block |
||
| 1726 | 1811 | { |
| 1727 | 1812 | global $scripturl, $modSettings, $user_info; |
| 1728 | 1813 | |
| 1729 | - if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view') || !allowedTo('profile_view')) |
|
| 1730 | - return; |
|
| 1814 | + if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view') || !allowedTo('profile_view')) { |
|
| 1815 | + return; |
|
| 1816 | + } |
|
| 1731 | 1817 | |
| 1732 | 1818 | $eventOptions = array( |
| 1733 | 1819 | 'include_birthdays' => true, |
@@ -1738,13 +1824,15 @@ discard block |
||
| 1738 | 1824 | // The ssi_todaysCalendar variants all use the same hook and just pass on $eventOptions so the hooked code can distinguish different cases if necessary |
| 1739 | 1825 | call_integration_hook('integrate_ssi_calendar', array(&$return, $eventOptions)); |
| 1740 | 1826 | |
| 1741 | - if ($output_method != 'echo') |
|
| 1742 | - return $return['calendar_birthdays']; |
|
| 1827 | + if ($output_method != 'echo') { |
|
| 1828 | + return $return['calendar_birthdays']; |
|
| 1829 | + } |
|
| 1743 | 1830 | |
| 1744 | - foreach ($return['calendar_birthdays'] as $member) |
|
| 1745 | - echo ' |
|
| 1831 | + foreach ($return['calendar_birthdays'] as $member) { |
|
| 1832 | + echo ' |
|
| 1746 | 1833 | <a href="', $scripturl, '?action=profile;u=', $member['id'], '"><span class="fix_rtl_names">' . $member['name'] . '</span>' . (isset($member['age']) ? ' (' . $member['age'] . ')' : '') . '</a>' . (!$member['is_last'] ? ', ' : ''); |
| 1747 | -} |
|
| 1834 | + } |
|
| 1835 | + } |
|
| 1748 | 1836 | |
| 1749 | 1837 | /** |
| 1750 | 1838 | * Shows today's holidays. |
@@ -1755,8 +1843,9 @@ discard block |
||
| 1755 | 1843 | { |
| 1756 | 1844 | global $modSettings, $user_info; |
| 1757 | 1845 | |
| 1758 | - if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view')) |
|
| 1759 | - return; |
|
| 1846 | + if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view')) { |
|
| 1847 | + return; |
|
| 1848 | + } |
|
| 1760 | 1849 | |
| 1761 | 1850 | $eventOptions = array( |
| 1762 | 1851 | 'include_holidays' => true, |
@@ -1767,8 +1856,9 @@ discard block |
||
| 1767 | 1856 | // The ssi_todaysCalendar variants all use the same hook and just pass on $eventOptions so the hooked code can distinguish different cases if necessary |
| 1768 | 1857 | call_integration_hook('integrate_ssi_calendar', array(&$return, $eventOptions)); |
| 1769 | 1858 | |
| 1770 | - if ($output_method != 'echo') |
|
| 1771 | - return $return['calendar_holidays']; |
|
| 1859 | + if ($output_method != 'echo') { |
|
| 1860 | + return $return['calendar_holidays']; |
|
| 1861 | + } |
|
| 1772 | 1862 | |
| 1773 | 1863 | echo ' |
| 1774 | 1864 | ', implode(', ', $return['calendar_holidays']); |
@@ -1782,8 +1872,9 @@ discard block |
||
| 1782 | 1872 | { |
| 1783 | 1873 | global $modSettings, $user_info; |
| 1784 | 1874 | |
| 1785 | - if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view')) |
|
| 1786 | - return; |
|
| 1875 | + if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view')) { |
|
| 1876 | + return; |
|
| 1877 | + } |
|
| 1787 | 1878 | |
| 1788 | 1879 | $eventOptions = array( |
| 1789 | 1880 | 'include_events' => true, |
@@ -1794,14 +1885,16 @@ discard block |
||
| 1794 | 1885 | // The ssi_todaysCalendar variants all use the same hook and just pass on $eventOptions so the hooked code can distinguish different cases if necessary |
| 1795 | 1886 | call_integration_hook('integrate_ssi_calendar', array(&$return, $eventOptions)); |
| 1796 | 1887 | |
| 1797 | - if ($output_method != 'echo') |
|
| 1798 | - return $return['calendar_events']; |
|
| 1888 | + if ($output_method != 'echo') { |
|
| 1889 | + return $return['calendar_events']; |
|
| 1890 | + } |
|
| 1799 | 1891 | |
| 1800 | 1892 | foreach ($return['calendar_events'] as $event) |
| 1801 | 1893 | { |
| 1802 | - if ($event['can_edit']) |
|
| 1803 | - echo ' |
|
| 1894 | + if ($event['can_edit']) { |
|
| 1895 | + echo ' |
|
| 1804 | 1896 | <a href="' . $event['modify_href'] . '" style="color: #ff0000;">*</a> '; |
| 1897 | + } |
|
| 1805 | 1898 | echo ' |
| 1806 | 1899 | ' . $event['link'] . (!$event['is_last'] ? ', ' : ''); |
| 1807 | 1900 | } |
@@ -1816,8 +1909,9 @@ discard block |
||
| 1816 | 1909 | { |
| 1817 | 1910 | global $modSettings, $txt, $scripturl, $user_info; |
| 1818 | 1911 | |
| 1819 | - if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view')) |
|
| 1820 | - return; |
|
| 1912 | + if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view')) { |
|
| 1913 | + return; |
|
| 1914 | + } |
|
| 1821 | 1915 | |
| 1822 | 1916 | $eventOptions = array( |
| 1823 | 1917 | 'include_birthdays' => allowedTo('profile_view'), |
@@ -1830,19 +1924,22 @@ discard block |
||
| 1830 | 1924 | // The ssi_todaysCalendar variants all use the same hook and just pass on $eventOptions so the hooked code can distinguish different cases if necessary |
| 1831 | 1925 | call_integration_hook('integrate_ssi_calendar', array(&$return, $eventOptions)); |
| 1832 | 1926 | |
| 1833 | - if ($output_method != 'echo') |
|
| 1834 | - return $return; |
|
| 1927 | + if ($output_method != 'echo') { |
|
| 1928 | + return $return; |
|
| 1929 | + } |
|
| 1835 | 1930 | |
| 1836 | - if (!empty($return['calendar_holidays'])) |
|
| 1837 | - echo ' |
|
| 1931 | + if (!empty($return['calendar_holidays'])) { |
|
| 1932 | + echo ' |
|
| 1838 | 1933 | <span class="holiday">' . $txt['calendar_prompt'] . ' ' . implode(', ', $return['calendar_holidays']) . '<br></span>'; |
| 1934 | + } |
|
| 1839 | 1935 | if (!empty($return['calendar_birthdays'])) |
| 1840 | 1936 | { |
| 1841 | 1937 | echo ' |
| 1842 | 1938 | <span class="birthday">' . $txt['birthdays_upcoming'] . '</span> '; |
| 1843 | - foreach ($return['calendar_birthdays'] as $member) |
|
| 1844 | - echo ' |
|
| 1939 | + foreach ($return['calendar_birthdays'] as $member) { |
|
| 1940 | + echo ' |
|
| 1845 | 1941 | <a href="', $scripturl, '?action=profile;u=', $member['id'], '"><span class="fix_rtl_names">', $member['name'], '</span>', isset($member['age']) ? ' (' . $member['age'] . ')' : '', '</a>', !$member['is_last'] ? ', ' : ''; |
| 1942 | + } |
|
| 1846 | 1943 | echo ' |
| 1847 | 1944 | <br>'; |
| 1848 | 1945 | } |
@@ -1852,9 +1949,10 @@ discard block |
||
| 1852 | 1949 | <span class="event">' . $txt['events_upcoming'] . '</span> '; |
| 1853 | 1950 | foreach ($return['calendar_events'] as $event) |
| 1854 | 1951 | { |
| 1855 | - if ($event['can_edit']) |
|
| 1856 | - echo ' |
|
| 1952 | + if ($event['can_edit']) { |
|
| 1953 | + echo ' |
|
| 1857 | 1954 | <a href="' . $event['modify_href'] . '" style="color: #ff0000;">*</a> '; |
| 1955 | + } |
|
| 1858 | 1956 | echo ' |
| 1859 | 1957 | ' . $event['link'] . (!$event['is_last'] ? ', ' : ''); |
| 1860 | 1958 | } |
@@ -1878,25 +1976,29 @@ discard block |
||
| 1878 | 1976 | loadLanguage('Stats'); |
| 1879 | 1977 | |
| 1880 | 1978 | // Must be integers.... |
| 1881 | - if ($limit === null) |
|
| 1882 | - $limit = isset($_GET['limit']) ? (int) $_GET['limit'] : 5; |
|
| 1883 | - else |
|
| 1884 | - $limit = (int) $limit; |
|
| 1885 | - |
|
| 1886 | - if ($start === null) |
|
| 1887 | - $start = isset($_GET['start']) ? (int) $_GET['start'] : 0; |
|
| 1888 | - else |
|
| 1889 | - $start = (int) $start; |
|
| 1890 | - |
|
| 1891 | - if ($board !== null) |
|
| 1892 | - $board = (int) $board; |
|
| 1893 | - elseif (isset($_GET['board'])) |
|
| 1894 | - $board = (int) $_GET['board']; |
|
| 1895 | - |
|
| 1896 | - if ($length === null) |
|
| 1897 | - $length = isset($_GET['length']) ? (int) $_GET['length'] : 0; |
|
| 1898 | - else |
|
| 1899 | - $length = (int) $length; |
|
| 1979 | + if ($limit === null) { |
|
| 1980 | + $limit = isset($_GET['limit']) ? (int) $_GET['limit'] : 5; |
|
| 1981 | + } else { |
|
| 1982 | + $limit = (int) $limit; |
|
| 1983 | + } |
|
| 1984 | + |
|
| 1985 | + if ($start === null) { |
|
| 1986 | + $start = isset($_GET['start']) ? (int) $_GET['start'] : 0; |
|
| 1987 | + } else { |
|
| 1988 | + $start = (int) $start; |
|
| 1989 | + } |
|
| 1990 | + |
|
| 1991 | + if ($board !== null) { |
|
| 1992 | + $board = (int) $board; |
|
| 1993 | + } elseif (isset($_GET['board'])) { |
|
| 1994 | + $board = (int) $_GET['board']; |
|
| 1995 | + } |
|
| 1996 | + |
|
| 1997 | + if ($length === null) { |
|
| 1998 | + $length = isset($_GET['length']) ? (int) $_GET['length'] : 0; |
|
| 1999 | + } else { |
|
| 2000 | + $length = (int) $length; |
|
| 2001 | + } |
|
| 1900 | 2002 | |
| 1901 | 2003 | $limit = max(0, $limit); |
| 1902 | 2004 | $start = max(0, $start); |
@@ -1914,17 +2016,19 @@ discard block |
||
| 1914 | 2016 | ); |
| 1915 | 2017 | if ($smcFunc['db_num_rows']($request) == 0) |
| 1916 | 2018 | { |
| 1917 | - if ($output_method == 'echo') |
|
| 1918 | - die($txt['ssi_no_guests']); |
|
| 1919 | - else |
|
| 1920 | - return array(); |
|
| 2019 | + if ($output_method == 'echo') { |
|
| 2020 | + die($txt['ssi_no_guests']); |
|
| 2021 | + } else { |
|
| 2022 | + return array(); |
|
| 2023 | + } |
|
| 1921 | 2024 | } |
| 1922 | 2025 | list ($board) = $smcFunc['db_fetch_row']($request); |
| 1923 | 2026 | $smcFunc['db_free_result']($request); |
| 1924 | 2027 | |
| 1925 | 2028 | $icon_sources = array(); |
| 1926 | - foreach ($context['stable_icons'] as $icon) |
|
| 1927 | - $icon_sources[$icon] = 'images_url'; |
|
| 2029 | + foreach ($context['stable_icons'] as $icon) { |
|
| 2030 | + $icon_sources[$icon] = 'images_url'; |
|
| 2031 | + } |
|
| 1928 | 2032 | |
| 1929 | 2033 | if (!empty($modSettings['enable_likes'])) |
| 1930 | 2034 | { |
@@ -1948,12 +2052,14 @@ discard block |
||
| 1948 | 2052 | ) |
| 1949 | 2053 | ); |
| 1950 | 2054 | $posts = array(); |
| 1951 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1952 | - $posts[] = $row['id_first_msg']; |
|
| 2055 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 2056 | + $posts[] = $row['id_first_msg']; |
|
| 2057 | + } |
|
| 1953 | 2058 | $smcFunc['db_free_result']($request); |
| 1954 | 2059 | |
| 1955 | - if (empty($posts)) |
|
| 1956 | - return array(); |
|
| 2060 | + if (empty($posts)) { |
|
| 2061 | + return array(); |
|
| 2062 | + } |
|
| 1957 | 2063 | |
| 1958 | 2064 | // Find the posts. |
| 1959 | 2065 | $request = $smcFunc['db_query']('', ' |
@@ -1983,24 +2089,28 @@ discard block |
||
| 1983 | 2089 | $last_space = strrpos($row['body'], ' '); |
| 1984 | 2090 | $last_open = strrpos($row['body'], '<'); |
| 1985 | 2091 | $last_close = strrpos($row['body'], '>'); |
| 1986 | - if (empty($last_space) || ($last_space == $last_open + 3 && (empty($last_close) || (!empty($last_close) && $last_close < $last_open))) || $last_space < $last_open || $last_open == $length - 6) |
|
| 1987 | - $cutoff = $last_open; |
|
| 1988 | - elseif (empty($last_close) || $last_close < $last_open) |
|
| 1989 | - $cutoff = $last_space; |
|
| 2092 | + if (empty($last_space) || ($last_space == $last_open + 3 && (empty($last_close) || (!empty($last_close) && $last_close < $last_open))) || $last_space < $last_open || $last_open == $length - 6) { |
|
| 2093 | + $cutoff = $last_open; |
|
| 2094 | + } elseif (empty($last_close) || $last_close < $last_open) { |
|
| 2095 | + $cutoff = $last_space; |
|
| 2096 | + } |
|
| 1990 | 2097 | |
| 1991 | - if ($cutoff !== false) |
|
| 1992 | - $row['body'] = $smcFunc['substr']($row['body'], 0, $cutoff); |
|
| 2098 | + if ($cutoff !== false) { |
|
| 2099 | + $row['body'] = $smcFunc['substr']($row['body'], 0, $cutoff); |
|
| 2100 | + } |
|
| 1993 | 2101 | $row['body'] .= '...'; |
| 1994 | 2102 | } |
| 1995 | 2103 | |
| 1996 | 2104 | $row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']); |
| 1997 | 2105 | |
| 1998 | - if (!empty($recycle_board) && $row['id_board'] == $recycle_board) |
|
| 1999 | - $row['icon'] = 'recycled'; |
|
| 2106 | + if (!empty($recycle_board) && $row['id_board'] == $recycle_board) { |
|
| 2107 | + $row['icon'] = 'recycled'; |
|
| 2108 | + } |
|
| 2000 | 2109 | |
| 2001 | 2110 | // Check that this message icon is there... |
| 2002 | - if (!empty($modSettings['messageIconChecks_enable']) && !isset($icon_sources[$row['icon']])) |
|
| 2003 | - $icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
| 2111 | + if (!empty($modSettings['messageIconChecks_enable']) && !isset($icon_sources[$row['icon']])) { |
|
| 2112 | + $icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
| 2113 | + } |
|
| 2004 | 2114 | |
| 2005 | 2115 | censorText($row['subject']); |
| 2006 | 2116 | censorText($row['body']); |
@@ -2037,16 +2147,18 @@ discard block |
||
| 2037 | 2147 | } |
| 2038 | 2148 | $smcFunc['db_free_result']($request); |
| 2039 | 2149 | |
| 2040 | - if (empty($return)) |
|
| 2041 | - return $return; |
|
| 2150 | + if (empty($return)) { |
|
| 2151 | + return $return; |
|
| 2152 | + } |
|
| 2042 | 2153 | |
| 2043 | 2154 | $return[count($return) - 1]['is_last'] = true; |
| 2044 | 2155 | |
| 2045 | 2156 | // If mods want to do somthing with this list of posts, let them do that now. |
| 2046 | 2157 | call_integration_hook('integrate_ssi_boardNews', array(&$return)); |
| 2047 | 2158 | |
| 2048 | - if ($output_method != 'echo') |
|
| 2049 | - return $return; |
|
| 2159 | + if ($output_method != 'echo') { |
|
| 2160 | + return $return; |
|
| 2161 | + } |
|
| 2050 | 2162 | |
| 2051 | 2163 | foreach ($return as $news) |
| 2052 | 2164 | { |
@@ -2098,9 +2210,10 @@ discard block |
||
| 2098 | 2210 | echo ' |
| 2099 | 2211 | </div>'; |
| 2100 | 2212 | |
| 2101 | - if (!$news['is_last']) |
|
| 2102 | - echo ' |
|
| 2213 | + if (!$news['is_last']) { |
|
| 2214 | + echo ' |
|
| 2103 | 2215 | <hr>'; |
| 2216 | + } |
|
| 2104 | 2217 | } |
| 2105 | 2218 | } |
| 2106 | 2219 | |
@@ -2114,8 +2227,9 @@ discard block |
||
| 2114 | 2227 | { |
| 2115 | 2228 | global $user_info, $scripturl, $modSettings, $txt, $context, $smcFunc; |
| 2116 | 2229 | |
| 2117 | - if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view')) |
|
| 2118 | - return; |
|
| 2230 | + if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view')) { |
|
| 2231 | + return; |
|
| 2232 | + } |
|
| 2119 | 2233 | |
| 2120 | 2234 | // Find all events which are happening in the near future that the member can see. |
| 2121 | 2235 | $request = $smcFunc['db_query']('', ' |
@@ -2141,20 +2255,23 @@ discard block |
||
| 2141 | 2255 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 2142 | 2256 | { |
| 2143 | 2257 | // Check if we've already come by an event linked to this same topic with the same title... and don't display it if we have. |
| 2144 | - if (!empty($duplicates[$row['title'] . $row['id_topic']])) |
|
| 2145 | - continue; |
|
| 2258 | + if (!empty($duplicates[$row['title'] . $row['id_topic']])) { |
|
| 2259 | + continue; |
|
| 2260 | + } |
|
| 2146 | 2261 | |
| 2147 | 2262 | // Censor the title. |
| 2148 | 2263 | censorText($row['title']); |
| 2149 | 2264 | |
| 2150 | - if ($row['start_date'] < strftime('%Y-%m-%d', forum_time(false))) |
|
| 2151 | - $date = strftime('%Y-%m-%d', forum_time(false)); |
|
| 2152 | - else |
|
| 2153 | - $date = $row['start_date']; |
|
| 2265 | + if ($row['start_date'] < strftime('%Y-%m-%d', forum_time(false))) { |
|
| 2266 | + $date = strftime('%Y-%m-%d', forum_time(false)); |
|
| 2267 | + } else { |
|
| 2268 | + $date = $row['start_date']; |
|
| 2269 | + } |
|
| 2154 | 2270 | |
| 2155 | 2271 | // If the topic it is attached to is not approved then don't link it. |
| 2156 | - if (!empty($row['id_first_msg']) && !$row['approved']) |
|
| 2157 | - $row['id_board'] = $row['id_topic'] = $row['id_first_msg'] = 0; |
|
| 2272 | + if (!empty($row['id_first_msg']) && !$row['approved']) { |
|
| 2273 | + $row['id_board'] = $row['id_topic'] = $row['id_first_msg'] = 0; |
|
| 2274 | + } |
|
| 2158 | 2275 | |
| 2159 | 2276 | $allday = (empty($row['start_time']) || empty($row['end_time']) || empty($row['timezone']) || !in_array($row['timezone'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) ? true : false; |
| 2160 | 2277 | |
@@ -2180,24 +2297,27 @@ discard block |
||
| 2180 | 2297 | } |
| 2181 | 2298 | $smcFunc['db_free_result']($request); |
| 2182 | 2299 | |
| 2183 | - foreach ($return as $mday => $array) |
|
| 2184 | - $return[$mday][count($array) - 1]['is_last'] = true; |
|
| 2300 | + foreach ($return as $mday => $array) { |
|
| 2301 | + $return[$mday][count($array) - 1]['is_last'] = true; |
|
| 2302 | + } |
|
| 2185 | 2303 | |
| 2186 | 2304 | // If mods want to do somthing with this list of events, let them do that now. |
| 2187 | 2305 | call_integration_hook('integrate_ssi_recentEvents', array(&$return)); |
| 2188 | 2306 | |
| 2189 | - if ($output_method != 'echo' || empty($return)) |
|
| 2190 | - return $return; |
|
| 2307 | + if ($output_method != 'echo' || empty($return)) { |
|
| 2308 | + return $return; |
|
| 2309 | + } |
|
| 2191 | 2310 | |
| 2192 | 2311 | // Well the output method is echo. |
| 2193 | 2312 | echo ' |
| 2194 | 2313 | <span class="event">' . $txt['events'] . '</span> '; |
| 2195 | - foreach ($return as $mday => $array) |
|
| 2196 | - foreach ($array as $event) |
|
| 2314 | + foreach ($return as $mday => $array) { |
|
| 2315 | + foreach ($array as $event) |
|
| 2197 | 2316 | { |
| 2198 | 2317 | if ($event['can_edit']) |
| 2199 | 2318 | echo ' |
| 2200 | 2319 | <a href="' . $event['modify_href'] . '" style="color: #ff0000;">*</a> '; |
| 2320 | + } |
|
| 2201 | 2321 | |
| 2202 | 2322 | echo ' |
| 2203 | 2323 | ' . $event['link'] . (!$event['is_last'] ? ', ' : ''); |
@@ -2216,8 +2336,9 @@ discard block |
||
| 2216 | 2336 | global $smcFunc; |
| 2217 | 2337 | |
| 2218 | 2338 | // If $id is null, this was most likely called from a query string and should do nothing. |
| 2219 | - if ($id === null) |
|
| 2220 | - return; |
|
| 2339 | + if ($id === null) { |
|
| 2340 | + return; |
|
| 2341 | + } |
|
| 2221 | 2342 | |
| 2222 | 2343 | $request = $smcFunc['db_query']('', ' |
| 2223 | 2344 | SELECT passwd, member_name, is_activated |
@@ -2249,8 +2370,9 @@ discard block |
||
| 2249 | 2370 | $attachments_boards = boardsAllowedTo('view_attachments'); |
| 2250 | 2371 | |
| 2251 | 2372 | // No boards? Adios amigo. |
| 2252 | - if (empty($attachments_boards)) |
|
| 2253 | - return array(); |
|
| 2373 | + if (empty($attachments_boards)) { |
|
| 2374 | + return array(); |
|
| 2375 | + } |
|
| 2254 | 2376 | |
| 2255 | 2377 | // Is it an array? |
| 2256 | 2378 | $attachment_ext = (array) $attachment_ext; |
@@ -2334,8 +2456,9 @@ discard block |
||
| 2334 | 2456 | call_integration_hook('integrate_ssi_recentAttachments', array(&$attachments)); |
| 2335 | 2457 | |
| 2336 | 2458 | // So you just want an array? Here you can have it. |
| 2337 | - if ($output_method == 'array' || empty($attachments)) |
|
| 2338 | - return $attachments; |
|
| 2459 | + if ($output_method == 'array' || empty($attachments)) { |
|
| 2460 | + return $attachments; |
|
| 2461 | + } |
|
| 2339 | 2462 | |
| 2340 | 2463 | // Give them the default. |
| 2341 | 2464 | echo ' |
@@ -2346,14 +2469,15 @@ discard block |
||
| 2346 | 2469 | <th style="text-align: left; padding: 2">', $txt['downloads'], '</th> |
| 2347 | 2470 | <th style="text-align: left; padding: 2">', $txt['filesize'], '</th> |
| 2348 | 2471 | </tr>'; |
| 2349 | - foreach ($attachments as $attach) |
|
| 2350 | - echo ' |
|
| 2472 | + foreach ($attachments as $attach) { |
|
| 2473 | + echo ' |
|
| 2351 | 2474 | <tr> |
| 2352 | 2475 | <td>', $attach['file']['link'], '</td> |
| 2353 | 2476 | <td>', $attach['member']['link'], '</td> |
| 2354 | 2477 | <td style="text-align: center">', $attach['file']['downloads'], '</td> |
| 2355 | 2478 | <td>', $attach['file']['filesize'], '</td> |
| 2356 | 2479 | </tr>'; |
| 2480 | + } |
|
| 2357 | 2481 | echo ' |
| 2358 | 2482 | </table>'; |
| 2359 | 2483 | } |
@@ -14,8 +14,9 @@ discard block |
||
| 14 | 14 | * @version 2.1 Beta 3 |
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | -if (!defined('SMF')) |
|
| 17 | +if (!defined('SMF')) { |
|
| 18 | 18 | die('No direct access...'); |
| 19 | +} |
|
| 19 | 20 | |
| 20 | 21 | /** |
| 21 | 22 | * !!!Compatibility!!! |
@@ -30,8 +31,9 @@ discard block |
||
| 30 | 31 | { |
| 31 | 32 | global $modSettings; |
| 32 | 33 | |
| 33 | - if (!$compat_mode) |
|
| 34 | - return $text; |
|
| 34 | + if (!$compat_mode) { |
|
| 35 | + return $text; |
|
| 36 | + } |
|
| 35 | 37 | |
| 36 | 38 | // Turn line breaks back into br's. |
| 37 | 39 | $text = strtr($text, array("\r" => '', "\n" => '<br>')); |
@@ -48,8 +50,9 @@ discard block |
||
| 48 | 50 | for ($i = 0, $n = count($parts); $i < $n; $i++) |
| 49 | 51 | { |
| 50 | 52 | // Value of 2 means we're inside the tag. |
| 51 | - if ($i % 4 == 2) |
|
| 52 | - $parts[$i] = strtr($parts[$i], array('[' => '[', ']' => ']', "'" => "'")); |
|
| 53 | + if ($i % 4 == 2) { |
|
| 54 | + $parts[$i] = strtr($parts[$i], array('[' => '[', ']' => ']', "'" => "'")); |
|
| 55 | + } |
|
| 53 | 56 | } |
| 54 | 57 | // Put our humpty dumpty message back together again. |
| 55 | 58 | $text = implode('', $parts); |
@@ -107,8 +110,9 @@ discard block |
||
| 107 | 110 | $text = preg_replace('~</p>\s*(?!<)~i', '</p><br>', $text); |
| 108 | 111 | |
| 109 | 112 | // Safari/webkit wraps lines in Wysiwyg in <div>'s. |
| 110 | - if (isBrowser('webkit')) |
|
| 111 | - $text = preg_replace(array('~<div(?:\s(?:[^<>]*?))?' . '>~i', '</div>'), array('<br>', ''), $text); |
|
| 113 | + if (isBrowser('webkit')) { |
|
| 114 | + $text = preg_replace(array('~<div(?:\s(?:[^<>]*?))?' . '>~i', '</div>'), array('<br>', ''), $text); |
|
| 115 | + } |
|
| 112 | 116 | |
| 113 | 117 | // If there's a trailing break get rid of it - Firefox tends to add one. |
| 114 | 118 | $text = preg_replace('~<br\s?/?' . '>$~i', '', $text); |
@@ -123,8 +127,9 @@ discard block |
||
| 123 | 127 | for ($i = 0, $n = count($parts); $i < $n; $i++) |
| 124 | 128 | { |
| 125 | 129 | // Value of 2 means we're inside the tag. |
| 126 | - if ($i % 4 == 2) |
|
| 127 | - $parts[$i] = strip_tags($parts[$i]); |
|
| 130 | + if ($i % 4 == 2) { |
|
| 131 | + $parts[$i] = strip_tags($parts[$i]); |
|
| 132 | + } |
|
| 128 | 133 | } |
| 129 | 134 | |
| 130 | 135 | $text = strtr(implode('', $parts), array('#smf_br_spec_grudge_cool!#' => '<br>')); |
@@ -150,18 +155,19 @@ discard block |
||
| 150 | 155 | { |
| 151 | 156 | $found = array_search($file, $smileysto); |
| 152 | 157 | // Note the weirdness here is to stop double spaces between smileys. |
| 153 | - if ($found) |
|
| 154 | - $matches[1][$k] = '-[]-smf_smily_start#|#' . $smcFunc['htmlspecialchars']($smileysfrom[$found]) . '-[]-smf_smily_end#|#'; |
|
| 155 | - else |
|
| 156 | - $matches[1][$k] = ''; |
|
| 158 | + if ($found) { |
|
| 159 | + $matches[1][$k] = '-[]-smf_smily_start#|#' . $smcFunc['htmlspecialchars']($smileysfrom[$found]) . '-[]-smf_smily_end#|#'; |
|
| 160 | + } else { |
|
| 161 | + $matches[1][$k] = ''; |
|
| 162 | + } |
|
| 157 | 163 | } |
| 158 | - } |
|
| 159 | - else |
|
| 164 | + } else |
|
| 160 | 165 | { |
| 161 | 166 | // Load all the smileys. |
| 162 | 167 | $names = array(); |
| 163 | - foreach ($matches[1] as $file) |
|
| 164 | - $names[] = $file; |
|
| 168 | + foreach ($matches[1] as $file) { |
|
| 169 | + $names[] = $file; |
|
| 170 | + } |
|
| 165 | 171 | $names = array_unique($names); |
| 166 | 172 | |
| 167 | 173 | if (!empty($names)) |
@@ -175,13 +181,15 @@ discard block |
||
| 175 | 181 | ) |
| 176 | 182 | ); |
| 177 | 183 | $mappings = array(); |
| 178 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 179 | - $mappings[$row['filename']] = $smcFunc['htmlspecialchars']($row['code']); |
|
| 184 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 185 | + $mappings[$row['filename']] = $smcFunc['htmlspecialchars']($row['code']); |
|
| 186 | + } |
|
| 180 | 187 | $smcFunc['db_free_result']($request); |
| 181 | 188 | |
| 182 | - foreach ($matches[1] as $k => $file) |
|
| 183 | - if (isset($mappings[$file])) |
|
| 189 | + foreach ($matches[1] as $k => $file) { |
|
| 190 | + if (isset($mappings[$file])) |
|
| 184 | 191 | $matches[1][$k] = '-[]-smf_smily_start#|#' . $mappings[$file] . '-[]-smf_smily_end#|#'; |
| 192 | + } |
|
| 185 | 193 | } |
| 186 | 194 | } |
| 187 | 195 | |
@@ -193,8 +201,9 @@ discard block |
||
| 193 | 201 | } |
| 194 | 202 | |
| 195 | 203 | // Only try to buy more time if the client didn't quit. |
| 196 | - if (connection_aborted() && $context['server']['is_apache']) |
|
| 197 | - @apache_reset_timeout(); |
|
| 204 | + if (connection_aborted() && $context['server']['is_apache']) { |
|
| 205 | + @apache_reset_timeout(); |
|
| 206 | + } |
|
| 198 | 207 | |
| 199 | 208 | $parts = preg_split('~(<[A-Za-z]+\s*[^<>]*?style="?[^<>"]+"?[^<>]*?(?:/?)>|</[A-Za-z]+>)~', $text, -1, PREG_SPLIT_DELIM_CAPTURE); |
| 200 | 209 | $replacement = ''; |
@@ -205,9 +214,9 @@ discard block |
||
| 205 | 214 | if (preg_match('~(<([A-Za-z]+)\s*[^<>]*?)style="?([^<>"]+)"?([^<>]*?(/?)>)~', $part, $matches) === 1) |
| 206 | 215 | { |
| 207 | 216 | // If it's being closed instantly, we can't deal with it...yet. |
| 208 | - if ($matches[5] === '/') |
|
| 209 | - continue; |
|
| 210 | - else |
|
| 217 | + if ($matches[5] === '/') { |
|
| 218 | + continue; |
|
| 219 | + } else |
|
| 211 | 220 | { |
| 212 | 221 | // Get an array of styles that apply to this element. (The strtr is there to combat HTML generated by Word.) |
| 213 | 222 | $styles = explode(';', strtr($matches[3], array('"' => ''))); |
@@ -223,8 +232,9 @@ discard block |
||
| 223 | 232 | $clean_type_value_pair = strtolower(strtr(trim($type_value_pair), '=', ':')); |
| 224 | 233 | |
| 225 | 234 | // Something like 'font-weight: bold' is expected here. |
| 226 | - if (strpos($clean_type_value_pair, ':') === false) |
|
| 227 | - continue; |
|
| 235 | + if (strpos($clean_type_value_pair, ':') === false) { |
|
| 236 | + continue; |
|
| 237 | + } |
|
| 228 | 238 | |
| 229 | 239 | // Capture the elements of a single style item (e.g. 'font-weight' and 'bold'). |
| 230 | 240 | list ($style_type, $style_value) = explode(':', $type_value_pair); |
@@ -246,8 +256,7 @@ discard block |
||
| 246 | 256 | { |
| 247 | 257 | $curCloseTags .= '[/u]'; |
| 248 | 258 | $replacement .= '[u]'; |
| 249 | - } |
|
| 250 | - elseif ($style_value == 'line-through') |
|
| 259 | + } elseif ($style_value == 'line-through') |
|
| 251 | 260 | { |
| 252 | 261 | $curCloseTags .= '[/s]'; |
| 253 | 262 | $replacement .= '[s]'; |
@@ -259,13 +268,11 @@ discard block |
||
| 259 | 268 | { |
| 260 | 269 | $curCloseTags .= '[/left]'; |
| 261 | 270 | $replacement .= '[left]'; |
| 262 | - } |
|
| 263 | - elseif ($style_value == 'center') |
|
| 271 | + } elseif ($style_value == 'center') |
|
| 264 | 272 | { |
| 265 | 273 | $curCloseTags .= '[/center]'; |
| 266 | 274 | $replacement .= '[center]'; |
| 267 | - } |
|
| 268 | - elseif ($style_value == 'right') |
|
| 275 | + } elseif ($style_value == 'right') |
|
| 269 | 276 | { |
| 270 | 277 | $curCloseTags .= '[/right]'; |
| 271 | 278 | $replacement .= '[right]'; |
@@ -287,8 +294,9 @@ discard block |
||
| 287 | 294 | |
| 288 | 295 | case 'font-size': |
| 289 | 296 | // Sometimes people put decimals where decimals should not be. |
| 290 | - if (preg_match('~(\d)+\.\d+(p[xt])~i', $style_value, $dec_matches) === 1) |
|
| 291 | - $style_value = $dec_matches[1] . $dec_matches[2]; |
|
| 297 | + if (preg_match('~(\d)+\.\d+(p[xt])~i', $style_value, $dec_matches) === 1) { |
|
| 298 | + $style_value = $dec_matches[1] . $dec_matches[2]; |
|
| 299 | + } |
|
| 292 | 300 | |
| 293 | 301 | $curCloseTags .= '[/size]'; |
| 294 | 302 | $replacement .= '[size=' . $style_value . ']'; |
@@ -296,8 +304,9 @@ discard block |
||
| 296 | 304 | |
| 297 | 305 | case 'font-family': |
| 298 | 306 | // Only get the first freaking font if there's a list! |
| 299 | - if (strpos($style_value, ',') !== false) |
|
| 300 | - $style_value = substr($style_value, 0, strpos($style_value, ',')); |
|
| 307 | + if (strpos($style_value, ',') !== false) { |
|
| 308 | + $style_value = substr($style_value, 0, strpos($style_value, ',')); |
|
| 309 | + } |
|
| 301 | 310 | |
| 302 | 311 | $curCloseTags .= '[/font]'; |
| 303 | 312 | $replacement .= '[font=' . strtr($style_value, array("'" => '')) . ']'; |
@@ -306,13 +315,15 @@ discard block |
||
| 306 | 315 | // This is a hack for images with dimensions embedded. |
| 307 | 316 | case 'width': |
| 308 | 317 | case 'height': |
| 309 | - if (preg_match('~[1-9]\d*~i', $style_value, $dimension) === 1) |
|
| 310 | - $extra_attr .= ' ' . $style_type . '="' . $dimension[0] . '"'; |
|
| 318 | + if (preg_match('~[1-9]\d*~i', $style_value, $dimension) === 1) { |
|
| 319 | + $extra_attr .= ' ' . $style_type . '="' . $dimension[0] . '"'; |
|
| 320 | + } |
|
| 311 | 321 | break; |
| 312 | 322 | |
| 313 | 323 | case 'list-style-type': |
| 314 | - if (preg_match('~none|disc|circle|square|decimal|decimal-leading-zero|lower-roman|upper-roman|lower-alpha|upper-alpha|lower-greek|lower-latin|upper-latin|hebrew|armenian|georgian|cjk-ideographic|hiragana|katakana|hiragana-iroha|katakana-iroha~i', $style_value, $listType) === 1) |
|
| 315 | - $extra_attr .= ' listtype="' . $listType[0] . '"'; |
|
| 324 | + if (preg_match('~none|disc|circle|square|decimal|decimal-leading-zero|lower-roman|upper-roman|lower-alpha|upper-alpha|lower-greek|lower-latin|upper-latin|hebrew|armenian|georgian|cjk-ideographic|hiragana|katakana|hiragana-iroha|katakana-iroha~i', $style_value, $listType) === 1) { |
|
| 325 | + $extra_attr .= ' listtype="' . $listType[0] . '"'; |
|
| 326 | + } |
|
| 316 | 327 | break; |
| 317 | 328 | } |
| 318 | 329 | } |
@@ -325,18 +336,17 @@ discard block |
||
| 325 | 336 | } |
| 326 | 337 | |
| 327 | 338 | // If there's something that still needs closing, push it to the stack. |
| 328 | - if (!empty($curCloseTags)) |
|
| 329 | - array_push($stack, array( |
|
| 339 | + if (!empty($curCloseTags)) { |
|
| 340 | + array_push($stack, array( |
|
| 330 | 341 | 'element' => strtolower($curElement), |
| 331 | 342 | 'closeTags' => $curCloseTags |
| 332 | 343 | ) |
| 333 | 344 | ); |
| 334 | - elseif (!empty($extra_attr)) |
|
| 335 | - $replacement .= $precedingStyle . $extra_attr . $afterStyle; |
|
| 345 | + } elseif (!empty($extra_attr)) { |
|
| 346 | + $replacement .= $precedingStyle . $extra_attr . $afterStyle; |
|
| 347 | + } |
|
| 336 | 348 | } |
| 337 | - } |
|
| 338 | - |
|
| 339 | - elseif (preg_match('~</([A-Za-z]+)>~', $part, $matches) === 1) |
|
| 349 | + } elseif (preg_match('~</([A-Za-z]+)>~', $part, $matches) === 1) |
|
| 340 | 350 | { |
| 341 | 351 | // Is this the element that we've been waiting for to be closed? |
| 342 | 352 | if (!empty($stack) && strtolower($matches[1]) === $stack[count($stack) - 1]['element']) |
@@ -346,28 +356,32 @@ discard block |
||
| 346 | 356 | } |
| 347 | 357 | |
| 348 | 358 | // Must've been something else. |
| 349 | - else |
|
| 350 | - $replacement .= $part; |
|
| 359 | + else { |
|
| 360 | + $replacement .= $part; |
|
| 361 | + } |
|
| 351 | 362 | } |
| 352 | 363 | // In all other cases, just add the part to the replacement. |
| 353 | - else |
|
| 354 | - $replacement .= $part; |
|
| 364 | + else { |
|
| 365 | + $replacement .= $part; |
|
| 366 | + } |
|
| 355 | 367 | } |
| 356 | 368 | |
| 357 | 369 | // Now put back the replacement in the text. |
| 358 | 370 | $text = $replacement; |
| 359 | 371 | |
| 360 | 372 | // We are not finished yet, request more time. |
| 361 | - if (connection_aborted() && $context['server']['is_apache']) |
|
| 362 | - @apache_reset_timeout(); |
|
| 373 | + if (connection_aborted() && $context['server']['is_apache']) { |
|
| 374 | + @apache_reset_timeout(); |
|
| 375 | + } |
|
| 363 | 376 | |
| 364 | 377 | // Let's pull out any legacy alignments. |
| 365 | 378 | while (preg_match('~<([A-Za-z]+)\s+[^<>]*?(align="*(left|center|right)"*)[^<>]*?(/?)>~i', $text, $matches) === 1) |
| 366 | 379 | { |
| 367 | 380 | // Find the position in the text of this tag over again. |
| 368 | 381 | $start_pos = strpos($text, $matches[0]); |
| 369 | - if ($start_pos === false) |
|
| 370 | - break; |
|
| 382 | + if ($start_pos === false) { |
|
| 383 | + break; |
|
| 384 | + } |
|
| 371 | 385 | |
| 372 | 386 | // End tag? |
| 373 | 387 | if ($matches[4] != '/' && strpos($text, '</' . $matches[1] . '>', $start_pos) !== false) |
@@ -382,8 +396,7 @@ discard block |
||
| 382 | 396 | |
| 383 | 397 | // Put the tags back into the body. |
| 384 | 398 | $text = substr($text, 0, $start_pos) . $tag . '[' . $matches[3] . ']' . $content . '[/' . $matches[3] . ']' . substr($text, $end_pos); |
| 385 | - } |
|
| 386 | - else |
|
| 399 | + } else |
|
| 387 | 400 | { |
| 388 | 401 | // Just get rid of this evil tag. |
| 389 | 402 | $text = substr($text, 0, $start_pos) . substr($text, $start_pos + strlen($matches[0])); |
@@ -396,8 +409,9 @@ discard block |
||
| 396 | 409 | // Find the position of this again. |
| 397 | 410 | $start_pos = strpos($text, $matches[0]); |
| 398 | 411 | $end_pos = false; |
| 399 | - if ($start_pos === false) |
|
| 400 | - break; |
|
| 412 | + if ($start_pos === false) { |
|
| 413 | + break; |
|
| 414 | + } |
|
| 401 | 415 | |
| 402 | 416 | // This must have an end tag - and we must find the right one. |
| 403 | 417 | $lower_text = strtolower($text); |
@@ -430,8 +444,9 @@ discard block |
||
| 430 | 444 | break; |
| 431 | 445 | } |
| 432 | 446 | } |
| 433 | - if ($end_pos === false) |
|
| 434 | - break; |
|
| 447 | + if ($end_pos === false) { |
|
| 448 | + break; |
|
| 449 | + } |
|
| 435 | 450 | |
| 436 | 451 | // Now work out what the attributes are. |
| 437 | 452 | $attribs = fetchTagAttributes($matches[1]); |
@@ -445,11 +460,11 @@ discard block |
||
| 445 | 460 | $v = (int) trim($v); |
| 446 | 461 | $v = empty($v) ? 1 : $v; |
| 447 | 462 | $tags[] = array('[size=' . $sizes_equivalence[$v] . ']', '[/size]'); |
| 463 | + } elseif ($s == 'face') { |
|
| 464 | + $tags[] = array('[font=' . trim(strtolower($v)) . ']', '[/font]'); |
|
| 465 | + } elseif ($s == 'color') { |
|
| 466 | + $tags[] = array('[color=' . trim(strtolower($v)) . ']', '[/color]'); |
|
| 448 | 467 | } |
| 449 | - elseif ($s == 'face') |
|
| 450 | - $tags[] = array('[font=' . trim(strtolower($v)) . ']', '[/font]'); |
|
| 451 | - elseif ($s == 'color') |
|
| 452 | - $tags[] = array('[color=' . trim(strtolower($v)) . ']', '[/color]'); |
|
| 453 | 468 | } |
| 454 | 469 | |
| 455 | 470 | // As before add in our tags. |
@@ -457,8 +472,9 @@ discard block |
||
| 457 | 472 | foreach ($tags as $tag) |
| 458 | 473 | { |
| 459 | 474 | $before .= $tag[0]; |
| 460 | - if (isset($tag[1])) |
|
| 461 | - $after = $tag[1] . $after; |
|
| 475 | + if (isset($tag[1])) { |
|
| 476 | + $after = $tag[1] . $after; |
|
| 477 | + } |
|
| 462 | 478 | } |
| 463 | 479 | |
| 464 | 480 | // Remove the tag so it's never checked again. |
@@ -469,8 +485,9 @@ discard block |
||
| 469 | 485 | } |
| 470 | 486 | |
| 471 | 487 | // Almost there, just a little more time. |
| 472 | - if (connection_aborted() && $context['server']['is_apache']) |
|
| 473 | - @apache_reset_timeout(); |
|
| 488 | + if (connection_aborted() && $context['server']['is_apache']) { |
|
| 489 | + @apache_reset_timeout(); |
|
| 490 | + } |
|
| 474 | 491 | |
| 475 | 492 | if (count($parts = preg_split('~<(/?)(li|ol|ul)([^>]*)>~i', $text, null, PREG_SPLIT_DELIM_CAPTURE)) > 1) |
| 476 | 493 | { |
@@ -526,12 +543,13 @@ discard block |
||
| 526 | 543 | { |
| 527 | 544 | $inList = true; |
| 528 | 545 | |
| 529 | - if ($tag === 'ol') |
|
| 530 | - $listType = 'decimal'; |
|
| 531 | - elseif (preg_match('~type="?(' . implode('|', array_keys($listTypeMapping)) . ')"?~', $parts[$i + 3], $match) === 1) |
|
| 532 | - $listType = $listTypeMapping[$match[1]]; |
|
| 533 | - else |
|
| 534 | - $listType = null; |
|
| 546 | + if ($tag === 'ol') { |
|
| 547 | + $listType = 'decimal'; |
|
| 548 | + } elseif (preg_match('~type="?(' . implode('|', array_keys($listTypeMapping)) . ')"?~', $parts[$i + 3], $match) === 1) { |
|
| 549 | + $listType = $listTypeMapping[$match[1]]; |
|
| 550 | + } else { |
|
| 551 | + $listType = null; |
|
| 552 | + } |
|
| 535 | 553 | |
| 536 | 554 | $listDepth++; |
| 537 | 555 | |
@@ -595,9 +613,7 @@ discard block |
||
| 595 | 613 | $parts[$i + 1] = ''; |
| 596 | 614 | $parts[$i + 2] = str_repeat("\t", $listDepth) . '[/list]'; |
| 597 | 615 | $parts[$i + 3] = ''; |
| 598 | - } |
|
| 599 | - |
|
| 600 | - else |
|
| 616 | + } else |
|
| 601 | 617 | { |
| 602 | 618 | // We're in a list item. |
| 603 | 619 | if ($listDepth > 0) |
@@ -634,9 +650,7 @@ discard block |
||
| 634 | 650 | $parts[$i + 1] = ''; |
| 635 | 651 | $parts[$i + 2] = ''; |
| 636 | 652 | $parts[$i + 3] = ''; |
| 637 | - } |
|
| 638 | - |
|
| 639 | - else |
|
| 653 | + } else |
|
| 640 | 654 | { |
| 641 | 655 | // Remove the trailing breaks from the list item. |
| 642 | 656 | $parts[$i] = preg_replace('~\s*<br\s*' . '/?' . '>\s*$~', '', $parts[$i]); |
@@ -674,8 +688,9 @@ discard block |
||
| 674 | 688 | $text .= str_repeat("\t", $listDepth) . '[/list]'; |
| 675 | 689 | } |
| 676 | 690 | |
| 677 | - for ($i = $listDepth; $i > 0; $i--) |
|
| 678 | - $text .= '[/li]' . "\n" . str_repeat("\t", $i - 1) . '[/list]'; |
|
| 691 | + for ($i = $listDepth; $i > 0; $i--) { |
|
| 692 | + $text .= '[/li]' . "\n" . str_repeat("\t", $i - 1) . '[/list]'; |
|
| 693 | + } |
|
| 679 | 694 | |
| 680 | 695 | } |
| 681 | 696 | |
@@ -684,8 +699,9 @@ discard block |
||
| 684 | 699 | { |
| 685 | 700 | // Find the position of the image. |
| 686 | 701 | $start_pos = strpos($text, $matches[0]); |
| 687 | - if ($start_pos === false) |
|
| 688 | - break; |
|
| 702 | + if ($start_pos === false) { |
|
| 703 | + break; |
|
| 704 | + } |
|
| 689 | 705 | $end_pos = $start_pos + strlen($matches[0]); |
| 690 | 706 | |
| 691 | 707 | $params = ''; |
@@ -694,12 +710,13 @@ discard block |
||
| 694 | 710 | $attrs = fetchTagAttributes($matches[1]); |
| 695 | 711 | foreach ($attrs as $attrib => $value) |
| 696 | 712 | { |
| 697 | - if (in_array($attrib, array('width', 'height'))) |
|
| 698 | - $params .= ' ' . $attrib . '=' . (int) $value; |
|
| 699 | - elseif ($attrib == 'alt' && trim($value) != '') |
|
| 700 | - $params .= ' alt=' . trim($value); |
|
| 701 | - elseif ($attrib == 'src') |
|
| 702 | - $src = trim($value); |
|
| 713 | + if (in_array($attrib, array('width', 'height'))) { |
|
| 714 | + $params .= ' ' . $attrib . '=' . (int) $value; |
|
| 715 | + } elseif ($attrib == 'alt' && trim($value) != '') { |
|
| 716 | + $params .= ' alt=' . trim($value); |
|
| 717 | + } elseif ($attrib == 'src') { |
|
| 718 | + $src = trim($value); |
|
| 719 | + } |
|
| 703 | 720 | } |
| 704 | 721 | |
| 705 | 722 | $tag = ''; |
@@ -710,10 +727,11 @@ discard block |
||
| 710 | 727 | { |
| 711 | 728 | $baseURL = (isset($parsedURL['scheme']) ? $parsedURL['scheme'] : 'http') . '://' . $parsedURL['host'] . (empty($parsedURL['port']) ? '' : ':' . $parsedURL['port']); |
| 712 | 729 | |
| 713 | - if (substr($src, 0, 1) === '/') |
|
| 714 | - $src = $baseURL . $src; |
|
| 715 | - else |
|
| 716 | - $src = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $src; |
|
| 730 | + if (substr($src, 0, 1) === '/') { |
|
| 731 | + $src = $baseURL . $src; |
|
| 732 | + } else { |
|
| 733 | + $src = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $src; |
|
| 734 | + } |
|
| 717 | 735 | } |
| 718 | 736 | |
| 719 | 737 | $tag = '[img' . $params . ']' . $src . '[/img]'; |
@@ -891,20 +909,23 @@ discard block |
||
| 891 | 909 | }, |
| 892 | 910 | ); |
| 893 | 911 | |
| 894 | - foreach ($tags as $tag => $replace) |
|
| 895 | - $text = preg_replace_callback($tag, $replace, $text); |
|
| 912 | + foreach ($tags as $tag => $replace) { |
|
| 913 | + $text = preg_replace_callback($tag, $replace, $text); |
|
| 914 | + } |
|
| 896 | 915 | |
| 897 | 916 | // Please give us just a little more time. |
| 898 | - if (connection_aborted() && $context['server']['is_apache']) |
|
| 899 | - @apache_reset_timeout(); |
|
| 917 | + if (connection_aborted() && $context['server']['is_apache']) { |
|
| 918 | + @apache_reset_timeout(); |
|
| 919 | + } |
|
| 900 | 920 | |
| 901 | 921 | // What about URL's - the pain in the ass of the tag world. |
| 902 | 922 | while (preg_match('~<a\s+([^<>]*)>([^<>]*)</a>~i', $text, $matches) === 1) |
| 903 | 923 | { |
| 904 | 924 | // Find the position of the URL. |
| 905 | 925 | $start_pos = strpos($text, $matches[0]); |
| 906 | - if ($start_pos === false) |
|
| 907 | - break; |
|
| 926 | + if ($start_pos === false) { |
|
| 927 | + break; |
|
| 928 | + } |
|
| 908 | 929 | $end_pos = $start_pos + strlen($matches[0]); |
| 909 | 930 | |
| 910 | 931 | $tag_type = 'url'; |
@@ -918,8 +939,9 @@ discard block |
||
| 918 | 939 | $href = trim($value); |
| 919 | 940 | |
| 920 | 941 | // Are we dealing with an FTP link? |
| 921 | - if (preg_match('~^ftps?://~', $href) === 1) |
|
| 922 | - $tag_type = 'ftp'; |
|
| 942 | + if (preg_match('~^ftps?://~', $href) === 1) { |
|
| 943 | + $tag_type = 'ftp'; |
|
| 944 | + } |
|
| 923 | 945 | |
| 924 | 946 | // Or is this a link to an email address? |
| 925 | 947 | elseif (substr($href, 0, 7) == 'mailto:') |
@@ -933,28 +955,31 @@ discard block |
||
| 933 | 955 | { |
| 934 | 956 | $baseURL = (isset($parsedURL['scheme']) ? $parsedURL['scheme'] : 'http') . '://' . $parsedURL['host'] . (empty($parsedURL['port']) ? '' : ':' . $parsedURL['port']); |
| 935 | 957 | |
| 936 | - if (substr($href, 0, 1) === '/') |
|
| 937 | - $href = $baseURL . $href; |
|
| 938 | - else |
|
| 939 | - $href = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $href; |
|
| 958 | + if (substr($href, 0, 1) === '/') { |
|
| 959 | + $href = $baseURL . $href; |
|
| 960 | + } else { |
|
| 961 | + $href = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $href; |
|
| 962 | + } |
|
| 940 | 963 | } |
| 941 | 964 | } |
| 942 | 965 | |
| 943 | 966 | // External URL? |
| 944 | 967 | if ($attrib == 'target' && $tag_type == 'url') |
| 945 | 968 | { |
| 946 | - if (trim($value) == '_blank') |
|
| 947 | - $tag_type == 'iurl'; |
|
| 969 | + if (trim($value) == '_blank') { |
|
| 970 | + $tag_type == 'iurl'; |
|
| 971 | + } |
|
| 948 | 972 | } |
| 949 | 973 | } |
| 950 | 974 | |
| 951 | 975 | $tag = ''; |
| 952 | 976 | if ($href != '') |
| 953 | 977 | { |
| 954 | - if ($matches[2] == $href) |
|
| 955 | - $tag = '[' . $tag_type . ']' . $href . '[/' . $tag_type . ']'; |
|
| 956 | - else |
|
| 957 | - $tag = '[' . $tag_type . '=' . $href . ']' . $matches[2] . '[/' . $tag_type . ']'; |
|
| 978 | + if ($matches[2] == $href) { |
|
| 979 | + $tag = '[' . $tag_type . ']' . $href . '[/' . $tag_type . ']'; |
|
| 980 | + } else { |
|
| 981 | + $tag = '[' . $tag_type . '=' . $href . ']' . $matches[2] . '[/' . $tag_type . ']'; |
|
| 982 | + } |
|
| 958 | 983 | } |
| 959 | 984 | |
| 960 | 985 | // Replace the tag |
@@ -993,17 +1018,18 @@ discard block |
||
| 993 | 1018 | // We're either moving from the key to the attribute or we're in a string and this is fine. |
| 994 | 1019 | if ($text[$i] == '=') |
| 995 | 1020 | { |
| 996 | - if ($tag_state == 0) |
|
| 997 | - $tag_state = 1; |
|
| 998 | - elseif ($tag_state == 2) |
|
| 999 | - $value .= '='; |
|
| 1021 | + if ($tag_state == 0) { |
|
| 1022 | + $tag_state = 1; |
|
| 1023 | + } elseif ($tag_state == 2) { |
|
| 1024 | + $value .= '='; |
|
| 1025 | + } |
|
| 1000 | 1026 | } |
| 1001 | 1027 | // A space is either moving from an attribute back to a potential key or in a string is fine. |
| 1002 | 1028 | elseif ($text[$i] == ' ') |
| 1003 | 1029 | { |
| 1004 | - if ($tag_state == 2) |
|
| 1005 | - $value .= ' '; |
|
| 1006 | - elseif ($tag_state == 1) |
|
| 1030 | + if ($tag_state == 2) { |
|
| 1031 | + $value .= ' '; |
|
| 1032 | + } elseif ($tag_state == 1) |
|
| 1007 | 1033 | { |
| 1008 | 1034 | $attribs[$key] = $value; |
| 1009 | 1035 | $key = $value = ''; |
@@ -1014,24 +1040,27 @@ discard block |
||
| 1014 | 1040 | elseif ($text[$i] == '"') |
| 1015 | 1041 | { |
| 1016 | 1042 | // Must be either going into or out of a string. |
| 1017 | - if ($tag_state == 1) |
|
| 1018 | - $tag_state = 2; |
|
| 1019 | - else |
|
| 1020 | - $tag_state = 1; |
|
| 1043 | + if ($tag_state == 1) { |
|
| 1044 | + $tag_state = 2; |
|
| 1045 | + } else { |
|
| 1046 | + $tag_state = 1; |
|
| 1047 | + } |
|
| 1021 | 1048 | } |
| 1022 | 1049 | // Otherwise it's fine. |
| 1023 | 1050 | else |
| 1024 | 1051 | { |
| 1025 | - if ($tag_state == 0) |
|
| 1026 | - $key .= $text[$i]; |
|
| 1027 | - else |
|
| 1028 | - $value .= $text[$i]; |
|
| 1052 | + if ($tag_state == 0) { |
|
| 1053 | + $key .= $text[$i]; |
|
| 1054 | + } else { |
|
| 1055 | + $value .= $text[$i]; |
|
| 1056 | + } |
|
| 1029 | 1057 | } |
| 1030 | 1058 | } |
| 1031 | 1059 | |
| 1032 | 1060 | // Anything left? |
| 1033 | - if ($key != '' && $value != '') |
|
| 1034 | - $attribs[$key] = $value; |
|
| 1061 | + if ($key != '' && $value != '') { |
|
| 1062 | + $attribs[$key] = $value; |
|
| 1063 | + } |
|
| 1035 | 1064 | |
| 1036 | 1065 | return $attribs; |
| 1037 | 1066 | } |
@@ -1047,15 +1076,17 @@ discard block |
||
| 1047 | 1076 | global $modSettings; |
| 1048 | 1077 | |
| 1049 | 1078 | // Don't care about the texts that are too short. |
| 1050 | - if (strlen($text) < 3) |
|
| 1051 | - return $text; |
|
| 1079 | + if (strlen($text) < 3) { |
|
| 1080 | + return $text; |
|
| 1081 | + } |
|
| 1052 | 1082 | |
| 1053 | 1083 | // A list of tags that's disabled by the admin. |
| 1054 | 1084 | $disabled = empty($modSettings['disabledBBC']) ? array() : array_flip(explode(',', strtolower($modSettings['disabledBBC']))); |
| 1055 | 1085 | |
| 1056 | 1086 | // Add flash if it's disabled as embedded tag. |
| 1057 | - if (empty($modSettings['enableEmbeddedFlash'])) |
|
| 1058 | - $disabled['flash'] = true; |
|
| 1087 | + if (empty($modSettings['enableEmbeddedFlash'])) { |
|
| 1088 | + $disabled['flash'] = true; |
|
| 1089 | + } |
|
| 1059 | 1090 | |
| 1060 | 1091 | // Get a list of all the tags that are not disabled. |
| 1061 | 1092 | $all_tags = parse_bbc(false); |
@@ -1063,10 +1094,12 @@ discard block |
||
| 1063 | 1094 | $self_closing_tags = array(); |
| 1064 | 1095 | foreach ($all_tags as $tag) |
| 1065 | 1096 | { |
| 1066 | - if (!isset($disabled[$tag['tag']])) |
|
| 1067 | - $valid_tags[$tag['tag']] = !empty($tag['block_level']); |
|
| 1068 | - if (isset($tag['type']) && $tag['type'] == 'closed') |
|
| 1069 | - $self_closing_tags[] = $tag['tag']; |
|
| 1097 | + if (!isset($disabled[$tag['tag']])) { |
|
| 1098 | + $valid_tags[$tag['tag']] = !empty($tag['block_level']); |
|
| 1099 | + } |
|
| 1100 | + if (isset($tag['type']) && $tag['type'] == 'closed') { |
|
| 1101 | + $self_closing_tags[] = $tag['tag']; |
|
| 1102 | + } |
|
| 1070 | 1103 | } |
| 1071 | 1104 | |
| 1072 | 1105 | // Right - we're going to start by going through the whole lot to make sure we don't have align stuff crossed as this happens load and is stupid! |
@@ -1093,16 +1126,19 @@ discard block |
||
| 1093 | 1126 | $tagName = substr($match, $isClosingTag ? 2 : 1, -1); |
| 1094 | 1127 | |
| 1095 | 1128 | // We're closing the exact same tag that we opened. |
| 1096 | - if ($isClosingTag && $insideTag === $tagName) |
|
| 1097 | - $insideTag = null; |
|
| 1129 | + if ($isClosingTag && $insideTag === $tagName) { |
|
| 1130 | + $insideTag = null; |
|
| 1131 | + } |
|
| 1098 | 1132 | |
| 1099 | 1133 | // We're opening a tag and we're not yet inside one either |
| 1100 | - elseif (!$isClosingTag && $insideTag === null) |
|
| 1101 | - $insideTag = $tagName; |
|
| 1134 | + elseif (!$isClosingTag && $insideTag === null) { |
|
| 1135 | + $insideTag = $tagName; |
|
| 1136 | + } |
|
| 1102 | 1137 | |
| 1103 | 1138 | // In all other cases, this tag must be invalid |
| 1104 | - else |
|
| 1105 | - unset($matches[$i]); |
|
| 1139 | + else { |
|
| 1140 | + unset($matches[$i]); |
|
| 1141 | + } |
|
| 1106 | 1142 | } |
| 1107 | 1143 | |
| 1108 | 1144 | // The next one is gonna be the other one. |
@@ -1110,8 +1146,9 @@ discard block |
||
| 1110 | 1146 | } |
| 1111 | 1147 | |
| 1112 | 1148 | // We're still inside a tag and had no chance for closure? |
| 1113 | - if ($insideTag !== null) |
|
| 1114 | - $matches[] = '[/' . $insideTag . ']'; |
|
| 1149 | + if ($insideTag !== null) { |
|
| 1150 | + $matches[] = '[/' . $insideTag . ']'; |
|
| 1151 | + } |
|
| 1115 | 1152 | |
| 1116 | 1153 | // And a complete text string again. |
| 1117 | 1154 | $text = implode('', $matches); |
@@ -1120,8 +1157,9 @@ discard block |
||
| 1120 | 1157 | // Quickly remove any tags which are back to back. |
| 1121 | 1158 | $backToBackPattern = '~\\[(' . implode('|', array_diff(array_keys($valid_tags), array('td', 'anchor'))) . ')[^<>\\[\\]]*\\]\s*\\[/\\1\\]~'; |
| 1122 | 1159 | $lastlen = 0; |
| 1123 | - while (strlen($text) !== $lastlen) |
|
| 1124 | - $lastlen = strlen($text = preg_replace($backToBackPattern, '', $text)); |
|
| 1160 | + while (strlen($text) !== $lastlen) { |
|
| 1161 | + $lastlen = strlen($text = preg_replace($backToBackPattern, '', $text)); |
|
| 1162 | + } |
|
| 1125 | 1163 | |
| 1126 | 1164 | // Need to sort the tags my name length. |
| 1127 | 1165 | uksort($valid_tags, 'sort_array_length'); |
@@ -1158,8 +1196,9 @@ discard block |
||
| 1158 | 1196 | $isCompetingTag = in_array($tag, $competing_tags); |
| 1159 | 1197 | |
| 1160 | 1198 | // Check if this might be one of those cleaned out tags. |
| 1161 | - if ($tag === '') |
|
| 1162 | - continue; |
|
| 1199 | + if ($tag === '') { |
|
| 1200 | + continue; |
|
| 1201 | + } |
|
| 1163 | 1202 | |
| 1164 | 1203 | // Special case: inside [code] blocks any code is left untouched. |
| 1165 | 1204 | elseif ($tag === 'code') |
@@ -1170,8 +1209,9 @@ discard block |
||
| 1170 | 1209 | $inCode = false; |
| 1171 | 1210 | |
| 1172 | 1211 | // Reopen tags that were closed before the code block. |
| 1173 | - if (!empty($inlineElements)) |
|
| 1174 | - $parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']'; |
|
| 1212 | + if (!empty($inlineElements)) { |
|
| 1213 | + $parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']'; |
|
| 1214 | + } |
|
| 1175 | 1215 | } |
| 1176 | 1216 | |
| 1177 | 1217 | // We're outside a coding and nobbc block and opening it. |
@@ -1200,8 +1240,9 @@ discard block |
||
| 1200 | 1240 | $inNoBbc = false; |
| 1201 | 1241 | |
| 1202 | 1242 | // Some inline elements might've been closed that need reopening. |
| 1203 | - if (!empty($inlineElements)) |
|
| 1204 | - $parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']'; |
|
| 1243 | + if (!empty($inlineElements)) { |
|
| 1244 | + $parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']'; |
|
| 1245 | + } |
|
| 1205 | 1246 | } |
| 1206 | 1247 | |
| 1207 | 1248 | // We're outside a nobbc and coding block and opening it. |
@@ -1221,8 +1262,9 @@ discard block |
||
| 1221 | 1262 | } |
| 1222 | 1263 | |
| 1223 | 1264 | // So, we're inside one of the special blocks: ignore any tag. |
| 1224 | - elseif ($inCode || $inNoBbc) |
|
| 1225 | - continue; |
|
| 1265 | + elseif ($inCode || $inNoBbc) { |
|
| 1266 | + continue; |
|
| 1267 | + } |
|
| 1226 | 1268 | |
| 1227 | 1269 | // We're dealing with an opening tag. |
| 1228 | 1270 | if ($isOpeningTag) |
@@ -1263,8 +1305,9 @@ discard block |
||
| 1263 | 1305 | if ($parts[$j + 3] === $tag) |
| 1264 | 1306 | { |
| 1265 | 1307 | // If it's an opening tag, increase the level. |
| 1266 | - if ($parts[$j + 2] === '') |
|
| 1267 | - $curLevel++; |
|
| 1308 | + if ($parts[$j + 2] === '') { |
|
| 1309 | + $curLevel++; |
|
| 1310 | + } |
|
| 1268 | 1311 | |
| 1269 | 1312 | // A closing tag, decrease the level. |
| 1270 | 1313 | else |
@@ -1287,13 +1330,15 @@ discard block |
||
| 1287 | 1330 | { |
| 1288 | 1331 | if ($isCompetingTag) |
| 1289 | 1332 | { |
| 1290 | - if (!isset($competingElements[$tag])) |
|
| 1291 | - $competingElements[$tag] = array(); |
|
| 1333 | + if (!isset($competingElements[$tag])) { |
|
| 1334 | + $competingElements[$tag] = array(); |
|
| 1335 | + } |
|
| 1292 | 1336 | |
| 1293 | 1337 | $competingElements[$tag][] = $parts[$i + 4]; |
| 1294 | 1338 | |
| 1295 | - if (count($competingElements[$tag]) > 1) |
|
| 1296 | - $parts[$i] .= '[/' . $tag . ']'; |
|
| 1339 | + if (count($competingElements[$tag]) > 1) { |
|
| 1340 | + $parts[$i] .= '[/' . $tag . ']'; |
|
| 1341 | + } |
|
| 1297 | 1342 | } |
| 1298 | 1343 | |
| 1299 | 1344 | $inlineElements[$elementContent] = $tag; |
@@ -1314,15 +1359,17 @@ discard block |
||
| 1314 | 1359 | $addClosingTags = array(); |
| 1315 | 1360 | while ($element = array_pop($blockElements)) |
| 1316 | 1361 | { |
| 1317 | - if ($element === $tag) |
|
| 1318 | - break; |
|
| 1362 | + if ($element === $tag) { |
|
| 1363 | + break; |
|
| 1364 | + } |
|
| 1319 | 1365 | |
| 1320 | 1366 | // Still a block tag was open not equal to this tag. |
| 1321 | 1367 | $addClosingTags[] = $element['type']; |
| 1322 | 1368 | } |
| 1323 | 1369 | |
| 1324 | - if (!empty($addClosingTags)) |
|
| 1325 | - $parts[$i + 1] = '[/' . implode('][/', array_reverse($addClosingTags)) . ']' . $parts[$i + 1]; |
|
| 1370 | + if (!empty($addClosingTags)) { |
|
| 1371 | + $parts[$i + 1] = '[/' . implode('][/', array_reverse($addClosingTags)) . ']' . $parts[$i + 1]; |
|
| 1372 | + } |
|
| 1326 | 1373 | |
| 1327 | 1374 | // Apparently the closing tag was not found on the stack. |
| 1328 | 1375 | if (!is_string($element) || $element !== $tag) |
@@ -1332,8 +1379,7 @@ discard block |
||
| 1332 | 1379 | $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = ''; |
| 1333 | 1380 | continue; |
| 1334 | 1381 | } |
| 1335 | - } |
|
| 1336 | - else |
|
| 1382 | + } else |
|
| 1337 | 1383 | { |
| 1338 | 1384 | // Get rid of this closing tag! |
| 1339 | 1385 | $parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = ''; |
@@ -1362,53 +1408,62 @@ discard block |
||
| 1362 | 1408 | unset($inlineElements[$tagContentToBeClosed]); |
| 1363 | 1409 | |
| 1364 | 1410 | // Was this the tag we were looking for? |
| 1365 | - if ($tagToBeClosed === $tag) |
|
| 1366 | - break; |
|
| 1411 | + if ($tagToBeClosed === $tag) { |
|
| 1412 | + break; |
|
| 1413 | + } |
|
| 1367 | 1414 | |
| 1368 | 1415 | // Nope, close it and look further! |
| 1369 | - else |
|
| 1370 | - $parts[$i] .= '[/' . $tagToBeClosed . ']'; |
|
| 1416 | + else { |
|
| 1417 | + $parts[$i] .= '[/' . $tagToBeClosed . ']'; |
|
| 1418 | + } |
|
| 1371 | 1419 | } |
| 1372 | 1420 | |
| 1373 | 1421 | if ($isCompetingTag && !empty($competingElements[$tag])) |
| 1374 | 1422 | { |
| 1375 | 1423 | array_pop($competingElements[$tag]); |
| 1376 | 1424 | |
| 1377 | - if (count($competingElements[$tag]) > 0) |
|
| 1378 | - $parts[$i + 5] = '[' . $tag . $competingElements[$tag][count($competingElements[$tag]) - 1] . $parts[$i + 5]; |
|
| 1425 | + if (count($competingElements[$tag]) > 0) { |
|
| 1426 | + $parts[$i + 5] = '[' . $tag . $competingElements[$tag][count($competingElements[$tag]) - 1] . $parts[$i + 5]; |
|
| 1427 | + } |
|
| 1379 | 1428 | } |
| 1380 | 1429 | } |
| 1381 | 1430 | |
| 1382 | 1431 | // Unexpected closing tag, ex-ter-mi-nate. |
| 1383 | - else |
|
| 1384 | - $parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = ''; |
|
| 1432 | + else { |
|
| 1433 | + $parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = ''; |
|
| 1434 | + } |
|
| 1385 | 1435 | } |
| 1386 | 1436 | } |
| 1387 | 1437 | } |
| 1388 | 1438 | |
| 1389 | 1439 | // Close the code tags. |
| 1390 | - if ($inCode) |
|
| 1391 | - $parts[$i] .= '[/code]'; |
|
| 1440 | + if ($inCode) { |
|
| 1441 | + $parts[$i] .= '[/code]'; |
|
| 1442 | + } |
|
| 1392 | 1443 | |
| 1393 | 1444 | // The same for nobbc tags. |
| 1394 | - elseif ($inNoBbc) |
|
| 1395 | - $parts[$i] .= '[/nobbc]'; |
|
| 1445 | + elseif ($inNoBbc) { |
|
| 1446 | + $parts[$i] .= '[/nobbc]'; |
|
| 1447 | + } |
|
| 1396 | 1448 | |
| 1397 | 1449 | // Still inline tags left unclosed? Close them now, better late than never. |
| 1398 | - elseif (!empty($inlineElements)) |
|
| 1399 | - $parts[$i] .= '[/' . implode('][/', array_reverse($inlineElements)) . ']'; |
|
| 1450 | + elseif (!empty($inlineElements)) { |
|
| 1451 | + $parts[$i] .= '[/' . implode('][/', array_reverse($inlineElements)) . ']'; |
|
| 1452 | + } |
|
| 1400 | 1453 | |
| 1401 | 1454 | // Now close the block elements. |
| 1402 | - if (!empty($blockElements)) |
|
| 1403 | - $parts[$i] .= '[/' . implode('][/', array_reverse($blockElements)) . ']'; |
|
| 1455 | + if (!empty($blockElements)) { |
|
| 1456 | + $parts[$i] .= '[/' . implode('][/', array_reverse($blockElements)) . ']'; |
|
| 1457 | + } |
|
| 1404 | 1458 | |
| 1405 | 1459 | $text = implode('', $parts); |
| 1406 | 1460 | } |
| 1407 | 1461 | |
| 1408 | 1462 | // Final clean up of back to back tags. |
| 1409 | 1463 | $lastlen = 0; |
| 1410 | - while (strlen($text) !== $lastlen) |
|
| 1411 | - $lastlen = strlen($text = preg_replace($backToBackPattern, '', $text)); |
|
| 1464 | + while (strlen($text) !== $lastlen) { |
|
| 1465 | + $lastlen = strlen($text = preg_replace($backToBackPattern, '', $text)); |
|
| 1466 | + } |
|
| 1412 | 1467 | |
| 1413 | 1468 | return $text; |
| 1414 | 1469 | } |
@@ -1437,22 +1492,25 @@ discard block |
||
| 1437 | 1492 | $context['template_layers'] = array(); |
| 1438 | 1493 | // Lets make sure we aren't going to output anything nasty. |
| 1439 | 1494 | @ob_end_clean(); |
| 1440 | - if (!empty($modSettings['enableCompressedOutput'])) |
|
| 1441 | - @ob_start('ob_gzhandler'); |
|
| 1442 | - else |
|
| 1443 | - @ob_start(); |
|
| 1495 | + if (!empty($modSettings['enableCompressedOutput'])) { |
|
| 1496 | + @ob_start('ob_gzhandler'); |
|
| 1497 | + } else { |
|
| 1498 | + @ob_start(); |
|
| 1499 | + } |
|
| 1444 | 1500 | |
| 1445 | 1501 | // If we don't have any locale better avoid broken js |
| 1446 | - if (empty($txt['lang_locale'])) |
|
| 1447 | - die(); |
|
| 1502 | + if (empty($txt['lang_locale'])) { |
|
| 1503 | + die(); |
|
| 1504 | + } |
|
| 1448 | 1505 | |
| 1449 | 1506 | $file_data = '(function ($) { |
| 1450 | 1507 | \'use strict\'; |
| 1451 | 1508 | |
| 1452 | 1509 | $.sceditor.locale[' . javaScriptEscape($txt['lang_locale']) . '] = {'; |
| 1453 | - foreach ($editortxt as $key => $val) |
|
| 1454 | - $file_data .= ' |
|
| 1510 | + foreach ($editortxt as $key => $val) { |
|
| 1511 | + $file_data .= ' |
|
| 1455 | 1512 | ' . javaScriptEscape($key) . ': ' . javaScriptEscape($val) . ','; |
| 1513 | + } |
|
| 1456 | 1514 | |
| 1457 | 1515 | $file_data .= ' |
| 1458 | 1516 | dateFormat: "day.month.year" |
@@ -1520,8 +1578,9 @@ discard block |
||
| 1520 | 1578 | ) |
| 1521 | 1579 | ); |
| 1522 | 1580 | $icon_data = array(); |
| 1523 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1524 | - $icon_data[] = $row; |
|
| 1581 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1582 | + $icon_data[] = $row; |
|
| 1583 | + } |
|
| 1525 | 1584 | $smcFunc['db_free_result']($request); |
| 1526 | 1585 | |
| 1527 | 1586 | $icons = array(); |
@@ -1536,9 +1595,9 @@ discard block |
||
| 1536 | 1595 | } |
| 1537 | 1596 | |
| 1538 | 1597 | cache_put_data('posting_icons-' . $board_id, $icons, 480); |
| 1598 | + } else { |
|
| 1599 | + $icons = $temp; |
|
| 1539 | 1600 | } |
| 1540 | - else |
|
| 1541 | - $icons = $temp; |
|
| 1542 | 1601 | } |
| 1543 | 1602 | call_integration_hook('integrate_load_message_icons', array(&$icons)); |
| 1544 | 1603 | |
@@ -1579,8 +1638,9 @@ discard block |
||
| 1579 | 1638 | { |
| 1580 | 1639 | // Some general stuff. |
| 1581 | 1640 | $settings['smileys_url'] = $modSettings['smileys_url'] . '/' . $user_info['smiley_set']; |
| 1582 | - if (!empty($context['drafts_autosave'])) |
|
| 1583 | - $context['drafts_autosave_frequency'] = empty($modSettings['drafts_autosave_frequency']) ? 60000 : $modSettings['drafts_autosave_frequency'] * 1000; |
|
| 1641 | + if (!empty($context['drafts_autosave'])) { |
|
| 1642 | + $context['drafts_autosave_frequency'] = empty($modSettings['drafts_autosave_frequency']) ? 60000 : $modSettings['drafts_autosave_frequency'] * 1000; |
|
| 1643 | + } |
|
| 1584 | 1644 | |
| 1585 | 1645 | // This really has some WYSIWYG stuff. |
| 1586 | 1646 | loadCSSFile('jquery.sceditor.css', array('force_current' => false, 'validate' => true), 'smf_jquery_sceditor'); |
@@ -1596,8 +1656,9 @@ discard block |
||
| 1596 | 1656 | var bbc_quote = \'' . addcslashes($txt['quote'], "'") . '\'; |
| 1597 | 1657 | var bbc_search_on = \'' . addcslashes($txt['search_on'], "'") . '\';'); |
| 1598 | 1658 | // editor language file |
| 1599 | - if (!empty($txt['lang_locale']) && $txt['lang_locale'] != 'en_US') |
|
| 1600 | - loadJavaScriptFile($scripturl . '?action=loadeditorlocale', array('external' => true), 'sceditor_language'); |
|
| 1659 | + if (!empty($txt['lang_locale']) && $txt['lang_locale'] != 'en_US') { |
|
| 1660 | + loadJavaScriptFile($scripturl . '?action=loadeditorlocale', array('external' => true), 'sceditor_language'); |
|
| 1661 | + } |
|
| 1601 | 1662 | |
| 1602 | 1663 | $context['shortcuts_text'] = $txt['shortcuts' . (!empty($context['drafts_save']) ? '_drafts' : '') . (stripos($_SERVER['HTTP_USER_AGENT'], 'Macintosh') !== false ? '_mac' : (isBrowser('is_firefox') ? '_firefox' : ''))]; |
| 1603 | 1664 | $context['show_spellchecking'] = !empty($modSettings['enableSpellChecking']) && (function_exists('pspell_new') || (function_exists('enchant_broker_init') && ($txt['lang_charset'] == 'UTF-8' || function_exists('iconv')))); |
@@ -1606,11 +1667,12 @@ discard block |
||
| 1606 | 1667 | loadJavaScriptFile('spellcheck.js', array(), 'smf_spellcheck'); |
| 1607 | 1668 | |
| 1608 | 1669 | // Some hidden information is needed in order to make the spell checking work. |
| 1609 | - if (!isset($_REQUEST['xml'])) |
|
| 1610 | - $context['insert_after_template'] .= ' |
|
| 1670 | + if (!isset($_REQUEST['xml'])) { |
|
| 1671 | + $context['insert_after_template'] .= ' |
|
| 1611 | 1672 | <form name="spell_form" id="spell_form" method="post" accept-charset="' . $context['character_set'] . '" target="spellWindow" action="' . $scripturl . '?action=spellcheck"> |
| 1612 | 1673 | <input type="hidden" name="spellstring" value=""> |
| 1613 | 1674 | </form>'; |
| 1675 | + } |
|
| 1614 | 1676 | } |
| 1615 | 1677 | } |
| 1616 | 1678 | |
@@ -1776,10 +1838,12 @@ discard block |
||
| 1776 | 1838 | |
| 1777 | 1839 | // Generate a list of buttons that shouldn't be shown - this should be the fastest way to do this. |
| 1778 | 1840 | $disabled_tags = array(); |
| 1779 | - if (!empty($modSettings['disabledBBC'])) |
|
| 1780 | - $disabled_tags = explode(',', $modSettings['disabledBBC']); |
|
| 1781 | - if (empty($modSettings['enableEmbeddedFlash'])) |
|
| 1782 | - $disabled_tags[] = 'flash'; |
|
| 1841 | + if (!empty($modSettings['disabledBBC'])) { |
|
| 1842 | + $disabled_tags = explode(',', $modSettings['disabledBBC']); |
|
| 1843 | + } |
|
| 1844 | + if (empty($modSettings['enableEmbeddedFlash'])) { |
|
| 1845 | + $disabled_tags[] = 'flash'; |
|
| 1846 | + } |
|
| 1783 | 1847 | |
| 1784 | 1848 | foreach ($disabled_tags as $tag) |
| 1785 | 1849 | { |
@@ -1789,9 +1853,10 @@ discard block |
||
| 1789 | 1853 | $context['disabled_tags']['orderedlist'] = true; |
| 1790 | 1854 | } |
| 1791 | 1855 | |
| 1792 | - foreach ($editor_tag_map as $thisTag => $tagNameBBC) |
|
| 1793 | - if ($tag === $thisTag) |
|
| 1856 | + foreach ($editor_tag_map as $thisTag => $tagNameBBC) { |
|
| 1857 | + if ($tag === $thisTag) |
|
| 1794 | 1858 | $context['disabled_tags'][$tagNameBBC] = true; |
| 1859 | + } |
|
| 1795 | 1860 | |
| 1796 | 1861 | $context['disabled_tags'][trim($tag)] = true; |
| 1797 | 1862 | } |
@@ -1801,19 +1866,21 @@ discard block |
||
| 1801 | 1866 | $context['bbc_toolbar'] = array(); |
| 1802 | 1867 | foreach ($context['bbc_tags'] as $row => $tagRow) |
| 1803 | 1868 | { |
| 1804 | - if (!isset($context['bbc_toolbar'][$row])) |
|
| 1805 | - $context['bbc_toolbar'][$row] = array(); |
|
| 1869 | + if (!isset($context['bbc_toolbar'][$row])) { |
|
| 1870 | + $context['bbc_toolbar'][$row] = array(); |
|
| 1871 | + } |
|
| 1806 | 1872 | $tagsRow = array(); |
| 1807 | 1873 | foreach ($tagRow as $tag) |
| 1808 | 1874 | { |
| 1809 | 1875 | if ((!empty($tag['code'])) && empty($context['disabled_tags'][$tag['code']])) |
| 1810 | 1876 | { |
| 1811 | 1877 | $tagsRow[] = $tag['code']; |
| 1812 | - if (isset($tag['image'])) |
|
| 1813 | - $bbcodes_styles .= ' |
|
| 1878 | + if (isset($tag['image'])) { |
|
| 1879 | + $bbcodes_styles .= ' |
|
| 1814 | 1880 | .sceditor-button-' . $tag['code'] . ' div { |
| 1815 | 1881 | background: url(\'' . $settings['default_theme_url'] . '/images/bbc/' . $tag['image'] . '.png\'); |
| 1816 | 1882 | }'; |
| 1883 | + } |
|
| 1817 | 1884 | if (isset($tag['before'])) |
| 1818 | 1885 | { |
| 1819 | 1886 | $context['bbcodes_handlers'] .= ' |
@@ -1827,8 +1894,7 @@ discard block |
||
| 1827 | 1894 | });'; |
| 1828 | 1895 | } |
| 1829 | 1896 | |
| 1830 | - } |
|
| 1831 | - else |
|
| 1897 | + } else |
|
| 1832 | 1898 | { |
| 1833 | 1899 | $context['bbc_toolbar'][$row][] = implode(',', $tagsRow); |
| 1834 | 1900 | $tagsRow = array(); |
@@ -1839,14 +1905,16 @@ discard block |
||
| 1839 | 1905 | { |
| 1840 | 1906 | $context['bbc_toolbar'][$row][] = implode(',', $tagsRow); |
| 1841 | 1907 | $tagsRow = array(); |
| 1842 | - if (!isset($context['disabled_tags']['font'])) |
|
| 1843 | - $tagsRow[] = 'font'; |
|
| 1844 | - if (!isset($context['disabled_tags']['size'])) |
|
| 1845 | - $tagsRow[] = 'size'; |
|
| 1846 | - if (!isset($context['disabled_tags']['color'])) |
|
| 1847 | - $tagsRow[] = 'color'; |
|
| 1848 | - } |
|
| 1849 | - elseif ($row == 1 && empty($modSettings['disable_wysiwyg'])) |
|
| 1908 | + if (!isset($context['disabled_tags']['font'])) { |
|
| 1909 | + $tagsRow[] = 'font'; |
|
| 1910 | + } |
|
| 1911 | + if (!isset($context['disabled_tags']['size'])) { |
|
| 1912 | + $tagsRow[] = 'size'; |
|
| 1913 | + } |
|
| 1914 | + if (!isset($context['disabled_tags']['color'])) { |
|
| 1915 | + $tagsRow[] = 'color'; |
|
| 1916 | + } |
|
| 1917 | + } elseif ($row == 1 && empty($modSettings['disable_wysiwyg'])) |
|
| 1850 | 1918 | { |
| 1851 | 1919 | $tmp = array(); |
| 1852 | 1920 | $tagsRow[] = 'removeformat'; |
@@ -1857,13 +1925,15 @@ discard block |
||
| 1857 | 1925 | } |
| 1858 | 1926 | } |
| 1859 | 1927 | |
| 1860 | - if (!empty($tagsRow)) |
|
| 1861 | - $context['bbc_toolbar'][$row][] = implode(',', $tagsRow); |
|
| 1928 | + if (!empty($tagsRow)) { |
|
| 1929 | + $context['bbc_toolbar'][$row][] = implode(',', $tagsRow); |
|
| 1930 | + } |
|
| 1862 | 1931 | } |
| 1863 | - if (!empty($bbcodes_styles)) |
|
| 1864 | - $context['html_headers'] .= ' |
|
| 1932 | + if (!empty($bbcodes_styles)) { |
|
| 1933 | + $context['html_headers'] .= ' |
|
| 1865 | 1934 | <style>' . $bbcodes_styles . ' |
| 1866 | 1935 | </style>'; |
| 1936 | + } |
|
| 1867 | 1937 | } |
| 1868 | 1938 | |
| 1869 | 1939 | // Initialize smiley array... if not loaded before. |
@@ -1875,8 +1945,8 @@ discard block |
||
| 1875 | 1945 | ); |
| 1876 | 1946 | |
| 1877 | 1947 | // Load smileys - don't bother to run a query if we're not using the database's ones anyhow. |
| 1878 | - if (empty($modSettings['smiley_enable']) && $user_info['smiley_set'] != 'none') |
|
| 1879 | - $context['smileys']['postform'][] = array( |
|
| 1948 | + if (empty($modSettings['smiley_enable']) && $user_info['smiley_set'] != 'none') { |
|
| 1949 | + $context['smileys']['postform'][] = array( |
|
| 1880 | 1950 | 'smileys' => array( |
| 1881 | 1951 | array( |
| 1882 | 1952 | 'code' => ':)', |
@@ -1962,7 +2032,7 @@ discard block |
||
| 1962 | 2032 | ), |
| 1963 | 2033 | 'isLast' => true, |
| 1964 | 2034 | ); |
| 1965 | - elseif ($user_info['smiley_set'] != 'none') |
|
| 2035 | + } elseif ($user_info['smiley_set'] != 'none') |
|
| 1966 | 2036 | { |
| 1967 | 2037 | if (($temp = cache_get_data('posting_smileys', 480)) == null) |
| 1968 | 2038 | { |
@@ -1985,17 +2055,19 @@ discard block |
||
| 1985 | 2055 | |
| 1986 | 2056 | foreach ($context['smileys'] as $section => $smileyRows) |
| 1987 | 2057 | { |
| 1988 | - foreach ($smileyRows as $rowIndex => $smileys) |
|
| 1989 | - $context['smileys'][$section][$rowIndex]['smileys'][count($smileys['smileys']) - 1]['isLast'] = true; |
|
| 2058 | + foreach ($smileyRows as $rowIndex => $smileys) { |
|
| 2059 | + $context['smileys'][$section][$rowIndex]['smileys'][count($smileys['smileys']) - 1]['isLast'] = true; |
|
| 2060 | + } |
|
| 1990 | 2061 | |
| 1991 | - if (!empty($smileyRows)) |
|
| 1992 | - $context['smileys'][$section][count($smileyRows) - 1]['isLast'] = true; |
|
| 2062 | + if (!empty($smileyRows)) { |
|
| 2063 | + $context['smileys'][$section][count($smileyRows) - 1]['isLast'] = true; |
|
| 2064 | + } |
|
| 1993 | 2065 | } |
| 1994 | 2066 | |
| 1995 | 2067 | cache_put_data('posting_smileys', $context['smileys'], 480); |
| 2068 | + } else { |
|
| 2069 | + $context['smileys'] = $temp; |
|
| 1996 | 2070 | } |
| 1997 | - else |
|
| 1998 | - $context['smileys'] = $temp; |
|
| 1999 | 2071 | } |
| 2000 | 2072 | } |
| 2001 | 2073 | |
@@ -2021,8 +2093,9 @@ discard block |
||
| 2021 | 2093 | loadTemplate('GenericControls'); |
| 2022 | 2094 | |
| 2023 | 2095 | // Some javascript ma'am? |
| 2024 | - if (!empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual']))) |
|
| 2025 | - loadJavaScriptFile('captcha.js', array(), 'smf_captcha'); |
|
| 2096 | + if (!empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual']))) { |
|
| 2097 | + loadJavaScriptFile('captcha.js', array(), 'smf_captcha'); |
|
| 2098 | + } |
|
| 2026 | 2099 | |
| 2027 | 2100 | $context['use_graphic_library'] = in_array('gd', get_loaded_extensions()); |
| 2028 | 2101 | |
@@ -2035,8 +2108,8 @@ discard block |
||
| 2035 | 2108 | $isNew = !isset($context['controls']['verification'][$verificationOptions['id']]); |
| 2036 | 2109 | |
| 2037 | 2110 | // Log this into our collection. |
| 2038 | - if ($isNew) |
|
| 2039 | - $context['controls']['verification'][$verificationOptions['id']] = array( |
|
| 2111 | + if ($isNew) { |
|
| 2112 | + $context['controls']['verification'][$verificationOptions['id']] = array( |
|
| 2040 | 2113 | 'id' => $verificationOptions['id'], |
| 2041 | 2114 | 'empty_field' => empty($verificationOptions['no_empty_field']), |
| 2042 | 2115 | 'show_visual' => !empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual'])), |
@@ -2047,13 +2120,15 @@ discard block |
||
| 2047 | 2120 | 'questions' => array(), |
| 2048 | 2121 | 'can_recaptcha' => !empty($modSettings['recaptcha_enabled']) && !empty($modSettings['recaptcha_site_key']) && !empty($modSettings['recaptcha_secret_key']), |
| 2049 | 2122 | ); |
| 2123 | + } |
|
| 2050 | 2124 | $thisVerification = &$context['controls']['verification'][$verificationOptions['id']]; |
| 2051 | 2125 | |
| 2052 | 2126 | // Is there actually going to be anything? |
| 2053 | - if (empty($thisVerification['show_visual']) && empty($thisVerification['number_questions']) && empty($thisVerification['can_recaptcha'])) |
|
| 2054 | - return false; |
|
| 2055 | - elseif (!$isNew && !$do_test) |
|
| 2056 | - return true; |
|
| 2127 | + if (empty($thisVerification['show_visual']) && empty($thisVerification['number_questions']) && empty($thisVerification['can_recaptcha'])) { |
|
| 2128 | + return false; |
|
| 2129 | + } elseif (!$isNew && !$do_test) { |
|
| 2130 | + return true; |
|
| 2131 | + } |
|
| 2057 | 2132 | |
| 2058 | 2133 | // Sanitize reCAPTCHA fields? |
| 2059 | 2134 | if ($thisVerification['can_recaptcha']) |
@@ -2066,11 +2141,12 @@ discard block |
||
| 2066 | 2141 | } |
| 2067 | 2142 | |
| 2068 | 2143 | // Add javascript for the object. |
| 2069 | - if ($context['controls']['verification'][$verificationOptions['id']]['show_visual']) |
|
| 2070 | - $context['insert_after_template'] .= ' |
|
| 2144 | + if ($context['controls']['verification'][$verificationOptions['id']]['show_visual']) { |
|
| 2145 | + $context['insert_after_template'] .= ' |
|
| 2071 | 2146 | <script> |
| 2072 | 2147 | var verification' . $verificationOptions['id'] . 'Handle = new smfCaptcha("' . $thisVerification['image_href'] . '", "' . $verificationOptions['id'] . '", ' . ($context['use_graphic_library'] ? 1 : 0) . '); |
| 2073 | 2148 | </script>'; |
| 2149 | + } |
|
| 2074 | 2150 | |
| 2075 | 2151 | // If we want questions do we have a cache of all the IDs? |
| 2076 | 2152 | if (!empty($thisVerification['number_questions']) && empty($modSettings['question_id_cache'])) |
@@ -2093,8 +2169,9 @@ discard block |
||
| 2093 | 2169 | unset ($row['id_question']); |
| 2094 | 2170 | // Make them all lowercase. We can't directly use $smcFunc['strtolower'] with array_walk, so do it manually, eh? |
| 2095 | 2171 | $row['answers'] = smf_json_decode($row['answers'], true); |
| 2096 | - foreach ($row['answers'] as $k => $v) |
|
| 2097 | - $row['answers'][$k] = $smcFunc['strtolower']($v); |
|
| 2172 | + foreach ($row['answers'] as $k => $v) { |
|
| 2173 | + $row['answers'][$k] = $smcFunc['strtolower']($v); |
|
| 2174 | + } |
|
| 2098 | 2175 | |
| 2099 | 2176 | $modSettings['question_id_cache']['questions'][$id_question] = $row; |
| 2100 | 2177 | $modSettings['question_id_cache']['langs'][$row['lngfile']][] = $id_question; |
@@ -2105,35 +2182,42 @@ discard block |
||
| 2105 | 2182 | } |
| 2106 | 2183 | } |
| 2107 | 2184 | |
| 2108 | - if (!isset($_SESSION[$verificationOptions['id'] . '_vv'])) |
|
| 2109 | - $_SESSION[$verificationOptions['id'] . '_vv'] = array(); |
|
| 2185 | + if (!isset($_SESSION[$verificationOptions['id'] . '_vv'])) { |
|
| 2186 | + $_SESSION[$verificationOptions['id'] . '_vv'] = array(); |
|
| 2187 | + } |
|
| 2110 | 2188 | |
| 2111 | 2189 | // Do we need to refresh the verification? |
| 2112 | - if (!$do_test && (!empty($_SESSION[$verificationOptions['id'] . '_vv']['did_pass']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['count']) || $_SESSION[$verificationOptions['id'] . '_vv']['count'] > 3) && empty($verificationOptions['dont_refresh'])) |
|
| 2113 | - $force_refresh = true; |
|
| 2114 | - else |
|
| 2115 | - $force_refresh = false; |
|
| 2190 | + if (!$do_test && (!empty($_SESSION[$verificationOptions['id'] . '_vv']['did_pass']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['count']) || $_SESSION[$verificationOptions['id'] . '_vv']['count'] > 3) && empty($verificationOptions['dont_refresh'])) { |
|
| 2191 | + $force_refresh = true; |
|
| 2192 | + } else { |
|
| 2193 | + $force_refresh = false; |
|
| 2194 | + } |
|
| 2116 | 2195 | |
| 2117 | 2196 | // This can also force a fresh, although unlikely. |
| 2118 | - if (($thisVerification['show_visual'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['code'])) || ($thisVerification['number_questions'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['q']))) |
|
| 2119 | - $force_refresh = true; |
|
| 2197 | + if (($thisVerification['show_visual'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['code'])) || ($thisVerification['number_questions'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['q']))) { |
|
| 2198 | + $force_refresh = true; |
|
| 2199 | + } |
|
| 2120 | 2200 | |
| 2121 | 2201 | $verification_errors = array(); |
| 2122 | 2202 | // Start with any testing. |
| 2123 | 2203 | if ($do_test) |
| 2124 | 2204 | { |
| 2125 | 2205 | // This cannot happen! |
| 2126 | - if (!isset($_SESSION[$verificationOptions['id'] . '_vv']['count'])) |
|
| 2127 | - fatal_lang_error('no_access', false); |
|
| 2206 | + if (!isset($_SESSION[$verificationOptions['id'] . '_vv']['count'])) { |
|
| 2207 | + fatal_lang_error('no_access', false); |
|
| 2208 | + } |
|
| 2128 | 2209 | // ... nor this! |
| 2129 | - if ($thisVerification['number_questions'] && (!isset($_SESSION[$verificationOptions['id'] . '_vv']['q']) || !isset($_REQUEST[$verificationOptions['id'] . '_vv']['q']))) |
|
| 2130 | - fatal_lang_error('no_access', false); |
|
| 2210 | + if ($thisVerification['number_questions'] && (!isset($_SESSION[$verificationOptions['id'] . '_vv']['q']) || !isset($_REQUEST[$verificationOptions['id'] . '_vv']['q']))) { |
|
| 2211 | + fatal_lang_error('no_access', false); |
|
| 2212 | + } |
|
| 2131 | 2213 | // Hmm, it's requested but not actually declared. This shouldn't happen. |
| 2132 | - if ($thisVerification['empty_field'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field'])) |
|
| 2133 | - fatal_lang_error('no_access', false); |
|
| 2214 | + if ($thisVerification['empty_field'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field'])) { |
|
| 2215 | + fatal_lang_error('no_access', false); |
|
| 2216 | + } |
|
| 2134 | 2217 | // While we're here, did the user do something bad? |
| 2135 | - if ($thisVerification['empty_field'] && !empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']) && !empty($_REQUEST[$_SESSION[$verificationOptions['id'] . '_vv']['empty_field']])) |
|
| 2136 | - $verification_errors[] = 'wrong_verification_answer'; |
|
| 2218 | + if ($thisVerification['empty_field'] && !empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']) && !empty($_REQUEST[$_SESSION[$verificationOptions['id'] . '_vv']['empty_field']])) { |
|
| 2219 | + $verification_errors[] = 'wrong_verification_answer'; |
|
| 2220 | + } |
|
| 2137 | 2221 | |
| 2138 | 2222 | if ($thisVerification['can_recaptcha']) |
| 2139 | 2223 | { |
@@ -2144,22 +2228,25 @@ discard block |
||
| 2144 | 2228 | { |
| 2145 | 2229 | $resp = $reCaptcha->verify($_POST['g-recaptcha-response'], $user_info['ip']); |
| 2146 | 2230 | |
| 2147 | - if (!$resp->isSuccess()) |
|
| 2148 | - $verification_errors[] = 'wrong_verification_code'; |
|
| 2231 | + if (!$resp->isSuccess()) { |
|
| 2232 | + $verification_errors[] = 'wrong_verification_code'; |
|
| 2233 | + } |
|
| 2234 | + } else { |
|
| 2235 | + $verification_errors[] = 'wrong_verification_code'; |
|
| 2149 | 2236 | } |
| 2150 | - else |
|
| 2151 | - $verification_errors[] = 'wrong_verification_code'; |
|
| 2152 | 2237 | } |
| 2153 | - if ($thisVerification['show_visual'] && (empty($_REQUEST[$verificationOptions['id'] . '_vv']['code']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['code']) || strtoupper($_REQUEST[$verificationOptions['id'] . '_vv']['code']) !== $_SESSION[$verificationOptions['id'] . '_vv']['code'])) |
|
| 2154 | - $verification_errors[] = 'wrong_verification_code'; |
|
| 2238 | + if ($thisVerification['show_visual'] && (empty($_REQUEST[$verificationOptions['id'] . '_vv']['code']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['code']) || strtoupper($_REQUEST[$verificationOptions['id'] . '_vv']['code']) !== $_SESSION[$verificationOptions['id'] . '_vv']['code'])) { |
|
| 2239 | + $verification_errors[] = 'wrong_verification_code'; |
|
| 2240 | + } |
|
| 2155 | 2241 | if ($thisVerification['number_questions']) |
| 2156 | 2242 | { |
| 2157 | 2243 | $incorrectQuestions = array(); |
| 2158 | 2244 | foreach ($_SESSION[$verificationOptions['id'] . '_vv']['q'] as $q) |
| 2159 | 2245 | { |
| 2160 | 2246 | // We don't have this question any more, thus no answers. |
| 2161 | - if (!isset($modSettings['question_id_cache']['questions'][$q])) |
|
| 2162 | - continue; |
|
| 2247 | + if (!isset($modSettings['question_id_cache']['questions'][$q])) { |
|
| 2248 | + continue; |
|
| 2249 | + } |
|
| 2163 | 2250 | // This is quite complex. We have our question but it might have multiple answers. |
| 2164 | 2251 | // First, did they actually answer this question? |
| 2165 | 2252 | if (!isset($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q]) || trim($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q]) == '') |
@@ -2171,24 +2258,28 @@ discard block |
||
| 2171 | 2258 | else |
| 2172 | 2259 | { |
| 2173 | 2260 | $given_answer = trim($smcFunc['htmlspecialchars'](strtolower($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q]))); |
| 2174 | - if (!in_array($given_answer, $modSettings['question_id_cache']['questions'][$q]['answers'])) |
|
| 2175 | - $incorrectQuestions[] = $q; |
|
| 2261 | + if (!in_array($given_answer, $modSettings['question_id_cache']['questions'][$q]['answers'])) { |
|
| 2262 | + $incorrectQuestions[] = $q; |
|
| 2263 | + } |
|
| 2176 | 2264 | } |
| 2177 | 2265 | } |
| 2178 | 2266 | |
| 2179 | - if (!empty($incorrectQuestions)) |
|
| 2180 | - $verification_errors[] = 'wrong_verification_answer'; |
|
| 2267 | + if (!empty($incorrectQuestions)) { |
|
| 2268 | + $verification_errors[] = 'wrong_verification_answer'; |
|
| 2269 | + } |
|
| 2181 | 2270 | } |
| 2182 | 2271 | } |
| 2183 | 2272 | |
| 2184 | 2273 | // Any errors means we refresh potentially. |
| 2185 | 2274 | if (!empty($verification_errors)) |
| 2186 | 2275 | { |
| 2187 | - if (empty($_SESSION[$verificationOptions['id'] . '_vv']['errors'])) |
|
| 2188 | - $_SESSION[$verificationOptions['id'] . '_vv']['errors'] = 0; |
|
| 2276 | + if (empty($_SESSION[$verificationOptions['id'] . '_vv']['errors'])) { |
|
| 2277 | + $_SESSION[$verificationOptions['id'] . '_vv']['errors'] = 0; |
|
| 2278 | + } |
|
| 2189 | 2279 | // Too many errors? |
| 2190 | - elseif ($_SESSION[$verificationOptions['id'] . '_vv']['errors'] > $thisVerification['max_errors']) |
|
| 2191 | - $force_refresh = true; |
|
| 2280 | + elseif ($_SESSION[$verificationOptions['id'] . '_vv']['errors'] > $thisVerification['max_errors']) { |
|
| 2281 | + $force_refresh = true; |
|
| 2282 | + } |
|
| 2192 | 2283 | |
| 2193 | 2284 | // Keep a track of these. |
| 2194 | 2285 | $_SESSION[$verificationOptions['id'] . '_vv']['errors']++; |
@@ -2221,8 +2312,9 @@ discard block |
||
| 2221 | 2312 | // Are we overriding the range? |
| 2222 | 2313 | $character_range = !empty($verificationOptions['override_range']) ? $verificationOptions['override_range'] : $context['standard_captcha_range']; |
| 2223 | 2314 | |
| 2224 | - for ($i = 0; $i < 6; $i++) |
|
| 2225 | - $_SESSION[$verificationOptions['id'] . '_vv']['code'] .= $character_range[array_rand($character_range)]; |
|
| 2315 | + for ($i = 0; $i < 6; $i++) { |
|
| 2316 | + $_SESSION[$verificationOptions['id'] . '_vv']['code'] .= $character_range[array_rand($character_range)]; |
|
| 2317 | + } |
|
| 2226 | 2318 | } |
| 2227 | 2319 | |
| 2228 | 2320 | // Getting some new questions? |
@@ -2230,8 +2322,9 @@ discard block |
||
| 2230 | 2322 | { |
| 2231 | 2323 | // Attempt to try the current page's language, followed by the user's preference, followed by the site default. |
| 2232 | 2324 | $possible_langs = array(); |
| 2233 | - if (isset($_SESSION['language'])) |
|
| 2234 | - $possible_langs[] = strtr($_SESSION['language'], array('-utf8' => '')); |
|
| 2325 | + if (isset($_SESSION['language'])) { |
|
| 2326 | + $possible_langs[] = strtr($_SESSION['language'], array('-utf8' => '')); |
|
| 2327 | + } |
|
| 2235 | 2328 | if (!empty($user_info['language'])); |
| 2236 | 2329 | $possible_langs[] = $user_info['language']; |
| 2237 | 2330 | $possible_langs[] = $language; |
@@ -2250,8 +2343,7 @@ discard block |
||
| 2250 | 2343 | } |
| 2251 | 2344 | } |
| 2252 | 2345 | } |
| 2253 | - } |
|
| 2254 | - else |
|
| 2346 | + } else |
|
| 2255 | 2347 | { |
| 2256 | 2348 | // Same questions as before. |
| 2257 | 2349 | $questionIDs = !empty($_SESSION[$verificationOptions['id'] . '_vv']['q']) ? $_SESSION[$verificationOptions['id'] . '_vv']['q'] : array(); |
@@ -2261,8 +2353,9 @@ discard block |
||
| 2261 | 2353 | // If we do have an empty field, it would be nice to hide it from legitimate users who shouldn't be populating it anyway. |
| 2262 | 2354 | if (!empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field'])) |
| 2263 | 2355 | { |
| 2264 | - if (!isset($context['html_headers'])) |
|
| 2265 | - $context['html_headers'] = ''; |
|
| 2356 | + if (!isset($context['html_headers'])) { |
|
| 2357 | + $context['html_headers'] = ''; |
|
| 2358 | + } |
|
| 2266 | 2359 | $context['html_headers'] .= '<style>.vv_special { display:none; }</style>'; |
| 2267 | 2360 | } |
| 2268 | 2361 | |
@@ -2288,11 +2381,13 @@ discard block |
||
| 2288 | 2381 | $_SESSION[$verificationOptions['id'] . '_vv']['count'] = empty($_SESSION[$verificationOptions['id'] . '_vv']['count']) ? 1 : $_SESSION[$verificationOptions['id'] . '_vv']['count'] + 1; |
| 2289 | 2382 | |
| 2290 | 2383 | // Return errors if we have them. |
| 2291 | - if (!empty($verification_errors)) |
|
| 2292 | - return $verification_errors; |
|
| 2384 | + if (!empty($verification_errors)) { |
|
| 2385 | + return $verification_errors; |
|
| 2386 | + } |
|
| 2293 | 2387 | // If we had a test that one, make a note. |
| 2294 | - elseif ($do_test) |
|
| 2295 | - $_SESSION[$verificationOptions['id'] . '_vv']['did_pass'] = true; |
|
| 2388 | + elseif ($do_test) { |
|
| 2389 | + $_SESSION[$verificationOptions['id'] . '_vv']['did_pass'] = true; |
|
| 2390 | + } |
|
| 2296 | 2391 | |
| 2297 | 2392 | // Say that everything went well chaps. |
| 2298 | 2393 | return true; |
@@ -2317,8 +2412,9 @@ discard block |
||
| 2317 | 2412 | call_integration_hook('integrate_autosuggest', array(&$searchTypes)); |
| 2318 | 2413 | |
| 2319 | 2414 | // If we're just checking the callback function is registered return true or false. |
| 2320 | - if ($checkRegistered != null) |
|
| 2321 | - return isset($searchTypes[$checkRegistered]) && function_exists('AutoSuggest_Search_' . $checkRegistered); |
|
| 2415 | + if ($checkRegistered != null) { |
|
| 2416 | + return isset($searchTypes[$checkRegistered]) && function_exists('AutoSuggest_Search_' . $checkRegistered); |
|
| 2417 | + } |
|
| 2322 | 2418 | |
| 2323 | 2419 | checkSession('get'); |
| 2324 | 2420 | loadTemplate('Xml'); |
@@ -2469,24 +2565,27 @@ discard block |
||
| 2469 | 2565 | foreach ($possible_versions as $ver) |
| 2470 | 2566 | { |
| 2471 | 2567 | $ver = trim($ver); |
| 2472 | - if (strpos($ver, 'SMF') === 0) |
|
| 2473 | - $versions[] = $ver; |
|
| 2568 | + if (strpos($ver, 'SMF') === 0) { |
|
| 2569 | + $versions[] = $ver; |
|
| 2570 | + } |
|
| 2474 | 2571 | } |
| 2475 | 2572 | } |
| 2476 | 2573 | $smcFunc['db_free_result']($request); |
| 2477 | 2574 | |
| 2478 | 2575 | // Just in case we don't have ANYthing. |
| 2479 | - if (empty($versions)) |
|
| 2480 | - $versions = array('SMF 2.0'); |
|
| 2576 | + if (empty($versions)) { |
|
| 2577 | + $versions = array('SMF 2.0'); |
|
| 2578 | + } |
|
| 2481 | 2579 | |
| 2482 | - foreach ($versions as $id => $version) |
|
| 2483 | - if (strpos($version, strtoupper($_REQUEST['search'])) !== false) |
|
| 2580 | + foreach ($versions as $id => $version) { |
|
| 2581 | + if (strpos($version, strtoupper($_REQUEST['search'])) !== false) |
|
| 2484 | 2582 | $xml_data['items']['children'][] = array( |
| 2485 | 2583 | 'attributes' => array( |
| 2486 | 2584 | 'id' => $id, |
| 2487 | 2585 | ), |
| 2488 | 2586 | 'value' => $version, |
| 2489 | 2587 | ); |
| 2588 | + } |
|
| 2490 | 2589 | |
| 2491 | 2590 | return $xml_data; |
| 2492 | 2591 | } |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 3 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * Update some basic statistics. |
@@ -122,10 +123,11 @@ discard block |
||
| 122 | 123 | $smcFunc['db_free_result']($result); |
| 123 | 124 | |
| 124 | 125 | // Add this to the number of unapproved members |
| 125 | - if (!empty($changes['unapprovedMembers'])) |
|
| 126 | - $changes['unapprovedMembers'] += $coppa_approvals; |
|
| 127 | - else |
|
| 128 | - $changes['unapprovedMembers'] = $coppa_approvals; |
|
| 126 | + if (!empty($changes['unapprovedMembers'])) { |
|
| 127 | + $changes['unapprovedMembers'] += $coppa_approvals; |
|
| 128 | + } else { |
|
| 129 | + $changes['unapprovedMembers'] = $coppa_approvals; |
|
| 130 | + } |
|
| 129 | 131 | } |
| 130 | 132 | } |
| 131 | 133 | } |
@@ -133,9 +135,9 @@ discard block |
||
| 133 | 135 | break; |
| 134 | 136 | |
| 135 | 137 | case 'message': |
| 136 | - if ($parameter1 === true && $parameter2 !== null) |
|
| 137 | - updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true); |
|
| 138 | - else |
|
| 138 | + if ($parameter1 === true && $parameter2 !== null) { |
|
| 139 | + updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true); |
|
| 140 | + } else |
|
| 139 | 141 | { |
| 140 | 142 | // SUM and MAX on a smaller table is better for InnoDB tables. |
| 141 | 143 | $result = $smcFunc['db_query']('', ' |
@@ -175,23 +177,25 @@ discard block |
||
| 175 | 177 | $parameter2 = text2words($parameter2); |
| 176 | 178 | |
| 177 | 179 | $inserts = array(); |
| 178 | - foreach ($parameter2 as $word) |
|
| 179 | - $inserts[] = array($word, $parameter1); |
|
| 180 | + foreach ($parameter2 as $word) { |
|
| 181 | + $inserts[] = array($word, $parameter1); |
|
| 182 | + } |
|
| 180 | 183 | |
| 181 | - if (!empty($inserts)) |
|
| 182 | - $smcFunc['db_insert']('ignore', |
|
| 184 | + if (!empty($inserts)) { |
|
| 185 | + $smcFunc['db_insert']('ignore', |
|
| 183 | 186 | '{db_prefix}log_search_subjects', |
| 184 | 187 | array('word' => 'string', 'id_topic' => 'int'), |
| 185 | 188 | $inserts, |
| 186 | 189 | array('word', 'id_topic') |
| 187 | 190 | ); |
| 191 | + } |
|
| 188 | 192 | } |
| 189 | 193 | break; |
| 190 | 194 | |
| 191 | 195 | case 'topic': |
| 192 | - if ($parameter1 === true) |
|
| 193 | - updateSettings(array('totalTopics' => true), true); |
|
| 194 | - else |
|
| 196 | + if ($parameter1 === true) { |
|
| 197 | + updateSettings(array('totalTopics' => true), true); |
|
| 198 | + } else |
|
| 195 | 199 | { |
| 196 | 200 | // Get the number of topics - a SUM is better for InnoDB tables. |
| 197 | 201 | // We also ignore the recycle bin here because there will probably be a bunch of one-post topics there. |
@@ -212,8 +216,9 @@ discard block |
||
| 212 | 216 | |
| 213 | 217 | case 'postgroups': |
| 214 | 218 | // Parameter two is the updated columns: we should check to see if we base groups off any of these. |
| 215 | - if ($parameter2 !== null && !in_array('posts', $parameter2)) |
|
| 216 | - return; |
|
| 219 | + if ($parameter2 !== null && !in_array('posts', $parameter2)) { |
|
| 220 | + return; |
|
| 221 | + } |
|
| 217 | 222 | |
| 218 | 223 | $postgroups = cache_get_data('updateStats:postgroups', 360); |
| 219 | 224 | if ($postgroups == null || $parameter1 == null) |
@@ -228,8 +233,9 @@ discard block |
||
| 228 | 233 | ) |
| 229 | 234 | ); |
| 230 | 235 | $postgroups = array(); |
| 231 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 232 | - $postgroups[$row['id_group']] = $row['min_posts']; |
|
| 236 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 237 | + $postgroups[$row['id_group']] = $row['min_posts']; |
|
| 238 | + } |
|
| 233 | 239 | $smcFunc['db_free_result']($request); |
| 234 | 240 | |
| 235 | 241 | // Sort them this way because if it's done with MySQL it causes a filesort :(. |
@@ -239,8 +245,9 @@ discard block |
||
| 239 | 245 | } |
| 240 | 246 | |
| 241 | 247 | // Oh great, they've screwed their post groups. |
| 242 | - if (empty($postgroups)) |
|
| 243 | - return; |
|
| 248 | + if (empty($postgroups)) { |
|
| 249 | + return; |
|
| 250 | + } |
|
| 244 | 251 | |
| 245 | 252 | // Set all membergroups from most posts to least posts. |
| 246 | 253 | $conditions = ''; |
@@ -298,10 +305,9 @@ discard block |
||
| 298 | 305 | { |
| 299 | 306 | $condition = 'id_member IN ({array_int:members})'; |
| 300 | 307 | $parameters['members'] = $members; |
| 301 | - } |
|
| 302 | - elseif ($members === null) |
|
| 303 | - $condition = '1=1'; |
|
| 304 | - else |
|
| 308 | + } elseif ($members === null) { |
|
| 309 | + $condition = '1=1'; |
|
| 310 | + } else |
|
| 305 | 311 | { |
| 306 | 312 | $condition = 'id_member = {int:member}'; |
| 307 | 313 | $parameters['member'] = $members; |
@@ -341,9 +347,9 @@ discard block |
||
| 341 | 347 | if (count($vars_to_integrate) != 0) |
| 342 | 348 | { |
| 343 | 349 | // Fetch a list of member_names if necessary |
| 344 | - if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) |
|
| 345 | - $member_names = array($user_info['username']); |
|
| 346 | - else |
|
| 350 | + if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) { |
|
| 351 | + $member_names = array($user_info['username']); |
|
| 352 | + } else |
|
| 347 | 353 | { |
| 348 | 354 | $member_names = array(); |
| 349 | 355 | $request = $smcFunc['db_query']('', ' |
@@ -352,14 +358,16 @@ discard block |
||
| 352 | 358 | WHERE ' . $condition, |
| 353 | 359 | $parameters |
| 354 | 360 | ); |
| 355 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 356 | - $member_names[] = $row['member_name']; |
|
| 361 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 362 | + $member_names[] = $row['member_name']; |
|
| 363 | + } |
|
| 357 | 364 | $smcFunc['db_free_result']($request); |
| 358 | 365 | } |
| 359 | 366 | |
| 360 | - if (!empty($member_names)) |
|
| 361 | - foreach ($vars_to_integrate as $var) |
|
| 367 | + if (!empty($member_names)) { |
|
| 368 | + foreach ($vars_to_integrate as $var) |
|
| 362 | 369 | call_integration_hook('integrate_change_member_data', array($member_names, $var, &$data[$var], &$knownInts, &$knownFloats)); |
| 370 | + } |
|
| 363 | 371 | } |
| 364 | 372 | } |
| 365 | 373 | |
@@ -367,16 +375,17 @@ discard block |
||
| 367 | 375 | foreach ($data as $var => $val) |
| 368 | 376 | { |
| 369 | 377 | $type = 'string'; |
| 370 | - if (in_array($var, $knownInts)) |
|
| 371 | - $type = 'int'; |
|
| 372 | - elseif (in_array($var, $knownFloats)) |
|
| 373 | - $type = 'float'; |
|
| 374 | - elseif ($var == 'birthdate') |
|
| 375 | - $type = 'date'; |
|
| 376 | - elseif ($var == 'member_ip') |
|
| 377 | - $type = 'inet'; |
|
| 378 | - elseif ($var == 'member_ip2') |
|
| 379 | - $type = 'inet'; |
|
| 378 | + if (in_array($var, $knownInts)) { |
|
| 379 | + $type = 'int'; |
|
| 380 | + } elseif (in_array($var, $knownFloats)) { |
|
| 381 | + $type = 'float'; |
|
| 382 | + } elseif ($var == 'birthdate') { |
|
| 383 | + $type = 'date'; |
|
| 384 | + } elseif ($var == 'member_ip') { |
|
| 385 | + $type = 'inet'; |
|
| 386 | + } elseif ($var == 'member_ip2') { |
|
| 387 | + $type = 'inet'; |
|
| 388 | + } |
|
| 380 | 389 | |
| 381 | 390 | // Doing an increment? |
| 382 | 391 | if ($type == 'int' && ($val === '+' || $val === '-')) |
@@ -390,8 +399,9 @@ discard block |
||
| 390 | 399 | { |
| 391 | 400 | if (preg_match('~^' . $var . ' (\+ |- |\+ -)([\d]+)~', $val, $match)) |
| 392 | 401 | { |
| 393 | - if ($match[1] != '+ ') |
|
| 394 | - $val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END'; |
|
| 402 | + if ($match[1] != '+ ') { |
|
| 403 | + $val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END'; |
|
| 404 | + } |
|
| 395 | 405 | $type = 'raw'; |
| 396 | 406 | } |
| 397 | 407 | } |
@@ -412,8 +422,9 @@ discard block |
||
| 412 | 422 | // Clear any caching? |
| 413 | 423 | if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && !empty($members)) |
| 414 | 424 | { |
| 415 | - if (!is_array($members)) |
|
| 416 | - $members = array($members); |
|
| 425 | + if (!is_array($members)) { |
|
| 426 | + $members = array($members); |
|
| 427 | + } |
|
| 417 | 428 | |
| 418 | 429 | foreach ($members as $member) |
| 419 | 430 | { |
@@ -446,29 +457,32 @@ discard block |
||
| 446 | 457 | { |
| 447 | 458 | global $modSettings, $smcFunc; |
| 448 | 459 | |
| 449 | - if (empty($changeArray) || !is_array($changeArray)) |
|
| 450 | - return; |
|
| 460 | + if (empty($changeArray) || !is_array($changeArray)) { |
|
| 461 | + return; |
|
| 462 | + } |
|
| 451 | 463 | |
| 452 | 464 | $toRemove = array(); |
| 453 | 465 | |
| 454 | 466 | // Go check if there is any setting to be removed. |
| 455 | - foreach ($changeArray as $k => $v) |
|
| 456 | - if ($v === null) |
|
| 467 | + foreach ($changeArray as $k => $v) { |
|
| 468 | + if ($v === null) |
|
| 457 | 469 | { |
| 458 | 470 | // Found some, remove them from the original array and add them to ours. |
| 459 | 471 | unset($changeArray[$k]); |
| 472 | + } |
|
| 460 | 473 | $toRemove[] = $k; |
| 461 | 474 | } |
| 462 | 475 | |
| 463 | 476 | // Proceed with the deletion. |
| 464 | - if (!empty($toRemove)) |
|
| 465 | - $smcFunc['db_query']('', ' |
|
| 477 | + if (!empty($toRemove)) { |
|
| 478 | + $smcFunc['db_query']('', ' |
|
| 466 | 479 | DELETE FROM {db_prefix}settings |
| 467 | 480 | WHERE variable IN ({array_string:remove})', |
| 468 | 481 | array( |
| 469 | 482 | 'remove' => $toRemove, |
| 470 | 483 | ) |
| 471 | 484 | ); |
| 485 | + } |
|
| 472 | 486 | |
| 473 | 487 | // In some cases, this may be better and faster, but for large sets we don't want so many UPDATEs. |
| 474 | 488 | if ($update) |
@@ -497,19 +511,22 @@ discard block |
||
| 497 | 511 | foreach ($changeArray as $variable => $value) |
| 498 | 512 | { |
| 499 | 513 | // Don't bother if it's already like that ;). |
| 500 | - if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) |
|
| 501 | - continue; |
|
| 514 | + if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) { |
|
| 515 | + continue; |
|
| 516 | + } |
|
| 502 | 517 | // If the variable isn't set, but would only be set to nothing'ness, then don't bother setting it. |
| 503 | - elseif (!isset($modSettings[$variable]) && empty($value)) |
|
| 504 | - continue; |
|
| 518 | + elseif (!isset($modSettings[$variable]) && empty($value)) { |
|
| 519 | + continue; |
|
| 520 | + } |
|
| 505 | 521 | |
| 506 | 522 | $replaceArray[] = array($variable, $value); |
| 507 | 523 | |
| 508 | 524 | $modSettings[$variable] = $value; |
| 509 | 525 | } |
| 510 | 526 | |
| 511 | - if (empty($replaceArray)) |
|
| 512 | - return; |
|
| 527 | + if (empty($replaceArray)) { |
|
| 528 | + return; |
|
| 529 | + } |
|
| 513 | 530 | |
| 514 | 531 | $smcFunc['db_insert']('replace', |
| 515 | 532 | '{db_prefix}settings', |
@@ -555,14 +572,17 @@ discard block |
||
| 555 | 572 | $start_invalid = $start < 0; |
| 556 | 573 | |
| 557 | 574 | // Make sure $start is a proper variable - not less than 0. |
| 558 | - if ($start_invalid) |
|
| 559 | - $start = 0; |
|
| 575 | + if ($start_invalid) { |
|
| 576 | + $start = 0; |
|
| 577 | + } |
|
| 560 | 578 | // Not greater than the upper bound. |
| 561 | - elseif ($start >= $max_value) |
|
| 562 | - $start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page))); |
|
| 579 | + elseif ($start >= $max_value) { |
|
| 580 | + $start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page))); |
|
| 581 | + } |
|
| 563 | 582 | // And it has to be a multiple of $num_per_page! |
| 564 | - else |
|
| 565 | - $start = max(0, (int) $start - ((int) $start % (int) $num_per_page)); |
|
| 583 | + else { |
|
| 584 | + $start = max(0, (int) $start - ((int) $start % (int) $num_per_page)); |
|
| 585 | + } |
|
| 566 | 586 | |
| 567 | 587 | $context['current_page'] = $start / $num_per_page; |
| 568 | 588 | |
@@ -592,77 +612,87 @@ discard block |
||
| 592 | 612 | |
| 593 | 613 | // Show all the pages. |
| 594 | 614 | $display_page = 1; |
| 595 | - for ($counter = 0; $counter < $max_value; $counter += $num_per_page) |
|
| 596 | - $pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++); |
|
| 615 | + for ($counter = 0; $counter < $max_value; $counter += $num_per_page) { |
|
| 616 | + $pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++); |
|
| 617 | + } |
|
| 597 | 618 | |
| 598 | 619 | // Show the right arrow. |
| 599 | 620 | $display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page); |
| 600 | - if ($start != $counter - $max_value && !$start_invalid) |
|
| 601 | - $pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']); |
|
| 602 | - } |
|
| 603 | - else |
|
| 621 | + if ($start != $counter - $max_value && !$start_invalid) { |
|
| 622 | + $pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']); |
|
| 623 | + } |
|
| 624 | + } else |
|
| 604 | 625 | { |
| 605 | 626 | // If they didn't enter an odd value, pretend they did. |
| 606 | 627 | $PageContiguous = (int) ($modSettings['compactTopicPagesContiguous'] - ($modSettings['compactTopicPagesContiguous'] % 2)) / 2; |
| 607 | 628 | |
| 608 | 629 | // Show the "prev page" link. (>prev page< 1 ... 6 7 [8] 9 10 ... 15 next page) |
| 609 | - if (!empty($start) && $show_prevnext) |
|
| 610 | - $pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']); |
|
| 611 | - else |
|
| 612 | - $pageindex .= ''; |
|
| 630 | + if (!empty($start) && $show_prevnext) { |
|
| 631 | + $pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']); |
|
| 632 | + } else { |
|
| 633 | + $pageindex .= ''; |
|
| 634 | + } |
|
| 613 | 635 | |
| 614 | 636 | // Show the first page. (prev page >1< ... 6 7 [8] 9 10 ... 15) |
| 615 | - if ($start > $num_per_page * $PageContiguous) |
|
| 616 | - $pageindex .= sprintf($base_link, 0, '1'); |
|
| 637 | + if ($start > $num_per_page * $PageContiguous) { |
|
| 638 | + $pageindex .= sprintf($base_link, 0, '1'); |
|
| 639 | + } |
|
| 617 | 640 | |
| 618 | 641 | // Show the ... after the first page. (prev page 1 >...< 6 7 [8] 9 10 ... 15 next page) |
| 619 | - if ($start > $num_per_page * ($PageContiguous + 1)) |
|
| 620 | - $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
| 642 | + if ($start > $num_per_page * ($PageContiguous + 1)) { |
|
| 643 | + $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
| 621 | 644 | '{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)), |
| 622 | 645 | '{FIRST_PAGE}' => $num_per_page, |
| 623 | 646 | '{LAST_PAGE}' => $start - $num_per_page * $PageContiguous, |
| 624 | 647 | '{PER_PAGE}' => $num_per_page, |
| 625 | 648 | )); |
| 649 | + } |
|
| 626 | 650 | |
| 627 | 651 | // Show the pages before the current one. (prev page 1 ... >6 7< [8] 9 10 ... 15 next page) |
| 628 | - for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) |
|
| 629 | - if ($start >= $num_per_page * $nCont) |
|
| 652 | + for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) { |
|
| 653 | + if ($start >= $num_per_page * $nCont) |
|
| 630 | 654 | { |
| 631 | 655 | $tmpStart = $start - $num_per_page * $nCont; |
| 656 | + } |
|
| 632 | 657 | $pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1); |
| 633 | 658 | } |
| 634 | 659 | |
| 635 | 660 | // Show the current page. (prev page 1 ... 6 7 >[8]< 9 10 ... 15 next page) |
| 636 | - if (!$start_invalid) |
|
| 637 | - $pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1); |
|
| 638 | - else |
|
| 639 | - $pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1); |
|
| 661 | + if (!$start_invalid) { |
|
| 662 | + $pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1); |
|
| 663 | + } else { |
|
| 664 | + $pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1); |
|
| 665 | + } |
|
| 640 | 666 | |
| 641 | 667 | // Show the pages after the current one... (prev page 1 ... 6 7 [8] >9 10< ... 15 next page) |
| 642 | 668 | $tmpMaxPages = (int) (($max_value - 1) / $num_per_page) * $num_per_page; |
| 643 | - for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) |
|
| 644 | - if ($start + $num_per_page * $nCont <= $tmpMaxPages) |
|
| 669 | + for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) { |
|
| 670 | + if ($start + $num_per_page * $nCont <= $tmpMaxPages) |
|
| 645 | 671 | { |
| 646 | 672 | $tmpStart = $start + $num_per_page * $nCont; |
| 673 | + } |
|
| 647 | 674 | $pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1); |
| 648 | 675 | } |
| 649 | 676 | |
| 650 | 677 | // Show the '...' part near the end. (prev page 1 ... 6 7 [8] 9 10 >...< 15 next page) |
| 651 | - if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) |
|
| 652 | - $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
| 678 | + if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) { |
|
| 679 | + $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
| 653 | 680 | '{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)), |
| 654 | 681 | '{FIRST_PAGE}' => $start + $num_per_page * ($PageContiguous + 1), |
| 655 | 682 | '{LAST_PAGE}' => $tmpMaxPages, |
| 656 | 683 | '{PER_PAGE}' => $num_per_page, |
| 657 | 684 | )); |
| 685 | + } |
|
| 658 | 686 | |
| 659 | 687 | // Show the last number in the list. (prev page 1 ... 6 7 [8] 9 10 ... >15< next page) |
| 660 | - if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) |
|
| 661 | - $pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1); |
|
| 688 | + if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) { |
|
| 689 | + $pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1); |
|
| 690 | + } |
|
| 662 | 691 | |
| 663 | 692 | // Show the "next page" link. (prev page 1 ... 6 7 [8] 9 10 ... 15 >next page<) |
| 664 | - if ($start != $tmpMaxPages && $show_prevnext) |
|
| 665 | - $pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']); |
|
| 693 | + if ($start != $tmpMaxPages && $show_prevnext) { |
|
| 694 | + $pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']); |
|
| 695 | + } |
|
| 666 | 696 | } |
| 667 | 697 | $pageindex .= $settings['page_index']['extra_after']; |
| 668 | 698 | |
@@ -688,8 +718,9 @@ discard block |
||
| 688 | 718 | if ($decimal_separator === null) |
| 689 | 719 | { |
| 690 | 720 | // Not set for whatever reason? |
| 691 | - if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) |
|
| 692 | - return $number; |
|
| 721 | + if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) { |
|
| 722 | + return $number; |
|
| 723 | + } |
|
| 693 | 724 | |
| 694 | 725 | // Cache these each load... |
| 695 | 726 | $thousands_separator = $matches[1]; |
@@ -721,17 +752,20 @@ discard block |
||
| 721 | 752 | static $non_twelve_hour; |
| 722 | 753 | |
| 723 | 754 | // Offset the time. |
| 724 | - if (!$offset_type) |
|
| 725 | - $time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600; |
|
| 755 | + if (!$offset_type) { |
|
| 756 | + $time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600; |
|
| 757 | + } |
|
| 726 | 758 | // Just the forum offset? |
| 727 | - elseif ($offset_type == 'forum') |
|
| 728 | - $time = $log_time + $modSettings['time_offset'] * 3600; |
|
| 729 | - else |
|
| 730 | - $time = $log_time; |
|
| 759 | + elseif ($offset_type == 'forum') { |
|
| 760 | + $time = $log_time + $modSettings['time_offset'] * 3600; |
|
| 761 | + } else { |
|
| 762 | + $time = $log_time; |
|
| 763 | + } |
|
| 731 | 764 | |
| 732 | 765 | // We can't have a negative date (on Windows, at least.) |
| 733 | - if ($log_time < 0) |
|
| 734 | - $log_time = 0; |
|
| 766 | + if ($log_time < 0) { |
|
| 767 | + $log_time = 0; |
|
| 768 | + } |
|
| 735 | 769 | |
| 736 | 770 | // Today and Yesterday? |
| 737 | 771 | if ($modSettings['todayMod'] >= 1 && $show_today === true) |
@@ -748,46 +782,53 @@ discard block |
||
| 748 | 782 | { |
| 749 | 783 | $h = strpos($user_info['time_format'], '%l') === false ? '%I' : '%l'; |
| 750 | 784 | $today_fmt = $h . ':%M' . $s . ' %p'; |
| 785 | + } else { |
|
| 786 | + $today_fmt = '%H:%M' . $s; |
|
| 751 | 787 | } |
| 752 | - else |
|
| 753 | - $today_fmt = '%H:%M' . $s; |
|
| 754 | 788 | |
| 755 | 789 | // Same day of the year, same year.... Today! |
| 756 | - if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) |
|
| 757 | - return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type); |
|
| 790 | + if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) { |
|
| 791 | + return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type); |
|
| 792 | + } |
|
| 758 | 793 | |
| 759 | 794 | // Day-of-year is one less and same year, or it's the first of the year and that's the last of the year... |
| 760 | - if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31)) |
|
| 761 | - return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type); |
|
| 795 | + if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31)) { |
|
| 796 | + return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type); |
|
| 797 | + } |
|
| 762 | 798 | } |
| 763 | 799 | |
| 764 | 800 | $str = !is_bool($show_today) ? $show_today : $user_info['time_format']; |
| 765 | 801 | |
| 766 | 802 | if (setlocale(LC_TIME, $txt['lang_locale'])) |
| 767 | 803 | { |
| 768 | - if (!isset($non_twelve_hour)) |
|
| 769 | - $non_twelve_hour = trim(strftime('%p')) === ''; |
|
| 770 | - if ($non_twelve_hour && strpos($str, '%p') !== false) |
|
| 771 | - $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
| 804 | + if (!isset($non_twelve_hour)) { |
|
| 805 | + $non_twelve_hour = trim(strftime('%p')) === ''; |
|
| 806 | + } |
|
| 807 | + if ($non_twelve_hour && strpos($str, '%p') !== false) { |
|
| 808 | + $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
| 809 | + } |
|
| 772 | 810 | |
| 773 | - foreach (array('%a', '%A', '%b', '%B') as $token) |
|
| 774 | - if (strpos($str, $token) !== false) |
|
| 811 | + foreach (array('%a', '%A', '%b', '%B') as $token) { |
|
| 812 | + if (strpos($str, $token) !== false) |
|
| 775 | 813 | $str = str_replace($token, strftime($token, $time), $str); |
| 776 | - } |
|
| 777 | - else |
|
| 814 | + } |
|
| 815 | + } else |
|
| 778 | 816 | { |
| 779 | 817 | // Do-it-yourself time localization. Fun. |
| 780 | - foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) |
|
| 781 | - if (strpos($str, $token) !== false) |
|
| 818 | + foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) { |
|
| 819 | + if (strpos($str, $token) !== false) |
|
| 782 | 820 | $str = str_replace($token, $txt[$text_label][(int) strftime($token === '%a' || $token === '%A' ? '%w' : '%m', $time)], $str); |
| 821 | + } |
|
| 783 | 822 | |
| 784 | - if (strpos($str, '%p') !== false) |
|
| 785 | - $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
| 823 | + if (strpos($str, '%p') !== false) { |
|
| 824 | + $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
| 825 | + } |
|
| 786 | 826 | } |
| 787 | 827 | |
| 788 | 828 | // Windows doesn't support %e; on some versions, strftime fails altogether if used, so let's prevent that. |
| 789 | - if ($context['server']['is_windows'] && strpos($str, '%e') !== false) |
|
| 790 | - $str = str_replace('%e', ltrim(strftime('%d', $time), '0'), $str); |
|
| 829 | + if ($context['server']['is_windows'] && strpos($str, '%e') !== false) { |
|
| 830 | + $str = str_replace('%e', ltrim(strftime('%d', $time), '0'), $str); |
|
| 831 | + } |
|
| 791 | 832 | |
| 792 | 833 | // Format any other characters.. |
| 793 | 834 | return strftime($str, $time); |
@@ -809,16 +850,19 @@ discard block |
||
| 809 | 850 | static $translation = array(); |
| 810 | 851 | |
| 811 | 852 | // Determine the character set... Default to UTF-8 |
| 812 | - if (empty($context['character_set'])) |
|
| 813 | - $charset = 'UTF-8'; |
|
| 853 | + if (empty($context['character_set'])) { |
|
| 854 | + $charset = 'UTF-8'; |
|
| 855 | + } |
|
| 814 | 856 | // Use ISO-8859-1 in place of non-supported ISO-8859 charsets... |
| 815 | - elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) |
|
| 816 | - $charset = 'ISO-8859-1'; |
|
| 817 | - else |
|
| 818 | - $charset = $context['character_set']; |
|
| 857 | + elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) { |
|
| 858 | + $charset = 'ISO-8859-1'; |
|
| 859 | + } else { |
|
| 860 | + $charset = $context['character_set']; |
|
| 861 | + } |
|
| 819 | 862 | |
| 820 | - if (empty($translation)) |
|
| 821 | - $translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array(''' => '\'', ''' => '\'', ' ' => ' '); |
|
| 863 | + if (empty($translation)) { |
|
| 864 | + $translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array(''' => '\'', ''' => '\'', ' ' => ' '); |
|
| 865 | + } |
|
| 822 | 866 | |
| 823 | 867 | return strtr($string, $translation); |
| 824 | 868 | } |
@@ -840,8 +884,9 @@ discard block |
||
| 840 | 884 | global $smcFunc; |
| 841 | 885 | |
| 842 | 886 | // It was already short enough! |
| 843 | - if ($smcFunc['strlen']($subject) <= $len) |
|
| 844 | - return $subject; |
|
| 887 | + if ($smcFunc['strlen']($subject) <= $len) { |
|
| 888 | + return $subject; |
|
| 889 | + } |
|
| 845 | 890 | |
| 846 | 891 | // Shorten it by the length it was too long, and strip off junk from the end. |
| 847 | 892 | return $smcFunc['substr']($subject, 0, $len) . '...'; |
@@ -860,10 +905,11 @@ discard block |
||
| 860 | 905 | { |
| 861 | 906 | global $user_info, $modSettings; |
| 862 | 907 | |
| 863 | - if ($timestamp === null) |
|
| 864 | - $timestamp = time(); |
|
| 865 | - elseif ($timestamp == 0) |
|
| 866 | - return 0; |
|
| 908 | + if ($timestamp === null) { |
|
| 909 | + $timestamp = time(); |
|
| 910 | + } elseif ($timestamp == 0) { |
|
| 911 | + return 0; |
|
| 912 | + } |
|
| 867 | 913 | |
| 868 | 914 | return $timestamp + ($modSettings['time_offset'] + ($use_user_offset ? $user_info['time_offset'] : 0)) * 3600; |
| 869 | 915 | } |
@@ -892,8 +938,9 @@ discard block |
||
| 892 | 938 | $array[$i] = $array[$j]; |
| 893 | 939 | $array[$j] = $temp; |
| 894 | 940 | |
| 895 | - for ($i = 1; $p[$i] == 0; $i++) |
|
| 896 | - $p[$i] = 1; |
|
| 941 | + for ($i = 1; $p[$i] == 0; $i++) { |
|
| 942 | + $p[$i] = 1; |
|
| 943 | + } |
|
| 897 | 944 | |
| 898 | 945 | $orders[] = $array; |
| 899 | 946 | } |
@@ -925,12 +972,14 @@ discard block |
||
| 925 | 972 | static $disabled; |
| 926 | 973 | |
| 927 | 974 | // Don't waste cycles |
| 928 | - if ($message === '') |
|
| 929 | - return ''; |
|
| 975 | + if ($message === '') { |
|
| 976 | + return ''; |
|
| 977 | + } |
|
| 930 | 978 | |
| 931 | 979 | // Just in case it wasn't determined yet whether UTF-8 is enabled. |
| 932 | - if (!isset($context['utf8'])) |
|
| 933 | - $context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8'; |
|
| 980 | + if (!isset($context['utf8'])) { |
|
| 981 | + $context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8'; |
|
| 982 | + } |
|
| 934 | 983 | |
| 935 | 984 | // Clean up any cut/paste issues we may have |
| 936 | 985 | $message = sanitizeMSCutPaste($message); |
@@ -942,13 +991,15 @@ discard block |
||
| 942 | 991 | return $message; |
| 943 | 992 | } |
| 944 | 993 | |
| 945 | - if ($smileys !== null && ($smileys == '1' || $smileys == '0')) |
|
| 946 | - $smileys = (bool) $smileys; |
|
| 994 | + if ($smileys !== null && ($smileys == '1' || $smileys == '0')) { |
|
| 995 | + $smileys = (bool) $smileys; |
|
| 996 | + } |
|
| 947 | 997 | |
| 948 | 998 | if (empty($modSettings['enableBBC']) && $message !== false) |
| 949 | 999 | { |
| 950 | - if ($smileys === true) |
|
| 951 | - parsesmileys($message); |
|
| 1000 | + if ($smileys === true) { |
|
| 1001 | + parsesmileys($message); |
|
| 1002 | + } |
|
| 952 | 1003 | |
| 953 | 1004 | return $message; |
| 954 | 1005 | } |
@@ -961,8 +1012,9 @@ discard block |
||
| 961 | 1012 | } |
| 962 | 1013 | |
| 963 | 1014 | // Ensure $modSettings['tld_regex'] contains a valid regex for the autolinker |
| 964 | - if (!empty($modSettings['autoLinkUrls'])) |
|
| 965 | - set_tld_regex(); |
|
| 1015 | + if (!empty($modSettings['autoLinkUrls'])) { |
|
| 1016 | + set_tld_regex(); |
|
| 1017 | + } |
|
| 966 | 1018 | |
| 967 | 1019 | // Allow mods access before entering the main parse_bbc loop |
| 968 | 1020 | call_integration_hook('integrate_pre_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags)); |
@@ -976,12 +1028,14 @@ discard block |
||
| 976 | 1028 | |
| 977 | 1029 | $temp = explode(',', strtolower($modSettings['disabledBBC'])); |
| 978 | 1030 | |
| 979 | - foreach ($temp as $tag) |
|
| 980 | - $disabled[trim($tag)] = true; |
|
| 1031 | + foreach ($temp as $tag) { |
|
| 1032 | + $disabled[trim($tag)] = true; |
|
| 1033 | + } |
|
| 981 | 1034 | } |
| 982 | 1035 | |
| 983 | - if (empty($modSettings['enableEmbeddedFlash'])) |
|
| 984 | - $disabled['flash'] = true; |
|
| 1036 | + if (empty($modSettings['enableEmbeddedFlash'])) { |
|
| 1037 | + $disabled['flash'] = true; |
|
| 1038 | + } |
|
| 985 | 1039 | |
| 986 | 1040 | /* The following bbc are formatted as an array, with keys as follows: |
| 987 | 1041 | |
@@ -1102,8 +1156,9 @@ discard block |
||
| 1102 | 1156 | $returnContext = ''; |
| 1103 | 1157 | |
| 1104 | 1158 | // BBC or the entire attachments feature is disabled |
| 1105 | - if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) |
|
| 1106 | - return $data; |
|
| 1159 | + if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) { |
|
| 1160 | + return $data; |
|
| 1161 | + } |
|
| 1107 | 1162 | |
| 1108 | 1163 | // Save the attach ID. |
| 1109 | 1164 | $attachID = $data; |
@@ -1114,8 +1169,9 @@ discard block |
||
| 1114 | 1169 | $currentAttachment = parseAttachBBC($attachID); |
| 1115 | 1170 | |
| 1116 | 1171 | // parseAttachBBC will return a string ($txt key) rather than diying with a fatal_error. Up to you to decide what to do. |
| 1117 | - if (is_string($currentAttachment)) |
|
| 1118 | - return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment; |
|
| 1172 | + if (is_string($currentAttachment)) { |
|
| 1173 | + return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment; |
|
| 1174 | + } |
|
| 1119 | 1175 | |
| 1120 | 1176 | if (!empty($currentAttachment['is_image'])) |
| 1121 | 1177 | { |
@@ -1131,15 +1187,17 @@ discard block |
||
| 1131 | 1187 | $height = ' height="' . $currentAttachment['height'] . '"'; |
| 1132 | 1188 | } |
| 1133 | 1189 | |
| 1134 | - if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) |
|
| 1135 | - $returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>'; |
|
| 1136 | - else |
|
| 1137 | - $returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>'; |
|
| 1190 | + if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) { |
|
| 1191 | + $returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>'; |
|
| 1192 | + } else { |
|
| 1193 | + $returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>'; |
|
| 1194 | + } |
|
| 1138 | 1195 | } |
| 1139 | 1196 | |
| 1140 | 1197 | // No image. Show a link. |
| 1141 | - else |
|
| 1142 | - $returnContext .= $currentAttachment['link']; |
|
| 1198 | + else { |
|
| 1199 | + $returnContext .= $currentAttachment['link']; |
|
| 1200 | + } |
|
| 1143 | 1201 | |
| 1144 | 1202 | // Gotta append what we just did. |
| 1145 | 1203 | $data = $returnContext; |
@@ -1170,8 +1228,9 @@ discard block |
||
| 1170 | 1228 | for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++) |
| 1171 | 1229 | { |
| 1172 | 1230 | // Do PHP code coloring? |
| 1173 | - if ($php_parts[$php_i] != '<?php') |
|
| 1174 | - continue; |
|
| 1231 | + if ($php_parts[$php_i] != '<?php') { |
|
| 1232 | + continue; |
|
| 1233 | + } |
|
| 1175 | 1234 | |
| 1176 | 1235 | $php_string = ''; |
| 1177 | 1236 | while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?>') |
@@ -1187,8 +1246,9 @@ discard block |
||
| 1187 | 1246 | $data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data); |
| 1188 | 1247 | |
| 1189 | 1248 | // Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection. |
| 1190 | - if ($context['browser']['is_opera']) |
|
| 1191 | - $data .= ' '; |
|
| 1249 | + if ($context['browser']['is_opera']) { |
|
| 1250 | + $data .= ' '; |
|
| 1251 | + } |
|
| 1192 | 1252 | } |
| 1193 | 1253 | }, |
| 1194 | 1254 | 'block_level' => true, |
@@ -1207,8 +1267,9 @@ discard block |
||
| 1207 | 1267 | for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++) |
| 1208 | 1268 | { |
| 1209 | 1269 | // Do PHP code coloring? |
| 1210 | - if ($php_parts[$php_i] != '<?php') |
|
| 1211 | - continue; |
|
| 1270 | + if ($php_parts[$php_i] != '<?php') { |
|
| 1271 | + continue; |
|
| 1272 | + } |
|
| 1212 | 1273 | |
| 1213 | 1274 | $php_string = ''; |
| 1214 | 1275 | while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?>') |
@@ -1224,8 +1285,9 @@ discard block |
||
| 1224 | 1285 | $data[0] = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data[0]); |
| 1225 | 1286 | |
| 1226 | 1287 | // Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection. |
| 1227 | - if ($context['browser']['is_opera']) |
|
| 1228 | - $data[0] .= ' '; |
|
| 1288 | + if ($context['browser']['is_opera']) { |
|
| 1289 | + $data[0] .= ' '; |
|
| 1290 | + } |
|
| 1229 | 1291 | } |
| 1230 | 1292 | }, |
| 1231 | 1293 | 'block_level' => true, |
@@ -1263,11 +1325,13 @@ discard block |
||
| 1263 | 1325 | 'content' => '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never">', |
| 1264 | 1326 | 'validate' => function (&$tag, &$data, $disabled) |
| 1265 | 1327 | { |
| 1266 | - if (isset($disabled['url'])) |
|
| 1267 | - $tag['content'] = '$1'; |
|
| 1328 | + if (isset($disabled['url'])) { |
|
| 1329 | + $tag['content'] = '$1'; |
|
| 1330 | + } |
|
| 1268 | 1331 | $scheme = parse_url($data[0], PHP_URL_SCHEME); |
| 1269 | - if (empty($scheme)) |
|
| 1270 | - $data[0] = '//' . ltrim($data[0], ':/'); |
|
| 1332 | + if (empty($scheme)) { |
|
| 1333 | + $data[0] = '//' . ltrim($data[0], ':/'); |
|
| 1334 | + } |
|
| 1271 | 1335 | }, |
| 1272 | 1336 | 'disabled_content' => '<a href="$1" target="_blank" class="new_win">$1</a>', |
| 1273 | 1337 | ), |
@@ -1281,10 +1345,11 @@ discard block |
||
| 1281 | 1345 | { |
| 1282 | 1346 | $class = 'class="bbc_float float' . (strpos($data, 'left') === 0 ? 'left' : 'right') . '"'; |
| 1283 | 1347 | |
| 1284 | - if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches)) |
|
| 1285 | - $css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"'; |
|
| 1286 | - else |
|
| 1287 | - $css = ''; |
|
| 1348 | + if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches)) { |
|
| 1349 | + $css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"'; |
|
| 1350 | + } else { |
|
| 1351 | + $css = ''; |
|
| 1352 | + } |
|
| 1288 | 1353 | |
| 1289 | 1354 | $data = $class . $css; |
| 1290 | 1355 | }, |
@@ -1334,14 +1399,16 @@ discard block |
||
| 1334 | 1399 | $scheme = parse_url($data, PHP_URL_SCHEME); |
| 1335 | 1400 | if ($image_proxy_enabled) |
| 1336 | 1401 | { |
| 1337 | - if (empty($scheme)) |
|
| 1338 | - $data = 'http://' . ltrim($data, ':/'); |
|
| 1402 | + if (empty($scheme)) { |
|
| 1403 | + $data = 'http://' . ltrim($data, ':/'); |
|
| 1404 | + } |
|
| 1339 | 1405 | |
| 1340 | - if ($scheme != 'https') |
|
| 1341 | - $data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret); |
|
| 1406 | + if ($scheme != 'https') { |
|
| 1407 | + $data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret); |
|
| 1408 | + } |
|
| 1409 | + } elseif (empty($scheme)) { |
|
| 1410 | + $data = '//' . ltrim($data, ':/'); |
|
| 1342 | 1411 | } |
| 1343 | - elseif (empty($scheme)) |
|
| 1344 | - $data = '//' . ltrim($data, ':/'); |
|
| 1345 | 1412 | }, |
| 1346 | 1413 | 'disabled_content' => '($1)', |
| 1347 | 1414 | ), |
@@ -1357,14 +1424,16 @@ discard block |
||
| 1357 | 1424 | $scheme = parse_url($data, PHP_URL_SCHEME); |
| 1358 | 1425 | if ($image_proxy_enabled) |
| 1359 | 1426 | { |
| 1360 | - if (empty($scheme)) |
|
| 1361 | - $data = 'http://' . ltrim($data, ':/'); |
|
| 1427 | + if (empty($scheme)) { |
|
| 1428 | + $data = 'http://' . ltrim($data, ':/'); |
|
| 1429 | + } |
|
| 1362 | 1430 | |
| 1363 | - if ($scheme != 'https') |
|
| 1364 | - $data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret); |
|
| 1431 | + if ($scheme != 'https') { |
|
| 1432 | + $data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret); |
|
| 1433 | + } |
|
| 1434 | + } elseif (empty($scheme)) { |
|
| 1435 | + $data = '//' . ltrim($data, ':/'); |
|
| 1365 | 1436 | } |
| 1366 | - elseif (empty($scheme)) |
|
| 1367 | - $data = '//' . ltrim($data, ':/'); |
|
| 1368 | 1437 | }, |
| 1369 | 1438 | 'disabled_content' => '($1)', |
| 1370 | 1439 | ), |
@@ -1376,8 +1445,9 @@ discard block |
||
| 1376 | 1445 | { |
| 1377 | 1446 | $data = strtr($data, array('<br>' => '')); |
| 1378 | 1447 | $scheme = parse_url($data, PHP_URL_SCHEME); |
| 1379 | - if (empty($scheme)) |
|
| 1380 | - $data = '//' . ltrim($data, ':/'); |
|
| 1448 | + if (empty($scheme)) { |
|
| 1449 | + $data = '//' . ltrim($data, ':/'); |
|
| 1450 | + } |
|
| 1381 | 1451 | }, |
| 1382 | 1452 | ), |
| 1383 | 1453 | array( |
@@ -1388,13 +1458,14 @@ discard block |
||
| 1388 | 1458 | 'after' => '</a>', |
| 1389 | 1459 | 'validate' => function (&$tag, &$data, $disabled) |
| 1390 | 1460 | { |
| 1391 | - if (substr($data, 0, 1) == '#') |
|
| 1392 | - $data = '#post_' . substr($data, 1); |
|
| 1393 | - else |
|
| 1461 | + if (substr($data, 0, 1) == '#') { |
|
| 1462 | + $data = '#post_' . substr($data, 1); |
|
| 1463 | + } else |
|
| 1394 | 1464 | { |
| 1395 | 1465 | $scheme = parse_url($data, PHP_URL_SCHEME); |
| 1396 | - if (empty($scheme)) |
|
| 1397 | - $data = '//' . ltrim($data, ':/'); |
|
| 1466 | + if (empty($scheme)) { |
|
| 1467 | + $data = '//' . ltrim($data, ':/'); |
|
| 1468 | + } |
|
| 1398 | 1469 | } |
| 1399 | 1470 | }, |
| 1400 | 1471 | 'disallow_children' => array('email', 'ftp', 'url', 'iurl'), |
@@ -1472,8 +1543,9 @@ discard block |
||
| 1472 | 1543 | { |
| 1473 | 1544 | $add_begin = substr(trim($data), 0, 5) != '<?'; |
| 1474 | 1545 | $data = highlight_php_code($add_begin ? '<?php ' . $data . '?>' : $data); |
| 1475 | - if ($add_begin) |
|
| 1476 | - $data = preg_replace(array('~^(.+?)<\?.{0,40}?php(?: |\s)~', '~\?>((?:</(font|span)>)*)$~'), '$1', $data, 2); |
|
| 1546 | + if ($add_begin) { |
|
| 1547 | + $data = preg_replace(array('~^(.+?)<\?.{0,40}?php(?: |\s)~', '~\?>((?:</(font|span)>)*)$~'), '$1', $data, 2); |
|
| 1548 | + } |
|
| 1477 | 1549 | } |
| 1478 | 1550 | }, |
| 1479 | 1551 | 'block_level' => false, |
@@ -1604,10 +1676,11 @@ discard block |
||
| 1604 | 1676 | 'content' => '$1', |
| 1605 | 1677 | 'validate' => function (&$tag, &$data, $disabled) |
| 1606 | 1678 | { |
| 1607 | - if (is_numeric($data)) |
|
| 1608 | - $data = timeformat($data); |
|
| 1609 | - else |
|
| 1610 | - $tag['content'] = '[time]$1[/time]'; |
|
| 1679 | + if (is_numeric($data)) { |
|
| 1680 | + $data = timeformat($data); |
|
| 1681 | + } else { |
|
| 1682 | + $tag['content'] = '[time]$1[/time]'; |
|
| 1683 | + } |
|
| 1611 | 1684 | }, |
| 1612 | 1685 | ), |
| 1613 | 1686 | array( |
@@ -1634,8 +1707,9 @@ discard block |
||
| 1634 | 1707 | { |
| 1635 | 1708 | $data = strtr($data, array('<br>' => '')); |
| 1636 | 1709 | $scheme = parse_url($data, PHP_URL_SCHEME); |
| 1637 | - if (empty($scheme)) |
|
| 1638 | - $data = '//' . ltrim($data, ':/'); |
|
| 1710 | + if (empty($scheme)) { |
|
| 1711 | + $data = '//' . ltrim($data, ':/'); |
|
| 1712 | + } |
|
| 1639 | 1713 | }, |
| 1640 | 1714 | ), |
| 1641 | 1715 | array( |
@@ -1647,8 +1721,9 @@ discard block |
||
| 1647 | 1721 | 'validate' => function (&$tag, &$data, $disabled) |
| 1648 | 1722 | { |
| 1649 | 1723 | $scheme = parse_url($data, PHP_URL_SCHEME); |
| 1650 | - if (empty($scheme)) |
|
| 1651 | - $data = '//' . ltrim($data, ':/'); |
|
| 1724 | + if (empty($scheme)) { |
|
| 1725 | + $data = '//' . ltrim($data, ':/'); |
|
| 1726 | + } |
|
| 1652 | 1727 | }, |
| 1653 | 1728 | 'disallow_children' => array('email', 'ftp', 'url', 'iurl'), |
| 1654 | 1729 | 'disabled_after' => ' ($1)', |
@@ -1668,8 +1743,9 @@ discard block |
||
| 1668 | 1743 | // This is mainly for the bbc manager, so it's easy to add tags above. Custom BBC should be added above this line. |
| 1669 | 1744 | if ($message === false) |
| 1670 | 1745 | { |
| 1671 | - if (isset($temp_bbc)) |
|
| 1672 | - $bbc_codes = $temp_bbc; |
|
| 1746 | + if (isset($temp_bbc)) { |
|
| 1747 | + $bbc_codes = $temp_bbc; |
|
| 1748 | + } |
|
| 1673 | 1749 | usort($codes, function ($a, $b) { |
| 1674 | 1750 | return strcmp($a['tag'], $b['tag']); |
| 1675 | 1751 | }); |
@@ -1689,8 +1765,9 @@ discard block |
||
| 1689 | 1765 | ); |
| 1690 | 1766 | if (!isset($disabled['li']) && !isset($disabled['list'])) |
| 1691 | 1767 | { |
| 1692 | - foreach ($itemcodes as $c => $dummy) |
|
| 1693 | - $bbc_codes[$c] = array(); |
|
| 1768 | + foreach ($itemcodes as $c => $dummy) { |
|
| 1769 | + $bbc_codes[$c] = array(); |
|
| 1770 | + } |
|
| 1694 | 1771 | } |
| 1695 | 1772 | |
| 1696 | 1773 | // Shhhh! |
@@ -1711,12 +1788,14 @@ discard block |
||
| 1711 | 1788 | foreach ($codes as $code) |
| 1712 | 1789 | { |
| 1713 | 1790 | // Make it easier to process parameters later |
| 1714 | - if (!empty($code['parameters'])) |
|
| 1715 | - ksort($code['parameters'], SORT_STRING); |
|
| 1791 | + if (!empty($code['parameters'])) { |
|
| 1792 | + ksort($code['parameters'], SORT_STRING); |
|
| 1793 | + } |
|
| 1716 | 1794 | |
| 1717 | 1795 | // If we are not doing every tag only do ones we are interested in. |
| 1718 | - if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) |
|
| 1719 | - $bbc_codes[substr($code['tag'], 0, 1)][] = $code; |
|
| 1796 | + if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) { |
|
| 1797 | + $bbc_codes[substr($code['tag'], 0, 1)][] = $code; |
|
| 1798 | + } |
|
| 1720 | 1799 | } |
| 1721 | 1800 | $codes = null; |
| 1722 | 1801 | } |
@@ -1727,8 +1806,9 @@ discard block |
||
| 1727 | 1806 | // It's likely this will change if the message is modified. |
| 1728 | 1807 | $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']); |
| 1729 | 1808 | |
| 1730 | - if (($temp = cache_get_data($cache_key, 240)) != null) |
|
| 1731 | - return $temp; |
|
| 1809 | + if (($temp = cache_get_data($cache_key, 240)) != null) { |
|
| 1810 | + return $temp; |
|
| 1811 | + } |
|
| 1732 | 1812 | |
| 1733 | 1813 | $cache_t = microtime(); |
| 1734 | 1814 | } |
@@ -1760,8 +1840,9 @@ discard block |
||
| 1760 | 1840 | $disabled['flash'] = true; |
| 1761 | 1841 | |
| 1762 | 1842 | // @todo Change maybe? |
| 1763 | - if (!isset($_GET['images'])) |
|
| 1764 | - $disabled['img'] = true; |
|
| 1843 | + if (!isset($_GET['images'])) { |
|
| 1844 | + $disabled['img'] = true; |
|
| 1845 | + } |
|
| 1765 | 1846 | |
| 1766 | 1847 | // @todo Interface/setting to add more? |
| 1767 | 1848 | } |
@@ -1785,8 +1866,9 @@ discard block |
||
| 1785 | 1866 | $pos = isset($matches[0][1]) ? $matches[0][1] : false; |
| 1786 | 1867 | |
| 1787 | 1868 | // Failsafe. |
| 1788 | - if ($pos === false || $last_pos > $pos) |
|
| 1789 | - $pos = strlen($message) + 1; |
|
| 1869 | + if ($pos === false || $last_pos > $pos) { |
|
| 1870 | + $pos = strlen($message) + 1; |
|
| 1871 | + } |
|
| 1790 | 1872 | |
| 1791 | 1873 | // Can't have a one letter smiley, URL, or email! (sorry.) |
| 1792 | 1874 | if ($last_pos < $pos - 1) |
@@ -1805,8 +1887,9 @@ discard block |
||
| 1805 | 1887 | |
| 1806 | 1888 | // <br> should be empty. |
| 1807 | 1889 | $empty_tags = array('br', 'hr'); |
| 1808 | - foreach ($empty_tags as $tag) |
|
| 1809 | - $data = str_replace(array('<' . $tag . '>', '<' . $tag . '/>', '<' . $tag . ' />'), '[' . $tag . ' /]', $data); |
|
| 1890 | + foreach ($empty_tags as $tag) { |
|
| 1891 | + $data = str_replace(array('<' . $tag . '>', '<' . $tag . '/>', '<' . $tag . ' />'), '[' . $tag . ' /]', $data); |
|
| 1892 | + } |
|
| 1810 | 1893 | |
| 1811 | 1894 | // b, u, i, s, pre... basic tags. |
| 1812 | 1895 | $closable_tags = array('b', 'u', 'i', 's', 'em', 'ins', 'del', 'pre', 'blockquote'); |
@@ -1815,8 +1898,9 @@ discard block |
||
| 1815 | 1898 | $diff = substr_count($data, '<' . $tag . '>') - substr_count($data, '</' . $tag . '>'); |
| 1816 | 1899 | $data = strtr($data, array('<' . $tag . '>' => '<' . $tag . '>', '</' . $tag . '>' => '</' . $tag . '>')); |
| 1817 | 1900 | |
| 1818 | - if ($diff > 0) |
|
| 1819 | - $data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1); |
|
| 1901 | + if ($diff > 0) { |
|
| 1902 | + $data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1); |
|
| 1903 | + } |
|
| 1820 | 1904 | } |
| 1821 | 1905 | |
| 1822 | 1906 | // Do <img ...> - with security... action= -> action-. |
@@ -1829,8 +1913,9 @@ discard block |
||
| 1829 | 1913 | $alt = empty($matches[3][$match]) ? '' : ' alt=' . preg_replace('~^"|"$~', '', $matches[3][$match]); |
| 1830 | 1914 | |
| 1831 | 1915 | // Remove action= from the URL - no funny business, now. |
| 1832 | - if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) |
|
| 1833 | - $imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag); |
|
| 1916 | + if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) { |
|
| 1917 | + $imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag); |
|
| 1918 | + } |
|
| 1834 | 1919 | |
| 1835 | 1920 | // Check if the image is larger than allowed. |
| 1836 | 1921 | if (!empty($modSettings['max_image_width']) && !empty($modSettings['max_image_height'])) |
@@ -1851,9 +1936,9 @@ discard block |
||
| 1851 | 1936 | |
| 1852 | 1937 | // Set the new image tag. |
| 1853 | 1938 | $replaces[$matches[0][$match]] = '[img width=' . $width . ' height=' . $height . $alt . ']' . $imgtag . '[/img]'; |
| 1939 | + } else { |
|
| 1940 | + $replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]'; |
|
| 1854 | 1941 | } |
| 1855 | - else |
|
| 1856 | - $replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]'; |
|
| 1857 | 1942 | } |
| 1858 | 1943 | |
| 1859 | 1944 | $data = strtr($data, $replaces); |
@@ -1866,16 +1951,18 @@ discard block |
||
| 1866 | 1951 | $no_autolink_area = false; |
| 1867 | 1952 | if (!empty($open_tags)) |
| 1868 | 1953 | { |
| 1869 | - foreach ($open_tags as $open_tag) |
|
| 1870 | - if (in_array($open_tag['tag'], $no_autolink_tags)) |
|
| 1954 | + foreach ($open_tags as $open_tag) { |
|
| 1955 | + if (in_array($open_tag['tag'], $no_autolink_tags)) |
|
| 1871 | 1956 | $no_autolink_area = true; |
| 1957 | + } |
|
| 1872 | 1958 | } |
| 1873 | 1959 | |
| 1874 | 1960 | // Don't go backwards. |
| 1875 | 1961 | // @todo Don't think is the real solution.... |
| 1876 | 1962 | $lastAutoPos = isset($lastAutoPos) ? $lastAutoPos : 0; |
| 1877 | - if ($pos < $lastAutoPos) |
|
| 1878 | - $no_autolink_area = true; |
|
| 1963 | + if ($pos < $lastAutoPos) { |
|
| 1964 | + $no_autolink_area = true; |
|
| 1965 | + } |
|
| 1879 | 1966 | $lastAutoPos = $pos; |
| 1880 | 1967 | |
| 1881 | 1968 | if (!$no_autolink_area) |
@@ -1984,17 +2071,19 @@ discard block |
||
| 1984 | 2071 | if ($scheme == 'mailto') |
| 1985 | 2072 | { |
| 1986 | 2073 | $email_address = str_replace('mailto:', '', $url); |
| 1987 | - if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) |
|
| 1988 | - return '[email=' . $email_address . ']' . $url . '[/email]'; |
|
| 1989 | - else |
|
| 1990 | - return $url; |
|
| 2074 | + if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) { |
|
| 2075 | + return '[email=' . $email_address . ']' . $url . '[/email]'; |
|
| 2076 | + } else { |
|
| 2077 | + return $url; |
|
| 2078 | + } |
|
| 1991 | 2079 | } |
| 1992 | 2080 | |
| 1993 | 2081 | // Are we linking a schemeless URL or naked domain name (e.g. "example.com")? |
| 1994 | - if (empty($scheme)) |
|
| 1995 | - $fullUrl = '//' . ltrim($url, ':/'); |
|
| 1996 | - else |
|
| 1997 | - $fullUrl = $url; |
|
| 2082 | + if (empty($scheme)) { |
|
| 2083 | + $fullUrl = '//' . ltrim($url, ':/'); |
|
| 2084 | + } else { |
|
| 2085 | + $fullUrl = $url; |
|
| 2086 | + } |
|
| 1998 | 2087 | |
| 1999 | 2088 | return '[url="' . str_replace(array('[', ']'), array('[', ']'), $fullUrl) . '"]' . $url . '[/url]'; |
| 2000 | 2089 | }, $data); |
@@ -2043,16 +2132,18 @@ discard block |
||
| 2043 | 2132 | } |
| 2044 | 2133 | |
| 2045 | 2134 | // Are we there yet? Are we there yet? |
| 2046 | - if ($pos >= strlen($message) - 1) |
|
| 2047 | - break; |
|
| 2135 | + if ($pos >= strlen($message) - 1) { |
|
| 2136 | + break; |
|
| 2137 | + } |
|
| 2048 | 2138 | |
| 2049 | 2139 | $tags = strtolower($message[$pos + 1]); |
| 2050 | 2140 | |
| 2051 | 2141 | if ($tags == '/' && !empty($open_tags)) |
| 2052 | 2142 | { |
| 2053 | 2143 | $pos2 = strpos($message, ']', $pos + 1); |
| 2054 | - if ($pos2 == $pos + 2) |
|
| 2055 | - continue; |
|
| 2144 | + if ($pos2 == $pos + 2) { |
|
| 2145 | + continue; |
|
| 2146 | + } |
|
| 2056 | 2147 | |
| 2057 | 2148 | $look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2)); |
| 2058 | 2149 | |
@@ -2062,8 +2153,9 @@ discard block |
||
| 2062 | 2153 | do |
| 2063 | 2154 | { |
| 2064 | 2155 | $tag = array_pop($open_tags); |
| 2065 | - if (!$tag) |
|
| 2066 | - break; |
|
| 2156 | + if (!$tag) { |
|
| 2157 | + break; |
|
| 2158 | + } |
|
| 2067 | 2159 | |
| 2068 | 2160 | if (!empty($tag['block_level'])) |
| 2069 | 2161 | { |
@@ -2077,10 +2169,11 @@ discard block |
||
| 2077 | 2169 | // The idea is, if we are LOOKING for a block level tag, we can close them on the way. |
| 2078 | 2170 | if (strlen($look_for) > 0 && isset($bbc_codes[$look_for[0]])) |
| 2079 | 2171 | { |
| 2080 | - foreach ($bbc_codes[$look_for[0]] as $temp) |
|
| 2081 | - if ($temp['tag'] == $look_for) |
|
| 2172 | + foreach ($bbc_codes[$look_for[0]] as $temp) { |
|
| 2173 | + if ($temp['tag'] == $look_for) |
|
| 2082 | 2174 | { |
| 2083 | 2175 | $block_level = !empty($temp['block_level']); |
| 2176 | + } |
|
| 2084 | 2177 | break; |
| 2085 | 2178 | } |
| 2086 | 2179 | } |
@@ -2102,15 +2195,15 @@ discard block |
||
| 2102 | 2195 | { |
| 2103 | 2196 | $open_tags = $to_close; |
| 2104 | 2197 | continue; |
| 2105 | - } |
|
| 2106 | - elseif (!empty($to_close) && $tag['tag'] != $look_for) |
|
| 2198 | + } elseif (!empty($to_close) && $tag['tag'] != $look_for) |
|
| 2107 | 2199 | { |
| 2108 | 2200 | if ($block_level === null && isset($look_for[0], $bbc_codes[$look_for[0]])) |
| 2109 | 2201 | { |
| 2110 | - foreach ($bbc_codes[$look_for[0]] as $temp) |
|
| 2111 | - if ($temp['tag'] == $look_for) |
|
| 2202 | + foreach ($bbc_codes[$look_for[0]] as $temp) { |
|
| 2203 | + if ($temp['tag'] == $look_for) |
|
| 2112 | 2204 | { |
| 2113 | 2205 | $block_level = !empty($temp['block_level']); |
| 2206 | + } |
|
| 2114 | 2207 | break; |
| 2115 | 2208 | } |
| 2116 | 2209 | } |
@@ -2118,8 +2211,9 @@ discard block |
||
| 2118 | 2211 | // We're not looking for a block level tag (or maybe even a tag that exists...) |
| 2119 | 2212 | if (!$block_level) |
| 2120 | 2213 | { |
| 2121 | - foreach ($to_close as $tag) |
|
| 2122 | - array_push($open_tags, $tag); |
|
| 2214 | + foreach ($to_close as $tag) { |
|
| 2215 | + array_push($open_tags, $tag); |
|
| 2216 | + } |
|
| 2123 | 2217 | continue; |
| 2124 | 2218 | } |
| 2125 | 2219 | } |
@@ -2132,14 +2226,17 @@ discard block |
||
| 2132 | 2226 | |
| 2133 | 2227 | // See the comment at the end of the big loop - just eating whitespace ;). |
| 2134 | 2228 | $whitespace_regex = ''; |
| 2135 | - if (!empty($tag['block_level'])) |
|
| 2136 | - $whitespace_regex .= '( |\s)*<br>'; |
|
| 2229 | + if (!empty($tag['block_level'])) { |
|
| 2230 | + $whitespace_regex .= '( |\s)*<br>'; |
|
| 2231 | + } |
|
| 2137 | 2232 | // Trim one line of whitespace after unnested tags, but all of it after nested ones |
| 2138 | - if (!empty($tag['trim']) && $tag['trim'] != 'inside') |
|
| 2139 | - $whitespace_regex .= empty($tag['require_parents']) ? '( |\s)*' : '(<br>| |\s)*'; |
|
| 2233 | + if (!empty($tag['trim']) && $tag['trim'] != 'inside') { |
|
| 2234 | + $whitespace_regex .= empty($tag['require_parents']) ? '( |\s)*' : '(<br>| |\s)*'; |
|
| 2235 | + } |
|
| 2140 | 2236 | |
| 2141 | - if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) |
|
| 2142 | - $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
| 2237 | + if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) { |
|
| 2238 | + $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
| 2239 | + } |
|
| 2143 | 2240 | } |
| 2144 | 2241 | |
| 2145 | 2242 | if (!empty($to_close)) |
@@ -2152,8 +2249,9 @@ discard block |
||
| 2152 | 2249 | } |
| 2153 | 2250 | |
| 2154 | 2251 | // No tags for this character, so just keep going (fastest possible course.) |
| 2155 | - if (!isset($bbc_codes[$tags])) |
|
| 2156 | - continue; |
|
| 2252 | + if (!isset($bbc_codes[$tags])) { |
|
| 2253 | + continue; |
|
| 2254 | + } |
|
| 2157 | 2255 | |
| 2158 | 2256 | $inside = empty($open_tags) ? null : $open_tags[count($open_tags) - 1]; |
| 2159 | 2257 | $tag = null; |
@@ -2162,44 +2260,52 @@ discard block |
||
| 2162 | 2260 | $pt_strlen = strlen($possible['tag']); |
| 2163 | 2261 | |
| 2164 | 2262 | // Not a match? |
| 2165 | - if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) |
|
| 2166 | - continue; |
|
| 2263 | + if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) { |
|
| 2264 | + continue; |
|
| 2265 | + } |
|
| 2167 | 2266 | |
| 2168 | 2267 | $next_c = $message[$pos + 1 + $pt_strlen]; |
| 2169 | 2268 | |
| 2170 | 2269 | // A test validation? |
| 2171 | - if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) |
|
| 2172 | - continue; |
|
| 2270 | + if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) { |
|
| 2271 | + continue; |
|
| 2272 | + } |
|
| 2173 | 2273 | // Do we want parameters? |
| 2174 | 2274 | elseif (!empty($possible['parameters'])) |
| 2175 | 2275 | { |
| 2176 | - if ($next_c != ' ') |
|
| 2177 | - continue; |
|
| 2178 | - } |
|
| 2179 | - elseif (isset($possible['type'])) |
|
| 2276 | + if ($next_c != ' ') { |
|
| 2277 | + continue; |
|
| 2278 | + } |
|
| 2279 | + } elseif (isset($possible['type'])) |
|
| 2180 | 2280 | { |
| 2181 | 2281 | // Do we need an equal sign? |
| 2182 | - if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') |
|
| 2183 | - continue; |
|
| 2282 | + if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') { |
|
| 2283 | + continue; |
|
| 2284 | + } |
|
| 2184 | 2285 | // Maybe we just want a /... |
| 2185 | - if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') |
|
| 2186 | - continue; |
|
| 2286 | + if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') { |
|
| 2287 | + continue; |
|
| 2288 | + } |
|
| 2187 | 2289 | // An immediate ]? |
| 2188 | - if ($possible['type'] == 'unparsed_content' && $next_c != ']') |
|
| 2189 | - continue; |
|
| 2290 | + if ($possible['type'] == 'unparsed_content' && $next_c != ']') { |
|
| 2291 | + continue; |
|
| 2292 | + } |
|
| 2190 | 2293 | } |
| 2191 | 2294 | // No type means 'parsed_content', which demands an immediate ] without parameters! |
| 2192 | - elseif ($next_c != ']') |
|
| 2193 | - continue; |
|
| 2295 | + elseif ($next_c != ']') { |
|
| 2296 | + continue; |
|
| 2297 | + } |
|
| 2194 | 2298 | |
| 2195 | 2299 | // Check allowed tree? |
| 2196 | - if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) |
|
| 2197 | - continue; |
|
| 2198 | - elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) |
|
| 2199 | - continue; |
|
| 2300 | + if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) { |
|
| 2301 | + continue; |
|
| 2302 | + } elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) { |
|
| 2303 | + continue; |
|
| 2304 | + } |
|
| 2200 | 2305 | // If this is in the list of disallowed child tags, don't parse it. |
| 2201 | - elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) |
|
| 2202 | - continue; |
|
| 2306 | + elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) { |
|
| 2307 | + continue; |
|
| 2308 | + } |
|
| 2203 | 2309 | |
| 2204 | 2310 | $pos1 = $pos + 1 + $pt_strlen + 1; |
| 2205 | 2311 | |
@@ -2211,8 +2317,9 @@ discard block |
||
| 2211 | 2317 | foreach ($open_tags as $open_quote) |
| 2212 | 2318 | { |
| 2213 | 2319 | // Every parent quote this quote has flips the styling |
| 2214 | - if ($open_quote['tag'] == 'quote') |
|
| 2215 | - $quote_alt = !$quote_alt; |
|
| 2320 | + if ($open_quote['tag'] == 'quote') { |
|
| 2321 | + $quote_alt = !$quote_alt; |
|
| 2322 | + } |
|
| 2216 | 2323 | } |
| 2217 | 2324 | // Add a class to the quote to style alternating blockquotes |
| 2218 | 2325 | $possible['before'] = strtr($possible['before'], array('<blockquote>' => '<blockquote class="bbc_' . ($quote_alt ? 'alternate' : 'standard') . '_quote">')); |
@@ -2223,8 +2330,9 @@ discard block |
||
| 2223 | 2330 | { |
| 2224 | 2331 | // Build a regular expression for each parameter for the current tag. |
| 2225 | 2332 | $preg = array(); |
| 2226 | - foreach ($possible['parameters'] as $p => $info) |
|
| 2227 | - $preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '"') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '"') . '\s*)' . (empty($info['optional']) ? '' : '?'); |
|
| 2333 | + foreach ($possible['parameters'] as $p => $info) { |
|
| 2334 | + $preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '"') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '"') . '\s*)' . (empty($info['optional']) ? '' : '?'); |
|
| 2335 | + } |
|
| 2228 | 2336 | |
| 2229 | 2337 | // Extract the string that potentially holds our parameters. |
| 2230 | 2338 | $blob = preg_split('~\[/?(?:' . $alltags_regex . ')~i', substr($message, $pos)); |
@@ -2244,24 +2352,27 @@ discard block |
||
| 2244 | 2352 | |
| 2245 | 2353 | $match = preg_match('~^' . implode('', $preg) . '$~i', implode(' ', $given_params), $matches) !== 0; |
| 2246 | 2354 | |
| 2247 | - if ($match) |
|
| 2248 | - $blob_counter = count($blobs) + 1; |
|
| 2355 | + if ($match) { |
|
| 2356 | + $blob_counter = count($blobs) + 1; |
|
| 2357 | + } |
|
| 2249 | 2358 | } |
| 2250 | 2359 | |
| 2251 | 2360 | // Didn't match our parameter list, try the next possible. |
| 2252 | - if (!$match) |
|
| 2253 | - continue; |
|
| 2361 | + if (!$match) { |
|
| 2362 | + continue; |
|
| 2363 | + } |
|
| 2254 | 2364 | |
| 2255 | 2365 | $params = array(); |
| 2256 | 2366 | for ($i = 1, $n = count($matches); $i < $n; $i += 2) |
| 2257 | 2367 | { |
| 2258 | 2368 | $key = strtok(ltrim($matches[$i]), '='); |
| 2259 | - if (isset($possible['parameters'][$key]['value'])) |
|
| 2260 | - $params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1])); |
|
| 2261 | - elseif (isset($possible['parameters'][$key]['validate'])) |
|
| 2262 | - $params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]); |
|
| 2263 | - else |
|
| 2264 | - $params['{' . $key . '}'] = $matches[$i + 1]; |
|
| 2369 | + if (isset($possible['parameters'][$key]['value'])) { |
|
| 2370 | + $params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1])); |
|
| 2371 | + } elseif (isset($possible['parameters'][$key]['validate'])) { |
|
| 2372 | + $params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]); |
|
| 2373 | + } else { |
|
| 2374 | + $params['{' . $key . '}'] = $matches[$i + 1]; |
|
| 2375 | + } |
|
| 2265 | 2376 | |
| 2266 | 2377 | // Just to make sure: replace any $ or { so they can't interpolate wrongly. |
| 2267 | 2378 | $params['{' . $key . '}'] = strtr($params['{' . $key . '}'], array('$' => '$', '{' => '{')); |
@@ -2269,23 +2380,26 @@ discard block |
||
| 2269 | 2380 | |
| 2270 | 2381 | foreach ($possible['parameters'] as $p => $info) |
| 2271 | 2382 | { |
| 2272 | - if (!isset($params['{' . $p . '}'])) |
|
| 2273 | - $params['{' . $p . '}'] = ''; |
|
| 2383 | + if (!isset($params['{' . $p . '}'])) { |
|
| 2384 | + $params['{' . $p . '}'] = ''; |
|
| 2385 | + } |
|
| 2274 | 2386 | } |
| 2275 | 2387 | |
| 2276 | 2388 | $tag = $possible; |
| 2277 | 2389 | |
| 2278 | 2390 | // Put the parameters into the string. |
| 2279 | - if (isset($tag['before'])) |
|
| 2280 | - $tag['before'] = strtr($tag['before'], $params); |
|
| 2281 | - if (isset($tag['after'])) |
|
| 2282 | - $tag['after'] = strtr($tag['after'], $params); |
|
| 2283 | - if (isset($tag['content'])) |
|
| 2284 | - $tag['content'] = strtr($tag['content'], $params); |
|
| 2391 | + if (isset($tag['before'])) { |
|
| 2392 | + $tag['before'] = strtr($tag['before'], $params); |
|
| 2393 | + } |
|
| 2394 | + if (isset($tag['after'])) { |
|
| 2395 | + $tag['after'] = strtr($tag['after'], $params); |
|
| 2396 | + } |
|
| 2397 | + if (isset($tag['content'])) { |
|
| 2398 | + $tag['content'] = strtr($tag['content'], $params); |
|
| 2399 | + } |
|
| 2285 | 2400 | |
| 2286 | 2401 | $pos1 += strlen($given_param_string); |
| 2287 | - } |
|
| 2288 | - else |
|
| 2402 | + } else |
|
| 2289 | 2403 | { |
| 2290 | 2404 | $tag = $possible; |
| 2291 | 2405 | $params = array(); |
@@ -2296,8 +2410,9 @@ discard block |
||
| 2296 | 2410 | // Item codes are complicated buggers... they are implicit [li]s and can make [list]s! |
| 2297 | 2411 | if ($smileys !== false && $tag === null && isset($itemcodes[$message[$pos + 1]]) && $message[$pos + 2] == ']' && !isset($disabled['list']) && !isset($disabled['li'])) |
| 2298 | 2412 | { |
| 2299 | - if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) |
|
| 2300 | - continue; |
|
| 2413 | + if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) { |
|
| 2414 | + continue; |
|
| 2415 | + } |
|
| 2301 | 2416 | |
| 2302 | 2417 | $tag = $itemcodes[$message[$pos + 1]]; |
| 2303 | 2418 | |
@@ -2318,9 +2433,9 @@ discard block |
||
| 2318 | 2433 | { |
| 2319 | 2434 | array_pop($open_tags); |
| 2320 | 2435 | $code = '</li>'; |
| 2436 | + } else { |
|
| 2437 | + $code = ''; |
|
| 2321 | 2438 | } |
| 2322 | - else |
|
| 2323 | - $code = ''; |
|
| 2324 | 2439 | |
| 2325 | 2440 | // Now we open a new tag. |
| 2326 | 2441 | $open_tags[] = array( |
@@ -2367,12 +2482,14 @@ discard block |
||
| 2367 | 2482 | } |
| 2368 | 2483 | |
| 2369 | 2484 | // No tag? Keep looking, then. Silly people using brackets without actual tags. |
| 2370 | - if ($tag === null) |
|
| 2371 | - continue; |
|
| 2485 | + if ($tag === null) { |
|
| 2486 | + continue; |
|
| 2487 | + } |
|
| 2372 | 2488 | |
| 2373 | 2489 | // Propagate the list to the child (so wrapping the disallowed tag won't work either.) |
| 2374 | - if (isset($inside['disallow_children'])) |
|
| 2375 | - $tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children']; |
|
| 2490 | + if (isset($inside['disallow_children'])) { |
|
| 2491 | + $tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children']; |
|
| 2492 | + } |
|
| 2376 | 2493 | |
| 2377 | 2494 | // Is this tag disabled? |
| 2378 | 2495 | if (isset($disabled[$tag['tag']])) |
@@ -2382,14 +2499,13 @@ discard block |
||
| 2382 | 2499 | $tag['before'] = !empty($tag['block_level']) ? '<div>' : ''; |
| 2383 | 2500 | $tag['after'] = !empty($tag['block_level']) ? '</div>' : ''; |
| 2384 | 2501 | $tag['content'] = isset($tag['type']) && $tag['type'] == 'closed' ? '' : (!empty($tag['block_level']) ? '<div>$1</div>' : '$1'); |
| 2385 | - } |
|
| 2386 | - elseif (isset($tag['disabled_before']) || isset($tag['disabled_after'])) |
|
| 2502 | + } elseif (isset($tag['disabled_before']) || isset($tag['disabled_after'])) |
|
| 2387 | 2503 | { |
| 2388 | 2504 | $tag['before'] = isset($tag['disabled_before']) ? $tag['disabled_before'] : (!empty($tag['block_level']) ? '<div>' : ''); |
| 2389 | 2505 | $tag['after'] = isset($tag['disabled_after']) ? $tag['disabled_after'] : (!empty($tag['block_level']) ? '</div>' : ''); |
| 2506 | + } else { |
|
| 2507 | + $tag['content'] = $tag['disabled_content']; |
|
| 2390 | 2508 | } |
| 2391 | - else |
|
| 2392 | - $tag['content'] = $tag['disabled_content']; |
|
| 2393 | 2509 | } |
| 2394 | 2510 | |
| 2395 | 2511 | // we use this a lot |
@@ -2399,8 +2515,9 @@ discard block |
||
| 2399 | 2515 | if (!empty($tag['block_level']) && $tag['tag'] != 'html' && empty($inside['block_level'])) |
| 2400 | 2516 | { |
| 2401 | 2517 | $n = count($open_tags) - 1; |
| 2402 | - while (empty($open_tags[$n]['block_level']) && $n >= 0) |
|
| 2403 | - $n--; |
|
| 2518 | + while (empty($open_tags[$n]['block_level']) && $n >= 0) { |
|
| 2519 | + $n--; |
|
| 2520 | + } |
|
| 2404 | 2521 | |
| 2405 | 2522 | // Close all the non block level tags so this tag isn't surrounded by them. |
| 2406 | 2523 | for ($i = count($open_tags) - 1; $i > $n; $i--) |
@@ -2412,12 +2529,15 @@ discard block |
||
| 2412 | 2529 | |
| 2413 | 2530 | // Trim or eat trailing stuff... see comment at the end of the big loop. |
| 2414 | 2531 | $whitespace_regex = ''; |
| 2415 | - if (!empty($tag['block_level'])) |
|
| 2416 | - $whitespace_regex .= '( |\s)*<br>'; |
|
| 2417 | - if (!empty($tag['trim']) && $tag['trim'] != 'inside') |
|
| 2418 | - $whitespace_regex .= empty($tag['require_parents']) ? '( |\s)*' : '(<br>| |\s)*'; |
|
| 2419 | - if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) |
|
| 2420 | - $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
| 2532 | + if (!empty($tag['block_level'])) { |
|
| 2533 | + $whitespace_regex .= '( |\s)*<br>'; |
|
| 2534 | + } |
|
| 2535 | + if (!empty($tag['trim']) && $tag['trim'] != 'inside') { |
|
| 2536 | + $whitespace_regex .= empty($tag['require_parents']) ? '( |\s)*' : '(<br>| |\s)*'; |
|
| 2537 | + } |
|
| 2538 | + if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) { |
|
| 2539 | + $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
| 2540 | + } |
|
| 2421 | 2541 | |
| 2422 | 2542 | array_pop($open_tags); |
| 2423 | 2543 | } |
@@ -2435,16 +2555,19 @@ discard block |
||
| 2435 | 2555 | elseif ($tag['type'] == 'unparsed_content') |
| 2436 | 2556 | { |
| 2437 | 2557 | $pos2 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos1); |
| 2438 | - if ($pos2 === false) |
|
| 2439 | - continue; |
|
| 2558 | + if ($pos2 === false) { |
|
| 2559 | + continue; |
|
| 2560 | + } |
|
| 2440 | 2561 | |
| 2441 | 2562 | $data = substr($message, $pos1, $pos2 - $pos1); |
| 2442 | 2563 | |
| 2443 | - if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') |
|
| 2444 | - $data = substr($data, 4); |
|
| 2564 | + if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') { |
|
| 2565 | + $data = substr($data, 4); |
|
| 2566 | + } |
|
| 2445 | 2567 | |
| 2446 | - if (isset($tag['validate'])) |
|
| 2447 | - $tag['validate']($tag, $data, $disabled, $params); |
|
| 2568 | + if (isset($tag['validate'])) { |
|
| 2569 | + $tag['validate']($tag, $data, $disabled, $params); |
|
| 2570 | + } |
|
| 2448 | 2571 | |
| 2449 | 2572 | $code = strtr($tag['content'], array('$1' => $data)); |
| 2450 | 2573 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 3 + $tag_strlen); |
@@ -2460,34 +2583,40 @@ discard block |
||
| 2460 | 2583 | if (isset($tag['quoted'])) |
| 2461 | 2584 | { |
| 2462 | 2585 | $quoted = substr($message, $pos1, 6) == '"'; |
| 2463 | - if ($tag['quoted'] != 'optional' && !$quoted) |
|
| 2464 | - continue; |
|
| 2586 | + if ($tag['quoted'] != 'optional' && !$quoted) { |
|
| 2587 | + continue; |
|
| 2588 | + } |
|
| 2465 | 2589 | |
| 2466 | - if ($quoted) |
|
| 2467 | - $pos1 += 6; |
|
| 2590 | + if ($quoted) { |
|
| 2591 | + $pos1 += 6; |
|
| 2592 | + } |
|
| 2593 | + } else { |
|
| 2594 | + $quoted = false; |
|
| 2468 | 2595 | } |
| 2469 | - else |
|
| 2470 | - $quoted = false; |
|
| 2471 | 2596 | |
| 2472 | 2597 | $pos2 = strpos($message, $quoted == false ? ']' : '"]', $pos1); |
| 2473 | - if ($pos2 === false) |
|
| 2474 | - continue; |
|
| 2598 | + if ($pos2 === false) { |
|
| 2599 | + continue; |
|
| 2600 | + } |
|
| 2475 | 2601 | |
| 2476 | 2602 | $pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2); |
| 2477 | - if ($pos3 === false) |
|
| 2478 | - continue; |
|
| 2603 | + if ($pos3 === false) { |
|
| 2604 | + continue; |
|
| 2605 | + } |
|
| 2479 | 2606 | |
| 2480 | 2607 | $data = array( |
| 2481 | 2608 | substr($message, $pos2 + ($quoted == false ? 1 : 7), $pos3 - ($pos2 + ($quoted == false ? 1 : 7))), |
| 2482 | 2609 | substr($message, $pos1, $pos2 - $pos1) |
| 2483 | 2610 | ); |
| 2484 | 2611 | |
| 2485 | - if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') |
|
| 2486 | - $data[0] = substr($data[0], 4); |
|
| 2612 | + if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') { |
|
| 2613 | + $data[0] = substr($data[0], 4); |
|
| 2614 | + } |
|
| 2487 | 2615 | |
| 2488 | 2616 | // Validation for my parking, please! |
| 2489 | - if (isset($tag['validate'])) |
|
| 2490 | - $tag['validate']($tag, $data, $disabled, $params); |
|
| 2617 | + if (isset($tag['validate'])) { |
|
| 2618 | + $tag['validate']($tag, $data, $disabled, $params); |
|
| 2619 | + } |
|
| 2491 | 2620 | |
| 2492 | 2621 | $code = strtr($tag['content'], array('$1' => $data[0], '$2' => $data[1])); |
| 2493 | 2622 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen); |
@@ -2504,23 +2633,27 @@ discard block |
||
| 2504 | 2633 | elseif ($tag['type'] == 'unparsed_commas_content') |
| 2505 | 2634 | { |
| 2506 | 2635 | $pos2 = strpos($message, ']', $pos1); |
| 2507 | - if ($pos2 === false) |
|
| 2508 | - continue; |
|
| 2636 | + if ($pos2 === false) { |
|
| 2637 | + continue; |
|
| 2638 | + } |
|
| 2509 | 2639 | |
| 2510 | 2640 | $pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2); |
| 2511 | - if ($pos3 === false) |
|
| 2512 | - continue; |
|
| 2641 | + if ($pos3 === false) { |
|
| 2642 | + continue; |
|
| 2643 | + } |
|
| 2513 | 2644 | |
| 2514 | 2645 | // We want $1 to be the content, and the rest to be csv. |
| 2515 | 2646 | $data = explode(',', ',' . substr($message, $pos1, $pos2 - $pos1)); |
| 2516 | 2647 | $data[0] = substr($message, $pos2 + 1, $pos3 - $pos2 - 1); |
| 2517 | 2648 | |
| 2518 | - if (isset($tag['validate'])) |
|
| 2519 | - $tag['validate']($tag, $data, $disabled, $params); |
|
| 2649 | + if (isset($tag['validate'])) { |
|
| 2650 | + $tag['validate']($tag, $data, $disabled, $params); |
|
| 2651 | + } |
|
| 2520 | 2652 | |
| 2521 | 2653 | $code = $tag['content']; |
| 2522 | - foreach ($data as $k => $d) |
|
| 2523 | - $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
| 2654 | + foreach ($data as $k => $d) { |
|
| 2655 | + $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
| 2656 | + } |
|
| 2524 | 2657 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen); |
| 2525 | 2658 | $pos += strlen($code) - 1 + 2; |
| 2526 | 2659 | } |
@@ -2528,24 +2661,28 @@ discard block |
||
| 2528 | 2661 | elseif ($tag['type'] == 'unparsed_commas') |
| 2529 | 2662 | { |
| 2530 | 2663 | $pos2 = strpos($message, ']', $pos1); |
| 2531 | - if ($pos2 === false) |
|
| 2532 | - continue; |
|
| 2664 | + if ($pos2 === false) { |
|
| 2665 | + continue; |
|
| 2666 | + } |
|
| 2533 | 2667 | |
| 2534 | 2668 | $data = explode(',', substr($message, $pos1, $pos2 - $pos1)); |
| 2535 | 2669 | |
| 2536 | - if (isset($tag['validate'])) |
|
| 2537 | - $tag['validate']($tag, $data, $disabled, $params); |
|
| 2670 | + if (isset($tag['validate'])) { |
|
| 2671 | + $tag['validate']($tag, $data, $disabled, $params); |
|
| 2672 | + } |
|
| 2538 | 2673 | |
| 2539 | 2674 | // Fix after, for disabled code mainly. |
| 2540 | - foreach ($data as $k => $d) |
|
| 2541 | - $tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d))); |
|
| 2675 | + foreach ($data as $k => $d) { |
|
| 2676 | + $tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d))); |
|
| 2677 | + } |
|
| 2542 | 2678 | |
| 2543 | 2679 | $open_tags[] = $tag; |
| 2544 | 2680 | |
| 2545 | 2681 | // Replace them out, $1, $2, $3, $4, etc. |
| 2546 | 2682 | $code = $tag['before']; |
| 2547 | - foreach ($data as $k => $d) |
|
| 2548 | - $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
| 2683 | + foreach ($data as $k => $d) { |
|
| 2684 | + $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
| 2685 | + } |
|
| 2549 | 2686 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 1); |
| 2550 | 2687 | $pos += strlen($code) - 1 + 2; |
| 2551 | 2688 | } |
@@ -2556,28 +2693,33 @@ discard block |
||
| 2556 | 2693 | if (isset($tag['quoted'])) |
| 2557 | 2694 | { |
| 2558 | 2695 | $quoted = substr($message, $pos1, 6) == '"'; |
| 2559 | - if ($tag['quoted'] != 'optional' && !$quoted) |
|
| 2560 | - continue; |
|
| 2696 | + if ($tag['quoted'] != 'optional' && !$quoted) { |
|
| 2697 | + continue; |
|
| 2698 | + } |
|
| 2561 | 2699 | |
| 2562 | - if ($quoted) |
|
| 2563 | - $pos1 += 6; |
|
| 2700 | + if ($quoted) { |
|
| 2701 | + $pos1 += 6; |
|
| 2702 | + } |
|
| 2703 | + } else { |
|
| 2704 | + $quoted = false; |
|
| 2564 | 2705 | } |
| 2565 | - else |
|
| 2566 | - $quoted = false; |
|
| 2567 | 2706 | |
| 2568 | 2707 | $pos2 = strpos($message, $quoted == false ? ']' : '"]', $pos1); |
| 2569 | - if ($pos2 === false) |
|
| 2570 | - continue; |
|
| 2708 | + if ($pos2 === false) { |
|
| 2709 | + continue; |
|
| 2710 | + } |
|
| 2571 | 2711 | |
| 2572 | 2712 | $data = substr($message, $pos1, $pos2 - $pos1); |
| 2573 | 2713 | |
| 2574 | 2714 | // Validation for my parking, please! |
| 2575 | - if (isset($tag['validate'])) |
|
| 2576 | - $tag['validate']($tag, $data, $disabled, $params); |
|
| 2715 | + if (isset($tag['validate'])) { |
|
| 2716 | + $tag['validate']($tag, $data, $disabled, $params); |
|
| 2717 | + } |
|
| 2577 | 2718 | |
| 2578 | 2719 | // For parsed content, we must recurse to avoid security problems. |
| 2579 | - if ($tag['type'] != 'unparsed_equals') |
|
| 2580 | - $data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array()); |
|
| 2720 | + if ($tag['type'] != 'unparsed_equals') { |
|
| 2721 | + $data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array()); |
|
| 2722 | + } |
|
| 2581 | 2723 | |
| 2582 | 2724 | $tag['after'] = strtr($tag['after'], array('$1' => $data)); |
| 2583 | 2725 | |
@@ -2589,34 +2731,40 @@ discard block |
||
| 2589 | 2731 | } |
| 2590 | 2732 | |
| 2591 | 2733 | // If this is block level, eat any breaks after it. |
| 2592 | - if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') |
|
| 2593 | - $message = substr($message, 0, $pos + 1) . substr($message, $pos + 5); |
|
| 2734 | + if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') { |
|
| 2735 | + $message = substr($message, 0, $pos + 1) . substr($message, $pos + 5); |
|
| 2736 | + } |
|
| 2594 | 2737 | |
| 2595 | 2738 | // Are we trimming outside this tag? |
| 2596 | - if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>| |\s)*~', substr($message, $pos + 1), $matches) != 0) |
|
| 2597 | - $message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0])); |
|
| 2739 | + if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>| |\s)*~', substr($message, $pos + 1), $matches) != 0) { |
|
| 2740 | + $message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0])); |
|
| 2741 | + } |
|
| 2598 | 2742 | } |
| 2599 | 2743 | |
| 2600 | 2744 | // Close any remaining tags. |
| 2601 | - while ($tag = array_pop($open_tags)) |
|
| 2602 | - $message .= "\n" . $tag['after'] . "\n"; |
|
| 2745 | + while ($tag = array_pop($open_tags)) { |
|
| 2746 | + $message .= "\n" . $tag['after'] . "\n"; |
|
| 2747 | + } |
|
| 2603 | 2748 | |
| 2604 | 2749 | // Parse the smileys within the parts where it can be done safely. |
| 2605 | 2750 | if ($smileys === true) |
| 2606 | 2751 | { |
| 2607 | 2752 | $message_parts = explode("\n", $message); |
| 2608 | - for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) |
|
| 2609 | - parsesmileys($message_parts[$i]); |
|
| 2753 | + for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) { |
|
| 2754 | + parsesmileys($message_parts[$i]); |
|
| 2755 | + } |
|
| 2610 | 2756 | |
| 2611 | 2757 | $message = implode('', $message_parts); |
| 2612 | 2758 | } |
| 2613 | 2759 | |
| 2614 | 2760 | // No smileys, just get rid of the markers. |
| 2615 | - else |
|
| 2616 | - $message = strtr($message, array("\n" => '')); |
|
| 2761 | + else { |
|
| 2762 | + $message = strtr($message, array("\n" => '')); |
|
| 2763 | + } |
|
| 2617 | 2764 | |
| 2618 | - if ($message !== '' && $message[0] === ' ') |
|
| 2619 | - $message = ' ' . substr($message, 1); |
|
| 2765 | + if ($message !== '' && $message[0] === ' ') { |
|
| 2766 | + $message = ' ' . substr($message, 1); |
|
| 2767 | + } |
|
| 2620 | 2768 | |
| 2621 | 2769 | // Cleanup whitespace. |
| 2622 | 2770 | $message = strtr($message, array(' ' => ' ', "\r" => '', "\n" => '<br>', '<br> ' => '<br> ', ' ' => "\n")); |
@@ -2625,15 +2773,16 @@ discard block |
||
| 2625 | 2773 | call_integration_hook('integrate_post_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags)); |
| 2626 | 2774 | |
| 2627 | 2775 | // Cache the output if it took some time... |
| 2628 | - if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) |
|
| 2629 | - cache_put_data($cache_key, $message, 240); |
|
| 2776 | + if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) { |
|
| 2777 | + cache_put_data($cache_key, $message, 240); |
|
| 2778 | + } |
|
| 2630 | 2779 | |
| 2631 | 2780 | // If this was a force parse revert if needed. |
| 2632 | 2781 | if (!empty($parse_tags)) |
| 2633 | 2782 | { |
| 2634 | - if (empty($temp_bbc)) |
|
| 2635 | - $bbc_codes = array(); |
|
| 2636 | - else |
|
| 2783 | + if (empty($temp_bbc)) { |
|
| 2784 | + $bbc_codes = array(); |
|
| 2785 | + } else |
|
| 2637 | 2786 | { |
| 2638 | 2787 | $bbc_codes = $temp_bbc; |
| 2639 | 2788 | unset($temp_bbc); |
@@ -2660,8 +2809,9 @@ discard block |
||
| 2660 | 2809 | static $smileyPregSearch = null, $smileyPregReplacements = array(); |
| 2661 | 2810 | |
| 2662 | 2811 | // No smiley set at all?! |
| 2663 | - if ($user_info['smiley_set'] == 'none' || trim($message) == '') |
|
| 2664 | - return; |
|
| 2812 | + if ($user_info['smiley_set'] == 'none' || trim($message) == '') { |
|
| 2813 | + return; |
|
| 2814 | + } |
|
| 2665 | 2815 | |
| 2666 | 2816 | // If smileyPregSearch hasn't been set, do it now. |
| 2667 | 2817 | if (empty($smileyPregSearch)) |
@@ -2672,8 +2822,7 @@ discard block |
||
| 2672 | 2822 | $smileysfrom = array('>:D', ':D', '::)', '>:(', ':))', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', '0:)'); |
| 2673 | 2823 | $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'); |
| 2674 | 2824 | $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'], '', '', '', ''); |
| 2675 | - } |
|
| 2676 | - else |
|
| 2825 | + } else |
|
| 2677 | 2826 | { |
| 2678 | 2827 | // Load the smileys in reverse order by length so they don't get parsed wrong. |
| 2679 | 2828 | if (($temp = cache_get_data('parsing_smileys', 480)) == null) |
@@ -2697,9 +2846,9 @@ discard block |
||
| 2697 | 2846 | $smcFunc['db_free_result']($result); |
| 2698 | 2847 | |
| 2699 | 2848 | cache_put_data('parsing_smileys', array($smileysfrom, $smileysto, $smileysdescs), 480); |
| 2849 | + } else { |
|
| 2850 | + list ($smileysfrom, $smileysto, $smileysdescs) = $temp; |
|
| 2700 | 2851 | } |
| 2701 | - else |
|
| 2702 | - list ($smileysfrom, $smileysto, $smileysdescs) = $temp; |
|
| 2703 | 2852 | } |
| 2704 | 2853 | |
| 2705 | 2854 | // The non-breaking-space is a complex thing... |
@@ -2776,35 +2925,41 @@ discard block |
||
| 2776 | 2925 | global $scripturl, $context, $modSettings, $db_show_debug, $db_cache; |
| 2777 | 2926 | |
| 2778 | 2927 | // In case we have mail to send, better do that - as obExit doesn't always quite make it... |
| 2779 | - if (!empty($context['flush_mail'])) |
|
| 2780 | - // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
| 2928 | + if (!empty($context['flush_mail'])) { |
|
| 2929 | + // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
| 2781 | 2930 | AddMailQueue(true); |
| 2931 | + } |
|
| 2782 | 2932 | |
| 2783 | 2933 | $add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && substr($setLocation, 0, 6) != 'about:'; |
| 2784 | 2934 | |
| 2785 | - if ($add) |
|
| 2786 | - $setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : ''); |
|
| 2935 | + if ($add) { |
|
| 2936 | + $setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : ''); |
|
| 2937 | + } |
|
| 2787 | 2938 | |
| 2788 | 2939 | // Put the session ID in. |
| 2789 | - if (defined('SID') && SID != '') |
|
| 2790 | - $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation); |
|
| 2940 | + if (defined('SID') && SID != '') { |
|
| 2941 | + $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation); |
|
| 2942 | + } |
|
| 2791 | 2943 | // Keep that debug in their for template debugging! |
| 2792 | - elseif (isset($_GET['debug'])) |
|
| 2793 | - $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation); |
|
| 2944 | + elseif (isset($_GET['debug'])) { |
|
| 2945 | + $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation); |
|
| 2946 | + } |
|
| 2794 | 2947 | |
| 2795 | 2948 | 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']))) |
| 2796 | 2949 | { |
| 2797 | - if (defined('SID') && SID != '') |
|
| 2798 | - $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#]+?)(#[^"]*?)?$~', |
|
| 2950 | + if (defined('SID') && SID != '') { |
|
| 2951 | + $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#]+?)(#[^"]*?)?$~', |
|
| 2799 | 2952 | function ($m) use ($scripturl) |
| 2800 | 2953 | { |
| 2801 | 2954 | return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : ""); |
| 2955 | + } |
|
| 2802 | 2956 | }, $setLocation); |
| 2803 | - else |
|
| 2804 | - $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~', |
|
| 2957 | + else { |
|
| 2958 | + $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~', |
|
| 2805 | 2959 | function ($m) use ($scripturl) |
| 2806 | 2960 | { |
| 2807 | 2961 | return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : ""); |
| 2962 | + } |
|
| 2808 | 2963 | }, $setLocation); |
| 2809 | 2964 | } |
| 2810 | 2965 | |
@@ -2815,8 +2970,9 @@ discard block |
||
| 2815 | 2970 | header('Location: ' . str_replace(' ', '%20', $setLocation), true, $permanent ? 301 : 302); |
| 2816 | 2971 | |
| 2817 | 2972 | // Debugging. |
| 2818 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
| 2819 | - $_SESSION['debug_redirect'] = $db_cache; |
|
| 2973 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
| 2974 | + $_SESSION['debug_redirect'] = $db_cache; |
|
| 2975 | + } |
|
| 2820 | 2976 | |
| 2821 | 2977 | obExit(false); |
| 2822 | 2978 | } |
@@ -2835,51 +2991,60 @@ discard block |
||
| 2835 | 2991 | |
| 2836 | 2992 | // Attempt to prevent a recursive loop. |
| 2837 | 2993 | ++$level; |
| 2838 | - if ($level > 1 && !$from_fatal_error && !$has_fatal_error) |
|
| 2839 | - exit; |
|
| 2840 | - if ($from_fatal_error) |
|
| 2841 | - $has_fatal_error = true; |
|
| 2994 | + if ($level > 1 && !$from_fatal_error && !$has_fatal_error) { |
|
| 2995 | + exit; |
|
| 2996 | + } |
|
| 2997 | + if ($from_fatal_error) { |
|
| 2998 | + $has_fatal_error = true; |
|
| 2999 | + } |
|
| 2842 | 3000 | |
| 2843 | 3001 | // Clear out the stat cache. |
| 2844 | 3002 | trackStats(); |
| 2845 | 3003 | |
| 2846 | 3004 | // If we have mail to send, send it. |
| 2847 | - if (!empty($context['flush_mail'])) |
|
| 2848 | - // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
| 3005 | + if (!empty($context['flush_mail'])) { |
|
| 3006 | + // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
| 2849 | 3007 | AddMailQueue(true); |
| 3008 | + } |
|
| 2850 | 3009 | |
| 2851 | 3010 | $do_header = $header === null ? !$header_done : $header; |
| 2852 | - if ($do_footer === null) |
|
| 2853 | - $do_footer = $do_header; |
|
| 3011 | + if ($do_footer === null) { |
|
| 3012 | + $do_footer = $do_header; |
|
| 3013 | + } |
|
| 2854 | 3014 | |
| 2855 | 3015 | // Has the template/header been done yet? |
| 2856 | 3016 | if ($do_header) |
| 2857 | 3017 | { |
| 2858 | 3018 | // Was the page title set last minute? Also update the HTML safe one. |
| 2859 | - if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) |
|
| 2860 | - $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); |
|
| 3019 | + if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) { |
|
| 3020 | + $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); |
|
| 3021 | + } |
|
| 2861 | 3022 | |
| 2862 | 3023 | // Start up the session URL fixer. |
| 2863 | 3024 | ob_start('ob_sessrewrite'); |
| 2864 | 3025 | |
| 2865 | - if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) |
|
| 2866 | - $buffers = explode(',', $settings['output_buffers']); |
|
| 2867 | - elseif (!empty($settings['output_buffers'])) |
|
| 2868 | - $buffers = $settings['output_buffers']; |
|
| 2869 | - else |
|
| 2870 | - $buffers = array(); |
|
| 3026 | + if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) { |
|
| 3027 | + $buffers = explode(',', $settings['output_buffers']); |
|
| 3028 | + } elseif (!empty($settings['output_buffers'])) { |
|
| 3029 | + $buffers = $settings['output_buffers']; |
|
| 3030 | + } else { |
|
| 3031 | + $buffers = array(); |
|
| 3032 | + } |
|
| 2871 | 3033 | |
| 2872 | - if (isset($modSettings['integrate_buffer'])) |
|
| 2873 | - $buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers); |
|
| 3034 | + if (isset($modSettings['integrate_buffer'])) { |
|
| 3035 | + $buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers); |
|
| 3036 | + } |
|
| 2874 | 3037 | |
| 2875 | - if (!empty($buffers)) |
|
| 2876 | - foreach ($buffers as $function) |
|
| 3038 | + if (!empty($buffers)) { |
|
| 3039 | + foreach ($buffers as $function) |
|
| 2877 | 3040 | { |
| 2878 | 3041 | $call = call_helper($function, true); |
| 3042 | + } |
|
| 2879 | 3043 | |
| 2880 | 3044 | // Is it valid? |
| 2881 | - if (!empty($call)) |
|
| 2882 | - ob_start($call); |
|
| 3045 | + if (!empty($call)) { |
|
| 3046 | + ob_start($call); |
|
| 3047 | + } |
|
| 2883 | 3048 | } |
| 2884 | 3049 | |
| 2885 | 3050 | // Display the screen in the logical order. |
@@ -2891,8 +3056,9 @@ discard block |
||
| 2891 | 3056 | loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main'); |
| 2892 | 3057 | |
| 2893 | 3058 | // Anything special to put out? |
| 2894 | - if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) |
|
| 2895 | - echo $context['insert_after_template']; |
|
| 3059 | + if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) { |
|
| 3060 | + echo $context['insert_after_template']; |
|
| 3061 | + } |
|
| 2896 | 3062 | |
| 2897 | 3063 | // Just so we don't get caught in an endless loop of errors from the footer... |
| 2898 | 3064 | if (!$footer_done) |
@@ -2901,14 +3067,16 @@ discard block |
||
| 2901 | 3067 | template_footer(); |
| 2902 | 3068 | |
| 2903 | 3069 | // (since this is just debugging... it's okay that it's after </html>.) |
| 2904 | - if (!isset($_REQUEST['xml'])) |
|
| 2905 | - displayDebug(); |
|
| 3070 | + if (!isset($_REQUEST['xml'])) { |
|
| 3071 | + displayDebug(); |
|
| 3072 | + } |
|
| 2906 | 3073 | } |
| 2907 | 3074 | } |
| 2908 | 3075 | |
| 2909 | 3076 | // Remember this URL in case someone doesn't like sending HTTP_REFERER. |
| 2910 | - if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) |
|
| 2911 | - $_SESSION['old_url'] = $_SERVER['REQUEST_URL']; |
|
| 3077 | + if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) { |
|
| 3078 | + $_SESSION['old_url'] = $_SERVER['REQUEST_URL']; |
|
| 3079 | + } |
|
| 2912 | 3080 | |
| 2913 | 3081 | // For session check verification.... don't switch browsers... |
| 2914 | 3082 | $_SESSION['USER_AGENT'] = empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT']; |
@@ -2917,9 +3085,10 @@ discard block |
||
| 2917 | 3085 | call_integration_hook('integrate_exit', array($do_footer)); |
| 2918 | 3086 | |
| 2919 | 3087 | // Don't exit if we're coming from index.php; that will pass through normally. |
| 2920 | - if (!$from_index) |
|
| 2921 | - exit; |
|
| 2922 | -} |
|
| 3088 | + if (!$from_index) { |
|
| 3089 | + exit; |
|
| 3090 | + } |
|
| 3091 | + } |
|
| 2923 | 3092 | |
| 2924 | 3093 | /** |
| 2925 | 3094 | * Get the size of a specified image with better error handling. |
@@ -2938,8 +3107,9 @@ discard block |
||
| 2938 | 3107 | $url = str_replace(' ', '%20', $url); |
| 2939 | 3108 | |
| 2940 | 3109 | // Can we pull this from the cache... please please? |
| 2941 | - if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) |
|
| 2942 | - return $temp; |
|
| 3110 | + if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) { |
|
| 3111 | + return $temp; |
|
| 3112 | + } |
|
| 2943 | 3113 | $t = microtime(); |
| 2944 | 3114 | |
| 2945 | 3115 | // Get the host to pester... |
@@ -2949,12 +3119,10 @@ discard block |
||
| 2949 | 3119 | if ($url == '' || $url == 'http://' || $url == 'https://') |
| 2950 | 3120 | { |
| 2951 | 3121 | return false; |
| 2952 | - } |
|
| 2953 | - elseif (!isset($match[1])) |
|
| 3122 | + } elseif (!isset($match[1])) |
|
| 2954 | 3123 | { |
| 2955 | 3124 | $size = @getimagesize($url); |
| 2956 | - } |
|
| 2957 | - else |
|
| 3125 | + } else |
|
| 2958 | 3126 | { |
| 2959 | 3127 | // Try to connect to the server... give it half a second. |
| 2960 | 3128 | $temp = 0; |
@@ -2993,12 +3161,14 @@ discard block |
||
| 2993 | 3161 | } |
| 2994 | 3162 | |
| 2995 | 3163 | // If we didn't get it, we failed. |
| 2996 | - if (!isset($size)) |
|
| 2997 | - $size = false; |
|
| 3164 | + if (!isset($size)) { |
|
| 3165 | + $size = false; |
|
| 3166 | + } |
|
| 2998 | 3167 | |
| 2999 | 3168 | // If this took a long time, we may never have to do it again, but then again we might... |
| 3000 | - if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) |
|
| 3001 | - cache_put_data('url_image_size-' . md5($url), $size, 240); |
|
| 3169 | + if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) { |
|
| 3170 | + cache_put_data('url_image_size-' . md5($url), $size, 240); |
|
| 3171 | + } |
|
| 3002 | 3172 | |
| 3003 | 3173 | // Didn't work. |
| 3004 | 3174 | return $size; |
@@ -3016,8 +3186,9 @@ discard block |
||
| 3016 | 3186 | |
| 3017 | 3187 | // Under SSI this function can be called more then once. That can cause some problems. |
| 3018 | 3188 | // So only run the function once unless we are forced to run it again. |
| 3019 | - if ($loaded && !$forceload) |
|
| 3020 | - return; |
|
| 3189 | + if ($loaded && !$forceload) { |
|
| 3190 | + return; |
|
| 3191 | + } |
|
| 3021 | 3192 | |
| 3022 | 3193 | $loaded = true; |
| 3023 | 3194 | |
@@ -3029,14 +3200,16 @@ discard block |
||
| 3029 | 3200 | $context['news_lines'] = array_filter(explode("\n", str_replace("\r", '', trim(addslashes($modSettings['news']))))); |
| 3030 | 3201 | for ($i = 0, $n = count($context['news_lines']); $i < $n; $i++) |
| 3031 | 3202 | { |
| 3032 | - if (trim($context['news_lines'][$i]) == '') |
|
| 3033 | - continue; |
|
| 3203 | + if (trim($context['news_lines'][$i]) == '') { |
|
| 3204 | + continue; |
|
| 3205 | + } |
|
| 3034 | 3206 | |
| 3035 | 3207 | // Clean it up for presentation ;). |
| 3036 | 3208 | $context['news_lines'][$i] = parse_bbc(stripslashes(trim($context['news_lines'][$i])), true, 'news' . $i); |
| 3037 | 3209 | } |
| 3038 | - if (!empty($context['news_lines'])) |
|
| 3039 | - $context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)]; |
|
| 3210 | + if (!empty($context['news_lines'])) { |
|
| 3211 | + $context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)]; |
|
| 3212 | + } |
|
| 3040 | 3213 | |
| 3041 | 3214 | if (!$user_info['is_guest']) |
| 3042 | 3215 | { |
@@ -3045,40 +3218,48 @@ discard block |
||
| 3045 | 3218 | $context['user']['alerts'] = &$user_info['alerts']; |
| 3046 | 3219 | |
| 3047 | 3220 | // Personal message popup... |
| 3048 | - if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) |
|
| 3049 | - $context['user']['popup_messages'] = true; |
|
| 3050 | - else |
|
| 3051 | - $context['user']['popup_messages'] = false; |
|
| 3221 | + if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) { |
|
| 3222 | + $context['user']['popup_messages'] = true; |
|
| 3223 | + } else { |
|
| 3224 | + $context['user']['popup_messages'] = false; |
|
| 3225 | + } |
|
| 3052 | 3226 | $_SESSION['unread_messages'] = $user_info['unread_messages']; |
| 3053 | 3227 | |
| 3054 | - if (allowedTo('moderate_forum')) |
|
| 3055 | - $context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0; |
|
| 3228 | + if (allowedTo('moderate_forum')) { |
|
| 3229 | + $context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0; |
|
| 3230 | + } |
|
| 3056 | 3231 | |
| 3057 | 3232 | $context['user']['avatar'] = array(); |
| 3058 | 3233 | |
| 3059 | 3234 | // Check for gravatar first since we might be forcing them... |
| 3060 | 3235 | if (($modSettings['gravatarEnabled'] && substr($user_info['avatar']['url'], 0, 11) == 'gravatar://') || !empty($modSettings['gravatarOverride'])) |
| 3061 | 3236 | { |
| 3062 | - if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) |
|
| 3063 | - $context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11)); |
|
| 3064 | - else |
|
| 3065 | - $context['user']['avatar']['href'] = get_gravatar_url($user_info['email']); |
|
| 3237 | + if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) { |
|
| 3238 | + $context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11)); |
|
| 3239 | + } else { |
|
| 3240 | + $context['user']['avatar']['href'] = get_gravatar_url($user_info['email']); |
|
| 3241 | + } |
|
| 3066 | 3242 | } |
| 3067 | 3243 | // Uploaded? |
| 3068 | - elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) |
|
| 3069 | - $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'; |
|
| 3244 | + elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) { |
|
| 3245 | + $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'; |
|
| 3246 | + } |
|
| 3070 | 3247 | // Full URL? |
| 3071 | - elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) |
|
| 3072 | - $context['user']['avatar']['href'] = $user_info['avatar']['url']; |
|
| 3248 | + elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) { |
|
| 3249 | + $context['user']['avatar']['href'] = $user_info['avatar']['url']; |
|
| 3250 | + } |
|
| 3073 | 3251 | // Otherwise we assume it's server stored. |
| 3074 | - elseif ($user_info['avatar']['url'] != '') |
|
| 3075 | - $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']); |
|
| 3252 | + elseif ($user_info['avatar']['url'] != '') { |
|
| 3253 | + $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']); |
|
| 3254 | + } |
|
| 3076 | 3255 | // No avatar at all? Fine, we have a big fat default avatar ;) |
| 3077 | - else |
|
| 3078 | - $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png'; |
|
| 3256 | + else { |
|
| 3257 | + $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png'; |
|
| 3258 | + } |
|
| 3079 | 3259 | |
| 3080 | - if (!empty($context['user']['avatar'])) |
|
| 3081 | - $context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">'; |
|
| 3260 | + if (!empty($context['user']['avatar'])) { |
|
| 3261 | + $context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">'; |
|
| 3262 | + } |
|
| 3082 | 3263 | |
| 3083 | 3264 | // Figure out how long they've been logged in. |
| 3084 | 3265 | $context['user']['total_time_logged_in'] = array( |
@@ -3086,8 +3267,7 @@ discard block |
||
| 3086 | 3267 | 'hours' => floor(($user_info['total_time_logged_in'] % 86400) / 3600), |
| 3087 | 3268 | 'minutes' => floor(($user_info['total_time_logged_in'] % 3600) / 60) |
| 3088 | 3269 | ); |
| 3089 | - } |
|
| 3090 | - else |
|
| 3270 | + } else |
|
| 3091 | 3271 | { |
| 3092 | 3272 | $context['user']['messages'] = 0; |
| 3093 | 3273 | $context['user']['unread_messages'] = 0; |
@@ -3095,12 +3275,14 @@ discard block |
||
| 3095 | 3275 | $context['user']['total_time_logged_in'] = array('days' => 0, 'hours' => 0, 'minutes' => 0); |
| 3096 | 3276 | $context['user']['popup_messages'] = false; |
| 3097 | 3277 | |
| 3098 | - if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) |
|
| 3099 | - $txt['welcome_guest'] .= $txt['welcome_guest_activate']; |
|
| 3278 | + if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) { |
|
| 3279 | + $txt['welcome_guest'] .= $txt['welcome_guest_activate']; |
|
| 3280 | + } |
|
| 3100 | 3281 | |
| 3101 | 3282 | // If we've upgraded recently, go easy on the passwords. |
| 3102 | - if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) |
|
| 3103 | - $context['disable_login_hashing'] = true; |
|
| 3283 | + if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) { |
|
| 3284 | + $context['disable_login_hashing'] = true; |
|
| 3285 | + } |
|
| 3104 | 3286 | } |
| 3105 | 3287 | |
| 3106 | 3288 | // Setup the main menu items. |
@@ -3113,8 +3295,8 @@ discard block |
||
| 3113 | 3295 | $context['show_pm_popup'] = $context['user']['popup_messages'] && !empty($options['popup_messages']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'pm'); |
| 3114 | 3296 | |
| 3115 | 3297 | // 2.1+: Add the PM popup here instead. Theme authors can still override it simply by editing/removing the 'fPmPopup' in the array. |
| 3116 | - if ($context['show_pm_popup']) |
|
| 3117 | - addInlineJavaScript(' |
|
| 3298 | + if ($context['show_pm_popup']) { |
|
| 3299 | + addInlineJavaScript(' |
|
| 3118 | 3300 | jQuery(document).ready(function($) { |
| 3119 | 3301 | new smc_Popup({ |
| 3120 | 3302 | heading: ' . JavaScriptEscape($txt['show_personal_messages_heading']) . ', |
@@ -3122,15 +3304,17 @@ discard block |
||
| 3122 | 3304 | icon_class: \'generic_icons mail_new\' |
| 3123 | 3305 | }); |
| 3124 | 3306 | });'); |
| 3307 | + } |
|
| 3125 | 3308 | |
| 3126 | 3309 | // Add a generic "Are you sure?" confirmation message. |
| 3127 | 3310 | addInlineJavaScript(' |
| 3128 | 3311 | var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';'); |
| 3129 | 3312 | |
| 3130 | 3313 | // Now add the capping code for avatars. |
| 3131 | - 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') |
|
| 3132 | - addInlineCss(' |
|
| 3314 | + 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') { |
|
| 3315 | + addInlineCss(' |
|
| 3133 | 3316 | img.avatar { max-width: ' . $modSettings['avatar_max_width_external'] . 'px; max-height: ' . $modSettings['avatar_max_height_external'] . 'px; }'); |
| 3317 | + } |
|
| 3134 | 3318 | |
| 3135 | 3319 | // This looks weird, but it's because BoardIndex.php references the variable. |
| 3136 | 3320 | $context['common_stats']['latest_member'] = array( |
@@ -3147,11 +3331,13 @@ discard block |
||
| 3147 | 3331 | ); |
| 3148 | 3332 | $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']); |
| 3149 | 3333 | |
| 3150 | - if (empty($settings['theme_version'])) |
|
| 3151 | - addJavaScriptVar('smf_scripturl', $scripturl); |
|
| 3334 | + if (empty($settings['theme_version'])) { |
|
| 3335 | + addJavaScriptVar('smf_scripturl', $scripturl); |
|
| 3336 | + } |
|
| 3152 | 3337 | |
| 3153 | - if (!isset($context['page_title'])) |
|
| 3154 | - $context['page_title'] = ''; |
|
| 3338 | + if (!isset($context['page_title'])) { |
|
| 3339 | + $context['page_title'] = ''; |
|
| 3340 | + } |
|
| 3155 | 3341 | |
| 3156 | 3342 | // Set some specific vars. |
| 3157 | 3343 | $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); |
@@ -3161,21 +3347,23 @@ discard block |
||
| 3161 | 3347 | $context['meta_tags'][] = array('property' => 'og:site_name', 'content' => $context['forum_name']); |
| 3162 | 3348 | $context['meta_tags'][] = array('property' => 'og:title', 'content' => $context['page_title_html_safe']); |
| 3163 | 3349 | |
| 3164 | - if (!empty($context['meta_keywords'])) |
|
| 3165 | - $context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']); |
|
| 3350 | + if (!empty($context['meta_keywords'])) { |
|
| 3351 | + $context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']); |
|
| 3352 | + } |
|
| 3166 | 3353 | |
| 3167 | - if (!empty($context['canonical_url'])) |
|
| 3168 | - $context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']); |
|
| 3354 | + if (!empty($context['canonical_url'])) { |
|
| 3355 | + $context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']); |
|
| 3356 | + } |
|
| 3169 | 3357 | |
| 3170 | - if (!empty($settings['og_image'])) |
|
| 3171 | - $context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']); |
|
| 3358 | + if (!empty($settings['og_image'])) { |
|
| 3359 | + $context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']); |
|
| 3360 | + } |
|
| 3172 | 3361 | |
| 3173 | 3362 | if (!empty($context['meta_description'])) |
| 3174 | 3363 | { |
| 3175 | 3364 | $context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['meta_description']); |
| 3176 | 3365 | $context['meta_tags'][] = array('name' => 'description', 'content' => $context['meta_description']); |
| 3177 | - } |
|
| 3178 | - else |
|
| 3366 | + } else |
|
| 3179 | 3367 | { |
| 3180 | 3368 | $context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['page_title_html_safe']); |
| 3181 | 3369 | $context['meta_tags'][] = array('name' => 'description', 'content' => $context['page_title_html_safe']); |
@@ -3200,8 +3388,9 @@ discard block |
||
| 3200 | 3388 | $memory_needed = memoryReturnBytes($needed); |
| 3201 | 3389 | |
| 3202 | 3390 | // should we account for how much is currently being used? |
| 3203 | - if ($in_use) |
|
| 3204 | - $memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576); |
|
| 3391 | + if ($in_use) { |
|
| 3392 | + $memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576); |
|
| 3393 | + } |
|
| 3205 | 3394 | |
| 3206 | 3395 | // if more is needed, request it |
| 3207 | 3396 | if ($memory_current < $memory_needed) |
@@ -3224,8 +3413,9 @@ discard block |
||
| 3224 | 3413 | */ |
| 3225 | 3414 | function memoryReturnBytes($val) |
| 3226 | 3415 | { |
| 3227 | - if (is_integer($val)) |
|
| 3228 | - return $val; |
|
| 3416 | + if (is_integer($val)) { |
|
| 3417 | + return $val; |
|
| 3418 | + } |
|
| 3229 | 3419 | |
| 3230 | 3420 | // Separate the number from the designator |
| 3231 | 3421 | $val = trim($val); |
@@ -3261,10 +3451,11 @@ discard block |
||
| 3261 | 3451 | header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); |
| 3262 | 3452 | |
| 3263 | 3453 | // Are we debugging the template/html content? |
| 3264 | - if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) |
|
| 3265 | - header('Content-Type: application/xhtml+xml'); |
|
| 3266 | - elseif (!isset($_REQUEST['xml'])) |
|
| 3267 | - header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
| 3454 | + if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) { |
|
| 3455 | + header('Content-Type: application/xhtml+xml'); |
|
| 3456 | + } elseif (!isset($_REQUEST['xml'])) { |
|
| 3457 | + header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
| 3458 | + } |
|
| 3268 | 3459 | } |
| 3269 | 3460 | |
| 3270 | 3461 | header('Content-Type: text/' . (isset($_REQUEST['xml']) ? 'xml' : 'html') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
@@ -3273,8 +3464,9 @@ discard block |
||
| 3273 | 3464 | if ($context['in_maintenance'] && $context['user']['is_admin']) |
| 3274 | 3465 | { |
| 3275 | 3466 | $position = array_search('body', $context['template_layers']); |
| 3276 | - if ($position === false) |
|
| 3277 | - $position = array_search('main', $context['template_layers']); |
|
| 3467 | + if ($position === false) { |
|
| 3468 | + $position = array_search('main', $context['template_layers']); |
|
| 3469 | + } |
|
| 3278 | 3470 | |
| 3279 | 3471 | if ($position !== false) |
| 3280 | 3472 | { |
@@ -3302,23 +3494,25 @@ discard block |
||
| 3302 | 3494 | |
| 3303 | 3495 | foreach ($securityFiles as $i => $securityFile) |
| 3304 | 3496 | { |
| 3305 | - if (!file_exists($boarddir . '/' . $securityFile)) |
|
| 3306 | - unset($securityFiles[$i]); |
|
| 3497 | + if (!file_exists($boarddir . '/' . $securityFile)) { |
|
| 3498 | + unset($securityFiles[$i]); |
|
| 3499 | + } |
|
| 3307 | 3500 | } |
| 3308 | 3501 | |
| 3309 | 3502 | // We are already checking so many files...just few more doesn't make any difference! :P |
| 3310 | - if (!empty($modSettings['currentAttachmentUploadDir'])) |
|
| 3311 | - $path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; |
|
| 3312 | - |
|
| 3313 | - else |
|
| 3314 | - $path = $modSettings['attachmentUploadDir']; |
|
| 3503 | + if (!empty($modSettings['currentAttachmentUploadDir'])) { |
|
| 3504 | + $path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; |
|
| 3505 | + } else { |
|
| 3506 | + $path = $modSettings['attachmentUploadDir']; |
|
| 3507 | + } |
|
| 3315 | 3508 | |
| 3316 | 3509 | secureDirectory($path, true); |
| 3317 | 3510 | secureDirectory($cachedir); |
| 3318 | 3511 | |
| 3319 | 3512 | // If agreement is enabled, at least the english version shall exists |
| 3320 | - if ($modSettings['requireAgreement']) |
|
| 3321 | - $agreement = !file_exists($boarddir . '/agreement.txt'); |
|
| 3513 | + if ($modSettings['requireAgreement']) { |
|
| 3514 | + $agreement = !file_exists($boarddir . '/agreement.txt'); |
|
| 3515 | + } |
|
| 3322 | 3516 | |
| 3323 | 3517 | if (!empty($securityFiles) || (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) || !empty($agreement)) |
| 3324 | 3518 | { |
@@ -3333,18 +3527,21 @@ discard block |
||
| 3333 | 3527 | echo ' |
| 3334 | 3528 | ', $txt['not_removed'], '<strong>', $securityFile, '</strong>!<br>'; |
| 3335 | 3529 | |
| 3336 | - if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') |
|
| 3337 | - echo ' |
|
| 3530 | + if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') { |
|
| 3531 | + echo ' |
|
| 3338 | 3532 | ', sprintf($txt['not_removed_extra'], $securityFile, substr($securityFile, 0, -1)), '<br>'; |
| 3533 | + } |
|
| 3339 | 3534 | } |
| 3340 | 3535 | |
| 3341 | - if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) |
|
| 3342 | - echo ' |
|
| 3536 | + if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) { |
|
| 3537 | + echo ' |
|
| 3343 | 3538 | <strong>', $txt['cache_writable'], '</strong><br>'; |
| 3539 | + } |
|
| 3344 | 3540 | |
| 3345 | - if (!empty($agreement)) |
|
| 3346 | - echo ' |
|
| 3541 | + if (!empty($agreement)) { |
|
| 3542 | + echo ' |
|
| 3347 | 3543 | <strong>', $txt['agreement_missing'], '</strong><br>'; |
| 3544 | + } |
|
| 3348 | 3545 | |
| 3349 | 3546 | echo ' |
| 3350 | 3547 | </p> |
@@ -3359,16 +3556,18 @@ discard block |
||
| 3359 | 3556 | <div class="windowbg alert" style="margin: 2ex; padding: 2ex; border: 2px dashed red;"> |
| 3360 | 3557 | ', sprintf($txt['you_are_post_banned'], $user_info['is_guest'] ? $txt['guest_title'] : $user_info['name']); |
| 3361 | 3558 | |
| 3362 | - if (!empty($_SESSION['ban']['cannot_post']['reason'])) |
|
| 3363 | - echo ' |
|
| 3559 | + if (!empty($_SESSION['ban']['cannot_post']['reason'])) { |
|
| 3560 | + echo ' |
|
| 3364 | 3561 | <div style="padding-left: 4ex; padding-top: 1ex;">', $_SESSION['ban']['cannot_post']['reason'], '</div>'; |
| 3562 | + } |
|
| 3365 | 3563 | |
| 3366 | - if (!empty($_SESSION['ban']['expire_time'])) |
|
| 3367 | - echo ' |
|
| 3564 | + if (!empty($_SESSION['ban']['expire_time'])) { |
|
| 3565 | + echo ' |
|
| 3368 | 3566 | <div>', sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)), '</div>'; |
| 3369 | - else |
|
| 3370 | - echo ' |
|
| 3567 | + } else { |
|
| 3568 | + echo ' |
|
| 3371 | 3569 | <div>', $txt['your_ban_expires_never'], '</div>'; |
| 3570 | + } |
|
| 3372 | 3571 | |
| 3373 | 3572 | echo ' |
| 3374 | 3573 | </div>'; |
@@ -3384,8 +3583,9 @@ discard block |
||
| 3384 | 3583 | global $forum_copyright, $software_year, $forum_version; |
| 3385 | 3584 | |
| 3386 | 3585 | // Don't display copyright for things like SSI. |
| 3387 | - if (!isset($forum_version) || !isset($software_year)) |
|
| 3388 | - return; |
|
| 3586 | + if (!isset($forum_version) || !isset($software_year)) { |
|
| 3587 | + return; |
|
| 3588 | + } |
|
| 3389 | 3589 | |
| 3390 | 3590 | // Put in the version... |
| 3391 | 3591 | printf($forum_copyright, $forum_version, $software_year); |
@@ -3403,9 +3603,10 @@ discard block |
||
| 3403 | 3603 | $context['load_time'] = comma_format(round(array_sum(explode(' ', microtime())) - array_sum(explode(' ', $time_start)), 3)); |
| 3404 | 3604 | $context['load_queries'] = $db_count; |
| 3405 | 3605 | |
| 3406 | - foreach (array_reverse($context['template_layers']) as $layer) |
|
| 3407 | - loadSubTemplate($layer . '_below', true); |
|
| 3408 | -} |
|
| 3606 | + foreach (array_reverse($context['template_layers']) as $layer) { |
|
| 3607 | + loadSubTemplate($layer . '_below', true); |
|
| 3608 | + } |
|
| 3609 | + } |
|
| 3409 | 3610 | |
| 3410 | 3611 | /** |
| 3411 | 3612 | * Output the Javascript files |
@@ -3436,8 +3637,7 @@ discard block |
||
| 3436 | 3637 | { |
| 3437 | 3638 | echo ' |
| 3438 | 3639 | var ', $key, ';'; |
| 3439 | - } |
|
| 3440 | - else |
|
| 3640 | + } else |
|
| 3441 | 3641 | { |
| 3442 | 3642 | echo ' |
| 3443 | 3643 | var ', $key, ' = ', $value, ';'; |
@@ -3452,26 +3652,27 @@ discard block |
||
| 3452 | 3652 | foreach ($context['javascript_files'] as $id => $js_file) |
| 3453 | 3653 | { |
| 3454 | 3654 | // Last minute call! allow theme authors to disable single files. |
| 3455 | - if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) |
|
| 3456 | - continue; |
|
| 3655 | + if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) { |
|
| 3656 | + continue; |
|
| 3657 | + } |
|
| 3457 | 3658 | |
| 3458 | 3659 | // By default all files don't get minimized unless the file explicitly says so! |
| 3459 | 3660 | if (!empty($js_file['options']['minimize']) && !empty($modSettings['minimize_files'])) |
| 3460 | 3661 | { |
| 3461 | - if ($do_deferred && !empty($js_file['options']['defer'])) |
|
| 3462 | - $toMinifyDefer[] = $js_file; |
|
| 3463 | - |
|
| 3464 | - elseif (!$do_deferred && empty($js_file['options']['defer'])) |
|
| 3465 | - $toMinify[] = $js_file; |
|
| 3662 | + if ($do_deferred && !empty($js_file['options']['defer'])) { |
|
| 3663 | + $toMinifyDefer[] = $js_file; |
|
| 3664 | + } elseif (!$do_deferred && empty($js_file['options']['defer'])) { |
|
| 3665 | + $toMinify[] = $js_file; |
|
| 3666 | + } |
|
| 3466 | 3667 | |
| 3467 | 3668 | // Grab a random seed. |
| 3468 | - if (!isset($minSeed)) |
|
| 3469 | - $minSeed = $js_file['options']['seed']; |
|
| 3470 | - } |
|
| 3471 | - |
|
| 3472 | - elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer']))) |
|
| 3473 | - echo ' |
|
| 3669 | + if (!isset($minSeed)) { |
|
| 3670 | + $minSeed = $js_file['options']['seed']; |
|
| 3671 | + } |
|
| 3672 | + } elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer']))) { |
|
| 3673 | + echo ' |
|
| 3474 | 3674 | <script src="', $js_file['fileUrl'], '"', !empty($js_file['options']['async']) ? ' async="async"' : '', '></script>'; |
| 3675 | + } |
|
| 3475 | 3676 | } |
| 3476 | 3677 | |
| 3477 | 3678 | if ((!$do_deferred && !empty($toMinify)) || ($do_deferred && !empty($toMinifyDefer))) |
@@ -3479,14 +3680,14 @@ discard block |
||
| 3479 | 3680 | $result = custMinify(($do_deferred ? $toMinifyDefer : $toMinify), 'js', $do_deferred); |
| 3480 | 3681 | |
| 3481 | 3682 | // Minify process couldn't work, print each individual files. |
| 3482 | - if (!empty($result) && is_array($result)) |
|
| 3483 | - foreach ($result as $minFailedFile) |
|
| 3683 | + if (!empty($result) && is_array($result)) { |
|
| 3684 | + foreach ($result as $minFailedFile) |
|
| 3484 | 3685 | echo ' |
| 3485 | 3686 | <script src="', $minFailedFile['fileUrl'], '"', !empty($minFailedFile['options']['async']) ? ' async="async"' : '', '></script>'; |
| 3486 | - |
|
| 3487 | - else |
|
| 3488 | - echo ' |
|
| 3687 | + } else { |
|
| 3688 | + echo ' |
|
| 3489 | 3689 | <script src="', $settings['theme_url'] ,'/scripts/minified', ($do_deferred ? '_deferred' : '') ,'.js', $minSeed ,'"></script>'; |
| 3690 | + } |
|
| 3490 | 3691 | } |
| 3491 | 3692 | |
| 3492 | 3693 | // Inline JavaScript - Actually useful some times! |
@@ -3497,8 +3698,9 @@ discard block |
||
| 3497 | 3698 | echo ' |
| 3498 | 3699 | <script>'; |
| 3499 | 3700 | |
| 3500 | - foreach ($context['javascript_inline']['defer'] as $js_code) |
|
| 3501 | - echo $js_code; |
|
| 3701 | + foreach ($context['javascript_inline']['defer'] as $js_code) { |
|
| 3702 | + echo $js_code; |
|
| 3703 | + } |
|
| 3502 | 3704 | |
| 3503 | 3705 | echo ' |
| 3504 | 3706 | </script>'; |
@@ -3509,8 +3711,9 @@ discard block |
||
| 3509 | 3711 | echo ' |
| 3510 | 3712 | <script>'; |
| 3511 | 3713 | |
| 3512 | - foreach ($context['javascript_inline']['standard'] as $js_code) |
|
| 3513 | - echo $js_code; |
|
| 3714 | + foreach ($context['javascript_inline']['standard'] as $js_code) { |
|
| 3715 | + echo $js_code; |
|
| 3716 | + } |
|
| 3514 | 3717 | |
| 3515 | 3718 | echo ' |
| 3516 | 3719 | </script>'; |
@@ -3535,8 +3738,9 @@ discard block |
||
| 3535 | 3738 | foreach ($context['css_files'] as $id => $file) |
| 3536 | 3739 | { |
| 3537 | 3740 | // Last minute call! allow theme authors to disable single files. |
| 3538 | - if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) |
|
| 3539 | - continue; |
|
| 3741 | + if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) { |
|
| 3742 | + continue; |
|
| 3743 | + } |
|
| 3540 | 3744 | |
| 3541 | 3745 | // By default all files don't get minimized unless the file explicitly says so! |
| 3542 | 3746 | if (!empty($file['options']['minimize']) && !empty($modSettings['minimize_files'])) |
@@ -3544,12 +3748,12 @@ discard block |
||
| 3544 | 3748 | $toMinify[] = $file; |
| 3545 | 3749 | |
| 3546 | 3750 | // Grab a random seed. |
| 3547 | - if (!isset($minSeed)) |
|
| 3548 | - $minSeed = $file['options']['seed']; |
|
| 3751 | + if (!isset($minSeed)) { |
|
| 3752 | + $minSeed = $file['options']['seed']; |
|
| 3753 | + } |
|
| 3754 | + } else { |
|
| 3755 | + $normal[] = $file['fileUrl']; |
|
| 3549 | 3756 | } |
| 3550 | - |
|
| 3551 | - else |
|
| 3552 | - $normal[] = $file['fileUrl']; |
|
| 3553 | 3757 | } |
| 3554 | 3758 | |
| 3555 | 3759 | if (!empty($toMinify)) |
@@ -3557,28 +3761,30 @@ discard block |
||
| 3557 | 3761 | $result = custMinify($toMinify, 'css'); |
| 3558 | 3762 | |
| 3559 | 3763 | // Minify process couldn't work, print each individual files. |
| 3560 | - if (!empty($result) && is_array($result)) |
|
| 3561 | - foreach ($result as $minFailedFile) |
|
| 3764 | + if (!empty($result) && is_array($result)) { |
|
| 3765 | + foreach ($result as $minFailedFile) |
|
| 3562 | 3766 | echo ' |
| 3563 | 3767 | <link rel="stylesheet" href="', $minFailedFile['fileUrl'], '">'; |
| 3564 | - |
|
| 3565 | - else |
|
| 3566 | - echo ' |
|
| 3768 | + } else { |
|
| 3769 | + echo ' |
|
| 3567 | 3770 | <link rel="stylesheet" href="', $settings['theme_url'] ,'/css/minified.css', $minSeed ,'">'; |
| 3771 | + } |
|
| 3568 | 3772 | } |
| 3569 | 3773 | |
| 3570 | 3774 | // Print the rest after the minified files. |
| 3571 | - if (!empty($normal)) |
|
| 3572 | - foreach ($normal as $nf) |
|
| 3775 | + if (!empty($normal)) { |
|
| 3776 | + foreach ($normal as $nf) |
|
| 3573 | 3777 | echo ' |
| 3574 | 3778 | <link rel="stylesheet" href="', $nf ,'">'; |
| 3779 | + } |
|
| 3575 | 3780 | |
| 3576 | 3781 | if ($db_show_debug === true) |
| 3577 | 3782 | { |
| 3578 | 3783 | // Try to keep only what's useful. |
| 3579 | 3784 | $repl = array($boardurl . '/Themes/' => '', $boardurl . '/' => ''); |
| 3580 | - foreach ($context['css_files'] as $file) |
|
| 3581 | - $context['debug']['sheets'][] = strtr($file['fileName'], $repl); |
|
| 3785 | + foreach ($context['css_files'] as $file) { |
|
| 3786 | + $context['debug']['sheets'][] = strtr($file['fileName'], $repl); |
|
| 3787 | + } |
|
| 3582 | 3788 | } |
| 3583 | 3789 | |
| 3584 | 3790 | if (!empty($context['css_header'])) |
@@ -3586,9 +3792,10 @@ discard block |
||
| 3586 | 3792 | echo ' |
| 3587 | 3793 | <style>'; |
| 3588 | 3794 | |
| 3589 | - foreach ($context['css_header'] as $css) |
|
| 3590 | - echo $css .' |
|
| 3795 | + foreach ($context['css_header'] as $css) { |
|
| 3796 | + echo $css .' |
|
| 3591 | 3797 | '; |
| 3798 | + } |
|
| 3592 | 3799 | |
| 3593 | 3800 | echo' |
| 3594 | 3801 | </style>'; |
@@ -3612,15 +3819,17 @@ discard block |
||
| 3612 | 3819 | $type = !empty($type) && in_array($type, $types) ? $type : false; |
| 3613 | 3820 | $data = !empty($data) ? $data : false; |
| 3614 | 3821 | |
| 3615 | - if (empty($type) || empty($data)) |
|
| 3616 | - return false; |
|
| 3822 | + if (empty($type) || empty($data)) { |
|
| 3823 | + return false; |
|
| 3824 | + } |
|
| 3617 | 3825 | |
| 3618 | 3826 | // Did we already did this? |
| 3619 | 3827 | $toCache = cache_get_data('minimized_'. $settings['theme_id'] .'_'. $type, 86400); |
| 3620 | 3828 | |
| 3621 | 3829 | // Already done? |
| 3622 | - if (!empty($toCache)) |
|
| 3623 | - return true; |
|
| 3830 | + if (!empty($toCache)) { |
|
| 3831 | + return true; |
|
| 3832 | + } |
|
| 3624 | 3833 | |
| 3625 | 3834 | // No namespaces, sorry! |
| 3626 | 3835 | $classType = 'MatthiasMullie\\Minify\\'. strtoupper($type); |
@@ -3702,8 +3911,9 @@ discard block |
||
| 3702 | 3911 | global $modSettings, $smcFunc; |
| 3703 | 3912 | |
| 3704 | 3913 | // Just make up a nice hash... |
| 3705 | - if ($new) |
|
| 3706 | - return sha1(md5($filename . time()) . mt_rand()); |
|
| 3914 | + if ($new) { |
|
| 3915 | + return sha1(md5($filename . time()) . mt_rand()); |
|
| 3916 | + } |
|
| 3707 | 3917 | |
| 3708 | 3918 | // Just make sure that attachment id is only a int |
| 3709 | 3919 | $attachment_id = (int) $attachment_id; |
@@ -3720,23 +3930,25 @@ discard block |
||
| 3720 | 3930 | 'id_attach' => $attachment_id, |
| 3721 | 3931 | )); |
| 3722 | 3932 | |
| 3723 | - if ($smcFunc['db_num_rows']($request) === 0) |
|
| 3724 | - return false; |
|
| 3933 | + if ($smcFunc['db_num_rows']($request) === 0) { |
|
| 3934 | + return false; |
|
| 3935 | + } |
|
| 3725 | 3936 | |
| 3726 | 3937 | list ($file_hash) = $smcFunc['db_fetch_row']($request); |
| 3727 | 3938 | $smcFunc['db_free_result']($request); |
| 3728 | 3939 | } |
| 3729 | 3940 | |
| 3730 | 3941 | // Still no hash? mmm... |
| 3731 | - if (empty($file_hash)) |
|
| 3732 | - $file_hash = sha1(md5($filename . time()) . mt_rand()); |
|
| 3942 | + if (empty($file_hash)) { |
|
| 3943 | + $file_hash = sha1(md5($filename . time()) . mt_rand()); |
|
| 3944 | + } |
|
| 3733 | 3945 | |
| 3734 | 3946 | // Are we using multiple directories? |
| 3735 | - if (is_array($modSettings['attachmentUploadDir'])) |
|
| 3736 | - $path = $modSettings['attachmentUploadDir'][$dir]; |
|
| 3737 | - |
|
| 3738 | - else |
|
| 3739 | - $path = $modSettings['attachmentUploadDir']; |
|
| 3947 | + if (is_array($modSettings['attachmentUploadDir'])) { |
|
| 3948 | + $path = $modSettings['attachmentUploadDir'][$dir]; |
|
| 3949 | + } else { |
|
| 3950 | + $path = $modSettings['attachmentUploadDir']; |
|
| 3951 | + } |
|
| 3740 | 3952 | |
| 3741 | 3953 | return $path . '/' . $attachment_id . '_' . $file_hash .'.dat'; |
| 3742 | 3954 | } |
@@ -3751,8 +3963,9 @@ discard block |
||
| 3751 | 3963 | function ip2range($fullip) |
| 3752 | 3964 | { |
| 3753 | 3965 | // Pretend that 'unknown' is 255.255.255.255. (since that can't be an IP anyway.) |
| 3754 | - if ($fullip == 'unknown') |
|
| 3755 | - $fullip = '255.255.255.255'; |
|
| 3966 | + if ($fullip == 'unknown') { |
|
| 3967 | + $fullip = '255.255.255.255'; |
|
| 3968 | + } |
|
| 3756 | 3969 | |
| 3757 | 3970 | $ip_parts = explode('-', $fullip); |
| 3758 | 3971 | $ip_array = array(); |
@@ -3776,10 +3989,11 @@ discard block |
||
| 3776 | 3989 | $ip_array['low'] = $ip_parts[0]; |
| 3777 | 3990 | $ip_array['high'] = $ip_parts[1]; |
| 3778 | 3991 | return $ip_array; |
| 3779 | - } |
|
| 3780 | - elseif (count($ip_parts) == 2) // if ip 22.22.*-22.22.* |
|
| 3992 | + } elseif (count($ip_parts) == 2) { |
|
| 3993 | + // if ip 22.22.*-22.22.* |
|
| 3781 | 3994 | { |
| 3782 | 3995 | $valid_low = isValidIP($ip_parts[0]); |
| 3996 | + } |
|
| 3783 | 3997 | $valid_high = isValidIP($ip_parts[1]); |
| 3784 | 3998 | $count = 0; |
| 3785 | 3999 | $mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.'); |
@@ -3794,7 +4008,9 @@ discard block |
||
| 3794 | 4008 | $ip_parts[0] .= $mode . $min; |
| 3795 | 4009 | $valid_low = isValidIP($ip_parts[0]); |
| 3796 | 4010 | $count++; |
| 3797 | - if ($count > 9) break; |
|
| 4011 | + if ($count > 9) { |
|
| 4012 | + break; |
|
| 4013 | + } |
|
| 3798 | 4014 | } |
| 3799 | 4015 | } |
| 3800 | 4016 | |
@@ -3808,7 +4024,9 @@ discard block |
||
| 3808 | 4024 | $ip_parts[1] .= $mode . $max; |
| 3809 | 4025 | $valid_high = isValidIP($ip_parts[1]); |
| 3810 | 4026 | $count++; |
| 3811 | - if ($count > 9) break; |
|
| 4027 | + if ($count > 9) { |
|
| 4028 | + break; |
|
| 4029 | + } |
|
| 3812 | 4030 | } |
| 3813 | 4031 | } |
| 3814 | 4032 | |
@@ -3833,46 +4051,54 @@ discard block |
||
| 3833 | 4051 | { |
| 3834 | 4052 | global $modSettings; |
| 3835 | 4053 | |
| 3836 | - if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) |
|
| 3837 | - return $host; |
|
| 4054 | + if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) { |
|
| 4055 | + return $host; |
|
| 4056 | + } |
|
| 3838 | 4057 | $t = microtime(); |
| 3839 | 4058 | |
| 3840 | 4059 | // Try the Linux host command, perhaps? |
| 3841 | 4060 | if (!isset($host) && (strpos(strtolower(PHP_OS), 'win') === false || strpos(strtolower(PHP_OS), 'darwin') !== false) && mt_rand(0, 1) == 1) |
| 3842 | 4061 | { |
| 3843 | - if (!isset($modSettings['host_to_dis'])) |
|
| 3844 | - $test = @shell_exec('host -W 1 ' . @escapeshellarg($ip)); |
|
| 3845 | - else |
|
| 3846 | - $test = @shell_exec('host ' . @escapeshellarg($ip)); |
|
| 4062 | + if (!isset($modSettings['host_to_dis'])) { |
|
| 4063 | + $test = @shell_exec('host -W 1 ' . @escapeshellarg($ip)); |
|
| 4064 | + } else { |
|
| 4065 | + $test = @shell_exec('host ' . @escapeshellarg($ip)); |
|
| 4066 | + } |
|
| 3847 | 4067 | |
| 3848 | 4068 | // Did host say it didn't find anything? |
| 3849 | - if (strpos($test, 'not found') !== false) |
|
| 3850 | - $host = ''; |
|
| 4069 | + if (strpos($test, 'not found') !== false) { |
|
| 4070 | + $host = ''; |
|
| 4071 | + } |
|
| 3851 | 4072 | // Invalid server option? |
| 3852 | - elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) |
|
| 3853 | - updateSettings(array('host_to_dis' => 1)); |
|
| 4073 | + elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) { |
|
| 4074 | + updateSettings(array('host_to_dis' => 1)); |
|
| 4075 | + } |
|
| 3854 | 4076 | // Maybe it found something, after all? |
| 3855 | - elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) |
|
| 3856 | - $host = $match[1]; |
|
| 4077 | + elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) { |
|
| 4078 | + $host = $match[1]; |
|
| 4079 | + } |
|
| 3857 | 4080 | } |
| 3858 | 4081 | |
| 3859 | 4082 | // This is nslookup; usually only Windows, but possibly some Unix? |
| 3860 | 4083 | if (!isset($host) && stripos(PHP_OS, 'win') !== false && strpos(strtolower(PHP_OS), 'darwin') === false && mt_rand(0, 1) == 1) |
| 3861 | 4084 | { |
| 3862 | 4085 | $test = @shell_exec('nslookup -timeout=1 ' . @escapeshellarg($ip)); |
| 3863 | - if (strpos($test, 'Non-existent domain') !== false) |
|
| 3864 | - $host = ''; |
|
| 3865 | - elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) |
|
| 3866 | - $host = $match[1]; |
|
| 4086 | + if (strpos($test, 'Non-existent domain') !== false) { |
|
| 4087 | + $host = ''; |
|
| 4088 | + } elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) { |
|
| 4089 | + $host = $match[1]; |
|
| 4090 | + } |
|
| 3867 | 4091 | } |
| 3868 | 4092 | |
| 3869 | 4093 | // This is the last try :/. |
| 3870 | - if (!isset($host) || $host === false) |
|
| 3871 | - $host = @gethostbyaddr($ip); |
|
| 4094 | + if (!isset($host) || $host === false) { |
|
| 4095 | + $host = @gethostbyaddr($ip); |
|
| 4096 | + } |
|
| 3872 | 4097 | |
| 3873 | 4098 | // It took a long time, so let's cache it! |
| 3874 | - if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) |
|
| 3875 | - cache_put_data('hostlookup-' . $ip, $host, 600); |
|
| 4099 | + if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) { |
|
| 4100 | + cache_put_data('hostlookup-' . $ip, $host, 600); |
|
| 4101 | + } |
|
| 3876 | 4102 | |
| 3877 | 4103 | return $host; |
| 3878 | 4104 | } |
@@ -3908,20 +4134,21 @@ discard block |
||
| 3908 | 4134 | { |
| 3909 | 4135 | $encrypted = substr(crypt($word, 'uk'), 2, $max_chars); |
| 3910 | 4136 | $total = 0; |
| 3911 | - for ($i = 0; $i < $max_chars; $i++) |
|
| 3912 | - $total += $possible_chars[ord($encrypted{$i})] * pow(63, $i); |
|
| 4137 | + for ($i = 0; $i < $max_chars; $i++) { |
|
| 4138 | + $total += $possible_chars[ord($encrypted{$i})] * pow(63, $i); |
|
| 4139 | + } |
|
| 3913 | 4140 | $returned_ints[] = $max_chars == 4 ? min($total, 16777215) : $total; |
| 3914 | 4141 | } |
| 3915 | 4142 | } |
| 3916 | 4143 | return array_unique($returned_ints); |
| 3917 | - } |
|
| 3918 | - else |
|
| 4144 | + } else |
|
| 3919 | 4145 | { |
| 3920 | 4146 | // Trim characters before and after and add slashes for database insertion. |
| 3921 | 4147 | $returned_words = array(); |
| 3922 | - foreach ($words as $word) |
|
| 3923 | - if (($word = trim($word, '-_\'')) !== '') |
|
| 4148 | + foreach ($words as $word) { |
|
| 4149 | + if (($word = trim($word, '-_\'')) !== '') |
|
| 3924 | 4150 | $returned_words[] = $max_chars === null ? $word : substr($word, 0, $max_chars); |
| 4151 | + } |
|
| 3925 | 4152 | |
| 3926 | 4153 | // Filter out all words that occur more than once. |
| 3927 | 4154 | return array_unique($returned_words); |
@@ -3943,16 +4170,18 @@ discard block |
||
| 3943 | 4170 | global $settings, $txt; |
| 3944 | 4171 | |
| 3945 | 4172 | // Does the current loaded theme have this and we are not forcing the usage of this function? |
| 3946 | - if (function_exists('template_create_button') && !$force_use) |
|
| 3947 | - return template_create_button($name, $alt, $label = '', $custom = ''); |
|
| 4173 | + if (function_exists('template_create_button') && !$force_use) { |
|
| 4174 | + return template_create_button($name, $alt, $label = '', $custom = ''); |
|
| 4175 | + } |
|
| 3948 | 4176 | |
| 3949 | - if (!$settings['use_image_buttons']) |
|
| 3950 | - return $txt[$alt]; |
|
| 3951 | - elseif (!empty($settings['use_buttons'])) |
|
| 3952 | - return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? ' <strong>' . $txt[$label] . '</strong>' : ''); |
|
| 3953 | - else |
|
| 3954 | - return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>'; |
|
| 3955 | -} |
|
| 4177 | + if (!$settings['use_image_buttons']) { |
|
| 4178 | + return $txt[$alt]; |
|
| 4179 | + } elseif (!empty($settings['use_buttons'])) { |
|
| 4180 | + return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? ' <strong>' . $txt[$label] . '</strong>' : ''); |
|
| 4181 | + } else { |
|
| 4182 | + return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>'; |
|
| 4183 | + } |
|
| 4184 | + } |
|
| 3956 | 4185 | |
| 3957 | 4186 | /** |
| 3958 | 4187 | * Sets up all of the top menu buttons |
@@ -3995,9 +4224,10 @@ discard block |
||
| 3995 | 4224 | var user_menus = new smc_PopupMenu(); |
| 3996 | 4225 | user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup"); |
| 3997 | 4226 | user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true); |
| 3998 | - if ($context['allow_pm']) |
|
| 3999 | - addInlineJavaScript(' |
|
| 4227 | + if ($context['allow_pm']) { |
|
| 4228 | + addInlineJavaScript(' |
|
| 4000 | 4229 | user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true); |
| 4230 | + } |
|
| 4001 | 4231 | |
| 4002 | 4232 | if (!empty($modSettings['enable_ajax_alerts'])) |
| 4003 | 4233 | { |
@@ -4157,88 +4387,96 @@ discard block |
||
| 4157 | 4387 | |
| 4158 | 4388 | // Now we put the buttons in the context so the theme can use them. |
| 4159 | 4389 | $menu_buttons = array(); |
| 4160 | - foreach ($buttons as $act => $button) |
|
| 4161 | - if (!empty($button['show'])) |
|
| 4390 | + foreach ($buttons as $act => $button) { |
|
| 4391 | + if (!empty($button['show'])) |
|
| 4162 | 4392 | { |
| 4163 | 4393 | $button['active_button'] = false; |
| 4394 | + } |
|
| 4164 | 4395 | |
| 4165 | 4396 | // This button needs some action. |
| 4166 | - if (isset($button['action_hook'])) |
|
| 4167 | - $needs_action_hook = true; |
|
| 4397 | + if (isset($button['action_hook'])) { |
|
| 4398 | + $needs_action_hook = true; |
|
| 4399 | + } |
|
| 4168 | 4400 | |
| 4169 | 4401 | // Make sure the last button truly is the last button. |
| 4170 | 4402 | if (!empty($button['is_last'])) |
| 4171 | 4403 | { |
| 4172 | - if (isset($last_button)) |
|
| 4173 | - unset($menu_buttons[$last_button]['is_last']); |
|
| 4404 | + if (isset($last_button)) { |
|
| 4405 | + unset($menu_buttons[$last_button]['is_last']); |
|
| 4406 | + } |
|
| 4174 | 4407 | $last_button = $act; |
| 4175 | 4408 | } |
| 4176 | 4409 | |
| 4177 | 4410 | // Go through the sub buttons if there are any. |
| 4178 | - if (!empty($button['sub_buttons'])) |
|
| 4179 | - foreach ($button['sub_buttons'] as $key => $subbutton) |
|
| 4411 | + if (!empty($button['sub_buttons'])) { |
|
| 4412 | + foreach ($button['sub_buttons'] as $key => $subbutton) |
|
| 4180 | 4413 | { |
| 4181 | 4414 | if (empty($subbutton['show'])) |
| 4182 | 4415 | unset($button['sub_buttons'][$key]); |
| 4416 | + } |
|
| 4183 | 4417 | |
| 4184 | 4418 | // 2nd level sub buttons next... |
| 4185 | 4419 | if (!empty($subbutton['sub_buttons'])) |
| 4186 | 4420 | { |
| 4187 | 4421 | foreach ($subbutton['sub_buttons'] as $key2 => $sub_button2) |
| 4188 | 4422 | { |
| 4189 | - if (empty($sub_button2['show'])) |
|
| 4190 | - unset($button['sub_buttons'][$key]['sub_buttons'][$key2]); |
|
| 4423 | + if (empty($sub_button2['show'])) { |
|
| 4424 | + unset($button['sub_buttons'][$key]['sub_buttons'][$key2]); |
|
| 4425 | + } |
|
| 4191 | 4426 | } |
| 4192 | 4427 | } |
| 4193 | 4428 | } |
| 4194 | 4429 | |
| 4195 | 4430 | // Does this button have its own icon? |
| 4196 | - if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) |
|
| 4197 | - $button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
| 4198 | - elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) |
|
| 4199 | - $button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
| 4200 | - elseif (isset($button['icon'])) |
|
| 4201 | - $button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>'; |
|
| 4202 | - else |
|
| 4203 | - $button['icon'] = '<span class="generic_icons ' . $act . '"></span>'; |
|
| 4431 | + if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) { |
|
| 4432 | + $button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
| 4433 | + } elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) { |
|
| 4434 | + $button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
| 4435 | + } elseif (isset($button['icon'])) { |
|
| 4436 | + $button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>'; |
|
| 4437 | + } else { |
|
| 4438 | + $button['icon'] = '<span class="generic_icons ' . $act . '"></span>'; |
|
| 4439 | + } |
|
| 4204 | 4440 | |
| 4205 | 4441 | $menu_buttons[$act] = $button; |
| 4206 | 4442 | } |
| 4207 | 4443 | |
| 4208 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
| 4209 | - cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime); |
|
| 4444 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
| 4445 | + cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime); |
|
| 4446 | + } |
|
| 4210 | 4447 | } |
| 4211 | 4448 | |
| 4212 | 4449 | $context['menu_buttons'] = $menu_buttons; |
| 4213 | 4450 | |
| 4214 | 4451 | // Logging out requires the session id in the url. |
| 4215 | - if (isset($context['menu_buttons']['logout'])) |
|
| 4216 | - $context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']); |
|
| 4452 | + if (isset($context['menu_buttons']['logout'])) { |
|
| 4453 | + $context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']); |
|
| 4454 | + } |
|
| 4217 | 4455 | |
| 4218 | 4456 | // Figure out which action we are doing so we can set the active tab. |
| 4219 | 4457 | // Default to home. |
| 4220 | 4458 | $current_action = 'home'; |
| 4221 | 4459 | |
| 4222 | - if (isset($context['menu_buttons'][$context['current_action']])) |
|
| 4223 | - $current_action = $context['current_action']; |
|
| 4224 | - elseif ($context['current_action'] == 'search2') |
|
| 4225 | - $current_action = 'search'; |
|
| 4226 | - elseif ($context['current_action'] == 'theme') |
|
| 4227 | - $current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin'; |
|
| 4228 | - elseif ($context['current_action'] == 'register2') |
|
| 4229 | - $current_action = 'register'; |
|
| 4230 | - elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) |
|
| 4231 | - $current_action = 'login'; |
|
| 4232 | - elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) |
|
| 4233 | - $current_action = 'moderate'; |
|
| 4460 | + if (isset($context['menu_buttons'][$context['current_action']])) { |
|
| 4461 | + $current_action = $context['current_action']; |
|
| 4462 | + } elseif ($context['current_action'] == 'search2') { |
|
| 4463 | + $current_action = 'search'; |
|
| 4464 | + } elseif ($context['current_action'] == 'theme') { |
|
| 4465 | + $current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin'; |
|
| 4466 | + } elseif ($context['current_action'] == 'register2') { |
|
| 4467 | + $current_action = 'register'; |
|
| 4468 | + } elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) { |
|
| 4469 | + $current_action = 'login'; |
|
| 4470 | + } elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) { |
|
| 4471 | + $current_action = 'moderate'; |
|
| 4472 | + } |
|
| 4234 | 4473 | |
| 4235 | 4474 | // There are certain exceptions to the above where we don't want anything on the menu highlighted. |
| 4236 | 4475 | if ($context['current_action'] == 'profile' && !empty($context['user']['is_owner'])) |
| 4237 | 4476 | { |
| 4238 | 4477 | $current_action = !empty($_GET['area']) && $_GET['area'] == 'showalerts' ? 'self_alerts' : 'self_profile'; |
| 4239 | 4478 | $context[$current_action] = true; |
| 4240 | - } |
|
| 4241 | - elseif ($context['current_action'] == 'pm') |
|
| 4479 | + } elseif ($context['current_action'] == 'pm') |
|
| 4242 | 4480 | { |
| 4243 | 4481 | $current_action = 'self_pm'; |
| 4244 | 4482 | $context['self_pm'] = true; |
@@ -4281,12 +4519,14 @@ discard block |
||
| 4281 | 4519 | } |
| 4282 | 4520 | |
| 4283 | 4521 | // Not all actions are simple. |
| 4284 | - if (!empty($needs_action_hook)) |
|
| 4285 | - call_integration_hook('integrate_current_action', array(&$current_action)); |
|
| 4522 | + if (!empty($needs_action_hook)) { |
|
| 4523 | + call_integration_hook('integrate_current_action', array(&$current_action)); |
|
| 4524 | + } |
|
| 4286 | 4525 | |
| 4287 | - if (isset($context['menu_buttons'][$current_action])) |
|
| 4288 | - $context['menu_buttons'][$current_action]['active_button'] = true; |
|
| 4289 | -} |
|
| 4526 | + if (isset($context['menu_buttons'][$current_action])) { |
|
| 4527 | + $context['menu_buttons'][$current_action]['active_button'] = true; |
|
| 4528 | + } |
|
| 4529 | + } |
|
| 4290 | 4530 | |
| 4291 | 4531 | /** |
| 4292 | 4532 | * Generate a random seed and ensure it's stored in settings. |
@@ -4310,16 +4550,19 @@ discard block |
||
| 4310 | 4550 | global $modSettings, $settings, $boarddir, $sourcedir, $db_show_debug; |
| 4311 | 4551 | global $context, $txt; |
| 4312 | 4552 | |
| 4313 | - if ($db_show_debug === true) |
|
| 4314 | - $context['debug']['hooks'][] = $hook; |
|
| 4553 | + if ($db_show_debug === true) { |
|
| 4554 | + $context['debug']['hooks'][] = $hook; |
|
| 4555 | + } |
|
| 4315 | 4556 | |
| 4316 | 4557 | // Need to have some control. |
| 4317 | - if (!isset($context['instances'])) |
|
| 4318 | - $context['instances'] = array(); |
|
| 4558 | + if (!isset($context['instances'])) { |
|
| 4559 | + $context['instances'] = array(); |
|
| 4560 | + } |
|
| 4319 | 4561 | |
| 4320 | 4562 | $results = array(); |
| 4321 | - if (empty($modSettings[$hook])) |
|
| 4322 | - return $results; |
|
| 4563 | + if (empty($modSettings[$hook])) { |
|
| 4564 | + return $results; |
|
| 4565 | + } |
|
| 4323 | 4566 | |
| 4324 | 4567 | // Define some needed vars. |
| 4325 | 4568 | $function = false; |
@@ -4329,14 +4572,16 @@ discard block |
||
| 4329 | 4572 | foreach ($functions as $function) |
| 4330 | 4573 | { |
| 4331 | 4574 | // Hook has been marked as "disabled". Skip it! |
| 4332 | - if (strpos($function, '!') !== false) |
|
| 4333 | - continue; |
|
| 4575 | + if (strpos($function, '!') !== false) { |
|
| 4576 | + continue; |
|
| 4577 | + } |
|
| 4334 | 4578 | |
| 4335 | 4579 | $call = call_helper($function, true); |
| 4336 | 4580 | |
| 4337 | 4581 | // Is it valid? |
| 4338 | - if (!empty($call)) |
|
| 4339 | - $results[$function] = call_user_func_array($call, $parameters); |
|
| 4582 | + if (!empty($call)) { |
|
| 4583 | + $results[$function] = call_user_func_array($call, $parameters); |
|
| 4584 | + } |
|
| 4340 | 4585 | |
| 4341 | 4586 | // Whatever it was suppose to call, it failed :( |
| 4342 | 4587 | elseif (!empty($function)) |
@@ -4352,8 +4597,9 @@ discard block |
||
| 4352 | 4597 | } |
| 4353 | 4598 | |
| 4354 | 4599 | // "Assume" the file resides on $boarddir somewhere... |
| 4355 | - else |
|
| 4356 | - log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general'); |
|
| 4600 | + else { |
|
| 4601 | + log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general'); |
|
| 4602 | + } |
|
| 4357 | 4603 | } |
| 4358 | 4604 | } |
| 4359 | 4605 | |
@@ -4375,12 +4621,14 @@ discard block |
||
| 4375 | 4621 | global $smcFunc, $modSettings; |
| 4376 | 4622 | |
| 4377 | 4623 | // Any objects? |
| 4378 | - if ($object) |
|
| 4379 | - $function = $function . '#'; |
|
| 4624 | + if ($object) { |
|
| 4625 | + $function = $function . '#'; |
|
| 4626 | + } |
|
| 4380 | 4627 | |
| 4381 | 4628 | // Any files to load? |
| 4382 | - if (!empty($file) && is_string($file)) |
|
| 4383 | - $function = $file . (!empty($function) ? '|' . $function : ''); |
|
| 4629 | + if (!empty($file) && is_string($file)) { |
|
| 4630 | + $function = $file . (!empty($function) ? '|' . $function : ''); |
|
| 4631 | + } |
|
| 4384 | 4632 | |
| 4385 | 4633 | // Get the correct string. |
| 4386 | 4634 | $integration_call = $function; |
@@ -4402,13 +4650,14 @@ discard block |
||
| 4402 | 4650 | if (!empty($current_functions)) |
| 4403 | 4651 | { |
| 4404 | 4652 | $current_functions = explode(',', $current_functions); |
| 4405 | - if (in_array($integration_call, $current_functions)) |
|
| 4406 | - return; |
|
| 4653 | + if (in_array($integration_call, $current_functions)) { |
|
| 4654 | + return; |
|
| 4655 | + } |
|
| 4407 | 4656 | |
| 4408 | 4657 | $permanent_functions = array_merge($current_functions, array($integration_call)); |
| 4658 | + } else { |
|
| 4659 | + $permanent_functions = array($integration_call); |
|
| 4409 | 4660 | } |
| 4410 | - else |
|
| 4411 | - $permanent_functions = array($integration_call); |
|
| 4412 | 4661 | |
| 4413 | 4662 | updateSettings(array($hook => implode(',', $permanent_functions))); |
| 4414 | 4663 | } |
@@ -4417,8 +4666,9 @@ discard block |
||
| 4417 | 4666 | $functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]); |
| 4418 | 4667 | |
| 4419 | 4668 | // Do nothing, if it's already there. |
| 4420 | - if (in_array($integration_call, $functions)) |
|
| 4421 | - return; |
|
| 4669 | + if (in_array($integration_call, $functions)) { |
|
| 4670 | + return; |
|
| 4671 | + } |
|
| 4422 | 4672 | |
| 4423 | 4673 | $functions[] = $integration_call; |
| 4424 | 4674 | $modSettings[$hook] = implode(',', $functions); |
@@ -4441,12 +4691,14 @@ discard block |
||
| 4441 | 4691 | global $smcFunc, $modSettings; |
| 4442 | 4692 | |
| 4443 | 4693 | // Any objects? |
| 4444 | - if ($object) |
|
| 4445 | - $function = $function . '#'; |
|
| 4694 | + if ($object) { |
|
| 4695 | + $function = $function . '#'; |
|
| 4696 | + } |
|
| 4446 | 4697 | |
| 4447 | 4698 | // Any files to load? |
| 4448 | - if (!empty($file) && is_string($file)) |
|
| 4449 | - $function = $file . '|' . $function; |
|
| 4699 | + if (!empty($file) && is_string($file)) { |
|
| 4700 | + $function = $file . '|' . $function; |
|
| 4701 | + } |
|
| 4450 | 4702 | |
| 4451 | 4703 | // Get the correct string. |
| 4452 | 4704 | $integration_call = $function; |
@@ -4467,16 +4719,18 @@ discard block |
||
| 4467 | 4719 | { |
| 4468 | 4720 | $current_functions = explode(',', $current_functions); |
| 4469 | 4721 | |
| 4470 | - if (in_array($integration_call, $current_functions)) |
|
| 4471 | - updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call))))); |
|
| 4722 | + if (in_array($integration_call, $current_functions)) { |
|
| 4723 | + updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call))))); |
|
| 4724 | + } |
|
| 4472 | 4725 | } |
| 4473 | 4726 | |
| 4474 | 4727 | // Turn the function list into something usable. |
| 4475 | 4728 | $functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]); |
| 4476 | 4729 | |
| 4477 | 4730 | // You can only remove it if it's available. |
| 4478 | - if (!in_array($integration_call, $functions)) |
|
| 4479 | - return; |
|
| 4731 | + if (!in_array($integration_call, $functions)) { |
|
| 4732 | + return; |
|
| 4733 | + } |
|
| 4480 | 4734 | |
| 4481 | 4735 | $functions = array_diff($functions, array($integration_call)); |
| 4482 | 4736 | $modSettings[$hook] = implode(',', $functions); |
@@ -4497,17 +4751,20 @@ discard block |
||
| 4497 | 4751 | global $context, $smcFunc, $txt, $db_show_debug; |
| 4498 | 4752 | |
| 4499 | 4753 | // Really? |
| 4500 | - if (empty($string)) |
|
| 4501 | - return false; |
|
| 4754 | + if (empty($string)) { |
|
| 4755 | + return false; |
|
| 4756 | + } |
|
| 4502 | 4757 | |
| 4503 | 4758 | // An array? should be a "callable" array IE array(object/class, valid_callable). |
| 4504 | 4759 | // A closure? should be a callable one. |
| 4505 | - if (is_array($string) || $string instanceof Closure) |
|
| 4506 | - return $return ? $string : (is_callable($string) ? call_user_func($string) : false); |
|
| 4760 | + if (is_array($string) || $string instanceof Closure) { |
|
| 4761 | + return $return ? $string : (is_callable($string) ? call_user_func($string) : false); |
|
| 4762 | + } |
|
| 4507 | 4763 | |
| 4508 | 4764 | // No full objects, sorry! pass a method or a property instead! |
| 4509 | - if (is_object($string)) |
|
| 4510 | - return false; |
|
| 4765 | + if (is_object($string)) { |
|
| 4766 | + return false; |
|
| 4767 | + } |
|
| 4511 | 4768 | |
| 4512 | 4769 | // Stay vitaminized my friends... |
| 4513 | 4770 | $string = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($string)); |
@@ -4516,8 +4773,9 @@ discard block |
||
| 4516 | 4773 | $string = load_file($string); |
| 4517 | 4774 | |
| 4518 | 4775 | // Loaded file failed |
| 4519 | - if (empty($string)) |
|
| 4520 | - return false; |
|
| 4776 | + if (empty($string)) { |
|
| 4777 | + return false; |
|
| 4778 | + } |
|
| 4521 | 4779 | |
| 4522 | 4780 | // Found a method. |
| 4523 | 4781 | if (strpos($string, '::') !== false) |
@@ -4538,8 +4796,9 @@ discard block |
||
| 4538 | 4796 | // Add another one to the list. |
| 4539 | 4797 | if ($db_show_debug === true) |
| 4540 | 4798 | { |
| 4541 | - if (!isset($context['debug']['instances'])) |
|
| 4542 | - $context['debug']['instances'] = array(); |
|
| 4799 | + if (!isset($context['debug']['instances'])) { |
|
| 4800 | + $context['debug']['instances'] = array(); |
|
| 4801 | + } |
|
| 4543 | 4802 | |
| 4544 | 4803 | $context['debug']['instances'][$class] = $class; |
| 4545 | 4804 | } |
@@ -4549,13 +4808,15 @@ discard block |
||
| 4549 | 4808 | } |
| 4550 | 4809 | |
| 4551 | 4810 | // Right then. This is a call to a static method. |
| 4552 | - else |
|
| 4553 | - $func = array($class, $method); |
|
| 4811 | + else { |
|
| 4812 | + $func = array($class, $method); |
|
| 4813 | + } |
|
| 4554 | 4814 | } |
| 4555 | 4815 | |
| 4556 | 4816 | // Nope! just a plain regular function. |
| 4557 | - else |
|
| 4558 | - $func = $string; |
|
| 4817 | + else { |
|
| 4818 | + $func = $string; |
|
| 4819 | + } |
|
| 4559 | 4820 | |
| 4560 | 4821 | // Right, we got what we need, time to do some checks. |
| 4561 | 4822 | if (!is_callable($func, false, $callable_name)) |
@@ -4571,17 +4832,18 @@ discard block |
||
| 4571 | 4832 | else |
| 4572 | 4833 | { |
| 4573 | 4834 | // What are we gonna do about it? |
| 4574 | - if ($return) |
|
| 4575 | - return $func; |
|
| 4835 | + if ($return) { |
|
| 4836 | + return $func; |
|
| 4837 | + } |
|
| 4576 | 4838 | |
| 4577 | 4839 | // If this is a plain function, avoid the heat of calling call_user_func(). |
| 4578 | 4840 | else |
| 4579 | 4841 | { |
| 4580 | - if (is_array($func)) |
|
| 4581 | - call_user_func($func); |
|
| 4582 | - |
|
| 4583 | - else |
|
| 4584 | - $func(); |
|
| 4842 | + if (is_array($func)) { |
|
| 4843 | + call_user_func($func); |
|
| 4844 | + } else { |
|
| 4845 | + $func(); |
|
| 4846 | + } |
|
| 4585 | 4847 | } |
| 4586 | 4848 | } |
| 4587 | 4849 | } |
@@ -4598,31 +4860,34 @@ discard block |
||
| 4598 | 4860 | { |
| 4599 | 4861 | global $sourcedir, $txt, $boarddir, $settings; |
| 4600 | 4862 | |
| 4601 | - if (empty($string)) |
|
| 4602 | - return false; |
|
| 4863 | + if (empty($string)) { |
|
| 4864 | + return false; |
|
| 4865 | + } |
|
| 4603 | 4866 | |
| 4604 | 4867 | if (strpos($string, '|') !== false) |
| 4605 | 4868 | { |
| 4606 | 4869 | list ($file, $string) = explode('|', $string); |
| 4607 | 4870 | |
| 4608 | 4871 | // Match the wildcards to their regular vars. |
| 4609 | - if (empty($settings['theme_dir'])) |
|
| 4610 | - $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
|
| 4611 | - |
|
| 4612 | - else |
|
| 4613 | - $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
|
| 4872 | + if (empty($settings['theme_dir'])) { |
|
| 4873 | + $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
|
| 4874 | + } else { |
|
| 4875 | + $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
|
| 4876 | + } |
|
| 4614 | 4877 | |
| 4615 | 4878 | // Load the file if it can be loaded. |
| 4616 | - if (file_exists($absPath)) |
|
| 4617 | - require_once($absPath); |
|
| 4879 | + if (file_exists($absPath)) { |
|
| 4880 | + require_once($absPath); |
|
| 4881 | + } |
|
| 4618 | 4882 | |
| 4619 | 4883 | // No? try a fallback to $sourcedir |
| 4620 | 4884 | else |
| 4621 | 4885 | { |
| 4622 | 4886 | $absPath = $sourcedir .'/'. $file; |
| 4623 | 4887 | |
| 4624 | - if (file_exists($absPath)) |
|
| 4625 | - require_once($absPath); |
|
| 4888 | + if (file_exists($absPath)) { |
|
| 4889 | + require_once($absPath); |
|
| 4890 | + } |
|
| 4626 | 4891 | |
| 4627 | 4892 | // Sorry, can't do much for you at this point. |
| 4628 | 4893 | else |
@@ -4649,8 +4914,9 @@ discard block |
||
| 4649 | 4914 | global $user_info, $smcFunc; |
| 4650 | 4915 | |
| 4651 | 4916 | // Make sure we have something to work with. |
| 4652 | - if (empty($topic)) |
|
| 4653 | - return array(); |
|
| 4917 | + if (empty($topic)) { |
|
| 4918 | + return array(); |
|
| 4919 | + } |
|
| 4654 | 4920 | |
| 4655 | 4921 | |
| 4656 | 4922 | // We already know the number of likes per message, we just want to know whether the current user liked it or not. |
@@ -4673,8 +4939,9 @@ discard block |
||
| 4673 | 4939 | 'topic' => $topic, |
| 4674 | 4940 | ) |
| 4675 | 4941 | ); |
| 4676 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 4677 | - $temp[] = (int) $row['content_id']; |
|
| 4942 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 4943 | + $temp[] = (int) $row['content_id']; |
|
| 4944 | + } |
|
| 4678 | 4945 | |
| 4679 | 4946 | cache_put_data($cache_key, $temp, $ttl); |
| 4680 | 4947 | } |
@@ -4695,8 +4962,9 @@ discard block |
||
| 4695 | 4962 | { |
| 4696 | 4963 | global $context; |
| 4697 | 4964 | |
| 4698 | - if (empty($string)) |
|
| 4699 | - return $string; |
|
| 4965 | + if (empty($string)) { |
|
| 4966 | + return $string; |
|
| 4967 | + } |
|
| 4700 | 4968 | |
| 4701 | 4969 | // UTF-8 occurences of MS special characters |
| 4702 | 4970 | $findchars_utf8 = array( |
@@ -4737,10 +5005,11 @@ discard block |
||
| 4737 | 5005 | '--', // — |
| 4738 | 5006 | ); |
| 4739 | 5007 | |
| 4740 | - if ($context['utf8']) |
|
| 4741 | - $string = str_replace($findchars_utf8, $replacechars, $string); |
|
| 4742 | - else |
|
| 4743 | - $string = str_replace($findchars_iso, $replacechars, $string); |
|
| 5008 | + if ($context['utf8']) { |
|
| 5009 | + $string = str_replace($findchars_utf8, $replacechars, $string); |
|
| 5010 | + } else { |
|
| 5011 | + $string = str_replace($findchars_iso, $replacechars, $string); |
|
| 5012 | + } |
|
| 4744 | 5013 | |
| 4745 | 5014 | return $string; |
| 4746 | 5015 | } |
@@ -4759,49 +5028,59 @@ discard block |
||
| 4759 | 5028 | { |
| 4760 | 5029 | global $context; |
| 4761 | 5030 | |
| 4762 | - if (!isset($matches[2])) |
|
| 4763 | - return ''; |
|
| 5031 | + if (!isset($matches[2])) { |
|
| 5032 | + return ''; |
|
| 5033 | + } |
|
| 4764 | 5034 | |
| 4765 | 5035 | $num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2]; |
| 4766 | 5036 | |
| 4767 | 5037 | // remove left to right / right to left overrides |
| 4768 | - if ($num === 0x202D || $num === 0x202E) |
|
| 4769 | - return ''; |
|
| 5038 | + if ($num === 0x202D || $num === 0x202E) { |
|
| 5039 | + return ''; |
|
| 5040 | + } |
|
| 4770 | 5041 | |
| 4771 | 5042 | // Quote, Ampersand, Apostrophe, Less/Greater Than get html replaced |
| 4772 | - if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) |
|
| 4773 | - return '&#' . $num . ';'; |
|
| 5043 | + if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) { |
|
| 5044 | + return '&#' . $num . ';'; |
|
| 5045 | + } |
|
| 4774 | 5046 | |
| 4775 | 5047 | if (empty($context['utf8'])) |
| 4776 | 5048 | { |
| 4777 | 5049 | // no control characters |
| 4778 | - if ($num < 0x20) |
|
| 4779 | - return ''; |
|
| 5050 | + if ($num < 0x20) { |
|
| 5051 | + return ''; |
|
| 5052 | + } |
|
| 4780 | 5053 | // text is text |
| 4781 | - elseif ($num < 0x80) |
|
| 4782 | - return chr($num); |
|
| 5054 | + elseif ($num < 0x80) { |
|
| 5055 | + return chr($num); |
|
| 5056 | + } |
|
| 4783 | 5057 | // all others get html-ised |
| 4784 | - else |
|
| 4785 | - return '&#' . $matches[2] . ';'; |
|
| 4786 | - } |
|
| 4787 | - else |
|
| 5058 | + else { |
|
| 5059 | + return '&#' . $matches[2] . ';'; |
|
| 5060 | + } |
|
| 5061 | + } else |
|
| 4788 | 5062 | { |
| 4789 | 5063 | // <0x20 are control characters, 0x20 is a space, > 0x10FFFF is past the end of the utf8 character set |
| 4790 | 5064 | // 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text) |
| 4791 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) |
|
| 4792 | - return ''; |
|
| 5065 | + if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) { |
|
| 5066 | + return ''; |
|
| 5067 | + } |
|
| 4793 | 5068 | // <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation |
| 4794 | - elseif ($num < 0x80) |
|
| 4795 | - return chr($num); |
|
| 5069 | + elseif ($num < 0x80) { |
|
| 5070 | + return chr($num); |
|
| 5071 | + } |
|
| 4796 | 5072 | // <0x800 (2048) |
| 4797 | - elseif ($num < 0x800) |
|
| 4798 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 5073 | + elseif ($num < 0x800) { |
|
| 5074 | + return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 5075 | + } |
|
| 4799 | 5076 | // < 0x10000 (65536) |
| 4800 | - elseif ($num < 0x10000) |
|
| 4801 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 5077 | + elseif ($num < 0x10000) { |
|
| 5078 | + return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 5079 | + } |
|
| 4802 | 5080 | // <= 0x10FFFF (1114111) |
| 4803 | - else |
|
| 4804 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 5081 | + else { |
|
| 5082 | + return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 5083 | + } |
|
| 4805 | 5084 | } |
| 4806 | 5085 | } |
| 4807 | 5086 | |
@@ -4817,28 +5096,34 @@ discard block |
||
| 4817 | 5096 | */ |
| 4818 | 5097 | function fixchar__callback($matches) |
| 4819 | 5098 | { |
| 4820 | - if (!isset($matches[1])) |
|
| 4821 | - return ''; |
|
| 5099 | + if (!isset($matches[1])) { |
|
| 5100 | + return ''; |
|
| 5101 | + } |
|
| 4822 | 5102 | |
| 4823 | 5103 | $num = $matches[1][0] === 'x' ? hexdec(substr($matches[1], 1)) : (int) $matches[1]; |
| 4824 | 5104 | |
| 4825 | 5105 | // <0x20 are control characters, > 0x10FFFF is past the end of the utf8 character set |
| 4826 | 5106 | // 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text), 0x202D-E are left to right overrides |
| 4827 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) |
|
| 4828 | - return ''; |
|
| 5107 | + if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) { |
|
| 5108 | + return ''; |
|
| 5109 | + } |
|
| 4829 | 5110 | // <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation |
| 4830 | - elseif ($num < 0x80) |
|
| 4831 | - return chr($num); |
|
| 5111 | + elseif ($num < 0x80) { |
|
| 5112 | + return chr($num); |
|
| 5113 | + } |
|
| 4832 | 5114 | // <0x800 (2048) |
| 4833 | - elseif ($num < 0x800) |
|
| 4834 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 5115 | + elseif ($num < 0x800) { |
|
| 5116 | + return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 5117 | + } |
|
| 4835 | 5118 | // < 0x10000 (65536) |
| 4836 | - elseif ($num < 0x10000) |
|
| 4837 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 5119 | + elseif ($num < 0x10000) { |
|
| 5120 | + return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 5121 | + } |
|
| 4838 | 5122 | // <= 0x10FFFF (1114111) |
| 4839 | - else |
|
| 4840 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 4841 | -} |
|
| 5123 | + else { |
|
| 5124 | + return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 5125 | + } |
|
| 5126 | + } |
|
| 4842 | 5127 | |
| 4843 | 5128 | /** |
| 4844 | 5129 | * Strips out invalid html entities, replaces others with html style { codes |
@@ -4851,17 +5136,19 @@ discard block |
||
| 4851 | 5136 | */ |
| 4852 | 5137 | function entity_fix__callback($matches) |
| 4853 | 5138 | { |
| 4854 | - if (!isset($matches[2])) |
|
| 4855 | - return ''; |
|
| 5139 | + if (!isset($matches[2])) { |
|
| 5140 | + return ''; |
|
| 5141 | + } |
|
| 4856 | 5142 | |
| 4857 | 5143 | $num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2]; |
| 4858 | 5144 | |
| 4859 | 5145 | // we don't allow control characters, characters out of range, byte markers, etc |
| 4860 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) |
|
| 4861 | - return ''; |
|
| 4862 | - else |
|
| 4863 | - return '&#' . $num . ';'; |
|
| 4864 | -} |
|
| 5146 | + if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) { |
|
| 5147 | + return ''; |
|
| 5148 | + } else { |
|
| 5149 | + return '&#' . $num . ';'; |
|
| 5150 | + } |
|
| 5151 | + } |
|
| 4865 | 5152 | |
| 4866 | 5153 | /** |
| 4867 | 5154 | * Return a Gravatar URL based on |
@@ -4885,18 +5172,23 @@ discard block |
||
| 4885 | 5172 | $ratings = array('G', 'PG', 'R', 'X'); |
| 4886 | 5173 | $defaults = array('mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank'); |
| 4887 | 5174 | $url_params = array(); |
| 4888 | - if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) |
|
| 4889 | - $url_params[] = 'rating=' . $modSettings['gravatarMaxRating']; |
|
| 4890 | - if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) |
|
| 4891 | - $url_params[] = 'default=' . $modSettings['gravatarDefault']; |
|
| 4892 | - if (!empty($modSettings['avatar_max_width_external'])) |
|
| 4893 | - $size_string = (int) $modSettings['avatar_max_width_external']; |
|
| 4894 | - if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) |
|
| 4895 | - if ((int) $modSettings['avatar_max_height_external'] < $size_string) |
|
| 5175 | + if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) { |
|
| 5176 | + $url_params[] = 'rating=' . $modSettings['gravatarMaxRating']; |
|
| 5177 | + } |
|
| 5178 | + if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) { |
|
| 5179 | + $url_params[] = 'default=' . $modSettings['gravatarDefault']; |
|
| 5180 | + } |
|
| 5181 | + if (!empty($modSettings['avatar_max_width_external'])) { |
|
| 5182 | + $size_string = (int) $modSettings['avatar_max_width_external']; |
|
| 5183 | + } |
|
| 5184 | + if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) { |
|
| 5185 | + if ((int) $modSettings['avatar_max_height_external'] < $size_string) |
|
| 4896 | 5186 | $size_string = $modSettings['avatar_max_height_external']; |
| 5187 | + } |
|
| 4897 | 5188 | |
| 4898 | - if (!empty($size_string)) |
|
| 4899 | - $url_params[] = 's=' . $size_string; |
|
| 5189 | + if (!empty($size_string)) { |
|
| 5190 | + $url_params[] = 's=' . $size_string; |
|
| 5191 | + } |
|
| 4900 | 5192 | } |
| 4901 | 5193 | $http_method = !empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 ? 'https://secure' : 'http://www'; |
| 4902 | 5194 | |
@@ -4915,22 +5207,26 @@ discard block |
||
| 4915 | 5207 | static $timezones = null, $lastwhen = null; |
| 4916 | 5208 | |
| 4917 | 5209 | // No point doing this over if we already did it once |
| 4918 | - if (!empty($timezones) && $when == $lastwhen) |
|
| 4919 | - return $timezones; |
|
| 4920 | - else |
|
| 4921 | - $lastwhen = $when; |
|
| 5210 | + if (!empty($timezones) && $when == $lastwhen) { |
|
| 5211 | + return $timezones; |
|
| 5212 | + } else { |
|
| 5213 | + $lastwhen = $when; |
|
| 5214 | + } |
|
| 4922 | 5215 | |
| 4923 | 5216 | // Parseable datetime string? |
| 4924 | - if (is_int($timestamp = strtotime($when))) |
|
| 4925 | - $when = $timestamp; |
|
| 5217 | + if (is_int($timestamp = strtotime($when))) { |
|
| 5218 | + $when = $timestamp; |
|
| 5219 | + } |
|
| 4926 | 5220 | |
| 4927 | 5221 | // A Unix timestamp? |
| 4928 | - elseif (is_numeric($when)) |
|
| 4929 | - $when = intval($when); |
|
| 5222 | + elseif (is_numeric($when)) { |
|
| 5223 | + $when = intval($when); |
|
| 5224 | + } |
|
| 4930 | 5225 | |
| 4931 | 5226 | // Invalid value? Just get current Unix timestamp. |
| 4932 | - else |
|
| 4933 | - $when = time(); |
|
| 5227 | + else { |
|
| 5228 | + $when = time(); |
|
| 5229 | + } |
|
| 4934 | 5230 | |
| 4935 | 5231 | // We'll need this too |
| 4936 | 5232 | $later = (int) date_format(date_add(date_create('@' . $when), date_interval_create_from_date_string('1 year')), 'U'); |
@@ -4993,8 +5289,9 @@ discard block |
||
| 4993 | 5289 | foreach ($priority_countries as $country) |
| 4994 | 5290 | { |
| 4995 | 5291 | $country_tzids = @timezone_identifiers_list(DateTimeZone::PER_COUNTRY, strtoupper(trim($country))); |
| 4996 | - if (!empty($country_tzids)) |
|
| 4997 | - $priority_tzids = array_merge($priority_tzids, $country_tzids); |
|
| 5292 | + if (!empty($country_tzids)) { |
|
| 5293 | + $priority_tzids = array_merge($priority_tzids, $country_tzids); |
|
| 5294 | + } |
|
| 4998 | 5295 | } |
| 4999 | 5296 | |
| 5000 | 5297 | // Process the preferred timezones first, then the rest. |
@@ -5004,8 +5301,9 @@ discard block |
||
| 5004 | 5301 | foreach ($tzids as $tzid) |
| 5005 | 5302 | { |
| 5006 | 5303 | // We don't want UTC right now |
| 5007 | - if ($tzid == 'UTC') |
|
| 5008 | - continue; |
|
| 5304 | + if ($tzid == 'UTC') { |
|
| 5305 | + continue; |
|
| 5306 | + } |
|
| 5009 | 5307 | |
| 5010 | 5308 | // First, get the set of transition rules for this tzid |
| 5011 | 5309 | $tzinfo = timezone_transitions_get(timezone_open($tzid), $when, $later); |
@@ -5016,8 +5314,9 @@ discard block |
||
| 5016 | 5314 | $tz_location = timezone_location_get(timezone_open($tzid)); |
| 5017 | 5315 | |
| 5018 | 5316 | // Kazakstan |
| 5019 | - if ($tz_location['country_code'] == 'KZ') |
|
| 5020 | - $tzinfo[0]['abbr'] = str_replace(array('+05', '+06'), array('AQTT', 'ALMT'), $tzinfo[0]['abbr']); |
|
| 5317 | + if ($tz_location['country_code'] == 'KZ') { |
|
| 5318 | + $tzinfo[0]['abbr'] = str_replace(array('+05', '+06'), array('AQTT', 'ALMT'), $tzinfo[0]['abbr']); |
|
| 5319 | + } |
|
| 5021 | 5320 | |
| 5022 | 5321 | // Russia likes to experiment with time zones |
| 5023 | 5322 | if ($tz_location['country_code'] == 'RU') |
@@ -5028,19 +5327,22 @@ discard block |
||
| 5028 | 5327 | } |
| 5029 | 5328 | |
| 5030 | 5329 | // Still no good? We'll just mark it as a UTC offset |
| 5031 | - if (strspn($tzinfo[0]['abbr'], '+-') > 0) |
|
| 5032 | - $tzinfo[0]['abbr'] = 'UTC' . $tzinfo[0]['abbr']; |
|
| 5330 | + if (strspn($tzinfo[0]['abbr'], '+-') > 0) { |
|
| 5331 | + $tzinfo[0]['abbr'] = 'UTC' . $tzinfo[0]['abbr']; |
|
| 5332 | + } |
|
| 5033 | 5333 | } |
| 5034 | 5334 | |
| 5035 | 5335 | $tzkey = serialize($tzinfo); |
| 5036 | 5336 | |
| 5037 | 5337 | // Don't overwrite our preferred tzids |
| 5038 | - if (empty($zones[$tzkey]['tzid'])) |
|
| 5039 | - $zones[$tzkey]['tzid'] = $tzid; |
|
| 5338 | + if (empty($zones[$tzkey]['tzid'])) { |
|
| 5339 | + $zones[$tzkey]['tzid'] = $tzid; |
|
| 5340 | + } |
|
| 5040 | 5341 | |
| 5041 | 5342 | // A time zone from a prioritized country? |
| 5042 | - if (in_array($tzid, $priority_tzids)) |
|
| 5043 | - $priority_zones[$tzkey] = true; |
|
| 5343 | + if (in_array($tzid, $priority_tzids)) { |
|
| 5344 | + $priority_zones[$tzkey] = true; |
|
| 5345 | + } |
|
| 5044 | 5346 | |
| 5045 | 5347 | // Keep track of the location and offset for this tzid |
| 5046 | 5348 | $tzid_parts = explode('/', $tzid); |
@@ -5058,15 +5360,17 @@ discard block |
||
| 5058 | 5360 | { |
| 5059 | 5361 | $tzinfo = unserialize($tzkey); |
| 5060 | 5362 | |
| 5061 | - if (!empty($timezone_descriptions[$tzvalue['tzid']])) |
|
| 5062 | - $desc = $timezone_descriptions[$tzvalue['tzid']]; |
|
| 5063 | - else |
|
| 5064 | - $desc = implode(', ', array_unique($tzvalue['locations'])); |
|
| 5363 | + if (!empty($timezone_descriptions[$tzvalue['tzid']])) { |
|
| 5364 | + $desc = $timezone_descriptions[$tzvalue['tzid']]; |
|
| 5365 | + } else { |
|
| 5366 | + $desc = implode(', ', array_unique($tzvalue['locations'])); |
|
| 5367 | + } |
|
| 5065 | 5368 | |
| 5066 | - if (isset($priority_zones[$tzkey])) |
|
| 5067 | - $priority_timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format(date_create($tzvalue['tzid']), 'P') . ']'; |
|
| 5068 | - else |
|
| 5069 | - $timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format(date_create($tzvalue['tzid']), 'P') . ']'; |
|
| 5369 | + if (isset($priority_zones[$tzkey])) { |
|
| 5370 | + $priority_timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format(date_create($tzvalue['tzid']), 'P') . ']'; |
|
| 5371 | + } else { |
|
| 5372 | + $timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format(date_create($tzvalue['tzid']), 'P') . ']'; |
|
| 5373 | + } |
|
| 5070 | 5374 | } |
| 5071 | 5375 | |
| 5072 | 5376 | $timezones = array_merge( |
@@ -5084,8 +5388,9 @@ discard block |
||
| 5084 | 5388 | */ |
| 5085 | 5389 | function inet_ptod($ip_address) |
| 5086 | 5390 | { |
| 5087 | - if (!isValidIP($ip_address)) |
|
| 5088 | - return $ip_address; |
|
| 5391 | + if (!isValidIP($ip_address)) { |
|
| 5392 | + return $ip_address; |
|
| 5393 | + } |
|
| 5089 | 5394 | |
| 5090 | 5395 | $bin = inet_pton($ip_address); |
| 5091 | 5396 | return $bin; |
@@ -5097,13 +5402,15 @@ discard block |
||
| 5097 | 5402 | */ |
| 5098 | 5403 | function inet_dtop($bin) |
| 5099 | 5404 | { |
| 5100 | - if(empty($bin)) |
|
| 5101 | - return ''; |
|
| 5405 | + if(empty($bin)) { |
|
| 5406 | + return ''; |
|
| 5407 | + } |
|
| 5102 | 5408 | |
| 5103 | 5409 | global $db_type; |
| 5104 | 5410 | |
| 5105 | - if ($db_type == 'postgresql') |
|
| 5106 | - return $bin; |
|
| 5411 | + if ($db_type == 'postgresql') { |
|
| 5412 | + return $bin; |
|
| 5413 | + } |
|
| 5107 | 5414 | |
| 5108 | 5415 | $ip_address = inet_ntop($bin); |
| 5109 | 5416 | |
@@ -5128,26 +5435,32 @@ discard block |
||
| 5128 | 5435 | */ |
| 5129 | 5436 | function _safe_serialize($value) |
| 5130 | 5437 | { |
| 5131 | - if(is_null($value)) |
|
| 5132 | - return 'N;'; |
|
| 5438 | + if(is_null($value)) { |
|
| 5439 | + return 'N;'; |
|
| 5440 | + } |
|
| 5133 | 5441 | |
| 5134 | - if(is_bool($value)) |
|
| 5135 | - return 'b:'. (int) $value .';'; |
|
| 5442 | + if(is_bool($value)) { |
|
| 5443 | + return 'b:'. (int) $value .';'; |
|
| 5444 | + } |
|
| 5136 | 5445 | |
| 5137 | - if(is_int($value)) |
|
| 5138 | - return 'i:'. $value .';'; |
|
| 5446 | + if(is_int($value)) { |
|
| 5447 | + return 'i:'. $value .';'; |
|
| 5448 | + } |
|
| 5139 | 5449 | |
| 5140 | - if(is_float($value)) |
|
| 5141 | - return 'd:'. str_replace(',', '.', $value) .';'; |
|
| 5450 | + if(is_float($value)) { |
|
| 5451 | + return 'd:'. str_replace(',', '.', $value) .';'; |
|
| 5452 | + } |
|
| 5142 | 5453 | |
| 5143 | - if(is_string($value)) |
|
| 5144 | - return 's:'. strlen($value) .':"'. $value .'";'; |
|
| 5454 | + if(is_string($value)) { |
|
| 5455 | + return 's:'. strlen($value) .':"'. $value .'";'; |
|
| 5456 | + } |
|
| 5145 | 5457 | |
| 5146 | 5458 | if(is_array($value)) |
| 5147 | 5459 | { |
| 5148 | 5460 | $out = ''; |
| 5149 | - foreach($value as $k => $v) |
|
| 5150 | - $out .= _safe_serialize($k) . _safe_serialize($v); |
|
| 5461 | + foreach($value as $k => $v) { |
|
| 5462 | + $out .= _safe_serialize($k) . _safe_serialize($v); |
|
| 5463 | + } |
|
| 5151 | 5464 | |
| 5152 | 5465 | return 'a:'. count($value) .':{'. $out .'}'; |
| 5153 | 5466 | } |
@@ -5173,8 +5486,9 @@ discard block |
||
| 5173 | 5486 | |
| 5174 | 5487 | $out = _safe_serialize($value); |
| 5175 | 5488 | |
| 5176 | - if (isset($mbIntEnc)) |
|
| 5177 | - mb_internal_encoding($mbIntEnc); |
|
| 5489 | + if (isset($mbIntEnc)) { |
|
| 5490 | + mb_internal_encoding($mbIntEnc); |
|
| 5491 | + } |
|
| 5178 | 5492 | |
| 5179 | 5493 | return $out; |
| 5180 | 5494 | } |
@@ -5191,8 +5505,9 @@ discard block |
||
| 5191 | 5505 | function _safe_unserialize($str) |
| 5192 | 5506 | { |
| 5193 | 5507 | // Input is not a string. |
| 5194 | - if(empty($str) || !is_string($str)) |
|
| 5195 | - return false; |
|
| 5508 | + if(empty($str) || !is_string($str)) { |
|
| 5509 | + return false; |
|
| 5510 | + } |
|
| 5196 | 5511 | |
| 5197 | 5512 | $stack = array(); |
| 5198 | 5513 | $expected = array(); |
@@ -5208,43 +5523,38 @@ discard block |
||
| 5208 | 5523 | while($state != 1) |
| 5209 | 5524 | { |
| 5210 | 5525 | $type = isset($str[0]) ? $str[0] : ''; |
| 5211 | - if($type == '}') |
|
| 5212 | - $str = substr($str, 1); |
|
| 5213 | - |
|
| 5214 | - else if($type == 'N' && $str[1] == ';') |
|
| 5526 | + if($type == '}') { |
|
| 5527 | + $str = substr($str, 1); |
|
| 5528 | + } else if($type == 'N' && $str[1] == ';') |
|
| 5215 | 5529 | { |
| 5216 | 5530 | $value = null; |
| 5217 | 5531 | $str = substr($str, 2); |
| 5218 | - } |
|
| 5219 | - else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches)) |
|
| 5532 | + } else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches)) |
|
| 5220 | 5533 | { |
| 5221 | 5534 | $value = $matches[1] == '1' ? true : false; |
| 5222 | 5535 | $str = substr($str, 4); |
| 5223 | - } |
|
| 5224 | - else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches)) |
|
| 5536 | + } else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches)) |
|
| 5225 | 5537 | { |
| 5226 | 5538 | $value = (int)$matches[1]; |
| 5227 | 5539 | $str = $matches[2]; |
| 5228 | - } |
|
| 5229 | - else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches)) |
|
| 5540 | + } else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches)) |
|
| 5230 | 5541 | { |
| 5231 | 5542 | $value = (float)$matches[1]; |
| 5232 | 5543 | $str = $matches[3]; |
| 5233 | - } |
|
| 5234 | - else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";') |
|
| 5544 | + } else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";') |
|
| 5235 | 5545 | { |
| 5236 | 5546 | $value = substr($matches[2], 0, (int)$matches[1]); |
| 5237 | 5547 | $str = substr($matches[2], (int)$matches[1] + 2); |
| 5238 | - } |
|
| 5239 | - else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches)) |
|
| 5548 | + } else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches)) |
|
| 5240 | 5549 | { |
| 5241 | 5550 | $expectedLength = (int)$matches[1]; |
| 5242 | 5551 | $str = $matches[2]; |
| 5243 | 5552 | } |
| 5244 | 5553 | |
| 5245 | 5554 | // Object or unknown/malformed type. |
| 5246 | - else |
|
| 5247 | - return false; |
|
| 5555 | + else { |
|
| 5556 | + return false; |
|
| 5557 | + } |
|
| 5248 | 5558 | |
| 5249 | 5559 | switch($state) |
| 5250 | 5560 | { |
@@ -5272,8 +5582,9 @@ discard block |
||
| 5272 | 5582 | if($type == '}') |
| 5273 | 5583 | { |
| 5274 | 5584 | // Array size is less than expected. |
| 5275 | - if(count($list) < end($expected)) |
|
| 5276 | - return false; |
|
| 5585 | + if(count($list) < end($expected)) { |
|
| 5586 | + return false; |
|
| 5587 | + } |
|
| 5277 | 5588 | |
| 5278 | 5589 | unset($list); |
| 5279 | 5590 | $list = &$stack[count($stack)-1]; |
@@ -5282,8 +5593,9 @@ discard block |
||
| 5282 | 5593 | // Go to terminal state if we're at the end of the root array. |
| 5283 | 5594 | array_pop($expected); |
| 5284 | 5595 | |
| 5285 | - if(count($expected) == 0) |
|
| 5286 | - $state = 1; |
|
| 5596 | + if(count($expected) == 0) { |
|
| 5597 | + $state = 1; |
|
| 5598 | + } |
|
| 5287 | 5599 | |
| 5288 | 5600 | break; |
| 5289 | 5601 | } |
@@ -5291,8 +5603,9 @@ discard block |
||
| 5291 | 5603 | if($type == 'i' || $type == 's') |
| 5292 | 5604 | { |
| 5293 | 5605 | // Array size exceeds expected length. |
| 5294 | - if(count($list) >= end($expected)) |
|
| 5295 | - return false; |
|
| 5606 | + if(count($list) >= end($expected)) { |
|
| 5607 | + return false; |
|
| 5608 | + } |
|
| 5296 | 5609 | |
| 5297 | 5610 | $key = $value; |
| 5298 | 5611 | $state = 3; |
@@ -5326,8 +5639,9 @@ discard block |
||
| 5326 | 5639 | } |
| 5327 | 5640 | |
| 5328 | 5641 | // Trailing data in input. |
| 5329 | - if(!empty($str)) |
|
| 5330 | - return false; |
|
| 5642 | + if(!empty($str)) { |
|
| 5643 | + return false; |
|
| 5644 | + } |
|
| 5331 | 5645 | |
| 5332 | 5646 | return $data; |
| 5333 | 5647 | } |
@@ -5350,8 +5664,9 @@ discard block |
||
| 5350 | 5664 | |
| 5351 | 5665 | $out = _safe_unserialize($str); |
| 5352 | 5666 | |
| 5353 | - if (isset($mbIntEnc)) |
|
| 5354 | - mb_internal_encoding($mbIntEnc); |
|
| 5667 | + if (isset($mbIntEnc)) { |
|
| 5668 | + mb_internal_encoding($mbIntEnc); |
|
| 5669 | + } |
|
| 5355 | 5670 | |
| 5356 | 5671 | return $out; |
| 5357 | 5672 | } |
@@ -5366,12 +5681,14 @@ discard block |
||
| 5366 | 5681 | function smf_chmod($file, $value = 0) |
| 5367 | 5682 | { |
| 5368 | 5683 | // No file? no checks! |
| 5369 | - if (empty($file)) |
|
| 5370 | - return false; |
|
| 5684 | + if (empty($file)) { |
|
| 5685 | + return false; |
|
| 5686 | + } |
|
| 5371 | 5687 | |
| 5372 | 5688 | // Already writable? |
| 5373 | - if (is_writable($file)) |
|
| 5374 | - return true; |
|
| 5689 | + if (is_writable($file)) { |
|
| 5690 | + return true; |
|
| 5691 | + } |
|
| 5375 | 5692 | |
| 5376 | 5693 | // Do we have a file or a dir? |
| 5377 | 5694 | $isDir = is_dir($file); |
@@ -5387,10 +5704,9 @@ discard block |
||
| 5387 | 5704 | { |
| 5388 | 5705 | $isWritable = true; |
| 5389 | 5706 | break; |
| 5707 | + } else { |
|
| 5708 | + @chmod($file, $val); |
|
| 5390 | 5709 | } |
| 5391 | - |
|
| 5392 | - else |
|
| 5393 | - @chmod($file, $val); |
|
| 5394 | 5710 | } |
| 5395 | 5711 | |
| 5396 | 5712 | return $isWritable; |
@@ -5409,8 +5725,9 @@ discard block |
||
| 5409 | 5725 | global $txt; |
| 5410 | 5726 | |
| 5411 | 5727 | // Come on... |
| 5412 | - if (empty($json) || !is_string($json)) |
|
| 5413 | - return array(); |
|
| 5728 | + if (empty($json) || !is_string($json)) { |
|
| 5729 | + return array(); |
|
| 5730 | + } |
|
| 5414 | 5731 | |
| 5415 | 5732 | $returnArray = @json_decode($json, $returnAsArray); |
| 5416 | 5733 | |
@@ -5448,11 +5765,11 @@ discard block |
||
| 5448 | 5765 | $jsonDebug = $jsonDebug[0]; |
| 5449 | 5766 | loadLanguage('Errors'); |
| 5450 | 5767 | |
| 5451 | - if (!empty($jsonDebug)) |
|
| 5452 | - log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']); |
|
| 5453 | - |
|
| 5454 | - else |
|
| 5455 | - log_error($txt['json_'. $jsonError], 'critical'); |
|
| 5768 | + if (!empty($jsonDebug)) { |
|
| 5769 | + log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']); |
|
| 5770 | + } else { |
|
| 5771 | + log_error($txt['json_'. $jsonError], 'critical'); |
|
| 5772 | + } |
|
| 5456 | 5773 | |
| 5457 | 5774 | // Everyone expects an array. |
| 5458 | 5775 | return array(); |
@@ -5482,8 +5799,9 @@ discard block |
||
| 5482 | 5799 | global $db_show_debug, $modSettings; |
| 5483 | 5800 | |
| 5484 | 5801 | // Defensive programming anyone? |
| 5485 | - if (empty($data)) |
|
| 5486 | - return false; |
|
| 5802 | + if (empty($data)) { |
|
| 5803 | + return false; |
|
| 5804 | + } |
|
| 5487 | 5805 | |
| 5488 | 5806 | // Don't need extra stuff... |
| 5489 | 5807 | $db_show_debug = false; |
@@ -5491,11 +5809,11 @@ discard block |
||
| 5491 | 5809 | // Kill anything else. |
| 5492 | 5810 | ob_end_clean(); |
| 5493 | 5811 | |
| 5494 | - if (!empty($modSettings['CompressedOutput'])) |
|
| 5495 | - @ob_start('ob_gzhandler'); |
|
| 5496 | - |
|
| 5497 | - else |
|
| 5498 | - ob_start(); |
|
| 5812 | + if (!empty($modSettings['CompressedOutput'])) { |
|
| 5813 | + @ob_start('ob_gzhandler'); |
|
| 5814 | + } else { |
|
| 5815 | + ob_start(); |
|
| 5816 | + } |
|
| 5499 | 5817 | |
| 5500 | 5818 | // Set the header. |
| 5501 | 5819 | header($type); |
@@ -5527,8 +5845,9 @@ discard block |
||
| 5527 | 5845 | static $done = false; |
| 5528 | 5846 | |
| 5529 | 5847 | // If we don't need to do anything, don't |
| 5530 | - if (!$update && $done) |
|
| 5531 | - return; |
|
| 5848 | + if (!$update && $done) { |
|
| 5849 | + return; |
|
| 5850 | + } |
|
| 5532 | 5851 | |
| 5533 | 5852 | // Should we get a new copy of the official list of TLDs? |
| 5534 | 5853 | if ($update) |
@@ -5549,10 +5868,11 @@ discard block |
||
| 5549 | 5868 | // Clean $tlds and convert it to an array |
| 5550 | 5869 | $tlds = array_filter(explode("\n", strtolower($tlds)), function($line) { |
| 5551 | 5870 | $line = trim($line); |
| 5552 | - if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) |
|
| 5553 | - return false; |
|
| 5554 | - else |
|
| 5555 | - return true; |
|
| 5871 | + if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) { |
|
| 5872 | + return false; |
|
| 5873 | + } else { |
|
| 5874 | + return true; |
|
| 5875 | + } |
|
| 5556 | 5876 | }); |
| 5557 | 5877 | |
| 5558 | 5878 | // Convert Punycode to Unicode |
@@ -5606,8 +5926,9 @@ discard block |
||
| 5606 | 5926 | $idx += $digit * $w; |
| 5607 | 5927 | $t = ($k <= $bias) ? $tmin : (($k >= $bias + $tmax) ? $tmax : ($k - $bias)); |
| 5608 | 5928 | |
| 5609 | - if ($digit < $t) |
|
| 5610 | - break; |
|
| 5929 | + if ($digit < $t) { |
|
| 5930 | + break; |
|
| 5931 | + } |
|
| 5611 | 5932 | |
| 5612 | 5933 | $w = (int) ($w * ($base - $t)); |
| 5613 | 5934 | } |
@@ -5616,8 +5937,9 @@ discard block |
||
| 5616 | 5937 | $delta = intval($is_first ? ($delta / $damp) : ($delta / 2)); |
| 5617 | 5938 | $delta += intval($delta / ($deco_len + 1)); |
| 5618 | 5939 | |
| 5619 | - for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base) |
|
| 5620 | - $delta = intval($delta / ($base - $tmin)); |
|
| 5940 | + for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base) { |
|
| 5941 | + $delta = intval($delta / ($base - $tmin)); |
|
| 5942 | + } |
|
| 5621 | 5943 | |
| 5622 | 5944 | $bias = intval($k + ($base - $tmin + 1) * $delta / ($delta + $skew)); |
| 5623 | 5945 | $is_first = false; |
@@ -5626,8 +5948,9 @@ discard block |
||
| 5626 | 5948 | |
| 5627 | 5949 | if ($deco_len > 0) |
| 5628 | 5950 | { |
| 5629 | - for ($i = $deco_len; $i > $idx; $i--) |
|
| 5630 | - $decoded[$i] = $decoded[($i - 1)]; |
|
| 5951 | + for ($i = $deco_len; $i > $idx; $i--) { |
|
| 5952 | + $decoded[$i] = $decoded[($i - 1)]; |
|
| 5953 | + } |
|
| 5631 | 5954 | } |
| 5632 | 5955 | $decoded[$idx++] = $char; |
| 5633 | 5956 | } |
@@ -5635,24 +5958,29 @@ discard block |
||
| 5635 | 5958 | foreach ($decoded as $k => $v) |
| 5636 | 5959 | { |
| 5637 | 5960 | // 7bit are transferred literally |
| 5638 | - if ($v < 128) |
|
| 5639 | - $output .= chr($v); |
|
| 5961 | + if ($v < 128) { |
|
| 5962 | + $output .= chr($v); |
|
| 5963 | + } |
|
| 5640 | 5964 | |
| 5641 | 5965 | // 2 bytes |
| 5642 | - elseif ($v < (1 << 11)) |
|
| 5643 | - $output .= chr(192+($v >> 6)) . chr(128+($v & 63)); |
|
| 5966 | + elseif ($v < (1 << 11)) { |
|
| 5967 | + $output .= chr(192+($v >> 6)) . chr(128+($v & 63)); |
|
| 5968 | + } |
|
| 5644 | 5969 | |
| 5645 | 5970 | // 3 bytes |
| 5646 | - elseif ($v < (1 << 16)) |
|
| 5647 | - $output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
| 5971 | + elseif ($v < (1 << 16)) { |
|
| 5972 | + $output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
| 5973 | + } |
|
| 5648 | 5974 | |
| 5649 | 5975 | // 4 bytes |
| 5650 | - elseif ($v < (1 << 21)) |
|
| 5651 | - $output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
| 5976 | + elseif ($v < (1 << 21)) { |
|
| 5977 | + $output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
| 5978 | + } |
|
| 5652 | 5979 | |
| 5653 | 5980 | // 'Conversion from UCS-4 to UTF-8 failed: malformed input at byte '.$k |
| 5654 | - else |
|
| 5655 | - $output .= $safe_char; |
|
| 5981 | + else { |
|
| 5982 | + $output .= $safe_char; |
|
| 5983 | + } |
|
| 5656 | 5984 | } |
| 5657 | 5985 | |
| 5658 | 5986 | $output_parts[] = $output; |
@@ -5747,8 +6075,7 @@ discard block |
||
| 5747 | 6075 | |
| 5748 | 6076 | $strlen = 'mb_strlen'; |
| 5749 | 6077 | $substr = 'mb_substr'; |
| 5750 | - } |
|
| 5751 | - else |
|
| 6078 | + } else |
|
| 5752 | 6079 | { |
| 5753 | 6080 | $strlen = $smcFunc['strlen']; |
| 5754 | 6081 | $substr = $smcFunc['substr']; |
@@ -5762,20 +6089,21 @@ discard block |
||
| 5762 | 6089 | |
| 5763 | 6090 | $first = $substr($string, 0, 1); |
| 5764 | 6091 | |
| 5765 | - if (empty($index[$first])) |
|
| 5766 | - $index[$first] = array(); |
|
| 6092 | + if (empty($index[$first])) { |
|
| 6093 | + $index[$first] = array(); |
|
| 6094 | + } |
|
| 5767 | 6095 | |
| 5768 | 6096 | if ($strlen($string) > 1) |
| 5769 | 6097 | { |
| 5770 | 6098 | // Sanity check on recursion |
| 5771 | - if ($depth > 99) |
|
| 5772 | - $index[$first][$substr($string, 1)] = ''; |
|
| 5773 | - |
|
| 5774 | - else |
|
| 5775 | - $index[$first] = $add_string_to_index($substr($string, 1), $index[$first]); |
|
| 6099 | + if ($depth > 99) { |
|
| 6100 | + $index[$first][$substr($string, 1)] = ''; |
|
| 6101 | + } else { |
|
| 6102 | + $index[$first] = $add_string_to_index($substr($string, 1), $index[$first]); |
|
| 6103 | + } |
|
| 6104 | + } else { |
|
| 6105 | + $index[$first][''] = ''; |
|
| 5776 | 6106 | } |
| 5777 | - else |
|
| 5778 | - $index[$first][''] = ''; |
|
| 5779 | 6107 | |
| 5780 | 6108 | $depth--; |
| 5781 | 6109 | return $index; |
@@ -5798,9 +6126,9 @@ discard block |
||
| 5798 | 6126 | $key_regex = preg_quote($key, $delim); |
| 5799 | 6127 | $new_key = $key; |
| 5800 | 6128 | |
| 5801 | - if (empty($value)) |
|
| 5802 | - $sub_regex = ''; |
|
| 5803 | - else |
|
| 6129 | + if (empty($value)) { |
|
| 6130 | + $sub_regex = ''; |
|
| 6131 | + } else |
|
| 5804 | 6132 | { |
| 5805 | 6133 | $sub_regex = $index_to_regex($value, $delim); |
| 5806 | 6134 | |
@@ -5808,22 +6136,22 @@ discard block |
||
| 5808 | 6136 | { |
| 5809 | 6137 | $new_key_array = explode('(?'.'>', $sub_regex); |
| 5810 | 6138 | $new_key .= $new_key_array[0]; |
| 6139 | + } else { |
|
| 6140 | + $sub_regex = '(?'.'>' . $sub_regex . ')'; |
|
| 5811 | 6141 | } |
| 5812 | - else |
|
| 5813 | - $sub_regex = '(?'.'>' . $sub_regex . ')'; |
|
| 5814 | 6142 | } |
| 5815 | 6143 | |
| 5816 | - if ($depth > 1) |
|
| 5817 | - $regex[$new_key] = $key_regex . $sub_regex; |
|
| 5818 | - else |
|
| 6144 | + if ($depth > 1) { |
|
| 6145 | + $regex[$new_key] = $key_regex . $sub_regex; |
|
| 6146 | + } else |
|
| 5819 | 6147 | { |
| 5820 | 6148 | if (($length += strlen($key_regex) + 1) < $max_length || empty($regex)) |
| 5821 | 6149 | { |
| 5822 | 6150 | $regex[$new_key] = $key_regex . $sub_regex; |
| 5823 | 6151 | unset($index[$key]); |
| 6152 | + } else { |
|
| 6153 | + break; |
|
| 5824 | 6154 | } |
| 5825 | - else |
|
| 5826 | - break; |
|
| 5827 | 6155 | } |
| 5828 | 6156 | } |
| 5829 | 6157 | |
@@ -5832,10 +6160,11 @@ discard block |
||
| 5832 | 6160 | $l1 = $strlen($k1); |
| 5833 | 6161 | $l2 = $strlen($k2); |
| 5834 | 6162 | |
| 5835 | - if ($l1 == $l2) |
|
| 5836 | - return strcmp($k1, $k2) > 0 ? 1 : -1; |
|
| 5837 | - else |
|
| 5838 | - return $l1 > $l2 ? -1 : 1; |
|
| 6163 | + if ($l1 == $l2) { |
|
| 6164 | + return strcmp($k1, $k2) > 0 ? 1 : -1; |
|
| 6165 | + } else { |
|
| 6166 | + return $l1 > $l2 ? -1 : 1; |
|
| 6167 | + } |
|
| 5839 | 6168 | }); |
| 5840 | 6169 | |
| 5841 | 6170 | $depth--; |
@@ -5846,15 +6175,18 @@ discard block |
||
| 5846 | 6175 | $index = array(); |
| 5847 | 6176 | $regexes = array(); |
| 5848 | 6177 | |
| 5849 | - foreach ($strings as $string) |
|
| 5850 | - $index = $add_string_to_index($string, $index); |
|
| 6178 | + foreach ($strings as $string) { |
|
| 6179 | + $index = $add_string_to_index($string, $index); |
|
| 6180 | + } |
|
| 5851 | 6181 | |
| 5852 | - while (!empty($index)) |
|
| 5853 | - $regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')'; |
|
| 6182 | + while (!empty($index)) { |
|
| 6183 | + $regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')'; |
|
| 6184 | + } |
|
| 5854 | 6185 | |
| 5855 | 6186 | // Restore PHP's internal character encoding to whatever it was originally |
| 5856 | - if (!empty($current_encoding)) |
|
| 5857 | - mb_internal_encoding($current_encoding); |
|
| 6187 | + if (!empty($current_encoding)) { |
|
| 6188 | + mb_internal_encoding($current_encoding); |
|
| 6189 | + } |
|
| 5858 | 6190 | |
| 5859 | 6191 | return $regexes; |
| 5860 | 6192 | } |
@@ -75,8 +75,9 @@ discard block |
||
| 75 | 75 | $upcontext['inactive_timeout'] = 10; |
| 76 | 76 | |
| 77 | 77 | // The helper is crucial. Include it first thing. |
| 78 | -if (!file_exists($upgrade_path . '/upgrade-helper.php')) |
|
| 78 | +if (!file_exists($upgrade_path . '/upgrade-helper.php')) { |
|
| 79 | 79 | die('upgrade-helper.php not found where it was expected: ' . $upgrade_path . '/upgrade-helper.php! Make sure you have uploaded ALL files from the upgrade package. The upgrader cannot continue.'); |
| 80 | +} |
|
| 80 | 81 | |
| 81 | 82 | require_once($upgrade_path . '/upgrade-helper.php'); |
| 82 | 83 | |
@@ -100,11 +101,14 @@ discard block |
||
| 100 | 101 | ini_set('default_socket_timeout', 900); |
| 101 | 102 | } |
| 102 | 103 | // Clean the upgrade path if this is from the client. |
| 103 | -if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) |
|
| 104 | - for ($i = 1; $i < $_SERVER['argc']; $i++) |
|
| 104 | +if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) { |
|
| 105 | + for ($i = 1; |
|
| 106 | +} |
|
| 107 | +$i < $_SERVER['argc']; $i++) |
|
| 105 | 108 | { |
| 106 | - if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0) |
|
| 107 | - $upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1]; |
|
| 109 | + if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0) { |
|
| 110 | + $upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1]; |
|
| 111 | + } |
|
| 108 | 112 | } |
| 109 | 113 | |
| 110 | 114 | // Are we from the client? |
@@ -112,16 +116,17 @@ discard block |
||
| 112 | 116 | { |
| 113 | 117 | $command_line = true; |
| 114 | 118 | $disable_security = true; |
| 115 | -} |
|
| 116 | -else |
|
| 119 | +} else { |
|
| 117 | 120 | $command_line = false; |
| 121 | +} |
|
| 118 | 122 | |
| 119 | 123 | // Load this now just because we can. |
| 120 | 124 | require_once($upgrade_path . '/Settings.php'); |
| 121 | 125 | |
| 122 | 126 | // We don't use "-utf8" anymore... Tweak the entry that may have been loaded by Settings.php |
| 123 | -if (isset($language)) |
|
| 127 | +if (isset($language)) { |
|
| 124 | 128 | $language = str_ireplace('-utf8', '', $language); |
| 129 | +} |
|
| 125 | 130 | |
| 126 | 131 | // Are we logged in? |
| 127 | 132 | if (isset($upgradeData)) |
@@ -129,10 +134,12 @@ discard block |
||
| 129 | 134 | $upcontext['user'] = json_decode(base64_decode($upgradeData), true); |
| 130 | 135 | |
| 131 | 136 | // Check for sensible values. |
| 132 | - if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400) |
|
| 133 | - $upcontext['user']['started'] = time(); |
|
| 134 | - if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400) |
|
| 135 | - $upcontext['user']['updated'] = 0; |
|
| 137 | + if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400) { |
|
| 138 | + $upcontext['user']['started'] = time(); |
|
| 139 | + } |
|
| 140 | + if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400) { |
|
| 141 | + $upcontext['user']['updated'] = 0; |
|
| 142 | + } |
|
| 136 | 143 | |
| 137 | 144 | $upcontext['started'] = $upcontext['user']['started']; |
| 138 | 145 | $upcontext['updated'] = $upcontext['user']['updated']; |
@@ -190,8 +197,9 @@ discard block |
||
| 190 | 197 | 'db_error_skip' => true, |
| 191 | 198 | ) |
| 192 | 199 | ); |
| 193 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 194 | - $modSettings[$row['variable']] = $row['value']; |
|
| 200 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 201 | + $modSettings[$row['variable']] = $row['value']; |
|
| 202 | + } |
|
| 195 | 203 | $smcFunc['db_free_result']($request); |
| 196 | 204 | } |
| 197 | 205 | |
@@ -201,10 +209,12 @@ discard block |
||
| 201 | 209 | $modSettings['theme_url'] = 'Themes/default'; |
| 202 | 210 | $modSettings['images_url'] = 'Themes/default/images'; |
| 203 | 211 | } |
| 204 | -if (!isset($settings['default_theme_url'])) |
|
| 212 | +if (!isset($settings['default_theme_url'])) { |
|
| 205 | 213 | $settings['default_theme_url'] = $modSettings['theme_url']; |
| 206 | -if (!isset($settings['default_theme_dir'])) |
|
| 214 | +} |
|
| 215 | +if (!isset($settings['default_theme_dir'])) { |
|
| 207 | 216 | $settings['default_theme_dir'] = $modSettings['theme_dir']; |
| 217 | +} |
|
| 208 | 218 | |
| 209 | 219 | $upcontext['is_large_forum'] = (empty($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC1') && !empty($modSettings['totalMessages']) && $modSettings['totalMessages'] > 75000; |
| 210 | 220 | // Default title... |
@@ -222,13 +232,15 @@ discard block |
||
| 222 | 232 | $support_js = $upcontext['upgrade_status']['js']; |
| 223 | 233 | |
| 224 | 234 | // Only set this if the upgrader status says so. |
| 225 | - if (empty($is_debug)) |
|
| 226 | - $is_debug = $upcontext['upgrade_status']['debug']; |
|
| 235 | + if (empty($is_debug)) { |
|
| 236 | + $is_debug = $upcontext['upgrade_status']['debug']; |
|
| 237 | + } |
|
| 227 | 238 | |
| 228 | 239 | // Load the language. |
| 229 | - if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) |
|
| 230 | - require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'); |
|
| 231 | -} |
|
| 240 | + if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) { |
|
| 241 | + require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'); |
|
| 242 | + } |
|
| 243 | + } |
|
| 232 | 244 | // Set the defaults. |
| 233 | 245 | else |
| 234 | 246 | { |
@@ -246,15 +258,18 @@ discard block |
||
| 246 | 258 | } |
| 247 | 259 | |
| 248 | 260 | // If this isn't the first stage see whether they are logging in and resuming. |
| 249 | -if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step'])) |
|
| 261 | +if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step'])) { |
|
| 250 | 262 | checkLogin(); |
| 263 | +} |
|
| 251 | 264 | |
| 252 | -if ($command_line) |
|
| 265 | +if ($command_line) { |
|
| 253 | 266 | cmdStep0(); |
| 267 | +} |
|
| 254 | 268 | |
| 255 | 269 | // Don't error if we're using xml. |
| 256 | -if (isset($_GET['xml'])) |
|
| 270 | +if (isset($_GET['xml'])) { |
|
| 257 | 271 | $upcontext['return_error'] = true; |
| 272 | +} |
|
| 258 | 273 | |
| 259 | 274 | // Loop through all the steps doing each one as required. |
| 260 | 275 | $upcontext['overall_percent'] = 0; |
@@ -275,9 +290,9 @@ discard block |
||
| 275 | 290 | } |
| 276 | 291 | |
| 277 | 292 | // Call the step and if it returns false that means pause! |
| 278 | - if (function_exists($step[2]) && $step[2]() === false) |
|
| 279 | - break; |
|
| 280 | - elseif (function_exists($step[2])) { |
|
| 293 | + if (function_exists($step[2]) && $step[2]() === false) { |
|
| 294 | + break; |
|
| 295 | + } elseif (function_exists($step[2])) { |
|
| 281 | 296 | //Start each new step with this unset, so the 'normal' template is called first |
| 282 | 297 | unset($_GET['xml']); |
| 283 | 298 | $_GET['substep'] = 0; |
@@ -321,17 +336,18 @@ discard block |
||
| 321 | 336 | // This should not happen my dear... HELP ME DEVELOPERS!! |
| 322 | 337 | if (!empty($command_line)) |
| 323 | 338 | { |
| 324 | - if (function_exists('debug_print_backtrace')) |
|
| 325 | - debug_print_backtrace(); |
|
| 339 | + if (function_exists('debug_print_backtrace')) { |
|
| 340 | + debug_print_backtrace(); |
|
| 341 | + } |
|
| 326 | 342 | |
| 327 | 343 | echo "\n" . 'Error: Unexpected call to use the ' . (isset($upcontext['sub_template']) ? $upcontext['sub_template'] : '') . ' template. Please copy and paste all the text above and visit the SMF support forum to tell the Developers that they\'ve made a boo boo; they\'ll get you up and running again.'; |
| 328 | 344 | flush(); |
| 329 | 345 | die(); |
| 330 | 346 | } |
| 331 | 347 | |
| 332 | - if (!isset($_GET['xml'])) |
|
| 333 | - template_upgrade_above(); |
|
| 334 | - else |
|
| 348 | + if (!isset($_GET['xml'])) { |
|
| 349 | + template_upgrade_above(); |
|
| 350 | + } else |
|
| 335 | 351 | { |
| 336 | 352 | header('Content-Type: text/xml; charset=UTF-8'); |
| 337 | 353 | // Sadly we need to retain the $_GET data thanks to the old upgrade scripts. |
@@ -353,25 +369,29 @@ discard block |
||
| 353 | 369 | $upcontext['form_url'] = $upgradeurl . '?step=' . $upcontext['current_step'] . '&substep=' . $_GET['substep'] . '&data=' . base64_encode(json_encode($upcontext['upgrade_status'])); |
| 354 | 370 | |
| 355 | 371 | // Custom stuff to pass back? |
| 356 | - if (!empty($upcontext['query_string'])) |
|
| 357 | - $upcontext['form_url'] .= $upcontext['query_string']; |
|
| 372 | + if (!empty($upcontext['query_string'])) { |
|
| 373 | + $upcontext['form_url'] .= $upcontext['query_string']; |
|
| 374 | + } |
|
| 358 | 375 | |
| 359 | 376 | // Call the appropriate subtemplate |
| 360 | - if (is_callable('template_' . $upcontext['sub_template'])) |
|
| 361 | - call_user_func('template_' . $upcontext['sub_template']); |
|
| 362 | - else |
|
| 363 | - die('Upgrade aborted! Invalid template: template_' . $upcontext['sub_template']); |
|
| 377 | + if (is_callable('template_' . $upcontext['sub_template'])) { |
|
| 378 | + call_user_func('template_' . $upcontext['sub_template']); |
|
| 379 | + } else { |
|
| 380 | + die('Upgrade aborted! Invalid template: template_' . $upcontext['sub_template']); |
|
| 381 | + } |
|
| 364 | 382 | } |
| 365 | 383 | |
| 366 | 384 | // Was there an error? |
| 367 | - if (!empty($upcontext['forced_error_message'])) |
|
| 368 | - echo $upcontext['forced_error_message']; |
|
| 385 | + if (!empty($upcontext['forced_error_message'])) { |
|
| 386 | + echo $upcontext['forced_error_message']; |
|
| 387 | + } |
|
| 369 | 388 | |
| 370 | 389 | // Show the footer. |
| 371 | - if (!isset($_GET['xml'])) |
|
| 372 | - template_upgrade_below(); |
|
| 373 | - else |
|
| 374 | - template_xml_below(); |
|
| 390 | + if (!isset($_GET['xml'])) { |
|
| 391 | + template_upgrade_below(); |
|
| 392 | + } else { |
|
| 393 | + template_xml_below(); |
|
| 394 | + } |
|
| 375 | 395 | } |
| 376 | 396 | |
| 377 | 397 | |
@@ -383,15 +403,19 @@ discard block |
||
| 383 | 403 | $seconds = intval($active % 60); |
| 384 | 404 | |
| 385 | 405 | $totalTime = ''; |
| 386 | - if ($hours > 0) |
|
| 387 | - $totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' '; |
|
| 388 | - if ($minutes > 0) |
|
| 389 | - $totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' '; |
|
| 390 | - if ($seconds > 0) |
|
| 391 | - $totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' '; |
|
| 406 | + if ($hours > 0) { |
|
| 407 | + $totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' '; |
|
| 408 | + } |
|
| 409 | + if ($minutes > 0) { |
|
| 410 | + $totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' '; |
|
| 411 | + } |
|
| 412 | + if ($seconds > 0) { |
|
| 413 | + $totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' '; |
|
| 414 | + } |
|
| 392 | 415 | |
| 393 | - if (!empty($totalTime)) |
|
| 394 | - echo "\n" . 'Upgrade completed in ' . $totalTime . "\n"; |
|
| 416 | + if (!empty($totalTime)) { |
|
| 417 | + echo "\n" . 'Upgrade completed in ' . $totalTime . "\n"; |
|
| 418 | + } |
|
| 395 | 419 | } |
| 396 | 420 | |
| 397 | 421 | // Bang - gone! |
@@ -404,8 +428,9 @@ discard block |
||
| 404 | 428 | global $upgradeurl, $upcontext, $command_line; |
| 405 | 429 | |
| 406 | 430 | // Command line users can't be redirected. |
| 407 | - if ($command_line) |
|
| 408 | - upgradeExit(true); |
|
| 431 | + if ($command_line) { |
|
| 432 | + upgradeExit(true); |
|
| 433 | + } |
|
| 409 | 434 | |
| 410 | 435 | // Are we providing the core info? |
| 411 | 436 | if ($addForm) |
@@ -428,19 +453,22 @@ discard block |
||
| 428 | 453 | global $modSettings, $sourcedir, $smcFunc; |
| 429 | 454 | |
| 430 | 455 | // Do the non-SSI stuff... |
| 431 | - if (function_exists('set_magic_quotes_runtime')) |
|
| 432 | - @set_magic_quotes_runtime(0); |
|
| 456 | + if (function_exists('set_magic_quotes_runtime')) { |
|
| 457 | + @set_magic_quotes_runtime(0); |
|
| 458 | + } |
|
| 433 | 459 | |
| 434 | 460 | error_reporting(E_ALL); |
| 435 | 461 | define('SMF', 1); |
| 436 | 462 | |
| 437 | 463 | // Start the session. |
| 438 | - if (@ini_get('session.save_handler') == 'user') |
|
| 439 | - @ini_set('session.save_handler', 'files'); |
|
| 464 | + if (@ini_get('session.save_handler') == 'user') { |
|
| 465 | + @ini_set('session.save_handler', 'files'); |
|
| 466 | + } |
|
| 440 | 467 | @session_start(); |
| 441 | 468 | |
| 442 | - if (empty($smcFunc)) |
|
| 443 | - $smcFunc = array(); |
|
| 469 | + if (empty($smcFunc)) { |
|
| 470 | + $smcFunc = array(); |
|
| 471 | + } |
|
| 444 | 472 | |
| 445 | 473 | // We need this for authentication and some upgrade code |
| 446 | 474 | require_once($sourcedir . '/Subs-Auth.php'); |
@@ -452,32 +480,36 @@ discard block |
||
| 452 | 480 | initialize_inputs(); |
| 453 | 481 | |
| 454 | 482 | // Get the database going! |
| 455 | - if (empty($db_type) || $db_type == 'mysqli') |
|
| 456 | - $db_type = 'mysql'; |
|
| 483 | + if (empty($db_type) || $db_type == 'mysqli') { |
|
| 484 | + $db_type = 'mysql'; |
|
| 485 | + } |
|
| 457 | 486 | |
| 458 | 487 | if (file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) |
| 459 | 488 | { |
| 460 | 489 | require_once($sourcedir . '/Subs-Db-' . $db_type . '.php'); |
| 461 | 490 | |
| 462 | 491 | // Make the connection... |
| 463 | - if (empty($db_connection)) |
|
| 464 | - $db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true)); |
|
| 465 | - else |
|
| 466 | - // If we've returned here, ping/reconnect to be safe |
|
| 492 | + if (empty($db_connection)) { |
|
| 493 | + $db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true)); |
|
| 494 | + } else { |
|
| 495 | + // If we've returned here, ping/reconnect to be safe |
|
| 467 | 496 | $smcFunc['db_ping']($db_connection); |
| 497 | + } |
|
| 468 | 498 | |
| 469 | 499 | // Oh dear god!! |
| 470 | - if ($db_connection === null) |
|
| 471 | - die('Unable to connect to database - please check username and password are correct in Settings.php'); |
|
| 500 | + if ($db_connection === null) { |
|
| 501 | + die('Unable to connect to database - please check username and password are correct in Settings.php'); |
|
| 502 | + } |
|
| 472 | 503 | |
| 473 | - if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) |
|
| 474 | - $smcFunc['db_query']('', ' |
|
| 504 | + if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) { |
|
| 505 | + $smcFunc['db_query']('', ' |
|
| 475 | 506 | SET NAMES {string:db_character_set}', |
| 476 | 507 | array( |
| 477 | 508 | 'db_error_skip' => true, |
| 478 | 509 | 'db_character_set' => $db_character_set, |
| 479 | 510 | ) |
| 480 | 511 | ); |
| 512 | + } |
|
| 481 | 513 | |
| 482 | 514 | // Load the modSettings data... |
| 483 | 515 | $request = $smcFunc['db_query']('', ' |
@@ -488,11 +520,11 @@ discard block |
||
| 488 | 520 | ) |
| 489 | 521 | ); |
| 490 | 522 | $modSettings = array(); |
| 491 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 492 | - $modSettings[$row['variable']] = $row['value']; |
|
| 523 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 524 | + $modSettings[$row['variable']] = $row['value']; |
|
| 525 | + } |
|
| 493 | 526 | $smcFunc['db_free_result']($request); |
| 494 | - } |
|
| 495 | - else |
|
| 527 | + } else |
|
| 496 | 528 | { |
| 497 | 529 | return throw_error('Cannot find ' . $sourcedir . '/Subs-Db-' . $db_type . '.php' . '. Please check you have uploaded all source files and have the correct paths set.'); |
| 498 | 530 | } |
@@ -506,9 +538,10 @@ discard block |
||
| 506 | 538 | cleanRequest(); |
| 507 | 539 | } |
| 508 | 540 | |
| 509 | - if (!isset($_GET['substep'])) |
|
| 510 | - $_GET['substep'] = 0; |
|
| 511 | -} |
|
| 541 | + if (!isset($_GET['substep'])) { |
|
| 542 | + $_GET['substep'] = 0; |
|
| 543 | + } |
|
| 544 | + } |
|
| 512 | 545 | |
| 513 | 546 | function initialize_inputs() |
| 514 | 547 | { |
@@ -538,8 +571,9 @@ discard block |
||
| 538 | 571 | $dh = opendir(dirname(__FILE__)); |
| 539 | 572 | while ($file = readdir($dh)) |
| 540 | 573 | { |
| 541 | - if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) |
|
| 542 | - @unlink(dirname(__FILE__) . '/' . $file); |
|
| 574 | + if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) { |
|
| 575 | + @unlink(dirname(__FILE__) . '/' . $file); |
|
| 576 | + } |
|
| 543 | 577 | } |
| 544 | 578 | closedir($dh); |
| 545 | 579 | |
@@ -568,8 +602,9 @@ discard block |
||
| 568 | 602 | $temp = 'upgrade_php?step'; |
| 569 | 603 | while (strlen($temp) > 4) |
| 570 | 604 | { |
| 571 | - if (isset($_GET[$temp])) |
|
| 572 | - unset($_GET[$temp]); |
|
| 605 | + if (isset($_GET[$temp])) { |
|
| 606 | + unset($_GET[$temp]); |
|
| 607 | + } |
|
| 573 | 608 | $temp = substr($temp, 1); |
| 574 | 609 | } |
| 575 | 610 | |
@@ -596,32 +631,39 @@ discard block |
||
| 596 | 631 | && @file_exists(dirname(__FILE__) . '/upgrade_2-1_' . $db_type . '.sql'); |
| 597 | 632 | |
| 598 | 633 | // Need legacy scripts? |
| 599 | - if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1) |
|
| 600 | - $check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql'); |
|
| 601 | - if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) |
|
| 602 | - $check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql'); |
|
| 603 | - if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) |
|
| 604 | - $check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql'); |
|
| 634 | + if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1) { |
|
| 635 | + $check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql'); |
|
| 636 | + } |
|
| 637 | + if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) { |
|
| 638 | + $check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql'); |
|
| 639 | + } |
|
| 640 | + if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) { |
|
| 641 | + $check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql'); |
|
| 642 | + } |
|
| 605 | 643 | |
| 606 | 644 | // We don't need "-utf8" files anymore... |
| 607 | 645 | $upcontext['language'] = str_ireplace('-utf8', '', $upcontext['language']); |
| 608 | 646 | |
| 609 | 647 | // This needs to exist! |
| 610 | - if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) |
|
| 611 | - return throw_error('The upgrader could not find the "Install" language file for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded all the files included in the package, even the theme and language files for the default theme.<br> [<a href="' . $upgradeurl . '?lang=english">Try English</a>]'); |
|
| 612 | - else |
|
| 613 | - require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'); |
|
| 648 | + if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) { |
|
| 649 | + return throw_error('The upgrader could not find the "Install" language file for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded all the files included in the package, even the theme and language files for the default theme.<br> [<a href="' . $upgradeurl . '?lang=english">Try English</a>]'); |
|
| 650 | + } else { |
|
| 651 | + require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'); |
|
| 652 | + } |
|
| 614 | 653 | |
| 615 | - if (!$check) |
|
| 616 | - // Don't tell them what files exactly because it's a spot check - just like teachers don't tell which problems they are spot checking, that's dumb. |
|
| 654 | + if (!$check) { |
|
| 655 | + // Don't tell them what files exactly because it's a spot check - just like teachers don't tell which problems they are spot checking, that's dumb. |
|
| 617 | 656 | return throw_error('The upgrader was unable to find some crucial files.<br><br>Please make sure you uploaded all of the files included in the package, including the Themes, Sources, and other directories.'); |
| 657 | + } |
|
| 618 | 658 | |
| 619 | 659 | // Do they meet the install requirements? |
| 620 | - if (!php_version_check()) |
|
| 621 | - return throw_error('Warning! You do not appear to have a version of PHP installed on your webserver that meets SMF\'s minimum installations requirements.<br><br>Please ask your host to upgrade.'); |
|
| 660 | + if (!php_version_check()) { |
|
| 661 | + return throw_error('Warning! You do not appear to have a version of PHP installed on your webserver that meets SMF\'s minimum installations requirements.<br><br>Please ask your host to upgrade.'); |
|
| 662 | + } |
|
| 622 | 663 | |
| 623 | - if (!db_version_check()) |
|
| 624 | - return throw_error('Your ' . $databases[$db_type]['name'] . ' version does not meet the minimum requirements of SMF.<br><br>Please ask your host to upgrade.'); |
|
| 664 | + if (!db_version_check()) { |
|
| 665 | + return throw_error('Your ' . $databases[$db_type]['name'] . ' version does not meet the minimum requirements of SMF.<br><br>Please ask your host to upgrade.'); |
|
| 666 | + } |
|
| 625 | 667 | |
| 626 | 668 | // Do some checks to make sure they have proper privileges |
| 627 | 669 | db_extend('packages'); |
@@ -636,14 +678,16 @@ discard block |
||
| 636 | 678 | $drop = $smcFunc['db_drop_table']('{db_prefix}priv_check'); |
| 637 | 679 | |
| 638 | 680 | // Sorry... we need CREATE, ALTER and DROP |
| 639 | - if (!$create || !$alter || !$drop) |
|
| 640 | - return throw_error('The ' . $databases[$db_type]['name'] . ' user you have set in Settings.php does not have proper privileges.<br><br>Please ask your host to give this user the ALTER, CREATE, and DROP privileges.'); |
|
| 681 | + if (!$create || !$alter || !$drop) { |
|
| 682 | + return throw_error('The ' . $databases[$db_type]['name'] . ' user you have set in Settings.php does not have proper privileges.<br><br>Please ask your host to give this user the ALTER, CREATE, and DROP privileges.'); |
|
| 683 | + } |
|
| 641 | 684 | |
| 642 | 685 | // Do a quick version spot check. |
| 643 | 686 | $temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096); |
| 644 | 687 | preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match); |
| 645 | - if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) |
|
| 646 | - return throw_error('The upgrader found some old or outdated files.<br><br>Please make certain you uploaded the new versions of all the files included in the package.'); |
|
| 688 | + if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) { |
|
| 689 | + return throw_error('The upgrader found some old or outdated files.<br><br>Please make certain you uploaded the new versions of all the files included in the package.'); |
|
| 690 | + } |
|
| 647 | 691 | |
| 648 | 692 | // What absolutely needs to be writable? |
| 649 | 693 | $writable_files = array( |
@@ -665,12 +709,13 @@ discard block |
||
| 665 | 709 | quickFileWritable($custom_av_dir); |
| 666 | 710 | |
| 667 | 711 | // Are we good now? |
| 668 | - if (!is_writable($custom_av_dir)) |
|
| 669 | - return throw_error(sprintf('The directory: %1$s has to be writable to continue the upgrade. Please make sure permissions are correctly set to allow this.', $custom_av_dir)); |
|
| 670 | - elseif ($need_settings_update) |
|
| 712 | + if (!is_writable($custom_av_dir)) { |
|
| 713 | + return throw_error(sprintf('The directory: %1$s has to be writable to continue the upgrade. Please make sure permissions are correctly set to allow this.', $custom_av_dir)); |
|
| 714 | + } elseif ($need_settings_update) |
|
| 671 | 715 | { |
| 672 | - if (!function_exists('cache_put_data')) |
|
| 673 | - require_once($sourcedir . '/Load.php'); |
|
| 716 | + if (!function_exists('cache_put_data')) { |
|
| 717 | + require_once($sourcedir . '/Load.php'); |
|
| 718 | + } |
|
| 674 | 719 | updateSettings(array('custom_avatar_dir' => $custom_av_dir)); |
| 675 | 720 | updateSettings(array('custom_avatar_url' => $custom_av_url)); |
| 676 | 721 | } |
@@ -679,28 +724,33 @@ discard block |
||
| 679 | 724 | |
| 680 | 725 | // Check the cache directory. |
| 681 | 726 | $cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir; |
| 682 | - if (!file_exists($cachedir_temp)) |
|
| 683 | - @mkdir($cachedir_temp); |
|
| 684 | - if (!file_exists($cachedir_temp)) |
|
| 685 | - return throw_error('The cache directory could not be found.<br><br>Please make sure you have a directory called "cache" in your forum directory before continuing.'); |
|
| 686 | - |
|
| 687 | - if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) |
|
| 688 | - return throw_error('The upgrader was unable to find language files for the language specified in Settings.php.<br>SMF will not work without the primary language files installed.<br><br>Please either install them, or <a href="' . $upgradeurl . '?step=0;lang=english">use english instead</a>.'); |
|
| 689 | - elseif (!isset($_GET['skiplang'])) |
|
| 727 | + if (!file_exists($cachedir_temp)) { |
|
| 728 | + @mkdir($cachedir_temp); |
|
| 729 | + } |
|
| 730 | + if (!file_exists($cachedir_temp)) { |
|
| 731 | + return throw_error('The cache directory could not be found.<br><br>Please make sure you have a directory called "cache" in your forum directory before continuing.'); |
|
| 732 | + } |
|
| 733 | + |
|
| 734 | + if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) { |
|
| 735 | + return throw_error('The upgrader was unable to find language files for the language specified in Settings.php.<br>SMF will not work without the primary language files installed.<br><br>Please either install them, or <a href="' . $upgradeurl . '?step=0;lang=english">use english instead</a>.'); |
|
| 736 | + } elseif (!isset($_GET['skiplang'])) |
|
| 690 | 737 | { |
| 691 | 738 | $temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096); |
| 692 | 739 | preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match); |
| 693 | 740 | |
| 694 | - if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) |
|
| 695 | - return throw_error('The upgrader found some old or outdated language files, for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded the new versions of all the files included in the package, even the theme and language files for the default theme.<br> [<a href="' . $upgradeurl . '?skiplang">SKIP</a>] [<a href="' . $upgradeurl . '?lang=english">Try English</a>]'); |
|
| 741 | + if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) { |
|
| 742 | + return throw_error('The upgrader found some old or outdated language files, for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded the new versions of all the files included in the package, even the theme and language files for the default theme.<br> [<a href="' . $upgradeurl . '?skiplang">SKIP</a>] [<a href="' . $upgradeurl . '?lang=english">Try English</a>]'); |
|
| 743 | + } |
|
| 696 | 744 | } |
| 697 | 745 | |
| 698 | - if (!makeFilesWritable($writable_files)) |
|
| 699 | - return false; |
|
| 746 | + if (!makeFilesWritable($writable_files)) { |
|
| 747 | + return false; |
|
| 748 | + } |
|
| 700 | 749 | |
| 701 | 750 | // Check agreement.txt. (it may not exist, in which case $boarddir must be writable.) |
| 702 | - if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) |
|
| 703 | - return throw_error('The upgrader was unable to obtain write access to agreement.txt.<br><br>If you are using a linux or unix based server, please ensure that the file is chmod\'d to 777, or if it does not exist that the directory this upgrader is in is 777.<br>If your server is running Windows, please ensure that the internet guest account has the proper permissions on it or its folder.'); |
|
| 751 | + if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) { |
|
| 752 | + return throw_error('The upgrader was unable to obtain write access to agreement.txt.<br><br>If you are using a linux or unix based server, please ensure that the file is chmod\'d to 777, or if it does not exist that the directory this upgrader is in is 777.<br>If your server is running Windows, please ensure that the internet guest account has the proper permissions on it or its folder.'); |
|
| 753 | + } |
|
| 704 | 754 | |
| 705 | 755 | // Upgrade the agreement. |
| 706 | 756 | elseif (isset($modSettings['agreement'])) |
@@ -711,8 +761,8 @@ discard block |
||
| 711 | 761 | } |
| 712 | 762 | |
| 713 | 763 | // We're going to check that their board dir setting is right in case they've been moving stuff around. |
| 714 | - if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) |
|
| 715 | - $upcontext['warning'] = ' |
|
| 764 | + if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) { |
|
| 765 | + $upcontext['warning'] = ' |
|
| 716 | 766 | It looks as if your board directory settings <em>might</em> be incorrect. Your board directory is currently set to "' . $boarddir . '" but should probably be "' . dirname(__FILE__) . '". Settings.php currently lists your paths as:<br> |
| 717 | 767 | <ul> |
| 718 | 768 | <li>Board Directory: ' . $boarddir . '</li> |
@@ -720,10 +770,12 @@ discard block |
||
| 720 | 770 | <li>Cache Directory: ' . $cachedir_temp . '</li> |
| 721 | 771 | </ul> |
| 722 | 772 | If these seem incorrect please open Settings.php in a text editor before proceeding with this upgrade. If they are incorrect due to you moving your forum to a new location please download and execute the <a href="https://download.simplemachines.org/?tools">Repair Settings</a> tool from the Simple Machines website before continuing.'; |
| 773 | + } |
|
| 723 | 774 | |
| 724 | 775 | // Either we're logged in or we're going to present the login. |
| 725 | - if (checkLogin()) |
|
| 726 | - return true; |
|
| 776 | + if (checkLogin()) { |
|
| 777 | + return true; |
|
| 778 | + } |
|
| 727 | 779 | |
| 728 | 780 | $upcontext += createToken('login'); |
| 729 | 781 | |
@@ -737,15 +789,17 @@ discard block |
||
| 737 | 789 | global $smcFunc, $db_type, $support_js; |
| 738 | 790 | |
| 739 | 791 | // Don't bother if the security is disabled. |
| 740 | - if ($disable_security) |
|
| 741 | - return true; |
|
| 792 | + if ($disable_security) { |
|
| 793 | + return true; |
|
| 794 | + } |
|
| 742 | 795 | |
| 743 | 796 | // Are we trying to login? |
| 744 | 797 | if (isset($_POST['contbutt']) && (!empty($_POST['user']))) |
| 745 | 798 | { |
| 746 | 799 | // If we've disabled security pick a suitable name! |
| 747 | - if (empty($_POST['user'])) |
|
| 748 | - $_POST['user'] = 'Administrator'; |
|
| 800 | + if (empty($_POST['user'])) { |
|
| 801 | + $_POST['user'] = 'Administrator'; |
|
| 802 | + } |
|
| 749 | 803 | |
| 750 | 804 | // Before 2.0 these column names were different! |
| 751 | 805 | $oldDB = false; |
@@ -760,16 +814,17 @@ discard block |
||
| 760 | 814 | 'db_error_skip' => true, |
| 761 | 815 | ) |
| 762 | 816 | ); |
| 763 | - if ($smcFunc['db_num_rows']($request) != 0) |
|
| 764 | - $oldDB = true; |
|
| 817 | + if ($smcFunc['db_num_rows']($request) != 0) { |
|
| 818 | + $oldDB = true; |
|
| 819 | + } |
|
| 765 | 820 | $smcFunc['db_free_result']($request); |
| 766 | 821 | } |
| 767 | 822 | |
| 768 | 823 | // Get what we believe to be their details. |
| 769 | 824 | if (!$disable_security) |
| 770 | 825 | { |
| 771 | - if ($oldDB) |
|
| 772 | - $request = $smcFunc['db_query']('', ' |
|
| 826 | + if ($oldDB) { |
|
| 827 | + $request = $smcFunc['db_query']('', ' |
|
| 773 | 828 | SELECT id_member, memberName AS member_name, passwd, id_group, |
| 774 | 829 | additionalGroups AS additional_groups, lngfile |
| 775 | 830 | FROM {db_prefix}members |
@@ -779,8 +834,8 @@ discard block |
||
| 779 | 834 | 'db_error_skip' => true, |
| 780 | 835 | ) |
| 781 | 836 | ); |
| 782 | - else |
|
| 783 | - $request = $smcFunc['db_query']('', ' |
|
| 837 | + } else { |
|
| 838 | + $request = $smcFunc['db_query']('', ' |
|
| 784 | 839 | SELECT id_member, member_name, passwd, id_group, additional_groups, lngfile |
| 785 | 840 | FROM {db_prefix}members |
| 786 | 841 | WHERE member_name = {string:member_name}', |
@@ -789,6 +844,7 @@ discard block |
||
| 789 | 844 | 'db_error_skip' => true, |
| 790 | 845 | ) |
| 791 | 846 | ); |
| 847 | + } |
|
| 792 | 848 | if ($smcFunc['db_num_rows']($request) != 0) |
| 793 | 849 | { |
| 794 | 850 | list ($id_member, $name, $password, $id_group, $addGroups, $user_language) = $smcFunc['db_fetch_row']($request); |
@@ -796,16 +852,17 @@ discard block |
||
| 796 | 852 | $groups = explode(',', $addGroups); |
| 797 | 853 | $groups[] = $id_group; |
| 798 | 854 | |
| 799 | - foreach ($groups as $k => $v) |
|
| 800 | - $groups[$k] = (int) $v; |
|
| 855 | + foreach ($groups as $k => $v) { |
|
| 856 | + $groups[$k] = (int) $v; |
|
| 857 | + } |
|
| 801 | 858 | |
| 802 | 859 | $sha_passwd = sha1(strtolower($name) . un_htmlspecialchars($_REQUEST['passwrd'])); |
| 803 | 860 | |
| 804 | 861 | // We don't use "-utf8" anymore... |
| 805 | 862 | $user_language = str_ireplace('-utf8', '', $user_language); |
| 863 | + } else { |
|
| 864 | + $upcontext['username_incorrect'] = true; |
|
| 806 | 865 | } |
| 807 | - else |
|
| 808 | - $upcontext['username_incorrect'] = true; |
|
| 809 | 866 | $smcFunc['db_free_result']($request); |
| 810 | 867 | } |
| 811 | 868 | $upcontext['username'] = $_POST['user']; |
@@ -815,13 +872,14 @@ discard block |
||
| 815 | 872 | { |
| 816 | 873 | $upcontext['upgrade_status']['js'] = 1; |
| 817 | 874 | $support_js = 1; |
| 875 | + } else { |
|
| 876 | + $support_js = 0; |
|
| 818 | 877 | } |
| 819 | - else |
|
| 820 | - $support_js = 0; |
|
| 821 | 878 | |
| 822 | 879 | // Note down the version we are coming from. |
| 823 | - if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) |
|
| 824 | - $upcontext['user']['version'] = $modSettings['smfVersion']; |
|
| 880 | + if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) { |
|
| 881 | + $upcontext['user']['version'] = $modSettings['smfVersion']; |
|
| 882 | + } |
|
| 825 | 883 | |
| 826 | 884 | // Didn't get anywhere? |
| 827 | 885 | if (!$disable_security && (empty($sha_passwd) || (!empty($password) ? $password : '') != $sha_passwd) && !hash_verify_password((!empty($name) ? $name : ''), $_REQUEST['passwrd'], (!empty($password) ? $password : '')) && empty($upcontext['username_incorrect'])) |
@@ -855,15 +913,15 @@ discard block |
||
| 855 | 913 | 'db_error_skip' => true, |
| 856 | 914 | ) |
| 857 | 915 | ); |
| 858 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 859 | - return throw_error('You need to be an admin to perform an upgrade!'); |
|
| 916 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 917 | + return throw_error('You need to be an admin to perform an upgrade!'); |
|
| 918 | + } |
|
| 860 | 919 | $smcFunc['db_free_result']($request); |
| 861 | 920 | } |
| 862 | 921 | |
| 863 | 922 | $upcontext['user']['id'] = $id_member; |
| 864 | 923 | $upcontext['user']['name'] = $name; |
| 865 | - } |
|
| 866 | - else |
|
| 924 | + } else |
|
| 867 | 925 | { |
| 868 | 926 | $upcontext['user']['id'] = 1; |
| 869 | 927 | $upcontext['user']['name'] = 'Administrator'; |
@@ -879,11 +937,11 @@ discard block |
||
| 879 | 937 | $temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $user_language . '.php')), 0, 4096); |
| 880 | 938 | preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match); |
| 881 | 939 | |
| 882 | - if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) |
|
| 883 | - $upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been updated to the latest version. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.'; |
|
| 884 | - elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) |
|
| 885 | - $upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been uploaded/updated as the "Install" language file is missing. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.'; |
|
| 886 | - else |
|
| 940 | + if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) { |
|
| 941 | + $upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been updated to the latest version. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.'; |
|
| 942 | + } elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) { |
|
| 943 | + $upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been uploaded/updated as the "Install" language file is missing. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.'; |
|
| 944 | + } else |
|
| 887 | 945 | { |
| 888 | 946 | // Set this as the new language. |
| 889 | 947 | $upcontext['language'] = $user_language; |
@@ -927,8 +985,9 @@ discard block |
||
| 927 | 985 | unset($member_columns); |
| 928 | 986 | |
| 929 | 987 | // If we've not submitted then we're done. |
| 930 | - if (empty($_POST['upcont'])) |
|
| 931 | - return false; |
|
| 988 | + if (empty($_POST['upcont'])) { |
|
| 989 | + return false; |
|
| 990 | + } |
|
| 932 | 991 | |
| 933 | 992 | // Firstly, if they're enabling SM stat collection just do it. |
| 934 | 993 | if (!empty($_POST['stats']) && (substr($boardurl, 0, 16) != 'http://localhost' || substr($boardurl, 0, 16) != 'https://localhost') && empty($modSettings['allow_sm_stats'])) |
@@ -943,25 +1002,26 @@ discard block |
||
| 943 | 1002 | fwrite($fp, $out); |
| 944 | 1003 | |
| 945 | 1004 | $return_data = ''; |
| 946 | - while (!feof($fp)) |
|
| 947 | - $return_data .= fgets($fp, 128); |
|
| 1005 | + while (!feof($fp)) { |
|
| 1006 | + $return_data .= fgets($fp, 128); |
|
| 1007 | + } |
|
| 948 | 1008 | |
| 949 | 1009 | fclose($fp); |
| 950 | 1010 | |
| 951 | 1011 | // Get the unique site ID. |
| 952 | 1012 | preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID); |
| 953 | 1013 | |
| 954 | - if (!empty($ID[1])) |
|
| 955 | - $smcFunc['db_insert']('replace', |
|
| 1014 | + if (!empty($ID[1])) { |
|
| 1015 | + $smcFunc['db_insert']('replace', |
|
| 956 | 1016 | $db_prefix . 'settings', |
| 957 | 1017 | array('variable' => 'string', 'value' => 'string'), |
| 958 | 1018 | array('allow_sm_stats', $ID[1]), |
| 959 | 1019 | array('variable') |
| 960 | 1020 | ); |
| 1021 | + } |
|
| 961 | 1022 | } |
| 962 | - } |
|
| 963 | - else |
|
| 964 | - $smcFunc['db_query']('', ' |
|
| 1023 | + } else { |
|
| 1024 | + $smcFunc['db_query']('', ' |
|
| 965 | 1025 | DELETE FROM {db_prefix}settings |
| 966 | 1026 | WHERE variable = {string:allow_sm_stats}', |
| 967 | 1027 | array( |
@@ -969,6 +1029,7 @@ discard block |
||
| 969 | 1029 | 'db_error_skip' => true, |
| 970 | 1030 | ) |
| 971 | 1031 | ); |
| 1032 | + } |
|
| 972 | 1033 | |
| 973 | 1034 | // Deleting old karma stuff? |
| 974 | 1035 | if (!empty($_POST['delete_karma'])) |
@@ -983,20 +1044,22 @@ discard block |
||
| 983 | 1044 | ); |
| 984 | 1045 | |
| 985 | 1046 | // Cleaning up old karma member settings. |
| 986 | - if ($upcontext['karma_installed']['good']) |
|
| 987 | - $smcFunc['db_query']('', ' |
|
| 1047 | + if ($upcontext['karma_installed']['good']) { |
|
| 1048 | + $smcFunc['db_query']('', ' |
|
| 988 | 1049 | ALTER TABLE {db_prefix}members |
| 989 | 1050 | DROP karma_good', |
| 990 | 1051 | array() |
| 991 | 1052 | ); |
| 1053 | + } |
|
| 992 | 1054 | |
| 993 | 1055 | // Does karma bad was enable? |
| 994 | - if ($upcontext['karma_installed']['bad']) |
|
| 995 | - $smcFunc['db_query']('', ' |
|
| 1056 | + if ($upcontext['karma_installed']['bad']) { |
|
| 1057 | + $smcFunc['db_query']('', ' |
|
| 996 | 1058 | ALTER TABLE {db_prefix}members |
| 997 | 1059 | DROP karma_bad', |
| 998 | 1060 | array() |
| 999 | 1061 | ); |
| 1062 | + } |
|
| 1000 | 1063 | |
| 1001 | 1064 | // Cleaning up old karma permissions. |
| 1002 | 1065 | $smcFunc['db_query']('', ' |
@@ -1009,26 +1072,29 @@ discard block |
||
| 1009 | 1072 | } |
| 1010 | 1073 | |
| 1011 | 1074 | // Emptying the error log? |
| 1012 | - if (!empty($_POST['empty_error'])) |
|
| 1013 | - $smcFunc['db_query']('truncate_table', ' |
|
| 1075 | + if (!empty($_POST['empty_error'])) { |
|
| 1076 | + $smcFunc['db_query']('truncate_table', ' |
|
| 1014 | 1077 | TRUNCATE {db_prefix}log_errors', |
| 1015 | 1078 | array( |
| 1016 | 1079 | ) |
| 1017 | 1080 | ); |
| 1081 | + } |
|
| 1018 | 1082 | |
| 1019 | 1083 | $changes = array(); |
| 1020 | 1084 | |
| 1021 | 1085 | // Add proxy settings. |
| 1022 | - if (!isset($GLOBALS['image_proxy_maxsize'])) |
|
| 1023 | - $changes += array( |
|
| 1086 | + if (!isset($GLOBALS['image_proxy_maxsize'])) { |
|
| 1087 | + $changes += array( |
|
| 1024 | 1088 | 'image_proxy_secret' => '\'' . substr(sha1(mt_rand()), 0, 20) . '\'', |
| 1025 | 1089 | 'image_proxy_maxsize' => 5190, |
| 1026 | 1090 | 'image_proxy_enabled' => 0, |
| 1027 | 1091 | ); |
| 1092 | + } |
|
| 1028 | 1093 | |
| 1029 | 1094 | // If we're overriding the language follow it through. |
| 1030 | - if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) |
|
| 1031 | - $changes['language'] = '\'' . $_GET['lang'] . '\''; |
|
| 1095 | + if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) { |
|
| 1096 | + $changes['language'] = '\'' . $_GET['lang'] . '\''; |
|
| 1097 | + } |
|
| 1032 | 1098 | |
| 1033 | 1099 | if (!empty($_POST['maint'])) |
| 1034 | 1100 | { |
@@ -1040,30 +1106,34 @@ discard block |
||
| 1040 | 1106 | { |
| 1041 | 1107 | $changes['mtitle'] = '\'' . addslashes($_POST['maintitle']) . '\''; |
| 1042 | 1108 | $changes['mmessage'] = '\'' . addslashes($_POST['mainmessage']) . '\''; |
| 1043 | - } |
|
| 1044 | - else |
|
| 1109 | + } else |
|
| 1045 | 1110 | { |
| 1046 | 1111 | $changes['mtitle'] = '\'Upgrading the forum...\''; |
| 1047 | 1112 | $changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum. It will only be a minute ;).\''; |
| 1048 | 1113 | } |
| 1049 | 1114 | } |
| 1050 | 1115 | |
| 1051 | - if ($command_line) |
|
| 1052 | - echo ' * Updating Settings.php...'; |
|
| 1116 | + if ($command_line) { |
|
| 1117 | + echo ' * Updating Settings.php...'; |
|
| 1118 | + } |
|
| 1053 | 1119 | |
| 1054 | 1120 | // Fix some old paths. |
| 1055 | - if (substr($boarddir, 0, 1) == '.') |
|
| 1056 | - $changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\''; |
|
| 1121 | + if (substr($boarddir, 0, 1) == '.') { |
|
| 1122 | + $changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\''; |
|
| 1123 | + } |
|
| 1057 | 1124 | |
| 1058 | - if (substr($sourcedir, 0, 1) == '.') |
|
| 1059 | - $changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\''; |
|
| 1125 | + if (substr($sourcedir, 0, 1) == '.') { |
|
| 1126 | + $changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\''; |
|
| 1127 | + } |
|
| 1060 | 1128 | |
| 1061 | - if (empty($cachedir) || substr($cachedir, 0, 1) == '.') |
|
| 1062 | - $changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\''; |
|
| 1129 | + if (empty($cachedir) || substr($cachedir, 0, 1) == '.') { |
|
| 1130 | + $changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\''; |
|
| 1131 | + } |
|
| 1063 | 1132 | |
| 1064 | 1133 | // Not had the database type added before? |
| 1065 | - if (empty($db_type)) |
|
| 1066 | - $changes['db_type'] = 'mysql'; |
|
| 1134 | + if (empty($db_type)) { |
|
| 1135 | + $changes['db_type'] = 'mysql'; |
|
| 1136 | + } |
|
| 1067 | 1137 | |
| 1068 | 1138 | // If they have a "host:port" setup for the host, split that into separate values |
| 1069 | 1139 | // You should never have a : in the hostname if you're not on MySQL, but better safe than sorry |
@@ -1074,32 +1144,36 @@ discard block |
||
| 1074 | 1144 | $changes['db_server'] = '\'' . $db_server . '\''; |
| 1075 | 1145 | |
| 1076 | 1146 | // Only set this if we're not using the default port |
| 1077 | - if ($db_port != ini_get('mysqli.default_port')) |
|
| 1078 | - $changes['db_port'] = (int) $db_port; |
|
| 1079 | - } |
|
| 1080 | - elseif (!empty($db_port)) |
|
| 1147 | + if ($db_port != ini_get('mysqli.default_port')) { |
|
| 1148 | + $changes['db_port'] = (int) $db_port; |
|
| 1149 | + } |
|
| 1150 | + } elseif (!empty($db_port)) |
|
| 1081 | 1151 | { |
| 1082 | 1152 | // If db_port is set and is the same as the default, set it to '' |
| 1083 | 1153 | if ($db_type == 'mysql') |
| 1084 | 1154 | { |
| 1085 | - if ($db_port == ini_get('mysqli.default_port')) |
|
| 1086 | - $changes['db_port'] = '\'\''; |
|
| 1087 | - elseif ($db_type == 'postgresql' && $db_port == 5432) |
|
| 1088 | - $changes['db_port'] = '\'\''; |
|
| 1155 | + if ($db_port == ini_get('mysqli.default_port')) { |
|
| 1156 | + $changes['db_port'] = '\'\''; |
|
| 1157 | + } elseif ($db_type == 'postgresql' && $db_port == 5432) { |
|
| 1158 | + $changes['db_port'] = '\'\''; |
|
| 1159 | + } |
|
| 1089 | 1160 | } |
| 1090 | 1161 | } |
| 1091 | 1162 | |
| 1092 | 1163 | // Maybe we haven't had this option yet? |
| 1093 | - if (empty($packagesdir)) |
|
| 1094 | - $changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\''; |
|
| 1164 | + if (empty($packagesdir)) { |
|
| 1165 | + $changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\''; |
|
| 1166 | + } |
|
| 1095 | 1167 | |
| 1096 | 1168 | // Add support for $tasksdir var. |
| 1097 | - if (empty($tasksdir)) |
|
| 1098 | - $changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\''; |
|
| 1169 | + if (empty($tasksdir)) { |
|
| 1170 | + $changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\''; |
|
| 1171 | + } |
|
| 1099 | 1172 | |
| 1100 | 1173 | // Make sure we fix the language as well. |
| 1101 | - if (stristr($language, '-utf8')) |
|
| 1102 | - $changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\''; |
|
| 1174 | + if (stristr($language, '-utf8')) { |
|
| 1175 | + $changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\''; |
|
| 1176 | + } |
|
| 1103 | 1177 | |
| 1104 | 1178 | // @todo Maybe change the cookie name if going to 1.1, too? |
| 1105 | 1179 | |
@@ -1107,8 +1181,9 @@ discard block |
||
| 1107 | 1181 | require_once($sourcedir . '/Subs-Admin.php'); |
| 1108 | 1182 | updateSettingsFile($changes); |
| 1109 | 1183 | |
| 1110 | - if ($command_line) |
|
| 1111 | - echo ' Successful.' . "\n"; |
|
| 1184 | + if ($command_line) { |
|
| 1185 | + echo ' Successful.' . "\n"; |
|
| 1186 | + } |
|
| 1112 | 1187 | |
| 1113 | 1188 | // Are we doing debug? |
| 1114 | 1189 | if (isset($_POST['debug'])) |
@@ -1118,8 +1193,9 @@ discard block |
||
| 1118 | 1193 | } |
| 1119 | 1194 | |
| 1120 | 1195 | // If we're not backing up then jump one. |
| 1121 | - if (empty($_POST['backup'])) |
|
| 1122 | - $upcontext['current_step']++; |
|
| 1196 | + if (empty($_POST['backup'])) { |
|
| 1197 | + $upcontext['current_step']++; |
|
| 1198 | + } |
|
| 1123 | 1199 | |
| 1124 | 1200 | // If we've got here then let's proceed to the next step! |
| 1125 | 1201 | return true; |
@@ -1134,8 +1210,9 @@ discard block |
||
| 1134 | 1210 | $upcontext['page_title'] = 'Backup Database'; |
| 1135 | 1211 | |
| 1136 | 1212 | // Done it already - js wise? |
| 1137 | - if (!empty($_POST['backup_done'])) |
|
| 1138 | - return true; |
|
| 1213 | + if (!empty($_POST['backup_done'])) { |
|
| 1214 | + return true; |
|
| 1215 | + } |
|
| 1139 | 1216 | |
| 1140 | 1217 | // Some useful stuff here. |
| 1141 | 1218 | db_extend(); |
@@ -1149,9 +1226,10 @@ discard block |
||
| 1149 | 1226 | $tables = $smcFunc['db_list_tables']($db, $filter); |
| 1150 | 1227 | |
| 1151 | 1228 | $table_names = array(); |
| 1152 | - foreach ($tables as $table) |
|
| 1153 | - if (substr($table, 0, 7) !== 'backup_') |
|
| 1229 | + foreach ($tables as $table) { |
|
| 1230 | + if (substr($table, 0, 7) !== 'backup_') |
|
| 1154 | 1231 | $table_names[] = $table; |
| 1232 | + } |
|
| 1155 | 1233 | |
| 1156 | 1234 | $upcontext['table_count'] = count($table_names); |
| 1157 | 1235 | $upcontext['cur_table_num'] = $_GET['substep']; |
@@ -1161,12 +1239,14 @@ discard block |
||
| 1161 | 1239 | $file_steps = $upcontext['table_count']; |
| 1162 | 1240 | |
| 1163 | 1241 | // What ones have we already done? |
| 1164 | - foreach ($table_names as $id => $table) |
|
| 1165 | - if ($id < $_GET['substep']) |
|
| 1242 | + foreach ($table_names as $id => $table) { |
|
| 1243 | + if ($id < $_GET['substep']) |
|
| 1166 | 1244 | $upcontext['previous_tables'][] = $table; |
| 1245 | + } |
|
| 1167 | 1246 | |
| 1168 | - if ($command_line) |
|
| 1169 | - echo 'Backing Up Tables.'; |
|
| 1247 | + if ($command_line) { |
|
| 1248 | + echo 'Backing Up Tables.'; |
|
| 1249 | + } |
|
| 1170 | 1250 | |
| 1171 | 1251 | // If we don't support javascript we backup here. |
| 1172 | 1252 | if (!$support_js || isset($_GET['xml'])) |
@@ -1185,8 +1265,9 @@ discard block |
||
| 1185 | 1265 | backupTable($table_names[$substep]); |
| 1186 | 1266 | |
| 1187 | 1267 | // If this is XML to keep it nice for the user do one table at a time anyway! |
| 1188 | - if (isset($_GET['xml'])) |
|
| 1189 | - return upgradeExit(); |
|
| 1268 | + if (isset($_GET['xml'])) { |
|
| 1269 | + return upgradeExit(); |
|
| 1270 | + } |
|
| 1190 | 1271 | } |
| 1191 | 1272 | |
| 1192 | 1273 | if ($command_line) |
@@ -1219,9 +1300,10 @@ discard block |
||
| 1219 | 1300 | |
| 1220 | 1301 | $smcFunc['db_backup_table']($table, 'backup_' . $table); |
| 1221 | 1302 | |
| 1222 | - if ($command_line) |
|
| 1223 | - echo ' done.'; |
|
| 1224 | -} |
|
| 1303 | + if ($command_line) { |
|
| 1304 | + echo ' done.'; |
|
| 1305 | + } |
|
| 1306 | + } |
|
| 1225 | 1307 | |
| 1226 | 1308 | // Step 2: Everything. |
| 1227 | 1309 | function DatabaseChanges() |
@@ -1230,8 +1312,9 @@ discard block |
||
| 1230 | 1312 | global $upcontext, $support_js, $db_type; |
| 1231 | 1313 | |
| 1232 | 1314 | // Have we just completed this? |
| 1233 | - if (!empty($_POST['database_done'])) |
|
| 1234 | - return true; |
|
| 1315 | + if (!empty($_POST['database_done'])) { |
|
| 1316 | + return true; |
|
| 1317 | + } |
|
| 1235 | 1318 | |
| 1236 | 1319 | $upcontext['sub_template'] = isset($_GET['xml']) ? 'database_xml' : 'database_changes'; |
| 1237 | 1320 | $upcontext['page_title'] = 'Database Changes'; |
@@ -1246,15 +1329,16 @@ discard block |
||
| 1246 | 1329 | ); |
| 1247 | 1330 | |
| 1248 | 1331 | // How many files are there in total? |
| 1249 | - if (isset($_GET['filecount'])) |
|
| 1250 | - $upcontext['file_count'] = (int) $_GET['filecount']; |
|
| 1251 | - else |
|
| 1332 | + if (isset($_GET['filecount'])) { |
|
| 1333 | + $upcontext['file_count'] = (int) $_GET['filecount']; |
|
| 1334 | + } else |
|
| 1252 | 1335 | { |
| 1253 | 1336 | $upcontext['file_count'] = 0; |
| 1254 | 1337 | foreach ($files as $file) |
| 1255 | 1338 | { |
| 1256 | - if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) |
|
| 1257 | - $upcontext['file_count']++; |
|
| 1339 | + if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) { |
|
| 1340 | + $upcontext['file_count']++; |
|
| 1341 | + } |
|
| 1258 | 1342 | } |
| 1259 | 1343 | } |
| 1260 | 1344 | |
@@ -1264,9 +1348,9 @@ discard block |
||
| 1264 | 1348 | $upcontext['cur_file_num'] = 0; |
| 1265 | 1349 | foreach ($files as $file) |
| 1266 | 1350 | { |
| 1267 | - if ($did_not_do) |
|
| 1268 | - $did_not_do--; |
|
| 1269 | - else |
|
| 1351 | + if ($did_not_do) { |
|
| 1352 | + $did_not_do--; |
|
| 1353 | + } else |
|
| 1270 | 1354 | { |
| 1271 | 1355 | $upcontext['cur_file_num']++; |
| 1272 | 1356 | $upcontext['cur_file_name'] = $file[0]; |
@@ -1293,12 +1377,13 @@ discard block |
||
| 1293 | 1377 | // Flag to move on to the next. |
| 1294 | 1378 | $upcontext['completed_step'] = true; |
| 1295 | 1379 | // Did we complete the whole file? |
| 1296 | - if ($nextFile) |
|
| 1297 | - $upcontext['current_debug_item_num'] = -1; |
|
| 1380 | + if ($nextFile) { |
|
| 1381 | + $upcontext['current_debug_item_num'] = -1; |
|
| 1382 | + } |
|
| 1298 | 1383 | return upgradeExit(); |
| 1384 | + } elseif ($support_js) { |
|
| 1385 | + break; |
|
| 1299 | 1386 | } |
| 1300 | - elseif ($support_js) |
|
| 1301 | - break; |
|
| 1302 | 1387 | } |
| 1303 | 1388 | // Set the progress bar to be right as if we had - even if we hadn't... |
| 1304 | 1389 | $upcontext['step_progress'] = ($upcontext['cur_file_num'] / $upcontext['file_count']) * 100; |
@@ -1323,8 +1408,9 @@ discard block |
||
| 1323 | 1408 | global $command_line, $language, $upcontext, $boarddir, $sourcedir, $forum_version, $user_info, $maintenance, $smcFunc, $db_type; |
| 1324 | 1409 | |
| 1325 | 1410 | // Now it's nice to have some of the basic SMF source files. |
| 1326 | - if (!isset($_GET['ssi']) && !$command_line) |
|
| 1327 | - redirectLocation('&ssi=1'); |
|
| 1411 | + if (!isset($_GET['ssi']) && !$command_line) { |
|
| 1412 | + redirectLocation('&ssi=1'); |
|
| 1413 | + } |
|
| 1328 | 1414 | |
| 1329 | 1415 | $upcontext['sub_template'] = 'upgrade_complete'; |
| 1330 | 1416 | $upcontext['page_title'] = 'Upgrade Complete'; |
@@ -1340,14 +1426,16 @@ discard block |
||
| 1340 | 1426 | // Are we in maintenance mode? |
| 1341 | 1427 | if (isset($upcontext['user']['main'])) |
| 1342 | 1428 | { |
| 1343 | - if ($command_line) |
|
| 1344 | - echo ' * '; |
|
| 1429 | + if ($command_line) { |
|
| 1430 | + echo ' * '; |
|
| 1431 | + } |
|
| 1345 | 1432 | $upcontext['removed_maintenance'] = true; |
| 1346 | 1433 | $changes['maintenance'] = $upcontext['user']['main']; |
| 1347 | 1434 | } |
| 1348 | 1435 | // Otherwise if somehow we are in 2 let's go to 1. |
| 1349 | - elseif (!empty($maintenance) && $maintenance == 2) |
|
| 1350 | - $changes['maintenance'] = 1; |
|
| 1436 | + elseif (!empty($maintenance) && $maintenance == 2) { |
|
| 1437 | + $changes['maintenance'] = 1; |
|
| 1438 | + } |
|
| 1351 | 1439 | |
| 1352 | 1440 | // Wipe this out... |
| 1353 | 1441 | $upcontext['user'] = array(); |
@@ -1362,9 +1450,9 @@ discard block |
||
| 1362 | 1450 | $upcontext['can_delete_script'] = is_writable(dirname(__FILE__)) || is_writable(__FILE__); |
| 1363 | 1451 | |
| 1364 | 1452 | // Now is the perfect time to fetch the SM files. |
| 1365 | - if ($command_line) |
|
| 1366 | - cli_scheduled_fetchSMfiles(); |
|
| 1367 | - else |
|
| 1453 | + if ($command_line) { |
|
| 1454 | + cli_scheduled_fetchSMfiles(); |
|
| 1455 | + } else |
|
| 1368 | 1456 | { |
| 1369 | 1457 | require_once($sourcedir . '/ScheduledTasks.php'); |
| 1370 | 1458 | $forum_version = SMF_VERSION; // The variable is usually defined in index.php so lets just use the constant to do it for us. |
@@ -1372,8 +1460,9 @@ discard block |
||
| 1372 | 1460 | } |
| 1373 | 1461 | |
| 1374 | 1462 | // Log what we've done. |
| 1375 | - if (empty($user_info['id'])) |
|
| 1376 | - $user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0; |
|
| 1463 | + if (empty($user_info['id'])) { |
|
| 1464 | + $user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0; |
|
| 1465 | + } |
|
| 1377 | 1466 | |
| 1378 | 1467 | // Log the action manually, so CLI still works. |
| 1379 | 1468 | $smcFunc['db_insert']('', |
@@ -1392,8 +1481,9 @@ discard block |
||
| 1392 | 1481 | |
| 1393 | 1482 | // Save the current database version. |
| 1394 | 1483 | $server_version = $smcFunc['db_server_info'](); |
| 1395 | - if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) |
|
| 1396 | - updateSettings(array('db_mysql_group_by_fix' => '1')); |
|
| 1484 | + if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) { |
|
| 1485 | + updateSettings(array('db_mysql_group_by_fix' => '1')); |
|
| 1486 | + } |
|
| 1397 | 1487 | |
| 1398 | 1488 | if ($command_line) |
| 1399 | 1489 | { |
@@ -1405,8 +1495,9 @@ discard block |
||
| 1405 | 1495 | |
| 1406 | 1496 | // Make sure it says we're done. |
| 1407 | 1497 | $upcontext['overall_percent'] = 100; |
| 1408 | - if (isset($upcontext['step_progress'])) |
|
| 1409 | - unset($upcontext['step_progress']); |
|
| 1498 | + if (isset($upcontext['step_progress'])) { |
|
| 1499 | + unset($upcontext['step_progress']); |
|
| 1500 | + } |
|
| 1410 | 1501 | |
| 1411 | 1502 | $_GET['substep'] = 0; |
| 1412 | 1503 | return false; |
@@ -1417,8 +1508,9 @@ discard block |
||
| 1417 | 1508 | { |
| 1418 | 1509 | global $sourcedir, $language, $forum_version, $modSettings, $smcFunc; |
| 1419 | 1510 | |
| 1420 | - if (empty($modSettings['time_format'])) |
|
| 1421 | - $modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p'; |
|
| 1511 | + if (empty($modSettings['time_format'])) { |
|
| 1512 | + $modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p'; |
|
| 1513 | + } |
|
| 1422 | 1514 | |
| 1423 | 1515 | // What files do we want to get |
| 1424 | 1516 | $request = $smcFunc['db_query']('', ' |
@@ -1452,8 +1544,9 @@ discard block |
||
| 1452 | 1544 | $file_data = fetch_web_data($url); |
| 1453 | 1545 | |
| 1454 | 1546 | // If we got an error - give up - the site might be down. |
| 1455 | - if ($file_data === false) |
|
| 1456 | - return throw_error(sprintf('Could not retrieve the file %1$s.', $url)); |
|
| 1547 | + if ($file_data === false) { |
|
| 1548 | + return throw_error(sprintf('Could not retrieve the file %1$s.', $url)); |
|
| 1549 | + } |
|
| 1457 | 1550 | |
| 1458 | 1551 | // Save the file to the database. |
| 1459 | 1552 | $smcFunc['db_query']('substring', ' |
@@ -1495,8 +1588,9 @@ discard block |
||
| 1495 | 1588 | $themeData = array(); |
| 1496 | 1589 | foreach ($values as $variable => $value) |
| 1497 | 1590 | { |
| 1498 | - if (!isset($value) || $value === null) |
|
| 1499 | - $value = 0; |
|
| 1591 | + if (!isset($value) || $value === null) { |
|
| 1592 | + $value = 0; |
|
| 1593 | + } |
|
| 1500 | 1594 | |
| 1501 | 1595 | $themeData[] = array(0, 1, $variable, $value); |
| 1502 | 1596 | } |
@@ -1525,8 +1619,9 @@ discard block |
||
| 1525 | 1619 | |
| 1526 | 1620 | foreach ($values as $variable => $value) |
| 1527 | 1621 | { |
| 1528 | - if (empty($modSettings[$value[0]])) |
|
| 1529 | - continue; |
|
| 1622 | + if (empty($modSettings[$value[0]])) { |
|
| 1623 | + continue; |
|
| 1624 | + } |
|
| 1530 | 1625 | |
| 1531 | 1626 | $smcFunc['db_query']('', ' |
| 1532 | 1627 | INSERT IGNORE INTO {db_prefix}themes |
@@ -1612,10 +1707,11 @@ discard block |
||
| 1612 | 1707 | set_error_handler( |
| 1613 | 1708 | function ($errno, $errstr, $errfile, $errline) use ($support_js) |
| 1614 | 1709 | { |
| 1615 | - if ($support_js) |
|
| 1616 | - return true; |
|
| 1617 | - else |
|
| 1618 | - echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline; |
|
| 1710 | + if ($support_js) { |
|
| 1711 | + return true; |
|
| 1712 | + } else { |
|
| 1713 | + echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline; |
|
| 1714 | + } |
|
| 1619 | 1715 | } |
| 1620 | 1716 | ); |
| 1621 | 1717 | |
@@ -1630,8 +1726,9 @@ discard block |
||
| 1630 | 1726 | 'db_error_skip' => true, |
| 1631 | 1727 | ) |
| 1632 | 1728 | ); |
| 1633 | - if ($smcFunc['db_num_rows']($request) === 0) |
|
| 1634 | - die('Unable to find members table!'); |
|
| 1729 | + if ($smcFunc['db_num_rows']($request) === 0) { |
|
| 1730 | + die('Unable to find members table!'); |
|
| 1731 | + } |
|
| 1635 | 1732 | $table_status = $smcFunc['db_fetch_assoc']($request); |
| 1636 | 1733 | $smcFunc['db_free_result']($request); |
| 1637 | 1734 | |
@@ -1646,17 +1743,20 @@ discard block |
||
| 1646 | 1743 | ) |
| 1647 | 1744 | ); |
| 1648 | 1745 | // Got something? |
| 1649 | - if ($smcFunc['db_num_rows']($request) !== 0) |
|
| 1650 | - $collation_info = $smcFunc['db_fetch_assoc']($request); |
|
| 1746 | + if ($smcFunc['db_num_rows']($request) !== 0) { |
|
| 1747 | + $collation_info = $smcFunc['db_fetch_assoc']($request); |
|
| 1748 | + } |
|
| 1651 | 1749 | $smcFunc['db_free_result']($request); |
| 1652 | 1750 | |
| 1653 | 1751 | // Excellent! |
| 1654 | - if (!empty($collation_info['Collation']) && !empty($collation_info['Charset'])) |
|
| 1655 | - $db_collation = ' CHARACTER SET ' . $collation_info['Charset'] . ' COLLATE ' . $collation_info['Collation']; |
|
| 1752 | + if (!empty($collation_info['Collation']) && !empty($collation_info['Charset'])) { |
|
| 1753 | + $db_collation = ' CHARACTER SET ' . $collation_info['Charset'] . ' COLLATE ' . $collation_info['Collation']; |
|
| 1754 | + } |
|
| 1656 | 1755 | } |
| 1657 | 1756 | } |
| 1658 | - if (empty($db_collation)) |
|
| 1659 | - $db_collation = ''; |
|
| 1757 | + if (empty($db_collation)) { |
|
| 1758 | + $db_collation = ''; |
|
| 1759 | + } |
|
| 1660 | 1760 | |
| 1661 | 1761 | $endl = $command_line ? "\n" : '<br>' . "\n"; |
| 1662 | 1762 | |
@@ -1668,8 +1768,9 @@ discard block |
||
| 1668 | 1768 | $last_step = ''; |
| 1669 | 1769 | |
| 1670 | 1770 | // Make sure all newly created tables will have the proper characters set. |
| 1671 | - if (isset($db_character_set) && $db_character_set === 'utf8') |
|
| 1672 | - $lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines); |
|
| 1771 | + if (isset($db_character_set) && $db_character_set === 'utf8') { |
|
| 1772 | + $lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines); |
|
| 1773 | + } |
|
| 1673 | 1774 | |
| 1674 | 1775 | // Count the total number of steps within this file - for progress. |
| 1675 | 1776 | $file_steps = substr_count(implode('', $lines), '---#'); |
@@ -1689,15 +1790,18 @@ discard block |
||
| 1689 | 1790 | $do_current = $substep >= $_GET['substep']; |
| 1690 | 1791 | |
| 1691 | 1792 | // Get rid of any comments in the beginning of the line... |
| 1692 | - if (substr(trim($line), 0, 2) === '/*') |
|
| 1693 | - $line = preg_replace('~/\*.+?\*/~', '', $line); |
|
| 1793 | + if (substr(trim($line), 0, 2) === '/*') { |
|
| 1794 | + $line = preg_replace('~/\*.+?\*/~', '', $line); |
|
| 1795 | + } |
|
| 1694 | 1796 | |
| 1695 | 1797 | // Always flush. Flush, flush, flush. Flush, flush, flush, flush! FLUSH! |
| 1696 | - if ($is_debug && !$support_js && $command_line) |
|
| 1697 | - flush(); |
|
| 1798 | + if ($is_debug && !$support_js && $command_line) { |
|
| 1799 | + flush(); |
|
| 1800 | + } |
|
| 1698 | 1801 | |
| 1699 | - if (trim($line) === '') |
|
| 1700 | - continue; |
|
| 1802 | + if (trim($line) === '') { |
|
| 1803 | + continue; |
|
| 1804 | + } |
|
| 1701 | 1805 | |
| 1702 | 1806 | if (trim(substr($line, 0, 3)) === '---') |
| 1703 | 1807 | { |
@@ -1707,8 +1811,9 @@ discard block |
||
| 1707 | 1811 | if (trim($current_data) != '' && $type !== '}') |
| 1708 | 1812 | { |
| 1709 | 1813 | $upcontext['error_message'] = 'Error in upgrade script - line ' . $line_number . '!' . $endl; |
| 1710 | - if ($command_line) |
|
| 1711 | - echo $upcontext['error_message']; |
|
| 1814 | + if ($command_line) { |
|
| 1815 | + echo $upcontext['error_message']; |
|
| 1816 | + } |
|
| 1712 | 1817 | } |
| 1713 | 1818 | |
| 1714 | 1819 | if ($type == ' ') |
@@ -1726,17 +1831,18 @@ discard block |
||
| 1726 | 1831 | if ($do_current) |
| 1727 | 1832 | { |
| 1728 | 1833 | $upcontext['actioned_items'][] = $last_step; |
| 1729 | - if ($command_line) |
|
| 1730 | - echo ' * '; |
|
| 1834 | + if ($command_line) { |
|
| 1835 | + echo ' * '; |
|
| 1836 | + } |
|
| 1731 | 1837 | } |
| 1732 | - } |
|
| 1733 | - elseif ($type == '#') |
|
| 1838 | + } elseif ($type == '#') |
|
| 1734 | 1839 | { |
| 1735 | 1840 | $upcontext['step_progress'] += (100 / $upcontext['file_count']) / $file_steps; |
| 1736 | 1841 | |
| 1737 | 1842 | $upcontext['current_debug_item_num']++; |
| 1738 | - if (trim($line) != '---#') |
|
| 1739 | - $upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4))); |
|
| 1843 | + if (trim($line) != '---#') { |
|
| 1844 | + $upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4))); |
|
| 1845 | + } |
|
| 1740 | 1846 | |
| 1741 | 1847 | // Have we already done something? |
| 1742 | 1848 | if (isset($_GET['xml']) && $done_something) |
@@ -1747,34 +1853,36 @@ discard block |
||
| 1747 | 1853 | |
| 1748 | 1854 | if ($do_current) |
| 1749 | 1855 | { |
| 1750 | - if (trim($line) == '---#' && $command_line) |
|
| 1751 | - echo ' done.', $endl; |
|
| 1752 | - elseif ($command_line) |
|
| 1753 | - echo ' +++ ', rtrim(substr($line, 4)); |
|
| 1754 | - elseif (trim($line) != '---#') |
|
| 1856 | + if (trim($line) == '---#' && $command_line) { |
|
| 1857 | + echo ' done.', $endl; |
|
| 1858 | + } elseif ($command_line) { |
|
| 1859 | + echo ' +++ ', rtrim(substr($line, 4)); |
|
| 1860 | + } elseif (trim($line) != '---#') |
|
| 1755 | 1861 | { |
| 1756 | - if ($is_debug) |
|
| 1757 | - $upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4))); |
|
| 1862 | + if ($is_debug) { |
|
| 1863 | + $upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4))); |
|
| 1864 | + } |
|
| 1758 | 1865 | } |
| 1759 | 1866 | } |
| 1760 | 1867 | |
| 1761 | 1868 | if ($substep < $_GET['substep'] && $substep + 1 >= $_GET['substep']) |
| 1762 | 1869 | { |
| 1763 | - if ($command_line) |
|
| 1764 | - echo ' * '; |
|
| 1765 | - else |
|
| 1766 | - $upcontext['actioned_items'][] = $last_step; |
|
| 1870 | + if ($command_line) { |
|
| 1871 | + echo ' * '; |
|
| 1872 | + } else { |
|
| 1873 | + $upcontext['actioned_items'][] = $last_step; |
|
| 1874 | + } |
|
| 1767 | 1875 | } |
| 1768 | 1876 | |
| 1769 | 1877 | // Small step - only if we're actually doing stuff. |
| 1770 | - if ($do_current) |
|
| 1771 | - nextSubstep(++$substep); |
|
| 1772 | - else |
|
| 1773 | - $substep++; |
|
| 1774 | - } |
|
| 1775 | - elseif ($type == '{') |
|
| 1776 | - $current_type = 'code'; |
|
| 1777 | - elseif ($type == '}') |
|
| 1878 | + if ($do_current) { |
|
| 1879 | + nextSubstep(++$substep); |
|
| 1880 | + } else { |
|
| 1881 | + $substep++; |
|
| 1882 | + } |
|
| 1883 | + } elseif ($type == '{') { |
|
| 1884 | + $current_type = 'code'; |
|
| 1885 | + } elseif ($type == '}') |
|
| 1778 | 1886 | { |
| 1779 | 1887 | $current_type = 'sql'; |
| 1780 | 1888 | |
@@ -1787,8 +1895,9 @@ discard block |
||
| 1787 | 1895 | if (eval('global $db_prefix, $modSettings, $smcFunc; ' . $current_data) === false) |
| 1788 | 1896 | { |
| 1789 | 1897 | $upcontext['error_message'] = 'Error in upgrade script ' . basename($filename) . ' on line ' . $line_number . '!' . $endl; |
| 1790 | - if ($command_line) |
|
| 1791 | - echo $upcontext['error_message']; |
|
| 1898 | + if ($command_line) { |
|
| 1899 | + echo $upcontext['error_message']; |
|
| 1900 | + } |
|
| 1792 | 1901 | } |
| 1793 | 1902 | |
| 1794 | 1903 | // Done with code! |
@@ -1868,8 +1977,9 @@ discard block |
||
| 1868 | 1977 | $db_unbuffered = false; |
| 1869 | 1978 | |
| 1870 | 1979 | // Failure?! |
| 1871 | - if ($result !== false) |
|
| 1872 | - return $result; |
|
| 1980 | + if ($result !== false) { |
|
| 1981 | + return $result; |
|
| 1982 | + } |
|
| 1873 | 1983 | |
| 1874 | 1984 | $db_error_message = $smcFunc['db_error']($db_connection); |
| 1875 | 1985 | // If MySQL we do something more clever. |
@@ -1897,54 +2007,61 @@ discard block |
||
| 1897 | 2007 | { |
| 1898 | 2008 | mysqli_query($db_connection, 'REPAIR TABLE `' . $match[1] . '`'); |
| 1899 | 2009 | $result = mysqli_query($db_connection, $string); |
| 1900 | - if ($result !== false) |
|
| 1901 | - return $result; |
|
| 2010 | + if ($result !== false) { |
|
| 2011 | + return $result; |
|
| 2012 | + } |
|
| 1902 | 2013 | } |
| 1903 | - } |
|
| 1904 | - elseif ($mysqli_errno == 2013) |
|
| 2014 | + } elseif ($mysqli_errno == 2013) |
|
| 1905 | 2015 | { |
| 1906 | 2016 | $db_connection = mysqli_connect($db_server, $db_user, $db_passwd); |
| 1907 | 2017 | mysqli_select_db($db_connection, $db_name); |
| 1908 | 2018 | if ($db_connection) |
| 1909 | 2019 | { |
| 1910 | 2020 | $result = mysqli_query($db_connection, $string); |
| 1911 | - if ($result !== false) |
|
| 1912 | - return $result; |
|
| 2021 | + if ($result !== false) { |
|
| 2022 | + return $result; |
|
| 2023 | + } |
|
| 1913 | 2024 | } |
| 1914 | 2025 | } |
| 1915 | 2026 | // Duplicate column name... should be okay ;). |
| 1916 | - elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091))) |
|
| 1917 | - return false; |
|
| 2027 | + elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091))) { |
|
| 2028 | + return false; |
|
| 2029 | + } |
|
| 1918 | 2030 | // Duplicate insert... make sure it's the proper type of query ;). |
| 1919 | - elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query) |
|
| 1920 | - return false; |
|
| 2031 | + elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query) { |
|
| 2032 | + return false; |
|
| 2033 | + } |
|
| 1921 | 2034 | // Creating an index on a non-existent column. |
| 1922 | - elseif ($mysqli_errno == 1072) |
|
| 1923 | - return false; |
|
| 1924 | - elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') |
|
| 1925 | - return false; |
|
| 2035 | + elseif ($mysqli_errno == 1072) { |
|
| 2036 | + return false; |
|
| 2037 | + } elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') { |
|
| 2038 | + return false; |
|
| 2039 | + } |
|
| 1926 | 2040 | } |
| 1927 | 2041 | // If a table already exists don't go potty. |
| 1928 | 2042 | else |
| 1929 | 2043 | { |
| 1930 | 2044 | if (in_array(substr(trim($string), 0, 8), array('CREATE T', 'CREATE S', 'DROP TABL', 'ALTER TA', 'CREATE I', 'CREATE U'))) |
| 1931 | 2045 | { |
| 1932 | - if (strpos($db_error_message, 'exist') !== false) |
|
| 1933 | - return true; |
|
| 1934 | - } |
|
| 1935 | - elseif (strpos(trim($string), 'INSERT ') !== false) |
|
| 2046 | + if (strpos($db_error_message, 'exist') !== false) { |
|
| 2047 | + return true; |
|
| 2048 | + } |
|
| 2049 | + } elseif (strpos(trim($string), 'INSERT ') !== false) |
|
| 1936 | 2050 | { |
| 1937 | - if (strpos($db_error_message, 'duplicate') !== false) |
|
| 1938 | - return true; |
|
| 2051 | + if (strpos($db_error_message, 'duplicate') !== false) { |
|
| 2052 | + return true; |
|
| 2053 | + } |
|
| 1939 | 2054 | } |
| 1940 | 2055 | } |
| 1941 | 2056 | |
| 1942 | 2057 | // Get the query string so we pass everything. |
| 1943 | 2058 | $query_string = ''; |
| 1944 | - foreach ($_GET as $k => $v) |
|
| 1945 | - $query_string .= ';' . $k . '=' . $v; |
|
| 1946 | - if (strlen($query_string) != 0) |
|
| 1947 | - $query_string = '?' . substr($query_string, 1); |
|
| 2059 | + foreach ($_GET as $k => $v) { |
|
| 2060 | + $query_string .= ';' . $k . '=' . $v; |
|
| 2061 | + } |
|
| 2062 | + if (strlen($query_string) != 0) { |
|
| 2063 | + $query_string = '?' . substr($query_string, 1); |
|
| 2064 | + } |
|
| 1948 | 2065 | |
| 1949 | 2066 | if ($command_line) |
| 1950 | 2067 | { |
@@ -1999,16 +2116,18 @@ discard block |
||
| 1999 | 2116 | { |
| 2000 | 2117 | $found |= 1; |
| 2001 | 2118 | // Do some checks on the data if we have it set. |
| 2002 | - if (isset($change['col_type'])) |
|
| 2003 | - $found &= $change['col_type'] === $column['type']; |
|
| 2004 | - if (isset($change['null_allowed'])) |
|
| 2005 | - $found &= $column['null'] == $change['null_allowed']; |
|
| 2006 | - if (isset($change['default'])) |
|
| 2007 | - $found &= $change['default'] === $column['default']; |
|
| 2119 | + if (isset($change['col_type'])) { |
|
| 2120 | + $found &= $change['col_type'] === $column['type']; |
|
| 2121 | + } |
|
| 2122 | + if (isset($change['null_allowed'])) { |
|
| 2123 | + $found &= $column['null'] == $change['null_allowed']; |
|
| 2124 | + } |
|
| 2125 | + if (isset($change['default'])) { |
|
| 2126 | + $found &= $change['default'] === $column['default']; |
|
| 2127 | + } |
|
| 2008 | 2128 | } |
| 2009 | 2129 | } |
| 2010 | - } |
|
| 2011 | - elseif ($change['type'] === 'index') |
|
| 2130 | + } elseif ($change['type'] === 'index') |
|
| 2012 | 2131 | { |
| 2013 | 2132 | $request = upgrade_query(' |
| 2014 | 2133 | SHOW INDEX |
@@ -2017,9 +2136,10 @@ discard block |
||
| 2017 | 2136 | { |
| 2018 | 2137 | $cur_index = array(); |
| 2019 | 2138 | |
| 2020 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 2021 | - if ($row['Key_name'] === $change['name']) |
|
| 2139 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 2140 | + if ($row['Key_name'] === $change['name']) |
|
| 2022 | 2141 | $cur_index[(int) $row['Seq_in_index']] = $row['Column_name']; |
| 2142 | + } |
|
| 2023 | 2143 | |
| 2024 | 2144 | ksort($cur_index, SORT_NUMERIC); |
| 2025 | 2145 | $found = array_values($cur_index) === $change['target_columns']; |
@@ -2029,14 +2149,17 @@ discard block |
||
| 2029 | 2149 | } |
| 2030 | 2150 | |
| 2031 | 2151 | // If we're trying to add and it's added, we're done. |
| 2032 | - if ($found && in_array($change['method'], array('add', 'change'))) |
|
| 2033 | - return true; |
|
| 2152 | + if ($found && in_array($change['method'], array('add', 'change'))) { |
|
| 2153 | + return true; |
|
| 2154 | + } |
|
| 2034 | 2155 | // Otherwise if we're removing and it wasn't found we're also done. |
| 2035 | - elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) |
|
| 2036 | - return true; |
|
| 2156 | + elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) { |
|
| 2157 | + return true; |
|
| 2158 | + } |
|
| 2037 | 2159 | // Otherwise is it just a test? |
| 2038 | - elseif ($is_test) |
|
| 2039 | - return false; |
|
| 2160 | + elseif ($is_test) { |
|
| 2161 | + return false; |
|
| 2162 | + } |
|
| 2040 | 2163 | |
| 2041 | 2164 | // Not found it yet? Bummer! How about we see if we're currently doing it? |
| 2042 | 2165 | $running = false; |
@@ -2047,8 +2170,9 @@ discard block |
||
| 2047 | 2170 | SHOW FULL PROCESSLIST'); |
| 2048 | 2171 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 2049 | 2172 | { |
| 2050 | - if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) |
|
| 2051 | - $found = true; |
|
| 2173 | + if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) { |
|
| 2174 | + $found = true; |
|
| 2175 | + } |
|
| 2052 | 2176 | } |
| 2053 | 2177 | |
| 2054 | 2178 | // Can't find it? Then we need to run it fools! |
@@ -2060,8 +2184,9 @@ discard block |
||
| 2060 | 2184 | ALTER TABLE ' . $db_prefix . $change['table'] . ' |
| 2061 | 2185 | ' . $change['text'], true) !== false; |
| 2062 | 2186 | |
| 2063 | - if (!$success) |
|
| 2064 | - return false; |
|
| 2187 | + if (!$success) { |
|
| 2188 | + return false; |
|
| 2189 | + } |
|
| 2065 | 2190 | |
| 2066 | 2191 | // Return |
| 2067 | 2192 | $running = true; |
@@ -2103,8 +2228,9 @@ discard block |
||
| 2103 | 2228 | 'db_error_skip' => true, |
| 2104 | 2229 | ) |
| 2105 | 2230 | ); |
| 2106 | - if ($smcFunc['db_num_rows']($request) === 0) |
|
| 2107 | - die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']); |
|
| 2231 | + if ($smcFunc['db_num_rows']($request) === 0) { |
|
| 2232 | + die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']); |
|
| 2233 | + } |
|
| 2108 | 2234 | $table_row = $smcFunc['db_fetch_assoc']($request); |
| 2109 | 2235 | $smcFunc['db_free_result']($request); |
| 2110 | 2236 | |
@@ -2126,18 +2252,19 @@ discard block |
||
| 2126 | 2252 | ) |
| 2127 | 2253 | ); |
| 2128 | 2254 | // No results? Just forget it all together. |
| 2129 | - if ($smcFunc['db_num_rows']($request) === 0) |
|
| 2130 | - unset($table_row['Collation']); |
|
| 2131 | - else |
|
| 2132 | - $collation_info = $smcFunc['db_fetch_assoc']($request); |
|
| 2255 | + if ($smcFunc['db_num_rows']($request) === 0) { |
|
| 2256 | + unset($table_row['Collation']); |
|
| 2257 | + } else { |
|
| 2258 | + $collation_info = $smcFunc['db_fetch_assoc']($request); |
|
| 2259 | + } |
|
| 2133 | 2260 | $smcFunc['db_free_result']($request); |
| 2134 | 2261 | } |
| 2135 | 2262 | |
| 2136 | 2263 | if ($column_fix) |
| 2137 | 2264 | { |
| 2138 | 2265 | // Make sure there are no NULL's left. |
| 2139 | - if ($null_fix) |
|
| 2140 | - $smcFunc['db_query']('', ' |
|
| 2266 | + if ($null_fix) { |
|
| 2267 | + $smcFunc['db_query']('', ' |
|
| 2141 | 2268 | UPDATE {db_prefix}' . $change['table'] . ' |
| 2142 | 2269 | SET ' . $change['column'] . ' = {string:default} |
| 2143 | 2270 | WHERE ' . $change['column'] . ' IS NULL', |
@@ -2146,6 +2273,7 @@ discard block |
||
| 2146 | 2273 | 'db_error_skip' => true, |
| 2147 | 2274 | ) |
| 2148 | 2275 | ); |
| 2276 | + } |
|
| 2149 | 2277 | |
| 2150 | 2278 | // Do the actual alteration. |
| 2151 | 2279 | $smcFunc['db_query']('', ' |
@@ -2174,8 +2302,9 @@ discard block |
||
| 2174 | 2302 | } |
| 2175 | 2303 | |
| 2176 | 2304 | // Not a column we need to check on? |
| 2177 | - if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) |
|
| 2178 | - return; |
|
| 2305 | + if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) { |
|
| 2306 | + return; |
|
| 2307 | + } |
|
| 2179 | 2308 | |
| 2180 | 2309 | // Break it up you (six|seven). |
| 2181 | 2310 | $temp = explode(' ', str_replace('NOT NULL', 'NOT_NULL', $change['text'])); |
@@ -2194,13 +2323,13 @@ discard block |
||
| 2194 | 2323 | 'new_name' => $temp[2], |
| 2195 | 2324 | )); |
| 2196 | 2325 | // !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet. |
| 2197 | - if ($smcFunc['db_num_rows'] != 1) |
|
| 2198 | - return; |
|
| 2326 | + if ($smcFunc['db_num_rows'] != 1) { |
|
| 2327 | + return; |
|
| 2328 | + } |
|
| 2199 | 2329 | |
| 2200 | 2330 | list (, $current_type) = $smcFunc['db_fetch_assoc']($request); |
| 2201 | 2331 | $smcFunc['db_free_result']($request); |
| 2202 | - } |
|
| 2203 | - else |
|
| 2332 | + } else |
|
| 2204 | 2333 | { |
| 2205 | 2334 | // Do this the old fashion, sure method way. |
| 2206 | 2335 | $request = $smcFunc['db_query']('', ' |
@@ -2211,21 +2340,24 @@ discard block |
||
| 2211 | 2340 | )); |
| 2212 | 2341 | // Mayday! |
| 2213 | 2342 | // !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet. |
| 2214 | - if ($smcFunc['db_num_rows'] == 0) |
|
| 2215 | - return; |
|
| 2343 | + if ($smcFunc['db_num_rows'] == 0) { |
|
| 2344 | + return; |
|
| 2345 | + } |
|
| 2216 | 2346 | |
| 2217 | 2347 | // Oh where, oh where has my little field gone. Oh where can it be... |
| 2218 | - while ($row = $smcFunc['db_query']($request)) |
|
| 2219 | - if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2]) |
|
| 2348 | + while ($row = $smcFunc['db_query']($request)) { |
|
| 2349 | + if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2]) |
|
| 2220 | 2350 | { |
| 2221 | 2351 | $current_type = $row['Type']; |
| 2352 | + } |
|
| 2222 | 2353 | break; |
| 2223 | 2354 | } |
| 2224 | 2355 | } |
| 2225 | 2356 | |
| 2226 | 2357 | // If this doesn't match, the column may of been altered for a reason. |
| 2227 | - if (trim($current_type) != trim($temp[3])) |
|
| 2228 | - $temp[3] = $current_type; |
|
| 2358 | + if (trim($current_type) != trim($temp[3])) { |
|
| 2359 | + $temp[3] = $current_type; |
|
| 2360 | + } |
|
| 2229 | 2361 | |
| 2230 | 2362 | // Piece this back together. |
| 2231 | 2363 | $change['text'] = str_replace('NOT_NULL', 'NOT NULL', implode(' ', $temp)); |
@@ -2237,8 +2369,9 @@ discard block |
||
| 2237 | 2369 | global $start_time, $timeLimitThreshold, $command_line, $custom_warning; |
| 2238 | 2370 | global $step_progress, $is_debug, $upcontext; |
| 2239 | 2371 | |
| 2240 | - if ($_GET['substep'] < $substep) |
|
| 2241 | - $_GET['substep'] = $substep; |
|
| 2372 | + if ($_GET['substep'] < $substep) { |
|
| 2373 | + $_GET['substep'] = $substep; |
|
| 2374 | + } |
|
| 2242 | 2375 | |
| 2243 | 2376 | if ($command_line) |
| 2244 | 2377 | { |
@@ -2251,29 +2384,33 @@ discard block |
||
| 2251 | 2384 | } |
| 2252 | 2385 | |
| 2253 | 2386 | @set_time_limit(300); |
| 2254 | - if (function_exists('apache_reset_timeout')) |
|
| 2255 | - @apache_reset_timeout(); |
|
| 2387 | + if (function_exists('apache_reset_timeout')) { |
|
| 2388 | + @apache_reset_timeout(); |
|
| 2389 | + } |
|
| 2256 | 2390 | |
| 2257 | - if (time() - $start_time <= $timeLimitThreshold) |
|
| 2258 | - return; |
|
| 2391 | + if (time() - $start_time <= $timeLimitThreshold) { |
|
| 2392 | + return; |
|
| 2393 | + } |
|
| 2259 | 2394 | |
| 2260 | 2395 | // Do we have some custom step progress stuff? |
| 2261 | 2396 | if (!empty($step_progress)) |
| 2262 | 2397 | { |
| 2263 | 2398 | $upcontext['substep_progress'] = 0; |
| 2264 | 2399 | $upcontext['substep_progress_name'] = $step_progress['name']; |
| 2265 | - if ($step_progress['current'] > $step_progress['total']) |
|
| 2266 | - $upcontext['substep_progress'] = 99.9; |
|
| 2267 | - else |
|
| 2268 | - $upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100; |
|
| 2400 | + if ($step_progress['current'] > $step_progress['total']) { |
|
| 2401 | + $upcontext['substep_progress'] = 99.9; |
|
| 2402 | + } else { |
|
| 2403 | + $upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100; |
|
| 2404 | + } |
|
| 2269 | 2405 | |
| 2270 | 2406 | // Make it nicely rounded. |
| 2271 | 2407 | $upcontext['substep_progress'] = round($upcontext['substep_progress'], 1); |
| 2272 | 2408 | } |
| 2273 | 2409 | |
| 2274 | 2410 | // If this is XML we just exit right away! |
| 2275 | - if (isset($_GET['xml'])) |
|
| 2276 | - return upgradeExit(); |
|
| 2411 | + if (isset($_GET['xml'])) { |
|
| 2412 | + return upgradeExit(); |
|
| 2413 | + } |
|
| 2277 | 2414 | |
| 2278 | 2415 | // We're going to pause after this! |
| 2279 | 2416 | $upcontext['pause'] = true; |
@@ -2281,13 +2418,15 @@ discard block |
||
| 2281 | 2418 | $upcontext['query_string'] = ''; |
| 2282 | 2419 | foreach ($_GET as $k => $v) |
| 2283 | 2420 | { |
| 2284 | - if ($k != 'data' && $k != 'substep' && $k != 'step') |
|
| 2285 | - $upcontext['query_string'] .= ';' . $k . '=' . $v; |
|
| 2421 | + if ($k != 'data' && $k != 'substep' && $k != 'step') { |
|
| 2422 | + $upcontext['query_string'] .= ';' . $k . '=' . $v; |
|
| 2423 | + } |
|
| 2286 | 2424 | } |
| 2287 | 2425 | |
| 2288 | 2426 | // Custom warning? |
| 2289 | - if (!empty($custom_warning)) |
|
| 2290 | - $upcontext['custom_warning'] = $custom_warning; |
|
| 2427 | + if (!empty($custom_warning)) { |
|
| 2428 | + $upcontext['custom_warning'] = $custom_warning; |
|
| 2429 | + } |
|
| 2291 | 2430 | |
| 2292 | 2431 | upgradeExit(); |
| 2293 | 2432 | } |
@@ -2302,25 +2441,26 @@ discard block |
||
| 2302 | 2441 | ob_implicit_flush(true); |
| 2303 | 2442 | @set_time_limit(600); |
| 2304 | 2443 | |
| 2305 | - if (!isset($_SERVER['argv'])) |
|
| 2306 | - $_SERVER['argv'] = array(); |
|
| 2444 | + if (!isset($_SERVER['argv'])) { |
|
| 2445 | + $_SERVER['argv'] = array(); |
|
| 2446 | + } |
|
| 2307 | 2447 | $_GET['maint'] = 1; |
| 2308 | 2448 | |
| 2309 | 2449 | foreach ($_SERVER['argv'] as $i => $arg) |
| 2310 | 2450 | { |
| 2311 | - if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) |
|
| 2312 | - $_GET['lang'] = $match[1]; |
|
| 2313 | - elseif (preg_match('~^--path=(.+)$~', $arg) != 0) |
|
| 2314 | - continue; |
|
| 2315 | - elseif ($arg == '--no-maintenance') |
|
| 2316 | - $_GET['maint'] = 0; |
|
| 2317 | - elseif ($arg == '--debug') |
|
| 2318 | - $is_debug = true; |
|
| 2319 | - elseif ($arg == '--backup') |
|
| 2320 | - $_POST['backup'] = 1; |
|
| 2321 | - elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) |
|
| 2322 | - $_GET['conv'] = 1; |
|
| 2323 | - elseif ($i != 0) |
|
| 2451 | + if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) { |
|
| 2452 | + $_GET['lang'] = $match[1]; |
|
| 2453 | + } elseif (preg_match('~^--path=(.+)$~', $arg) != 0) { |
|
| 2454 | + continue; |
|
| 2455 | + } elseif ($arg == '--no-maintenance') { |
|
| 2456 | + $_GET['maint'] = 0; |
|
| 2457 | + } elseif ($arg == '--debug') { |
|
| 2458 | + $is_debug = true; |
|
| 2459 | + } elseif ($arg == '--backup') { |
|
| 2460 | + $_POST['backup'] = 1; |
|
| 2461 | + } elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) { |
|
| 2462 | + $_GET['conv'] = 1; |
|
| 2463 | + } elseif ($i != 0) |
|
| 2324 | 2464 | { |
| 2325 | 2465 | echo 'SMF Command-line Upgrader |
| 2326 | 2466 | Usage: /path/to/php -f ' . basename(__FILE__) . ' -- [OPTION]... |
@@ -2334,10 +2474,12 @@ discard block |
||
| 2334 | 2474 | } |
| 2335 | 2475 | } |
| 2336 | 2476 | |
| 2337 | - if (!php_version_check()) |
|
| 2338 | - print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true); |
|
| 2339 | - if (!db_version_check()) |
|
| 2340 | - print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true); |
|
| 2477 | + if (!php_version_check()) { |
|
| 2478 | + print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true); |
|
| 2479 | + } |
|
| 2480 | + if (!db_version_check()) { |
|
| 2481 | + print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true); |
|
| 2482 | + } |
|
| 2341 | 2483 | |
| 2342 | 2484 | // Do some checks to make sure they have proper privileges |
| 2343 | 2485 | db_extend('packages'); |
@@ -2352,34 +2494,39 @@ discard block |
||
| 2352 | 2494 | $drop = $smcFunc['db_drop_table']('{db_prefix}priv_check'); |
| 2353 | 2495 | |
| 2354 | 2496 | // Sorry... we need CREATE, ALTER and DROP |
| 2355 | - if (!$create || !$alter || !$drop) |
|
| 2356 | - print_error("The " . $databases[$db_type]['name'] . " user you have set in Settings.php does not have proper privileges.\n\nPlease ask your host to give this user the ALTER, CREATE, and DROP privileges.", true); |
|
| 2497 | + if (!$create || !$alter || !$drop) { |
|
| 2498 | + print_error("The " . $databases[$db_type]['name'] . " user you have set in Settings.php does not have proper privileges.\n\nPlease ask your host to give this user the ALTER, CREATE, and DROP privileges.", true); |
|
| 2499 | + } |
|
| 2357 | 2500 | |
| 2358 | 2501 | $check = @file_exists($modSettings['theme_dir'] . '/index.template.php') |
| 2359 | 2502 | && @file_exists($sourcedir . '/QueryString.php') |
| 2360 | 2503 | && @file_exists($sourcedir . '/ManageBoards.php'); |
| 2361 | - if (!$check && !isset($modSettings['smfVersion'])) |
|
| 2362 | - print_error('Error: Some files are missing or out-of-date.', true); |
|
| 2504 | + if (!$check && !isset($modSettings['smfVersion'])) { |
|
| 2505 | + print_error('Error: Some files are missing or out-of-date.', true); |
|
| 2506 | + } |
|
| 2363 | 2507 | |
| 2364 | 2508 | // Do a quick version spot check. |
| 2365 | 2509 | $temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096); |
| 2366 | 2510 | preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match); |
| 2367 | - if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) |
|
| 2368 | - print_error('Error: Some files have not yet been updated properly.'); |
|
| 2511 | + if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) { |
|
| 2512 | + print_error('Error: Some files have not yet been updated properly.'); |
|
| 2513 | + } |
|
| 2369 | 2514 | |
| 2370 | 2515 | // Make sure Settings.php is writable. |
| 2371 | 2516 | quickFileWritable($boarddir . '/Settings.php'); |
| 2372 | - if (!is_writable($boarddir . '/Settings.php')) |
|
| 2373 | - print_error('Error: Unable to obtain write access to "Settings.php".', true); |
|
| 2517 | + if (!is_writable($boarddir . '/Settings.php')) { |
|
| 2518 | + print_error('Error: Unable to obtain write access to "Settings.php".', true); |
|
| 2519 | + } |
|
| 2374 | 2520 | |
| 2375 | 2521 | // Make sure Settings_bak.php is writable. |
| 2376 | 2522 | quickFileWritable($boarddir . '/Settings_bak.php'); |
| 2377 | - if (!is_writable($boarddir . '/Settings_bak.php')) |
|
| 2378 | - print_error('Error: Unable to obtain write access to "Settings_bak.php".'); |
|
| 2523 | + if (!is_writable($boarddir . '/Settings_bak.php')) { |
|
| 2524 | + print_error('Error: Unable to obtain write access to "Settings_bak.php".'); |
|
| 2525 | + } |
|
| 2379 | 2526 | |
| 2380 | - if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) |
|
| 2381 | - print_error('Error: Unable to obtain write access to "agreement.txt".'); |
|
| 2382 | - elseif (isset($modSettings['agreement'])) |
|
| 2527 | + if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) { |
|
| 2528 | + print_error('Error: Unable to obtain write access to "agreement.txt".'); |
|
| 2529 | + } elseif (isset($modSettings['agreement'])) |
|
| 2383 | 2530 | { |
| 2384 | 2531 | $fp = fopen($boarddir . '/agreement.txt', 'w'); |
| 2385 | 2532 | fwrite($fp, $modSettings['agreement']); |
@@ -2389,31 +2536,36 @@ discard block |
||
| 2389 | 2536 | // Make sure Themes is writable. |
| 2390 | 2537 | quickFileWritable($modSettings['theme_dir']); |
| 2391 | 2538 | |
| 2392 | - if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) |
|
| 2393 | - print_error('Error: Unable to obtain write access to "Themes".'); |
|
| 2539 | + if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) { |
|
| 2540 | + print_error('Error: Unable to obtain write access to "Themes".'); |
|
| 2541 | + } |
|
| 2394 | 2542 | |
| 2395 | 2543 | // Make sure cache directory exists and is writable! |
| 2396 | 2544 | $cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir; |
| 2397 | - if (!file_exists($cachedir_temp)) |
|
| 2398 | - @mkdir($cachedir_temp); |
|
| 2545 | + if (!file_exists($cachedir_temp)) { |
|
| 2546 | + @mkdir($cachedir_temp); |
|
| 2547 | + } |
|
| 2399 | 2548 | |
| 2400 | 2549 | // Make sure the cache temp dir is writable. |
| 2401 | 2550 | quickFileWritable($cachedir_temp); |
| 2402 | 2551 | |
| 2403 | - if (!is_writable($cachedir_temp)) |
|
| 2404 | - print_error('Error: Unable to obtain write access to "cache".', true); |
|
| 2552 | + if (!is_writable($cachedir_temp)) { |
|
| 2553 | + print_error('Error: Unable to obtain write access to "cache".', true); |
|
| 2554 | + } |
|
| 2405 | 2555 | |
| 2406 | - if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) |
|
| 2407 | - print_error('Error: Unable to find language files!', true); |
|
| 2408 | - else |
|
| 2556 | + if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) { |
|
| 2557 | + print_error('Error: Unable to find language files!', true); |
|
| 2558 | + } else |
|
| 2409 | 2559 | { |
| 2410 | 2560 | $temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096); |
| 2411 | 2561 | preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match); |
| 2412 | 2562 | |
| 2413 | - if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) |
|
| 2414 | - print_error('Error: Language files out of date.', true); |
|
| 2415 | - if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) |
|
| 2416 | - print_error('Error: Install language is missing for selected language.', true); |
|
| 2563 | + if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) { |
|
| 2564 | + print_error('Error: Language files out of date.', true); |
|
| 2565 | + } |
|
| 2566 | + if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) { |
|
| 2567 | + print_error('Error: Install language is missing for selected language.', true); |
|
| 2568 | + } |
|
| 2417 | 2569 | |
| 2418 | 2570 | // Otherwise include it! |
| 2419 | 2571 | require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'); |
@@ -2432,8 +2584,9 @@ discard block |
||
| 2432 | 2584 | global $upcontext, $db_character_set, $sourcedir, $smcFunc, $modSettings, $language, $db_prefix, $db_type, $command_line, $support_js; |
| 2433 | 2585 | |
| 2434 | 2586 | // Done it already? |
| 2435 | - if (!empty($_POST['utf8_done'])) |
|
| 2436 | - return true; |
|
| 2587 | + if (!empty($_POST['utf8_done'])) { |
|
| 2588 | + return true; |
|
| 2589 | + } |
|
| 2437 | 2590 | |
| 2438 | 2591 | // First make sure they aren't already on UTF-8 before we go anywhere... |
| 2439 | 2592 | if ($db_type == 'postgresql' || ($db_character_set === 'utf8' && !empty($modSettings['global_character_set']) && $modSettings['global_character_set'] === 'UTF-8')) |
@@ -2446,8 +2599,7 @@ discard block |
||
| 2446 | 2599 | ); |
| 2447 | 2600 | |
| 2448 | 2601 | return true; |
| 2449 | - } |
|
| 2450 | - else |
|
| 2602 | + } else |
|
| 2451 | 2603 | { |
| 2452 | 2604 | $upcontext['page_title'] = 'Converting to UTF8'; |
| 2453 | 2605 | $upcontext['sub_template'] = isset($_GET['xml']) ? 'convert_xml' : 'convert_utf8'; |
@@ -2491,8 +2643,9 @@ discard block |
||
| 2491 | 2643 | ) |
| 2492 | 2644 | ); |
| 2493 | 2645 | $db_charsets = array(); |
| 2494 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 2495 | - $db_charsets[] = $row['Charset']; |
|
| 2646 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 2647 | + $db_charsets[] = $row['Charset']; |
|
| 2648 | + } |
|
| 2496 | 2649 | |
| 2497 | 2650 | $smcFunc['db_free_result']($request); |
| 2498 | 2651 | |
@@ -2528,13 +2681,15 @@ discard block |
||
| 2528 | 2681 | // If there's a fulltext index, we need to drop it first... |
| 2529 | 2682 | if ($request !== false || $smcFunc['db_num_rows']($request) != 0) |
| 2530 | 2683 | { |
| 2531 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 2532 | - if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT')) |
|
| 2684 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 2685 | + if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT')) |
|
| 2533 | 2686 | $upcontext['fulltext_index'][] = $row['Key_name']; |
| 2687 | + } |
|
| 2534 | 2688 | $smcFunc['db_free_result']($request); |
| 2535 | 2689 | |
| 2536 | - if (isset($upcontext['fulltext_index'])) |
|
| 2537 | - $upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']); |
|
| 2690 | + if (isset($upcontext['fulltext_index'])) { |
|
| 2691 | + $upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']); |
|
| 2692 | + } |
|
| 2538 | 2693 | } |
| 2539 | 2694 | |
| 2540 | 2695 | // Drop it and make a note... |
@@ -2724,8 +2879,9 @@ discard block |
||
| 2724 | 2879 | $replace = '%field%'; |
| 2725 | 2880 | |
| 2726 | 2881 | // Build a huge REPLACE statement... |
| 2727 | - foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) |
|
| 2728 | - $replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')'; |
|
| 2882 | + foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) { |
|
| 2883 | + $replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')'; |
|
| 2884 | + } |
|
| 2729 | 2885 | } |
| 2730 | 2886 | |
| 2731 | 2887 | // Get a list of table names ahead of time... This makes it easier to set our substep and such |
@@ -2735,9 +2891,10 @@ discard block |
||
| 2735 | 2891 | $upcontext['table_count'] = count($queryTables); |
| 2736 | 2892 | |
| 2737 | 2893 | // What ones have we already done? |
| 2738 | - foreach ($queryTables as $id => $table) |
|
| 2739 | - if ($id < $_GET['substep']) |
|
| 2894 | + foreach ($queryTables as $id => $table) { |
|
| 2895 | + if ($id < $_GET['substep']) |
|
| 2740 | 2896 | $upcontext['previous_tables'][] = $table; |
| 2897 | + } |
|
| 2741 | 2898 | |
| 2742 | 2899 | $upcontext['cur_table_num'] = $_GET['substep']; |
| 2743 | 2900 | $upcontext['cur_table_name'] = str_replace($db_prefix, '', $queryTables[$_GET['substep']]); |
@@ -2774,8 +2931,9 @@ discard block |
||
| 2774 | 2931 | nextSubstep($substep); |
| 2775 | 2932 | |
| 2776 | 2933 | // Just to make sure it doesn't time out. |
| 2777 | - if (function_exists('apache_reset_timeout')) |
|
| 2778 | - @apache_reset_timeout(); |
|
| 2934 | + if (function_exists('apache_reset_timeout')) { |
|
| 2935 | + @apache_reset_timeout(); |
|
| 2936 | + } |
|
| 2779 | 2937 | |
| 2780 | 2938 | $table_charsets = array(); |
| 2781 | 2939 | |
@@ -2796,8 +2954,9 @@ discard block |
||
| 2796 | 2954 | { |
| 2797 | 2955 | list($charset) = explode('_', $collation); |
| 2798 | 2956 | |
| 2799 | - if (!isset($table_charsets[$charset])) |
|
| 2800 | - $table_charsets[$charset] = array(); |
|
| 2957 | + if (!isset($table_charsets[$charset])) { |
|
| 2958 | + $table_charsets[$charset] = array(); |
|
| 2959 | + } |
|
| 2801 | 2960 | |
| 2802 | 2961 | $table_charsets[$charset][] = $column_info; |
| 2803 | 2962 | } |
@@ -2837,10 +2996,11 @@ discard block |
||
| 2837 | 2996 | if (isset($translation_tables[$upcontext['charset_detected']])) |
| 2838 | 2997 | { |
| 2839 | 2998 | $update = ''; |
| 2840 | - foreach ($table_charsets as $charset => $columns) |
|
| 2841 | - foreach ($columns as $column) |
|
| 2999 | + foreach ($table_charsets as $charset => $columns) { |
|
| 3000 | + foreach ($columns as $column) |
|
| 2842 | 3001 | $update .= ' |
| 2843 | 3002 | ' . $column['Field'] . ' = ' . strtr($replace, array('%field%' => $column['Field'])) . ','; |
| 3003 | + } |
|
| 2844 | 3004 | |
| 2845 | 3005 | $smcFunc['db_query']('', ' |
| 2846 | 3006 | UPDATE {raw:table_name} |
@@ -2865,8 +3025,9 @@ discard block |
||
| 2865 | 3025 | // Now do the actual conversion (if still needed). |
| 2866 | 3026 | if ($charsets[$upcontext['charset_detected']] !== 'utf8') |
| 2867 | 3027 | { |
| 2868 | - if ($command_line) |
|
| 2869 | - echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...'; |
|
| 3028 | + if ($command_line) { |
|
| 3029 | + echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...'; |
|
| 3030 | + } |
|
| 2870 | 3031 | |
| 2871 | 3032 | $smcFunc['db_query']('', ' |
| 2872 | 3033 | ALTER TABLE {raw:table_name} |
@@ -2876,12 +3037,14 @@ discard block |
||
| 2876 | 3037 | ) |
| 2877 | 3038 | ); |
| 2878 | 3039 | |
| 2879 | - if ($command_line) |
|
| 2880 | - echo " done.\n"; |
|
| 3040 | + if ($command_line) { |
|
| 3041 | + echo " done.\n"; |
|
| 3042 | + } |
|
| 2881 | 3043 | } |
| 2882 | 3044 | // If this is XML to keep it nice for the user do one table at a time anyway! |
| 2883 | - if (isset($_GET['xml'])) |
|
| 2884 | - return upgradeExit(); |
|
| 3045 | + if (isset($_GET['xml'])) { |
|
| 3046 | + return upgradeExit(); |
|
| 3047 | + } |
|
| 2885 | 3048 | } |
| 2886 | 3049 | |
| 2887 | 3050 | $prev_charset = empty($translation_tables[$upcontext['charset_detected']]) ? $charsets[$upcontext['charset_detected']] : $translation_tables[$upcontext['charset_detected']]; |
@@ -2910,8 +3073,8 @@ discard block |
||
| 2910 | 3073 | ); |
| 2911 | 3074 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 2912 | 3075 | { |
| 2913 | - if (@safe_unserialize($row['extra']) === false && preg_match('~^(a:3:{s:5:"topic";i:\d+;s:7:"subject";s:)(\d+):"(.+)"(;s:6:"member";s:5:"\d+";})$~', $row['extra'], $matches) === 1) |
|
| 2914 | - $smcFunc['db_query']('', ' |
|
| 3076 | + if (@safe_unserialize($row['extra']) === false && preg_match('~^(a:3:{s:5:"topic";i:\d+;s:7:"subject";s:)(\d+):"(.+)"(;s:6:"member";s:5:"\d+";})$~', $row['extra'], $matches) === 1) { |
|
| 3077 | + $smcFunc['db_query']('', ' |
|
| 2915 | 3078 | UPDATE {db_prefix}log_actions |
| 2916 | 3079 | SET extra = {string:extra} |
| 2917 | 3080 | WHERE id_action = {int:current_action}', |
@@ -2920,6 +3083,7 @@ discard block |
||
| 2920 | 3083 | 'extra' => $matches[1] . strlen($matches[3]) . ':"' . $matches[3] . '"' . $matches[4], |
| 2921 | 3084 | ) |
| 2922 | 3085 | ); |
| 3086 | + } |
|
| 2923 | 3087 | } |
| 2924 | 3088 | $smcFunc['db_free_result']($request); |
| 2925 | 3089 | |
@@ -2941,15 +3105,17 @@ discard block |
||
| 2941 | 3105 | // First thing's first - did we already do this? |
| 2942 | 3106 | if (!empty($modSettings['json_done'])) |
| 2943 | 3107 | { |
| 2944 | - if ($command_line) |
|
| 2945 | - return DeleteUpgrade(); |
|
| 2946 | - else |
|
| 2947 | - return true; |
|
| 3108 | + if ($command_line) { |
|
| 3109 | + return DeleteUpgrade(); |
|
| 3110 | + } else { |
|
| 3111 | + return true; |
|
| 3112 | + } |
|
| 2948 | 3113 | } |
| 2949 | 3114 | |
| 2950 | 3115 | // Done it already - js wise? |
| 2951 | - if (!empty($_POST['json_done'])) |
|
| 2952 | - return true; |
|
| 3116 | + if (!empty($_POST['json_done'])) { |
|
| 3117 | + return true; |
|
| 3118 | + } |
|
| 2953 | 3119 | |
| 2954 | 3120 | // List of tables affected by this function |
| 2955 | 3121 | // name => array('key', col1[,col2|true[,col3]]) |
@@ -2981,12 +3147,14 @@ discard block |
||
| 2981 | 3147 | $upcontext['cur_table_name'] = isset($keys[$_GET['substep']]) ? $keys[$_GET['substep']] : $keys[0]; |
| 2982 | 3148 | $upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100); |
| 2983 | 3149 | |
| 2984 | - foreach ($keys as $id => $table) |
|
| 2985 | - if ($id < $_GET['substep']) |
|
| 3150 | + foreach ($keys as $id => $table) { |
|
| 3151 | + if ($id < $_GET['substep']) |
|
| 2986 | 3152 | $upcontext['previous_tables'][] = $table; |
| 3153 | + } |
|
| 2987 | 3154 | |
| 2988 | - if ($command_line) |
|
| 2989 | - echo 'Converting data from serialize() to json_encode().'; |
|
| 3155 | + if ($command_line) { |
|
| 3156 | + echo 'Converting data from serialize() to json_encode().'; |
|
| 3157 | + } |
|
| 2990 | 3158 | |
| 2991 | 3159 | if (!$support_js || isset($_GET['xml'])) |
| 2992 | 3160 | { |
@@ -3026,8 +3194,9 @@ discard block |
||
| 3026 | 3194 | |
| 3027 | 3195 | // Loop through and fix these... |
| 3028 | 3196 | $new_settings = array(); |
| 3029 | - if ($command_line) |
|
| 3030 | - echo "\n" . 'Fixing some settings...'; |
|
| 3197 | + if ($command_line) { |
|
| 3198 | + echo "\n" . 'Fixing some settings...'; |
|
| 3199 | + } |
|
| 3031 | 3200 | |
| 3032 | 3201 | foreach ($serialized_settings as $var) |
| 3033 | 3202 | { |
@@ -3035,22 +3204,24 @@ discard block |
||
| 3035 | 3204 | { |
| 3036 | 3205 | // Attempt to unserialize the setting |
| 3037 | 3206 | $temp = @safe_unserialize($modSettings[$var]); |
| 3038 | - if (!$temp && $command_line) |
|
| 3039 | - echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping."; |
|
| 3040 | - elseif ($temp !== false) |
|
| 3041 | - $new_settings[$var] = json_encode($temp); |
|
| 3207 | + if (!$temp && $command_line) { |
|
| 3208 | + echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping."; |
|
| 3209 | + } elseif ($temp !== false) { |
|
| 3210 | + $new_settings[$var] = json_encode($temp); |
|
| 3211 | + } |
|
| 3042 | 3212 | } |
| 3043 | 3213 | } |
| 3044 | 3214 | |
| 3045 | 3215 | // Update everything at once |
| 3046 | - if (!function_exists('cache_put_data')) |
|
| 3047 | - require_once($sourcedir . '/Load.php'); |
|
| 3216 | + if (!function_exists('cache_put_data')) { |
|
| 3217 | + require_once($sourcedir . '/Load.php'); |
|
| 3218 | + } |
|
| 3048 | 3219 | updateSettings($new_settings, true); |
| 3049 | 3220 | |
| 3050 | - if ($command_line) |
|
| 3051 | - echo ' done.'; |
|
| 3052 | - } |
|
| 3053 | - elseif ($table == 'themes') |
|
| 3221 | + if ($command_line) { |
|
| 3222 | + echo ' done.'; |
|
| 3223 | + } |
|
| 3224 | + } elseif ($table == 'themes') |
|
| 3054 | 3225 | { |
| 3055 | 3226 | // Finally, fix the admin prefs. Unfortunately this is stored per theme, but hopefully they only have one theme installed at this point... |
| 3056 | 3227 | $query = $smcFunc['db_query']('', ' |
@@ -3069,10 +3240,11 @@ discard block |
||
| 3069 | 3240 | |
| 3070 | 3241 | if ($command_line) |
| 3071 | 3242 | { |
| 3072 | - if ($temp === false) |
|
| 3073 | - echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.'; |
|
| 3074 | - else |
|
| 3075 | - echo "\n" . 'Fixing admin preferences...'; |
|
| 3243 | + if ($temp === false) { |
|
| 3244 | + echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.'; |
|
| 3245 | + } else { |
|
| 3246 | + echo "\n" . 'Fixing admin preferences...'; |
|
| 3247 | + } |
|
| 3076 | 3248 | } |
| 3077 | 3249 | |
| 3078 | 3250 | if ($temp !== false) |
@@ -3094,15 +3266,15 @@ discard block |
||
| 3094 | 3266 | ) |
| 3095 | 3267 | ); |
| 3096 | 3268 | |
| 3097 | - if ($command_line) |
|
| 3098 | - echo ' done.'; |
|
| 3269 | + if ($command_line) { |
|
| 3270 | + echo ' done.'; |
|
| 3271 | + } |
|
| 3099 | 3272 | } |
| 3100 | 3273 | } |
| 3101 | 3274 | |
| 3102 | 3275 | $smcFunc['db_free_result']($query); |
| 3103 | 3276 | } |
| 3104 | - } |
|
| 3105 | - else |
|
| 3277 | + } else |
|
| 3106 | 3278 | { |
| 3107 | 3279 | // First item is always the key... |
| 3108 | 3280 | $key = $info[0]; |
@@ -3113,8 +3285,7 @@ discard block |
||
| 3113 | 3285 | { |
| 3114 | 3286 | $col_select = $info[1]; |
| 3115 | 3287 | $where = ' WHERE ' . $info[1] . ' != {empty}'; |
| 3116 | - } |
|
| 3117 | - else |
|
| 3288 | + } else |
|
| 3118 | 3289 | { |
| 3119 | 3290 | $col_select = implode(', ', $info); |
| 3120 | 3291 | } |
@@ -3147,8 +3318,7 @@ discard block |
||
| 3147 | 3318 | if ($temp === false && $command_line) |
| 3148 | 3319 | { |
| 3149 | 3320 | echo "\nFailed to unserialize " . $row[$col] . "... Skipping\n"; |
| 3150 | - } |
|
| 3151 | - else |
|
| 3321 | + } else |
|
| 3152 | 3322 | { |
| 3153 | 3323 | $row[$col] = json_encode($temp); |
| 3154 | 3324 | |
@@ -3173,16 +3343,18 @@ discard block |
||
| 3173 | 3343 | } |
| 3174 | 3344 | } |
| 3175 | 3345 | |
| 3176 | - if ($command_line) |
|
| 3177 | - echo ' done.'; |
|
| 3346 | + if ($command_line) { |
|
| 3347 | + echo ' done.'; |
|
| 3348 | + } |
|
| 3178 | 3349 | |
| 3179 | 3350 | // Free up some memory... |
| 3180 | 3351 | $smcFunc['db_free_result']($query); |
| 3181 | 3352 | } |
| 3182 | 3353 | } |
| 3183 | 3354 | // If this is XML to keep it nice for the user do one table at a time anyway! |
| 3184 | - if (isset($_GET['xml'])) |
|
| 3185 | - return upgradeExit(); |
|
| 3355 | + if (isset($_GET['xml'])) { |
|
| 3356 | + return upgradeExit(); |
|
| 3357 | + } |
|
| 3186 | 3358 | } |
| 3187 | 3359 | |
| 3188 | 3360 | if ($command_line) |
@@ -3197,8 +3369,9 @@ discard block |
||
| 3197 | 3369 | |
| 3198 | 3370 | $_GET['substep'] = 0; |
| 3199 | 3371 | // Make sure we move on! |
| 3200 | - if ($command_line) |
|
| 3201 | - return DeleteUpgrade(); |
|
| 3372 | + if ($command_line) { |
|
| 3373 | + return DeleteUpgrade(); |
|
| 3374 | + } |
|
| 3202 | 3375 | |
| 3203 | 3376 | return true; |
| 3204 | 3377 | } |
@@ -3218,14 +3391,16 @@ discard block |
||
| 3218 | 3391 | global $upcontext, $txt, $settings; |
| 3219 | 3392 | |
| 3220 | 3393 | // Don't call me twice! |
| 3221 | - if (!empty($upcontext['chmod_called'])) |
|
| 3222 | - return; |
|
| 3394 | + if (!empty($upcontext['chmod_called'])) { |
|
| 3395 | + return; |
|
| 3396 | + } |
|
| 3223 | 3397 | |
| 3224 | 3398 | $upcontext['chmod_called'] = true; |
| 3225 | 3399 | |
| 3226 | 3400 | // Nothing? |
| 3227 | - if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) |
|
| 3228 | - return; |
|
| 3401 | + if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) { |
|
| 3402 | + return; |
|
| 3403 | + } |
|
| 3229 | 3404 | |
| 3230 | 3405 | // Was it a problem with Windows? |
| 3231 | 3406 | if (!empty($upcontext['chmod']['ftp_error']) && $upcontext['chmod']['ftp_error'] == 'total_mess') |
@@ -3257,11 +3432,12 @@ discard block |
||
| 3257 | 3432 | content.write(\'<div class="windowbg description">\n\t\t\t<h4>The following files needs to be made writable to continue:</h4>\n\t\t\t\'); |
| 3258 | 3433 | content.write(\'<p>', implode('<br>\n\t\t\t', $upcontext['chmod']['files']), '</p>\n\t\t\t\');'; |
| 3259 | 3434 | |
| 3260 | - if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') |
|
| 3261 | - echo ' |
|
| 3435 | + if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') { |
|
| 3436 | + echo ' |
|
| 3262 | 3437 | content.write(\'<hr>\n\t\t\t\'); |
| 3263 | 3438 | content.write(\'<p>If you have a shell account, the convenient below command can automatically correct permissions on these files</p>\n\t\t\t\'); |
| 3264 | 3439 | content.write(\'<tt># chmod a+w ', implode(' ', $upcontext['chmod']['files']), '</tt>\n\t\t\t\');'; |
| 3440 | + } |
|
| 3265 | 3441 | |
| 3266 | 3442 | echo ' |
| 3267 | 3443 | content.write(\'<a href="javascript:self.close();">close</a>\n\t\t</div>\n\t</body>\n</html>\'); |
@@ -3269,17 +3445,19 @@ discard block |
||
| 3269 | 3445 | } |
| 3270 | 3446 | </script>'; |
| 3271 | 3447 | |
| 3272 | - if (!empty($upcontext['chmod']['ftp_error'])) |
|
| 3273 | - echo ' |
|
| 3448 | + if (!empty($upcontext['chmod']['ftp_error'])) { |
|
| 3449 | + echo ' |
|
| 3274 | 3450 | <div class="error_message red"> |
| 3275 | 3451 | The following error was encountered when trying to connect:<br><br> |
| 3276 | 3452 | <code>', $upcontext['chmod']['ftp_error'], '</code> |
| 3277 | 3453 | </div> |
| 3278 | 3454 | <br>'; |
| 3455 | + } |
|
| 3279 | 3456 | |
| 3280 | - if (empty($upcontext['chmod_in_form'])) |
|
| 3281 | - echo ' |
|
| 3457 | + if (empty($upcontext['chmod_in_form'])) { |
|
| 3458 | + echo ' |
|
| 3282 | 3459 | <form action="', $upcontext['form_url'], '" method="post">'; |
| 3460 | + } |
|
| 3283 | 3461 | |
| 3284 | 3462 | echo ' |
| 3285 | 3463 | <table width="520" border="0" align="center" style="margin-bottom: 1ex;"> |
@@ -3314,10 +3492,11 @@ discard block |
||
| 3314 | 3492 | <div class="righttext" style="margin: 1ex;"><input type="submit" value="', $txt['ftp_connect'], '" class="button_submit"></div> |
| 3315 | 3493 | </div>'; |
| 3316 | 3494 | |
| 3317 | - if (empty($upcontext['chmod_in_form'])) |
|
| 3318 | - echo ' |
|
| 3495 | + if (empty($upcontext['chmod_in_form'])) { |
|
| 3496 | + echo ' |
|
| 3319 | 3497 | </form>'; |
| 3320 | -} |
|
| 3498 | + } |
|
| 3499 | + } |
|
| 3321 | 3500 | |
| 3322 | 3501 | function template_upgrade_above() |
| 3323 | 3502 | { |
@@ -3377,9 +3556,10 @@ discard block |
||
| 3377 | 3556 | <h2>', $txt['upgrade_progress'], '</h2> |
| 3378 | 3557 | <ul>'; |
| 3379 | 3558 | |
| 3380 | - foreach ($upcontext['steps'] as $num => $step) |
|
| 3381 | - echo ' |
|
| 3559 | + foreach ($upcontext['steps'] as $num => $step) { |
|
| 3560 | + echo ' |
|
| 3382 | 3561 | <li class="', $num < $upcontext['current_step'] ? 'stepdone' : ($num == $upcontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>'; |
| 3562 | + } |
|
| 3383 | 3563 | |
| 3384 | 3564 | echo ' |
| 3385 | 3565 | </ul> |
@@ -3392,8 +3572,8 @@ discard block |
||
| 3392 | 3572 | </div> |
| 3393 | 3573 | </div>'; |
| 3394 | 3574 | |
| 3395 | - if (isset($upcontext['step_progress'])) |
|
| 3396 | - echo ' |
|
| 3575 | + if (isset($upcontext['step_progress'])) { |
|
| 3576 | + echo ' |
|
| 3397 | 3577 | <br> |
| 3398 | 3578 | <br> |
| 3399 | 3579 | <div id="progress_bar_step"> |
@@ -3402,6 +3582,7 @@ discard block |
||
| 3402 | 3582 | <span>', $txt['upgrade_step_progress'], '</span> |
| 3403 | 3583 | </div> |
| 3404 | 3584 | </div>'; |
| 3585 | + } |
|
| 3405 | 3586 | |
| 3406 | 3587 | echo ' |
| 3407 | 3588 | <div id="substep_bar_div" class="smalltext" style="float: left;width: 50%;margin-top: 0.6em;display: ', isset($upcontext['substep_progress']) ? '' : 'none', ';">', isset($upcontext['substep_progress_name']) ? trim(strtr($upcontext['substep_progress_name'], array('.' => ''))) : '', ':</div> |
@@ -3432,32 +3613,36 @@ discard block |
||
| 3432 | 3613 | { |
| 3433 | 3614 | global $upcontext, $txt; |
| 3434 | 3615 | |
| 3435 | - if (!empty($upcontext['pause'])) |
|
| 3436 | - echo ' |
|
| 3616 | + if (!empty($upcontext['pause'])) { |
|
| 3617 | + echo ' |
|
| 3437 | 3618 | <em>', $txt['upgrade_incomplete'], '.</em><br> |
| 3438 | 3619 | |
| 3439 | 3620 | <h2 style="margin-top: 2ex;">', $txt['upgrade_not_quite_done'], '</h2> |
| 3440 | 3621 | <h3> |
| 3441 | 3622 | ', $txt['upgrade_paused_overload'], ' |
| 3442 | 3623 | </h3>'; |
| 3624 | + } |
|
| 3443 | 3625 | |
| 3444 | - if (!empty($upcontext['custom_warning'])) |
|
| 3445 | - echo ' |
|
| 3626 | + if (!empty($upcontext['custom_warning'])) { |
|
| 3627 | + echo ' |
|
| 3446 | 3628 | <div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;"> |
| 3447 | 3629 | <div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div> |
| 3448 | 3630 | <strong style="text-decoration: underline;">', $txt['upgrade_note'], '</strong><br> |
| 3449 | 3631 | <div style="padding-left: 6ex;">', $upcontext['custom_warning'], '</div> |
| 3450 | 3632 | </div>'; |
| 3633 | + } |
|
| 3451 | 3634 | |
| 3452 | 3635 | echo ' |
| 3453 | 3636 | <div class="righttext" style="margin: 1ex;">'; |
| 3454 | 3637 | |
| 3455 | - if (!empty($upcontext['continue'])) |
|
| 3456 | - echo ' |
|
| 3638 | + if (!empty($upcontext['continue'])) { |
|
| 3639 | + echo ' |
|
| 3457 | 3640 | <input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '"', $upcontext['continue'] == 2 ? ' disabled' : '', ' class="button_submit">'; |
| 3458 | - if (!empty($upcontext['skip'])) |
|
| 3459 | - echo ' |
|
| 3641 | + } |
|
| 3642 | + if (!empty($upcontext['skip'])) { |
|
| 3643 | + echo ' |
|
| 3460 | 3644 | <input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="dontSubmit = true; document.getElementById(\'contbutt\').disabled = \'disabled\'; return true;" class="button_submit">'; |
| 3645 | + } |
|
| 3461 | 3646 | |
| 3462 | 3647 | echo ' |
| 3463 | 3648 | </div> |
@@ -3507,11 +3692,12 @@ discard block |
||
| 3507 | 3692 | echo '<', '?xml version="1.0" encoding="UTF-8"?', '> |
| 3508 | 3693 | <smf>'; |
| 3509 | 3694 | |
| 3510 | - if (!empty($upcontext['get_data'])) |
|
| 3511 | - foreach ($upcontext['get_data'] as $k => $v) |
|
| 3695 | + if (!empty($upcontext['get_data'])) { |
|
| 3696 | + foreach ($upcontext['get_data'] as $k => $v) |
|
| 3512 | 3697 | echo ' |
| 3513 | 3698 | <get key="', $k, '">', $v, '</get>'; |
| 3514 | -} |
|
| 3699 | + } |
|
| 3700 | + } |
|
| 3515 | 3701 | |
| 3516 | 3702 | function template_xml_below() |
| 3517 | 3703 | { |
@@ -3552,8 +3738,8 @@ discard block |
||
| 3552 | 3738 | template_chmod(); |
| 3553 | 3739 | |
| 3554 | 3740 | // For large, pre 1.1 RC2 forums give them a warning about the possible impact of this upgrade! |
| 3555 | - if ($upcontext['is_large_forum']) |
|
| 3556 | - echo ' |
|
| 3741 | + if ($upcontext['is_large_forum']) { |
|
| 3742 | + echo ' |
|
| 3557 | 3743 | <div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;"> |
| 3558 | 3744 | <div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div> |
| 3559 | 3745 | <strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br> |
@@ -3561,10 +3747,11 @@ discard block |
||
| 3561 | 3747 | ', $txt['upgrade_warning_lots_data'], ' |
| 3562 | 3748 | </div> |
| 3563 | 3749 | </div>'; |
| 3750 | + } |
|
| 3564 | 3751 | |
| 3565 | 3752 | // A warning message? |
| 3566 | - if (!empty($upcontext['warning'])) |
|
| 3567 | - echo ' |
|
| 3753 | + if (!empty($upcontext['warning'])) { |
|
| 3754 | + echo ' |
|
| 3568 | 3755 | <div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;"> |
| 3569 | 3756 | <div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div> |
| 3570 | 3757 | <strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br> |
@@ -3572,6 +3759,7 @@ discard block |
||
| 3572 | 3759 | ', $upcontext['warning'], ' |
| 3573 | 3760 | </div> |
| 3574 | 3761 | </div>'; |
| 3762 | + } |
|
| 3575 | 3763 | |
| 3576 | 3764 | // Paths are incorrect? |
| 3577 | 3765 | echo ' |
@@ -3587,20 +3775,22 @@ discard block |
||
| 3587 | 3775 | if (!empty($upcontext['user']['id']) && (time() - $upcontext['started'] < 72600 || time() - $upcontext['updated'] < 3600)) |
| 3588 | 3776 | { |
| 3589 | 3777 | $ago = time() - $upcontext['started']; |
| 3590 | - if ($ago < 60) |
|
| 3591 | - $ago = $ago . ' seconds'; |
|
| 3592 | - elseif ($ago < 3600) |
|
| 3593 | - $ago = (int) ($ago / 60) . ' minutes'; |
|
| 3594 | - else |
|
| 3595 | - $ago = (int) ($ago / 3600) . ' hours'; |
|
| 3778 | + if ($ago < 60) { |
|
| 3779 | + $ago = $ago . ' seconds'; |
|
| 3780 | + } elseif ($ago < 3600) { |
|
| 3781 | + $ago = (int) ($ago / 60) . ' minutes'; |
|
| 3782 | + } else { |
|
| 3783 | + $ago = (int) ($ago / 3600) . ' hours'; |
|
| 3784 | + } |
|
| 3596 | 3785 | |
| 3597 | 3786 | $active = time() - $upcontext['updated']; |
| 3598 | - if ($active < 60) |
|
| 3599 | - $updated = $active . ' seconds'; |
|
| 3600 | - elseif ($active < 3600) |
|
| 3601 | - $updated = (int) ($active / 60) . ' minutes'; |
|
| 3602 | - else |
|
| 3603 | - $updated = (int) ($active / 3600) . ' hours'; |
|
| 3787 | + if ($active < 60) { |
|
| 3788 | + $updated = $active . ' seconds'; |
|
| 3789 | + } elseif ($active < 3600) { |
|
| 3790 | + $updated = (int) ($active / 60) . ' minutes'; |
|
| 3791 | + } else { |
|
| 3792 | + $updated = (int) ($active / 3600) . ' hours'; |
|
| 3793 | + } |
|
| 3604 | 3794 | |
| 3605 | 3795 | echo ' |
| 3606 | 3796 | <div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;"> |
@@ -3609,16 +3799,18 @@ discard block |
||
| 3609 | 3799 | <div style="padding-left: 6ex;"> |
| 3610 | 3800 | "', $upcontext['user']['name'], '" has been running the upgrade script for the last ', $ago, ' - and was last active ', $updated, ' ago.'; |
| 3611 | 3801 | |
| 3612 | - if ($active < 600) |
|
| 3613 | - echo ' |
|
| 3802 | + if ($active < 600) { |
|
| 3803 | + echo ' |
|
| 3614 | 3804 | We recommend that you do not run this script unless you are sure that ', $upcontext['user']['name'], ' has completed their upgrade.'; |
| 3805 | + } |
|
| 3615 | 3806 | |
| 3616 | - if ($active > $upcontext['inactive_timeout']) |
|
| 3617 | - echo ' |
|
| 3807 | + if ($active > $upcontext['inactive_timeout']) { |
|
| 3808 | + echo ' |
|
| 3618 | 3809 | <br><br>You can choose to either run the upgrade again from the beginning - or alternatively continue from the last step reached during the last upgrade.'; |
| 3619 | - else |
|
| 3620 | - echo ' |
|
| 3810 | + } else { |
|
| 3811 | + echo ' |
|
| 3621 | 3812 | <br><br>This upgrade script cannot be run until ', $upcontext['user']['name'], ' has been inactive for at least ', ($upcontext['inactive_timeout'] > 120 ? round($upcontext['inactive_timeout'] / 60, 1) . ' minutes!' : $upcontext['inactive_timeout'] . ' seconds!'); |
| 3813 | + } |
|
| 3622 | 3814 | |
| 3623 | 3815 | echo ' |
| 3624 | 3816 | </div> |
@@ -3634,9 +3826,10 @@ discard block |
||
| 3634 | 3826 | <td> |
| 3635 | 3827 | <input type="text" name="user" value="', !empty($upcontext['username']) ? $upcontext['username'] : '', '"', $disable_security ? ' disabled' : '', ' class="input_text">'; |
| 3636 | 3828 | |
| 3637 | - if (!empty($upcontext['username_incorrect'])) |
|
| 3638 | - echo ' |
|
| 3829 | + if (!empty($upcontext['username_incorrect'])) { |
|
| 3830 | + echo ' |
|
| 3639 | 3831 | <div class="smalltext" style="color: red;">Username Incorrect</div>'; |
| 3832 | + } |
|
| 3640 | 3833 | |
| 3641 | 3834 | echo ' |
| 3642 | 3835 | </td> |
@@ -3647,9 +3840,10 @@ discard block |
||
| 3647 | 3840 | <input type="password" name="passwrd" value=""', $disable_security ? ' disabled' : '', ' class="input_password"> |
| 3648 | 3841 | <input type="hidden" name="hash_passwrd" value="">'; |
| 3649 | 3842 | |
| 3650 | - if (!empty($upcontext['password_failed'])) |
|
| 3651 | - echo ' |
|
| 3843 | + if (!empty($upcontext['password_failed'])) { |
|
| 3844 | + echo ' |
|
| 3652 | 3845 | <div class="smalltext" style="color: red;">Password Incorrect</div>'; |
| 3846 | + } |
|
| 3653 | 3847 | |
| 3654 | 3848 | echo ' |
| 3655 | 3849 | </td> |
@@ -3720,8 +3914,8 @@ discard block |
||
| 3720 | 3914 | <form action="', $upcontext['form_url'], '" method="post" name="upform" id="upform">'; |
| 3721 | 3915 | |
| 3722 | 3916 | // Warning message? |
| 3723 | - if (!empty($upcontext['upgrade_options_warning'])) |
|
| 3724 | - echo ' |
|
| 3917 | + if (!empty($upcontext['upgrade_options_warning'])) { |
|
| 3918 | + echo ' |
|
| 3725 | 3919 | <div style="margin: 1ex; padding: 1ex; border: 1px dashed #cc3344; color: black; background-color: #ffe4e9;"> |
| 3726 | 3920 | <div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div> |
| 3727 | 3921 | <strong style="text-decoration: underline;">Warning!</strong><br> |
@@ -3729,6 +3923,7 @@ discard block |
||
| 3729 | 3923 | ', $upcontext['upgrade_options_warning'], ' |
| 3730 | 3924 | </div> |
| 3731 | 3925 | </div>'; |
| 3926 | + } |
|
| 3732 | 3927 | |
| 3733 | 3928 | echo ' |
| 3734 | 3929 | <table> |
@@ -3771,8 +3966,8 @@ discard block |
||
| 3771 | 3966 | </td> |
| 3772 | 3967 | </tr>'; |
| 3773 | 3968 | |
| 3774 | - if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) |
|
| 3775 | - echo ' |
|
| 3969 | + if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) { |
|
| 3970 | + echo ' |
|
| 3776 | 3971 | <tr valign="top"> |
| 3777 | 3972 | <td width="2%"> |
| 3778 | 3973 | <input type="checkbox" name="delete_karma" id="delete_karma" value="1" class="input_check"> |
@@ -3781,6 +3976,7 @@ discard block |
||
| 3781 | 3976 | <label for="delete_karma">Delete all karma settings and info from the DB</label> |
| 3782 | 3977 | </td> |
| 3783 | 3978 | </tr>'; |
| 3979 | + } |
|
| 3784 | 3980 | |
| 3785 | 3981 | echo ' |
| 3786 | 3982 | <tr valign="top"> |
@@ -3818,10 +4014,11 @@ discard block |
||
| 3818 | 4014 | </div>'; |
| 3819 | 4015 | |
| 3820 | 4016 | // Dont any tables so far? |
| 3821 | - if (!empty($upcontext['previous_tables'])) |
|
| 3822 | - foreach ($upcontext['previous_tables'] as $table) |
|
| 4017 | + if (!empty($upcontext['previous_tables'])) { |
|
| 4018 | + foreach ($upcontext['previous_tables'] as $table) |
|
| 3823 | 4019 | echo ' |
| 3824 | 4020 | <br>Completed Table: "', $table, '".'; |
| 4021 | + } |
|
| 3825 | 4022 | |
| 3826 | 4023 | echo ' |
| 3827 | 4024 | <h3 id="current_tab_div">Current Table: "<span id="current_table">', $upcontext['cur_table_name'], '</span>"</h3> |
@@ -3858,12 +4055,13 @@ discard block |
||
| 3858 | 4055 | updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');'; |
| 3859 | 4056 | |
| 3860 | 4057 | // If debug flood the screen. |
| 3861 | - if ($is_debug) |
|
| 3862 | - echo ' |
|
| 4058 | + if ($is_debug) { |
|
| 4059 | + echo ' |
|
| 3863 | 4060 | setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: "\' + sCompletedTableName + \'".<span id="debuginfo"><\' + \'/span>\'); |
| 3864 | 4061 | |
| 3865 | 4062 | if (document.getElementById(\'debug_section\').scrollHeight) |
| 3866 | 4063 | document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight'; |
| 4064 | + } |
|
| 3867 | 4065 | |
| 3868 | 4066 | echo ' |
| 3869 | 4067 | // Get the next update... |
@@ -3896,8 +4094,9 @@ discard block |
||
| 3896 | 4094 | { |
| 3897 | 4095 | global $upcontext, $support_js, $is_debug, $timeLimitThreshold; |
| 3898 | 4096 | |
| 3899 | - if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) |
|
| 3900 | - $is_debug = true; |
|
| 4097 | + if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) { |
|
| 4098 | + $is_debug = true; |
|
| 4099 | + } |
|
| 3901 | 4100 | |
| 3902 | 4101 | echo ' |
| 3903 | 4102 | <h3>Executing database changes</h3> |
@@ -3912,8 +4111,9 @@ discard block |
||
| 3912 | 4111 | { |
| 3913 | 4112 | foreach ($upcontext['actioned_items'] as $num => $item) |
| 3914 | 4113 | { |
| 3915 | - if ($num != 0) |
|
| 3916 | - echo ' Successful!'; |
|
| 4114 | + if ($num != 0) { |
|
| 4115 | + echo ' Successful!'; |
|
| 4116 | + } |
|
| 3917 | 4117 | echo '<br>' . $item; |
| 3918 | 4118 | } |
| 3919 | 4119 | if (!empty($upcontext['changes_complete'])) |
@@ -3926,28 +4126,32 @@ discard block |
||
| 3926 | 4126 | $seconds = intval($active % 60); |
| 3927 | 4127 | |
| 3928 | 4128 | $totalTime = ''; |
| 3929 | - if ($hours > 0) |
|
| 3930 | - $totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' '; |
|
| 3931 | - if ($minutes > 0) |
|
| 3932 | - $totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' '; |
|
| 3933 | - if ($seconds > 0) |
|
| 3934 | - $totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' '; |
|
| 4129 | + if ($hours > 0) { |
|
| 4130 | + $totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' '; |
|
| 4131 | + } |
|
| 4132 | + if ($minutes > 0) { |
|
| 4133 | + $totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' '; |
|
| 4134 | + } |
|
| 4135 | + if ($seconds > 0) { |
|
| 4136 | + $totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' '; |
|
| 4137 | + } |
|
| 3935 | 4138 | } |
| 3936 | 4139 | |
| 3937 | - if ($is_debug && !empty($totalTime)) |
|
| 3938 | - echo ' Successful! Completed in ', $totalTime, '<br><br>'; |
|
| 3939 | - else |
|
| 3940 | - echo ' Successful!<br><br>'; |
|
| 4140 | + if ($is_debug && !empty($totalTime)) { |
|
| 4141 | + echo ' Successful! Completed in ', $totalTime, '<br><br>'; |
|
| 4142 | + } else { |
|
| 4143 | + echo ' Successful!<br><br>'; |
|
| 4144 | + } |
|
| 3941 | 4145 | |
| 3942 | 4146 | echo '<span id="commess" style="font-weight: bold;">1 Database Updates Complete! Click Continue to Proceed.</span><br>'; |
| 3943 | 4147 | } |
| 3944 | - } |
|
| 3945 | - else |
|
| 4148 | + } else |
|
| 3946 | 4149 | { |
| 3947 | 4150 | // Tell them how many files we have in total. |
| 3948 | - if ($upcontext['file_count'] > 1) |
|
| 3949 | - echo ' |
|
| 4151 | + if ($upcontext['file_count'] > 1) { |
|
| 4152 | + echo ' |
|
| 3950 | 4153 | <strong id="info1">Executing upgrade script <span id="file_done">', $upcontext['cur_file_num'], '</span> of ', $upcontext['file_count'], '.</strong>'; |
| 4154 | + } |
|
| 3951 | 4155 | |
| 3952 | 4156 | echo ' |
| 3953 | 4157 | <h3 id="info2"><strong>Executing:</strong> "<span id="cur_item_name">', $upcontext['current_item_name'], '</span>" (<span id="item_num">', $upcontext['current_item_num'], '</span> of <span id="total_items"><span id="item_count">', $upcontext['total_items'], '</span>', $upcontext['file_count'] > 1 ? ' - of this script' : '', ')</span></h3> |
@@ -3963,19 +4167,23 @@ discard block |
||
| 3963 | 4167 | $seconds = intval($active % 60); |
| 3964 | 4168 | |
| 3965 | 4169 | $totalTime = ''; |
| 3966 | - if ($hours > 0) |
|
| 3967 | - $totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' '; |
|
| 3968 | - if ($minutes > 0) |
|
| 3969 | - $totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' '; |
|
| 3970 | - if ($seconds > 0) |
|
| 3971 | - $totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' '; |
|
| 4170 | + if ($hours > 0) { |
|
| 4171 | + $totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' '; |
|
| 4172 | + } |
|
| 4173 | + if ($minutes > 0) { |
|
| 4174 | + $totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' '; |
|
| 4175 | + } |
|
| 4176 | + if ($seconds > 0) { |
|
| 4177 | + $totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' '; |
|
| 4178 | + } |
|
| 3972 | 4179 | } |
| 3973 | 4180 | |
| 3974 | 4181 | echo ' |
| 3975 | 4182 | <br><span id="upgradeCompleted">'; |
| 3976 | 4183 | |
| 3977 | - if (!empty($totalTime)) |
|
| 3978 | - echo 'Completed in ', $totalTime, '<br>'; |
|
| 4184 | + if (!empty($totalTime)) { |
|
| 4185 | + echo 'Completed in ', $totalTime, '<br>'; |
|
| 4186 | + } |
|
| 3979 | 4187 | |
| 3980 | 4188 | echo '</span> |
| 3981 | 4189 | <div id="debug_section" style="height: 117px; overflow: auto;"> |
@@ -4012,9 +4220,10 @@ discard block |
||
| 4012 | 4220 | var getData = ""; |
| 4013 | 4221 | var debugItems = ', $upcontext['debug_items'], ';'; |
| 4014 | 4222 | |
| 4015 | - if ($is_debug) |
|
| 4016 | - echo ' |
|
| 4223 | + if ($is_debug) { |
|
| 4224 | + echo ' |
|
| 4017 | 4225 | var upgradeStartTime = ' . $upcontext['started'] . ';'; |
| 4226 | + } |
|
| 4018 | 4227 | |
| 4019 | 4228 | echo ' |
| 4020 | 4229 | function getNextItem() |
@@ -4054,9 +4263,10 @@ discard block |
||
| 4054 | 4263 | document.getElementById("error_block").style.display = ""; |
| 4055 | 4264 | setInnerHTML(document.getElementById("error_message"), "Error retrieving information on step: " + (sDebugName == "" ? sLastString : sDebugName));'; |
| 4056 | 4265 | |
| 4057 | - if ($is_debug) |
|
| 4058 | - echo ' |
|
| 4266 | + if ($is_debug) { |
|
| 4267 | + echo ' |
|
| 4059 | 4268 | setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');'; |
| 4269 | + } |
|
| 4060 | 4270 | |
| 4061 | 4271 | echo ' |
| 4062 | 4272 | } |
@@ -4077,9 +4287,10 @@ discard block |
||
| 4077 | 4287 | document.getElementById("error_block").style.display = ""; |
| 4078 | 4288 | setInnerHTML(document.getElementById("error_message"), "Upgrade script appears to be going into a loop - step: " + sDebugName);'; |
| 4079 | 4289 | |
| 4080 | - if ($is_debug) |
|
| 4081 | - echo ' |
|
| 4290 | + if ($is_debug) { |
|
| 4291 | + echo ' |
|
| 4082 | 4292 | setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');'; |
| 4293 | + } |
|
| 4083 | 4294 | |
| 4084 | 4295 | echo ' |
| 4085 | 4296 | } |
@@ -4138,8 +4349,8 @@ discard block |
||
| 4138 | 4349 | if (bIsComplete && iDebugNum == -1 && curFile >= ', $upcontext['file_count'], ') |
| 4139 | 4350 | {'; |
| 4140 | 4351 | |
| 4141 | - if ($is_debug) |
|
| 4142 | - echo ' |
|
| 4352 | + if ($is_debug) { |
|
| 4353 | + echo ' |
|
| 4143 | 4354 | document.getElementById(\'debug_section\').style.display = "none"; |
| 4144 | 4355 | |
| 4145 | 4356 | var upgradeFinishedTime = parseInt(oXMLDoc.getElementsByTagName("curtime")[0].childNodes[0].nodeValue); |
@@ -4157,6 +4368,7 @@ discard block |
||
| 4157 | 4368 | totalTime = totalTime + diffSeconds + " second" + (diffSeconds > 1 ? "s" : ""); |
| 4158 | 4369 | |
| 4159 | 4370 | setInnerHTML(document.getElementById("upgradeCompleted"), "Completed in " + totalTime);'; |
| 4371 | + } |
|
| 4160 | 4372 | |
| 4161 | 4373 | echo ' |
| 4162 | 4374 | |
@@ -4164,9 +4376,10 @@ discard block |
||
| 4164 | 4376 | document.getElementById(\'contbutt\').disabled = 0; |
| 4165 | 4377 | document.getElementById(\'database_done\').value = 1;'; |
| 4166 | 4378 | |
| 4167 | - if ($upcontext['file_count'] > 1) |
|
| 4168 | - echo ' |
|
| 4379 | + if ($upcontext['file_count'] > 1) { |
|
| 4380 | + echo ' |
|
| 4169 | 4381 | document.getElementById(\'info1\').style.display = "none";'; |
| 4382 | + } |
|
| 4170 | 4383 | |
| 4171 | 4384 | echo ' |
| 4172 | 4385 | document.getElementById(\'info2\').style.display = "none"; |
@@ -4179,9 +4392,10 @@ discard block |
||
| 4179 | 4392 | lastItem = 0; |
| 4180 | 4393 | prevFile = curFile;'; |
| 4181 | 4394 | |
| 4182 | - if ($is_debug) |
|
| 4183 | - echo ' |
|
| 4395 | + if ($is_debug) { |
|
| 4396 | + echo ' |
|
| 4184 | 4397 | setOuterHTML(document.getElementById(\'debuginfo\'), \'Moving to next script file...done<br><span id="debuginfo"><\' + \'/span>\');'; |
| 4398 | + } |
|
| 4185 | 4399 | |
| 4186 | 4400 | echo ' |
| 4187 | 4401 | getNextItem(); |
@@ -4189,8 +4403,8 @@ discard block |
||
| 4189 | 4403 | }'; |
| 4190 | 4404 | |
| 4191 | 4405 | // If debug scroll the screen. |
| 4192 | - if ($is_debug) |
|
| 4193 | - echo ' |
|
| 4406 | + if ($is_debug) { |
|
| 4407 | + echo ' |
|
| 4194 | 4408 | if (iLastSubStepProgress == -1) |
| 4195 | 4409 | { |
| 4196 | 4410 | // Give it consistent dots. |
@@ -4209,6 +4423,7 @@ discard block |
||
| 4209 | 4423 | |
| 4210 | 4424 | if (document.getElementById(\'debug_section\').scrollHeight) |
| 4211 | 4425 | document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight'; |
| 4426 | + } |
|
| 4212 | 4427 | |
| 4213 | 4428 | echo ' |
| 4214 | 4429 | // Update the page. |
@@ -4269,9 +4484,10 @@ discard block |
||
| 4269 | 4484 | }'; |
| 4270 | 4485 | |
| 4271 | 4486 | // Start things off assuming we've not errored. |
| 4272 | - if (empty($upcontext['error_message'])) |
|
| 4273 | - echo ' |
|
| 4487 | + if (empty($upcontext['error_message'])) { |
|
| 4488 | + echo ' |
|
| 4274 | 4489 | getNextItem();'; |
| 4490 | + } |
|
| 4275 | 4491 | |
| 4276 | 4492 | echo ' |
| 4277 | 4493 | //# sourceURL=dynamicScript-dbch.js |
@@ -4289,18 +4505,21 @@ discard block |
||
| 4289 | 4505 | <item num="', $upcontext['current_item_num'], '">', $upcontext['current_item_name'], '</item> |
| 4290 | 4506 | <debug num="', $upcontext['current_debug_item_num'], '" percent="', isset($upcontext['substep_progress']) ? $upcontext['substep_progress'] : '-1', '" complete="', empty($upcontext['completed_step']) ? 0 : 1, '">', $upcontext['current_debug_item_name'], '</debug>'; |
| 4291 | 4507 | |
| 4292 | - if (!empty($upcontext['error_message'])) |
|
| 4293 | - echo ' |
|
| 4508 | + if (!empty($upcontext['error_message'])) { |
|
| 4509 | + echo ' |
|
| 4294 | 4510 | <error>', $upcontext['error_message'], '</error>'; |
| 4511 | + } |
|
| 4295 | 4512 | |
| 4296 | - if (!empty($upcontext['error_string'])) |
|
| 4297 | - echo ' |
|
| 4513 | + if (!empty($upcontext['error_string'])) { |
|
| 4514 | + echo ' |
|
| 4298 | 4515 | <sql>', $upcontext['error_string'], '</sql>'; |
| 4516 | + } |
|
| 4299 | 4517 | |
| 4300 | - if ($is_debug) |
|
| 4301 | - echo ' |
|
| 4518 | + if ($is_debug) { |
|
| 4519 | + echo ' |
|
| 4302 | 4520 | <curtime>', time(), '</curtime>'; |
| 4303 | -} |
|
| 4521 | + } |
|
| 4522 | + } |
|
| 4304 | 4523 | |
| 4305 | 4524 | // Template for the UTF-8 conversion step. Basically a copy of the backup stuff with slight modifications.... |
| 4306 | 4525 | function template_convert_utf8() |
@@ -4319,18 +4538,20 @@ discard block |
||
| 4319 | 4538 | </div>'; |
| 4320 | 4539 | |
| 4321 | 4540 | // Done any tables so far? |
| 4322 | - if (!empty($upcontext['previous_tables'])) |
|
| 4323 | - foreach ($upcontext['previous_tables'] as $table) |
|
| 4541 | + if (!empty($upcontext['previous_tables'])) { |
|
| 4542 | + foreach ($upcontext['previous_tables'] as $table) |
|
| 4324 | 4543 | echo ' |
| 4325 | 4544 | <br>Completed Table: "', $table, '".'; |
| 4545 | + } |
|
| 4326 | 4546 | |
| 4327 | 4547 | echo ' |
| 4328 | 4548 | <h3 id="current_tab_div">Current Table: "<span id="current_table">', $upcontext['cur_table_name'], '</span>"</h3>'; |
| 4329 | 4549 | |
| 4330 | 4550 | // If we dropped their index, let's let them know |
| 4331 | - if ($upcontext['cur_table_num'] == $upcontext['table_count'] && $upcontext['dropping_index']) |
|
| 4332 | - echo ' |
|
| 4551 | + if ($upcontext['cur_table_num'] == $upcontext['table_count'] && $upcontext['dropping_index']) { |
|
| 4552 | + echo ' |
|
| 4333 | 4553 | <br><span style="display:inline;">Please note that your fulltext index was dropped to facilitate the conversion and will need to be recreated.</span>'; |
| 4554 | + } |
|
| 4334 | 4555 | |
| 4335 | 4556 | echo ' |
| 4336 | 4557 | <br><span id="commess" style="font-weight: bold; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">Conversion Complete! Click Continue to Proceed.</span>'; |
@@ -4366,12 +4587,13 @@ discard block |
||
| 4366 | 4587 | updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');'; |
| 4367 | 4588 | |
| 4368 | 4589 | // If debug flood the screen. |
| 4369 | - if ($is_debug) |
|
| 4370 | - echo ' |
|
| 4590 | + if ($is_debug) { |
|
| 4591 | + echo ' |
|
| 4371 | 4592 | setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: "\' + sCompletedTableName + \'".<span id="debuginfo"><\' + \'/span>\'); |
| 4372 | 4593 | |
| 4373 | 4594 | if (document.getElementById(\'debug_section\').scrollHeight) |
| 4374 | 4595 | document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight'; |
| 4596 | + } |
|
| 4375 | 4597 | |
| 4376 | 4598 | echo ' |
| 4377 | 4599 | // Get the next update... |
@@ -4416,19 +4638,21 @@ discard block |
||
| 4416 | 4638 | </div>'; |
| 4417 | 4639 | |
| 4418 | 4640 | // Dont any tables so far? |
| 4419 | - if (!empty($upcontext['previous_tables'])) |
|
| 4420 | - foreach ($upcontext['previous_tables'] as $table) |
|
| 4641 | + if (!empty($upcontext['previous_tables'])) { |
|
| 4642 | + foreach ($upcontext['previous_tables'] as $table) |
|
| 4421 | 4643 | echo ' |
| 4422 | 4644 | <br>Completed Table: "', $table, '".'; |
| 4645 | + } |
|
| 4423 | 4646 | |
| 4424 | 4647 | echo ' |
| 4425 | 4648 | <h3 id="current_tab_div">Current Table: "<span id="current_table">', $upcontext['cur_table_name'], '</span>"</h3> |
| 4426 | 4649 | <br><span id="commess" style="font-weight: bold; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">Convert to JSON Complete! Click Continue to Proceed.</span>'; |
| 4427 | 4650 | |
| 4428 | 4651 | // Try to make sure substep was reset. |
| 4429 | - if ($upcontext['cur_table_num'] == $upcontext['table_count']) |
|
| 4430 | - echo ' |
|
| 4652 | + if ($upcontext['cur_table_num'] == $upcontext['table_count']) { |
|
| 4653 | + echo ' |
|
| 4431 | 4654 | <input type="hidden" name="substep" id="substep" value="0">'; |
| 4655 | + } |
|
| 4432 | 4656 | |
| 4433 | 4657 | // Continue please! |
| 4434 | 4658 | $upcontext['continue'] = $support_js ? 2 : 1; |
@@ -4461,12 +4685,13 @@ discard block |
||
| 4461 | 4685 | updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');'; |
| 4462 | 4686 | |
| 4463 | 4687 | // If debug flood the screen. |
| 4464 | - if ($is_debug) |
|
| 4465 | - echo ' |
|
| 4688 | + if ($is_debug) { |
|
| 4689 | + echo ' |
|
| 4466 | 4690 | setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: "\' + sCompletedTableName + \'".<span id="debuginfo"><\' + \'/span>\'); |
| 4467 | 4691 | |
| 4468 | 4692 | if (document.getElementById(\'debug_section\').scrollHeight) |
| 4469 | 4693 | document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight'; |
| 4694 | + } |
|
| 4470 | 4695 | |
| 4471 | 4696 | echo ' |
| 4472 | 4697 | // Get the next update... |
@@ -4502,8 +4727,8 @@ discard block |
||
| 4502 | 4727 | <h3>That wasn\'t so hard, was it? Now you are ready to use <a href="', $boardurl, '/index.php">your installation of SMF</a>. Hope you like it!</h3> |
| 4503 | 4728 | <form action="', $boardurl, '/index.php">'; |
| 4504 | 4729 | |
| 4505 | - if (!empty($upcontext['can_delete_script'])) |
|
| 4506 | - echo ' |
|
| 4730 | + if (!empty($upcontext['can_delete_script'])) { |
|
| 4731 | + echo ' |
|
| 4507 | 4732 | <label for="delete_self"><input type="checkbox" id="delete_self" onclick="doTheDelete(this);" class="input_check"> Delete upgrade.php and its data files now</label> <em>(doesn\'t work on all servers).</em> |
| 4508 | 4733 | <script> |
| 4509 | 4734 | function doTheDelete(theCheck) |
@@ -4515,6 +4740,7 @@ discard block |
||
| 4515 | 4740 | } |
| 4516 | 4741 | </script> |
| 4517 | 4742 | <img src="', $settings['default_theme_url'], '/images/blank.png" alt="" id="delete_upgrader"><br>'; |
| 4743 | + } |
|
| 4518 | 4744 | |
| 4519 | 4745 | $active = time() - $upcontext['started']; |
| 4520 | 4746 | $hours = floor($active / 3600); |
@@ -4524,16 +4750,20 @@ discard block |
||
| 4524 | 4750 | if ($is_debug) |
| 4525 | 4751 | { |
| 4526 | 4752 | $totalTime = ''; |
| 4527 | - if ($hours > 0) |
|
| 4528 | - $totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' '; |
|
| 4529 | - if ($minutes > 0) |
|
| 4530 | - $totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' '; |
|
| 4531 | - if ($seconds > 0) |
|
| 4532 | - $totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' '; |
|
| 4753 | + if ($hours > 0) { |
|
| 4754 | + $totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' '; |
|
| 4755 | + } |
|
| 4756 | + if ($minutes > 0) { |
|
| 4757 | + $totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' '; |
|
| 4758 | + } |
|
| 4759 | + if ($seconds > 0) { |
|
| 4760 | + $totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' '; |
|
| 4761 | + } |
|
| 4533 | 4762 | } |
| 4534 | 4763 | |
| 4535 | - if ($is_debug && !empty($totalTime)) |
|
| 4536 | - echo '<br> Upgrade completed in ', $totalTime, '<br><br>'; |
|
| 4764 | + if ($is_debug && !empty($totalTime)) { |
|
| 4765 | + echo '<br> Upgrade completed in ', $totalTime, '<br><br>'; |
|
| 4766 | + } |
|
| 4537 | 4767 | |
| 4538 | 4768 | echo '<br> |
| 4539 | 4769 | If you had any problems with this upgrade, or have any problems using SMF, please don\'t hesitate to <a href="https://www.simplemachines.org/community/index.php">look to us for assistance</a>.<br> |
@@ -4560,8 +4790,9 @@ discard block |
||
| 4560 | 4790 | |
| 4561 | 4791 | $current_substep = $_GET['substep']; |
| 4562 | 4792 | |
| 4563 | - if (empty($_GET['a'])) |
|
| 4564 | - $_GET['a'] = 0; |
|
| 4793 | + if (empty($_GET['a'])) { |
|
| 4794 | + $_GET['a'] = 0; |
|
| 4795 | + } |
|
| 4565 | 4796 | $step_progress['name'] = 'Converting ips'; |
| 4566 | 4797 | $step_progress['current'] = $_GET['a']; |
| 4567 | 4798 | |
@@ -4604,16 +4835,19 @@ discard block |
||
| 4604 | 4835 | 'empty' => '', |
| 4605 | 4836 | 'limit' => $limit, |
| 4606 | 4837 | )); |
| 4607 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 4608 | - $arIp[] = $row[$oldCol]; |
|
| 4838 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 4839 | + $arIp[] = $row[$oldCol]; |
|
| 4840 | + } |
|
| 4609 | 4841 | $smcFunc['db_free_result']($request); |
| 4610 | 4842 | |
| 4611 | 4843 | // Special case, null ip could keep us in a loop. |
| 4612 | - if (is_null($arIp[0])) |
|
| 4613 | - unset($arIp[0]); |
|
| 4844 | + if (is_null($arIp[0])) { |
|
| 4845 | + unset($arIp[0]); |
|
| 4846 | + } |
|
| 4614 | 4847 | |
| 4615 | - if (empty($arIp)) |
|
| 4616 | - $is_done = true; |
|
| 4848 | + if (empty($arIp)) { |
|
| 4849 | + $is_done = true; |
|
| 4850 | + } |
|
| 4617 | 4851 | |
| 4618 | 4852 | $updates = array(); |
| 4619 | 4853 | $cases = array(); |
@@ -4622,16 +4856,18 @@ discard block |
||
| 4622 | 4856 | { |
| 4623 | 4857 | $arIp[$i] = trim($arIp[$i]); |
| 4624 | 4858 | |
| 4625 | - if (empty($arIp[$i])) |
|
| 4626 | - continue; |
|
| 4859 | + if (empty($arIp[$i])) { |
|
| 4860 | + continue; |
|
| 4861 | + } |
|
| 4627 | 4862 | |
| 4628 | 4863 | $updates['ip' . $i] = $arIp[$i]; |
| 4629 | 4864 | $cases[$arIp[$i]] = 'WHEN ' . $oldCol . ' = {string:ip' . $i . '} THEN {inet:ip' . $i . '}'; |
| 4630 | 4865 | |
| 4631 | 4866 | if ($setSize > 0 && $i % $setSize === 0) |
| 4632 | 4867 | { |
| 4633 | - if (count($updates) == 1) |
|
| 4634 | - continue; |
|
| 4868 | + if (count($updates) == 1) { |
|
| 4869 | + continue; |
|
| 4870 | + } |
|
| 4635 | 4871 | |
| 4636 | 4872 | $updates['whereSet'] = array_values($updates); |
| 4637 | 4873 | $smcFunc['db_query']('', ' |
@@ -4665,8 +4901,7 @@ discard block |
||
| 4665 | 4901 | 'ip' => $ip |
| 4666 | 4902 | )); |
| 4667 | 4903 | } |
| 4668 | - } |
|
| 4669 | - else |
|
| 4904 | + } else |
|
| 4670 | 4905 | { |
| 4671 | 4906 | $updates['whereSet'] = array_values($updates); |
| 4672 | 4907 | $smcFunc['db_query']('', ' |
@@ -4680,9 +4915,9 @@ discard block |
||
| 4680 | 4915 | $updates |
| 4681 | 4916 | ); |
| 4682 | 4917 | } |
| 4918 | + } else { |
|
| 4919 | + $is_done = true; |
|
| 4683 | 4920 | } |
| 4684 | - else |
|
| 4685 | - $is_done = true; |
|
| 4686 | 4921 | |
| 4687 | 4922 | $_GET['a'] += $limit; |
| 4688 | 4923 | $step_progress['current'] = $_GET['a']; |
@@ -4708,10 +4943,11 @@ discard block |
||
| 4708 | 4943 | |
| 4709 | 4944 | $columns = $smcFunc['db_list_columns']($targetTable, true); |
| 4710 | 4945 | |
| 4711 | - if (isset($columns[$column])) |
|
| 4712 | - return $columns[$column]; |
|
| 4713 | - else |
|
| 4714 | - return null; |
|
| 4715 | -} |
|
| 4946 | + if (isset($columns[$column])) { |
|
| 4947 | + return $columns[$column]; |
|
| 4948 | + } else { |
|
| 4949 | + return null; |
|
| 4950 | + } |
|
| 4951 | + } |
|
| 4716 | 4952 | |
| 4717 | 4953 | ?> |
| 4718 | 4954 | \ No newline at end of file |