@@ -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'); |
@@ -98,23 +102,26 @@ discard block |
||
| 98 | 102 | if (isset($_GET['sa']) && $_GET['sa'] == 'salt' && !$user_info['is_guest']) |
| 99 | 103 | { |
| 100 | 104 | // First check for 2.1 json-format cookie in $_COOKIE |
| 101 | - if (isset($_COOKIE[$cookiename]) && preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+~', $_COOKIE[$cookiename]) === 1) |
|
| 102 | - list (,, $timeout) = $smcFunc['json_decode']($_COOKIE[$cookiename], true); |
|
| 105 | + if (isset($_COOKIE[$cookiename]) && preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+~', $_COOKIE[$cookiename]) === 1) { |
|
| 106 | + list (,, $timeout) = $smcFunc['json_decode']($_COOKIE[$cookiename], true); |
|
| 107 | + } |
|
| 103 | 108 | |
| 104 | 109 | // Try checking for 2.1 json-format cookie in $_SESSION |
| 105 | - elseif (isset($_SESSION['login_' . $cookiename]) && preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+~', $_SESSION['login_' . $cookiename]) === 1) |
|
| 106 | - list (,, $timeout) = $smcFunc['json_decode']($_SESSION['login_' . $cookiename]); |
|
| 110 | + elseif (isset($_SESSION['login_' . $cookiename]) && preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+~', $_SESSION['login_' . $cookiename]) === 1) { |
|
| 111 | + list (,, $timeout) = $smcFunc['json_decode']($_SESSION['login_' . $cookiename]); |
|
| 112 | + } |
|
| 107 | 113 | |
| 108 | 114 | // Next, try checking for 2.0 serialized string cookie in $_COOKIE |
| 109 | - elseif (isset($_COOKIE[$cookiename]) && preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;~', $_COOKIE[$cookiename]) === 1) |
|
| 110 | - list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]); |
|
| 115 | + elseif (isset($_COOKIE[$cookiename]) && preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;~', $_COOKIE[$cookiename]) === 1) { |
|
| 116 | + list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]); |
|
| 117 | + } |
|
| 111 | 118 | |
| 112 | 119 | // Last, see if you need to fall back on checking for 2.0 serialized string cookie in $_SESSION |
| 113 | - elseif (isset($_SESSION['login_' . $cookiename]) && preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;~', $_SESSION['login_' . $cookiename]) === 1) |
|
| 114 | - list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]); |
|
| 115 | - |
|
| 116 | - else |
|
| 117 | - trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR); |
|
| 120 | + elseif (isset($_SESSION['login_' . $cookiename]) && preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;~', $_SESSION['login_' . $cookiename]) === 1) { |
|
| 121 | + list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]); |
|
| 122 | + } else { |
|
| 123 | + trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR); |
|
| 124 | + } |
|
| 118 | 125 | |
| 119 | 126 | $user_settings['password_salt'] = substr(md5(mt_rand()), 0, 4); |
| 120 | 127 | updateMemberData($user_info['id'], array('password_salt' => $user_settings['password_salt'])); |
@@ -134,24 +141,23 @@ discard block |
||
| 134 | 141 | elseif (isset($_GET['sa']) && $_GET['sa'] == 'check') |
| 135 | 142 | { |
| 136 | 143 | // Strike! You're outta there! |
| 137 | - if ($_GET['member'] != $user_info['id']) |
|
| 138 | - fatal_lang_error('login_cookie_error', false); |
|
| 144 | + if ($_GET['member'] != $user_info['id']) { |
|
| 145 | + fatal_lang_error('login_cookie_error', false); |
|
| 146 | + } |
|
| 139 | 147 | |
| 140 | 148 | $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'])))); |
| 141 | 149 | |
| 142 | 150 | // Some whitelisting for login_url... |
| 143 | - if (empty($_SESSION['login_url'])) |
|
| 144 | - redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa'); |
|
| 145 | - elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false)) |
|
| 151 | + if (empty($_SESSION['login_url'])) { |
|
| 152 | + redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa'); |
|
| 153 | + } elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false)) |
|
| 146 | 154 | { |
| 147 | 155 | unset ($_SESSION['login_url']); |
| 148 | 156 | redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa'); |
| 149 | - } |
|
| 150 | - elseif (!empty($user_settings['tfa_secret'])) |
|
| 157 | + } elseif (!empty($user_settings['tfa_secret'])) |
|
| 151 | 158 | { |
| 152 | 159 | redirectexit('action=logintfa'); |
| 153 | - } |
|
| 154 | - else |
|
| 160 | + } else |
|
| 155 | 161 | { |
| 156 | 162 | // Best not to clutter the session data too much... |
| 157 | 163 | $temp = $_SESSION['login_url']; |
@@ -162,8 +168,9 @@ discard block |
||
| 162 | 168 | } |
| 163 | 169 | |
| 164 | 170 | // Beyond this point you are assumed to be a guest trying to login. |
| 165 | - if (!$user_info['is_guest']) |
|
| 166 | - redirectexit(); |
|
| 171 | + if (!$user_info['is_guest']) { |
|
| 172 | + redirectexit(); |
|
| 173 | + } |
|
| 167 | 174 | |
| 168 | 175 | // Are you guessing with a script? |
| 169 | 176 | checkSession(); |
@@ -171,18 +178,21 @@ discard block |
||
| 171 | 178 | spamProtection('login'); |
| 172 | 179 | |
| 173 | 180 | // Set the login_url if it's not already set (but careful not to send us to an attachment). |
| 174 | - 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)) |
|
| 175 | - $_SESSION['login_url'] = $_SESSION['old_url']; |
|
| 181 | + 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)) { |
|
| 182 | + $_SESSION['login_url'] = $_SESSION['old_url']; |
|
| 183 | + } |
|
| 176 | 184 | |
| 177 | 185 | // Been guessing a lot, haven't we? |
| 178 | - if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3) |
|
| 179 | - fatal_lang_error('login_threshold_fail', 'login'); |
|
| 186 | + if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3) { |
|
| 187 | + fatal_lang_error('login_threshold_fail', 'login'); |
|
| 188 | + } |
|
| 180 | 189 | |
| 181 | 190 | // Set up the cookie length. (if it's invalid, just fall through and use the default.) |
| 182 | - if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1)) |
|
| 183 | - $modSettings['cookieTime'] = 3153600; |
|
| 184 | - elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 525600)) |
|
| 185 | - $modSettings['cookieTime'] = (int) $_POST['cookielength']; |
|
| 191 | + if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1)) { |
|
| 192 | + $modSettings['cookieTime'] = 3153600; |
|
| 193 | + } elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 525600)) { |
|
| 194 | + $modSettings['cookieTime'] = (int) $_POST['cookielength']; |
|
| 195 | + } |
|
| 186 | 196 | |
| 187 | 197 | loadLanguage('Login'); |
| 188 | 198 | // Load the template stuff. |
@@ -302,8 +312,9 @@ discard block |
||
| 302 | 312 | $other_passwords[] = crypt(md5($_POST['passwrd']), md5($_POST['passwrd'])); |
| 303 | 313 | |
| 304 | 314 | // Snitz style - SHA-256. Technically, this is a downgrade, but most PHP configurations don't support sha256 anyway. |
| 305 | - if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256')) |
|
| 306 | - $other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd'])); |
|
| 315 | + if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256')) { |
|
| 316 | + $other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd'])); |
|
| 317 | + } |
|
| 307 | 318 | |
| 308 | 319 | // phpBB3 users new hashing. We now support it as well ;). |
| 309 | 320 | $other_passwords[] = phpBB3_password_check($_POST['passwrd'], $user_settings['passwd']); |
@@ -323,27 +334,29 @@ discard block |
||
| 323 | 334 | // Some common md5 ones. |
| 324 | 335 | $other_passwords[] = md5($user_settings['password_salt'] . $_POST['passwrd']); |
| 325 | 336 | $other_passwords[] = md5($_POST['passwrd'] . $user_settings['password_salt']); |
| 326 | - } |
|
| 327 | - elseif (strlen($user_settings['passwd']) == 40) |
|
| 337 | + } elseif (strlen($user_settings['passwd']) == 40) |
|
| 328 | 338 | { |
| 329 | 339 | // Maybe they are using a hash from before the password fix. |
| 330 | 340 | // This is also valid for SMF 1.1 to 2.0 style of hashing, changed to bcrypt in SMF 2.1 |
| 331 | 341 | $other_passwords[] = sha1(strtolower($user_settings['member_name']) . un_htmlspecialchars($_POST['passwrd'])); |
| 332 | 342 | |
| 333 | 343 | // BurningBoard3 style of hashing. |
| 334 | - if (!empty($modSettings['enable_password_conversion'])) |
|
| 335 | - $other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd']))); |
|
| 344 | + if (!empty($modSettings['enable_password_conversion'])) { |
|
| 345 | + $other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd']))); |
|
| 346 | + } |
|
| 336 | 347 | |
| 337 | 348 | // Perhaps we converted to UTF-8 and have a valid password being hashed differently. |
| 338 | 349 | if ($context['character_set'] == 'UTF-8' && !empty($modSettings['previousCharacterSet']) && $modSettings['previousCharacterSet'] != 'utf8') |
| 339 | 350 | { |
| 340 | 351 | // Try iconv first, for no particular reason. |
| 341 | - if (function_exists('iconv')) |
|
| 342 | - $other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd']))); |
|
| 352 | + if (function_exists('iconv')) { |
|
| 353 | + $other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd']))); |
|
| 354 | + } |
|
| 343 | 355 | |
| 344 | 356 | // Say it aint so, iconv failed! |
| 345 | - if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding')) |
|
| 346 | - $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']))); |
|
| 357 | + if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding')) { |
|
| 358 | + $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']))); |
|
| 359 | + } |
|
| 347 | 360 | } |
| 348 | 361 | } |
| 349 | 362 | |
@@ -373,8 +386,9 @@ discard block |
||
| 373 | 386 | $_SESSION['failed_login'] = isset($_SESSION['failed_login']) ? ($_SESSION['failed_login'] + 1) : 1; |
| 374 | 387 | |
| 375 | 388 | // Hmm... don't remember it, do you? Here, try the password reminder ;). |
| 376 | - if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold']) |
|
| 377 | - redirectexit('action=reminder'); |
|
| 389 | + if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold']) { |
|
| 390 | + redirectexit('action=reminder'); |
|
| 391 | + } |
|
| 378 | 392 | // We'll give you another chance... |
| 379 | 393 | else |
| 380 | 394 | { |
@@ -385,8 +399,7 @@ discard block |
||
| 385 | 399 | return; |
| 386 | 400 | } |
| 387 | 401 | } |
| 388 | - } |
|
| 389 | - elseif (!empty($user_settings['passwd_flood'])) |
|
| 402 | + } elseif (!empty($user_settings['passwd_flood'])) |
|
| 390 | 403 | { |
| 391 | 404 | // Let's be sure they weren't a little hacker. |
| 392 | 405 | validatePasswordFlood($user_settings['id_member'], $user_settings['member_name'], $user_settings['passwd_flood'], true); |
@@ -403,8 +416,9 @@ discard block |
||
| 403 | 416 | } |
| 404 | 417 | |
| 405 | 418 | // Check their activation status. |
| 406 | - if (!checkActivation()) |
|
| 407 | - return; |
|
| 419 | + if (!checkActivation()) { |
|
| 420 | + return; |
|
| 421 | + } |
|
| 408 | 422 | |
| 409 | 423 | DoLogin(); |
| 410 | 424 | } |
@@ -416,8 +430,9 @@ discard block |
||
| 416 | 430 | { |
| 417 | 431 | global $sourcedir, $txt, $context, $user_info, $modSettings, $scripturl; |
| 418 | 432 | |
| 419 | - if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode'])) |
|
| 420 | - fatal_lang_error('no_access', false); |
|
| 433 | + if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode'])) { |
|
| 434 | + fatal_lang_error('no_access', false); |
|
| 435 | + } |
|
| 421 | 436 | |
| 422 | 437 | loadLanguage('Profile'); |
| 423 | 438 | require_once($sourcedir . '/Class-TOTP.php'); |
@@ -425,8 +440,9 @@ discard block |
||
| 425 | 440 | $member = $context['tfa_member']; |
| 426 | 441 | |
| 427 | 442 | // Prevent replay attacks by limiting at least 2 minutes before they can log in again via 2FA |
| 428 | - if (time() - $member['last_login'] < 120) |
|
| 429 | - fatal_lang_error('tfa_wait', false); |
|
| 443 | + if (time() - $member['last_login'] < 120) { |
|
| 444 | + fatal_lang_error('tfa_wait', false); |
|
| 445 | + } |
|
| 430 | 446 | |
| 431 | 447 | $totp = new \TOTP\Auth($member['tfa_secret']); |
| 432 | 448 | $totp->setRange(1); |
@@ -440,8 +456,9 @@ discard block |
||
| 440 | 456 | if (!empty($_POST['tfa_code']) && empty($_POST['tfa_backup'])) |
| 441 | 457 | { |
| 442 | 458 | // Check to ensure we're forcing SSL for authentication |
| 443 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) |
|
| 444 | - fatal_lang_error('login_ssl_required'); |
|
| 459 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) { |
|
| 460 | + fatal_lang_error('login_ssl_required'); |
|
| 461 | + } |
|
| 445 | 462 | |
| 446 | 463 | $code = $_POST['tfa_code']; |
| 447 | 464 | |
@@ -451,20 +468,19 @@ discard block |
||
| 451 | 468 | |
| 452 | 469 | setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt'])); |
| 453 | 470 | redirectexit(); |
| 454 | - } |
|
| 455 | - else |
|
| 471 | + } else |
|
| 456 | 472 | { |
| 457 | 473 | validatePasswordFlood($member['id_member'], $member['member_name'], $member['passwd_flood'], false, true); |
| 458 | 474 | |
| 459 | 475 | $context['tfa_error'] = true; |
| 460 | 476 | $context['tfa_value'] = $_POST['tfa_code']; |
| 461 | 477 | } |
| 462 | - } |
|
| 463 | - elseif (!empty($_POST['tfa_backup'])) |
|
| 478 | + } elseif (!empty($_POST['tfa_backup'])) |
|
| 464 | 479 | { |
| 465 | 480 | // Check to ensure we're forcing SSL for authentication |
| 466 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) |
|
| 467 | - fatal_lang_error('login_ssl_required'); |
|
| 481 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) { |
|
| 482 | + fatal_lang_error('login_ssl_required'); |
|
| 483 | + } |
|
| 468 | 484 | |
| 469 | 485 | $backup = $_POST['tfa_backup']; |
| 470 | 486 | |
@@ -478,8 +494,7 @@ discard block |
||
| 478 | 494 | )); |
| 479 | 495 | setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt'])); |
| 480 | 496 | redirectexit('action=profile;area=tfasetup;backup'); |
| 481 | - } |
|
| 482 | - else |
|
| 497 | + } else |
|
| 483 | 498 | { |
| 484 | 499 | validatePasswordFlood($member['id_member'], $member['member_name'], $member['passwd_flood'], false, true); |
| 485 | 500 | |
@@ -502,8 +517,9 @@ discard block |
||
| 502 | 517 | { |
| 503 | 518 | global $context, $txt, $scripturl, $user_settings, $modSettings; |
| 504 | 519 | |
| 505 | - if (!isset($context['login_errors'])) |
|
| 506 | - $context['login_errors'] = array(); |
|
| 520 | + if (!isset($context['login_errors'])) { |
|
| 521 | + $context['login_errors'] = array(); |
|
| 522 | + } |
|
| 507 | 523 | |
| 508 | 524 | // What is the true activation status of this account? |
| 509 | 525 | $activation_status = $user_settings['is_activated'] > 10 ? $user_settings['is_activated'] - 10 : $user_settings['is_activated']; |
@@ -515,8 +531,9 @@ discard block |
||
| 515 | 531 | return false; |
| 516 | 532 | } |
| 517 | 533 | // Awaiting approval still? |
| 518 | - elseif ($activation_status == 3) |
|
| 519 | - fatal_lang_error('still_awaiting_approval', 'user'); |
|
| 534 | + elseif ($activation_status == 3) { |
|
| 535 | + fatal_lang_error('still_awaiting_approval', 'user'); |
|
| 536 | + } |
|
| 520 | 537 | // Awaiting deletion, changed their mind? |
| 521 | 538 | elseif ($activation_status == 4) |
| 522 | 539 | { |
@@ -524,8 +541,7 @@ discard block |
||
| 524 | 541 | { |
| 525 | 542 | updateMemberData($user_settings['id_member'], array('is_activated' => 1)); |
| 526 | 543 | updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 0 ? $modSettings['unapprovedMembers'] - 1 : 0))); |
| 527 | - } |
|
| 528 | - else |
|
| 544 | + } else |
|
| 529 | 545 | { |
| 530 | 546 | $context['disable_login_hashing'] = true; |
| 531 | 547 | $context['login_errors'][] = $txt['awaiting_delete_account']; |
@@ -565,8 +581,9 @@ discard block |
||
| 565 | 581 | setLoginCookie(60 * $modSettings['cookieTime'], $user_settings['id_member'], hash_salt($user_settings['passwd'], $user_settings['password_salt'])); |
| 566 | 582 | |
| 567 | 583 | // Reset the login threshold. |
| 568 | - if (isset($_SESSION['failed_login'])) |
|
| 569 | - unset($_SESSION['failed_login']); |
|
| 584 | + if (isset($_SESSION['failed_login'])) { |
|
| 585 | + unset($_SESSION['failed_login']); |
|
| 586 | + } |
|
| 570 | 587 | |
| 571 | 588 | $user_info['is_guest'] = false; |
| 572 | 589 | $user_settings['additional_groups'] = explode(',', $user_settings['additional_groups']); |
@@ -588,16 +605,18 @@ discard block |
||
| 588 | 605 | 'id_member' => $user_info['id'], |
| 589 | 606 | ) |
| 590 | 607 | ); |
| 591 | - if ($smcFunc['db_num_rows']($request) == 1) |
|
| 592 | - $_SESSION['first_login'] = true; |
|
| 593 | - else |
|
| 594 | - unset($_SESSION['first_login']); |
|
| 608 | + if ($smcFunc['db_num_rows']($request) == 1) { |
|
| 609 | + $_SESSION['first_login'] = true; |
|
| 610 | + } else { |
|
| 611 | + unset($_SESSION['first_login']); |
|
| 612 | + } |
|
| 595 | 613 | $smcFunc['db_free_result']($request); |
| 596 | 614 | |
| 597 | 615 | // You've logged in, haven't you? |
| 598 | 616 | $update = array('member_ip' => $user_info['ip'], 'member_ip2' => $_SERVER['BAN_CHECK_IP']); |
| 599 | - if (empty($user_settings['tfa_secret'])) |
|
| 600 | - $update['last_login'] = time(); |
|
| 617 | + if (empty($user_settings['tfa_secret'])) { |
|
| 618 | + $update['last_login'] = time(); |
|
| 619 | + } |
|
| 601 | 620 | updateMemberData($user_info['id'], $update); |
| 602 | 621 | |
| 603 | 622 | // Get rid of the online entry for that old guest.... |
@@ -611,8 +630,8 @@ discard block |
||
| 611 | 630 | $_SESSION['log_time'] = 0; |
| 612 | 631 | |
| 613 | 632 | // Log this entry, only if we have it enabled. |
| 614 | - if (!empty($modSettings['loginHistoryDays'])) |
|
| 615 | - $smcFunc['db_insert']('insert', |
|
| 633 | + if (!empty($modSettings['loginHistoryDays'])) { |
|
| 634 | + $smcFunc['db_insert']('insert', |
|
| 616 | 635 | '{db_prefix}member_logins', |
| 617 | 636 | array( |
| 618 | 637 | 'id_member' => 'int', 'time' => 'int', 'ip' => 'inet', 'ip2' => 'inet', |
@@ -624,13 +643,15 @@ discard block |
||
| 624 | 643 | 'id_member', 'time' |
| 625 | 644 | ) |
| 626 | 645 | ); |
| 646 | + } |
|
| 627 | 647 | |
| 628 | 648 | // Just log you back out if it's in maintenance mode and you AREN'T an admin. |
| 629 | - if (empty($maintenance) || allowedTo('admin_forum')) |
|
| 630 | - redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']); |
|
| 631 | - else |
|
| 632 | - redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']); |
|
| 633 | -} |
|
| 649 | + if (empty($maintenance) || allowedTo('admin_forum')) { |
|
| 650 | + redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']); |
|
| 651 | + } else { |
|
| 652 | + redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']); |
|
| 653 | + } |
|
| 654 | + } |
|
| 634 | 655 | |
| 635 | 656 | /** |
| 636 | 657 | * Logs the current user out of their account. |
@@ -646,13 +667,15 @@ discard block |
||
| 646 | 667 | global $sourcedir, $user_info, $user_settings, $context, $smcFunc, $cookiename, $modSettings; |
| 647 | 668 | |
| 648 | 669 | // Make sure they aren't being auto-logged out. |
| 649 | - if (!$internal) |
|
| 650 | - checkSession('get'); |
|
| 670 | + if (!$internal) { |
|
| 671 | + checkSession('get'); |
|
| 672 | + } |
|
| 651 | 673 | |
| 652 | 674 | require_once($sourcedir . '/Subs-Auth.php'); |
| 653 | 675 | |
| 654 | - if (isset($_SESSION['pack_ftp'])) |
|
| 655 | - $_SESSION['pack_ftp'] = null; |
|
| 676 | + if (isset($_SESSION['pack_ftp'])) { |
|
| 677 | + $_SESSION['pack_ftp'] = null; |
|
| 678 | + } |
|
| 656 | 679 | |
| 657 | 680 | // It won't be first login anymore. |
| 658 | 681 | unset($_SESSION['first_login']); |
@@ -680,8 +703,9 @@ discard block |
||
| 680 | 703 | |
| 681 | 704 | // And some other housekeeping while we're at it. |
| 682 | 705 | $salt = substr(md5(mt_rand()), 0, 4); |
| 683 | - if (!empty($user_info['id'])) |
|
| 684 | - updateMemberData($user_info['id'], array('password_salt' => $salt)); |
|
| 706 | + if (!empty($user_info['id'])) { |
|
| 707 | + updateMemberData($user_info['id'], array('password_salt' => $salt)); |
|
| 708 | + } |
|
| 685 | 709 | |
| 686 | 710 | if (!empty($modSettings['tfa_mode']) && !empty($user_info['id']) && !empty($_COOKIE[$cookiename . '_tfa'])) |
| 687 | 711 | { |
@@ -694,14 +718,13 @@ discard block |
||
| 694 | 718 | // Off to the merry board index we go! |
| 695 | 719 | if ($redirect) |
| 696 | 720 | { |
| 697 | - if (empty($_SESSION['logout_url'])) |
|
| 698 | - redirectexit('', $context['server']['needs_login_fix']); |
|
| 699 | - elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false)) |
|
| 721 | + if (empty($_SESSION['logout_url'])) { |
|
| 722 | + redirectexit('', $context['server']['needs_login_fix']); |
|
| 723 | + } elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false)) |
|
| 700 | 724 | { |
| 701 | 725 | unset ($_SESSION['logout_url']); |
| 702 | 726 | redirectexit(); |
| 703 | - } |
|
| 704 | - else |
|
| 727 | + } else |
|
| 705 | 728 | { |
| 706 | 729 | $temp = $_SESSION['logout_url']; |
| 707 | 730 | unset($_SESSION['logout_url']); |
@@ -734,8 +757,9 @@ discard block |
||
| 734 | 757 | function phpBB3_password_check($passwd, $passwd_hash) |
| 735 | 758 | { |
| 736 | 759 | // Too long or too short? |
| 737 | - if (strlen($passwd_hash) != 34) |
|
| 738 | - return; |
|
| 760 | + if (strlen($passwd_hash) != 34) { |
|
| 761 | + return; |
|
| 762 | + } |
|
| 739 | 763 | |
| 740 | 764 | // Range of characters allowed. |
| 741 | 765 | $range = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; |
@@ -746,8 +770,9 @@ discard block |
||
| 746 | 770 | $salt = substr($passwd_hash, 4, 8); |
| 747 | 771 | |
| 748 | 772 | $hash = md5($salt . $passwd, true); |
| 749 | - for (; $count != 0; --$count) |
|
| 750 | - $hash = md5($hash . $passwd, true); |
|
| 773 | + for (; $count != 0; --$count) { |
|
| 774 | + $hash = md5($hash . $passwd, true); |
|
| 775 | + } |
|
| 751 | 776 | |
| 752 | 777 | $output = substr($passwd_hash, 0, 12); |
| 753 | 778 | $i = 0; |
@@ -756,21 +781,25 @@ discard block |
||
| 756 | 781 | $value = ord($hash[$i++]); |
| 757 | 782 | $output .= $range[$value & 0x3f]; |
| 758 | 783 | |
| 759 | - if ($i < 16) |
|
| 760 | - $value |= ord($hash[$i]) << 8; |
|
| 784 | + if ($i < 16) { |
|
| 785 | + $value |= ord($hash[$i]) << 8; |
|
| 786 | + } |
|
| 761 | 787 | |
| 762 | 788 | $output .= $range[($value >> 6) & 0x3f]; |
| 763 | 789 | |
| 764 | - if ($i++ >= 16) |
|
| 765 | - break; |
|
| 790 | + if ($i++ >= 16) { |
|
| 791 | + break; |
|
| 792 | + } |
|
| 766 | 793 | |
| 767 | - if ($i < 16) |
|
| 768 | - $value |= ord($hash[$i]) << 16; |
|
| 794 | + if ($i < 16) { |
|
| 795 | + $value |= ord($hash[$i]) << 16; |
|
| 796 | + } |
|
| 769 | 797 | |
| 770 | 798 | $output .= $range[($value >> 12) & 0x3f]; |
| 771 | 799 | |
| 772 | - if ($i++ >= 16) |
|
| 773 | - break; |
|
| 800 | + if ($i++ >= 16) { |
|
| 801 | + break; |
|
| 802 | + } |
|
| 774 | 803 | |
| 775 | 804 | $output .= $range[($value >> 18) & 0x3f]; |
| 776 | 805 | } |
@@ -802,8 +831,9 @@ discard block |
||
| 802 | 831 | require_once($sourcedir . '/Subs-Auth.php'); |
| 803 | 832 | setLoginCookie(-3600, 0); |
| 804 | 833 | |
| 805 | - if (isset($_SESSION['login_' . $cookiename])) |
|
| 806 | - unset($_SESSION['login_' . $cookiename]); |
|
| 834 | + if (isset($_SESSION['login_' . $cookiename])) { |
|
| 835 | + unset($_SESSION['login_' . $cookiename]); |
|
| 836 | + } |
|
| 807 | 837 | } |
| 808 | 838 | |
| 809 | 839 | // We need a member! |
@@ -817,8 +847,9 @@ discard block |
||
| 817 | 847 | } |
| 818 | 848 | |
| 819 | 849 | // Right, have we got a flood value? |
| 820 | - if ($password_flood_value !== false) |
|
| 821 | - @list ($time_stamp, $number_tries) = explode('|', $password_flood_value); |
|
| 850 | + if ($password_flood_value !== false) { |
|
| 851 | + @list ($time_stamp, $number_tries) = explode('|', $password_flood_value); |
|
| 852 | + } |
|
| 822 | 853 | |
| 823 | 854 | // Timestamp or number of tries invalid? |
| 824 | 855 | if (empty($number_tries) || empty($time_stamp)) |
@@ -834,15 +865,17 @@ discard block |
||
| 834 | 865 | $number_tries = $time_stamp < time() - 20 ? 2 : $number_tries; |
| 835 | 866 | |
| 836 | 867 | // They are trying too fast, make them wait longer |
| 837 | - if ($time_stamp < time() - 10) |
|
| 838 | - $time_stamp = time(); |
|
| 868 | + if ($time_stamp < time() - 10) { |
|
| 869 | + $time_stamp = time(); |
|
| 870 | + } |
|
| 839 | 871 | } |
| 840 | 872 | |
| 841 | 873 | $number_tries++; |
| 842 | 874 | |
| 843 | 875 | // Broken the law? |
| 844 | - if ($number_tries > 5) |
|
| 845 | - fatal_lang_error('login_threshold_brute_fail', 'login', [$member_name]); |
|
| 876 | + if ($number_tries > 5) { |
|
| 877 | + fatal_lang_error('login_threshold_brute_fail', 'login', [$member_name]); |
|
| 878 | + } |
|
| 846 | 879 | |
| 847 | 880 | // Otherwise set the members data. If they correct on their first attempt then we actually clear it, otherwise we set it! |
| 848 | 881 | updateMemberData($id_member, array('passwd_flood' => $was_correct && $number_tries == 1 ? '' : $time_stamp . '|' . $number_tries)); |
@@ -1,9 +1,10 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | // Try to handle it with the upper level index.php. (it should know what to do.) |
| 4 | -if (file_exists(dirname(dirname(__FILE__)) . '/index.php')) |
|
| 4 | +if (file_exists(dirname(dirname(__FILE__)) . '/index.php')) { |
|
| 5 | 5 | include (dirname(dirname(__FILE__)) . '/index.php'); |
| 6 | -else |
|
| 6 | +} else { |
|
| 7 | 7 | exit; |
| 8 | +} |
|
| 8 | 9 | |
| 9 | 10 | ?> |
| 10 | 11 | \ No newline at end of file |
@@ -23,15 +23,15 @@ discard block |
||
| 23 | 23 | { |
| 24 | 24 | global $context, $txt; |
| 25 | 25 | |
| 26 | - if (!empty($context['simple_action'])) |
|
| 27 | - echo ' |
|
| 26 | + if (!empty($context['simple_action'])) { |
|
| 27 | + echo ' |
|
| 28 | 28 | <strong> |
| 29 | 29 | ', $context['error_title'], ' |
| 30 | 30 | </strong><br> |
| 31 | 31 | <div ', $context['error_code'], 'class="padding"> |
| 32 | 32 | ', $context['error_message'], ' |
| 33 | 33 | </div>'; |
| 34 | - else |
|
| 34 | + } else |
|
| 35 | 35 | { |
| 36 | 36 | echo ' |
| 37 | 37 | <div id="fatal_error"> |
@@ -85,21 +85,23 @@ discard block |
||
| 85 | 85 | |
| 86 | 86 | $error_types = array(); |
| 87 | 87 | |
| 88 | - foreach ($context['error_types'] as $type => $details) |
|
| 89 | - $error_types[] = ($details['is_selected'] ? '<img src="' . $settings['images_url'] . '/selected.png" alt=""> ' : '') . '<a href="' . $details['url'] . '" ' . ($details['is_selected'] ? 'style="font-weight: bold;"' : '') . ' title="' . $details['description'] . '">' . $details['label'] . '</a>'; |
|
| 88 | + foreach ($context['error_types'] as $type => $details) { |
|
| 89 | + $error_types[] = ($details['is_selected'] ? '<img src="' . $settings['images_url'] . '/selected.png" alt=""> ' : '') . '<a href="' . $details['url'] . '" ' . ($details['is_selected'] ? 'style="font-weight: bold;"' : '') . ' title="' . $details['description'] . '">' . $details['label'] . '</a>'; |
|
| 90 | + } |
|
| 90 | 91 | |
| 91 | 92 | echo ' |
| 92 | 93 | ', implode(' | ', $error_types), ' |
| 93 | 94 | </td> |
| 94 | 95 | </tr>'; |
| 95 | 96 | |
| 96 | - if ($context['has_filter']) |
|
| 97 | - echo ' |
|
| 97 | + if ($context['has_filter']) { |
|
| 98 | + echo ' |
|
| 98 | 99 | <tr> |
| 99 | 100 | <td colspan="3" class="windowbg"> |
| 100 | 101 | <strong>', $txt['applying_filter'], ':</strong> ', $context['filter']['entity'], ' ', $context['filter']['value']['html'], ' [<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', '">', $txt['clear_filter'], '</a>] |
| 101 | 102 | </td> |
| 102 | 103 | </tr>'; |
| 104 | + } |
|
| 103 | 105 | |
| 104 | 106 | echo ' |
| 105 | 107 | <tr> |
@@ -110,11 +112,12 @@ discard block |
||
| 110 | 112 | </tr>'; |
| 111 | 113 | |
| 112 | 114 | // No errors, then show a message |
| 113 | - if (count($context['errors']) == 0) |
|
| 114 | - echo ' |
|
| 115 | + if (count($context['errors']) == 0) { |
|
| 116 | + echo ' |
|
| 115 | 117 | <tr class="windowbg"> |
| 116 | 118 | <td class="centertext" colspan="2">', $txt['errlog_no_entries'], '</td> |
| 117 | 119 | </tr>'; |
| 120 | + } |
|
| 118 | 121 | |
| 119 | 122 | // We have some errors, must be some mods installed :P |
| 120 | 123 | foreach ($context['errors'] as $error) |
@@ -128,16 +131,18 @@ discard block |
||
| 128 | 131 | <a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? '' : ';desc', $context['has_filter'] ? $context['filter']['href'] : '', '" title="', $txt['reverse_direction'], '"><span class="generic_icons sort_' . $context['sort_direction'] . '"></span></a> |
| 129 | 132 | ', $error['time'], '<br>'; |
| 130 | 133 | |
| 131 | - if (!empty($error['member']['ip'])) |
|
| 132 | - echo ' |
|
| 134 | + if (!empty($error['member']['ip'])) { |
|
| 135 | + echo ' |
|
| 133 | 136 | <a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';filter=ip;value=', $error['member']['ip'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_ip'], '"><span class="generic_icons filter centericon"></span></a> |
| 134 | 137 | <strong><a href="', $scripturl, '?action=trackip;searchip=', $error['member']['ip'], '">', $error['member']['ip'], '</a></strong>'; |
| 138 | + } |
|
| 135 | 139 | |
| 136 | - if ($error['member']['session'] != '') |
|
| 137 | - echo ' |
|
| 140 | + if ($error['member']['session'] != '') { |
|
| 141 | + echo ' |
|
| 138 | 142 | <br> |
| 139 | 143 | <a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';filter=session;value=', $error['member']['session'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_session'], '"><span class="generic_icons filter centericon"></span></a> |
| 140 | 144 | ', $error['member']['session'], '<br>'; |
| 145 | + } |
|
| 141 | 146 | |
| 142 | 147 | echo ' |
| 143 | 148 | </div> |
@@ -152,12 +157,13 @@ discard block |
||
| 152 | 157 | <a href="', $error['url']['html'], '">', $error['url']['html'], '</a> |
| 153 | 158 | '; |
| 154 | 159 | |
| 155 | - if (!empty($error['file'])) |
|
| 156 | - echo ' |
|
| 160 | + if (!empty($error['file'])) { |
|
| 161 | + echo ' |
|
| 157 | 162 | <div> |
| 158 | 163 | <a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';filter=file;value=', $error['file']['search'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_file'], '">' |
| 159 | 164 | . ' <span class="generic_icons filter"></span></a> ', $error['file']['link'], ' (', $txt['line'], ' ', $error['file']['line'], ') |
| 160 | 165 | </div>'; |
| 166 | + } |
|
| 161 | 167 | |
| 162 | 168 | echo ' |
| 163 | 169 | </div> |
@@ -186,9 +192,10 @@ discard block |
||
| 186 | 192 | </div> |
| 187 | 193 | </div>'; |
| 188 | 194 | |
| 189 | - if ($context['sort_direction'] == 'down') |
|
| 190 | - echo ' |
|
| 195 | + if ($context['sort_direction'] == 'down') { |
|
| 196 | + echo ' |
|
| 191 | 197 | <input type="hidden" name="desc" value="1">'; |
| 198 | + } |
|
| 192 | 199 | |
| 193 | 200 | echo ' |
| 194 | 201 | <input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '"> |
@@ -30,8 +30,9 @@ discard block |
||
| 30 | 30 | * @version 2.1 Beta 4 |
| 31 | 31 | */ |
| 32 | 32 | |
| 33 | -if (!defined('SMF')) |
|
| 33 | +if (!defined('SMF')) { |
|
| 34 | 34 | die('No direct access...'); |
| 35 | +} |
|
| 35 | 36 | |
| 36 | 37 | /** |
| 37 | 38 | * Subaction handler - manages the action and delegates control to the proper |
@@ -103,12 +104,12 @@ discard block |
||
| 103 | 104 | cache_put_data('minimized_css', null); |
| 104 | 105 | |
| 105 | 106 | // Follow the sa or just go to administration. |
| 106 | - if (isset($_GET['sa']) && !empty($subActions[$_GET['sa']])) |
|
| 107 | - call_helper($subActions[$_GET['sa']]); |
|
| 108 | - |
|
| 109 | - else |
|
| 110 | - call_helper($subActions['admin']); |
|
| 111 | -} |
|
| 107 | + if (isset($_GET['sa']) && !empty($subActions[$_GET['sa']])) { |
|
| 108 | + call_helper($subActions[$_GET['sa']]); |
|
| 109 | + } else { |
|
| 110 | + call_helper($subActions['admin']); |
|
| 111 | + } |
|
| 112 | + } |
|
| 112 | 113 | |
| 113 | 114 | /** |
| 114 | 115 | * This function allows administration of themes and their settings, |
@@ -130,15 +131,16 @@ discard block |
||
| 130 | 131 | checkSession(); |
| 131 | 132 | validateToken('admin-tm'); |
| 132 | 133 | |
| 133 | - if (isset($_POST['options']['known_themes'])) |
|
| 134 | - foreach ($_POST['options']['known_themes'] as $key => $id) |
|
| 134 | + if (isset($_POST['options']['known_themes'])) { |
|
| 135 | + foreach ($_POST['options']['known_themes'] as $key => $id) |
|
| 135 | 136 | $_POST['options']['known_themes'][$key] = (int) $id; |
| 137 | + } else { |
|
| 138 | + fatal_lang_error('themes_none_selectable', false); |
|
| 139 | + } |
|
| 136 | 140 | |
| 137 | - else |
|
| 138 | - fatal_lang_error('themes_none_selectable', false); |
|
| 139 | - |
|
| 140 | - if (!in_array($_POST['options']['theme_guests'], $_POST['options']['known_themes'])) |
|
| 141 | - fatal_lang_error('themes_default_selectable', false); |
|
| 141 | + if (!in_array($_POST['options']['theme_guests'], $_POST['options']['known_themes'])) { |
|
| 142 | + fatal_lang_error('themes_default_selectable', false); |
|
| 143 | + } |
|
| 142 | 144 | |
| 143 | 145 | // Commit the new settings. |
| 144 | 146 | updateSettings(array( |
@@ -146,8 +148,9 @@ discard block |
||
| 146 | 148 | 'theme_guests' => $_POST['options']['theme_guests'], |
| 147 | 149 | 'knownThemes' => implode(',', $_POST['options']['known_themes']), |
| 148 | 150 | )); |
| 149 | - if ((int) $_POST['theme_reset'] == 0 || in_array($_POST['theme_reset'], $_POST['options']['known_themes'])) |
|
| 150 | - updateMemberData(null, array('id_theme' => (int) $_POST['theme_reset'])); |
|
| 151 | + if ((int) $_POST['theme_reset'] == 0 || in_array($_POST['theme_reset'], $_POST['options']['known_themes'])) { |
|
| 152 | + updateMemberData(null, array('id_theme' => (int) $_POST['theme_reset'])); |
|
| 153 | + } |
|
| 151 | 154 | |
| 152 | 155 | redirectexit('action=admin;area=theme;' . $context['session_var'] . '=' . $context['session_id'] . ';sa=admin'); |
| 153 | 156 | } |
@@ -166,8 +169,9 @@ discard block |
||
| 166 | 169 | // Look for a non existent theme directory. (ie theme87.) |
| 167 | 170 | $theme_dir = $boarddir . '/Themes/theme'; |
| 168 | 171 | $i = 1; |
| 169 | - while (file_exists($theme_dir . $i)) |
|
| 170 | - $i++; |
|
| 172 | + while (file_exists($theme_dir . $i)) { |
|
| 173 | + $i++; |
|
| 174 | + } |
|
| 171 | 175 | |
| 172 | 176 | $context['new_theme_name'] = 'theme' . $i; |
| 173 | 177 | |
@@ -189,8 +193,9 @@ discard block |
||
| 189 | 193 | loadLanguage('Admin'); |
| 190 | 194 | isAllowedTo('admin_forum'); |
| 191 | 195 | |
| 192 | - if (isset($_REQUEST['th'])) |
|
| 193 | - return SetThemeSettings(); |
|
| 196 | + if (isset($_REQUEST['th'])) { |
|
| 197 | + return SetThemeSettings(); |
|
| 198 | + } |
|
| 194 | 199 | |
| 195 | 200 | if (isset($_POST['save'])) |
| 196 | 201 | { |
@@ -274,12 +279,13 @@ discard block |
||
| 274 | 279 | $context['themes'] = array(); |
| 275 | 280 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 276 | 281 | { |
| 277 | - if (!isset($context['themes'][$row['id_theme']])) |
|
| 278 | - $context['themes'][$row['id_theme']] = array( |
|
| 282 | + if (!isset($context['themes'][$row['id_theme']])) { |
|
| 283 | + $context['themes'][$row['id_theme']] = array( |
|
| 279 | 284 | 'id' => $row['id_theme'], |
| 280 | 285 | 'num_default_options' => 0, |
| 281 | 286 | 'num_members' => 0, |
| 282 | 287 | ); |
| 288 | + } |
|
| 283 | 289 | $context['themes'][$row['id_theme']][$row['variable']] = $row['value']; |
| 284 | 290 | } |
| 285 | 291 | $smcFunc['db_free_result']($request); |
@@ -293,8 +299,9 @@ discard block |
||
| 293 | 299 | 'guest_member' => -1, |
| 294 | 300 | ) |
| 295 | 301 | ); |
| 296 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 297 | - $context['themes'][$row['id_theme']]['num_default_options'] = $row['value']; |
|
| 302 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 303 | + $context['themes'][$row['id_theme']]['num_default_options'] = $row['value']; |
|
| 304 | + } |
|
| 298 | 305 | $smcFunc['db_free_result']($request); |
| 299 | 306 | |
| 300 | 307 | // Need to make sure we don't do custom fields. |
@@ -305,8 +312,9 @@ discard block |
||
| 305 | 312 | ) |
| 306 | 313 | ); |
| 307 | 314 | $customFields = array(); |
| 308 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 309 | - $customFields[] = $row['col_name']; |
|
| 315 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 316 | + $customFields[] = $row['col_name']; |
|
| 317 | + } |
|
| 310 | 318 | $smcFunc['db_free_result']($request); |
| 311 | 319 | $customFieldsQuery = empty($customFields) ? '' : ('AND variable NOT IN ({array_string:custom_fields})'); |
| 312 | 320 | |
@@ -321,14 +329,16 @@ discard block |
||
| 321 | 329 | 'custom_fields' => empty($customFields) ? array() : $customFields, |
| 322 | 330 | ) |
| 323 | 331 | ); |
| 324 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 325 | - $context['themes'][$row['id_theme']]['num_members'] = $row['value']; |
|
| 332 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 333 | + $context['themes'][$row['id_theme']]['num_members'] = $row['value']; |
|
| 334 | + } |
|
| 326 | 335 | $smcFunc['db_free_result']($request); |
| 327 | 336 | |
| 328 | 337 | // There has to be a Settings template! |
| 329 | - foreach ($context['themes'] as $k => $v) |
|
| 330 | - if (empty($v['theme_dir']) || (!file_exists($v['theme_dir'] . '/Settings.template.php') && empty($v['num_members']))) |
|
| 338 | + foreach ($context['themes'] as $k => $v) { |
|
| 339 | + if (empty($v['theme_dir']) || (!file_exists($v['theme_dir'] . '/Settings.template.php') && empty($v['num_members']))) |
|
| 331 | 340 | unset($context['themes'][$k]); |
| 341 | + } |
|
| 332 | 342 | |
| 333 | 343 | loadTemplate('Themes'); |
| 334 | 344 | $context['sub_template'] = 'reset_list'; |
@@ -343,16 +353,19 @@ discard block |
||
| 343 | 353 | checkSession(); |
| 344 | 354 | validateToken('admin-sto'); |
| 345 | 355 | |
| 346 | - if (empty($_POST['options'])) |
|
| 347 | - $_POST['options'] = array(); |
|
| 348 | - if (empty($_POST['default_options'])) |
|
| 349 | - $_POST['default_options'] = array(); |
|
| 356 | + if (empty($_POST['options'])) { |
|
| 357 | + $_POST['options'] = array(); |
|
| 358 | + } |
|
| 359 | + if (empty($_POST['default_options'])) { |
|
| 360 | + $_POST['default_options'] = array(); |
|
| 361 | + } |
|
| 350 | 362 | |
| 351 | 363 | // Set up the sql query. |
| 352 | 364 | $setValues = array(); |
| 353 | 365 | |
| 354 | - foreach ($_POST['options'] as $opt => $val) |
|
| 355 | - $setValues[] = array(-1, $_GET['th'], $opt, is_array($val) ? implode(',', $val) : $val); |
|
| 366 | + foreach ($_POST['options'] as $opt => $val) { |
|
| 367 | + $setValues[] = array(-1, $_GET['th'], $opt, is_array($val) ? implode(',', $val) : $val); |
|
| 368 | + } |
|
| 356 | 369 | |
| 357 | 370 | $old_settings = array(); |
| 358 | 371 | foreach ($_POST['default_options'] as $opt => $val) |
@@ -366,8 +379,8 @@ discard block |
||
| 366 | 379 | if (!empty($setValues)) |
| 367 | 380 | { |
| 368 | 381 | // Are there options in non-default themes set that should be cleared? |
| 369 | - if (!empty($old_settings)) |
|
| 370 | - $smcFunc['db_query']('', ' |
|
| 382 | + if (!empty($old_settings)) { |
|
| 383 | + $smcFunc['db_query']('', ' |
|
| 371 | 384 | DELETE FROM {db_prefix}themes |
| 372 | 385 | WHERE id_theme != {int:default_theme} |
| 373 | 386 | AND id_member = {int:guest_member} |
@@ -378,6 +391,7 @@ discard block |
||
| 378 | 391 | 'old_settings' => $old_settings, |
| 379 | 392 | ) |
| 380 | 393 | ); |
| 394 | + } |
|
| 381 | 395 | |
| 382 | 396 | $smcFunc['db_insert']('replace', |
| 383 | 397 | '{db_prefix}themes', |
@@ -391,8 +405,7 @@ discard block |
||
| 391 | 405 | cache_put_data('theme_settings-1', null, 90); |
| 392 | 406 | |
| 393 | 407 | redirectexit('action=admin;area=theme;' . $context['session_var'] . '=' . $context['session_id'] . ';sa=reset'); |
| 394 | - } |
|
| 395 | - elseif (isset($_POST['submit']) && $_POST['who'] == 1) |
|
| 408 | + } elseif (isset($_POST['submit']) && $_POST['who'] == 1) |
|
| 396 | 409 | { |
| 397 | 410 | checkSession(); |
| 398 | 411 | validateToken('admin-sto'); |
@@ -405,9 +418,9 @@ discard block |
||
| 405 | 418 | $old_settings = array(); |
| 406 | 419 | foreach ($_POST['default_options'] as $opt => $val) |
| 407 | 420 | { |
| 408 | - if ($_POST['default_options_master'][$opt] == 0) |
|
| 409 | - continue; |
|
| 410 | - elseif ($_POST['default_options_master'][$opt] == 1) |
|
| 421 | + if ($_POST['default_options_master'][$opt] == 0) { |
|
| 422 | + continue; |
|
| 423 | + } elseif ($_POST['default_options_master'][$opt] == 1) |
|
| 411 | 424 | { |
| 412 | 425 | // Delete then insert for ease of database compatibility! |
| 413 | 426 | $smcFunc['db_query']('substring', ' |
@@ -433,8 +446,7 @@ discard block |
||
| 433 | 446 | ); |
| 434 | 447 | |
| 435 | 448 | $old_settings[] = $opt; |
| 436 | - } |
|
| 437 | - elseif ($_POST['default_options_master'][$opt] == 2) |
|
| 449 | + } elseif ($_POST['default_options_master'][$opt] == 2) |
|
| 438 | 450 | { |
| 439 | 451 | $smcFunc['db_query']('', ' |
| 440 | 452 | DELETE FROM {db_prefix}themes |
@@ -449,8 +461,8 @@ discard block |
||
| 449 | 461 | } |
| 450 | 462 | |
| 451 | 463 | // Delete options from other themes. |
| 452 | - if (!empty($old_settings)) |
|
| 453 | - $smcFunc['db_query']('', ' |
|
| 464 | + if (!empty($old_settings)) { |
|
| 465 | + $smcFunc['db_query']('', ' |
|
| 454 | 466 | DELETE FROM {db_prefix}themes |
| 455 | 467 | WHERE id_theme != {int:default_theme} |
| 456 | 468 | AND id_member > {int:no_member} |
@@ -461,12 +473,13 @@ discard block |
||
| 461 | 473 | 'old_settings' => $old_settings, |
| 462 | 474 | ) |
| 463 | 475 | ); |
| 476 | + } |
|
| 464 | 477 | |
| 465 | 478 | foreach ($_POST['options'] as $opt => $val) |
| 466 | 479 | { |
| 467 | - if ($_POST['options_master'][$opt] == 0) |
|
| 468 | - continue; |
|
| 469 | - elseif ($_POST['options_master'][$opt] == 1) |
|
| 480 | + if ($_POST['options_master'][$opt] == 0) { |
|
| 481 | + continue; |
|
| 482 | + } elseif ($_POST['options_master'][$opt] == 1) |
|
| 470 | 483 | { |
| 471 | 484 | // Delete then insert for ease of database compatibility - again! |
| 472 | 485 | $smcFunc['db_query']('substring', ' |
@@ -491,8 +504,7 @@ discard block |
||
| 491 | 504 | 'value' => (is_array($val) ? implode(',', $val) : $val), |
| 492 | 505 | ) |
| 493 | 506 | ); |
| 494 | - } |
|
| 495 | - elseif ($_POST['options_master'][$opt] == 2) |
|
| 507 | + } elseif ($_POST['options_master'][$opt] == 2) |
|
| 496 | 508 | { |
| 497 | 509 | $smcFunc['db_query']('', ' |
| 498 | 510 | DELETE FROM {db_prefix}themes |
@@ -509,8 +521,7 @@ discard block |
||
| 509 | 521 | } |
| 510 | 522 | |
| 511 | 523 | redirectexit('action=admin;area=theme;' . $context['session_var'] . '=' . $context['session_id'] . ';sa=reset'); |
| 512 | - } |
|
| 513 | - elseif (!empty($_GET['who']) && $_GET['who'] == 2) |
|
| 524 | + } elseif (!empty($_GET['who']) && $_GET['who'] == 2) |
|
| 514 | 525 | { |
| 515 | 526 | checkSession('get'); |
| 516 | 527 | validateToken('admin-stor', 'request'); |
@@ -525,8 +536,9 @@ discard block |
||
| 525 | 536 | ) |
| 526 | 537 | ); |
| 527 | 538 | $customFields = array(); |
| 528 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 529 | - $customFields[] = $row['col_name']; |
|
| 539 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 540 | + $customFields[] = $row['col_name']; |
|
| 541 | + } |
|
| 530 | 542 | $smcFunc['db_free_result']($request); |
| 531 | 543 | } |
| 532 | 544 | $customFieldsQuery = empty($customFields) ? '' : ('AND variable NOT IN ({array_string:custom_fields})'); |
@@ -581,13 +593,13 @@ discard block |
||
| 581 | 593 | ) |
| 582 | 594 | ); |
| 583 | 595 | $context['theme_options'] = array(); |
| 584 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 585 | - $context['theme_options'][$row['variable']] = $row['value']; |
|
| 596 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 597 | + $context['theme_options'][$row['variable']] = $row['value']; |
|
| 598 | + } |
|
| 586 | 599 | $smcFunc['db_free_result']($request); |
| 587 | 600 | |
| 588 | 601 | $context['theme_options_reset'] = false; |
| 589 | - } |
|
| 590 | - else |
|
| 602 | + } else |
|
| 591 | 603 | { |
| 592 | 604 | $context['theme_options'] = array(); |
| 593 | 605 | $context['theme_options_reset'] = true; |
@@ -596,30 +608,32 @@ discard block |
||
| 596 | 608 | foreach ($context['options'] as $i => $setting) |
| 597 | 609 | { |
| 598 | 610 | // Just skip separators |
| 599 | - if (!is_array($setting)) |
|
| 600 | - continue; |
|
| 611 | + if (!is_array($setting)) { |
|
| 612 | + continue; |
|
| 613 | + } |
|
| 601 | 614 | |
| 602 | 615 | // Is this disabled? |
| 603 | 616 | if ($setting['id'] == 'calendar_start_day' && empty($modSettings['cal_enabled'])) |
| 604 | 617 | { |
| 605 | 618 | unset($context['options'][$i]); |
| 606 | 619 | continue; |
| 607 | - } |
|
| 608 | - elseif (($setting['id'] == 'topics_per_page' || $setting['id'] == 'messages_per_page') && !empty($modSettings['disableCustomPerPage'])) |
|
| 620 | + } elseif (($setting['id'] == 'topics_per_page' || $setting['id'] == 'messages_per_page') && !empty($modSettings['disableCustomPerPage'])) |
|
| 609 | 621 | { |
| 610 | 622 | unset($context['options'][$i]); |
| 611 | 623 | continue; |
| 612 | 624 | } |
| 613 | 625 | |
| 614 | - if (!isset($setting['type']) || $setting['type'] == 'bool') |
|
| 615 | - $context['options'][$i]['type'] = 'checkbox'; |
|
| 616 | - elseif ($setting['type'] == 'int' || $setting['type'] == 'integer') |
|
| 617 | - $context['options'][$i]['type'] = 'number'; |
|
| 618 | - elseif ($setting['type'] == 'string') |
|
| 619 | - $context['options'][$i]['type'] = 'text'; |
|
| 626 | + if (!isset($setting['type']) || $setting['type'] == 'bool') { |
|
| 627 | + $context['options'][$i]['type'] = 'checkbox'; |
|
| 628 | + } elseif ($setting['type'] == 'int' || $setting['type'] == 'integer') { |
|
| 629 | + $context['options'][$i]['type'] = 'number'; |
|
| 630 | + } elseif ($setting['type'] == 'string') { |
|
| 631 | + $context['options'][$i]['type'] = 'text'; |
|
| 632 | + } |
|
| 620 | 633 | |
| 621 | - if (isset($setting['options'])) |
|
| 622 | - $context['options'][$i]['type'] = 'list'; |
|
| 634 | + if (isset($setting['options'])) { |
|
| 635 | + $context['options'][$i]['type'] = 'list'; |
|
| 636 | + } |
|
| 623 | 637 | |
| 624 | 638 | $context['options'][$i]['value'] = !isset($context['theme_options'][$setting['id']]) ? '' : $context['theme_options'][$setting['id']]; |
| 625 | 639 | } |
@@ -644,8 +658,9 @@ discard block |
||
| 644 | 658 | { |
| 645 | 659 | global $txt, $context, $settings, $modSettings, $smcFunc; |
| 646 | 660 | |
| 647 | - if (empty($_GET['th']) && empty($_GET['id'])) |
|
| 648 | - return ThemeAdmin(); |
|
| 661 | + if (empty($_GET['th']) && empty($_GET['id'])) { |
|
| 662 | + return ThemeAdmin(); |
|
| 663 | + } |
|
| 649 | 664 | |
| 650 | 665 | $_GET['th'] = isset($_GET['th']) ? (int) $_GET['th'] : (int) $_GET['id']; |
| 651 | 666 | |
@@ -656,8 +671,9 @@ discard block |
||
| 656 | 671 | isAllowedTo('admin_forum'); |
| 657 | 672 | |
| 658 | 673 | // Validate inputs/user. |
| 659 | - if (empty($_GET['th'])) |
|
| 660 | - fatal_lang_error('no_theme', false); |
|
| 674 | + if (empty($_GET['th'])) { |
|
| 675 | + fatal_lang_error('no_theme', false); |
|
| 676 | + } |
|
| 661 | 677 | |
| 662 | 678 | // Fetch the smiley sets... |
| 663 | 679 | $sets = explode(',', 'none,' . $modSettings['smiley_sets_known']); |
@@ -665,8 +681,9 @@ discard block |
||
| 665 | 681 | $context['smiley_sets'] = array( |
| 666 | 682 | '' => $txt['smileys_no_default'] |
| 667 | 683 | ); |
| 668 | - foreach ($sets as $i => $set) |
|
| 669 | - $context['smiley_sets'][$set] = $smcFunc['htmlspecialchars']($set_names[$i]); |
|
| 684 | + foreach ($sets as $i => $set) { |
|
| 685 | + $context['smiley_sets'][$set] = $smcFunc['htmlspecialchars']($set_names[$i]); |
|
| 686 | + } |
|
| 670 | 687 | |
| 671 | 688 | $old_id = $settings['theme_id']; |
| 672 | 689 | $old_settings = $settings; |
@@ -691,8 +708,9 @@ discard block |
||
| 691 | 708 | if (file_exists($settings['theme_dir'] . '/index.template.php')) |
| 692 | 709 | { |
| 693 | 710 | $file_contents = implode('', file($settings['theme_dir'] . '/index.template.php')); |
| 694 | - if (preg_match('~\$settings\[\'theme_variants\'\]\s*=(.+?);~', $file_contents, $matches)) |
|
| 695 | - eval('global $settings;' . $matches[0]); |
|
| 711 | + if (preg_match('~\$settings\[\'theme_variants\'\]\s*=(.+?);~', $file_contents, $matches)) { |
|
| 712 | + eval('global $settings;' . $matches[0]); |
|
| 713 | + } |
|
| 696 | 714 | } |
| 697 | 715 | |
| 698 | 716 | // Let mods hook into the theme settings. |
@@ -704,37 +722,45 @@ discard block |
||
| 704 | 722 | checkSession(); |
| 705 | 723 | validateToken('admin-sts'); |
| 706 | 724 | |
| 707 | - if (empty($_POST['options'])) |
|
| 708 | - $_POST['options'] = array(); |
|
| 709 | - if (empty($_POST['default_options'])) |
|
| 710 | - $_POST['default_options'] = array(); |
|
| 725 | + if (empty($_POST['options'])) { |
|
| 726 | + $_POST['options'] = array(); |
|
| 727 | + } |
|
| 728 | + if (empty($_POST['default_options'])) { |
|
| 729 | + $_POST['default_options'] = array(); |
|
| 730 | + } |
|
| 711 | 731 | |
| 712 | 732 | // Make sure items are cast correctly. |
| 713 | 733 | foreach ($context['theme_settings'] as $item) |
| 714 | 734 | { |
| 715 | 735 | // Disregard this item if this is just a separator. |
| 716 | - if (!is_array($item)) |
|
| 717 | - continue; |
|
| 736 | + if (!is_array($item)) { |
|
| 737 | + continue; |
|
| 738 | + } |
|
| 718 | 739 | |
| 719 | 740 | foreach (array('options', 'default_options') as $option) |
| 720 | 741 | { |
| 721 | - if (!isset($_POST[$option][$item['id']])) |
|
| 722 | - continue; |
|
| 742 | + if (!isset($_POST[$option][$item['id']])) { |
|
| 743 | + continue; |
|
| 744 | + } |
|
| 723 | 745 | // Checkbox. |
| 724 | - elseif (empty($item['type'])) |
|
| 725 | - $_POST[$option][$item['id']] = $_POST[$option][$item['id']] ? 1 : 0; |
|
| 746 | + elseif (empty($item['type'])) { |
|
| 747 | + $_POST[$option][$item['id']] = $_POST[$option][$item['id']] ? 1 : 0; |
|
| 748 | + } |
|
| 726 | 749 | // Number |
| 727 | - elseif ($item['type'] == 'number') |
|
| 728 | - $_POST[$option][$item['id']] = (int) $_POST[$option][$item['id']]; |
|
| 750 | + elseif ($item['type'] == 'number') { |
|
| 751 | + $_POST[$option][$item['id']] = (int) $_POST[$option][$item['id']]; |
|
| 752 | + } |
|
| 729 | 753 | } |
| 730 | 754 | } |
| 731 | 755 | |
| 732 | 756 | // Set up the sql query. |
| 733 | 757 | $inserts = array(); |
| 734 | - foreach ($_POST['options'] as $opt => $val) |
|
| 735 | - $inserts[] = array(0, $_GET['th'], $opt, is_array($val) ? implode(',', $val) : $val); |
|
| 736 | - foreach ($_POST['default_options'] as $opt => $val) |
|
| 737 | - $inserts[] = array(0, 1, $opt, is_array($val) ? implode(',', $val) : $val); |
|
| 758 | + foreach ($_POST['options'] as $opt => $val) { |
|
| 759 | + $inserts[] = array(0, $_GET['th'], $opt, is_array($val) ? implode(',', $val) : $val); |
|
| 760 | + } |
|
| 761 | + foreach ($_POST['default_options'] as $opt => $val) { |
|
| 762 | + $inserts[] = array(0, 1, $opt, is_array($val) ? implode(',', $val) : $val); |
|
| 763 | + } |
|
| 738 | 764 | // If we're actually inserting something.. |
| 739 | 765 | if (!empty($inserts)) |
| 740 | 766 | { |
@@ -760,8 +786,9 @@ discard block |
||
| 760 | 786 | |
| 761 | 787 | foreach ($settings as $setting => $dummy) |
| 762 | 788 | { |
| 763 | - if (!in_array($setting, array('theme_url', 'theme_dir', 'images_url', 'template_dirs'))) |
|
| 764 | - $settings[$setting] = htmlspecialchars__recursive($settings[$setting]); |
|
| 789 | + if (!in_array($setting, array('theme_url', 'theme_dir', 'images_url', 'template_dirs'))) { |
|
| 790 | + $settings[$setting] = htmlspecialchars__recursive($settings[$setting]); |
|
| 791 | + } |
|
| 765 | 792 | } |
| 766 | 793 | |
| 767 | 794 | $context['settings'] = $context['theme_settings']; |
@@ -770,18 +797,21 @@ discard block |
||
| 770 | 797 | foreach ($context['settings'] as $i => $setting) |
| 771 | 798 | { |
| 772 | 799 | // Separators are dummies, so leave them alone. |
| 773 | - if (!is_array($setting)) |
|
| 774 | - continue; |
|
| 800 | + if (!is_array($setting)) { |
|
| 801 | + continue; |
|
| 802 | + } |
|
| 775 | 803 | |
| 776 | - if (!isset($setting['type']) || $setting['type'] == 'bool') |
|
| 777 | - $context['settings'][$i]['type'] = 'checkbox'; |
|
| 778 | - elseif ($setting['type'] == 'int' || $setting['type'] == 'integer') |
|
| 779 | - $context['settings'][$i]['type'] = 'number'; |
|
| 780 | - elseif ($setting['type'] == 'string') |
|
| 781 | - $context['settings'][$i]['type'] = 'text'; |
|
| 804 | + if (!isset($setting['type']) || $setting['type'] == 'bool') { |
|
| 805 | + $context['settings'][$i]['type'] = 'checkbox'; |
|
| 806 | + } elseif ($setting['type'] == 'int' || $setting['type'] == 'integer') { |
|
| 807 | + $context['settings'][$i]['type'] = 'number'; |
|
| 808 | + } elseif ($setting['type'] == 'string') { |
|
| 809 | + $context['settings'][$i]['type'] = 'text'; |
|
| 810 | + } |
|
| 782 | 811 | |
| 783 | - if (isset($setting['options'])) |
|
| 784 | - $context['settings'][$i]['type'] = 'list'; |
|
| 812 | + if (isset($setting['options'])) { |
|
| 813 | + $context['settings'][$i]['type'] = 'list'; |
|
| 814 | + } |
|
| 785 | 815 | |
| 786 | 816 | $context['settings'][$i]['value'] = !isset($settings[$setting['id']]) ? '' : $settings[$setting['id']]; |
| 787 | 817 | } |
@@ -834,8 +864,9 @@ discard block |
||
| 834 | 864 | $themeID = isset($_GET['th']) ? (int) $_GET['th'] : (int) $_GET['id']; |
| 835 | 865 | |
| 836 | 866 | // You can't delete the default theme! |
| 837 | - if ($themeID == 1) |
|
| 838 | - fatal_lang_error('no_access', false); |
|
| 867 | + if ($themeID == 1) { |
|
| 868 | + fatal_lang_error('no_access', false); |
|
| 869 | + } |
|
| 839 | 870 | |
| 840 | 871 | $theme_info = get_single_theme($themeID); |
| 841 | 872 | |
@@ -843,8 +874,9 @@ discard block |
||
| 843 | 874 | remove_theme($themeID); |
| 844 | 875 | |
| 845 | 876 | // And remove all its files and folders too. |
| 846 | - if (!empty($theme_info) && !empty($theme_info['theme_dir'])) |
|
| 847 | - remove_dir($theme_info['theme_dir']); |
|
| 877 | + if (!empty($theme_info) && !empty($theme_info['theme_dir'])) { |
|
| 878 | + remove_dir($theme_info['theme_dir']); |
|
| 879 | + } |
|
| 848 | 880 | |
| 849 | 881 | // Go back to the list page. |
| 850 | 882 | redirectexit('action=admin;area=theme;sa=list;' . $context['session_var'] . '=' . $context['session_id'] . ';done=removing'); |
@@ -869,12 +901,14 @@ discard block |
||
| 869 | 901 | $enableThemes = explode(',', $modSettings['enableThemes']); |
| 870 | 902 | |
| 871 | 903 | // Are we disabling it? |
| 872 | - if (isset($_GET['disabled'])) |
|
| 873 | - $enableThemes = array_diff($enableThemes, array($themeID)); |
|
| 904 | + if (isset($_GET['disabled'])) { |
|
| 905 | + $enableThemes = array_diff($enableThemes, array($themeID)); |
|
| 906 | + } |
|
| 874 | 907 | |
| 875 | 908 | // Nope? then enable it! |
| 876 | - else |
|
| 877 | - $enableThemes[] = (string) $themeID; |
|
| 909 | + else { |
|
| 910 | + $enableThemes[] = (string) $themeID; |
|
| 911 | + } |
|
| 878 | 912 | |
| 879 | 913 | // Update the setting. |
| 880 | 914 | $enableThemes = strtr(implode(',', $enableThemes), array(',,' => ',')); |
@@ -909,18 +943,21 @@ discard block |
||
| 909 | 943 | |
| 910 | 944 | $_SESSION['id_theme'] = 0; |
| 911 | 945 | |
| 912 | - if (isset($_GET['id'])) |
|
| 913 | - $_GET['th'] = $_GET['id']; |
|
| 946 | + if (isset($_GET['id'])) { |
|
| 947 | + $_GET['th'] = $_GET['id']; |
|
| 948 | + } |
|
| 914 | 949 | |
| 915 | 950 | // Saving a variant cause JS doesn't work - pretend it did ;) |
| 916 | 951 | if (isset($_POST['save'])) |
| 917 | 952 | { |
| 918 | 953 | // Which theme? |
| 919 | - foreach ($_POST['save'] as $k => $v) |
|
| 920 | - $_GET['th'] = (int) $k; |
|
| 954 | + foreach ($_POST['save'] as $k => $v) { |
|
| 955 | + $_GET['th'] = (int) $k; |
|
| 956 | + } |
|
| 921 | 957 | |
| 922 | - if (isset($_POST['vrt'][$k])) |
|
| 923 | - $_GET['vrt'] = $_POST['vrt'][$k]; |
|
| 958 | + if (isset($_POST['vrt'][$k])) { |
|
| 959 | + $_GET['vrt'] = $_POST['vrt'][$k]; |
|
| 960 | + } |
|
| 924 | 961 | } |
| 925 | 962 | |
| 926 | 963 | // Have we made a decision, or are we just browsing? |
@@ -1009,10 +1046,10 @@ discard block |
||
| 1009 | 1046 | ); |
| 1010 | 1047 | cache_put_data('theme_settings-' . $_GET['th'] . ':' . (int) $_REQUEST['u'], null, 90); |
| 1011 | 1048 | |
| 1012 | - if ($user_info['id'] == $_REQUEST['u']) |
|
| 1013 | - $_SESSION['id_variant'] = 0; |
|
| 1014 | - } |
|
| 1015 | - elseif ($_GET['th'] == 0) |
|
| 1049 | + if ($user_info['id'] == $_REQUEST['u']) { |
|
| 1050 | + $_SESSION['id_variant'] = 0; |
|
| 1051 | + } |
|
| 1052 | + } elseif ($_GET['th'] == 0) |
|
| 1016 | 1053 | { |
| 1017 | 1054 | // Remove any custom variants. |
| 1018 | 1055 | $smcFunc['db_query']('', ' |
@@ -1093,12 +1130,13 @@ discard block |
||
| 1093 | 1130 | ); |
| 1094 | 1131 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1095 | 1132 | { |
| 1096 | - if (!isset($context['available_themes'][$row['id_theme']])) |
|
| 1097 | - $context['available_themes'][$row['id_theme']] = array( |
|
| 1133 | + if (!isset($context['available_themes'][$row['id_theme']])) { |
|
| 1134 | + $context['available_themes'][$row['id_theme']] = array( |
|
| 1098 | 1135 | 'id' => $row['id_theme'], |
| 1099 | 1136 | 'selected' => $context['current_theme'] == $row['id_theme'], |
| 1100 | 1137 | 'num_users' => 0 |
| 1101 | 1138 | ); |
| 1139 | + } |
|
| 1102 | 1140 | $context['available_themes'][$row['id_theme']][$row['variable']] = $row['value']; |
| 1103 | 1141 | } |
| 1104 | 1142 | $smcFunc['db_free_result']($request); |
@@ -1111,9 +1149,9 @@ discard block |
||
| 1111 | 1149 | 'num_users' => 0 |
| 1112 | 1150 | ); |
| 1113 | 1151 | $guest_theme = 0; |
| 1152 | + } else { |
|
| 1153 | + $guest_theme = $modSettings['theme_guests']; |
|
| 1114 | 1154 | } |
| 1115 | - else |
|
| 1116 | - $guest_theme = $modSettings['theme_guests']; |
|
| 1117 | 1155 | |
| 1118 | 1156 | $request = $smcFunc['db_query']('', ' |
| 1119 | 1157 | SELECT id_theme, COUNT(*) AS the_count |
@@ -1126,15 +1164,17 @@ discard block |
||
| 1126 | 1164 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1127 | 1165 | { |
| 1128 | 1166 | // Figure out which theme it is they are REALLY using. |
| 1129 | - if (!empty($modSettings['knownThemes']) && !in_array($row['id_theme'], explode(',', $modSettings['knownThemes']))) |
|
| 1130 | - $row['id_theme'] = $guest_theme; |
|
| 1131 | - elseif (empty($modSettings['theme_allow'])) |
|
| 1132 | - $row['id_theme'] = $guest_theme; |
|
| 1167 | + if (!empty($modSettings['knownThemes']) && !in_array($row['id_theme'], explode(',', $modSettings['knownThemes']))) { |
|
| 1168 | + $row['id_theme'] = $guest_theme; |
|
| 1169 | + } elseif (empty($modSettings['theme_allow'])) { |
|
| 1170 | + $row['id_theme'] = $guest_theme; |
|
| 1171 | + } |
|
| 1133 | 1172 | |
| 1134 | - if (isset($context['available_themes'][$row['id_theme']])) |
|
| 1135 | - $context['available_themes'][$row['id_theme']]['num_users'] += $row['the_count']; |
|
| 1136 | - else |
|
| 1137 | - $context['available_themes'][$guest_theme]['num_users'] += $row['the_count']; |
|
| 1173 | + if (isset($context['available_themes'][$row['id_theme']])) { |
|
| 1174 | + $context['available_themes'][$row['id_theme']]['num_users'] += $row['the_count']; |
|
| 1175 | + } else { |
|
| 1176 | + $context['available_themes'][$guest_theme]['num_users'] += $row['the_count']; |
|
| 1177 | + } |
|
| 1138 | 1178 | } |
| 1139 | 1179 | $smcFunc['db_free_result']($request); |
| 1140 | 1180 | |
@@ -1153,8 +1193,9 @@ discard block |
||
| 1153 | 1193 | 'id_member' => isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? array(-1, $context['current_member']) : array(-1), |
| 1154 | 1194 | ) |
| 1155 | 1195 | ); |
| 1156 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1157 | - $variant_preferences[$row['id_theme']] = $row['value']; |
|
| 1196 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1197 | + $variant_preferences[$row['id_theme']] = $row['value']; |
|
| 1198 | + } |
|
| 1158 | 1199 | $smcFunc['db_free_result']($request); |
| 1159 | 1200 | } |
| 1160 | 1201 | |
@@ -1165,17 +1206,18 @@ discard block |
||
| 1165 | 1206 | foreach ($context['available_themes'] as $id_theme => $theme_data) |
| 1166 | 1207 | { |
| 1167 | 1208 | // Don't try to load the forum or board default theme's data... it doesn't have any! |
| 1168 | - if ($id_theme == 0) |
|
| 1169 | - continue; |
|
| 1209 | + if ($id_theme == 0) { |
|
| 1210 | + continue; |
|
| 1211 | + } |
|
| 1170 | 1212 | |
| 1171 | 1213 | // The thumbnail needs the correct path. |
| 1172 | 1214 | $settings['images_url'] = &$theme_data['images_url']; |
| 1173 | 1215 | |
| 1174 | - if (file_exists($theme_data['theme_dir'] . '/languages/Settings.' . $user_info['language'] . '.php')) |
|
| 1175 | - include($theme_data['theme_dir'] . '/languages/Settings.' . $user_info['language'] . '.php'); |
|
| 1176 | - elseif (file_exists($theme_data['theme_dir'] . '/languages/Settings.' . $language . '.php')) |
|
| 1177 | - include($theme_data['theme_dir'] . '/languages/Settings.' . $language . '.php'); |
|
| 1178 | - else |
|
| 1216 | + if (file_exists($theme_data['theme_dir'] . '/languages/Settings.' . $user_info['language'] . '.php')) { |
|
| 1217 | + include($theme_data['theme_dir'] . '/languages/Settings.' . $user_info['language'] . '.php'); |
|
| 1218 | + } elseif (file_exists($theme_data['theme_dir'] . '/languages/Settings.' . $language . '.php')) { |
|
| 1219 | + include($theme_data['theme_dir'] . '/languages/Settings.' . $language . '.php'); |
|
| 1220 | + } else |
|
| 1179 | 1221 | { |
| 1180 | 1222 | $txt['theme_thumbnail_href'] = $theme_data['images_url'] . '/thumbnail.png'; |
| 1181 | 1223 | $txt['theme_description'] = ''; |
@@ -1200,15 +1242,17 @@ discard block |
||
| 1200 | 1242 | loadLanguage('Settings'); |
| 1201 | 1243 | |
| 1202 | 1244 | $context['available_themes'][$id_theme]['variants'] = array(); |
| 1203 | - foreach ($settings['theme_variants'] as $variant) |
|
| 1204 | - $context['available_themes'][$id_theme]['variants'][$variant] = array( |
|
| 1245 | + foreach ($settings['theme_variants'] as $variant) { |
|
| 1246 | + $context['available_themes'][$id_theme]['variants'][$variant] = array( |
|
| 1205 | 1247 | 'label' => isset($txt['variant_' . $variant]) ? $txt['variant_' . $variant] : $variant, |
| 1206 | 1248 | 'thumbnail' => !file_exists($theme_data['theme_dir'] . '/images/thumbnail.png') || file_exists($theme_data['theme_dir'] . '/images/thumbnail_' . $variant . '.png') ? $theme_data['images_url'] . '/thumbnail_' . $variant . '.png' : ($theme_data['images_url'] . '/thumbnail.png'), |
| 1207 | 1249 | ); |
| 1250 | + } |
|
| 1208 | 1251 | |
| 1209 | 1252 | $context['available_themes'][$id_theme]['selected_variant'] = isset($_GET['vrt']) ? $_GET['vrt'] : (!empty($variant_preferences[$id_theme]) ? $variant_preferences[$id_theme] : (!empty($settings['default_variant']) ? $settings['default_variant'] : $settings['theme_variants'][0])); |
| 1210 | - if (!isset($context['available_themes'][$id_theme]['variants'][$context['available_themes'][$id_theme]['selected_variant']]['thumbnail'])) |
|
| 1211 | - $context['available_themes'][$id_theme]['selected_variant'] = $settings['theme_variants'][0]; |
|
| 1253 | + if (!isset($context['available_themes'][$id_theme]['variants'][$context['available_themes'][$id_theme]['selected_variant']]['thumbnail'])) { |
|
| 1254 | + $context['available_themes'][$id_theme]['selected_variant'] = $settings['theme_variants'][0]; |
|
| 1255 | + } |
|
| 1212 | 1256 | |
| 1213 | 1257 | $context['available_themes'][$id_theme]['thumbnail_href'] = $context['available_themes'][$id_theme]['variants'][$context['available_themes'][$id_theme]['selected_variant']]['thumbnail']; |
| 1214 | 1258 | // Allow themes to override the text. |
@@ -1224,8 +1268,9 @@ discard block |
||
| 1224 | 1268 | // As long as we're not doing the default theme... |
| 1225 | 1269 | if (!isset($_REQUEST['u']) || $_REQUEST['u'] >= 0) |
| 1226 | 1270 | { |
| 1227 | - if ($guest_theme != 0) |
|
| 1228 | - $context['available_themes'][0] = $context['available_themes'][$guest_theme]; |
|
| 1271 | + if ($guest_theme != 0) { |
|
| 1272 | + $context['available_themes'][0] = $context['available_themes'][$guest_theme]; |
|
| 1273 | + } |
|
| 1229 | 1274 | |
| 1230 | 1275 | $context['available_themes'][0]['id'] = 0; |
| 1231 | 1276 | $context['available_themes'][0]['name'] = $txt['theme_forum_default']; |
@@ -1274,14 +1319,16 @@ discard block |
||
| 1274 | 1319 | $action = $smcFunc['htmlspecialchars'](trim($_GET['do'])); |
| 1275 | 1320 | |
| 1276 | 1321 | // Got any info from the specific form? |
| 1277 | - if (!isset($_POST['save_' . $action])) |
|
| 1278 | - fatal_lang_error('theme_install_no_action', false); |
|
| 1322 | + if (!isset($_POST['save_' . $action])) { |
|
| 1323 | + fatal_lang_error('theme_install_no_action', false); |
|
| 1324 | + } |
|
| 1279 | 1325 | |
| 1280 | 1326 | validateToken('admin-t-' . $action); |
| 1281 | 1327 | |
| 1282 | 1328 | // Hopefully the themes directory is writable, or we might have a problem. |
| 1283 | - if (!is_writable($themedir)) |
|
| 1284 | - fatal_lang_error('theme_install_write_error', 'critical'); |
|
| 1329 | + if (!is_writable($themedir)) { |
|
| 1330 | + fatal_lang_error('theme_install_write_error', 'critical'); |
|
| 1331 | + } |
|
| 1285 | 1332 | |
| 1286 | 1333 | // Call the function and handle the result. |
| 1287 | 1334 | $result = $subActions[$action](); |
@@ -1296,9 +1343,10 @@ discard block |
||
| 1296 | 1343 | } |
| 1297 | 1344 | |
| 1298 | 1345 | // Nope, show a nice error. |
| 1299 | - else |
|
| 1300 | - fatal_lang_error('theme_install_no_action', false); |
|
| 1301 | -} |
|
| 1346 | + else { |
|
| 1347 | + fatal_lang_error('theme_install_no_action', false); |
|
| 1348 | + } |
|
| 1349 | + } |
|
| 1302 | 1350 | |
| 1303 | 1351 | /** |
| 1304 | 1352 | * Installs a theme from a theme package. |
@@ -1314,8 +1362,9 @@ discard block |
||
| 1314 | 1362 | $dirtemp = $themedir . '/temp'; |
| 1315 | 1363 | |
| 1316 | 1364 | // Make sure the temp dir doesn't already exist |
| 1317 | - if (file_exists($dirtemp)) |
|
| 1318 | - remove_dir($dirtemp); |
|
| 1365 | + if (file_exists($dirtemp)) { |
|
| 1366 | + remove_dir($dirtemp); |
|
| 1367 | + } |
|
| 1319 | 1368 | |
| 1320 | 1369 | // Create the temp dir. |
| 1321 | 1370 | mkdir($dirtemp, 0777); |
@@ -1327,17 +1376,20 @@ discard block |
||
| 1327 | 1376 | smf_chmod($dirtemp, '0755'); |
| 1328 | 1377 | |
| 1329 | 1378 | // How about now? |
| 1330 | - if (!is_writable($dirtemp)) |
|
| 1331 | - fatal_lang_error('theme_install_write_error', 'critical'); |
|
| 1379 | + if (!is_writable($dirtemp)) { |
|
| 1380 | + fatal_lang_error('theme_install_write_error', 'critical'); |
|
| 1381 | + } |
|
| 1332 | 1382 | } |
| 1333 | 1383 | |
| 1334 | 1384 | // This happens when the admin session is gone and the user has to login again. |
| 1335 | - if (!isset($_FILES) || !isset($_FILES['theme_gz']) || empty($_FILES['theme_gz'])) |
|
| 1336 | - redirectexit('action=admin;area=theme;sa=admin;' . $context['session_var'] . '=' . $context['session_id']); |
|
| 1385 | + if (!isset($_FILES) || !isset($_FILES['theme_gz']) || empty($_FILES['theme_gz'])) { |
|
| 1386 | + redirectexit('action=admin;area=theme;sa=admin;' . $context['session_var'] . '=' . $context['session_id']); |
|
| 1387 | + } |
|
| 1337 | 1388 | |
| 1338 | 1389 | // Another error check layer, something went wrong with the upload. |
| 1339 | - if (isset($_FILES['theme_gz']['error']) && $_FILES['theme_gz']['error'] != 0) |
|
| 1340 | - fatal_lang_error('theme_install_error_file_' . $_FILES['theme_gz']['error'], false); |
|
| 1390 | + if (isset($_FILES['theme_gz']['error']) && $_FILES['theme_gz']['error'] != 0) { |
|
| 1391 | + fatal_lang_error('theme_install_error_file_' . $_FILES['theme_gz']['error'], false); |
|
| 1392 | + } |
|
| 1341 | 1393 | |
| 1342 | 1394 | // Get the theme's name. |
| 1343 | 1395 | $name = pathinfo($_FILES['theme_gz']['name'], PATHINFO_FILENAME); |
@@ -1368,11 +1420,10 @@ discard block |
||
| 1368 | 1420 | |
| 1369 | 1421 | // return all the info. |
| 1370 | 1422 | return $context['to_install']; |
| 1423 | + } else { |
|
| 1424 | + fatal_lang_error('theme_install_error_title', false); |
|
| 1425 | + } |
|
| 1371 | 1426 | } |
| 1372 | - |
|
| 1373 | - else |
|
| 1374 | - fatal_lang_error('theme_install_error_title', false); |
|
| 1375 | -} |
|
| 1376 | 1427 | |
| 1377 | 1428 | /** |
| 1378 | 1429 | * Makes a copy from the default theme, assigns a name for it and installs it. |
@@ -1386,15 +1437,17 @@ discard block |
||
| 1386 | 1437 | global $forum_version; |
| 1387 | 1438 | |
| 1388 | 1439 | // There's gotta be something to work with. |
| 1389 | - if (!isset($_REQUEST['copy']) || empty($_REQUEST['copy'])) |
|
| 1390 | - fatal_lang_error('theme_install_error_title', false); |
|
| 1440 | + if (!isset($_REQUEST['copy']) || empty($_REQUEST['copy'])) { |
|
| 1441 | + fatal_lang_error('theme_install_error_title', false); |
|
| 1442 | + } |
|
| 1391 | 1443 | |
| 1392 | 1444 | // Get a cleaner version. |
| 1393 | 1445 | $name = preg_replace('~[^A-Za-z0-9_\- ]~', '', $_REQUEST['copy']); |
| 1394 | 1446 | |
| 1395 | 1447 | // Is there a theme already named like this? |
| 1396 | - if (file_exists($themedir . '/' . $name)) |
|
| 1397 | - fatal_lang_error('theme_install_already_dir', false); |
|
| 1448 | + if (file_exists($themedir . '/' . $name)) { |
|
| 1449 | + fatal_lang_error('theme_install_already_dir', false); |
|
| 1450 | + } |
|
| 1398 | 1451 | |
| 1399 | 1452 | // This is a brand new theme so set all possible values. |
| 1400 | 1453 | $context['to_install'] = array( |
@@ -1414,8 +1467,9 @@ discard block |
||
| 1414 | 1467 | |
| 1415 | 1468 | // Buy some time. |
| 1416 | 1469 | @set_time_limit(600); |
| 1417 | - if (function_exists('apache_reset_timeout')) |
|
| 1418 | - @apache_reset_timeout(); |
|
| 1470 | + if (function_exists('apache_reset_timeout')) { |
|
| 1471 | + @apache_reset_timeout(); |
|
| 1472 | + } |
|
| 1419 | 1473 | |
| 1420 | 1474 | // Create subdirectories for css and javascript files. |
| 1421 | 1475 | mkdir($context['to_install']['theme_dir'] . '/css', 0777); |
@@ -1451,12 +1505,13 @@ discard block |
||
| 1451 | 1505 | |
| 1452 | 1506 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1453 | 1507 | { |
| 1454 | - if ($row['variable'] == 'theme_templates') |
|
| 1455 | - $theme_templates = $row['value']; |
|
| 1456 | - elseif ($row['variable'] == 'theme_layers') |
|
| 1457 | - $theme_layers = $row['value']; |
|
| 1458 | - else |
|
| 1459 | - continue; |
|
| 1508 | + if ($row['variable'] == 'theme_templates') { |
|
| 1509 | + $theme_templates = $row['value']; |
|
| 1510 | + } elseif ($row['variable'] == 'theme_layers') { |
|
| 1511 | + $theme_layers = $row['value']; |
|
| 1512 | + } else { |
|
| 1513 | + continue; |
|
| 1514 | + } |
|
| 1460 | 1515 | } |
| 1461 | 1516 | |
| 1462 | 1517 | $smcFunc['db_free_result']($request); |
@@ -1515,12 +1570,14 @@ discard block |
||
| 1515 | 1570 | global $themedir, $themeurl, $context; |
| 1516 | 1571 | |
| 1517 | 1572 | // Cannot use the theme dir as a theme dir. |
| 1518 | - if (!isset($_REQUEST['theme_dir']) || empty($_REQUEST['theme_dir']) || rtrim(realpath($_REQUEST['theme_dir']), '/\\') == realpath($themedir)) |
|
| 1519 | - fatal_lang_error('theme_install_invalid_dir', false); |
|
| 1573 | + if (!isset($_REQUEST['theme_dir']) || empty($_REQUEST['theme_dir']) || rtrim(realpath($_REQUEST['theme_dir']), '/\\') == realpath($themedir)) { |
|
| 1574 | + fatal_lang_error('theme_install_invalid_dir', false); |
|
| 1575 | + } |
|
| 1520 | 1576 | |
| 1521 | 1577 | // Check is there is "something" on the dir. |
| 1522 | - elseif (!is_dir($_REQUEST['theme_dir']) || !file_exists($_REQUEST['theme_dir'] . '/theme_info.xml')) |
|
| 1523 | - fatal_lang_error('theme_install_error', false); |
|
| 1578 | + elseif (!is_dir($_REQUEST['theme_dir']) || !file_exists($_REQUEST['theme_dir'] . '/theme_info.xml')) { |
|
| 1579 | + fatal_lang_error('theme_install_error', false); |
|
| 1580 | + } |
|
| 1524 | 1581 | |
| 1525 | 1582 | $name = basename($_REQUEST['theme_dir']); |
| 1526 | 1583 | $name = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $name); |
@@ -1564,24 +1621,27 @@ discard block |
||
| 1564 | 1621 | } |
| 1565 | 1622 | |
| 1566 | 1623 | // Any special layers? |
| 1567 | - if (isset($settings['catch_action']['layers'])) |
|
| 1568 | - $context['template_layers'] = $settings['catch_action']['layers']; |
|
| 1624 | + if (isset($settings['catch_action']['layers'])) { |
|
| 1625 | + $context['template_layers'] = $settings['catch_action']['layers']; |
|
| 1626 | + } |
|
| 1569 | 1627 | |
| 1570 | 1628 | // Any function to call? |
| 1571 | 1629 | if (isset($settings['catch_action']['function'])) |
| 1572 | 1630 | { |
| 1573 | 1631 | $hook = $settings['catch_action']['function']; |
| 1574 | 1632 | |
| 1575 | - if (!isset($settings['catch_action']['filename'])) |
|
| 1576 | - $settings['catch_action']['filename'] = ''; |
|
| 1633 | + if (!isset($settings['catch_action']['filename'])) { |
|
| 1634 | + $settings['catch_action']['filename'] = ''; |
|
| 1635 | + } |
|
| 1577 | 1636 | |
| 1578 | 1637 | add_integration_function('integrate_wrap_action', $hook, false, $settings['catch_action']['filename'], false); |
| 1579 | 1638 | call_integration_hook('integrate_wrap_action'); |
| 1580 | 1639 | } |
| 1581 | 1640 | // And finally, the main sub template ;). |
| 1582 | - if (isset($settings['catch_action']['sub_template'])) |
|
| 1583 | - $context['sub_template'] = $settings['catch_action']['sub_template']; |
|
| 1584 | -} |
|
| 1641 | + if (isset($settings['catch_action']['sub_template'])) { |
|
| 1642 | + $context['sub_template'] = $settings['catch_action']['sub_template']; |
|
| 1643 | + } |
|
| 1644 | + } |
|
| 1585 | 1645 | |
| 1586 | 1646 | /** |
| 1587 | 1647 | * Set an option via javascript. |
@@ -1600,12 +1660,14 @@ discard block |
||
| 1600 | 1660 | checkSession('get'); |
| 1601 | 1661 | |
| 1602 | 1662 | // This good-for-nothing pixel is being used to keep the session alive. |
| 1603 | - if (empty($_GET['var']) || !isset($_GET['val'])) |
|
| 1604 | - redirectexit($settings['images_url'] . '/blank.png'); |
|
| 1663 | + if (empty($_GET['var']) || !isset($_GET['val'])) { |
|
| 1664 | + redirectexit($settings['images_url'] . '/blank.png'); |
|
| 1665 | + } |
|
| 1605 | 1666 | |
| 1606 | 1667 | // Sorry, guests can't go any further than this. |
| 1607 | - if ($user_info['is_guest'] || $user_info['id'] == 0) |
|
| 1608 | - obExit(false); |
|
| 1668 | + if ($user_info['is_guest'] || $user_info['id'] == 0) { |
|
| 1669 | + obExit(false); |
|
| 1670 | + } |
|
| 1609 | 1671 | |
| 1610 | 1672 | $reservedVars = array( |
| 1611 | 1673 | 'actual_theme_url', |
@@ -1628,8 +1690,9 @@ discard block |
||
| 1628 | 1690 | ); |
| 1629 | 1691 | |
| 1630 | 1692 | // Can't change reserved vars. |
| 1631 | - if (in_array(strtolower($_GET['var']), $reservedVars)) |
|
| 1632 | - redirectexit($settings['images_url'] . '/blank.png'); |
|
| 1693 | + if (in_array(strtolower($_GET['var']), $reservedVars)) { |
|
| 1694 | + redirectexit($settings['images_url'] . '/blank.png'); |
|
| 1695 | + } |
|
| 1633 | 1696 | |
| 1634 | 1697 | // Use a specific theme? |
| 1635 | 1698 | if (isset($_GET['th']) || isset($_GET['id'])) |
@@ -1645,8 +1708,9 @@ discard block |
||
| 1645 | 1708 | { |
| 1646 | 1709 | $options['admin_preferences'] = !empty($options['admin_preferences']) ? $smcFunc['json_decode']($options['admin_preferences'], true) : array(); |
| 1647 | 1710 | // New thingy... |
| 1648 | - if (isset($_GET['admin_key']) && strlen($_GET['admin_key']) < 5) |
|
| 1649 | - $options['admin_preferences'][$_GET['admin_key']] = $_GET['val']; |
|
| 1711 | + if (isset($_GET['admin_key']) && strlen($_GET['admin_key']) < 5) { |
|
| 1712 | + $options['admin_preferences'][$_GET['admin_key']] = $_GET['val']; |
|
| 1713 | + } |
|
| 1650 | 1714 | |
| 1651 | 1715 | // Change the value to be something nice, |
| 1652 | 1716 | $_GET['val'] = $smcFunc['json_encode']($options['admin_preferences']); |
@@ -1676,8 +1740,9 @@ discard block |
||
| 1676 | 1740 | global $context, $scripturl, $boarddir, $smcFunc, $txt; |
| 1677 | 1741 | |
| 1678 | 1742 | // @todo Should this be removed? |
| 1679 | - if (isset($_REQUEST['preview'])) |
|
| 1680 | - die('die() with fire'); |
|
| 1743 | + if (isset($_REQUEST['preview'])) { |
|
| 1744 | + die('die() with fire'); |
|
| 1745 | + } |
|
| 1681 | 1746 | |
| 1682 | 1747 | isAllowedTo('admin_forum'); |
| 1683 | 1748 | loadTemplate('Themes'); |
@@ -1691,11 +1756,11 @@ discard block |
||
| 1691 | 1756 | foreach ($context['themes'] as $key => $theme) |
| 1692 | 1757 | { |
| 1693 | 1758 | // There has to be a Settings template! |
| 1694 | - if (!file_exists($theme['theme_dir'] . '/index.template.php') && !file_exists($theme['theme_dir'] . '/css/index.css')) |
|
| 1695 | - unset($context['themes'][$key]); |
|
| 1696 | - |
|
| 1697 | - else |
|
| 1698 | - $context['themes'][$key]['can_edit_style'] = file_exists($theme['theme_dir'] . '/css/index.css'); |
|
| 1759 | + if (!file_exists($theme['theme_dir'] . '/index.template.php') && !file_exists($theme['theme_dir'] . '/css/index.css')) { |
|
| 1760 | + unset($context['themes'][$key]); |
|
| 1761 | + } else { |
|
| 1762 | + $context['themes'][$key]['can_edit_style'] = file_exists($theme['theme_dir'] . '/css/index.css'); |
|
| 1763 | + } |
|
| 1699 | 1764 | } |
| 1700 | 1765 | |
| 1701 | 1766 | $context['sub_template'] = 'edit_list'; |
@@ -1710,22 +1775,24 @@ discard block |
||
| 1710 | 1775 | $context['theme_id'] = $currentTheme['id']; |
| 1711 | 1776 | $context['browse_title'] = sprintf($txt['themeadmin_browsing_theme'], $currentTheme['name']); |
| 1712 | 1777 | |
| 1713 | - if (!file_exists($currentTheme['theme_dir'] . '/index.template.php') && !file_exists($currentTheme['theme_dir'] . '/css/index.css')) |
|
| 1714 | - fatal_lang_error('theme_edit_missing', false); |
|
| 1778 | + if (!file_exists($currentTheme['theme_dir'] . '/index.template.php') && !file_exists($currentTheme['theme_dir'] . '/css/index.css')) { |
|
| 1779 | + fatal_lang_error('theme_edit_missing', false); |
|
| 1780 | + } |
|
| 1715 | 1781 | |
| 1716 | 1782 | if (!isset($_REQUEST['filename'])) |
| 1717 | 1783 | { |
| 1718 | 1784 | if (isset($_GET['directory'])) |
| 1719 | 1785 | { |
| 1720 | - if (substr($_GET['directory'], 0, 1) == '.') |
|
| 1721 | - $_GET['directory'] = ''; |
|
| 1722 | - else |
|
| 1786 | + if (substr($_GET['directory'], 0, 1) == '.') { |
|
| 1787 | + $_GET['directory'] = ''; |
|
| 1788 | + } else |
|
| 1723 | 1789 | { |
| 1724 | 1790 | $_GET['directory'] = preg_replace(array('~^[\./\\:\0\n\r]+~', '~[\\\\]~', '~/[\./]+~'), array('', '/', '/'), $_GET['directory']); |
| 1725 | 1791 | |
| 1726 | 1792 | $temp = realpath($currentTheme['theme_dir'] . '/' . $_GET['directory']); |
| 1727 | - if (empty($temp) || substr($temp, 0, strlen(realpath($currentTheme['theme_dir']))) != realpath($currentTheme['theme_dir'])) |
|
| 1728 | - $_GET['directory'] = ''; |
|
| 1793 | + if (empty($temp) || substr($temp, 0, strlen(realpath($currentTheme['theme_dir']))) != realpath($currentTheme['theme_dir'])) { |
|
| 1794 | + $_GET['directory'] = ''; |
|
| 1795 | + } |
|
| 1729 | 1796 | } |
| 1730 | 1797 | } |
| 1731 | 1798 | |
@@ -1744,37 +1811,39 @@ discard block |
||
| 1744 | 1811 | 'href' => $scripturl . '?action=admin;area=theme;th=' . $_GET['th'] . ';' . $context['session_var'] . '=' . $context['session_id'] . ';sa=edit;directory=' . $temp, |
| 1745 | 1812 | 'size' => '', |
| 1746 | 1813 | )); |
| 1814 | + } else { |
|
| 1815 | + $context['theme_files'] = get_file_listing($currentTheme['theme_dir'], ''); |
|
| 1747 | 1816 | } |
| 1748 | - else |
|
| 1749 | - $context['theme_files'] = get_file_listing($currentTheme['theme_dir'], ''); |
|
| 1750 | 1817 | |
| 1751 | 1818 | $context['sub_template'] = 'edit_browse'; |
| 1752 | 1819 | |
| 1753 | 1820 | return; |
| 1754 | - } |
|
| 1755 | - else |
|
| 1821 | + } else |
|
| 1756 | 1822 | { |
| 1757 | - if (substr($_REQUEST['filename'], 0, 1) == '.') |
|
| 1758 | - $_REQUEST['filename'] = ''; |
|
| 1759 | - else |
|
| 1823 | + if (substr($_REQUEST['filename'], 0, 1) == '.') { |
|
| 1824 | + $_REQUEST['filename'] = ''; |
|
| 1825 | + } else |
|
| 1760 | 1826 | { |
| 1761 | 1827 | $_REQUEST['filename'] = preg_replace(array('~^[\./\\:\0\n\r]+~', '~[\\\\]~', '~/[\./]+~'), array('', '/', '/'), $_REQUEST['filename']); |
| 1762 | 1828 | |
| 1763 | 1829 | $temp = realpath($currentTheme['theme_dir'] . '/' . $_REQUEST['filename']); |
| 1764 | - if (empty($temp) || substr($temp, 0, strlen(realpath($currentTheme['theme_dir']))) != realpath($currentTheme['theme_dir'])) |
|
| 1765 | - $_REQUEST['filename'] = ''; |
|
| 1830 | + if (empty($temp) || substr($temp, 0, strlen(realpath($currentTheme['theme_dir']))) != realpath($currentTheme['theme_dir'])) { |
|
| 1831 | + $_REQUEST['filename'] = ''; |
|
| 1832 | + } |
|
| 1766 | 1833 | } |
| 1767 | 1834 | |
| 1768 | - if (empty($_REQUEST['filename'])) |
|
| 1769 | - fatal_lang_error('theme_edit_missing', false); |
|
| 1835 | + if (empty($_REQUEST['filename'])) { |
|
| 1836 | + fatal_lang_error('theme_edit_missing', false); |
|
| 1837 | + } |
|
| 1770 | 1838 | } |
| 1771 | 1839 | |
| 1772 | 1840 | if (isset($_POST['save'])) |
| 1773 | 1841 | { |
| 1774 | 1842 | if (checkSession('post', '', false) == '' && validateToken('admin-te-' . md5($_GET['th'] . '-' . $_REQUEST['filename']), 'post', false) == true) |
| 1775 | 1843 | { |
| 1776 | - if (is_array($_POST['entire_file'])) |
|
| 1777 | - $_POST['entire_file'] = implode("\n", $_POST['entire_file']); |
|
| 1844 | + if (is_array($_POST['entire_file'])) { |
|
| 1845 | + $_POST['entire_file'] = implode("\n", $_POST['entire_file']); |
|
| 1846 | + } |
|
| 1778 | 1847 | |
| 1779 | 1848 | $_POST['entire_file'] = rtrim(strtr($_POST['entire_file'], array("\r" => '', ' ' => "\t"))); |
| 1780 | 1849 | |
@@ -1786,10 +1855,11 @@ discard block |
||
| 1786 | 1855 | fclose($fp); |
| 1787 | 1856 | |
| 1788 | 1857 | $error = @file_get_contents($currentTheme['theme_url'] . '/tmp_' . session_id() . '.php'); |
| 1789 | - if (preg_match('~ <b>(\d+)</b><br( /)?' . '>$~i', $error) != 0) |
|
| 1790 | - $error_file = $currentTheme['theme_dir'] . '/tmp_' . session_id() . '.php'; |
|
| 1791 | - else |
|
| 1792 | - unlink($currentTheme['theme_dir'] . '/tmp_' . session_id() . '.php'); |
|
| 1858 | + if (preg_match('~ <b>(\d+)</b><br( /)?' . '>$~i', $error) != 0) { |
|
| 1859 | + $error_file = $currentTheme['theme_dir'] . '/tmp_' . session_id() . '.php'; |
|
| 1860 | + } else { |
|
| 1861 | + unlink($currentTheme['theme_dir'] . '/tmp_' . session_id() . '.php'); |
|
| 1862 | + } |
|
| 1793 | 1863 | } |
| 1794 | 1864 | |
| 1795 | 1865 | if (!isset($error_file)) |
@@ -1810,10 +1880,11 @@ discard block |
||
| 1810 | 1880 | $context['sub_template'] = 'edit_file'; |
| 1811 | 1881 | |
| 1812 | 1882 | // Recycle the submitted data. |
| 1813 | - if (is_array($_POST['entire_file'])) |
|
| 1814 | - $context['entire_file'] = $smcFunc['htmlspecialchars'](implode("\n", $_POST['entire_file'])); |
|
| 1815 | - else |
|
| 1816 | - $context['entire_file'] = $smcFunc['htmlspecialchars']($_POST['entire_file']); |
|
| 1883 | + if (is_array($_POST['entire_file'])) { |
|
| 1884 | + $context['entire_file'] = $smcFunc['htmlspecialchars'](implode("\n", $_POST['entire_file'])); |
|
| 1885 | + } else { |
|
| 1886 | + $context['entire_file'] = $smcFunc['htmlspecialchars']($_POST['entire_file']); |
|
| 1887 | + } |
|
| 1817 | 1888 | |
| 1818 | 1889 | $context['edit_filename'] = $smcFunc['htmlspecialchars']($_POST['filename']); |
| 1819 | 1890 | |
@@ -1836,17 +1907,17 @@ discard block |
||
| 1836 | 1907 | $context['sub_template'] = 'edit_style'; |
| 1837 | 1908 | |
| 1838 | 1909 | $context['entire_file'] = $smcFunc['htmlspecialchars'](strtr(file_get_contents($currentTheme['theme_dir'] . '/' . $_REQUEST['filename']), array("\t" => ' '))); |
| 1839 | - } |
|
| 1840 | - elseif (substr($_REQUEST['filename'], -13) == '.template.php') |
|
| 1910 | + } elseif (substr($_REQUEST['filename'], -13) == '.template.php') |
|
| 1841 | 1911 | { |
| 1842 | 1912 | $context['sub_template'] = 'edit_template'; |
| 1843 | 1913 | |
| 1844 | - if (!isset($error_file)) |
|
| 1845 | - $file_data = file($currentTheme['theme_dir'] . '/' . $_REQUEST['filename']); |
|
| 1846 | - else |
|
| 1914 | + if (!isset($error_file)) { |
|
| 1915 | + $file_data = file($currentTheme['theme_dir'] . '/' . $_REQUEST['filename']); |
|
| 1916 | + } else |
|
| 1847 | 1917 | { |
| 1848 | - if (preg_match('~(<b>.+?</b>:.+?<b>).+?(</b>.+?<b>\d+</b>)<br( /)?' . '>$~i', $error, $match) != 0) |
|
| 1849 | - $context['parse_error'] = $match[1] . $_REQUEST['filename'] . $match[2]; |
|
| 1918 | + if (preg_match('~(<b>.+?</b>:.+?<b>).+?(</b>.+?<b>\d+</b>)<br( /)?' . '>$~i', $error, $match) != 0) { |
|
| 1919 | + $context['parse_error'] = $match[1] . $_REQUEST['filename'] . $match[2]; |
|
| 1920 | + } |
|
| 1850 | 1921 | $file_data = file($error_file); |
| 1851 | 1922 | unlink($error_file); |
| 1852 | 1923 | } |
@@ -1860,8 +1931,9 @@ discard block |
||
| 1860 | 1931 | // Try to format the functions a little nicer... |
| 1861 | 1932 | $context['file_parts'][$j]['data'] = trim($context['file_parts'][$j]['data']) . "\n"; |
| 1862 | 1933 | |
| 1863 | - if (empty($context['file_parts'][$j]['lines'])) |
|
| 1864 | - unset($context['file_parts'][$j]); |
|
| 1934 | + if (empty($context['file_parts'][$j]['lines'])) { |
|
| 1935 | + unset($context['file_parts'][$j]); |
|
| 1936 | + } |
|
| 1865 | 1937 | $context['file_parts'][++$j] = array('lines' => 0, 'line' => $i + 1, 'data' => ''); |
| 1866 | 1938 | } |
| 1867 | 1939 | |
@@ -1870,8 +1942,7 @@ discard block |
||
| 1870 | 1942 | } |
| 1871 | 1943 | |
| 1872 | 1944 | $context['entire_file'] = $smcFunc['htmlspecialchars'](strtr(implode('', $file_data), array("\t" => ' '))); |
| 1873 | - } |
|
| 1874 | - else |
|
| 1945 | + } else |
|
| 1875 | 1946 | { |
| 1876 | 1947 | $context['sub_template'] = 'edit_file'; |
| 1877 | 1948 | |
@@ -1897,8 +1968,9 @@ discard block |
||
| 1897 | 1968 | |
| 1898 | 1969 | $_GET['th'] = isset($_GET['th']) ? (int) $_GET['th'] : (int) $_GET['id']; |
| 1899 | 1970 | |
| 1900 | - if (empty($_GET['th'])) |
|
| 1901 | - fatal_lang_error('theme_install_invalid_id'); |
|
| 1971 | + if (empty($_GET['th'])) { |
|
| 1972 | + fatal_lang_error('theme_install_invalid_id'); |
|
| 1973 | + } |
|
| 1902 | 1974 | |
| 1903 | 1975 | // Get the theme info. |
| 1904 | 1976 | $theme = get_single_theme($_GET['th']); |
@@ -1906,25 +1978,24 @@ discard block |
||
| 1906 | 1978 | |
| 1907 | 1979 | if (isset($_REQUEST['template']) && preg_match('~[\./\\\\:\0]~', $_REQUEST['template']) == 0) |
| 1908 | 1980 | { |
| 1909 | - if (file_exists($settings['default_theme_dir'] . '/' . $_REQUEST['template'] . '.template.php')) |
|
| 1910 | - $filename = $settings['default_theme_dir'] . '/' . $_REQUEST['template'] . '.template.php'; |
|
| 1911 | - |
|
| 1912 | - else |
|
| 1913 | - fatal_lang_error('no_access', false); |
|
| 1981 | + if (file_exists($settings['default_theme_dir'] . '/' . $_REQUEST['template'] . '.template.php')) { |
|
| 1982 | + $filename = $settings['default_theme_dir'] . '/' . $_REQUEST['template'] . '.template.php'; |
|
| 1983 | + } else { |
|
| 1984 | + fatal_lang_error('no_access', false); |
|
| 1985 | + } |
|
| 1914 | 1986 | |
| 1915 | 1987 | $fp = fopen($theme['theme_dir'] . '/' . $_REQUEST['template'] . '.template.php', 'w'); |
| 1916 | 1988 | fwrite($fp, file_get_contents($filename)); |
| 1917 | 1989 | fclose($fp); |
| 1918 | 1990 | |
| 1919 | 1991 | redirectexit('action=admin;area=theme;th=' . $context['theme_id'] . ';' . $context['session_var'] . '=' . $context['session_id'] . ';sa=copy'); |
| 1920 | - } |
|
| 1921 | - elseif (isset($_REQUEST['lang_file']) && preg_match('~^[^\./\\\\:\0]\.[^\./\\\\:\0]$~', $_REQUEST['lang_file']) != 0) |
|
| 1992 | + } elseif (isset($_REQUEST['lang_file']) && preg_match('~^[^\./\\\\:\0]\.[^\./\\\\:\0]$~', $_REQUEST['lang_file']) != 0) |
|
| 1922 | 1993 | { |
| 1923 | - if (file_exists($settings['default_theme_dir'] . '/languages/' . $_REQUEST['template'] . '.php')) |
|
| 1924 | - $filename = $settings['default_theme_dir'] . '/languages/' . $_REQUEST['template'] . '.php'; |
|
| 1925 | - |
|
| 1926 | - else |
|
| 1927 | - fatal_lang_error('no_access', false); |
|
| 1994 | + if (file_exists($settings['default_theme_dir'] . '/languages/' . $_REQUEST['template'] . '.php')) { |
|
| 1995 | + $filename = $settings['default_theme_dir'] . '/languages/' . $_REQUEST['template'] . '.php'; |
|
| 1996 | + } else { |
|
| 1997 | + fatal_lang_error('no_access', false); |
|
| 1998 | + } |
|
| 1928 | 1999 | |
| 1929 | 2000 | $fp = fopen($theme['theme_dir'] . '/languages/' . $_REQUEST['lang_file'] . '.php', 'w'); |
| 1930 | 2001 | fwrite($fp, file_get_contents($filename)); |
@@ -1939,16 +2010,18 @@ discard block |
||
| 1939 | 2010 | $dir = dir($settings['default_theme_dir']); |
| 1940 | 2011 | while ($entry = $dir->read()) |
| 1941 | 2012 | { |
| 1942 | - if (substr($entry, -13) == '.template.php') |
|
| 1943 | - $templates[] = substr($entry, 0, -13); |
|
| 2013 | + if (substr($entry, -13) == '.template.php') { |
|
| 2014 | + $templates[] = substr($entry, 0, -13); |
|
| 2015 | + } |
|
| 1944 | 2016 | } |
| 1945 | 2017 | $dir->close(); |
| 1946 | 2018 | |
| 1947 | 2019 | $dir = dir($settings['default_theme_dir'] . '/languages'); |
| 1948 | 2020 | while ($entry = $dir->read()) |
| 1949 | 2021 | { |
| 1950 | - if (preg_match('~^([^\.]+\.[^\.]+)\.php$~', $entry, $matches)) |
|
| 1951 | - $lang_files[] = $matches[1]; |
|
| 2022 | + if (preg_match('~^([^\.]+\.[^\.]+)\.php$~', $entry, $matches)) { |
|
| 2023 | + $lang_files[] = $matches[1]; |
|
| 2024 | + } |
|
| 1952 | 2025 | } |
| 1953 | 2026 | $dir->close(); |
| 1954 | 2027 | |
@@ -1956,21 +2029,23 @@ discard block |
||
| 1956 | 2029 | natcasesort($lang_files); |
| 1957 | 2030 | |
| 1958 | 2031 | $context['available_templates'] = array(); |
| 1959 | - foreach ($templates as $template) |
|
| 1960 | - $context['available_templates'][$template] = array( |
|
| 2032 | + foreach ($templates as $template) { |
|
| 2033 | + $context['available_templates'][$template] = array( |
|
| 1961 | 2034 | 'filename' => $template . '.template.php', |
| 1962 | 2035 | 'value' => $template, |
| 1963 | 2036 | 'already_exists' => false, |
| 1964 | 2037 | 'can_copy' => is_writable($theme['theme_dir']), |
| 1965 | 2038 | ); |
| 2039 | + } |
|
| 1966 | 2040 | $context['available_language_files'] = array(); |
| 1967 | - foreach ($lang_files as $file) |
|
| 1968 | - $context['available_language_files'][$file] = array( |
|
| 2041 | + foreach ($lang_files as $file) { |
|
| 2042 | + $context['available_language_files'][$file] = array( |
|
| 1969 | 2043 | 'filename' => $file . '.php', |
| 1970 | 2044 | 'value' => $file, |
| 1971 | 2045 | 'already_exists' => false, |
| 1972 | 2046 | 'can_copy' => file_exists($theme['theme_dir'] . '/languages') ? is_writable($theme['theme_dir'] . '/languages') : is_writable($theme['theme_dir']), |
| 1973 | 2047 | ); |
| 2048 | + } |
|
| 1974 | 2049 | |
| 1975 | 2050 | $dir = dir($theme['theme_dir']); |
| 1976 | 2051 | while ($entry = $dir->read()) |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 4 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * Truncate the GET array to a specified length |
@@ -26,24 +27,28 @@ discard block |
||
| 26 | 27 | function truncateArray($arr, $max_length=1900) |
| 27 | 28 | { |
| 28 | 29 | $curr_length = 0; |
| 29 | - foreach ($arr as $key => $value) |
|
| 30 | - if (is_array($value)) |
|
| 30 | + foreach ($arr as $key => $value) { |
|
| 31 | + if (is_array($value)) |
|
| 31 | 32 | foreach ($value as $key2 => $value2) |
| 32 | 33 | $curr_length += strlen ($value2); |
| 33 | - else |
|
| 34 | - $curr_length += strlen ($value); |
|
| 35 | - if ($curr_length <= $max_length) |
|
| 36 | - return $arr; |
|
| 37 | - else |
|
| 34 | + } |
|
| 35 | + else { |
|
| 36 | + $curr_length += strlen ($value); |
|
| 37 | + } |
|
| 38 | + if ($curr_length <= $max_length) { |
|
| 39 | + return $arr; |
|
| 40 | + } else |
|
| 38 | 41 | { |
| 39 | 42 | // Truncate each element's value to a reasonable length |
| 40 | 43 | $param_max = floor($max_length/count($arr)); |
| 41 | - foreach ($arr as $key => &$value) |
|
| 42 | - if (is_array($value)) |
|
| 44 | + foreach ($arr as $key => &$value) { |
|
| 45 | + if (is_array($value)) |
|
| 43 | 46 | foreach ($value as $key2 => &$value2) |
| 44 | 47 | $value2 = substr($value2, 0, $param_max - strlen($key) - 5); |
| 45 | - else |
|
| 46 | - $value = substr($value, 0, $param_max - strlen($key) - 5); |
|
| 48 | + } |
|
| 49 | + else { |
|
| 50 | + $value = substr($value, 0, $param_max - strlen($key) - 5); |
|
| 51 | + } |
|
| 47 | 52 | return $arr; |
| 48 | 53 | } |
| 49 | 54 | } |
@@ -65,8 +70,9 @@ discard block |
||
| 65 | 70 | // Don't update for every page - this isn't wholly accurate but who cares. |
| 66 | 71 | if ($topic) |
| 67 | 72 | { |
| 68 | - if (isset($_SESSION['last_topic_id']) && $_SESSION['last_topic_id'] == $topic) |
|
| 69 | - $force = false; |
|
| 73 | + if (isset($_SESSION['last_topic_id']) && $_SESSION['last_topic_id'] == $topic) { |
|
| 74 | + $force = false; |
|
| 75 | + } |
|
| 70 | 76 | $_SESSION['last_topic_id'] = $topic; |
| 71 | 77 | } |
| 72 | 78 | } |
@@ -79,22 +85,24 @@ discard block |
||
| 79 | 85 | } |
| 80 | 86 | |
| 81 | 87 | // Don't mark them as online more than every so often. |
| 82 | - if (!empty($_SESSION['log_time']) && $_SESSION['log_time'] >= (time() - 8) && !$force) |
|
| 83 | - return; |
|
| 88 | + if (!empty($_SESSION['log_time']) && $_SESSION['log_time'] >= (time() - 8) && !$force) { |
|
| 89 | + return; |
|
| 90 | + } |
|
| 84 | 91 | |
| 85 | 92 | if (!empty($modSettings['who_enabled'])) |
| 86 | 93 | { |
| 87 | 94 | $encoded_get = truncateArray($_GET) + array('USER_AGENT' => $_SERVER['HTTP_USER_AGENT']); |
| 88 | 95 | |
| 89 | 96 | // In the case of a dlattach action, session_var may not be set. |
| 90 | - if (!isset($context['session_var'])) |
|
| 91 | - $context['session_var'] = $_SESSION['session_var']; |
|
| 97 | + if (!isset($context['session_var'])) { |
|
| 98 | + $context['session_var'] = $_SESSION['session_var']; |
|
| 99 | + } |
|
| 92 | 100 | |
| 93 | 101 | unset($encoded_get['sesc'], $encoded_get[$context['session_var']]); |
| 94 | 102 | $encoded_get = $smcFunc['json_encode']($encoded_get); |
| 103 | + } else { |
|
| 104 | + $encoded_get = ''; |
|
| 95 | 105 | } |
| 96 | - else |
|
| 97 | - $encoded_get = ''; |
|
| 98 | 106 | |
| 99 | 107 | // Guests use 0, members use their session ID. |
| 100 | 108 | $session_id = $user_info['is_guest'] ? 'ip' . $user_info['ip'] : session_id(); |
@@ -134,17 +142,18 @@ discard block |
||
| 134 | 142 | ); |
| 135 | 143 | |
| 136 | 144 | // Guess it got deleted. |
| 137 | - if ($smcFunc['db_affected_rows']() == 0) |
|
| 145 | + if ($smcFunc['db_affected_rows']() == 0) { |
|
| 146 | + $_SESSION['log_time'] = 0; |
|
| 147 | + } |
|
| 148 | + } else { |
|
| 138 | 149 | $_SESSION['log_time'] = 0; |
| 139 | 150 | } |
| 140 | - else |
|
| 141 | - $_SESSION['log_time'] = 0; |
|
| 142 | 151 | |
| 143 | 152 | // Otherwise, we have to delete and insert. |
| 144 | 153 | if (empty($_SESSION['log_time'])) |
| 145 | 154 | { |
| 146 | - if ($do_delete || !empty($user_info['id'])) |
|
| 147 | - $smcFunc['db_query']('', ' |
|
| 155 | + if ($do_delete || !empty($user_info['id'])) { |
|
| 156 | + $smcFunc['db_query']('', ' |
|
| 148 | 157 | DELETE FROM {db_prefix}log_online |
| 149 | 158 | WHERE ' . ($do_delete ? 'log_time < {int:log_time}' : '') . ($do_delete && !empty($user_info['id']) ? ' OR ' : '') . (empty($user_info['id']) ? '' : 'id_member = {int:current_member}'), |
| 150 | 159 | array( |
@@ -152,6 +161,7 @@ discard block |
||
| 152 | 161 | 'log_time' => time() - $modSettings['lastActive'] * 60, |
| 153 | 162 | ) |
| 154 | 163 | ); |
| 164 | + } |
|
| 155 | 165 | |
| 156 | 166 | $smcFunc['db_insert']($do_delete ? 'ignore' : 'replace', |
| 157 | 167 | '{db_prefix}log_online', |
@@ -165,21 +175,24 @@ discard block |
||
| 165 | 175 | $_SESSION['log_time'] = time(); |
| 166 | 176 | |
| 167 | 177 | // Well, they are online now. |
| 168 | - if (empty($_SESSION['timeOnlineUpdated'])) |
|
| 169 | - $_SESSION['timeOnlineUpdated'] = time(); |
|
| 178 | + if (empty($_SESSION['timeOnlineUpdated'])) { |
|
| 179 | + $_SESSION['timeOnlineUpdated'] = time(); |
|
| 180 | + } |
|
| 170 | 181 | |
| 171 | 182 | // Set their login time, if not already done within the last minute. |
| 172 | 183 | if (SMF != 'SSI' && !empty($user_info['last_login']) && $user_info['last_login'] < time() - 60 && (!isset($_REQUEST['action']) || !in_array($_REQUEST['action'], array('.xml', 'login2', 'logintfa')))) |
| 173 | 184 | { |
| 174 | 185 | // Don't count longer than 15 minutes. |
| 175 | - if (time() - $_SESSION['timeOnlineUpdated'] > 60 * 15) |
|
| 176 | - $_SESSION['timeOnlineUpdated'] = time(); |
|
| 186 | + if (time() - $_SESSION['timeOnlineUpdated'] > 60 * 15) { |
|
| 187 | + $_SESSION['timeOnlineUpdated'] = time(); |
|
| 188 | + } |
|
| 177 | 189 | |
| 178 | 190 | $user_settings['total_time_logged_in'] += time() - $_SESSION['timeOnlineUpdated']; |
| 179 | 191 | updateMemberData($user_info['id'], array('last_login' => time(), 'member_ip' => $user_info['ip'], 'member_ip2' => $_SERVER['BAN_CHECK_IP'], 'total_time_logged_in' => $user_settings['total_time_logged_in'])); |
| 180 | 192 | |
| 181 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
| 182 | - cache_put_data('user_settings-' . $user_info['id'], $user_settings, 60); |
|
| 193 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
| 194 | + cache_put_data('user_settings-' . $user_info['id'], $user_settings, 60); |
|
| 195 | + } |
|
| 183 | 196 | |
| 184 | 197 | $user_info['total_time_logged_in'] += time() - $_SESSION['timeOnlineUpdated']; |
| 185 | 198 | $_SESSION['timeOnlineUpdated'] = time(); |
@@ -216,8 +229,7 @@ discard block |
||
| 216 | 229 | // Oops. maybe we have no more disk space left, or some other troubles, troubles... |
| 217 | 230 | // Copy the file back and run for your life! |
| 218 | 231 | @copy($cachedir . '/db_last_error_bak.php', $cachedir . '/db_last_error.php'); |
| 219 | - } |
|
| 220 | - else |
|
| 232 | + } else |
|
| 221 | 233 | { |
| 222 | 234 | @touch($boarddir . '/' . 'Settings.php'); |
| 223 | 235 | return true; |
@@ -237,22 +249,27 @@ discard block |
||
| 237 | 249 | global $db_cache, $db_count, $cache_misses, $cache_count_misses, $db_show_debug, $cache_count, $cache_hits, $smcFunc, $txt; |
| 238 | 250 | |
| 239 | 251 | // Add to Settings.php if you want to show the debugging information. |
| 240 | - if (!isset($db_show_debug) || $db_show_debug !== true || (isset($_GET['action']) && $_GET['action'] == 'viewquery')) |
|
| 241 | - return; |
|
| 252 | + if (!isset($db_show_debug) || $db_show_debug !== true || (isset($_GET['action']) && $_GET['action'] == 'viewquery')) { |
|
| 253 | + return; |
|
| 254 | + } |
|
| 242 | 255 | |
| 243 | - if (empty($_SESSION['view_queries'])) |
|
| 244 | - $_SESSION['view_queries'] = 0; |
|
| 245 | - if (empty($context['debug']['language_files'])) |
|
| 246 | - $context['debug']['language_files'] = array(); |
|
| 247 | - if (empty($context['debug']['sheets'])) |
|
| 248 | - $context['debug']['sheets'] = array(); |
|
| 256 | + if (empty($_SESSION['view_queries'])) { |
|
| 257 | + $_SESSION['view_queries'] = 0; |
|
| 258 | + } |
|
| 259 | + if (empty($context['debug']['language_files'])) { |
|
| 260 | + $context['debug']['language_files'] = array(); |
|
| 261 | + } |
|
| 262 | + if (empty($context['debug']['sheets'])) { |
|
| 263 | + $context['debug']['sheets'] = array(); |
|
| 264 | + } |
|
| 249 | 265 | |
| 250 | 266 | $files = get_included_files(); |
| 251 | 267 | $total_size = 0; |
| 252 | 268 | for ($i = 0, $n = count($files); $i < $n; $i++) |
| 253 | 269 | { |
| 254 | - if (file_exists($files[$i])) |
|
| 255 | - $total_size += filesize($files[$i]); |
|
| 270 | + if (file_exists($files[$i])) { |
|
| 271 | + $total_size += filesize($files[$i]); |
|
| 272 | + } |
|
| 256 | 273 | $files[$i] = strtr($files[$i], array($boarddir => '.', $sourcedir => '(Sources)', $cachedir => '(Cache)', $settings['actual_theme_dir'] => '(Current Theme)')); |
| 257 | 274 | } |
| 258 | 275 | |
@@ -261,8 +278,9 @@ discard block |
||
| 261 | 278 | { |
| 262 | 279 | foreach ($db_cache as $q => $query_data) |
| 263 | 280 | { |
| 264 | - if (!empty($query_data['w'])) |
|
| 265 | - $warnings += count($query_data['w']); |
|
| 281 | + if (!empty($query_data['w'])) { |
|
| 282 | + $warnings += count($query_data['w']); |
|
| 283 | + } |
|
| 266 | 284 | } |
| 267 | 285 | |
| 268 | 286 | $_SESSION['debug'] = &$db_cache; |
@@ -283,12 +301,14 @@ discard block |
||
| 283 | 301 | ',(isset($context['debug']['instances']) ? ($txt['debug_instances'] . (empty($context['debug']['instances']) ? 0 : count($context['debug']['instances'])) . ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_instances\').style.display = \'inline\'; this.style.display = \'none\'; return false;">'. $txt['debug_show'] .'</a><span id="debug_instances" style="display: none;"><em>'. implode('</em>, <em>', array_keys($context['debug']['instances'])) .'</em></span>)'. '<br>') : ''),' |
| 284 | 302 | ', $txt['debug_files_included'], count($files), ' - ', round($total_size / 1024), $txt['debug_kb'], ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_include_info\').style.display = \'inline\'; this.style.display = \'none\'; return false;">', $txt['debug_show'], '</a><span id="debug_include_info" style="display: none;"><em>', implode('</em>, <em>', $files), '</em></span>)<br>'; |
| 285 | 303 | |
| 286 | - if (function_exists('memory_get_peak_usage')) |
|
| 287 | - echo $txt['debug_memory_use'], ceil(memory_get_peak_usage() / 1024), $txt['debug_kb'], '<br>'; |
|
| 304 | + if (function_exists('memory_get_peak_usage')) { |
|
| 305 | + echo $txt['debug_memory_use'], ceil(memory_get_peak_usage() / 1024), $txt['debug_kb'], '<br>'; |
|
| 306 | + } |
|
| 288 | 307 | |
| 289 | 308 | // What tokens are active? |
| 290 | - if (isset($_SESSION['token'])) |
|
| 291 | - echo $txt['debug_tokens'] . '<em>' . implode(',</em> <em>', array_keys($_SESSION['token'])), '</em>.<br>'; |
|
| 309 | + if (isset($_SESSION['token'])) { |
|
| 310 | + echo $txt['debug_tokens'] . '<em>' . implode(',</em> <em>', array_keys($_SESSION['token'])), '</em>.<br>'; |
|
| 311 | + } |
|
| 292 | 312 | |
| 293 | 313 | if (!empty($modSettings['cache_enable']) && !empty($cache_hits)) |
| 294 | 314 | { |
@@ -302,10 +322,12 @@ discard block |
||
| 302 | 322 | $total_t += $cache_hit['t']; |
| 303 | 323 | $total_s += $cache_hit['s']; |
| 304 | 324 | } |
| 305 | - if (!isset($cache_misses)) |
|
| 306 | - $cache_misses = array(); |
|
| 307 | - foreach ($cache_misses as $missed) |
|
| 308 | - $missed_entries[] = $missed['d'] . ' ' . $missed['k']; |
|
| 325 | + if (!isset($cache_misses)) { |
|
| 326 | + $cache_misses = array(); |
|
| 327 | + } |
|
| 328 | + foreach ($cache_misses as $missed) { |
|
| 329 | + $missed_entries[] = $missed['d'] . ' ' . $missed['k']; |
|
| 330 | + } |
|
| 309 | 331 | |
| 310 | 332 | echo ' |
| 311 | 333 | ', $txt['debug_cache_hits'], $cache_count, ': ', sprintf($txt['debug_cache_seconds_bytes_total'], comma_format($total_t, 5), comma_format($total_s)), ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_cache_info\').style.display = \'inline\'; this.style.display = \'none\'; return false;">', $txt['debug_show'], '</a><span id="debug_cache_info" style="display: none;"><em>', implode('</em>, <em>', $entries), '</em></span>)<br> |
@@ -316,38 +338,44 @@ discard block |
||
| 316 | 338 | <a href="', $scripturl, '?action=viewquery" target="_blank" rel="noopener">', $warnings == 0 ? sprintf($txt['debug_queries_used'], (int) $db_count) : sprintf($txt['debug_queries_used_and_warnings'], (int) $db_count, $warnings), '</a><br> |
| 317 | 339 | <br>'; |
| 318 | 340 | |
| 319 | - if ($_SESSION['view_queries'] == 1 && !empty($db_cache)) |
|
| 320 | - foreach ($db_cache as $q => $query_data) |
|
| 341 | + if ($_SESSION['view_queries'] == 1 && !empty($db_cache)) { |
|
| 342 | + foreach ($db_cache as $q => $query_data) |
|
| 321 | 343 | { |
| 322 | 344 | $is_select = strpos(trim($query_data['q']), 'SELECT') === 0 || preg_match('~^INSERT(?: IGNORE)? INTO \w+(?:\s+\([^)]+\))?\s+SELECT .+$~s', trim($query_data['q'])) != 0; |
| 345 | + } |
|
| 323 | 346 | // Temporary tables created in earlier queries are not explainable. |
| 324 | 347 | if ($is_select) |
| 325 | 348 | { |
| 326 | - foreach (array('log_topics_unread', 'topics_posted_in', 'tmp_log_search_topics', 'tmp_log_search_messages') as $tmp) |
|
| 327 | - if (strpos(trim($query_data['q']), $tmp) !== false) |
|
| 349 | + foreach (array('log_topics_unread', 'topics_posted_in', 'tmp_log_search_topics', 'tmp_log_search_messages') as $tmp) { |
|
| 350 | + if (strpos(trim($query_data['q']), $tmp) !== false) |
|
| 328 | 351 | { |
| 329 | 352 | $is_select = false; |
| 353 | + } |
|
| 330 | 354 | break; |
| 331 | 355 | } |
| 332 | 356 | } |
| 333 | 357 | // But actual creation of the temporary tables are. |
| 334 | - elseif (preg_match('~^CREATE TEMPORARY TABLE .+?SELECT .+$~s', trim($query_data['q'])) != 0) |
|
| 335 | - $is_select = true; |
|
| 358 | + elseif (preg_match('~^CREATE TEMPORARY TABLE .+?SELECT .+$~s', trim($query_data['q'])) != 0) { |
|
| 359 | + $is_select = true; |
|
| 360 | + } |
|
| 336 | 361 | |
| 337 | 362 | // Make the filenames look a bit better. |
| 338 | - if (isset($query_data['f'])) |
|
| 339 | - $query_data['f'] = preg_replace('~^' . preg_quote($boarddir, '~') . '~', '...', $query_data['f']); |
|
| 363 | + if (isset($query_data['f'])) { |
|
| 364 | + $query_data['f'] = preg_replace('~^' . preg_quote($boarddir, '~') . '~', '...', $query_data['f']); |
|
| 365 | + } |
|
| 340 | 366 | |
| 341 | 367 | echo ' |
| 342 | 368 | <strong>', $is_select ? '<a href="' . $scripturl . '?action=viewquery;qq=' . ($q + 1) . '#qq' . $q . '" target="_blank" rel="noopener" style="text-decoration: none;">' : '', nl2br(str_replace("\t", ' ', $smcFunc['htmlspecialchars'](ltrim($query_data['q'], "\n\r")))) . ($is_select ? '</a></strong>' : '</strong>') . '<br> |
| 343 | 369 | '; |
| 344 | - if (!empty($query_data['f']) && !empty($query_data['l'])) |
|
| 345 | - echo sprintf($txt['debug_query_in_line'], $query_data['f'], $query_data['l']); |
|
| 370 | + if (!empty($query_data['f']) && !empty($query_data['l'])) { |
|
| 371 | + echo sprintf($txt['debug_query_in_line'], $query_data['f'], $query_data['l']); |
|
| 372 | + } |
|
| 346 | 373 | |
| 347 | - if (isset($query_data['s'], $query_data['t']) && isset($txt['debug_query_which_took_at'])) |
|
| 348 | - echo sprintf($txt['debug_query_which_took_at'], round($query_data['t'], 8), round($query_data['s'], 8)) . '<br>'; |
|
| 349 | - elseif (isset($query_data['t'])) |
|
| 350 | - echo sprintf($txt['debug_query_which_took'], round($query_data['t'], 8)) . '<br>'; |
|
| 374 | + if (isset($query_data['s'], $query_data['t']) && isset($txt['debug_query_which_took_at'])) { |
|
| 375 | + echo sprintf($txt['debug_query_which_took_at'], round($query_data['t'], 8), round($query_data['s'], 8)) . '<br>'; |
|
| 376 | + } elseif (isset($query_data['t'])) { |
|
| 377 | + echo sprintf($txt['debug_query_which_took'], round($query_data['t'], 8)) . '<br>'; |
|
| 378 | + } |
|
| 351 | 379 | echo ' |
| 352 | 380 | <br>'; |
| 353 | 381 | } |
@@ -372,12 +400,14 @@ discard block |
||
| 372 | 400 | global $modSettings, $smcFunc; |
| 373 | 401 | static $cache_stats = array(); |
| 374 | 402 | |
| 375 | - if (empty($modSettings['trackStats'])) |
|
| 376 | - return false; |
|
| 377 | - if (!empty($stats)) |
|
| 378 | - return $cache_stats = array_merge($cache_stats, $stats); |
|
| 379 | - elseif (empty($cache_stats)) |
|
| 380 | - return false; |
|
| 403 | + if (empty($modSettings['trackStats'])) { |
|
| 404 | + return false; |
|
| 405 | + } |
|
| 406 | + if (!empty($stats)) { |
|
| 407 | + return $cache_stats = array_merge($cache_stats, $stats); |
|
| 408 | + } elseif (empty($cache_stats)) { |
|
| 409 | + return false; |
|
| 410 | + } |
|
| 381 | 411 | |
| 382 | 412 | $setStringUpdate = ''; |
| 383 | 413 | $insert_keys = array(); |
@@ -390,10 +420,11 @@ discard block |
||
| 390 | 420 | $setStringUpdate .= ' |
| 391 | 421 | ' . $field . ' = ' . ($change === '+' ? $field . ' + 1' : '{int:' . $field . '}') . ','; |
| 392 | 422 | |
| 393 | - if ($change === '+') |
|
| 394 | - $cache_stats[$field] = 1; |
|
| 395 | - else |
|
| 396 | - $update_parameters[$field] = $change; |
|
| 423 | + if ($change === '+') { |
|
| 424 | + $cache_stats[$field] = 1; |
|
| 425 | + } else { |
|
| 426 | + $update_parameters[$field] = $change; |
|
| 427 | + } |
|
| 397 | 428 | $insert_keys[$field] = 'int'; |
| 398 | 429 | } |
| 399 | 430 | |
@@ -457,43 +488,50 @@ discard block |
||
| 457 | 488 | ); |
| 458 | 489 | |
| 459 | 490 | // Make sure this particular log is enabled first... |
| 460 | - if (empty($modSettings['modlog_enabled'])) |
|
| 461 | - unset ($log_types['moderate']); |
|
| 462 | - if (empty($modSettings['userlog_enabled'])) |
|
| 463 | - unset ($log_types['user']); |
|
| 464 | - if (empty($modSettings['adminlog_enabled'])) |
|
| 465 | - unset ($log_types['admin']); |
|
| 491 | + if (empty($modSettings['modlog_enabled'])) { |
|
| 492 | + unset ($log_types['moderate']); |
|
| 493 | + } |
|
| 494 | + if (empty($modSettings['userlog_enabled'])) { |
|
| 495 | + unset ($log_types['user']); |
|
| 496 | + } |
|
| 497 | + if (empty($modSettings['adminlog_enabled'])) { |
|
| 498 | + unset ($log_types['admin']); |
|
| 499 | + } |
|
| 466 | 500 | |
| 467 | 501 | call_integration_hook('integrate_log_types', array(&$log_types)); |
| 468 | 502 | |
| 469 | 503 | foreach ($logs as $log) |
| 470 | 504 | { |
| 471 | - if (!isset($log_types[$log['log_type']])) |
|
| 472 | - return false; |
|
| 505 | + if (!isset($log_types[$log['log_type']])) { |
|
| 506 | + return false; |
|
| 507 | + } |
|
| 473 | 508 | |
| 474 | - if (!is_array($log['extra'])) |
|
| 475 | - trigger_error('logActions(): data is not an array with action \'' . $log['action'] . '\'', E_USER_NOTICE); |
|
| 509 | + if (!is_array($log['extra'])) { |
|
| 510 | + trigger_error('logActions(): data is not an array with action \'' . $log['action'] . '\'', E_USER_NOTICE); |
|
| 511 | + } |
|
| 476 | 512 | |
| 477 | 513 | // Pull out the parts we want to store separately, but also make sure that the data is proper |
| 478 | 514 | if (isset($log['extra']['topic'])) |
| 479 | 515 | { |
| 480 | - if (!is_numeric($log['extra']['topic'])) |
|
| 481 | - trigger_error('logActions(): data\'s topic is not a number', E_USER_NOTICE); |
|
| 516 | + if (!is_numeric($log['extra']['topic'])) { |
|
| 517 | + trigger_error('logActions(): data\'s topic is not a number', E_USER_NOTICE); |
|
| 518 | + } |
|
| 482 | 519 | $topic_id = empty($log['extra']['topic']) ? 0 : (int) $log['extra']['topic']; |
| 483 | 520 | unset($log['extra']['topic']); |
| 521 | + } else { |
|
| 522 | + $topic_id = 0; |
|
| 484 | 523 | } |
| 485 | - else |
|
| 486 | - $topic_id = 0; |
|
| 487 | 524 | |
| 488 | 525 | if (isset($log['extra']['message'])) |
| 489 | 526 | { |
| 490 | - if (!is_numeric($log['extra']['message'])) |
|
| 491 | - trigger_error('logActions(): data\'s message is not a number', E_USER_NOTICE); |
|
| 527 | + if (!is_numeric($log['extra']['message'])) { |
|
| 528 | + trigger_error('logActions(): data\'s message is not a number', E_USER_NOTICE); |
|
| 529 | + } |
|
| 492 | 530 | $msg_id = empty($log['extra']['message']) ? 0 : (int) $log['extra']['message']; |
| 493 | 531 | unset($log['extra']['message']); |
| 532 | + } else { |
|
| 533 | + $msg_id = 0; |
|
| 494 | 534 | } |
| 495 | - else |
|
| 496 | - $msg_id = 0; |
|
| 497 | 535 | |
| 498 | 536 | // @todo cache this? |
| 499 | 537 | // Is there an associated report on this? |
@@ -520,23 +558,26 @@ discard block |
||
| 520 | 558 | $smcFunc['db_free_result']($request); |
| 521 | 559 | } |
| 522 | 560 | |
| 523 | - if (isset($log['extra']['member']) && !is_numeric($log['extra']['member'])) |
|
| 524 | - trigger_error('logActions(): data\'s member is not a number', E_USER_NOTICE); |
|
| 561 | + if (isset($log['extra']['member']) && !is_numeric($log['extra']['member'])) { |
|
| 562 | + trigger_error('logActions(): data\'s member is not a number', E_USER_NOTICE); |
|
| 563 | + } |
|
| 525 | 564 | |
| 526 | 565 | if (isset($log['extra']['board'])) |
| 527 | 566 | { |
| 528 | - if (!is_numeric($log['extra']['board'])) |
|
| 529 | - trigger_error('logActions(): data\'s board is not a number', E_USER_NOTICE); |
|
| 567 | + if (!is_numeric($log['extra']['board'])) { |
|
| 568 | + trigger_error('logActions(): data\'s board is not a number', E_USER_NOTICE); |
|
| 569 | + } |
|
| 530 | 570 | $board_id = empty($log['extra']['board']) ? 0 : (int) $log['extra']['board']; |
| 531 | 571 | unset($log['extra']['board']); |
| 572 | + } else { |
|
| 573 | + $board_id = 0; |
|
| 532 | 574 | } |
| 533 | - else |
|
| 534 | - $board_id = 0; |
|
| 535 | 575 | |
| 536 | 576 | if (isset($log['extra']['board_to'])) |
| 537 | 577 | { |
| 538 | - if (!is_numeric($log['extra']['board_to'])) |
|
| 539 | - trigger_error('logActions(): data\'s board_to is not a number', E_USER_NOTICE); |
|
| 578 | + if (!is_numeric($log['extra']['board_to'])) { |
|
| 579 | + trigger_error('logActions(): data\'s board_to is not a number', E_USER_NOTICE); |
|
| 580 | + } |
|
| 540 | 581 | if (empty($board_id)) |
| 541 | 582 | { |
| 542 | 583 | $board_id = empty($log['extra']['board_to']) ? 0 : (int) $log['extra']['board_to']; |
@@ -544,10 +585,11 @@ discard block |
||
| 544 | 585 | } |
| 545 | 586 | } |
| 546 | 587 | |
| 547 | - if (isset($log['extra']['member_affected'])) |
|
| 548 | - $memID = $log['extra']['member_affected']; |
|
| 549 | - else |
|
| 550 | - $memID = $user_info['id']; |
|
| 588 | + if (isset($log['extra']['member_affected'])) { |
|
| 589 | + $memID = $log['extra']['member_affected']; |
|
| 590 | + } else { |
|
| 591 | + $memID = $user_info['id']; |
|
| 592 | + } |
|
| 551 | 593 | |
| 552 | 594 | $inserts[] = array( |
| 553 | 595 | time(), $log_types[$log['log_type']], $memID, $user_info['ip'], $log['action'], |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 4 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * The main entrance point for the Manage Members screen. |
@@ -62,16 +63,18 @@ discard block |
||
| 62 | 63 | $context['activation_numbers'] = array(); |
| 63 | 64 | $context['awaiting_activation'] = 0; |
| 64 | 65 | $context['awaiting_approval'] = 0; |
| 65 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 66 | - $context['activation_numbers'][$row['is_activated']] = $row['total_members']; |
|
| 66 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 67 | + $context['activation_numbers'][$row['is_activated']] = $row['total_members']; |
|
| 68 | + } |
|
| 67 | 69 | $smcFunc['db_free_result']($request); |
| 68 | 70 | |
| 69 | 71 | foreach ($context['activation_numbers'] as $activation_type => $total_members) |
| 70 | 72 | { |
| 71 | - if (in_array($activation_type, array(0, 2))) |
|
| 72 | - $context['awaiting_activation'] += $total_members; |
|
| 73 | - elseif (in_array($activation_type, array(3, 4, 5))) |
|
| 74 | - $context['awaiting_approval'] += $total_members; |
|
| 73 | + if (in_array($activation_type, array(0, 2))) { |
|
| 74 | + $context['awaiting_activation'] += $total_members; |
|
| 75 | + } elseif (in_array($activation_type, array(3, 4, 5))) { |
|
| 76 | + $context['awaiting_approval'] += $total_members; |
|
| 77 | + } |
|
| 75 | 78 | } |
| 76 | 79 | |
| 77 | 80 | // For the page header... do we show activation? |
@@ -124,8 +127,9 @@ discard block |
||
| 124 | 127 | } |
| 125 | 128 | if (!$context['show_approve'] && ($_REQUEST['sa'] != 'browse' || $_REQUEST['type'] != 'approve')) |
| 126 | 129 | { |
| 127 | - if (!$context['show_activate'] && ($_REQUEST['sa'] != 'browse' || $_REQUEST['type'] != 'activate')) |
|
| 128 | - $context['tabs']['search']['is_last'] = true; |
|
| 130 | + if (!$context['show_activate'] && ($_REQUEST['sa'] != 'browse' || $_REQUEST['type'] != 'activate')) { |
|
| 131 | + $context['tabs']['search']['is_last'] = true; |
|
| 132 | + } |
|
| 129 | 133 | unset($context['tabs']['approve']); |
| 130 | 134 | } |
| 131 | 135 | |
@@ -157,8 +161,9 @@ discard block |
||
| 157 | 161 | foreach ($_POST['delete'] as $key => $value) |
| 158 | 162 | { |
| 159 | 163 | // Don't delete yourself, idiot. |
| 160 | - if ($value != $user_info['id']) |
|
| 161 | - $delete[$key] = (int) $value; |
|
| 164 | + if ($value != $user_info['id']) { |
|
| 165 | + $delete[$key] = (int) $value; |
|
| 166 | + } |
|
| 162 | 167 | } |
| 163 | 168 | |
| 164 | 169 | if (!empty($delete)) |
@@ -194,17 +199,18 @@ discard block |
||
| 194 | 199 | ); |
| 195 | 200 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 196 | 201 | { |
| 197 | - if ($row['min_posts'] == -1) |
|
| 198 | - $context['membergroups'][] = array( |
|
| 202 | + if ($row['min_posts'] == -1) { |
|
| 203 | + $context['membergroups'][] = array( |
|
| 199 | 204 | 'id' => $row['id_group'], |
| 200 | 205 | 'name' => $row['group_name'], |
| 201 | 206 | 'can_be_additional' => true |
| 202 | 207 | ); |
| 203 | - else |
|
| 204 | - $context['postgroups'][] = array( |
|
| 208 | + } else { |
|
| 209 | + $context['postgroups'][] = array( |
|
| 205 | 210 | 'id' => $row['id_group'], |
| 206 | 211 | 'name' => $row['group_name'] |
| 207 | 212 | ); |
| 213 | + } |
|
| 208 | 214 | } |
| 209 | 215 | $smcFunc['db_free_result']($request); |
| 210 | 216 | |
@@ -276,14 +282,15 @@ discard block |
||
| 276 | 282 | call_integration_hook('integrate_view_members_params', array(&$params)); |
| 277 | 283 | |
| 278 | 284 | $search_params = array(); |
| 279 | - if ($context['sub_action'] == 'query' && !empty($_REQUEST['params']) && empty($_POST['types'])) |
|
| 280 | - $search_params = $smcFunc['json_decode'](base64_decode($_REQUEST['params']), true); |
|
| 281 | - elseif (!empty($_POST)) |
|
| 285 | + if ($context['sub_action'] == 'query' && !empty($_REQUEST['params']) && empty($_POST['types'])) { |
|
| 286 | + $search_params = $smcFunc['json_decode'](base64_decode($_REQUEST['params']), true); |
|
| 287 | + } elseif (!empty($_POST)) |
|
| 282 | 288 | { |
| 283 | 289 | $search_params['types'] = $_POST['types']; |
| 284 | - foreach ($params as $param_name => $param_info) |
|
| 285 | - if (isset($_POST[$param_name])) |
|
| 290 | + foreach ($params as $param_name => $param_info) { |
|
| 291 | + if (isset($_POST[$param_name])) |
|
| 286 | 292 | $search_params[$param_name] = $_POST[$param_name]; |
| 293 | + } |
|
| 287 | 294 | } |
| 288 | 295 | |
| 289 | 296 | $search_url_params = isset($search_params) ? base64_encode($smcFunc['json_encode']($search_params)) : null; |
@@ -296,34 +303,38 @@ discard block |
||
| 296 | 303 | foreach ($params as $param_name => $param_info) |
| 297 | 304 | { |
| 298 | 305 | // Not filled in? |
| 299 | - if (!isset($search_params[$param_name]) || $search_params[$param_name] === '') |
|
| 300 | - continue; |
|
| 306 | + if (!isset($search_params[$param_name]) || $search_params[$param_name] === '') { |
|
| 307 | + continue; |
|
| 308 | + } |
|
| 301 | 309 | |
| 302 | 310 | // Make sure numeric values are really numeric. |
| 303 | - if (in_array($param_info['type'], array('int', 'age'))) |
|
| 304 | - $search_params[$param_name] = (int) $search_params[$param_name]; |
|
| 311 | + if (in_array($param_info['type'], array('int', 'age'))) { |
|
| 312 | + $search_params[$param_name] = (int) $search_params[$param_name]; |
|
| 313 | + } |
|
| 305 | 314 | // Date values have to match the specified format. |
| 306 | 315 | elseif ($param_info['type'] == 'date') |
| 307 | 316 | { |
| 308 | 317 | // Check if this date format is valid. |
| 309 | - if (preg_match('/^\d{4}-\d{1,2}-\d{1,2}$/', $search_params[$param_name]) == 0) |
|
| 310 | - continue; |
|
| 318 | + if (preg_match('/^\d{4}-\d{1,2}-\d{1,2}$/', $search_params[$param_name]) == 0) { |
|
| 319 | + continue; |
|
| 320 | + } |
|
| 311 | 321 | |
| 312 | 322 | $search_params[$param_name] = strtotime($search_params[$param_name]); |
| 313 | - } |
|
| 314 | - elseif ($param_info['type'] == 'inet') |
|
| 323 | + } elseif ($param_info['type'] == 'inet') |
|
| 315 | 324 | { |
| 316 | 325 | $search_params[$param_name] = ip2range($search_params[$param_name]); |
| 317 | - if (empty($search_params[$param_name])) |
|
| 318 | - continue; |
|
| 326 | + if (empty($search_params[$param_name])) { |
|
| 327 | + continue; |
|
| 328 | + } |
|
| 319 | 329 | } |
| 320 | 330 | |
| 321 | 331 | // Those values that are in some kind of range (<, <=, =, >=, >). |
| 322 | 332 | if (!empty($param_info['range'])) |
| 323 | 333 | { |
| 324 | 334 | // Default to '=', just in case... |
| 325 | - if (empty($range_trans[$search_params['types'][$param_name]])) |
|
| 326 | - $search_params['types'][$param_name] = '='; |
|
| 335 | + if (empty($range_trans[$search_params['types'][$param_name]])) { |
|
| 336 | + $search_params['types'][$param_name] = '='; |
|
| 337 | + } |
|
| 327 | 338 | |
| 328 | 339 | // Handle special case 'age'. |
| 329 | 340 | if ($param_info['type'] == 'age') |
@@ -351,16 +362,17 @@ discard block |
||
| 351 | 362 | elseif ($param_info['type'] == 'date' && $search_params['types'][$param_name] == '=') |
| 352 | 363 | { |
| 353 | 364 | $query_parts[] = $param_info['db_fields'][0] . ' > ' . $search_params[$param_name] . ' AND ' . $param_info['db_fields'][0] . ' < ' . ($search_params[$param_name] + 86400); |
| 365 | + } else { |
|
| 366 | + $query_parts[] = $param_info['db_fields'][0] . ' ' . $range_trans[$search_params['types'][$param_name]] . ' ' . $search_params[$param_name]; |
|
| 354 | 367 | } |
| 355 | - else |
|
| 356 | - $query_parts[] = $param_info['db_fields'][0] . ' ' . $range_trans[$search_params['types'][$param_name]] . ' ' . $search_params[$param_name]; |
|
| 357 | 368 | } |
| 358 | 369 | // Checkboxes. |
| 359 | 370 | elseif ($param_info['type'] == 'checkbox') |
| 360 | 371 | { |
| 361 | 372 | // Each checkbox or no checkbox at all is checked -> ignore. |
| 362 | - if (!is_array($search_params[$param_name]) || count($search_params[$param_name]) == 0 || count($search_params[$param_name]) == count($param_info['values'])) |
|
| 363 | - continue; |
|
| 373 | + if (!is_array($search_params[$param_name]) || count($search_params[$param_name]) == 0 || count($search_params[$param_name]) == count($param_info['values'])) { |
|
| 374 | + continue; |
|
| 375 | + } |
|
| 364 | 376 | |
| 365 | 377 | $query_parts[] = ($param_info['db_fields'][0]) . ' IN ({array_string:' . $param_name . '_check})'; |
| 366 | 378 | $where_params[$param_name . '_check'] = $search_params[$param_name]; |
@@ -372,24 +384,23 @@ discard block |
||
| 372 | 384 | { |
| 373 | 385 | $query_parts[] = '(' . $param_info['db_fields'][0] . ' = {inet:' . $param_name . '})'; |
| 374 | 386 | $where_params[$param_name] = $search_params[$param_name][0]; |
| 375 | - } |
|
| 376 | - elseif (count($search_params[$param_name]) === 2) |
|
| 387 | + } elseif (count($search_params[$param_name]) === 2) |
|
| 377 | 388 | { |
| 378 | 389 | $query_parts[] = '(' . $param_info['db_fields'][0] . ' <= {inet:' . $param_name . '_high} and ' . $param_info['db_fields'][0] . ' >= {inet:' . $param_name . '_low})'; |
| 379 | 390 | $where_params[$param_name.'_low'] = $search_params[$param_name]['low']; |
| 380 | 391 | $where_params[$param_name.'_high'] = $search_params[$param_name]['high']; |
| 381 | 392 | } |
| 382 | 393 | |
| 383 | - } |
|
| 384 | - elseif ($param_info['type'] != 'groups') |
|
| 394 | + } elseif ($param_info['type'] != 'groups') |
|
| 385 | 395 | { |
| 386 | 396 | // Replace the wildcard characters ('*' and '?') into MySQL ones. |
| 387 | 397 | $parameter = strtolower(strtr($smcFunc['htmlspecialchars']($search_params[$param_name], ENT_QUOTES), array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_'))); |
| 388 | 398 | |
| 389 | - if ($smcFunc['db_case_sensitive']) |
|
| 390 | - $query_parts[] = '(LOWER(' . implode(') LIKE {string:' . $param_name . '_normal} OR LOWER(', $param_info['db_fields']) . ') LIKE {string:' . $param_name . '_normal})'; |
|
| 391 | - else |
|
| 392 | - $query_parts[] = '(' . implode(' LIKE {string:' . $param_name . '_normal} OR ', $param_info['db_fields']) . ' LIKE {string:' . $param_name . '_normal})'; |
|
| 399 | + if ($smcFunc['db_case_sensitive']) { |
|
| 400 | + $query_parts[] = '(LOWER(' . implode(') LIKE {string:' . $param_name . '_normal} OR LOWER(', $param_info['db_fields']) . ') LIKE {string:' . $param_name . '_normal})'; |
|
| 401 | + } else { |
|
| 402 | + $query_parts[] = '(' . implode(' LIKE {string:' . $param_name . '_normal} OR ', $param_info['db_fields']) . ' LIKE {string:' . $param_name . '_normal})'; |
|
| 403 | + } |
|
| 393 | 404 | $where_params[$param_name . '_normal'] = '%' . $parameter . '%'; |
| 394 | 405 | } |
| 395 | 406 | } |
@@ -405,16 +416,18 @@ discard block |
||
| 405 | 416 | } |
| 406 | 417 | |
| 407 | 418 | // Additional membergroups (these are only relevant if not all primary groups where selected!). |
| 408 | - if (!empty($search_params['membergroups'][2]) && (empty($search_params['membergroups'][1]) || count($context['membergroups']) != count($search_params['membergroups'][1]))) |
|
| 409 | - foreach ($search_params['membergroups'][2] as $mg) |
|
| 419 | + if (!empty($search_params['membergroups'][2]) && (empty($search_params['membergroups'][1]) || count($context['membergroups']) != count($search_params['membergroups'][1]))) { |
|
| 420 | + foreach ($search_params['membergroups'][2] as $mg) |
|
| 410 | 421 | { |
| 411 | 422 | $mg_query_parts[] = 'FIND_IN_SET({int:add_group_' . $mg . '}, mem.additional_groups) != 0'; |
| 423 | + } |
|
| 412 | 424 | $where_params['add_group_' . $mg] = $mg; |
| 413 | 425 | } |
| 414 | 426 | |
| 415 | 427 | // Combine the one or two membergroup parts into one query part linked with an OR. |
| 416 | - if (!empty($mg_query_parts)) |
|
| 417 | - $query_parts[] = '(' . implode(' OR ', $mg_query_parts) . ')'; |
|
| 428 | + if (!empty($mg_query_parts)) { |
|
| 429 | + $query_parts[] = '(' . implode(' OR ', $mg_query_parts) . ')'; |
|
| 430 | + } |
|
| 418 | 431 | |
| 419 | 432 | // Get all selected post count related membergroups. |
| 420 | 433 | if (!empty($search_params['postgroups']) && count($search_params['postgroups']) != count($context['postgroups'])) |
@@ -426,9 +439,9 @@ discard block |
||
| 426 | 439 | // Construct the where part of the query. |
| 427 | 440 | $where = empty($query_parts) ? '1=1' : implode(' |
| 428 | 441 | AND ', $query_parts); |
| 442 | + } else { |
|
| 443 | + $search_url_params = null; |
|
| 429 | 444 | } |
| 430 | - else |
|
| 431 | - $search_url_params = null; |
|
| 432 | 445 | |
| 433 | 446 | // Construct the additional URL part with the query info in it. |
| 434 | 447 | $context['params_url'] = $context['sub_action'] == 'query' ? ';sa=query;params=' . $search_url_params : ''; |
@@ -551,28 +564,32 @@ discard block |
||
| 551 | 564 | 'function' => function($rowData) use ($txt) |
| 552 | 565 | { |
| 553 | 566 | // Calculate number of days since last online. |
| 554 | - if (empty($rowData['last_login'])) |
|
| 555 | - $difference = $txt['never']; |
|
| 556 | - else |
|
| 567 | + if (empty($rowData['last_login'])) { |
|
| 568 | + $difference = $txt['never']; |
|
| 569 | + } else |
|
| 557 | 570 | { |
| 558 | 571 | $num_days_difference = jeffsdatediff($rowData['last_login']); |
| 559 | 572 | |
| 560 | 573 | // Today. |
| 561 | - if (empty($num_days_difference)) |
|
| 562 | - $difference = $txt['viewmembers_today']; |
|
| 574 | + if (empty($num_days_difference)) { |
|
| 575 | + $difference = $txt['viewmembers_today']; |
|
| 576 | + } |
|
| 563 | 577 | |
| 564 | 578 | // Yesterday. |
| 565 | - elseif ($num_days_difference == 1) |
|
| 566 | - $difference = sprintf('1 %1$s', $txt['viewmembers_day_ago']); |
|
| 579 | + elseif ($num_days_difference == 1) { |
|
| 580 | + $difference = sprintf('1 %1$s', $txt['viewmembers_day_ago']); |
|
| 581 | + } |
|
| 567 | 582 | |
| 568 | 583 | // X days ago. |
| 569 | - else |
|
| 570 | - $difference = sprintf('%1$d %2$s', $num_days_difference, $txt['viewmembers_days_ago']); |
|
| 584 | + else { |
|
| 585 | + $difference = sprintf('%1$d %2$s', $num_days_difference, $txt['viewmembers_days_ago']); |
|
| 586 | + } |
|
| 571 | 587 | } |
| 572 | 588 | |
| 573 | 589 | // Show it in italics if they're not activated... |
| 574 | - if ($rowData['is_activated'] % 10 != 1) |
|
| 575 | - $difference = sprintf('<em title="%1$s">%2$s</em>', $txt['not_activated'], $difference); |
|
| 590 | + if ($rowData['is_activated'] % 10 != 1) { |
|
| 591 | + $difference = sprintf('<em title="%1$s">%2$s</em>', $txt['not_activated'], $difference); |
|
| 592 | + } |
|
| 576 | 593 | |
| 577 | 594 | return $difference; |
| 578 | 595 | }, |
@@ -624,8 +641,9 @@ discard block |
||
| 624 | 641 | ); |
| 625 | 642 | |
| 626 | 643 | // Without enough permissions, don't show 'delete members' checkboxes. |
| 627 | - if (!allowedTo('profile_remove_any')) |
|
| 628 | - unset($listOptions['cols']['check'], $listOptions['form'], $listOptions['additional_rows']); |
|
| 644 | + if (!allowedTo('profile_remove_any')) { |
|
| 645 | + unset($listOptions['cols']['check'], $listOptions['form'], $listOptions['additional_rows']); |
|
| 646 | + } |
|
| 629 | 647 | |
| 630 | 648 | require_once($sourcedir . '/Subs-List.php'); |
| 631 | 649 | createList($listOptions); |
@@ -668,17 +686,18 @@ discard block |
||
| 668 | 686 | ); |
| 669 | 687 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 670 | 688 | { |
| 671 | - if ($row['min_posts'] == -1) |
|
| 672 | - $context['membergroups'][] = array( |
|
| 689 | + if ($row['min_posts'] == -1) { |
|
| 690 | + $context['membergroups'][] = array( |
|
| 673 | 691 | 'id' => $row['id_group'], |
| 674 | 692 | 'name' => $row['group_name'], |
| 675 | 693 | 'can_be_additional' => true |
| 676 | 694 | ); |
| 677 | - else |
|
| 678 | - $context['postgroups'][] = array( |
|
| 695 | + } else { |
|
| 696 | + $context['postgroups'][] = array( |
|
| 679 | 697 | 'id' => $row['id_group'], |
| 680 | 698 | 'name' => $row['group_name'] |
| 681 | 699 | ); |
| 700 | + } |
|
| 682 | 701 | } |
| 683 | 702 | $smcFunc['db_free_result']($request); |
| 684 | 703 | |
@@ -705,8 +724,9 @@ discard block |
||
| 705 | 724 | $context['page_title'] = $txt['admin_members']; |
| 706 | 725 | $context['sub_template'] = 'admin_browse'; |
| 707 | 726 | $context['browse_type'] = isset($_REQUEST['type']) ? $_REQUEST['type'] : (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1 ? 'activate' : 'approve'); |
| 708 | - if (isset($context['tabs'][$context['browse_type']])) |
|
| 709 | - $context['tabs'][$context['browse_type']]['is_selected'] = true; |
|
| 727 | + if (isset($context['tabs'][$context['browse_type']])) { |
|
| 728 | + $context['tabs'][$context['browse_type']]['is_selected'] = true; |
|
| 729 | + } |
|
| 710 | 730 | |
| 711 | 731 | // Allowed filters are those we can have, in theory. |
| 712 | 732 | $context['allowed_filters'] = $context['browse_type'] == 'approve' ? array(3, 4, 5) : array(0, 2); |
@@ -717,18 +737,20 @@ discard block |
||
| 717 | 737 | foreach ($context['activation_numbers'] as $type => $amount) |
| 718 | 738 | { |
| 719 | 739 | // We have some of these... |
| 720 | - if (in_array($type, $context['allowed_filters']) && $amount > 0) |
|
| 721 | - $context['available_filters'][] = array( |
|
| 740 | + if (in_array($type, $context['allowed_filters']) && $amount > 0) { |
|
| 741 | + $context['available_filters'][] = array( |
|
| 722 | 742 | 'type' => $type, |
| 723 | 743 | 'amount' => $amount, |
| 724 | 744 | 'desc' => isset($txt['admin_browse_filter_type_' . $type]) ? $txt['admin_browse_filter_type_' . $type] : '?', |
| 725 | 745 | 'selected' => $type == $context['current_filter'] |
| 726 | 746 | ); |
| 747 | + } |
|
| 727 | 748 | } |
| 728 | 749 | |
| 729 | 750 | // If the filter was not sent, set it to whatever has people in it! |
| 730 | - if ($context['current_filter'] == -1 && !empty($context['available_filters'][0]['amount'])) |
|
| 731 | - $context['current_filter'] = $context['available_filters'][0]['type']; |
|
| 751 | + if ($context['current_filter'] == -1 && !empty($context['available_filters'][0]['amount'])) { |
|
| 752 | + $context['current_filter'] = $context['available_filters'][0]['type']; |
|
| 753 | + } |
|
| 732 | 754 | |
| 733 | 755 | // This little variable is used to determine if we should flag where we are looking. |
| 734 | 756 | $context['show_filter'] = ($context['current_filter'] != 0 && $context['current_filter'] != 3) || count($context['available_filters']) > 1; |
@@ -743,44 +765,47 @@ discard block |
||
| 743 | 765 | ); |
| 744 | 766 | |
| 745 | 767 | // Are we showing duplicate information? |
| 746 | - if (isset($_GET['showdupes'])) |
|
| 747 | - $_SESSION['showdupes'] = (int) $_GET['showdupes']; |
|
| 768 | + if (isset($_GET['showdupes'])) { |
|
| 769 | + $_SESSION['showdupes'] = (int) $_GET['showdupes']; |
|
| 770 | + } |
|
| 748 | 771 | $context['show_duplicates'] = !empty($_SESSION['showdupes']); |
| 749 | 772 | |
| 750 | 773 | // Determine which actions we should allow on this page. |
| 751 | 774 | if ($context['browse_type'] == 'approve') |
| 752 | 775 | { |
| 753 | 776 | // If we are approving deleted accounts we have a slightly different list... actually a mirror ;) |
| 754 | - if ($context['current_filter'] == 4) |
|
| 755 | - $context['allowed_actions'] = array( |
|
| 777 | + if ($context['current_filter'] == 4) { |
|
| 778 | + $context['allowed_actions'] = array( |
|
| 756 | 779 | 'reject' => $txt['admin_browse_w_approve_deletion'], |
| 757 | 780 | 'ok' => $txt['admin_browse_w_reject'], |
| 758 | 781 | ); |
| 759 | - else |
|
| 760 | - $context['allowed_actions'] = array( |
|
| 782 | + } else { |
|
| 783 | + $context['allowed_actions'] = array( |
|
| 761 | 784 | 'ok' => $txt['admin_browse_w_approve'], |
| 762 | 785 | 'okemail' => $txt['admin_browse_w_approve'] . ' ' . $txt['admin_browse_w_email'], |
| 763 | 786 | 'require_activation' => $txt['admin_browse_w_approve_require_activate'], |
| 764 | 787 | 'reject' => $txt['admin_browse_w_reject'], |
| 765 | 788 | 'rejectemail' => $txt['admin_browse_w_reject'] . ' ' . $txt['admin_browse_w_email'], |
| 766 | 789 | ); |
| 767 | - } |
|
| 768 | - elseif ($context['browse_type'] == 'activate') |
|
| 769 | - $context['allowed_actions'] = array( |
|
| 790 | + } |
|
| 791 | + } elseif ($context['browse_type'] == 'activate') { |
|
| 792 | + $context['allowed_actions'] = array( |
|
| 770 | 793 | 'ok' => $txt['admin_browse_w_activate'], |
| 771 | 794 | 'okemail' => $txt['admin_browse_w_activate'] . ' ' . $txt['admin_browse_w_email'], |
| 772 | 795 | 'delete' => $txt['admin_browse_w_delete'], |
| 773 | 796 | 'deleteemail' => $txt['admin_browse_w_delete'] . ' ' . $txt['admin_browse_w_email'], |
| 774 | 797 | 'remind' => $txt['admin_browse_w_remind'] . ' ' . $txt['admin_browse_w_email'], |
| 775 | 798 | ); |
| 799 | + } |
|
| 776 | 800 | |
| 777 | 801 | // Create an option list for actions allowed to be done with selected members. |
| 778 | 802 | $allowed_actions = ' |
| 779 | 803 | <option selected value="">' . $txt['admin_browse_with_selected'] . ':</option> |
| 780 | 804 | <option value="" disabled>-----------------------------</option>'; |
| 781 | - foreach ($context['allowed_actions'] as $key => $desc) |
|
| 782 | - $allowed_actions .= ' |
|
| 805 | + foreach ($context['allowed_actions'] as $key => $desc) { |
|
| 806 | + $allowed_actions .= ' |
|
| 783 | 807 | <option value="' . $key . '">' . $desc . '</option>'; |
| 808 | + } |
|
| 784 | 809 | |
| 785 | 810 | // Setup the Javascript function for selecting an action for the list. |
| 786 | 811 | $javascript = ' |
@@ -792,15 +817,16 @@ discard block |
||
| 792 | 817 | var message = "";'; |
| 793 | 818 | |
| 794 | 819 | // We have special messages for approving deletion of accounts - it's surprisingly logical - honest. |
| 795 | - if ($context['current_filter'] == 4) |
|
| 796 | - $javascript .= ' |
|
| 820 | + if ($context['current_filter'] == 4) { |
|
| 821 | + $javascript .= ' |
|
| 797 | 822 | if (document.forms.postForm.todo.value.indexOf("reject") != -1) |
| 798 | 823 | message = "' . $txt['admin_browse_w_delete'] . '"; |
| 799 | 824 | else |
| 800 | 825 | message = "' . $txt['admin_browse_w_reject'] . '";'; |
| 826 | + } |
|
| 801 | 827 | // Otherwise a nice standard message. |
| 802 | - else |
|
| 803 | - $javascript .= ' |
|
| 828 | + else { |
|
| 829 | + $javascript .= ' |
|
| 804 | 830 | if (document.forms.postForm.todo.value.indexOf("delete") != -1) |
| 805 | 831 | message = "' . $txt['admin_browse_w_delete'] . '"; |
| 806 | 832 | else if (document.forms.postForm.todo.value.indexOf("reject") != -1) |
@@ -809,6 +835,7 @@ discard block |
||
| 809 | 835 | message = "' . $txt['admin_browse_w_remind'] . '"; |
| 810 | 836 | else |
| 811 | 837 | message = "' . ($context['browse_type'] == 'approve' ? $txt['admin_browse_w_approve'] : $txt['admin_browse_w_activate']) . '";'; |
| 838 | + } |
|
| 812 | 839 | $javascript .= ' |
| 813 | 840 | if (confirm(message + " ' . $txt['admin_browse_warn'] . '")) |
| 814 | 841 | document.forms.postForm.submit(); |
@@ -941,10 +968,11 @@ discard block |
||
| 941 | 968 | $member_links = array(); |
| 942 | 969 | foreach ($rowData['duplicate_members'] as $member) |
| 943 | 970 | { |
| 944 | - if ($member['id']) |
|
| 945 | - $member_links[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '" ' . (!empty($member['is_banned']) ? 'class="red"' : '') . '>' . $member['name'] . '</a>'; |
|
| 946 | - else |
|
| 947 | - $member_links[] = $member['name'] . ' (' . $txt['guest'] . ')'; |
|
| 971 | + if ($member['id']) { |
|
| 972 | + $member_links[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '" ' . (!empty($member['is_banned']) ? 'class="red"' : '') . '>' . $member['name'] . '</a>'; |
|
| 973 | + } else { |
|
| 974 | + $member_links[] = $member['name'] . ' (' . $txt['guest'] . ')'; |
|
| 975 | + } |
|
| 948 | 976 | } |
| 949 | 977 | return implode(', ', $member_links); |
| 950 | 978 | }, |
@@ -993,14 +1021,16 @@ discard block |
||
| 993 | 1021 | ); |
| 994 | 1022 | |
| 995 | 1023 | // Pick what column to actually include if we're showing duplicates. |
| 996 | - if ($context['show_duplicates']) |
|
| 997 | - unset($listOptions['columns']['email']); |
|
| 998 | - else |
|
| 999 | - unset($listOptions['columns']['duplicates']); |
|
| 1024 | + if ($context['show_duplicates']) { |
|
| 1025 | + unset($listOptions['columns']['email']); |
|
| 1026 | + } else { |
|
| 1027 | + unset($listOptions['columns']['duplicates']); |
|
| 1028 | + } |
|
| 1000 | 1029 | |
| 1001 | 1030 | // Only show hostname on duplicates as it takes a lot of time. |
| 1002 | - if (!$context['show_duplicates'] || !empty($modSettings['disableHostnameLookup'])) |
|
| 1003 | - unset($listOptions['columns']['hostname']); |
|
| 1031 | + if (!$context['show_duplicates'] || !empty($modSettings['disableHostnameLookup'])) { |
|
| 1032 | + unset($listOptions['columns']['hostname']); |
|
| 1033 | + } |
|
| 1004 | 1034 | |
| 1005 | 1035 | // Is there any need to show filters? |
| 1006 | 1036 | if (isset($context['available_filters']) && count($context['available_filters']) > 1) |
@@ -1008,9 +1038,10 @@ discard block |
||
| 1008 | 1038 | $filterOptions = ' |
| 1009 | 1039 | <strong>' . $txt['admin_browse_filter_by'] . ':</strong> |
| 1010 | 1040 | <select name="filter" onchange="this.form.submit();">'; |
| 1011 | - foreach ($context['available_filters'] as $filter) |
|
| 1012 | - $filterOptions .= ' |
|
| 1041 | + foreach ($context['available_filters'] as $filter) { |
|
| 1042 | + $filterOptions .= ' |
|
| 1013 | 1043 | <option value="' . $filter['type'] . '"' . ($filter['selected'] ? ' selected' : '') . '>' . $filter['desc'] . ' - ' . $filter['amount'] . ' ' . ($filter['amount'] == 1 ? $txt['user'] : $txt['users']) . '</option>'; |
| 1044 | + } |
|
| 1014 | 1045 | $filterOptions .= ' |
| 1015 | 1046 | </select> |
| 1016 | 1047 | <noscript><input type="submit" value="' . $txt['go'] . '" name="filter" class="button"></noscript>'; |
@@ -1022,12 +1053,13 @@ discard block |
||
| 1022 | 1053 | } |
| 1023 | 1054 | |
| 1024 | 1055 | // What about if we only have one filter, but it's not the "standard" filter - show them what they are looking at. |
| 1025 | - if (!empty($context['show_filter']) && !empty($context['available_filters'])) |
|
| 1026 | - $listOptions['additional_rows'][] = array( |
|
| 1056 | + if (!empty($context['show_filter']) && !empty($context['available_filters'])) { |
|
| 1057 | + $listOptions['additional_rows'][] = array( |
|
| 1027 | 1058 | 'position' => 'above_column_headers', |
| 1028 | 1059 | 'value' => '<strong>' . $txt['admin_browse_filter_show'] . ':</strong> ' . $context['available_filters'][0]['desc'], |
| 1029 | 1060 | 'class' => 'smalltext floatright', |
| 1030 | 1061 | ); |
| 1062 | + } |
|
| 1031 | 1063 | |
| 1032 | 1064 | // Now that we have all the options, create the list. |
| 1033 | 1065 | require_once($sourcedir . '/Subs-List.php'); |
@@ -1057,12 +1089,14 @@ discard block |
||
| 1057 | 1089 | $current_filter = (int) $_REQUEST['orig_filter']; |
| 1058 | 1090 | |
| 1059 | 1091 | // If we are applying a filter do just that - then redirect. |
| 1060 | - if (isset($_REQUEST['filter']) && $_REQUEST['filter'] != $_REQUEST['orig_filter']) |
|
| 1061 | - redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $_REQUEST['filter'] . ';start=' . $_REQUEST['start']); |
|
| 1092 | + if (isset($_REQUEST['filter']) && $_REQUEST['filter'] != $_REQUEST['orig_filter']) { |
|
| 1093 | + redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $_REQUEST['filter'] . ';start=' . $_REQUEST['start']); |
|
| 1094 | + } |
|
| 1062 | 1095 | |
| 1063 | 1096 | // Nothing to do? |
| 1064 | - if (!isset($_POST['todoAction']) && !isset($_POST['time_passed'])) |
|
| 1065 | - redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']); |
|
| 1097 | + if (!isset($_POST['todoAction']) && !isset($_POST['time_passed'])) { |
|
| 1098 | + redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']); |
|
| 1099 | + } |
|
| 1066 | 1100 | |
| 1067 | 1101 | // Are we dealing with members who have been waiting for > set amount of time? |
| 1068 | 1102 | if (isset($_POST['time_passed'])) |
@@ -1075,8 +1109,9 @@ discard block |
||
| 1075 | 1109 | else |
| 1076 | 1110 | { |
| 1077 | 1111 | $members = array(); |
| 1078 | - foreach ($_POST['todoAction'] as $id) |
|
| 1079 | - $members[] = (int) $id; |
|
| 1112 | + foreach ($_POST['todoAction'] as $id) { |
|
| 1113 | + $members[] = (int) $id; |
|
| 1114 | + } |
|
| 1080 | 1115 | $condition = ' |
| 1081 | 1116 | AND id_member IN ({array_int:members})'; |
| 1082 | 1117 | } |
@@ -1097,8 +1132,9 @@ discard block |
||
| 1097 | 1132 | $member_count = $smcFunc['db_num_rows']($request); |
| 1098 | 1133 | |
| 1099 | 1134 | // If no results then just return! |
| 1100 | - if ($member_count == 0) |
|
| 1101 | - redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']); |
|
| 1135 | + if ($member_count == 0) { |
|
| 1136 | + redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']); |
|
| 1137 | + } |
|
| 1102 | 1138 | |
| 1103 | 1139 | $member_info = array(); |
| 1104 | 1140 | $members = array(); |
@@ -1137,8 +1173,9 @@ discard block |
||
| 1137 | 1173 | // Do we have to let the integration code know about the activations? |
| 1138 | 1174 | if (!empty($modSettings['integrate_activate'])) |
| 1139 | 1175 | { |
| 1140 | - foreach ($member_info as $member) |
|
| 1141 | - call_integration_hook('integrate_activate', array($member['username'])); |
|
| 1176 | + foreach ($member_info as $member) { |
|
| 1177 | + call_integration_hook('integrate_activate', array($member['username'])); |
|
| 1178 | + } |
|
| 1142 | 1179 | } |
| 1143 | 1180 | |
| 1144 | 1181 | // Check for email. |
@@ -1268,20 +1305,23 @@ discard block |
||
| 1268 | 1305 | $log_action = $_POST['todo'] == 'remind' ? 'remind_member' : 'approve_member'; |
| 1269 | 1306 | |
| 1270 | 1307 | require_once($sourcedir . '/Logging.php'); |
| 1271 | - foreach ($member_info as $member) |
|
| 1272 | - logAction($log_action, array('member' => $member['id']), 'admin'); |
|
| 1308 | + foreach ($member_info as $member) { |
|
| 1309 | + logAction($log_action, array('member' => $member['id']), 'admin'); |
|
| 1310 | + } |
|
| 1273 | 1311 | } |
| 1274 | 1312 | |
| 1275 | 1313 | // Although updateStats *may* catch this, best to do it manually just in case (Doesn't always sort out unapprovedMembers). |
| 1276 | - if (in_array($current_filter, array(3, 4, 5))) |
|
| 1277 | - updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > $member_count ? $modSettings['unapprovedMembers'] - $member_count : 0))); |
|
| 1314 | + if (in_array($current_filter, array(3, 4, 5))) { |
|
| 1315 | + updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > $member_count ? $modSettings['unapprovedMembers'] - $member_count : 0))); |
|
| 1316 | + } |
|
| 1278 | 1317 | |
| 1279 | 1318 | // Update the member's stats. (but, we know the member didn't change their name.) |
| 1280 | 1319 | updateStats('member', false); |
| 1281 | 1320 | |
| 1282 | 1321 | // If they haven't been deleted, update the post group statistics on them... |
| 1283 | - if (!in_array($_POST['todo'], array('delete', 'deleteemail', 'reject', 'rejectemail', 'remind'))) |
|
| 1284 | - updateStats('postgroups', $members); |
|
| 1322 | + if (!in_array($_POST['todo'], array('delete', 'deleteemail', 'reject', 'rejectemail', 'remind'))) { |
|
| 1323 | + updateStats('postgroups', $members); |
|
| 1324 | + } |
|
| 1285 | 1325 | |
| 1286 | 1326 | redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']); |
| 1287 | 1327 | } |
@@ -1306,10 +1346,11 @@ discard block |
||
| 1306 | 1346 | $dis = time() - $old; |
| 1307 | 1347 | |
| 1308 | 1348 | // Before midnight? |
| 1309 | - if ($dis < $sinceMidnight) |
|
| 1310 | - return 0; |
|
| 1311 | - else |
|
| 1312 | - $dis -= $sinceMidnight; |
|
| 1349 | + if ($dis < $sinceMidnight) { |
|
| 1350 | + return 0; |
|
| 1351 | + } else { |
|
| 1352 | + $dis -= $sinceMidnight; |
|
| 1353 | + } |
|
| 1313 | 1354 | |
| 1314 | 1355 | // Divide out the seconds in a day to get the number of days. |
| 1315 | 1356 | return ceil($dis / (24 * 60 * 60)); |
@@ -12,7 +12,8 @@ |
||
| 12 | 12 | header('location: ' . $boardurl); |
| 13 | 13 | } |
| 14 | 14 | // Can't find it... just forget it. |
| 15 | -else |
|
| 15 | +else { |
|
| 16 | 16 | exit; |
| 17 | +} |
|
| 17 | 18 | |
| 18 | 19 | ?> |
| 19 | 20 | \ No newline at end of file |
@@ -41,37 +41,43 @@ discard block |
||
| 41 | 41 | define('TIME_START', microtime(true)); |
| 42 | 42 | |
| 43 | 43 | // Just being safe... |
| 44 | -foreach (array('db_character_set', 'cachedir') as $variable) |
|
| 44 | +foreach (array('db_character_set', 'cachedir') as $variable) { |
|
| 45 | 45 | if (isset($GLOBALS[$variable])) |
| 46 | 46 | unset($GLOBALS[$variable]); |
| 47 | +} |
|
| 47 | 48 | |
| 48 | 49 | // Get the forum's settings for database and file paths. |
| 49 | 50 | require_once(dirname(__FILE__) . '/Settings.php'); |
| 50 | 51 | |
| 51 | 52 | // Make absolutely sure the cache directory is defined. |
| 52 | -if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) |
|
| 53 | +if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) { |
|
| 53 | 54 | $cachedir = $boarddir . '/cache'; |
| 55 | +} |
|
| 54 | 56 | |
| 55 | 57 | // Don't do john didley if the forum's been shut down competely. |
| 56 | -if ($maintenance == 2) |
|
| 58 | +if ($maintenance == 2) { |
|
| 57 | 59 | die($mmessage); |
| 60 | +} |
|
| 58 | 61 | |
| 59 | 62 | // Fix for using the current directory as a path. |
| 60 | -if (substr($sourcedir, 0, 1) == '.' && substr($sourcedir, 1, 1) != '.') |
|
| 63 | +if (substr($sourcedir, 0, 1) == '.' && substr($sourcedir, 1, 1) != '.') { |
|
| 61 | 64 | $sourcedir = dirname(__FILE__) . substr($sourcedir, 1); |
| 65 | +} |
|
| 62 | 66 | |
| 63 | 67 | // Have we already turned this off? If so, exist gracefully. |
| 64 | -if (file_exists($cachedir . '/cron.lock')) |
|
| 68 | +if (file_exists($cachedir . '/cron.lock')) { |
|
| 65 | 69 | obExit_cron(); |
| 70 | +} |
|
| 66 | 71 | |
| 67 | 72 | // Before we go any further, if this is not a CLI request, we need to do some checking. |
| 68 | 73 | if (!FROM_CLI) |
| 69 | 74 | { |
| 70 | 75 | // We will clean up $_GET shortly. But we want to this ASAP. |
| 71 | 76 | $ts = isset($_GET['ts']) ? (int) $_GET['ts'] : 0; |
| 72 | - if ($ts <= 0 || $ts % 15 != 0 || time() - $ts < 0 || time() - $ts > 20) |
|
| 73 | - obExit_cron(); |
|
| 74 | -} |
|
| 77 | + if ($ts <= 0 || $ts % 15 != 0 || time() - $ts < 0 || time() - $ts > 20) { |
|
| 78 | + obExit_cron(); |
|
| 79 | + } |
|
| 80 | + } |
|
| 75 | 81 | |
| 76 | 82 | // Load the most important includes. In general, a background should be loading its own dependencies. |
| 77 | 83 | require_once($sourcedir . '/Errors.php'); |
@@ -123,8 +129,9 @@ discard block |
||
| 123 | 129 | global $smcFunc; |
| 124 | 130 | |
| 125 | 131 | // Check we haven't run over our time limit. |
| 126 | - if (microtime(true) - TIME_START > MAX_CRON_TIME) |
|
| 127 | - return false; |
|
| 132 | + if (microtime(true) - TIME_START > MAX_CRON_TIME) { |
|
| 133 | + return false; |
|
| 134 | + } |
|
| 128 | 135 | |
| 129 | 136 | // Try to find a task. Specifically, try to find one that hasn't been claimed previously, or failing that, |
| 130 | 137 | // a task that was claimed but failed for whatever reason and failed long enough ago. We should not care |
@@ -159,14 +166,12 @@ discard block |
||
| 159 | 166 | // Update the time and go back. |
| 160 | 167 | $row['claimed_time'] = time(); |
| 161 | 168 | return $row; |
| 162 | - } |
|
| 163 | - else |
|
| 169 | + } else |
|
| 164 | 170 | { |
| 165 | 171 | // Uh oh, we just missed it. Try to claim another one, and let it fall through if there aren't any. |
| 166 | 172 | return fetch_task(); |
| 167 | 173 | } |
| 168 | - } |
|
| 169 | - else |
|
| 174 | + } else |
|
| 170 | 175 | { |
| 171 | 176 | // No dice. Clean up and go home. |
| 172 | 177 | $smcFunc['db_free_result']($request); |
@@ -187,8 +192,9 @@ discard block |
||
| 187 | 192 | if (!empty($task_details['task_file'])) |
| 188 | 193 | { |
| 189 | 194 | $include = strtr(trim($task_details['task_file']), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
| 190 | - if (file_exists($include)) |
|
| 191 | - require_once($include); |
|
| 195 | + if (file_exists($include)) { |
|
| 196 | + require_once($include); |
|
| 197 | + } |
|
| 192 | 198 | } |
| 193 | 199 | |
| 194 | 200 | if (empty($task_details['task_class'])) |
@@ -204,8 +210,7 @@ discard block |
||
| 204 | 210 | $details = empty($task_details['task_data']) ? array() : $smcFunc['json_decode']($task_details['task_data'], true); |
| 205 | 211 | $bgtask = new $task_details['task_class']($details); |
| 206 | 212 | return $bgtask->execute(); |
| 207 | - } |
|
| 208 | - else |
|
| 213 | + } else |
|
| 209 | 214 | { |
| 210 | 215 | log_error('Invalid background task specified: (class: ' . $task_details['task_class'] . ', ' . (empty($task_details['task_file']) ? ' no file' : ' to load ' . $task_details['task_file']) . ')'); |
| 211 | 216 | return true; // So we clear it from the queue. |
@@ -224,8 +229,9 @@ discard block |
||
| 224 | 229 | $scripturl = $boardurl . '/index.php'; |
| 225 | 230 | |
| 226 | 231 | // These keys shouldn't be set...ever. |
| 227 | - if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS'])) |
|
| 228 | - die('Invalid request variable.'); |
|
| 232 | + if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS'])) { |
|
| 233 | + die('Invalid request variable.'); |
|
| 234 | + } |
|
| 229 | 235 | |
| 230 | 236 | // Save some memory.. (since we don't use these anyway.) |
| 231 | 237 | unset($GLOBALS['HTTP_POST_VARS'], $GLOBALS['HTTP_POST_VARS']); |
@@ -246,26 +252,28 @@ discard block |
||
| 246 | 252 | global $modSettings; |
| 247 | 253 | |
| 248 | 254 | // Ignore errors if we're ignoring them or they are strict notices from PHP 5 |
| 249 | - if (error_reporting() == 0) |
|
| 250 | - return; |
|
| 255 | + if (error_reporting() == 0) { |
|
| 256 | + return; |
|
| 257 | + } |
|
| 251 | 258 | |
| 252 | 259 | $error_type = 'cron'; |
| 253 | 260 | |
| 254 | 261 | log_error($error_level . ': ' . $error_string, $error_type, $file, $line); |
| 255 | 262 | |
| 256 | 263 | // If this is an E_ERROR or E_USER_ERROR.... die. Violently so. |
| 257 | - if ($error_level % 255 == E_ERROR) |
|
| 258 | - die('No direct access...'); |
|
| 259 | -} |
|
| 264 | + if ($error_level % 255 == E_ERROR) { |
|
| 265 | + die('No direct access...'); |
|
| 266 | + } |
|
| 267 | + } |
|
| 260 | 268 | |
| 261 | 269 | /** |
| 262 | 270 | * The exit function |
| 263 | 271 | */ |
| 264 | 272 | function obExit_cron() |
| 265 | 273 | { |
| 266 | - if (FROM_CLI) |
|
| 267 | - die(0); |
|
| 268 | - else |
|
| 274 | + if (FROM_CLI) { |
|
| 275 | + die(0); |
|
| 276 | + } else |
|
| 269 | 277 | { |
| 270 | 278 | header('content-type: image/gif'); |
| 271 | 279 | 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"); |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 4 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * Downloads an avatar or attachment based on $_GET['attach'], and increments the download count. |
@@ -40,11 +41,11 @@ discard block |
||
| 40 | 41 | |
| 41 | 42 | if (!empty($modSettings['enableCompressedOutput']) && !headers_sent() && ob_get_length() == 0) |
| 42 | 43 | { |
| 43 | - if (@ini_get('zlib.output_compression') == '1' || @ini_get('output_handler') == 'ob_gzhandler') |
|
| 44 | - $modSettings['enableCompressedOutput'] = 0; |
|
| 45 | - |
|
| 46 | - else |
|
| 47 | - ob_start('ob_gzhandler'); |
|
| 44 | + if (@ini_get('zlib.output_compression') == '1' || @ini_get('output_handler') == 'ob_gzhandler') { |
|
| 45 | + $modSettings['enableCompressedOutput'] = 0; |
|
| 46 | + } else { |
|
| 47 | + ob_start('ob_gzhandler'); |
|
| 48 | + } |
|
| 48 | 49 | } |
| 49 | 50 | |
| 50 | 51 | if (empty($modSettings['enableCompressedOutput'])) |
@@ -76,8 +77,9 @@ discard block |
||
| 76 | 77 | } |
| 77 | 78 | |
| 78 | 79 | // Use cache when possible. |
| 79 | - if (($cache = cache_get_data('attachment_lookup_id-' . $attachId)) != null) |
|
| 80 | - list($file, $thumbFile) = $cache; |
|
| 80 | + if (($cache = cache_get_data('attachment_lookup_id-' . $attachId)) != null) { |
|
| 81 | + list($file, $thumbFile) = $cache; |
|
| 82 | + } |
|
| 81 | 83 | |
| 82 | 84 | // Get the info from the DB. |
| 83 | 85 | if (empty($file) || empty($thumbFile) && !empty($file['id_thumb'])) |
@@ -85,10 +87,9 @@ discard block |
||
| 85 | 87 | // Do we have a hook wanting to use our attachment system? We use $attachRequest to prevent accidental usage of $request. |
| 86 | 88 | $attachRequest = null; |
| 87 | 89 | call_integration_hook('integrate_download_request', array(&$attachRequest)); |
| 88 | - if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest)) |
|
| 89 | - $request = $attachRequest; |
|
| 90 | - |
|
| 91 | - else |
|
| 90 | + if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest)) { |
|
| 91 | + $request = $attachRequest; |
|
| 92 | + } else |
|
| 92 | 93 | { |
| 93 | 94 | // Make sure this attachment is on this board and load its info while we are at it. |
| 94 | 95 | $request = $smcFunc['db_query']('', ' |
@@ -181,13 +182,15 @@ discard block |
||
| 181 | 182 | } |
| 182 | 183 | |
| 183 | 184 | // Cache it. |
| 184 | - if (!empty($file) || !empty($thumbFile)) |
|
| 185 | - cache_put_data('attachment_lookup_id-' . $file['id_attach'], array($file, $thumbFile), mt_rand(850, 900)); |
|
| 185 | + if (!empty($file) || !empty($thumbFile)) { |
|
| 186 | + cache_put_data('attachment_lookup_id-' . $file['id_attach'], array($file, $thumbFile), mt_rand(850, 900)); |
|
| 187 | + } |
|
| 186 | 188 | } |
| 187 | 189 | |
| 188 | 190 | // Replace the normal file with its thumbnail if it has one! |
| 189 | - if (!empty($showThumb) && !empty($thumbFile)) |
|
| 190 | - $file = $thumbFile; |
|
| 191 | + if (!empty($showThumb) && !empty($thumbFile)) { |
|
| 192 | + $file = $thumbFile; |
|
| 193 | + } |
|
| 191 | 194 | |
| 192 | 195 | // No point in a nicer message, because this is supposed to be an attachment anyway... |
| 193 | 196 | if (!file_exists($file['filePath'])) |
@@ -237,8 +240,8 @@ discard block |
||
| 237 | 240 | } |
| 238 | 241 | |
| 239 | 242 | // Update the download counter (unless it's a thumbnail or resuming an incomplete download). |
| 240 | - if ($file['attachment_type'] != 3 && empty($showThumb) && $range === 0) |
|
| 241 | - $smcFunc['db_query']('', ' |
|
| 243 | + if ($file['attachment_type'] != 3 && empty($showThumb) && $range === 0) { |
|
| 244 | + $smcFunc['db_query']('', ' |
|
| 242 | 245 | UPDATE {db_prefix}attachments |
| 243 | 246 | SET downloads = downloads + 1 |
| 244 | 247 | WHERE id_attach = {int:id_attach}', |
@@ -246,12 +249,14 @@ discard block |
||
| 246 | 249 | 'id_attach' => $attachId, |
| 247 | 250 | ) |
| 248 | 251 | ); |
| 252 | + } |
|
| 249 | 253 | |
| 250 | 254 | // Send the attachment headers. |
| 251 | 255 | header('pragma: '); |
| 252 | 256 | |
| 253 | - if (!isBrowser('gecko')) |
|
| 254 | - header('content-transfer-encoding: binary'); |
|
| 257 | + if (!isBrowser('gecko')) { |
|
| 258 | + header('content-transfer-encoding: binary'); |
|
| 259 | + } |
|
| 255 | 260 | |
| 256 | 261 | header('expires: ' . gmdate('D, d M Y H:i:s', time() + 525600 * 60) . ' GMT'); |
| 257 | 262 | header('last-modified: ' . gmdate('D, d M Y H:i:s', filemtime($file['filePath'])) . ' GMT'); |
@@ -260,18 +265,19 @@ discard block |
||
| 260 | 265 | header('etag: ' . $eTag); |
| 261 | 266 | |
| 262 | 267 | // Make sure the mime type warrants an inline display. |
| 263 | - if (isset($_REQUEST['image']) && !empty($file['mime_type']) && strpos($file['mime_type'], 'image/') !== 0) |
|
| 264 | - unset($_REQUEST['image']); |
|
| 268 | + if (isset($_REQUEST['image']) && !empty($file['mime_type']) && strpos($file['mime_type'], 'image/') !== 0) { |
|
| 269 | + unset($_REQUEST['image']); |
|
| 270 | + } |
|
| 265 | 271 | |
| 266 | 272 | // Does this have a mime type? |
| 267 | - elseif (!empty($file['mime_type']) && (isset($_REQUEST['image']) || !in_array($file['fileext'], array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff')))) |
|
| 268 | - header('content-type: ' . strtr($file['mime_type'], array('image/bmp' => 'image/x-ms-bmp'))); |
|
| 269 | - |
|
| 270 | - else |
|
| 273 | + elseif (!empty($file['mime_type']) && (isset($_REQUEST['image']) || !in_array($file['fileext'], array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff')))) { |
|
| 274 | + header('content-type: ' . strtr($file['mime_type'], array('image/bmp' => 'image/x-ms-bmp'))); |
|
| 275 | + } else |
|
| 271 | 276 | { |
| 272 | 277 | header('content-type: ' . (isBrowser('ie') || isBrowser('opera') ? 'application/octetstream' : 'application/octet-stream')); |
| 273 | - if (isset($_REQUEST['image'])) |
|
| 274 | - unset($_REQUEST['image']); |
|
| 278 | + if (isset($_REQUEST['image'])) { |
|
| 279 | + unset($_REQUEST['image']); |
|
| 280 | + } |
|
| 275 | 281 | } |
| 276 | 282 | |
| 277 | 283 | // Convert the file to UTF-8, cuz most browsers dig that. |
@@ -279,24 +285,22 @@ discard block |
||
| 279 | 285 | $disposition = !isset($_REQUEST['image']) ? 'attachment' : 'inline'; |
| 280 | 286 | |
| 281 | 287 | // Different browsers like different standards... |
| 282 | - if (isBrowser('firefox')) |
|
| 283 | - header('content-disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name))); |
|
| 284 | - |
|
| 285 | - elseif (isBrowser('opera')) |
|
| 286 | - header('content-disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"'); |
|
| 287 | - |
|
| 288 | - elseif (isBrowser('ie')) |
|
| 289 | - header('content-disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"'); |
|
| 290 | - |
|
| 291 | - else |
|
| 292 | - header('content-disposition: ' . $disposition . '; filename="' . $utf8name . '"'); |
|
| 288 | + if (isBrowser('firefox')) { |
|
| 289 | + header('content-disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name))); |
|
| 290 | + } elseif (isBrowser('opera')) { |
|
| 291 | + header('content-disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"'); |
|
| 292 | + } elseif (isBrowser('ie')) { |
|
| 293 | + header('content-disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"'); |
|
| 294 | + } else { |
|
| 295 | + header('content-disposition: ' . $disposition . '; filename="' . $utf8name . '"'); |
|
| 296 | + } |
|
| 293 | 297 | |
| 294 | 298 | // If this has an "image extension" - but isn't actually an image - then ensure it isn't cached cause of silly IE. |
| 295 | - if (!isset($_REQUEST['image']) && in_array($file['fileext'], array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff'))) |
|
| 296 | - header('cache-control: no-cache'); |
|
| 297 | - |
|
| 298 | - else |
|
| 299 | - header('cache-control: max-age=' . (525600 * 60) . ', private'); |
|
| 299 | + if (!isset($_REQUEST['image']) && in_array($file['fileext'], array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff'))) { |
|
| 300 | + header('cache-control: no-cache'); |
|
| 301 | + } else { |
|
| 302 | + header('cache-control: max-age=' . (525600 * 60) . ', private'); |
|
| 303 | + } |
|
| 300 | 304 | |
| 301 | 305 | // Multipart and resuming support |
| 302 | 306 | if (isset($_SERVER['HTTP_RANGE'])) |
@@ -304,9 +308,9 @@ discard block |
||
| 304 | 308 | header("HTTP/1.1 206 Partial Content"); |
| 305 | 309 | header("content-length: $new_length"); |
| 306 | 310 | header("content-range: bytes $range-$range_end/$size"); |
| 311 | + } else { |
|
| 312 | + header("content-length: " . $size); |
|
| 307 | 313 | } |
| 308 | - else |
|
| 309 | - header("content-length: " . $size); |
|
| 310 | 314 | |
| 311 | 315 | |
| 312 | 316 | // Try to buy some time... |
@@ -315,8 +319,9 @@ discard block |
||
| 315 | 319 | // For multipart/resumable downloads, send the requested chunk(s) of the file |
| 316 | 320 | if (isset($_SERVER['HTTP_RANGE'])) |
| 317 | 321 | { |
| 318 | - while (@ob_get_level() > 0) |
|
| 319 | - @ob_end_clean(); |
|
| 322 | + while (@ob_get_level() > 0) { |
|
| 323 | + @ob_end_clean(); |
|
| 324 | + } |
|
| 320 | 325 | |
| 321 | 326 | // 40 kilobytes is a good-ish amount |
| 322 | 327 | $chunksize = 40 * 1024; |
@@ -340,8 +345,9 @@ discard block |
||
| 340 | 345 | elseif ($size > 4194304) |
| 341 | 346 | { |
| 342 | 347 | // Forcibly end any output buffering going on. |
| 343 | - while (@ob_get_level() > 0) |
|
| 344 | - @ob_end_clean(); |
|
| 348 | + while (@ob_get_level() > 0) { |
|
| 349 | + @ob_end_clean(); |
|
| 350 | + } |
|
| 345 | 351 | |
| 346 | 352 | $fp = fopen($file['filePath'], 'rb'); |
| 347 | 353 | while (!feof($fp)) |
@@ -353,8 +359,9 @@ discard block |
||
| 353 | 359 | } |
| 354 | 360 | |
| 355 | 361 | // On some of the less-bright hosts, readfile() is disabled. It's just a faster, more byte safe, version of what's in the if. |
| 356 | - elseif (@readfile($file['filePath']) === null) |
|
| 357 | - echo file_get_contents($file['filePath']); |
|
| 362 | + elseif (@readfile($file['filePath']) === null) { |
|
| 363 | + echo file_get_contents($file['filePath']); |
|
| 364 | + } |
|
| 358 | 365 | |
| 359 | 366 | die(); |
| 360 | 367 | } |