@@ -14,8 +14,9 @@ discard block |
||
| 14 | 14 | * @version 2.1 Beta 4 |
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | -if (!defined('SMF')) |
|
| 17 | +if (!defined('SMF')) { |
|
| 18 | 18 | die('No direct access...'); |
| 19 | +} |
|
| 19 | 20 | |
| 20 | 21 | /** |
| 21 | 22 | * Check if the user is who he/she says he is |
@@ -42,12 +43,14 @@ discard block |
||
| 42 | 43 | $refreshTime = isset($_GET['xml']) ? 4200 : 3600; |
| 43 | 44 | |
| 44 | 45 | // Is the security option off? |
| 45 | - if (!empty($modSettings['securityDisable' . ($type != 'admin' ? '_' . $type : '')])) |
|
| 46 | - return; |
|
| 46 | + if (!empty($modSettings['securityDisable' . ($type != 'admin' ? '_' . $type : '')])) { |
|
| 47 | + return; |
|
| 48 | + } |
|
| 47 | 49 | |
| 48 | 50 | // Or are they already logged in?, Moderator or admin session is need for this area |
| 49 | - if ((!empty($_SESSION[$type . '_time']) && $_SESSION[$type . '_time'] + $refreshTime >= time()) || (!empty($_SESSION['admin_time']) && $_SESSION['admin_time'] + $refreshTime >= time())) |
|
| 50 | - return; |
|
| 51 | + if ((!empty($_SESSION[$type . '_time']) && $_SESSION[$type . '_time'] + $refreshTime >= time()) || (!empty($_SESSION['admin_time']) && $_SESSION['admin_time'] + $refreshTime >= time())) { |
|
| 52 | + return; |
|
| 53 | + } |
|
| 51 | 54 | |
| 52 | 55 | require_once($sourcedir . '/Subs-Auth.php'); |
| 53 | 56 | |
@@ -55,8 +58,9 @@ discard block |
||
| 55 | 58 | if (isset($_POST[$type . '_pass'])) |
| 56 | 59 | { |
| 57 | 60 | // Check to ensure we're forcing SSL for authentication |
| 58 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) |
|
| 59 | - fatal_lang_error('login_ssl_required'); |
|
| 61 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) { |
|
| 62 | + fatal_lang_error('login_ssl_required'); |
|
| 63 | + } |
|
| 60 | 64 | |
| 61 | 65 | checkSession(); |
| 62 | 66 | |
@@ -72,17 +76,19 @@ discard block |
||
| 72 | 76 | } |
| 73 | 77 | |
| 74 | 78 | // Better be sure to remember the real referer |
| 75 | - if (empty($_SESSION['request_referer'])) |
|
| 76 | - $_SESSION['request_referer'] = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array(); |
|
| 77 | - elseif (empty($_POST)) |
|
| 78 | - unset($_SESSION['request_referer']); |
|
| 79 | + if (empty($_SESSION['request_referer'])) { |
|
| 80 | + $_SESSION['request_referer'] = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array(); |
|
| 81 | + } elseif (empty($_POST)) { |
|
| 82 | + unset($_SESSION['request_referer']); |
|
| 83 | + } |
|
| 79 | 84 | |
| 80 | 85 | // Need to type in a password for that, man. |
| 81 | - if (!isset($_GET['xml'])) |
|
| 82 | - adminLogin($type); |
|
| 83 | - else |
|
| 84 | - return 'session_verify_fail'; |
|
| 85 | -} |
|
| 86 | + if (!isset($_GET['xml'])) { |
|
| 87 | + adminLogin($type); |
|
| 88 | + } else { |
|
| 89 | + return 'session_verify_fail'; |
|
| 90 | + } |
|
| 91 | + } |
|
| 86 | 92 | |
| 87 | 93 | /** |
| 88 | 94 | * Require a user who is logged in. (not a guest.) |
@@ -96,25 +102,30 @@ discard block |
||
| 96 | 102 | global $user_info, $txt, $context, $scripturl, $modSettings; |
| 97 | 103 | |
| 98 | 104 | // Luckily, this person isn't a guest. |
| 99 | - if (!$user_info['is_guest']) |
|
| 100 | - return; |
|
| 105 | + if (!$user_info['is_guest']) { |
|
| 106 | + return; |
|
| 107 | + } |
|
| 101 | 108 | |
| 102 | 109 | // Log what they were trying to do didn't work) |
| 103 | - if (!empty($modSettings['who_enabled'])) |
|
| 104 | - $_GET['error'] = 'guest_login'; |
|
| 110 | + if (!empty($modSettings['who_enabled'])) { |
|
| 111 | + $_GET['error'] = 'guest_login'; |
|
| 112 | + } |
|
| 105 | 113 | writeLog(true); |
| 106 | 114 | |
| 107 | 115 | // Just die. |
| 108 | - if (isset($_REQUEST['xml'])) |
|
| 109 | - obExit(false); |
|
| 116 | + if (isset($_REQUEST['xml'])) { |
|
| 117 | + obExit(false); |
|
| 118 | + } |
|
| 110 | 119 | |
| 111 | 120 | // Attempt to detect if they came from dlattach. |
| 112 | - if (SMF != 'SSI' && empty($context['theme_loaded'])) |
|
| 113 | - loadTheme(); |
|
| 121 | + if (SMF != 'SSI' && empty($context['theme_loaded'])) { |
|
| 122 | + loadTheme(); |
|
| 123 | + } |
|
| 114 | 124 | |
| 115 | 125 | // Never redirect to an attachment |
| 116 | - if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) |
|
| 117 | - $_SESSION['login_url'] = $_SERVER['REQUEST_URL']; |
|
| 126 | + if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) { |
|
| 127 | + $_SESSION['login_url'] = $_SERVER['REQUEST_URL']; |
|
| 128 | + } |
|
| 118 | 129 | |
| 119 | 130 | // Load the Login template and language file. |
| 120 | 131 | loadLanguage('Login'); |
@@ -124,8 +135,7 @@ discard block |
||
| 124 | 135 | { |
| 125 | 136 | $_SESSION['login_url'] = $scripturl . '?' . $_SERVER['QUERY_STRING']; |
| 126 | 137 | redirectexit('action=login'); |
| 127 | - } |
|
| 128 | - else |
|
| 138 | + } else |
|
| 129 | 139 | { |
| 130 | 140 | loadTemplate('Login'); |
| 131 | 141 | $context['sub_template'] = 'kick_guest'; |
@@ -155,8 +165,9 @@ discard block |
||
| 155 | 165 | global $sourcedir, $cookiename, $user_settings, $smcFunc; |
| 156 | 166 | |
| 157 | 167 | // You cannot be banned if you are an admin - doesn't help if you log out. |
| 158 | - if ($user_info['is_admin']) |
|
| 159 | - return; |
|
| 168 | + if ($user_info['is_admin']) { |
|
| 169 | + return; |
|
| 170 | + } |
|
| 160 | 171 | |
| 161 | 172 | // Only check the ban every so often. (to reduce load.) |
| 162 | 173 | if ($forceCheck || !isset($_SESSION['ban']) || empty($modSettings['banLastUpdated']) || ($_SESSION['ban']['last_checked'] < $modSettings['banLastUpdated']) || $_SESSION['ban']['id_member'] != $user_info['id'] || $_SESSION['ban']['ip'] != $user_info['ip'] || $_SESSION['ban']['ip2'] != $user_info['ip2'] || (isset($user_info['email'], $_SESSION['ban']['email']) && $_SESSION['ban']['email'] != $user_info['email'])) |
@@ -177,8 +188,9 @@ discard block |
||
| 177 | 188 | // Check both IP addresses. |
| 178 | 189 | foreach (array('ip', 'ip2') as $ip_number) |
| 179 | 190 | { |
| 180 | - if ($ip_number == 'ip2' && $user_info['ip2'] == $user_info['ip']) |
|
| 181 | - continue; |
|
| 191 | + if ($ip_number == 'ip2' && $user_info['ip2'] == $user_info['ip']) { |
|
| 192 | + continue; |
|
| 193 | + } |
|
| 182 | 194 | $ban_query[] = ' {inet:' . $ip_number . '} BETWEEN bi.ip_low and bi.ip_high'; |
| 183 | 195 | $ban_query_vars[$ip_number] = $user_info[$ip_number]; |
| 184 | 196 | // IP was valid, maybe there's also a hostname... |
@@ -228,24 +240,28 @@ discard block |
||
| 228 | 240 | // Store every type of ban that applies to you in your session. |
| 229 | 241 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 230 | 242 | { |
| 231 | - foreach ($restrictions as $restriction) |
|
| 232 | - if (!empty($row[$restriction])) |
|
| 243 | + foreach ($restrictions as $restriction) { |
|
| 244 | + if (!empty($row[$restriction])) |
|
| 233 | 245 | { |
| 234 | 246 | $_SESSION['ban'][$restriction]['reason'] = $row['reason']; |
| 247 | + } |
|
| 235 | 248 | $_SESSION['ban'][$restriction]['ids'][] = $row['id_ban']; |
| 236 | - if (!isset($_SESSION['ban']['expire_time']) || ($_SESSION['ban']['expire_time'] != 0 && ($row['expire_time'] == 0 || $row['expire_time'] > $_SESSION['ban']['expire_time']))) |
|
| 237 | - $_SESSION['ban']['expire_time'] = $row['expire_time']; |
|
| 249 | + if (!isset($_SESSION['ban']['expire_time']) || ($_SESSION['ban']['expire_time'] != 0 && ($row['expire_time'] == 0 || $row['expire_time'] > $_SESSION['ban']['expire_time']))) { |
|
| 250 | + $_SESSION['ban']['expire_time'] = $row['expire_time']; |
|
| 251 | + } |
|
| 238 | 252 | |
| 239 | - if (!$user_info['is_guest'] && $restriction == 'cannot_access' && ($row['id_member'] == $user_info['id'] || $row['email_address'] == $user_info['email'])) |
|
| 240 | - $flag_is_activated = true; |
|
| 253 | + if (!$user_info['is_guest'] && $restriction == 'cannot_access' && ($row['id_member'] == $user_info['id'] || $row['email_address'] == $user_info['email'])) { |
|
| 254 | + $flag_is_activated = true; |
|
| 255 | + } |
|
| 241 | 256 | } |
| 242 | 257 | } |
| 243 | 258 | $smcFunc['db_free_result']($request); |
| 244 | 259 | } |
| 245 | 260 | |
| 246 | 261 | // Mark the cannot_access and cannot_post bans as being 'hit'. |
| 247 | - if (isset($_SESSION['ban']['cannot_access']) || isset($_SESSION['ban']['cannot_post']) || isset($_SESSION['ban']['cannot_login'])) |
|
| 248 | - log_ban(array_merge(isset($_SESSION['ban']['cannot_access']) ? $_SESSION['ban']['cannot_access']['ids'] : array(), isset($_SESSION['ban']['cannot_post']) ? $_SESSION['ban']['cannot_post']['ids'] : array(), isset($_SESSION['ban']['cannot_login']) ? $_SESSION['ban']['cannot_login']['ids'] : array())); |
|
| 262 | + if (isset($_SESSION['ban']['cannot_access']) || isset($_SESSION['ban']['cannot_post']) || isset($_SESSION['ban']['cannot_login'])) { |
|
| 263 | + log_ban(array_merge(isset($_SESSION['ban']['cannot_access']) ? $_SESSION['ban']['cannot_access']['ids'] : array(), isset($_SESSION['ban']['cannot_post']) ? $_SESSION['ban']['cannot_post']['ids'] : array(), isset($_SESSION['ban']['cannot_login']) ? $_SESSION['ban']['cannot_login']['ids'] : array())); |
|
| 264 | + } |
|
| 249 | 265 | |
| 250 | 266 | // If for whatever reason the is_activated flag seems wrong, do a little work to clear it up. |
| 251 | 267 | if ($user_info['id'] && (($user_settings['is_activated'] >= 10 && !$flag_is_activated) |
@@ -260,8 +276,9 @@ discard block |
||
| 260 | 276 | if (!isset($_SESSION['ban']['cannot_access']) && !empty($_COOKIE[$cookiename . '_'])) |
| 261 | 277 | { |
| 262 | 278 | $bans = explode(',', $_COOKIE[$cookiename . '_']); |
| 263 | - foreach ($bans as $key => $value) |
|
| 264 | - $bans[$key] = (int) $value; |
|
| 279 | + foreach ($bans as $key => $value) { |
|
| 280 | + $bans[$key] = (int) $value; |
|
| 281 | + } |
|
| 265 | 282 | $request = $smcFunc['db_query']('', ' |
| 266 | 283 | SELECT bi.id_ban, bg.reason |
| 267 | 284 | FROM {db_prefix}ban_items AS bi |
@@ -297,14 +314,15 @@ discard block |
||
| 297 | 314 | if (isset($_SESSION['ban']['cannot_access'])) |
| 298 | 315 | { |
| 299 | 316 | // We don't wanna see you! |
| 300 | - if (!$user_info['is_guest']) |
|
| 301 | - $smcFunc['db_query']('', ' |
|
| 317 | + if (!$user_info['is_guest']) { |
|
| 318 | + $smcFunc['db_query']('', ' |
|
| 302 | 319 | DELETE FROM {db_prefix}log_online |
| 303 | 320 | WHERE id_member = {int:current_member}', |
| 304 | 321 | array( |
| 305 | 322 | 'current_member' => $user_info['id'], |
| 306 | 323 | ) |
| 307 | 324 | ); |
| 325 | + } |
|
| 308 | 326 | |
| 309 | 327 | // 'Log' the user out. Can't have any funny business... (save the name!) |
| 310 | 328 | $old_name = isset($user_info['name']) && $user_info['name'] != '' ? $user_info['name'] : $txt['guest_title']; |
@@ -390,9 +408,10 @@ discard block |
||
| 390 | 408 | } |
| 391 | 409 | |
| 392 | 410 | // Fix up the banning permissions. |
| 393 | - if (isset($user_info['permissions'])) |
|
| 394 | - banPermissions(); |
|
| 395 | -} |
|
| 411 | + if (isset($user_info['permissions'])) { |
|
| 412 | + banPermissions(); |
|
| 413 | + } |
|
| 414 | + } |
|
| 396 | 415 | |
| 397 | 416 | /** |
| 398 | 417 | * Fix permissions according to ban status. |
@@ -403,8 +422,9 @@ discard block |
||
| 403 | 422 | global $user_info, $sourcedir, $modSettings, $context; |
| 404 | 423 | |
| 405 | 424 | // Somehow they got here, at least take away all permissions... |
| 406 | - if (isset($_SESSION['ban']['cannot_access'])) |
|
| 407 | - $user_info['permissions'] = array(); |
|
| 425 | + if (isset($_SESSION['ban']['cannot_access'])) { |
|
| 426 | + $user_info['permissions'] = array(); |
|
| 427 | + } |
|
| 408 | 428 | // Okay, well, you can watch, but don't touch a thing. |
| 409 | 429 | elseif (isset($_SESSION['ban']['cannot_post']) || (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $user_info['warning'])) |
| 410 | 430 | { |
@@ -446,19 +466,20 @@ discard block |
||
| 446 | 466 | call_integration_hook('integrate_warn_permissions', array(&$permission_change)); |
| 447 | 467 | foreach ($permission_change as $old => $new) |
| 448 | 468 | { |
| 449 | - if (!in_array($old, $user_info['permissions'])) |
|
| 450 | - unset($permission_change[$old]); |
|
| 451 | - else |
|
| 452 | - $user_info['permissions'][] = $new; |
|
| 469 | + if (!in_array($old, $user_info['permissions'])) { |
|
| 470 | + unset($permission_change[$old]); |
|
| 471 | + } else { |
|
| 472 | + $user_info['permissions'][] = $new; |
|
| 473 | + } |
|
| 453 | 474 | } |
| 454 | 475 | $user_info['permissions'] = array_diff($user_info['permissions'], array_keys($permission_change)); |
| 455 | 476 | } |
| 456 | 477 | |
| 457 | 478 | // @todo Find a better place to call this? Needs to be after permissions loaded! |
| 458 | 479 | // Finally, some bits we cache in the session because it saves queries. |
| 459 | - if (isset($_SESSION['mc']) && $_SESSION['mc']['time'] > $modSettings['settings_updated'] && $_SESSION['mc']['id'] == $user_info['id']) |
|
| 460 | - $user_info['mod_cache'] = $_SESSION['mc']; |
|
| 461 | - else |
|
| 480 | + if (isset($_SESSION['mc']) && $_SESSION['mc']['time'] > $modSettings['settings_updated'] && $_SESSION['mc']['id'] == $user_info['id']) { |
|
| 481 | + $user_info['mod_cache'] = $_SESSION['mc']; |
|
| 482 | + } else |
|
| 462 | 483 | { |
| 463 | 484 | require_once($sourcedir . '/Subs-Auth.php'); |
| 464 | 485 | rebuildModCache(); |
@@ -469,14 +490,12 @@ discard block |
||
| 469 | 490 | { |
| 470 | 491 | $context['open_mod_reports'] = $_SESSION['rc']['reports']; |
| 471 | 492 | $context['open_member_reports'] = $_SESSION['rc']['member_reports']; |
| 472 | - } |
|
| 473 | - elseif ($_SESSION['mc']['bq'] != '0=1') |
|
| 493 | + } elseif ($_SESSION['mc']['bq'] != '0=1') |
|
| 474 | 494 | { |
| 475 | 495 | require_once($sourcedir . '/Subs-ReportedContent.php'); |
| 476 | 496 | $context['open_mod_reports'] = recountOpenReports('posts'); |
| 477 | 497 | $context['open_member_reports'] = recountOpenReports('members'); |
| 478 | - } |
|
| 479 | - else |
|
| 498 | + } else |
|
| 480 | 499 | { |
| 481 | 500 | $context['open_mod_reports'] = 0; |
| 482 | 501 | $context['open_member_reports'] = 0; |
@@ -496,8 +515,9 @@ discard block |
||
| 496 | 515 | global $user_info, $smcFunc; |
| 497 | 516 | |
| 498 | 517 | // Don't log web accelerators, it's very confusing... |
| 499 | - if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') |
|
| 500 | - return; |
|
| 518 | + if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') { |
|
| 519 | + return; |
|
| 520 | + } |
|
| 501 | 521 | |
| 502 | 522 | $smcFunc['db_insert']('', |
| 503 | 523 | '{db_prefix}log_banned', |
@@ -507,8 +527,8 @@ discard block |
||
| 507 | 527 | ); |
| 508 | 528 | |
| 509 | 529 | // One extra point for these bans. |
| 510 | - if (!empty($ban_ids)) |
|
| 511 | - $smcFunc['db_query']('', ' |
|
| 530 | + if (!empty($ban_ids)) { |
|
| 531 | + $smcFunc['db_query']('', ' |
|
| 512 | 532 | UPDATE {db_prefix}ban_items |
| 513 | 533 | SET hits = hits + 1 |
| 514 | 534 | WHERE id_ban IN ({array_int:ban_ids})', |
@@ -516,7 +536,8 @@ discard block |
||
| 516 | 536 | 'ban_ids' => $ban_ids, |
| 517 | 537 | ) |
| 518 | 538 | ); |
| 519 | -} |
|
| 539 | + } |
|
| 540 | + } |
|
| 520 | 541 | |
| 521 | 542 | /** |
| 522 | 543 | * Checks if a given email address might be banned. |
@@ -532,8 +553,9 @@ discard block |
||
| 532 | 553 | global $txt, $smcFunc; |
| 533 | 554 | |
| 534 | 555 | // Can't ban an empty email |
| 535 | - if (empty($email) || trim($email) == '') |
|
| 536 | - return; |
|
| 556 | + if (empty($email) || trim($email) == '') { |
|
| 557 | + return; |
|
| 558 | + } |
|
| 537 | 559 | |
| 538 | 560 | // Let's start with the bans based on your IP/hostname/memberID... |
| 539 | 561 | $ban_ids = isset($_SESSION['ban'][$restriction]) ? $_SESSION['ban'][$restriction]['ids'] : array(); |
@@ -606,16 +628,18 @@ discard block |
||
| 606 | 628 | if ($type == 'post') |
| 607 | 629 | { |
| 608 | 630 | $check = isset($_POST[$_SESSION['session_var']]) ? $_POST[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_POST['sc']) ? $_POST['sc'] : null); |
| 609 | - if ($check !== $sc) |
|
| 610 | - $error = 'session_timeout'; |
|
| 631 | + if ($check !== $sc) { |
|
| 632 | + $error = 'session_timeout'; |
|
| 633 | + } |
|
| 611 | 634 | } |
| 612 | 635 | |
| 613 | 636 | // How about $_GET['sesc']? |
| 614 | 637 | elseif ($type == 'get') |
| 615 | 638 | { |
| 616 | 639 | $check = isset($_GET[$_SESSION['session_var']]) ? $_GET[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_GET['sesc']) ? $_GET['sesc'] : null); |
| 617 | - if ($check !== $sc) |
|
| 618 | - $error = 'session_verify_fail'; |
|
| 640 | + if ($check !== $sc) { |
|
| 641 | + $error = 'session_verify_fail'; |
|
| 642 | + } |
|
| 619 | 643 | } |
| 620 | 644 | |
| 621 | 645 | // Or can it be in either? |
@@ -623,13 +647,15 @@ discard block |
||
| 623 | 647 | { |
| 624 | 648 | $check = isset($_GET[$_SESSION['session_var']]) ? $_GET[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_GET['sesc']) ? $_GET['sesc'] : (isset($_POST[$_SESSION['session_var']]) ? $_POST[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_POST['sc']) ? $_POST['sc'] : null))); |
| 625 | 649 | |
| 626 | - if ($check !== $sc) |
|
| 627 | - $error = 'session_verify_fail'; |
|
| 650 | + if ($check !== $sc) { |
|
| 651 | + $error = 'session_verify_fail'; |
|
| 652 | + } |
|
| 628 | 653 | } |
| 629 | 654 | |
| 630 | 655 | // Verify that they aren't changing user agents on us - that could be bad. |
| 631 | - if ((!isset($_SESSION['USER_AGENT']) || $_SESSION['USER_AGENT'] != $_SERVER['HTTP_USER_AGENT']) && empty($modSettings['disableCheckUA'])) |
|
| 632 | - $error = 'session_verify_fail'; |
|
| 656 | + if ((!isset($_SESSION['USER_AGENT']) || $_SESSION['USER_AGENT'] != $_SERVER['HTTP_USER_AGENT']) && empty($modSettings['disableCheckUA'])) { |
|
| 657 | + $error = 'session_verify_fail'; |
|
| 658 | + } |
|
| 633 | 659 | |
| 634 | 660 | // Make sure a page with session check requirement is not being prefetched. |
| 635 | 661 | if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') |
@@ -640,30 +666,35 @@ discard block |
||
| 640 | 666 | } |
| 641 | 667 | |
| 642 | 668 | // Check the referring site - it should be the same server at least! |
| 643 | - if (isset($_SESSION['request_referer'])) |
|
| 644 | - $referrer = $_SESSION['request_referer']; |
|
| 645 | - else |
|
| 646 | - $referrer = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array(); |
|
| 669 | + if (isset($_SESSION['request_referer'])) { |
|
| 670 | + $referrer = $_SESSION['request_referer']; |
|
| 671 | + } else { |
|
| 672 | + $referrer = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array(); |
|
| 673 | + } |
|
| 647 | 674 | if (!empty($referrer['host'])) |
| 648 | 675 | { |
| 649 | - if (strpos($_SERVER['HTTP_HOST'], ':') !== false) |
|
| 650 | - $real_host = substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], ':')); |
|
| 651 | - else |
|
| 652 | - $real_host = $_SERVER['HTTP_HOST']; |
|
| 676 | + if (strpos($_SERVER['HTTP_HOST'], ':') !== false) { |
|
| 677 | + $real_host = substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], ':')); |
|
| 678 | + } else { |
|
| 679 | + $real_host = $_SERVER['HTTP_HOST']; |
|
| 680 | + } |
|
| 653 | 681 | |
| 654 | 682 | $parsed_url = parse_url($boardurl); |
| 655 | 683 | |
| 656 | 684 | // Are global cookies on? If so, let's check them ;). |
| 657 | 685 | if (!empty($modSettings['globalCookies'])) |
| 658 | 686 | { |
| 659 | - if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $parsed_url['host'], $parts) == 1) |
|
| 660 | - $parsed_url['host'] = $parts[1]; |
|
| 687 | + if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $parsed_url['host'], $parts) == 1) { |
|
| 688 | + $parsed_url['host'] = $parts[1]; |
|
| 689 | + } |
|
| 661 | 690 | |
| 662 | - if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $referrer['host'], $parts) == 1) |
|
| 663 | - $referrer['host'] = $parts[1]; |
|
| 691 | + if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $referrer['host'], $parts) == 1) { |
|
| 692 | + $referrer['host'] = $parts[1]; |
|
| 693 | + } |
|
| 664 | 694 | |
| 665 | - if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $real_host, $parts) == 1) |
|
| 666 | - $real_host = $parts[1]; |
|
| 695 | + if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $real_host, $parts) == 1) { |
|
| 696 | + $real_host = $parts[1]; |
|
| 697 | + } |
|
| 667 | 698 | } |
| 668 | 699 | |
| 669 | 700 | // Okay: referrer must either match parsed_url or real_host. |
@@ -681,12 +712,14 @@ discard block |
||
| 681 | 712 | $log_error = true; |
| 682 | 713 | } |
| 683 | 714 | |
| 684 | - if (strtolower($_SERVER['HTTP_USER_AGENT']) == 'hacker') |
|
| 685 | - fatal_error('Sound the alarm! It\'s a hacker! Close the castle gates!!', false); |
|
| 715 | + if (strtolower($_SERVER['HTTP_USER_AGENT']) == 'hacker') { |
|
| 716 | + fatal_error('Sound the alarm! It\'s a hacker! Close the castle gates!!', false); |
|
| 717 | + } |
|
| 686 | 718 | |
| 687 | 719 | // Everything is ok, return an empty string. |
| 688 | - if (!isset($error)) |
|
| 689 | - return ''; |
|
| 720 | + if (!isset($error)) { |
|
| 721 | + return ''; |
|
| 722 | + } |
|
| 690 | 723 | // A session error occurred, show the error. |
| 691 | 724 | elseif ($is_fatal) |
| 692 | 725 | { |
@@ -695,13 +728,14 @@ discard block |
||
| 695 | 728 | ob_end_clean(); |
| 696 | 729 | header('HTTP/1.1 403 Forbidden - Session timeout'); |
| 697 | 730 | die; |
| 731 | + } else { |
|
| 732 | + fatal_lang_error($error, isset($log_error) ? 'user' : false); |
|
| 698 | 733 | } |
| 699 | - else |
|
| 700 | - fatal_lang_error($error, isset($log_error) ? 'user' : false); |
|
| 701 | 734 | } |
| 702 | 735 | // A session error occurred, return the error to the calling function. |
| 703 | - else |
|
| 704 | - return $error; |
|
| 736 | + else { |
|
| 737 | + return $error; |
|
| 738 | + } |
|
| 705 | 739 | |
| 706 | 740 | // We really should never fall through here, for very important reasons. Let's make sure. |
| 707 | 741 | trigger_error('Hacking attempt...', E_USER_ERROR); |
@@ -717,10 +751,9 @@ discard block |
||
| 717 | 751 | { |
| 718 | 752 | global $modSettings; |
| 719 | 753 | |
| 720 | - if (isset($_GET['confirm']) && isset($_SESSION['confirm_' . $action]) && md5($_GET['confirm'] . $_SERVER['HTTP_USER_AGENT']) == $_SESSION['confirm_' . $action]) |
|
| 721 | - return true; |
|
| 722 | - |
|
| 723 | - else |
|
| 754 | + if (isset($_GET['confirm']) && isset($_SESSION['confirm_' . $action]) && md5($_GET['confirm'] . $_SERVER['HTTP_USER_AGENT']) == $_SESSION['confirm_' . $action]) { |
|
| 755 | + return true; |
|
| 756 | + } else |
|
| 724 | 757 | { |
| 725 | 758 | $token = md5(mt_rand() . session_id() . (string) microtime() . $modSettings['rand_seed']); |
| 726 | 759 | $_SESSION['confirm_' . $action] = md5($token . $_SERVER['HTTP_USER_AGENT']); |
@@ -771,9 +804,9 @@ discard block |
||
| 771 | 804 | $return = $_SESSION['token'][$type . '-' . $action][3]; |
| 772 | 805 | unset($_SESSION['token'][$type . '-' . $action]); |
| 773 | 806 | return $return; |
| 807 | + } else { |
|
| 808 | + return ''; |
|
| 774 | 809 | } |
| 775 | - else |
|
| 776 | - return ''; |
|
| 777 | 810 | } |
| 778 | 811 | |
| 779 | 812 | // This nasty piece of code validates a token. |
@@ -804,12 +837,14 @@ discard block |
||
| 804 | 837 | fatal_lang_error('token_verify_fail', false); |
| 805 | 838 | } |
| 806 | 839 | // Remove this token as its useless |
| 807 | - else |
|
| 808 | - unset($_SESSION['token'][$type . '-' . $action]); |
|
| 840 | + else { |
|
| 841 | + unset($_SESSION['token'][$type . '-' . $action]); |
|
| 842 | + } |
|
| 809 | 843 | |
| 810 | 844 | // Randomly check if we should remove some older tokens. |
| 811 | - if (mt_rand(0, 138) == 23) |
|
| 812 | - cleanTokens(); |
|
| 845 | + if (mt_rand(0, 138) == 23) { |
|
| 846 | + cleanTokens(); |
|
| 847 | + } |
|
| 813 | 848 | |
| 814 | 849 | return false; |
| 815 | 850 | } |
@@ -824,14 +859,16 @@ discard block |
||
| 824 | 859 | function cleanTokens($complete = false) |
| 825 | 860 | { |
| 826 | 861 | // We appreciate cleaning up after yourselves. |
| 827 | - if (!isset($_SESSION['token'])) |
|
| 828 | - return; |
|
| 862 | + if (!isset($_SESSION['token'])) { |
|
| 863 | + return; |
|
| 864 | + } |
|
| 829 | 865 | |
| 830 | 866 | // Clean up tokens, trying to give enough time still. |
| 831 | - foreach ($_SESSION['token'] as $key => $data) |
|
| 832 | - if ($data[2] + 10800 < time() || $complete) |
|
| 867 | + foreach ($_SESSION['token'] as $key => $data) { |
|
| 868 | + if ($data[2] + 10800 < time() || $complete) |
|
| 833 | 869 | unset($_SESSION['token'][$key]); |
| 834 | -} |
|
| 870 | + } |
|
| 871 | + } |
|
| 835 | 872 | |
| 836 | 873 | /** |
| 837 | 874 | * Check whether a form has been submitted twice. |
@@ -849,37 +886,40 @@ discard block |
||
| 849 | 886 | { |
| 850 | 887 | global $context; |
| 851 | 888 | |
| 852 | - if (!isset($_SESSION['forms'])) |
|
| 853 | - $_SESSION['forms'] = array(); |
|
| 889 | + if (!isset($_SESSION['forms'])) { |
|
| 890 | + $_SESSION['forms'] = array(); |
|
| 891 | + } |
|
| 854 | 892 | |
| 855 | 893 | // Register a form number and store it in the session stack. (use this on the page that has the form.) |
| 856 | 894 | if ($action == 'register') |
| 857 | 895 | { |
| 858 | 896 | $context['form_sequence_number'] = 0; |
| 859 | - while (empty($context['form_sequence_number']) || in_array($context['form_sequence_number'], $_SESSION['forms'])) |
|
| 860 | - $context['form_sequence_number'] = mt_rand(1, 16000000); |
|
| 897 | + while (empty($context['form_sequence_number']) || in_array($context['form_sequence_number'], $_SESSION['forms'])) { |
|
| 898 | + $context['form_sequence_number'] = mt_rand(1, 16000000); |
|
| 899 | + } |
|
| 861 | 900 | } |
| 862 | 901 | // Check whether the submitted number can be found in the session. |
| 863 | 902 | elseif ($action == 'check') |
| 864 | 903 | { |
| 865 | - if (!isset($_REQUEST['seqnum'])) |
|
| 866 | - return true; |
|
| 867 | - elseif (!in_array($_REQUEST['seqnum'], $_SESSION['forms'])) |
|
| 904 | + if (!isset($_REQUEST['seqnum'])) { |
|
| 905 | + return true; |
|
| 906 | + } elseif (!in_array($_REQUEST['seqnum'], $_SESSION['forms'])) |
|
| 868 | 907 | { |
| 869 | 908 | $_SESSION['forms'][] = (int) $_REQUEST['seqnum']; |
| 870 | 909 | return true; |
| 910 | + } elseif ($is_fatal) { |
|
| 911 | + fatal_lang_error('error_form_already_submitted', false); |
|
| 912 | + } else { |
|
| 913 | + return false; |
|
| 871 | 914 | } |
| 872 | - elseif ($is_fatal) |
|
| 873 | - fatal_lang_error('error_form_already_submitted', false); |
|
| 874 | - else |
|
| 875 | - return false; |
|
| 876 | 915 | } |
| 877 | 916 | // Don't check, just free the stack number. |
| 878 | - elseif ($action == 'free' && isset($_REQUEST['seqnum']) && in_array($_REQUEST['seqnum'], $_SESSION['forms'])) |
|
| 879 | - $_SESSION['forms'] = array_diff($_SESSION['forms'], array($_REQUEST['seqnum'])); |
|
| 880 | - elseif ($action != 'free') |
|
| 881 | - trigger_error('checkSubmitOnce(): Invalid action \'' . $action . '\'', E_USER_WARNING); |
|
| 882 | -} |
|
| 917 | + elseif ($action == 'free' && isset($_REQUEST['seqnum']) && in_array($_REQUEST['seqnum'], $_SESSION['forms'])) { |
|
| 918 | + $_SESSION['forms'] = array_diff($_SESSION['forms'], array($_REQUEST['seqnum'])); |
|
| 919 | + } elseif ($action != 'free') { |
|
| 920 | + trigger_error('checkSubmitOnce(): Invalid action \'' . $action . '\'', E_USER_WARNING); |
|
| 921 | + } |
|
| 922 | + } |
|
| 883 | 923 | |
| 884 | 924 | /** |
| 885 | 925 | * Check the user's permissions. |
@@ -896,16 +936,19 @@ discard block |
||
| 896 | 936 | global $user_info, $smcFunc; |
| 897 | 937 | |
| 898 | 938 | // You're always allowed to do nothing. (unless you're a working man, MR. LAZY :P!) |
| 899 | - if (empty($permission)) |
|
| 900 | - return true; |
|
| 939 | + if (empty($permission)) { |
|
| 940 | + return true; |
|
| 941 | + } |
|
| 901 | 942 | |
| 902 | 943 | // You're never allowed to do something if your data hasn't been loaded yet! |
| 903 | - if (empty($user_info)) |
|
| 904 | - return false; |
|
| 944 | + if (empty($user_info)) { |
|
| 945 | + return false; |
|
| 946 | + } |
|
| 905 | 947 | |
| 906 | 948 | // Administrators are supermen :P. |
| 907 | - if ($user_info['is_admin']) |
|
| 908 | - return true; |
|
| 949 | + if ($user_info['is_admin']) { |
|
| 950 | + return true; |
|
| 951 | + } |
|
| 909 | 952 | |
| 910 | 953 | // Let's ensure this is an array. |
| 911 | 954 | $permission = (array) $permission; |
@@ -913,14 +956,16 @@ discard block |
||
| 913 | 956 | // Are we checking the _current_ board, or some other boards? |
| 914 | 957 | if ($boards === null) |
| 915 | 958 | { |
| 916 | - if (count(array_intersect($permission, $user_info['permissions'])) != 0) |
|
| 917 | - return true; |
|
| 959 | + if (count(array_intersect($permission, $user_info['permissions'])) != 0) { |
|
| 960 | + return true; |
|
| 961 | + } |
|
| 918 | 962 | // You aren't allowed, by default. |
| 919 | - else |
|
| 920 | - return false; |
|
| 963 | + else { |
|
| 964 | + return false; |
|
| 965 | + } |
|
| 966 | + } elseif (!is_array($boards)) { |
|
| 967 | + $boards = array($boards); |
|
| 921 | 968 | } |
| 922 | - elseif (!is_array($boards)) |
|
| 923 | - $boards = array($boards); |
|
| 924 | 969 | |
| 925 | 970 | $request = $smcFunc['db_query']('', ' |
| 926 | 971 | SELECT MIN(bp.add_deny) AS add_deny |
@@ -943,12 +988,14 @@ discard block |
||
| 943 | 988 | ); |
| 944 | 989 | |
| 945 | 990 | // Make sure they can do it on all of the boards. |
| 946 | - if ($smcFunc['db_num_rows']($request) != count($boards)) |
|
| 947 | - return false; |
|
| 991 | + if ($smcFunc['db_num_rows']($request) != count($boards)) { |
|
| 992 | + return false; |
|
| 993 | + } |
|
| 948 | 994 | |
| 949 | 995 | $result = true; |
| 950 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 951 | - $result &= !empty($row['add_deny']); |
|
| 996 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 997 | + $result &= !empty($row['add_deny']); |
|
| 998 | + } |
|
| 952 | 999 | $smcFunc['db_free_result']($request); |
| 953 | 1000 | |
| 954 | 1001 | // If the query returned 1, they can do it... otherwise, they can't. |
@@ -1013,9 +1060,10 @@ discard block |
||
| 1013 | 1060 | |
| 1014 | 1061 | // If you're doing something on behalf of some "heavy" permissions, validate your session. |
| 1015 | 1062 | // (take out the heavy permissions, and if you can't do anything but those, you need a validated session.) |
| 1016 | - if (!allowedTo(array_diff($permission, $heavy_permissions), $boards)) |
|
| 1017 | - validateSession(); |
|
| 1018 | -} |
|
| 1063 | + if (!allowedTo(array_diff($permission, $heavy_permissions), $boards)) { |
|
| 1064 | + validateSession(); |
|
| 1065 | + } |
|
| 1066 | + } |
|
| 1019 | 1067 | |
| 1020 | 1068 | /** |
| 1021 | 1069 | * Return the boards a user has a certain (board) permission on. (array(0) if all.) |
@@ -1034,8 +1082,9 @@ discard block |
||
| 1034 | 1082 | global $user_info, $smcFunc; |
| 1035 | 1083 | |
| 1036 | 1084 | // Arrays are nice, most of the time. |
| 1037 | - if (!is_array($permissions)) |
|
| 1038 | - $permissions = array($permissions); |
|
| 1085 | + if (!is_array($permissions)) { |
|
| 1086 | + $permissions = array($permissions); |
|
| 1087 | + } |
|
| 1039 | 1088 | |
| 1040 | 1089 | /* |
| 1041 | 1090 | * Set $simple to true to use this function as it were in SMF 2.0.x. |
@@ -1047,13 +1096,14 @@ discard block |
||
| 1047 | 1096 | // Administrators are all powerful, sorry. |
| 1048 | 1097 | if ($user_info['is_admin']) |
| 1049 | 1098 | { |
| 1050 | - if ($simple) |
|
| 1051 | - return array(0); |
|
| 1052 | - else |
|
| 1099 | + if ($simple) { |
|
| 1100 | + return array(0); |
|
| 1101 | + } else |
|
| 1053 | 1102 | { |
| 1054 | 1103 | $boards = array(); |
| 1055 | - foreach ($permissions as $permission) |
|
| 1056 | - $boards[$permission] = array(0); |
|
| 1104 | + foreach ($permissions as $permission) { |
|
| 1105 | + $boards[$permission] = array(0); |
|
| 1106 | + } |
|
| 1057 | 1107 | |
| 1058 | 1108 | return $boards; |
| 1059 | 1109 | } |
@@ -1085,31 +1135,32 @@ discard block |
||
| 1085 | 1135 | { |
| 1086 | 1136 | if ($simple) |
| 1087 | 1137 | { |
| 1088 | - if (empty($row['add_deny'])) |
|
| 1089 | - $deny_boards[] = $row['id_board']; |
|
| 1090 | - else |
|
| 1091 | - $boards[] = $row['id_board']; |
|
| 1092 | - } |
|
| 1093 | - else |
|
| 1138 | + if (empty($row['add_deny'])) { |
|
| 1139 | + $deny_boards[] = $row['id_board']; |
|
| 1140 | + } else { |
|
| 1141 | + $boards[] = $row['id_board']; |
|
| 1142 | + } |
|
| 1143 | + } else |
|
| 1094 | 1144 | { |
| 1095 | - if (empty($row['add_deny'])) |
|
| 1096 | - $deny_boards[$row['permission']][] = $row['id_board']; |
|
| 1097 | - else |
|
| 1098 | - $boards[$row['permission']][] = $row['id_board']; |
|
| 1145 | + if (empty($row['add_deny'])) { |
|
| 1146 | + $deny_boards[$row['permission']][] = $row['id_board']; |
|
| 1147 | + } else { |
|
| 1148 | + $boards[$row['permission']][] = $row['id_board']; |
|
| 1149 | + } |
|
| 1099 | 1150 | } |
| 1100 | 1151 | } |
| 1101 | 1152 | $smcFunc['db_free_result']($request); |
| 1102 | 1153 | |
| 1103 | - if ($simple) |
|
| 1104 | - $boards = array_unique(array_values(array_diff($boards, $deny_boards))); |
|
| 1105 | - else |
|
| 1154 | + if ($simple) { |
|
| 1155 | + $boards = array_unique(array_values(array_diff($boards, $deny_boards))); |
|
| 1156 | + } else |
|
| 1106 | 1157 | { |
| 1107 | 1158 | foreach ($permissions as $permission) |
| 1108 | 1159 | { |
| 1109 | 1160 | // never had it to start with |
| 1110 | - if (empty($boards[$permission])) |
|
| 1111 | - $boards[$permission] = array(); |
|
| 1112 | - else |
|
| 1161 | + if (empty($boards[$permission])) { |
|
| 1162 | + $boards[$permission] = array(); |
|
| 1163 | + } else |
|
| 1113 | 1164 | { |
| 1114 | 1165 | // Or it may have been removed |
| 1115 | 1166 | $deny_boards[$permission] = isset($deny_boards[$permission]) ? $deny_boards[$permission] : array(); |
@@ -1145,10 +1196,11 @@ discard block |
||
| 1145 | 1196 | |
| 1146 | 1197 | |
| 1147 | 1198 | // Moderators are free... |
| 1148 | - if (!allowedTo('moderate_board')) |
|
| 1149 | - $timeLimit = isset($timeOverrides[$error_type]) ? $timeOverrides[$error_type] : $modSettings['spamWaitTime']; |
|
| 1150 | - else |
|
| 1151 | - $timeLimit = 2; |
|
| 1199 | + if (!allowedTo('moderate_board')) { |
|
| 1200 | + $timeLimit = isset($timeOverrides[$error_type]) ? $timeOverrides[$error_type] : $modSettings['spamWaitTime']; |
|
| 1201 | + } else { |
|
| 1202 | + $timeLimit = 2; |
|
| 1203 | + } |
|
| 1152 | 1204 | |
| 1153 | 1205 | call_integration_hook('integrate_spam_protection', array(&$timeOverrides, &$timeLimit)); |
| 1154 | 1206 | |
@@ -1175,8 +1227,9 @@ discard block |
||
| 1175 | 1227 | if ($smcFunc['db_affected_rows']() != 1) |
| 1176 | 1228 | { |
| 1177 | 1229 | // Spammer! You only have to wait a *few* seconds! |
| 1178 | - if (!$only_return_result) |
|
| 1179 | - fatal_lang_error($error_type . '_WaitTime_broken', false, array($timeLimit)); |
|
| 1230 | + if (!$only_return_result) { |
|
| 1231 | + fatal_lang_error($error_type . '_WaitTime_broken', false, array($timeLimit)); |
|
| 1232 | + } |
|
| 1180 | 1233 | |
| 1181 | 1234 | return true; |
| 1182 | 1235 | } |
@@ -1194,11 +1247,13 @@ discard block |
||
| 1194 | 1247 | */ |
| 1195 | 1248 | function secureDirectory($path, $attachments = false) |
| 1196 | 1249 | { |
| 1197 | - if (empty($path)) |
|
| 1198 | - return 'empty_path'; |
|
| 1250 | + if (empty($path)) { |
|
| 1251 | + return 'empty_path'; |
|
| 1252 | + } |
|
| 1199 | 1253 | |
| 1200 | - if (!is_writable($path)) |
|
| 1201 | - return 'path_not_writable'; |
|
| 1254 | + if (!is_writable($path)) { |
|
| 1255 | + return 'path_not_writable'; |
|
| 1256 | + } |
|
| 1202 | 1257 | |
| 1203 | 1258 | $directoryname = basename($path); |
| 1204 | 1259 | |
@@ -1210,9 +1265,9 @@ discard block |
||
| 1210 | 1265 | |
| 1211 | 1266 | RemoveHandler .php .php3 .phtml .cgi .fcgi .pl .fpl .shtml'; |
| 1212 | 1267 | |
| 1213 | - if (file_exists($path . '/.htaccess')) |
|
| 1214 | - $errors[] = 'htaccess_exists'; |
|
| 1215 | - else |
|
| 1268 | + if (file_exists($path . '/.htaccess')) { |
|
| 1269 | + $errors[] = 'htaccess_exists'; |
|
| 1270 | + } else |
|
| 1216 | 1271 | { |
| 1217 | 1272 | $fh = @fopen($path . '/.htaccess', 'w'); |
| 1218 | 1273 | if ($fh) { |
@@ -1224,9 +1279,9 @@ discard block |
||
| 1224 | 1279 | $errors[] = 'htaccess_cannot_create_file'; |
| 1225 | 1280 | } |
| 1226 | 1281 | |
| 1227 | - if (file_exists($path . '/index.php')) |
|
| 1228 | - $errors[] = 'index-php_exists'; |
|
| 1229 | - else |
|
| 1282 | + if (file_exists($path . '/index.php')) { |
|
| 1283 | + $errors[] = 'index-php_exists'; |
|
| 1284 | + } else |
|
| 1230 | 1285 | { |
| 1231 | 1286 | $fh = @fopen($path . '/index.php', 'w'); |
| 1232 | 1287 | if ($fh) { |
@@ -1253,11 +1308,12 @@ discard block |
||
| 1253 | 1308 | $errors[] = 'index-php_cannot_create_file'; |
| 1254 | 1309 | } |
| 1255 | 1310 | |
| 1256 | - if (!empty($errors)) |
|
| 1257 | - return $errors; |
|
| 1258 | - else |
|
| 1259 | - return true; |
|
| 1260 | -} |
|
| 1311 | + if (!empty($errors)) { |
|
| 1312 | + return $errors; |
|
| 1313 | + } else { |
|
| 1314 | + return true; |
|
| 1315 | + } |
|
| 1316 | + } |
|
| 1261 | 1317 | |
| 1262 | 1318 | /** |
| 1263 | 1319 | * This sets the X-Frame-Options header. |
@@ -1270,14 +1326,16 @@ discard block |
||
| 1270 | 1326 | global $modSettings; |
| 1271 | 1327 | |
| 1272 | 1328 | $option = 'SAMEORIGIN'; |
| 1273 | - if (is_null($override) && !empty($modSettings['frame_security'])) |
|
| 1274 | - $option = $modSettings['frame_security']; |
|
| 1275 | - elseif (in_array($override, array('SAMEORIGIN', 'DENY'))) |
|
| 1276 | - $option = $override; |
|
| 1329 | + if (is_null($override) && !empty($modSettings['frame_security'])) { |
|
| 1330 | + $option = $modSettings['frame_security']; |
|
| 1331 | + } elseif (in_array($override, array('SAMEORIGIN', 'DENY'))) { |
|
| 1332 | + $option = $override; |
|
| 1333 | + } |
|
| 1277 | 1334 | |
| 1278 | 1335 | // Don't bother setting the header if we have disabled it. |
| 1279 | - if ($option == 'DISABLE') |
|
| 1280 | - return; |
|
| 1336 | + if ($option == 'DISABLE') { |
|
| 1337 | + return; |
|
| 1338 | + } |
|
| 1281 | 1339 | |
| 1282 | 1340 | // Finally set it. |
| 1283 | 1341 | header('X-Frame-Options: ' . $option); |
@@ -14,8 +14,9 @@ discard block |
||
| 14 | 14 | * @version 2.1 Beta 4 |
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | -if (!defined('SMF')) |
|
| 17 | +if (!defined('SMF')) { |
|
| 18 | 18 | die('No direct access...'); |
| 19 | +} |
|
| 19 | 20 | |
| 20 | 21 | /** |
| 21 | 22 | * Ask them for their login information. (shows a page for the user to type |
@@ -29,8 +30,9 @@ discard block |
||
| 29 | 30 | global $txt, $context, $scripturl, $user_info; |
| 30 | 31 | |
| 31 | 32 | // You are already logged in, go take a tour of the boards |
| 32 | - if (!empty($user_info['id'])) |
|
| 33 | - redirectexit(); |
|
| 33 | + if (!empty($user_info['id'])) { |
|
| 34 | + redirectexit(); |
|
| 35 | + } |
|
| 34 | 36 | |
| 35 | 37 | // We need to load the Login template/language file. |
| 36 | 38 | loadLanguage('Login'); |
@@ -57,10 +59,11 @@ discard block |
||
| 57 | 59 | ); |
| 58 | 60 | |
| 59 | 61 | // Set the login URL - will be used when the login process is done (but careful not to send us to an attachment). |
| 60 | - if (isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) |
|
| 61 | - $_SESSION['login_url'] = $_SESSION['old_url']; |
|
| 62 | - elseif (isset($_SESSION['login_url']) && strpos($_SESSION['login_url'], 'dlattach') !== false) |
|
| 63 | - unset($_SESSION['login_url']); |
|
| 62 | + if (isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) { |
|
| 63 | + $_SESSION['login_url'] = $_SESSION['old_url']; |
|
| 64 | + } elseif (isset($_SESSION['login_url']) && strpos($_SESSION['login_url'], 'dlattach') !== false) { |
|
| 65 | + unset($_SESSION['login_url']); |
|
| 66 | + } |
|
| 64 | 67 | |
| 65 | 68 | // Create a one time token. |
| 66 | 69 | createToken('login'); |
@@ -83,8 +86,9 @@ discard block |
||
| 83 | 86 | global $cookiename, $modSettings, $context, $sourcedir, $maintenance; |
| 84 | 87 | |
| 85 | 88 | // Check to ensure we're forcing SSL for authentication |
| 86 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) |
|
| 87 | - fatal_lang_error('login_ssl_required'); |
|
| 89 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) { |
|
| 90 | + fatal_lang_error('login_ssl_required'); |
|
| 91 | + } |
|
| 88 | 92 | |
| 89 | 93 | // Load cookie authentication stuff. |
| 90 | 94 | require_once($sourcedir . '/Subs-Auth.php'); |
@@ -102,19 +106,20 @@ discard block |
||
| 102 | 106 | list (,, $timeout) = $smcFunc['json_decode']($_COOKIE[$cookiename], true); |
| 103 | 107 | |
| 104 | 108 | // That didn't work... Maybe it's using serialize? |
| 105 | - if (is_null($timeout)) |
|
| 106 | - list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]); |
|
| 107 | - } |
|
| 108 | - elseif (isset($_SESSION['login_' . $cookiename])) |
|
| 109 | + if (is_null($timeout)) { |
|
| 110 | + list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]); |
|
| 111 | + } |
|
| 112 | + } elseif (isset($_SESSION['login_' . $cookiename])) |
|
| 109 | 113 | { |
| 110 | 114 | list (,, $timeout) = $smcFunc['json_decode']($_SESSION['login_' . $cookiename]); |
| 111 | 115 | |
| 112 | 116 | // Try for old format |
| 113 | - if (is_null($timeout)) |
|
| 114 | - list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]); |
|
| 117 | + if (is_null($timeout)) { |
|
| 118 | + list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]); |
|
| 119 | + } |
|
| 120 | + } else { |
|
| 121 | + trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR); |
|
| 115 | 122 | } |
| 116 | - else |
|
| 117 | - trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR); |
|
| 118 | 123 | |
| 119 | 124 | $user_settings['password_salt'] = substr(md5(mt_rand()), 0, 4); |
| 120 | 125 | updateMemberData($user_info['id'], array('password_salt' => $user_settings['password_salt'])); |
@@ -127,10 +132,11 @@ discard block |
||
| 127 | 132 | list ($tfamember, $tfasecret, $exp, $state, $preserve) = $tfadata; |
| 128 | 133 | |
| 129 | 134 | // If we're preserving the cookie, reset it with updated salt |
| 130 | - if (isset($tfamember, $tfasecret, $exp, $state, $preserve) && $preserve && time() < $exp) |
|
| 131 | - setTFACookie(3153600, $user_info['password_salt'], hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']), true); |
|
| 132 | - else |
|
| 133 | - setTFACookie(-3600, 0, ''); |
|
| 135 | + if (isset($tfamember, $tfasecret, $exp, $state, $preserve) && $preserve && time() < $exp) { |
|
| 136 | + setTFACookie(3153600, $user_info['password_salt'], hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']), true); |
|
| 137 | + } else { |
|
| 138 | + setTFACookie(-3600, 0, ''); |
|
| 139 | + } |
|
| 134 | 140 | } |
| 135 | 141 | |
| 136 | 142 | setLoginCookie($timeout - time(), $user_info['id'], hash_salt($user_settings['passwd'], $user_settings['password_salt'])); |
@@ -141,20 +147,20 @@ discard block |
||
| 141 | 147 | elseif (isset($_GET['sa']) && $_GET['sa'] == 'check') |
| 142 | 148 | { |
| 143 | 149 | // Strike! You're outta there! |
| 144 | - if ($_GET['member'] != $user_info['id']) |
|
| 145 | - fatal_lang_error('login_cookie_error', false); |
|
| 150 | + if ($_GET['member'] != $user_info['id']) { |
|
| 151 | + fatal_lang_error('login_cookie_error', false); |
|
| 152 | + } |
|
| 146 | 153 | |
| 147 | 154 | $user_info['can_mod'] = allowedTo('access_mod_center') || (!$user_info['is_guest'] && ($user_info['mod_cache']['gq'] != '0=1' || $user_info['mod_cache']['bq'] != '0=1' || ($modSettings['postmod_active'] && !empty($user_info['mod_cache']['ap'])))); |
| 148 | 155 | |
| 149 | 156 | // Some whitelisting for login_url... |
| 150 | - if (empty($_SESSION['login_url'])) |
|
| 151 | - redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa'); |
|
| 152 | - elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false)) |
|
| 157 | + if (empty($_SESSION['login_url'])) { |
|
| 158 | + redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa'); |
|
| 159 | + } elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false)) |
|
| 153 | 160 | { |
| 154 | 161 | unset ($_SESSION['login_url']); |
| 155 | 162 | redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa'); |
| 156 | - } |
|
| 157 | - else |
|
| 163 | + } else |
|
| 158 | 164 | { |
| 159 | 165 | // Best not to clutter the session data too much... |
| 160 | 166 | $temp = $_SESSION['login_url']; |
@@ -165,8 +171,9 @@ discard block |
||
| 165 | 171 | } |
| 166 | 172 | |
| 167 | 173 | // Beyond this point you are assumed to be a guest trying to login. |
| 168 | - if (!$user_info['is_guest']) |
|
| 169 | - redirectexit(); |
|
| 174 | + if (!$user_info['is_guest']) { |
|
| 175 | + redirectexit(); |
|
| 176 | + } |
|
| 170 | 177 | |
| 171 | 178 | // Are you guessing with a script? |
| 172 | 179 | checkSession(); |
@@ -174,18 +181,21 @@ discard block |
||
| 174 | 181 | spamProtection('login'); |
| 175 | 182 | |
| 176 | 183 | // Set the login_url if it's not already set (but careful not to send us to an attachment). |
| 177 | - if ((empty($_SESSION['login_url']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) || (isset($_GET['quicklogin']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'login') === false)) |
|
| 178 | - $_SESSION['login_url'] = $_SESSION['old_url']; |
|
| 184 | + if ((empty($_SESSION['login_url']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) || (isset($_GET['quicklogin']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'login') === false)) { |
|
| 185 | + $_SESSION['login_url'] = $_SESSION['old_url']; |
|
| 186 | + } |
|
| 179 | 187 | |
| 180 | 188 | // Been guessing a lot, haven't we? |
| 181 | - if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3) |
|
| 182 | - fatal_lang_error('login_threshold_fail', 'login'); |
|
| 189 | + if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3) { |
|
| 190 | + fatal_lang_error('login_threshold_fail', 'login'); |
|
| 191 | + } |
|
| 183 | 192 | |
| 184 | 193 | // Set up the cookie length. (if it's invalid, just fall through and use the default.) |
| 185 | - if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1)) |
|
| 186 | - $modSettings['cookieTime'] = 3153600; |
|
| 187 | - elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 525600)) |
|
| 188 | - $modSettings['cookieTime'] = (int) $_POST['cookielength']; |
|
| 194 | + if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1)) { |
|
| 195 | + $modSettings['cookieTime'] = 3153600; |
|
| 196 | + } elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 525600)) { |
|
| 197 | + $modSettings['cookieTime'] = (int) $_POST['cookielength']; |
|
| 198 | + } |
|
| 189 | 199 | |
| 190 | 200 | loadLanguage('Login'); |
| 191 | 201 | // Load the template stuff. |
@@ -305,8 +315,9 @@ discard block |
||
| 305 | 315 | $other_passwords[] = crypt(md5($_POST['passwrd']), md5($_POST['passwrd'])); |
| 306 | 316 | |
| 307 | 317 | // Snitz style - SHA-256. Technically, this is a downgrade, but most PHP configurations don't support sha256 anyway. |
| 308 | - if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256')) |
|
| 309 | - $other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd'])); |
|
| 318 | + if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256')) { |
|
| 319 | + $other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd'])); |
|
| 320 | + } |
|
| 310 | 321 | |
| 311 | 322 | // phpBB3 users new hashing. We now support it as well ;). |
| 312 | 323 | $other_passwords[] = phpBB3_password_check($_POST['passwrd'], $user_settings['passwd']); |
@@ -326,27 +337,29 @@ discard block |
||
| 326 | 337 | // Some common md5 ones. |
| 327 | 338 | $other_passwords[] = md5($user_settings['password_salt'] . $_POST['passwrd']); |
| 328 | 339 | $other_passwords[] = md5($_POST['passwrd'] . $user_settings['password_salt']); |
| 329 | - } |
|
| 330 | - elseif (strlen($user_settings['passwd']) == 40) |
|
| 340 | + } elseif (strlen($user_settings['passwd']) == 40) |
|
| 331 | 341 | { |
| 332 | 342 | // Maybe they are using a hash from before the password fix. |
| 333 | 343 | // This is also valid for SMF 1.1 to 2.0 style of hashing, changed to bcrypt in SMF 2.1 |
| 334 | 344 | $other_passwords[] = sha1(strtolower($user_settings['member_name']) . un_htmlspecialchars($_POST['passwrd'])); |
| 335 | 345 | |
| 336 | 346 | // BurningBoard3 style of hashing. |
| 337 | - if (!empty($modSettings['enable_password_conversion'])) |
|
| 338 | - $other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd']))); |
|
| 347 | + if (!empty($modSettings['enable_password_conversion'])) { |
|
| 348 | + $other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd']))); |
|
| 349 | + } |
|
| 339 | 350 | |
| 340 | 351 | // Perhaps we converted to UTF-8 and have a valid password being hashed differently. |
| 341 | 352 | if ($context['character_set'] == 'UTF-8' && !empty($modSettings['previousCharacterSet']) && $modSettings['previousCharacterSet'] != 'utf8') |
| 342 | 353 | { |
| 343 | 354 | // Try iconv first, for no particular reason. |
| 344 | - if (function_exists('iconv')) |
|
| 345 | - $other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd']))); |
|
| 355 | + if (function_exists('iconv')) { |
|
| 356 | + $other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd']))); |
|
| 357 | + } |
|
| 346 | 358 | |
| 347 | 359 | // Say it aint so, iconv failed! |
| 348 | - if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding')) |
|
| 349 | - $other_passwords[] = sha1(strtolower(mb_convert_encoding($user_settings['member_name'], 'UTF-8', $modSettings['previousCharacterSet'])) . un_htmlspecialchars(mb_convert_encoding($_POST['passwrd'], 'UTF-8', $modSettings['previousCharacterSet']))); |
|
| 360 | + if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding')) { |
|
| 361 | + $other_passwords[] = sha1(strtolower(mb_convert_encoding($user_settings['member_name'], 'UTF-8', $modSettings['previousCharacterSet'])) . un_htmlspecialchars(mb_convert_encoding($_POST['passwrd'], 'UTF-8', $modSettings['previousCharacterSet']))); |
|
| 362 | + } |
|
| 350 | 363 | } |
| 351 | 364 | } |
| 352 | 365 | |
@@ -376,8 +389,9 @@ discard block |
||
| 376 | 389 | $_SESSION['failed_login'] = isset($_SESSION['failed_login']) ? ($_SESSION['failed_login'] + 1) : 1; |
| 377 | 390 | |
| 378 | 391 | // Hmm... don't remember it, do you? Here, try the password reminder ;). |
| 379 | - if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold']) |
|
| 380 | - redirectexit('action=reminder'); |
|
| 392 | + if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold']) { |
|
| 393 | + redirectexit('action=reminder'); |
|
| 394 | + } |
|
| 381 | 395 | // We'll give you another chance... |
| 382 | 396 | else |
| 383 | 397 | { |
@@ -388,8 +402,7 @@ discard block |
||
| 388 | 402 | return; |
| 389 | 403 | } |
| 390 | 404 | } |
| 391 | - } |
|
| 392 | - elseif (!empty($user_settings['passwd_flood'])) |
|
| 405 | + } elseif (!empty($user_settings['passwd_flood'])) |
|
| 393 | 406 | { |
| 394 | 407 | // Let's be sure they weren't a little hacker. |
| 395 | 408 | validatePasswordFlood($user_settings['id_member'], $user_settings['member_name'], $user_settings['passwd_flood'], true); |
@@ -406,8 +419,9 @@ discard block |
||
| 406 | 419 | } |
| 407 | 420 | |
| 408 | 421 | // Check their activation status. |
| 409 | - if (!checkActivation()) |
|
| 410 | - return; |
|
| 422 | + if (!checkActivation()) { |
|
| 423 | + return; |
|
| 424 | + } |
|
| 411 | 425 | |
| 412 | 426 | DoLogin(); |
| 413 | 427 | } |
@@ -419,8 +433,9 @@ discard block |
||
| 419 | 433 | { |
| 420 | 434 | global $sourcedir, $txt, $context, $user_info, $modSettings, $scripturl; |
| 421 | 435 | |
| 422 | - if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode'])) |
|
| 423 | - fatal_lang_error('no_access', false); |
|
| 436 | + if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode'])) { |
|
| 437 | + fatal_lang_error('no_access', false); |
|
| 438 | + } |
|
| 424 | 439 | |
| 425 | 440 | loadLanguage('Profile'); |
| 426 | 441 | require_once($sourcedir . '/Class-TOTP.php'); |
@@ -428,8 +443,9 @@ discard block |
||
| 428 | 443 | $member = $context['tfa_member']; |
| 429 | 444 | |
| 430 | 445 | // Prevent replay attacks by limiting at least 2 minutes before they can log in again via 2FA |
| 431 | - if (time() - $member['last_login'] < 120) |
|
| 432 | - fatal_lang_error('tfa_wait', false); |
|
| 446 | + if (time() - $member['last_login'] < 120) { |
|
| 447 | + fatal_lang_error('tfa_wait', false); |
|
| 448 | + } |
|
| 433 | 449 | |
| 434 | 450 | $totp = new \TOTP\Auth($member['tfa_secret']); |
| 435 | 451 | $totp->setRange(1); |
@@ -443,8 +459,9 @@ discard block |
||
| 443 | 459 | if (!empty($_POST['tfa_code']) && empty($_POST['tfa_backup'])) |
| 444 | 460 | { |
| 445 | 461 | // Check to ensure we're forcing SSL for authentication |
| 446 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) |
|
| 447 | - fatal_lang_error('login_ssl_required'); |
|
| 462 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) { |
|
| 463 | + fatal_lang_error('login_ssl_required'); |
|
| 464 | + } |
|
| 448 | 465 | |
| 449 | 466 | $code = $_POST['tfa_code']; |
| 450 | 467 | |
@@ -454,20 +471,19 @@ discard block |
||
| 454 | 471 | |
| 455 | 472 | setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt']), !empty($_POST['tfa_preserve'])); |
| 456 | 473 | redirectexit(); |
| 457 | - } |
|
| 458 | - else |
|
| 474 | + } else |
|
| 459 | 475 | { |
| 460 | 476 | validatePasswordFlood($member['id_member'], $member['member_name'], $member['passwd_flood'], false, true); |
| 461 | 477 | |
| 462 | 478 | $context['tfa_error'] = true; |
| 463 | 479 | $context['tfa_value'] = $_POST['tfa_code']; |
| 464 | 480 | } |
| 465 | - } |
|
| 466 | - elseif (!empty($_POST['tfa_backup'])) |
|
| 481 | + } elseif (!empty($_POST['tfa_backup'])) |
|
| 467 | 482 | { |
| 468 | 483 | // Check to ensure we're forcing SSL for authentication |
| 469 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) |
|
| 470 | - fatal_lang_error('login_ssl_required'); |
|
| 484 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) { |
|
| 485 | + fatal_lang_error('login_ssl_required'); |
|
| 486 | + } |
|
| 471 | 487 | |
| 472 | 488 | $backup = $_POST['tfa_backup']; |
| 473 | 489 | |
@@ -481,8 +497,7 @@ discard block |
||
| 481 | 497 | )); |
| 482 | 498 | setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt'])); |
| 483 | 499 | redirectexit('action=profile;area=tfasetup;backup'); |
| 484 | - } |
|
| 485 | - else |
|
| 500 | + } else |
|
| 486 | 501 | { |
| 487 | 502 | validatePasswordFlood($member['id_member'], $member['member_name'], $member['passwd_flood'], false, true); |
| 488 | 503 | |
@@ -505,8 +520,9 @@ discard block |
||
| 505 | 520 | { |
| 506 | 521 | global $context, $txt, $scripturl, $user_settings, $modSettings; |
| 507 | 522 | |
| 508 | - if (!isset($context['login_errors'])) |
|
| 509 | - $context['login_errors'] = array(); |
|
| 523 | + if (!isset($context['login_errors'])) { |
|
| 524 | + $context['login_errors'] = array(); |
|
| 525 | + } |
|
| 510 | 526 | |
| 511 | 527 | // What is the true activation status of this account? |
| 512 | 528 | $activation_status = $user_settings['is_activated'] > 10 ? $user_settings['is_activated'] - 10 : $user_settings['is_activated']; |
@@ -518,8 +534,9 @@ discard block |
||
| 518 | 534 | return false; |
| 519 | 535 | } |
| 520 | 536 | // Awaiting approval still? |
| 521 | - elseif ($activation_status == 3) |
|
| 522 | - fatal_lang_error('still_awaiting_approval', 'user'); |
|
| 537 | + elseif ($activation_status == 3) { |
|
| 538 | + fatal_lang_error('still_awaiting_approval', 'user'); |
|
| 539 | + } |
|
| 523 | 540 | // Awaiting deletion, changed their mind? |
| 524 | 541 | elseif ($activation_status == 4) |
| 525 | 542 | { |
@@ -527,8 +544,7 @@ discard block |
||
| 527 | 544 | { |
| 528 | 545 | updateMemberData($user_settings['id_member'], array('is_activated' => 1)); |
| 529 | 546 | updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 0 ? $modSettings['unapprovedMembers'] - 1 : 0))); |
| 530 | - } |
|
| 531 | - else |
|
| 547 | + } else |
|
| 532 | 548 | { |
| 533 | 549 | $context['disable_login_hashing'] = true; |
| 534 | 550 | $context['login_errors'][] = $txt['awaiting_delete_account']; |
@@ -568,8 +584,9 @@ discard block |
||
| 568 | 584 | setLoginCookie(60 * $modSettings['cookieTime'], $user_settings['id_member'], hash_salt($user_settings['passwd'], $user_settings['password_salt'])); |
| 569 | 585 | |
| 570 | 586 | // Reset the login threshold. |
| 571 | - if (isset($_SESSION['failed_login'])) |
|
| 572 | - unset($_SESSION['failed_login']); |
|
| 587 | + if (isset($_SESSION['failed_login'])) { |
|
| 588 | + unset($_SESSION['failed_login']); |
|
| 589 | + } |
|
| 573 | 590 | |
| 574 | 591 | $user_info['is_guest'] = false; |
| 575 | 592 | $user_settings['additional_groups'] = explode(',', $user_settings['additional_groups']); |
@@ -591,16 +608,18 @@ discard block |
||
| 591 | 608 | 'id_member' => $user_info['id'], |
| 592 | 609 | ) |
| 593 | 610 | ); |
| 594 | - if ($smcFunc['db_num_rows']($request) == 1) |
|
| 595 | - $_SESSION['first_login'] = true; |
|
| 596 | - else |
|
| 597 | - unset($_SESSION['first_login']); |
|
| 611 | + if ($smcFunc['db_num_rows']($request) == 1) { |
|
| 612 | + $_SESSION['first_login'] = true; |
|
| 613 | + } else { |
|
| 614 | + unset($_SESSION['first_login']); |
|
| 615 | + } |
|
| 598 | 616 | $smcFunc['db_free_result']($request); |
| 599 | 617 | |
| 600 | 618 | // You've logged in, haven't you? |
| 601 | 619 | $update = array('member_ip' => $user_info['ip'], 'member_ip2' => $_SERVER['BAN_CHECK_IP']); |
| 602 | - if (empty($user_settings['tfa_secret'])) |
|
| 603 | - $update['last_login'] = time(); |
|
| 620 | + if (empty($user_settings['tfa_secret'])) { |
|
| 621 | + $update['last_login'] = time(); |
|
| 622 | + } |
|
| 604 | 623 | updateMemberData($user_info['id'], $update); |
| 605 | 624 | |
| 606 | 625 | // Get rid of the online entry for that old guest.... |
@@ -614,8 +633,8 @@ discard block |
||
| 614 | 633 | $_SESSION['log_time'] = 0; |
| 615 | 634 | |
| 616 | 635 | // Log this entry, only if we have it enabled. |
| 617 | - if (!empty($modSettings['loginHistoryDays'])) |
|
| 618 | - $smcFunc['db_insert']('insert', |
|
| 636 | + if (!empty($modSettings['loginHistoryDays'])) { |
|
| 637 | + $smcFunc['db_insert']('insert', |
|
| 619 | 638 | '{db_prefix}member_logins', |
| 620 | 639 | array( |
| 621 | 640 | 'id_member' => 'int', 'time' => 'int', 'ip' => 'inet', 'ip2' => 'inet', |
@@ -627,13 +646,15 @@ discard block |
||
| 627 | 646 | 'id_member', 'time' |
| 628 | 647 | ) |
| 629 | 648 | ); |
| 649 | + } |
|
| 630 | 650 | |
| 631 | 651 | // Just log you back out if it's in maintenance mode and you AREN'T an admin. |
| 632 | - if (empty($maintenance) || allowedTo('admin_forum')) |
|
| 633 | - redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']); |
|
| 634 | - else |
|
| 635 | - redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']); |
|
| 636 | -} |
|
| 652 | + if (empty($maintenance) || allowedTo('admin_forum')) { |
|
| 653 | + redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']); |
|
| 654 | + } else { |
|
| 655 | + redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']); |
|
| 656 | + } |
|
| 657 | + } |
|
| 637 | 658 | |
| 638 | 659 | /** |
| 639 | 660 | * Logs the current user out of their account. |
@@ -649,13 +670,15 @@ discard block |
||
| 649 | 670 | global $sourcedir, $user_info, $user_settings, $context, $smcFunc, $cookiename, $modSettings; |
| 650 | 671 | |
| 651 | 672 | // Make sure they aren't being auto-logged out. |
| 652 | - if (!$internal) |
|
| 653 | - checkSession('get'); |
|
| 673 | + if (!$internal) { |
|
| 674 | + checkSession('get'); |
|
| 675 | + } |
|
| 654 | 676 | |
| 655 | 677 | require_once($sourcedir . '/Subs-Auth.php'); |
| 656 | 678 | |
| 657 | - if (isset($_SESSION['pack_ftp'])) |
|
| 658 | - $_SESSION['pack_ftp'] = null; |
|
| 679 | + if (isset($_SESSION['pack_ftp'])) { |
|
| 680 | + $_SESSION['pack_ftp'] = null; |
|
| 681 | + } |
|
| 659 | 682 | |
| 660 | 683 | // It won't be first login anymore. |
| 661 | 684 | unset($_SESSION['first_login']); |
@@ -683,8 +706,9 @@ discard block |
||
| 683 | 706 | |
| 684 | 707 | // And some other housekeeping while we're at it. |
| 685 | 708 | $salt = substr(md5(mt_rand()), 0, 4); |
| 686 | - if (!empty($user_info['id'])) |
|
| 687 | - updateMemberData($user_info['id'], array('password_salt' => $salt)); |
|
| 709 | + if (!empty($user_info['id'])) { |
|
| 710 | + updateMemberData($user_info['id'], array('password_salt' => $salt)); |
|
| 711 | + } |
|
| 688 | 712 | |
| 689 | 713 | if (!empty($modSettings['tfa_mode']) && !empty($user_info['id']) && !empty($_COOKIE[$cookiename . '_tfa'])) |
| 690 | 714 | { |
@@ -693,10 +717,11 @@ discard block |
||
| 693 | 717 | list ($tfamember, $tfasecret, $exp, $state, $preserve) = $tfadata; |
| 694 | 718 | |
| 695 | 719 | // If we're preserving the cookie, reset it with updated salt |
| 696 | - if (isset($tfamember, $tfasecret, $exp, $state, $preserve) && $preserve && time() < $exp) |
|
| 697 | - setTFACookie(3153600, $user_info['id'], hash_salt($user_settings['tfa_backup'], $salt), true); |
|
| 698 | - else |
|
| 699 | - setTFACookie(-3600, 0, ''); |
|
| 720 | + if (isset($tfamember, $tfasecret, $exp, $state, $preserve) && $preserve && time() < $exp) { |
|
| 721 | + setTFACookie(3153600, $user_info['id'], hash_salt($user_settings['tfa_backup'], $salt), true); |
|
| 722 | + } else { |
|
| 723 | + setTFACookie(-3600, 0, ''); |
|
| 724 | + } |
|
| 700 | 725 | } |
| 701 | 726 | |
| 702 | 727 | session_destroy(); |
@@ -704,14 +729,13 @@ discard block |
||
| 704 | 729 | // Off to the merry board index we go! |
| 705 | 730 | if ($redirect) |
| 706 | 731 | { |
| 707 | - if (empty($_SESSION['logout_url'])) |
|
| 708 | - redirectexit('', $context['server']['needs_login_fix']); |
|
| 709 | - elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false)) |
|
| 732 | + if (empty($_SESSION['logout_url'])) { |
|
| 733 | + redirectexit('', $context['server']['needs_login_fix']); |
|
| 734 | + } elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false)) |
|
| 710 | 735 | { |
| 711 | 736 | unset ($_SESSION['logout_url']); |
| 712 | 737 | redirectexit(); |
| 713 | - } |
|
| 714 | - else |
|
| 738 | + } else |
|
| 715 | 739 | { |
| 716 | 740 | $temp = $_SESSION['logout_url']; |
| 717 | 741 | unset($_SESSION['logout_url']); |
@@ -744,8 +768,9 @@ discard block |
||
| 744 | 768 | function phpBB3_password_check($passwd, $passwd_hash) |
| 745 | 769 | { |
| 746 | 770 | // Too long or too short? |
| 747 | - if (strlen($passwd_hash) != 34) |
|
| 748 | - return; |
|
| 771 | + if (strlen($passwd_hash) != 34) { |
|
| 772 | + return; |
|
| 773 | + } |
|
| 749 | 774 | |
| 750 | 775 | // Range of characters allowed. |
| 751 | 776 | $range = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; |
@@ -756,8 +781,9 @@ discard block |
||
| 756 | 781 | $salt = substr($passwd_hash, 4, 8); |
| 757 | 782 | |
| 758 | 783 | $hash = md5($salt . $passwd, true); |
| 759 | - for (; $count != 0; --$count) |
|
| 760 | - $hash = md5($hash . $passwd, true); |
|
| 784 | + for (; $count != 0; --$count) { |
|
| 785 | + $hash = md5($hash . $passwd, true); |
|
| 786 | + } |
|
| 761 | 787 | |
| 762 | 788 | $output = substr($passwd_hash, 0, 12); |
| 763 | 789 | $i = 0; |
@@ -766,21 +792,25 @@ discard block |
||
| 766 | 792 | $value = ord($hash[$i++]); |
| 767 | 793 | $output .= $range[$value & 0x3f]; |
| 768 | 794 | |
| 769 | - if ($i < 16) |
|
| 770 | - $value |= ord($hash[$i]) << 8; |
|
| 795 | + if ($i < 16) { |
|
| 796 | + $value |= ord($hash[$i]) << 8; |
|
| 797 | + } |
|
| 771 | 798 | |
| 772 | 799 | $output .= $range[($value >> 6) & 0x3f]; |
| 773 | 800 | |
| 774 | - if ($i++ >= 16) |
|
| 775 | - break; |
|
| 801 | + if ($i++ >= 16) { |
|
| 802 | + break; |
|
| 803 | + } |
|
| 776 | 804 | |
| 777 | - if ($i < 16) |
|
| 778 | - $value |= ord($hash[$i]) << 16; |
|
| 805 | + if ($i < 16) { |
|
| 806 | + $value |= ord($hash[$i]) << 16; |
|
| 807 | + } |
|
| 779 | 808 | |
| 780 | 809 | $output .= $range[($value >> 12) & 0x3f]; |
| 781 | 810 | |
| 782 | - if ($i++ >= 16) |
|
| 783 | - break; |
|
| 811 | + if ($i++ >= 16) { |
|
| 812 | + break; |
|
| 813 | + } |
|
| 784 | 814 | |
| 785 | 815 | $output .= $range[($value >> 18) & 0x3f]; |
| 786 | 816 | } |
@@ -812,8 +842,9 @@ discard block |
||
| 812 | 842 | require_once($sourcedir . '/Subs-Auth.php'); |
| 813 | 843 | setLoginCookie(-3600, 0); |
| 814 | 844 | |
| 815 | - if (isset($_SESSION['login_' . $cookiename])) |
|
| 816 | - unset($_SESSION['login_' . $cookiename]); |
|
| 845 | + if (isset($_SESSION['login_' . $cookiename])) { |
|
| 846 | + unset($_SESSION['login_' . $cookiename]); |
|
| 847 | + } |
|
| 817 | 848 | } |
| 818 | 849 | |
| 819 | 850 | // We need a member! |
@@ -827,8 +858,9 @@ discard block |
||
| 827 | 858 | } |
| 828 | 859 | |
| 829 | 860 | // Right, have we got a flood value? |
| 830 | - if ($password_flood_value !== false) |
|
| 831 | - @list ($time_stamp, $number_tries) = explode('|', $password_flood_value); |
|
| 861 | + if ($password_flood_value !== false) { |
|
| 862 | + @list ($time_stamp, $number_tries) = explode('|', $password_flood_value); |
|
| 863 | + } |
|
| 832 | 864 | |
| 833 | 865 | // Timestamp or number of tries invalid? |
| 834 | 866 | if (empty($number_tries) || empty($time_stamp)) |
@@ -844,15 +876,17 @@ discard block |
||
| 844 | 876 | $number_tries = $time_stamp < time() - 20 ? 2 : $number_tries; |
| 845 | 877 | |
| 846 | 878 | // They are trying too fast, make them wait longer |
| 847 | - if ($time_stamp < time() - 10) |
|
| 848 | - $time_stamp = time(); |
|
| 879 | + if ($time_stamp < time() - 10) { |
|
| 880 | + $time_stamp = time(); |
|
| 881 | + } |
|
| 849 | 882 | } |
| 850 | 883 | |
| 851 | 884 | $number_tries++; |
| 852 | 885 | |
| 853 | 886 | // Broken the law? |
| 854 | - if ($number_tries > 5) |
|
| 855 | - fatal_lang_error('login_threshold_brute_fail', 'login', [$member_name]); |
|
| 887 | + if ($number_tries > 5) { |
|
| 888 | + fatal_lang_error('login_threshold_brute_fail', 'login', [$member_name]); |
|
| 889 | + } |
|
| 856 | 890 | |
| 857 | 891 | // Otherwise set the members data. If they correct on their first attempt then we actually clear it, otherwise we set it! |
| 858 | 892 | updateMemberData($id_member, array('passwd_flood' => $was_correct && $number_tries == 1 ? '' : $time_stamp . '|' . $number_tries)); |
@@ -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 | * Begin the registration process. |
@@ -29,19 +30,23 @@ discard block |
||
| 29 | 30 | global $language, $scripturl, $smcFunc, $sourcedir, $cur_profile; |
| 30 | 31 | |
| 31 | 32 | // Is this an incoming AJAX check? |
| 32 | - if (isset($_GET['sa']) && $_GET['sa'] == 'usernamecheck') |
|
| 33 | - return RegisterCheckUsername(); |
|
| 33 | + if (isset($_GET['sa']) && $_GET['sa'] == 'usernamecheck') { |
|
| 34 | + return RegisterCheckUsername(); |
|
| 35 | + } |
|
| 34 | 36 | |
| 35 | 37 | // Check if the administrator has it disabled. |
| 36 | - if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == '3') |
|
| 37 | - fatal_lang_error('registration_disabled', false); |
|
| 38 | + if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == '3') { |
|
| 39 | + fatal_lang_error('registration_disabled', false); |
|
| 40 | + } |
|
| 38 | 41 | |
| 39 | 42 | // If this user is an admin - redirect them to the admin registration page. |
| 40 | - if (allowedTo('moderate_forum') && !$user_info['is_guest']) |
|
| 41 | - redirectexit('action=admin;area=regcenter;sa=register'); |
|
| 43 | + if (allowedTo('moderate_forum') && !$user_info['is_guest']) { |
|
| 44 | + redirectexit('action=admin;area=regcenter;sa=register'); |
|
| 45 | + } |
|
| 42 | 46 | // You are not a guest, so you are a member - and members don't get to register twice! |
| 43 | - elseif (empty($user_info['is_guest'])) |
|
| 44 | - redirectexit(); |
|
| 47 | + elseif (empty($user_info['is_guest'])) { |
|
| 48 | + redirectexit(); |
|
| 49 | + } |
|
| 45 | 50 | |
| 46 | 51 | loadLanguage('Login'); |
| 47 | 52 | loadTemplate('Register'); |
@@ -82,16 +87,18 @@ discard block |
||
| 82 | 87 | } |
| 83 | 88 | } |
| 84 | 89 | // Make sure they don't squeeze through without agreeing. |
| 85 | - elseif ($current_step > 1 && $context['require_agreement'] && !$context['registration_passed_agreement']) |
|
| 86 | - $current_step = 1; |
|
| 90 | + elseif ($current_step > 1 && $context['require_agreement'] && !$context['registration_passed_agreement']) { |
|
| 91 | + $current_step = 1; |
|
| 92 | + } |
|
| 87 | 93 | |
| 88 | 94 | // Show the user the right form. |
| 89 | 95 | $context['sub_template'] = $current_step == 1 ? 'registration_agreement' : 'registration_form'; |
| 90 | 96 | $context['page_title'] = $current_step == 1 ? $txt['registration_agreement'] : $txt['registration_form']; |
| 91 | 97 | |
| 92 | 98 | // Kinda need this. |
| 93 | - if ($context['sub_template'] == 'registration_form') |
|
| 94 | - loadJavaScriptFile('register.js', array('defer' => false), 'smf_register'); |
|
| 99 | + if ($context['sub_template'] == 'registration_form') { |
|
| 100 | + loadJavaScriptFile('register.js', array('defer' => false), 'smf_register'); |
|
| 101 | + } |
|
| 95 | 102 | |
| 96 | 103 | // Add the register chain to the link tree. |
| 97 | 104 | $context['linktree'][] = array( |
@@ -100,24 +107,26 @@ discard block |
||
| 100 | 107 | ); |
| 101 | 108 | |
| 102 | 109 | // Prepare the time gate! Do it like so, in case later steps want to reset the limit for any reason, but make sure the time is the current one. |
| 103 | - if (!isset($_SESSION['register'])) |
|
| 104 | - $_SESSION['register'] = array( |
|
| 110 | + if (!isset($_SESSION['register'])) { |
|
| 111 | + $_SESSION['register'] = array( |
|
| 105 | 112 | 'timenow' => time(), |
| 106 | 113 | 'limit' => 10, // minimum number of seconds required on this page for registration |
| 107 | 114 | ); |
| 108 | - else |
|
| 109 | - $_SESSION['register']['timenow'] = time(); |
|
| 115 | + } else { |
|
| 116 | + $_SESSION['register']['timenow'] = time(); |
|
| 117 | + } |
|
| 110 | 118 | |
| 111 | 119 | // If you have to agree to the agreement, it needs to be fetched from the file. |
| 112 | 120 | if ($context['require_agreement']) |
| 113 | 121 | { |
| 114 | 122 | // Have we got a localized one? |
| 115 | - if (file_exists($boarddir . '/agreement.' . $user_info['language'] . '.txt')) |
|
| 116 | - $context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.' . $user_info['language'] . '.txt'), true, 'agreement_' . $user_info['language']); |
|
| 117 | - elseif (file_exists($boarddir . '/agreement.txt')) |
|
| 118 | - $context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.txt'), true, 'agreement'); |
|
| 119 | - else |
|
| 120 | - $context['agreement'] = ''; |
|
| 123 | + if (file_exists($boarddir . '/agreement.' . $user_info['language'] . '.txt')) { |
|
| 124 | + $context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.' . $user_info['language'] . '.txt'), true, 'agreement_' . $user_info['language']); |
|
| 125 | + } elseif (file_exists($boarddir . '/agreement.txt')) { |
|
| 126 | + $context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.txt'), true, 'agreement'); |
|
| 127 | + } else { |
|
| 128 | + $context['agreement'] = ''; |
|
| 129 | + } |
|
| 121 | 130 | |
| 122 | 131 | // Nothing to show, lets disable registration and inform the admin of this error |
| 123 | 132 | if (empty($context['agreement'])) |
@@ -133,8 +142,9 @@ discard block |
||
| 133 | 142 | $selectedLanguage = empty($_SESSION['language']) ? $language : $_SESSION['language']; |
| 134 | 143 | |
| 135 | 144 | // Do we have any languages? |
| 136 | - if (empty($context['languages'])) |
|
| 137 | - getLanguages(); |
|
| 145 | + if (empty($context['languages'])) { |
|
| 146 | + getLanguages(); |
|
| 147 | + } |
|
| 138 | 148 | |
| 139 | 149 | // Try to find our selected language. |
| 140 | 150 | foreach ($context['languages'] as $key => $lang) |
@@ -142,8 +152,9 @@ discard block |
||
| 142 | 152 | $context['languages'][$key]['name'] = strtr($lang['name'], array('-utf8' => '')); |
| 143 | 153 | |
| 144 | 154 | // Found it! |
| 145 | - if ($selectedLanguage == $lang['filename']) |
|
| 146 | - $context['languages'][$key]['selected'] = true; |
|
| 155 | + if ($selectedLanguage == $lang['filename']) { |
|
| 156 | + $context['languages'][$key]['selected'] = true; |
|
| 157 | + } |
|
| 147 | 158 | } |
| 148 | 159 | } |
| 149 | 160 | |
@@ -167,9 +178,10 @@ discard block |
||
| 167 | 178 | $reg_fields = explode(',', $modSettings['registration_fields']); |
| 168 | 179 | |
| 169 | 180 | // We might have had some submissions on this front - go check. |
| 170 | - foreach ($reg_fields as $field) |
|
| 171 | - if (isset($_POST[$field])) |
|
| 181 | + foreach ($reg_fields as $field) { |
|
| 182 | + if (isset($_POST[$field])) |
|
| 172 | 183 | $cur_profile[$field] = $smcFunc['htmlspecialchars']($_POST[$field]); |
| 184 | + } |
|
| 173 | 185 | |
| 174 | 186 | // Load all the fields in question. |
| 175 | 187 | setupProfileContext($reg_fields); |
@@ -186,8 +198,9 @@ discard block |
||
| 186 | 198 | $context['visual_verification_id'] = $verificationOptions['id']; |
| 187 | 199 | } |
| 188 | 200 | // Otherwise we have nothing to show. |
| 189 | - else |
|
| 190 | - $context['visual_verification'] = false; |
|
| 201 | + else { |
|
| 202 | + $context['visual_verification'] = false; |
|
| 203 | + } |
|
| 191 | 204 | |
| 192 | 205 | |
| 193 | 206 | $context += array( |
@@ -198,8 +211,9 @@ discard block |
||
| 198 | 211 | |
| 199 | 212 | // Were there any errors? |
| 200 | 213 | $context['registration_errors'] = array(); |
| 201 | - if (!empty($reg_errors)) |
|
| 202 | - $context['registration_errors'] = $reg_errors; |
|
| 214 | + if (!empty($reg_errors)) { |
|
| 215 | + $context['registration_errors'] = $reg_errors; |
|
| 216 | + } |
|
| 203 | 217 | |
| 204 | 218 | createToken('register'); |
| 205 | 219 | } |
@@ -216,27 +230,32 @@ discard block |
||
| 216 | 230 | validateToken('register'); |
| 217 | 231 | |
| 218 | 232 | // Check to ensure we're forcing SSL for authentication |
| 219 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) |
|
| 220 | - fatal_lang_error('register_ssl_required'); |
|
| 233 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) { |
|
| 234 | + fatal_lang_error('register_ssl_required'); |
|
| 235 | + } |
|
| 221 | 236 | |
| 222 | 237 | // Start collecting together any errors. |
| 223 | 238 | $reg_errors = array(); |
| 224 | 239 | |
| 225 | 240 | // You can't register if it's disabled. |
| 226 | - if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 3) |
|
| 227 | - fatal_lang_error('registration_disabled', false); |
|
| 241 | + if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 3) { |
|
| 242 | + fatal_lang_error('registration_disabled', false); |
|
| 243 | + } |
|
| 228 | 244 | |
| 229 | 245 | // Well, if you don't agree, you can't register. |
| 230 | - if (!empty($modSettings['requireAgreement']) && empty($_SESSION['registration_agreed'])) |
|
| 231 | - redirectexit(); |
|
| 246 | + if (!empty($modSettings['requireAgreement']) && empty($_SESSION['registration_agreed'])) { |
|
| 247 | + redirectexit(); |
|
| 248 | + } |
|
| 232 | 249 | |
| 233 | 250 | // Make sure they came from *somewhere*, have a session. |
| 234 | - if (!isset($_SESSION['old_url'])) |
|
| 235 | - redirectexit('action=signup'); |
|
| 251 | + if (!isset($_SESSION['old_url'])) { |
|
| 252 | + redirectexit('action=signup'); |
|
| 253 | + } |
|
| 236 | 254 | |
| 237 | 255 | // If we don't require an agreement, we need a extra check for coppa. |
| 238 | - if (empty($modSettings['requireAgreement']) && !empty($modSettings['coppaAge'])) |
|
| 239 | - $_SESSION['skip_coppa'] = !empty($_POST['accept_agreement']); |
|
| 256 | + if (empty($modSettings['requireAgreement']) && !empty($modSettings['coppaAge'])) { |
|
| 257 | + $_SESSION['skip_coppa'] = !empty($_POST['accept_agreement']); |
|
| 258 | + } |
|
| 240 | 259 | // Are they under age, and under age users are banned? |
| 241 | 260 | if (!empty($modSettings['coppaAge']) && empty($modSettings['coppaType']) && empty($_SESSION['skip_coppa'])) |
| 242 | 261 | { |
@@ -245,8 +264,9 @@ discard block |
||
| 245 | 264 | } |
| 246 | 265 | |
| 247 | 266 | // Check the time gate for miscreants. First make sure they came from somewhere that actually set it up. |
| 248 | - if (empty($_SESSION['register']['timenow']) || empty($_SESSION['register']['limit'])) |
|
| 249 | - redirectexit('action=signup'); |
|
| 267 | + if (empty($_SESSION['register']['timenow']) || empty($_SESSION['register']['limit'])) { |
|
| 268 | + redirectexit('action=signup'); |
|
| 269 | + } |
|
| 250 | 270 | // Failing that, check the time on it. |
| 251 | 271 | if (time() - $_SESSION['register']['timenow'] < $_SESSION['register']['limit']) |
| 252 | 272 | { |
@@ -266,15 +286,17 @@ discard block |
||
| 266 | 286 | if (is_array($context['visual_verification'])) |
| 267 | 287 | { |
| 268 | 288 | loadLanguage('Errors'); |
| 269 | - foreach ($context['visual_verification'] as $error) |
|
| 270 | - $reg_errors[] = $txt['error_' . $error]; |
|
| 289 | + foreach ($context['visual_verification'] as $error) { |
|
| 290 | + $reg_errors[] = $txt['error_' . $error]; |
|
| 291 | + } |
|
| 271 | 292 | } |
| 272 | 293 | } |
| 273 | 294 | |
| 274 | 295 | foreach ($_POST as $key => $value) |
| 275 | 296 | { |
| 276 | - if (!is_array($_POST[$key])) |
|
| 277 | - $_POST[$key] = htmltrim__recursive(str_replace(array("\n", "\r"), '', $_POST[$key])); |
|
| 297 | + if (!is_array($_POST[$key])) { |
|
| 298 | + $_POST[$key] = htmltrim__recursive(str_replace(array("\n", "\r"), '', $_POST[$key])); |
|
| 299 | + } |
|
| 278 | 300 | } |
| 279 | 301 | |
| 280 | 302 | // Collect all extra registration fields someone might have filled in. |
@@ -304,12 +326,14 @@ discard block |
||
| 304 | 326 | $reg_fields = explode(',', $modSettings['registration_fields']); |
| 305 | 327 | |
| 306 | 328 | // Website is a little different |
| 307 | - if (in_array('website', $reg_fields)) |
|
| 308 | - $possible_strings = array_merge(array('website_url', 'website_title'), $possible_strings); |
|
| 329 | + if (in_array('website', $reg_fields)) { |
|
| 330 | + $possible_strings = array_merge(array('website_url', 'website_title'), $possible_strings); |
|
| 331 | + } |
|
| 309 | 332 | } |
| 310 | 333 | |
| 311 | - if (isset($_POST['secret_answer']) && $_POST['secret_answer'] != '') |
|
| 312 | - $_POST['secret_answer'] = md5($_POST['secret_answer']); |
|
| 334 | + if (isset($_POST['secret_answer']) && $_POST['secret_answer'] != '') { |
|
| 335 | + $_POST['secret_answer'] = md5($_POST['secret_answer']); |
|
| 336 | + } |
|
| 313 | 337 | |
| 314 | 338 | // Needed for isReservedName() and registerMember(). |
| 315 | 339 | require_once($sourcedir . '/Subs-Members.php'); |
@@ -318,8 +342,9 @@ discard block |
||
| 318 | 342 | if (isset($_POST['real_name'])) |
| 319 | 343 | { |
| 320 | 344 | // Are you already allowed to edit the displayed name? |
| 321 | - if (allowedTo('profile_displayed_name') || allowedTo('moderate_forum')) |
|
| 322 | - $canEditDisplayName = true; |
|
| 345 | + if (allowedTo('profile_displayed_name') || allowedTo('moderate_forum')) { |
|
| 346 | + $canEditDisplayName = true; |
|
| 347 | + } |
|
| 323 | 348 | |
| 324 | 349 | // If you are a guest, will you be allowed to once you register? |
| 325 | 350 | else |
@@ -343,33 +368,38 @@ discard block |
||
| 343 | 368 | $_POST['real_name'] = trim(preg_replace('~[\t\n\r \x0B\0' . ($context['utf8'] ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : '\x00-\x08\x0B\x0C\x0E-\x19\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $_POST['real_name'])); |
| 344 | 369 | |
| 345 | 370 | // Only set it if we are sure it is good |
| 346 | - if (trim($_POST['real_name']) != '' && !isReservedName($_POST['real_name']) && $smcFunc['strlen']($_POST['real_name']) < 60) |
|
| 347 | - $possible_strings[] = 'real_name'; |
|
| 371 | + if (trim($_POST['real_name']) != '' && !isReservedName($_POST['real_name']) && $smcFunc['strlen']($_POST['real_name']) < 60) { |
|
| 372 | + $possible_strings[] = 'real_name'; |
|
| 373 | + } |
|
| 348 | 374 | } |
| 349 | 375 | } |
| 350 | 376 | |
| 351 | 377 | // Handle a string as a birthdate... |
| 352 | - if (isset($_POST['birthdate']) && $_POST['birthdate'] != '') |
|
| 353 | - $_POST['birthdate'] = strftime('%Y-%m-%d', strtotime($_POST['birthdate'])); |
|
| 378 | + if (isset($_POST['birthdate']) && $_POST['birthdate'] != '') { |
|
| 379 | + $_POST['birthdate'] = strftime('%Y-%m-%d', strtotime($_POST['birthdate'])); |
|
| 380 | + } |
|
| 354 | 381 | // Or birthdate parts... |
| 355 | - elseif (!empty($_POST['bday1']) && !empty($_POST['bday2'])) |
|
| 356 | - $_POST['birthdate'] = sprintf('%04d-%02d-%02d', empty($_POST['bday3']) ? 0 : (int) $_POST['bday3'], (int) $_POST['bday1'], (int) $_POST['bday2']); |
|
| 382 | + elseif (!empty($_POST['bday1']) && !empty($_POST['bday2'])) { |
|
| 383 | + $_POST['birthdate'] = sprintf('%04d-%02d-%02d', empty($_POST['bday3']) ? 0 : (int) $_POST['bday3'], (int) $_POST['bday1'], (int) $_POST['bday2']); |
|
| 384 | + } |
|
| 357 | 385 | |
| 358 | 386 | // Validate the passed language file. |
| 359 | 387 | if (isset($_POST['lngfile']) && !empty($modSettings['userLanguage'])) |
| 360 | 388 | { |
| 361 | 389 | // Do we have any languages? |
| 362 | - if (empty($context['languages'])) |
|
| 363 | - getLanguages(); |
|
| 390 | + if (empty($context['languages'])) { |
|
| 391 | + getLanguages(); |
|
| 392 | + } |
|
| 364 | 393 | |
| 365 | 394 | // Did we find it? |
| 366 | - if (isset($context['languages'][$_POST['lngfile']])) |
|
| 367 | - $_SESSION['language'] = $_POST['lngfile']; |
|
| 368 | - else |
|
| 395 | + if (isset($context['languages'][$_POST['lngfile']])) { |
|
| 396 | + $_SESSION['language'] = $_POST['lngfile']; |
|
| 397 | + } else { |
|
| 398 | + unset($_POST['lngfile']); |
|
| 399 | + } |
|
| 400 | + } else { |
|
| 369 | 401 | unset($_POST['lngfile']); |
| 370 | 402 | } |
| 371 | - else |
|
| 372 | - unset($_POST['lngfile']); |
|
| 373 | 403 | |
| 374 | 404 | // Set the options needed for registration. |
| 375 | 405 | $regOptions = array( |
@@ -389,22 +419,27 @@ discard block |
||
| 389 | 419 | ); |
| 390 | 420 | |
| 391 | 421 | // Include the additional options that might have been filled in. |
| 392 | - foreach ($possible_strings as $var) |
|
| 393 | - if (isset($_POST[$var])) |
|
| 422 | + foreach ($possible_strings as $var) { |
|
| 423 | + if (isset($_POST[$var])) |
|
| 394 | 424 | $regOptions['extra_register_vars'][$var] = $smcFunc['htmlspecialchars']($_POST[$var], ENT_QUOTES); |
| 395 | - foreach ($possible_ints as $var) |
|
| 396 | - if (isset($_POST[$var])) |
|
| 425 | + } |
|
| 426 | + foreach ($possible_ints as $var) { |
|
| 427 | + if (isset($_POST[$var])) |
|
| 397 | 428 | $regOptions['extra_register_vars'][$var] = (int) $_POST[$var]; |
| 398 | - foreach ($possible_floats as $var) |
|
| 399 | - if (isset($_POST[$var])) |
|
| 429 | + } |
|
| 430 | + foreach ($possible_floats as $var) { |
|
| 431 | + if (isset($_POST[$var])) |
|
| 400 | 432 | $regOptions['extra_register_vars'][$var] = (float) $_POST[$var]; |
| 401 | - foreach ($possible_bools as $var) |
|
| 402 | - if (isset($_POST[$var])) |
|
| 433 | + } |
|
| 434 | + foreach ($possible_bools as $var) { |
|
| 435 | + if (isset($_POST[$var])) |
|
| 403 | 436 | $regOptions['extra_register_vars'][$var] = empty($_POST[$var]) ? 0 : 1; |
| 437 | + } |
|
| 404 | 438 | |
| 405 | 439 | // Registration options are always default options... |
| 406 | - if (isset($_POST['default_options'])) |
|
| 407 | - $_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options']; |
|
| 440 | + if (isset($_POST['default_options'])) { |
|
| 441 | + $_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options']; |
|
| 442 | + } |
|
| 408 | 443 | $regOptions['theme_vars'] = isset($_POST['options']) && is_array($_POST['options']) ? $_POST['options'] : array(); |
| 409 | 444 | |
| 410 | 445 | // Make sure they are clean, dammit! |
@@ -424,12 +459,14 @@ discard block |
||
| 424 | 459 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 425 | 460 | { |
| 426 | 461 | // Don't allow overriding of the theme variables. |
| 427 | - if (isset($regOptions['theme_vars'][$row['col_name']])) |
|
| 428 | - unset($regOptions['theme_vars'][$row['col_name']]); |
|
| 462 | + if (isset($regOptions['theme_vars'][$row['col_name']])) { |
|
| 463 | + unset($regOptions['theme_vars'][$row['col_name']]); |
|
| 464 | + } |
|
| 429 | 465 | |
| 430 | 466 | // Not actually showing it then? |
| 431 | - if (!$row['show_reg']) |
|
| 432 | - continue; |
|
| 467 | + if (!$row['show_reg']) { |
|
| 468 | + continue; |
|
| 469 | + } |
|
| 433 | 470 | |
| 434 | 471 | // Prepare the value! |
| 435 | 472 | $value = isset($_POST['customfield'][$row['col_name']]) ? trim($_POST['customfield'][$row['col_name']]) : ''; |
@@ -438,24 +475,27 @@ discard block |
||
| 438 | 475 | if (!in_array($row['field_type'], array('check', 'select', 'radio'))) |
| 439 | 476 | { |
| 440 | 477 | // Is it too long? |
| 441 | - if ($row['field_length'] && $row['field_length'] < $smcFunc['strlen']($value)) |
|
| 442 | - $custom_field_errors[] = array('custom_field_too_long', array($row['field_name'], $row['field_length'])); |
|
| 478 | + if ($row['field_length'] && $row['field_length'] < $smcFunc['strlen']($value)) { |
|
| 479 | + $custom_field_errors[] = array('custom_field_too_long', array($row['field_name'], $row['field_length'])); |
|
| 480 | + } |
|
| 443 | 481 | |
| 444 | 482 | // Any masks to apply? |
| 445 | 483 | if ($row['field_type'] == 'text' && !empty($row['mask']) && $row['mask'] != 'none') |
| 446 | 484 | { |
| 447 | - if ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255)) |
|
| 448 | - $custom_field_errors[] = array('custom_field_invalid_email', array($row['field_name'])); |
|
| 449 | - elseif ($row['mask'] == 'number' && preg_match('~[^\d]~', $value)) |
|
| 450 | - $custom_field_errors[] = array('custom_field_not_number', array($row['field_name'])); |
|
| 451 | - elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0) |
|
| 452 | - $custom_field_errors[] = array('custom_field_inproper_format', array($row['field_name'])); |
|
| 485 | + if ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255)) { |
|
| 486 | + $custom_field_errors[] = array('custom_field_invalid_email', array($row['field_name'])); |
|
| 487 | + } elseif ($row['mask'] == 'number' && preg_match('~[^\d]~', $value)) { |
|
| 488 | + $custom_field_errors[] = array('custom_field_not_number', array($row['field_name'])); |
|
| 489 | + } elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0) { |
|
| 490 | + $custom_field_errors[] = array('custom_field_inproper_format', array($row['field_name'])); |
|
| 491 | + } |
|
| 453 | 492 | } |
| 454 | 493 | } |
| 455 | 494 | |
| 456 | 495 | // Is this required but not there? |
| 457 | - if (trim($value) == '' && $row['show_reg'] > 1) |
|
| 458 | - $custom_field_errors[] = array('custom_field_empty', array($row['field_name'])); |
|
| 496 | + if (trim($value) == '' && $row['show_reg'] > 1) { |
|
| 497 | + $custom_field_errors[] = array('custom_field_empty', array($row['field_name'])); |
|
| 498 | + } |
|
| 459 | 499 | } |
| 460 | 500 | $smcFunc['db_free_result']($request); |
| 461 | 501 | |
@@ -463,8 +503,9 @@ discard block |
||
| 463 | 503 | if (!empty($custom_field_errors)) |
| 464 | 504 | { |
| 465 | 505 | loadLanguage('Errors'); |
| 466 | - foreach ($custom_field_errors as $error) |
|
| 467 | - $reg_errors[] = vsprintf($txt['error_' . $error[0]], $error[1]); |
|
| 506 | + foreach ($custom_field_errors as $error) { |
|
| 507 | + $reg_errors[] = vsprintf($txt['error_' . $error[0]], $error[1]); |
|
| 508 | + } |
|
| 468 | 509 | } |
| 469 | 510 | |
| 470 | 511 | // Lets check for other errors before trying to register the member. |
@@ -509,8 +550,9 @@ discard block |
||
| 509 | 550 | } |
| 510 | 551 | |
| 511 | 552 | // If COPPA has been selected then things get complicated, setup the template. |
| 512 | - if (!empty($modSettings['coppaAge']) && empty($_SESSION['skip_coppa'])) |
|
| 513 | - redirectexit('action=coppa;member=' . $memberID); |
|
| 553 | + if (!empty($modSettings['coppaAge']) && empty($_SESSION['skip_coppa'])) { |
|
| 554 | + redirectexit('action=coppa;member=' . $memberID); |
|
| 555 | + } |
|
| 514 | 556 | // Basic template variable setup. |
| 515 | 557 | elseif (!empty($modSettings['registration_method'])) |
| 516 | 558 | { |
@@ -522,8 +564,7 @@ discard block |
||
| 522 | 564 | 'sub_template' => 'after', |
| 523 | 565 | 'description' => $modSettings['registration_method'] == 2 ? $txt['approval_after_registration'] : $txt['activate_after_registration'] |
| 524 | 566 | ); |
| 525 | - } |
|
| 526 | - else |
|
| 567 | + } else |
|
| 527 | 568 | { |
| 528 | 569 | call_integration_hook('integrate_activate', array($regOptions['username'])); |
| 529 | 570 | |
@@ -543,16 +584,18 @@ discard block |
||
| 543 | 584 | global $context, $txt, $modSettings, $scripturl, $sourcedir, $smcFunc, $language, $user_info; |
| 544 | 585 | |
| 545 | 586 | // Logged in users should not bother to activate their accounts |
| 546 | - if (!empty($user_info['id'])) |
|
| 547 | - redirectexit(); |
|
| 587 | + if (!empty($user_info['id'])) { |
|
| 588 | + redirectexit(); |
|
| 589 | + } |
|
| 548 | 590 | |
| 549 | 591 | loadLanguage('Login'); |
| 550 | 592 | loadTemplate('Login'); |
| 551 | 593 | |
| 552 | 594 | if (empty($_REQUEST['u']) && empty($_POST['user'])) |
| 553 | 595 | { |
| 554 | - if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == '3') |
|
| 555 | - fatal_lang_error('no_access', false); |
|
| 596 | + if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == '3') { |
|
| 597 | + fatal_lang_error('no_access', false); |
|
| 598 | + } |
|
| 556 | 599 | |
| 557 | 600 | $context['member_id'] = 0; |
| 558 | 601 | $context['sub_template'] = 'resend'; |
@@ -592,11 +635,13 @@ discard block |
||
| 592 | 635 | // Change their email address? (they probably tried a fake one first :P.) |
| 593 | 636 | if (isset($_POST['new_email'], $_REQUEST['passwd']) && hash_password($row['member_name'], $_REQUEST['passwd']) == $row['passwd'] && ($row['is_activated'] == 0 || $row['is_activated'] == 2)) |
| 594 | 637 | { |
| 595 | - if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == 3) |
|
| 596 | - fatal_lang_error('no_access', false); |
|
| 638 | + if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == 3) { |
|
| 639 | + fatal_lang_error('no_access', false); |
|
| 640 | + } |
|
| 597 | 641 | |
| 598 | - if (!filter_var($_POST['new_email'], FILTER_VALIDATE_EMAIL)) |
|
| 599 | - fatal_error(sprintf($txt['valid_email_needed'], $smcFunc['htmlspecialchars']($_POST['new_email'])), false); |
|
| 642 | + if (!filter_var($_POST['new_email'], FILTER_VALIDATE_EMAIL)) { |
|
| 643 | + fatal_error(sprintf($txt['valid_email_needed'], $smcFunc['htmlspecialchars']($_POST['new_email'])), false); |
|
| 644 | + } |
|
| 600 | 645 | |
| 601 | 646 | // Make sure their email isn't banned. |
| 602 | 647 | isBannedEmail($_POST['new_email'], 'cannot_register', $txt['ban_register_prohibited']); |
@@ -612,8 +657,9 @@ discard block |
||
| 612 | 657 | ) |
| 613 | 658 | ); |
| 614 | 659 | |
| 615 | - if ($smcFunc['db_num_rows']($request) != 0) |
|
| 616 | - fatal_lang_error('email_in_use', false, array($smcFunc['htmlspecialchars']($_POST['new_email']))); |
|
| 660 | + if ($smcFunc['db_num_rows']($request) != 0) { |
|
| 661 | + fatal_lang_error('email_in_use', false, array($smcFunc['htmlspecialchars']($_POST['new_email']))); |
|
| 662 | + } |
|
| 617 | 663 | $smcFunc['db_free_result']($request); |
| 618 | 664 | |
| 619 | 665 | updateMemberData($row['id_member'], array('email_address' => $_POST['new_email'])); |
@@ -651,9 +697,9 @@ discard block |
||
| 651 | 697 | // Quit if this code is not right. |
| 652 | 698 | if (empty($_REQUEST['code']) || $row['validation_code'] != $_REQUEST['code']) |
| 653 | 699 | { |
| 654 | - if (!empty($row['is_activated'])) |
|
| 655 | - fatal_lang_error('already_activated', false); |
|
| 656 | - elseif ($row['validation_code'] == '') |
|
| 700 | + if (!empty($row['is_activated'])) { |
|
| 701 | + fatal_lang_error('already_activated', false); |
|
| 702 | + } elseif ($row['validation_code'] == '') |
|
| 657 | 703 | { |
| 658 | 704 | loadLanguage('Profile'); |
| 659 | 705 | fatal_error(sprintf($txt['registration_not_approved'], $scripturl . '?action=activate;user=' . $row['member_name']), false); |
@@ -703,8 +749,9 @@ discard block |
||
| 703 | 749 | loadTemplate('Register'); |
| 704 | 750 | |
| 705 | 751 | // No User ID?? |
| 706 | - if (!isset($_GET['member'])) |
|
| 707 | - fatal_lang_error('no_access', false); |
|
| 752 | + if (!isset($_GET['member'])) { |
|
| 753 | + fatal_lang_error('no_access', false); |
|
| 754 | + } |
|
| 708 | 755 | |
| 709 | 756 | // Get the user details... |
| 710 | 757 | $request = $smcFunc['db_query']('', ' |
@@ -717,8 +764,9 @@ discard block |
||
| 717 | 764 | 'is_coppa' => 5, |
| 718 | 765 | ) |
| 719 | 766 | ); |
| 720 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 721 | - fatal_lang_error('no_access', false); |
|
| 767 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 768 | + fatal_lang_error('no_access', false); |
|
| 769 | + } |
|
| 722 | 770 | list ($username) = $smcFunc['db_fetch_row']($request); |
| 723 | 771 | $smcFunc['db_free_result']($request); |
| 724 | 772 | |
@@ -756,8 +804,7 @@ discard block |
||
| 756 | 804 | echo $data; |
| 757 | 805 | obExit(false); |
| 758 | 806 | } |
| 759 | - } |
|
| 760 | - else |
|
| 807 | + } else |
|
| 761 | 808 | { |
| 762 | 809 | $context += array( |
| 763 | 810 | 'page_title' => $txt['coppa_title'], |
@@ -810,8 +857,9 @@ discard block |
||
| 810 | 857 | { |
| 811 | 858 | require_once($sourcedir . '/Subs-Graphics.php'); |
| 812 | 859 | |
| 813 | - if (in_array('gd', get_loaded_extensions()) && !showCodeImage($code)) |
|
| 814 | - header('HTTP/1.1 400 Bad Request'); |
|
| 860 | + if (in_array('gd', get_loaded_extensions()) && !showCodeImage($code)) { |
|
| 861 | + header('HTTP/1.1 400 Bad Request'); |
|
| 862 | + } |
|
| 815 | 863 | |
| 816 | 864 | // Otherwise just show a pre-defined letter. |
| 817 | 865 | elseif (isset($_REQUEST['letter'])) |
@@ -829,14 +877,13 @@ discard block |
||
| 829 | 877 | header('Content-Type: image/gif'); |
| 830 | 878 | die("\x47\x49\x46\x38\x39\x61\x01\x00\x01\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x21\xF9\x04\x01\x00\x00\x00\x00\x2C\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02\x44\x01\x00\x3B"); |
| 831 | 879 | } |
| 832 | - } |
|
| 833 | - |
|
| 834 | - elseif ($_REQUEST['format'] === '.wav') |
|
| 880 | + } elseif ($_REQUEST['format'] === '.wav') |
|
| 835 | 881 | { |
| 836 | 882 | require_once($sourcedir . '/Subs-Sound.php'); |
| 837 | 883 | |
| 838 | - if (!createWaveFile($code)) |
|
| 839 | - header('HTTP/1.1 400 Bad Request'); |
|
| 884 | + if (!createWaveFile($code)) { |
|
| 885 | + header('HTTP/1.1 400 Bad Request'); |
|
| 886 | + } |
|
| 840 | 887 | } |
| 841 | 888 | |
| 842 | 889 | // We all die one day... |
@@ -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 | * The main designating function for modifying profiles. Loads up info, determins what to do, etc. |
@@ -29,18 +30,21 @@ discard block |
||
| 29 | 30 | global $modSettings, $memberContext, $profile_vars, $post_errors, $smcFunc; |
| 30 | 31 | |
| 31 | 32 | // Don't reload this as we may have processed error strings. |
| 32 | - if (empty($post_errors)) |
|
| 33 | - loadLanguage('Profile+Drafts'); |
|
| 33 | + if (empty($post_errors)) { |
|
| 34 | + loadLanguage('Profile+Drafts'); |
|
| 35 | + } |
|
| 34 | 36 | loadTemplate('Profile'); |
| 35 | 37 | |
| 36 | 38 | require_once($sourcedir . '/Subs-Menu.php'); |
| 37 | 39 | |
| 38 | 40 | // Did we get the user by name... |
| 39 | - if (isset($_REQUEST['user'])) |
|
| 40 | - $memberResult = loadMemberData($_REQUEST['user'], true, 'profile'); |
|
| 41 | + if (isset($_REQUEST['user'])) { |
|
| 42 | + $memberResult = loadMemberData($_REQUEST['user'], true, 'profile'); |
|
| 43 | + } |
|
| 41 | 44 | // ... or by id_member? |
| 42 | - elseif (!empty($_REQUEST['u'])) |
|
| 43 | - $memberResult = loadMemberData((int) $_REQUEST['u'], false, 'profile'); |
|
| 45 | + elseif (!empty($_REQUEST['u'])) { |
|
| 46 | + $memberResult = loadMemberData((int) $_REQUEST['u'], false, 'profile'); |
|
| 47 | + } |
|
| 44 | 48 | // If it was just ?action=profile, edit your own profile, but only if you're not a guest. |
| 45 | 49 | else |
| 46 | 50 | { |
@@ -50,8 +54,9 @@ discard block |
||
| 50 | 54 | } |
| 51 | 55 | |
| 52 | 56 | // Check if loadMemberData() has returned a valid result. |
| 53 | - if (!$memberResult) |
|
| 54 | - fatal_lang_error('not_a_user', false, 404); |
|
| 57 | + if (!$memberResult) { |
|
| 58 | + fatal_lang_error('not_a_user', false, 404); |
|
| 59 | + } |
|
| 55 | 60 | |
| 56 | 61 | // If all went well, we have a valid member ID! |
| 57 | 62 | list ($memID) = $memberResult; |
@@ -67,8 +72,9 @@ discard block |
||
| 67 | 72 | |
| 68 | 73 | // Group management isn't actually a permission. But we need it to be for this, so we need a phantom permission. |
| 69 | 74 | // And we care about what the current user can do, not what the user whose profile it is. |
| 70 | - if ($user_info['mod_cache']['gq'] != '0=1') |
|
| 71 | - $user_info['permissions'][] = 'approve_group_requests'; |
|
| 75 | + if ($user_info['mod_cache']['gq'] != '0=1') { |
|
| 76 | + $user_info['permissions'][] = 'approve_group_requests'; |
|
| 77 | + } |
|
| 72 | 78 | |
| 73 | 79 | // If paid subscriptions are enabled, make sure we actually have at least one subscription available... |
| 74 | 80 | $context['subs_available'] = false; |
@@ -436,21 +442,25 @@ discard block |
||
| 436 | 442 | foreach ($section['areas'] as $area_id => $area) |
| 437 | 443 | { |
| 438 | 444 | // If it said no permissions that meant it wasn't valid! |
| 439 | - if (empty($area['permission'][$context['user']['is_owner'] ? 'own' : 'any'])) |
|
| 440 | - $profile_areas[$section_id]['areas'][$area_id]['enabled'] = false; |
|
| 445 | + if (empty($area['permission'][$context['user']['is_owner'] ? 'own' : 'any'])) { |
|
| 446 | + $profile_areas[$section_id]['areas'][$area_id]['enabled'] = false; |
|
| 447 | + } |
|
| 441 | 448 | // Otherwise pick the right set. |
| 442 | - else |
|
| 443 | - $profile_areas[$section_id]['areas'][$area_id]['permission'] = $area['permission'][$context['user']['is_owner'] ? 'own' : 'any']; |
|
| 449 | + else { |
|
| 450 | + $profile_areas[$section_id]['areas'][$area_id]['permission'] = $area['permission'][$context['user']['is_owner'] ? 'own' : 'any']; |
|
| 451 | + } |
|
| 444 | 452 | |
| 445 | 453 | // Password required in most cases |
| 446 | - if (!empty($area['password'])) |
|
| 447 | - $context['password_areas'][] = $area_id; |
|
| 454 | + if (!empty($area['password'])) { |
|
| 455 | + $context['password_areas'][] = $area_id; |
|
| 456 | + } |
|
| 448 | 457 | } |
| 449 | 458 | } |
| 450 | 459 | |
| 451 | 460 | // Is there an updated message to show? |
| 452 | - if (isset($_GET['updated'])) |
|
| 453 | - $context['profile_updated'] = $txt['profile_updated_own']; |
|
| 461 | + if (isset($_GET['updated'])) { |
|
| 462 | + $context['profile_updated'] = $txt['profile_updated_own']; |
|
| 463 | + } |
|
| 454 | 464 | |
| 455 | 465 | // Set a few options for the menu. |
| 456 | 466 | $menuOptions = array( |
@@ -465,8 +475,9 @@ discard block |
||
| 465 | 475 | $profile_include_data = createMenu($profile_areas, $menuOptions); |
| 466 | 476 | |
| 467 | 477 | // No menu means no access. |
| 468 | - if (!$profile_include_data && (!$user_info['is_guest'] || validateSession())) |
|
| 469 | - fatal_lang_error('no_access', false); |
|
| 478 | + if (!$profile_include_data && (!$user_info['is_guest'] || validateSession())) { |
|
| 479 | + fatal_lang_error('no_access', false); |
|
| 480 | + } |
|
| 470 | 481 | |
| 471 | 482 | // Make a note of the Unique ID for this menu. |
| 472 | 483 | $context['profile_menu_id'] = $context['max_menu_id']; |
@@ -492,8 +503,9 @@ discard block |
||
| 492 | 503 | if ($current_area == $area_id) |
| 493 | 504 | { |
| 494 | 505 | // This can't happen - but is a security check. |
| 495 | - if ((isset($section['enabled']) && $section['enabled'] == false) || (isset($area['enabled']) && $area['enabled'] == false)) |
|
| 496 | - fatal_lang_error('no_access', false); |
|
| 506 | + if ((isset($section['enabled']) && $section['enabled'] == false) || (isset($area['enabled']) && $area['enabled'] == false)) { |
|
| 507 | + fatal_lang_error('no_access', false); |
|
| 508 | + } |
|
| 497 | 509 | |
| 498 | 510 | // Are we saving data in a valid area? |
| 499 | 511 | if (isset($area['sc']) && (isset($_REQUEST['save']) || $context['do_preview'])) |
@@ -512,12 +524,14 @@ discard block |
||
| 512 | 524 | } |
| 513 | 525 | |
| 514 | 526 | // Does this require session validating? |
| 515 | - if (!empty($area['validate']) || (isset($_REQUEST['save']) && !$context['user']['is_owner'])) |
|
| 516 | - $security_checks['validate'] = true; |
|
| 527 | + if (!empty($area['validate']) || (isset($_REQUEST['save']) && !$context['user']['is_owner'])) { |
|
| 528 | + $security_checks['validate'] = true; |
|
| 529 | + } |
|
| 517 | 530 | |
| 518 | 531 | // Permissions for good measure. |
| 519 | - if (!empty($profile_include_data['permission'])) |
|
| 520 | - $security_checks['permission'] = $profile_include_data['permission']; |
|
| 532 | + if (!empty($profile_include_data['permission'])) { |
|
| 533 | + $security_checks['permission'] = $profile_include_data['permission']; |
|
| 534 | + } |
|
| 521 | 535 | |
| 522 | 536 | // Either way got something. |
| 523 | 537 | $found_area = true; |
@@ -526,21 +540,26 @@ discard block |
||
| 526 | 540 | } |
| 527 | 541 | |
| 528 | 542 | // Oh dear, some serious security lapse is going on here... we'll put a stop to that! |
| 529 | - if (!$found_area) |
|
| 530 | - fatal_lang_error('no_access', false); |
|
| 543 | + if (!$found_area) { |
|
| 544 | + fatal_lang_error('no_access', false); |
|
| 545 | + } |
|
| 531 | 546 | |
| 532 | 547 | // Release this now. |
| 533 | 548 | unset($profile_areas); |
| 534 | 549 | |
| 535 | 550 | // Now the context is setup have we got any security checks to carry out additional to that above? |
| 536 | - if (isset($security_checks['session'])) |
|
| 537 | - checkSession($security_checks['session']); |
|
| 538 | - if (isset($security_checks['validate'])) |
|
| 539 | - validateSession(); |
|
| 540 | - if (isset($security_checks['validateToken'])) |
|
| 541 | - validateToken($token_name, $token_type); |
|
| 542 | - if (isset($security_checks['permission'])) |
|
| 543 | - isAllowedTo($security_checks['permission']); |
|
| 551 | + if (isset($security_checks['session'])) { |
|
| 552 | + checkSession($security_checks['session']); |
|
| 553 | + } |
|
| 554 | + if (isset($security_checks['validate'])) { |
|
| 555 | + validateSession(); |
|
| 556 | + } |
|
| 557 | + if (isset($security_checks['validateToken'])) { |
|
| 558 | + validateToken($token_name, $token_type); |
|
| 559 | + } |
|
| 560 | + if (isset($security_checks['permission'])) { |
|
| 561 | + isAllowedTo($security_checks['permission']); |
|
| 562 | + } |
|
| 544 | 563 | |
| 545 | 564 | // Create a token if needed. |
| 546 | 565 | if (isset($security_checks['needsToken']) || isset($security_checks['validateToken'])) |
@@ -550,8 +569,9 @@ discard block |
||
| 550 | 569 | } |
| 551 | 570 | |
| 552 | 571 | // File to include? |
| 553 | - if (isset($profile_include_data['file'])) |
|
| 554 | - require_once($sourcedir . '/' . $profile_include_data['file']); |
|
| 572 | + if (isset($profile_include_data['file'])) { |
|
| 573 | + require_once($sourcedir . '/' . $profile_include_data['file']); |
|
| 574 | + } |
|
| 555 | 575 | |
| 556 | 576 | // Build the link tree. |
| 557 | 577 | $context['linktree'][] = array( |
@@ -559,17 +579,19 @@ discard block |
||
| 559 | 579 | 'name' => sprintf($txt['profile_of_username'], $context['member']['name']), |
| 560 | 580 | ); |
| 561 | 581 | |
| 562 | - if (!empty($profile_include_data['label'])) |
|
| 563 | - $context['linktree'][] = array( |
|
| 582 | + if (!empty($profile_include_data['label'])) { |
|
| 583 | + $context['linktree'][] = array( |
|
| 564 | 584 | 'url' => $scripturl . '?action=profile' . ($memID != $user_info['id'] ? ';u=' . $memID : '') . ';area=' . $profile_include_data['current_area'], |
| 565 | 585 | 'name' => $profile_include_data['label'], |
| 566 | 586 | ); |
| 587 | + } |
|
| 567 | 588 | |
| 568 | - if (!empty($profile_include_data['current_subsection']) && $profile_include_data['subsections'][$profile_include_data['current_subsection']][0] != $profile_include_data['label']) |
|
| 569 | - $context['linktree'][] = array( |
|
| 589 | + if (!empty($profile_include_data['current_subsection']) && $profile_include_data['subsections'][$profile_include_data['current_subsection']][0] != $profile_include_data['label']) { |
|
| 590 | + $context['linktree'][] = array( |
|
| 570 | 591 | 'url' => $scripturl . '?action=profile' . ($memID != $user_info['id'] ? ';u=' . $memID : '') . ';area=' . $profile_include_data['current_area'] . ';sa=' . $profile_include_data['current_subsection'], |
| 571 | 592 | 'name' => $profile_include_data['subsections'][$profile_include_data['current_subsection']][0], |
| 572 | 593 | ); |
| 594 | + } |
|
| 573 | 595 | |
| 574 | 596 | // Set the template for this area and add the profile layer. |
| 575 | 597 | $context['sub_template'] = $profile_include_data['function']; |
@@ -595,12 +617,14 @@ discard block |
||
| 595 | 617 | if ($check_password) |
| 596 | 618 | { |
| 597 | 619 | // Check to ensure we're forcing SSL for authentication |
| 598 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) |
|
| 599 | - fatal_lang_error('login_ssl_required'); |
|
| 620 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) { |
|
| 621 | + fatal_lang_error('login_ssl_required'); |
|
| 622 | + } |
|
| 600 | 623 | |
| 601 | 624 | // You didn't even enter a password! |
| 602 | - if (trim($_POST['oldpasswrd']) == '') |
|
| 603 | - $post_errors[] = 'no_password'; |
|
| 625 | + if (trim($_POST['oldpasswrd']) == '') { |
|
| 626 | + $post_errors[] = 'no_password'; |
|
| 627 | + } |
|
| 604 | 628 | |
| 605 | 629 | // Since the password got modified due to all the $_POST cleaning, lets undo it so we can get the correct password |
| 606 | 630 | $_POST['oldpasswrd'] = un_htmlspecialchars($_POST['oldpasswrd']); |
@@ -609,42 +633,43 @@ discard block |
||
| 609 | 633 | $good_password = in_array(true, call_integration_hook('integrate_verify_password', array($cur_profile['member_name'], $_POST['oldpasswrd'], false)), true); |
| 610 | 634 | |
| 611 | 635 | // Bad password!!! |
| 612 | - if (!$good_password && !hash_verify_password($user_profile[$memID]['member_name'], un_htmlspecialchars(stripslashes($_POST['oldpasswrd'])), $user_info['passwd'])) |
|
| 613 | - $post_errors[] = 'bad_password'; |
|
| 636 | + if (!$good_password && !hash_verify_password($user_profile[$memID]['member_name'], un_htmlspecialchars(stripslashes($_POST['oldpasswrd'])), $user_info['passwd'])) { |
|
| 637 | + $post_errors[] = 'bad_password'; |
|
| 638 | + } |
|
| 614 | 639 | |
| 615 | 640 | // Warn other elements not to jump the gun and do custom changes! |
| 616 | - if (in_array('bad_password', $post_errors)) |
|
| 617 | - $context['password_auth_failed'] = true; |
|
| 641 | + if (in_array('bad_password', $post_errors)) { |
|
| 642 | + $context['password_auth_failed'] = true; |
|
| 643 | + } |
|
| 618 | 644 | } |
| 619 | 645 | |
| 620 | 646 | // Change the IP address in the database. |
| 621 | - if ($context['user']['is_owner']) |
|
| 622 | - $profile_vars['member_ip'] = $user_info['ip']; |
|
| 647 | + if ($context['user']['is_owner']) { |
|
| 648 | + $profile_vars['member_ip'] = $user_info['ip']; |
|
| 649 | + } |
|
| 623 | 650 | |
| 624 | 651 | // Now call the sub-action function... |
| 625 | 652 | if ($current_area == 'activateaccount') |
| 626 | 653 | { |
| 627 | - if (empty($post_errors)) |
|
| 628 | - activateAccount($memID); |
|
| 629 | - } |
|
| 630 | - elseif ($current_area == 'deleteaccount') |
|
| 654 | + if (empty($post_errors)) { |
|
| 655 | + activateAccount($memID); |
|
| 656 | + } |
|
| 657 | + } elseif ($current_area == 'deleteaccount') |
|
| 631 | 658 | { |
| 632 | 659 | if (empty($post_errors)) |
| 633 | 660 | { |
| 634 | 661 | deleteAccount2($memID); |
| 635 | 662 | redirectexit(); |
| 636 | 663 | } |
| 637 | - } |
|
| 638 | - elseif ($current_area == 'groupmembership' && empty($post_errors)) |
|
| 664 | + } elseif ($current_area == 'groupmembership' && empty($post_errors)) |
|
| 639 | 665 | { |
| 640 | 666 | $msg = groupMembership2($profile_vars, $post_errors, $memID); |
| 641 | 667 | |
| 642 | 668 | // Whatever we've done, we have nothing else to do here... |
| 643 | 669 | redirectexit('action=profile' . ($context['user']['is_owner'] ? '' : ';u=' . $memID) . ';area=groupmembership' . (!empty($msg) ? ';msg=' . $msg : '')); |
| 644 | - } |
|
| 645 | - elseif (in_array($current_area, array('account', 'forumprofile', 'theme'))) |
|
| 646 | - saveProfileFields(); |
|
| 647 | - else |
|
| 670 | + } elseif (in_array($current_area, array('account', 'forumprofile', 'theme'))) { |
|
| 671 | + saveProfileFields(); |
|
| 672 | + } else |
|
| 648 | 673 | { |
| 649 | 674 | $force_redirect = true; |
| 650 | 675 | // Ensure we include this. |
@@ -660,34 +685,36 @@ discard block |
||
| 660 | 685 | // Load the language file so we can give a nice explanation of the errors. |
| 661 | 686 | loadLanguage('Errors'); |
| 662 | 687 | $context['post_errors'] = $post_errors; |
| 663 | - } |
|
| 664 | - elseif (!empty($profile_vars)) |
|
| 688 | + } elseif (!empty($profile_vars)) |
|
| 665 | 689 | { |
| 666 | 690 | // If we've changed the password, notify any integration that may be listening in. |
| 667 | - if (isset($profile_vars['passwd'])) |
|
| 668 | - call_integration_hook('integrate_reset_pass', array($cur_profile['member_name'], $cur_profile['member_name'], $_POST['passwrd2'])); |
|
| 691 | + if (isset($profile_vars['passwd'])) { |
|
| 692 | + call_integration_hook('integrate_reset_pass', array($cur_profile['member_name'], $cur_profile['member_name'], $_POST['passwrd2'])); |
|
| 693 | + } |
|
| 669 | 694 | |
| 670 | 695 | updateMemberData($memID, $profile_vars); |
| 671 | 696 | |
| 672 | 697 | // What if this is the newest member? |
| 673 | - if ($modSettings['latestMember'] == $memID) |
|
| 674 | - updateStats('member'); |
|
| 675 | - elseif (isset($profile_vars['real_name'])) |
|
| 676 | - updateSettings(array('memberlist_updated' => time())); |
|
| 698 | + if ($modSettings['latestMember'] == $memID) { |
|
| 699 | + updateStats('member'); |
|
| 700 | + } elseif (isset($profile_vars['real_name'])) { |
|
| 701 | + updateSettings(array('memberlist_updated' => time())); |
|
| 702 | + } |
|
| 677 | 703 | |
| 678 | 704 | // If the member changed his/her birthdate, update calendar statistics. |
| 679 | - if (isset($profile_vars['birthdate']) || isset($profile_vars['real_name'])) |
|
| 680 | - updateSettings(array( |
|
| 705 | + if (isset($profile_vars['birthdate']) || isset($profile_vars['real_name'])) { |
|
| 706 | + updateSettings(array( |
|
| 681 | 707 | 'calendar_updated' => time(), |
| 682 | 708 | )); |
| 709 | + } |
|
| 683 | 710 | |
| 684 | 711 | // Anything worth logging? |
| 685 | 712 | if (!empty($context['log_changes']) && !empty($modSettings['modlog_enabled'])) |
| 686 | 713 | { |
| 687 | 714 | $log_changes = array(); |
| 688 | 715 | require_once($sourcedir . '/Logging.php'); |
| 689 | - foreach ($context['log_changes'] as $k => $v) |
|
| 690 | - $log_changes[] = array( |
|
| 716 | + foreach ($context['log_changes'] as $k => $v) { |
|
| 717 | + $log_changes[] = array( |
|
| 691 | 718 | 'action' => $k, |
| 692 | 719 | 'log_type' => 'user', |
| 693 | 720 | 'extra' => array_merge($v, array( |
@@ -695,14 +722,16 @@ discard block |
||
| 695 | 722 | 'member_affected' => $memID, |
| 696 | 723 | )), |
| 697 | 724 | ); |
| 725 | + } |
|
| 698 | 726 | |
| 699 | 727 | logActions($log_changes); |
| 700 | 728 | } |
| 701 | 729 | |
| 702 | 730 | // Have we got any post save functions to execute? |
| 703 | - if (!empty($context['profile_execute_on_save'])) |
|
| 704 | - foreach ($context['profile_execute_on_save'] as $saveFunc) |
|
| 731 | + if (!empty($context['profile_execute_on_save'])) { |
|
| 732 | + foreach ($context['profile_execute_on_save'] as $saveFunc) |
|
| 705 | 733 | $saveFunc(); |
| 734 | + } |
|
| 706 | 735 | |
| 707 | 736 | // Let them know it worked! |
| 708 | 737 | $context['profile_updated'] = $context['user']['is_owner'] ? $txt['profile_updated_own'] : sprintf($txt['profile_updated_else'], $cur_profile['member_name']); |
@@ -716,27 +745,31 @@ discard block |
||
| 716 | 745 | if (!empty($post_errors)) |
| 717 | 746 | { |
| 718 | 747 | // Set all the errors so the template knows what went wrong. |
| 719 | - foreach ($post_errors as $error_type) |
|
| 720 | - $context['modify_error'][$error_type] = true; |
|
| 748 | + foreach ($post_errors as $error_type) { |
|
| 749 | + $context['modify_error'][$error_type] = true; |
|
| 750 | + } |
|
| 721 | 751 | } |
| 722 | 752 | // If it's you then we should redirect upon save. |
| 723 | - elseif (!empty($profile_vars) && $context['user']['is_owner'] && !$context['do_preview']) |
|
| 724 | - redirectexit('action=profile;area=' . $current_area . (!empty($current_sa) ? ';sa=' . $current_sa : '') . ';updated'); |
|
| 725 | - elseif (!empty($force_redirect)) |
|
| 726 | - redirectexit('action=profile' . ($context['user']['is_owner'] ? '' : ';u=' . $memID) . ';area=' . $current_area); |
|
| 753 | + elseif (!empty($profile_vars) && $context['user']['is_owner'] && !$context['do_preview']) { |
|
| 754 | + redirectexit('action=profile;area=' . $current_area . (!empty($current_sa) ? ';sa=' . $current_sa : '') . ';updated'); |
|
| 755 | + } elseif (!empty($force_redirect)) { |
|
| 756 | + redirectexit('action=profile' . ($context['user']['is_owner'] ? '' : ';u=' . $memID) . ';area=' . $current_area); |
|
| 757 | + } |
|
| 727 | 758 | |
| 728 | 759 | |
| 729 | 760 | // Get the right callable. |
| 730 | 761 | $call = call_helper($profile_include_data['function'], true); |
| 731 | 762 | |
| 732 | 763 | // Is it valid? |
| 733 | - if (!empty($call)) |
|
| 734 | - call_user_func($call, $memID); |
|
| 764 | + if (!empty($call)) { |
|
| 765 | + call_user_func($call, $memID); |
|
| 766 | + } |
|
| 735 | 767 | |
| 736 | 768 | // Set the page title if it's not already set... |
| 737 | - if (!isset($context['page_title'])) |
|
| 738 | - $context['page_title'] = $txt['profile'] . (isset($txt[$current_area]) ? ' - ' . $txt[$current_area] : ''); |
|
| 739 | -} |
|
| 769 | + if (!isset($context['page_title'])) { |
|
| 770 | + $context['page_title'] = $txt['profile'] . (isset($txt[$current_area]) ? ' - ' . $txt[$current_area] : ''); |
|
| 771 | + } |
|
| 772 | + } |
|
| 740 | 773 | |
| 741 | 774 | /** |
| 742 | 775 | * Set up the requirements for the profile popup - the area that is shown as the popup menu for the current user. |
@@ -859,16 +892,18 @@ discard block |
||
| 859 | 892 | if (!allowedTo('admin_forum') && $area != 'register') |
| 860 | 893 | { |
| 861 | 894 | // If it's the owner they can see two types of private fields, regardless. |
| 862 | - if ($memID == $user_info['id']) |
|
| 863 | - $where .= $area == 'summary' ? ' AND private < 3' : ' AND (private = 0 OR private = 2)'; |
|
| 864 | - else |
|
| 865 | - $where .= $area == 'summary' ? ' AND private < 2' : ' AND private = 0'; |
|
| 895 | + if ($memID == $user_info['id']) { |
|
| 896 | + $where .= $area == 'summary' ? ' AND private < 3' : ' AND (private = 0 OR private = 2)'; |
|
| 897 | + } else { |
|
| 898 | + $where .= $area == 'summary' ? ' AND private < 2' : ' AND private = 0'; |
|
| 899 | + } |
|
| 866 | 900 | } |
| 867 | 901 | |
| 868 | - if ($area == 'register') |
|
| 869 | - $where .= ' AND show_reg != 0'; |
|
| 870 | - elseif ($area != 'summary') |
|
| 871 | - $where .= ' AND show_profile = {string:area}'; |
|
| 902 | + if ($area == 'register') { |
|
| 903 | + $where .= ' AND show_reg != 0'; |
|
| 904 | + } elseif ($area != 'summary') { |
|
| 905 | + $where .= ' AND show_profile = {string:area}'; |
|
| 906 | + } |
|
| 872 | 907 | |
| 873 | 908 | // Load all the relevant fields - and data. |
| 874 | 909 | $request = $smcFunc['db_query']('', ' |
@@ -894,13 +929,15 @@ discard block |
||
| 894 | 929 | if (isset($_POST['customfield']) && isset($_POST['customfield'][$row['col_name']])) |
| 895 | 930 | { |
| 896 | 931 | $value = $smcFunc['htmlspecialchars']($_POST['customfield'][$row['col_name']]); |
| 897 | - if (in_array($row['field_type'], array('select', 'radio'))) |
|
| 898 | - $value = ($options = explode(',', $row['field_options'])) && isset($options[$value]) ? $options[$value] : ''; |
|
| 932 | + if (in_array($row['field_type'], array('select', 'radio'))) { |
|
| 933 | + $value = ($options = explode(',', $row['field_options'])) && isset($options[$value]) ? $options[$value] : ''; |
|
| 934 | + } |
|
| 899 | 935 | } |
| 900 | 936 | |
| 901 | 937 | // Don't show the "disabled" option for the "gender" field if we are on the "summary" area. |
| 902 | - if ($area == 'summary' && $row['col_name'] == 'cust_gender' && $value == 'None') |
|
| 903 | - continue; |
|
| 938 | + if ($area == 'summary' && $row['col_name'] == 'cust_gender' && $value == 'None') { |
|
| 939 | + continue; |
|
| 940 | + } |
|
| 904 | 941 | |
| 905 | 942 | // HTML for the input form. |
| 906 | 943 | $output_html = $value; |
@@ -909,8 +946,7 @@ discard block |
||
| 909 | 946 | $true = (!$exists && $row['default_value']) || $value; |
| 910 | 947 | $input_html = '<input type="checkbox" name="customfield[' . $row['col_name'] . ']" id="customfield[' . $row['col_name'] . ']"' . ($true ? ' checked' : '') . '>'; |
| 911 | 948 | $output_html = $true ? $txt['yes'] : $txt['no']; |
| 912 | - } |
|
| 913 | - elseif ($row['field_type'] == 'select') |
|
| 949 | + } elseif ($row['field_type'] == 'select') |
|
| 914 | 950 | { |
| 915 | 951 | $input_html = '<select name="customfield[' . $row['col_name'] . ']" id="customfield[' . $row['col_name'] . ']"><option value="-1"></option>'; |
| 916 | 952 | $options = explode(',', $row['field_options']); |
@@ -918,13 +954,13 @@ discard block |
||
| 918 | 954 | { |
| 919 | 955 | $true = (!$exists && $row['default_value'] == $v) || $value == $v; |
| 920 | 956 | $input_html .= '<option value="' . $k . '"' . ($true ? ' selected' : '') . '>' . $v . '</option>'; |
| 921 | - if ($true) |
|
| 922 | - $output_html = $v; |
|
| 957 | + if ($true) { |
|
| 958 | + $output_html = $v; |
|
| 959 | + } |
|
| 923 | 960 | } |
| 924 | 961 | |
| 925 | 962 | $input_html .= '</select>'; |
| 926 | - } |
|
| 927 | - elseif ($row['field_type'] == 'radio') |
|
| 963 | + } elseif ($row['field_type'] == 'radio') |
|
| 928 | 964 | { |
| 929 | 965 | $input_html = '<fieldset>'; |
| 930 | 966 | $options = explode(',', $row['field_options']); |
@@ -932,36 +968,37 @@ discard block |
||
| 932 | 968 | { |
| 933 | 969 | $true = (!$exists && $row['default_value'] == $v) || $value == $v; |
| 934 | 970 | $input_html .= '<label for="customfield_' . $row['col_name'] . '_' . $k . '"><input type="radio" name="customfield[' . $row['col_name'] . ']" id="customfield_' . $row['col_name'] . '_' . $k . '" value="' . $k . '"' . ($true ? ' checked' : '') . '>' . $v . '</label><br>'; |
| 935 | - if ($true) |
|
| 936 | - $output_html = $v; |
|
| 971 | + if ($true) { |
|
| 972 | + $output_html = $v; |
|
| 973 | + } |
|
| 937 | 974 | } |
| 938 | 975 | $input_html .= '</fieldset>'; |
| 939 | - } |
|
| 940 | - elseif ($row['field_type'] == 'text') |
|
| 976 | + } elseif ($row['field_type'] == 'text') |
|
| 941 | 977 | { |
| 942 | 978 | $input_html = '<input type="text" name="customfield[' . $row['col_name'] . ']" id="customfield[' . $row['col_name'] . ']"' . ($row['field_length'] != 0 ? ' maxlength="' . $row['field_length'] . '"' : '') . ' size="' . ($row['field_length'] == 0 || $row['field_length'] >= 50 ? 50 : ($row['field_length'] > 30 ? 30 : ($row['field_length'] > 10 ? 20 : 10))) . '" value="' . un_htmlspecialchars($value) . '"' . ($row['show_reg'] == 2 ? ' required' : '') . '>'; |
| 943 | - } |
|
| 944 | - else |
|
| 979 | + } else |
|
| 945 | 980 | { |
| 946 | 981 | @list ($rows, $cols) = @explode(',', $row['default_value']); |
| 947 | 982 | $input_html = '<textarea name="customfield[' . $row['col_name'] . ']" id="customfield[' . $row['col_name'] . ']"' . (!empty($rows) ? ' rows="' . $rows . '"' : '') . (!empty($cols) ? ' cols="' . $cols . '"' : '') . ($row['show_reg'] == 2 ? ' required' : '') . '>' . un_htmlspecialchars($value) . '</textarea>'; |
| 948 | 983 | } |
| 949 | 984 | |
| 950 | 985 | // Parse BBCode |
| 951 | - if ($row['bbc']) |
|
| 952 | - $output_html = parse_bbc($output_html); |
|
| 953 | - elseif ($row['field_type'] == 'textarea') |
|
| 954 | - // Allow for newlines at least |
|
| 986 | + if ($row['bbc']) { |
|
| 987 | + $output_html = parse_bbc($output_html); |
|
| 988 | + } elseif ($row['field_type'] == 'textarea') { |
|
| 989 | + // Allow for newlines at least |
|
| 955 | 990 | $output_html = strtr($output_html, array("\n" => '<br>')); |
| 991 | + } |
|
| 956 | 992 | |
| 957 | 993 | // Enclosing the user input within some other text? |
| 958 | - if (!empty($row['enclose']) && !empty($output_html)) |
|
| 959 | - $output_html = strtr($row['enclose'], array( |
|
| 994 | + if (!empty($row['enclose']) && !empty($output_html)) { |
|
| 995 | + $output_html = strtr($row['enclose'], array( |
|
| 960 | 996 | '{SCRIPTURL}' => $scripturl, |
| 961 | 997 | '{IMAGES_URL}' => $settings['images_url'], |
| 962 | 998 | '{DEFAULT_IMAGES_URL}' => $settings['default_images_url'], |
| 963 | 999 | '{INPUT}' => un_htmlspecialchars($output_html), |
| 964 | 1000 | )); |
| 1001 | + } |
|
| 965 | 1002 | |
| 966 | 1003 | $context['custom_fields'][] = array( |
| 967 | 1004 | 'name' => $row['field_name'], |
@@ -186,8 +186,9 @@ discard block |
||
| 186 | 186 | |
| 187 | 187 | ########## Error-Catching ########## |
| 188 | 188 | # Note: You shouldn't touch these settings. |
| 189 | -if (file_exists(dirname(__FILE__) . '/db_last_error.php')) |
|
| 189 | +if (file_exists(dirname(__FILE__) . '/db_last_error.php')) { |
|
| 190 | 190 | include(dirname(__FILE__) . '/db_last_error.php'); |
| 191 | +} |
|
| 191 | 192 | |
| 192 | 193 | if (!isset($db_last_error)) |
| 193 | 194 | { |
@@ -199,20 +200,24 @@ discard block |
||
| 199 | 200 | if (file_exists(dirname(__FILE__) . '/install.php')) |
| 200 | 201 | { |
| 201 | 202 | $secure = false; |
| 202 | - if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') |
|
| 203 | - $secure = true; |
|
| 204 | - 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') |
|
| 205 | - $secure = true; |
|
| 203 | + if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { |
|
| 204 | + $secure = true; |
|
| 205 | + } 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') { |
|
| 206 | + $secure = true; |
|
| 207 | + } |
|
| 206 | 208 | |
| 207 | 209 | header('Location: http' . ($secure ? 's' : '') . '://' . (empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST']) . (strtr(dirname($_SERVER['PHP_SELF']), '\\', '/') == '/' ? '' : strtr(dirname($_SERVER['PHP_SELF']), '\\', '/')) . '/install.php'); exit; |
| 208 | 210 | } |
| 209 | 211 | |
| 210 | 212 | # Make sure the paths are correct... at least try to fix them. |
| 211 | -if (!file_exists($boarddir) && file_exists(dirname(__FILE__) . '/agreement.txt')) |
|
| 213 | +if (!file_exists($boarddir) && file_exists(dirname(__FILE__) . '/agreement.txt')) { |
|
| 212 | 214 | $boarddir = dirname(__FILE__); |
| 213 | -if (!file_exists($sourcedir) && file_exists($boarddir . '/Sources')) |
|
| 215 | +} |
|
| 216 | +if (!file_exists($sourcedir) && file_exists($boarddir . '/Sources')) { |
|
| 214 | 217 | $sourcedir = $boarddir . '/Sources'; |
| 215 | -if (!file_exists($cachedir) && file_exists($boarddir . '/cache')) |
|
| 218 | +} |
|
| 219 | +if (!file_exists($cachedir) && file_exists($boarddir . '/cache')) { |
|
| 216 | 220 | $cachedir = $boarddir . '/cache'; |
| 221 | +} |
|
| 217 | 222 | |
| 218 | 223 | ?> |
| 219 | 224 | \ No newline at end of file |
@@ -27,9 +27,10 @@ discard block |
||
| 27 | 27 | <h3 class="catbg"> |
| 28 | 28 | <span class="floatleft">', $txt['members_list'], '</span>'; |
| 29 | 29 | |
| 30 | - if (!isset($context['old_search'])) |
|
| 31 | - echo ' |
|
| 30 | + if (!isset($context['old_search'])) { |
|
| 31 | + echo ' |
|
| 32 | 32 | <span class="floatright">', $context['letter_links'], '</span>'; |
| 33 | + } |
|
| 33 | 34 | echo ' |
| 34 | 35 | </h3> |
| 35 | 36 | </div>'; |
@@ -44,20 +45,23 @@ discard block |
||
| 44 | 45 | foreach ($context['columns'] as $key => $column) |
| 45 | 46 | { |
| 46 | 47 | // @TODO maybe find something nicer? |
| 47 | - if ($key == 'email_address' && !$context['can_send_email']) |
|
| 48 | - continue; |
|
| 48 | + if ($key == 'email_address' && !$context['can_send_email']) { |
|
| 49 | + continue; |
|
| 50 | + } |
|
| 49 | 51 | |
| 50 | 52 | // This is a selected column, so underline it or some such. |
| 51 | - if ($column['selected']) |
|
| 52 | - echo ' |
|
| 53 | + if ($column['selected']) { |
|
| 54 | + echo ' |
|
| 53 | 55 | <th scope="col" class="', $key, isset($column['class']) ? ' ' . $column['class'] : '', ' selected" style="width: auto;"' . (isset($column['colspan']) ? ' colspan="' . $column['colspan'] . '"' : '') . '> |
| 54 | 56 | <a href="' . $column['href'] . '" rel="nofollow">' . $column['label'] . '</a><span class="generic_icons sort_' . $context['sort_direction'] . '"></span></th>'; |
| 57 | + } |
|
| 55 | 58 | |
| 56 | 59 | // This is just some column... show the link and be done with it. |
| 57 | - else |
|
| 58 | - echo ' |
|
| 60 | + else { |
|
| 61 | + echo ' |
|
| 59 | 62 | <th scope="col" class="', $key, isset($column['class']) ? ' ' . $column['class'] : '', '"', isset($column['width']) ? ' style="width: ' . $column['width'] . '"' : '', isset($column['colspan']) ? ' colspan="' . $column['colspan'] . '"' : '', '> |
| 60 | 63 | ', $column['link'], '</th>'; |
| 64 | + } |
|
| 61 | 65 | } |
| 62 | 66 | |
| 63 | 67 | echo ' |
@@ -77,9 +81,10 @@ discard block |
||
| 77 | 81 | </td> |
| 78 | 82 | <td class="lefttext">', $member['link'], '</td>'; |
| 79 | 83 | |
| 80 | - if (!isset($context['disabled_fields']['website'])) |
|
| 81 | - echo ' |
|
| 84 | + if (!isset($context['disabled_fields']['website'])) { |
|
| 85 | + echo ' |
|
| 82 | 86 | <td class="centertext website_url">', $member['website']['url'] != '' ? '<a href="' . $member['website']['url'] . '" target="_blank" rel="noopener"><span class="generic_icons www" title="' . $member['website']['title'] . '"></span></a>' : '', '</td>'; |
| 87 | + } |
|
| 83 | 88 | |
| 84 | 89 | // Group and date. |
| 85 | 90 | echo ' |
@@ -92,32 +97,35 @@ discard block |
||
| 92 | 97 | <td class="centertext" style="white-space: nowrap; width: 15px">', $member['posts'], '</td> |
| 93 | 98 | <td class="centertext statsbar" style="width: 120px">'; |
| 94 | 99 | |
| 95 | - if (!empty($member['post_percent'])) |
|
| 96 | - echo ' |
|
| 100 | + if (!empty($member['post_percent'])) { |
|
| 101 | + echo ' |
|
| 97 | 102 | <div class="bar" style="width: ', $member['post_percent'] + 4, 'px;"> |
| 98 | 103 | <div style="width: ', $member['post_percent'], 'px;"></div> |
| 99 | 104 | </div>'; |
| 105 | + } |
|
| 100 | 106 | |
| 101 | 107 | echo ' |
| 102 | 108 | </td>'; |
| 103 | 109 | } |
| 104 | 110 | |
| 105 | 111 | // Show custom fields marked to be shown here |
| 106 | - if (!empty($context['custom_profile_fields']['columns'])) |
|
| 107 | - foreach ($context['custom_profile_fields']['columns'] as $key => $column) |
|
| 112 | + if (!empty($context['custom_profile_fields']['columns'])) { |
|
| 113 | + foreach ($context['custom_profile_fields']['columns'] as $key => $column) |
|
| 108 | 114 | echo ' |
| 109 | 115 | <td class="righttext">', $member['options'][$key], '</td>'; |
| 116 | + } |
|
| 110 | 117 | |
| 111 | 118 | echo ' |
| 112 | 119 | </tr>'; |
| 113 | 120 | } |
| 114 | 121 | } |
| 115 | 122 | // No members? |
| 116 | - else |
|
| 117 | - echo ' |
|
| 123 | + else { |
|
| 124 | + echo ' |
|
| 118 | 125 | <tr> |
| 119 | 126 | <td colspan="', $context['colspan'], '" class="windowbg">', $txt['search_no_results'], '</td> |
| 120 | 127 | </tr>'; |
| 128 | + } |
|
| 121 | 129 | |
| 122 | 130 | echo ' |
| 123 | 131 | </tbody> |
@@ -130,11 +138,12 @@ discard block |
||
| 130 | 138 | <div class="pagelinks floatleft">', $context['page_index'], '</div>'; |
| 131 | 139 | |
| 132 | 140 | // If it is displaying the result of a search show a "search again" link to edit their criteria. |
| 133 | - if (isset($context['old_search'])) |
|
| 134 | - echo ' |
|
| 141 | + if (isset($context['old_search'])) { |
|
| 142 | + echo ' |
|
| 135 | 143 | <div class="buttonlist floatright"> |
| 136 | 144 | <a class="button" href="', $scripturl, '?action=mlist;sa=search;search=', $context['old_search_value'], '">', $txt['mlist_search_again'], '</a> |
| 137 | 145 | </div>'; |
| 146 | + } |
|
| 138 | 147 | echo ' |
| 139 | 148 | </div> |
| 140 | 149 | </div><!-- #memberlist -->'; |
@@ -174,12 +183,13 @@ discard block |
||
| 174 | 183 | <dd> |
| 175 | 184 | <ul>'; |
| 176 | 185 | |
| 177 | - foreach ($context['search_fields'] as $id => $title) |
|
| 178 | - echo ' |
|
| 186 | + foreach ($context['search_fields'] as $id => $title) { |
|
| 187 | + echo ' |
|
| 179 | 188 | <li> |
| 180 | 189 | <input type="checkbox" name="fields[]" id="fields-', $id, '" value="', $id, '"', in_array($id, $context['search_defaults']) ? ' checked' : '', '> |
| 181 | 190 | <label for="fields-', $id, '">', $title, '</label> |
| 182 | 191 | </li>'; |
| 192 | + } |
|
| 183 | 193 | |
| 184 | 194 | echo ' |
| 185 | 195 | </ul> |