@@ -20,8 +20,9 @@ discard block |
||
| 20 | 20 | // ><html dir="ltr"><head><title>Error!</title></head><body>Sorry, this installer requires PHP!<div style="display: none;"> |
| 21 | 21 | |
| 22 | 22 | // Let's pull in useful classes |
| 23 | -if (!defined('SMF')) |
|
| 23 | +if (!defined('SMF')) { |
|
| 24 | 24 | define('SMF', 1); |
| 25 | +} |
|
| 25 | 26 | |
| 26 | 27 | require_once('Sources/Class-Package.php'); |
| 27 | 28 | |
@@ -63,10 +64,11 @@ discard block |
||
| 63 | 64 | |
| 64 | 65 | list ($charcode) = pg_fetch_row($request); |
| 65 | 66 | |
| 66 | - if ($charcode == 'UTF8') |
|
| 67 | - return true; |
|
| 68 | - else |
|
| 69 | - return false; |
|
| 67 | + if ($charcode == 'UTF8') { |
|
| 68 | + return true; |
|
| 69 | + } else { |
|
| 70 | + return false; |
|
| 71 | + } |
|
| 70 | 72 | }, |
| 71 | 73 | 'utf8_version' => '8.0', |
| 72 | 74 | 'utf8_version_check' => '$request = pg_query(\'SELECT version()\'); list ($version) = pg_fetch_row($request); list($pgl, $version) = explode(" ", $version); return $version;', |
@@ -76,12 +78,14 @@ discard block |
||
| 76 | 78 | $value = preg_replace('~[^A-Za-z0-9_\$]~', '', $value); |
| 77 | 79 | |
| 78 | 80 | // Is it reserved? |
| 79 | - if ($value == 'pg_') |
|
| 80 | - return $txt['error_db_prefix_reserved']; |
|
| 81 | + if ($value == 'pg_') { |
|
| 82 | + return $txt['error_db_prefix_reserved']; |
|
| 83 | + } |
|
| 81 | 84 | |
| 82 | 85 | // Is the prefix numeric? |
| 83 | - if (preg_match('~^\d~', $value)) |
|
| 84 | - return $txt['error_db_prefix_numeric']; |
|
| 86 | + if (preg_match('~^\d~', $value)) { |
|
| 87 | + return $txt['error_db_prefix_numeric']; |
|
| 88 | + } |
|
| 85 | 89 | |
| 86 | 90 | return true; |
| 87 | 91 | }, |
@@ -128,10 +132,11 @@ discard block |
||
| 128 | 132 | $incontext['skip'] = false; |
| 129 | 133 | |
| 130 | 134 | // Call the step and if it returns false that means pause! |
| 131 | - if (function_exists($step[2]) && $step[2]() === false) |
|
| 132 | - break; |
|
| 133 | - elseif (function_exists($step[2])) |
|
| 134 | - $incontext['current_step']++; |
|
| 135 | + if (function_exists($step[2]) && $step[2]() === false) { |
|
| 136 | + break; |
|
| 137 | + } elseif (function_exists($step[2])) { |
|
| 138 | + $incontext['current_step']++; |
|
| 139 | + } |
|
| 135 | 140 | |
| 136 | 141 | // No warnings pass on. |
| 137 | 142 | $incontext['warning'] = ''; |
@@ -147,8 +152,9 @@ discard block |
||
| 147 | 152 | global $databases; |
| 148 | 153 | |
| 149 | 154 | // Just so people using older versions of PHP aren't left in the cold. |
| 150 | - if (!isset($_SERVER['PHP_SELF'])) |
|
| 151 | - $_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php'; |
|
| 155 | + if (!isset($_SERVER['PHP_SELF'])) { |
|
| 156 | + $_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php'; |
|
| 157 | + } |
|
| 152 | 158 | |
| 153 | 159 | // Enable error reporting for fatal errors. |
| 154 | 160 | error_reporting(E_ERROR | E_PARSE); |
@@ -164,21 +170,23 @@ discard block |
||
| 164 | 170 | { |
| 165 | 171 | ob_start(); |
| 166 | 172 | |
| 167 | - if (ini_get('session.save_handler') == 'user') |
|
| 168 | - @ini_set('session.save_handler', 'files'); |
|
| 169 | - if (function_exists('session_start')) |
|
| 170 | - @session_start(); |
|
| 171 | - } |
|
| 172 | - else |
|
| 173 | + if (ini_get('session.save_handler') == 'user') { |
|
| 174 | + @ini_set('session.save_handler', 'files'); |
|
| 175 | + } |
|
| 176 | + if (function_exists('session_start')) { |
|
| 177 | + @session_start(); |
|
| 178 | + } |
|
| 179 | + } else |
|
| 173 | 180 | { |
| 174 | 181 | ob_start('ob_gzhandler'); |
| 175 | 182 | |
| 176 | - if (ini_get('session.save_handler') == 'user') |
|
| 177 | - @ini_set('session.save_handler', 'files'); |
|
| 183 | + if (ini_get('session.save_handler') == 'user') { |
|
| 184 | + @ini_set('session.save_handler', 'files'); |
|
| 185 | + } |
|
| 178 | 186 | session_start(); |
| 179 | 187 | |
| 180 | - if (!headers_sent()) |
|
| 181 | - echo '<!DOCTYPE html> |
|
| 188 | + if (!headers_sent()) { |
|
| 189 | + echo '<!DOCTYPE html> |
|
| 182 | 190 | <html> |
| 183 | 191 | <head> |
| 184 | 192 | <title>', htmlspecialchars($_GET['pass_string']), '</title> |
@@ -187,14 +195,16 @@ discard block |
||
| 187 | 195 | <strong>', htmlspecialchars($_GET['pass_string']), '</strong> |
| 188 | 196 | </body> |
| 189 | 197 | </html>'; |
| 198 | + } |
|
| 190 | 199 | exit; |
| 191 | 200 | } |
| 192 | 201 | |
| 193 | 202 | // Add slashes, as long as they aren't already being added. |
| 194 | - if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0) |
|
| 195 | - foreach ($_POST as $k => $v) |
|
| 203 | + if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0) { |
|
| 204 | + foreach ($_POST as $k => $v) |
|
| 196 | 205 | if (strpos($k, 'password') === false && strpos($k, 'db_passwd') === false) |
| 197 | 206 | $_POST[$k] = addslashes($v); |
| 207 | + } |
|
| 198 | 208 | |
| 199 | 209 | // This is really quite simple; if ?delete is on the URL, delete the installer... |
| 200 | 210 | if (isset($_GET['delete'])) |
@@ -215,8 +225,7 @@ discard block |
||
| 215 | 225 | $ftp->close(); |
| 216 | 226 | |
| 217 | 227 | unset($_SESSION['installer_temp_ftp']); |
| 218 | - } |
|
| 219 | - else |
|
| 228 | + } else |
|
| 220 | 229 | { |
| 221 | 230 | @unlink(__FILE__); |
| 222 | 231 | |
@@ -237,10 +246,11 @@ discard block |
||
| 237 | 246 | { |
| 238 | 247 | // Get PHP's default timezone, if set |
| 239 | 248 | $ini_tz = ini_get('date.timezone'); |
| 240 | - if (!empty($ini_tz)) |
|
| 241 | - $timezone_id = $ini_tz; |
|
| 242 | - else |
|
| 243 | - $timezone_id = ''; |
|
| 249 | + if (!empty($ini_tz)) { |
|
| 250 | + $timezone_id = $ini_tz; |
|
| 251 | + } else { |
|
| 252 | + $timezone_id = ''; |
|
| 253 | + } |
|
| 244 | 254 | |
| 245 | 255 | // If date.timezone is unset, invalid, or just plain weird, make a best guess |
| 246 | 256 | if (!in_array($timezone_id, timezone_identifiers_list())) |
@@ -270,8 +280,9 @@ discard block |
||
| 270 | 280 | $dir = dir(dirname(__FILE__) . '/Themes/default/languages'); |
| 271 | 281 | while ($entry = $dir->read()) |
| 272 | 282 | { |
| 273 | - if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') |
|
| 274 | - $incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12)); |
|
| 283 | + if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') { |
|
| 284 | + $incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12)); |
|
| 285 | + } |
|
| 275 | 286 | } |
| 276 | 287 | $dir->close(); |
| 277 | 288 | } |
@@ -306,10 +317,11 @@ discard block |
||
| 306 | 317 | } |
| 307 | 318 | |
| 308 | 319 | // Override the language file? |
| 309 | - if (isset($_GET['lang_file'])) |
|
| 310 | - $_SESSION['installer_temp_lang'] = $_GET['lang_file']; |
|
| 311 | - elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) |
|
| 312 | - $_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file']; |
|
| 320 | + if (isset($_GET['lang_file'])) { |
|
| 321 | + $_SESSION['installer_temp_lang'] = $_GET['lang_file']; |
|
| 322 | + } elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) { |
|
| 323 | + $_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file']; |
|
| 324 | + } |
|
| 313 | 325 | |
| 314 | 326 | // Make sure it exists, if it doesn't reset it. |
| 315 | 327 | if (!isset($_SESSION['installer_temp_lang']) || preg_match('~[^\\w_\\-.]~', $_SESSION['installer_temp_lang']) === 1 || !file_exists(dirname(__FILE__) . '/Themes/default/languages/' . $_SESSION['installer_temp_lang'])) |
@@ -318,8 +330,9 @@ discard block |
||
| 318 | 330 | list ($_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']); |
| 319 | 331 | |
| 320 | 332 | // If we have english and some other language, use the other language. We Americans hate english :P. |
| 321 | - if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) |
|
| 322 | - list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']); |
|
| 333 | + if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) { |
|
| 334 | + list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']); |
|
| 335 | + } |
|
| 323 | 336 | } |
| 324 | 337 | |
| 325 | 338 | // And now include the actual language file itself. |
@@ -332,15 +345,18 @@ discard block |
||
| 332 | 345 | global $db_prefix, $db_connection, $sourcedir, $smcFunc, $modSettings; |
| 333 | 346 | global $db_server, $db_passwd, $db_type, $db_name, $db_user, $db_persist; |
| 334 | 347 | |
| 335 | - if (empty($sourcedir)) |
|
| 336 | - $sourcedir = dirname(__FILE__) . '/Sources'; |
|
| 348 | + if (empty($sourcedir)) { |
|
| 349 | + $sourcedir = dirname(__FILE__) . '/Sources'; |
|
| 350 | + } |
|
| 337 | 351 | |
| 338 | 352 | // Need this to check whether we need the database password. |
| 339 | 353 | require(dirname(__FILE__) . '/Settings.php'); |
| 340 | - if (!defined('SMF')) |
|
| 341 | - define('SMF', 1); |
|
| 342 | - if (empty($smcFunc)) |
|
| 343 | - $smcFunc = array(); |
|
| 354 | + if (!defined('SMF')) { |
|
| 355 | + define('SMF', 1); |
|
| 356 | + } |
|
| 357 | + if (empty($smcFunc)) { |
|
| 358 | + $smcFunc = array(); |
|
| 359 | + } |
|
| 344 | 360 | |
| 345 | 361 | $modSettings['disableQueryCheck'] = true; |
| 346 | 362 | |
@@ -348,8 +364,9 @@ discard block |
||
| 348 | 364 | if (!$db_connection) |
| 349 | 365 | { |
| 350 | 366 | require_once($sourcedir . '/Subs-Db-' . $db_type . '.php'); |
| 351 | - if (version_compare(PHP_VERSION, '5', '<')) |
|
| 352 | - require_once($sourcedir . '/Subs-Compat.php'); |
|
| 367 | + if (version_compare(PHP_VERSION, '5', '<')) { |
|
| 368 | + require_once($sourcedir . '/Subs-Compat.php'); |
|
| 369 | + } |
|
| 353 | 370 | |
| 354 | 371 | $db_options = array('persist' => $db_persist); |
| 355 | 372 | $port = ''; |
@@ -360,19 +377,20 @@ discard block |
||
| 360 | 377 | if ($db_type == 'mysql') |
| 361 | 378 | { |
| 362 | 379 | $port = ((int) $_POST['db_port'] == ini_get($db_type . 'default_port')) ? '' : (int) $_POST['db_port']; |
| 363 | - } |
|
| 364 | - elseif ($db_type == 'postgresql') |
|
| 380 | + } elseif ($db_type == 'postgresql') |
|
| 365 | 381 | { |
| 366 | 382 | // PostgreSQL doesn't have a default port setting in php.ini, so just check against the default |
| 367 | 383 | $port = ((int) $_POST['db_port'] == 5432) ? '' : (int) $_POST['db_port']; |
| 368 | 384 | } |
| 369 | 385 | } |
| 370 | 386 | |
| 371 | - if (!empty($port)) |
|
| 372 | - $db_options['port'] = $port; |
|
| 387 | + if (!empty($port)) { |
|
| 388 | + $db_options['port'] = $port; |
|
| 389 | + } |
|
| 373 | 390 | |
| 374 | - if (!$db_connection) |
|
| 375 | - $db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options); |
|
| 391 | + if (!$db_connection) { |
|
| 392 | + $db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options); |
|
| 393 | + } |
|
| 376 | 394 | } |
| 377 | 395 | } |
| 378 | 396 | |
@@ -400,8 +418,9 @@ discard block |
||
| 400 | 418 | // @todo REMOVE THIS!! |
| 401 | 419 | else |
| 402 | 420 | { |
| 403 | - if (function_exists('doStep' . $_GET['step'])) |
|
| 404 | - call_user_func('doStep' . $_GET['step']); |
|
| 421 | + if (function_exists('doStep' . $_GET['step'])) { |
|
| 422 | + call_user_func('doStep' . $_GET['step']); |
|
| 423 | + } |
|
| 405 | 424 | } |
| 406 | 425 | // Show the footer. |
| 407 | 426 | template_install_below(); |
@@ -419,8 +438,9 @@ discard block |
||
| 419 | 438 | $incontext['sub_template'] = 'welcome_message'; |
| 420 | 439 | |
| 421 | 440 | // Done the submission? |
| 422 | - if (isset($_POST['contbutt'])) |
|
| 423 | - return true; |
|
| 441 | + if (isset($_POST['contbutt'])) { |
|
| 442 | + return true; |
|
| 443 | + } |
|
| 424 | 444 | |
| 425 | 445 | // See if we think they have already installed it? |
| 426 | 446 | if (is_readable(dirname(__FILE__) . '/Settings.php')) |
@@ -428,14 +448,17 @@ discard block |
||
| 428 | 448 | $probably_installed = 0; |
| 429 | 449 | foreach (file(dirname(__FILE__) . '/Settings.php') as $line) |
| 430 | 450 | { |
| 431 | - if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line)) |
|
| 432 | - $probably_installed++; |
|
| 433 | - if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line)) |
|
| 434 | - $probably_installed++; |
|
| 451 | + if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line)) { |
|
| 452 | + $probably_installed++; |
|
| 453 | + } |
|
| 454 | + if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line)) { |
|
| 455 | + $probably_installed++; |
|
| 456 | + } |
|
| 435 | 457 | } |
| 436 | 458 | |
| 437 | - if ($probably_installed == 2) |
|
| 438 | - $incontext['warning'] = $txt['error_already_installed']; |
|
| 459 | + if ($probably_installed == 2) { |
|
| 460 | + $incontext['warning'] = $txt['error_already_installed']; |
|
| 461 | + } |
|
| 439 | 462 | } |
| 440 | 463 | |
| 441 | 464 | // Is some database support even compiled in? |
@@ -450,45 +473,54 @@ discard block |
||
| 450 | 473 | $databases[$key]['supported'] = false; |
| 451 | 474 | $notFoundSQLFile = true; |
| 452 | 475 | $txt['error_db_script_missing'] = sprintf($txt['error_db_script_missing'], 'install_' . $GLOBALS['db_script_version'] . '_' . $type . '.sql'); |
| 476 | + } else { |
|
| 477 | + $incontext['supported_databases'][] = $db; |
|
| 453 | 478 | } |
| 454 | - else |
|
| 455 | - $incontext['supported_databases'][] = $db; |
|
| 456 | 479 | } |
| 457 | 480 | } |
| 458 | 481 | |
| 459 | 482 | // Check the PHP version. |
| 460 | - if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>='))) |
|
| 461 | - $error = 'error_php_too_low'; |
|
| 483 | + if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>='))) { |
|
| 484 | + $error = 'error_php_too_low'; |
|
| 485 | + } |
|
| 462 | 486 | // Make sure we have a supported database |
| 463 | - elseif (empty($incontext['supported_databases'])) |
|
| 464 | - $error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing'; |
|
| 487 | + elseif (empty($incontext['supported_databases'])) { |
|
| 488 | + $error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing'; |
|
| 489 | + } |
|
| 465 | 490 | // How about session support? Some crazy sysadmin remove it? |
| 466 | - elseif (!function_exists('session_start')) |
|
| 467 | - $error = 'error_session_missing'; |
|
| 491 | + elseif (!function_exists('session_start')) { |
|
| 492 | + $error = 'error_session_missing'; |
|
| 493 | + } |
|
| 468 | 494 | // Make sure they uploaded all the files. |
| 469 | - elseif (!file_exists(dirname(__FILE__) . '/index.php')) |
|
| 470 | - $error = 'error_missing_files'; |
|
| 495 | + elseif (!file_exists(dirname(__FILE__) . '/index.php')) { |
|
| 496 | + $error = 'error_missing_files'; |
|
| 497 | + } |
|
| 471 | 498 | // Very simple check on the session.save_path for Windows. |
| 472 | 499 | // @todo Move this down later if they don't use database-driven sessions? |
| 473 | - elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\') |
|
| 474 | - $error = 'error_session_save_path'; |
|
| 500 | + elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\') { |
|
| 501 | + $error = 'error_session_save_path'; |
|
| 502 | + } |
|
| 475 | 503 | |
| 476 | 504 | // Since each of the three messages would look the same, anyway... |
| 477 | - if (isset($error)) |
|
| 478 | - $incontext['error'] = $txt[$error]; |
|
| 505 | + if (isset($error)) { |
|
| 506 | + $incontext['error'] = $txt[$error]; |
|
| 507 | + } |
|
| 479 | 508 | |
| 480 | 509 | // Mod_security blocks everything that smells funny. Let SMF handle security. |
| 481 | - if (!fixModSecurity() && !isset($_GET['overmodsecurity'])) |
|
| 482 | - $incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again']; |
|
| 510 | + if (!fixModSecurity() && !isset($_GET['overmodsecurity'])) { |
|
| 511 | + $incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again']; |
|
| 512 | + } |
|
| 483 | 513 | |
| 484 | 514 | // Confirm mbstring is loaded... |
| 485 | - if (!extension_loaded('mbstring')) |
|
| 486 | - $incontext['error'] = $txt['install_no_mbstring']; |
|
| 515 | + if (!extension_loaded('mbstring')) { |
|
| 516 | + $incontext['error'] = $txt['install_no_mbstring']; |
|
| 517 | + } |
|
| 487 | 518 | |
| 488 | 519 | // Check for https stream support. |
| 489 | 520 | $supported_streams = stream_get_wrappers(); |
| 490 | - if (!in_array('https', $supported_streams)) |
|
| 491 | - $incontext['warning'] = $txt['install_no_https']; |
|
| 521 | + if (!in_array('https', $supported_streams)) { |
|
| 522 | + $incontext['warning'] = $txt['install_no_https']; |
|
| 523 | + } |
|
| 492 | 524 | |
| 493 | 525 | return false; |
| 494 | 526 | } |
@@ -514,12 +546,14 @@ discard block |
||
| 514 | 546 | 'db_last_error.php', |
| 515 | 547 | ); |
| 516 | 548 | |
| 517 | - foreach ($incontext['detected_languages'] as $lang => $temp) |
|
| 518 | - $extra_files[] = 'Themes/default/languages/' . $lang; |
|
| 549 | + foreach ($incontext['detected_languages'] as $lang => $temp) { |
|
| 550 | + $extra_files[] = 'Themes/default/languages/' . $lang; |
|
| 551 | + } |
|
| 519 | 552 | |
| 520 | 553 | // With mod_security installed, we could attempt to fix it with .htaccess. |
| 521 | - if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules())) |
|
| 522 | - $writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.'; |
|
| 554 | + if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules())) { |
|
| 555 | + $writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.'; |
|
| 556 | + } |
|
| 523 | 557 | |
| 524 | 558 | $failed_files = array(); |
| 525 | 559 | |
@@ -531,20 +565,23 @@ discard block |
||
| 531 | 565 | foreach ($writable_files as $file) |
| 532 | 566 | { |
| 533 | 567 | // Some files won't exist, try to address up front |
| 534 | - if (!file_exists(dirname(__FILE__) . '/' . $file)) |
|
| 535 | - @touch(dirname(__FILE__) . '/' . $file); |
|
| 568 | + if (!file_exists(dirname(__FILE__) . '/' . $file)) { |
|
| 569 | + @touch(dirname(__FILE__) . '/' . $file); |
|
| 570 | + } |
|
| 536 | 571 | // NOW do the writable check... |
| 537 | 572 | if (!is_writable(dirname(__FILE__) . '/' . $file)) |
| 538 | 573 | { |
| 539 | 574 | @chmod(dirname(__FILE__) . '/' . $file, 0755); |
| 540 | 575 | |
| 541 | 576 | // Well, 755 hopefully worked... if not, try 777. |
| 542 | - if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777)) |
|
| 543 | - $failed_files[] = $file; |
|
| 577 | + if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777)) { |
|
| 578 | + $failed_files[] = $file; |
|
| 579 | + } |
|
| 544 | 580 | } |
| 545 | 581 | } |
| 546 | - foreach ($extra_files as $file) |
|
| 547 | - @chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777); |
|
| 582 | + foreach ($extra_files as $file) { |
|
| 583 | + @chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777); |
|
| 584 | + } |
|
| 548 | 585 | } |
| 549 | 586 | // Windows is trickier. Let's try opening for r+... |
| 550 | 587 | else |
@@ -554,30 +591,35 @@ discard block |
||
| 554 | 591 | foreach ($writable_files as $file) |
| 555 | 592 | { |
| 556 | 593 | // Folders can't be opened for write... but the index.php in them can ;) |
| 557 | - if (is_dir(dirname(__FILE__) . '/' . $file)) |
|
| 558 | - $file .= '/index.php'; |
|
| 594 | + if (is_dir(dirname(__FILE__) . '/' . $file)) { |
|
| 595 | + $file .= '/index.php'; |
|
| 596 | + } |
|
| 559 | 597 | |
| 560 | 598 | // Funny enough, chmod actually does do something on windows - it removes the read only attribute. |
| 561 | 599 | @chmod(dirname(__FILE__) . '/' . $file, 0777); |
| 562 | 600 | $fp = @fopen(dirname(__FILE__) . '/' . $file, 'r+'); |
| 563 | 601 | |
| 564 | 602 | // Hmm, okay, try just for write in that case... |
| 565 | - if (!is_resource($fp)) |
|
| 566 | - $fp = @fopen(dirname(__FILE__) . '/' . $file, 'w'); |
|
| 603 | + if (!is_resource($fp)) { |
|
| 604 | + $fp = @fopen(dirname(__FILE__) . '/' . $file, 'w'); |
|
| 605 | + } |
|
| 567 | 606 | |
| 568 | - if (!is_resource($fp)) |
|
| 569 | - $failed_files[] = $file; |
|
| 607 | + if (!is_resource($fp)) { |
|
| 608 | + $failed_files[] = $file; |
|
| 609 | + } |
|
| 570 | 610 | |
| 571 | 611 | @fclose($fp); |
| 572 | 612 | } |
| 573 | - foreach ($extra_files as $file) |
|
| 574 | - @chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777); |
|
| 613 | + foreach ($extra_files as $file) { |
|
| 614 | + @chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777); |
|
| 615 | + } |
|
| 575 | 616 | } |
| 576 | 617 | |
| 577 | 618 | $failure = count($failed_files) >= 1; |
| 578 | 619 | |
| 579 | - if (!isset($_SERVER)) |
|
| 580 | - return !$failure; |
|
| 620 | + if (!isset($_SERVER)) { |
|
| 621 | + return !$failure; |
|
| 622 | + } |
|
| 581 | 623 | |
| 582 | 624 | // Put the list into context. |
| 583 | 625 | $incontext['failed_files'] = $failed_files; |
@@ -625,19 +667,23 @@ discard block |
||
| 625 | 667 | |
| 626 | 668 | if (!isset($ftp) || $ftp->error !== false) |
| 627 | 669 | { |
| 628 | - if (!isset($ftp)) |
|
| 629 | - $ftp = new ftp_connection(null); |
|
| 670 | + if (!isset($ftp)) { |
|
| 671 | + $ftp = new ftp_connection(null); |
|
| 672 | + } |
|
| 630 | 673 | // Save the error so we can mess with listing... |
| 631 | - elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message)) |
|
| 632 | - $incontext['ftp_errors'][] = $ftp->last_message; |
|
| 674 | + elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message)) { |
|
| 675 | + $incontext['ftp_errors'][] = $ftp->last_message; |
|
| 676 | + } |
|
| 633 | 677 | |
| 634 | 678 | list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__)); |
| 635 | 679 | |
| 636 | - if (empty($_POST['ftp_path']) && $found_path) |
|
| 637 | - $_POST['ftp_path'] = $detect_path; |
|
| 680 | + if (empty($_POST['ftp_path']) && $found_path) { |
|
| 681 | + $_POST['ftp_path'] = $detect_path; |
|
| 682 | + } |
|
| 638 | 683 | |
| 639 | - if (!isset($_POST['ftp_username'])) |
|
| 640 | - $_POST['ftp_username'] = $username; |
|
| 684 | + if (!isset($_POST['ftp_username'])) { |
|
| 685 | + $_POST['ftp_username'] = $username; |
|
| 686 | + } |
|
| 641 | 687 | |
| 642 | 688 | // Set the username etc, into context. |
| 643 | 689 | $incontext['ftp'] = array( |
@@ -649,8 +695,7 @@ discard block |
||
| 649 | 695 | ); |
| 650 | 696 | |
| 651 | 697 | return false; |
| 652 | - } |
|
| 653 | - else |
|
| 698 | + } else |
|
| 654 | 699 | { |
| 655 | 700 | $_SESSION['installer_temp_ftp'] = array( |
| 656 | 701 | 'server' => $_POST['ftp_server'], |
@@ -664,10 +709,12 @@ discard block |
||
| 664 | 709 | |
| 665 | 710 | foreach ($failed_files as $file) |
| 666 | 711 | { |
| 667 | - if (!is_writable(dirname(__FILE__) . '/' . $file)) |
|
| 668 | - $ftp->chmod($file, 0755); |
|
| 669 | - if (!is_writable(dirname(__FILE__) . '/' . $file)) |
|
| 670 | - $ftp->chmod($file, 0777); |
|
| 712 | + if (!is_writable(dirname(__FILE__) . '/' . $file)) { |
|
| 713 | + $ftp->chmod($file, 0755); |
|
| 714 | + } |
|
| 715 | + if (!is_writable(dirname(__FILE__) . '/' . $file)) { |
|
| 716 | + $ftp->chmod($file, 0777); |
|
| 717 | + } |
|
| 671 | 718 | if (!is_writable(dirname(__FILE__) . '/' . $file)) |
| 672 | 719 | { |
| 673 | 720 | $failed_files_updated[] = $file; |
@@ -723,15 +770,17 @@ discard block |
||
| 723 | 770 | |
| 724 | 771 | if (!$foundOne) |
| 725 | 772 | { |
| 726 | - if (isset($db['default_host'])) |
|
| 727 | - $incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost'; |
|
| 773 | + if (isset($db['default_host'])) { |
|
| 774 | + $incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost'; |
|
| 775 | + } |
|
| 728 | 776 | if (isset($db['default_user'])) |
| 729 | 777 | { |
| 730 | 778 | $incontext['db']['user'] = ini_get($db['default_user']); |
| 731 | 779 | $incontext['db']['name'] = ini_get($db['default_user']); |
| 732 | 780 | } |
| 733 | - if (isset($db['default_password'])) |
|
| 734 | - $incontext['db']['pass'] = ini_get($db['default_password']); |
|
| 781 | + if (isset($db['default_password'])) { |
|
| 782 | + $incontext['db']['pass'] = ini_get($db['default_password']); |
|
| 783 | + } |
|
| 735 | 784 | |
| 736 | 785 | // For simplicity and less confusion, leave the port blank by default |
| 737 | 786 | $incontext['db']['port'] = ''; |
@@ -750,10 +799,10 @@ discard block |
||
| 750 | 799 | $incontext['db']['server'] = $_POST['db_server']; |
| 751 | 800 | $incontext['db']['prefix'] = $_POST['db_prefix']; |
| 752 | 801 | |
| 753 | - if (!empty($_POST['db_port'])) |
|
| 754 | - $incontext['db']['port'] = $_POST['db_port']; |
|
| 755 | - } |
|
| 756 | - else |
|
| 802 | + if (!empty($_POST['db_port'])) { |
|
| 803 | + $incontext['db']['port'] = $_POST['db_port']; |
|
| 804 | + } |
|
| 805 | + } else |
|
| 757 | 806 | { |
| 758 | 807 | $incontext['db']['prefix'] = 'smf_'; |
| 759 | 808 | } |
@@ -789,10 +838,11 @@ discard block |
||
| 789 | 838 | if (!empty($_POST['db_port'])) |
| 790 | 839 | { |
| 791 | 840 | // For MySQL, we can get the "default port" from PHP. PostgreSQL has no such option though. |
| 792 | - if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port')) |
|
| 793 | - $vars['db_port'] = (int) $_POST['db_port']; |
|
| 794 | - elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432) |
|
| 795 | - $vars['db_port'] = (int) $_POST['db_port']; |
|
| 841 | + if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port')) { |
|
| 842 | + $vars['db_port'] = (int) $_POST['db_port']; |
|
| 843 | + } elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432) { |
|
| 844 | + $vars['db_port'] = (int) $_POST['db_port']; |
|
| 845 | + } |
|
| 796 | 846 | } |
| 797 | 847 | |
| 798 | 848 | // God I hope it saved! |
@@ -805,8 +855,9 @@ discard block |
||
| 805 | 855 | // Make sure it works. |
| 806 | 856 | require(dirname(__FILE__) . '/Settings.php'); |
| 807 | 857 | |
| 808 | - if (empty($sourcedir)) |
|
| 809 | - $sourcedir = dirname(__FILE__) . '/Sources'; |
|
| 858 | + if (empty($sourcedir)) { |
|
| 859 | + $sourcedir = dirname(__FILE__) . '/Sources'; |
|
| 860 | + } |
|
| 810 | 861 | |
| 811 | 862 | // Better find the database file! |
| 812 | 863 | if (!file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) |
@@ -816,18 +867,21 @@ discard block |
||
| 816 | 867 | } |
| 817 | 868 | |
| 818 | 869 | // Now include it for database functions! |
| 819 | - if (!defined('SMF')) |
|
| 820 | - define('SMF', 1); |
|
| 870 | + if (!defined('SMF')) { |
|
| 871 | + define('SMF', 1); |
|
| 872 | + } |
|
| 821 | 873 | |
| 822 | 874 | $modSettings['disableQueryCheck'] = true; |
| 823 | - if (empty($smcFunc)) |
|
| 824 | - $smcFunc = array(); |
|
| 875 | + if (empty($smcFunc)) { |
|
| 876 | + $smcFunc = array(); |
|
| 877 | + } |
|
| 825 | 878 | |
| 826 | 879 | require_once($sourcedir . '/Subs-Db-' . $db_type . '.php'); |
| 827 | 880 | |
| 828 | 881 | // What - running PHP4? The shame! |
| 829 | - if (version_compare(PHP_VERSION, '5', '<')) |
|
| 830 | - require_once($sourcedir . '/Subs-Compat.php'); |
|
| 882 | + if (version_compare(PHP_VERSION, '5', '<')) { |
|
| 883 | + require_once($sourcedir . '/Subs-Compat.php'); |
|
| 884 | + } |
|
| 831 | 885 | |
| 832 | 886 | // Attempt a connection. |
| 833 | 887 | $needsDB = !empty($databases[$db_type]['always_has_db']); |
@@ -915,12 +969,14 @@ discard block |
||
| 915 | 969 | $incontext['page_title'] = $txt['install_settings']; |
| 916 | 970 | |
| 917 | 971 | // Let's see if we got the database type correct. |
| 918 | - if (isset($_POST['db_type'], $databases[$_POST['db_type']])) |
|
| 919 | - $db_type = $_POST['db_type']; |
|
| 972 | + if (isset($_POST['db_type'], $databases[$_POST['db_type']])) { |
|
| 973 | + $db_type = $_POST['db_type']; |
|
| 974 | + } |
|
| 920 | 975 | |
| 921 | 976 | // Else we'd better be able to get the connection. |
| 922 | - else |
|
| 923 | - load_database(); |
|
| 977 | + else { |
|
| 978 | + load_database(); |
|
| 979 | + } |
|
| 924 | 980 | |
| 925 | 981 | $db_type = isset($_POST['db_type']) ? $_POST['db_type'] : $db_type; |
| 926 | 982 | |
@@ -957,18 +1013,21 @@ discard block |
||
| 957 | 1013 | // Submitting? |
| 958 | 1014 | if (isset($_POST['boardurl'])) |
| 959 | 1015 | { |
| 960 | - if (substr($_POST['boardurl'], -10) == '/index.php') |
|
| 961 | - $_POST['boardurl'] = substr($_POST['boardurl'], 0, -10); |
|
| 962 | - elseif (substr($_POST['boardurl'], -1) == '/') |
|
| 963 | - $_POST['boardurl'] = substr($_POST['boardurl'], 0, -1); |
|
| 964 | - if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') |
|
| 965 | - $_POST['boardurl'] = 'http://' . $_POST['boardurl']; |
|
| 1016 | + if (substr($_POST['boardurl'], -10) == '/index.php') { |
|
| 1017 | + $_POST['boardurl'] = substr($_POST['boardurl'], 0, -10); |
|
| 1018 | + } elseif (substr($_POST['boardurl'], -1) == '/') { |
|
| 1019 | + $_POST['boardurl'] = substr($_POST['boardurl'], 0, -1); |
|
| 1020 | + } |
|
| 1021 | + if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') { |
|
| 1022 | + $_POST['boardurl'] = 'http://' . $_POST['boardurl']; |
|
| 1023 | + } |
|
| 966 | 1024 | |
| 967 | 1025 | //Make sure boardurl is aligned with ssl setting |
| 968 | - if (empty($_POST['force_ssl'])) |
|
| 969 | - $_POST['boardurl'] = strtr($_POST['boardurl'], array('https://' => 'http://')); |
|
| 970 | - else |
|
| 971 | - $_POST['boardurl'] = strtr($_POST['boardurl'], array('http://' => 'https://')); |
|
| 1026 | + if (empty($_POST['force_ssl'])) { |
|
| 1027 | + $_POST['boardurl'] = strtr($_POST['boardurl'], array('https://' => 'http://')); |
|
| 1028 | + } else { |
|
| 1029 | + $_POST['boardurl'] = strtr($_POST['boardurl'], array('http://' => 'https://')); |
|
| 1030 | + } |
|
| 972 | 1031 | |
| 973 | 1032 | // Save these variables. |
| 974 | 1033 | $vars = array( |
@@ -1007,10 +1066,10 @@ discard block |
||
| 1007 | 1066 | { |
| 1008 | 1067 | $incontext['error'] = sprintf($txt['error_utf8_version'], $databases[$db_type]['utf8_version']); |
| 1009 | 1068 | return false; |
| 1010 | - } |
|
| 1011 | - else |
|
| 1012 | - // Set the character set here. |
|
| 1069 | + } else { |
|
| 1070 | + // Set the character set here. |
|
| 1013 | 1071 | updateSettingsFile(array('db_character_set' => 'utf8')); |
| 1072 | + } |
|
| 1014 | 1073 | } |
| 1015 | 1074 | |
| 1016 | 1075 | // Good, skip on. |
@@ -1030,8 +1089,9 @@ discard block |
||
| 1030 | 1089 | $incontext['continue'] = 1; |
| 1031 | 1090 | |
| 1032 | 1091 | // Already done? |
| 1033 | - if (isset($_POST['pop_done'])) |
|
| 1034 | - return true; |
|
| 1092 | + if (isset($_POST['pop_done'])) { |
|
| 1093 | + return true; |
|
| 1094 | + } |
|
| 1035 | 1095 | |
| 1036 | 1096 | // Reload settings. |
| 1037 | 1097 | require(dirname(__FILE__) . '/Settings.php'); |
@@ -1049,8 +1109,9 @@ discard block |
||
| 1049 | 1109 | $modSettings = array(); |
| 1050 | 1110 | if ($result !== false) |
| 1051 | 1111 | { |
| 1052 | - while ($row = $smcFunc['db_fetch_assoc']($result)) |
|
| 1053 | - $modSettings[$row['variable']] = $row['value']; |
|
| 1112 | + while ($row = $smcFunc['db_fetch_assoc']($result)) { |
|
| 1113 | + $modSettings[$row['variable']] = $row['value']; |
|
| 1114 | + } |
|
| 1054 | 1115 | $smcFunc['db_free_result']($result); |
| 1055 | 1116 | |
| 1056 | 1117 | // Do they match? If so, this is just a refresh so charge on! |
@@ -1063,20 +1124,22 @@ discard block |
||
| 1063 | 1124 | $modSettings['disableQueryCheck'] = true; |
| 1064 | 1125 | |
| 1065 | 1126 | // If doing UTF8, select it. PostgreSQL requires passing it as a string... |
| 1066 | - if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support'])) |
|
| 1067 | - $smcFunc['db_query']('', ' |
|
| 1127 | + if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support'])) { |
|
| 1128 | + $smcFunc['db_query']('', ' |
|
| 1068 | 1129 | SET NAMES {string:utf8}', |
| 1069 | 1130 | array( |
| 1070 | 1131 | 'db_error_skip' => true, |
| 1071 | 1132 | 'utf8' => 'utf8', |
| 1072 | 1133 | ) |
| 1073 | 1134 | ); |
| 1135 | + } |
|
| 1074 | 1136 | |
| 1075 | 1137 | // Windows likes to leave the trailing slash, which yields to C:\path\to\SMF\/attachments... |
| 1076 | - if (substr(__DIR__, -1) == '\\') |
|
| 1077 | - $attachdir = __DIR__ . 'attachments'; |
|
| 1078 | - else |
|
| 1079 | - $attachdir = __DIR__ . '/attachments'; |
|
| 1138 | + if (substr(__DIR__, -1) == '\\') { |
|
| 1139 | + $attachdir = __DIR__ . 'attachments'; |
|
| 1140 | + } else { |
|
| 1141 | + $attachdir = __DIR__ . '/attachments'; |
|
| 1142 | + } |
|
| 1080 | 1143 | |
| 1081 | 1144 | $replaces = array( |
| 1082 | 1145 | '{$db_prefix}' => $db_prefix, |
@@ -1093,8 +1156,9 @@ discard block |
||
| 1093 | 1156 | |
| 1094 | 1157 | foreach ($txt as $key => $value) |
| 1095 | 1158 | { |
| 1096 | - if (substr($key, 0, 8) == 'default_') |
|
| 1097 | - $replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value); |
|
| 1159 | + if (substr($key, 0, 8) == 'default_') { |
|
| 1160 | + $replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value); |
|
| 1161 | + } |
|
| 1098 | 1162 | } |
| 1099 | 1163 | $replaces['{$default_reserved_names}'] = strtr($replaces['{$default_reserved_names}'], array('\\\\n' => '\\n')); |
| 1100 | 1164 | |
@@ -1109,8 +1173,9 @@ discard block |
||
| 1109 | 1173 | |
| 1110 | 1174 | while ($row = $smcFunc['db_fetch_assoc']($get_engines)) |
| 1111 | 1175 | { |
| 1112 | - if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') |
|
| 1113 | - $engines[] = $row['Engine']; |
|
| 1176 | + if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') { |
|
| 1177 | + $engines[] = $row['Engine']; |
|
| 1178 | + } |
|
| 1114 | 1179 | } |
| 1115 | 1180 | |
| 1116 | 1181 | // Done with this now |
@@ -1134,8 +1199,7 @@ discard block |
||
| 1134 | 1199 | $replaces['START TRANSACTION;'] = ''; |
| 1135 | 1200 | $replaces['COMMIT;'] = ''; |
| 1136 | 1201 | } |
| 1137 | - } |
|
| 1138 | - else |
|
| 1202 | + } else |
|
| 1139 | 1203 | { |
| 1140 | 1204 | $has_innodb = false; |
| 1141 | 1205 | } |
@@ -1157,21 +1221,24 @@ discard block |
||
| 1157 | 1221 | foreach ($sql_lines as $count => $line) |
| 1158 | 1222 | { |
| 1159 | 1223 | // No comments allowed! |
| 1160 | - if (substr(trim($line), 0, 1) != '#') |
|
| 1161 | - $current_statement .= "\n" . rtrim($line); |
|
| 1224 | + if (substr(trim($line), 0, 1) != '#') { |
|
| 1225 | + $current_statement .= "\n" . rtrim($line); |
|
| 1226 | + } |
|
| 1162 | 1227 | |
| 1163 | 1228 | // Is this the end of the query string? |
| 1164 | - if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines))) |
|
| 1165 | - continue; |
|
| 1229 | + if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines))) { |
|
| 1230 | + continue; |
|
| 1231 | + } |
|
| 1166 | 1232 | |
| 1167 | 1233 | // Does this table already exist? If so, don't insert more data into it! |
| 1168 | 1234 | if (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) != 0 && in_array($match[1], $exists)) |
| 1169 | 1235 | { |
| 1170 | 1236 | preg_match_all('~\)[,;]~', $current_statement, $matches); |
| 1171 | - if (!empty($matches[0])) |
|
| 1172 | - $incontext['sql_results']['insert_dups'] += count($matches[0]); |
|
| 1173 | - else |
|
| 1174 | - $incontext['sql_results']['insert_dups']++; |
|
| 1237 | + if (!empty($matches[0])) { |
|
| 1238 | + $incontext['sql_results']['insert_dups'] += count($matches[0]); |
|
| 1239 | + } else { |
|
| 1240 | + $incontext['sql_results']['insert_dups']++; |
|
| 1241 | + } |
|
| 1175 | 1242 | |
| 1176 | 1243 | $current_statement = ''; |
| 1177 | 1244 | continue; |
@@ -1180,8 +1247,9 @@ discard block |
||
| 1180 | 1247 | if ($smcFunc['db_query']('', $current_statement, array('security_override' => true, 'db_error_skip' => true), $db_connection) === false) |
| 1181 | 1248 | { |
| 1182 | 1249 | // Use the appropriate function based on the DB type |
| 1183 | - if ($db_type == 'mysql' || $db_type == 'mysqli') |
|
| 1184 | - $db_errorno = $db_type . '_errno'; |
|
| 1250 | + if ($db_type == 'mysql' || $db_type == 'mysqli') { |
|
| 1251 | + $db_errorno = $db_type . '_errno'; |
|
| 1252 | + } |
|
| 1185 | 1253 | |
| 1186 | 1254 | // Error 1050: Table already exists! |
| 1187 | 1255 | // @todo Needs to be made better! |
@@ -1196,18 +1264,18 @@ discard block |
||
| 1196 | 1264 | // MySQLi requires a connection object. It's optional with MySQL and Postgres |
| 1197 | 1265 | $incontext['failures'][$count] = $smcFunc['db_error']($db_connection); |
| 1198 | 1266 | } |
| 1199 | - } |
|
| 1200 | - else |
|
| 1267 | + } else |
|
| 1201 | 1268 | { |
| 1202 | - if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1) |
|
| 1203 | - $incontext['sql_results']['tables']++; |
|
| 1204 | - elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1) |
|
| 1269 | + if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1) { |
|
| 1270 | + $incontext['sql_results']['tables']++; |
|
| 1271 | + } elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1) |
|
| 1205 | 1272 | { |
| 1206 | 1273 | preg_match_all('~\)[,;]~', $current_statement, $matches); |
| 1207 | - if (!empty($matches[0])) |
|
| 1208 | - $incontext['sql_results']['inserts'] += count($matches[0]); |
|
| 1209 | - else |
|
| 1210 | - $incontext['sql_results']['inserts']++; |
|
| 1274 | + if (!empty($matches[0])) { |
|
| 1275 | + $incontext['sql_results']['inserts'] += count($matches[0]); |
|
| 1276 | + } else { |
|
| 1277 | + $incontext['sql_results']['inserts']++; |
|
| 1278 | + } |
|
| 1211 | 1279 | } |
| 1212 | 1280 | } |
| 1213 | 1281 | |
@@ -1220,15 +1288,17 @@ discard block |
||
| 1220 | 1288 | // Sort out the context for the SQL. |
| 1221 | 1289 | foreach ($incontext['sql_results'] as $key => $number) |
| 1222 | 1290 | { |
| 1223 | - if ($number == 0) |
|
| 1224 | - unset($incontext['sql_results'][$key]); |
|
| 1225 | - else |
|
| 1226 | - $incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number); |
|
| 1291 | + if ($number == 0) { |
|
| 1292 | + unset($incontext['sql_results'][$key]); |
|
| 1293 | + } else { |
|
| 1294 | + $incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number); |
|
| 1295 | + } |
|
| 1227 | 1296 | } |
| 1228 | 1297 | |
| 1229 | 1298 | // Make sure UTF will be used globally. |
| 1230 | - if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8']))) |
|
| 1231 | - $newSettings[] = array('global_character_set', 'UTF-8'); |
|
| 1299 | + if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8']))) { |
|
| 1300 | + $newSettings[] = array('global_character_set', 'UTF-8'); |
|
| 1301 | + } |
|
| 1232 | 1302 | |
| 1233 | 1303 | // Maybe we can auto-detect better cookie settings? |
| 1234 | 1304 | preg_match('~^http[s]?://([^\.]+?)([^/]*?)(/.*)?$~', $boardurl, $matches); |
@@ -1239,16 +1309,20 @@ discard block |
||
| 1239 | 1309 | $globalCookies = false; |
| 1240 | 1310 | |
| 1241 | 1311 | // Okay... let's see. Using a subdomain other than www.? (not a perfect check.) |
| 1242 | - if ($matches[2] != '' && (strpos(substr($matches[2], 1), '.') === false || in_array($matches[1], array('forum', 'board', 'community', 'forums', 'support', 'chat', 'help', 'talk', 'boards', 'www')))) |
|
| 1243 | - $globalCookies = true; |
|
| 1312 | + if ($matches[2] != '' && (strpos(substr($matches[2], 1), '.') === false || in_array($matches[1], array('forum', 'board', 'community', 'forums', 'support', 'chat', 'help', 'talk', 'boards', 'www')))) { |
|
| 1313 | + $globalCookies = true; |
|
| 1314 | + } |
|
| 1244 | 1315 | // If there's a / in the middle of the path, or it starts with ~... we want local. |
| 1245 | - if (isset($matches[3]) && strlen($matches[3]) > 3 && (substr($matches[3], 0, 2) == '/~' || strpos(substr($matches[3], 1), '/') !== false)) |
|
| 1246 | - $localCookies = true; |
|
| 1316 | + if (isset($matches[3]) && strlen($matches[3]) > 3 && (substr($matches[3], 0, 2) == '/~' || strpos(substr($matches[3], 1), '/') !== false)) { |
|
| 1317 | + $localCookies = true; |
|
| 1318 | + } |
|
| 1247 | 1319 | |
| 1248 | - if ($globalCookies) |
|
| 1249 | - $newSettings[] = array('globalCookies', '1'); |
|
| 1250 | - if ($localCookies) |
|
| 1251 | - $newSettings[] = array('localCookies', '1'); |
|
| 1320 | + if ($globalCookies) { |
|
| 1321 | + $newSettings[] = array('globalCookies', '1'); |
|
| 1322 | + } |
|
| 1323 | + if ($localCookies) { |
|
| 1324 | + $newSettings[] = array('localCookies', '1'); |
|
| 1325 | + } |
|
| 1252 | 1326 | } |
| 1253 | 1327 | |
| 1254 | 1328 | // Are we allowing stat collection? |
@@ -1266,16 +1340,17 @@ discard block |
||
| 1266 | 1340 | fwrite($fp, $out); |
| 1267 | 1341 | |
| 1268 | 1342 | $return_data = ''; |
| 1269 | - while (!feof($fp)) |
|
| 1270 | - $return_data .= fgets($fp, 128); |
|
| 1343 | + while (!feof($fp)) { |
|
| 1344 | + $return_data .= fgets($fp, 128); |
|
| 1345 | + } |
|
| 1271 | 1346 | |
| 1272 | 1347 | fclose($fp); |
| 1273 | 1348 | |
| 1274 | 1349 | // Get the unique site ID. |
| 1275 | 1350 | preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID); |
| 1276 | 1351 | |
| 1277 | - if (!empty($ID[1])) |
|
| 1278 | - $smcFunc['db_insert']('replace', |
|
| 1352 | + if (!empty($ID[1])) { |
|
| 1353 | + $smcFunc['db_insert']('replace', |
|
| 1279 | 1354 | $db_prefix . 'settings', |
| 1280 | 1355 | array('variable' => 'string', 'value' => 'string'), |
| 1281 | 1356 | array( |
@@ -1284,11 +1359,12 @@ discard block |
||
| 1284 | 1359 | ), |
| 1285 | 1360 | array('variable') |
| 1286 | 1361 | ); |
| 1362 | + } |
|
| 1287 | 1363 | } |
| 1288 | 1364 | } |
| 1289 | 1365 | // Don't remove stat collection unless we unchecked the box for real, not from the loop. |
| 1290 | - elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) |
|
| 1291 | - $smcFunc['db_query']('', ' |
|
| 1366 | + elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) { |
|
| 1367 | + $smcFunc['db_query']('', ' |
|
| 1292 | 1368 | DELETE FROM {db_prefix}settings |
| 1293 | 1369 | WHERE variable = {string:enable_sm_stats}', |
| 1294 | 1370 | array( |
@@ -1296,20 +1372,23 @@ discard block |
||
| 1296 | 1372 | 'db_error_skip' => true, |
| 1297 | 1373 | ) |
| 1298 | 1374 | ); |
| 1375 | + } |
|
| 1299 | 1376 | |
| 1300 | 1377 | // Are we enabling SSL? |
| 1301 | - if (!empty($_POST['force_ssl'])) |
|
| 1302 | - $newSettings[] = array('force_ssl', 2); |
|
| 1378 | + if (!empty($_POST['force_ssl'])) { |
|
| 1379 | + $newSettings[] = array('force_ssl', 2); |
|
| 1380 | + } |
|
| 1303 | 1381 | |
| 1304 | 1382 | // Setting a timezone is required. |
| 1305 | 1383 | if (!isset($modSettings['default_timezone']) && function_exists('date_default_timezone_set')) |
| 1306 | 1384 | { |
| 1307 | 1385 | // Get PHP's default timezone, if set |
| 1308 | 1386 | $ini_tz = ini_get('date.timezone'); |
| 1309 | - if (!empty($ini_tz)) |
|
| 1310 | - $timezone_id = $ini_tz; |
|
| 1311 | - else |
|
| 1312 | - $timezone_id = ''; |
|
| 1387 | + if (!empty($ini_tz)) { |
|
| 1388 | + $timezone_id = $ini_tz; |
|
| 1389 | + } else { |
|
| 1390 | + $timezone_id = ''; |
|
| 1391 | + } |
|
| 1313 | 1392 | |
| 1314 | 1393 | // If date.timezone is unset, invalid, or just plain weird, make a best guess |
| 1315 | 1394 | if (!in_array($timezone_id, timezone_identifiers_list())) |
@@ -1318,8 +1397,9 @@ discard block |
||
| 1318 | 1397 | $timezone_id = timezone_name_from_abbr('', $server_offset, 0); |
| 1319 | 1398 | } |
| 1320 | 1399 | |
| 1321 | - if (date_default_timezone_set($timezone_id)) |
|
| 1322 | - $newSettings[] = array('default_timezone', $timezone_id); |
|
| 1400 | + if (date_default_timezone_set($timezone_id)) { |
|
| 1401 | + $newSettings[] = array('default_timezone', $timezone_id); |
|
| 1402 | + } |
|
| 1323 | 1403 | } |
| 1324 | 1404 | |
| 1325 | 1405 | if (!empty($newSettings)) |
@@ -1350,16 +1430,18 @@ discard block |
||
| 1350 | 1430 | } |
| 1351 | 1431 | |
| 1352 | 1432 | // MySQL specific stuff |
| 1353 | - if (substr($db_type, 0, 5) != 'mysql') |
|
| 1354 | - return false; |
|
| 1433 | + if (substr($db_type, 0, 5) != 'mysql') { |
|
| 1434 | + return false; |
|
| 1435 | + } |
|
| 1355 | 1436 | |
| 1356 | 1437 | // Find database user privileges. |
| 1357 | 1438 | $privs = array(); |
| 1358 | 1439 | $get_privs = $smcFunc['db_query']('', 'SHOW PRIVILEGES', array()); |
| 1359 | 1440 | while ($row = $smcFunc['db_fetch_assoc']($get_privs)) |
| 1360 | 1441 | { |
| 1361 | - if ($row['Privilege'] == 'Alter') |
|
| 1362 | - $privs[] = $row['Privilege']; |
|
| 1442 | + if ($row['Privilege'] == 'Alter') { |
|
| 1443 | + $privs[] = $row['Privilege']; |
|
| 1444 | + } |
|
| 1363 | 1445 | } |
| 1364 | 1446 | $smcFunc['db_free_result']($get_privs); |
| 1365 | 1447 | |
@@ -1389,8 +1471,9 @@ discard block |
||
| 1389 | 1471 | $incontext['continue'] = 1; |
| 1390 | 1472 | |
| 1391 | 1473 | // Skipping? |
| 1392 | - if (!empty($_POST['skip'])) |
|
| 1393 | - return true; |
|
| 1474 | + if (!empty($_POST['skip'])) { |
|
| 1475 | + return true; |
|
| 1476 | + } |
|
| 1394 | 1477 | |
| 1395 | 1478 | // Need this to check whether we need the database password. |
| 1396 | 1479 | require(dirname(__FILE__) . '/Settings.php'); |
@@ -1407,18 +1490,22 @@ discard block |
||
| 1407 | 1490 | // We need this to properly hash the password for Admin |
| 1408 | 1491 | $smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' : function($string) { |
| 1409 | 1492 | global $sourcedir; |
| 1410 | - if (function_exists('mb_strtolower')) |
|
| 1411 | - return mb_strtolower($string, 'UTF-8'); |
|
| 1493 | + if (function_exists('mb_strtolower')) { |
|
| 1494 | + return mb_strtolower($string, 'UTF-8'); |
|
| 1495 | + } |
|
| 1412 | 1496 | require_once($sourcedir . '/Subs-Charset.php'); |
| 1413 | 1497 | return utf8_strtolower($string); |
| 1414 | 1498 | }; |
| 1415 | 1499 | |
| 1416 | - if (!isset($_POST['username'])) |
|
| 1417 | - $_POST['username'] = ''; |
|
| 1418 | - if (!isset($_POST['email'])) |
|
| 1419 | - $_POST['email'] = ''; |
|
| 1420 | - if (!isset($_POST['server_email'])) |
|
| 1421 | - $_POST['server_email'] = ''; |
|
| 1500 | + if (!isset($_POST['username'])) { |
|
| 1501 | + $_POST['username'] = ''; |
|
| 1502 | + } |
|
| 1503 | + if (!isset($_POST['email'])) { |
|
| 1504 | + $_POST['email'] = ''; |
|
| 1505 | + } |
|
| 1506 | + if (!isset($_POST['server_email'])) { |
|
| 1507 | + $_POST['server_email'] = ''; |
|
| 1508 | + } |
|
| 1422 | 1509 | |
| 1423 | 1510 | $incontext['username'] = htmlspecialchars(stripslashes($_POST['username'])); |
| 1424 | 1511 | $incontext['email'] = htmlspecialchars(stripslashes($_POST['email'])); |
@@ -1437,8 +1524,9 @@ discard block |
||
| 1437 | 1524 | 'admin_group' => 1, |
| 1438 | 1525 | ) |
| 1439 | 1526 | ); |
| 1440 | - if ($smcFunc['db_num_rows']($request) != 0) |
|
| 1441 | - $incontext['skip'] = 1; |
|
| 1527 | + if ($smcFunc['db_num_rows']($request) != 0) { |
|
| 1528 | + $incontext['skip'] = 1; |
|
| 1529 | + } |
|
| 1442 | 1530 | $smcFunc['db_free_result']($request); |
| 1443 | 1531 | |
| 1444 | 1532 | // Trying to create an account? |
@@ -1469,8 +1557,9 @@ discard block |
||
| 1469 | 1557 | } |
| 1470 | 1558 | |
| 1471 | 1559 | // Update the webmaster's email? |
| 1472 | - if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]')) |
|
| 1473 | - updateSettingsFile(array('webmaster_email' => $_POST['server_email'])); |
|
| 1560 | + if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]')) { |
|
| 1561 | + updateSettingsFile(array('webmaster_email' => $_POST['server_email'])); |
|
| 1562 | + } |
|
| 1474 | 1563 | |
| 1475 | 1564 | // Work out whether we're going to have dodgy characters and remove them. |
| 1476 | 1565 | $invalid_characters = preg_match('~[<>&"\'=\\\]~', $_POST['username']) != 0; |
@@ -1493,32 +1582,27 @@ discard block |
||
| 1493 | 1582 | $smcFunc['db_free_result']($result); |
| 1494 | 1583 | |
| 1495 | 1584 | $incontext['account_existed'] = $txt['error_user_settings_taken']; |
| 1496 | - } |
|
| 1497 | - elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25) |
|
| 1585 | + } elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25) |
|
| 1498 | 1586 | { |
| 1499 | 1587 | // Try the previous step again. |
| 1500 | 1588 | $incontext['error'] = $_POST['username'] == '' ? $txt['error_username_left_empty'] : $txt['error_username_too_long']; |
| 1501 | 1589 | return false; |
| 1502 | - } |
|
| 1503 | - elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false) |
|
| 1590 | + } elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false) |
|
| 1504 | 1591 | { |
| 1505 | 1592 | // Try the previous step again. |
| 1506 | 1593 | $incontext['error'] = $txt['error_invalid_characters_username']; |
| 1507 | 1594 | return false; |
| 1508 | - } |
|
| 1509 | - elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255) |
|
| 1595 | + } elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255) |
|
| 1510 | 1596 | { |
| 1511 | 1597 | // One step back, this time fill out a proper admin email address. |
| 1512 | 1598 | $incontext['error'] = sprintf($txt['error_valid_admin_email_needed'], $_POST['username']); |
| 1513 | 1599 | return false; |
| 1514 | - } |
|
| 1515 | - elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255) |
|
| 1600 | + } elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255) |
|
| 1516 | 1601 | { |
| 1517 | 1602 | // One step back, this time fill out a proper admin email address. |
| 1518 | 1603 | $incontext['error'] = $txt['error_valid_server_email_needed']; |
| 1519 | 1604 | return false; |
| 1520 | - } |
|
| 1521 | - elseif ($_POST['username'] != '') |
|
| 1605 | + } elseif ($_POST['username'] != '') |
|
| 1522 | 1606 | { |
| 1523 | 1607 | $incontext['member_salt'] = substr(md5(mt_rand()), 0, 4); |
| 1524 | 1608 | |
@@ -1586,17 +1670,19 @@ discard block |
||
| 1586 | 1670 | reloadSettings(); |
| 1587 | 1671 | |
| 1588 | 1672 | // Bring a warning over. |
| 1589 | - if (!empty($incontext['account_existed'])) |
|
| 1590 | - $incontext['warning'] = $incontext['account_existed']; |
|
| 1673 | + if (!empty($incontext['account_existed'])) { |
|
| 1674 | + $incontext['warning'] = $incontext['account_existed']; |
|
| 1675 | + } |
|
| 1591 | 1676 | |
| 1592 | - if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support'])) |
|
| 1593 | - $smcFunc['db_query']('', ' |
|
| 1677 | + if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support'])) { |
|
| 1678 | + $smcFunc['db_query']('', ' |
|
| 1594 | 1679 | SET NAMES {string:db_character_set}', |
| 1595 | 1680 | array( |
| 1596 | 1681 | 'db_character_set' => $db_character_set, |
| 1597 | 1682 | 'db_error_skip' => true, |
| 1598 | 1683 | ) |
| 1599 | 1684 | ); |
| 1685 | + } |
|
| 1600 | 1686 | |
| 1601 | 1687 | // As track stats is by default enabled let's add some activity. |
| 1602 | 1688 | $smcFunc['db_insert']('ignore', |
@@ -1617,14 +1703,16 @@ discard block |
||
| 1617 | 1703 | // Only proceed if we can load the data. |
| 1618 | 1704 | if ($request) |
| 1619 | 1705 | { |
| 1620 | - while ($row = $smcFunc['db_fetch_row']($request)) |
|
| 1621 | - $modSettings[$row[0]] = $row[1]; |
|
| 1706 | + while ($row = $smcFunc['db_fetch_row']($request)) { |
|
| 1707 | + $modSettings[$row[0]] = $row[1]; |
|
| 1708 | + } |
|
| 1622 | 1709 | $smcFunc['db_free_result']($request); |
| 1623 | 1710 | } |
| 1624 | 1711 | |
| 1625 | 1712 | // Automatically log them in ;) |
| 1626 | - if (isset($incontext['member_id']) && isset($incontext['member_salt'])) |
|
| 1627 | - setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt'])); |
|
| 1713 | + if (isset($incontext['member_id']) && isset($incontext['member_salt'])) { |
|
| 1714 | + setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt'])); |
|
| 1715 | + } |
|
| 1628 | 1716 | |
| 1629 | 1717 | $result = $smcFunc['db_query']('', ' |
| 1630 | 1718 | SELECT value |
@@ -1635,13 +1723,14 @@ discard block |
||
| 1635 | 1723 | 'db_error_skip' => true, |
| 1636 | 1724 | ) |
| 1637 | 1725 | ); |
| 1638 | - if ($smcFunc['db_num_rows']($result) != 0) |
|
| 1639 | - list ($db_sessions) = $smcFunc['db_fetch_row']($result); |
|
| 1726 | + if ($smcFunc['db_num_rows']($result) != 0) { |
|
| 1727 | + list ($db_sessions) = $smcFunc['db_fetch_row']($result); |
|
| 1728 | + } |
|
| 1640 | 1729 | $smcFunc['db_free_result']($result); |
| 1641 | 1730 | |
| 1642 | - if (empty($db_sessions)) |
|
| 1643 | - $_SESSION['admin_time'] = time(); |
|
| 1644 | - else |
|
| 1731 | + if (empty($db_sessions)) { |
|
| 1732 | + $_SESSION['admin_time'] = time(); |
|
| 1733 | + } else |
|
| 1645 | 1734 | { |
| 1646 | 1735 | $_SERVER['HTTP_USER_AGENT'] = substr($_SERVER['HTTP_USER_AGENT'], 0, 211); |
| 1647 | 1736 | |
@@ -1665,8 +1754,9 @@ discard block |
||
| 1665 | 1754 | $smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' : |
| 1666 | 1755 | function($string){ |
| 1667 | 1756 | global $sourcedir; |
| 1668 | - if (function_exists('mb_strtolower')) |
|
| 1669 | - return mb_strtolower($string, 'UTF-8'); |
|
| 1757 | + if (function_exists('mb_strtolower')) { |
|
| 1758 | + return mb_strtolower($string, 'UTF-8'); |
|
| 1759 | + } |
|
| 1670 | 1760 | require_once($sourcedir . '/Subs-Charset.php'); |
| 1671 | 1761 | return utf8_strtolower($string); |
| 1672 | 1762 | }; |
@@ -1682,8 +1772,9 @@ discard block |
||
| 1682 | 1772 | ) |
| 1683 | 1773 | ); |
| 1684 | 1774 | $context['utf8'] = $db_character_set === 'utf8' || $txt['lang_character_set'] === 'UTF-8'; |
| 1685 | - if ($smcFunc['db_num_rows']($request) > 0) |
|
| 1686 | - updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject'])); |
|
| 1775 | + if ($smcFunc['db_num_rows']($request) > 0) { |
|
| 1776 | + updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject'])); |
|
| 1777 | + } |
|
| 1687 | 1778 | $smcFunc['db_free_result']($request); |
| 1688 | 1779 | |
| 1689 | 1780 | // Now is the perfect time to fetch the SM files. |
@@ -1702,8 +1793,9 @@ discard block |
||
| 1702 | 1793 | |
| 1703 | 1794 | // Check if we need some stupid MySQL fix. |
| 1704 | 1795 | $server_version = $smcFunc['db_server_info'](); |
| 1705 | - if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) |
|
| 1706 | - updateSettings(array('db_mysql_group_by_fix' => '1')); |
|
| 1796 | + if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) { |
|
| 1797 | + updateSettings(array('db_mysql_group_by_fix' => '1')); |
|
| 1798 | + } |
|
| 1707 | 1799 | |
| 1708 | 1800 | // Some final context for the template. |
| 1709 | 1801 | $incontext['dir_still_writable'] = is_writable(dirname(__FILE__)) && substr(__FILE__, 1, 2) != ':\\'; |
@@ -1723,8 +1815,9 @@ discard block |
||
| 1723 | 1815 | $settingsArray = file(dirname(__FILE__) . '/Settings.php'); |
| 1724 | 1816 | |
| 1725 | 1817 | // @todo Do we just want to read the file in clean, and split it this way always? |
| 1726 | - if (count($settingsArray) == 1) |
|
| 1727 | - $settingsArray = preg_split('~[\r\n]~', $settingsArray[0]); |
|
| 1818 | + if (count($settingsArray) == 1) { |
|
| 1819 | + $settingsArray = preg_split('~[\r\n]~', $settingsArray[0]); |
|
| 1820 | + } |
|
| 1728 | 1821 | |
| 1729 | 1822 | for ($i = 0, $n = count($settingsArray); $i < $n; $i++) |
| 1730 | 1823 | { |
@@ -1739,19 +1832,22 @@ discard block |
||
| 1739 | 1832 | continue; |
| 1740 | 1833 | } |
| 1741 | 1834 | |
| 1742 | - if (trim($settingsArray[$i]) == '?' . '>') |
|
| 1743 | - $settingsArray[$i] = ''; |
|
| 1835 | + if (trim($settingsArray[$i]) == '?' . '>') { |
|
| 1836 | + $settingsArray[$i] = ''; |
|
| 1837 | + } |
|
| 1744 | 1838 | |
| 1745 | 1839 | // Don't trim or bother with it if it's not a variable. |
| 1746 | - if (substr($settingsArray[$i], 0, 1) != '$') |
|
| 1747 | - continue; |
|
| 1840 | + if (substr($settingsArray[$i], 0, 1) != '$') { |
|
| 1841 | + continue; |
|
| 1842 | + } |
|
| 1748 | 1843 | |
| 1749 | 1844 | $settingsArray[$i] = rtrim($settingsArray[$i]) . "\n"; |
| 1750 | 1845 | |
| 1751 | - foreach ($vars as $var => $val) |
|
| 1752 | - if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0) |
|
| 1846 | + foreach ($vars as $var => $val) { |
|
| 1847 | + if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0) |
|
| 1753 | 1848 | { |
| 1754 | 1849 | $comment = strstr($settingsArray[$i], '#'); |
| 1850 | + } |
|
| 1755 | 1851 | $settingsArray[$i] = '$' . $var . ' = \'' . $val . '\';' . ($comment != '' ? "\t\t" . $comment : "\n"); |
| 1756 | 1852 | unset($vars[$var]); |
| 1757 | 1853 | } |
@@ -1761,36 +1857,41 @@ discard block |
||
| 1761 | 1857 | if (!empty($vars)) |
| 1762 | 1858 | { |
| 1763 | 1859 | $settingsArray[$i++] = ''; |
| 1764 | - foreach ($vars as $var => $val) |
|
| 1765 | - $settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n"; |
|
| 1860 | + foreach ($vars as $var => $val) { |
|
| 1861 | + $settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n"; |
|
| 1862 | + } |
|
| 1766 | 1863 | } |
| 1767 | 1864 | |
| 1768 | 1865 | // Blank out the file - done to fix a oddity with some servers. |
| 1769 | 1866 | $fp = @fopen(dirname(__FILE__) . '/Settings.php', 'w'); |
| 1770 | - if (!$fp) |
|
| 1771 | - return false; |
|
| 1867 | + if (!$fp) { |
|
| 1868 | + return false; |
|
| 1869 | + } |
|
| 1772 | 1870 | fclose($fp); |
| 1773 | 1871 | |
| 1774 | 1872 | $fp = fopen(dirname(__FILE__) . '/Settings.php', 'r+'); |
| 1775 | 1873 | |
| 1776 | 1874 | // Gotta have one of these ;) |
| 1777 | - if (trim($settingsArray[0]) != '<?php') |
|
| 1778 | - fwrite($fp, "<?php\n"); |
|
| 1875 | + if (trim($settingsArray[0]) != '<?php') { |
|
| 1876 | + fwrite($fp, "<?php\n"); |
|
| 1877 | + } |
|
| 1779 | 1878 | |
| 1780 | 1879 | $lines = count($settingsArray); |
| 1781 | 1880 | for ($i = 0; $i < $lines - 1; $i++) |
| 1782 | 1881 | { |
| 1783 | 1882 | // Don't just write a bunch of blank lines. |
| 1784 | - if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '') |
|
| 1785 | - fwrite($fp, strtr($settingsArray[$i], "\r", '')); |
|
| 1883 | + if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '') { |
|
| 1884 | + fwrite($fp, strtr($settingsArray[$i], "\r", '')); |
|
| 1885 | + } |
|
| 1786 | 1886 | } |
| 1787 | 1887 | fwrite($fp, $settingsArray[$i] . '?' . '>'); |
| 1788 | 1888 | fclose($fp); |
| 1789 | 1889 | |
| 1790 | 1890 | // Even though on normal installations the filemtime should prevent this being used by the installer incorrectly |
| 1791 | 1891 | // it seems that there are times it might not. So let's MAKE it dump the cache. |
| 1792 | - if (function_exists('opcache_invalidate')) |
|
| 1793 | - opcache_invalidate(dirname(__FILE__) . '/Settings.php', true); |
|
| 1892 | + if (function_exists('opcache_invalidate')) { |
|
| 1893 | + opcache_invalidate(dirname(__FILE__) . '/Settings.php', true); |
|
| 1894 | + } |
|
| 1794 | 1895 | |
| 1795 | 1896 | return true; |
| 1796 | 1897 | } |
@@ -1815,9 +1916,9 @@ discard block |
||
| 1815 | 1916 | SecFilterScanPOST Off |
| 1816 | 1917 | </IfModule>'; |
| 1817 | 1918 | |
| 1818 | - if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules())) |
|
| 1819 | - return true; |
|
| 1820 | - elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess')) |
|
| 1919 | + if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules())) { |
|
| 1920 | + return true; |
|
| 1921 | + } elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess')) |
|
| 1821 | 1922 | { |
| 1822 | 1923 | $current_htaccess = implode('', file(dirname(__FILE__) . '/.htaccess')); |
| 1823 | 1924 | |
@@ -1829,29 +1930,28 @@ discard block |
||
| 1829 | 1930 | fwrite($ht_handle, $htaccess_addition); |
| 1830 | 1931 | fclose($ht_handle); |
| 1831 | 1932 | return true; |
| 1933 | + } else { |
|
| 1934 | + return false; |
|
| 1832 | 1935 | } |
| 1833 | - else |
|
| 1834 | - return false; |
|
| 1936 | + } else { |
|
| 1937 | + return true; |
|
| 1835 | 1938 | } |
| 1836 | - else |
|
| 1837 | - return true; |
|
| 1838 | - } |
|
| 1839 | - elseif (file_exists(dirname(__FILE__) . '/.htaccess')) |
|
| 1840 | - return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false; |
|
| 1841 | - elseif (is_writable(dirname(__FILE__))) |
|
| 1939 | + } elseif (file_exists(dirname(__FILE__) . '/.htaccess')) { |
|
| 1940 | + return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false; |
|
| 1941 | + } elseif (is_writable(dirname(__FILE__))) |
|
| 1842 | 1942 | { |
| 1843 | 1943 | if ($ht_handle = fopen(dirname(__FILE__) . '/.htaccess', 'w')) |
| 1844 | 1944 | { |
| 1845 | 1945 | fwrite($ht_handle, $htaccess_addition); |
| 1846 | 1946 | fclose($ht_handle); |
| 1847 | 1947 | return true; |
| 1948 | + } else { |
|
| 1949 | + return false; |
|
| 1848 | 1950 | } |
| 1849 | - else |
|
| 1951 | + } else { |
|
| 1850 | 1952 | return false; |
| 1851 | 1953 | } |
| 1852 | - else |
|
| 1853 | - return false; |
|
| 1854 | -} |
|
| 1954 | + } |
|
| 1855 | 1955 | |
| 1856 | 1956 | function template_install_above() |
| 1857 | 1957 | { |
@@ -1889,9 +1989,10 @@ discard block |
||
| 1889 | 1989 | <label for="installer_language">', $txt['installer_language'], ':</label> |
| 1890 | 1990 | <select id="installer_language" name="lang_file" onchange="location.href = \'', $installurl, '?lang_file=\' + this.options[this.selectedIndex].value;">'; |
| 1891 | 1991 | |
| 1892 | - foreach ($incontext['detected_languages'] as $lang => $name) |
|
| 1893 | - echo ' |
|
| 1992 | + foreach ($incontext['detected_languages'] as $lang => $name) { |
|
| 1993 | + echo ' |
|
| 1894 | 1994 | <option', isset($_SESSION['installer_temp_lang']) && $_SESSION['installer_temp_lang'] == $lang ? ' selected' : '', ' value="', $lang, '">', $name, '</option>'; |
| 1995 | + } |
|
| 1895 | 1996 | |
| 1896 | 1997 | echo ' |
| 1897 | 1998 | </select> |
@@ -1911,9 +2012,10 @@ discard block |
||
| 1911 | 2012 | <h2>', $txt['upgrade_progress'], '</h2> |
| 1912 | 2013 | <ul>'; |
| 1913 | 2014 | |
| 1914 | - foreach ($incontext['steps'] as $num => $step) |
|
| 1915 | - echo ' |
|
| 2015 | + foreach ($incontext['steps'] as $num => $step) { |
|
| 2016 | + echo ' |
|
| 1916 | 2017 | <li class="', $num < $incontext['current_step'] ? 'stepdone' : ($num == $incontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>'; |
| 2018 | + } |
|
| 1917 | 2019 | |
| 1918 | 2020 | echo ' |
| 1919 | 2021 | </ul> |
@@ -1938,20 +2040,23 @@ discard block |
||
| 1938 | 2040 | echo ' |
| 1939 | 2041 | <div>'; |
| 1940 | 2042 | |
| 1941 | - if (!empty($incontext['continue'])) |
|
| 1942 | - echo ' |
|
| 2043 | + if (!empty($incontext['continue'])) { |
|
| 2044 | + echo ' |
|
| 1943 | 2045 | <input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '" onclick="return submitThisOnce(this);" class="button" />'; |
| 1944 | - if (!empty($incontext['skip'])) |
|
| 1945 | - echo ' |
|
| 2046 | + } |
|
| 2047 | + if (!empty($incontext['skip'])) { |
|
| 2048 | + echo ' |
|
| 1946 | 2049 | <input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="return submitThisOnce(this);" class="button" />'; |
| 2050 | + } |
|
| 1947 | 2051 | echo ' |
| 1948 | 2052 | </div>'; |
| 1949 | 2053 | } |
| 1950 | 2054 | |
| 1951 | 2055 | // Show the closing form tag and other data only if not in the last step |
| 1952 | - if (count($incontext['steps']) - 1 !== (int) $incontext['current_step']) |
|
| 1953 | - echo ' |
|
| 2056 | + if (count($incontext['steps']) - 1 !== (int) $incontext['current_step']) { |
|
| 2057 | + echo ' |
|
| 1954 | 2058 | </form>'; |
| 2059 | + } |
|
| 1955 | 2060 | |
| 1956 | 2061 | echo ' |
| 1957 | 2062 | </div> |
@@ -1986,13 +2091,15 @@ discard block |
||
| 1986 | 2091 | </div>'; |
| 1987 | 2092 | |
| 1988 | 2093 | // Show the warnings, or not. |
| 1989 | - if (template_warning_divs()) |
|
| 1990 | - echo ' |
|
| 2094 | + if (template_warning_divs()) { |
|
| 2095 | + echo ' |
|
| 1991 | 2096 | <h3>', $txt['install_all_lovely'], '</h3>'; |
| 2097 | + } |
|
| 1992 | 2098 | |
| 1993 | 2099 | // Say we want the continue button! |
| 1994 | - if (empty($incontext['error'])) |
|
| 1995 | - $incontext['continue'] = 1; |
|
| 2100 | + if (empty($incontext['error'])) { |
|
| 2101 | + $incontext['continue'] = 1; |
|
| 2102 | + } |
|
| 1996 | 2103 | |
| 1997 | 2104 | // For the latest version stuff. |
| 1998 | 2105 | echo ' |
@@ -2026,8 +2133,8 @@ discard block |
||
| 2026 | 2133 | global $txt, $incontext; |
| 2027 | 2134 | |
| 2028 | 2135 | // Errors are very serious.. |
| 2029 | - if (!empty($incontext['error'])) |
|
| 2030 | - echo ' |
|
| 2136 | + if (!empty($incontext['error'])) { |
|
| 2137 | + echo ' |
|
| 2031 | 2138 | <div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;"> |
| 2032 | 2139 | <div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div> |
| 2033 | 2140 | <strong style="text-decoration: underline;">', $txt['upgrade_critical_error'], '</strong><br> |
@@ -2035,9 +2142,10 @@ discard block |
||
| 2035 | 2142 | ', $incontext['error'], ' |
| 2036 | 2143 | </div> |
| 2037 | 2144 | </div>'; |
| 2145 | + } |
|
| 2038 | 2146 | // A warning message? |
| 2039 | - elseif (!empty($incontext['warning'])) |
|
| 2040 | - echo ' |
|
| 2147 | + elseif (!empty($incontext['warning'])) { |
|
| 2148 | + echo ' |
|
| 2041 | 2149 | <div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;"> |
| 2042 | 2150 | <div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div> |
| 2043 | 2151 | <strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br> |
@@ -2045,6 +2153,7 @@ discard block |
||
| 2045 | 2153 | ', $incontext['warning'], ' |
| 2046 | 2154 | </div> |
| 2047 | 2155 | </div>'; |
| 2156 | + } |
|
| 2048 | 2157 | |
| 2049 | 2158 | return empty($incontext['error']) && empty($incontext['warning']); |
| 2050 | 2159 | } |
@@ -2060,27 +2169,30 @@ discard block |
||
| 2060 | 2169 | <li>', $incontext['failed_files']), '</li> |
| 2061 | 2170 | </ul>'; |
| 2062 | 2171 | |
| 2063 | - if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux') |
|
| 2064 | - echo ' |
|
| 2172 | + if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux') { |
|
| 2173 | + echo ' |
|
| 2065 | 2174 | <hr> |
| 2066 | 2175 | <p>', $txt['chmod_linux_info'], '</p> |
| 2067 | 2176 | <tt># chmod a+w ', implode(' ' . $incontext['detected_path'] . '/', $incontext['failed_files']), '</tt>'; |
| 2177 | + } |
|
| 2068 | 2178 | |
| 2069 | 2179 | // This is serious! |
| 2070 | - if (!template_warning_divs()) |
|
| 2071 | - return; |
|
| 2180 | + if (!template_warning_divs()) { |
|
| 2181 | + return; |
|
| 2182 | + } |
|
| 2072 | 2183 | |
| 2073 | 2184 | echo ' |
| 2074 | 2185 | <hr> |
| 2075 | 2186 | <p>', $txt['ftp_setup_info'], '</p>'; |
| 2076 | 2187 | |
| 2077 | - if (!empty($incontext['ftp_errors'])) |
|
| 2078 | - echo ' |
|
| 2188 | + if (!empty($incontext['ftp_errors'])) { |
|
| 2189 | + echo ' |
|
| 2079 | 2190 | <div class="error_message"> |
| 2080 | 2191 | ', $txt['error_ftp_no_connect'], '<br><br> |
| 2081 | 2192 | <code>', implode('<br>', $incontext['ftp_errors']), '</code> |
| 2082 | 2193 | </div> |
| 2083 | 2194 | <br>'; |
| 2195 | + } |
|
| 2084 | 2196 | |
| 2085 | 2197 | echo ' |
| 2086 | 2198 | <form action="', $incontext['form_url'], '" method="post"> |
@@ -2140,17 +2252,17 @@ discard block |
||
| 2140 | 2252 | <td> |
| 2141 | 2253 | <select name="db_type" id="db_type_input" onchange="toggleDBInput();">'; |
| 2142 | 2254 | |
| 2143 | - foreach ($incontext['supported_databases'] as $key => $db) |
|
| 2144 | - echo ' |
|
| 2255 | + foreach ($incontext['supported_databases'] as $key => $db) { |
|
| 2256 | + echo ' |
|
| 2145 | 2257 | <option value="', $key, '"', isset($_POST['db_type']) && $_POST['db_type'] == $key ? ' selected' : '', '>', $db['name'], '</option>'; |
| 2258 | + } |
|
| 2146 | 2259 | |
| 2147 | 2260 | echo ' |
| 2148 | 2261 | </select> |
| 2149 | 2262 | <div class="smalltext block">', $txt['db_settings_type_info'], '</div> |
| 2150 | 2263 | </td> |
| 2151 | 2264 | </tr>'; |
| 2152 | - } |
|
| 2153 | - else |
|
| 2265 | + } else |
|
| 2154 | 2266 | { |
| 2155 | 2267 | echo ' |
| 2156 | 2268 | <tr style="display: none;"> |
@@ -2343,9 +2455,10 @@ discard block |
||
| 2343 | 2455 | <div style="color: red;">', $txt['error_db_queries'], '</div> |
| 2344 | 2456 | <ul>'; |
| 2345 | 2457 | |
| 2346 | - foreach ($incontext['failures'] as $line => $fail) |
|
| 2347 | - echo ' |
|
| 2458 | + foreach ($incontext['failures'] as $line => $fail) { |
|
| 2459 | + echo ' |
|
| 2348 | 2460 | <li><strong>', $txt['error_db_queries_line'], $line + 1, ':</strong> ', nl2br(htmlspecialchars($fail)), '</li>'; |
| 2461 | + } |
|
| 2349 | 2462 | |
| 2350 | 2463 | echo ' |
| 2351 | 2464 | </ul>'; |
@@ -2406,15 +2519,16 @@ discard block |
||
| 2406 | 2519 | </tr> |
| 2407 | 2520 | </table>'; |
| 2408 | 2521 | |
| 2409 | - if ($incontext['require_db_confirm']) |
|
| 2410 | - echo ' |
|
| 2522 | + if ($incontext['require_db_confirm']) { |
|
| 2523 | + echo ' |
|
| 2411 | 2524 | <h2>', $txt['user_settings_database'], '</h2> |
| 2412 | 2525 | <p>', $txt['user_settings_database_info'], '</p> |
| 2413 | 2526 | |
| 2414 | 2527 | <div style="margin-bottom: 2ex; padding-', $txt['lang_rtl'] == false ? 'left' : 'right', ': 50px;"> |
| 2415 | 2528 | <input type="password" name="password3" size="30" /> |
| 2416 | 2529 | </div>'; |
| 2417 | -} |
|
| 2530 | + } |
|
| 2531 | + } |
|
| 2418 | 2532 | |
| 2419 | 2533 | // Tell them it's done, and to delete. |
| 2420 | 2534 | function template_delete_install() |
@@ -2427,14 +2541,15 @@ discard block |
||
| 2427 | 2541 | template_warning_divs(); |
| 2428 | 2542 | |
| 2429 | 2543 | // Install directory still writable? |
| 2430 | - if ($incontext['dir_still_writable']) |
|
| 2431 | - echo ' |
|
| 2544 | + if ($incontext['dir_still_writable']) { |
|
| 2545 | + echo ' |
|
| 2432 | 2546 | <em>', $txt['still_writable'], '</em><br> |
| 2433 | 2547 | <br>'; |
| 2548 | + } |
|
| 2434 | 2549 | |
| 2435 | 2550 | // Don't show the box if it's like 99% sure it won't work :P. |
| 2436 | - if ($incontext['probably_delete_install']) |
|
| 2437 | - echo ' |
|
| 2551 | + if ($incontext['probably_delete_install']) { |
|
| 2552 | + echo ' |
|
| 2438 | 2553 | <div style="margin: 1ex; font-weight: bold;"> |
| 2439 | 2554 | <label for="delete_self"><input type="checkbox" id="delete_self" onclick="doTheDelete();" /> ', $txt['delete_installer'], !isset($_SESSION['installer_temp_ftp']) ? ' ' . $txt['delete_installer_maybe'] : '', '</label> |
| 2440 | 2555 | </div> |
@@ -2450,6 +2565,7 @@ discard block |
||
| 2450 | 2565 | } |
| 2451 | 2566 | </script> |
| 2452 | 2567 | <br>'; |
| 2568 | + } |
|
| 2453 | 2569 | |
| 2454 | 2570 | echo ' |
| 2455 | 2571 | ', sprintf($txt['go_to_your_forum'], $boardurl . '/index.php'), '<br> |