@@ -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 | |
@@ -28,16 +29,18 @@ discard block |
||
| 28 | 29 | $time_start = microtime(true); |
| 29 | 30 | |
| 30 | 31 | // Just being safe... |
| 31 | -foreach (array('db_character_set', 'cachedir') as $variable) |
|
| 32 | +foreach (array('db_character_set', 'cachedir') as $variable) { |
|
| 32 | 33 | if (isset($GLOBALS[$variable])) |
| 33 | 34 | unset($GLOBALS[$variable]); |
| 35 | +} |
|
| 34 | 36 | |
| 35 | 37 | // Get the forum's settings for database and file paths. |
| 36 | 38 | require_once(dirname(__FILE__) . '/Settings.php'); |
| 37 | 39 | |
| 38 | 40 | // Make absolutely sure the cache directory is defined. |
| 39 | -if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) |
|
| 41 | +if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) { |
|
| 40 | 42 | $cachedir = $boarddir . '/cache'; |
| 43 | +} |
|
| 41 | 44 | |
| 42 | 45 | $ssi_error_reporting = error_reporting(E_ALL); |
| 43 | 46 | /* Set this to one of three values depending on what you want to happen in the case of a fatal error. |
@@ -48,16 +51,19 @@ discard block |
||
| 48 | 51 | $ssi_on_error_method = false; |
| 49 | 52 | |
| 50 | 53 | // Don't do john didley if the forum's been shut down completely. |
| 51 | -if ($maintenance == 2 && (!isset($ssi_maintenance_off) || $ssi_maintenance_off !== true)) |
|
| 54 | +if ($maintenance == 2 && (!isset($ssi_maintenance_off) || $ssi_maintenance_off !== true)) { |
|
| 52 | 55 | die($mmessage); |
| 56 | +} |
|
| 53 | 57 | |
| 54 | 58 | // Fix for using the current directory as a path. |
| 55 | -if (substr($sourcedir, 0, 1) == '.' && substr($sourcedir, 1, 1) != '.') |
|
| 59 | +if (substr($sourcedir, 0, 1) == '.' && substr($sourcedir, 1, 1) != '.') { |
|
| 56 | 60 | $sourcedir = dirname(__FILE__) . substr($sourcedir, 1); |
| 61 | +} |
|
| 57 | 62 | |
| 58 | 63 | // For php below 7 |
| 59 | -if (!function_exists('random_int')) |
|
| 64 | +if (!function_exists('random_int')) { |
|
| 60 | 65 | require_once ($sourcedir . '/random_compat/random_int.php'); |
| 66 | +} |
|
| 61 | 67 | |
| 62 | 68 | // Load the important includes. |
| 63 | 69 | require_once($sourcedir . '/QueryString.php'); |
@@ -82,26 +88,30 @@ discard block |
||
| 82 | 88 | cleanRequest(); |
| 83 | 89 | |
| 84 | 90 | // Seed the random generator? |
| 85 | -if (empty($modSettings['rand_seed']) || random_int(1, 250) == 69) |
|
| 91 | +if (empty($modSettings['rand_seed']) || random_int(1, 250) == 69) { |
|
| 86 | 92 | smf_seed_generator(); |
| 93 | +} |
|
| 87 | 94 | |
| 88 | 95 | // Check on any hacking attempts. |
| 89 | -if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS'])) |
|
| 96 | +if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS'])) { |
|
| 90 | 97 | die('No direct access...'); |
| 91 | -elseif (isset($_REQUEST['ssi_theme']) && (int) $_REQUEST['ssi_theme'] == (int) $ssi_theme) |
|
| 98 | +} elseif (isset($_REQUEST['ssi_theme']) && (int) $_REQUEST['ssi_theme'] == (int) $ssi_theme) { |
|
| 92 | 99 | die('No direct access...'); |
| 93 | -elseif (isset($_COOKIE['ssi_theme']) && (int) $_COOKIE['ssi_theme'] == (int) $ssi_theme) |
|
| 100 | +} elseif (isset($_COOKIE['ssi_theme']) && (int) $_COOKIE['ssi_theme'] == (int) $ssi_theme) { |
|
| 94 | 101 | die('No direct access...'); |
| 95 | -elseif (isset($_REQUEST['ssi_layers'], $ssi_layers) && (@get_magic_quotes_gpc() ? stripslashes($_REQUEST['ssi_layers']) : $_REQUEST['ssi_layers']) == $ssi_layers) |
|
| 102 | +} elseif (isset($_REQUEST['ssi_layers'], $ssi_layers) && (@get_magic_quotes_gpc() ? stripslashes($_REQUEST['ssi_layers']) : $_REQUEST['ssi_layers']) == $ssi_layers) { |
|
| 96 | 103 | die('No direct access...'); |
| 97 | -if (isset($_REQUEST['context'])) |
|
| 104 | +} |
|
| 105 | +if (isset($_REQUEST['context'])) { |
|
| 98 | 106 | die('No direct access...'); |
| 107 | +} |
|
| 99 | 108 | |
| 100 | 109 | // Gzip output? (because it must be boolean and true, this can't be hacked.) |
| 101 | -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', '>=')) |
|
| 110 | +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', '>=')) { |
|
| 102 | 111 | ob_start('ob_gzhandler'); |
| 103 | -else |
|
| 112 | +} else { |
|
| 104 | 113 | $modSettings['enableCompressedOutput'] = '0'; |
| 114 | +} |
|
| 105 | 115 | |
| 106 | 116 | /** |
| 107 | 117 | * An autoloader for certain classes. |
@@ -150,9 +160,9 @@ discard block |
||
| 150 | 160 | ob_start('ob_sessrewrite'); |
| 151 | 161 | |
| 152 | 162 | // Start the session... known to scramble SSI includes in cases... |
| 153 | -if (!headers_sent()) |
|
| 163 | +if (!headers_sent()) { |
|
| 154 | 164 | loadSession(); |
| 155 | -else |
|
| 165 | +} else |
|
| 156 | 166 | { |
| 157 | 167 | if (isset($_COOKIE[session_name()]) || isset($_REQUEST[session_name()])) |
| 158 | 168 | { |
@@ -186,12 +196,14 @@ discard block |
||
| 186 | 196 | loadTheme(isset($ssi_theme) ? (int) $ssi_theme : 0); |
| 187 | 197 | |
| 188 | 198 | // @todo: probably not the best place, but somewhere it should be set... |
| 189 | -if (!headers_sent()) |
|
| 199 | +if (!headers_sent()) { |
|
| 190 | 200 | 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'])); |
| 201 | +} |
|
| 191 | 202 | |
| 192 | 203 | // Take care of any banning that needs to be done. |
| 193 | -if (isset($_REQUEST['ssi_ban']) || (isset($ssi_ban) && $ssi_ban === true)) |
|
| 204 | +if (isset($_REQUEST['ssi_ban']) || (isset($ssi_ban) && $ssi_ban === true)) { |
|
| 194 | 205 | is_not_banned(); |
| 206 | +} |
|
| 195 | 207 | |
| 196 | 208 | // Do we allow guests in here? |
| 197 | 209 | if (empty($ssi_guest_access) && empty($modSettings['allow_guestAccess']) && $user_info['is_guest'] && basename($_SERVER['PHP_SELF']) != 'SSI.php') |
@@ -206,17 +218,19 @@ discard block |
||
| 206 | 218 | { |
| 207 | 219 | $context['template_layers'] = $ssi_layers; |
| 208 | 220 | template_header(); |
| 209 | -} |
|
| 210 | -else |
|
| 221 | +} else { |
|
| 211 | 222 | setupThemeContext(); |
| 223 | +} |
|
| 212 | 224 | |
| 213 | 225 | // Make sure they didn't muss around with the settings... but only if it's not cli. |
| 214 | -if (isset($_SERVER['REMOTE_ADDR']) && !isset($_SERVER['is_cli']) && session_id() == '') |
|
| 226 | +if (isset($_SERVER['REMOTE_ADDR']) && !isset($_SERVER['is_cli']) && session_id() == '') { |
|
| 215 | 227 | trigger_error($txt['ssi_session_broken'], E_USER_NOTICE); |
| 228 | +} |
|
| 216 | 229 | |
| 217 | 230 | // Without visiting the forum this session variable might not be set on submit. |
| 218 | -if (!isset($_SESSION['USER_AGENT']) && (!isset($_GET['ssi_function']) || $_GET['ssi_function'] !== 'pollVote')) |
|
| 231 | +if (!isset($_SESSION['USER_AGENT']) && (!isset($_GET['ssi_function']) || $_GET['ssi_function'] !== 'pollVote')) { |
|
| 219 | 232 | $_SESSION['USER_AGENT'] = $_SERVER['HTTP_USER_AGENT']; |
| 233 | +} |
|
| 220 | 234 | |
| 221 | 235 | // Have the ability to easily add functions to SSI. |
| 222 | 236 | call_integration_hook('integrate_SSI'); |
@@ -225,11 +239,13 @@ discard block |
||
| 225 | 239 | if (basename($_SERVER['PHP_SELF']) == 'SSI.php') |
| 226 | 240 | { |
| 227 | 241 | // You shouldn't just access SSI.php directly by URL!! |
| 228 | - if (!isset($_GET['ssi_function'])) |
|
| 229 | - die(sprintf($txt['ssi_not_direct'], $user_info['is_admin'] ? '\'' . addslashes(__FILE__) . '\'' : '\'SSI.php\'')); |
|
| 242 | + if (!isset($_GET['ssi_function'])) { |
|
| 243 | + die(sprintf($txt['ssi_not_direct'], $user_info['is_admin'] ? '\'' . addslashes(__FILE__) . '\'' : '\'SSI.php\'')); |
|
| 244 | + } |
|
| 230 | 245 | // Call a function passed by GET. |
| 231 | - if (function_exists('ssi_' . $_GET['ssi_function']) && (!empty($modSettings['allow_guestAccess']) || !$user_info['is_guest'])) |
|
| 232 | - call_user_func('ssi_' . $_GET['ssi_function']); |
|
| 246 | + if (function_exists('ssi_' . $_GET['ssi_function']) && (!empty($modSettings['allow_guestAccess']) || !$user_info['is_guest'])) { |
|
| 247 | + call_user_func('ssi_' . $_GET['ssi_function']); |
|
| 248 | + } |
|
| 233 | 249 | exit; |
| 234 | 250 | } |
| 235 | 251 | |
@@ -246,9 +262,10 @@ discard block |
||
| 246 | 262 | */ |
| 247 | 263 | function ssi_shutdown() |
| 248 | 264 | { |
| 249 | - if (!isset($_GET['ssi_function']) || $_GET['ssi_function'] != 'shutdown') |
|
| 250 | - template_footer(); |
|
| 251 | -} |
|
| 265 | + if (!isset($_GET['ssi_function']) || $_GET['ssi_function'] != 'shutdown') { |
|
| 266 | + template_footer(); |
|
| 267 | + } |
|
| 268 | + } |
|
| 252 | 269 | |
| 253 | 270 | /** |
| 254 | 271 | * Display a welcome message, like: Hey, User, you have 0 messages, 0 are new. |
@@ -261,15 +278,17 @@ discard block |
||
| 261 | 278 | |
| 262 | 279 | if ($output_method == 'echo') |
| 263 | 280 | { |
| 264 | - if ($context['user']['is_guest']) |
|
| 265 | - 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'); |
|
| 266 | - else |
|
| 267 | - 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'])))) : ''; |
|
| 281 | + if ($context['user']['is_guest']) { |
|
| 282 | + 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'); |
|
| 283 | + } else { |
|
| 284 | + 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'])))) : ''; |
|
| 285 | + } |
|
| 268 | 286 | } |
| 269 | 287 | // Don't echo... then do what?! |
| 270 | - else |
|
| 271 | - return $context['user']; |
|
| 272 | -} |
|
| 288 | + else { |
|
| 289 | + return $context['user']; |
|
| 290 | + } |
|
| 291 | + } |
|
| 273 | 292 | |
| 274 | 293 | /** |
| 275 | 294 | * Display a menu bar, like is displayed at the top of the forum. |
@@ -280,12 +299,14 @@ discard block |
||
| 280 | 299 | { |
| 281 | 300 | global $context; |
| 282 | 301 | |
| 283 | - if ($output_method == 'echo') |
|
| 284 | - template_menu(); |
|
| 302 | + if ($output_method == 'echo') { |
|
| 303 | + template_menu(); |
|
| 304 | + } |
|
| 285 | 305 | // What else could this do? |
| 286 | - else |
|
| 287 | - return $context['menu_buttons']; |
|
| 288 | -} |
|
| 306 | + else { |
|
| 307 | + return $context['menu_buttons']; |
|
| 308 | + } |
|
| 309 | + } |
|
| 289 | 310 | |
| 290 | 311 | /** |
| 291 | 312 | * Show a logout link. |
@@ -297,20 +318,23 @@ discard block |
||
| 297 | 318 | { |
| 298 | 319 | global $context, $txt, $scripturl; |
| 299 | 320 | |
| 300 | - if ($redirect_to != '') |
|
| 301 | - $_SESSION['logout_url'] = $redirect_to; |
|
| 321 | + if ($redirect_to != '') { |
|
| 322 | + $_SESSION['logout_url'] = $redirect_to; |
|
| 323 | + } |
|
| 302 | 324 | |
| 303 | 325 | // Guests can't log out. |
| 304 | - if ($context['user']['is_guest']) |
|
| 305 | - return false; |
|
| 326 | + if ($context['user']['is_guest']) { |
|
| 327 | + return false; |
|
| 328 | + } |
|
| 306 | 329 | |
| 307 | 330 | $link = '<a href="' . $scripturl . '?action=logout;' . $context['session_var'] . '=' . $context['session_id'] . '">' . $txt['logout'] . '</a>'; |
| 308 | 331 | |
| 309 | - if ($output_method == 'echo') |
|
| 310 | - echo $link; |
|
| 311 | - else |
|
| 312 | - return $link; |
|
| 313 | -} |
|
| 332 | + if ($output_method == 'echo') { |
|
| 333 | + echo $link; |
|
| 334 | + } else { |
|
| 335 | + return $link; |
|
| 336 | + } |
|
| 337 | + } |
|
| 314 | 338 | |
| 315 | 339 | /** |
| 316 | 340 | * Recent post list: [board] Subject by Poster Date |
@@ -326,17 +350,17 @@ discard block |
||
| 326 | 350 | global $modSettings, $context; |
| 327 | 351 | |
| 328 | 352 | // Excluding certain boards... |
| 329 | - if ($exclude_boards === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0) |
|
| 330 | - $exclude_boards = array($modSettings['recycle_board']); |
|
| 331 | - else |
|
| 332 | - $exclude_boards = empty($exclude_boards) ? array() : (is_array($exclude_boards) ? $exclude_boards : array($exclude_boards)); |
|
| 353 | + if ($exclude_boards === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0) { |
|
| 354 | + $exclude_boards = array($modSettings['recycle_board']); |
|
| 355 | + } else { |
|
| 356 | + $exclude_boards = empty($exclude_boards) ? array() : (is_array($exclude_boards) ? $exclude_boards : array($exclude_boards)); |
|
| 357 | + } |
|
| 333 | 358 | |
| 334 | 359 | // What about including certain boards - note we do some protection here as pre-2.0 didn't have this parameter. |
| 335 | 360 | if (is_array($include_boards) || (int) $include_boards === $include_boards) |
| 336 | 361 | { |
| 337 | 362 | $include_boards = is_array($include_boards) ? $include_boards : array($include_boards); |
| 338 | - } |
|
| 339 | - elseif ($include_boards != null) |
|
| 363 | + } elseif ($include_boards != null) |
|
| 340 | 364 | { |
| 341 | 365 | $include_boards = array(); |
| 342 | 366 | } |
@@ -373,8 +397,9 @@ discard block |
||
| 373 | 397 | { |
| 374 | 398 | global $modSettings; |
| 375 | 399 | |
| 376 | - if (empty($post_ids)) |
|
| 377 | - return; |
|
| 400 | + if (empty($post_ids)) { |
|
| 401 | + return; |
|
| 402 | + } |
|
| 378 | 403 | |
| 379 | 404 | // Allow the user to request more than one - why not? |
| 380 | 405 | $post_ids = is_array($post_ids) ? $post_ids : array($post_ids); |
@@ -409,8 +434,9 @@ discard block |
||
| 409 | 434 | global $scripturl, $txt, $user_info; |
| 410 | 435 | global $modSettings, $smcFunc, $context; |
| 411 | 436 | |
| 412 | - if (!empty($modSettings['enable_likes'])) |
|
| 413 | - $context['can_like'] = allowedTo('likes_like'); |
|
| 437 | + if (!empty($modSettings['enable_likes'])) { |
|
| 438 | + $context['can_like'] = allowedTo('likes_like'); |
|
| 439 | + } |
|
| 414 | 440 | |
| 415 | 441 | // Find all the posts. Newer ones will have higher IDs. |
| 416 | 442 | $request = $smcFunc['db_query']('substring', ' |
@@ -476,12 +502,13 @@ discard block |
||
| 476 | 502 | ); |
| 477 | 503 | |
| 478 | 504 | // Get the likes for each message. |
| 479 | - if (!empty($modSettings['enable_likes'])) |
|
| 480 | - $posts[$row['id_msg']]['likes'] = array( |
|
| 505 | + if (!empty($modSettings['enable_likes'])) { |
|
| 506 | + $posts[$row['id_msg']]['likes'] = array( |
|
| 481 | 507 | 'count' => $row['likes'], |
| 482 | 508 | 'you' => in_array($row['id_msg'], prepareLikesContext($row['id_topic'])), |
| 483 | 509 | 'can_like' => !$context['user']['is_guest'] && $row['id_member'] != $context['user']['id'] && !empty($context['can_like']), |
| 484 | 510 | ); |
| 511 | + } |
|
| 485 | 512 | } |
| 486 | 513 | $smcFunc['db_free_result']($request); |
| 487 | 514 | |
@@ -489,13 +516,14 @@ discard block |
||
| 489 | 516 | call_integration_hook('integrate_ssi_queryPosts', array(&$posts)); |
| 490 | 517 | |
| 491 | 518 | // Just return it. |
| 492 | - if ($output_method != 'echo' || empty($posts)) |
|
| 493 | - return $posts; |
|
| 519 | + if ($output_method != 'echo' || empty($posts)) { |
|
| 520 | + return $posts; |
|
| 521 | + } |
|
| 494 | 522 | |
| 495 | 523 | echo ' |
| 496 | 524 | <table style="border: none" class="ssi_table">'; |
| 497 | - foreach ($posts as $post) |
|
| 498 | - echo ' |
|
| 525 | + foreach ($posts as $post) { |
|
| 526 | + echo ' |
|
| 499 | 527 | <tr> |
| 500 | 528 | <td style="text-align: right; vertical-align: top; white-space: nowrap"> |
| 501 | 529 | [', $post['board']['link'], '] |
@@ -509,6 +537,7 @@ discard block |
||
| 509 | 537 | ', $post['time'], ' |
| 510 | 538 | </td> |
| 511 | 539 | </tr>'; |
| 540 | + } |
|
| 512 | 541 | echo ' |
| 513 | 542 | </table>'; |
| 514 | 543 | } |
@@ -526,25 +555,26 @@ discard block |
||
| 526 | 555 | global $settings, $scripturl, $txt, $user_info; |
| 527 | 556 | global $modSettings, $smcFunc, $context; |
| 528 | 557 | |
| 529 | - if ($exclude_boards === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0) |
|
| 530 | - $exclude_boards = array($modSettings['recycle_board']); |
|
| 531 | - else |
|
| 532 | - $exclude_boards = empty($exclude_boards) ? array() : (is_array($exclude_boards) ? $exclude_boards : array($exclude_boards)); |
|
| 558 | + if ($exclude_boards === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0) { |
|
| 559 | + $exclude_boards = array($modSettings['recycle_board']); |
|
| 560 | + } else { |
|
| 561 | + $exclude_boards = empty($exclude_boards) ? array() : (is_array($exclude_boards) ? $exclude_boards : array($exclude_boards)); |
|
| 562 | + } |
|
| 533 | 563 | |
| 534 | 564 | // Only some boards?. |
| 535 | 565 | if (is_array($include_boards) || (int) $include_boards === $include_boards) |
| 536 | 566 | { |
| 537 | 567 | $include_boards = is_array($include_boards) ? $include_boards : array($include_boards); |
| 538 | - } |
|
| 539 | - elseif ($include_boards != null) |
|
| 568 | + } elseif ($include_boards != null) |
|
| 540 | 569 | { |
| 541 | 570 | $output_method = $include_boards; |
| 542 | 571 | $include_boards = array(); |
| 543 | 572 | } |
| 544 | 573 | |
| 545 | 574 | $icon_sources = array(); |
| 546 | - foreach ($context['stable_icons'] as $icon) |
|
| 547 | - $icon_sources[$icon] = 'images_url'; |
|
| 575 | + foreach ($context['stable_icons'] as $icon) { |
|
| 576 | + $icon_sources[$icon] = 'images_url'; |
|
| 577 | + } |
|
| 548 | 578 | |
| 549 | 579 | // Find all the posts in distinct topics. Newer ones will have higher IDs. |
| 550 | 580 | $request = $smcFunc['db_query']('substring', ' |
@@ -569,13 +599,15 @@ discard block |
||
| 569 | 599 | ) |
| 570 | 600 | ); |
| 571 | 601 | $topics = array(); |
| 572 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 573 | - $topics[$row['id_topic']] = $row; |
|
| 602 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 603 | + $topics[$row['id_topic']] = $row; |
|
| 604 | + } |
|
| 574 | 605 | $smcFunc['db_free_result']($request); |
| 575 | 606 | |
| 576 | 607 | // Did we find anything? If not, bail. |
| 577 | - if (empty($topics)) |
|
| 578 | - return array(); |
|
| 608 | + if (empty($topics)) { |
|
| 609 | + return array(); |
|
| 610 | + } |
|
| 579 | 611 | |
| 580 | 612 | $recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0; |
| 581 | 613 | |
@@ -603,21 +635,24 @@ discard block |
||
| 603 | 635 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 604 | 636 | { |
| 605 | 637 | $row['body'] = strip_tags(strtr(parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']), array('<br>' => ' '))); |
| 606 | - if ($smcFunc['strlen']($row['body']) > 128) |
|
| 607 | - $row['body'] = $smcFunc['substr']($row['body'], 0, 128) . '...'; |
|
| 638 | + if ($smcFunc['strlen']($row['body']) > 128) { |
|
| 639 | + $row['body'] = $smcFunc['substr']($row['body'], 0, 128) . '...'; |
|
| 640 | + } |
|
| 608 | 641 | |
| 609 | 642 | // Censor the subject. |
| 610 | 643 | censorText($row['subject']); |
| 611 | 644 | censorText($row['body']); |
| 612 | 645 | |
| 613 | 646 | // Recycled icon |
| 614 | - if (!empty($recycle_board) && $topics[$row['id_topic']]['id_board']) |
|
| 615 | - $row['icon'] = 'recycled'; |
|
| 647 | + if (!empty($recycle_board) && $topics[$row['id_topic']]['id_board']) { |
|
| 648 | + $row['icon'] = 'recycled'; |
|
| 649 | + } |
|
| 616 | 650 | |
| 617 | - if (!empty($modSettings['messageIconChecks_enable']) && !isset($icon_sources[$row['icon']])) |
|
| 618 | - $icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
| 619 | - elseif (!isset($icon_sources[$row['icon']])) |
|
| 620 | - $icon_sources[$row['icon']] = 'images_url'; |
|
| 651 | + if (!empty($modSettings['messageIconChecks_enable']) && !isset($icon_sources[$row['icon']])) { |
|
| 652 | + $icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
| 653 | + } elseif (!isset($icon_sources[$row['icon']])) { |
|
| 654 | + $icon_sources[$row['icon']] = 'images_url'; |
|
| 655 | + } |
|
| 621 | 656 | |
| 622 | 657 | // Build the array. |
| 623 | 658 | $posts[] = array( |
@@ -656,13 +691,14 @@ discard block |
||
| 656 | 691 | call_integration_hook('integrate_ssi_recentTopics', array(&$posts)); |
| 657 | 692 | |
| 658 | 693 | // Just return it. |
| 659 | - if ($output_method != 'echo' || empty($posts)) |
|
| 660 | - return $posts; |
|
| 694 | + if ($output_method != 'echo' || empty($posts)) { |
|
| 695 | + return $posts; |
|
| 696 | + } |
|
| 661 | 697 | |
| 662 | 698 | echo ' |
| 663 | 699 | <table style="border: none" class="ssi_table">'; |
| 664 | - foreach ($posts as $post) |
|
| 665 | - echo ' |
|
| 700 | + foreach ($posts as $post) { |
|
| 701 | + echo ' |
|
| 666 | 702 | <tr> |
| 667 | 703 | <td style="text-align: right; vertical-align: top; white-space: nowrap"> |
| 668 | 704 | [', $post['board']['link'], '] |
@@ -676,6 +712,7 @@ discard block |
||
| 676 | 712 | ', $post['time'], ' |
| 677 | 713 | </td> |
| 678 | 714 | </tr>'; |
| 715 | + } |
|
| 679 | 716 | echo ' |
| 680 | 717 | </table>'; |
| 681 | 718 | } |
@@ -700,27 +737,30 @@ discard block |
||
| 700 | 737 | ) |
| 701 | 738 | ); |
| 702 | 739 | $return = array(); |
| 703 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 704 | - $return[] = array( |
|
| 740 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 741 | + $return[] = array( |
|
| 705 | 742 | 'id' => $row['id_member'], |
| 706 | 743 | 'name' => $row['real_name'], |
| 707 | 744 | 'href' => $scripturl . '?action=profile;u=' . $row['id_member'], |
| 708 | 745 | 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>', |
| 709 | 746 | 'posts' => $row['posts'] |
| 710 | 747 | ); |
| 748 | + } |
|
| 711 | 749 | $smcFunc['db_free_result']($request); |
| 712 | 750 | |
| 713 | 751 | // If mods want to do somthing with this list of members, let them do that now. |
| 714 | 752 | call_integration_hook('integrate_ssi_topPoster', array(&$return)); |
| 715 | 753 | |
| 716 | 754 | // Just return all the top posters. |
| 717 | - if ($output_method != 'echo') |
|
| 718 | - return $return; |
|
| 755 | + if ($output_method != 'echo') { |
|
| 756 | + return $return; |
|
| 757 | + } |
|
| 719 | 758 | |
| 720 | 759 | // Make a quick array to list the links in. |
| 721 | 760 | $temp_array = array(); |
| 722 | - foreach ($return as $member) |
|
| 723 | - $temp_array[] = $member['link']; |
|
| 761 | + foreach ($return as $member) { |
|
| 762 | + $temp_array[] = $member['link']; |
|
| 763 | + } |
|
| 724 | 764 | |
| 725 | 765 | echo implode(', ', $temp_array); |
| 726 | 766 | } |
@@ -752,8 +792,8 @@ discard block |
||
| 752 | 792 | ) |
| 753 | 793 | ); |
| 754 | 794 | $boards = array(); |
| 755 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 756 | - $boards[] = array( |
|
| 795 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 796 | + $boards[] = array( |
|
| 757 | 797 | 'id' => $row['id_board'], |
| 758 | 798 | 'num_posts' => $row['num_posts'], |
| 759 | 799 | 'num_topics' => $row['num_topics'], |
@@ -762,14 +802,16 @@ discard block |
||
| 762 | 802 | 'href' => $scripturl . '?board=' . $row['id_board'] . '.0', |
| 763 | 803 | 'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>' |
| 764 | 804 | ); |
| 805 | + } |
|
| 765 | 806 | $smcFunc['db_free_result']($request); |
| 766 | 807 | |
| 767 | 808 | // If mods want to do somthing with this list of boards, let them do that now. |
| 768 | 809 | call_integration_hook('integrate_ssi_topBoards', array(&$boards)); |
| 769 | 810 | |
| 770 | 811 | // If we shouldn't output or have nothing to output, just jump out. |
| 771 | - if ($output_method != 'echo' || empty($boards)) |
|
| 772 | - return $boards; |
|
| 812 | + if ($output_method != 'echo' || empty($boards)) { |
|
| 813 | + return $boards; |
|
| 814 | + } |
|
| 773 | 815 | |
| 774 | 816 | echo ' |
| 775 | 817 | <table class="ssi_table"> |
@@ -778,13 +820,14 @@ discard block |
||
| 778 | 820 | <th style="text-align: left">', $txt['board_topics'], '</th> |
| 779 | 821 | <th style="text-align: left">', $txt['posts'], '</th> |
| 780 | 822 | </tr>'; |
| 781 | - foreach ($boards as $sBoard) |
|
| 782 | - echo ' |
|
| 823 | + foreach ($boards as $sBoard) { |
|
| 824 | + echo ' |
|
| 783 | 825 | <tr> |
| 784 | 826 | <td>', $sBoard['link'], $sBoard['new'] ? ' <a href="' . $sBoard['href'] . '" class="new_posts">' . $txt['new'] . '</a>' : '', '</td> |
| 785 | 827 | <td style="text-align: right">', comma_format($sBoard['num_topics']), '</td> |
| 786 | 828 | <td style="text-align: right">', comma_format($sBoard['num_posts']), '</td> |
| 787 | 829 | </tr>'; |
| 830 | + } |
|
| 788 | 831 | echo ' |
| 789 | 832 | </table>'; |
| 790 | 833 | } |
@@ -817,12 +860,13 @@ discard block |
||
| 817 | 860 | ) |
| 818 | 861 | ); |
| 819 | 862 | $topic_ids = array(); |
| 820 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 821 | - $topic_ids[] = $row['id_topic']; |
|
| 863 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 864 | + $topic_ids[] = $row['id_topic']; |
|
| 865 | + } |
|
| 822 | 866 | $smcFunc['db_free_result']($request); |
| 867 | + } else { |
|
| 868 | + $topic_ids = array(); |
|
| 823 | 869 | } |
| 824 | - else |
|
| 825 | - $topic_ids = array(); |
|
| 826 | 870 | |
| 827 | 871 | $request = $smcFunc['db_query']('', ' |
| 828 | 872 | SELECT m.subject, m.id_topic, t.num_views, t.num_replies |
@@ -861,8 +905,9 @@ discard block |
||
| 861 | 905 | // If mods want to do somthing with this list of topics, let them do that now. |
| 862 | 906 | call_integration_hook('integrate_ssi_topTopics', array(&$topics, $type)); |
| 863 | 907 | |
| 864 | - if ($output_method != 'echo' || empty($topics)) |
|
| 865 | - return $topics; |
|
| 908 | + if ($output_method != 'echo' || empty($topics)) { |
|
| 909 | + return $topics; |
|
| 910 | + } |
|
| 866 | 911 | |
| 867 | 912 | echo ' |
| 868 | 913 | <table class="ssi_table"> |
@@ -871,8 +916,8 @@ discard block |
||
| 871 | 916 | <th style="text-align: left">', $txt['views'], '</th> |
| 872 | 917 | <th style="text-align: left">', $txt['replies'], '</th> |
| 873 | 918 | </tr>'; |
| 874 | - foreach ($topics as $sTopic) |
|
| 875 | - echo ' |
|
| 919 | + foreach ($topics as $sTopic) { |
|
| 920 | + echo ' |
|
| 876 | 921 | <tr> |
| 877 | 922 | <td style="text-align: left"> |
| 878 | 923 | ', $sTopic['link'], ' |
@@ -880,6 +925,7 @@ discard block |
||
| 880 | 925 | <td style="text-align: right">', comma_format($sTopic['num_views']), '</td> |
| 881 | 926 | <td style="text-align: right">', comma_format($sTopic['num_replies']), '</td> |
| 882 | 927 | </tr>'; |
| 928 | + } |
|
| 883 | 929 | echo ' |
| 884 | 930 | </table>'; |
| 885 | 931 | } |
@@ -915,12 +961,13 @@ discard block |
||
| 915 | 961 | { |
| 916 | 962 | global $txt, $context; |
| 917 | 963 | |
| 918 | - if ($output_method == 'echo') |
|
| 919 | - echo ' |
|
| 964 | + if ($output_method == 'echo') { |
|
| 965 | + echo ' |
|
| 920 | 966 | ', sprintf($txt['welcome_newest_member'], $context['common_stats']['latest_member']['link']), '<br>'; |
| 921 | - else |
|
| 922 | - return $context['common_stats']['latest_member']; |
|
| 923 | -} |
|
| 967 | + } else { |
|
| 968 | + return $context['common_stats']['latest_member']; |
|
| 969 | + } |
|
| 970 | + } |
|
| 924 | 971 | |
| 925 | 972 | /** |
| 926 | 973 | * Fetches a random member. |
@@ -969,8 +1016,9 @@ discard block |
||
| 969 | 1016 | } |
| 970 | 1017 | |
| 971 | 1018 | // Just to be sure put the random generator back to something... random. |
| 972 | - if ($random_type != '') |
|
| 973 | - mt_srand(time()); |
|
| 1019 | + if ($random_type != '') { |
|
| 1020 | + mt_srand(time()); |
|
| 1021 | + } |
|
| 974 | 1022 | |
| 975 | 1023 | return $result; |
| 976 | 1024 | } |
@@ -983,8 +1031,9 @@ discard block |
||
| 983 | 1031 | */ |
| 984 | 1032 | function ssi_fetchMember($member_ids = array(), $output_method = 'echo') |
| 985 | 1033 | { |
| 986 | - if (empty($member_ids)) |
|
| 987 | - return; |
|
| 1034 | + if (empty($member_ids)) { |
|
| 1035 | + return; |
|
| 1036 | + } |
|
| 988 | 1037 | |
| 989 | 1038 | // Can have more than one member if you really want... |
| 990 | 1039 | $member_ids = is_array($member_ids) ? $member_ids : array($member_ids); |
@@ -1009,8 +1058,9 @@ discard block |
||
| 1009 | 1058 | */ |
| 1010 | 1059 | function ssi_fetchGroupMembers($group_id = null, $output_method = 'echo') |
| 1011 | 1060 | { |
| 1012 | - if ($group_id === null) |
|
| 1013 | - return; |
|
| 1061 | + if ($group_id === null) { |
|
| 1062 | + return; |
|
| 1063 | + } |
|
| 1014 | 1064 | |
| 1015 | 1065 | $query_where = ' |
| 1016 | 1066 | id_group = {int:id_group} |
@@ -1037,8 +1087,9 @@ discard block |
||
| 1037 | 1087 | { |
| 1038 | 1088 | global $smcFunc, $memberContext; |
| 1039 | 1089 | |
| 1040 | - if ($query_where === null) |
|
| 1041 | - return; |
|
| 1090 | + if ($query_where === null) { |
|
| 1091 | + return; |
|
| 1092 | + } |
|
| 1042 | 1093 | |
| 1043 | 1094 | // Fetch the members in question. |
| 1044 | 1095 | $request = $smcFunc['db_query']('', ' |
@@ -1051,12 +1102,14 @@ discard block |
||
| 1051 | 1102 | )) |
| 1052 | 1103 | ); |
| 1053 | 1104 | $members = array(); |
| 1054 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1055 | - $members[] = $row['id_member']; |
|
| 1105 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1106 | + $members[] = $row['id_member']; |
|
| 1107 | + } |
|
| 1056 | 1108 | $smcFunc['db_free_result']($request); |
| 1057 | 1109 | |
| 1058 | - if (empty($members)) |
|
| 1059 | - return array(); |
|
| 1110 | + if (empty($members)) { |
|
| 1111 | + return array(); |
|
| 1112 | + } |
|
| 1060 | 1113 | |
| 1061 | 1114 | // If mods want to do somthing with this list of members, let them do that now. |
| 1062 | 1115 | call_integration_hook('integrate_ssi_queryMembers', array(&$members)); |
@@ -1065,23 +1118,25 @@ discard block |
||
| 1065 | 1118 | loadMemberData($members); |
| 1066 | 1119 | |
| 1067 | 1120 | // Draw the table! |
| 1068 | - if ($output_method == 'echo') |
|
| 1069 | - echo ' |
|
| 1121 | + if ($output_method == 'echo') { |
|
| 1122 | + echo ' |
|
| 1070 | 1123 | <table style="border: none" class="ssi_table">'; |
| 1124 | + } |
|
| 1071 | 1125 | |
| 1072 | 1126 | $query_members = array(); |
| 1073 | 1127 | foreach ($members as $member) |
| 1074 | 1128 | { |
| 1075 | 1129 | // Load their context data. |
| 1076 | - if (!loadMemberContext($member)) |
|
| 1077 | - continue; |
|
| 1130 | + if (!loadMemberContext($member)) { |
|
| 1131 | + continue; |
|
| 1132 | + } |
|
| 1078 | 1133 | |
| 1079 | 1134 | // Store this member's information. |
| 1080 | 1135 | $query_members[$member] = $memberContext[$member]; |
| 1081 | 1136 | |
| 1082 | 1137 | // Only do something if we're echo'ing. |
| 1083 | - if ($output_method == 'echo') |
|
| 1084 | - echo ' |
|
| 1138 | + if ($output_method == 'echo') { |
|
| 1139 | + echo ' |
|
| 1085 | 1140 | <tr> |
| 1086 | 1141 | <td style="text-align: right; vertical-align: top; white-space: nowrap"> |
| 1087 | 1142 | ', $query_members[$member]['link'], ' |
@@ -1089,12 +1144,14 @@ discard block |
||
| 1089 | 1144 | <br>', $query_members[$member]['avatar']['image'], ' |
| 1090 | 1145 | </td> |
| 1091 | 1146 | </tr>'; |
| 1147 | + } |
|
| 1092 | 1148 | } |
| 1093 | 1149 | |
| 1094 | 1150 | // End the table if appropriate. |
| 1095 | - if ($output_method == 'echo') |
|
| 1096 | - echo ' |
|
| 1151 | + if ($output_method == 'echo') { |
|
| 1152 | + echo ' |
|
| 1097 | 1153 | </table>'; |
| 1154 | + } |
|
| 1098 | 1155 | |
| 1099 | 1156 | // Send back the data. |
| 1100 | 1157 | return $query_members; |
@@ -1109,8 +1166,9 @@ discard block |
||
| 1109 | 1166 | { |
| 1110 | 1167 | global $txt, $scripturl, $modSettings, $smcFunc; |
| 1111 | 1168 | |
| 1112 | - if (!allowedTo('view_stats')) |
|
| 1113 | - return; |
|
| 1169 | + if (!allowedTo('view_stats')) { |
|
| 1170 | + return; |
|
| 1171 | + } |
|
| 1114 | 1172 | |
| 1115 | 1173 | $totals = array( |
| 1116 | 1174 | 'members' => $modSettings['totalMembers'], |
@@ -1139,8 +1197,9 @@ discard block |
||
| 1139 | 1197 | // If mods want to do somthing with the board stats, let them do that now. |
| 1140 | 1198 | call_integration_hook('integrate_ssi_boardStats', array(&$totals)); |
| 1141 | 1199 | |
| 1142 | - if ($output_method != 'echo') |
|
| 1143 | - return $totals; |
|
| 1200 | + if ($output_method != 'echo') { |
|
| 1201 | + return $totals; |
|
| 1202 | + } |
|
| 1144 | 1203 | |
| 1145 | 1204 | echo ' |
| 1146 | 1205 | ', $txt['total_members'], ': <a href="', $scripturl . '?action=mlist">', comma_format($totals['members']), '</a><br> |
@@ -1169,8 +1228,8 @@ discard block |
||
| 1169 | 1228 | call_integration_hook('integrate_ssi_whosOnline', array(&$return)); |
| 1170 | 1229 | |
| 1171 | 1230 | // Add some redundancy for backwards compatibility reasons. |
| 1172 | - if ($output_method != 'echo') |
|
| 1173 | - return $return + array( |
|
| 1231 | + if ($output_method != 'echo') { |
|
| 1232 | + return $return + array( |
|
| 1174 | 1233 | 'users' => $return['users_online'], |
| 1175 | 1234 | 'guests' => $return['num_guests'], |
| 1176 | 1235 | 'hidden' => $return['num_users_hidden'], |
@@ -1178,29 +1237,35 @@ discard block |
||
| 1178 | 1237 | 'num_users' => $return['num_users_online'], |
| 1179 | 1238 | 'total_users' => $return['num_users_online'] + $return['num_guests'], |
| 1180 | 1239 | ); |
| 1240 | + } |
|
| 1181 | 1241 | |
| 1182 | 1242 | echo ' |
| 1183 | 1243 | ', 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']; |
| 1184 | 1244 | |
| 1185 | 1245 | $bracketList = array(); |
| 1186 | - if (!empty($user_info['buddies'])) |
|
| 1187 | - $bracketList[] = comma_format($return['num_buddies']) . ' ' . ($return['num_buddies'] == 1 ? $txt['buddy'] : $txt['buddies']); |
|
| 1188 | - if (!empty($return['num_spiders'])) |
|
| 1189 | - $bracketList[] = comma_format($return['num_spiders']) . ' ' . ($return['num_spiders'] == 1 ? $txt['spider'] : $txt['spiders']); |
|
| 1190 | - if (!empty($return['num_users_hidden'])) |
|
| 1191 | - $bracketList[] = comma_format($return['num_users_hidden']) . ' ' . $txt['hidden']; |
|
| 1246 | + if (!empty($user_info['buddies'])) { |
|
| 1247 | + $bracketList[] = comma_format($return['num_buddies']) . ' ' . ($return['num_buddies'] == 1 ? $txt['buddy'] : $txt['buddies']); |
|
| 1248 | + } |
|
| 1249 | + if (!empty($return['num_spiders'])) { |
|
| 1250 | + $bracketList[] = comma_format($return['num_spiders']) . ' ' . ($return['num_spiders'] == 1 ? $txt['spider'] : $txt['spiders']); |
|
| 1251 | + } |
|
| 1252 | + if (!empty($return['num_users_hidden'])) { |
|
| 1253 | + $bracketList[] = comma_format($return['num_users_hidden']) . ' ' . $txt['hidden']; |
|
| 1254 | + } |
|
| 1192 | 1255 | |
| 1193 | - if (!empty($bracketList)) |
|
| 1194 | - echo ' (' . implode(', ', $bracketList) . ')'; |
|
| 1256 | + if (!empty($bracketList)) { |
|
| 1257 | + echo ' (' . implode(', ', $bracketList) . ')'; |
|
| 1258 | + } |
|
| 1195 | 1259 | |
| 1196 | 1260 | echo '<br> |
| 1197 | 1261 | ', implode(', ', $return['list_users_online']); |
| 1198 | 1262 | |
| 1199 | 1263 | // Showing membergroups? |
| 1200 | - if (!empty($settings['show_group_key']) && !empty($return['membergroups'])) |
|
| 1201 | - echo '<br> |
|
| 1264 | + if (!empty($settings['show_group_key']) && !empty($return['membergroups'])) { |
|
| 1265 | + echo '<br> |
|
| 1202 | 1266 | [' . implode('] [', $return['membergroups']) . ']'; |
| 1203 | -} |
|
| 1267 | + } |
|
| 1268 | + } |
|
| 1204 | 1269 | |
| 1205 | 1270 | /** |
| 1206 | 1271 | * Just like whosOnline except it also logs the online presence. |
@@ -1211,11 +1276,12 @@ discard block |
||
| 1211 | 1276 | { |
| 1212 | 1277 | writeLog(); |
| 1213 | 1278 | |
| 1214 | - if ($output_method != 'echo') |
|
| 1215 | - return ssi_whosOnline($output_method); |
|
| 1216 | - else |
|
| 1217 | - ssi_whosOnline($output_method); |
|
| 1218 | -} |
|
| 1279 | + if ($output_method != 'echo') { |
|
| 1280 | + return ssi_whosOnline($output_method); |
|
| 1281 | + } else { |
|
| 1282 | + ssi_whosOnline($output_method); |
|
| 1283 | + } |
|
| 1284 | + } |
|
| 1219 | 1285 | |
| 1220 | 1286 | // Shows a login box. |
| 1221 | 1287 | /** |
@@ -1228,11 +1294,13 @@ discard block |
||
| 1228 | 1294 | { |
| 1229 | 1295 | global $scripturl, $txt, $user_info, $context; |
| 1230 | 1296 | |
| 1231 | - if ($redirect_to != '') |
|
| 1232 | - $_SESSION['login_url'] = $redirect_to; |
|
| 1297 | + if ($redirect_to != '') { |
|
| 1298 | + $_SESSION['login_url'] = $redirect_to; |
|
| 1299 | + } |
|
| 1233 | 1300 | |
| 1234 | - if ($output_method != 'echo' || !$user_info['is_guest']) |
|
| 1235 | - return $user_info['is_guest']; |
|
| 1301 | + if ($output_method != 'echo' || !$user_info['is_guest']) { |
|
| 1302 | + return $user_info['is_guest']; |
|
| 1303 | + } |
|
| 1236 | 1304 | |
| 1237 | 1305 | // Create a login token |
| 1238 | 1306 | createToken('login'); |
@@ -1284,8 +1352,9 @@ discard block |
||
| 1284 | 1352 | |
| 1285 | 1353 | $boardsAllowed = array_intersect(boardsAllowedTo('poll_view'), boardsAllowedTo('poll_vote')); |
| 1286 | 1354 | |
| 1287 | - if (empty($boardsAllowed)) |
|
| 1288 | - return array(); |
|
| 1355 | + if (empty($boardsAllowed)) { |
|
| 1356 | + return array(); |
|
| 1357 | + } |
|
| 1289 | 1358 | |
| 1290 | 1359 | $request = $smcFunc['db_query']('', ' |
| 1291 | 1360 | SELECT p.id_poll, p.question, t.id_topic, p.max_votes, p.guest_vote, p.hide_results, p.expire_time |
@@ -1318,12 +1387,14 @@ discard block |
||
| 1318 | 1387 | $smcFunc['db_free_result']($request); |
| 1319 | 1388 | |
| 1320 | 1389 | // This user has voted on all the polls. |
| 1321 | - if (empty($row) || !is_array($row)) |
|
| 1322 | - return array(); |
|
| 1390 | + if (empty($row) || !is_array($row)) { |
|
| 1391 | + return array(); |
|
| 1392 | + } |
|
| 1323 | 1393 | |
| 1324 | 1394 | // If this is a guest who's voted we'll through ourselves to show poll to show the results. |
| 1325 | - if ($user_info['is_guest'] && (!$row['guest_vote'] || (isset($_COOKIE['guest_poll_vote']) && in_array($row['id_poll'], explode(',', $_COOKIE['guest_poll_vote']))))) |
|
| 1326 | - return ssi_showPoll($row['id_topic'], $output_method); |
|
| 1395 | + if ($user_info['is_guest'] && (!$row['guest_vote'] || (isset($_COOKIE['guest_poll_vote']) && in_array($row['id_poll'], explode(',', $_COOKIE['guest_poll_vote']))))) { |
|
| 1396 | + return ssi_showPoll($row['id_topic'], $output_method); |
|
| 1397 | + } |
|
| 1327 | 1398 | |
| 1328 | 1399 | $request = $smcFunc['db_query']('', ' |
| 1329 | 1400 | SELECT COUNT(DISTINCT id_member) |
@@ -1387,8 +1458,9 @@ discard block |
||
| 1387 | 1458 | // If mods want to do somthing with this list of polls, let them do that now. |
| 1388 | 1459 | call_integration_hook('integrate_ssi_recentPoll', array(&$return, $topPollInstead)); |
| 1389 | 1460 | |
| 1390 | - if ($output_method != 'echo') |
|
| 1391 | - return $return; |
|
| 1461 | + if ($output_method != 'echo') { |
|
| 1462 | + return $return; |
|
| 1463 | + } |
|
| 1392 | 1464 | |
| 1393 | 1465 | if ($allow_view_results) |
| 1394 | 1466 | { |
@@ -1397,19 +1469,20 @@ discard block |
||
| 1397 | 1469 | <strong>', $return['question'], '</strong><br> |
| 1398 | 1470 | ', !empty($return['allowed_warning']) ? $return['allowed_warning'] . '<br>' : ''; |
| 1399 | 1471 | |
| 1400 | - foreach ($return['options'] as $option) |
|
| 1401 | - echo ' |
|
| 1472 | + foreach ($return['options'] as $option) { |
|
| 1473 | + echo ' |
|
| 1402 | 1474 | <label for="', $option['id'], '">', $option['vote_button'], ' ', $option['option'], '</label><br>'; |
| 1475 | + } |
|
| 1403 | 1476 | |
| 1404 | 1477 | echo ' |
| 1405 | 1478 | <input type="submit" value="', $txt['poll_vote'], '" class="button"> |
| 1406 | 1479 | <input type="hidden" name="poll" value="', $return['id'], '"> |
| 1407 | 1480 | <input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '"> |
| 1408 | 1481 | </form>'; |
| 1482 | + } else { |
|
| 1483 | + echo $txt['poll_cannot_see']; |
|
| 1484 | + } |
|
| 1409 | 1485 | } |
| 1410 | - else |
|
| 1411 | - echo $txt['poll_cannot_see']; |
|
| 1412 | -} |
|
| 1413 | 1486 | |
| 1414 | 1487 | /** |
| 1415 | 1488 | * Shows the poll from the specified topic |
@@ -1423,13 +1496,15 @@ discard block |
||
| 1423 | 1496 | |
| 1424 | 1497 | $boardsAllowed = boardsAllowedTo('poll_view'); |
| 1425 | 1498 | |
| 1426 | - if (empty($boardsAllowed)) |
|
| 1427 | - return array(); |
|
| 1499 | + if (empty($boardsAllowed)) { |
|
| 1500 | + return array(); |
|
| 1501 | + } |
|
| 1428 | 1502 | |
| 1429 | - if ($topic === null && isset($_REQUEST['ssi_topic'])) |
|
| 1430 | - $topic = (int) $_REQUEST['ssi_topic']; |
|
| 1431 | - else |
|
| 1432 | - $topic = (int) $topic; |
|
| 1503 | + if ($topic === null && isset($_REQUEST['ssi_topic'])) { |
|
| 1504 | + $topic = (int) $_REQUEST['ssi_topic']; |
|
| 1505 | + } else { |
|
| 1506 | + $topic = (int) $topic; |
|
| 1507 | + } |
|
| 1433 | 1508 | |
| 1434 | 1509 | $request = $smcFunc['db_query']('', ' |
| 1435 | 1510 | SELECT |
@@ -1450,17 +1525,18 @@ discard block |
||
| 1450 | 1525 | ); |
| 1451 | 1526 | |
| 1452 | 1527 | // Either this topic has no poll, or the user cannot view it. |
| 1453 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 1454 | - return array(); |
|
| 1528 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 1529 | + return array(); |
|
| 1530 | + } |
|
| 1455 | 1531 | |
| 1456 | 1532 | $row = $smcFunc['db_fetch_assoc']($request); |
| 1457 | 1533 | $smcFunc['db_free_result']($request); |
| 1458 | 1534 | |
| 1459 | 1535 | // Check if they can vote. |
| 1460 | 1536 | $already_voted = false; |
| 1461 | - if (!empty($row['expire_time']) && $row['expire_time'] < time()) |
|
| 1462 | - $allow_vote = false; |
|
| 1463 | - elseif ($user_info['is_guest']) |
|
| 1537 | + if (!empty($row['expire_time']) && $row['expire_time'] < time()) { |
|
| 1538 | + $allow_vote = false; |
|
| 1539 | + } elseif ($user_info['is_guest']) |
|
| 1464 | 1540 | { |
| 1465 | 1541 | // There's a difference between "allowed to vote" and "already voted"... |
| 1466 | 1542 | $allow_vote = $row['guest_vote']; |
@@ -1470,10 +1546,9 @@ discard block |
||
| 1470 | 1546 | { |
| 1471 | 1547 | $already_voted = true; |
| 1472 | 1548 | } |
| 1473 | - } |
|
| 1474 | - elseif (!empty($row['voting_locked']) || !allowedTo('poll_vote', $row['id_board'])) |
|
| 1475 | - $allow_vote = false; |
|
| 1476 | - else |
|
| 1549 | + } elseif (!empty($row['voting_locked']) || !allowedTo('poll_vote', $row['id_board'])) { |
|
| 1550 | + $allow_vote = false; |
|
| 1551 | + } else |
|
| 1477 | 1552 | { |
| 1478 | 1553 | $request = $smcFunc['db_query']('', ' |
| 1479 | 1554 | SELECT id_member |
@@ -1555,8 +1630,9 @@ discard block |
||
| 1555 | 1630 | // If mods want to do somthing with this poll, let them do that now. |
| 1556 | 1631 | call_integration_hook('integrate_ssi_showPoll', array(&$return)); |
| 1557 | 1632 | |
| 1558 | - if ($output_method != 'echo') |
|
| 1559 | - return $return; |
|
| 1633 | + if ($output_method != 'echo') { |
|
| 1634 | + return $return; |
|
| 1635 | + } |
|
| 1560 | 1636 | |
| 1561 | 1637 | if ($return['allow_vote']) |
| 1562 | 1638 | { |
@@ -1565,17 +1641,17 @@ discard block |
||
| 1565 | 1641 | <strong>', $return['question'], '</strong><br> |
| 1566 | 1642 | ', !empty($return['allowed_warning']) ? $return['allowed_warning'] . '<br>' : ''; |
| 1567 | 1643 | |
| 1568 | - foreach ($return['options'] as $option) |
|
| 1569 | - echo ' |
|
| 1644 | + foreach ($return['options'] as $option) { |
|
| 1645 | + echo ' |
|
| 1570 | 1646 | <label for="', $option['id'], '">', $option['vote_button'], ' ', $option['option'], '</label><br>'; |
| 1647 | + } |
|
| 1571 | 1648 | |
| 1572 | 1649 | echo ' |
| 1573 | 1650 | <input type="submit" value="', $txt['poll_vote'], '" class="button"> |
| 1574 | 1651 | <input type="hidden" name="poll" value="', $return['id'], '"> |
| 1575 | 1652 | <input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '"> |
| 1576 | 1653 | </form>'; |
| 1577 | - } |
|
| 1578 | - else |
|
| 1654 | + } else |
|
| 1579 | 1655 | { |
| 1580 | 1656 | echo ' |
| 1581 | 1657 | <div class="ssi_poll"> |
@@ -1655,27 +1731,32 @@ discard block |
||
| 1655 | 1731 | 'is_approved' => 1, |
| 1656 | 1732 | ) |
| 1657 | 1733 | ); |
| 1658 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 1659 | - die; |
|
| 1734 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 1735 | + die; |
|
| 1736 | + } |
|
| 1660 | 1737 | $row = $smcFunc['db_fetch_assoc']($request); |
| 1661 | 1738 | $smcFunc['db_free_result']($request); |
| 1662 | 1739 | |
| 1663 | - if (!empty($row['voting_locked']) || ($row['selected'] != -1 && !$user_info['is_guest']) || (!empty($row['expire_time']) && time() > $row['expire_time'])) |
|
| 1664 | - redirectexit('topic=' . $row['id_topic'] . '.0'); |
|
| 1740 | + if (!empty($row['voting_locked']) || ($row['selected'] != -1 && !$user_info['is_guest']) || (!empty($row['expire_time']) && time() > $row['expire_time'])) { |
|
| 1741 | + redirectexit('topic=' . $row['id_topic'] . '.0'); |
|
| 1742 | + } |
|
| 1665 | 1743 | |
| 1666 | 1744 | // Too many options checked? |
| 1667 | - if (count($_REQUEST['options']) > $row['max_votes']) |
|
| 1668 | - redirectexit('topic=' . $row['id_topic'] . '.0'); |
|
| 1745 | + if (count($_REQUEST['options']) > $row['max_votes']) { |
|
| 1746 | + redirectexit('topic=' . $row['id_topic'] . '.0'); |
|
| 1747 | + } |
|
| 1669 | 1748 | |
| 1670 | 1749 | // It's a guest who has already voted? |
| 1671 | 1750 | if ($user_info['is_guest']) |
| 1672 | 1751 | { |
| 1673 | 1752 | // Guest voting disabled? |
| 1674 | - if (!$row['guest_vote']) |
|
| 1675 | - redirectexit('topic=' . $row['id_topic'] . '.0'); |
|
| 1753 | + if (!$row['guest_vote']) { |
|
| 1754 | + redirectexit('topic=' . $row['id_topic'] . '.0'); |
|
| 1755 | + } |
|
| 1676 | 1756 | // Already voted? |
| 1677 | - elseif (isset($_COOKIE['guest_poll_vote']) && in_array($row['id_poll'], explode(',', $_COOKIE['guest_poll_vote']))) |
|
| 1678 | - redirectexit('topic=' . $row['id_topic'] . '.0'); |
|
| 1757 | + elseif (isset($_COOKIE['guest_poll_vote']) && in_array($row['id_poll'], explode(',', $_COOKIE['guest_poll_vote']))) { |
|
| 1758 | + redirectexit('topic=' . $row['id_topic'] . '.0'); |
|
| 1759 | + } |
|
| 1679 | 1760 | } |
| 1680 | 1761 | |
| 1681 | 1762 | $sOptions = array(); |
@@ -1729,11 +1810,13 @@ discard block |
||
| 1729 | 1810 | { |
| 1730 | 1811 | global $scripturl, $txt, $context; |
| 1731 | 1812 | |
| 1732 | - if (!allowedTo('search_posts')) |
|
| 1733 | - return; |
|
| 1813 | + if (!allowedTo('search_posts')) { |
|
| 1814 | + return; |
|
| 1815 | + } |
|
| 1734 | 1816 | |
| 1735 | - if ($output_method != 'echo') |
|
| 1736 | - return $scripturl . '?action=search'; |
|
| 1817 | + if ($output_method != 'echo') { |
|
| 1818 | + return $scripturl . '?action=search'; |
|
| 1819 | + } |
|
| 1737 | 1820 | |
| 1738 | 1821 | echo ' |
| 1739 | 1822 | <form action="', $scripturl, '?action=search2" method="post" accept-charset="', $context['character_set'], '"> |
@@ -1755,8 +1838,9 @@ discard block |
||
| 1755 | 1838 | // 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. |
| 1756 | 1839 | call_integration_hook('integrate_ssi_news'); |
| 1757 | 1840 | |
| 1758 | - if ($output_method != 'echo') |
|
| 1759 | - return $context['random_news_line']; |
|
| 1841 | + if ($output_method != 'echo') { |
|
| 1842 | + return $context['random_news_line']; |
|
| 1843 | + } |
|
| 1760 | 1844 | |
| 1761 | 1845 | echo $context['random_news_line']; |
| 1762 | 1846 | } |
@@ -1770,8 +1854,9 @@ discard block |
||
| 1770 | 1854 | { |
| 1771 | 1855 | global $scripturl, $modSettings, $user_info; |
| 1772 | 1856 | |
| 1773 | - if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view') || !allowedTo('profile_view')) |
|
| 1774 | - return; |
|
| 1857 | + if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view') || !allowedTo('profile_view')) { |
|
| 1858 | + return; |
|
| 1859 | + } |
|
| 1775 | 1860 | |
| 1776 | 1861 | $eventOptions = array( |
| 1777 | 1862 | 'include_birthdays' => true, |
@@ -1782,13 +1867,15 @@ discard block |
||
| 1782 | 1867 | // The ssi_todaysCalendar variants all use the same hook and just pass on $eventOptions so the hooked code can distinguish different cases if necessary |
| 1783 | 1868 | call_integration_hook('integrate_ssi_calendar', array(&$return, $eventOptions)); |
| 1784 | 1869 | |
| 1785 | - if ($output_method != 'echo') |
|
| 1786 | - return $return['calendar_birthdays']; |
|
| 1870 | + if ($output_method != 'echo') { |
|
| 1871 | + return $return['calendar_birthdays']; |
|
| 1872 | + } |
|
| 1787 | 1873 | |
| 1788 | - foreach ($return['calendar_birthdays'] as $member) |
|
| 1789 | - echo ' |
|
| 1874 | + foreach ($return['calendar_birthdays'] as $member) { |
|
| 1875 | + echo ' |
|
| 1790 | 1876 | <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'] ? ', ' : ''); |
| 1791 | -} |
|
| 1877 | + } |
|
| 1878 | + } |
|
| 1792 | 1879 | |
| 1793 | 1880 | /** |
| 1794 | 1881 | * Shows today's holidays. |
@@ -1799,8 +1886,9 @@ discard block |
||
| 1799 | 1886 | { |
| 1800 | 1887 | global $modSettings, $user_info; |
| 1801 | 1888 | |
| 1802 | - if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view')) |
|
| 1803 | - return; |
|
| 1889 | + if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view')) { |
|
| 1890 | + return; |
|
| 1891 | + } |
|
| 1804 | 1892 | |
| 1805 | 1893 | $eventOptions = array( |
| 1806 | 1894 | 'include_holidays' => true, |
@@ -1811,8 +1899,9 @@ discard block |
||
| 1811 | 1899 | // The ssi_todaysCalendar variants all use the same hook and just pass on $eventOptions so the hooked code can distinguish different cases if necessary |
| 1812 | 1900 | call_integration_hook('integrate_ssi_calendar', array(&$return, $eventOptions)); |
| 1813 | 1901 | |
| 1814 | - if ($output_method != 'echo') |
|
| 1815 | - return $return['calendar_holidays']; |
|
| 1902 | + if ($output_method != 'echo') { |
|
| 1903 | + return $return['calendar_holidays']; |
|
| 1904 | + } |
|
| 1816 | 1905 | |
| 1817 | 1906 | echo ' |
| 1818 | 1907 | ', implode(', ', $return['calendar_holidays']); |
@@ -1826,8 +1915,9 @@ discard block |
||
| 1826 | 1915 | { |
| 1827 | 1916 | global $modSettings, $user_info; |
| 1828 | 1917 | |
| 1829 | - if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view')) |
|
| 1830 | - return; |
|
| 1918 | + if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view')) { |
|
| 1919 | + return; |
|
| 1920 | + } |
|
| 1831 | 1921 | |
| 1832 | 1922 | $eventOptions = array( |
| 1833 | 1923 | 'include_events' => true, |
@@ -1838,14 +1928,16 @@ discard block |
||
| 1838 | 1928 | // The ssi_todaysCalendar variants all use the same hook and just pass on $eventOptions so the hooked code can distinguish different cases if necessary |
| 1839 | 1929 | call_integration_hook('integrate_ssi_calendar', array(&$return, $eventOptions)); |
| 1840 | 1930 | |
| 1841 | - if ($output_method != 'echo') |
|
| 1842 | - return $return['calendar_events']; |
|
| 1931 | + if ($output_method != 'echo') { |
|
| 1932 | + return $return['calendar_events']; |
|
| 1933 | + } |
|
| 1843 | 1934 | |
| 1844 | 1935 | foreach ($return['calendar_events'] as $event) |
| 1845 | 1936 | { |
| 1846 | - if ($event['can_edit']) |
|
| 1847 | - echo ' |
|
| 1937 | + if ($event['can_edit']) { |
|
| 1938 | + echo ' |
|
| 1848 | 1939 | <a href="' . $event['modify_href'] . '" style="color: #ff0000;">*</a> '; |
| 1940 | + } |
|
| 1849 | 1941 | echo ' |
| 1850 | 1942 | ' . $event['link'] . (!$event['is_last'] ? ', ' : ''); |
| 1851 | 1943 | } |
@@ -1860,8 +1952,9 @@ discard block |
||
| 1860 | 1952 | { |
| 1861 | 1953 | global $modSettings, $txt, $scripturl, $user_info; |
| 1862 | 1954 | |
| 1863 | - if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view')) |
|
| 1864 | - return; |
|
| 1955 | + if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view')) { |
|
| 1956 | + return; |
|
| 1957 | + } |
|
| 1865 | 1958 | |
| 1866 | 1959 | $eventOptions = array( |
| 1867 | 1960 | 'include_birthdays' => allowedTo('profile_view'), |
@@ -1874,19 +1967,22 @@ discard block |
||
| 1874 | 1967 | // The ssi_todaysCalendar variants all use the same hook and just pass on $eventOptions so the hooked code can distinguish different cases if necessary |
| 1875 | 1968 | call_integration_hook('integrate_ssi_calendar', array(&$return, $eventOptions)); |
| 1876 | 1969 | |
| 1877 | - if ($output_method != 'echo') |
|
| 1878 | - return $return; |
|
| 1970 | + if ($output_method != 'echo') { |
|
| 1971 | + return $return; |
|
| 1972 | + } |
|
| 1879 | 1973 | |
| 1880 | - if (!empty($return['calendar_holidays'])) |
|
| 1881 | - echo ' |
|
| 1974 | + if (!empty($return['calendar_holidays'])) { |
|
| 1975 | + echo ' |
|
| 1882 | 1976 | <span class="holiday">' . $txt['calendar_prompt'] . ' ' . implode(', ', $return['calendar_holidays']) . '<br></span>'; |
| 1977 | + } |
|
| 1883 | 1978 | if (!empty($return['calendar_birthdays'])) |
| 1884 | 1979 | { |
| 1885 | 1980 | echo ' |
| 1886 | 1981 | <span class="birthday">' . $txt['birthdays_upcoming'] . '</span> '; |
| 1887 | - foreach ($return['calendar_birthdays'] as $member) |
|
| 1888 | - echo ' |
|
| 1982 | + foreach ($return['calendar_birthdays'] as $member) { |
|
| 1983 | + echo ' |
|
| 1889 | 1984 | <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'] ? ', ' : ''; |
| 1985 | + } |
|
| 1890 | 1986 | echo ' |
| 1891 | 1987 | <br>'; |
| 1892 | 1988 | } |
@@ -1896,9 +1992,10 @@ discard block |
||
| 1896 | 1992 | <span class="event">' . $txt['events_upcoming'] . '</span> '; |
| 1897 | 1993 | foreach ($return['calendar_events'] as $event) |
| 1898 | 1994 | { |
| 1899 | - if ($event['can_edit']) |
|
| 1900 | - echo ' |
|
| 1995 | + if ($event['can_edit']) { |
|
| 1996 | + echo ' |
|
| 1901 | 1997 | <a href="' . $event['modify_href'] . '" style="color: #ff0000;">*</a> '; |
| 1998 | + } |
|
| 1902 | 1999 | echo ' |
| 1903 | 2000 | ' . $event['link'] . (!$event['is_last'] ? ', ' : ''); |
| 1904 | 2001 | } |
@@ -1922,25 +2019,29 @@ discard block |
||
| 1922 | 2019 | loadLanguage('Stats'); |
| 1923 | 2020 | |
| 1924 | 2021 | // Must be integers.... |
| 1925 | - if ($limit === null) |
|
| 1926 | - $limit = isset($_GET['limit']) ? (int) $_GET['limit'] : 5; |
|
| 1927 | - else |
|
| 1928 | - $limit = (int) $limit; |
|
| 1929 | - |
|
| 1930 | - if ($start === null) |
|
| 1931 | - $start = isset($_GET['start']) ? (int) $_GET['start'] : 0; |
|
| 1932 | - else |
|
| 1933 | - $start = (int) $start; |
|
| 1934 | - |
|
| 1935 | - if ($board !== null) |
|
| 1936 | - $board = (int) $board; |
|
| 1937 | - elseif (isset($_GET['board'])) |
|
| 1938 | - $board = (int) $_GET['board']; |
|
| 1939 | - |
|
| 1940 | - if ($length === null) |
|
| 1941 | - $length = isset($_GET['length']) ? (int) $_GET['length'] : 0; |
|
| 1942 | - else |
|
| 1943 | - $length = (int) $length; |
|
| 2022 | + if ($limit === null) { |
|
| 2023 | + $limit = isset($_GET['limit']) ? (int) $_GET['limit'] : 5; |
|
| 2024 | + } else { |
|
| 2025 | + $limit = (int) $limit; |
|
| 2026 | + } |
|
| 2027 | + |
|
| 2028 | + if ($start === null) { |
|
| 2029 | + $start = isset($_GET['start']) ? (int) $_GET['start'] : 0; |
|
| 2030 | + } else { |
|
| 2031 | + $start = (int) $start; |
|
| 2032 | + } |
|
| 2033 | + |
|
| 2034 | + if ($board !== null) { |
|
| 2035 | + $board = (int) $board; |
|
| 2036 | + } elseif (isset($_GET['board'])) { |
|
| 2037 | + $board = (int) $_GET['board']; |
|
| 2038 | + } |
|
| 2039 | + |
|
| 2040 | + if ($length === null) { |
|
| 2041 | + $length = isset($_GET['length']) ? (int) $_GET['length'] : 0; |
|
| 2042 | + } else { |
|
| 2043 | + $length = (int) $length; |
|
| 2044 | + } |
|
| 1944 | 2045 | |
| 1945 | 2046 | $limit = max(0, $limit); |
| 1946 | 2047 | $start = max(0, $start); |
@@ -1958,17 +2059,19 @@ discard block |
||
| 1958 | 2059 | ); |
| 1959 | 2060 | if ($smcFunc['db_num_rows']($request) == 0) |
| 1960 | 2061 | { |
| 1961 | - if ($output_method == 'echo') |
|
| 1962 | - die($txt['ssi_no_guests']); |
|
| 1963 | - else |
|
| 1964 | - return array(); |
|
| 2062 | + if ($output_method == 'echo') { |
|
| 2063 | + die($txt['ssi_no_guests']); |
|
| 2064 | + } else { |
|
| 2065 | + return array(); |
|
| 2066 | + } |
|
| 1965 | 2067 | } |
| 1966 | 2068 | list ($board) = $smcFunc['db_fetch_row']($request); |
| 1967 | 2069 | $smcFunc['db_free_result']($request); |
| 1968 | 2070 | |
| 1969 | 2071 | $icon_sources = array(); |
| 1970 | - foreach ($context['stable_icons'] as $icon) |
|
| 1971 | - $icon_sources[$icon] = 'images_url'; |
|
| 2072 | + foreach ($context['stable_icons'] as $icon) { |
|
| 2073 | + $icon_sources[$icon] = 'images_url'; |
|
| 2074 | + } |
|
| 1972 | 2075 | |
| 1973 | 2076 | if (!empty($modSettings['enable_likes'])) |
| 1974 | 2077 | { |
@@ -1991,12 +2094,14 @@ discard block |
||
| 1991 | 2094 | ) |
| 1992 | 2095 | ); |
| 1993 | 2096 | $posts = array(); |
| 1994 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1995 | - $posts[] = $row['id_first_msg']; |
|
| 2097 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 2098 | + $posts[] = $row['id_first_msg']; |
|
| 2099 | + } |
|
| 1996 | 2100 | $smcFunc['db_free_result']($request); |
| 1997 | 2101 | |
| 1998 | - if (empty($posts)) |
|
| 1999 | - return array(); |
|
| 2102 | + if (empty($posts)) { |
|
| 2103 | + return array(); |
|
| 2104 | + } |
|
| 2000 | 2105 | |
| 2001 | 2106 | // Find the posts. |
| 2002 | 2107 | $request = $smcFunc['db_query']('', ' |
@@ -2026,26 +2131,30 @@ discard block |
||
| 2026 | 2131 | $last_space = strrpos($row['body'], ' '); |
| 2027 | 2132 | $last_open = strrpos($row['body'], '<'); |
| 2028 | 2133 | $last_close = strrpos($row['body'], '>'); |
| 2029 | - 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) |
|
| 2030 | - $cutoff = $last_open; |
|
| 2031 | - elseif (empty($last_close) || $last_close < $last_open) |
|
| 2032 | - $cutoff = $last_space; |
|
| 2134 | + 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) { |
|
| 2135 | + $cutoff = $last_open; |
|
| 2136 | + } elseif (empty($last_close) || $last_close < $last_open) { |
|
| 2137 | + $cutoff = $last_space; |
|
| 2138 | + } |
|
| 2033 | 2139 | |
| 2034 | - if ($cutoff !== false) |
|
| 2035 | - $row['body'] = $smcFunc['substr']($row['body'], 0, $cutoff); |
|
| 2140 | + if ($cutoff !== false) { |
|
| 2141 | + $row['body'] = $smcFunc['substr']($row['body'], 0, $cutoff); |
|
| 2142 | + } |
|
| 2036 | 2143 | $row['body'] .= '...'; |
| 2037 | 2144 | } |
| 2038 | 2145 | |
| 2039 | 2146 | $row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']); |
| 2040 | 2147 | |
| 2041 | - if (!empty($recycle_board) && $row['id_board'] == $recycle_board) |
|
| 2042 | - $row['icon'] = 'recycled'; |
|
| 2148 | + if (!empty($recycle_board) && $row['id_board'] == $recycle_board) { |
|
| 2149 | + $row['icon'] = 'recycled'; |
|
| 2150 | + } |
|
| 2043 | 2151 | |
| 2044 | 2152 | // Check that this message icon is there... |
| 2045 | - if (!empty($modSettings['messageIconChecks_enable']) && !isset($icon_sources[$row['icon']])) |
|
| 2046 | - $icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
| 2047 | - elseif (!isset($icon_sources[$row['icon']])) |
|
| 2048 | - $icon_sources[$row['icon']] = 'images_url'; |
|
| 2153 | + if (!empty($modSettings['messageIconChecks_enable']) && !isset($icon_sources[$row['icon']])) { |
|
| 2154 | + $icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
| 2155 | + } elseif (!isset($icon_sources[$row['icon']])) { |
|
| 2156 | + $icon_sources[$row['icon']] = 'images_url'; |
|
| 2157 | + } |
|
| 2049 | 2158 | |
| 2050 | 2159 | censorText($row['subject']); |
| 2051 | 2160 | censorText($row['body']); |
@@ -2082,16 +2191,18 @@ discard block |
||
| 2082 | 2191 | } |
| 2083 | 2192 | $smcFunc['db_free_result']($request); |
| 2084 | 2193 | |
| 2085 | - if (empty($return)) |
|
| 2086 | - return $return; |
|
| 2194 | + if (empty($return)) { |
|
| 2195 | + return $return; |
|
| 2196 | + } |
|
| 2087 | 2197 | |
| 2088 | 2198 | $return[count($return) - 1]['is_last'] = true; |
| 2089 | 2199 | |
| 2090 | 2200 | // If mods want to do somthing with this list of posts, let them do that now. |
| 2091 | 2201 | call_integration_hook('integrate_ssi_boardNews', array(&$return)); |
| 2092 | 2202 | |
| 2093 | - if ($output_method != 'echo') |
|
| 2094 | - return $return; |
|
| 2203 | + if ($output_method != 'echo') { |
|
| 2204 | + return $return; |
|
| 2205 | + } |
|
| 2095 | 2206 | |
| 2096 | 2207 | foreach ($return as $news) |
| 2097 | 2208 | { |
@@ -2143,9 +2254,10 @@ discard block |
||
| 2143 | 2254 | echo ' |
| 2144 | 2255 | </div>'; |
| 2145 | 2256 | |
| 2146 | - if (!$news['is_last']) |
|
| 2147 | - echo ' |
|
| 2257 | + if (!$news['is_last']) { |
|
| 2258 | + echo ' |
|
| 2148 | 2259 | <hr>'; |
| 2260 | + } |
|
| 2149 | 2261 | } |
| 2150 | 2262 | } |
| 2151 | 2263 | |
@@ -2159,8 +2271,9 @@ discard block |
||
| 2159 | 2271 | { |
| 2160 | 2272 | global $user_info, $scripturl, $modSettings, $txt, $context, $smcFunc; |
| 2161 | 2273 | |
| 2162 | - if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view')) |
|
| 2163 | - return; |
|
| 2274 | + if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view')) { |
|
| 2275 | + return; |
|
| 2276 | + } |
|
| 2164 | 2277 | |
| 2165 | 2278 | // Find all events which are happening in the near future that the member can see. |
| 2166 | 2279 | $request = $smcFunc['db_query']('', ' |
@@ -2186,20 +2299,23 @@ discard block |
||
| 2186 | 2299 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 2187 | 2300 | { |
| 2188 | 2301 | // 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. |
| 2189 | - if (!empty($duplicates[$row['title'] . $row['id_topic']])) |
|
| 2190 | - continue; |
|
| 2302 | + if (!empty($duplicates[$row['title'] . $row['id_topic']])) { |
|
| 2303 | + continue; |
|
| 2304 | + } |
|
| 2191 | 2305 | |
| 2192 | 2306 | // Censor the title. |
| 2193 | 2307 | censorText($row['title']); |
| 2194 | 2308 | |
| 2195 | - if ($row['start_date'] < strftime('%Y-%m-%d', forum_time(false))) |
|
| 2196 | - $date = strftime('%Y-%m-%d', forum_time(false)); |
|
| 2197 | - else |
|
| 2198 | - $date = $row['start_date']; |
|
| 2309 | + if ($row['start_date'] < strftime('%Y-%m-%d', forum_time(false))) { |
|
| 2310 | + $date = strftime('%Y-%m-%d', forum_time(false)); |
|
| 2311 | + } else { |
|
| 2312 | + $date = $row['start_date']; |
|
| 2313 | + } |
|
| 2199 | 2314 | |
| 2200 | 2315 | // If the topic it is attached to is not approved then don't link it. |
| 2201 | - if (!empty($row['id_first_msg']) && !$row['approved']) |
|
| 2202 | - $row['id_board'] = $row['id_topic'] = $row['id_first_msg'] = 0; |
|
| 2316 | + if (!empty($row['id_first_msg']) && !$row['approved']) { |
|
| 2317 | + $row['id_board'] = $row['id_topic'] = $row['id_first_msg'] = 0; |
|
| 2318 | + } |
|
| 2203 | 2319 | |
| 2204 | 2320 | $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; |
| 2205 | 2321 | |
@@ -2225,24 +2341,27 @@ discard block |
||
| 2225 | 2341 | } |
| 2226 | 2342 | $smcFunc['db_free_result']($request); |
| 2227 | 2343 | |
| 2228 | - foreach ($return as $mday => $array) |
|
| 2229 | - $return[$mday][count($array) - 1]['is_last'] = true; |
|
| 2344 | + foreach ($return as $mday => $array) { |
|
| 2345 | + $return[$mday][count($array) - 1]['is_last'] = true; |
|
| 2346 | + } |
|
| 2230 | 2347 | |
| 2231 | 2348 | // If mods want to do somthing with this list of events, let them do that now. |
| 2232 | 2349 | call_integration_hook('integrate_ssi_recentEvents', array(&$return)); |
| 2233 | 2350 | |
| 2234 | - if ($output_method != 'echo' || empty($return)) |
|
| 2235 | - return $return; |
|
| 2351 | + if ($output_method != 'echo' || empty($return)) { |
|
| 2352 | + return $return; |
|
| 2353 | + } |
|
| 2236 | 2354 | |
| 2237 | 2355 | // Well the output method is echo. |
| 2238 | 2356 | echo ' |
| 2239 | 2357 | <span class="event">' . $txt['events'] . '</span> '; |
| 2240 | - foreach ($return as $mday => $array) |
|
| 2241 | - foreach ($array as $event) |
|
| 2358 | + foreach ($return as $mday => $array) { |
|
| 2359 | + foreach ($array as $event) |
|
| 2242 | 2360 | { |
| 2243 | 2361 | if ($event['can_edit']) |
| 2244 | 2362 | echo ' |
| 2245 | 2363 | <a href="' . $event['modify_href'] . '" style="color: #ff0000;">*</a> '; |
| 2364 | + } |
|
| 2246 | 2365 | |
| 2247 | 2366 | echo ' |
| 2248 | 2367 | ' . $event['link'] . (!$event['is_last'] ? ', ' : ''); |
@@ -2261,8 +2380,9 @@ discard block |
||
| 2261 | 2380 | global $smcFunc; |
| 2262 | 2381 | |
| 2263 | 2382 | // If $id is null, this was most likely called from a query string and should do nothing. |
| 2264 | - if ($id === null) |
|
| 2265 | - return; |
|
| 2383 | + if ($id === null) { |
|
| 2384 | + return; |
|
| 2385 | + } |
|
| 2266 | 2386 | |
| 2267 | 2387 | $request = $smcFunc['db_query']('', ' |
| 2268 | 2388 | SELECT passwd, member_name, is_activated |
@@ -2294,8 +2414,9 @@ discard block |
||
| 2294 | 2414 | $attachments_boards = boardsAllowedTo('view_attachments'); |
| 2295 | 2415 | |
| 2296 | 2416 | // No boards? Adios amigo. |
| 2297 | - if (empty($attachments_boards)) |
|
| 2298 | - return array(); |
|
| 2417 | + if (empty($attachments_boards)) { |
|
| 2418 | + return array(); |
|
| 2419 | + } |
|
| 2299 | 2420 | |
| 2300 | 2421 | // Is it an array? |
| 2301 | 2422 | $attachment_ext = (array) $attachment_ext; |
@@ -2379,8 +2500,9 @@ discard block |
||
| 2379 | 2500 | call_integration_hook('integrate_ssi_recentAttachments', array(&$attachments)); |
| 2380 | 2501 | |
| 2381 | 2502 | // So you just want an array? Here you can have it. |
| 2382 | - if ($output_method == 'array' || empty($attachments)) |
|
| 2383 | - return $attachments; |
|
| 2503 | + if ($output_method == 'array' || empty($attachments)) { |
|
| 2504 | + return $attachments; |
|
| 2505 | + } |
|
| 2384 | 2506 | |
| 2385 | 2507 | // Give them the default. |
| 2386 | 2508 | echo ' |
@@ -2391,14 +2513,15 @@ discard block |
||
| 2391 | 2513 | <th style="text-align: left; padding: 2">', $txt['downloads'], '</th> |
| 2392 | 2514 | <th style="text-align: left; padding: 2">', $txt['filesize'], '</th> |
| 2393 | 2515 | </tr>'; |
| 2394 | - foreach ($attachments as $attach) |
|
| 2395 | - echo ' |
|
| 2516 | + foreach ($attachments as $attach) { |
|
| 2517 | + echo ' |
|
| 2396 | 2518 | <tr> |
| 2397 | 2519 | <td>', $attach['file']['link'], '</td> |
| 2398 | 2520 | <td>', $attach['member']['link'], '</td> |
| 2399 | 2521 | <td style="text-align: center">', $attach['file']['downloads'], '</td> |
| 2400 | 2522 | <td>', $attach['file']['filesize'], '</td> |
| 2401 | 2523 | </tr>'; |
| 2524 | + } |
|
| 2402 | 2525 | echo ' |
| 2403 | 2526 | </table>'; |
| 2404 | 2527 | } |
@@ -32,20 +32,23 @@ discard block |
||
| 32 | 32 | ob_start(); |
| 33 | 33 | |
| 34 | 34 | // Do some cleaning, just in case. |
| 35 | -foreach (array('db_character_set', 'cachedir') as $variable) |
|
| 35 | +foreach (array('db_character_set', 'cachedir') as $variable) { |
|
| 36 | 36 | if (isset($GLOBALS[$variable])) |
| 37 | 37 | unset($GLOBALS[$variable], $GLOBALS[$variable]); |
| 38 | +} |
|
| 38 | 39 | |
| 39 | 40 | // Load the settings... |
| 40 | 41 | require_once(dirname(__FILE__) . '/Settings.php'); |
| 41 | 42 | |
| 42 | 43 | // Make absolutely sure the cache directory is defined. |
| 43 | -if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) |
|
| 44 | +if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) { |
|
| 44 | 45 | $cachedir = $boarddir . '/cache'; |
| 46 | +} |
|
| 45 | 47 | |
| 46 | 48 | // For php below 7 |
| 47 | -if (!function_exists('random_int')) |
|
| 49 | +if (!function_exists('random_int')) { |
|
| 48 | 50 | require_once ($sourcedir . '/random_compat/random_int.php'); |
| 51 | +} |
|
| 49 | 52 | |
| 50 | 53 | // Without those we can't go anywhere |
| 51 | 54 | require_once($sourcedir . '/QueryString.php'); |
@@ -55,8 +58,9 @@ discard block |
||
| 55 | 58 | require_once($sourcedir . '/Load.php'); |
| 56 | 59 | |
| 57 | 60 | // If $maintenance is set specifically to 2, then we're upgrading or something. |
| 58 | -if (!empty($maintenance) && $maintenance == 2) |
|
| 61 | +if (!empty($maintenance) && $maintenance == 2) { |
|
| 59 | 62 | display_maintenance_message(); |
| 63 | +} |
|
| 60 | 64 | |
| 61 | 65 | // Create a variable to store some SMF specific functions in. |
| 62 | 66 | $smcFunc = array(); |
@@ -71,8 +75,9 @@ discard block |
||
| 71 | 75 | cleanRequest(); |
| 72 | 76 | |
| 73 | 77 | // Seed the random generator. |
| 74 | -if (empty($modSettings['rand_seed']) || random_int(1, 250) == 69) |
|
| 78 | +if (empty($modSettings['rand_seed']) || random_int(1, 250) == 69) { |
|
| 75 | 79 | smf_seed_generator(); |
| 80 | +} |
|
| 76 | 81 | |
| 77 | 82 | // Before we get carried away, are we doing a scheduled task? If so save CPU cycles by jumping out! |
| 78 | 83 | if (isset($_GET['scheduled'])) |
@@ -92,9 +97,9 @@ discard block |
||
| 92 | 97 | if (!empty($modSettings['enableCompressedOutput']) && !headers_sent()) |
| 93 | 98 | { |
| 94 | 99 | // If zlib is being used, turn off output compression. |
| 95 | - if (ini_get('zlib.output_compression') >= 1 || ini_get('output_handler') == 'ob_gzhandler') |
|
| 96 | - $modSettings['enableCompressedOutput'] = '0'; |
|
| 97 | - else |
|
| 100 | + if (ini_get('zlib.output_compression') >= 1 || ini_get('output_handler') == 'ob_gzhandler') { |
|
| 101 | + $modSettings['enableCompressedOutput'] = '0'; |
|
| 102 | + } else |
|
| 98 | 103 | { |
| 99 | 104 | ob_end_clean(); |
| 100 | 105 | ob_start('ob_gzhandler'); |
@@ -186,18 +191,21 @@ discard block |
||
| 186 | 191 | loadPermissions(); |
| 187 | 192 | |
| 188 | 193 | // Attachments don't require the entire theme to be loaded. |
| 189 | - if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'dlattach') |
|
| 190 | - detectBrowser(); |
|
| 194 | + if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'dlattach') { |
|
| 195 | + detectBrowser(); |
|
| 196 | + } |
|
| 191 | 197 | // Load the current theme. (note that ?theme=1 will also work, may be used for guest theming.) |
| 192 | - else |
|
| 193 | - loadTheme(); |
|
| 198 | + else { |
|
| 199 | + loadTheme(); |
|
| 200 | + } |
|
| 194 | 201 | |
| 195 | 202 | // Check if the user should be disallowed access. |
| 196 | 203 | is_not_banned(); |
| 197 | 204 | |
| 198 | 205 | // If we are in a topic and don't have permission to approve it then duck out now. |
| 199 | - if (!empty($topic) && empty($board_info['cur_topic_approved']) && !allowedTo('approve_posts') && ($user_info['id'] != $board_info['cur_topic_starter'] || $user_info['is_guest'])) |
|
| 200 | - fatal_lang_error('not_a_topic', false); |
|
| 206 | + if (!empty($topic) && empty($board_info['cur_topic_approved']) && !allowedTo('approve_posts') && ($user_info['id'] != $board_info['cur_topic_starter'] || $user_info['is_guest'])) { |
|
| 207 | + fatal_lang_error('not_a_topic', false); |
|
| 208 | + } |
|
| 201 | 209 | |
| 202 | 210 | $no_stat_actions = array('clock', 'dlattach', 'findmember', 'jsoption', 'likes', 'loadeditorlocale', 'modifycat', 'requestmembers', 'smstats', 'suggest', 'about:unknown', '.xml', 'xmlhttp', 'verificationcode', 'viewquery', 'viewsmfile'); |
| 203 | 211 | call_integration_hook('integrate_pre_log_stats', array(&$no_stat_actions)); |
@@ -208,8 +216,9 @@ discard block |
||
| 208 | 216 | writeLog(); |
| 209 | 217 | |
| 210 | 218 | // Track forum statistics and hits...? |
| 211 | - if (!empty($modSettings['hitStats'])) |
|
| 212 | - trackStats(array('hits' => '+')); |
|
| 219 | + if (!empty($modSettings['hitStats'])) { |
|
| 220 | + trackStats(array('hits' => '+')); |
|
| 221 | + } |
|
| 213 | 222 | } |
| 214 | 223 | unset($no_stat_actions); |
| 215 | 224 | |
@@ -226,13 +235,14 @@ discard block |
||
| 226 | 235 | return ($_REQUEST['action'] == 'login2' ? 'Login2' : ($_REQUEST['action'] == 'logintfa' ? 'LoginTFA' : 'Logout')); |
| 227 | 236 | } |
| 228 | 237 | // Don't even try it, sonny. |
| 229 | - else |
|
| 230 | - return 'InMaintenance'; |
|
| 238 | + else { |
|
| 239 | + return 'InMaintenance'; |
|
| 240 | + } |
|
| 231 | 241 | } |
| 232 | 242 | // If guest access is off, a guest can only do one of the very few following actions. |
| 233 | - elseif (empty($modSettings['allow_guestAccess']) && $user_info['is_guest'] && (!isset($_REQUEST['action']) || !in_array($_REQUEST['action'], array('coppa', 'login', 'login2', 'logintfa', 'reminder', 'activate', 'help', 'helpadmin', 'smstats', 'verificationcode', 'signup', 'signup2')))) |
|
| 234 | - return 'KickGuest'; |
|
| 235 | - elseif (empty($_REQUEST['action'])) |
|
| 243 | + elseif (empty($modSettings['allow_guestAccess']) && $user_info['is_guest'] && (!isset($_REQUEST['action']) || !in_array($_REQUEST['action'], array('coppa', 'login', 'login2', 'logintfa', 'reminder', 'activate', 'help', 'helpadmin', 'smstats', 'verificationcode', 'signup', 'signup2')))) { |
|
| 244 | + return 'KickGuest'; |
|
| 245 | + } elseif (empty($_REQUEST['action'])) |
|
| 236 | 246 | { |
| 237 | 247 | // Action and board are both empty... BoardIndex! Unless someone else wants to do something different. |
| 238 | 248 | if (empty($board) && empty($topic)) |
@@ -246,8 +256,9 @@ discard block |
||
| 246 | 256 | |
| 247 | 257 | $call = call_helper($defaultAction, true); |
| 248 | 258 | |
| 249 | - if (!empty($call)) |
|
| 250 | - return $call; |
|
| 259 | + if (!empty($call)) { |
|
| 260 | + return $call; |
|
| 261 | + } |
|
| 251 | 262 | } |
| 252 | 263 | |
| 253 | 264 | // No default action huh? then go to our good old BoardIndex. |
@@ -377,8 +388,9 @@ discard block |
||
| 377 | 388 | |
| 378 | 389 | $call = call_helper($fallbackAction, true); |
| 379 | 390 | |
| 380 | - if (!empty($call)) |
|
| 381 | - return $call; |
|
| 391 | + if (!empty($call)) { |
|
| 392 | + return $call; |
|
| 393 | + } |
|
| 382 | 394 | } |
| 383 | 395 | |
| 384 | 396 | // No fallback action, huh? |
@@ -389,8 +401,9 @@ discard block |
||
| 389 | 401 | } |
| 390 | 402 | |
| 391 | 403 | // Otherwise, it was set - so let's go to that action. |
| 392 | - if (!empty($actionArray[$_REQUEST['action']][0])) |
|
| 393 | - require_once($sourcedir . '/' . $actionArray[$_REQUEST['action']][0]); |
|
| 404 | + if (!empty($actionArray[$_REQUEST['action']][0])) { |
|
| 405 | + require_once($sourcedir . '/' . $actionArray[$_REQUEST['action']][0]); |
|
| 406 | + } |
|
| 394 | 407 | |
| 395 | 408 | // Do the right thing. |
| 396 | 409 | return call_helper($actionArray[$_REQUEST['action']][1], true); |
@@ -20,12 +20,14 @@ 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 | // For php below 7 |
| 23 | -if (!function_exists('random_int')) |
|
| 23 | +if (!function_exists('random_int')) { |
|
| 24 | 24 | require_once ('Sources/random_compat/random_int.php'); |
| 25 | +} |
|
| 25 | 26 | |
| 26 | 27 | // Let's pull in useful classes |
| 27 | -if (!defined('SMF')) |
|
| 28 | +if (!defined('SMF')) { |
|
| 28 | 29 | define('SMF', 1); |
| 30 | +} |
|
| 29 | 31 | |
| 30 | 32 | require_once('Sources/Class-Package.php'); |
| 31 | 33 | |
@@ -67,10 +69,11 @@ discard block |
||
| 67 | 69 | |
| 68 | 70 | list ($charcode) = pg_fetch_row($request); |
| 69 | 71 | |
| 70 | - if ($charcode == 'UTF8') |
|
| 71 | - return true; |
|
| 72 | - else |
|
| 73 | - return false; |
|
| 72 | + if ($charcode == 'UTF8') { |
|
| 73 | + return true; |
|
| 74 | + } else { |
|
| 75 | + return false; |
|
| 76 | + } |
|
| 74 | 77 | }, |
| 75 | 78 | 'utf8_version' => '8.0', |
| 76 | 79 | 'utf8_version_check' => '$request = pg_query(\'SELECT version()\'); list ($version) = pg_fetch_row($request); list($pgl, $version) = explode(" ", $version); return $version;', |
@@ -80,12 +83,14 @@ discard block |
||
| 80 | 83 | $value = preg_replace('~[^A-Za-z0-9_\$]~', '', $value); |
| 81 | 84 | |
| 82 | 85 | // Is it reserved? |
| 83 | - if ($value == 'pg_') |
|
| 84 | - return $txt['error_db_prefix_reserved']; |
|
| 86 | + if ($value == 'pg_') { |
|
| 87 | + return $txt['error_db_prefix_reserved']; |
|
| 88 | + } |
|
| 85 | 89 | |
| 86 | 90 | // Is the prefix numeric? |
| 87 | - if (preg_match('~^\d~', $value)) |
|
| 88 | - return $txt['error_db_prefix_numeric']; |
|
| 91 | + if (preg_match('~^\d~', $value)) { |
|
| 92 | + return $txt['error_db_prefix_numeric']; |
|
| 93 | + } |
|
| 89 | 94 | |
| 90 | 95 | return true; |
| 91 | 96 | }, |
@@ -132,10 +137,11 @@ discard block |
||
| 132 | 137 | $incontext['skip'] = false; |
| 133 | 138 | |
| 134 | 139 | // Call the step and if it returns false that means pause! |
| 135 | - if (function_exists($step[2]) && $step[2]() === false) |
|
| 136 | - break; |
|
| 137 | - elseif (function_exists($step[2])) |
|
| 138 | - $incontext['current_step']++; |
|
| 140 | + if (function_exists($step[2]) && $step[2]() === false) { |
|
| 141 | + break; |
|
| 142 | + } elseif (function_exists($step[2])) { |
|
| 143 | + $incontext['current_step']++; |
|
| 144 | + } |
|
| 139 | 145 | |
| 140 | 146 | // No warnings pass on. |
| 141 | 147 | $incontext['warning'] = ''; |
@@ -151,8 +157,9 @@ discard block |
||
| 151 | 157 | global $databases; |
| 152 | 158 | |
| 153 | 159 | // Just so people using older versions of PHP aren't left in the cold. |
| 154 | - if (!isset($_SERVER['PHP_SELF'])) |
|
| 155 | - $_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php'; |
|
| 160 | + if (!isset($_SERVER['PHP_SELF'])) { |
|
| 161 | + $_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php'; |
|
| 162 | + } |
|
| 156 | 163 | |
| 157 | 164 | // Enable error reporting for fatal errors. |
| 158 | 165 | error_reporting(E_ERROR | E_PARSE); |
@@ -168,21 +175,23 @@ discard block |
||
| 168 | 175 | { |
| 169 | 176 | ob_start(); |
| 170 | 177 | |
| 171 | - if (ini_get('session.save_handler') == 'user') |
|
| 172 | - @ini_set('session.save_handler', 'files'); |
|
| 173 | - if (function_exists('session_start')) |
|
| 174 | - @session_start(); |
|
| 175 | - } |
|
| 176 | - else |
|
| 178 | + if (ini_get('session.save_handler') == 'user') { |
|
| 179 | + @ini_set('session.save_handler', 'files'); |
|
| 180 | + } |
|
| 181 | + if (function_exists('session_start')) { |
|
| 182 | + @session_start(); |
|
| 183 | + } |
|
| 184 | + } else |
|
| 177 | 185 | { |
| 178 | 186 | ob_start('ob_gzhandler'); |
| 179 | 187 | |
| 180 | - if (ini_get('session.save_handler') == 'user') |
|
| 181 | - @ini_set('session.save_handler', 'files'); |
|
| 188 | + if (ini_get('session.save_handler') == 'user') { |
|
| 189 | + @ini_set('session.save_handler', 'files'); |
|
| 190 | + } |
|
| 182 | 191 | session_start(); |
| 183 | 192 | |
| 184 | - if (!headers_sent()) |
|
| 185 | - echo '<!DOCTYPE html> |
|
| 193 | + if (!headers_sent()) { |
|
| 194 | + echo '<!DOCTYPE html> |
|
| 186 | 195 | <html> |
| 187 | 196 | <head> |
| 188 | 197 | <title>', htmlspecialchars($_GET['pass_string']), '</title> |
@@ -191,14 +200,16 @@ discard block |
||
| 191 | 200 | <strong>', htmlspecialchars($_GET['pass_string']), '</strong> |
| 192 | 201 | </body> |
| 193 | 202 | </html>'; |
| 203 | + } |
|
| 194 | 204 | exit; |
| 195 | 205 | } |
| 196 | 206 | |
| 197 | 207 | // Add slashes, as long as they aren't already being added. |
| 198 | - if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0) |
|
| 199 | - foreach ($_POST as $k => $v) |
|
| 208 | + if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0) { |
|
| 209 | + foreach ($_POST as $k => $v) |
|
| 200 | 210 | if (strpos($k, 'password') === false && strpos($k, 'db_passwd') === false) |
| 201 | 211 | $_POST[$k] = addslashes($v); |
| 212 | + } |
|
| 202 | 213 | |
| 203 | 214 | // This is really quite simple; if ?delete is on the URL, delete the installer... |
| 204 | 215 | if (isset($_GET['delete'])) |
@@ -219,8 +230,7 @@ discard block |
||
| 219 | 230 | $ftp->close(); |
| 220 | 231 | |
| 221 | 232 | unset($_SESSION['installer_temp_ftp']); |
| 222 | - } |
|
| 223 | - else |
|
| 233 | + } else |
|
| 224 | 234 | { |
| 225 | 235 | @unlink(__FILE__); |
| 226 | 236 | |
@@ -234,10 +244,11 @@ discard block |
||
| 234 | 244 | // Now just redirect to a blank.png... |
| 235 | 245 | $secure = false; |
| 236 | 246 | |
| 237 | - if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') |
|
| 238 | - $secure = true; |
|
| 239 | - elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') |
|
| 240 | - $secure = true; |
|
| 247 | + if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { |
|
| 248 | + $secure = true; |
|
| 249 | + } elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') { |
|
| 250 | + $secure = true; |
|
| 251 | + } |
|
| 241 | 252 | |
| 242 | 253 | header('location: http' . ($secure ? 's' : '') . '://' . (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT']) . dirname($_SERVER['PHP_SELF']) . '/Themes/default/images/blank.png'); |
| 243 | 254 | exit; |
@@ -248,10 +259,11 @@ discard block |
||
| 248 | 259 | { |
| 249 | 260 | // Get PHP's default timezone, if set |
| 250 | 261 | $ini_tz = ini_get('date.timezone'); |
| 251 | - if (!empty($ini_tz)) |
|
| 252 | - $timezone_id = $ini_tz; |
|
| 253 | - else |
|
| 254 | - $timezone_id = ''; |
|
| 262 | + if (!empty($ini_tz)) { |
|
| 263 | + $timezone_id = $ini_tz; |
|
| 264 | + } else { |
|
| 265 | + $timezone_id = ''; |
|
| 266 | + } |
|
| 255 | 267 | |
| 256 | 268 | // If date.timezone is unset, invalid, or just plain weird, make a best guess |
| 257 | 269 | if (!in_array($timezone_id, timezone_identifiers_list())) |
@@ -281,8 +293,9 @@ discard block |
||
| 281 | 293 | $dir = dir(dirname(__FILE__) . '/Themes/default/languages'); |
| 282 | 294 | while ($entry = $dir->read()) |
| 283 | 295 | { |
| 284 | - if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') |
|
| 285 | - $incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12)); |
|
| 296 | + if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') { |
|
| 297 | + $incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12)); |
|
| 298 | + } |
|
| 286 | 299 | } |
| 287 | 300 | $dir->close(); |
| 288 | 301 | } |
@@ -329,10 +342,11 @@ discard block |
||
| 329 | 342 | } |
| 330 | 343 | |
| 331 | 344 | // Override the language file? |
| 332 | - if (isset($_GET['lang_file'])) |
|
| 333 | - $_SESSION['installer_temp_lang'] = $_GET['lang_file']; |
|
| 334 | - elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) |
|
| 335 | - $_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file']; |
|
| 345 | + if (isset($_GET['lang_file'])) { |
|
| 346 | + $_SESSION['installer_temp_lang'] = $_GET['lang_file']; |
|
| 347 | + } elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) { |
|
| 348 | + $_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file']; |
|
| 349 | + } |
|
| 336 | 350 | |
| 337 | 351 | // Make sure it exists, if it doesn't reset it. |
| 338 | 352 | 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'])) |
@@ -341,8 +355,9 @@ discard block |
||
| 341 | 355 | list ($_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']); |
| 342 | 356 | |
| 343 | 357 | // If we have english and some other language, use the other language. We Americans hate english :P. |
| 344 | - if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) |
|
| 345 | - list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']); |
|
| 358 | + if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) { |
|
| 359 | + list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']); |
|
| 360 | + } |
|
| 346 | 361 | } |
| 347 | 362 | |
| 348 | 363 | // And now include the actual language file itself. |
@@ -359,15 +374,18 @@ discard block |
||
| 359 | 374 | global $db_prefix, $db_connection, $sourcedir, $smcFunc, $modSettings, $db_port; |
| 360 | 375 | global $db_server, $db_passwd, $db_type, $db_name, $db_user, $db_persist, $db_mb4; |
| 361 | 376 | |
| 362 | - if (empty($sourcedir)) |
|
| 363 | - $sourcedir = dirname(__FILE__) . '/Sources'; |
|
| 377 | + if (empty($sourcedir)) { |
|
| 378 | + $sourcedir = dirname(__FILE__) . '/Sources'; |
|
| 379 | + } |
|
| 364 | 380 | |
| 365 | 381 | // Need this to check whether we need the database password. |
| 366 | 382 | require(dirname(__FILE__) . '/Settings.php'); |
| 367 | - if (!defined('SMF')) |
|
| 368 | - define('SMF', 1); |
|
| 369 | - if (empty($smcFunc)) |
|
| 370 | - $smcFunc = array(); |
|
| 383 | + if (!defined('SMF')) { |
|
| 384 | + define('SMF', 1); |
|
| 385 | + } |
|
| 386 | + if (empty($smcFunc)) { |
|
| 387 | + $smcFunc = array(); |
|
| 388 | + } |
|
| 371 | 389 | |
| 372 | 390 | $modSettings['disableQueryCheck'] = true; |
| 373 | 391 | |
@@ -378,14 +396,17 @@ discard block |
||
| 378 | 396 | |
| 379 | 397 | $options = array('persist' => $db_persist); |
| 380 | 398 | |
| 381 | - if (!empty($db_port)) |
|
| 382 | - $options['port'] = $db_port; |
|
| 399 | + if (!empty($db_port)) { |
|
| 400 | + $options['port'] = $db_port; |
|
| 401 | + } |
|
| 383 | 402 | |
| 384 | - if (!empty($db_mb4)) |
|
| 385 | - $options['db_mb4'] = $db_mb4; |
|
| 403 | + if (!empty($db_mb4)) { |
|
| 404 | + $options['db_mb4'] = $db_mb4; |
|
| 405 | + } |
|
| 386 | 406 | |
| 387 | - if (!$db_connection) |
|
| 388 | - $db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $options); |
|
| 407 | + if (!$db_connection) { |
|
| 408 | + $db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $options); |
|
| 409 | + } |
|
| 389 | 410 | } |
| 390 | 411 | } |
| 391 | 412 | |
@@ -413,8 +434,9 @@ discard block |
||
| 413 | 434 | // @todo REMOVE THIS!! |
| 414 | 435 | else |
| 415 | 436 | { |
| 416 | - if (function_exists('doStep' . $_GET['step'])) |
|
| 417 | - call_user_func('doStep' . $_GET['step']); |
|
| 437 | + if (function_exists('doStep' . $_GET['step'])) { |
|
| 438 | + call_user_func('doStep' . $_GET['step']); |
|
| 439 | + } |
|
| 418 | 440 | } |
| 419 | 441 | // Show the footer. |
| 420 | 442 | template_install_below(); |
@@ -432,8 +454,9 @@ discard block |
||
| 432 | 454 | $incontext['sub_template'] = 'welcome_message'; |
| 433 | 455 | |
| 434 | 456 | // Done the submission? |
| 435 | - if (isset($_POST['contbutt'])) |
|
| 436 | - return true; |
|
| 457 | + if (isset($_POST['contbutt'])) { |
|
| 458 | + return true; |
|
| 459 | + } |
|
| 437 | 460 | |
| 438 | 461 | // See if we think they have already installed it? |
| 439 | 462 | if (is_readable(dirname(__FILE__) . '/Settings.php')) |
@@ -441,14 +464,17 @@ discard block |
||
| 441 | 464 | $probably_installed = 0; |
| 442 | 465 | foreach (file(dirname(__FILE__) . '/Settings.php') as $line) |
| 443 | 466 | { |
| 444 | - if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line)) |
|
| 445 | - $probably_installed++; |
|
| 446 | - if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line)) |
|
| 447 | - $probably_installed++; |
|
| 467 | + if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line)) { |
|
| 468 | + $probably_installed++; |
|
| 469 | + } |
|
| 470 | + if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line)) { |
|
| 471 | + $probably_installed++; |
|
| 472 | + } |
|
| 448 | 473 | } |
| 449 | 474 | |
| 450 | - if ($probably_installed == 2) |
|
| 451 | - $incontext['warning'] = $txt['error_already_installed']; |
|
| 475 | + if ($probably_installed == 2) { |
|
| 476 | + $incontext['warning'] = $txt['error_already_installed']; |
|
| 477 | + } |
|
| 452 | 478 | } |
| 453 | 479 | |
| 454 | 480 | // Is some database support even compiled in? |
@@ -463,45 +489,54 @@ discard block |
||
| 463 | 489 | $databases[$key]['supported'] = false; |
| 464 | 490 | $notFoundSQLFile = true; |
| 465 | 491 | $txt['error_db_script_missing'] = sprintf($txt['error_db_script_missing'], 'install_' . $GLOBALS['db_script_version'] . '_' . $type . '.sql'); |
| 492 | + } else { |
|
| 493 | + $incontext['supported_databases'][] = $db; |
|
| 466 | 494 | } |
| 467 | - else |
|
| 468 | - $incontext['supported_databases'][] = $db; |
|
| 469 | 495 | } |
| 470 | 496 | } |
| 471 | 497 | |
| 472 | 498 | // Check the PHP version. |
| 473 | - if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>='))) |
|
| 474 | - $error = 'error_php_too_low'; |
|
| 499 | + if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>='))) { |
|
| 500 | + $error = 'error_php_too_low'; |
|
| 501 | + } |
|
| 475 | 502 | // Make sure we have a supported database |
| 476 | - elseif (empty($incontext['supported_databases'])) |
|
| 477 | - $error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing'; |
|
| 503 | + elseif (empty($incontext['supported_databases'])) { |
|
| 504 | + $error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing'; |
|
| 505 | + } |
|
| 478 | 506 | // How about session support? Some crazy sysadmin remove it? |
| 479 | - elseif (!function_exists('session_start')) |
|
| 480 | - $error = 'error_session_missing'; |
|
| 507 | + elseif (!function_exists('session_start')) { |
|
| 508 | + $error = 'error_session_missing'; |
|
| 509 | + } |
|
| 481 | 510 | // Make sure they uploaded all the files. |
| 482 | - elseif (!file_exists(dirname(__FILE__) . '/index.php')) |
|
| 483 | - $error = 'error_missing_files'; |
|
| 511 | + elseif (!file_exists(dirname(__FILE__) . '/index.php')) { |
|
| 512 | + $error = 'error_missing_files'; |
|
| 513 | + } |
|
| 484 | 514 | // Very simple check on the session.save_path for Windows. |
| 485 | 515 | // @todo Move this down later if they don't use database-driven sessions? |
| 486 | - elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\') |
|
| 487 | - $error = 'error_session_save_path'; |
|
| 516 | + elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\') { |
|
| 517 | + $error = 'error_session_save_path'; |
|
| 518 | + } |
|
| 488 | 519 | |
| 489 | 520 | // Since each of the three messages would look the same, anyway... |
| 490 | - if (isset($error)) |
|
| 491 | - $incontext['error'] = $txt[$error]; |
|
| 521 | + if (isset($error)) { |
|
| 522 | + $incontext['error'] = $txt[$error]; |
|
| 523 | + } |
|
| 492 | 524 | |
| 493 | 525 | // Mod_security blocks everything that smells funny. Let SMF handle security. |
| 494 | - if (!fixModSecurity() && !isset($_GET['overmodsecurity'])) |
|
| 495 | - $incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again']; |
|
| 526 | + if (!fixModSecurity() && !isset($_GET['overmodsecurity'])) { |
|
| 527 | + $incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again']; |
|
| 528 | + } |
|
| 496 | 529 | |
| 497 | 530 | // Confirm mbstring is loaded... |
| 498 | - if (!extension_loaded('mbstring')) |
|
| 499 | - $incontext['error'] = $txt['install_no_mbstring']; |
|
| 531 | + if (!extension_loaded('mbstring')) { |
|
| 532 | + $incontext['error'] = $txt['install_no_mbstring']; |
|
| 533 | + } |
|
| 500 | 534 | |
| 501 | 535 | // Check for https stream support. |
| 502 | 536 | $supported_streams = stream_get_wrappers(); |
| 503 | - if (!in_array('https', $supported_streams)) |
|
| 504 | - $incontext['warning'] = $txt['install_no_https']; |
|
| 537 | + if (!in_array('https', $supported_streams)) { |
|
| 538 | + $incontext['warning'] = $txt['install_no_https']; |
|
| 539 | + } |
|
| 505 | 540 | |
| 506 | 541 | return false; |
| 507 | 542 | } |
@@ -526,12 +561,14 @@ discard block |
||
| 526 | 561 | 'Settings_bak.php', |
| 527 | 562 | ); |
| 528 | 563 | |
| 529 | - foreach ($incontext['detected_languages'] as $lang => $temp) |
|
| 530 | - $extra_files[] = 'Themes/default/languages/' . $lang; |
|
| 564 | + foreach ($incontext['detected_languages'] as $lang => $temp) { |
|
| 565 | + $extra_files[] = 'Themes/default/languages/' . $lang; |
|
| 566 | + } |
|
| 531 | 567 | |
| 532 | 568 | // With mod_security installed, we could attempt to fix it with .htaccess. |
| 533 | - if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules())) |
|
| 534 | - $writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.'; |
|
| 569 | + if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules())) { |
|
| 570 | + $writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.'; |
|
| 571 | + } |
|
| 535 | 572 | |
| 536 | 573 | $failed_files = array(); |
| 537 | 574 | |
@@ -543,20 +580,23 @@ discard block |
||
| 543 | 580 | foreach ($writable_files as $file) |
| 544 | 581 | { |
| 545 | 582 | // Some files won't exist, try to address up front |
| 546 | - if (!file_exists(dirname(__FILE__) . '/' . $file)) |
|
| 547 | - @touch(dirname(__FILE__) . '/' . $file); |
|
| 583 | + if (!file_exists(dirname(__FILE__) . '/' . $file)) { |
|
| 584 | + @touch(dirname(__FILE__) . '/' . $file); |
|
| 585 | + } |
|
| 548 | 586 | // NOW do the writable check... |
| 549 | 587 | if (!is_writable(dirname(__FILE__) . '/' . $file)) |
| 550 | 588 | { |
| 551 | 589 | @chmod(dirname(__FILE__) . '/' . $file, 0755); |
| 552 | 590 | |
| 553 | 591 | // Well, 755 hopefully worked... if not, try 777. |
| 554 | - if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777)) |
|
| 555 | - $failed_files[] = $file; |
|
| 592 | + if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777)) { |
|
| 593 | + $failed_files[] = $file; |
|
| 594 | + } |
|
| 556 | 595 | } |
| 557 | 596 | } |
| 558 | - foreach ($extra_files as $file) |
|
| 559 | - @chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777); |
|
| 597 | + foreach ($extra_files as $file) { |
|
| 598 | + @chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777); |
|
| 599 | + } |
|
| 560 | 600 | } |
| 561 | 601 | // Windows is trickier. Let's try opening for r+... |
| 562 | 602 | else |
@@ -566,30 +606,35 @@ discard block |
||
| 566 | 606 | foreach ($writable_files as $file) |
| 567 | 607 | { |
| 568 | 608 | // Folders can't be opened for write... but the index.php in them can ;) |
| 569 | - if (is_dir(dirname(__FILE__) . '/' . $file)) |
|
| 570 | - $file .= '/index.php'; |
|
| 609 | + if (is_dir(dirname(__FILE__) . '/' . $file)) { |
|
| 610 | + $file .= '/index.php'; |
|
| 611 | + } |
|
| 571 | 612 | |
| 572 | 613 | // Funny enough, chmod actually does do something on windows - it removes the read only attribute. |
| 573 | 614 | @chmod(dirname(__FILE__) . '/' . $file, 0777); |
| 574 | 615 | $fp = @fopen(dirname(__FILE__) . '/' . $file, 'r+'); |
| 575 | 616 | |
| 576 | 617 | // Hmm, okay, try just for write in that case... |
| 577 | - if (!is_resource($fp)) |
|
| 578 | - $fp = @fopen(dirname(__FILE__) . '/' . $file, 'w'); |
|
| 618 | + if (!is_resource($fp)) { |
|
| 619 | + $fp = @fopen(dirname(__FILE__) . '/' . $file, 'w'); |
|
| 620 | + } |
|
| 579 | 621 | |
| 580 | - if (!is_resource($fp)) |
|
| 581 | - $failed_files[] = $file; |
|
| 622 | + if (!is_resource($fp)) { |
|
| 623 | + $failed_files[] = $file; |
|
| 624 | + } |
|
| 582 | 625 | |
| 583 | 626 | @fclose($fp); |
| 584 | 627 | } |
| 585 | - foreach ($extra_files as $file) |
|
| 586 | - @chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777); |
|
| 628 | + foreach ($extra_files as $file) { |
|
| 629 | + @chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777); |
|
| 630 | + } |
|
| 587 | 631 | } |
| 588 | 632 | |
| 589 | 633 | $failure = count($failed_files) >= 1; |
| 590 | 634 | |
| 591 | - if (!isset($_SERVER)) |
|
| 592 | - return !$failure; |
|
| 635 | + if (!isset($_SERVER)) { |
|
| 636 | + return !$failure; |
|
| 637 | + } |
|
| 593 | 638 | |
| 594 | 639 | // Put the list into context. |
| 595 | 640 | $incontext['failed_files'] = $failed_files; |
@@ -637,19 +682,23 @@ discard block |
||
| 637 | 682 | |
| 638 | 683 | if (!isset($ftp) || $ftp->error !== false) |
| 639 | 684 | { |
| 640 | - if (!isset($ftp)) |
|
| 641 | - $ftp = new ftp_connection(null); |
|
| 685 | + if (!isset($ftp)) { |
|
| 686 | + $ftp = new ftp_connection(null); |
|
| 687 | + } |
|
| 642 | 688 | // Save the error so we can mess with listing... |
| 643 | - elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message)) |
|
| 644 | - $incontext['ftp_errors'][] = $ftp->last_message; |
|
| 689 | + elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message)) { |
|
| 690 | + $incontext['ftp_errors'][] = $ftp->last_message; |
|
| 691 | + } |
|
| 645 | 692 | |
| 646 | 693 | list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__)); |
| 647 | 694 | |
| 648 | - if (empty($_POST['ftp_path']) && $found_path) |
|
| 649 | - $_POST['ftp_path'] = $detect_path; |
|
| 695 | + if (empty($_POST['ftp_path']) && $found_path) { |
|
| 696 | + $_POST['ftp_path'] = $detect_path; |
|
| 697 | + } |
|
| 650 | 698 | |
| 651 | - if (!isset($_POST['ftp_username'])) |
|
| 652 | - $_POST['ftp_username'] = $username; |
|
| 699 | + if (!isset($_POST['ftp_username'])) { |
|
| 700 | + $_POST['ftp_username'] = $username; |
|
| 701 | + } |
|
| 653 | 702 | |
| 654 | 703 | // Set the username etc, into context. |
| 655 | 704 | $incontext['ftp'] = array( |
@@ -661,8 +710,7 @@ discard block |
||
| 661 | 710 | ); |
| 662 | 711 | |
| 663 | 712 | return false; |
| 664 | - } |
|
| 665 | - else |
|
| 713 | + } else |
|
| 666 | 714 | { |
| 667 | 715 | $_SESSION['installer_temp_ftp'] = array( |
| 668 | 716 | 'server' => $_POST['ftp_server'], |
@@ -676,10 +724,12 @@ discard block |
||
| 676 | 724 | |
| 677 | 725 | foreach ($failed_files as $file) |
| 678 | 726 | { |
| 679 | - if (!is_writable(dirname(__FILE__) . '/' . $file)) |
|
| 680 | - $ftp->chmod($file, 0755); |
|
| 681 | - if (!is_writable(dirname(__FILE__) . '/' . $file)) |
|
| 682 | - $ftp->chmod($file, 0777); |
|
| 727 | + if (!is_writable(dirname(__FILE__) . '/' . $file)) { |
|
| 728 | + $ftp->chmod($file, 0755); |
|
| 729 | + } |
|
| 730 | + if (!is_writable(dirname(__FILE__) . '/' . $file)) { |
|
| 731 | + $ftp->chmod($file, 0777); |
|
| 732 | + } |
|
| 683 | 733 | if (!is_writable(dirname(__FILE__) . '/' . $file)) |
| 684 | 734 | { |
| 685 | 735 | $failed_files_updated[] = $file; |
@@ -735,15 +785,17 @@ discard block |
||
| 735 | 785 | |
| 736 | 786 | if (!$foundOne) |
| 737 | 787 | { |
| 738 | - if (isset($db['default_host'])) |
|
| 739 | - $incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost'; |
|
| 788 | + if (isset($db['default_host'])) { |
|
| 789 | + $incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost'; |
|
| 790 | + } |
|
| 740 | 791 | if (isset($db['default_user'])) |
| 741 | 792 | { |
| 742 | 793 | $incontext['db']['user'] = ini_get($db['default_user']); |
| 743 | 794 | $incontext['db']['name'] = ini_get($db['default_user']); |
| 744 | 795 | } |
| 745 | - if (isset($db['default_password'])) |
|
| 746 | - $incontext['db']['pass'] = ini_get($db['default_password']); |
|
| 796 | + if (isset($db['default_password'])) { |
|
| 797 | + $incontext['db']['pass'] = ini_get($db['default_password']); |
|
| 798 | + } |
|
| 747 | 799 | |
| 748 | 800 | // For simplicity and less confusion, leave the port blank by default |
| 749 | 801 | $incontext['db']['port'] = ''; |
@@ -762,10 +814,10 @@ discard block |
||
| 762 | 814 | $incontext['db']['server'] = $_POST['db_server']; |
| 763 | 815 | $incontext['db']['prefix'] = $_POST['db_prefix']; |
| 764 | 816 | |
| 765 | - if (!empty($_POST['db_port'])) |
|
| 766 | - $incontext['db']['port'] = $_POST['db_port']; |
|
| 767 | - } |
|
| 768 | - else |
|
| 817 | + if (!empty($_POST['db_port'])) { |
|
| 818 | + $incontext['db']['port'] = $_POST['db_port']; |
|
| 819 | + } |
|
| 820 | + } else |
|
| 769 | 821 | { |
| 770 | 822 | $incontext['db']['prefix'] = 'smf_'; |
| 771 | 823 | } |
@@ -801,10 +853,11 @@ discard block |
||
| 801 | 853 | if (!empty($_POST['db_port'])) |
| 802 | 854 | { |
| 803 | 855 | // For MySQL, we can get the "default port" from PHP. PostgreSQL has no such option though. |
| 804 | - if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port')) |
|
| 805 | - $vars['db_port'] = (int) $_POST['db_port']; |
|
| 806 | - elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432) |
|
| 807 | - $vars['db_port'] = (int) $_POST['db_port']; |
|
| 856 | + if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port')) { |
|
| 857 | + $vars['db_port'] = (int) $_POST['db_port']; |
|
| 858 | + } elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432) { |
|
| 859 | + $vars['db_port'] = (int) $_POST['db_port']; |
|
| 860 | + } |
|
| 808 | 861 | } |
| 809 | 862 | |
| 810 | 863 | // God I hope it saved! |
@@ -817,8 +870,9 @@ discard block |
||
| 817 | 870 | // Make sure it works. |
| 818 | 871 | require(dirname(__FILE__) . '/Settings.php'); |
| 819 | 872 | |
| 820 | - if (empty($sourcedir)) |
|
| 821 | - $sourcedir = dirname(__FILE__) . '/Sources'; |
|
| 873 | + if (empty($sourcedir)) { |
|
| 874 | + $sourcedir = dirname(__FILE__) . '/Sources'; |
|
| 875 | + } |
|
| 822 | 876 | |
| 823 | 877 | // Better find the database file! |
| 824 | 878 | if (!file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) |
@@ -828,12 +882,14 @@ discard block |
||
| 828 | 882 | } |
| 829 | 883 | |
| 830 | 884 | // Now include it for database functions! |
| 831 | - if (!defined('SMF')) |
|
| 832 | - define('SMF', 1); |
|
| 885 | + if (!defined('SMF')) { |
|
| 886 | + define('SMF', 1); |
|
| 887 | + } |
|
| 833 | 888 | |
| 834 | 889 | $modSettings['disableQueryCheck'] = true; |
| 835 | - if (empty($smcFunc)) |
|
| 836 | - $smcFunc = array(); |
|
| 890 | + if (empty($smcFunc)) { |
|
| 891 | + $smcFunc = array(); |
|
| 892 | + } |
|
| 837 | 893 | |
| 838 | 894 | require_once($sourcedir . '/Subs-Db-' . $db_type . '.php'); |
| 839 | 895 | |
@@ -842,11 +898,13 @@ discard block |
||
| 842 | 898 | |
| 843 | 899 | $options = array('non_fatal' => true, 'dont_select_db' => !$needsDB); |
| 844 | 900 | // Add in the port if needed |
| 845 | - if (!empty($db_port)) |
|
| 846 | - $options['port'] = $db_port; |
|
| 901 | + if (!empty($db_port)) { |
|
| 902 | + $options['port'] = $db_port; |
|
| 903 | + } |
|
| 847 | 904 | |
| 848 | - if (!empty($db_mb4)) |
|
| 849 | - $options['db_mb4'] = $db_mb4; |
|
| 905 | + if (!empty($db_mb4)) { |
|
| 906 | + $options['db_mb4'] = $db_mb4; |
|
| 907 | + } |
|
| 850 | 908 | |
| 851 | 909 | $db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $options); |
| 852 | 910 | |
@@ -932,12 +990,14 @@ discard block |
||
| 932 | 990 | $incontext['page_title'] = $txt['install_settings']; |
| 933 | 991 | |
| 934 | 992 | // Let's see if we got the database type correct. |
| 935 | - if (isset($_POST['db_type'], $databases[$_POST['db_type']])) |
|
| 936 | - $db_type = $_POST['db_type']; |
|
| 993 | + if (isset($_POST['db_type'], $databases[$_POST['db_type']])) { |
|
| 994 | + $db_type = $_POST['db_type']; |
|
| 995 | + } |
|
| 937 | 996 | |
| 938 | 997 | // Else we'd better be able to get the connection. |
| 939 | - else |
|
| 940 | - load_database(); |
|
| 998 | + else { |
|
| 999 | + load_database(); |
|
| 1000 | + } |
|
| 941 | 1001 | |
| 942 | 1002 | $db_type = isset($_POST['db_type']) ? $_POST['db_type'] : $db_type; |
| 943 | 1003 | |
@@ -946,10 +1006,11 @@ discard block |
||
| 946 | 1006 | |
| 947 | 1007 | $secure = false; |
| 948 | 1008 | |
| 949 | - if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') |
|
| 950 | - $secure = true; |
|
| 951 | - elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') |
|
| 952 | - $secure = true; |
|
| 1009 | + if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { |
|
| 1010 | + $secure = true; |
|
| 1011 | + } elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') { |
|
| 1012 | + $secure = true; |
|
| 1013 | + } |
|
| 953 | 1014 | |
| 954 | 1015 | // Now, to put what we've learned together... and add a path. |
| 955 | 1016 | $incontext['detected_url'] = 'http' . ($secure ? 's' : '') . '://' . $host . substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/')); |
@@ -981,18 +1042,21 @@ discard block |
||
| 981 | 1042 | // Submitting? |
| 982 | 1043 | if (isset($_POST['boardurl'])) |
| 983 | 1044 | { |
| 984 | - if (substr($_POST['boardurl'], -10) == '/index.php') |
|
| 985 | - $_POST['boardurl'] = substr($_POST['boardurl'], 0, -10); |
|
| 986 | - elseif (substr($_POST['boardurl'], -1) == '/') |
|
| 987 | - $_POST['boardurl'] = substr($_POST['boardurl'], 0, -1); |
|
| 988 | - if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') |
|
| 989 | - $_POST['boardurl'] = 'http://' . $_POST['boardurl']; |
|
| 1045 | + if (substr($_POST['boardurl'], -10) == '/index.php') { |
|
| 1046 | + $_POST['boardurl'] = substr($_POST['boardurl'], 0, -10); |
|
| 1047 | + } elseif (substr($_POST['boardurl'], -1) == '/') { |
|
| 1048 | + $_POST['boardurl'] = substr($_POST['boardurl'], 0, -1); |
|
| 1049 | + } |
|
| 1050 | + if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') { |
|
| 1051 | + $_POST['boardurl'] = 'http://' . $_POST['boardurl']; |
|
| 1052 | + } |
|
| 990 | 1053 | |
| 991 | 1054 | //Make sure boardurl is aligned with ssl setting |
| 992 | - if (empty($_POST['force_ssl'])) |
|
| 993 | - $_POST['boardurl'] = strtr($_POST['boardurl'], array('https://' => 'http://')); |
|
| 994 | - else |
|
| 995 | - $_POST['boardurl'] = strtr($_POST['boardurl'], array('http://' => 'https://')); |
|
| 1055 | + if (empty($_POST['force_ssl'])) { |
|
| 1056 | + $_POST['boardurl'] = strtr($_POST['boardurl'], array('https://' => 'http://')); |
|
| 1057 | + } else { |
|
| 1058 | + $_POST['boardurl'] = strtr($_POST['boardurl'], array('http://' => 'https://')); |
|
| 1059 | + } |
|
| 996 | 1060 | |
| 997 | 1061 | // Save these variables. |
| 998 | 1062 | $vars = array( |
@@ -1031,10 +1095,10 @@ discard block |
||
| 1031 | 1095 | { |
| 1032 | 1096 | $incontext['error'] = sprintf($txt['error_utf8_version'], $databases[$db_type]['utf8_version']); |
| 1033 | 1097 | return false; |
| 1034 | - } |
|
| 1035 | - else |
|
| 1036 | - // Set the character set here. |
|
| 1098 | + } else { |
|
| 1099 | + // Set the character set here. |
|
| 1037 | 1100 | updateSettingsFile(array('db_character_set' => 'utf8')); |
| 1101 | + } |
|
| 1038 | 1102 | } |
| 1039 | 1103 | |
| 1040 | 1104 | // Good, skip on. |
@@ -1054,8 +1118,9 @@ discard block |
||
| 1054 | 1118 | $incontext['continue'] = 1; |
| 1055 | 1119 | |
| 1056 | 1120 | // Already done? |
| 1057 | - if (isset($_POST['pop_done'])) |
|
| 1058 | - return true; |
|
| 1121 | + if (isset($_POST['pop_done'])) { |
|
| 1122 | + return true; |
|
| 1123 | + } |
|
| 1059 | 1124 | |
| 1060 | 1125 | // Reload settings. |
| 1061 | 1126 | require(dirname(__FILE__) . '/Settings.php'); |
@@ -1073,8 +1138,9 @@ discard block |
||
| 1073 | 1138 | $modSettings = array(); |
| 1074 | 1139 | if ($result !== false) |
| 1075 | 1140 | { |
| 1076 | - while ($row = $smcFunc['db_fetch_assoc']($result)) |
|
| 1077 | - $modSettings[$row['variable']] = $row['value']; |
|
| 1141 | + while ($row = $smcFunc['db_fetch_assoc']($result)) { |
|
| 1142 | + $modSettings[$row['variable']] = $row['value']; |
|
| 1143 | + } |
|
| 1078 | 1144 | $smcFunc['db_free_result']($result); |
| 1079 | 1145 | |
| 1080 | 1146 | // Do they match? If so, this is just a refresh so charge on! |
@@ -1087,20 +1153,22 @@ discard block |
||
| 1087 | 1153 | $modSettings['disableQueryCheck'] = true; |
| 1088 | 1154 | |
| 1089 | 1155 | // If doing UTF8, select it. PostgreSQL requires passing it as a string... |
| 1090 | - if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support'])) |
|
| 1091 | - $smcFunc['db_query']('', ' |
|
| 1156 | + if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support'])) { |
|
| 1157 | + $smcFunc['db_query']('', ' |
|
| 1092 | 1158 | SET NAMES {string:utf8}', |
| 1093 | 1159 | array( |
| 1094 | 1160 | 'db_error_skip' => true, |
| 1095 | 1161 | 'utf8' => 'utf8', |
| 1096 | 1162 | ) |
| 1097 | 1163 | ); |
| 1164 | + } |
|
| 1098 | 1165 | |
| 1099 | 1166 | // Windows likes to leave the trailing slash, which yields to C:\path\to\SMF\/attachments... |
| 1100 | - if (substr(__DIR__, -1) == '\\') |
|
| 1101 | - $attachdir = __DIR__ . 'attachments'; |
|
| 1102 | - else |
|
| 1103 | - $attachdir = __DIR__ . '/attachments'; |
|
| 1167 | + if (substr(__DIR__, -1) == '\\') { |
|
| 1168 | + $attachdir = __DIR__ . 'attachments'; |
|
| 1169 | + } else { |
|
| 1170 | + $attachdir = __DIR__ . '/attachments'; |
|
| 1171 | + } |
|
| 1104 | 1172 | |
| 1105 | 1173 | $replaces = array( |
| 1106 | 1174 | '{$db_prefix}' => $db_prefix, |
@@ -1117,8 +1185,9 @@ discard block |
||
| 1117 | 1185 | |
| 1118 | 1186 | foreach ($txt as $key => $value) |
| 1119 | 1187 | { |
| 1120 | - if (substr($key, 0, 8) == 'default_') |
|
| 1121 | - $replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value); |
|
| 1188 | + if (substr($key, 0, 8) == 'default_') { |
|
| 1189 | + $replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value); |
|
| 1190 | + } |
|
| 1122 | 1191 | } |
| 1123 | 1192 | $replaces['{$default_reserved_names}'] = strtr($replaces['{$default_reserved_names}'], array('\\\\n' => '\\n')); |
| 1124 | 1193 | |
@@ -1133,8 +1202,9 @@ discard block |
||
| 1133 | 1202 | |
| 1134 | 1203 | while ($row = $smcFunc['db_fetch_assoc']($get_engines)) |
| 1135 | 1204 | { |
| 1136 | - if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') |
|
| 1137 | - $engines[] = $row['Engine']; |
|
| 1205 | + if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') { |
|
| 1206 | + $engines[] = $row['Engine']; |
|
| 1207 | + } |
|
| 1138 | 1208 | } |
| 1139 | 1209 | |
| 1140 | 1210 | // Done with this now |
@@ -1158,8 +1228,7 @@ discard block |
||
| 1158 | 1228 | $replaces['START TRANSACTION;'] = ''; |
| 1159 | 1229 | $replaces['COMMIT;'] = ''; |
| 1160 | 1230 | } |
| 1161 | - } |
|
| 1162 | - else |
|
| 1231 | + } else |
|
| 1163 | 1232 | { |
| 1164 | 1233 | $has_innodb = false; |
| 1165 | 1234 | } |
@@ -1181,21 +1250,24 @@ discard block |
||
| 1181 | 1250 | foreach ($sql_lines as $count => $line) |
| 1182 | 1251 | { |
| 1183 | 1252 | // No comments allowed! |
| 1184 | - if (substr(trim($line), 0, 1) != '#') |
|
| 1185 | - $current_statement .= "\n" . rtrim($line); |
|
| 1253 | + if (substr(trim($line), 0, 1) != '#') { |
|
| 1254 | + $current_statement .= "\n" . rtrim($line); |
|
| 1255 | + } |
|
| 1186 | 1256 | |
| 1187 | 1257 | // Is this the end of the query string? |
| 1188 | - if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines))) |
|
| 1189 | - continue; |
|
| 1258 | + if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines))) { |
|
| 1259 | + continue; |
|
| 1260 | + } |
|
| 1190 | 1261 | |
| 1191 | 1262 | // Does this table already exist? If so, don't insert more data into it! |
| 1192 | 1263 | if (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) != 0 && in_array($match[1], $exists)) |
| 1193 | 1264 | { |
| 1194 | 1265 | preg_match_all('~\)[,;]~', $current_statement, $matches); |
| 1195 | - if (!empty($matches[0])) |
|
| 1196 | - $incontext['sql_results']['insert_dups'] += count($matches[0]); |
|
| 1197 | - else |
|
| 1198 | - $incontext['sql_results']['insert_dups']++; |
|
| 1266 | + if (!empty($matches[0])) { |
|
| 1267 | + $incontext['sql_results']['insert_dups'] += count($matches[0]); |
|
| 1268 | + } else { |
|
| 1269 | + $incontext['sql_results']['insert_dups']++; |
|
| 1270 | + } |
|
| 1199 | 1271 | |
| 1200 | 1272 | $current_statement = ''; |
| 1201 | 1273 | continue; |
@@ -1216,18 +1288,18 @@ discard block |
||
| 1216 | 1288 | // MySQLi requires a connection object. It's optional with MySQL and Postgres |
| 1217 | 1289 | $incontext['failures'][$count] = $smcFunc['db_error']($db_connection); |
| 1218 | 1290 | } |
| 1219 | - } |
|
| 1220 | - else |
|
| 1291 | + } else |
|
| 1221 | 1292 | { |
| 1222 | - if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1) |
|
| 1223 | - $incontext['sql_results']['tables']++; |
|
| 1224 | - elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1) |
|
| 1293 | + if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1) { |
|
| 1294 | + $incontext['sql_results']['tables']++; |
|
| 1295 | + } elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1) |
|
| 1225 | 1296 | { |
| 1226 | 1297 | preg_match_all('~\)[,;]~', $current_statement, $matches); |
| 1227 | - if (!empty($matches[0])) |
|
| 1228 | - $incontext['sql_results']['inserts'] += count($matches[0]); |
|
| 1229 | - else |
|
| 1230 | - $incontext['sql_results']['inserts']++; |
|
| 1298 | + if (!empty($matches[0])) { |
|
| 1299 | + $incontext['sql_results']['inserts'] += count($matches[0]); |
|
| 1300 | + } else { |
|
| 1301 | + $incontext['sql_results']['inserts']++; |
|
| 1302 | + } |
|
| 1231 | 1303 | } |
| 1232 | 1304 | } |
| 1233 | 1305 | |
@@ -1240,15 +1312,17 @@ discard block |
||
| 1240 | 1312 | // Sort out the context for the SQL. |
| 1241 | 1313 | foreach ($incontext['sql_results'] as $key => $number) |
| 1242 | 1314 | { |
| 1243 | - if ($number == 0) |
|
| 1244 | - unset($incontext['sql_results'][$key]); |
|
| 1245 | - else |
|
| 1246 | - $incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number); |
|
| 1315 | + if ($number == 0) { |
|
| 1316 | + unset($incontext['sql_results'][$key]); |
|
| 1317 | + } else { |
|
| 1318 | + $incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number); |
|
| 1319 | + } |
|
| 1247 | 1320 | } |
| 1248 | 1321 | |
| 1249 | 1322 | // Make sure UTF will be used globally. |
| 1250 | - 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']))) |
|
| 1251 | - $newSettings[] = array('global_character_set', 'UTF-8'); |
|
| 1323 | + 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']))) { |
|
| 1324 | + $newSettings[] = array('global_character_set', 'UTF-8'); |
|
| 1325 | + } |
|
| 1252 | 1326 | |
| 1253 | 1327 | // Auto-detect local & global cookie settings |
| 1254 | 1328 | $url_parts = parse_url($boardurl); |
@@ -1277,15 +1351,19 @@ discard block |
||
| 1277 | 1351 | |
| 1278 | 1352 | // Look for subfolder, if found, set localCookie |
| 1279 | 1353 | // Checking for len > 1 ensures you don't have just a slash... |
| 1280 | - if (!empty($url_parts['path']) && strlen($url_parts['path']) > 1) |
|
| 1281 | - $localCookies = '1'; |
|
| 1354 | + if (!empty($url_parts['path']) && strlen($url_parts['path']) > 1) { |
|
| 1355 | + $localCookies = '1'; |
|
| 1356 | + } |
|
| 1282 | 1357 | |
| 1283 | - if (isset($globalCookies)) |
|
| 1284 | - $newSettings[] = array('globalCookies', $globalCookies); |
|
| 1285 | - if (isset($globalCookiesDomain)) |
|
| 1286 | - $newSettings[] = array('globalCookiesDomain', $globalCookiesDomain); |
|
| 1287 | - if (isset($localCookies)) |
|
| 1288 | - $newSettings[] = array('localCookies', $localCookies); |
|
| 1358 | + if (isset($globalCookies)) { |
|
| 1359 | + $newSettings[] = array('globalCookies', $globalCookies); |
|
| 1360 | + } |
|
| 1361 | + if (isset($globalCookiesDomain)) { |
|
| 1362 | + $newSettings[] = array('globalCookiesDomain', $globalCookiesDomain); |
|
| 1363 | + } |
|
| 1364 | + if (isset($localCookies)) { |
|
| 1365 | + $newSettings[] = array('localCookies', $localCookies); |
|
| 1366 | + } |
|
| 1289 | 1367 | } |
| 1290 | 1368 | |
| 1291 | 1369 | // Are we allowing stat collection? |
@@ -1303,16 +1381,17 @@ discard block |
||
| 1303 | 1381 | fwrite($fp, $out); |
| 1304 | 1382 | |
| 1305 | 1383 | $return_data = ''; |
| 1306 | - while (!feof($fp)) |
|
| 1307 | - $return_data .= fgets($fp, 128); |
|
| 1384 | + while (!feof($fp)) { |
|
| 1385 | + $return_data .= fgets($fp, 128); |
|
| 1386 | + } |
|
| 1308 | 1387 | |
| 1309 | 1388 | fclose($fp); |
| 1310 | 1389 | |
| 1311 | 1390 | // Get the unique site ID. |
| 1312 | 1391 | preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID); |
| 1313 | 1392 | |
| 1314 | - if (!empty($ID[1])) |
|
| 1315 | - $smcFunc['db_insert']('replace', |
|
| 1393 | + if (!empty($ID[1])) { |
|
| 1394 | + $smcFunc['db_insert']('replace', |
|
| 1316 | 1395 | $db_prefix . 'settings', |
| 1317 | 1396 | array('variable' => 'string', 'value' => 'string'), |
| 1318 | 1397 | array( |
@@ -1321,11 +1400,12 @@ discard block |
||
| 1321 | 1400 | ), |
| 1322 | 1401 | array('variable') |
| 1323 | 1402 | ); |
| 1403 | + } |
|
| 1324 | 1404 | } |
| 1325 | 1405 | } |
| 1326 | 1406 | // Don't remove stat collection unless we unchecked the box for real, not from the loop. |
| 1327 | - elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) |
|
| 1328 | - $smcFunc['db_query']('', ' |
|
| 1407 | + elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) { |
|
| 1408 | + $smcFunc['db_query']('', ' |
|
| 1329 | 1409 | DELETE FROM {db_prefix}settings |
| 1330 | 1410 | WHERE variable = {string:enable_sm_stats}', |
| 1331 | 1411 | array( |
@@ -1333,20 +1413,23 @@ discard block |
||
| 1333 | 1413 | 'db_error_skip' => true, |
| 1334 | 1414 | ) |
| 1335 | 1415 | ); |
| 1416 | + } |
|
| 1336 | 1417 | |
| 1337 | 1418 | // Are we enabling SSL? |
| 1338 | - if (!empty($_POST['force_ssl'])) |
|
| 1339 | - $newSettings[] = array('force_ssl', 1); |
|
| 1419 | + if (!empty($_POST['force_ssl'])) { |
|
| 1420 | + $newSettings[] = array('force_ssl', 1); |
|
| 1421 | + } |
|
| 1340 | 1422 | |
| 1341 | 1423 | // Setting a timezone is required. |
| 1342 | 1424 | if (!isset($modSettings['default_timezone']) && function_exists('date_default_timezone_set')) |
| 1343 | 1425 | { |
| 1344 | 1426 | // Get PHP's default timezone, if set |
| 1345 | 1427 | $ini_tz = ini_get('date.timezone'); |
| 1346 | - if (!empty($ini_tz)) |
|
| 1347 | - $timezone_id = $ini_tz; |
|
| 1348 | - else |
|
| 1349 | - $timezone_id = ''; |
|
| 1428 | + if (!empty($ini_tz)) { |
|
| 1429 | + $timezone_id = $ini_tz; |
|
| 1430 | + } else { |
|
| 1431 | + $timezone_id = ''; |
|
| 1432 | + } |
|
| 1350 | 1433 | |
| 1351 | 1434 | // If date.timezone is unset, invalid, or just plain weird, make a best guess |
| 1352 | 1435 | if (!in_array($timezone_id, timezone_identifiers_list())) |
@@ -1355,8 +1438,9 @@ discard block |
||
| 1355 | 1438 | $timezone_id = timezone_name_from_abbr('', $server_offset, 0); |
| 1356 | 1439 | } |
| 1357 | 1440 | |
| 1358 | - if (date_default_timezone_set($timezone_id)) |
|
| 1359 | - $newSettings[] = array('default_timezone', $timezone_id); |
|
| 1441 | + if (date_default_timezone_set($timezone_id)) { |
|
| 1442 | + $newSettings[] = array('default_timezone', $timezone_id); |
|
| 1443 | + } |
|
| 1360 | 1444 | } |
| 1361 | 1445 | |
| 1362 | 1446 | if (!empty($newSettings)) |
@@ -1387,16 +1471,18 @@ discard block |
||
| 1387 | 1471 | } |
| 1388 | 1472 | |
| 1389 | 1473 | // MySQL specific stuff |
| 1390 | - if (substr($db_type, 0, 5) != 'mysql') |
|
| 1391 | - return false; |
|
| 1474 | + if (substr($db_type, 0, 5) != 'mysql') { |
|
| 1475 | + return false; |
|
| 1476 | + } |
|
| 1392 | 1477 | |
| 1393 | 1478 | // Find database user privileges. |
| 1394 | 1479 | $privs = array(); |
| 1395 | 1480 | $get_privs = $smcFunc['db_query']('', 'SHOW PRIVILEGES', array()); |
| 1396 | 1481 | while ($row = $smcFunc['db_fetch_assoc']($get_privs)) |
| 1397 | 1482 | { |
| 1398 | - if ($row['Privilege'] == 'Alter') |
|
| 1399 | - $privs[] = $row['Privilege']; |
|
| 1483 | + if ($row['Privilege'] == 'Alter') { |
|
| 1484 | + $privs[] = $row['Privilege']; |
|
| 1485 | + } |
|
| 1400 | 1486 | } |
| 1401 | 1487 | $smcFunc['db_free_result']($get_privs); |
| 1402 | 1488 | |
@@ -1426,8 +1512,9 @@ discard block |
||
| 1426 | 1512 | $incontext['continue'] = 1; |
| 1427 | 1513 | |
| 1428 | 1514 | // Skipping? |
| 1429 | - if (!empty($_POST['skip'])) |
|
| 1430 | - return true; |
|
| 1515 | + if (!empty($_POST['skip'])) { |
|
| 1516 | + return true; |
|
| 1517 | + } |
|
| 1431 | 1518 | |
| 1432 | 1519 | // Need this to check whether we need the database password. |
| 1433 | 1520 | require(dirname(__FILE__) . '/Settings.php'); |
@@ -1444,18 +1531,22 @@ discard block |
||
| 1444 | 1531 | // We need this to properly hash the password for Admin |
| 1445 | 1532 | $smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' : function($string) { |
| 1446 | 1533 | global $sourcedir; |
| 1447 | - if (function_exists('mb_strtolower')) |
|
| 1448 | - return mb_strtolower($string, 'UTF-8'); |
|
| 1534 | + if (function_exists('mb_strtolower')) { |
|
| 1535 | + return mb_strtolower($string, 'UTF-8'); |
|
| 1536 | + } |
|
| 1449 | 1537 | require_once($sourcedir . '/Subs-Charset.php'); |
| 1450 | 1538 | return utf8_strtolower($string); |
| 1451 | 1539 | }; |
| 1452 | 1540 | |
| 1453 | - if (!isset($_POST['username'])) |
|
| 1454 | - $_POST['username'] = ''; |
|
| 1455 | - if (!isset($_POST['email'])) |
|
| 1456 | - $_POST['email'] = ''; |
|
| 1457 | - if (!isset($_POST['server_email'])) |
|
| 1458 | - $_POST['server_email'] = ''; |
|
| 1541 | + if (!isset($_POST['username'])) { |
|
| 1542 | + $_POST['username'] = ''; |
|
| 1543 | + } |
|
| 1544 | + if (!isset($_POST['email'])) { |
|
| 1545 | + $_POST['email'] = ''; |
|
| 1546 | + } |
|
| 1547 | + if (!isset($_POST['server_email'])) { |
|
| 1548 | + $_POST['server_email'] = ''; |
|
| 1549 | + } |
|
| 1459 | 1550 | |
| 1460 | 1551 | $incontext['username'] = htmlspecialchars(stripslashes($_POST['username'])); |
| 1461 | 1552 | $incontext['email'] = htmlspecialchars(stripslashes($_POST['email'])); |
@@ -1474,8 +1565,9 @@ discard block |
||
| 1474 | 1565 | 'admin_group' => 1, |
| 1475 | 1566 | ) |
| 1476 | 1567 | ); |
| 1477 | - if ($smcFunc['db_num_rows']($request) != 0) |
|
| 1478 | - $incontext['skip'] = 1; |
|
| 1568 | + if ($smcFunc['db_num_rows']($request) != 0) { |
|
| 1569 | + $incontext['skip'] = 1; |
|
| 1570 | + } |
|
| 1479 | 1571 | $smcFunc['db_free_result']($request); |
| 1480 | 1572 | |
| 1481 | 1573 | // Trying to create an account? |
@@ -1506,8 +1598,9 @@ discard block |
||
| 1506 | 1598 | } |
| 1507 | 1599 | |
| 1508 | 1600 | // Update the webmaster's email? |
| 1509 | - if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]')) |
|
| 1510 | - updateSettingsFile(array('webmaster_email' => $_POST['server_email'])); |
|
| 1601 | + if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]')) { |
|
| 1602 | + updateSettingsFile(array('webmaster_email' => $_POST['server_email'])); |
|
| 1603 | + } |
|
| 1511 | 1604 | |
| 1512 | 1605 | // Work out whether we're going to have dodgy characters and remove them. |
| 1513 | 1606 | $invalid_characters = preg_match('~[<>&"\'=\\\]~', $_POST['username']) != 0; |
@@ -1530,32 +1623,27 @@ discard block |
||
| 1530 | 1623 | $smcFunc['db_free_result']($result); |
| 1531 | 1624 | |
| 1532 | 1625 | $incontext['account_existed'] = $txt['error_user_settings_taken']; |
| 1533 | - } |
|
| 1534 | - elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25) |
|
| 1626 | + } elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25) |
|
| 1535 | 1627 | { |
| 1536 | 1628 | // Try the previous step again. |
| 1537 | 1629 | $incontext['error'] = $_POST['username'] == '' ? $txt['error_username_left_empty'] : $txt['error_username_too_long']; |
| 1538 | 1630 | return false; |
| 1539 | - } |
|
| 1540 | - elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false) |
|
| 1631 | + } elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false) |
|
| 1541 | 1632 | { |
| 1542 | 1633 | // Try the previous step again. |
| 1543 | 1634 | $incontext['error'] = $txt['error_invalid_characters_username']; |
| 1544 | 1635 | return false; |
| 1545 | - } |
|
| 1546 | - elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255) |
|
| 1636 | + } elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255) |
|
| 1547 | 1637 | { |
| 1548 | 1638 | // One step back, this time fill out a proper admin email address. |
| 1549 | 1639 | $incontext['error'] = sprintf($txt['error_valid_admin_email_needed'], $_POST['username']); |
| 1550 | 1640 | return false; |
| 1551 | - } |
|
| 1552 | - elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255) |
|
| 1641 | + } elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255) |
|
| 1553 | 1642 | { |
| 1554 | 1643 | // One step back, this time fill out a proper admin email address. |
| 1555 | 1644 | $incontext['error'] = $txt['error_valid_server_email_needed']; |
| 1556 | 1645 | return false; |
| 1557 | - } |
|
| 1558 | - elseif ($_POST['username'] != '') |
|
| 1646 | + } elseif ($_POST['username'] != '') |
|
| 1559 | 1647 | { |
| 1560 | 1648 | $incontext['member_salt'] = substr(md5(random_int(0, PHP_INT_MAX)), 0, 4); |
| 1561 | 1649 | |
@@ -1623,17 +1711,19 @@ discard block |
||
| 1623 | 1711 | reloadSettings(); |
| 1624 | 1712 | |
| 1625 | 1713 | // Bring a warning over. |
| 1626 | - if (!empty($incontext['account_existed'])) |
|
| 1627 | - $incontext['warning'] = $incontext['account_existed']; |
|
| 1714 | + if (!empty($incontext['account_existed'])) { |
|
| 1715 | + $incontext['warning'] = $incontext['account_existed']; |
|
| 1716 | + } |
|
| 1628 | 1717 | |
| 1629 | - if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support'])) |
|
| 1630 | - $smcFunc['db_query']('', ' |
|
| 1718 | + if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support'])) { |
|
| 1719 | + $smcFunc['db_query']('', ' |
|
| 1631 | 1720 | SET NAMES {string:db_character_set}', |
| 1632 | 1721 | array( |
| 1633 | 1722 | 'db_character_set' => $db_character_set, |
| 1634 | 1723 | 'db_error_skip' => true, |
| 1635 | 1724 | ) |
| 1636 | 1725 | ); |
| 1726 | + } |
|
| 1637 | 1727 | |
| 1638 | 1728 | // As track stats is by default enabled let's add some activity. |
| 1639 | 1729 | $smcFunc['db_insert']('ignore', |
@@ -1654,14 +1744,16 @@ discard block |
||
| 1654 | 1744 | // Only proceed if we can load the data. |
| 1655 | 1745 | if ($request) |
| 1656 | 1746 | { |
| 1657 | - while ($row = $smcFunc['db_fetch_row']($request)) |
|
| 1658 | - $modSettings[$row[0]] = $row[1]; |
|
| 1747 | + while ($row = $smcFunc['db_fetch_row']($request)) { |
|
| 1748 | + $modSettings[$row[0]] = $row[1]; |
|
| 1749 | + } |
|
| 1659 | 1750 | $smcFunc['db_free_result']($request); |
| 1660 | 1751 | } |
| 1661 | 1752 | |
| 1662 | 1753 | // Automatically log them in ;) |
| 1663 | - if (isset($incontext['member_id']) && isset($incontext['member_salt'])) |
|
| 1664 | - setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt'])); |
|
| 1754 | + if (isset($incontext['member_id']) && isset($incontext['member_salt'])) { |
|
| 1755 | + setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt'])); |
|
| 1756 | + } |
|
| 1665 | 1757 | |
| 1666 | 1758 | $result = $smcFunc['db_query']('', ' |
| 1667 | 1759 | SELECT value |
@@ -1672,13 +1764,14 @@ discard block |
||
| 1672 | 1764 | 'db_error_skip' => true, |
| 1673 | 1765 | ) |
| 1674 | 1766 | ); |
| 1675 | - if ($smcFunc['db_num_rows']($result) != 0) |
|
| 1676 | - list ($db_sessions) = $smcFunc['db_fetch_row']($result); |
|
| 1767 | + if ($smcFunc['db_num_rows']($result) != 0) { |
|
| 1768 | + list ($db_sessions) = $smcFunc['db_fetch_row']($result); |
|
| 1769 | + } |
|
| 1677 | 1770 | $smcFunc['db_free_result']($result); |
| 1678 | 1771 | |
| 1679 | - if (empty($db_sessions)) |
|
| 1680 | - $_SESSION['admin_time'] = time(); |
|
| 1681 | - else |
|
| 1772 | + if (empty($db_sessions)) { |
|
| 1773 | + $_SESSION['admin_time'] = time(); |
|
| 1774 | + } else |
|
| 1682 | 1775 | { |
| 1683 | 1776 | $_SERVER['HTTP_USER_AGENT'] = substr($_SERVER['HTTP_USER_AGENT'], 0, 211); |
| 1684 | 1777 | |
@@ -1702,8 +1795,9 @@ discard block |
||
| 1702 | 1795 | $smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' : |
| 1703 | 1796 | function($string){ |
| 1704 | 1797 | global $sourcedir; |
| 1705 | - if (function_exists('mb_strtolower')) |
|
| 1706 | - return mb_strtolower($string, 'UTF-8'); |
|
| 1798 | + if (function_exists('mb_strtolower')) { |
|
| 1799 | + return mb_strtolower($string, 'UTF-8'); |
|
| 1800 | + } |
|
| 1707 | 1801 | require_once($sourcedir . '/Subs-Charset.php'); |
| 1708 | 1802 | return utf8_strtolower($string); |
| 1709 | 1803 | }; |
@@ -1719,8 +1813,9 @@ discard block |
||
| 1719 | 1813 | ) |
| 1720 | 1814 | ); |
| 1721 | 1815 | $context['utf8'] = $db_character_set === 'utf8' || $txt['lang_character_set'] === 'UTF-8'; |
| 1722 | - if ($smcFunc['db_num_rows']($request) > 0) |
|
| 1723 | - updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject'])); |
|
| 1816 | + if ($smcFunc['db_num_rows']($request) > 0) { |
|
| 1817 | + updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject'])); |
|
| 1818 | + } |
|
| 1724 | 1819 | $smcFunc['db_free_result']($request); |
| 1725 | 1820 | |
| 1726 | 1821 | // Now is the perfect time to fetch the SM files. |
@@ -1739,8 +1834,9 @@ discard block |
||
| 1739 | 1834 | |
| 1740 | 1835 | // Check if we need some stupid MySQL fix. |
| 1741 | 1836 | $server_version = $smcFunc['db_server_info'](); |
| 1742 | - if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) |
|
| 1743 | - updateSettings(array('db_mysql_group_by_fix' => '1')); |
|
| 1837 | + if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) { |
|
| 1838 | + updateSettings(array('db_mysql_group_by_fix' => '1')); |
|
| 1839 | + } |
|
| 1744 | 1840 | |
| 1745 | 1841 | // Some final context for the template. |
| 1746 | 1842 | $incontext['dir_still_writable'] = is_writable(dirname(__FILE__)) && substr(__FILE__, 1, 2) != ':\\'; |
@@ -1760,8 +1856,9 @@ discard block |
||
| 1760 | 1856 | $settingsArray = file(dirname(__FILE__) . '/Settings.php'); |
| 1761 | 1857 | |
| 1762 | 1858 | // @todo Do we just want to read the file in clean, and split it this way always? |
| 1763 | - if (count($settingsArray) == 1) |
|
| 1764 | - $settingsArray = preg_split('~[\r\n]~', $settingsArray[0]); |
|
| 1859 | + if (count($settingsArray) == 1) { |
|
| 1860 | + $settingsArray = preg_split('~[\r\n]~', $settingsArray[0]); |
|
| 1861 | + } |
|
| 1765 | 1862 | |
| 1766 | 1863 | for ($i = 0, $n = count($settingsArray); $i < $n; $i++) |
| 1767 | 1864 | { |
@@ -1769,25 +1866,29 @@ discard block |
||
| 1769 | 1866 | if (trim($settingsArray[$i]) == 'if (file_exists(dirname(__FILE__) . \'/install.php\'))' && trim($settingsArray[$i + 1]) == '{' && trim($settingsArray[$i + 9]) == '}') |
| 1770 | 1867 | { |
| 1771 | 1868 | // Set the ten lines to nothing. |
| 1772 | - for ($j=0; $j < 10; $j++) |
|
| 1773 | - $settingsArray[$i++] = ''; |
|
| 1869 | + for ($j=0; $j < 10; $j++) { |
|
| 1870 | + $settingsArray[$i++] = ''; |
|
| 1871 | + } |
|
| 1774 | 1872 | |
| 1775 | 1873 | continue; |
| 1776 | 1874 | } |
| 1777 | 1875 | |
| 1778 | - if (trim($settingsArray[$i]) == '?' . '>') |
|
| 1779 | - $settingsArray[$i] = ''; |
|
| 1876 | + if (trim($settingsArray[$i]) == '?' . '>') { |
|
| 1877 | + $settingsArray[$i] = ''; |
|
| 1878 | + } |
|
| 1780 | 1879 | |
| 1781 | 1880 | // Don't trim or bother with it if it's not a variable. |
| 1782 | - if (substr($settingsArray[$i], 0, 1) != '$') |
|
| 1783 | - continue; |
|
| 1881 | + if (substr($settingsArray[$i], 0, 1) != '$') { |
|
| 1882 | + continue; |
|
| 1883 | + } |
|
| 1784 | 1884 | |
| 1785 | 1885 | $settingsArray[$i] = rtrim($settingsArray[$i]) . "\n"; |
| 1786 | 1886 | |
| 1787 | - foreach ($vars as $var => $val) |
|
| 1788 | - if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0) |
|
| 1887 | + foreach ($vars as $var => $val) { |
|
| 1888 | + if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0) |
|
| 1789 | 1889 | { |
| 1790 | 1890 | $comment = strstr($settingsArray[$i], '#'); |
| 1891 | + } |
|
| 1791 | 1892 | $settingsArray[$i] = '$' . $var . ' = \'' . $val . '\';' . ($comment != '' ? "\t\t" . $comment : "\n"); |
| 1792 | 1893 | unset($vars[$var]); |
| 1793 | 1894 | } |
@@ -1797,36 +1898,41 @@ discard block |
||
| 1797 | 1898 | if (!empty($vars)) |
| 1798 | 1899 | { |
| 1799 | 1900 | $settingsArray[$i++] = ''; |
| 1800 | - foreach ($vars as $var => $val) |
|
| 1801 | - $settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n"; |
|
| 1901 | + foreach ($vars as $var => $val) { |
|
| 1902 | + $settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n"; |
|
| 1903 | + } |
|
| 1802 | 1904 | } |
| 1803 | 1905 | |
| 1804 | 1906 | // Blank out the file - done to fix a oddity with some servers. |
| 1805 | 1907 | $fp = @fopen(dirname(__FILE__) . '/Settings.php', 'w'); |
| 1806 | - if (!$fp) |
|
| 1807 | - return false; |
|
| 1908 | + if (!$fp) { |
|
| 1909 | + return false; |
|
| 1910 | + } |
|
| 1808 | 1911 | fclose($fp); |
| 1809 | 1912 | |
| 1810 | 1913 | $fp = fopen(dirname(__FILE__) . '/Settings.php', 'r+'); |
| 1811 | 1914 | |
| 1812 | 1915 | // Gotta have one of these ;) |
| 1813 | - if (trim($settingsArray[0]) != '<?php') |
|
| 1814 | - fwrite($fp, "<?php\n"); |
|
| 1916 | + if (trim($settingsArray[0]) != '<?php') { |
|
| 1917 | + fwrite($fp, "<?php\n"); |
|
| 1918 | + } |
|
| 1815 | 1919 | |
| 1816 | 1920 | $lines = count($settingsArray); |
| 1817 | 1921 | for ($i = 0; $i < $lines - 1; $i++) |
| 1818 | 1922 | { |
| 1819 | 1923 | // Don't just write a bunch of blank lines. |
| 1820 | - if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '') |
|
| 1821 | - fwrite($fp, strtr($settingsArray[$i], "\r", '')); |
|
| 1924 | + if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '') { |
|
| 1925 | + fwrite($fp, strtr($settingsArray[$i], "\r", '')); |
|
| 1926 | + } |
|
| 1822 | 1927 | } |
| 1823 | 1928 | fwrite($fp, $settingsArray[$i] . '?' . '>'); |
| 1824 | 1929 | fclose($fp); |
| 1825 | 1930 | |
| 1826 | 1931 | // Even though on normal installations the filemtime should prevent this being used by the installer incorrectly |
| 1827 | 1932 | // it seems that there are times it might not. So let's MAKE it dump the cache. |
| 1828 | - if (function_exists('opcache_invalidate')) |
|
| 1829 | - opcache_invalidate(dirname(__FILE__) . '/Settings.php', true); |
|
| 1933 | + if (function_exists('opcache_invalidate')) { |
|
| 1934 | + opcache_invalidate(dirname(__FILE__) . '/Settings.php', true); |
|
| 1935 | + } |
|
| 1830 | 1936 | |
| 1831 | 1937 | return true; |
| 1832 | 1938 | } |
@@ -1836,10 +1942,11 @@ discard block |
||
| 1836 | 1942 | global $cachedir; |
| 1837 | 1943 | |
| 1838 | 1944 | // Write out the db_last_error file with the error timestamp |
| 1839 | - if (!empty($cachedir) && is_writable($cachedir)) |
|
| 1840 | - file_put_contents($cachedir . '/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>'); |
|
| 1841 | - else |
|
| 1842 | - file_put_contents(dirname(__FILE__) . '/cache/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>'); |
|
| 1945 | + if (!empty($cachedir) && is_writable($cachedir)) { |
|
| 1946 | + file_put_contents($cachedir . '/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>'); |
|
| 1947 | + } else { |
|
| 1948 | + file_put_contents(dirname(__FILE__) . '/cache/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>'); |
|
| 1949 | + } |
|
| 1843 | 1950 | |
| 1844 | 1951 | return true; |
| 1845 | 1952 | } |
@@ -1856,9 +1963,9 @@ discard block |
||
| 1856 | 1963 | SecFilterScanPOST Off |
| 1857 | 1964 | </IfModule>'; |
| 1858 | 1965 | |
| 1859 | - if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules())) |
|
| 1860 | - return true; |
|
| 1861 | - elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess')) |
|
| 1966 | + if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules())) { |
|
| 1967 | + return true; |
|
| 1968 | + } elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess')) |
|
| 1862 | 1969 | { |
| 1863 | 1970 | $current_htaccess = implode('', file(dirname(__FILE__) . '/.htaccess')); |
| 1864 | 1971 | |
@@ -1870,29 +1977,28 @@ discard block |
||
| 1870 | 1977 | fwrite($ht_handle, $htaccess_addition); |
| 1871 | 1978 | fclose($ht_handle); |
| 1872 | 1979 | return true; |
| 1980 | + } else { |
|
| 1981 | + return false; |
|
| 1873 | 1982 | } |
| 1874 | - else |
|
| 1875 | - return false; |
|
| 1983 | + } else { |
|
| 1984 | + return true; |
|
| 1876 | 1985 | } |
| 1877 | - else |
|
| 1878 | - return true; |
|
| 1879 | - } |
|
| 1880 | - elseif (file_exists(dirname(__FILE__) . '/.htaccess')) |
|
| 1881 | - return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false; |
|
| 1882 | - elseif (is_writable(dirname(__FILE__))) |
|
| 1986 | + } elseif (file_exists(dirname(__FILE__) . '/.htaccess')) { |
|
| 1987 | + return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false; |
|
| 1988 | + } elseif (is_writable(dirname(__FILE__))) |
|
| 1883 | 1989 | { |
| 1884 | 1990 | if ($ht_handle = fopen(dirname(__FILE__) . '/.htaccess', 'w')) |
| 1885 | 1991 | { |
| 1886 | 1992 | fwrite($ht_handle, $htaccess_addition); |
| 1887 | 1993 | fclose($ht_handle); |
| 1888 | 1994 | return true; |
| 1995 | + } else { |
|
| 1996 | + return false; |
|
| 1889 | 1997 | } |
| 1890 | - else |
|
| 1998 | + } else { |
|
| 1891 | 1999 | return false; |
| 1892 | 2000 | } |
| 1893 | - else |
|
| 1894 | - return false; |
|
| 1895 | -} |
|
| 2001 | + } |
|
| 1896 | 2002 | |
| 1897 | 2003 | function template_install_above() |
| 1898 | 2004 | { |
@@ -1931,9 +2037,10 @@ discard block |
||
| 1931 | 2037 | <label for="installer_language">', $txt['installer_language'], ':</label> |
| 1932 | 2038 | <select id="installer_language" name="lang_file" onchange="location.href = \'', $installurl, '?lang_file=\' + this.options[this.selectedIndex].value;">'; |
| 1933 | 2039 | |
| 1934 | - foreach ($incontext['detected_languages'] as $lang => $name) |
|
| 1935 | - echo ' |
|
| 2040 | + foreach ($incontext['detected_languages'] as $lang => $name) { |
|
| 2041 | + echo ' |
|
| 1936 | 2042 | <option', isset($_SESSION['installer_temp_lang']) && $_SESSION['installer_temp_lang'] == $lang ? ' selected' : '', ' value="', $lang, '">', $name, '</option>'; |
| 2043 | + } |
|
| 1937 | 2044 | |
| 1938 | 2045 | echo ' |
| 1939 | 2046 | </select> |
@@ -1953,9 +2060,10 @@ discard block |
||
| 1953 | 2060 | <h2>', $txt['upgrade_progress'], '</h2> |
| 1954 | 2061 | <ul>'; |
| 1955 | 2062 | |
| 1956 | - foreach ($incontext['steps'] as $num => $step) |
|
| 1957 | - echo ' |
|
| 2063 | + foreach ($incontext['steps'] as $num => $step) { |
|
| 2064 | + echo ' |
|
| 1958 | 2065 | <li class="', $num < $incontext['current_step'] ? 'stepdone' : ($num == $incontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>'; |
| 2066 | + } |
|
| 1959 | 2067 | |
| 1960 | 2068 | echo ' |
| 1961 | 2069 | </ul> |
@@ -1981,20 +2089,23 @@ discard block |
||
| 1981 | 2089 | echo ' |
| 1982 | 2090 | <div class="floatright">'; |
| 1983 | 2091 | |
| 1984 | - if (!empty($incontext['continue'])) |
|
| 1985 | - echo ' |
|
| 2092 | + if (!empty($incontext['continue'])) { |
|
| 2093 | + echo ' |
|
| 1986 | 2094 | <input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '" onclick="return submitThisOnce(this);" class="button">'; |
| 1987 | - if (!empty($incontext['skip'])) |
|
| 1988 | - echo ' |
|
| 2095 | + } |
|
| 2096 | + if (!empty($incontext['skip'])) { |
|
| 2097 | + echo ' |
|
| 1989 | 2098 | <input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="return submitThisOnce(this);" class="button">'; |
| 2099 | + } |
|
| 1990 | 2100 | echo ' |
| 1991 | 2101 | </div>'; |
| 1992 | 2102 | } |
| 1993 | 2103 | |
| 1994 | 2104 | // Show the closing form tag and other data only if not in the last step |
| 1995 | - if (count($incontext['steps']) - 1 !== (int) $incontext['current_step']) |
|
| 1996 | - echo ' |
|
| 2105 | + if (count($incontext['steps']) - 1 !== (int) $incontext['current_step']) { |
|
| 2106 | + echo ' |
|
| 1997 | 2107 | </form>'; |
| 2108 | + } |
|
| 1998 | 2109 | |
| 1999 | 2110 | echo ' |
| 2000 | 2111 | </div><!-- .panel --> |
@@ -2027,13 +2138,15 @@ discard block |
||
| 2027 | 2138 | </div>'; |
| 2028 | 2139 | |
| 2029 | 2140 | // Show the warnings, or not. |
| 2030 | - if (template_warning_divs()) |
|
| 2031 | - echo ' |
|
| 2141 | + if (template_warning_divs()) { |
|
| 2142 | + echo ' |
|
| 2032 | 2143 | <h3>', $txt['install_all_lovely'], '</h3>'; |
| 2144 | + } |
|
| 2033 | 2145 | |
| 2034 | 2146 | // Say we want the continue button! |
| 2035 | - if (empty($incontext['error'])) |
|
| 2036 | - $incontext['continue'] = 1; |
|
| 2147 | + if (empty($incontext['error'])) { |
|
| 2148 | + $incontext['continue'] = 1; |
|
| 2149 | + } |
|
| 2037 | 2150 | |
| 2038 | 2151 | // For the latest version stuff. |
| 2039 | 2152 | echo ' |
@@ -2067,19 +2180,21 @@ discard block |
||
| 2067 | 2180 | global $txt, $incontext; |
| 2068 | 2181 | |
| 2069 | 2182 | // Errors are very serious.. |
| 2070 | - if (!empty($incontext['error'])) |
|
| 2071 | - echo ' |
|
| 2183 | + if (!empty($incontext['error'])) { |
|
| 2184 | + echo ' |
|
| 2072 | 2185 | <div class="errorbox"> |
| 2073 | 2186 | <h3>', $txt['upgrade_critical_error'], '</h3> |
| 2074 | 2187 | ', $incontext['error'], ' |
| 2075 | 2188 | </div>'; |
| 2189 | + } |
|
| 2076 | 2190 | // A warning message? |
| 2077 | - elseif (!empty($incontext['warning'])) |
|
| 2078 | - echo ' |
|
| 2191 | + elseif (!empty($incontext['warning'])) { |
|
| 2192 | + echo ' |
|
| 2079 | 2193 | <div class="errorbox"> |
| 2080 | 2194 | <h3>', $txt['upgrade_warning'], '</h3> |
| 2081 | 2195 | ', $incontext['warning'], ' |
| 2082 | 2196 | </div>'; |
| 2197 | + } |
|
| 2083 | 2198 | |
| 2084 | 2199 | return empty($incontext['error']) && empty($incontext['warning']); |
| 2085 | 2200 | } |
@@ -2095,26 +2210,29 @@ discard block |
||
| 2095 | 2210 | <li>', $incontext['failed_files']), '</li> |
| 2096 | 2211 | </ul>'; |
| 2097 | 2212 | |
| 2098 | - if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux') |
|
| 2099 | - echo ' |
|
| 2213 | + if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux') { |
|
| 2214 | + echo ' |
|
| 2100 | 2215 | <hr> |
| 2101 | 2216 | <p>', $txt['chmod_linux_info'], '</p> |
| 2102 | 2217 | <samp># chmod a+w ', implode(' ' . $incontext['detected_path'] . '/', $incontext['failed_files']), '</samp>'; |
| 2218 | + } |
|
| 2103 | 2219 | |
| 2104 | 2220 | // This is serious! |
| 2105 | - if (!template_warning_divs()) |
|
| 2106 | - return; |
|
| 2221 | + if (!template_warning_divs()) { |
|
| 2222 | + return; |
|
| 2223 | + } |
|
| 2107 | 2224 | |
| 2108 | 2225 | echo ' |
| 2109 | 2226 | <hr> |
| 2110 | 2227 | <p>', $txt['ftp_setup_info'], '</p>'; |
| 2111 | 2228 | |
| 2112 | - if (!empty($incontext['ftp_errors'])) |
|
| 2113 | - echo ' |
|
| 2229 | + if (!empty($incontext['ftp_errors'])) { |
|
| 2230 | + echo ' |
|
| 2114 | 2231 | <div class="error_message"> |
| 2115 | 2232 | ', $txt['error_ftp_no_connect'], '<br><br> |
| 2116 | 2233 | <code>', implode('<br>', $incontext['ftp_errors']), '</code> |
| 2117 | 2234 | </div>'; |
| 2235 | + } |
|
| 2118 | 2236 | |
| 2119 | 2237 | echo ' |
| 2120 | 2238 | <form action="', $incontext['form_url'], '" method="post"> |
@@ -2183,16 +2301,16 @@ discard block |
||
| 2183 | 2301 | <dd> |
| 2184 | 2302 | <select name="db_type" id="db_type_input" onchange="toggleDBInput();">'; |
| 2185 | 2303 | |
| 2186 | - foreach ($incontext['supported_databases'] as $key => $db) |
|
| 2187 | - echo ' |
|
| 2304 | + foreach ($incontext['supported_databases'] as $key => $db) { |
|
| 2305 | + echo ' |
|
| 2188 | 2306 | <option value="', $key, '"', isset($_POST['db_type']) && $_POST['db_type'] == $key ? ' selected' : '', '>', $db['name'], '</option>'; |
| 2307 | + } |
|
| 2189 | 2308 | |
| 2190 | 2309 | echo ' |
| 2191 | 2310 | </select> |
| 2192 | 2311 | <div class="smalltext">', $txt['db_settings_type_info'], '</div> |
| 2193 | 2312 | </dd>'; |
| 2194 | - } |
|
| 2195 | - else |
|
| 2313 | + } else |
|
| 2196 | 2314 | { |
| 2197 | 2315 | echo ' |
| 2198 | 2316 | <dd> |
@@ -2360,9 +2478,10 @@ discard block |
||
| 2360 | 2478 | <div class="red">', $txt['error_db_queries'], '</div> |
| 2361 | 2479 | <ul>'; |
| 2362 | 2480 | |
| 2363 | - foreach ($incontext['failures'] as $line => $fail) |
|
| 2364 | - echo ' |
|
| 2481 | + foreach ($incontext['failures'] as $line => $fail) { |
|
| 2482 | + echo ' |
|
| 2365 | 2483 | <li><strong>', $txt['error_db_queries_line'], $line + 1, ':</strong> ', nl2br(htmlspecialchars($fail)), '</li>'; |
| 2484 | + } |
|
| 2366 | 2485 | |
| 2367 | 2486 | echo ' |
| 2368 | 2487 | </ul>'; |
@@ -2427,15 +2546,16 @@ discard block |
||
| 2427 | 2546 | </dd> |
| 2428 | 2547 | </dl>'; |
| 2429 | 2548 | |
| 2430 | - if ($incontext['require_db_confirm']) |
|
| 2431 | - echo ' |
|
| 2549 | + if ($incontext['require_db_confirm']) { |
|
| 2550 | + echo ' |
|
| 2432 | 2551 | <h2>', $txt['user_settings_database'], '</h2> |
| 2433 | 2552 | <p>', $txt['user_settings_database_info'], '</p> |
| 2434 | 2553 | |
| 2435 | 2554 | <div class="lefttext"> |
| 2436 | 2555 | <input type="password" name="password3" size="30"> |
| 2437 | 2556 | </div>'; |
| 2438 | -} |
|
| 2557 | + } |
|
| 2558 | + } |
|
| 2439 | 2559 | |
| 2440 | 2560 | // Tell them it's done, and to delete. |
| 2441 | 2561 | function template_delete_install() |
@@ -2448,13 +2568,14 @@ discard block |
||
| 2448 | 2568 | template_warning_divs(); |
| 2449 | 2569 | |
| 2450 | 2570 | // Install directory still writable? |
| 2451 | - if ($incontext['dir_still_writable']) |
|
| 2452 | - echo ' |
|
| 2571 | + if ($incontext['dir_still_writable']) { |
|
| 2572 | + echo ' |
|
| 2453 | 2573 | <p><em>', $txt['still_writable'], '</em></p>'; |
| 2574 | + } |
|
| 2454 | 2575 | |
| 2455 | 2576 | // Don't show the box if it's like 99% sure it won't work :P. |
| 2456 | - if ($incontext['probably_delete_install']) |
|
| 2457 | - echo ' |
|
| 2577 | + if ($incontext['probably_delete_install']) { |
|
| 2578 | + echo ' |
|
| 2458 | 2579 | <label> |
| 2459 | 2580 | <input type="checkbox" id="delete_self" onclick="doTheDelete();"> |
| 2460 | 2581 | <strong>', $txt['delete_installer'], !isset($_SESSION['installer_temp_ftp']) ? ' ' . $txt['delete_installer_maybe'] : '', '</strong> |
@@ -2470,6 +2591,7 @@ discard block |
||
| 2470 | 2591 | theCheck.disabled = true; |
| 2471 | 2592 | } |
| 2472 | 2593 | </script>'; |
| 2594 | + } |
|
| 2473 | 2595 | |
| 2474 | 2596 | echo ' |
| 2475 | 2597 | <p>', sprintf($txt['go_to_your_forum'], $boardurl . '/index.php'), '</p> |
@@ -75,14 +75,16 @@ 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 | |
| 83 | 84 | // For php below 7 |
| 84 | -if (!function_exists('random_int')) |
|
| 85 | +if (!function_exists('random_int')) { |
|
| 85 | 86 | require_once ('Sources/random_compat/random_int.php'); |
| 87 | +} |
|
| 86 | 88 | |
| 87 | 89 | global $txt; |
| 88 | 90 | |
@@ -111,11 +113,14 @@ discard block |
||
| 111 | 113 | ini_set('default_socket_timeout', 900); |
| 112 | 114 | } |
| 113 | 115 | // Clean the upgrade path if this is from the client. |
| 114 | -if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) |
|
| 115 | - for ($i = 1; $i < $_SERVER['argc']; $i++) |
|
| 116 | +if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) { |
|
| 117 | + for ($i = 1; |
|
| 118 | +} |
|
| 119 | +$i < $_SERVER['argc']; $i++) |
|
| 116 | 120 | { |
| 117 | - if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0) |
|
| 118 | - $upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1]; |
|
| 121 | + if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0) { |
|
| 122 | + $upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1]; |
|
| 123 | + } |
|
| 119 | 124 | } |
| 120 | 125 | |
| 121 | 126 | // Are we from the client? |
@@ -123,16 +128,17 @@ discard block |
||
| 123 | 128 | { |
| 124 | 129 | $command_line = true; |
| 125 | 130 | $disable_security = true; |
| 126 | -} |
|
| 127 | -else |
|
| 131 | +} else { |
|
| 128 | 132 | $command_line = false; |
| 133 | +} |
|
| 129 | 134 | |
| 130 | 135 | // Load this now just because we can. |
| 131 | 136 | require_once($upgrade_path . '/Settings.php'); |
| 132 | 137 | |
| 133 | 138 | // We don't use "-utf8" anymore... Tweak the entry that may have been loaded by Settings.php |
| 134 | -if (isset($language)) |
|
| 139 | +if (isset($language)) { |
|
| 135 | 140 | $language = str_ireplace('-utf8', '', $language); |
| 141 | +} |
|
| 136 | 142 | |
| 137 | 143 | // Are we logged in? |
| 138 | 144 | if (isset($upgradeData)) |
@@ -140,10 +146,12 @@ discard block |
||
| 140 | 146 | $upcontext['user'] = json_decode(base64_decode($upgradeData), true); |
| 141 | 147 | |
| 142 | 148 | // Check for sensible values. |
| 143 | - if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400) |
|
| 144 | - $upcontext['user']['started'] = time(); |
|
| 145 | - if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400) |
|
| 146 | - $upcontext['user']['updated'] = 0; |
|
| 149 | + if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400) { |
|
| 150 | + $upcontext['user']['started'] = time(); |
|
| 151 | + } |
|
| 152 | + if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400) { |
|
| 153 | + $upcontext['user']['updated'] = 0; |
|
| 154 | + } |
|
| 147 | 155 | |
| 148 | 156 | $upcontext['started'] = $upcontext['user']['started']; |
| 149 | 157 | $upcontext['updated'] = $upcontext['user']['updated']; |
@@ -208,8 +216,9 @@ discard block |
||
| 208 | 216 | 'db_error_skip' => true, |
| 209 | 217 | ) |
| 210 | 218 | ); |
| 211 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 212 | - $modSettings[$row['variable']] = $row['value']; |
|
| 219 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 220 | + $modSettings[$row['variable']] = $row['value']; |
|
| 221 | + } |
|
| 213 | 222 | $smcFunc['db_free_result']($request); |
| 214 | 223 | } |
| 215 | 224 | |
@@ -219,14 +228,17 @@ discard block |
||
| 219 | 228 | $modSettings['theme_url'] = 'Themes/default'; |
| 220 | 229 | $modSettings['images_url'] = 'Themes/default/images'; |
| 221 | 230 | } |
| 222 | -if (!isset($settings['default_theme_url'])) |
|
| 231 | +if (!isset($settings['default_theme_url'])) { |
|
| 223 | 232 | $settings['default_theme_url'] = $modSettings['theme_url']; |
| 224 | -if (!isset($settings['default_theme_dir'])) |
|
| 233 | +} |
|
| 234 | +if (!isset($settings['default_theme_dir'])) { |
|
| 225 | 235 | $settings['default_theme_dir'] = $modSettings['theme_dir']; |
| 236 | +} |
|
| 226 | 237 | |
| 227 | 238 | // This is needed in case someone invokes the upgrader using https when upgrading an http forum |
| 228 | -if (httpsOn()) |
|
| 239 | +if (httpsOn()) { |
|
| 229 | 240 | $settings['default_theme_url'] = strtr($settings['default_theme_url'], array('http://' => 'https://')); |
| 241 | +} |
|
| 230 | 242 | |
| 231 | 243 | $upcontext['is_large_forum'] = (empty($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC1') && !empty($modSettings['totalMessages']) && $modSettings['totalMessages'] > 75000; |
| 232 | 244 | // Default title... |
@@ -244,13 +256,15 @@ discard block |
||
| 244 | 256 | $support_js = $upcontext['upgrade_status']['js']; |
| 245 | 257 | |
| 246 | 258 | // Only set this if the upgrader status says so. |
| 247 | - if (empty($is_debug)) |
|
| 248 | - $is_debug = $upcontext['upgrade_status']['debug']; |
|
| 259 | + if (empty($is_debug)) { |
|
| 260 | + $is_debug = $upcontext['upgrade_status']['debug']; |
|
| 261 | + } |
|
| 249 | 262 | |
| 250 | 263 | // Load the language. |
| 251 | - if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) |
|
| 252 | - require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'); |
|
| 253 | -} |
|
| 264 | + if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) { |
|
| 265 | + require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'); |
|
| 266 | + } |
|
| 267 | + } |
|
| 254 | 268 | // Set the defaults. |
| 255 | 269 | else |
| 256 | 270 | { |
@@ -268,15 +282,18 @@ discard block |
||
| 268 | 282 | } |
| 269 | 283 | |
| 270 | 284 | // If this isn't the first stage see whether they are logging in and resuming. |
| 271 | -if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step'])) |
|
| 285 | +if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step'])) { |
|
| 272 | 286 | checkLogin(); |
| 287 | +} |
|
| 273 | 288 | |
| 274 | -if ($command_line) |
|
| 289 | +if ($command_line) { |
|
| 275 | 290 | cmdStep0(); |
| 291 | +} |
|
| 276 | 292 | |
| 277 | 293 | // Don't error if we're using xml. |
| 278 | -if (isset($_GET['xml'])) |
|
| 294 | +if (isset($_GET['xml'])) { |
|
| 279 | 295 | $upcontext['return_error'] = true; |
| 296 | +} |
|
| 280 | 297 | |
| 281 | 298 | // Loop through all the steps doing each one as required. |
| 282 | 299 | $upcontext['overall_percent'] = 0; |
@@ -297,9 +314,9 @@ discard block |
||
| 297 | 314 | } |
| 298 | 315 | |
| 299 | 316 | // Call the step and if it returns false that means pause! |
| 300 | - if (function_exists($step[2]) && $step[2]() === false) |
|
| 301 | - break; |
|
| 302 | - elseif (function_exists($step[2])) { |
|
| 317 | + if (function_exists($step[2]) && $step[2]() === false) { |
|
| 318 | + break; |
|
| 319 | + } elseif (function_exists($step[2])) { |
|
| 303 | 320 | //Start each new step with this unset, so the 'normal' template is called first |
| 304 | 321 | unset($_GET['xml']); |
| 305 | 322 | //Clear out warnings at the start of each step |
@@ -345,17 +362,18 @@ discard block |
||
| 345 | 362 | // This should not happen my dear... HELP ME DEVELOPERS!! |
| 346 | 363 | if (!empty($command_line)) |
| 347 | 364 | { |
| 348 | - if (function_exists('debug_print_backtrace')) |
|
| 349 | - debug_print_backtrace(); |
|
| 365 | + if (function_exists('debug_print_backtrace')) { |
|
| 366 | + debug_print_backtrace(); |
|
| 367 | + } |
|
| 350 | 368 | |
| 351 | 369 | 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.'; |
| 352 | 370 | flush(); |
| 353 | 371 | die(); |
| 354 | 372 | } |
| 355 | 373 | |
| 356 | - if (!isset($_GET['xml'])) |
|
| 357 | - template_upgrade_above(); |
|
| 358 | - else |
|
| 374 | + if (!isset($_GET['xml'])) { |
|
| 375 | + template_upgrade_above(); |
|
| 376 | + } else |
|
| 359 | 377 | { |
| 360 | 378 | header('content-type: text/xml; charset=UTF-8'); |
| 361 | 379 | // Sadly we need to retain the $_GET data thanks to the old upgrade scripts. |
@@ -377,25 +395,29 @@ discard block |
||
| 377 | 395 | $upcontext['form_url'] = $upgradeurl . '?step=' . $upcontext['current_step'] . '&substep=' . $_GET['substep'] . '&data=' . base64_encode(json_encode($upcontext['upgrade_status'])); |
| 378 | 396 | |
| 379 | 397 | // Custom stuff to pass back? |
| 380 | - if (!empty($upcontext['query_string'])) |
|
| 381 | - $upcontext['form_url'] .= $upcontext['query_string']; |
|
| 398 | + if (!empty($upcontext['query_string'])) { |
|
| 399 | + $upcontext['form_url'] .= $upcontext['query_string']; |
|
| 400 | + } |
|
| 382 | 401 | |
| 383 | 402 | // Call the appropriate subtemplate |
| 384 | - if (is_callable('template_' . $upcontext['sub_template'])) |
|
| 385 | - call_user_func('template_' . $upcontext['sub_template']); |
|
| 386 | - else |
|
| 387 | - die('Upgrade aborted! Invalid template: template_' . $upcontext['sub_template']); |
|
| 403 | + if (is_callable('template_' . $upcontext['sub_template'])) { |
|
| 404 | + call_user_func('template_' . $upcontext['sub_template']); |
|
| 405 | + } else { |
|
| 406 | + die('Upgrade aborted! Invalid template: template_' . $upcontext['sub_template']); |
|
| 407 | + } |
|
| 388 | 408 | } |
| 389 | 409 | |
| 390 | 410 | // Was there an error? |
| 391 | - if (!empty($upcontext['forced_error_message'])) |
|
| 392 | - echo $upcontext['forced_error_message']; |
|
| 411 | + if (!empty($upcontext['forced_error_message'])) { |
|
| 412 | + echo $upcontext['forced_error_message']; |
|
| 413 | + } |
|
| 393 | 414 | |
| 394 | 415 | // Show the footer. |
| 395 | - if (!isset($_GET['xml'])) |
|
| 396 | - template_upgrade_below(); |
|
| 397 | - else |
|
| 398 | - template_xml_below(); |
|
| 416 | + if (!isset($_GET['xml'])) { |
|
| 417 | + template_upgrade_below(); |
|
| 418 | + } else { |
|
| 419 | + template_xml_below(); |
|
| 420 | + } |
|
| 399 | 421 | } |
| 400 | 422 | |
| 401 | 423 | // Show the upgrade time for CLI when we are completely done, if in debug mode. |
@@ -407,12 +429,13 @@ discard block |
||
| 407 | 429 | $seconds = intval($active % 60); |
| 408 | 430 | |
| 409 | 431 | $totalTime = ''; |
| 410 | - if ($hours > 0) |
|
| 411 | - echo "\n" . '', sprintf($txt['upgrade_completed_time_hms'], $hours, $minutes, $seconds), '' . "\n"; |
|
| 412 | - elseif ($minutes > 0) |
|
| 413 | - echo "\n" . '', sprintf($txt['upgrade_completed_time_ms'], $minutes, $seconds), '' . "\n"; |
|
| 414 | - elseif ($seconds > 0) |
|
| 415 | - echo "\n" . '', sprintf($txt['upgrade_completed_time_s'], $seconds), '' . "\n"; |
|
| 432 | + if ($hours > 0) { |
|
| 433 | + echo "\n" . '', sprintf($txt['upgrade_completed_time_hms'], $hours, $minutes, $seconds), '' . "\n"; |
|
| 434 | + } elseif ($minutes > 0) { |
|
| 435 | + echo "\n" . '', sprintf($txt['upgrade_completed_time_ms'], $minutes, $seconds), '' . "\n"; |
|
| 436 | + } elseif ($seconds > 0) { |
|
| 437 | + echo "\n" . '', sprintf($txt['upgrade_completed_time_s'], $seconds), '' . "\n"; |
|
| 438 | + } |
|
| 416 | 439 | } |
| 417 | 440 | |
| 418 | 441 | // Bang - gone! |
@@ -433,8 +456,9 @@ discard block |
||
| 433 | 456 | $dir = dir(dirname(__FILE__) . '/Themes/default/languages'); |
| 434 | 457 | while ($entry = $dir->read()) |
| 435 | 458 | { |
| 436 | - if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') |
|
| 437 | - $incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12)); |
|
| 459 | + if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') { |
|
| 460 | + $incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12)); |
|
| 461 | + } |
|
| 438 | 462 | } |
| 439 | 463 | $dir->close(); |
| 440 | 464 | } |
@@ -478,10 +502,11 @@ discard block |
||
| 478 | 502 | } |
| 479 | 503 | |
| 480 | 504 | // Override the language file? |
| 481 | - if (isset($_GET['lang_file'])) |
|
| 482 | - $_SESSION['installer_temp_lang'] = $_GET['lang_file']; |
|
| 483 | - elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) |
|
| 484 | - $_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file']; |
|
| 505 | + if (isset($_GET['lang_file'])) { |
|
| 506 | + $_SESSION['installer_temp_lang'] = $_GET['lang_file']; |
|
| 507 | + } elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) { |
|
| 508 | + $_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file']; |
|
| 509 | + } |
|
| 485 | 510 | |
| 486 | 511 | // Make sure it exists, if it doesn't reset it. |
| 487 | 512 | 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'])) |
@@ -490,12 +515,14 @@ discard block |
||
| 490 | 515 | list ($_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']); |
| 491 | 516 | |
| 492 | 517 | // If we have english and some other language, use the other language. We Americans hate english :P. |
| 493 | - if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) |
|
| 494 | - list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']); |
|
| 518 | + if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) { |
|
| 519 | + list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']); |
|
| 520 | + } |
|
| 495 | 521 | |
| 496 | 522 | // For backup we load the english at first -> second language overwrite the english one |
| 497 | - if (count($incontext['detected_languages']) > 1) |
|
| 498 | - require_once(dirname(__FILE__) . '/Themes/default/languages/Install.english.php'); |
|
| 523 | + if (count($incontext['detected_languages']) > 1) { |
|
| 524 | + require_once(dirname(__FILE__) . '/Themes/default/languages/Install.english.php'); |
|
| 525 | + } |
|
| 499 | 526 | } |
| 500 | 527 | |
| 501 | 528 | // And now include the actual language file itself. |
@@ -503,11 +530,12 @@ discard block |
||
| 503 | 530 | |
| 504 | 531 | // Which language did we load? Assume that he likes his language. |
| 505 | 532 | preg_match('~^Install\.(.+[^-utf8])\.php$~', $_SESSION['installer_temp_lang'], $matches); |
| 506 | - if (empty($matches[1])) |
|
| 507 | - $matches = [ |
|
| 533 | + if (empty($matches[1])) { |
|
| 534 | + $matches = [ |
|
| 508 | 535 | 0 => 'nothing', |
| 509 | 536 | 1 => 'english', |
| 510 | 537 | ]; |
| 538 | + } |
|
| 511 | 539 | $user_info['language'] = $matches[1]; |
| 512 | 540 | } |
| 513 | 541 | |
@@ -517,8 +545,9 @@ discard block |
||
| 517 | 545 | global $upgradeurl, $upcontext, $command_line; |
| 518 | 546 | |
| 519 | 547 | // Command line users can't be redirected. |
| 520 | - if ($command_line) |
|
| 521 | - upgradeExit(true); |
|
| 548 | + if ($command_line) { |
|
| 549 | + upgradeExit(true); |
|
| 550 | + } |
|
| 522 | 551 | |
| 523 | 552 | // Are we providing the core info? |
| 524 | 553 | if ($addForm) |
@@ -544,12 +573,14 @@ discard block |
||
| 544 | 573 | define('SMF', 1); |
| 545 | 574 | |
| 546 | 575 | // Start the session. |
| 547 | - if (@ini_get('session.save_handler') == 'user') |
|
| 548 | - @ini_set('session.save_handler', 'files'); |
|
| 576 | + if (@ini_get('session.save_handler') == 'user') { |
|
| 577 | + @ini_set('session.save_handler', 'files'); |
|
| 578 | + } |
|
| 549 | 579 | @session_start(); |
| 550 | 580 | |
| 551 | - if (empty($smcFunc)) |
|
| 552 | - $smcFunc = array(); |
|
| 581 | + if (empty($smcFunc)) { |
|
| 582 | + $smcFunc = array(); |
|
| 583 | + } |
|
| 553 | 584 | |
| 554 | 585 | // We need this for authentication and some upgrade code |
| 555 | 586 | require_once($sourcedir . '/Subs-Auth.php'); |
@@ -580,30 +611,34 @@ discard block |
||
| 580 | 611 | { |
| 581 | 612 | $options = array('non_fatal' => true); |
| 582 | 613 | // Add in the port if needed |
| 583 | - if (!empty($db_port)) |
|
| 584 | - $options['port'] = $db_port; |
|
| 614 | + if (!empty($db_port)) { |
|
| 615 | + $options['port'] = $db_port; |
|
| 616 | + } |
|
| 585 | 617 | |
| 586 | - if (!empty($db_mb4)) |
|
| 587 | - $options['db_mb4'] = $db_mb4; |
|
| 618 | + if (!empty($db_mb4)) { |
|
| 619 | + $options['db_mb4'] = $db_mb4; |
|
| 620 | + } |
|
| 588 | 621 | |
| 589 | 622 | $db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $options); |
| 590 | - } |
|
| 591 | - else |
|
| 592 | - // If we've returned here, ping/reconnect to be safe |
|
| 623 | + } else { |
|
| 624 | + // If we've returned here, ping/reconnect to be safe |
|
| 593 | 625 | $smcFunc['db_ping']($db_connection); |
| 626 | + } |
|
| 594 | 627 | |
| 595 | 628 | // Oh dear god!! |
| 596 | - if ($db_connection === null) |
|
| 597 | - die('Unable to connect to database - please check username and password are correct in Settings.php'); |
|
| 629 | + if ($db_connection === null) { |
|
| 630 | + die('Unable to connect to database - please check username and password are correct in Settings.php'); |
|
| 631 | + } |
|
| 598 | 632 | |
| 599 | - if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) |
|
| 600 | - $smcFunc['db_query']('', ' |
|
| 633 | + if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) { |
|
| 634 | + $smcFunc['db_query']('', ' |
|
| 601 | 635 | SET NAMES {string:db_character_set}', |
| 602 | 636 | array( |
| 603 | 637 | 'db_error_skip' => true, |
| 604 | 638 | 'db_character_set' => $db_character_set, |
| 605 | 639 | ) |
| 606 | 640 | ); |
| 641 | + } |
|
| 607 | 642 | |
| 608 | 643 | // Load the modSettings data... |
| 609 | 644 | $request = $smcFunc['db_query']('', ' |
@@ -614,11 +649,11 @@ discard block |
||
| 614 | 649 | ) |
| 615 | 650 | ); |
| 616 | 651 | $modSettings = array(); |
| 617 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 618 | - $modSettings[$row['variable']] = $row['value']; |
|
| 652 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 653 | + $modSettings[$row['variable']] = $row['value']; |
|
| 654 | + } |
|
| 619 | 655 | $smcFunc['db_free_result']($request); |
| 620 | - } |
|
| 621 | - else |
|
| 656 | + } else |
|
| 622 | 657 | { |
| 623 | 658 | 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.'); |
| 624 | 659 | } |
@@ -632,9 +667,10 @@ discard block |
||
| 632 | 667 | cleanRequest(); |
| 633 | 668 | } |
| 634 | 669 | |
| 635 | - if (!isset($_GET['substep'])) |
|
| 636 | - $_GET['substep'] = 0; |
|
| 637 | -} |
|
| 670 | + if (!isset($_GET['substep'])) { |
|
| 671 | + $_GET['substep'] = 0; |
|
| 672 | + } |
|
| 673 | + } |
|
| 638 | 674 | |
| 639 | 675 | function initialize_inputs() |
| 640 | 676 | { |
@@ -664,8 +700,9 @@ discard block |
||
| 664 | 700 | $dh = opendir(dirname(__FILE__)); |
| 665 | 701 | while ($file = readdir($dh)) |
| 666 | 702 | { |
| 667 | - if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) |
|
| 668 | - @unlink(dirname(__FILE__) . '/' . $file); |
|
| 703 | + if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) { |
|
| 704 | + @unlink(dirname(__FILE__) . '/' . $file); |
|
| 705 | + } |
|
| 669 | 706 | } |
| 670 | 707 | closedir($dh); |
| 671 | 708 | |
@@ -694,8 +731,9 @@ discard block |
||
| 694 | 731 | $temp = 'upgrade_php?step'; |
| 695 | 732 | while (strlen($temp) > 4) |
| 696 | 733 | { |
| 697 | - if (isset($_GET[$temp])) |
|
| 698 | - unset($_GET[$temp]); |
|
| 734 | + if (isset($_GET[$temp])) { |
|
| 735 | + unset($_GET[$temp]); |
|
| 736 | + } |
|
| 699 | 737 | $temp = substr($temp, 1); |
| 700 | 738 | } |
| 701 | 739 | |
@@ -722,32 +760,39 @@ discard block |
||
| 722 | 760 | && @file_exists(dirname(__FILE__) . '/upgrade_2-1_' . $db_type . '.sql'); |
| 723 | 761 | |
| 724 | 762 | // Need legacy scripts? |
| 725 | - if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1) |
|
| 726 | - $check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql'); |
|
| 727 | - if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) |
|
| 728 | - $check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql'); |
|
| 729 | - if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) |
|
| 730 | - $check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql'); |
|
| 763 | + if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1) { |
|
| 764 | + $check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql'); |
|
| 765 | + } |
|
| 766 | + if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) { |
|
| 767 | + $check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql'); |
|
| 768 | + } |
|
| 769 | + if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) { |
|
| 770 | + $check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql'); |
|
| 771 | + } |
|
| 731 | 772 | |
| 732 | 773 | // We don't need "-utf8" files anymore... |
| 733 | 774 | $upcontext['language'] = str_ireplace('-utf8', '', $upcontext['language']); |
| 734 | 775 | |
| 735 | 776 | // This needs to exist! |
| 736 | - if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) |
|
| 737 | - 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>]'); |
|
| 738 | - else |
|
| 739 | - require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'); |
|
| 777 | + if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) { |
|
| 778 | + 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>]'); |
|
| 779 | + } else { |
|
| 780 | + require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'); |
|
| 781 | + } |
|
| 740 | 782 | |
| 741 | - if (!$check) |
|
| 742 | - // 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. |
|
| 783 | + if (!$check) { |
|
| 784 | + // 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. |
|
| 743 | 785 | 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.'); |
| 786 | + } |
|
| 744 | 787 | |
| 745 | 788 | // Do they meet the install requirements? |
| 746 | - if (!php_version_check()) |
|
| 747 | - 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.'); |
|
| 789 | + if (!php_version_check()) { |
|
| 790 | + 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.'); |
|
| 791 | + } |
|
| 748 | 792 | |
| 749 | - if (!db_version_check()) |
|
| 750 | - 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.'); |
|
| 793 | + if (!db_version_check()) { |
|
| 794 | + 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.'); |
|
| 795 | + } |
|
| 751 | 796 | |
| 752 | 797 | // Do some checks to make sure they have proper privileges |
| 753 | 798 | db_extend('packages'); |
@@ -762,14 +807,16 @@ discard block |
||
| 762 | 807 | $drop = $smcFunc['db_drop_table']('{db_prefix}priv_check'); |
| 763 | 808 | |
| 764 | 809 | // Sorry... we need CREATE, ALTER and DROP |
| 765 | - if (!$create || !$alter || !$drop) |
|
| 766 | - 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.'); |
|
| 810 | + if (!$create || !$alter || !$drop) { |
|
| 811 | + 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.'); |
|
| 812 | + } |
|
| 767 | 813 | |
| 768 | 814 | // Do a quick version spot check. |
| 769 | 815 | $temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096); |
| 770 | 816 | preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match); |
| 771 | - if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) |
|
| 772 | - 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.'); |
|
| 817 | + if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) { |
|
| 818 | + 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.'); |
|
| 819 | + } |
|
| 773 | 820 | |
| 774 | 821 | // What absolutely needs to be writable? |
| 775 | 822 | $writable_files = array( |
@@ -778,12 +825,13 @@ discard block |
||
| 778 | 825 | ); |
| 779 | 826 | |
| 780 | 827 | // Only check for minified writable files if we have it enabled or not set. |
| 781 | - if (!empty($modSettings['minimize_files']) || !isset($modSettings['minimize_files'])) |
|
| 782 | - $writable_files += array( |
|
| 828 | + if (!empty($modSettings['minimize_files']) || !isset($modSettings['minimize_files'])) { |
|
| 829 | + $writable_files += array( |
|
| 783 | 830 | $modSettings['theme_dir'] . '/css/minified.css', |
| 784 | 831 | $modSettings['theme_dir'] . '/scripts/minified.js', |
| 785 | 832 | $modSettings['theme_dir'] . '/scripts/minified_deferred.js', |
| 786 | 833 | ); |
| 834 | + } |
|
| 787 | 835 | |
| 788 | 836 | // Do we need to add this setting? |
| 789 | 837 | $need_settings_update = empty($modSettings['custom_avatar_dir']); |
@@ -795,12 +843,13 @@ discard block |
||
| 795 | 843 | quickFileWritable($custom_av_dir); |
| 796 | 844 | |
| 797 | 845 | // Are we good now? |
| 798 | - if (!is_writable($custom_av_dir)) |
|
| 799 | - 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)); |
|
| 800 | - elseif ($need_settings_update) |
|
| 846 | + if (!is_writable($custom_av_dir)) { |
|
| 847 | + 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)); |
|
| 848 | + } elseif ($need_settings_update) |
|
| 801 | 849 | { |
| 802 | - if (!function_exists('cache_put_data')) |
|
| 803 | - require_once($sourcedir . '/Load.php'); |
|
| 850 | + if (!function_exists('cache_put_data')) { |
|
| 851 | + require_once($sourcedir . '/Load.php'); |
|
| 852 | + } |
|
| 804 | 853 | |
| 805 | 854 | updateSettings(array('custom_avatar_dir' => $custom_av_dir)); |
| 806 | 855 | updateSettings(array('custom_avatar_url' => $custom_av_url)); |
@@ -810,29 +859,34 @@ discard block |
||
| 810 | 859 | |
| 811 | 860 | // Check the cache directory. |
| 812 | 861 | $cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir; |
| 813 | - if (!file_exists($cachedir_temp)) |
|
| 814 | - @mkdir($cachedir_temp); |
|
| 862 | + if (!file_exists($cachedir_temp)) { |
|
| 863 | + @mkdir($cachedir_temp); |
|
| 864 | + } |
|
| 815 | 865 | |
| 816 | - if (!file_exists($cachedir_temp)) |
|
| 817 | - 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.'); |
|
| 866 | + if (!file_exists($cachedir_temp)) { |
|
| 867 | + 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.'); |
|
| 868 | + } |
|
| 818 | 869 | |
| 819 | - if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) |
|
| 820 | - 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>.'); |
|
| 821 | - elseif (!isset($_GET['skiplang'])) |
|
| 870 | + if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) { |
|
| 871 | + 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>.'); |
|
| 872 | + } elseif (!isset($_GET['skiplang'])) |
|
| 822 | 873 | { |
| 823 | 874 | $temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096); |
| 824 | 875 | preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match); |
| 825 | 876 | |
| 826 | - if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) |
|
| 827 | - 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>]'); |
|
| 877 | + if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) { |
|
| 878 | + 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>]'); |
|
| 879 | + } |
|
| 828 | 880 | } |
| 829 | 881 | |
| 830 | - if (!makeFilesWritable($writable_files)) |
|
| 831 | - return false; |
|
| 882 | + if (!makeFilesWritable($writable_files)) { |
|
| 883 | + return false; |
|
| 884 | + } |
|
| 832 | 885 | |
| 833 | 886 | // Check agreement.txt. (it may not exist, in which case $boarddir must be writable.) |
| 834 | - if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) |
|
| 835 | - 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.'); |
|
| 887 | + if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) { |
|
| 888 | + 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.'); |
|
| 889 | + } |
|
| 836 | 890 | |
| 837 | 891 | // Upgrade the agreement. |
| 838 | 892 | elseif (isset($modSettings['agreement'])) |
@@ -843,8 +897,8 @@ discard block |
||
| 843 | 897 | } |
| 844 | 898 | |
| 845 | 899 | // We're going to check that their board dir setting is right in case they've been moving stuff around. |
| 846 | - if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) |
|
| 847 | - $upcontext['warning'] = ' |
|
| 900 | + if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) { |
|
| 901 | + $upcontext['warning'] = ' |
|
| 848 | 902 | '. sprintf($txt['upgrade_boarddir_settings'], $boarddir, dirname(__FILE__)) .'<br> |
| 849 | 903 | <ul> |
| 850 | 904 | <li>'. $txt['upgrade_boarddir'] .' ' . $boarddir . '</li> |
@@ -852,19 +906,23 @@ discard block |
||
| 852 | 906 | <li>'. $txt['upgrade_cachedir'] .' ' . $cachedir_temp . '</li> |
| 853 | 907 | </ul> |
| 854 | 908 | '. $txt['upgrade_incorrect_settings'] .''; |
| 909 | + } |
|
| 855 | 910 | |
| 856 | 911 | // Confirm mbstring is loaded... |
| 857 | - if (!extension_loaded('mbstring')) |
|
| 858 | - return throw_error($txt['install_no_mbstring']); |
|
| 912 | + if (!extension_loaded('mbstring')) { |
|
| 913 | + return throw_error($txt['install_no_mbstring']); |
|
| 914 | + } |
|
| 859 | 915 | |
| 860 | 916 | // Check for https stream support. |
| 861 | 917 | $supported_streams = stream_get_wrappers(); |
| 862 | - if (!in_array('https', $supported_streams)) |
|
| 863 | - $upcontext['custom_warning'] = $txt['install_no_https']; |
|
| 918 | + if (!in_array('https', $supported_streams)) { |
|
| 919 | + $upcontext['custom_warning'] = $txt['install_no_https']; |
|
| 920 | + } |
|
| 864 | 921 | |
| 865 | 922 | // Either we're logged in or we're going to present the login. |
| 866 | - if (checkLogin()) |
|
| 867 | - return true; |
|
| 923 | + if (checkLogin()) { |
|
| 924 | + return true; |
|
| 925 | + } |
|
| 868 | 926 | |
| 869 | 927 | $upcontext += createToken('login'); |
| 870 | 928 | |
@@ -878,15 +936,17 @@ discard block |
||
| 878 | 936 | global $smcFunc, $db_type, $support_js; |
| 879 | 937 | |
| 880 | 938 | // Don't bother if the security is disabled. |
| 881 | - if ($disable_security) |
|
| 882 | - return true; |
|
| 939 | + if ($disable_security) { |
|
| 940 | + return true; |
|
| 941 | + } |
|
| 883 | 942 | |
| 884 | 943 | // Are we trying to login? |
| 885 | 944 | if (isset($_POST['contbutt']) && (!empty($_POST['user']))) |
| 886 | 945 | { |
| 887 | 946 | // If we've disabled security pick a suitable name! |
| 888 | - if (empty($_POST['user'])) |
|
| 889 | - $_POST['user'] = 'Administrator'; |
|
| 947 | + if (empty($_POST['user'])) { |
|
| 948 | + $_POST['user'] = 'Administrator'; |
|
| 949 | + } |
|
| 890 | 950 | |
| 891 | 951 | // Before 2.0 these column names were different! |
| 892 | 952 | $oldDB = false; |
@@ -901,16 +961,17 @@ discard block |
||
| 901 | 961 | 'db_error_skip' => true, |
| 902 | 962 | ) |
| 903 | 963 | ); |
| 904 | - if ($smcFunc['db_num_rows']($request) != 0) |
|
| 905 | - $oldDB = true; |
|
| 964 | + if ($smcFunc['db_num_rows']($request) != 0) { |
|
| 965 | + $oldDB = true; |
|
| 966 | + } |
|
| 906 | 967 | $smcFunc['db_free_result']($request); |
| 907 | 968 | } |
| 908 | 969 | |
| 909 | 970 | // Get what we believe to be their details. |
| 910 | 971 | if (!$disable_security) |
| 911 | 972 | { |
| 912 | - if ($oldDB) |
|
| 913 | - $request = $smcFunc['db_query']('', ' |
|
| 973 | + if ($oldDB) { |
|
| 974 | + $request = $smcFunc['db_query']('', ' |
|
| 914 | 975 | SELECT id_member, memberName AS member_name, passwd, id_group, |
| 915 | 976 | additionalGroups AS additional_groups, lngfile |
| 916 | 977 | FROM {db_prefix}members |
@@ -920,8 +981,8 @@ discard block |
||
| 920 | 981 | 'db_error_skip' => true, |
| 921 | 982 | ) |
| 922 | 983 | ); |
| 923 | - else |
|
| 924 | - $request = $smcFunc['db_query']('', ' |
|
| 984 | + } else { |
|
| 985 | + $request = $smcFunc['db_query']('', ' |
|
| 925 | 986 | SELECT id_member, member_name, passwd, id_group, additional_groups, lngfile |
| 926 | 987 | FROM {db_prefix}members |
| 927 | 988 | WHERE member_name = {string:member_name}', |
@@ -930,6 +991,7 @@ discard block |
||
| 930 | 991 | 'db_error_skip' => true, |
| 931 | 992 | ) |
| 932 | 993 | ); |
| 994 | + } |
|
| 933 | 995 | if ($smcFunc['db_num_rows']($request) != 0) |
| 934 | 996 | { |
| 935 | 997 | list ($id_member, $name, $password, $id_group, $addGroups, $user_language) = $smcFunc['db_fetch_row']($request); |
@@ -937,16 +999,17 @@ discard block |
||
| 937 | 999 | $groups = explode(',', $addGroups); |
| 938 | 1000 | $groups[] = $id_group; |
| 939 | 1001 | |
| 940 | - foreach ($groups as $k => $v) |
|
| 941 | - $groups[$k] = (int) $v; |
|
| 1002 | + foreach ($groups as $k => $v) { |
|
| 1003 | + $groups[$k] = (int) $v; |
|
| 1004 | + } |
|
| 942 | 1005 | |
| 943 | 1006 | $sha_passwd = sha1(strtolower($name) . un_htmlspecialchars($_REQUEST['passwrd'])); |
| 944 | 1007 | |
| 945 | 1008 | // We don't use "-utf8" anymore... |
| 946 | 1009 | $user_language = str_ireplace('-utf8', '', $user_language); |
| 1010 | + } else { |
|
| 1011 | + $upcontext['username_incorrect'] = true; |
|
| 947 | 1012 | } |
| 948 | - else |
|
| 949 | - $upcontext['username_incorrect'] = true; |
|
| 950 | 1013 | |
| 951 | 1014 | $smcFunc['db_free_result']($request); |
| 952 | 1015 | } |
@@ -957,13 +1020,14 @@ discard block |
||
| 957 | 1020 | { |
| 958 | 1021 | $upcontext['upgrade_status']['js'] = 1; |
| 959 | 1022 | $support_js = 1; |
| 1023 | + } else { |
|
| 1024 | + $support_js = 0; |
|
| 960 | 1025 | } |
| 961 | - else |
|
| 962 | - $support_js = 0; |
|
| 963 | 1026 | |
| 964 | 1027 | // Note down the version we are coming from. |
| 965 | - if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) |
|
| 966 | - $upcontext['user']['version'] = $modSettings['smfVersion']; |
|
| 1028 | + if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) { |
|
| 1029 | + $upcontext['user']['version'] = $modSettings['smfVersion']; |
|
| 1030 | + } |
|
| 967 | 1031 | |
| 968 | 1032 | // Didn't get anywhere? |
| 969 | 1033 | 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'])) |
@@ -997,15 +1061,15 @@ discard block |
||
| 997 | 1061 | 'db_error_skip' => true, |
| 998 | 1062 | ) |
| 999 | 1063 | ); |
| 1000 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 1001 | - return throw_error('You need to be an admin to perform an upgrade!'); |
|
| 1064 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 1065 | + return throw_error('You need to be an admin to perform an upgrade!'); |
|
| 1066 | + } |
|
| 1002 | 1067 | $smcFunc['db_free_result']($request); |
| 1003 | 1068 | } |
| 1004 | 1069 | |
| 1005 | 1070 | $upcontext['user']['id'] = $id_member; |
| 1006 | 1071 | $upcontext['user']['name'] = $name; |
| 1007 | - } |
|
| 1008 | - else |
|
| 1072 | + } else |
|
| 1009 | 1073 | { |
| 1010 | 1074 | $upcontext['user']['id'] = 1; |
| 1011 | 1075 | $upcontext['user']['name'] = 'Administrator'; |
@@ -1021,11 +1085,11 @@ discard block |
||
| 1021 | 1085 | $temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $user_language . '.php')), 0, 4096); |
| 1022 | 1086 | preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match); |
| 1023 | 1087 | |
| 1024 | - if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) |
|
| 1025 | - $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'] . '.'; |
|
| 1026 | - elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) |
|
| 1027 | - $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'] . '.'; |
|
| 1028 | - else |
|
| 1088 | + if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) { |
|
| 1089 | + $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'] . '.'; |
|
| 1090 | + } elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) { |
|
| 1091 | + $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'] . '.'; |
|
| 1092 | + } else |
|
| 1029 | 1093 | { |
| 1030 | 1094 | // Set this as the new language. |
| 1031 | 1095 | $upcontext['language'] = $user_language; |
@@ -1072,8 +1136,9 @@ discard block |
||
| 1072 | 1136 | $upcontext['migrateSettingsNeeded'] = detectSettingsFileMigrationNeeded() ? 1 : 0; |
| 1073 | 1137 | |
| 1074 | 1138 | // If we've not submitted then we're done. |
| 1075 | - if (empty($_POST['upcont'])) |
|
| 1076 | - return false; |
|
| 1139 | + if (empty($_POST['upcont'])) { |
|
| 1140 | + return false; |
|
| 1141 | + } |
|
| 1077 | 1142 | |
| 1078 | 1143 | // Firstly, if they're enabling SM stat collection just do it. |
| 1079 | 1144 | if (!empty($_POST['stats']) && substr($boardurl, 0, 16) != 'http://localhost' && empty($modSettings['allow_sm_stats']) && empty($modSettings['enable_sm_stats'])) |
@@ -1093,16 +1158,17 @@ discard block |
||
| 1093 | 1158 | fwrite($fp, $out); |
| 1094 | 1159 | |
| 1095 | 1160 | $return_data = ''; |
| 1096 | - while (!feof($fp)) |
|
| 1097 | - $return_data .= fgets($fp, 128); |
|
| 1161 | + while (!feof($fp)) { |
|
| 1162 | + $return_data .= fgets($fp, 128); |
|
| 1163 | + } |
|
| 1098 | 1164 | |
| 1099 | 1165 | fclose($fp); |
| 1100 | 1166 | |
| 1101 | 1167 | // Get the unique site ID. |
| 1102 | 1168 | preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID); |
| 1103 | 1169 | |
| 1104 | - if (!empty($ID[1])) |
|
| 1105 | - $smcFunc['db_insert']('replace', |
|
| 1170 | + if (!empty($ID[1])) { |
|
| 1171 | + $smcFunc['db_insert']('replace', |
|
| 1106 | 1172 | $db_prefix . 'settings', |
| 1107 | 1173 | array('variable' => 'string', 'value' => 'string'), |
| 1108 | 1174 | array( |
@@ -1111,9 +1177,9 @@ discard block |
||
| 1111 | 1177 | ), |
| 1112 | 1178 | array('variable') |
| 1113 | 1179 | ); |
| 1180 | + } |
|
| 1114 | 1181 | } |
| 1115 | - } |
|
| 1116 | - else |
|
| 1182 | + } else |
|
| 1117 | 1183 | { |
| 1118 | 1184 | $smcFunc['db_insert']('replace', |
| 1119 | 1185 | $db_prefix . 'settings', |
@@ -1124,8 +1190,8 @@ discard block |
||
| 1124 | 1190 | } |
| 1125 | 1191 | } |
| 1126 | 1192 | // Don't remove stat collection unless we unchecked the box for real, not from the loop. |
| 1127 | - elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) |
|
| 1128 | - $smcFunc['db_query']('', ' |
|
| 1193 | + elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) { |
|
| 1194 | + $smcFunc['db_query']('', ' |
|
| 1129 | 1195 | DELETE FROM {db_prefix}settings |
| 1130 | 1196 | WHERE variable = {string:enable_sm_stats}', |
| 1131 | 1197 | array( |
@@ -1133,6 +1199,7 @@ discard block |
||
| 1133 | 1199 | 'db_error_skip' => true, |
| 1134 | 1200 | ) |
| 1135 | 1201 | ); |
| 1202 | + } |
|
| 1136 | 1203 | |
| 1137 | 1204 | // Deleting old karma stuff? |
| 1138 | 1205 | if (!empty($_POST['delete_karma'])) |
@@ -1147,20 +1214,22 @@ discard block |
||
| 1147 | 1214 | ); |
| 1148 | 1215 | |
| 1149 | 1216 | // Cleaning up old karma member settings. |
| 1150 | - if ($upcontext['karma_installed']['good']) |
|
| 1151 | - $smcFunc['db_query']('', ' |
|
| 1217 | + if ($upcontext['karma_installed']['good']) { |
|
| 1218 | + $smcFunc['db_query']('', ' |
|
| 1152 | 1219 | ALTER TABLE {db_prefix}members |
| 1153 | 1220 | DROP karma_good', |
| 1154 | 1221 | array() |
| 1155 | 1222 | ); |
| 1223 | + } |
|
| 1156 | 1224 | |
| 1157 | 1225 | // Does karma bad was enable? |
| 1158 | - if ($upcontext['karma_installed']['bad']) |
|
| 1159 | - $smcFunc['db_query']('', ' |
|
| 1226 | + if ($upcontext['karma_installed']['bad']) { |
|
| 1227 | + $smcFunc['db_query']('', ' |
|
| 1160 | 1228 | ALTER TABLE {db_prefix}members |
| 1161 | 1229 | DROP karma_bad', |
| 1162 | 1230 | array() |
| 1163 | 1231 | ); |
| 1232 | + } |
|
| 1164 | 1233 | |
| 1165 | 1234 | // Cleaning up old karma permissions. |
| 1166 | 1235 | $smcFunc['db_query']('', ' |
@@ -1178,32 +1247,37 @@ discard block |
||
| 1178 | 1247 | } |
| 1179 | 1248 | |
| 1180 | 1249 | // Emptying the error log? |
| 1181 | - if (!empty($_POST['empty_error'])) |
|
| 1182 | - $smcFunc['db_query']('truncate_table', ' |
|
| 1250 | + if (!empty($_POST['empty_error'])) { |
|
| 1251 | + $smcFunc['db_query']('truncate_table', ' |
|
| 1183 | 1252 | TRUNCATE {db_prefix}log_errors', |
| 1184 | 1253 | array( |
| 1185 | 1254 | ) |
| 1186 | 1255 | ); |
| 1256 | + } |
|
| 1187 | 1257 | |
| 1188 | 1258 | $changes = array(); |
| 1189 | 1259 | |
| 1190 | 1260 | // Add proxy settings. |
| 1191 | - if (!isset($GLOBALS['image_proxy_maxsize'])) |
|
| 1192 | - $changes += array( |
|
| 1261 | + if (!isset($GLOBALS['image_proxy_maxsize'])) { |
|
| 1262 | + $changes += array( |
|
| 1193 | 1263 | 'image_proxy_secret' => '\'' . substr(sha1(random_int(0, PHP_INT_MAX)), 0, 20) . '\'', |
| 1194 | 1264 | 'image_proxy_maxsize' => 5190, |
| 1195 | 1265 | 'image_proxy_enabled' => 0, |
| 1196 | 1266 | ); |
| 1267 | + } |
|
| 1197 | 1268 | |
| 1198 | 1269 | // If $boardurl reflects https, set force_ssl |
| 1199 | - if (!function_exists('cache_put_data')) |
|
| 1200 | - require_once($sourcedir . '/Load.php'); |
|
| 1201 | - if (stripos($boardurl, 'https://') !== false) |
|
| 1202 | - updateSettings(array('force_ssl' => '1')); |
|
| 1270 | + if (!function_exists('cache_put_data')) { |
|
| 1271 | + require_once($sourcedir . '/Load.php'); |
|
| 1272 | + } |
|
| 1273 | + if (stripos($boardurl, 'https://') !== false) { |
|
| 1274 | + updateSettings(array('force_ssl' => '1')); |
|
| 1275 | + } |
|
| 1203 | 1276 | |
| 1204 | 1277 | // If we're overriding the language follow it through. |
| 1205 | - if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) |
|
| 1206 | - $changes['language'] = '\'' . $_GET['lang'] . '\''; |
|
| 1278 | + if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) { |
|
| 1279 | + $changes['language'] = '\'' . $_GET['lang'] . '\''; |
|
| 1280 | + } |
|
| 1207 | 1281 | |
| 1208 | 1282 | if (!empty($_POST['maint'])) |
| 1209 | 1283 | { |
@@ -1215,26 +1289,29 @@ discard block |
||
| 1215 | 1289 | { |
| 1216 | 1290 | $changes['mtitle'] = '\'' . addslashes($_POST['maintitle']) . '\''; |
| 1217 | 1291 | $changes['mmessage'] = '\'' . addslashes($_POST['mainmessage']) . '\''; |
| 1218 | - } |
|
| 1219 | - else |
|
| 1292 | + } else |
|
| 1220 | 1293 | { |
| 1221 | 1294 | $changes['mtitle'] = '\'Upgrading the forum...\''; |
| 1222 | 1295 | $changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum. It will only be a minute ;).\''; |
| 1223 | 1296 | } |
| 1224 | 1297 | } |
| 1225 | 1298 | |
| 1226 | - if ($command_line) |
|
| 1227 | - echo ' * Updating Settings.php...'; |
|
| 1299 | + if ($command_line) { |
|
| 1300 | + echo ' * Updating Settings.php...'; |
|
| 1301 | + } |
|
| 1228 | 1302 | |
| 1229 | 1303 | // Fix some old paths. |
| 1230 | - if (substr($boarddir, 0, 1) == '.') |
|
| 1231 | - $changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\''; |
|
| 1304 | + if (substr($boarddir, 0, 1) == '.') { |
|
| 1305 | + $changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\''; |
|
| 1306 | + } |
|
| 1232 | 1307 | |
| 1233 | - if (substr($sourcedir, 0, 1) == '.') |
|
| 1234 | - $changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\''; |
|
| 1308 | + if (substr($sourcedir, 0, 1) == '.') { |
|
| 1309 | + $changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\''; |
|
| 1310 | + } |
|
| 1235 | 1311 | |
| 1236 | - if (empty($cachedir) || substr($cachedir, 0, 1) == '.') |
|
| 1237 | - $changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\''; |
|
| 1312 | + if (empty($cachedir) || substr($cachedir, 0, 1) == '.') { |
|
| 1313 | + $changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\''; |
|
| 1314 | + } |
|
| 1238 | 1315 | |
| 1239 | 1316 | // If they have a "host:port" setup for the host, split that into separate values |
| 1240 | 1317 | // You should never have a : in the hostname if you're not on MySQL, but better safe than sorry |
@@ -1245,32 +1322,36 @@ discard block |
||
| 1245 | 1322 | $changes['db_server'] = '\'' . $db_server . '\''; |
| 1246 | 1323 | |
| 1247 | 1324 | // Only set this if we're not using the default port |
| 1248 | - if ($db_port != ini_get('mysqli.default_port')) |
|
| 1249 | - $changes['db_port'] = (int) $db_port; |
|
| 1250 | - } |
|
| 1251 | - elseif (!empty($db_port)) |
|
| 1325 | + if ($db_port != ini_get('mysqli.default_port')) { |
|
| 1326 | + $changes['db_port'] = (int) $db_port; |
|
| 1327 | + } |
|
| 1328 | + } elseif (!empty($db_port)) |
|
| 1252 | 1329 | { |
| 1253 | 1330 | // If db_port is set and is the same as the default, set it to '' |
| 1254 | 1331 | if ($db_type == 'mysql') |
| 1255 | 1332 | { |
| 1256 | - if ($db_port == ini_get('mysqli.default_port')) |
|
| 1257 | - $changes['db_port'] = '\'\''; |
|
| 1258 | - elseif ($db_type == 'postgresql' && $db_port == 5432) |
|
| 1259 | - $changes['db_port'] = '\'\''; |
|
| 1333 | + if ($db_port == ini_get('mysqli.default_port')) { |
|
| 1334 | + $changes['db_port'] = '\'\''; |
|
| 1335 | + } elseif ($db_type == 'postgresql' && $db_port == 5432) { |
|
| 1336 | + $changes['db_port'] = '\'\''; |
|
| 1337 | + } |
|
| 1260 | 1338 | } |
| 1261 | 1339 | } |
| 1262 | 1340 | |
| 1263 | 1341 | // Maybe we haven't had this option yet? |
| 1264 | - if (empty($packagesdir)) |
|
| 1265 | - $changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\''; |
|
| 1342 | + if (empty($packagesdir)) { |
|
| 1343 | + $changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\''; |
|
| 1344 | + } |
|
| 1266 | 1345 | |
| 1267 | 1346 | // Add support for $tasksdir var. |
| 1268 | - if (empty($tasksdir)) |
|
| 1269 | - $changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\''; |
|
| 1347 | + if (empty($tasksdir)) { |
|
| 1348 | + $changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\''; |
|
| 1349 | + } |
|
| 1270 | 1350 | |
| 1271 | 1351 | // Make sure we fix the language as well. |
| 1272 | - if (stristr($language, '-utf8')) |
|
| 1273 | - $changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\''; |
|
| 1352 | + if (stristr($language, '-utf8')) { |
|
| 1353 | + $changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\''; |
|
| 1354 | + } |
|
| 1274 | 1355 | |
| 1275 | 1356 | // @todo Maybe change the cookie name if going to 1.1, too? |
| 1276 | 1357 | |
@@ -1281,8 +1362,7 @@ discard block |
||
| 1281 | 1362 | $changes['upgradeData'] = '"' . base64_encode(json_encode($upcontext['user'])) . '"'; |
| 1282 | 1363 | |
| 1283 | 1364 | migrateSettingsFile($changes); |
| 1284 | - } |
|
| 1285 | - else |
|
| 1365 | + } else |
|
| 1286 | 1366 | { |
| 1287 | 1367 | // Update Settings.php with the new settings. |
| 1288 | 1368 | require_once($sourcedir . '/Subs-Admin.php'); |
@@ -1292,8 +1372,9 @@ discard block |
||
| 1292 | 1372 | move_db_last_error_to_cachedir(); |
| 1293 | 1373 | } |
| 1294 | 1374 | |
| 1295 | - if ($command_line) |
|
| 1296 | - echo ' Successful.' . "\n"; |
|
| 1375 | + if ($command_line) { |
|
| 1376 | + echo ' Successful.' . "\n"; |
|
| 1377 | + } |
|
| 1297 | 1378 | |
| 1298 | 1379 | // Are we doing debug? |
| 1299 | 1380 | if (isset($_POST['debug'])) |
@@ -1303,8 +1384,9 @@ discard block |
||
| 1303 | 1384 | } |
| 1304 | 1385 | |
| 1305 | 1386 | // If we're not backing up then jump one. |
| 1306 | - if (empty($_POST['backup'])) |
|
| 1307 | - $upcontext['current_step']++; |
|
| 1387 | + if (empty($_POST['backup'])) { |
|
| 1388 | + $upcontext['current_step']++; |
|
| 1389 | + } |
|
| 1308 | 1390 | |
| 1309 | 1391 | // If we've got here then let's proceed to the next step! |
| 1310 | 1392 | return true; |
@@ -1319,8 +1401,9 @@ discard block |
||
| 1319 | 1401 | $upcontext['page_title'] = $txt['backup_database']; |
| 1320 | 1402 | |
| 1321 | 1403 | // Done it already - js wise? |
| 1322 | - if (!empty($_POST['backup_done'])) |
|
| 1323 | - return true; |
|
| 1404 | + if (!empty($_POST['backup_done'])) { |
|
| 1405 | + return true; |
|
| 1406 | + } |
|
| 1324 | 1407 | |
| 1325 | 1408 | // Some useful stuff here. |
| 1326 | 1409 | db_extend(); |
@@ -1334,9 +1417,10 @@ discard block |
||
| 1334 | 1417 | $tables = $smcFunc['db_list_tables']($db, $filter); |
| 1335 | 1418 | |
| 1336 | 1419 | $table_names = array(); |
| 1337 | - foreach ($tables as $table) |
|
| 1338 | - if (substr($table, 0, 7) !== 'backup_') |
|
| 1420 | + foreach ($tables as $table) { |
|
| 1421 | + if (substr($table, 0, 7) !== 'backup_') |
|
| 1339 | 1422 | $table_names[] = $table; |
| 1423 | + } |
|
| 1340 | 1424 | |
| 1341 | 1425 | $upcontext['table_count'] = count($table_names); |
| 1342 | 1426 | $upcontext['cur_table_num'] = $_GET['substep']; |
@@ -1346,12 +1430,14 @@ discard block |
||
| 1346 | 1430 | $file_steps = $upcontext['table_count']; |
| 1347 | 1431 | |
| 1348 | 1432 | // What ones have we already done? |
| 1349 | - foreach ($table_names as $id => $table) |
|
| 1350 | - if ($id < $_GET['substep']) |
|
| 1433 | + foreach ($table_names as $id => $table) { |
|
| 1434 | + if ($id < $_GET['substep']) |
|
| 1351 | 1435 | $upcontext['previous_tables'][] = $table; |
| 1436 | + } |
|
| 1352 | 1437 | |
| 1353 | - if ($command_line) |
|
| 1354 | - echo 'Backing Up Tables.'; |
|
| 1438 | + if ($command_line) { |
|
| 1439 | + echo 'Backing Up Tables.'; |
|
| 1440 | + } |
|
| 1355 | 1441 | |
| 1356 | 1442 | // If we don't support javascript we backup here. |
| 1357 | 1443 | if (!$support_js || isset($_GET['xml'])) |
@@ -1370,8 +1456,9 @@ discard block |
||
| 1370 | 1456 | backupTable($table_names[$substep]); |
| 1371 | 1457 | |
| 1372 | 1458 | // If this is XML to keep it nice for the user do one table at a time anyway! |
| 1373 | - if (isset($_GET['xml'])) |
|
| 1374 | - return upgradeExit(); |
|
| 1459 | + if (isset($_GET['xml'])) { |
|
| 1460 | + return upgradeExit(); |
|
| 1461 | + } |
|
| 1375 | 1462 | } |
| 1376 | 1463 | |
| 1377 | 1464 | if ($command_line) |
@@ -1404,9 +1491,10 @@ discard block |
||
| 1404 | 1491 | |
| 1405 | 1492 | $smcFunc['db_backup_table']($table, 'backup_' . $table); |
| 1406 | 1493 | |
| 1407 | - if ($command_line) |
|
| 1408 | - echo ' done.'; |
|
| 1409 | -} |
|
| 1494 | + if ($command_line) { |
|
| 1495 | + echo ' done.'; |
|
| 1496 | + } |
|
| 1497 | + } |
|
| 1410 | 1498 | |
| 1411 | 1499 | // Step 2: Everything. |
| 1412 | 1500 | function DatabaseChanges() |
@@ -1415,8 +1503,9 @@ discard block |
||
| 1415 | 1503 | global $upcontext, $support_js, $db_type; |
| 1416 | 1504 | |
| 1417 | 1505 | // Have we just completed this? |
| 1418 | - if (!empty($_POST['database_done'])) |
|
| 1419 | - return true; |
|
| 1506 | + if (!empty($_POST['database_done'])) { |
|
| 1507 | + return true; |
|
| 1508 | + } |
|
| 1420 | 1509 | |
| 1421 | 1510 | $upcontext['sub_template'] = isset($_GET['xml']) ? 'database_xml' : 'database_changes'; |
| 1422 | 1511 | $upcontext['page_title'] = $txt['database_changes']; |
@@ -1431,15 +1520,16 @@ discard block |
||
| 1431 | 1520 | ); |
| 1432 | 1521 | |
| 1433 | 1522 | // How many files are there in total? |
| 1434 | - if (isset($_GET['filecount'])) |
|
| 1435 | - $upcontext['file_count'] = (int) $_GET['filecount']; |
|
| 1436 | - else |
|
| 1523 | + if (isset($_GET['filecount'])) { |
|
| 1524 | + $upcontext['file_count'] = (int) $_GET['filecount']; |
|
| 1525 | + } else |
|
| 1437 | 1526 | { |
| 1438 | 1527 | $upcontext['file_count'] = 0; |
| 1439 | 1528 | foreach ($files as $file) |
| 1440 | 1529 | { |
| 1441 | - if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) |
|
| 1442 | - $upcontext['file_count']++; |
|
| 1530 | + if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) { |
|
| 1531 | + $upcontext['file_count']++; |
|
| 1532 | + } |
|
| 1443 | 1533 | } |
| 1444 | 1534 | } |
| 1445 | 1535 | |
@@ -1449,9 +1539,9 @@ discard block |
||
| 1449 | 1539 | $upcontext['cur_file_num'] = 0; |
| 1450 | 1540 | foreach ($files as $file) |
| 1451 | 1541 | { |
| 1452 | - if ($did_not_do) |
|
| 1453 | - $did_not_do--; |
|
| 1454 | - else |
|
| 1542 | + if ($did_not_do) { |
|
| 1543 | + $did_not_do--; |
|
| 1544 | + } else |
|
| 1455 | 1545 | { |
| 1456 | 1546 | $upcontext['cur_file_num']++; |
| 1457 | 1547 | $upcontext['cur_file_name'] = $file[0]; |
@@ -1478,12 +1568,13 @@ discard block |
||
| 1478 | 1568 | // Flag to move on to the next. |
| 1479 | 1569 | $upcontext['completed_step'] = true; |
| 1480 | 1570 | // Did we complete the whole file? |
| 1481 | - if ($nextFile) |
|
| 1482 | - $upcontext['current_debug_item_num'] = -1; |
|
| 1571 | + if ($nextFile) { |
|
| 1572 | + $upcontext['current_debug_item_num'] = -1; |
|
| 1573 | + } |
|
| 1483 | 1574 | return upgradeExit(); |
| 1575 | + } elseif ($support_js) { |
|
| 1576 | + break; |
|
| 1484 | 1577 | } |
| 1485 | - elseif ($support_js) |
|
| 1486 | - break; |
|
| 1487 | 1578 | } |
| 1488 | 1579 | // Set the progress bar to be right as if we had - even if we hadn't... |
| 1489 | 1580 | $upcontext['step_progress'] = ($upcontext['cur_file_num'] / $upcontext['file_count']) * 100; |
@@ -1509,8 +1600,9 @@ discard block |
||
| 1509 | 1600 | global $user_info, $maintenance, $smcFunc, $db_type, $txt, $settings; |
| 1510 | 1601 | |
| 1511 | 1602 | // Now it's nice to have some of the basic SMF source files. |
| 1512 | - if (!isset($_GET['ssi']) && !$command_line) |
|
| 1513 | - redirectLocation('&ssi=1'); |
|
| 1603 | + if (!isset($_GET['ssi']) && !$command_line) { |
|
| 1604 | + redirectLocation('&ssi=1'); |
|
| 1605 | + } |
|
| 1514 | 1606 | |
| 1515 | 1607 | $upcontext['sub_template'] = 'upgrade_complete'; |
| 1516 | 1608 | $upcontext['page_title'] = $txt['upgrade_complete']; |
@@ -1526,14 +1618,16 @@ discard block |
||
| 1526 | 1618 | // Are we in maintenance mode? |
| 1527 | 1619 | if (isset($upcontext['user']['main'])) |
| 1528 | 1620 | { |
| 1529 | - if ($command_line) |
|
| 1530 | - echo ' * '; |
|
| 1621 | + if ($command_line) { |
|
| 1622 | + echo ' * '; |
|
| 1623 | + } |
|
| 1531 | 1624 | $upcontext['removed_maintenance'] = true; |
| 1532 | 1625 | $changes['maintenance'] = $upcontext['user']['main']; |
| 1533 | 1626 | } |
| 1534 | 1627 | // Otherwise if somehow we are in 2 let's go to 1. |
| 1535 | - elseif (!empty($maintenance) && $maintenance == 2) |
|
| 1536 | - $changes['maintenance'] = 1; |
|
| 1628 | + elseif (!empty($maintenance) && $maintenance == 2) { |
|
| 1629 | + $changes['maintenance'] = 1; |
|
| 1630 | + } |
|
| 1537 | 1631 | |
| 1538 | 1632 | // Wipe this out... |
| 1539 | 1633 | $upcontext['user'] = array(); |
@@ -1548,21 +1642,23 @@ discard block |
||
| 1548 | 1642 | $upcontext['can_delete_script'] = is_writable(dirname(__FILE__)) || is_writable(__FILE__); |
| 1549 | 1643 | |
| 1550 | 1644 | // Now is the perfect time to fetch the SM files. |
| 1551 | - if ($command_line) |
|
| 1552 | - cli_scheduled_fetchSMfiles(); |
|
| 1553 | - else |
|
| 1645 | + if ($command_line) { |
|
| 1646 | + cli_scheduled_fetchSMfiles(); |
|
| 1647 | + } else |
|
| 1554 | 1648 | { |
| 1555 | 1649 | require_once($sourcedir . '/ScheduledTasks.php'); |
| 1556 | 1650 | $forum_version = SMF_VERSION; // The variable is usually defined in index.php so lets just use the constant to do it for us. |
| 1557 | 1651 | scheduled_fetchSMfiles(); // Now go get those files! |
| 1558 | 1652 | // This is needed in case someone invokes the upgrader using https when upgrading an http forum |
| 1559 | - if (httpsOn()) |
|
| 1560 | - $settings['default_theme_url'] = strtr($settings['default_theme_url'], array('http://' => 'https://')); |
|
| 1653 | + if (httpsOn()) { |
|
| 1654 | + $settings['default_theme_url'] = strtr($settings['default_theme_url'], array('http://' => 'https://')); |
|
| 1655 | + } |
|
| 1561 | 1656 | } |
| 1562 | 1657 | |
| 1563 | 1658 | // Log what we've done. |
| 1564 | - if (empty($user_info['id'])) |
|
| 1565 | - $user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0; |
|
| 1659 | + if (empty($user_info['id'])) { |
|
| 1660 | + $user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0; |
|
| 1661 | + } |
|
| 1566 | 1662 | |
| 1567 | 1663 | // Log the action manually, so CLI still works. |
| 1568 | 1664 | $smcFunc['db_insert']('', |
@@ -1581,8 +1677,9 @@ discard block |
||
| 1581 | 1677 | |
| 1582 | 1678 | // Save the current database version. |
| 1583 | 1679 | $server_version = $smcFunc['db_server_info'](); |
| 1584 | - if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) |
|
| 1585 | - updateSettings(array('db_mysql_group_by_fix' => '1')); |
|
| 1680 | + if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) { |
|
| 1681 | + updateSettings(array('db_mysql_group_by_fix' => '1')); |
|
| 1682 | + } |
|
| 1586 | 1683 | |
| 1587 | 1684 | if ($command_line) |
| 1588 | 1685 | { |
@@ -1594,8 +1691,9 @@ discard block |
||
| 1594 | 1691 | |
| 1595 | 1692 | // Make sure it says we're done. |
| 1596 | 1693 | $upcontext['overall_percent'] = 100; |
| 1597 | - if (isset($upcontext['step_progress'])) |
|
| 1598 | - unset($upcontext['step_progress']); |
|
| 1694 | + if (isset($upcontext['step_progress'])) { |
|
| 1695 | + unset($upcontext['step_progress']); |
|
| 1696 | + } |
|
| 1599 | 1697 | |
| 1600 | 1698 | $_GET['substep'] = 0; |
| 1601 | 1699 | return false; |
@@ -1606,8 +1704,9 @@ discard block |
||
| 1606 | 1704 | { |
| 1607 | 1705 | global $sourcedir, $language, $forum_version, $modSettings, $smcFunc; |
| 1608 | 1706 | |
| 1609 | - if (empty($modSettings['time_format'])) |
|
| 1610 | - $modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p'; |
|
| 1707 | + if (empty($modSettings['time_format'])) { |
|
| 1708 | + $modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p'; |
|
| 1709 | + } |
|
| 1611 | 1710 | |
| 1612 | 1711 | // What files do we want to get |
| 1613 | 1712 | $request = $smcFunc['db_query']('', ' |
@@ -1641,8 +1740,9 @@ discard block |
||
| 1641 | 1740 | $file_data = fetch_web_data($url); |
| 1642 | 1741 | |
| 1643 | 1742 | // If we got an error - give up - the site might be down. |
| 1644 | - if ($file_data === false) |
|
| 1645 | - return throw_error(sprintf('Could not retrieve the file %1$s.', $url)); |
|
| 1743 | + if ($file_data === false) { |
|
| 1744 | + return throw_error(sprintf('Could not retrieve the file %1$s.', $url)); |
|
| 1745 | + } |
|
| 1646 | 1746 | |
| 1647 | 1747 | // Save the file to the database. |
| 1648 | 1748 | $smcFunc['db_query']('substring', ' |
@@ -1684,8 +1784,9 @@ discard block |
||
| 1684 | 1784 | $themeData = array(); |
| 1685 | 1785 | foreach ($values as $variable => $value) |
| 1686 | 1786 | { |
| 1687 | - if (!isset($value) || $value === null) |
|
| 1688 | - $value = 0; |
|
| 1787 | + if (!isset($value) || $value === null) { |
|
| 1788 | + $value = 0; |
|
| 1789 | + } |
|
| 1689 | 1790 | |
| 1690 | 1791 | $themeData[] = array(0, 1, $variable, $value); |
| 1691 | 1792 | } |
@@ -1714,8 +1815,9 @@ discard block |
||
| 1714 | 1815 | |
| 1715 | 1816 | foreach ($values as $variable => $value) |
| 1716 | 1817 | { |
| 1717 | - if (empty($modSettings[$value[0]])) |
|
| 1718 | - continue; |
|
| 1818 | + if (empty($modSettings[$value[0]])) { |
|
| 1819 | + continue; |
|
| 1820 | + } |
|
| 1719 | 1821 | |
| 1720 | 1822 | $smcFunc['db_query']('', ' |
| 1721 | 1823 | INSERT IGNORE INTO {db_prefix}themes |
@@ -1801,19 +1903,21 @@ discard block |
||
| 1801 | 1903 | set_error_handler( |
| 1802 | 1904 | function ($errno, $errstr, $errfile, $errline) use ($support_js) |
| 1803 | 1905 | { |
| 1804 | - if ($support_js) |
|
| 1805 | - return true; |
|
| 1806 | - else |
|
| 1807 | - echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline; |
|
| 1906 | + if ($support_js) { |
|
| 1907 | + return true; |
|
| 1908 | + } else { |
|
| 1909 | + echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline; |
|
| 1910 | + } |
|
| 1808 | 1911 | } |
| 1809 | 1912 | ); |
| 1810 | 1913 | |
| 1811 | 1914 | // If we're on MySQL, set {db_collation}; this approach is used throughout upgrade_2-0_mysql.php to set new tables to utf8 |
| 1812 | 1915 | // Note it is expected to be in the format: ENGINE=MyISAM{$db_collation}; |
| 1813 | - if ($db_type == 'mysql') |
|
| 1814 | - $db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci'; |
|
| 1815 | - else |
|
| 1816 | - $db_collation = ''; |
|
| 1916 | + if ($db_type == 'mysql') { |
|
| 1917 | + $db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci'; |
|
| 1918 | + } else { |
|
| 1919 | + $db_collation = ''; |
|
| 1920 | + } |
|
| 1817 | 1921 | |
| 1818 | 1922 | $endl = $command_line ? "\n" : '<br>' . "\n"; |
| 1819 | 1923 | |
@@ -1825,8 +1929,9 @@ discard block |
||
| 1825 | 1929 | $last_step = ''; |
| 1826 | 1930 | |
| 1827 | 1931 | // Make sure all newly created tables will have the proper characters set; this approach is used throughout upgrade_2-1_mysql.php |
| 1828 | - if (isset($db_character_set) && $db_character_set === 'utf8') |
|
| 1829 | - $lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines); |
|
| 1932 | + if (isset($db_character_set) && $db_character_set === 'utf8') { |
|
| 1933 | + $lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines); |
|
| 1934 | + } |
|
| 1830 | 1935 | |
| 1831 | 1936 | // Count the total number of steps within this file - for progress. |
| 1832 | 1937 | $file_steps = substr_count(implode('', $lines), '---#'); |
@@ -1846,15 +1951,18 @@ discard block |
||
| 1846 | 1951 | $do_current = $substep >= $_GET['substep']; |
| 1847 | 1952 | |
| 1848 | 1953 | // Get rid of any comments in the beginning of the line... |
| 1849 | - if (substr(trim($line), 0, 2) === '/*') |
|
| 1850 | - $line = preg_replace('~/\*.+?\*/~', '', $line); |
|
| 1954 | + if (substr(trim($line), 0, 2) === '/*') { |
|
| 1955 | + $line = preg_replace('~/\*.+?\*/~', '', $line); |
|
| 1956 | + } |
|
| 1851 | 1957 | |
| 1852 | 1958 | // Always flush. Flush, flush, flush. Flush, flush, flush, flush! FLUSH! |
| 1853 | - if ($is_debug && !$support_js && $command_line) |
|
| 1854 | - flush(); |
|
| 1959 | + if ($is_debug && !$support_js && $command_line) { |
|
| 1960 | + flush(); |
|
| 1961 | + } |
|
| 1855 | 1962 | |
| 1856 | - if (trim($line) === '') |
|
| 1857 | - continue; |
|
| 1963 | + if (trim($line) === '') { |
|
| 1964 | + continue; |
|
| 1965 | + } |
|
| 1858 | 1966 | |
| 1859 | 1967 | if (trim(substr($line, 0, 3)) === '---') |
| 1860 | 1968 | { |
@@ -1864,8 +1972,9 @@ discard block |
||
| 1864 | 1972 | if (trim($current_data) != '' && $type !== '}') |
| 1865 | 1973 | { |
| 1866 | 1974 | $upcontext['error_message'] = 'Error in upgrade script - line ' . $line_number . '!' . $endl; |
| 1867 | - if ($command_line) |
|
| 1868 | - echo $upcontext['error_message']; |
|
| 1975 | + if ($command_line) { |
|
| 1976 | + echo $upcontext['error_message']; |
|
| 1977 | + } |
|
| 1869 | 1978 | } |
| 1870 | 1979 | |
| 1871 | 1980 | if ($type == ' ') |
@@ -1883,17 +1992,18 @@ discard block |
||
| 1883 | 1992 | if ($do_current) |
| 1884 | 1993 | { |
| 1885 | 1994 | $upcontext['actioned_items'][] = $last_step; |
| 1886 | - if ($command_line) |
|
| 1887 | - echo ' * '; |
|
| 1995 | + if ($command_line) { |
|
| 1996 | + echo ' * '; |
|
| 1997 | + } |
|
| 1888 | 1998 | } |
| 1889 | - } |
|
| 1890 | - elseif ($type == '#') |
|
| 1999 | + } elseif ($type == '#') |
|
| 1891 | 2000 | { |
| 1892 | 2001 | $upcontext['step_progress'] += (100 / $upcontext['file_count']) / $file_steps; |
| 1893 | 2002 | |
| 1894 | 2003 | $upcontext['current_debug_item_num']++; |
| 1895 | - if (trim($line) != '---#') |
|
| 1896 | - $upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4))); |
|
| 2004 | + if (trim($line) != '---#') { |
|
| 2005 | + $upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4))); |
|
| 2006 | + } |
|
| 1897 | 2007 | |
| 1898 | 2008 | // Have we already done something? |
| 1899 | 2009 | if (isset($_GET['xml']) && $done_something) |
@@ -1904,34 +2014,36 @@ discard block |
||
| 1904 | 2014 | |
| 1905 | 2015 | if ($do_current) |
| 1906 | 2016 | { |
| 1907 | - if (trim($line) == '---#' && $command_line) |
|
| 1908 | - echo ' done.', $endl; |
|
| 1909 | - elseif ($command_line) |
|
| 1910 | - echo ' +++ ', rtrim(substr($line, 4)); |
|
| 1911 | - elseif (trim($line) != '---#') |
|
| 2017 | + if (trim($line) == '---#' && $command_line) { |
|
| 2018 | + echo ' done.', $endl; |
|
| 2019 | + } elseif ($command_line) { |
|
| 2020 | + echo ' +++ ', rtrim(substr($line, 4)); |
|
| 2021 | + } elseif (trim($line) != '---#') |
|
| 1912 | 2022 | { |
| 1913 | - if ($is_debug) |
|
| 1914 | - $upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4))); |
|
| 2023 | + if ($is_debug) { |
|
| 2024 | + $upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4))); |
|
| 2025 | + } |
|
| 1915 | 2026 | } |
| 1916 | 2027 | } |
| 1917 | 2028 | |
| 1918 | 2029 | if ($substep < $_GET['substep'] && $substep + 1 >= $_GET['substep']) |
| 1919 | 2030 | { |
| 1920 | - if ($command_line) |
|
| 1921 | - echo ' * '; |
|
| 1922 | - else |
|
| 1923 | - $upcontext['actioned_items'][] = $last_step; |
|
| 2031 | + if ($command_line) { |
|
| 2032 | + echo ' * '; |
|
| 2033 | + } else { |
|
| 2034 | + $upcontext['actioned_items'][] = $last_step; |
|
| 2035 | + } |
|
| 1924 | 2036 | } |
| 1925 | 2037 | |
| 1926 | 2038 | // Small step - only if we're actually doing stuff. |
| 1927 | - if ($do_current) |
|
| 1928 | - nextSubstep(++$substep); |
|
| 1929 | - else |
|
| 1930 | - $substep++; |
|
| 1931 | - } |
|
| 1932 | - elseif ($type == '{') |
|
| 1933 | - $current_type = 'code'; |
|
| 1934 | - elseif ($type == '}') |
|
| 2039 | + if ($do_current) { |
|
| 2040 | + nextSubstep(++$substep); |
|
| 2041 | + } else { |
|
| 2042 | + $substep++; |
|
| 2043 | + } |
|
| 2044 | + } elseif ($type == '{') { |
|
| 2045 | + $current_type = 'code'; |
|
| 2046 | + } elseif ($type == '}') |
|
| 1935 | 2047 | { |
| 1936 | 2048 | $current_type = 'sql'; |
| 1937 | 2049 | |
@@ -1944,8 +2056,9 @@ discard block |
||
| 1944 | 2056 | if (eval('global $db_prefix, $modSettings, $smcFunc, $txt; ' . $current_data) === false) |
| 1945 | 2057 | { |
| 1946 | 2058 | $upcontext['error_message'] = 'Error in upgrade script ' . basename($filename) . ' on line ' . $line_number . '!' . $endl; |
| 1947 | - if ($command_line) |
|
| 1948 | - echo $upcontext['error_message']; |
|
| 2059 | + if ($command_line) { |
|
| 2060 | + echo $upcontext['error_message']; |
|
| 2061 | + } |
|
| 1949 | 2062 | } |
| 1950 | 2063 | |
| 1951 | 2064 | // Done with code! |
@@ -2033,8 +2146,9 @@ discard block |
||
| 2033 | 2146 | $db_unbuffered = false; |
| 2034 | 2147 | |
| 2035 | 2148 | // Failure?! |
| 2036 | - if ($result !== false) |
|
| 2037 | - return $result; |
|
| 2149 | + if ($result !== false) { |
|
| 2150 | + return $result; |
|
| 2151 | + } |
|
| 2038 | 2152 | |
| 2039 | 2153 | $db_error_message = $smcFunc['db_error']($db_connection); |
| 2040 | 2154 | // If MySQL we do something more clever. |
@@ -2062,54 +2176,61 @@ discard block |
||
| 2062 | 2176 | { |
| 2063 | 2177 | mysqli_query($db_connection, 'REPAIR TABLE `' . $match[1] . '`'); |
| 2064 | 2178 | $result = mysqli_query($db_connection, $string); |
| 2065 | - if ($result !== false) |
|
| 2066 | - return $result; |
|
| 2179 | + if ($result !== false) { |
|
| 2180 | + return $result; |
|
| 2181 | + } |
|
| 2067 | 2182 | } |
| 2068 | - } |
|
| 2069 | - elseif ($mysqli_errno == 2013) |
|
| 2183 | + } elseif ($mysqli_errno == 2013) |
|
| 2070 | 2184 | { |
| 2071 | 2185 | $db_connection = mysqli_connect($db_server, $db_user, $db_passwd); |
| 2072 | 2186 | mysqli_select_db($db_connection, $db_name); |
| 2073 | 2187 | if ($db_connection) |
| 2074 | 2188 | { |
| 2075 | 2189 | $result = mysqli_query($db_connection, $string); |
| 2076 | - if ($result !== false) |
|
| 2077 | - return $result; |
|
| 2190 | + if ($result !== false) { |
|
| 2191 | + return $result; |
|
| 2192 | + } |
|
| 2078 | 2193 | } |
| 2079 | 2194 | } |
| 2080 | 2195 | // Duplicate column name... should be okay ;). |
| 2081 | - elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091))) |
|
| 2082 | - return false; |
|
| 2196 | + elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091))) { |
|
| 2197 | + return false; |
|
| 2198 | + } |
|
| 2083 | 2199 | // Duplicate insert... make sure it's the proper type of query ;). |
| 2084 | - elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query) |
|
| 2085 | - return false; |
|
| 2200 | + elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query) { |
|
| 2201 | + return false; |
|
| 2202 | + } |
|
| 2086 | 2203 | // Creating an index on a non-existent column. |
| 2087 | - elseif ($mysqli_errno == 1072) |
|
| 2088 | - return false; |
|
| 2089 | - elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') |
|
| 2090 | - return false; |
|
| 2204 | + elseif ($mysqli_errno == 1072) { |
|
| 2205 | + return false; |
|
| 2206 | + } elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') { |
|
| 2207 | + return false; |
|
| 2208 | + } |
|
| 2091 | 2209 | } |
| 2092 | 2210 | // If a table already exists don't go potty. |
| 2093 | 2211 | else |
| 2094 | 2212 | { |
| 2095 | 2213 | if (in_array(substr(trim($string), 0, 8), array('CREATE T', 'CREATE S', 'DROP TABL', 'ALTER TA', 'CREATE I', 'CREATE U'))) |
| 2096 | 2214 | { |
| 2097 | - if (strpos($db_error_message, 'exist') !== false) |
|
| 2098 | - return true; |
|
| 2099 | - } |
|
| 2100 | - elseif (strpos(trim($string), 'INSERT ') !== false) |
|
| 2215 | + if (strpos($db_error_message, 'exist') !== false) { |
|
| 2216 | + return true; |
|
| 2217 | + } |
|
| 2218 | + } elseif (strpos(trim($string), 'INSERT ') !== false) |
|
| 2101 | 2219 | { |
| 2102 | - if (strpos($db_error_message, 'duplicate') !== false || $ignore_insert_error) |
|
| 2103 | - return true; |
|
| 2220 | + if (strpos($db_error_message, 'duplicate') !== false || $ignore_insert_error) { |
|
| 2221 | + return true; |
|
| 2222 | + } |
|
| 2104 | 2223 | } |
| 2105 | 2224 | } |
| 2106 | 2225 | |
| 2107 | 2226 | // Get the query string so we pass everything. |
| 2108 | 2227 | $query_string = ''; |
| 2109 | - foreach ($_GET as $k => $v) |
|
| 2110 | - $query_string .= ';' . $k . '=' . $v; |
|
| 2111 | - if (strlen($query_string) != 0) |
|
| 2112 | - $query_string = '?' . substr($query_string, 1); |
|
| 2228 | + foreach ($_GET as $k => $v) { |
|
| 2229 | + $query_string .= ';' . $k . '=' . $v; |
|
| 2230 | + } |
|
| 2231 | + if (strlen($query_string) != 0) { |
|
| 2232 | + $query_string = '?' . substr($query_string, 1); |
|
| 2233 | + } |
|
| 2113 | 2234 | |
| 2114 | 2235 | if ($command_line) |
| 2115 | 2236 | { |
@@ -2164,16 +2285,18 @@ discard block |
||
| 2164 | 2285 | { |
| 2165 | 2286 | $found |= 1; |
| 2166 | 2287 | // Do some checks on the data if we have it set. |
| 2167 | - if (isset($change['col_type'])) |
|
| 2168 | - $found &= $change['col_type'] === $column['type']; |
|
| 2169 | - if (isset($change['null_allowed'])) |
|
| 2170 | - $found &= $column['null'] == $change['null_allowed']; |
|
| 2171 | - if (isset($change['default'])) |
|
| 2172 | - $found &= $change['default'] === $column['default']; |
|
| 2288 | + if (isset($change['col_type'])) { |
|
| 2289 | + $found &= $change['col_type'] === $column['type']; |
|
| 2290 | + } |
|
| 2291 | + if (isset($change['null_allowed'])) { |
|
| 2292 | + $found &= $column['null'] == $change['null_allowed']; |
|
| 2293 | + } |
|
| 2294 | + if (isset($change['default'])) { |
|
| 2295 | + $found &= $change['default'] === $column['default']; |
|
| 2296 | + } |
|
| 2173 | 2297 | } |
| 2174 | 2298 | } |
| 2175 | - } |
|
| 2176 | - elseif ($change['type'] === 'index') |
|
| 2299 | + } elseif ($change['type'] === 'index') |
|
| 2177 | 2300 | { |
| 2178 | 2301 | $request = upgrade_query(' |
| 2179 | 2302 | SHOW INDEX |
@@ -2182,9 +2305,10 @@ discard block |
||
| 2182 | 2305 | { |
| 2183 | 2306 | $cur_index = array(); |
| 2184 | 2307 | |
| 2185 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 2186 | - if ($row['Key_name'] === $change['name']) |
|
| 2308 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 2309 | + if ($row['Key_name'] === $change['name']) |
|
| 2187 | 2310 | $cur_index[(int) $row['Seq_in_index']] = $row['Column_name']; |
| 2311 | + } |
|
| 2188 | 2312 | |
| 2189 | 2313 | ksort($cur_index, SORT_NUMERIC); |
| 2190 | 2314 | $found = array_values($cur_index) === $change['target_columns']; |
@@ -2194,14 +2318,17 @@ discard block |
||
| 2194 | 2318 | } |
| 2195 | 2319 | |
| 2196 | 2320 | // If we're trying to add and it's added, we're done. |
| 2197 | - if ($found && in_array($change['method'], array('add', 'change'))) |
|
| 2198 | - return true; |
|
| 2321 | + if ($found && in_array($change['method'], array('add', 'change'))) { |
|
| 2322 | + return true; |
|
| 2323 | + } |
|
| 2199 | 2324 | // Otherwise if we're removing and it wasn't found we're also done. |
| 2200 | - elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) |
|
| 2201 | - return true; |
|
| 2325 | + elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) { |
|
| 2326 | + return true; |
|
| 2327 | + } |
|
| 2202 | 2328 | // Otherwise is it just a test? |
| 2203 | - elseif ($is_test) |
|
| 2204 | - return false; |
|
| 2329 | + elseif ($is_test) { |
|
| 2330 | + return false; |
|
| 2331 | + } |
|
| 2205 | 2332 | |
| 2206 | 2333 | // Not found it yet? Bummer! How about we see if we're currently doing it? |
| 2207 | 2334 | $running = false; |
@@ -2212,8 +2339,9 @@ discard block |
||
| 2212 | 2339 | SHOW FULL PROCESSLIST'); |
| 2213 | 2340 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 2214 | 2341 | { |
| 2215 | - if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) |
|
| 2216 | - $found = true; |
|
| 2342 | + if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) { |
|
| 2343 | + $found = true; |
|
| 2344 | + } |
|
| 2217 | 2345 | } |
| 2218 | 2346 | |
| 2219 | 2347 | // Can't find it? Then we need to run it fools! |
@@ -2225,8 +2353,9 @@ discard block |
||
| 2225 | 2353 | ALTER TABLE ' . $db_prefix . $change['table'] . ' |
| 2226 | 2354 | ' . $change['text'], true) !== false; |
| 2227 | 2355 | |
| 2228 | - if (!$success) |
|
| 2229 | - return false; |
|
| 2356 | + if (!$success) { |
|
| 2357 | + return false; |
|
| 2358 | + } |
|
| 2230 | 2359 | |
| 2231 | 2360 | // Return |
| 2232 | 2361 | $running = true; |
@@ -2268,8 +2397,9 @@ discard block |
||
| 2268 | 2397 | 'db_error_skip' => true, |
| 2269 | 2398 | ) |
| 2270 | 2399 | ); |
| 2271 | - if ($smcFunc['db_num_rows']($request) === 0) |
|
| 2272 | - die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']); |
|
| 2400 | + if ($smcFunc['db_num_rows']($request) === 0) { |
|
| 2401 | + die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']); |
|
| 2402 | + } |
|
| 2273 | 2403 | $table_row = $smcFunc['db_fetch_assoc']($request); |
| 2274 | 2404 | $smcFunc['db_free_result']($request); |
| 2275 | 2405 | |
@@ -2291,18 +2421,19 @@ discard block |
||
| 2291 | 2421 | ) |
| 2292 | 2422 | ); |
| 2293 | 2423 | // No results? Just forget it all together. |
| 2294 | - if ($smcFunc['db_num_rows']($request) === 0) |
|
| 2295 | - unset($table_row['Collation']); |
|
| 2296 | - else |
|
| 2297 | - $collation_info = $smcFunc['db_fetch_assoc']($request); |
|
| 2424 | + if ($smcFunc['db_num_rows']($request) === 0) { |
|
| 2425 | + unset($table_row['Collation']); |
|
| 2426 | + } else { |
|
| 2427 | + $collation_info = $smcFunc['db_fetch_assoc']($request); |
|
| 2428 | + } |
|
| 2298 | 2429 | $smcFunc['db_free_result']($request); |
| 2299 | 2430 | } |
| 2300 | 2431 | |
| 2301 | 2432 | if ($column_fix) |
| 2302 | 2433 | { |
| 2303 | 2434 | // Make sure there are no NULL's left. |
| 2304 | - if ($null_fix) |
|
| 2305 | - $smcFunc['db_query']('', ' |
|
| 2435 | + if ($null_fix) { |
|
| 2436 | + $smcFunc['db_query']('', ' |
|
| 2306 | 2437 | UPDATE {db_prefix}' . $change['table'] . ' |
| 2307 | 2438 | SET ' . $change['column'] . ' = {string:default} |
| 2308 | 2439 | WHERE ' . $change['column'] . ' IS NULL', |
@@ -2311,6 +2442,7 @@ discard block |
||
| 2311 | 2442 | 'db_error_skip' => true, |
| 2312 | 2443 | ) |
| 2313 | 2444 | ); |
| 2445 | + } |
|
| 2314 | 2446 | |
| 2315 | 2447 | // Do the actual alteration. |
| 2316 | 2448 | $smcFunc['db_query']('', ' |
@@ -2339,8 +2471,9 @@ discard block |
||
| 2339 | 2471 | } |
| 2340 | 2472 | |
| 2341 | 2473 | // Not a column we need to check on? |
| 2342 | - if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) |
|
| 2343 | - return; |
|
| 2474 | + if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) { |
|
| 2475 | + return; |
|
| 2476 | + } |
|
| 2344 | 2477 | |
| 2345 | 2478 | // Break it up you (six|seven). |
| 2346 | 2479 | $temp = explode(' ', str_replace('NOT NULL', 'NOT_NULL', $change['text'])); |
@@ -2359,13 +2492,13 @@ discard block |
||
| 2359 | 2492 | 'new_name' => $temp[2], |
| 2360 | 2493 | )); |
| 2361 | 2494 | // !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet. |
| 2362 | - if ($smcFunc['db_num_rows'] != 1) |
|
| 2363 | - return; |
|
| 2495 | + if ($smcFunc['db_num_rows'] != 1) { |
|
| 2496 | + return; |
|
| 2497 | + } |
|
| 2364 | 2498 | |
| 2365 | 2499 | list (, $current_type) = $smcFunc['db_fetch_assoc']($request); |
| 2366 | 2500 | $smcFunc['db_free_result']($request); |
| 2367 | - } |
|
| 2368 | - else |
|
| 2501 | + } else |
|
| 2369 | 2502 | { |
| 2370 | 2503 | // Do this the old fashion, sure method way. |
| 2371 | 2504 | $request = $smcFunc['db_query']('', ' |
@@ -2376,21 +2509,24 @@ discard block |
||
| 2376 | 2509 | )); |
| 2377 | 2510 | // Mayday! |
| 2378 | 2511 | // !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet. |
| 2379 | - if ($smcFunc['db_num_rows'] == 0) |
|
| 2380 | - return; |
|
| 2512 | + if ($smcFunc['db_num_rows'] == 0) { |
|
| 2513 | + return; |
|
| 2514 | + } |
|
| 2381 | 2515 | |
| 2382 | 2516 | // Oh where, oh where has my little field gone. Oh where can it be... |
| 2383 | - while ($row = $smcFunc['db_query']($request)) |
|
| 2384 | - if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2]) |
|
| 2517 | + while ($row = $smcFunc['db_query']($request)) { |
|
| 2518 | + if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2]) |
|
| 2385 | 2519 | { |
| 2386 | 2520 | $current_type = $row['Type']; |
| 2521 | + } |
|
| 2387 | 2522 | break; |
| 2388 | 2523 | } |
| 2389 | 2524 | } |
| 2390 | 2525 | |
| 2391 | 2526 | // If this doesn't match, the column may of been altered for a reason. |
| 2392 | - if (trim($current_type) != trim($temp[3])) |
|
| 2393 | - $temp[3] = $current_type; |
|
| 2527 | + if (trim($current_type) != trim($temp[3])) { |
|
| 2528 | + $temp[3] = $current_type; |
|
| 2529 | + } |
|
| 2394 | 2530 | |
| 2395 | 2531 | // Piece this back together. |
| 2396 | 2532 | $change['text'] = str_replace('NOT_NULL', 'NOT NULL', implode(' ', $temp)); |
@@ -2402,8 +2538,9 @@ discard block |
||
| 2402 | 2538 | global $start_time, $timeLimitThreshold, $command_line, $custom_warning; |
| 2403 | 2539 | global $step_progress, $is_debug, $upcontext; |
| 2404 | 2540 | |
| 2405 | - if ($_GET['substep'] < $substep) |
|
| 2406 | - $_GET['substep'] = $substep; |
|
| 2541 | + if ($_GET['substep'] < $substep) { |
|
| 2542 | + $_GET['substep'] = $substep; |
|
| 2543 | + } |
|
| 2407 | 2544 | |
| 2408 | 2545 | if ($command_line) |
| 2409 | 2546 | { |
@@ -2416,29 +2553,33 @@ discard block |
||
| 2416 | 2553 | } |
| 2417 | 2554 | |
| 2418 | 2555 | @set_time_limit(300); |
| 2419 | - if (function_exists('apache_reset_timeout')) |
|
| 2420 | - @apache_reset_timeout(); |
|
| 2556 | + if (function_exists('apache_reset_timeout')) { |
|
| 2557 | + @apache_reset_timeout(); |
|
| 2558 | + } |
|
| 2421 | 2559 | |
| 2422 | - if (time() - $start_time <= $timeLimitThreshold) |
|
| 2423 | - return; |
|
| 2560 | + if (time() - $start_time <= $timeLimitThreshold) { |
|
| 2561 | + return; |
|
| 2562 | + } |
|
| 2424 | 2563 | |
| 2425 | 2564 | // Do we have some custom step progress stuff? |
| 2426 | 2565 | if (!empty($step_progress)) |
| 2427 | 2566 | { |
| 2428 | 2567 | $upcontext['substep_progress'] = 0; |
| 2429 | 2568 | $upcontext['substep_progress_name'] = $step_progress['name']; |
| 2430 | - if ($step_progress['current'] > $step_progress['total']) |
|
| 2431 | - $upcontext['substep_progress'] = 99.9; |
|
| 2432 | - else |
|
| 2433 | - $upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100; |
|
| 2569 | + if ($step_progress['current'] > $step_progress['total']) { |
|
| 2570 | + $upcontext['substep_progress'] = 99.9; |
|
| 2571 | + } else { |
|
| 2572 | + $upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100; |
|
| 2573 | + } |
|
| 2434 | 2574 | |
| 2435 | 2575 | // Make it nicely rounded. |
| 2436 | 2576 | $upcontext['substep_progress'] = round($upcontext['substep_progress'], 1); |
| 2437 | 2577 | } |
| 2438 | 2578 | |
| 2439 | 2579 | // If this is XML we just exit right away! |
| 2440 | - if (isset($_GET['xml'])) |
|
| 2441 | - return upgradeExit(); |
|
| 2580 | + if (isset($_GET['xml'])) { |
|
| 2581 | + return upgradeExit(); |
|
| 2582 | + } |
|
| 2442 | 2583 | |
| 2443 | 2584 | // We're going to pause after this! |
| 2444 | 2585 | $upcontext['pause'] = true; |
@@ -2446,13 +2587,15 @@ discard block |
||
| 2446 | 2587 | $upcontext['query_string'] = ''; |
| 2447 | 2588 | foreach ($_GET as $k => $v) |
| 2448 | 2589 | { |
| 2449 | - if ($k != 'data' && $k != 'substep' && $k != 'step') |
|
| 2450 | - $upcontext['query_string'] .= ';' . $k . '=' . $v; |
|
| 2590 | + if ($k != 'data' && $k != 'substep' && $k != 'step') { |
|
| 2591 | + $upcontext['query_string'] .= ';' . $k . '=' . $v; |
|
| 2592 | + } |
|
| 2451 | 2593 | } |
| 2452 | 2594 | |
| 2453 | 2595 | // Custom warning? |
| 2454 | - if (!empty($custom_warning)) |
|
| 2455 | - $upcontext['custom_warning'] = $custom_warning; |
|
| 2596 | + if (!empty($custom_warning)) { |
|
| 2597 | + $upcontext['custom_warning'] = $custom_warning; |
|
| 2598 | + } |
|
| 2456 | 2599 | |
| 2457 | 2600 | upgradeExit(); |
| 2458 | 2601 | } |
@@ -2467,25 +2610,26 @@ discard block |
||
| 2467 | 2610 | ob_implicit_flush(true); |
| 2468 | 2611 | @set_time_limit(600); |
| 2469 | 2612 | |
| 2470 | - if (!isset($_SERVER['argv'])) |
|
| 2471 | - $_SERVER['argv'] = array(); |
|
| 2613 | + if (!isset($_SERVER['argv'])) { |
|
| 2614 | + $_SERVER['argv'] = array(); |
|
| 2615 | + } |
|
| 2472 | 2616 | $_GET['maint'] = 1; |
| 2473 | 2617 | |
| 2474 | 2618 | foreach ($_SERVER['argv'] as $i => $arg) |
| 2475 | 2619 | { |
| 2476 | - if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) |
|
| 2477 | - $_GET['lang'] = $match[1]; |
|
| 2478 | - elseif (preg_match('~^--path=(.+)$~', $arg) != 0) |
|
| 2479 | - continue; |
|
| 2480 | - elseif ($arg == '--no-maintenance') |
|
| 2481 | - $_GET['maint'] = 0; |
|
| 2482 | - elseif ($arg == '--debug') |
|
| 2483 | - $is_debug = true; |
|
| 2484 | - elseif ($arg == '--backup') |
|
| 2485 | - $_POST['backup'] = 1; |
|
| 2486 | - elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) |
|
| 2487 | - $_GET['conv'] = 1; |
|
| 2488 | - elseif ($i != 0) |
|
| 2620 | + if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) { |
|
| 2621 | + $_GET['lang'] = $match[1]; |
|
| 2622 | + } elseif (preg_match('~^--path=(.+)$~', $arg) != 0) { |
|
| 2623 | + continue; |
|
| 2624 | + } elseif ($arg == '--no-maintenance') { |
|
| 2625 | + $_GET['maint'] = 0; |
|
| 2626 | + } elseif ($arg == '--debug') { |
|
| 2627 | + $is_debug = true; |
|
| 2628 | + } elseif ($arg == '--backup') { |
|
| 2629 | + $_POST['backup'] = 1; |
|
| 2630 | + } elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) { |
|
| 2631 | + $_GET['conv'] = 1; |
|
| 2632 | + } elseif ($i != 0) |
|
| 2489 | 2633 | { |
| 2490 | 2634 | echo 'SMF Command-line Upgrader |
| 2491 | 2635 | Usage: /path/to/php -f ' . basename(__FILE__) . ' -- [OPTION]... |
@@ -2499,10 +2643,12 @@ discard block |
||
| 2499 | 2643 | } |
| 2500 | 2644 | } |
| 2501 | 2645 | |
| 2502 | - if (!php_version_check()) |
|
| 2503 | - print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true); |
|
| 2504 | - if (!db_version_check()) |
|
| 2505 | - print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true); |
|
| 2646 | + if (!php_version_check()) { |
|
| 2647 | + print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true); |
|
| 2648 | + } |
|
| 2649 | + if (!db_version_check()) { |
|
| 2650 | + print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true); |
|
| 2651 | + } |
|
| 2506 | 2652 | |
| 2507 | 2653 | // Do some checks to make sure they have proper privileges |
| 2508 | 2654 | db_extend('packages'); |
@@ -2517,34 +2663,39 @@ discard block |
||
| 2517 | 2663 | $drop = $smcFunc['db_drop_table']('{db_prefix}priv_check'); |
| 2518 | 2664 | |
| 2519 | 2665 | // Sorry... we need CREATE, ALTER and DROP |
| 2520 | - if (!$create || !$alter || !$drop) |
|
| 2521 | - 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); |
|
| 2666 | + if (!$create || !$alter || !$drop) { |
|
| 2667 | + 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); |
|
| 2668 | + } |
|
| 2522 | 2669 | |
| 2523 | 2670 | $check = @file_exists($modSettings['theme_dir'] . '/index.template.php') |
| 2524 | 2671 | && @file_exists($sourcedir . '/QueryString.php') |
| 2525 | 2672 | && @file_exists($sourcedir . '/ManageBoards.php'); |
| 2526 | - if (!$check && !isset($modSettings['smfVersion'])) |
|
| 2527 | - print_error('Error: Some files are missing or out-of-date.', true); |
|
| 2673 | + if (!$check && !isset($modSettings['smfVersion'])) { |
|
| 2674 | + print_error('Error: Some files are missing or out-of-date.', true); |
|
| 2675 | + } |
|
| 2528 | 2676 | |
| 2529 | 2677 | // Do a quick version spot check. |
| 2530 | 2678 | $temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096); |
| 2531 | 2679 | preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match); |
| 2532 | - if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) |
|
| 2533 | - print_error('Error: Some files have not yet been updated properly.'); |
|
| 2680 | + if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) { |
|
| 2681 | + print_error('Error: Some files have not yet been updated properly.'); |
|
| 2682 | + } |
|
| 2534 | 2683 | |
| 2535 | 2684 | // Make sure Settings.php is writable. |
| 2536 | 2685 | quickFileWritable($boarddir . '/Settings.php'); |
| 2537 | - if (!is_writable($boarddir . '/Settings.php')) |
|
| 2538 | - print_error('Error: Unable to obtain write access to "Settings.php".', true); |
|
| 2686 | + if (!is_writable($boarddir . '/Settings.php')) { |
|
| 2687 | + print_error('Error: Unable to obtain write access to "Settings.php".', true); |
|
| 2688 | + } |
|
| 2539 | 2689 | |
| 2540 | 2690 | // Make sure Settings_bak.php is writable. |
| 2541 | 2691 | quickFileWritable($boarddir . '/Settings_bak.php'); |
| 2542 | - if (!is_writable($boarddir . '/Settings_bak.php')) |
|
| 2543 | - print_error('Error: Unable to obtain write access to "Settings_bak.php".'); |
|
| 2692 | + if (!is_writable($boarddir . '/Settings_bak.php')) { |
|
| 2693 | + print_error('Error: Unable to obtain write access to "Settings_bak.php".'); |
|
| 2694 | + } |
|
| 2544 | 2695 | |
| 2545 | - if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) |
|
| 2546 | - print_error('Error: Unable to obtain write access to "agreement.txt".'); |
|
| 2547 | - elseif (isset($modSettings['agreement'])) |
|
| 2696 | + if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) { |
|
| 2697 | + print_error('Error: Unable to obtain write access to "agreement.txt".'); |
|
| 2698 | + } elseif (isset($modSettings['agreement'])) |
|
| 2548 | 2699 | { |
| 2549 | 2700 | $fp = fopen($boarddir . '/agreement.txt', 'w'); |
| 2550 | 2701 | fwrite($fp, $modSettings['agreement']); |
@@ -2554,36 +2705,42 @@ discard block |
||
| 2554 | 2705 | // Make sure Themes is writable. |
| 2555 | 2706 | quickFileWritable($modSettings['theme_dir']); |
| 2556 | 2707 | |
| 2557 | - if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) |
|
| 2558 | - print_error('Error: Unable to obtain write access to "Themes".'); |
|
| 2708 | + if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) { |
|
| 2709 | + print_error('Error: Unable to obtain write access to "Themes".'); |
|
| 2710 | + } |
|
| 2559 | 2711 | |
| 2560 | 2712 | // Make sure cache directory exists and is writable! |
| 2561 | 2713 | $cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir; |
| 2562 | - if (!file_exists($cachedir_temp)) |
|
| 2563 | - @mkdir($cachedir_temp); |
|
| 2714 | + if (!file_exists($cachedir_temp)) { |
|
| 2715 | + @mkdir($cachedir_temp); |
|
| 2716 | + } |
|
| 2564 | 2717 | |
| 2565 | 2718 | // Make sure the cache temp dir is writable. |
| 2566 | 2719 | quickFileWritable($cachedir_temp); |
| 2567 | 2720 | |
| 2568 | - if (!is_writable($cachedir_temp)) |
|
| 2569 | - print_error('Error: Unable to obtain write access to "cache".', true); |
|
| 2721 | + if (!is_writable($cachedir_temp)) { |
|
| 2722 | + print_error('Error: Unable to obtain write access to "cache".', true); |
|
| 2723 | + } |
|
| 2570 | 2724 | |
| 2571 | 2725 | // Make sure db_last_error.php is writable. |
| 2572 | 2726 | quickFileWritable($cachedir_temp . '/db_last_error.php'); |
| 2573 | - if (!is_writable($cachedir_temp . '/db_last_error.php')) |
|
| 2574 | - print_error('Error: Unable to obtain write access to "db_last_error.php".'); |
|
| 2727 | + if (!is_writable($cachedir_temp . '/db_last_error.php')) { |
|
| 2728 | + print_error('Error: Unable to obtain write access to "db_last_error.php".'); |
|
| 2729 | + } |
|
| 2575 | 2730 | |
| 2576 | - if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) |
|
| 2577 | - print_error('Error: Unable to find language files!', true); |
|
| 2578 | - else |
|
| 2731 | + if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) { |
|
| 2732 | + print_error('Error: Unable to find language files!', true); |
|
| 2733 | + } else |
|
| 2579 | 2734 | { |
| 2580 | 2735 | $temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096); |
| 2581 | 2736 | preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match); |
| 2582 | 2737 | |
| 2583 | - if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) |
|
| 2584 | - print_error('Error: Language files out of date.', true); |
|
| 2585 | - if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) |
|
| 2586 | - print_error('Error: Install language is missing for selected language.', true); |
|
| 2738 | + if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) { |
|
| 2739 | + print_error('Error: Language files out of date.', true); |
|
| 2740 | + } |
|
| 2741 | + if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) { |
|
| 2742 | + print_error('Error: Install language is missing for selected language.', true); |
|
| 2743 | + } |
|
| 2587 | 2744 | |
| 2588 | 2745 | // Otherwise include it! |
| 2589 | 2746 | require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'); |
@@ -2603,8 +2760,9 @@ discard block |
||
| 2603 | 2760 | global $db_prefix, $db_type, $command_line, $support_js, $txt; |
| 2604 | 2761 | |
| 2605 | 2762 | // Done it already? |
| 2606 | - if (!empty($_POST['utf8_done'])) |
|
| 2607 | - return true; |
|
| 2763 | + if (!empty($_POST['utf8_done'])) { |
|
| 2764 | + return true; |
|
| 2765 | + } |
|
| 2608 | 2766 | |
| 2609 | 2767 | // First make sure they aren't already on UTF-8 before we go anywhere... |
| 2610 | 2768 | if ($db_type == 'postgresql' || ($db_character_set === 'utf8' && !empty($modSettings['global_character_set']) && $modSettings['global_character_set'] === 'UTF-8')) |
@@ -2617,8 +2775,7 @@ discard block |
||
| 2617 | 2775 | ); |
| 2618 | 2776 | |
| 2619 | 2777 | return true; |
| 2620 | - } |
|
| 2621 | - else |
|
| 2778 | + } else |
|
| 2622 | 2779 | { |
| 2623 | 2780 | $upcontext['page_title'] = $txt['converting_utf8']; |
| 2624 | 2781 | $upcontext['sub_template'] = isset($_GET['xml']) ? 'convert_xml' : 'convert_utf8'; |
@@ -2662,8 +2819,9 @@ discard block |
||
| 2662 | 2819 | ) |
| 2663 | 2820 | ); |
| 2664 | 2821 | $db_charsets = array(); |
| 2665 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 2666 | - $db_charsets[] = $row['Charset']; |
|
| 2822 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 2823 | + $db_charsets[] = $row['Charset']; |
|
| 2824 | + } |
|
| 2667 | 2825 | |
| 2668 | 2826 | $smcFunc['db_free_result']($request); |
| 2669 | 2827 | |
@@ -2699,13 +2857,15 @@ discard block |
||
| 2699 | 2857 | // If there's a fulltext index, we need to drop it first... |
| 2700 | 2858 | if ($request !== false || $smcFunc['db_num_rows']($request) != 0) |
| 2701 | 2859 | { |
| 2702 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 2703 | - if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT')) |
|
| 2860 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 2861 | + if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT')) |
|
| 2704 | 2862 | $upcontext['fulltext_index'][] = $row['Key_name']; |
| 2863 | + } |
|
| 2705 | 2864 | $smcFunc['db_free_result']($request); |
| 2706 | 2865 | |
| 2707 | - if (isset($upcontext['fulltext_index'])) |
|
| 2708 | - $upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']); |
|
| 2866 | + if (isset($upcontext['fulltext_index'])) { |
|
| 2867 | + $upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']); |
|
| 2868 | + } |
|
| 2709 | 2869 | } |
| 2710 | 2870 | |
| 2711 | 2871 | // Drop it and make a note... |
@@ -2895,8 +3055,9 @@ discard block |
||
| 2895 | 3055 | $replace = '%field%'; |
| 2896 | 3056 | |
| 2897 | 3057 | // Build a huge REPLACE statement... |
| 2898 | - foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) |
|
| 2899 | - $replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')'; |
|
| 3058 | + foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) { |
|
| 3059 | + $replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')'; |
|
| 3060 | + } |
|
| 2900 | 3061 | } |
| 2901 | 3062 | |
| 2902 | 3063 | // Get a list of table names ahead of time... This makes it easier to set our substep and such |
@@ -2906,9 +3067,10 @@ discard block |
||
| 2906 | 3067 | $upcontext['table_count'] = count($queryTables); |
| 2907 | 3068 | |
| 2908 | 3069 | // What ones have we already done? |
| 2909 | - foreach ($queryTables as $id => $table) |
|
| 2910 | - if ($id < $_GET['substep']) |
|
| 3070 | + foreach ($queryTables as $id => $table) { |
|
| 3071 | + if ($id < $_GET['substep']) |
|
| 2911 | 3072 | $upcontext['previous_tables'][] = $table; |
| 3073 | + } |
|
| 2912 | 3074 | |
| 2913 | 3075 | $upcontext['cur_table_num'] = $_GET['substep']; |
| 2914 | 3076 | $upcontext['cur_table_name'] = str_replace($db_prefix, '', $queryTables[$_GET['substep']]); |
@@ -2945,8 +3107,9 @@ discard block |
||
| 2945 | 3107 | nextSubstep($substep); |
| 2946 | 3108 | |
| 2947 | 3109 | // Just to make sure it doesn't time out. |
| 2948 | - if (function_exists('apache_reset_timeout')) |
|
| 2949 | - @apache_reset_timeout(); |
|
| 3110 | + if (function_exists('apache_reset_timeout')) { |
|
| 3111 | + @apache_reset_timeout(); |
|
| 3112 | + } |
|
| 2950 | 3113 | |
| 2951 | 3114 | $table_charsets = array(); |
| 2952 | 3115 | |
@@ -2969,8 +3132,9 @@ discard block |
||
| 2969 | 3132 | |
| 2970 | 3133 | // Build structure of columns to operate on organized by charset; only operate on columns not yet utf8 |
| 2971 | 3134 | if ($charset != 'utf8') { |
| 2972 | - if (!isset($table_charsets[$charset])) |
|
| 2973 | - $table_charsets[$charset] = array(); |
|
| 3135 | + if (!isset($table_charsets[$charset])) { |
|
| 3136 | + $table_charsets[$charset] = array(); |
|
| 3137 | + } |
|
| 2974 | 3138 | |
| 2975 | 3139 | $table_charsets[$charset][] = $column_info; |
| 2976 | 3140 | } |
@@ -3011,10 +3175,11 @@ discard block |
||
| 3011 | 3175 | if (isset($translation_tables[$upcontext['charset_detected']])) |
| 3012 | 3176 | { |
| 3013 | 3177 | $update = ''; |
| 3014 | - foreach ($table_charsets as $charset => $columns) |
|
| 3015 | - foreach ($columns as $column) |
|
| 3178 | + foreach ($table_charsets as $charset => $columns) { |
|
| 3179 | + foreach ($columns as $column) |
|
| 3016 | 3180 | $update .= ' |
| 3017 | 3181 | ' . $column['Field'] . ' = ' . strtr($replace, array('%field%' => $column['Field'])) . ','; |
| 3182 | + } |
|
| 3018 | 3183 | |
| 3019 | 3184 | $smcFunc['db_query']('', ' |
| 3020 | 3185 | UPDATE {raw:table_name} |
@@ -3039,8 +3204,9 @@ discard block |
||
| 3039 | 3204 | // Now do the actual conversion (if still needed). |
| 3040 | 3205 | if ($charsets[$upcontext['charset_detected']] !== 'utf8') |
| 3041 | 3206 | { |
| 3042 | - if ($command_line) |
|
| 3043 | - echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...'; |
|
| 3207 | + if ($command_line) { |
|
| 3208 | + echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...'; |
|
| 3209 | + } |
|
| 3044 | 3210 | |
| 3045 | 3211 | $smcFunc['db_query']('', ' |
| 3046 | 3212 | ALTER TABLE {raw:table_name} |
@@ -3050,12 +3216,14 @@ discard block |
||
| 3050 | 3216 | ) |
| 3051 | 3217 | ); |
| 3052 | 3218 | |
| 3053 | - if ($command_line) |
|
| 3054 | - echo " done.\n"; |
|
| 3219 | + if ($command_line) { |
|
| 3220 | + echo " done.\n"; |
|
| 3221 | + } |
|
| 3055 | 3222 | } |
| 3056 | 3223 | // If this is XML to keep it nice for the user do one table at a time anyway! |
| 3057 | - if (isset($_GET['xml']) && $upcontext['cur_table_num'] < $upcontext['table_count']) |
|
| 3058 | - return upgradeExit(); |
|
| 3224 | + if (isset($_GET['xml']) && $upcontext['cur_table_num'] < $upcontext['table_count']) { |
|
| 3225 | + return upgradeExit(); |
|
| 3226 | + } |
|
| 3059 | 3227 | } |
| 3060 | 3228 | |
| 3061 | 3229 | $prev_charset = empty($translation_tables[$upcontext['charset_detected']]) ? $charsets[$upcontext['charset_detected']] : $translation_tables[$upcontext['charset_detected']]; |
@@ -3084,8 +3252,8 @@ discard block |
||
| 3084 | 3252 | ); |
| 3085 | 3253 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 3086 | 3254 | { |
| 3087 | - 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) |
|
| 3088 | - $smcFunc['db_query']('', ' |
|
| 3255 | + 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) { |
|
| 3256 | + $smcFunc['db_query']('', ' |
|
| 3089 | 3257 | UPDATE {db_prefix}log_actions |
| 3090 | 3258 | SET extra = {string:extra} |
| 3091 | 3259 | WHERE id_action = {int:current_action}', |
@@ -3094,6 +3262,7 @@ discard block |
||
| 3094 | 3262 | 'extra' => $matches[1] . strlen($matches[3]) . ':"' . $matches[3] . '"' . $matches[4], |
| 3095 | 3263 | ) |
| 3096 | 3264 | ); |
| 3265 | + } |
|
| 3097 | 3266 | } |
| 3098 | 3267 | $smcFunc['db_free_result']($request); |
| 3099 | 3268 | |
@@ -3115,15 +3284,17 @@ discard block |
||
| 3115 | 3284 | // First thing's first - did we already do this? |
| 3116 | 3285 | if (!empty($modSettings['json_done'])) |
| 3117 | 3286 | { |
| 3118 | - if ($command_line) |
|
| 3119 | - return DeleteUpgrade(); |
|
| 3120 | - else |
|
| 3121 | - return true; |
|
| 3287 | + if ($command_line) { |
|
| 3288 | + return DeleteUpgrade(); |
|
| 3289 | + } else { |
|
| 3290 | + return true; |
|
| 3291 | + } |
|
| 3122 | 3292 | } |
| 3123 | 3293 | |
| 3124 | 3294 | // Done it already - js wise? |
| 3125 | - if (!empty($_POST['json_done'])) |
|
| 3126 | - return true; |
|
| 3295 | + if (!empty($_POST['json_done'])) { |
|
| 3296 | + return true; |
|
| 3297 | + } |
|
| 3127 | 3298 | |
| 3128 | 3299 | // List of tables affected by this function |
| 3129 | 3300 | // name => array('key', col1[,col2|true[,col3]]) |
@@ -3155,12 +3326,14 @@ discard block |
||
| 3155 | 3326 | $upcontext['cur_table_name'] = isset($keys[$_GET['substep']]) ? $keys[$_GET['substep']] : $keys[0]; |
| 3156 | 3327 | $upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100); |
| 3157 | 3328 | |
| 3158 | - foreach ($keys as $id => $table) |
|
| 3159 | - if ($id < $_GET['substep']) |
|
| 3329 | + foreach ($keys as $id => $table) { |
|
| 3330 | + if ($id < $_GET['substep']) |
|
| 3160 | 3331 | $upcontext['previous_tables'][] = $table; |
| 3332 | + } |
|
| 3161 | 3333 | |
| 3162 | - if ($command_line) |
|
| 3163 | - echo 'Converting data from serialize() to json_encode().'; |
|
| 3334 | + if ($command_line) { |
|
| 3335 | + echo 'Converting data from serialize() to json_encode().'; |
|
| 3336 | + } |
|
| 3164 | 3337 | |
| 3165 | 3338 | if (!$support_js || isset($_GET['xml'])) |
| 3166 | 3339 | { |
@@ -3200,8 +3373,9 @@ discard block |
||
| 3200 | 3373 | |
| 3201 | 3374 | // Loop through and fix these... |
| 3202 | 3375 | $new_settings = array(); |
| 3203 | - if ($command_line) |
|
| 3204 | - echo "\n" . 'Fixing some settings...'; |
|
| 3376 | + if ($command_line) { |
|
| 3377 | + echo "\n" . 'Fixing some settings...'; |
|
| 3378 | + } |
|
| 3205 | 3379 | |
| 3206 | 3380 | foreach ($serialized_settings as $var) |
| 3207 | 3381 | { |
@@ -3209,22 +3383,24 @@ discard block |
||
| 3209 | 3383 | { |
| 3210 | 3384 | // Attempt to unserialize the setting |
| 3211 | 3385 | $temp = @safe_unserialize($modSettings[$var]); |
| 3212 | - if (!$temp && $command_line) |
|
| 3213 | - echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping."; |
|
| 3214 | - elseif ($temp !== false) |
|
| 3215 | - $new_settings[$var] = json_encode($temp); |
|
| 3386 | + if (!$temp && $command_line) { |
|
| 3387 | + echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping."; |
|
| 3388 | + } elseif ($temp !== false) { |
|
| 3389 | + $new_settings[$var] = json_encode($temp); |
|
| 3390 | + } |
|
| 3216 | 3391 | } |
| 3217 | 3392 | } |
| 3218 | 3393 | |
| 3219 | 3394 | // Update everything at once |
| 3220 | - if (!function_exists('cache_put_data')) |
|
| 3221 | - require_once($sourcedir . '/Load.php'); |
|
| 3395 | + if (!function_exists('cache_put_data')) { |
|
| 3396 | + require_once($sourcedir . '/Load.php'); |
|
| 3397 | + } |
|
| 3222 | 3398 | updateSettings($new_settings, true); |
| 3223 | 3399 | |
| 3224 | - if ($command_line) |
|
| 3225 | - echo ' done.'; |
|
| 3226 | - } |
|
| 3227 | - elseif ($table == 'themes') |
|
| 3400 | + if ($command_line) { |
|
| 3401 | + echo ' done.'; |
|
| 3402 | + } |
|
| 3403 | + } elseif ($table == 'themes') |
|
| 3228 | 3404 | { |
| 3229 | 3405 | // Finally, fix the admin prefs. Unfortunately this is stored per theme, but hopefully they only have one theme installed at this point... |
| 3230 | 3406 | $query = $smcFunc['db_query']('', ' |
@@ -3243,10 +3419,11 @@ discard block |
||
| 3243 | 3419 | |
| 3244 | 3420 | if ($command_line) |
| 3245 | 3421 | { |
| 3246 | - if ($temp === false) |
|
| 3247 | - echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.'; |
|
| 3248 | - else |
|
| 3249 | - echo "\n" . 'Fixing admin preferences...'; |
|
| 3422 | + if ($temp === false) { |
|
| 3423 | + echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.'; |
|
| 3424 | + } else { |
|
| 3425 | + echo "\n" . 'Fixing admin preferences...'; |
|
| 3426 | + } |
|
| 3250 | 3427 | } |
| 3251 | 3428 | |
| 3252 | 3429 | if ($temp !== false) |
@@ -3268,15 +3445,15 @@ discard block |
||
| 3268 | 3445 | ) |
| 3269 | 3446 | ); |
| 3270 | 3447 | |
| 3271 | - if ($command_line) |
|
| 3272 | - echo ' done.'; |
|
| 3448 | + if ($command_line) { |
|
| 3449 | + echo ' done.'; |
|
| 3450 | + } |
|
| 3273 | 3451 | } |
| 3274 | 3452 | } |
| 3275 | 3453 | |
| 3276 | 3454 | $smcFunc['db_free_result']($query); |
| 3277 | 3455 | } |
| 3278 | - } |
|
| 3279 | - else |
|
| 3456 | + } else |
|
| 3280 | 3457 | { |
| 3281 | 3458 | // First item is always the key... |
| 3282 | 3459 | $key = $info[0]; |
@@ -3287,8 +3464,7 @@ discard block |
||
| 3287 | 3464 | { |
| 3288 | 3465 | $col_select = $info[1]; |
| 3289 | 3466 | $where = ' WHERE ' . $info[1] . ' != {empty}'; |
| 3290 | - } |
|
| 3291 | - else |
|
| 3467 | + } else |
|
| 3292 | 3468 | { |
| 3293 | 3469 | $col_select = implode(', ', $info); |
| 3294 | 3470 | } |
@@ -3321,8 +3497,7 @@ discard block |
||
| 3321 | 3497 | if ($temp === false && $command_line) |
| 3322 | 3498 | { |
| 3323 | 3499 | echo "\nFailed to unserialize " . $row[$col] . "... Skipping\n"; |
| 3324 | - } |
|
| 3325 | - else |
|
| 3500 | + } else |
|
| 3326 | 3501 | { |
| 3327 | 3502 | $row[$col] = json_encode($temp); |
| 3328 | 3503 | |
@@ -3347,16 +3522,18 @@ discard block |
||
| 3347 | 3522 | } |
| 3348 | 3523 | } |
| 3349 | 3524 | |
| 3350 | - if ($command_line) |
|
| 3351 | - echo ' done.'; |
|
| 3525 | + if ($command_line) { |
|
| 3526 | + echo ' done.'; |
|
| 3527 | + } |
|
| 3352 | 3528 | |
| 3353 | 3529 | // Free up some memory... |
| 3354 | 3530 | $smcFunc['db_free_result']($query); |
| 3355 | 3531 | } |
| 3356 | 3532 | } |
| 3357 | 3533 | // If this is XML to keep it nice for the user do one table at a time anyway! |
| 3358 | - if (isset($_GET['xml'])) |
|
| 3359 | - return upgradeExit(); |
|
| 3534 | + if (isset($_GET['xml'])) { |
|
| 3535 | + return upgradeExit(); |
|
| 3536 | + } |
|
| 3360 | 3537 | } |
| 3361 | 3538 | |
| 3362 | 3539 | if ($command_line) |
@@ -3371,8 +3548,9 @@ discard block |
||
| 3371 | 3548 | |
| 3372 | 3549 | $_GET['substep'] = 0; |
| 3373 | 3550 | // Make sure we move on! |
| 3374 | - if ($command_line) |
|
| 3375 | - return DeleteUpgrade(); |
|
| 3551 | + if ($command_line) { |
|
| 3552 | + return DeleteUpgrade(); |
|
| 3553 | + } |
|
| 3376 | 3554 | |
| 3377 | 3555 | return true; |
| 3378 | 3556 | } |
@@ -3429,14 +3607,16 @@ discard block |
||
| 3429 | 3607 | global $upcontext, $txt, $settings; |
| 3430 | 3608 | |
| 3431 | 3609 | // Don't call me twice! |
| 3432 | - if (!empty($upcontext['chmod_called'])) |
|
| 3433 | - return; |
|
| 3610 | + if (!empty($upcontext['chmod_called'])) { |
|
| 3611 | + return; |
|
| 3612 | + } |
|
| 3434 | 3613 | |
| 3435 | 3614 | $upcontext['chmod_called'] = true; |
| 3436 | 3615 | |
| 3437 | 3616 | // Nothing? |
| 3438 | - if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) |
|
| 3439 | - return; |
|
| 3617 | + if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) { |
|
| 3618 | + return; |
|
| 3619 | + } |
|
| 3440 | 3620 | |
| 3441 | 3621 | // Was it a problem with Windows? |
| 3442 | 3622 | if (!empty($upcontext['chmod']['ftp_error']) && $upcontext['chmod']['ftp_error'] == 'total_mess') |
@@ -3468,11 +3648,12 @@ discard block |
||
| 3468 | 3648 | content.write(\'<div class="windowbg description">\n\t\t\t<h4>', $txt['upgrade_ftp_files'], '</h4>\n\t\t\t\'); |
| 3469 | 3649 | content.write(\'<p>', implode('<br>\n\t\t\t', $upcontext['chmod']['files']), '</p>\n\t\t\t\');'; |
| 3470 | 3650 | |
| 3471 | - if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') |
|
| 3472 | - echo ' |
|
| 3651 | + if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') { |
|
| 3652 | + echo ' |
|
| 3473 | 3653 | content.write(\'<hr>\n\t\t\t\'); |
| 3474 | 3654 | content.write(\'<p>', $txt['upgrade_ftp_shell'], '</p>\n\t\t\t\'); |
| 3475 | 3655 | content.write(\'<tt># chmod a+w ', implode(' ', $upcontext['chmod']['files']), '</tt>\n\t\t\t\');'; |
| 3656 | + } |
|
| 3476 | 3657 | |
| 3477 | 3658 | echo ' |
| 3478 | 3659 | content.write(\'<a href="javascript:self.close();">close</a>\n\t\t</div>\n\t</body>\n</html>\'); |
@@ -3480,16 +3661,18 @@ discard block |
||
| 3480 | 3661 | } |
| 3481 | 3662 | </script>'; |
| 3482 | 3663 | |
| 3483 | - if (!empty($upcontext['chmod']['ftp_error'])) |
|
| 3484 | - echo ' |
|
| 3664 | + if (!empty($upcontext['chmod']['ftp_error'])) { |
|
| 3665 | + echo ' |
|
| 3485 | 3666 | <div class="error_message red"> |
| 3486 | 3667 | <p>', $txt['upgrade_ftp_error'], '<p> |
| 3487 | 3668 | <code>', $upcontext['chmod']['ftp_error'], '</code> |
| 3488 | 3669 | </div>'; |
| 3670 | + } |
|
| 3489 | 3671 | |
| 3490 | - if (empty($upcontext['chmod_in_form'])) |
|
| 3491 | - echo ' |
|
| 3672 | + if (empty($upcontext['chmod_in_form'])) { |
|
| 3673 | + echo ' |
|
| 3492 | 3674 | <form action="', $upcontext['form_url'], '" method="post">'; |
| 3675 | + } |
|
| 3493 | 3676 | |
| 3494 | 3677 | echo ' |
| 3495 | 3678 | <dl class="settings"> |
@@ -3531,9 +3714,10 @@ discard block |
||
| 3531 | 3714 | <input type="submit" value="', $txt['ftp_connect'], '" class="button"> |
| 3532 | 3715 | </div>'; |
| 3533 | 3716 | |
| 3534 | - if (empty($upcontext['chmod_in_form'])) |
|
| 3535 | - echo ' |
|
| 3717 | + if (empty($upcontext['chmod_in_form'])) { |
|
| 3718 | + echo ' |
|
| 3536 | 3719 | </form>'; |
| 3720 | + } |
|
| 3537 | 3721 | |
| 3538 | 3722 | echo ' |
| 3539 | 3723 | </div><!-- .panel -->'; |
@@ -3597,9 +3781,10 @@ discard block |
||
| 3597 | 3781 | <h2>', $txt['upgrade_progress'], '</h2> |
| 3598 | 3782 | <ul>'; |
| 3599 | 3783 | |
| 3600 | - foreach ($upcontext['steps'] as $num => $step) |
|
| 3601 | - echo ' |
|
| 3784 | + foreach ($upcontext['steps'] as $num => $step) { |
|
| 3785 | + echo ' |
|
| 3602 | 3786 | <li class="', $num < $upcontext['current_step'] ? 'stepdone' : ($num == $upcontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>'; |
| 3787 | + } |
|
| 3603 | 3788 | |
| 3604 | 3789 | echo ' |
| 3605 | 3790 | </ul> |
@@ -3612,13 +3797,14 @@ discard block |
||
| 3612 | 3797 | <span id="overall_text">', $upcontext['overall_percent'], '%</span> |
| 3613 | 3798 | </div>'; |
| 3614 | 3799 | |
| 3615 | - if (isset($upcontext['step_progress'])) |
|
| 3616 | - echo ' |
|
| 3800 | + if (isset($upcontext['step_progress'])) { |
|
| 3801 | + echo ' |
|
| 3617 | 3802 | <div id="progress_bar_step" class="progress_bar progress_yellow"> |
| 3618 | 3803 | <h3>', $txt['upgrade_step_progress'], '</h3> |
| 3619 | 3804 | <div id="step_progress" class="bar" style="width: ', $upcontext['step_progress'], '%;"></div> |
| 3620 | 3805 | <span id="step_text">', $upcontext['step_progress'], '%</span> |
| 3621 | 3806 | </div>'; |
| 3807 | + } |
|
| 3622 | 3808 | |
| 3623 | 3809 | echo ' |
| 3624 | 3810 | <div id="substep_bar_div" class="progress_bar ', isset($upcontext['substep_progress']) ? '' : 'hidden', '"> |
@@ -3649,31 +3835,35 @@ discard block |
||
| 3649 | 3835 | { |
| 3650 | 3836 | global $upcontext, $txt; |
| 3651 | 3837 | |
| 3652 | - if (!empty($upcontext['pause'])) |
|
| 3653 | - echo ' |
|
| 3838 | + if (!empty($upcontext['pause'])) { |
|
| 3839 | + echo ' |
|
| 3654 | 3840 | <em>', $txt['upgrade_incomplete'], '.</em><br> |
| 3655 | 3841 | |
| 3656 | 3842 | <h2 style="margin-top: 2ex;">', $txt['upgrade_not_quite_done'], '</h2> |
| 3657 | 3843 | <h3> |
| 3658 | 3844 | ', $txt['upgrade_paused_overload'], ' |
| 3659 | 3845 | </h3>'; |
| 3846 | + } |
|
| 3660 | 3847 | |
| 3661 | - if (!empty($upcontext['custom_warning'])) |
|
| 3662 | - echo ' |
|
| 3848 | + if (!empty($upcontext['custom_warning'])) { |
|
| 3849 | + echo ' |
|
| 3663 | 3850 | <div class="errorbox"> |
| 3664 | 3851 | <h3>', $txt['upgrade_note'], '</h3> |
| 3665 | 3852 | ', $upcontext['custom_warning'], ' |
| 3666 | 3853 | </div>'; |
| 3854 | + } |
|
| 3667 | 3855 | |
| 3668 | 3856 | echo ' |
| 3669 | 3857 | <div class="righttext" style="margin: 1ex;">'; |
| 3670 | 3858 | |
| 3671 | - if (!empty($upcontext['continue'])) |
|
| 3672 | - echo ' |
|
| 3859 | + if (!empty($upcontext['continue'])) { |
|
| 3860 | + echo ' |
|
| 3673 | 3861 | <input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '"', $upcontext['continue'] == 2 ? ' disabled' : '', ' class="button">'; |
| 3674 | - if (!empty($upcontext['skip'])) |
|
| 3675 | - echo ' |
|
| 3862 | + } |
|
| 3863 | + if (!empty($upcontext['skip'])) { |
|
| 3864 | + echo ' |
|
| 3676 | 3865 | <input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="dontSubmit = true; document.getElementById(\'contbutt\').disabled = \'disabled\'; return true;" class="button">'; |
| 3866 | + } |
|
| 3677 | 3867 | |
| 3678 | 3868 | echo ' |
| 3679 | 3869 | </div> |
@@ -3724,11 +3914,12 @@ discard block |
||
| 3724 | 3914 | echo '<', '?xml version="1.0" encoding="UTF-8"?', '> |
| 3725 | 3915 | <smf>'; |
| 3726 | 3916 | |
| 3727 | - if (!empty($upcontext['get_data'])) |
|
| 3728 | - foreach ($upcontext['get_data'] as $k => $v) |
|
| 3917 | + if (!empty($upcontext['get_data'])) { |
|
| 3918 | + foreach ($upcontext['get_data'] as $k => $v) |
|
| 3729 | 3919 | echo ' |
| 3730 | 3920 | <get key="', $k, '">', $v, '</get>'; |
| 3731 | -} |
|
| 3921 | + } |
|
| 3922 | + } |
|
| 3732 | 3923 | |
| 3733 | 3924 | function template_xml_below() |
| 3734 | 3925 | { |
@@ -3768,20 +3959,22 @@ discard block |
||
| 3768 | 3959 | template_chmod(); |
| 3769 | 3960 | |
| 3770 | 3961 | // For large, pre 1.1 RC2 forums give them a warning about the possible impact of this upgrade! |
| 3771 | - if ($upcontext['is_large_forum']) |
|
| 3772 | - echo ' |
|
| 3962 | + if ($upcontext['is_large_forum']) { |
|
| 3963 | + echo ' |
|
| 3773 | 3964 | <div class="errorbox"> |
| 3774 | 3965 | <h3>', $txt['upgrade_warning'], '</h3> |
| 3775 | 3966 | ', $txt['upgrade_warning_lots_data'], ' |
| 3776 | 3967 | </div>'; |
| 3968 | + } |
|
| 3777 | 3969 | |
| 3778 | 3970 | // A warning message? |
| 3779 | - if (!empty($upcontext['warning'])) |
|
| 3780 | - echo ' |
|
| 3971 | + if (!empty($upcontext['warning'])) { |
|
| 3972 | + echo ' |
|
| 3781 | 3973 | <div class="errorbox"> |
| 3782 | 3974 | <h3>', $txt['upgrade_warning'], '</h3> |
| 3783 | 3975 | ', $upcontext['warning'], ' |
| 3784 | 3976 | </div>'; |
| 3977 | + } |
|
| 3785 | 3978 | |
| 3786 | 3979 | // Paths are incorrect? |
| 3787 | 3980 | echo ' |
@@ -3812,16 +4005,18 @@ discard block |
||
| 3812 | 4005 | <p>', sprintf($txt[$agoTxt], $ago_seconds, $ago_minutes, $ago_hours), '</p> |
| 3813 | 4006 | <p>', sprintf($txt[$updatedTxt], $updated_seconds, $updated_minutes, $updated_hours), '</p>'; |
| 3814 | 4007 | |
| 3815 | - if ($updated < 600) |
|
| 3816 | - echo ' |
|
| 4008 | + if ($updated < 600) { |
|
| 4009 | + echo ' |
|
| 3817 | 4010 | <p>', $txt['upgrade_run_script'], ' ', $upcontext['user']['name'],' ', $txt['upgrade_run_script2'], '</p>'; |
| 4011 | + } |
|
| 3818 | 4012 | |
| 3819 | - if ($updated > $upcontext['inactive_timeout']) |
|
| 3820 | - echo ' |
|
| 4013 | + if ($updated > $upcontext['inactive_timeout']) { |
|
| 4014 | + echo ' |
|
| 3821 | 4015 | <p>',$txt['upgrade_run'], '</p>'; |
| 3822 | - else |
|
| 3823 | - echo ' |
|
| 4016 | + } else { |
|
| 4017 | + echo ' |
|
| 3824 | 4018 | <p>', $txt['upgrade_script_timeout'], ' ', $upcontext['user']['name'], ' ', $txt['upgrade_script_timeout2'], ' ', ($upcontext['inactive_timeout'] > 120 ? round($upcontext['inactive_timeout'] / 60, 1) . ' minutes!' : $upcontext['inactive_timeout'] . ' seconds!'), '</p>'; |
| 4019 | + } |
|
| 3825 | 4020 | |
| 3826 | 4021 | echo ' |
| 3827 | 4022 | </div>'; |
@@ -3837,9 +4032,10 @@ discard block |
||
| 3837 | 4032 | <dd> |
| 3838 | 4033 | <input type="text" name="user" value="', !empty($upcontext['username']) ? $upcontext['username'] : '', '"', $disable_security ? ' disabled' : '', '>'; |
| 3839 | 4034 | |
| 3840 | - if (!empty($upcontext['username_incorrect'])) |
|
| 3841 | - echo ' |
|
| 4035 | + if (!empty($upcontext['username_incorrect'])) { |
|
| 4036 | + echo ' |
|
| 3842 | 4037 | <div class="smalltext red">', $txt['upgrade_wrong_username'], '</div>'; |
| 4038 | + } |
|
| 3843 | 4039 | |
| 3844 | 4040 | echo ' |
| 3845 | 4041 | </dd> |
@@ -3850,9 +4046,10 @@ discard block |
||
| 3850 | 4046 | <input type="password" name="passwrd" value=""', $disable_security ? ' disabled' : '', '> |
| 3851 | 4047 | <input type="hidden" name="hash_passwrd" value="">'; |
| 3852 | 4048 | |
| 3853 | - if (!empty($upcontext['password_failed'])) |
|
| 3854 | - echo ' |
|
| 4049 | + if (!empty($upcontext['password_failed'])) { |
|
| 4050 | + echo ' |
|
| 3855 | 4051 | <div class="smalltext red">', $txt['upgrade_wrong_password'], '</div>'; |
| 4052 | + } |
|
| 3856 | 4053 | |
| 3857 | 4054 | echo ' |
| 3858 | 4055 | </dd>'; |
@@ -3920,12 +4117,13 @@ discard block |
||
| 3920 | 4117 | <form action="', $upcontext['form_url'], '" method="post" name="upform" id="upform">'; |
| 3921 | 4118 | |
| 3922 | 4119 | // Warning message? |
| 3923 | - if (!empty($upcontext['upgrade_options_warning'])) |
|
| 3924 | - echo ' |
|
| 4120 | + if (!empty($upcontext['upgrade_options_warning'])) { |
|
| 4121 | + echo ' |
|
| 3925 | 4122 | <div class="errorbox"> |
| 3926 | 4123 | <h3>', $txt['upgrade_warning'] ,'</h3> |
| 3927 | 4124 | ', $upcontext['upgrade_options_warning'], ' |
| 3928 | 4125 | </div>'; |
| 4126 | + } |
|
| 3929 | 4127 | |
| 3930 | 4128 | echo ' |
| 3931 | 4129 | <ul class="upgrade_settings"> |
@@ -3954,12 +4152,13 @@ discard block |
||
| 3954 | 4152 | <label for="empty_error">', $txt['upgrade_empty_errlog'], '</label> |
| 3955 | 4153 | </li>'; |
| 3956 | 4154 | |
| 3957 | - if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) |
|
| 3958 | - echo ' |
|
| 4155 | + if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) { |
|
| 4156 | + echo ' |
|
| 3959 | 4157 | <li> |
| 3960 | 4158 | <input type="checkbox" name="delete_karma" id="delete_karma" value="1"> |
| 3961 | 4159 | <label for="delete_karma">', $txt['upgrade_delete_karma'], '</label> |
| 3962 | 4160 | </li>'; |
| 4161 | + } |
|
| 3963 | 4162 | |
| 3964 | 4163 | echo ' |
| 3965 | 4164 | <li> |
@@ -3999,10 +4198,11 @@ discard block |
||
| 3999 | 4198 | </div>'; |
| 4000 | 4199 | |
| 4001 | 4200 | // Dont any tables so far? |
| 4002 | - if (!empty($upcontext['previous_tables'])) |
|
| 4003 | - foreach ($upcontext['previous_tables'] as $table) |
|
| 4201 | + if (!empty($upcontext['previous_tables'])) { |
|
| 4202 | + foreach ($upcontext['previous_tables'] as $table) |
|
| 4004 | 4203 | echo ' |
| 4005 | 4204 | <br>', $txt['upgrade_completed_table'], ' "', $table, '".'; |
| 4205 | + } |
|
| 4006 | 4206 | |
| 4007 | 4207 | echo ' |
| 4008 | 4208 | <h3 id="current_tab"> |
@@ -4041,12 +4241,13 @@ discard block |
||
| 4041 | 4241 | updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');'; |
| 4042 | 4242 | |
| 4043 | 4243 | // If debug flood the screen. |
| 4044 | - if ($is_debug) |
|
| 4045 | - echo ' |
|
| 4244 | + if ($is_debug) { |
|
| 4245 | + echo ' |
|
| 4046 | 4246 | setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: "\' + sCompletedTableName + \'".<span id="debuginfo"><\' + \'/span>\'); |
| 4047 | 4247 | |
| 4048 | 4248 | if (document.getElementById(\'debug_section\').scrollHeight) |
| 4049 | 4249 | document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight'; |
| 4250 | + } |
|
| 4050 | 4251 | |
| 4051 | 4252 | echo ' |
| 4052 | 4253 | // Get the next update... |
@@ -4079,8 +4280,9 @@ discard block |
||
| 4079 | 4280 | { |
| 4080 | 4281 | global $upcontext, $support_js, $is_debug, $timeLimitThreshold, $txt; |
| 4081 | 4282 | |
| 4082 | - if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) |
|
| 4083 | - $is_debug = true; |
|
| 4283 | + if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) { |
|
| 4284 | + $is_debug = true; |
|
| 4285 | + } |
|
| 4084 | 4286 | |
| 4085 | 4287 | echo ' |
| 4086 | 4288 | <h3>', $txt['upgrade_db_changes'], '</h3> |
@@ -4095,8 +4297,9 @@ discard block |
||
| 4095 | 4297 | { |
| 4096 | 4298 | foreach ($upcontext['actioned_items'] as $num => $item) |
| 4097 | 4299 | { |
| 4098 | - if ($num != 0) |
|
| 4099 | - echo ' Successful!'; |
|
| 4300 | + if ($num != 0) { |
|
| 4301 | + echo ' Successful!'; |
|
| 4302 | + } |
|
| 4100 | 4303 | echo '<br>' . $item; |
| 4101 | 4304 | } |
| 4102 | 4305 | |
@@ -4111,20 +4314,20 @@ discard block |
||
| 4111 | 4314 | $seconds = intval($active % 60); |
| 4112 | 4315 | |
| 4113 | 4316 | echo '', sprintf($txt['upgrade_success_time_db'], $seconds, $minutes, $hours), '<br>'; |
| 4317 | + } else { |
|
| 4318 | + echo '', $txt['upgrade_success'], '<br>'; |
|
| 4114 | 4319 | } |
| 4115 | - else |
|
| 4116 | - echo '', $txt['upgrade_success'], '<br>'; |
|
| 4117 | 4320 | |
| 4118 | 4321 | echo ' |
| 4119 | 4322 | <p id="commess">', $txt['upgrade_db_complete'], '</p>'; |
| 4120 | 4323 | } |
| 4121 | - } |
|
| 4122 | - else |
|
| 4324 | + } else |
|
| 4123 | 4325 | { |
| 4124 | 4326 | // Tell them how many files we have in total. |
| 4125 | - if ($upcontext['file_count'] > 1) |
|
| 4126 | - echo ' |
|
| 4327 | + if ($upcontext['file_count'] > 1) { |
|
| 4328 | + echo ' |
|
| 4127 | 4329 | <strong id="info1">', $txt['upgrade_script'], ' <span id="file_done">', $upcontext['cur_file_num'], '</span> of ', $upcontext['file_count'], '.</strong>'; |
| 4330 | + } |
|
| 4128 | 4331 | |
| 4129 | 4332 | echo ' |
| 4130 | 4333 | <h3 id="info2"> |
@@ -4144,10 +4347,10 @@ discard block |
||
| 4144 | 4347 | |
| 4145 | 4348 | echo ' |
| 4146 | 4349 | <p id="upgradeCompleted">', sprintf($txt['upgrade_success_time_db'], $seconds, $minutes, $hours), '</p>'; |
| 4147 | - } |
|
| 4148 | - else |
|
| 4149 | - echo ' |
|
| 4350 | + } else { |
|
| 4351 | + echo ' |
|
| 4150 | 4352 | <p id="upgradeCompleted"></p>'; |
| 4353 | + } |
|
| 4151 | 4354 | |
| 4152 | 4355 | echo ' |
| 4153 | 4356 | <div id="debug_section"> |
@@ -4183,9 +4386,10 @@ discard block |
||
| 4183 | 4386 | var getData = ""; |
| 4184 | 4387 | var debugItems = ', $upcontext['debug_items'], ';'; |
| 4185 | 4388 | |
| 4186 | - if ($is_debug) |
|
| 4187 | - echo ' |
|
| 4389 | + if ($is_debug) { |
|
| 4390 | + echo ' |
|
| 4188 | 4391 | var upgradeStartTime = ' . $upcontext['started'] . ';'; |
| 4392 | + } |
|
| 4189 | 4393 | |
| 4190 | 4394 | echo ' |
| 4191 | 4395 | function getNextItem() |
@@ -4225,9 +4429,10 @@ discard block |
||
| 4225 | 4429 | document.getElementById("error_block").classList.remove("hidden"); |
| 4226 | 4430 | setInnerHTML(document.getElementById("error_message"), "Error retrieving information on step: " + (sDebugName == "" ? sLastString : sDebugName));'; |
| 4227 | 4431 | |
| 4228 | - if ($is_debug) |
|
| 4229 | - echo ' |
|
| 4432 | + if ($is_debug) { |
|
| 4433 | + echo ' |
|
| 4230 | 4434 | setOuterHTML(document.getElementById(\'debuginfo\'), \'<span class="red">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');'; |
| 4435 | + } |
|
| 4231 | 4436 | |
| 4232 | 4437 | echo ' |
| 4233 | 4438 | } |
@@ -4248,9 +4453,10 @@ discard block |
||
| 4248 | 4453 | document.getElementById("error_block").classList.remove("hidden"); |
| 4249 | 4454 | setInnerHTML(document.getElementById("error_message"), "', $txt['upgrade_loop'], '" + sDebugName);'; |
| 4250 | 4455 | |
| 4251 | - if ($is_debug) |
|
| 4252 | - echo ' |
|
| 4456 | + if ($is_debug) { |
|
| 4457 | + echo ' |
|
| 4253 | 4458 | setOuterHTML(document.getElementById(\'debuginfo\'), \'<span class="red">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');'; |
| 4459 | + } |
|
| 4254 | 4460 | |
| 4255 | 4461 | echo ' |
| 4256 | 4462 | } |
@@ -4308,8 +4514,8 @@ discard block |
||
| 4308 | 4514 | {'; |
| 4309 | 4515 | |
| 4310 | 4516 | // Database Changes, tell us how much time we spen to do this. If this gets updated via JS. |
| 4311 | - if ($is_debug) |
|
| 4312 | - echo ' |
|
| 4517 | + if ($is_debug) { |
|
| 4518 | + echo ' |
|
| 4313 | 4519 | document.getElementById(\'debug_section\').classList.add("hidden"); |
| 4314 | 4520 | |
| 4315 | 4521 | var upgradeFinishedTime = parseInt(oXMLDoc.getElementsByTagName("curtime")[0].childNodes[0].nodeValue); |
@@ -4324,6 +4530,7 @@ discard block |
||
| 4324 | 4530 | completedTxt = completedTxt.replace("%1$d", diffSeconds).replace("%2$d", diffMinutes).replace("%3$d", diffHours); |
| 4325 | 4531 | console.log(completedTxt, upgradeFinishedTime, diffTime, diffHours, diffMinutes, diffSeconds); |
| 4326 | 4532 | setInnerHTML(document.getElementById("upgradeCompleted"), completedTxt);'; |
| 4533 | + } |
|
| 4327 | 4534 | |
| 4328 | 4535 | echo ' |
| 4329 | 4536 | |
@@ -4331,9 +4538,10 @@ discard block |
||
| 4331 | 4538 | document.getElementById(\'contbutt\').disabled = 0; |
| 4332 | 4539 | document.getElementById(\'database_done\').value = 1;'; |
| 4333 | 4540 | |
| 4334 | - if ($upcontext['file_count'] > 1) |
|
| 4335 | - echo ' |
|
| 4541 | + if ($upcontext['file_count'] > 1) { |
|
| 4542 | + echo ' |
|
| 4336 | 4543 | document.getElementById(\'info1\').classList.add(\'hidden\');'; |
| 4544 | + } |
|
| 4337 | 4545 | |
| 4338 | 4546 | echo ' |
| 4339 | 4547 | document.getElementById(\'info2\').classList.add(\'hidden\'); |
@@ -4346,9 +4554,10 @@ discard block |
||
| 4346 | 4554 | lastItem = 0; |
| 4347 | 4555 | prevFile = curFile;'; |
| 4348 | 4556 | |
| 4349 | - if ($is_debug) |
|
| 4350 | - echo ' |
|
| 4557 | + if ($is_debug) { |
|
| 4558 | + echo ' |
|
| 4351 | 4559 | setOuterHTML(document.getElementById(\'debuginfo\'), \'Moving to next script file...done<br><span id="debuginfo"><\' + \'/span>\');'; |
| 4560 | + } |
|
| 4352 | 4561 | |
| 4353 | 4562 | echo ' |
| 4354 | 4563 | getNextItem(); |
@@ -4356,8 +4565,8 @@ discard block |
||
| 4356 | 4565 | }'; |
| 4357 | 4566 | |
| 4358 | 4567 | // If debug scroll the screen. |
| 4359 | - if ($is_debug) |
|
| 4360 | - echo ' |
|
| 4568 | + if ($is_debug) { |
|
| 4569 | + echo ' |
|
| 4361 | 4570 | if (iLastSubStepProgress == -1) |
| 4362 | 4571 | { |
| 4363 | 4572 | // Give it consistent dots. |
@@ -4376,6 +4585,7 @@ discard block |
||
| 4376 | 4585 | |
| 4377 | 4586 | if (document.getElementById(\'debug_section\').scrollHeight) |
| 4378 | 4587 | document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight'; |
| 4588 | + } |
|
| 4379 | 4589 | |
| 4380 | 4590 | echo ' |
| 4381 | 4591 | // Update the page. |
@@ -4436,9 +4646,10 @@ discard block |
||
| 4436 | 4646 | }'; |
| 4437 | 4647 | |
| 4438 | 4648 | // Start things off assuming we've not errored. |
| 4439 | - if (empty($upcontext['error_message'])) |
|
| 4440 | - echo ' |
|
| 4649 | + if (empty($upcontext['error_message'])) { |
|
| 4650 | + echo ' |
|
| 4441 | 4651 | getNextItem();'; |
| 4652 | + } |
|
| 4442 | 4653 | |
| 4443 | 4654 | echo ' |
| 4444 | 4655 | //# sourceURL=dynamicScript-dbch.js |
@@ -4456,18 +4667,21 @@ discard block |
||
| 4456 | 4667 | <item num="', $upcontext['current_item_num'], '">', $upcontext['current_item_name'], '</item> |
| 4457 | 4668 | <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>'; |
| 4458 | 4669 | |
| 4459 | - if (!empty($upcontext['error_message'])) |
|
| 4460 | - echo ' |
|
| 4670 | + if (!empty($upcontext['error_message'])) { |
|
| 4671 | + echo ' |
|
| 4461 | 4672 | <error>', $upcontext['error_message'], '</error>'; |
| 4673 | + } |
|
| 4462 | 4674 | |
| 4463 | - if (!empty($upcontext['error_string'])) |
|
| 4464 | - echo ' |
|
| 4675 | + if (!empty($upcontext['error_string'])) { |
|
| 4676 | + echo ' |
|
| 4465 | 4677 | <sql>', $upcontext['error_string'], '</sql>'; |
| 4678 | + } |
|
| 4466 | 4679 | |
| 4467 | - if ($is_debug) |
|
| 4468 | - echo ' |
|
| 4680 | + if ($is_debug) { |
|
| 4681 | + echo ' |
|
| 4469 | 4682 | <curtime>', time(), '</curtime>'; |
| 4470 | -} |
|
| 4683 | + } |
|
| 4684 | + } |
|
| 4471 | 4685 | |
| 4472 | 4686 | // Template for the UTF-8 conversion step. Basically a copy of the backup stuff with slight modifications.... |
| 4473 | 4687 | function template_convert_utf8() |
@@ -4484,10 +4698,11 @@ discard block |
||
| 4484 | 4698 | </div>'; |
| 4485 | 4699 | |
| 4486 | 4700 | // Done any tables so far? |
| 4487 | - if (!empty($upcontext['previous_tables'])) |
|
| 4488 | - foreach ($upcontext['previous_tables'] as $table) |
|
| 4701 | + if (!empty($upcontext['previous_tables'])) { |
|
| 4702 | + foreach ($upcontext['previous_tables'] as $table) |
|
| 4489 | 4703 | echo ' |
| 4490 | 4704 | <br>', $txt['upgrade_completed_table'], ' "', $table, '".'; |
| 4705 | + } |
|
| 4491 | 4706 | |
| 4492 | 4707 | echo ' |
| 4493 | 4708 | <h3 id="current_tab"> |
@@ -4495,9 +4710,10 @@ discard block |
||
| 4495 | 4710 | </h3>'; |
| 4496 | 4711 | |
| 4497 | 4712 | // If we dropped their index, let's let them know |
| 4498 | - if ($upcontext['dropping_index']) |
|
| 4499 | - echo ' |
|
| 4713 | + if ($upcontext['dropping_index']) { |
|
| 4714 | + echo ' |
|
| 4500 | 4715 | <p id="indexmsg" class="', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline_block' : 'hidden', ' style="font-weight: bold; font-style: italic">', $txt['upgrade_fulltext'], '</p>'; |
| 4716 | + } |
|
| 4501 | 4717 | |
| 4502 | 4718 | // Completion notification |
| 4503 | 4719 | echo ' |
@@ -4534,12 +4750,13 @@ discard block |
||
| 4534 | 4750 | updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');'; |
| 4535 | 4751 | |
| 4536 | 4752 | // If debug flood the screen. |
| 4537 | - if ($is_debug) |
|
| 4538 | - echo ' |
|
| 4753 | + if ($is_debug) { |
|
| 4754 | + echo ' |
|
| 4539 | 4755 | setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: "\' + sCompletedTableName + \'".<span id="debuginfo"><\' + \'/span>\'); |
| 4540 | 4756 | |
| 4541 | 4757 | if (document.getElementById(\'debug_section\').scrollHeight) |
| 4542 | 4758 | document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight'; |
| 4759 | + } |
|
| 4543 | 4760 | |
| 4544 | 4761 | echo ' |
| 4545 | 4762 | // Get the next update... |
@@ -4585,10 +4802,11 @@ discard block |
||
| 4585 | 4802 | </div>'; |
| 4586 | 4803 | |
| 4587 | 4804 | // Dont any tables so far? |
| 4588 | - if (!empty($upcontext['previous_tables'])) |
|
| 4589 | - foreach ($upcontext['previous_tables'] as $table) |
|
| 4805 | + if (!empty($upcontext['previous_tables'])) { |
|
| 4806 | + foreach ($upcontext['previous_tables'] as $table) |
|
| 4590 | 4807 | echo ' |
| 4591 | 4808 | <br>', $txt['upgrade_completed_table'], ' "', $table, '".'; |
| 4809 | + } |
|
| 4592 | 4810 | |
| 4593 | 4811 | echo ' |
| 4594 | 4812 | <h3 id="current_tab"> |
@@ -4597,9 +4815,10 @@ discard block |
||
| 4597 | 4815 | <p id="commess" class="', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline_block' : 'hidden', '">', $txt['upgrade_json_completed'], '</p>'; |
| 4598 | 4816 | |
| 4599 | 4817 | // Try to make sure substep was reset. |
| 4600 | - if ($upcontext['cur_table_num'] == $upcontext['table_count']) |
|
| 4601 | - echo ' |
|
| 4818 | + if ($upcontext['cur_table_num'] == $upcontext['table_count']) { |
|
| 4819 | + echo ' |
|
| 4602 | 4820 | <input type="hidden" name="substep" id="substep" value="0">'; |
| 4821 | + } |
|
| 4603 | 4822 | |
| 4604 | 4823 | // Continue please! |
| 4605 | 4824 | $upcontext['continue'] = $support_js ? 2 : 1; |
@@ -4632,12 +4851,13 @@ discard block |
||
| 4632 | 4851 | updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');'; |
| 4633 | 4852 | |
| 4634 | 4853 | // If debug flood the screen. |
| 4635 | - if ($is_debug) |
|
| 4636 | - echo ' |
|
| 4854 | + if ($is_debug) { |
|
| 4855 | + echo ' |
|
| 4637 | 4856 | setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>', $txt['upgrade_completed_table'], ' "\' + sCompletedTableName + \'".<span id="debuginfo"><\' + \'/span>\'); |
| 4638 | 4857 | |
| 4639 | 4858 | if (document.getElementById(\'debug_section\').scrollHeight) |
| 4640 | 4859 | document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight'; |
| 4860 | + } |
|
| 4641 | 4861 | |
| 4642 | 4862 | echo ' |
| 4643 | 4863 | // Get the next update... |
@@ -4673,8 +4893,8 @@ discard block |
||
| 4673 | 4893 | <h3>', $txt['upgrade_done'], ' <a href="', $boardurl, '/index.php">', $txt['upgrade_done2'], '</a>. ', $txt['upgrade_done3'], '</h3> |
| 4674 | 4894 | <form action="', $boardurl, '/index.php">'; |
| 4675 | 4895 | |
| 4676 | - if (!empty($upcontext['can_delete_script'])) |
|
| 4677 | - echo ' |
|
| 4896 | + if (!empty($upcontext['can_delete_script'])) { |
|
| 4897 | + echo ' |
|
| 4678 | 4898 | <label> |
| 4679 | 4899 | <input type="checkbox" id="delete_self" onclick="doTheDelete(this);"> ', $txt['upgrade_delete_now'], ' |
| 4680 | 4900 | </label> |
@@ -4688,6 +4908,7 @@ discard block |
||
| 4688 | 4908 | } |
| 4689 | 4909 | </script> |
| 4690 | 4910 | <img src="', $settings['default_theme_url'], '/images/blank.png" alt="" id="delete_upgrader"><br>'; |
| 4911 | + } |
|
| 4691 | 4912 | |
| 4692 | 4913 | // Show Upgrade time in debug mode when we completed the upgrade process totatly |
| 4693 | 4914 | if ($is_debug) |
@@ -4697,12 +4918,13 @@ discard block |
||
| 4697 | 4918 | $minutes = intval(($active / 60) % 60); |
| 4698 | 4919 | $seconds = intval($active % 60); |
| 4699 | 4920 | |
| 4700 | - if ($hours > 0) |
|
| 4701 | - echo '', sprintf($txt['upgrade_completed_time_hms'], $seconds, $minutes, $hours), ''; |
|
| 4702 | - elseif ($minutes > 0) |
|
| 4703 | - echo '', sprintf($txt['upgrade_completed_time_ms'], $seconds, $minutes), ''; |
|
| 4704 | - elseif ($seconds > 0) |
|
| 4705 | - echo '', sprintf($txt['upgrade_completed_time_s'], $seconds), ''; |
|
| 4921 | + if ($hours > 0) { |
|
| 4922 | + echo '', sprintf($txt['upgrade_completed_time_hms'], $seconds, $minutes, $hours), ''; |
|
| 4923 | + } elseif ($minutes > 0) { |
|
| 4924 | + echo '', sprintf($txt['upgrade_completed_time_ms'], $seconds, $minutes), ''; |
|
| 4925 | + } elseif ($seconds > 0) { |
|
| 4926 | + echo '', sprintf($txt['upgrade_completed_time_s'], $seconds), ''; |
|
| 4927 | + } |
|
| 4706 | 4928 | } |
| 4707 | 4929 | |
| 4708 | 4930 | echo ' |
@@ -4732,8 +4954,9 @@ discard block |
||
| 4732 | 4954 | |
| 4733 | 4955 | $current_substep = $_GET['substep']; |
| 4734 | 4956 | |
| 4735 | - if (empty($_GET['a'])) |
|
| 4736 | - $_GET['a'] = 0; |
|
| 4957 | + if (empty($_GET['a'])) { |
|
| 4958 | + $_GET['a'] = 0; |
|
| 4959 | + } |
|
| 4737 | 4960 | $step_progress['name'] = 'Converting ips'; |
| 4738 | 4961 | $step_progress['current'] = $_GET['a']; |
| 4739 | 4962 | |
@@ -4776,16 +4999,19 @@ discard block |
||
| 4776 | 4999 | 'empty' => '', |
| 4777 | 5000 | 'limit' => $limit, |
| 4778 | 5001 | )); |
| 4779 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 4780 | - $arIp[] = $row[$oldCol]; |
|
| 5002 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 5003 | + $arIp[] = $row[$oldCol]; |
|
| 5004 | + } |
|
| 4781 | 5005 | $smcFunc['db_free_result']($request); |
| 4782 | 5006 | |
| 4783 | 5007 | // Special case, null ip could keep us in a loop. |
| 4784 | - if (is_null($arIp[0])) |
|
| 4785 | - unset($arIp[0]); |
|
| 5008 | + if (is_null($arIp[0])) { |
|
| 5009 | + unset($arIp[0]); |
|
| 5010 | + } |
|
| 4786 | 5011 | |
| 4787 | - if (empty($arIp)) |
|
| 4788 | - $is_done = true; |
|
| 5012 | + if (empty($arIp)) { |
|
| 5013 | + $is_done = true; |
|
| 5014 | + } |
|
| 4789 | 5015 | |
| 4790 | 5016 | $updates = array(); |
| 4791 | 5017 | $cases = array(); |
@@ -4794,16 +5020,18 @@ discard block |
||
| 4794 | 5020 | { |
| 4795 | 5021 | $arIp[$i] = trim($arIp[$i]); |
| 4796 | 5022 | |
| 4797 | - if (empty($arIp[$i])) |
|
| 4798 | - continue; |
|
| 5023 | + if (empty($arIp[$i])) { |
|
| 5024 | + continue; |
|
| 5025 | + } |
|
| 4799 | 5026 | |
| 4800 | 5027 | $updates['ip' . $i] = $arIp[$i]; |
| 4801 | 5028 | $cases[$arIp[$i]] = 'WHEN ' . $oldCol . ' = {string:ip' . $i . '} THEN {inet:ip' . $i . '}'; |
| 4802 | 5029 | |
| 4803 | 5030 | if ($setSize > 0 && $i % $setSize === 0) |
| 4804 | 5031 | { |
| 4805 | - if (count($updates) == 1) |
|
| 4806 | - continue; |
|
| 5032 | + if (count($updates) == 1) { |
|
| 5033 | + continue; |
|
| 5034 | + } |
|
| 4807 | 5035 | |
| 4808 | 5036 | $updates['whereSet'] = array_values($updates); |
| 4809 | 5037 | $smcFunc['db_query']('', ' |
@@ -4837,8 +5065,7 @@ discard block |
||
| 4837 | 5065 | 'ip' => $ip |
| 4838 | 5066 | )); |
| 4839 | 5067 | } |
| 4840 | - } |
|
| 4841 | - else |
|
| 5068 | + } else |
|
| 4842 | 5069 | { |
| 4843 | 5070 | $updates['whereSet'] = array_values($updates); |
| 4844 | 5071 | $smcFunc['db_query']('', ' |
@@ -4852,9 +5079,9 @@ discard block |
||
| 4852 | 5079 | $updates |
| 4853 | 5080 | ); |
| 4854 | 5081 | } |
| 5082 | + } else { |
|
| 5083 | + $is_done = true; |
|
| 4855 | 5084 | } |
| 4856 | - else |
|
| 4857 | - $is_done = true; |
|
| 4858 | 5085 | |
| 4859 | 5086 | $_GET['a'] += $limit; |
| 4860 | 5087 | $step_progress['current'] = $_GET['a']; |
@@ -4880,11 +5107,12 @@ discard block |
||
| 4880 | 5107 | |
| 4881 | 5108 | $columns = $smcFunc['db_list_columns']($targetTable, true); |
| 4882 | 5109 | |
| 4883 | - if (isset($columns[$column])) |
|
| 4884 | - return $columns[$column]; |
|
| 4885 | - else |
|
| 4886 | - return null; |
|
| 4887 | -} |
|
| 5110 | + if (isset($columns[$column])) { |
|
| 5111 | + return $columns[$column]; |
|
| 5112 | + } else { |
|
| 5113 | + return null; |
|
| 5114 | + } |
|
| 5115 | + } |
|
| 4888 | 5116 | |
| 4889 | 5117 | /** |
| 4890 | 5118 | * Takes the changes to be made during the upgradeOptions step, grabs all known Settings data from Settings.php, then runs |
@@ -5163,18 +5391,20 @@ discard block |
||
| 5163 | 5391 | global $$setVar; |
| 5164 | 5392 | |
| 5165 | 5393 | // Find the setting. |
| 5166 | - if ($setType == 'string' || $setType == 'string_fatal') |
|
| 5167 | - $original[$setVar] = isset($$setVar) ? '\'' . addslashes($$setVar) . '\'' : (strpos('fatal', $setType) ? null : '\'\''); |
|
| 5168 | - elseif ($setType == 'int' || $setType == 'int_fatal') |
|
| 5169 | - $original[$setVar] = isset($$setVar) ? (int) $$setVar : (strpos('fatal', $setType) ? null : 0); |
|
| 5170 | - elseif ($setType == 'bool' || $setType == 'bool_fatal') |
|
| 5171 | - $original[$setVar] = isset($$setVar) && in_array($$setVar, array(1, true)) ? 'true' : (strpos('fatal', $setType) ? null : 'false'); |
|
| 5172 | - elseif ($setType == 'null' || $setType == 'null_fatal') |
|
| 5173 | - $original[$setVar] = isset($$setVar) && in_array($$setVar, array(1, true)) ? 'true' : (strpos('fatal', $setType) ? null : 'null'); |
|
| 5394 | + if ($setType == 'string' || $setType == 'string_fatal') { |
|
| 5395 | + $original[$setVar] = isset($$setVar) ? '\'' . addslashes($$setVar) . '\'' : (strpos('fatal', $setType) ? null : '\'\''); |
|
| 5396 | + } elseif ($setType == 'int' || $setType == 'int_fatal') { |
|
| 5397 | + $original[$setVar] = isset($$setVar) ? (int) $$setVar : (strpos('fatal', $setType) ? null : 0); |
|
| 5398 | + } elseif ($setType == 'bool' || $setType == 'bool_fatal') { |
|
| 5399 | + $original[$setVar] = isset($$setVar) && in_array($$setVar, array(1, true)) ? 'true' : (strpos('fatal', $setType) ? null : 'false'); |
|
| 5400 | + } elseif ($setType == 'null' || $setType == 'null_fatal') { |
|
| 5401 | + $original[$setVar] = isset($$setVar) && in_array($$setVar, array(1, true)) ? 'true' : (strpos('fatal', $setType) ? null : 'null'); |
|
| 5402 | + } |
|
| 5174 | 5403 | |
| 5175 | 5404 | // Well this isn't good. Do we fix it or bail? |
| 5176 | - if (is_null($original) && $setType != 'null' && strpos('fatal', $setType) > -1) |
|
| 5177 | - return throw_error('The upgrader could not copy a setting (' . $setVar . ') from your Settings file. Unable to migrate your Settings file to a new version.'); |
|
| 5405 | + if (is_null($original) && $setType != 'null' && strpos('fatal', $setType) > -1) { |
|
| 5406 | + return throw_error('The upgrader could not copy a setting (' . $setVar . ') from your Settings file. Unable to migrate your Settings file to a new version.'); |
|
| 5407 | + } |
|
| 5178 | 5408 | } |
| 5179 | 5409 | |
| 5180 | 5410 | // Finally, merge the changes with the new ones. |
@@ -5182,8 +5412,9 @@ discard block |
||
| 5182 | 5412 | foreach ($changes as $setVar => $value) |
| 5183 | 5413 | { |
| 5184 | 5414 | // Nothing needed here. |
| 5185 | - if ($setVar != 'upgradeData' && $config_vars[$setVar] == $changes[$setVar]) |
|
| 5186 | - continue; |
|
| 5415 | + if ($setVar != 'upgradeData' && $config_vars[$setVar] == $changes[$setVar]) { |
|
| 5416 | + continue; |
|
| 5417 | + } |
|
| 5187 | 5418 | |
| 5188 | 5419 | $config_vars[$setVar] = $value; |
| 5189 | 5420 | } |
@@ -5196,15 +5427,17 @@ discard block |
||
| 5196 | 5427 | $last_settings_change = filemtime($boarddir . '/Settings.php'); |
| 5197 | 5428 | |
| 5198 | 5429 | // remove any /r's that made there way in here |
| 5199 | - foreach ($settingsArray as $k => $dummy) |
|
| 5200 | - $settingsArray[$k] = strtr($dummy, array("\r" => '')) . "\n"; |
|
| 5430 | + foreach ($settingsArray as $k => $dummy) { |
|
| 5431 | + $settingsArray[$k] = strtr($dummy, array("\r" => '')) . "\n"; |
|
| 5432 | + } |
|
| 5201 | 5433 | |
| 5202 | 5434 | // go line by line and see whats changing |
| 5203 | 5435 | for ($i = 0, $n = count($settingsArray); $i < $n; $i++) |
| 5204 | 5436 | { |
| 5205 | 5437 | // Don't trim or bother with it if it's not a variable. |
| 5206 | - if (substr($settingsArray[$i], 0, 1) != '$') |
|
| 5207 | - continue; |
|
| 5438 | + if (substr($settingsArray[$i], 0, 1) != '$') { |
|
| 5439 | + continue; |
|
| 5440 | + } |
|
| 5208 | 5441 | |
| 5209 | 5442 | $settingsArray[$i] = trim($settingsArray[$i]) . "\n"; |
| 5210 | 5443 | |
@@ -5212,9 +5445,9 @@ discard block |
||
| 5212 | 5445 | foreach ($config_vars as $var => $val) |
| 5213 | 5446 | { |
| 5214 | 5447 | // be sure someone is not updating db_last_error this with a group |
| 5215 | - if ($var === 'db_last_error') |
|
| 5216 | - unset($config_vars[$var]); |
|
| 5217 | - elseif (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0) |
|
| 5448 | + if ($var === 'db_last_error') { |
|
| 5449 | + unset($config_vars[$var]); |
|
| 5450 | + } elseif (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0) |
|
| 5218 | 5451 | { |
| 5219 | 5452 | $comment = strstr(substr($settingsArray[$i], strpos($settingsArray[$i], ';')), '#'); |
| 5220 | 5453 | $settingsArray[$i] = '$' . $var . ' = ' . $val . ';' . ($comment == '' ? '' : "\t\t" . rtrim($comment)) . "\n"; |
@@ -5225,34 +5458,39 @@ discard block |
||
| 5225 | 5458 | } |
| 5226 | 5459 | |
| 5227 | 5460 | // End of the file ... maybe |
| 5228 | - if (substr(trim($settingsArray[$i]), 0, 2) == '?' . '>') |
|
| 5229 | - $end = $i; |
|
| 5461 | + if (substr(trim($settingsArray[$i]), 0, 2) == '?' . '>') { |
|
| 5462 | + $end = $i; |
|
| 5463 | + } |
|
| 5230 | 5464 | } |
| 5231 | 5465 | |
| 5232 | 5466 | // This should never happen, but apparently it is happening. |
| 5233 | - if (empty($end) || $end < 10) |
|
| 5234 | - $end = count($settingsArray) - 1; |
|
| 5467 | + if (empty($end) || $end < 10) { |
|
| 5468 | + $end = count($settingsArray) - 1; |
|
| 5469 | + } |
|
| 5235 | 5470 | |
| 5236 | 5471 | // Still more variables to go? Then lets add them at the end. |
| 5237 | 5472 | if (!empty($config_vars)) |
| 5238 | 5473 | { |
| 5239 | - if (trim($settingsArray[$end]) == '?' . '>') |
|
| 5240 | - $settingsArray[$end++] = ''; |
|
| 5241 | - else |
|
| 5242 | - $end++; |
|
| 5474 | + if (trim($settingsArray[$end]) == '?' . '>') { |
|
| 5475 | + $settingsArray[$end++] = ''; |
|
| 5476 | + } else { |
|
| 5477 | + $end++; |
|
| 5478 | + } |
|
| 5243 | 5479 | |
| 5244 | 5480 | // Add in any newly defined vars that were passed |
| 5245 | - foreach ($config_vars as $var => $val) |
|
| 5246 | - $settingsArray[$end++] = '$' . $var . ' = ' . $val . ';' . "\n"; |
|
| 5481 | + foreach ($config_vars as $var => $val) { |
|
| 5482 | + $settingsArray[$end++] = '$' . $var . ' = ' . $val . ';' . "\n"; |
|
| 5483 | + } |
|
| 5247 | 5484 | |
| 5248 | 5485 | $settingsArray[$end] = '?' . '>'; |
| 5486 | + } else { |
|
| 5487 | + $settingsArray[$end] = trim($settingsArray[$end]); |
|
| 5249 | 5488 | } |
| 5250 | - else |
|
| 5251 | - $settingsArray[$end] = trim($settingsArray[$end]); |
|
| 5252 | 5489 | |
| 5253 | 5490 | // Sanity error checking: the file needs to be at least 12 lines. |
| 5254 | - if (count($settingsArray) < 12) |
|
| 5255 | - return throw_error('The upgrader could not process your Settings file for updates. Unable to migrate your Settings file to a new version.'); |
|
| 5491 | + if (count($settingsArray) < 12) { |
|
| 5492 | + return throw_error('The upgrader could not process your Settings file for updates. Unable to migrate your Settings file to a new version.'); |
|
| 5493 | + } |
|
| 5256 | 5494 | |
| 5257 | 5495 | // Try to avoid a few pitfalls: |
| 5258 | 5496 | // - like a possible race condition, |
@@ -5260,8 +5498,9 @@ discard block |
||
| 5260 | 5498 | // |
| 5261 | 5499 | // Check before you act: if cache is enabled, we can do a simple write test |
| 5262 | 5500 | // to validate that we even write things on this filesystem. |
| 5263 | - if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) |
|
| 5264 | - $cachedir = $boarddir . '/cache'; |
|
| 5501 | + if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) { |
|
| 5502 | + $cachedir = $boarddir . '/cache'; |
|
| 5503 | + } |
|
| 5265 | 5504 | |
| 5266 | 5505 | $test_fp = @fopen($cachedir . '/settings_update.tmp', "w+"); |
| 5267 | 5506 | if ($test_fp) |
@@ -5272,8 +5511,9 @@ discard block |
||
| 5272 | 5511 | |
| 5273 | 5512 | // Oops. Low disk space, perhaps. Don't mess with Settings.php then. |
| 5274 | 5513 | // No means no. :P |
| 5275 | - if ($written_bytes !== 4) |
|
| 5276 | - return throw_error('The upgrader could not write a test file, perhaps not enough storage? Unable to migrate your Settings file to a new version.'); |
|
| 5514 | + if ($written_bytes !== 4) { |
|
| 5515 | + return throw_error('The upgrader could not write a test file, perhaps not enough storage? Unable to migrate your Settings file to a new version.'); |
|
| 5516 | + } |
|
| 5277 | 5517 | } |
| 5278 | 5518 | |
| 5279 | 5519 | // Protect me from what I want! :P |
@@ -5291,8 +5531,9 @@ discard block |
||
| 5291 | 5531 | // survey says ... |
| 5292 | 5532 | if ($written_bytes !== strlen($write_settings) && !$settings_backup_fail) |
| 5293 | 5533 | { |
| 5294 | - if (file_exists($boarddir . '/Settings_bak.php')) |
|
| 5295 | - @copy($boarddir . '/Settings_bak.php', $boarddir . '/Settings.php'); |
|
| 5534 | + if (file_exists($boarddir . '/Settings_bak.php')) { |
|
| 5535 | + @copy($boarddir . '/Settings_bak.php', $boarddir . '/Settings.php'); |
|
| 5536 | + } |
|
| 5296 | 5537 | |
| 5297 | 5538 | return throw_error('The upgrader detected a bad Settings file and reverted the changes. Unable to migrate your Settings file to a new version.'); |
| 5298 | 5539 | } |
@@ -5300,9 +5541,10 @@ discard block |
||
| 5300 | 5541 | |
| 5301 | 5542 | // Even though on normal installations the filemtime should prevent this being used by the installer incorrectly |
| 5302 | 5543 | // it seems that there are times it might not. So let's MAKE it dump the cache. |
| 5303 | - if (function_exists('opcache_invalidate')) |
|
| 5304 | - opcache_invalidate($boarddir . '/Settings.php', true); |
|
| 5305 | -} |
|
| 5544 | + if (function_exists('opcache_invalidate')) { |
|
| 5545 | + opcache_invalidate($boarddir . '/Settings.php', true); |
|
| 5546 | + } |
|
| 5547 | + } |
|
| 5306 | 5548 | |
| 5307 | 5549 | /** |
| 5308 | 5550 | * Determine if we should auto select the migrate Settings file. This is determined by a variety of missing settings. |
@@ -5319,23 +5561,27 @@ discard block |
||
| 5319 | 5561 | global $boarddir, $packagesdir, $tasksdir, $db_server, $db_type, $image_proxy_enabled, $db_show_debug; |
| 5320 | 5562 | |
| 5321 | 5563 | // We should not migrate if db_show_debug is in there, some dev stuff going on here. |
| 5322 | - if (isset($db_show_debug)) |
|
| 5323 | - return false; |
|
| 5564 | + if (isset($db_show_debug)) { |
|
| 5565 | + return false; |
|
| 5566 | + } |
|
| 5324 | 5567 | |
| 5325 | 5568 | $file_contents = file_get_contents($boarddir . '/Settings.php'); |
| 5326 | 5569 | |
| 5327 | 5570 | // Is there a include statement somewhere in there? Some advanced handling of the variables elsewhere? |
| 5328 | 5571 | // Try our best to stay away from the cachedir match. |
| 5329 | - if (preg_match('~\sinclude\((?:(?!\(isset\(\$cachedir))~im', $file_contents)) |
|
| 5330 | - return false; |
|
| 5572 | + if (preg_match('~\sinclude\((?:(?!\(isset\(\$cachedir))~im', $file_contents)) { |
|
| 5573 | + return false; |
|
| 5574 | + } |
|
| 5331 | 5575 | |
| 5332 | 5576 | // If we find a mention of $GLOBALS, there may be a integration going on. |
| 5333 | - if (preg_match('~\$GLOBALS\[~im', $file_contents)) |
|
| 5334 | - return false; |
|
| 5577 | + if (preg_match('~\$GLOBALS\[~im', $file_contents)) { |
|
| 5578 | + return false; |
|
| 5579 | + } |
|
| 5335 | 5580 | |
| 5336 | 5581 | // If these are not set, it makes us a canidate to migrate. |
| 5337 | - if (!isset($packagesdir, $tasksdir, $db_server, $db_type, $image_proxy_enabled)) |
|
| 5338 | - return true; |
|
| 5582 | + if (!isset($packagesdir, $tasksdir, $db_server, $db_type, $image_proxy_enabled)) { |
|
| 5583 | + return true; |
|
| 5584 | + } |
|
| 5339 | 5585 | |
| 5340 | 5586 | return false; |
| 5341 | 5587 | } |
@@ -586,7 +586,7 @@ discard block |
||
| 586 | 586 | 'member_name' => $regOptions['username'], |
| 587 | 587 | 'email_address' => $regOptions['email'], |
| 588 | 588 | 'passwd' => hash_password($regOptions['username'], $regOptions['password']), |
| 589 | - 'password_salt' => substr(md5(random_int(0, PHP_INT_MAX)), 0, 4) , |
|
| 589 | + 'password_salt' => substr(md5(random_int(0, PHP_INT_MAX)), 0, 4), |
|
| 590 | 590 | 'posts' => 0, |
| 591 | 591 | 'date_registered' => time(), |
| 592 | 592 | 'member_ip' => $regOptions['interface'] == 'admin' ? '127.0.0.1' : $user_info['ip'], |
@@ -676,7 +676,7 @@ discard block |
||
| 676 | 676 | 'time_offset', |
| 677 | 677 | ); |
| 678 | 678 | $knownInets = array( |
| 679 | - 'member_ip','member_ip2', |
|
| 679 | + 'member_ip', 'member_ip2', |
|
| 680 | 680 | ); |
| 681 | 681 | |
| 682 | 682 | // Call an optional function to validate the users' input. |
@@ -904,7 +904,7 @@ discard block |
||
| 904 | 904 | $checkName = strtr($name, array('_' => '\\_', '%' => '\\%')); |
| 905 | 905 | |
| 906 | 906 | //when we got no wildcard we can use equal -> fast |
| 907 | - $operator = (strpos($checkName, '%') || strpos($checkName, '_') ? 'LIKE' : '=' ); |
|
| 907 | + $operator = (strpos($checkName, '%') || strpos($checkName, '_') ? 'LIKE' : '='); |
|
| 908 | 908 | |
| 909 | 909 | // Make sure they don't want someone else's name. |
| 910 | 910 | $request = $smcFunc['db_query']('', ' |
@@ -1273,7 +1273,7 @@ discard block |
||
| 1273 | 1273 | $user_info['buddies'][] = $userReceiver; |
| 1274 | 1274 | |
| 1275 | 1275 | // And add a nice alert. Don't abuse though! |
| 1276 | - if ((cache_get_data('Buddy-sent-'. $user_info['id'] .'-'. $userReceiver, 86400)) == null) |
|
| 1276 | + if ((cache_get_data('Buddy-sent-' . $user_info['id'] . '-' . $userReceiver, 86400)) == null) |
|
| 1277 | 1277 | { |
| 1278 | 1278 | $smcFunc['db_insert']('insert', |
| 1279 | 1279 | '{db_prefix}background_tasks', |
@@ -1288,7 +1288,7 @@ discard block |
||
| 1288 | 1288 | ); |
| 1289 | 1289 | |
| 1290 | 1290 | // Store this in a cache entry to avoid creating multiple alerts. Give it a long life cycle. |
| 1291 | - cache_put_data('Buddy-sent-'. $user_info['id'] .'-'. $userReceiver, '1', 86400); |
|
| 1291 | + cache_put_data('Buddy-sent-' . $user_info['id'] . '-' . $userReceiver, '1', 86400); |
|
| 1292 | 1292 | } |
| 1293 | 1293 | } |
| 1294 | 1294 | |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 4 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * Downloads an avatar or attachment based on $_GET['attach'], and increments the download count. |
@@ -40,11 +41,11 @@ discard block |
||
| 40 | 41 | |
| 41 | 42 | if (!empty($modSettings['enableCompressedOutput']) && !headers_sent() && ob_get_length() == 0) |
| 42 | 43 | { |
| 43 | - if (@ini_get('zlib.output_compression') == '1' || @ini_get('output_handler') == 'ob_gzhandler') |
|
| 44 | - $modSettings['enableCompressedOutput'] = 0; |
|
| 45 | - |
|
| 46 | - else |
|
| 47 | - ob_start('ob_gzhandler'); |
|
| 44 | + if (@ini_get('zlib.output_compression') == '1' || @ini_get('output_handler') == 'ob_gzhandler') { |
|
| 45 | + $modSettings['enableCompressedOutput'] = 0; |
|
| 46 | + } else { |
|
| 47 | + ob_start('ob_gzhandler'); |
|
| 48 | + } |
|
| 48 | 49 | } |
| 49 | 50 | |
| 50 | 51 | if (empty($modSettings['enableCompressedOutput'])) |
@@ -76,8 +77,9 @@ discard block |
||
| 76 | 77 | } |
| 77 | 78 | |
| 78 | 79 | // Use cache when possible. |
| 79 | - if (($cache = cache_get_data('attachment_lookup_id-' . $attachId)) != null) |
|
| 80 | - list($file, $thumbFile) = $cache; |
|
| 80 | + if (($cache = cache_get_data('attachment_lookup_id-' . $attachId)) != null) { |
|
| 81 | + list($file, $thumbFile) = $cache; |
|
| 82 | + } |
|
| 81 | 83 | |
| 82 | 84 | // Get the info from the DB. |
| 83 | 85 | if (empty($file) || empty($thumbFile) && !empty($file['id_thumb'])) |
@@ -85,10 +87,9 @@ discard block |
||
| 85 | 87 | // Do we have a hook wanting to use our attachment system? We use $attachRequest to prevent accidental usage of $request. |
| 86 | 88 | $attachRequest = null; |
| 87 | 89 | call_integration_hook('integrate_download_request', array(&$attachRequest)); |
| 88 | - if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest)) |
|
| 89 | - $request = $attachRequest; |
|
| 90 | - |
|
| 91 | - else |
|
| 90 | + if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest)) { |
|
| 91 | + $request = $attachRequest; |
|
| 92 | + } else |
|
| 92 | 93 | { |
| 93 | 94 | // Make sure this attachment is on this board and load its info while we are at it. |
| 94 | 95 | $request = $smcFunc['db_query']('', ' |
@@ -181,13 +182,15 @@ discard block |
||
| 181 | 182 | } |
| 182 | 183 | |
| 183 | 184 | // Cache it. |
| 184 | - if (!empty($file) || !empty($thumbFile)) |
|
| 185 | - cache_put_data('attachment_lookup_id-' . $file['id_attach'], array($file, $thumbFile), random_int(850, 900)); |
|
| 185 | + if (!empty($file) || !empty($thumbFile)) { |
|
| 186 | + cache_put_data('attachment_lookup_id-' . $file['id_attach'], array($file, $thumbFile), random_int(850, 900)); |
|
| 187 | + } |
|
| 186 | 188 | } |
| 187 | 189 | |
| 188 | 190 | // Replace the normal file with its thumbnail if it has one! |
| 189 | - if (!empty($showThumb) && !empty($thumbFile)) |
|
| 190 | - $file = $thumbFile; |
|
| 191 | + if (!empty($showThumb) && !empty($thumbFile)) { |
|
| 192 | + $file = $thumbFile; |
|
| 193 | + } |
|
| 191 | 194 | |
| 192 | 195 | // No point in a nicer message, because this is supposed to be an attachment anyway... |
| 193 | 196 | if (!file_exists($file['filePath'])) |
@@ -237,8 +240,8 @@ discard block |
||
| 237 | 240 | } |
| 238 | 241 | |
| 239 | 242 | // Update the download counter (unless it's a thumbnail or resuming an incomplete download). |
| 240 | - if ($file['attachment_type'] != 3 && empty($showThumb) && $range === 0) |
|
| 241 | - $smcFunc['db_query']('', ' |
|
| 243 | + if ($file['attachment_type'] != 3 && empty($showThumb) && $range === 0) { |
|
| 244 | + $smcFunc['db_query']('', ' |
|
| 242 | 245 | UPDATE {db_prefix}attachments |
| 243 | 246 | SET downloads = downloads + 1 |
| 244 | 247 | WHERE id_attach = {int:id_attach}', |
@@ -246,12 +249,14 @@ discard block |
||
| 246 | 249 | 'id_attach' => $attachId, |
| 247 | 250 | ) |
| 248 | 251 | ); |
| 252 | + } |
|
| 249 | 253 | |
| 250 | 254 | // Send the attachment headers. |
| 251 | 255 | header('pragma: '); |
| 252 | 256 | |
| 253 | - if (!isBrowser('gecko')) |
|
| 254 | - header('content-transfer-encoding: binary'); |
|
| 257 | + if (!isBrowser('gecko')) { |
|
| 258 | + header('content-transfer-encoding: binary'); |
|
| 259 | + } |
|
| 255 | 260 | |
| 256 | 261 | header('expires: ' . gmdate('D, d M Y H:i:s', time() + 525600 * 60) . ' GMT'); |
| 257 | 262 | header('last-modified: ' . gmdate('D, d M Y H:i:s', filemtime($file['filePath'])) . ' GMT'); |
@@ -260,18 +265,19 @@ discard block |
||
| 260 | 265 | header('etag: ' . $eTag); |
| 261 | 266 | |
| 262 | 267 | // Make sure the mime type warrants an inline display. |
| 263 | - if (isset($_REQUEST['image']) && !empty($file['mime_type']) && strpos($file['mime_type'], 'image/') !== 0) |
|
| 264 | - unset($_REQUEST['image']); |
|
| 268 | + if (isset($_REQUEST['image']) && !empty($file['mime_type']) && strpos($file['mime_type'], 'image/') !== 0) { |
|
| 269 | + unset($_REQUEST['image']); |
|
| 270 | + } |
|
| 265 | 271 | |
| 266 | 272 | // Does this have a mime type? |
| 267 | - elseif (!empty($file['mime_type']) && (isset($_REQUEST['image']) || !in_array($file['fileext'], array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff')))) |
|
| 268 | - header('content-type: ' . strtr($file['mime_type'], array('image/bmp' => 'image/x-ms-bmp'))); |
|
| 269 | - |
|
| 270 | - else |
|
| 273 | + elseif (!empty($file['mime_type']) && (isset($_REQUEST['image']) || !in_array($file['fileext'], array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff')))) { |
|
| 274 | + header('content-type: ' . strtr($file['mime_type'], array('image/bmp' => 'image/x-ms-bmp'))); |
|
| 275 | + } else |
|
| 271 | 276 | { |
| 272 | 277 | header('content-type: ' . (isBrowser('ie') || isBrowser('opera') ? 'application/octetstream' : 'application/octet-stream')); |
| 273 | - if (isset($_REQUEST['image'])) |
|
| 274 | - unset($_REQUEST['image']); |
|
| 278 | + if (isset($_REQUEST['image'])) { |
|
| 279 | + unset($_REQUEST['image']); |
|
| 280 | + } |
|
| 275 | 281 | } |
| 276 | 282 | |
| 277 | 283 | // Convert the file to UTF-8, cuz most browsers dig that. |
@@ -279,24 +285,22 @@ discard block |
||
| 279 | 285 | $disposition = !isset($_REQUEST['image']) ? 'attachment' : 'inline'; |
| 280 | 286 | |
| 281 | 287 | // Different browsers like different standards... |
| 282 | - if (isBrowser('firefox')) |
|
| 283 | - header('content-disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name))); |
|
| 284 | - |
|
| 285 | - elseif (isBrowser('opera')) |
|
| 286 | - header('content-disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"'); |
|
| 287 | - |
|
| 288 | - elseif (isBrowser('ie')) |
|
| 289 | - header('content-disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"'); |
|
| 290 | - |
|
| 291 | - else |
|
| 292 | - header('content-disposition: ' . $disposition . '; filename="' . $utf8name . '"'); |
|
| 288 | + if (isBrowser('firefox')) { |
|
| 289 | + header('content-disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name))); |
|
| 290 | + } elseif (isBrowser('opera')) { |
|
| 291 | + header('content-disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"'); |
|
| 292 | + } elseif (isBrowser('ie')) { |
|
| 293 | + header('content-disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"'); |
|
| 294 | + } else { |
|
| 295 | + header('content-disposition: ' . $disposition . '; filename="' . $utf8name . '"'); |
|
| 296 | + } |
|
| 293 | 297 | |
| 294 | 298 | // If this has an "image extension" - but isn't actually an image - then ensure it isn't cached cause of silly IE. |
| 295 | - if (!isset($_REQUEST['image']) && in_array($file['fileext'], array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff'))) |
|
| 296 | - header('cache-control: no-cache'); |
|
| 297 | - |
|
| 298 | - else |
|
| 299 | - header('cache-control: max-age=' . (525600 * 60) . ', private'); |
|
| 299 | + if (!isset($_REQUEST['image']) && in_array($file['fileext'], array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff'))) { |
|
| 300 | + header('cache-control: no-cache'); |
|
| 301 | + } else { |
|
| 302 | + header('cache-control: max-age=' . (525600 * 60) . ', private'); |
|
| 303 | + } |
|
| 300 | 304 | |
| 301 | 305 | // Multipart and resuming support |
| 302 | 306 | if (isset($_SERVER['HTTP_RANGE'])) |
@@ -304,9 +308,9 @@ discard block |
||
| 304 | 308 | send_http_status(206); |
| 305 | 309 | header("content-length: $new_length"); |
| 306 | 310 | header("content-range: bytes $range-$range_end/$size"); |
| 311 | + } else { |
|
| 312 | + header("content-length: " . $size); |
|
| 307 | 313 | } |
| 308 | - else |
|
| 309 | - header("content-length: " . $size); |
|
| 310 | 314 | |
| 311 | 315 | |
| 312 | 316 | // Try to buy some time... |
@@ -315,8 +319,9 @@ discard block |
||
| 315 | 319 | // For multipart/resumable downloads, send the requested chunk(s) of the file |
| 316 | 320 | if (isset($_SERVER['HTTP_RANGE'])) |
| 317 | 321 | { |
| 318 | - while (@ob_get_level() > 0) |
|
| 319 | - @ob_end_clean(); |
|
| 322 | + while (@ob_get_level() > 0) { |
|
| 323 | + @ob_end_clean(); |
|
| 324 | + } |
|
| 320 | 325 | |
| 321 | 326 | // 40 kilobytes is a good-ish amount |
| 322 | 327 | $chunksize = 40 * 1024; |
@@ -340,8 +345,9 @@ discard block |
||
| 340 | 345 | elseif ($size > 4194304) |
| 341 | 346 | { |
| 342 | 347 | // Forcibly end any output buffering going on. |
| 343 | - while (@ob_get_level() > 0) |
|
| 344 | - @ob_end_clean(); |
|
| 348 | + while (@ob_get_level() > 0) { |
|
| 349 | + @ob_end_clean(); |
|
| 350 | + } |
|
| 345 | 351 | |
| 346 | 352 | $fp = fopen($file['filePath'], 'rb'); |
| 347 | 353 | while (!feof($fp)) |
@@ -353,8 +359,9 @@ discard block |
||
| 353 | 359 | } |
| 354 | 360 | |
| 355 | 361 | // On some of the less-bright hosts, readfile() is disabled. It's just a faster, more byte safe, version of what's in the if. |
| 356 | - elseif (@readfile($file['filePath']) === null) |
|
| 357 | - echo file_get_contents($file['filePath']); |
|
| 362 | + elseif (@readfile($file['filePath']) === null) { |
|
| 363 | + echo file_get_contents($file['filePath']); |
|
| 364 | + } |
|
| 358 | 365 | |
| 359 | 366 | die(); |
| 360 | 367 | } |
@@ -15,8 +15,9 @@ discard block |
||
| 15 | 15 | * @version 2.1 Beta 4 |
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | -if (!defined('SMF')) |
|
| 18 | +if (!defined('SMF')) { |
|
| 19 | 19 | die('No direct access...'); |
| 20 | +} |
|
| 20 | 21 | |
| 21 | 22 | /** |
| 22 | 23 | * Creates a wave file that spells the letters of $word. |
@@ -32,8 +33,9 @@ discard block |
||
| 32 | 33 | global $settings, $user_info; |
| 33 | 34 | |
| 34 | 35 | // Allow max 2 requests per 20 seconds. |
| 35 | - if (($ip = cache_get_data('wave_file/' . $user_info['ip'], 20)) > 2 || ($ip2 = cache_get_data('wave_file/' . $user_info['ip2'], 20)) > 2) |
|
| 36 | - die(send_http_status(400)); |
|
| 36 | + if (($ip = cache_get_data('wave_file/' . $user_info['ip'], 20)) > 2 || ($ip2 = cache_get_data('wave_file/' . $user_info['ip2'], 20)) > 2) { |
|
| 37 | + die(send_http_status(400)); |
|
| 38 | + } |
|
| 37 | 39 | cache_put_data('wave_file/' . $user_info['ip'], $ip ? $ip + 1 : 1, 20); |
| 38 | 40 | cache_put_data('wave_file/' . $user_info['ip2'], $ip2 ? $ip2 + 1 : 1, 20); |
| 39 | 41 | |
@@ -42,16 +44,19 @@ discard block |
||
| 42 | 44 | mt_srand(end($tmp)); |
| 43 | 45 | |
| 44 | 46 | // Try to see if there's a sound font in the user's language. |
| 45 | - if (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.' . $user_info['language'] . '.wav')) |
|
| 46 | - $sound_language = $user_info['language']; |
|
| 47 | + if (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.' . $user_info['language'] . '.wav')) { |
|
| 48 | + $sound_language = $user_info['language']; |
|
| 49 | + } |
|
| 47 | 50 | |
| 48 | 51 | // English should be there. |
| 49 | - elseif (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.english.wav')) |
|
| 50 | - $sound_language = 'english'; |
|
| 52 | + elseif (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.english.wav')) { |
|
| 53 | + $sound_language = 'english'; |
|
| 54 | + } |
|
| 51 | 55 | |
| 52 | 56 | // Guess not... |
| 53 | - else |
|
| 54 | - return false; |
|
| 57 | + else { |
|
| 58 | + return false; |
|
| 59 | + } |
|
| 55 | 60 | |
| 56 | 61 | // File names are in lower case so lets make sure that we are only using a lower case string |
| 57 | 62 | $word = strtolower($word); |
@@ -61,20 +66,25 @@ discard block |
||
| 61 | 66 | for ($i = 0; $i < strlen($word); $i++) |
| 62 | 67 | { |
| 63 | 68 | $sound_letter = implode('', file($settings['default_theme_dir'] . '/fonts/sound/' . $word{$i} . '.' . $sound_language . '.wav')); |
| 64 | - if (strpos($sound_letter, 'data') === false) |
|
| 65 | - return false; |
|
| 69 | + if (strpos($sound_letter, 'data') === false) { |
|
| 70 | + return false; |
|
| 71 | + } |
|
| 66 | 72 | |
| 67 | 73 | $sound_letter = substr($sound_letter, strpos($sound_letter, 'data') + 8); |
| 68 | 74 | switch ($word{$i} === 's' ? 0 : random_int(0, 2)) |
| 69 | 75 | { |
| 70 | - case 0 : for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++) |
|
| 71 | - for ($k = 0, $m = round(random_int(15, 25) / 10); $k < $m; $k++) |
|
| 72 | - $sound_word .= $word{$i} === 's' ? $sound_letter{$j} : chr(random_int(max(ord($sound_letter{$j}) - 1, 0x00), min(ord($sound_letter{$j}) + 1, 0xFF))); |
|
| 76 | + case 0 : for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++) { |
|
| 77 | + for ($k = 0, $m = round(random_int(15, 25) / 10); |
|
| 78 | + } |
|
| 79 | + $k < $m; $k++) { |
|
| 80 | + $sound_word .= $word{$i} === 's' ? $sound_letter{$j} : chr(random_int(max(ord($sound_letter{$j}) - 1, 0x00), min(ord($sound_letter{$j}) + 1, 0xFF))); |
|
| 81 | + } |
|
| 73 | 82 | break; |
| 74 | 83 | |
| 75 | 84 | case 1: |
| 76 | - for ($j = 0, $n = strlen($sound_letter) - 1; $j < $n; $j += 2) |
|
| 77 | - $sound_word .= (random_int(0, 3) == 0 ? '' : $sound_letter{$j}) . (random_int(0, 3) === 0 ? $sound_letter{$j + 1} : $sound_letter{$j}) . (random_int(0, 3) === 0 ? $sound_letter{$j} : $sound_letter{$j + 1}) . $sound_letter{$j + 1} . (random_int(0, 3) == 0 ? $sound_letter{$j + 1} : ''); |
|
| 85 | + for ($j = 0, $n = strlen($sound_letter) - 1; $j < $n; $j += 2) { |
|
| 86 | + $sound_word .= (random_int(0, 3) == 0 ? '' : $sound_letter{$j}) . (random_int(0, 3) === 0 ? $sound_letter{$j + 1} : $sound_letter{$j}) . (random_int(0, 3) === 0 ? $sound_letter{$j} : $sound_letter{$j + 1}) . $sound_letter{$j + 1} . (random_int(0, 3) == 0 ? $sound_letter{$j + 1} : ''); |
|
| 87 | + } |
|
| 78 | 88 | $sound_word .= str_repeat($sound_letter{$n}, 2); |
| 79 | 89 | break; |
| 80 | 90 | |
@@ -82,10 +92,12 @@ discard block |
||
| 82 | 92 | $shift = 0; |
| 83 | 93 | for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++) |
| 84 | 94 | { |
| 85 | - if (random_int(0, 10) === 0) |
|
| 86 | - $shift += random_int(-3, 3); |
|
| 87 | - for ($k = 0, $m = round(random_int(15, 25) / 10); $k < $m; $k++) |
|
| 88 | - $sound_word .= chr(min(max(ord($sound_letter{$j}) + $shift, 0x00), 0xFF)); |
|
| 95 | + if (random_int(0, 10) === 0) { |
|
| 96 | + $shift += random_int(-3, 3); |
|
| 97 | + } |
|
| 98 | + for ($k = 0, $m = round(random_int(15, 25) / 10); $k < $m; $k++) { |
|
| 99 | + $sound_word .= chr(min(max(ord($sound_letter{$j}) + $shift, 0x00), 0xFF)); |
|
| 100 | + } |
|
| 89 | 101 | } |
| 90 | 102 | break; |
| 91 | 103 | } |
@@ -1,204 +1,204 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | if (!is_callable('random_int')) { |
| 4 | - /** |
|
| 5 | - * Random_* Compatibility Library |
|
| 6 | - * for using the new PHP 7 random_* API in PHP 5 projects |
|
| 7 | - * |
|
| 8 | - * The MIT License (MIT) |
|
| 9 | - * |
|
| 10 | - * Copyright (c) 2015 - 2018 Paragon Initiative Enterprises |
|
| 11 | - * |
|
| 12 | - * Permission is hereby granted, free of charge, to any person obtaining a copy |
|
| 13 | - * of this software and associated documentation files (the "Software"), to deal |
|
| 14 | - * in the Software without restriction, including without limitation the rights |
|
| 15 | - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
| 16 | - * copies of the Software, and to permit persons to whom the Software is |
|
| 17 | - * furnished to do so, subject to the following conditions: |
|
| 18 | - * |
|
| 19 | - * The above copyright notice and this permission notice shall be included in |
|
| 20 | - * all copies or substantial portions of the Software. |
|
| 21 | - * |
|
| 22 | - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
| 23 | - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
| 24 | - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
| 25 | - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
| 26 | - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
| 27 | - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|
| 28 | - * SOFTWARE. |
|
| 29 | - */ |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * Fetch a random integer between $min and $max inclusive |
|
| 33 | - * |
|
| 34 | - * @param int $min |
|
| 35 | - * @param int $max |
|
| 36 | - * |
|
| 37 | - * @throws Exception |
|
| 38 | - * |
|
| 39 | - * @return int |
|
| 40 | - */ |
|
| 41 | - function random_int($min, $max) |
|
| 42 | - { |
|
| 43 | - /** |
|
| 44 | - * Type and input logic checks |
|
| 45 | - * |
|
| 46 | - * If you pass it a float in the range (~PHP_INT_MAX, PHP_INT_MAX) |
|
| 47 | - * (non-inclusive), it will sanely cast it to an int. If you it's equal to |
|
| 48 | - * ~PHP_INT_MAX or PHP_INT_MAX, we let it fail as not an integer. Floats |
|
| 49 | - * lose precision, so the <= and => operators might accidentally let a float |
|
| 50 | - * through. |
|
| 51 | - */ |
|
| 52 | - |
|
| 53 | - try { |
|
| 54 | - /** @var int $min */ |
|
| 55 | - $min = RandomCompat_intval($min); |
|
| 56 | - } catch (TypeError $ex) { |
|
| 57 | - throw new TypeError( |
|
| 58 | - 'random_int(): $min must be an integer' |
|
| 59 | - ); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - try { |
|
| 63 | - /** @var int $max */ |
|
| 64 | - $max = RandomCompat_intval($max); |
|
| 65 | - } catch (TypeError $ex) { |
|
| 66 | - throw new TypeError( |
|
| 67 | - 'random_int(): $max must be an integer' |
|
| 68 | - ); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * Now that we've verified our weak typing system has given us an integer, |
|
| 73 | - * let's validate the logic then we can move forward with generating random |
|
| 74 | - * integers along a given range. |
|
| 75 | - */ |
|
| 76 | - if ($min > $max) { |
|
| 77 | - throw new Error( |
|
| 78 | - 'Minimum value must be less than or equal to the maximum value' |
|
| 79 | - ); |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - if ($max === $min) { |
|
| 83 | - return (int) $min; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Initialize variables to 0 |
|
| 88 | - * |
|
| 89 | - * We want to store: |
|
| 90 | - * $bytes => the number of random bytes we need |
|
| 91 | - * $mask => an integer bitmask (for use with the &) operator |
|
| 92 | - * so we can minimize the number of discards |
|
| 93 | - */ |
|
| 94 | - $attempts = $bits = $bytes = $mask = $valueShift = 0; |
|
| 95 | - /** @var int $attempts */ |
|
| 96 | - /** @var int $bits */ |
|
| 97 | - /** @var int $bytes */ |
|
| 98 | - /** @var int $mask */ |
|
| 99 | - /** @var int $valueShift */ |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * At this point, $range is a positive number greater than 0. It might |
|
| 103 | - * overflow, however, if $max - $min > PHP_INT_MAX. PHP will cast it to |
|
| 104 | - * a float and we will lose some precision. |
|
| 105 | - * |
|
| 106 | - * @var int|float $range |
|
| 107 | - */ |
|
| 108 | - $range = $max - $min; |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Test for integer overflow: |
|
| 112 | - */ |
|
| 113 | - if (!is_int($range)) { |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * Still safely calculate wider ranges. |
|
| 117 | - * Provided by @CodesInChaos, @oittaa |
|
| 118 | - * |
|
| 119 | - * @ref https://gist.github.com/CodesInChaos/03f9ea0b58e8b2b8d435 |
|
| 120 | - * |
|
| 121 | - * We use ~0 as a mask in this case because it generates all 1s |
|
| 122 | - * |
|
| 123 | - * @ref https://eval.in/400356 (32-bit) |
|
| 124 | - * @ref http://3v4l.org/XX9r5 (64-bit) |
|
| 125 | - */ |
|
| 126 | - $bytes = PHP_INT_SIZE; |
|
| 127 | - /** @var int $mask */ |
|
| 128 | - $mask = ~0; |
|
| 129 | - |
|
| 130 | - } else { |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * $bits is effectively ceil(log($range, 2)) without dealing with |
|
| 134 | - * type juggling |
|
| 135 | - */ |
|
| 136 | - while ($range > 0) { |
|
| 137 | - if ($bits % 8 === 0) { |
|
| 138 | - ++$bytes; |
|
| 139 | - } |
|
| 140 | - ++$bits; |
|
| 141 | - $range >>= 1; |
|
| 142 | - /** @var int $mask */ |
|
| 143 | - $mask = $mask << 1 | 1; |
|
| 144 | - } |
|
| 145 | - $valueShift = $min; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - /** @var int $val */ |
|
| 149 | - $val = 0; |
|
| 150 | - /** |
|
| 151 | - * Now that we have our parameters set up, let's begin generating |
|
| 152 | - * random integers until one falls between $min and $max |
|
| 153 | - */ |
|
| 154 | - /** @psalm-suppress RedundantCondition */ |
|
| 155 | - do { |
|
| 156 | - /** |
|
| 157 | - * The rejection probability is at most 0.5, so this corresponds |
|
| 158 | - * to a failure probability of 2^-128 for a working RNG |
|
| 159 | - */ |
|
| 160 | - if ($attempts > 128) { |
|
| 161 | - throw new Exception( |
|
| 162 | - 'random_int: RNG is broken - too many rejections' |
|
| 163 | - ); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * Let's grab the necessary number of random bytes |
|
| 168 | - */ |
|
| 169 | - $randomByteString = random_bytes($bytes); |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * Let's turn $randomByteString into an integer |
|
| 173 | - * |
|
| 174 | - * This uses bitwise operators (<< and |) to build an integer |
|
| 175 | - * out of the values extracted from ord() |
|
| 176 | - * |
|
| 177 | - * Example: [9F] | [6D] | [32] | [0C] => |
|
| 178 | - * 159 + 27904 + 3276800 + 201326592 => |
|
| 179 | - * 204631455 |
|
| 180 | - */ |
|
| 181 | - $val &= 0; |
|
| 182 | - for ($i = 0; $i < $bytes; ++$i) { |
|
| 183 | - $val |= ord($randomByteString[$i]) << ($i * 8); |
|
| 184 | - } |
|
| 185 | - /** @var int $val */ |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * Apply mask |
|
| 189 | - */ |
|
| 190 | - $val &= $mask; |
|
| 191 | - $val += $valueShift; |
|
| 192 | - |
|
| 193 | - ++$attempts; |
|
| 194 | - /** |
|
| 195 | - * If $val overflows to a floating point number, |
|
| 196 | - * ... or is larger than $max, |
|
| 197 | - * ... or smaller than $min, |
|
| 198 | - * then try again. |
|
| 199 | - */ |
|
| 200 | - } while (!is_int($val) || $val > $max || $val < $min); |
|
| 201 | - |
|
| 202 | - return (int) $val; |
|
| 203 | - } |
|
| 4 | + /** |
|
| 5 | + * Random_* Compatibility Library |
|
| 6 | + * for using the new PHP 7 random_* API in PHP 5 projects |
|
| 7 | + * |
|
| 8 | + * The MIT License (MIT) |
|
| 9 | + * |
|
| 10 | + * Copyright (c) 2015 - 2018 Paragon Initiative Enterprises |
|
| 11 | + * |
|
| 12 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
|
| 13 | + * of this software and associated documentation files (the "Software"), to deal |
|
| 14 | + * in the Software without restriction, including without limitation the rights |
|
| 15 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
| 16 | + * copies of the Software, and to permit persons to whom the Software is |
|
| 17 | + * furnished to do so, subject to the following conditions: |
|
| 18 | + * |
|
| 19 | + * The above copyright notice and this permission notice shall be included in |
|
| 20 | + * all copies or substantial portions of the Software. |
|
| 21 | + * |
|
| 22 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
| 23 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
| 24 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
| 25 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
| 26 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
| 27 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|
| 28 | + * SOFTWARE. |
|
| 29 | + */ |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * Fetch a random integer between $min and $max inclusive |
|
| 33 | + * |
|
| 34 | + * @param int $min |
|
| 35 | + * @param int $max |
|
| 36 | + * |
|
| 37 | + * @throws Exception |
|
| 38 | + * |
|
| 39 | + * @return int |
|
| 40 | + */ |
|
| 41 | + function random_int($min, $max) |
|
| 42 | + { |
|
| 43 | + /** |
|
| 44 | + * Type and input logic checks |
|
| 45 | + * |
|
| 46 | + * If you pass it a float in the range (~PHP_INT_MAX, PHP_INT_MAX) |
|
| 47 | + * (non-inclusive), it will sanely cast it to an int. If you it's equal to |
|
| 48 | + * ~PHP_INT_MAX or PHP_INT_MAX, we let it fail as not an integer. Floats |
|
| 49 | + * lose precision, so the <= and => operators might accidentally let a float |
|
| 50 | + * through. |
|
| 51 | + */ |
|
| 52 | + |
|
| 53 | + try { |
|
| 54 | + /** @var int $min */ |
|
| 55 | + $min = RandomCompat_intval($min); |
|
| 56 | + } catch (TypeError $ex) { |
|
| 57 | + throw new TypeError( |
|
| 58 | + 'random_int(): $min must be an integer' |
|
| 59 | + ); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + try { |
|
| 63 | + /** @var int $max */ |
|
| 64 | + $max = RandomCompat_intval($max); |
|
| 65 | + } catch (TypeError $ex) { |
|
| 66 | + throw new TypeError( |
|
| 67 | + 'random_int(): $max must be an integer' |
|
| 68 | + ); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * Now that we've verified our weak typing system has given us an integer, |
|
| 73 | + * let's validate the logic then we can move forward with generating random |
|
| 74 | + * integers along a given range. |
|
| 75 | + */ |
|
| 76 | + if ($min > $max) { |
|
| 77 | + throw new Error( |
|
| 78 | + 'Minimum value must be less than or equal to the maximum value' |
|
| 79 | + ); |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + if ($max === $min) { |
|
| 83 | + return (int) $min; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Initialize variables to 0 |
|
| 88 | + * |
|
| 89 | + * We want to store: |
|
| 90 | + * $bytes => the number of random bytes we need |
|
| 91 | + * $mask => an integer bitmask (for use with the &) operator |
|
| 92 | + * so we can minimize the number of discards |
|
| 93 | + */ |
|
| 94 | + $attempts = $bits = $bytes = $mask = $valueShift = 0; |
|
| 95 | + /** @var int $attempts */ |
|
| 96 | + /** @var int $bits */ |
|
| 97 | + /** @var int $bytes */ |
|
| 98 | + /** @var int $mask */ |
|
| 99 | + /** @var int $valueShift */ |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * At this point, $range is a positive number greater than 0. It might |
|
| 103 | + * overflow, however, if $max - $min > PHP_INT_MAX. PHP will cast it to |
|
| 104 | + * a float and we will lose some precision. |
|
| 105 | + * |
|
| 106 | + * @var int|float $range |
|
| 107 | + */ |
|
| 108 | + $range = $max - $min; |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Test for integer overflow: |
|
| 112 | + */ |
|
| 113 | + if (!is_int($range)) { |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * Still safely calculate wider ranges. |
|
| 117 | + * Provided by @CodesInChaos, @oittaa |
|
| 118 | + * |
|
| 119 | + * @ref https://gist.github.com/CodesInChaos/03f9ea0b58e8b2b8d435 |
|
| 120 | + * |
|
| 121 | + * We use ~0 as a mask in this case because it generates all 1s |
|
| 122 | + * |
|
| 123 | + * @ref https://eval.in/400356 (32-bit) |
|
| 124 | + * @ref http://3v4l.org/XX9r5 (64-bit) |
|
| 125 | + */ |
|
| 126 | + $bytes = PHP_INT_SIZE; |
|
| 127 | + /** @var int $mask */ |
|
| 128 | + $mask = ~0; |
|
| 129 | + |
|
| 130 | + } else { |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * $bits is effectively ceil(log($range, 2)) without dealing with |
|
| 134 | + * type juggling |
|
| 135 | + */ |
|
| 136 | + while ($range > 0) { |
|
| 137 | + if ($bits % 8 === 0) { |
|
| 138 | + ++$bytes; |
|
| 139 | + } |
|
| 140 | + ++$bits; |
|
| 141 | + $range >>= 1; |
|
| 142 | + /** @var int $mask */ |
|
| 143 | + $mask = $mask << 1 | 1; |
|
| 144 | + } |
|
| 145 | + $valueShift = $min; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + /** @var int $val */ |
|
| 149 | + $val = 0; |
|
| 150 | + /** |
|
| 151 | + * Now that we have our parameters set up, let's begin generating |
|
| 152 | + * random integers until one falls between $min and $max |
|
| 153 | + */ |
|
| 154 | + /** @psalm-suppress RedundantCondition */ |
|
| 155 | + do { |
|
| 156 | + /** |
|
| 157 | + * The rejection probability is at most 0.5, so this corresponds |
|
| 158 | + * to a failure probability of 2^-128 for a working RNG |
|
| 159 | + */ |
|
| 160 | + if ($attempts > 128) { |
|
| 161 | + throw new Exception( |
|
| 162 | + 'random_int: RNG is broken - too many rejections' |
|
| 163 | + ); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * Let's grab the necessary number of random bytes |
|
| 168 | + */ |
|
| 169 | + $randomByteString = random_bytes($bytes); |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * Let's turn $randomByteString into an integer |
|
| 173 | + * |
|
| 174 | + * This uses bitwise operators (<< and |) to build an integer |
|
| 175 | + * out of the values extracted from ord() |
|
| 176 | + * |
|
| 177 | + * Example: [9F] | [6D] | [32] | [0C] => |
|
| 178 | + * 159 + 27904 + 3276800 + 201326592 => |
|
| 179 | + * 204631455 |
|
| 180 | + */ |
|
| 181 | + $val &= 0; |
|
| 182 | + for ($i = 0; $i < $bytes; ++$i) { |
|
| 183 | + $val |= ord($randomByteString[$i]) << ($i * 8); |
|
| 184 | + } |
|
| 185 | + /** @var int $val */ |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * Apply mask |
|
| 189 | + */ |
|
| 190 | + $val &= $mask; |
|
| 191 | + $val += $valueShift; |
|
| 192 | + |
|
| 193 | + ++$attempts; |
|
| 194 | + /** |
|
| 195 | + * If $val overflows to a floating point number, |
|
| 196 | + * ... or is larger than $max, |
|
| 197 | + * ... or smaller than $min, |
|
| 198 | + * then try again. |
|
| 199 | + */ |
|
| 200 | + } while (!is_int($val) || $val > $max || $val < $min); |
|
| 201 | + |
|
| 202 | + return (int) $val; |
|
| 203 | + } |
|
| 204 | 204 | } |
@@ -18,8 +18,9 @@ discard block |
||
| 18 | 18 | * @version 2.1 Beta 4 |
| 19 | 19 | */ |
| 20 | 20 | |
| 21 | -if (!defined('SMF')) |
|
| 21 | +if (!defined('SMF')) { |
|
| 22 | 22 | die('No direct access...'); |
| 23 | +} |
|
| 23 | 24 | |
| 24 | 25 | /** |
| 25 | 26 | * downloads a file from a url and stores it locally for avatar use by id_member. |
@@ -44,8 +45,9 @@ discard block |
||
| 44 | 45 | $destName = 'avatar_' . $memID . '_' . time() . '.' . $ext; |
| 45 | 46 | |
| 46 | 47 | // Just making sure there is a non-zero member. |
| 47 | - if (empty($memID)) |
|
| 48 | - return false; |
|
| 48 | + if (empty($memID)) { |
|
| 49 | + return false; |
|
| 50 | + } |
|
| 49 | 51 | |
| 50 | 52 | require_once($sourcedir . '/ManageAttachments.php'); |
| 51 | 53 | removeAttachments(array('id_member' => $memID)); |
@@ -76,10 +78,11 @@ discard block |
||
| 76 | 78 | $destName = $modSettings['custom_avatar_dir'] . '/' . $destName . '.tmp'; |
| 77 | 79 | |
| 78 | 80 | // Resize it. |
| 79 | - if (!empty($modSettings['avatar_download_png'])) |
|
| 80 | - $success = resizeImageFile($url, $destName, $max_width, $max_height, 3); |
|
| 81 | - else |
|
| 82 | - $success = resizeImageFile($url, $destName, $max_width, $max_height); |
|
| 81 | + if (!empty($modSettings['avatar_download_png'])) { |
|
| 82 | + $success = resizeImageFile($url, $destName, $max_width, $max_height, 3); |
|
| 83 | + } else { |
|
| 84 | + $success = resizeImageFile($url, $destName, $max_width, $max_height); |
|
| 85 | + } |
|
| 83 | 86 | |
| 84 | 87 | // Remove the .tmp extension. |
| 85 | 88 | $destName = substr($destName, 0, -4); |
@@ -108,11 +111,10 @@ discard block |
||
| 108 | 111 | ) |
| 109 | 112 | ); |
| 110 | 113 | return true; |
| 114 | + } else { |
|
| 115 | + return false; |
|
| 111 | 116 | } |
| 112 | - else |
|
| 113 | - return false; |
|
| 114 | - } |
|
| 115 | - else |
|
| 117 | + } else |
|
| 116 | 118 | { |
| 117 | 119 | $smcFunc['db_query']('', ' |
| 118 | 120 | DELETE FROM {db_prefix}attachments |
@@ -144,17 +146,18 @@ discard block |
||
| 144 | 146 | $destName = $source . '_thumb.tmp'; |
| 145 | 147 | |
| 146 | 148 | // Do the actual resize. |
| 147 | - if (!empty($modSettings['attachment_thumb_png'])) |
|
| 148 | - $success = resizeImageFile($source, $destName, $max_width, $max_height, 3); |
|
| 149 | - else |
|
| 150 | - $success = resizeImageFile($source, $destName, $max_width, $max_height); |
|
| 149 | + if (!empty($modSettings['attachment_thumb_png'])) { |
|
| 150 | + $success = resizeImageFile($source, $destName, $max_width, $max_height, 3); |
|
| 151 | + } else { |
|
| 152 | + $success = resizeImageFile($source, $destName, $max_width, $max_height); |
|
| 153 | + } |
|
| 151 | 154 | |
| 152 | 155 | // Okay, we're done with the temporary stuff. |
| 153 | 156 | $destName = substr($destName, 0, -4); |
| 154 | 157 | |
| 155 | - if ($success && @rename($destName . '.tmp', $destName)) |
|
| 156 | - return true; |
|
| 157 | - else |
|
| 158 | + if ($success && @rename($destName . '.tmp', $destName)) { |
|
| 159 | + return true; |
|
| 160 | + } else |
|
| 158 | 161 | { |
| 159 | 162 | @unlink($destName . '.tmp'); |
| 160 | 163 | @touch($destName); |
@@ -176,18 +179,21 @@ discard block |
||
| 176 | 179 | { |
| 177 | 180 | if (!resizeImageFile($fileName, $fileName . '.tmp', null, null, $preferred_format)) |
| 178 | 181 | { |
| 179 | - if (file_exists($fileName . '.tmp')) |
|
| 180 | - unlink($fileName . '.tmp'); |
|
| 182 | + if (file_exists($fileName . '.tmp')) { |
|
| 183 | + unlink($fileName . '.tmp'); |
|
| 184 | + } |
|
| 181 | 185 | |
| 182 | 186 | return false; |
| 183 | 187 | } |
| 184 | 188 | |
| 185 | - if (!unlink($fileName)) |
|
| 186 | - return false; |
|
| 189 | + if (!unlink($fileName)) { |
|
| 190 | + return false; |
|
| 191 | + } |
|
| 187 | 192 | |
| 188 | - if (!rename($fileName . '.tmp', $fileName)) |
|
| 189 | - return false; |
|
| 190 | -} |
|
| 193 | + if (!rename($fileName . '.tmp', $fileName)) { |
|
| 194 | + return false; |
|
| 195 | + } |
|
| 196 | + } |
|
| 191 | 197 | |
| 192 | 198 | /** |
| 193 | 199 | * Searches through the file to see if there's potentially harmful non-binary content. |
@@ -200,8 +206,9 @@ discard block |
||
| 200 | 206 | function checkImageContents($fileName, $extensiveCheck = false) |
| 201 | 207 | { |
| 202 | 208 | $fp = fopen($fileName, 'rb'); |
| 203 | - if (!$fp) |
|
| 204 | - fatal_lang_error('attach_timeout'); |
|
| 209 | + if (!$fp) { |
|
| 210 | + fatal_lang_error('attach_timeout'); |
|
| 211 | + } |
|
| 205 | 212 | |
| 206 | 213 | $prev_chunk = ''; |
| 207 | 214 | while (!feof($fp)) |
@@ -218,8 +225,7 @@ discard block |
||
| 218 | 225 | fclose($fp); |
| 219 | 226 | return false; |
| 220 | 227 | } |
| 221 | - } |
|
| 222 | - else |
|
| 228 | + } else |
|
| 223 | 229 | { |
| 224 | 230 | // Check for potential infection - focus on clues for inline php & flash. |
| 225 | 231 | // Will result in significantly fewer false positives than the paranoid check. |
@@ -247,8 +253,9 @@ discard block |
||
| 247 | 253 | global $gd2; |
| 248 | 254 | |
| 249 | 255 | // Check to see if GD is installed and what version. |
| 250 | - if (($extensionFunctions = get_extension_funcs('gd')) === false) |
|
| 251 | - return false; |
|
| 256 | + if (($extensionFunctions = get_extension_funcs('gd')) === false) { |
|
| 257 | + return false; |
|
| 258 | + } |
|
| 252 | 259 | |
| 253 | 260 | // Also determine if GD2 is installed and store it in a global. |
| 254 | 261 | $gd2 = in_array('imagecreatetruecolor', $extensionFunctions) && function_exists('imagecreatetruecolor'); |
@@ -320,8 +327,9 @@ discard block |
||
| 320 | 327 | global $sourcedir; |
| 321 | 328 | |
| 322 | 329 | // Nothing to do without GD or IM/MW |
| 323 | - if (!checkGD() && !checkImagick() && !checkMagickWand()) |
|
| 324 | - return false; |
|
| 330 | + if (!checkGD() && !checkImagick() && !checkMagickWand()) { |
|
| 331 | + return false; |
|
| 332 | + } |
|
| 325 | 333 | |
| 326 | 334 | static $default_formats = array( |
| 327 | 335 | '1' => 'gif', |
@@ -341,38 +349,39 @@ discard block |
||
| 341 | 349 | fclose($fp_destination); |
| 342 | 350 | |
| 343 | 351 | $sizes = @getimagesize($destination); |
| 344 | - } |
|
| 345 | - elseif ($fp_destination) |
|
| 352 | + } elseif ($fp_destination) |
|
| 346 | 353 | { |
| 347 | 354 | $sizes = @getimagesize($source); |
| 348 | 355 | |
| 349 | 356 | $fp_source = fopen($source, 'rb'); |
| 350 | 357 | if ($fp_source !== false) |
| 351 | 358 | { |
| 352 | - while (!feof($fp_source)) |
|
| 353 | - fwrite($fp_destination, fread($fp_source, 8192)); |
|
| 359 | + while (!feof($fp_source)) { |
|
| 360 | + fwrite($fp_destination, fread($fp_source, 8192)); |
|
| 361 | + } |
|
| 354 | 362 | fclose($fp_source); |
| 363 | + } else { |
|
| 364 | + $sizes = array(-1, -1, -1); |
|
| 355 | 365 | } |
| 356 | - else |
|
| 357 | - $sizes = array(-1, -1, -1); |
|
| 358 | 366 | fclose($fp_destination); |
| 359 | 367 | } |
| 360 | 368 | // We can't get to the file. |
| 361 | - else |
|
| 362 | - $sizes = array(-1, -1, -1); |
|
| 369 | + else { |
|
| 370 | + $sizes = array(-1, -1, -1); |
|
| 371 | + } |
|
| 363 | 372 | |
| 364 | 373 | // See if we have -or- can get the needed memory for this operation |
| 365 | 374 | // ImageMagick isn't subject to PHP's memory limits :) |
| 366 | - if (!(checkIMagick() || checkMagickWand()) && checkGD() && !imageMemoryCheck($sizes)) |
|
| 367 | - return false; |
|
| 375 | + if (!(checkIMagick() || checkMagickWand()) && checkGD() && !imageMemoryCheck($sizes)) { |
|
| 376 | + return false; |
|
| 377 | + } |
|
| 368 | 378 | |
| 369 | 379 | // A known and supported format? |
| 370 | 380 | // @todo test PSD and gif. |
| 371 | 381 | if ((checkImagick() || checkMagickWand()) && isset($default_formats[$sizes[2]])) |
| 372 | 382 | { |
| 373 | 383 | return resizeImage(null, $destination, null, null, $max_width, $max_height, true, $preferred_format); |
| 374 | - } |
|
| 375 | - elseif (checkGD() && isset($default_formats[$sizes[2]]) && function_exists('imagecreatefrom' . $default_formats[$sizes[2]])) |
|
| 384 | + } elseif (checkGD() && isset($default_formats[$sizes[2]]) && function_exists('imagecreatefrom' . $default_formats[$sizes[2]])) |
|
| 376 | 385 | { |
| 377 | 386 | $imagecreatefrom = 'imagecreatefrom' . $default_formats[$sizes[2]]; |
| 378 | 387 | if ($src_img = @$imagecreatefrom($destination)) |
@@ -425,14 +434,14 @@ discard block |
||
| 425 | 434 | $dest_width = empty($max_width) ? $src_width : $max_width; |
| 426 | 435 | $dest_height = empty($max_height) ? $src_height : $max_height; |
| 427 | 436 | |
| 428 | - if ($default_formats[$preferred_format] == 'jpeg') |
|
| 429 | - $imagick->setCompressionQuality(!empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82); |
|
| 437 | + if ($default_formats[$preferred_format] == 'jpeg') { |
|
| 438 | + $imagick->setCompressionQuality(!empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82); |
|
| 439 | + } |
|
| 430 | 440 | |
| 431 | 441 | $imagick->setImageFormat($default_formats[$preferred_format]); |
| 432 | 442 | $imagick->resizeImage($dest_width, $dest_height, Imagick::FILTER_LANCZOS, 1, true); |
| 433 | 443 | $success = $imagick->writeImage($destName); |
| 434 | - } |
|
| 435 | - else |
|
| 444 | + } else |
|
| 436 | 445 | { |
| 437 | 446 | $magick_wand = newMagickWand(); |
| 438 | 447 | MagickReadImage($magick_wand, $destName); |
@@ -441,8 +450,9 @@ discard block |
||
| 441 | 450 | $dest_width = empty($max_width) ? $src_width : $max_width; |
| 442 | 451 | $dest_height = empty($max_height) ? $src_height : $max_height; |
| 443 | 452 | |
| 444 | - if ($default_formats[$preferred_format] == 'jpeg') |
|
| 445 | - MagickSetCompressionQuality($magick_wand, !empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82); |
|
| 453 | + if ($default_formats[$preferred_format] == 'jpeg') { |
|
| 454 | + MagickSetCompressionQuality($magick_wand, !empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82); |
|
| 455 | + } |
|
| 446 | 456 | |
| 447 | 457 | MagickSetImageFormat($magick_wand, $default_formats[$preferred_format]); |
| 448 | 458 | MagickResizeImage($magick_wand, $dest_width, $dest_height, MW_LanczosFilter, 1, true); |
@@ -450,8 +460,7 @@ discard block |
||
| 450 | 460 | } |
| 451 | 461 | |
| 452 | 462 | return !empty($success); |
| 453 | - } |
|
| 454 | - elseif (checkGD()) |
|
| 463 | + } elseif (checkGD()) |
|
| 455 | 464 | { |
| 456 | 465 | $success = false; |
| 457 | 466 | |
@@ -462,8 +471,7 @@ discard block |
||
| 462 | 471 | { |
| 463 | 472 | $dst_width = $max_width; |
| 464 | 473 | $dst_height = round($src_height * $max_width / $src_width); |
| 465 | - } |
|
| 466 | - elseif (!empty($max_height)) |
|
| 474 | + } elseif (!empty($max_height)) |
|
| 467 | 475 | { |
| 468 | 476 | $dst_width = round($src_width * $max_height / $src_height); |
| 469 | 477 | $dst_height = $max_height; |
@@ -481,44 +489,48 @@ discard block |
||
| 481 | 489 | if ((!empty($preferred_format)) && ($preferred_format == 3)) |
| 482 | 490 | { |
| 483 | 491 | imagealphablending($dst_img, false); |
| 484 | - if (function_exists('imagesavealpha')) |
|
| 485 | - imagesavealpha($dst_img, true); |
|
| 492 | + if (function_exists('imagesavealpha')) { |
|
| 493 | + imagesavealpha($dst_img, true); |
|
| 494 | + } |
|
| 486 | 495 | } |
| 496 | + } else { |
|
| 497 | + $dst_img = imagecreate($dst_width, $dst_height); |
|
| 487 | 498 | } |
| 488 | - else |
|
| 489 | - $dst_img = imagecreate($dst_width, $dst_height); |
|
| 490 | 499 | |
| 491 | 500 | // Resize it! |
| 492 | - if ($gd2) |
|
| 493 | - imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height); |
|
| 494 | - else |
|
| 495 | - imagecopyresamplebicubic($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height); |
|
| 501 | + if ($gd2) { |
|
| 502 | + imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height); |
|
| 503 | + } else { |
|
| 504 | + imagecopyresamplebicubic($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height); |
|
| 505 | + } |
|
| 506 | + } else { |
|
| 507 | + $dst_img = $src_img; |
|
| 496 | 508 | } |
| 497 | - else |
|
| 498 | - $dst_img = $src_img; |
|
| 509 | + } else { |
|
| 510 | + $dst_img = $src_img; |
|
| 499 | 511 | } |
| 500 | - else |
|
| 501 | - $dst_img = $src_img; |
|
| 502 | 512 | |
| 503 | 513 | // Save the image as ... |
| 504 | - if (!empty($preferred_format) && ($preferred_format == 3) && function_exists('imagepng')) |
|
| 505 | - $success = imagepng($dst_img, $destName); |
|
| 506 | - elseif (!empty($preferred_format) && ($preferred_format == 1) && function_exists('imagegif')) |
|
| 507 | - $success = imagegif($dst_img, $destName); |
|
| 508 | - elseif (function_exists('imagejpeg')) |
|
| 509 | - $success = imagejpeg($dst_img, $destName, !empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82); |
|
| 514 | + if (!empty($preferred_format) && ($preferred_format == 3) && function_exists('imagepng')) { |
|
| 515 | + $success = imagepng($dst_img, $destName); |
|
| 516 | + } elseif (!empty($preferred_format) && ($preferred_format == 1) && function_exists('imagegif')) { |
|
| 517 | + $success = imagegif($dst_img, $destName); |
|
| 518 | + } elseif (function_exists('imagejpeg')) { |
|
| 519 | + $success = imagejpeg($dst_img, $destName, !empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82); |
|
| 520 | + } |
|
| 510 | 521 | |
| 511 | 522 | // Free the memory. |
| 512 | 523 | imagedestroy($src_img); |
| 513 | - if ($dst_img != $src_img) |
|
| 514 | - imagedestroy($dst_img); |
|
| 524 | + if ($dst_img != $src_img) { |
|
| 525 | + imagedestroy($dst_img); |
|
| 526 | + } |
|
| 515 | 527 | |
| 516 | 528 | return $success; |
| 517 | - } |
|
| 518 | - else |
|
| 519 | - // Without GD, no image resizing at all. |
|
| 529 | + } else { |
|
| 530 | + // Without GD, no image resizing at all. |
|
| 520 | 531 | return false; |
| 521 | -} |
|
| 532 | + } |
|
| 533 | + } |
|
| 522 | 534 | |
| 523 | 535 | /** |
| 524 | 536 | * Copy image. |
@@ -572,8 +584,9 @@ discard block |
||
| 572 | 584 | $color = imagecolorresolve($dst_img, $red, $green, $blue); |
| 573 | 585 | if ($color == -1) |
| 574 | 586 | { |
| 575 | - if ($palsize++ < 256) |
|
| 576 | - imagecolorallocate($dst_img, $red, $green, $blue); |
|
| 587 | + if ($palsize++ < 256) { |
|
| 588 | + imagecolorallocate($dst_img, $red, $green, $blue); |
|
| 589 | + } |
|
| 577 | 590 | $color = imagecolorclosest($dst_img, $red, $green, $blue); |
| 578 | 591 | } |
| 579 | 592 | |
@@ -603,13 +616,15 @@ discard block |
||
| 603 | 616 | $header = unpack('vtype/Vsize/Vreserved/Voffset', fread($fp, 14)); |
| 604 | 617 | $info = unpack('Vsize/Vwidth/Vheight/vplanes/vbits/Vcompression/Vimagesize/Vxres/Vyres/Vncolor/Vcolorimportant', fread($fp, 40)); |
| 605 | 618 | |
| 606 | - if ($header['type'] != 0x4D42) |
|
| 607 | - return false; |
|
| 619 | + if ($header['type'] != 0x4D42) { |
|
| 620 | + return false; |
|
| 621 | + } |
|
| 608 | 622 | |
| 609 | - if ($gd2) |
|
| 610 | - $dst_img = imagecreatetruecolor($info['width'], $info['height']); |
|
| 611 | - else |
|
| 612 | - $dst_img = imagecreate($info['width'], $info['height']); |
|
| 623 | + if ($gd2) { |
|
| 624 | + $dst_img = imagecreatetruecolor($info['width'], $info['height']); |
|
| 625 | + } else { |
|
| 626 | + $dst_img = imagecreate($info['width'], $info['height']); |
|
| 627 | + } |
|
| 613 | 628 | |
| 614 | 629 | $palette_size = $header['offset'] - 54; |
| 615 | 630 | $info['ncolor'] = $palette_size / 4; |
@@ -635,8 +650,9 @@ discard block |
||
| 635 | 650 | fseek($fp, $header['offset'] + ($scan_line_size + $scan_line_align) * $l); |
| 636 | 651 | $scan_line = fread($fp, $scan_line_size); |
| 637 | 652 | |
| 638 | - if (strlen($scan_line) < $scan_line_size) |
|
| 639 | - continue; |
|
| 653 | + if (strlen($scan_line) < $scan_line_size) { |
|
| 654 | + continue; |
|
| 655 | + } |
|
| 640 | 656 | |
| 641 | 657 | if ($info['bits'] == 32) |
| 642 | 658 | { |
@@ -654,14 +670,14 @@ discard block |
||
| 654 | 670 | $color = imagecolorallocate($dst_img, $r, $g, $b); |
| 655 | 671 | |
| 656 | 672 | // Gah! Out of colors? Stupid GD 1... try anyhow. |
| 657 | - if ($color == -1) |
|
| 658 | - $color = imagecolorclosest($dst_img, $r, $g, $b); |
|
| 673 | + if ($color == -1) { |
|
| 674 | + $color = imagecolorclosest($dst_img, $r, $g, $b); |
|
| 675 | + } |
|
| 659 | 676 | } |
| 660 | 677 | |
| 661 | 678 | imagesetpixel($dst_img, $x, $y, $color); |
| 662 | 679 | } |
| 663 | - } |
|
| 664 | - elseif ($info['bits'] == 24) |
|
| 680 | + } elseif ($info['bits'] == 24) |
|
| 665 | 681 | { |
| 666 | 682 | $x = 0; |
| 667 | 683 | for ($j = 0; $j < $scan_line_size; $x++) |
@@ -676,14 +692,14 @@ discard block |
||
| 676 | 692 | $color = imagecolorallocate($dst_img, $r, $g, $b); |
| 677 | 693 | |
| 678 | 694 | // Gah! Out of colors? Stupid GD 1... try anyhow. |
| 679 | - if ($color == -1) |
|
| 680 | - $color = imagecolorclosest($dst_img, $r, $g, $b); |
|
| 695 | + if ($color == -1) { |
|
| 696 | + $color = imagecolorclosest($dst_img, $r, $g, $b); |
|
| 697 | + } |
|
| 681 | 698 | } |
| 682 | 699 | |
| 683 | 700 | imagesetpixel($dst_img, $x, $y, $color); |
| 684 | 701 | } |
| 685 | - } |
|
| 686 | - elseif ($info['bits'] == 16) |
|
| 702 | + } elseif ($info['bits'] == 16) |
|
| 687 | 703 | { |
| 688 | 704 | $x = 0; |
| 689 | 705 | for ($j = 0; $j < $scan_line_size; $x++) |
@@ -704,20 +720,20 @@ discard block |
||
| 704 | 720 | $color = imagecolorallocate($dst_img, $r, $g, $b); |
| 705 | 721 | |
| 706 | 722 | // Gah! Out of colors? Stupid GD 1... try anyhow. |
| 707 | - if ($color == -1) |
|
| 708 | - $color = imagecolorclosest($dst_img, $r, $g, $b); |
|
| 723 | + if ($color == -1) { |
|
| 724 | + $color = imagecolorclosest($dst_img, $r, $g, $b); |
|
| 725 | + } |
|
| 709 | 726 | } |
| 710 | 727 | |
| 711 | 728 | imagesetpixel($dst_img, $x, $y, $color); |
| 712 | 729 | } |
| 713 | - } |
|
| 714 | - elseif ($info['bits'] == 8) |
|
| 730 | + } elseif ($info['bits'] == 8) |
|
| 715 | 731 | { |
| 716 | 732 | $x = 0; |
| 717 | - for ($j = 0; $j < $scan_line_size; $x++) |
|
| 718 | - imagesetpixel($dst_img, $x, $y, $palette[ord($scan_line{$j++})]); |
|
| 719 | - } |
|
| 720 | - elseif ($info['bits'] == 4) |
|
| 733 | + for ($j = 0; $j < $scan_line_size; $x++) { |
|
| 734 | + imagesetpixel($dst_img, $x, $y, $palette[ord($scan_line{$j++})]); |
|
| 735 | + } |
|
| 736 | + } elseif ($info['bits'] == 4) |
|
| 721 | 737 | { |
| 722 | 738 | $x = 0; |
| 723 | 739 | for ($j = 0; $j < $scan_line_size; $x++) |
@@ -726,11 +742,11 @@ discard block |
||
| 726 | 742 | |
| 727 | 743 | imagesetpixel($dst_img, $x, $y, $palette[(int) ($byte / 16)]); |
| 728 | 744 | |
| 729 | - if (++$x < $info['width']) |
|
| 730 | - imagesetpixel($dst_img, $x, $y, $palette[$byte & 15]); |
|
| 745 | + if (++$x < $info['width']) { |
|
| 746 | + imagesetpixel($dst_img, $x, $y, $palette[$byte & 15]); |
|
| 747 | + } |
|
| 731 | 748 | } |
| 732 | - } |
|
| 733 | - elseif ($info['bits'] == 1) |
|
| 749 | + } elseif ($info['bits'] == 1) |
|
| 734 | 750 | { |
| 735 | 751 | $x = 0; |
| 736 | 752 | for ($j = 0; $j < $scan_line_size; $x++) |
@@ -741,8 +757,9 @@ discard block |
||
| 741 | 757 | |
| 742 | 758 | for ($shift = 1; $shift < 8; $shift++) |
| 743 | 759 | { |
| 744 | - if (++$x < $info['width']) |
|
| 745 | - imagesetpixel($dst_img, $x, $y, $palette[(($byte << $shift) & 128) != 0]); |
|
| 760 | + if (++$x < $info['width']) { |
|
| 761 | + imagesetpixel($dst_img, $x, $y, $palette[(($byte << $shift) & 128) != 0]); |
|
| 762 | + } |
|
| 746 | 763 | } |
| 747 | 764 | } |
| 748 | 765 | } |
@@ -766,15 +783,18 @@ discard block |
||
| 766 | 783 | */ |
| 767 | 784 | function gif_outputAsPng($gif, $lpszFileName, $background_color = -1) |
| 768 | 785 | { |
| 769 | - if (!isset($gif) || @get_class($gif) != 'cgif' || !$gif->loaded || $lpszFileName == '') |
|
| 770 | - return false; |
|
| 786 | + if (!isset($gif) || @get_class($gif) != 'cgif' || !$gif->loaded || $lpszFileName == '') { |
|
| 787 | + return false; |
|
| 788 | + } |
|
| 771 | 789 | |
| 772 | 790 | $fd = $gif->get_png_data($background_color); |
| 773 | - if (strlen($fd) <= 0) |
|
| 774 | - return false; |
|
| 791 | + if (strlen($fd) <= 0) { |
|
| 792 | + return false; |
|
| 793 | + } |
|
| 775 | 794 | |
| 776 | - if (!($fh = @fopen($lpszFileName, 'wb'))) |
|
| 777 | - return false; |
|
| 795 | + if (!($fh = @fopen($lpszFileName, 'wb'))) { |
|
| 796 | + return false; |
|
| 797 | + } |
|
| 778 | 798 | |
| 779 | 799 | @fwrite($fh, $fd, strlen($fd)); |
| 780 | 800 | @fflush($fh); |
@@ -801,8 +821,9 @@ discard block |
||
| 801 | 821 | // What type are we going to be doing? |
| 802 | 822 | $imageType = $modSettings['visual_verification_type']; |
| 803 | 823 | // Special case to allow the admin center to show samples. |
| 804 | - if ($user_info['is_admin'] && isset($_GET['type'])) |
|
| 805 | - $imageType = (int) $_GET['type']; |
|
| 824 | + if ($user_info['is_admin'] && isset($_GET['type'])) { |
|
| 825 | + $imageType = (int) $_GET['type']; |
|
| 826 | + } |
|
| 806 | 827 | |
| 807 | 828 | // Some quick references for what we do. |
| 808 | 829 | // Do we show no, low or high noise? |
@@ -836,25 +857,28 @@ discard block |
||
| 836 | 857 | $character_spacing = 1; |
| 837 | 858 | |
| 838 | 859 | // What color is the background - generally white unless we're on "hard". |
| 839 | - if ($simpleBGColor) |
|
| 840 | - $background_color = array(255, 255, 255); |
|
| 841 | - else |
|
| 842 | - $background_color = isset($settings['verification_background']) ? $settings['verification_background'] : array(236, 237, 243); |
|
| 860 | + if ($simpleBGColor) { |
|
| 861 | + $background_color = array(255, 255, 255); |
|
| 862 | + } else { |
|
| 863 | + $background_color = isset($settings['verification_background']) ? $settings['verification_background'] : array(236, 237, 243); |
|
| 864 | + } |
|
| 843 | 865 | |
| 844 | 866 | // The color of the characters shown (red, green, blue). |
| 845 | - if ($simpleFGColor) |
|
| 846 | - $foreground_color = array(0, 0, 0); |
|
| 847 | - else |
|
| 867 | + if ($simpleFGColor) { |
|
| 868 | + $foreground_color = array(0, 0, 0); |
|
| 869 | + } else |
|
| 848 | 870 | { |
| 849 | 871 | $foreground_color = array(64, 101, 136); |
| 850 | 872 | |
| 851 | 873 | // Has the theme author requested a custom color? |
| 852 | - if (isset($settings['verification_foreground'])) |
|
| 853 | - $foreground_color = $settings['verification_foreground']; |
|
| 874 | + if (isset($settings['verification_foreground'])) { |
|
| 875 | + $foreground_color = $settings['verification_foreground']; |
|
| 876 | + } |
|
| 854 | 877 | } |
| 855 | 878 | |
| 856 | - if (!is_dir($settings['default_theme_dir'] . '/fonts')) |
|
| 857 | - return false; |
|
| 879 | + if (!is_dir($settings['default_theme_dir'] . '/fonts')) { |
|
| 880 | + return false; |
|
| 881 | + } |
|
| 858 | 882 | |
| 859 | 883 | // Get a list of the available fonts. |
| 860 | 884 | $font_dir = dir($settings['default_theme_dir'] . '/fonts'); |
@@ -865,25 +889,28 @@ discard block |
||
| 865 | 889 | { |
| 866 | 890 | if (preg_match('~^(.+)\.gdf$~', $entry, $matches) === 1) |
| 867 | 891 | { |
| 868 | - if ($endian ^ (strpos($entry, '_end.gdf') === false)) |
|
| 869 | - $font_list[] = $entry; |
|
| 892 | + if ($endian ^ (strpos($entry, '_end.gdf') === false)) { |
|
| 893 | + $font_list[] = $entry; |
|
| 894 | + } |
|
| 895 | + } elseif (preg_match('~^(.+)\.ttf$~', $entry, $matches) === 1) { |
|
| 896 | + $ttfont_list[] = $entry; |
|
| 870 | 897 | } |
| 871 | - elseif (preg_match('~^(.+)\.ttf$~', $entry, $matches) === 1) |
|
| 872 | - $ttfont_list[] = $entry; |
|
| 873 | 898 | } |
| 874 | 899 | |
| 875 | - if (empty($font_list)) |
|
| 876 | - return false; |
|
| 900 | + if (empty($font_list)) { |
|
| 901 | + return false; |
|
| 902 | + } |
|
| 877 | 903 | |
| 878 | 904 | // For non-hard things don't even change fonts. |
| 879 | 905 | if (!$varyFonts) |
| 880 | 906 | { |
| 881 | 907 | $font_list = array($font_list[0]); |
| 882 | 908 | // Try use Screenge if we can - it looks good! |
| 883 | - if (in_array('AnonymousPro.ttf', $ttfont_list)) |
|
| 884 | - $ttfont_list = array('AnonymousPro.ttf'); |
|
| 885 | - else |
|
| 886 | - $ttfont_list = empty($ttfont_list) ? array() : array($ttfont_list[0]); |
|
| 909 | + if (in_array('AnonymousPro.ttf', $ttfont_list)) { |
|
| 910 | + $ttfont_list = array('AnonymousPro.ttf'); |
|
| 911 | + } else { |
|
| 912 | + $ttfont_list = empty($ttfont_list) ? array() : array($ttfont_list[0]); |
|
| 913 | + } |
|
| 887 | 914 | } |
| 888 | 915 | |
| 889 | 916 | // Create a list of characters to be shown. |
@@ -900,14 +927,16 @@ discard block |
||
| 900 | 927 | } |
| 901 | 928 | |
| 902 | 929 | // Load all fonts and determine the maximum font height. |
| 903 | - foreach ($loaded_fonts as $font_index => $dummy) |
|
| 904 | - $loaded_fonts[$font_index] = imageloadfont($settings['default_theme_dir'] . '/fonts/' . $font_list[$font_index]); |
|
| 930 | + foreach ($loaded_fonts as $font_index => $dummy) { |
|
| 931 | + $loaded_fonts[$font_index] = imageloadfont($settings['default_theme_dir'] . '/fonts/' . $font_list[$font_index]); |
|
| 932 | + } |
|
| 905 | 933 | |
| 906 | 934 | // Determine the dimensions of each character. |
| 907 | - if ($imageType == 4 || $imageType == 5) |
|
| 908 | - $extra = 80; |
|
| 909 | - else |
|
| 910 | - $extra = 45; |
|
| 935 | + if ($imageType == 4 || $imageType == 5) { |
|
| 936 | + $extra = 80; |
|
| 937 | + } else { |
|
| 938 | + $extra = 45; |
|
| 939 | + } |
|
| 911 | 940 | |
| 912 | 941 | $total_width = $character_spacing * strlen($code) + $extra; |
| 913 | 942 | $max_height = 0; |
@@ -928,13 +957,15 @@ discard block |
||
| 928 | 957 | imagefilledrectangle($code_image, 0, 0, $total_width - 1, $max_height - 1, $bg_color); |
| 929 | 958 | |
| 930 | 959 | // Randomize the foreground color a little. |
| 931 | - for ($i = 0; $i < 3; $i++) |
|
| 932 | - $foreground_color[$i] = random_int(max($foreground_color[$i] - 3, 0), min($foreground_color[$i] + 3, 255)); |
|
| 960 | + for ($i = 0; $i < 3; $i++) { |
|
| 961 | + $foreground_color[$i] = random_int(max($foreground_color[$i] - 3, 0), min($foreground_color[$i] + 3, 255)); |
|
| 962 | + } |
|
| 933 | 963 | $fg_color = imagecolorallocate($code_image, $foreground_color[0], $foreground_color[1], $foreground_color[2]); |
| 934 | 964 | |
| 935 | 965 | // Color for the dots. |
| 936 | - for ($i = 0; $i < 3; $i++) |
|
| 937 | - $dotbgcolor[$i] = $background_color[$i] < $foreground_color[$i] ? random_int(0, max($foreground_color[$i] - 20, 0)) : random_int(min($foreground_color[$i] + 20, 255), 255); |
|
| 966 | + for ($i = 0; $i < 3; $i++) { |
|
| 967 | + $dotbgcolor[$i] = $background_color[$i] < $foreground_color[$i] ? random_int(0, max($foreground_color[$i] - 20, 0)) : random_int(min($foreground_color[$i] + 20, 255), 255); |
|
| 968 | + } |
|
| 938 | 969 | $randomness_color = imagecolorallocate($code_image, $dotbgcolor[0], $dotbgcolor[1], $dotbgcolor[2]); |
| 939 | 970 | |
| 940 | 971 | // Some squares/rectanges for new extreme level |
@@ -960,10 +991,11 @@ discard block |
||
| 960 | 991 | $can_do_ttf = function_exists('imagettftext'); |
| 961 | 992 | |
| 962 | 993 | // How much rotation will we give? |
| 963 | - if ($rotationType == 'none') |
|
| 964 | - $angle = 0; |
|
| 965 | - else |
|
| 966 | - $angle = random_int(-100, 100) / ($rotationType == 'high' ? 6 : 10); |
|
| 994 | + if ($rotationType == 'none') { |
|
| 995 | + $angle = 0; |
|
| 996 | + } else { |
|
| 997 | + $angle = random_int(-100, 100) / ($rotationType == 'high' ? 6 : 10); |
|
| 998 | + } |
|
| 967 | 999 | |
| 968 | 1000 | // What color shall we do it? |
| 969 | 1001 | if ($fontColorType == 'cyclic') |
@@ -977,51 +1009,56 @@ discard block |
||
| 977 | 1009 | array(0, 0, 0), |
| 978 | 1010 | array(143, 39, 31), |
| 979 | 1011 | ); |
| 980 | - if (!isset($last_index)) |
|
| 981 | - $last_index = -1; |
|
| 1012 | + if (!isset($last_index)) { |
|
| 1013 | + $last_index = -1; |
|
| 1014 | + } |
|
| 982 | 1015 | $new_index = $last_index; |
| 983 | - while ($last_index == $new_index) |
|
| 984 | - $new_index = random_int(0, count($colors) - 1); |
|
| 1016 | + while ($last_index == $new_index) { |
|
| 1017 | + $new_index = random_int(0, count($colors) - 1); |
|
| 1018 | + } |
|
| 985 | 1019 | $char_fg_color = $colors[$new_index]; |
| 986 | 1020 | $last_index = $new_index; |
| 1021 | + } elseif ($fontColorType == 'random') { |
|
| 1022 | + $char_fg_color = array(random_int(max($foreground_color[0] - 2, 0), $foreground_color[0]), random_int(max($foreground_color[1] - 2, 0), $foreground_color[1]), random_int(max($foreground_color[2] - 2, 0), $foreground_color[2])); |
|
| 1023 | + } else { |
|
| 1024 | + $char_fg_color = array($foreground_color[0], $foreground_color[1], $foreground_color[2]); |
|
| 987 | 1025 | } |
| 988 | - elseif ($fontColorType == 'random') |
|
| 989 | - $char_fg_color = array(random_int(max($foreground_color[0] - 2, 0), $foreground_color[0]), random_int(max($foreground_color[1] - 2, 0), $foreground_color[1]), random_int(max($foreground_color[2] - 2, 0), $foreground_color[2])); |
|
| 990 | - else |
|
| 991 | - $char_fg_color = array($foreground_color[0], $foreground_color[1], $foreground_color[2]); |
|
| 992 | 1026 | |
| 993 | 1027 | if (!empty($can_do_ttf)) |
| 994 | 1028 | { |
| 995 | 1029 | // GD2 handles font size differently. |
| 996 | - if ($fontSizeRandom) |
|
| 997 | - $font_size = $gd2 ? random_int(17, 19) : random_int(18, 25); |
|
| 998 | - else |
|
| 999 | - $font_size = $gd2 ? 18 : 24; |
|
| 1030 | + if ($fontSizeRandom) { |
|
| 1031 | + $font_size = $gd2 ? random_int(17, 19) : random_int(18, 25); |
|
| 1032 | + } else { |
|
| 1033 | + $font_size = $gd2 ? 18 : 24; |
|
| 1034 | + } |
|
| 1000 | 1035 | |
| 1001 | 1036 | // Work out the sizes - also fix the character width cause TTF not quite so wide! |
| 1002 | 1037 | $font_x = $fontHorSpace == 'minus' && $cur_x > 0 ? $cur_x - 3 : $cur_x + 5; |
| 1003 | 1038 | $font_y = $max_height - ($fontVerPos == 'vrandom' ? random_int(2, 8) : ($fontVerPos == 'random' ? random_int(3, 5) : 5)); |
| 1004 | 1039 | |
| 1005 | 1040 | // What font face? |
| 1006 | - if (!empty($ttfont_list)) |
|
| 1007 | - $fontface = $settings['default_theme_dir'] . '/fonts/' . $ttfont_list[random_int(0, count($ttfont_list) - 1)]; |
|
| 1041 | + if (!empty($ttfont_list)) { |
|
| 1042 | + $fontface = $settings['default_theme_dir'] . '/fonts/' . $ttfont_list[random_int(0, count($ttfont_list) - 1)]; |
|
| 1043 | + } |
|
| 1008 | 1044 | |
| 1009 | 1045 | // What color are we to do it in? |
| 1010 | 1046 | $is_reverse = $showReverseChars ? random_int(0, 1) : false; |
| 1011 | 1047 | $char_color = function_exists('imagecolorallocatealpha') && $fontTrans ? imagecolorallocatealpha($code_image, $char_fg_color[0], $char_fg_color[1], $char_fg_color[2], 50) : imagecolorallocate($code_image, $char_fg_color[0], $char_fg_color[1], $char_fg_color[2]); |
| 1012 | 1048 | |
| 1013 | 1049 | $fontcord = @imagettftext($code_image, $font_size, $angle, $font_x, $font_y, $char_color, $fontface, $character['id']); |
| 1014 | - if (empty($fontcord)) |
|
| 1015 | - $can_do_ttf = false; |
|
| 1016 | - elseif ($is_reverse) |
|
| 1050 | + if (empty($fontcord)) { |
|
| 1051 | + $can_do_ttf = false; |
|
| 1052 | + } elseif ($is_reverse) |
|
| 1017 | 1053 | { |
| 1018 | 1054 | imagefilledpolygon($code_image, $fontcord, 4, $fg_color); |
| 1019 | 1055 | // Put the character back! |
| 1020 | 1056 | imagettftext($code_image, $font_size, $angle, $font_x, $font_y, $randomness_color, $fontface, $character['id']); |
| 1021 | 1057 | } |
| 1022 | 1058 | |
| 1023 | - if ($can_do_ttf) |
|
| 1024 | - $cur_x = max($fontcord[2], $fontcord[4]) + ($angle == 0 ? 0 : 3); |
|
| 1059 | + if ($can_do_ttf) { |
|
| 1060 | + $cur_x = max($fontcord[2], $fontcord[4]) + ($angle == 0 ? 0 : 3); |
|
| 1061 | + } |
|
| 1025 | 1062 | } |
| 1026 | 1063 | |
| 1027 | 1064 | if (!$can_do_ttf) |
@@ -1040,8 +1077,9 @@ discard block |
||
| 1040 | 1077 | } |
| 1041 | 1078 | |
| 1042 | 1079 | // Sorry, no rotation available. |
| 1043 | - else |
|
| 1044 | - imagechar($code_image, $loaded_fonts[$character['font']], $cur_x, floor(($max_height - $character['height']) / 2), $character['id'], imagecolorallocate($code_image, $char_fg_color[0], $char_fg_color[1], $char_fg_color[2])); |
|
| 1080 | + else { |
|
| 1081 | + imagechar($code_image, $loaded_fonts[$character['font']], $cur_x, floor(($max_height - $character['height']) / 2), $character['id'], imagecolorallocate($code_image, $char_fg_color[0], $char_fg_color[1], $char_fg_color[2])); |
|
| 1082 | + } |
|
| 1045 | 1083 | $cur_x += $character['width'] + $character_spacing; |
| 1046 | 1084 | } |
| 1047 | 1085 | } |
@@ -1054,17 +1092,22 @@ discard block |
||
| 1054 | 1092 | } |
| 1055 | 1093 | |
| 1056 | 1094 | // Make the background color transparent on the hard image. |
| 1057 | - if (!$simpleBGColor) |
|
| 1058 | - imagecolortransparent($code_image, $bg_color); |
|
| 1059 | - if ($hasBorder) |
|
| 1060 | - imagerectangle($code_image, 0, 0, $total_width - 1, $max_height - 1, $fg_color); |
|
| 1095 | + if (!$simpleBGColor) { |
|
| 1096 | + imagecolortransparent($code_image, $bg_color); |
|
| 1097 | + } |
|
| 1098 | + if ($hasBorder) { |
|
| 1099 | + imagerectangle($code_image, 0, 0, $total_width - 1, $max_height - 1, $fg_color); |
|
| 1100 | + } |
|
| 1061 | 1101 | |
| 1062 | 1102 | // Add some noise to the background? |
| 1063 | 1103 | if ($noiseType != 'none') |
| 1064 | 1104 | { |
| 1065 | - for ($i = random_int(0, 2); $i < $max_height; $i += random_int(1, 2)) |
|
| 1066 | - for ($j = random_int(0, 10); $j < $total_width; $j += random_int(1, 10)) |
|
| 1067 | - imagesetpixel($code_image, $j, $i, random_int(0, 1) ? $fg_color : $randomness_color); |
|
| 1105 | + for ($i = random_int(0, 2); $i < $max_height; $i += random_int(1, 2)) { |
|
| 1106 | + for ($j = random_int(0, 10); |
|
| 1107 | + } |
|
| 1108 | + $j < $total_width; $j += random_int(1, 10)) { |
|
| 1109 | + imagesetpixel($code_image, $j, $i, random_int(0, 1) ? $fg_color : $randomness_color); |
|
| 1110 | + } |
|
| 1068 | 1111 | |
| 1069 | 1112 | // Put in some lines too? |
| 1070 | 1113 | if ($noiseType != 'extreme') |
@@ -1077,8 +1120,7 @@ discard block |
||
| 1077 | 1120 | $x1 = random_int(0, $total_width); |
| 1078 | 1121 | $x2 = random_int(0, $total_width); |
| 1079 | 1122 | $y1 = 0; $y2 = $max_height; |
| 1080 | - } |
|
| 1081 | - else |
|
| 1123 | + } else |
|
| 1082 | 1124 | { |
| 1083 | 1125 | $y1 = random_int(0, $max_height); |
| 1084 | 1126 | $y2 = random_int(0, $max_height); |
@@ -1087,8 +1129,7 @@ discard block |
||
| 1087 | 1129 | imagesetthickness($code_image, random_int(1, 2)); |
| 1088 | 1130 | imageline($code_image, $x1, $y1, $x2, $y2, random_int(0, 1) ? $fg_color : $randomness_color); |
| 1089 | 1131 | } |
| 1090 | - } |
|
| 1091 | - else |
|
| 1132 | + } else |
|
| 1092 | 1133 | { |
| 1093 | 1134 | // Put in some ellipse |
| 1094 | 1135 | $num_ellipse = $noiseType == 'extreme' ? random_int(6, 12) : random_int(2, 6); |
@@ -1108,8 +1149,7 @@ discard block |
||
| 1108 | 1149 | { |
| 1109 | 1150 | header('content-type: image/gif'); |
| 1110 | 1151 | imagegif($code_image); |
| 1111 | - } |
|
| 1112 | - else |
|
| 1152 | + } else |
|
| 1113 | 1153 | { |
| 1114 | 1154 | header('content-type: image/png'); |
| 1115 | 1155 | imagepng($code_image); |
@@ -1132,25 +1172,29 @@ discard block |
||
| 1132 | 1172 | { |
| 1133 | 1173 | global $settings; |
| 1134 | 1174 | |
| 1135 | - if (!is_dir($settings['default_theme_dir'] . '/fonts')) |
|
| 1136 | - return false; |
|
| 1175 | + if (!is_dir($settings['default_theme_dir'] . '/fonts')) { |
|
| 1176 | + return false; |
|
| 1177 | + } |
|
| 1137 | 1178 | |
| 1138 | 1179 | // Get a list of the available font directories. |
| 1139 | 1180 | $font_dir = dir($settings['default_theme_dir'] . '/fonts'); |
| 1140 | 1181 | $font_list = array(); |
| 1141 | - while ($entry = $font_dir->read()) |
|
| 1142 | - if ($entry[0] !== '.' && is_dir($settings['default_theme_dir'] . '/fonts/' . $entry) && file_exists($settings['default_theme_dir'] . '/fonts/' . $entry . '.gdf')) |
|
| 1182 | + while ($entry = $font_dir->read()) { |
|
| 1183 | + if ($entry[0] !== '.' && is_dir($settings['default_theme_dir'] . '/fonts/' . $entry) && file_exists($settings['default_theme_dir'] . '/fonts/' . $entry . '.gdf')) |
|
| 1143 | 1184 | $font_list[] = $entry; |
| 1185 | + } |
|
| 1144 | 1186 | |
| 1145 | - if (empty($font_list)) |
|
| 1146 | - return false; |
|
| 1187 | + if (empty($font_list)) { |
|
| 1188 | + return false; |
|
| 1189 | + } |
|
| 1147 | 1190 | |
| 1148 | 1191 | // Pick a random font. |
| 1149 | 1192 | $random_font = $font_list[array_rand($font_list)]; |
| 1150 | 1193 | |
| 1151 | 1194 | // Check if the given letter exists. |
| 1152 | - if (!file_exists($settings['default_theme_dir'] . '/fonts/' . $random_font . '/' . $letter . '.png')) |
|
| 1153 | - return false; |
|
| 1195 | + if (!file_exists($settings['default_theme_dir'] . '/fonts/' . $random_font . '/' . $letter . '.png')) { |
|
| 1196 | + return false; |
|
| 1197 | + } |
|
| 1154 | 1198 | |
| 1155 | 1199 | // Include it! |
| 1156 | 1200 | header('content-type: image/png'); |