@@ -20,8 +20,9 @@ discard block |
||
| 20 | 20 | // ><html dir="ltr"><head><title>Error!</title></head><body>Sorry, this installer requires PHP!<div style="display: none;"> |
| 21 | 21 | |
| 22 | 22 | // Let's pull in useful classes |
| 23 | -if (!defined('SMF')) |
|
| 23 | +if (!defined('SMF')) { |
|
| 24 | 24 | define('SMF', 1); |
| 25 | +} |
|
| 25 | 26 | |
| 26 | 27 | require_once('Sources/Class-Package.php'); |
| 27 | 28 | |
@@ -63,10 +64,11 @@ discard block |
||
| 63 | 64 | |
| 64 | 65 | list ($charcode) = pg_fetch_row($request); |
| 65 | 66 | |
| 66 | - if ($charcode == 'UTF8') |
|
| 67 | - return true; |
|
| 68 | - else |
|
| 69 | - return false; |
|
| 67 | + if ($charcode == 'UTF8') { |
|
| 68 | + return true; |
|
| 69 | + } else { |
|
| 70 | + return false; |
|
| 71 | + } |
|
| 70 | 72 | }, |
| 71 | 73 | 'utf8_version' => '8.0', |
| 72 | 74 | 'utf8_version_check' => '$request = pg_query(\'SELECT version()\'); list ($version) = pg_fetch_row($request); list($pgl, $version) = explode(" ", $version); return $version;', |
@@ -76,12 +78,14 @@ discard block |
||
| 76 | 78 | $value = preg_replace('~[^A-Za-z0-9_\$]~', '', $value); |
| 77 | 79 | |
| 78 | 80 | // Is it reserved? |
| 79 | - if ($value == 'pg_') |
|
| 80 | - return $txt['error_db_prefix_reserved']; |
|
| 81 | + if ($value == 'pg_') { |
|
| 82 | + return $txt['error_db_prefix_reserved']; |
|
| 83 | + } |
|
| 81 | 84 | |
| 82 | 85 | // Is the prefix numeric? |
| 83 | - if (preg_match('~^\d~', $value)) |
|
| 84 | - return $txt['error_db_prefix_numeric']; |
|
| 86 | + if (preg_match('~^\d~', $value)) { |
|
| 87 | + return $txt['error_db_prefix_numeric']; |
|
| 88 | + } |
|
| 85 | 89 | |
| 86 | 90 | return true; |
| 87 | 91 | }, |
@@ -128,10 +132,11 @@ discard block |
||
| 128 | 132 | $incontext['skip'] = false; |
| 129 | 133 | |
| 130 | 134 | // Call the step and if it returns false that means pause! |
| 131 | - if (function_exists($step[2]) && $step[2]() === false) |
|
| 132 | - break; |
|
| 133 | - elseif (function_exists($step[2])) |
|
| 134 | - $incontext['current_step']++; |
|
| 135 | + if (function_exists($step[2]) && $step[2]() === false) { |
|
| 136 | + break; |
|
| 137 | + } elseif (function_exists($step[2])) { |
|
| 138 | + $incontext['current_step']++; |
|
| 139 | + } |
|
| 135 | 140 | |
| 136 | 141 | // No warnings pass on. |
| 137 | 142 | $incontext['warning'] = ''; |
@@ -147,8 +152,9 @@ discard block |
||
| 147 | 152 | global $databases; |
| 148 | 153 | |
| 149 | 154 | // Just so people using older versions of PHP aren't left in the cold. |
| 150 | - if (!isset($_SERVER['PHP_SELF'])) |
|
| 151 | - $_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php'; |
|
| 155 | + if (!isset($_SERVER['PHP_SELF'])) { |
|
| 156 | + $_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php'; |
|
| 157 | + } |
|
| 152 | 158 | |
| 153 | 159 | // Enable error reporting for fatal errors. |
| 154 | 160 | error_reporting(E_ERROR | E_PARSE); |
@@ -164,21 +170,23 @@ discard block |
||
| 164 | 170 | { |
| 165 | 171 | ob_start(); |
| 166 | 172 | |
| 167 | - if (ini_get('session.save_handler') == 'user') |
|
| 168 | - @ini_set('session.save_handler', 'files'); |
|
| 169 | - if (function_exists('session_start')) |
|
| 170 | - @session_start(); |
|
| 171 | - } |
|
| 172 | - else |
|
| 173 | + if (ini_get('session.save_handler') == 'user') { |
|
| 174 | + @ini_set('session.save_handler', 'files'); |
|
| 175 | + } |
|
| 176 | + if (function_exists('session_start')) { |
|
| 177 | + @session_start(); |
|
| 178 | + } |
|
| 179 | + } else |
|
| 173 | 180 | { |
| 174 | 181 | ob_start('ob_gzhandler'); |
| 175 | 182 | |
| 176 | - if (ini_get('session.save_handler') == 'user') |
|
| 177 | - @ini_set('session.save_handler', 'files'); |
|
| 183 | + if (ini_get('session.save_handler') == 'user') { |
|
| 184 | + @ini_set('session.save_handler', 'files'); |
|
| 185 | + } |
|
| 178 | 186 | session_start(); |
| 179 | 187 | |
| 180 | - if (!headers_sent()) |
|
| 181 | - echo '<!DOCTYPE html> |
|
| 188 | + if (!headers_sent()) { |
|
| 189 | + echo '<!DOCTYPE html> |
|
| 182 | 190 | <html> |
| 183 | 191 | <head> |
| 184 | 192 | <title>', htmlspecialchars($_GET['pass_string']), '</title> |
@@ -187,14 +195,16 @@ discard block |
||
| 187 | 195 | <strong>', htmlspecialchars($_GET['pass_string']), '</strong> |
| 188 | 196 | </body> |
| 189 | 197 | </html>'; |
| 198 | + } |
|
| 190 | 199 | exit; |
| 191 | 200 | } |
| 192 | 201 | |
| 193 | 202 | // Add slashes, as long as they aren't already being added. |
| 194 | - if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0) |
|
| 195 | - foreach ($_POST as $k => $v) |
|
| 203 | + if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0) { |
|
| 204 | + foreach ($_POST as $k => $v) |
|
| 196 | 205 | if (strpos($k, 'password') === false && strpos($k, 'db_passwd') === false) |
| 197 | 206 | $_POST[$k] = addslashes($v); |
| 207 | + } |
|
| 198 | 208 | |
| 199 | 209 | // This is really quite simple; if ?delete is on the URL, delete the installer... |
| 200 | 210 | if (isset($_GET['delete'])) |
@@ -215,8 +225,7 @@ discard block |
||
| 215 | 225 | $ftp->close(); |
| 216 | 226 | |
| 217 | 227 | unset($_SESSION['installer_temp_ftp']); |
| 218 | - } |
|
| 219 | - else |
|
| 228 | + } else |
|
| 220 | 229 | { |
| 221 | 230 | @unlink(__FILE__); |
| 222 | 231 | |
@@ -230,10 +239,11 @@ discard block |
||
| 230 | 239 | // Now just redirect to a blank.png... |
| 231 | 240 | $secure = false; |
| 232 | 241 | |
| 233 | - if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') |
|
| 234 | - $secure = true; |
|
| 235 | - elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') |
|
| 236 | - $secure = true; |
|
| 242 | + if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { |
|
| 243 | + $secure = true; |
|
| 244 | + } elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') { |
|
| 245 | + $secure = true; |
|
| 246 | + } |
|
| 237 | 247 | |
| 238 | 248 | header('Location: http' . ($secure ? 's' : '') . '://' . (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT']) . dirname($_SERVER['PHP_SELF']) . '/Themes/default/images/blank.png'); |
| 239 | 249 | exit; |
@@ -244,10 +254,11 @@ discard block |
||
| 244 | 254 | { |
| 245 | 255 | // Get PHP's default timezone, if set |
| 246 | 256 | $ini_tz = ini_get('date.timezone'); |
| 247 | - if (!empty($ini_tz)) |
|
| 248 | - $timezone_id = $ini_tz; |
|
| 249 | - else |
|
| 250 | - $timezone_id = ''; |
|
| 257 | + if (!empty($ini_tz)) { |
|
| 258 | + $timezone_id = $ini_tz; |
|
| 259 | + } else { |
|
| 260 | + $timezone_id = ''; |
|
| 261 | + } |
|
| 251 | 262 | |
| 252 | 263 | // If date.timezone is unset, invalid, or just plain weird, make a best guess |
| 253 | 264 | if (!in_array($timezone_id, timezone_identifiers_list())) |
@@ -277,8 +288,9 @@ discard block |
||
| 277 | 288 | $dir = dir(dirname(__FILE__) . '/Themes/default/languages'); |
| 278 | 289 | while ($entry = $dir->read()) |
| 279 | 290 | { |
| 280 | - if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') |
|
| 281 | - $incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12)); |
|
| 291 | + if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') { |
|
| 292 | + $incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12)); |
|
| 293 | + } |
|
| 282 | 294 | } |
| 283 | 295 | $dir->close(); |
| 284 | 296 | } |
@@ -313,10 +325,11 @@ discard block |
||
| 313 | 325 | } |
| 314 | 326 | |
| 315 | 327 | // Override the language file? |
| 316 | - if (isset($_GET['lang_file'])) |
|
| 317 | - $_SESSION['installer_temp_lang'] = $_GET['lang_file']; |
|
| 318 | - elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) |
|
| 319 | - $_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file']; |
|
| 328 | + if (isset($_GET['lang_file'])) { |
|
| 329 | + $_SESSION['installer_temp_lang'] = $_GET['lang_file']; |
|
| 330 | + } elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) { |
|
| 331 | + $_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file']; |
|
| 332 | + } |
|
| 320 | 333 | |
| 321 | 334 | // Make sure it exists, if it doesn't reset it. |
| 322 | 335 | if (!isset($_SESSION['installer_temp_lang']) || preg_match('~[^\\w_\\-.]~', $_SESSION['installer_temp_lang']) === 1 || !file_exists(dirname(__FILE__) . '/Themes/default/languages/' . $_SESSION['installer_temp_lang'])) |
@@ -325,8 +338,9 @@ discard block |
||
| 325 | 338 | list ($_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']); |
| 326 | 339 | |
| 327 | 340 | // If we have english and some other language, use the other language. We Americans hate english :P. |
| 328 | - if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) |
|
| 329 | - list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']); |
|
| 341 | + if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) { |
|
| 342 | + list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']); |
|
| 343 | + } |
|
| 330 | 344 | } |
| 331 | 345 | |
| 332 | 346 | // And now include the actual language file itself. |
@@ -343,15 +357,18 @@ discard block |
||
| 343 | 357 | global $db_prefix, $db_connection, $sourcedir, $smcFunc, $modSettings; |
| 344 | 358 | global $db_server, $db_passwd, $db_type, $db_name, $db_user, $db_persist; |
| 345 | 359 | |
| 346 | - if (empty($sourcedir)) |
|
| 347 | - $sourcedir = dirname(__FILE__) . '/Sources'; |
|
| 360 | + if (empty($sourcedir)) { |
|
| 361 | + $sourcedir = dirname(__FILE__) . '/Sources'; |
|
| 362 | + } |
|
| 348 | 363 | |
| 349 | 364 | // Need this to check whether we need the database password. |
| 350 | 365 | require(dirname(__FILE__) . '/Settings.php'); |
| 351 | - if (!defined('SMF')) |
|
| 352 | - define('SMF', 1); |
|
| 353 | - if (empty($smcFunc)) |
|
| 354 | - $smcFunc = array(); |
|
| 366 | + if (!defined('SMF')) { |
|
| 367 | + define('SMF', 1); |
|
| 368 | + } |
|
| 369 | + if (empty($smcFunc)) { |
|
| 370 | + $smcFunc = array(); |
|
| 371 | + } |
|
| 355 | 372 | |
| 356 | 373 | $modSettings['disableQueryCheck'] = true; |
| 357 | 374 | |
@@ -359,8 +376,9 @@ discard block |
||
| 359 | 376 | if (!$db_connection) |
| 360 | 377 | { |
| 361 | 378 | require_once($sourcedir . '/Subs-Db-' . $db_type . '.php'); |
| 362 | - if (version_compare(PHP_VERSION, '5', '<')) |
|
| 363 | - require_once($sourcedir . '/Subs-Compat.php'); |
|
| 379 | + if (version_compare(PHP_VERSION, '5', '<')) { |
|
| 380 | + require_once($sourcedir . '/Subs-Compat.php'); |
|
| 381 | + } |
|
| 364 | 382 | |
| 365 | 383 | $db_options = array('persist' => $db_persist); |
| 366 | 384 | $port = ''; |
@@ -371,19 +389,20 @@ discard block |
||
| 371 | 389 | if ($db_type == 'mysql') |
| 372 | 390 | { |
| 373 | 391 | $port = ((int) $_POST['db_port'] == ini_get($db_type . 'default_port')) ? '' : (int) $_POST['db_port']; |
| 374 | - } |
|
| 375 | - elseif ($db_type == 'postgresql') |
|
| 392 | + } elseif ($db_type == 'postgresql') |
|
| 376 | 393 | { |
| 377 | 394 | // PostgreSQL doesn't have a default port setting in php.ini, so just check against the default |
| 378 | 395 | $port = ((int) $_POST['db_port'] == 5432) ? '' : (int) $_POST['db_port']; |
| 379 | 396 | } |
| 380 | 397 | } |
| 381 | 398 | |
| 382 | - if (!empty($port)) |
|
| 383 | - $db_options['port'] = $port; |
|
| 399 | + if (!empty($port)) { |
|
| 400 | + $db_options['port'] = $port; |
|
| 401 | + } |
|
| 384 | 402 | |
| 385 | - if (!$db_connection) |
|
| 386 | - $db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options); |
|
| 403 | + if (!$db_connection) { |
|
| 404 | + $db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options); |
|
| 405 | + } |
|
| 387 | 406 | } |
| 388 | 407 | } |
| 389 | 408 | |
@@ -411,8 +430,9 @@ discard block |
||
| 411 | 430 | // @todo REMOVE THIS!! |
| 412 | 431 | else |
| 413 | 432 | { |
| 414 | - if (function_exists('doStep' . $_GET['step'])) |
|
| 415 | - call_user_func('doStep' . $_GET['step']); |
|
| 433 | + if (function_exists('doStep' . $_GET['step'])) { |
|
| 434 | + call_user_func('doStep' . $_GET['step']); |
|
| 435 | + } |
|
| 416 | 436 | } |
| 417 | 437 | // Show the footer. |
| 418 | 438 | template_install_below(); |
@@ -430,8 +450,9 @@ discard block |
||
| 430 | 450 | $incontext['sub_template'] = 'welcome_message'; |
| 431 | 451 | |
| 432 | 452 | // Done the submission? |
| 433 | - if (isset($_POST['contbutt'])) |
|
| 434 | - return true; |
|
| 453 | + if (isset($_POST['contbutt'])) { |
|
| 454 | + return true; |
|
| 455 | + } |
|
| 435 | 456 | |
| 436 | 457 | // See if we think they have already installed it? |
| 437 | 458 | if (is_readable(dirname(__FILE__) . '/Settings.php')) |
@@ -439,14 +460,17 @@ discard block |
||
| 439 | 460 | $probably_installed = 0; |
| 440 | 461 | foreach (file(dirname(__FILE__) . '/Settings.php') as $line) |
| 441 | 462 | { |
| 442 | - if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line)) |
|
| 443 | - $probably_installed++; |
|
| 444 | - if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line)) |
|
| 445 | - $probably_installed++; |
|
| 463 | + if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line)) { |
|
| 464 | + $probably_installed++; |
|
| 465 | + } |
|
| 466 | + if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line)) { |
|
| 467 | + $probably_installed++; |
|
| 468 | + } |
|
| 446 | 469 | } |
| 447 | 470 | |
| 448 | - if ($probably_installed == 2) |
|
| 449 | - $incontext['warning'] = $txt['error_already_installed']; |
|
| 471 | + if ($probably_installed == 2) { |
|
| 472 | + $incontext['warning'] = $txt['error_already_installed']; |
|
| 473 | + } |
|
| 450 | 474 | } |
| 451 | 475 | |
| 452 | 476 | // Is some database support even compiled in? |
@@ -461,45 +485,54 @@ discard block |
||
| 461 | 485 | $databases[$key]['supported'] = false; |
| 462 | 486 | $notFoundSQLFile = true; |
| 463 | 487 | $txt['error_db_script_missing'] = sprintf($txt['error_db_script_missing'], 'install_' . $GLOBALS['db_script_version'] . '_' . $type . '.sql'); |
| 488 | + } else { |
|
| 489 | + $incontext['supported_databases'][] = $db; |
|
| 464 | 490 | } |
| 465 | - else |
|
| 466 | - $incontext['supported_databases'][] = $db; |
|
| 467 | 491 | } |
| 468 | 492 | } |
| 469 | 493 | |
| 470 | 494 | // Check the PHP version. |
| 471 | - if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>='))) |
|
| 472 | - $error = 'error_php_too_low'; |
|
| 495 | + if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>='))) { |
|
| 496 | + $error = 'error_php_too_low'; |
|
| 497 | + } |
|
| 473 | 498 | // Make sure we have a supported database |
| 474 | - elseif (empty($incontext['supported_databases'])) |
|
| 475 | - $error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing'; |
|
| 499 | + elseif (empty($incontext['supported_databases'])) { |
|
| 500 | + $error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing'; |
|
| 501 | + } |
|
| 476 | 502 | // How about session support? Some crazy sysadmin remove it? |
| 477 | - elseif (!function_exists('session_start')) |
|
| 478 | - $error = 'error_session_missing'; |
|
| 503 | + elseif (!function_exists('session_start')) { |
|
| 504 | + $error = 'error_session_missing'; |
|
| 505 | + } |
|
| 479 | 506 | // Make sure they uploaded all the files. |
| 480 | - elseif (!file_exists(dirname(__FILE__) . '/index.php')) |
|
| 481 | - $error = 'error_missing_files'; |
|
| 507 | + elseif (!file_exists(dirname(__FILE__) . '/index.php')) { |
|
| 508 | + $error = 'error_missing_files'; |
|
| 509 | + } |
|
| 482 | 510 | // Very simple check on the session.save_path for Windows. |
| 483 | 511 | // @todo Move this down later if they don't use database-driven sessions? |
| 484 | - elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\') |
|
| 485 | - $error = 'error_session_save_path'; |
|
| 512 | + elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\') { |
|
| 513 | + $error = 'error_session_save_path'; |
|
| 514 | + } |
|
| 486 | 515 | |
| 487 | 516 | // Since each of the three messages would look the same, anyway... |
| 488 | - if (isset($error)) |
|
| 489 | - $incontext['error'] = $txt[$error]; |
|
| 517 | + if (isset($error)) { |
|
| 518 | + $incontext['error'] = $txt[$error]; |
|
| 519 | + } |
|
| 490 | 520 | |
| 491 | 521 | // Mod_security blocks everything that smells funny. Let SMF handle security. |
| 492 | - if (!fixModSecurity() && !isset($_GET['overmodsecurity'])) |
|
| 493 | - $incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again']; |
|
| 522 | + if (!fixModSecurity() && !isset($_GET['overmodsecurity'])) { |
|
| 523 | + $incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again']; |
|
| 524 | + } |
|
| 494 | 525 | |
| 495 | 526 | // Confirm mbstring is loaded... |
| 496 | - if (!extension_loaded('mbstring')) |
|
| 497 | - $incontext['error'] = $txt['install_no_mbstring']; |
|
| 527 | + if (!extension_loaded('mbstring')) { |
|
| 528 | + $incontext['error'] = $txt['install_no_mbstring']; |
|
| 529 | + } |
|
| 498 | 530 | |
| 499 | 531 | // Check for https stream support. |
| 500 | 532 | $supported_streams = stream_get_wrappers(); |
| 501 | - if (!in_array('https', $supported_streams)) |
|
| 502 | - $incontext['warning'] = $txt['install_no_https']; |
|
| 533 | + if (!in_array('https', $supported_streams)) { |
|
| 534 | + $incontext['warning'] = $txt['install_no_https']; |
|
| 535 | + } |
|
| 503 | 536 | |
| 504 | 537 | return false; |
| 505 | 538 | } |
@@ -525,12 +558,14 @@ discard block |
||
| 525 | 558 | 'db_last_error.php', |
| 526 | 559 | ); |
| 527 | 560 | |
| 528 | - foreach ($incontext['detected_languages'] as $lang => $temp) |
|
| 529 | - $extra_files[] = 'Themes/default/languages/' . $lang; |
|
| 561 | + foreach ($incontext['detected_languages'] as $lang => $temp) { |
|
| 562 | + $extra_files[] = 'Themes/default/languages/' . $lang; |
|
| 563 | + } |
|
| 530 | 564 | |
| 531 | 565 | // With mod_security installed, we could attempt to fix it with .htaccess. |
| 532 | - if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules())) |
|
| 533 | - $writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.'; |
|
| 566 | + if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules())) { |
|
| 567 | + $writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.'; |
|
| 568 | + } |
|
| 534 | 569 | |
| 535 | 570 | $failed_files = array(); |
| 536 | 571 | |
@@ -542,20 +577,23 @@ discard block |
||
| 542 | 577 | foreach ($writable_files as $file) |
| 543 | 578 | { |
| 544 | 579 | // Some files won't exist, try to address up front |
| 545 | - if (!file_exists(dirname(__FILE__) . '/' . $file)) |
|
| 546 | - @touch(dirname(__FILE__) . '/' . $file); |
|
| 580 | + if (!file_exists(dirname(__FILE__) . '/' . $file)) { |
|
| 581 | + @touch(dirname(__FILE__) . '/' . $file); |
|
| 582 | + } |
|
| 547 | 583 | // NOW do the writable check... |
| 548 | 584 | if (!is_writable(dirname(__FILE__) . '/' . $file)) |
| 549 | 585 | { |
| 550 | 586 | @chmod(dirname(__FILE__) . '/' . $file, 0755); |
| 551 | 587 | |
| 552 | 588 | // Well, 755 hopefully worked... if not, try 777. |
| 553 | - if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777)) |
|
| 554 | - $failed_files[] = $file; |
|
| 589 | + if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777)) { |
|
| 590 | + $failed_files[] = $file; |
|
| 591 | + } |
|
| 555 | 592 | } |
| 556 | 593 | } |
| 557 | - foreach ($extra_files as $file) |
|
| 558 | - @chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777); |
|
| 594 | + foreach ($extra_files as $file) { |
|
| 595 | + @chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777); |
|
| 596 | + } |
|
| 559 | 597 | } |
| 560 | 598 | // Windows is trickier. Let's try opening for r+... |
| 561 | 599 | else |
@@ -565,30 +603,35 @@ discard block |
||
| 565 | 603 | foreach ($writable_files as $file) |
| 566 | 604 | { |
| 567 | 605 | // Folders can't be opened for write... but the index.php in them can ;) |
| 568 | - if (is_dir(dirname(__FILE__) . '/' . $file)) |
|
| 569 | - $file .= '/index.php'; |
|
| 606 | + if (is_dir(dirname(__FILE__) . '/' . $file)) { |
|
| 607 | + $file .= '/index.php'; |
|
| 608 | + } |
|
| 570 | 609 | |
| 571 | 610 | // Funny enough, chmod actually does do something on windows - it removes the read only attribute. |
| 572 | 611 | @chmod(dirname(__FILE__) . '/' . $file, 0777); |
| 573 | 612 | $fp = @fopen(dirname(__FILE__) . '/' . $file, 'r+'); |
| 574 | 613 | |
| 575 | 614 | // Hmm, okay, try just for write in that case... |
| 576 | - if (!is_resource($fp)) |
|
| 577 | - $fp = @fopen(dirname(__FILE__) . '/' . $file, 'w'); |
|
| 615 | + if (!is_resource($fp)) { |
|
| 616 | + $fp = @fopen(dirname(__FILE__) . '/' . $file, 'w'); |
|
| 617 | + } |
|
| 578 | 618 | |
| 579 | - if (!is_resource($fp)) |
|
| 580 | - $failed_files[] = $file; |
|
| 619 | + if (!is_resource($fp)) { |
|
| 620 | + $failed_files[] = $file; |
|
| 621 | + } |
|
| 581 | 622 | |
| 582 | 623 | @fclose($fp); |
| 583 | 624 | } |
| 584 | - foreach ($extra_files as $file) |
|
| 585 | - @chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777); |
|
| 625 | + foreach ($extra_files as $file) { |
|
| 626 | + @chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777); |
|
| 627 | + } |
|
| 586 | 628 | } |
| 587 | 629 | |
| 588 | 630 | $failure = count($failed_files) >= 1; |
| 589 | 631 | |
| 590 | - if (!isset($_SERVER)) |
|
| 591 | - return !$failure; |
|
| 632 | + if (!isset($_SERVER)) { |
|
| 633 | + return !$failure; |
|
| 634 | + } |
|
| 592 | 635 | |
| 593 | 636 | // Put the list into context. |
| 594 | 637 | $incontext['failed_files'] = $failed_files; |
@@ -636,19 +679,23 @@ discard block |
||
| 636 | 679 | |
| 637 | 680 | if (!isset($ftp) || $ftp->error !== false) |
| 638 | 681 | { |
| 639 | - if (!isset($ftp)) |
|
| 640 | - $ftp = new ftp_connection(null); |
|
| 682 | + if (!isset($ftp)) { |
|
| 683 | + $ftp = new ftp_connection(null); |
|
| 684 | + } |
|
| 641 | 685 | // Save the error so we can mess with listing... |
| 642 | - elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message)) |
|
| 643 | - $incontext['ftp_errors'][] = $ftp->last_message; |
|
| 686 | + elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message)) { |
|
| 687 | + $incontext['ftp_errors'][] = $ftp->last_message; |
|
| 688 | + } |
|
| 644 | 689 | |
| 645 | 690 | list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__)); |
| 646 | 691 | |
| 647 | - if (empty($_POST['ftp_path']) && $found_path) |
|
| 648 | - $_POST['ftp_path'] = $detect_path; |
|
| 692 | + if (empty($_POST['ftp_path']) && $found_path) { |
|
| 693 | + $_POST['ftp_path'] = $detect_path; |
|
| 694 | + } |
|
| 649 | 695 | |
| 650 | - if (!isset($_POST['ftp_username'])) |
|
| 651 | - $_POST['ftp_username'] = $username; |
|
| 696 | + if (!isset($_POST['ftp_username'])) { |
|
| 697 | + $_POST['ftp_username'] = $username; |
|
| 698 | + } |
|
| 652 | 699 | |
| 653 | 700 | // Set the username etc, into context. |
| 654 | 701 | $incontext['ftp'] = array( |
@@ -660,8 +707,7 @@ discard block |
||
| 660 | 707 | ); |
| 661 | 708 | |
| 662 | 709 | return false; |
| 663 | - } |
|
| 664 | - else |
|
| 710 | + } else |
|
| 665 | 711 | { |
| 666 | 712 | $_SESSION['installer_temp_ftp'] = array( |
| 667 | 713 | 'server' => $_POST['ftp_server'], |
@@ -675,10 +721,12 @@ discard block |
||
| 675 | 721 | |
| 676 | 722 | foreach ($failed_files as $file) |
| 677 | 723 | { |
| 678 | - if (!is_writable(dirname(__FILE__) . '/' . $file)) |
|
| 679 | - $ftp->chmod($file, 0755); |
|
| 680 | - if (!is_writable(dirname(__FILE__) . '/' . $file)) |
|
| 681 | - $ftp->chmod($file, 0777); |
|
| 724 | + if (!is_writable(dirname(__FILE__) . '/' . $file)) { |
|
| 725 | + $ftp->chmod($file, 0755); |
|
| 726 | + } |
|
| 727 | + if (!is_writable(dirname(__FILE__) . '/' . $file)) { |
|
| 728 | + $ftp->chmod($file, 0777); |
|
| 729 | + } |
|
| 682 | 730 | if (!is_writable(dirname(__FILE__) . '/' . $file)) |
| 683 | 731 | { |
| 684 | 732 | $failed_files_updated[] = $file; |
@@ -734,15 +782,17 @@ discard block |
||
| 734 | 782 | |
| 735 | 783 | if (!$foundOne) |
| 736 | 784 | { |
| 737 | - if (isset($db['default_host'])) |
|
| 738 | - $incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost'; |
|
| 785 | + if (isset($db['default_host'])) { |
|
| 786 | + $incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost'; |
|
| 787 | + } |
|
| 739 | 788 | if (isset($db['default_user'])) |
| 740 | 789 | { |
| 741 | 790 | $incontext['db']['user'] = ini_get($db['default_user']); |
| 742 | 791 | $incontext['db']['name'] = ini_get($db['default_user']); |
| 743 | 792 | } |
| 744 | - if (isset($db['default_password'])) |
|
| 745 | - $incontext['db']['pass'] = ini_get($db['default_password']); |
|
| 793 | + if (isset($db['default_password'])) { |
|
| 794 | + $incontext['db']['pass'] = ini_get($db['default_password']); |
|
| 795 | + } |
|
| 746 | 796 | |
| 747 | 797 | // For simplicity and less confusion, leave the port blank by default |
| 748 | 798 | $incontext['db']['port'] = ''; |
@@ -761,10 +811,10 @@ discard block |
||
| 761 | 811 | $incontext['db']['server'] = $_POST['db_server']; |
| 762 | 812 | $incontext['db']['prefix'] = $_POST['db_prefix']; |
| 763 | 813 | |
| 764 | - if (!empty($_POST['db_port'])) |
|
| 765 | - $incontext['db']['port'] = $_POST['db_port']; |
|
| 766 | - } |
|
| 767 | - else |
|
| 814 | + if (!empty($_POST['db_port'])) { |
|
| 815 | + $incontext['db']['port'] = $_POST['db_port']; |
|
| 816 | + } |
|
| 817 | + } else |
|
| 768 | 818 | { |
| 769 | 819 | $incontext['db']['prefix'] = 'smf_'; |
| 770 | 820 | } |
@@ -800,10 +850,11 @@ discard block |
||
| 800 | 850 | if (!empty($_POST['db_port'])) |
| 801 | 851 | { |
| 802 | 852 | // For MySQL, we can get the "default port" from PHP. PostgreSQL has no such option though. |
| 803 | - if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port')) |
|
| 804 | - $vars['db_port'] = (int) $_POST['db_port']; |
|
| 805 | - elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432) |
|
| 806 | - $vars['db_port'] = (int) $_POST['db_port']; |
|
| 853 | + if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port')) { |
|
| 854 | + $vars['db_port'] = (int) $_POST['db_port']; |
|
| 855 | + } elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432) { |
|
| 856 | + $vars['db_port'] = (int) $_POST['db_port']; |
|
| 857 | + } |
|
| 807 | 858 | } |
| 808 | 859 | |
| 809 | 860 | // God I hope it saved! |
@@ -816,8 +867,9 @@ discard block |
||
| 816 | 867 | // Make sure it works. |
| 817 | 868 | require(dirname(__FILE__) . '/Settings.php'); |
| 818 | 869 | |
| 819 | - if (empty($sourcedir)) |
|
| 820 | - $sourcedir = dirname(__FILE__) . '/Sources'; |
|
| 870 | + if (empty($sourcedir)) { |
|
| 871 | + $sourcedir = dirname(__FILE__) . '/Sources'; |
|
| 872 | + } |
|
| 821 | 873 | |
| 822 | 874 | // Better find the database file! |
| 823 | 875 | if (!file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) |
@@ -827,18 +879,21 @@ discard block |
||
| 827 | 879 | } |
| 828 | 880 | |
| 829 | 881 | // Now include it for database functions! |
| 830 | - if (!defined('SMF')) |
|
| 831 | - define('SMF', 1); |
|
| 882 | + if (!defined('SMF')) { |
|
| 883 | + define('SMF', 1); |
|
| 884 | + } |
|
| 832 | 885 | |
| 833 | 886 | $modSettings['disableQueryCheck'] = true; |
| 834 | - if (empty($smcFunc)) |
|
| 835 | - $smcFunc = array(); |
|
| 887 | + if (empty($smcFunc)) { |
|
| 888 | + $smcFunc = array(); |
|
| 889 | + } |
|
| 836 | 890 | |
| 837 | 891 | require_once($sourcedir . '/Subs-Db-' . $db_type . '.php'); |
| 838 | 892 | |
| 839 | 893 | // What - running PHP4? The shame! |
| 840 | - if (version_compare(PHP_VERSION, '5', '<')) |
|
| 841 | - require_once($sourcedir . '/Subs-Compat.php'); |
|
| 894 | + if (version_compare(PHP_VERSION, '5', '<')) { |
|
| 895 | + require_once($sourcedir . '/Subs-Compat.php'); |
|
| 896 | + } |
|
| 842 | 897 | |
| 843 | 898 | // Attempt a connection. |
| 844 | 899 | $needsDB = !empty($databases[$db_type]['always_has_db']); |
@@ -926,12 +981,14 @@ discard block |
||
| 926 | 981 | $incontext['page_title'] = $txt['install_settings']; |
| 927 | 982 | |
| 928 | 983 | // Let's see if we got the database type correct. |
| 929 | - if (isset($_POST['db_type'], $databases[$_POST['db_type']])) |
|
| 930 | - $db_type = $_POST['db_type']; |
|
| 984 | + if (isset($_POST['db_type'], $databases[$_POST['db_type']])) { |
|
| 985 | + $db_type = $_POST['db_type']; |
|
| 986 | + } |
|
| 931 | 987 | |
| 932 | 988 | // Else we'd better be able to get the connection. |
| 933 | - else |
|
| 934 | - load_database(); |
|
| 989 | + else { |
|
| 990 | + load_database(); |
|
| 991 | + } |
|
| 935 | 992 | |
| 936 | 993 | $db_type = isset($_POST['db_type']) ? $_POST['db_type'] : $db_type; |
| 937 | 994 | |
@@ -940,10 +997,11 @@ discard block |
||
| 940 | 997 | |
| 941 | 998 | $secure = false; |
| 942 | 999 | |
| 943 | - if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') |
|
| 944 | - $secure = true; |
|
| 945 | - elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') |
|
| 946 | - $secure = true; |
|
| 1000 | + if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { |
|
| 1001 | + $secure = true; |
|
| 1002 | + } elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') { |
|
| 1003 | + $secure = true; |
|
| 1004 | + } |
|
| 947 | 1005 | |
| 948 | 1006 | // Now, to put what we've learned together... and add a path. |
| 949 | 1007 | $incontext['detected_url'] = 'http' . ($secure ? 's' : '') . '://' . $host . substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/')); |
@@ -975,18 +1033,21 @@ discard block |
||
| 975 | 1033 | // Submitting? |
| 976 | 1034 | if (isset($_POST['boardurl'])) |
| 977 | 1035 | { |
| 978 | - if (substr($_POST['boardurl'], -10) == '/index.php') |
|
| 979 | - $_POST['boardurl'] = substr($_POST['boardurl'], 0, -10); |
|
| 980 | - elseif (substr($_POST['boardurl'], -1) == '/') |
|
| 981 | - $_POST['boardurl'] = substr($_POST['boardurl'], 0, -1); |
|
| 982 | - if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') |
|
| 983 | - $_POST['boardurl'] = 'http://' . $_POST['boardurl']; |
|
| 1036 | + if (substr($_POST['boardurl'], -10) == '/index.php') { |
|
| 1037 | + $_POST['boardurl'] = substr($_POST['boardurl'], 0, -10); |
|
| 1038 | + } elseif (substr($_POST['boardurl'], -1) == '/') { |
|
| 1039 | + $_POST['boardurl'] = substr($_POST['boardurl'], 0, -1); |
|
| 1040 | + } |
|
| 1041 | + if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') { |
|
| 1042 | + $_POST['boardurl'] = 'http://' . $_POST['boardurl']; |
|
| 1043 | + } |
|
| 984 | 1044 | |
| 985 | 1045 | //Make sure boardurl is aligned with ssl setting |
| 986 | - if (empty($_POST['force_ssl'])) |
|
| 987 | - $_POST['boardurl'] = strtr($_POST['boardurl'], array('https://' => 'http://')); |
|
| 988 | - else |
|
| 989 | - $_POST['boardurl'] = strtr($_POST['boardurl'], array('http://' => 'https://')); |
|
| 1046 | + if (empty($_POST['force_ssl'])) { |
|
| 1047 | + $_POST['boardurl'] = strtr($_POST['boardurl'], array('https://' => 'http://')); |
|
| 1048 | + } else { |
|
| 1049 | + $_POST['boardurl'] = strtr($_POST['boardurl'], array('http://' => 'https://')); |
|
| 1050 | + } |
|
| 990 | 1051 | |
| 991 | 1052 | // Save these variables. |
| 992 | 1053 | $vars = array( |
@@ -1025,10 +1086,10 @@ discard block |
||
| 1025 | 1086 | { |
| 1026 | 1087 | $incontext['error'] = sprintf($txt['error_utf8_version'], $databases[$db_type]['utf8_version']); |
| 1027 | 1088 | return false; |
| 1028 | - } |
|
| 1029 | - else |
|
| 1030 | - // Set the character set here. |
|
| 1089 | + } else { |
|
| 1090 | + // Set the character set here. |
|
| 1031 | 1091 | updateSettingsFile(array('db_character_set' => 'utf8')); |
| 1092 | + } |
|
| 1032 | 1093 | } |
| 1033 | 1094 | |
| 1034 | 1095 | // Good, skip on. |
@@ -1048,8 +1109,9 @@ discard block |
||
| 1048 | 1109 | $incontext['continue'] = 1; |
| 1049 | 1110 | |
| 1050 | 1111 | // Already done? |
| 1051 | - if (isset($_POST['pop_done'])) |
|
| 1052 | - return true; |
|
| 1112 | + if (isset($_POST['pop_done'])) { |
|
| 1113 | + return true; |
|
| 1114 | + } |
|
| 1053 | 1115 | |
| 1054 | 1116 | // Reload settings. |
| 1055 | 1117 | require(dirname(__FILE__) . '/Settings.php'); |
@@ -1067,8 +1129,9 @@ discard block |
||
| 1067 | 1129 | $modSettings = array(); |
| 1068 | 1130 | if ($result !== false) |
| 1069 | 1131 | { |
| 1070 | - while ($row = $smcFunc['db_fetch_assoc']($result)) |
|
| 1071 | - $modSettings[$row['variable']] = $row['value']; |
|
| 1132 | + while ($row = $smcFunc['db_fetch_assoc']($result)) { |
|
| 1133 | + $modSettings[$row['variable']] = $row['value']; |
|
| 1134 | + } |
|
| 1072 | 1135 | $smcFunc['db_free_result']($result); |
| 1073 | 1136 | |
| 1074 | 1137 | // Do they match? If so, this is just a refresh so charge on! |
@@ -1081,20 +1144,22 @@ discard block |
||
| 1081 | 1144 | $modSettings['disableQueryCheck'] = true; |
| 1082 | 1145 | |
| 1083 | 1146 | // If doing UTF8, select it. PostgreSQL requires passing it as a string... |
| 1084 | - if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support'])) |
|
| 1085 | - $smcFunc['db_query']('', ' |
|
| 1147 | + if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support'])) { |
|
| 1148 | + $smcFunc['db_query']('', ' |
|
| 1086 | 1149 | SET NAMES {string:utf8}', |
| 1087 | 1150 | array( |
| 1088 | 1151 | 'db_error_skip' => true, |
| 1089 | 1152 | 'utf8' => 'utf8', |
| 1090 | 1153 | ) |
| 1091 | 1154 | ); |
| 1155 | + } |
|
| 1092 | 1156 | |
| 1093 | 1157 | // Windows likes to leave the trailing slash, which yields to C:\path\to\SMF\/attachments... |
| 1094 | - if (substr(__DIR__, -1) == '\\') |
|
| 1095 | - $attachdir = __DIR__ . 'attachments'; |
|
| 1096 | - else |
|
| 1097 | - $attachdir = __DIR__ . '/attachments'; |
|
| 1158 | + if (substr(__DIR__, -1) == '\\') { |
|
| 1159 | + $attachdir = __DIR__ . 'attachments'; |
|
| 1160 | + } else { |
|
| 1161 | + $attachdir = __DIR__ . '/attachments'; |
|
| 1162 | + } |
|
| 1098 | 1163 | |
| 1099 | 1164 | $replaces = array( |
| 1100 | 1165 | '{$db_prefix}' => $db_prefix, |
@@ -1111,8 +1176,9 @@ discard block |
||
| 1111 | 1176 | |
| 1112 | 1177 | foreach ($txt as $key => $value) |
| 1113 | 1178 | { |
| 1114 | - if (substr($key, 0, 8) == 'default_') |
|
| 1115 | - $replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value); |
|
| 1179 | + if (substr($key, 0, 8) == 'default_') { |
|
| 1180 | + $replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value); |
|
| 1181 | + } |
|
| 1116 | 1182 | } |
| 1117 | 1183 | $replaces['{$default_reserved_names}'] = strtr($replaces['{$default_reserved_names}'], array('\\\\n' => '\\n')); |
| 1118 | 1184 | |
@@ -1127,8 +1193,9 @@ discard block |
||
| 1127 | 1193 | |
| 1128 | 1194 | while ($row = $smcFunc['db_fetch_assoc']($get_engines)) |
| 1129 | 1195 | { |
| 1130 | - if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') |
|
| 1131 | - $engines[] = $row['Engine']; |
|
| 1196 | + if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') { |
|
| 1197 | + $engines[] = $row['Engine']; |
|
| 1198 | + } |
|
| 1132 | 1199 | } |
| 1133 | 1200 | |
| 1134 | 1201 | // Done with this now |
@@ -1152,8 +1219,7 @@ discard block |
||
| 1152 | 1219 | $replaces['START TRANSACTION;'] = ''; |
| 1153 | 1220 | $replaces['COMMIT;'] = ''; |
| 1154 | 1221 | } |
| 1155 | - } |
|
| 1156 | - else |
|
| 1222 | + } else |
|
| 1157 | 1223 | { |
| 1158 | 1224 | $has_innodb = false; |
| 1159 | 1225 | } |
@@ -1175,21 +1241,24 @@ discard block |
||
| 1175 | 1241 | foreach ($sql_lines as $count => $line) |
| 1176 | 1242 | { |
| 1177 | 1243 | // No comments allowed! |
| 1178 | - if (substr(trim($line), 0, 1) != '#') |
|
| 1179 | - $current_statement .= "\n" . rtrim($line); |
|
| 1244 | + if (substr(trim($line), 0, 1) != '#') { |
|
| 1245 | + $current_statement .= "\n" . rtrim($line); |
|
| 1246 | + } |
|
| 1180 | 1247 | |
| 1181 | 1248 | // Is this the end of the query string? |
| 1182 | - if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines))) |
|
| 1183 | - continue; |
|
| 1249 | + if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines))) { |
|
| 1250 | + continue; |
|
| 1251 | + } |
|
| 1184 | 1252 | |
| 1185 | 1253 | // Does this table already exist? If so, don't insert more data into it! |
| 1186 | 1254 | if (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) != 0 && in_array($match[1], $exists)) |
| 1187 | 1255 | { |
| 1188 | 1256 | preg_match_all('~\)[,;]~', $current_statement, $matches); |
| 1189 | - if (!empty($matches[0])) |
|
| 1190 | - $incontext['sql_results']['insert_dups'] += count($matches[0]); |
|
| 1191 | - else |
|
| 1192 | - $incontext['sql_results']['insert_dups']++; |
|
| 1257 | + if (!empty($matches[0])) { |
|
| 1258 | + $incontext['sql_results']['insert_dups'] += count($matches[0]); |
|
| 1259 | + } else { |
|
| 1260 | + $incontext['sql_results']['insert_dups']++; |
|
| 1261 | + } |
|
| 1193 | 1262 | |
| 1194 | 1263 | $current_statement = ''; |
| 1195 | 1264 | continue; |
@@ -1198,8 +1267,9 @@ discard block |
||
| 1198 | 1267 | if ($smcFunc['db_query']('', $current_statement, array('security_override' => true, 'db_error_skip' => true), $db_connection) === false) |
| 1199 | 1268 | { |
| 1200 | 1269 | // Use the appropriate function based on the DB type |
| 1201 | - if ($db_type == 'mysql' || $db_type == 'mysqli') |
|
| 1202 | - $db_errorno = $db_type . '_errno'; |
|
| 1270 | + if ($db_type == 'mysql' || $db_type == 'mysqli') { |
|
| 1271 | + $db_errorno = $db_type . '_errno'; |
|
| 1272 | + } |
|
| 1203 | 1273 | |
| 1204 | 1274 | // Error 1050: Table already exists! |
| 1205 | 1275 | // @todo Needs to be made better! |
@@ -1214,18 +1284,18 @@ discard block |
||
| 1214 | 1284 | // MySQLi requires a connection object. It's optional with MySQL and Postgres |
| 1215 | 1285 | $incontext['failures'][$count] = $smcFunc['db_error']($db_connection); |
| 1216 | 1286 | } |
| 1217 | - } |
|
| 1218 | - else |
|
| 1287 | + } else |
|
| 1219 | 1288 | { |
| 1220 | - if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1) |
|
| 1221 | - $incontext['sql_results']['tables']++; |
|
| 1222 | - elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1) |
|
| 1289 | + if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1) { |
|
| 1290 | + $incontext['sql_results']['tables']++; |
|
| 1291 | + } elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1) |
|
| 1223 | 1292 | { |
| 1224 | 1293 | preg_match_all('~\)[,;]~', $current_statement, $matches); |
| 1225 | - if (!empty($matches[0])) |
|
| 1226 | - $incontext['sql_results']['inserts'] += count($matches[0]); |
|
| 1227 | - else |
|
| 1228 | - $incontext['sql_results']['inserts']++; |
|
| 1294 | + if (!empty($matches[0])) { |
|
| 1295 | + $incontext['sql_results']['inserts'] += count($matches[0]); |
|
| 1296 | + } else { |
|
| 1297 | + $incontext['sql_results']['inserts']++; |
|
| 1298 | + } |
|
| 1229 | 1299 | } |
| 1230 | 1300 | } |
| 1231 | 1301 | |
@@ -1238,15 +1308,17 @@ discard block |
||
| 1238 | 1308 | // Sort out the context for the SQL. |
| 1239 | 1309 | foreach ($incontext['sql_results'] as $key => $number) |
| 1240 | 1310 | { |
| 1241 | - if ($number == 0) |
|
| 1242 | - unset($incontext['sql_results'][$key]); |
|
| 1243 | - else |
|
| 1244 | - $incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number); |
|
| 1311 | + if ($number == 0) { |
|
| 1312 | + unset($incontext['sql_results'][$key]); |
|
| 1313 | + } else { |
|
| 1314 | + $incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number); |
|
| 1315 | + } |
|
| 1245 | 1316 | } |
| 1246 | 1317 | |
| 1247 | 1318 | // Make sure UTF will be used globally. |
| 1248 | - if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8']))) |
|
| 1249 | - $newSettings[] = array('global_character_set', 'UTF-8'); |
|
| 1319 | + if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8']))) { |
|
| 1320 | + $newSettings[] = array('global_character_set', 'UTF-8'); |
|
| 1321 | + } |
|
| 1250 | 1322 | |
| 1251 | 1323 | // Auto-detect local & global cookie settings |
| 1252 | 1324 | $url_parts = parse_url($boardurl); |
@@ -1275,15 +1347,19 @@ discard block |
||
| 1275 | 1347 | |
| 1276 | 1348 | // Look for subfolder, if found, set localCookie |
| 1277 | 1349 | // Checking for len > 1 ensures you don't have just a slash... |
| 1278 | - if (!empty($url_parts['path']) && strlen($url_parts['path']) > 1) |
|
| 1279 | - $localCookies = '1'; |
|
| 1350 | + if (!empty($url_parts['path']) && strlen($url_parts['path']) > 1) { |
|
| 1351 | + $localCookies = '1'; |
|
| 1352 | + } |
|
| 1280 | 1353 | |
| 1281 | - if (isset($globalCookies)) |
|
| 1282 | - $newSettings[] = array('globalCookies', $globalCookies); |
|
| 1283 | - if (isset($globalCookiesDomain)) |
|
| 1284 | - $newSettings[] = array('globalCookiesDomain', $globalCookiesDomain); |
|
| 1285 | - if (isset($localCookies)) |
|
| 1286 | - $newSettings[] = array('localCookies', $localCookies); |
|
| 1354 | + if (isset($globalCookies)) { |
|
| 1355 | + $newSettings[] = array('globalCookies', $globalCookies); |
|
| 1356 | + } |
|
| 1357 | + if (isset($globalCookiesDomain)) { |
|
| 1358 | + $newSettings[] = array('globalCookiesDomain', $globalCookiesDomain); |
|
| 1359 | + } |
|
| 1360 | + if (isset($localCookies)) { |
|
| 1361 | + $newSettings[] = array('localCookies', $localCookies); |
|
| 1362 | + } |
|
| 1287 | 1363 | } |
| 1288 | 1364 | |
| 1289 | 1365 | // Are we allowing stat collection? |
@@ -1301,16 +1377,17 @@ discard block |
||
| 1301 | 1377 | fwrite($fp, $out); |
| 1302 | 1378 | |
| 1303 | 1379 | $return_data = ''; |
| 1304 | - while (!feof($fp)) |
|
| 1305 | - $return_data .= fgets($fp, 128); |
|
| 1380 | + while (!feof($fp)) { |
|
| 1381 | + $return_data .= fgets($fp, 128); |
|
| 1382 | + } |
|
| 1306 | 1383 | |
| 1307 | 1384 | fclose($fp); |
| 1308 | 1385 | |
| 1309 | 1386 | // Get the unique site ID. |
| 1310 | 1387 | preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID); |
| 1311 | 1388 | |
| 1312 | - if (!empty($ID[1])) |
|
| 1313 | - $smcFunc['db_insert']('replace', |
|
| 1389 | + if (!empty($ID[1])) { |
|
| 1390 | + $smcFunc['db_insert']('replace', |
|
| 1314 | 1391 | $db_prefix . 'settings', |
| 1315 | 1392 | array('variable' => 'string', 'value' => 'string'), |
| 1316 | 1393 | array( |
@@ -1319,11 +1396,12 @@ discard block |
||
| 1319 | 1396 | ), |
| 1320 | 1397 | array('variable') |
| 1321 | 1398 | ); |
| 1399 | + } |
|
| 1322 | 1400 | } |
| 1323 | 1401 | } |
| 1324 | 1402 | // Don't remove stat collection unless we unchecked the box for real, not from the loop. |
| 1325 | - elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) |
|
| 1326 | - $smcFunc['db_query']('', ' |
|
| 1403 | + elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) { |
|
| 1404 | + $smcFunc['db_query']('', ' |
|
| 1327 | 1405 | DELETE FROM {db_prefix}settings |
| 1328 | 1406 | WHERE variable = {string:enable_sm_stats}', |
| 1329 | 1407 | array( |
@@ -1331,20 +1409,23 @@ discard block |
||
| 1331 | 1409 | 'db_error_skip' => true, |
| 1332 | 1410 | ) |
| 1333 | 1411 | ); |
| 1412 | + } |
|
| 1334 | 1413 | |
| 1335 | 1414 | // Are we enabling SSL? |
| 1336 | - if (!empty($_POST['force_ssl'])) |
|
| 1337 | - $newSettings[] = array('force_ssl', 2); |
|
| 1415 | + if (!empty($_POST['force_ssl'])) { |
|
| 1416 | + $newSettings[] = array('force_ssl', 2); |
|
| 1417 | + } |
|
| 1338 | 1418 | |
| 1339 | 1419 | // Setting a timezone is required. |
| 1340 | 1420 | if (!isset($modSettings['default_timezone']) && function_exists('date_default_timezone_set')) |
| 1341 | 1421 | { |
| 1342 | 1422 | // Get PHP's default timezone, if set |
| 1343 | 1423 | $ini_tz = ini_get('date.timezone'); |
| 1344 | - if (!empty($ini_tz)) |
|
| 1345 | - $timezone_id = $ini_tz; |
|
| 1346 | - else |
|
| 1347 | - $timezone_id = ''; |
|
| 1424 | + if (!empty($ini_tz)) { |
|
| 1425 | + $timezone_id = $ini_tz; |
|
| 1426 | + } else { |
|
| 1427 | + $timezone_id = ''; |
|
| 1428 | + } |
|
| 1348 | 1429 | |
| 1349 | 1430 | // If date.timezone is unset, invalid, or just plain weird, make a best guess |
| 1350 | 1431 | if (!in_array($timezone_id, timezone_identifiers_list())) |
@@ -1353,8 +1434,9 @@ discard block |
||
| 1353 | 1434 | $timezone_id = timezone_name_from_abbr('', $server_offset, 0); |
| 1354 | 1435 | } |
| 1355 | 1436 | |
| 1356 | - if (date_default_timezone_set($timezone_id)) |
|
| 1357 | - $newSettings[] = array('default_timezone', $timezone_id); |
|
| 1437 | + if (date_default_timezone_set($timezone_id)) { |
|
| 1438 | + $newSettings[] = array('default_timezone', $timezone_id); |
|
| 1439 | + } |
|
| 1358 | 1440 | } |
| 1359 | 1441 | |
| 1360 | 1442 | if (!empty($newSettings)) |
@@ -1385,16 +1467,18 @@ discard block |
||
| 1385 | 1467 | } |
| 1386 | 1468 | |
| 1387 | 1469 | // MySQL specific stuff |
| 1388 | - if (substr($db_type, 0, 5) != 'mysql') |
|
| 1389 | - return false; |
|
| 1470 | + if (substr($db_type, 0, 5) != 'mysql') { |
|
| 1471 | + return false; |
|
| 1472 | + } |
|
| 1390 | 1473 | |
| 1391 | 1474 | // Find database user privileges. |
| 1392 | 1475 | $privs = array(); |
| 1393 | 1476 | $get_privs = $smcFunc['db_query']('', 'SHOW PRIVILEGES', array()); |
| 1394 | 1477 | while ($row = $smcFunc['db_fetch_assoc']($get_privs)) |
| 1395 | 1478 | { |
| 1396 | - if ($row['Privilege'] == 'Alter') |
|
| 1397 | - $privs[] = $row['Privilege']; |
|
| 1479 | + if ($row['Privilege'] == 'Alter') { |
|
| 1480 | + $privs[] = $row['Privilege']; |
|
| 1481 | + } |
|
| 1398 | 1482 | } |
| 1399 | 1483 | $smcFunc['db_free_result']($get_privs); |
| 1400 | 1484 | |
@@ -1424,8 +1508,9 @@ discard block |
||
| 1424 | 1508 | $incontext['continue'] = 1; |
| 1425 | 1509 | |
| 1426 | 1510 | // Skipping? |
| 1427 | - if (!empty($_POST['skip'])) |
|
| 1428 | - return true; |
|
| 1511 | + if (!empty($_POST['skip'])) { |
|
| 1512 | + return true; |
|
| 1513 | + } |
|
| 1429 | 1514 | |
| 1430 | 1515 | // Need this to check whether we need the database password. |
| 1431 | 1516 | require(dirname(__FILE__) . '/Settings.php'); |
@@ -1442,18 +1527,22 @@ discard block |
||
| 1442 | 1527 | // We need this to properly hash the password for Admin |
| 1443 | 1528 | $smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' : function($string) { |
| 1444 | 1529 | global $sourcedir; |
| 1445 | - if (function_exists('mb_strtolower')) |
|
| 1446 | - return mb_strtolower($string, 'UTF-8'); |
|
| 1530 | + if (function_exists('mb_strtolower')) { |
|
| 1531 | + return mb_strtolower($string, 'UTF-8'); |
|
| 1532 | + } |
|
| 1447 | 1533 | require_once($sourcedir . '/Subs-Charset.php'); |
| 1448 | 1534 | return utf8_strtolower($string); |
| 1449 | 1535 | }; |
| 1450 | 1536 | |
| 1451 | - if (!isset($_POST['username'])) |
|
| 1452 | - $_POST['username'] = ''; |
|
| 1453 | - if (!isset($_POST['email'])) |
|
| 1454 | - $_POST['email'] = ''; |
|
| 1455 | - if (!isset($_POST['server_email'])) |
|
| 1456 | - $_POST['server_email'] = ''; |
|
| 1537 | + if (!isset($_POST['username'])) { |
|
| 1538 | + $_POST['username'] = ''; |
|
| 1539 | + } |
|
| 1540 | + if (!isset($_POST['email'])) { |
|
| 1541 | + $_POST['email'] = ''; |
|
| 1542 | + } |
|
| 1543 | + if (!isset($_POST['server_email'])) { |
|
| 1544 | + $_POST['server_email'] = ''; |
|
| 1545 | + } |
|
| 1457 | 1546 | |
| 1458 | 1547 | $incontext['username'] = htmlspecialchars(stripslashes($_POST['username'])); |
| 1459 | 1548 | $incontext['email'] = htmlspecialchars(stripslashes($_POST['email'])); |
@@ -1472,8 +1561,9 @@ discard block |
||
| 1472 | 1561 | 'admin_group' => 1, |
| 1473 | 1562 | ) |
| 1474 | 1563 | ); |
| 1475 | - if ($smcFunc['db_num_rows']($request) != 0) |
|
| 1476 | - $incontext['skip'] = 1; |
|
| 1564 | + if ($smcFunc['db_num_rows']($request) != 0) { |
|
| 1565 | + $incontext['skip'] = 1; |
|
| 1566 | + } |
|
| 1477 | 1567 | $smcFunc['db_free_result']($request); |
| 1478 | 1568 | |
| 1479 | 1569 | // Trying to create an account? |
@@ -1504,8 +1594,9 @@ discard block |
||
| 1504 | 1594 | } |
| 1505 | 1595 | |
| 1506 | 1596 | // Update the webmaster's email? |
| 1507 | - if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]')) |
|
| 1508 | - updateSettingsFile(array('webmaster_email' => $_POST['server_email'])); |
|
| 1597 | + if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]')) { |
|
| 1598 | + updateSettingsFile(array('webmaster_email' => $_POST['server_email'])); |
|
| 1599 | + } |
|
| 1509 | 1600 | |
| 1510 | 1601 | // Work out whether we're going to have dodgy characters and remove them. |
| 1511 | 1602 | $invalid_characters = preg_match('~[<>&"\'=\\\]~', $_POST['username']) != 0; |
@@ -1528,32 +1619,27 @@ discard block |
||
| 1528 | 1619 | $smcFunc['db_free_result']($result); |
| 1529 | 1620 | |
| 1530 | 1621 | $incontext['account_existed'] = $txt['error_user_settings_taken']; |
| 1531 | - } |
|
| 1532 | - elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25) |
|
| 1622 | + } elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25) |
|
| 1533 | 1623 | { |
| 1534 | 1624 | // Try the previous step again. |
| 1535 | 1625 | $incontext['error'] = $_POST['username'] == '' ? $txt['error_username_left_empty'] : $txt['error_username_too_long']; |
| 1536 | 1626 | return false; |
| 1537 | - } |
|
| 1538 | - elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false) |
|
| 1627 | + } elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false) |
|
| 1539 | 1628 | { |
| 1540 | 1629 | // Try the previous step again. |
| 1541 | 1630 | $incontext['error'] = $txt['error_invalid_characters_username']; |
| 1542 | 1631 | return false; |
| 1543 | - } |
|
| 1544 | - elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255) |
|
| 1632 | + } elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255) |
|
| 1545 | 1633 | { |
| 1546 | 1634 | // One step back, this time fill out a proper admin email address. |
| 1547 | 1635 | $incontext['error'] = sprintf($txt['error_valid_admin_email_needed'], $_POST['username']); |
| 1548 | 1636 | return false; |
| 1549 | - } |
|
| 1550 | - elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255) |
|
| 1637 | + } elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255) |
|
| 1551 | 1638 | { |
| 1552 | 1639 | // One step back, this time fill out a proper admin email address. |
| 1553 | 1640 | $incontext['error'] = $txt['error_valid_server_email_needed']; |
| 1554 | 1641 | return false; |
| 1555 | - } |
|
| 1556 | - elseif ($_POST['username'] != '') |
|
| 1642 | + } elseif ($_POST['username'] != '') |
|
| 1557 | 1643 | { |
| 1558 | 1644 | $incontext['member_salt'] = substr(md5(mt_rand()), 0, 4); |
| 1559 | 1645 | |
@@ -1621,17 +1707,19 @@ discard block |
||
| 1621 | 1707 | reloadSettings(); |
| 1622 | 1708 | |
| 1623 | 1709 | // Bring a warning over. |
| 1624 | - if (!empty($incontext['account_existed'])) |
|
| 1625 | - $incontext['warning'] = $incontext['account_existed']; |
|
| 1710 | + if (!empty($incontext['account_existed'])) { |
|
| 1711 | + $incontext['warning'] = $incontext['account_existed']; |
|
| 1712 | + } |
|
| 1626 | 1713 | |
| 1627 | - if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support'])) |
|
| 1628 | - $smcFunc['db_query']('', ' |
|
| 1714 | + if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support'])) { |
|
| 1715 | + $smcFunc['db_query']('', ' |
|
| 1629 | 1716 | SET NAMES {string:db_character_set}', |
| 1630 | 1717 | array( |
| 1631 | 1718 | 'db_character_set' => $db_character_set, |
| 1632 | 1719 | 'db_error_skip' => true, |
| 1633 | 1720 | ) |
| 1634 | 1721 | ); |
| 1722 | + } |
|
| 1635 | 1723 | |
| 1636 | 1724 | // As track stats is by default enabled let's add some activity. |
| 1637 | 1725 | $smcFunc['db_insert']('ignore', |
@@ -1652,14 +1740,16 @@ discard block |
||
| 1652 | 1740 | // Only proceed if we can load the data. |
| 1653 | 1741 | if ($request) |
| 1654 | 1742 | { |
| 1655 | - while ($row = $smcFunc['db_fetch_row']($request)) |
|
| 1656 | - $modSettings[$row[0]] = $row[1]; |
|
| 1743 | + while ($row = $smcFunc['db_fetch_row']($request)) { |
|
| 1744 | + $modSettings[$row[0]] = $row[1]; |
|
| 1745 | + } |
|
| 1657 | 1746 | $smcFunc['db_free_result']($request); |
| 1658 | 1747 | } |
| 1659 | 1748 | |
| 1660 | 1749 | // Automatically log them in ;) |
| 1661 | - if (isset($incontext['member_id']) && isset($incontext['member_salt'])) |
|
| 1662 | - setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt'])); |
|
| 1750 | + if (isset($incontext['member_id']) && isset($incontext['member_salt'])) { |
|
| 1751 | + setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt'])); |
|
| 1752 | + } |
|
| 1663 | 1753 | |
| 1664 | 1754 | $result = $smcFunc['db_query']('', ' |
| 1665 | 1755 | SELECT value |
@@ -1670,13 +1760,14 @@ discard block |
||
| 1670 | 1760 | 'db_error_skip' => true, |
| 1671 | 1761 | ) |
| 1672 | 1762 | ); |
| 1673 | - if ($smcFunc['db_num_rows']($result) != 0) |
|
| 1674 | - list ($db_sessions) = $smcFunc['db_fetch_row']($result); |
|
| 1763 | + if ($smcFunc['db_num_rows']($result) != 0) { |
|
| 1764 | + list ($db_sessions) = $smcFunc['db_fetch_row']($result); |
|
| 1765 | + } |
|
| 1675 | 1766 | $smcFunc['db_free_result']($result); |
| 1676 | 1767 | |
| 1677 | - if (empty($db_sessions)) |
|
| 1678 | - $_SESSION['admin_time'] = time(); |
|
| 1679 | - else |
|
| 1768 | + if (empty($db_sessions)) { |
|
| 1769 | + $_SESSION['admin_time'] = time(); |
|
| 1770 | + } else |
|
| 1680 | 1771 | { |
| 1681 | 1772 | $_SERVER['HTTP_USER_AGENT'] = substr($_SERVER['HTTP_USER_AGENT'], 0, 211); |
| 1682 | 1773 | |
@@ -1700,8 +1791,9 @@ discard block |
||
| 1700 | 1791 | $smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' : |
| 1701 | 1792 | function($string){ |
| 1702 | 1793 | global $sourcedir; |
| 1703 | - if (function_exists('mb_strtolower')) |
|
| 1704 | - return mb_strtolower($string, 'UTF-8'); |
|
| 1794 | + if (function_exists('mb_strtolower')) { |
|
| 1795 | + return mb_strtolower($string, 'UTF-8'); |
|
| 1796 | + } |
|
| 1705 | 1797 | require_once($sourcedir . '/Subs-Charset.php'); |
| 1706 | 1798 | return utf8_strtolower($string); |
| 1707 | 1799 | }; |
@@ -1717,8 +1809,9 @@ discard block |
||
| 1717 | 1809 | ) |
| 1718 | 1810 | ); |
| 1719 | 1811 | $context['utf8'] = $db_character_set === 'utf8' || $txt['lang_character_set'] === 'UTF-8'; |
| 1720 | - if ($smcFunc['db_num_rows']($request) > 0) |
|
| 1721 | - updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject'])); |
|
| 1812 | + if ($smcFunc['db_num_rows']($request) > 0) { |
|
| 1813 | + updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject'])); |
|
| 1814 | + } |
|
| 1722 | 1815 | $smcFunc['db_free_result']($request); |
| 1723 | 1816 | |
| 1724 | 1817 | // Now is the perfect time to fetch the SM files. |
@@ -1737,8 +1830,9 @@ discard block |
||
| 1737 | 1830 | |
| 1738 | 1831 | // Check if we need some stupid MySQL fix. |
| 1739 | 1832 | $server_version = $smcFunc['db_server_info'](); |
| 1740 | - if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) |
|
| 1741 | - updateSettings(array('db_mysql_group_by_fix' => '1')); |
|
| 1833 | + if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) { |
|
| 1834 | + updateSettings(array('db_mysql_group_by_fix' => '1')); |
|
| 1835 | + } |
|
| 1742 | 1836 | |
| 1743 | 1837 | // Some final context for the template. |
| 1744 | 1838 | $incontext['dir_still_writable'] = is_writable(dirname(__FILE__)) && substr(__FILE__, 1, 2) != ':\\'; |
@@ -1758,8 +1852,9 @@ discard block |
||
| 1758 | 1852 | $settingsArray = file(dirname(__FILE__) . '/Settings.php'); |
| 1759 | 1853 | |
| 1760 | 1854 | // @todo Do we just want to read the file in clean, and split it this way always? |
| 1761 | - if (count($settingsArray) == 1) |
|
| 1762 | - $settingsArray = preg_split('~[\r\n]~', $settingsArray[0]); |
|
| 1855 | + if (count($settingsArray) == 1) { |
|
| 1856 | + $settingsArray = preg_split('~[\r\n]~', $settingsArray[0]); |
|
| 1857 | + } |
|
| 1763 | 1858 | |
| 1764 | 1859 | for ($i = 0, $n = count($settingsArray); $i < $n; $i++) |
| 1765 | 1860 | { |
@@ -1774,19 +1869,22 @@ discard block |
||
| 1774 | 1869 | continue; |
| 1775 | 1870 | } |
| 1776 | 1871 | |
| 1777 | - if (trim($settingsArray[$i]) == '?' . '>') |
|
| 1778 | - $settingsArray[$i] = ''; |
|
| 1872 | + if (trim($settingsArray[$i]) == '?' . '>') { |
|
| 1873 | + $settingsArray[$i] = ''; |
|
| 1874 | + } |
|
| 1779 | 1875 | |
| 1780 | 1876 | // Don't trim or bother with it if it's not a variable. |
| 1781 | - if (substr($settingsArray[$i], 0, 1) != '$') |
|
| 1782 | - continue; |
|
| 1877 | + if (substr($settingsArray[$i], 0, 1) != '$') { |
|
| 1878 | + continue; |
|
| 1879 | + } |
|
| 1783 | 1880 | |
| 1784 | 1881 | $settingsArray[$i] = rtrim($settingsArray[$i]) . "\n"; |
| 1785 | 1882 | |
| 1786 | - foreach ($vars as $var => $val) |
|
| 1787 | - if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0) |
|
| 1883 | + foreach ($vars as $var => $val) { |
|
| 1884 | + if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0) |
|
| 1788 | 1885 | { |
| 1789 | 1886 | $comment = strstr($settingsArray[$i], '#'); |
| 1887 | + } |
|
| 1790 | 1888 | $settingsArray[$i] = '$' . $var . ' = \'' . $val . '\';' . ($comment != '' ? "\t\t" . $comment : "\n"); |
| 1791 | 1889 | unset($vars[$var]); |
| 1792 | 1890 | } |
@@ -1796,36 +1894,41 @@ discard block |
||
| 1796 | 1894 | if (!empty($vars)) |
| 1797 | 1895 | { |
| 1798 | 1896 | $settingsArray[$i++] = ''; |
| 1799 | - foreach ($vars as $var => $val) |
|
| 1800 | - $settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n"; |
|
| 1897 | + foreach ($vars as $var => $val) { |
|
| 1898 | + $settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n"; |
|
| 1899 | + } |
|
| 1801 | 1900 | } |
| 1802 | 1901 | |
| 1803 | 1902 | // Blank out the file - done to fix a oddity with some servers. |
| 1804 | 1903 | $fp = @fopen(dirname(__FILE__) . '/Settings.php', 'w'); |
| 1805 | - if (!$fp) |
|
| 1806 | - return false; |
|
| 1904 | + if (!$fp) { |
|
| 1905 | + return false; |
|
| 1906 | + } |
|
| 1807 | 1907 | fclose($fp); |
| 1808 | 1908 | |
| 1809 | 1909 | $fp = fopen(dirname(__FILE__) . '/Settings.php', 'r+'); |
| 1810 | 1910 | |
| 1811 | 1911 | // Gotta have one of these ;) |
| 1812 | - if (trim($settingsArray[0]) != '<?php') |
|
| 1813 | - fwrite($fp, "<?php\n"); |
|
| 1912 | + if (trim($settingsArray[0]) != '<?php') { |
|
| 1913 | + fwrite($fp, "<?php\n"); |
|
| 1914 | + } |
|
| 1814 | 1915 | |
| 1815 | 1916 | $lines = count($settingsArray); |
| 1816 | 1917 | for ($i = 0; $i < $lines - 1; $i++) |
| 1817 | 1918 | { |
| 1818 | 1919 | // Don't just write a bunch of blank lines. |
| 1819 | - if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '') |
|
| 1820 | - fwrite($fp, strtr($settingsArray[$i], "\r", '')); |
|
| 1920 | + if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '') { |
|
| 1921 | + fwrite($fp, strtr($settingsArray[$i], "\r", '')); |
|
| 1922 | + } |
|
| 1821 | 1923 | } |
| 1822 | 1924 | fwrite($fp, $settingsArray[$i] . '?' . '>'); |
| 1823 | 1925 | fclose($fp); |
| 1824 | 1926 | |
| 1825 | 1927 | // Even though on normal installations the filemtime should prevent this being used by the installer incorrectly |
| 1826 | 1928 | // it seems that there are times it might not. So let's MAKE it dump the cache. |
| 1827 | - if (function_exists('opcache_invalidate')) |
|
| 1828 | - opcache_invalidate(dirname(__FILE__) . '/Settings.php', true); |
|
| 1929 | + if (function_exists('opcache_invalidate')) { |
|
| 1930 | + opcache_invalidate(dirname(__FILE__) . '/Settings.php', true); |
|
| 1931 | + } |
|
| 1829 | 1932 | |
| 1830 | 1933 | return true; |
| 1831 | 1934 | } |
@@ -1850,9 +1953,9 @@ discard block |
||
| 1850 | 1953 | SecFilterScanPOST Off |
| 1851 | 1954 | </IfModule>'; |
| 1852 | 1955 | |
| 1853 | - if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules())) |
|
| 1854 | - return true; |
|
| 1855 | - elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess')) |
|
| 1956 | + if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules())) { |
|
| 1957 | + return true; |
|
| 1958 | + } elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess')) |
|
| 1856 | 1959 | { |
| 1857 | 1960 | $current_htaccess = implode('', file(dirname(__FILE__) . '/.htaccess')); |
| 1858 | 1961 | |
@@ -1864,29 +1967,28 @@ discard block |
||
| 1864 | 1967 | fwrite($ht_handle, $htaccess_addition); |
| 1865 | 1968 | fclose($ht_handle); |
| 1866 | 1969 | return true; |
| 1970 | + } else { |
|
| 1971 | + return false; |
|
| 1867 | 1972 | } |
| 1868 | - else |
|
| 1869 | - return false; |
|
| 1973 | + } else { |
|
| 1974 | + return true; |
|
| 1870 | 1975 | } |
| 1871 | - else |
|
| 1872 | - return true; |
|
| 1873 | - } |
|
| 1874 | - elseif (file_exists(dirname(__FILE__) . '/.htaccess')) |
|
| 1875 | - return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false; |
|
| 1876 | - elseif (is_writable(dirname(__FILE__))) |
|
| 1976 | + } elseif (file_exists(dirname(__FILE__) . '/.htaccess')) { |
|
| 1977 | + return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false; |
|
| 1978 | + } elseif (is_writable(dirname(__FILE__))) |
|
| 1877 | 1979 | { |
| 1878 | 1980 | if ($ht_handle = fopen(dirname(__FILE__) . '/.htaccess', 'w')) |
| 1879 | 1981 | { |
| 1880 | 1982 | fwrite($ht_handle, $htaccess_addition); |
| 1881 | 1983 | fclose($ht_handle); |
| 1882 | 1984 | return true; |
| 1985 | + } else { |
|
| 1986 | + return false; |
|
| 1883 | 1987 | } |
| 1884 | - else |
|
| 1988 | + } else { |
|
| 1885 | 1989 | return false; |
| 1886 | 1990 | } |
| 1887 | - else |
|
| 1888 | - return false; |
|
| 1889 | -} |
|
| 1991 | + } |
|
| 1890 | 1992 | |
| 1891 | 1993 | function template_install_above() |
| 1892 | 1994 | { |
@@ -1924,9 +2026,10 @@ discard block |
||
| 1924 | 2026 | <label for="installer_language">', $txt['installer_language'], ':</label> |
| 1925 | 2027 | <select id="installer_language" name="lang_file" onchange="location.href = \'', $installurl, '?lang_file=\' + this.options[this.selectedIndex].value;">'; |
| 1926 | 2028 | |
| 1927 | - foreach ($incontext['detected_languages'] as $lang => $name) |
|
| 1928 | - echo ' |
|
| 2029 | + foreach ($incontext['detected_languages'] as $lang => $name) { |
|
| 2030 | + echo ' |
|
| 1929 | 2031 | <option', isset($_SESSION['installer_temp_lang']) && $_SESSION['installer_temp_lang'] == $lang ? ' selected' : '', ' value="', $lang, '">', $name, '</option>'; |
| 2032 | + } |
|
| 1930 | 2033 | |
| 1931 | 2034 | echo ' |
| 1932 | 2035 | </select> |
@@ -1946,9 +2049,10 @@ discard block |
||
| 1946 | 2049 | <h2>', $txt['upgrade_progress'], '</h2> |
| 1947 | 2050 | <ul>'; |
| 1948 | 2051 | |
| 1949 | - foreach ($incontext['steps'] as $num => $step) |
|
| 1950 | - echo ' |
|
| 2052 | + foreach ($incontext['steps'] as $num => $step) { |
|
| 2053 | + echo ' |
|
| 1951 | 2054 | <li class="', $num < $incontext['current_step'] ? 'stepdone' : ($num == $incontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>'; |
| 2055 | + } |
|
| 1952 | 2056 | |
| 1953 | 2057 | echo ' |
| 1954 | 2058 | </ul> |
@@ -1973,20 +2077,23 @@ discard block |
||
| 1973 | 2077 | echo ' |
| 1974 | 2078 | <div class="floatright">'; |
| 1975 | 2079 | |
| 1976 | - if (!empty($incontext['continue'])) |
|
| 1977 | - echo ' |
|
| 2080 | + if (!empty($incontext['continue'])) { |
|
| 2081 | + echo ' |
|
| 1978 | 2082 | <input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '" onclick="return submitThisOnce(this);" class="button" />'; |
| 1979 | - if (!empty($incontext['skip'])) |
|
| 1980 | - echo ' |
|
| 2083 | + } |
|
| 2084 | + if (!empty($incontext['skip'])) { |
|
| 2085 | + echo ' |
|
| 1981 | 2086 | <input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="return submitThisOnce(this);" class="button" />'; |
| 2087 | + } |
|
| 1982 | 2088 | echo ' |
| 1983 | 2089 | </div>'; |
| 1984 | 2090 | } |
| 1985 | 2091 | |
| 1986 | 2092 | // Show the closing form tag and other data only if not in the last step |
| 1987 | - if (count($incontext['steps']) - 1 !== (int) $incontext['current_step']) |
|
| 1988 | - echo ' |
|
| 2093 | + if (count($incontext['steps']) - 1 !== (int) $incontext['current_step']) { |
|
| 2094 | + echo ' |
|
| 1989 | 2095 | </form>'; |
| 2096 | + } |
|
| 1990 | 2097 | |
| 1991 | 2098 | echo ' |
| 1992 | 2099 | </div> |
@@ -2021,13 +2128,15 @@ discard block |
||
| 2021 | 2128 | </div>'; |
| 2022 | 2129 | |
| 2023 | 2130 | // Show the warnings, or not. |
| 2024 | - if (template_warning_divs()) |
|
| 2025 | - echo ' |
|
| 2131 | + if (template_warning_divs()) { |
|
| 2132 | + echo ' |
|
| 2026 | 2133 | <h3>', $txt['install_all_lovely'], '</h3>'; |
| 2134 | + } |
|
| 2027 | 2135 | |
| 2028 | 2136 | // Say we want the continue button! |
| 2029 | - if (empty($incontext['error'])) |
|
| 2030 | - $incontext['continue'] = 1; |
|
| 2137 | + if (empty($incontext['error'])) { |
|
| 2138 | + $incontext['continue'] = 1; |
|
| 2139 | + } |
|
| 2031 | 2140 | |
| 2032 | 2141 | // For the latest version stuff. |
| 2033 | 2142 | echo ' |
@@ -2061,8 +2170,8 @@ discard block |
||
| 2061 | 2170 | global $txt, $incontext; |
| 2062 | 2171 | |
| 2063 | 2172 | // Errors are very serious.. |
| 2064 | - if (!empty($incontext['error'])) |
|
| 2065 | - echo ' |
|
| 2173 | + if (!empty($incontext['error'])) { |
|
| 2174 | + echo ' |
|
| 2066 | 2175 | <div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;"> |
| 2067 | 2176 | <div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div> |
| 2068 | 2177 | <strong style="text-decoration: underline;">', $txt['upgrade_critical_error'], '</strong><br> |
@@ -2070,9 +2179,10 @@ discard block |
||
| 2070 | 2179 | ', $incontext['error'], ' |
| 2071 | 2180 | </div> |
| 2072 | 2181 | </div>'; |
| 2182 | + } |
|
| 2073 | 2183 | // A warning message? |
| 2074 | - elseif (!empty($incontext['warning'])) |
|
| 2075 | - echo ' |
|
| 2184 | + elseif (!empty($incontext['warning'])) { |
|
| 2185 | + echo ' |
|
| 2076 | 2186 | <div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;"> |
| 2077 | 2187 | <div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div> |
| 2078 | 2188 | <strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br> |
@@ -2080,6 +2190,7 @@ discard block |
||
| 2080 | 2190 | ', $incontext['warning'], ' |
| 2081 | 2191 | </div> |
| 2082 | 2192 | </div>'; |
| 2193 | + } |
|
| 2083 | 2194 | |
| 2084 | 2195 | return empty($incontext['error']) && empty($incontext['warning']); |
| 2085 | 2196 | } |
@@ -2095,27 +2206,30 @@ discard block |
||
| 2095 | 2206 | <li>', $incontext['failed_files']), '</li> |
| 2096 | 2207 | </ul>'; |
| 2097 | 2208 | |
| 2098 | - if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux') |
|
| 2099 | - echo ' |
|
| 2209 | + if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux') { |
|
| 2210 | + echo ' |
|
| 2100 | 2211 | <hr> |
| 2101 | 2212 | <p>', $txt['chmod_linux_info'], '</p> |
| 2102 | 2213 | <tt># chmod a+w ', implode(' ' . $incontext['detected_path'] . '/', $incontext['failed_files']), '</tt>'; |
| 2214 | + } |
|
| 2103 | 2215 | |
| 2104 | 2216 | // This is serious! |
| 2105 | - if (!template_warning_divs()) |
|
| 2106 | - return; |
|
| 2217 | + if (!template_warning_divs()) { |
|
| 2218 | + return; |
|
| 2219 | + } |
|
| 2107 | 2220 | |
| 2108 | 2221 | echo ' |
| 2109 | 2222 | <hr> |
| 2110 | 2223 | <p>', $txt['ftp_setup_info'], '</p>'; |
| 2111 | 2224 | |
| 2112 | - if (!empty($incontext['ftp_errors'])) |
|
| 2113 | - echo ' |
|
| 2225 | + if (!empty($incontext['ftp_errors'])) { |
|
| 2226 | + echo ' |
|
| 2114 | 2227 | <div class="error_message"> |
| 2115 | 2228 | ', $txt['error_ftp_no_connect'], '<br><br> |
| 2116 | 2229 | <code>', implode('<br>', $incontext['ftp_errors']), '</code> |
| 2117 | 2230 | </div> |
| 2118 | 2231 | <br>'; |
| 2232 | + } |
|
| 2119 | 2233 | |
| 2120 | 2234 | echo ' |
| 2121 | 2235 | <form action="', $incontext['form_url'], '" method="post"> |
@@ -2175,17 +2289,17 @@ discard block |
||
| 2175 | 2289 | <td> |
| 2176 | 2290 | <select name="db_type" id="db_type_input" onchange="toggleDBInput();">'; |
| 2177 | 2291 | |
| 2178 | - foreach ($incontext['supported_databases'] as $key => $db) |
|
| 2179 | - echo ' |
|
| 2292 | + foreach ($incontext['supported_databases'] as $key => $db) { |
|
| 2293 | + echo ' |
|
| 2180 | 2294 | <option value="', $key, '"', isset($_POST['db_type']) && $_POST['db_type'] == $key ? ' selected' : '', '>', $db['name'], '</option>'; |
| 2295 | + } |
|
| 2181 | 2296 | |
| 2182 | 2297 | echo ' |
| 2183 | 2298 | </select> |
| 2184 | 2299 | <div class="smalltext block">', $txt['db_settings_type_info'], '</div> |
| 2185 | 2300 | </td> |
| 2186 | 2301 | </tr>'; |
| 2187 | - } |
|
| 2188 | - else |
|
| 2302 | + } else |
|
| 2189 | 2303 | { |
| 2190 | 2304 | echo ' |
| 2191 | 2305 | <tr style="display: none;"> |
@@ -2378,9 +2492,10 @@ discard block |
||
| 2378 | 2492 | <div style="color: red;">', $txt['error_db_queries'], '</div> |
| 2379 | 2493 | <ul>'; |
| 2380 | 2494 | |
| 2381 | - foreach ($incontext['failures'] as $line => $fail) |
|
| 2382 | - echo ' |
|
| 2495 | + foreach ($incontext['failures'] as $line => $fail) { |
|
| 2496 | + echo ' |
|
| 2383 | 2497 | <li><strong>', $txt['error_db_queries_line'], $line + 1, ':</strong> ', nl2br(htmlspecialchars($fail)), '</li>'; |
| 2498 | + } |
|
| 2384 | 2499 | |
| 2385 | 2500 | echo ' |
| 2386 | 2501 | </ul>'; |
@@ -2441,15 +2556,16 @@ discard block |
||
| 2441 | 2556 | </tr> |
| 2442 | 2557 | </table>'; |
| 2443 | 2558 | |
| 2444 | - if ($incontext['require_db_confirm']) |
|
| 2445 | - echo ' |
|
| 2559 | + if ($incontext['require_db_confirm']) { |
|
| 2560 | + echo ' |
|
| 2446 | 2561 | <h2>', $txt['user_settings_database'], '</h2> |
| 2447 | 2562 | <p>', $txt['user_settings_database_info'], '</p> |
| 2448 | 2563 | |
| 2449 | 2564 | <div style="margin-bottom: 2ex; padding-', $txt['lang_rtl'] == false ? 'left' : 'right', ': 50px;"> |
| 2450 | 2565 | <input type="password" name="password3" size="30" /> |
| 2451 | 2566 | </div>'; |
| 2452 | -} |
|
| 2567 | + } |
|
| 2568 | + } |
|
| 2453 | 2569 | |
| 2454 | 2570 | // Tell them it's done, and to delete. |
| 2455 | 2571 | function template_delete_install() |
@@ -2462,14 +2578,15 @@ discard block |
||
| 2462 | 2578 | template_warning_divs(); |
| 2463 | 2579 | |
| 2464 | 2580 | // Install directory still writable? |
| 2465 | - if ($incontext['dir_still_writable']) |
|
| 2466 | - echo ' |
|
| 2581 | + if ($incontext['dir_still_writable']) { |
|
| 2582 | + echo ' |
|
| 2467 | 2583 | <em>', $txt['still_writable'], '</em><br> |
| 2468 | 2584 | <br>'; |
| 2585 | + } |
|
| 2469 | 2586 | |
| 2470 | 2587 | // Don't show the box if it's like 99% sure it won't work :P. |
| 2471 | - if ($incontext['probably_delete_install']) |
|
| 2472 | - echo ' |
|
| 2588 | + if ($incontext['probably_delete_install']) { |
|
| 2589 | + echo ' |
|
| 2473 | 2590 | <div style="margin: 1ex; font-weight: bold;"> |
| 2474 | 2591 | <label for="delete_self"><input type="checkbox" id="delete_self" onclick="doTheDelete();" /> ', $txt['delete_installer'], !isset($_SESSION['installer_temp_ftp']) ? ' ' . $txt['delete_installer_maybe'] : '', '</label> |
| 2475 | 2592 | </div> |
@@ -2485,6 +2602,7 @@ discard block |
||
| 2485 | 2602 | } |
| 2486 | 2603 | </script> |
| 2487 | 2604 | <br>'; |
| 2605 | + } |
|
| 2488 | 2606 | |
| 2489 | 2607 | echo ' |
| 2490 | 2608 | ', sprintf($txt['go_to_your_forum'], $boardurl . '/index.php'), '<br> |
@@ -14,8 +14,9 @@ discard block |
||
| 14 | 14 | * @version 2.1 Beta 4 |
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | -if (!defined('SMF')) |
|
| 17 | +if (!defined('SMF')) { |
|
| 18 | 18 | die('No direct access...'); |
| 19 | +} |
|
| 19 | 20 | |
| 20 | 21 | /** |
| 21 | 22 | * Ask them for their login information. (shows a page for the user to type |
@@ -29,8 +30,9 @@ discard block |
||
| 29 | 30 | global $txt, $context, $scripturl, $user_info; |
| 30 | 31 | |
| 31 | 32 | // You are already logged in, go take a tour of the boards |
| 32 | - if (!empty($user_info['id'])) |
|
| 33 | - redirectexit(); |
|
| 33 | + if (!empty($user_info['id'])) { |
|
| 34 | + redirectexit(); |
|
| 35 | + } |
|
| 34 | 36 | |
| 35 | 37 | // We need to load the Login template/language file. |
| 36 | 38 | loadLanguage('Login'); |
@@ -57,10 +59,11 @@ discard block |
||
| 57 | 59 | ); |
| 58 | 60 | |
| 59 | 61 | // Set the login URL - will be used when the login process is done (but careful not to send us to an attachment). |
| 60 | - if (isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) |
|
| 61 | - $_SESSION['login_url'] = $_SESSION['old_url']; |
|
| 62 | - elseif (isset($_SESSION['login_url']) && strpos($_SESSION['login_url'], 'dlattach') !== false) |
|
| 63 | - unset($_SESSION['login_url']); |
|
| 62 | + if (isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) { |
|
| 63 | + $_SESSION['login_url'] = $_SESSION['old_url']; |
|
| 64 | + } elseif (isset($_SESSION['login_url']) && strpos($_SESSION['login_url'], 'dlattach') !== false) { |
|
| 65 | + unset($_SESSION['login_url']); |
|
| 66 | + } |
|
| 64 | 67 | |
| 65 | 68 | // Create a one time token. |
| 66 | 69 | createToken('login'); |
@@ -83,8 +86,9 @@ discard block |
||
| 83 | 86 | global $cookiename, $modSettings, $context, $sourcedir, $maintenance; |
| 84 | 87 | |
| 85 | 88 | // Check to ensure we're forcing SSL for authentication |
| 86 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) |
|
| 87 | - fatal_lang_error('login_ssl_required'); |
|
| 89 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) { |
|
| 90 | + fatal_lang_error('login_ssl_required'); |
|
| 91 | + } |
|
| 88 | 92 | |
| 89 | 93 | // Load cookie authentication stuff. |
| 90 | 94 | require_once($sourcedir . '/Subs-Auth.php'); |
@@ -102,19 +106,20 @@ discard block |
||
| 102 | 106 | list (,, $timeout) = $smcFunc['json_decode']($_COOKIE[$cookiename], true); |
| 103 | 107 | |
| 104 | 108 | // That didn't work... Maybe it's using serialize? |
| 105 | - if (is_null($timeout)) |
|
| 106 | - list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]); |
|
| 107 | - } |
|
| 108 | - elseif (isset($_SESSION['login_' . $cookiename])) |
|
| 109 | + if (is_null($timeout)) { |
|
| 110 | + list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]); |
|
| 111 | + } |
|
| 112 | + } elseif (isset($_SESSION['login_' . $cookiename])) |
|
| 109 | 113 | { |
| 110 | 114 | list (,, $timeout) = $smcFunc['json_decode']($_SESSION['login_' . $cookiename]); |
| 111 | 115 | |
| 112 | 116 | // Try for old format |
| 113 | - if (is_null($timeout)) |
|
| 114 | - list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]); |
|
| 117 | + if (is_null($timeout)) { |
|
| 118 | + list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]); |
|
| 119 | + } |
|
| 120 | + } else { |
|
| 121 | + trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR); |
|
| 115 | 122 | } |
| 116 | - else |
|
| 117 | - trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR); |
|
| 118 | 123 | |
| 119 | 124 | $user_settings['password_salt'] = substr(md5(mt_rand()), 0, 4); |
| 120 | 125 | updateMemberData($user_info['id'], array('password_salt' => $user_settings['password_salt'])); |
@@ -127,10 +132,11 @@ discard block |
||
| 127 | 132 | list ($tfamember, $tfasecret, $exp, $state, $preserve) = $tfadata; |
| 128 | 133 | |
| 129 | 134 | // If we're preserving the cookie, reset it with updated salt |
| 130 | - if (isset($tfamember, $tfasecret, $exp, $state, $preserve) && $preserve && time() < $exp) |
|
| 131 | - setTFACookie(3153600, $user_info['password_salt'], hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']), true); |
|
| 132 | - else |
|
| 133 | - setTFACookie(-3600, 0, ''); |
|
| 135 | + if (isset($tfamember, $tfasecret, $exp, $state, $preserve) && $preserve && time() < $exp) { |
|
| 136 | + setTFACookie(3153600, $user_info['password_salt'], hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']), true); |
|
| 137 | + } else { |
|
| 138 | + setTFACookie(-3600, 0, ''); |
|
| 139 | + } |
|
| 134 | 140 | } |
| 135 | 141 | |
| 136 | 142 | setLoginCookie($timeout - time(), $user_info['id'], hash_salt($user_settings['passwd'], $user_settings['password_salt'])); |
@@ -141,20 +147,20 @@ discard block |
||
| 141 | 147 | elseif (isset($_GET['sa']) && $_GET['sa'] == 'check') |
| 142 | 148 | { |
| 143 | 149 | // Strike! You're outta there! |
| 144 | - if ($_GET['member'] != $user_info['id']) |
|
| 145 | - fatal_lang_error('login_cookie_error', false); |
|
| 150 | + if ($_GET['member'] != $user_info['id']) { |
|
| 151 | + fatal_lang_error('login_cookie_error', false); |
|
| 152 | + } |
|
| 146 | 153 | |
| 147 | 154 | $user_info['can_mod'] = allowedTo('access_mod_center') || (!$user_info['is_guest'] && ($user_info['mod_cache']['gq'] != '0=1' || $user_info['mod_cache']['bq'] != '0=1' || ($modSettings['postmod_active'] && !empty($user_info['mod_cache']['ap'])))); |
| 148 | 155 | |
| 149 | 156 | // Some whitelisting for login_url... |
| 150 | - if (empty($_SESSION['login_url'])) |
|
| 151 | - redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa'); |
|
| 152 | - elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false)) |
|
| 157 | + if (empty($_SESSION['login_url'])) { |
|
| 158 | + redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa'); |
|
| 159 | + } elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false)) |
|
| 153 | 160 | { |
| 154 | 161 | unset ($_SESSION['login_url']); |
| 155 | 162 | redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa'); |
| 156 | - } |
|
| 157 | - else |
|
| 163 | + } else |
|
| 158 | 164 | { |
| 159 | 165 | // Best not to clutter the session data too much... |
| 160 | 166 | $temp = $_SESSION['login_url']; |
@@ -165,8 +171,9 @@ discard block |
||
| 165 | 171 | } |
| 166 | 172 | |
| 167 | 173 | // Beyond this point you are assumed to be a guest trying to login. |
| 168 | - if (!$user_info['is_guest']) |
|
| 169 | - redirectexit(); |
|
| 174 | + if (!$user_info['is_guest']) { |
|
| 175 | + redirectexit(); |
|
| 176 | + } |
|
| 170 | 177 | |
| 171 | 178 | // Are you guessing with a script? |
| 172 | 179 | checkSession(); |
@@ -174,18 +181,21 @@ discard block |
||
| 174 | 181 | spamProtection('login'); |
| 175 | 182 | |
| 176 | 183 | // Set the login_url if it's not already set (but careful not to send us to an attachment). |
| 177 | - if ((empty($_SESSION['login_url']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) || (isset($_GET['quicklogin']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'login') === false)) |
|
| 178 | - $_SESSION['login_url'] = $_SESSION['old_url']; |
|
| 184 | + if ((empty($_SESSION['login_url']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) || (isset($_GET['quicklogin']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'login') === false)) { |
|
| 185 | + $_SESSION['login_url'] = $_SESSION['old_url']; |
|
| 186 | + } |
|
| 179 | 187 | |
| 180 | 188 | // Been guessing a lot, haven't we? |
| 181 | - if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3) |
|
| 182 | - fatal_lang_error('login_threshold_fail', 'login'); |
|
| 189 | + if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3) { |
|
| 190 | + fatal_lang_error('login_threshold_fail', 'login'); |
|
| 191 | + } |
|
| 183 | 192 | |
| 184 | 193 | // Set up the cookie length. (if it's invalid, just fall through and use the default.) |
| 185 | - if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1)) |
|
| 186 | - $modSettings['cookieTime'] = 3153600; |
|
| 187 | - elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 525600)) |
|
| 188 | - $modSettings['cookieTime'] = (int) $_POST['cookielength']; |
|
| 194 | + if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1)) { |
|
| 195 | + $modSettings['cookieTime'] = 3153600; |
|
| 196 | + } elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 525600)) { |
|
| 197 | + $modSettings['cookieTime'] = (int) $_POST['cookielength']; |
|
| 198 | + } |
|
| 189 | 199 | |
| 190 | 200 | loadLanguage('Login'); |
| 191 | 201 | // Load the template stuff. |
@@ -305,8 +315,9 @@ discard block |
||
| 305 | 315 | $other_passwords[] = crypt(md5($_POST['passwrd']), md5($_POST['passwrd'])); |
| 306 | 316 | |
| 307 | 317 | // Snitz style - SHA-256. Technically, this is a downgrade, but most PHP configurations don't support sha256 anyway. |
| 308 | - if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256')) |
|
| 309 | - $other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd'])); |
|
| 318 | + if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256')) { |
|
| 319 | + $other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd'])); |
|
| 320 | + } |
|
| 310 | 321 | |
| 311 | 322 | // phpBB3 users new hashing. We now support it as well ;). |
| 312 | 323 | $other_passwords[] = phpBB3_password_check($_POST['passwrd'], $user_settings['passwd']); |
@@ -326,27 +337,29 @@ discard block |
||
| 326 | 337 | // Some common md5 ones. |
| 327 | 338 | $other_passwords[] = md5($user_settings['password_salt'] . $_POST['passwrd']); |
| 328 | 339 | $other_passwords[] = md5($_POST['passwrd'] . $user_settings['password_salt']); |
| 329 | - } |
|
| 330 | - elseif (strlen($user_settings['passwd']) == 40) |
|
| 340 | + } elseif (strlen($user_settings['passwd']) == 40) |
|
| 331 | 341 | { |
| 332 | 342 | // Maybe they are using a hash from before the password fix. |
| 333 | 343 | // This is also valid for SMF 1.1 to 2.0 style of hashing, changed to bcrypt in SMF 2.1 |
| 334 | 344 | $other_passwords[] = sha1(strtolower($user_settings['member_name']) . un_htmlspecialchars($_POST['passwrd'])); |
| 335 | 345 | |
| 336 | 346 | // BurningBoard3 style of hashing. |
| 337 | - if (!empty($modSettings['enable_password_conversion'])) |
|
| 338 | - $other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd']))); |
|
| 347 | + if (!empty($modSettings['enable_password_conversion'])) { |
|
| 348 | + $other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd']))); |
|
| 349 | + } |
|
| 339 | 350 | |
| 340 | 351 | // Perhaps we converted to UTF-8 and have a valid password being hashed differently. |
| 341 | 352 | if ($context['character_set'] == 'UTF-8' && !empty($modSettings['previousCharacterSet']) && $modSettings['previousCharacterSet'] != 'utf8') |
| 342 | 353 | { |
| 343 | 354 | // Try iconv first, for no particular reason. |
| 344 | - if (function_exists('iconv')) |
|
| 345 | - $other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd']))); |
|
| 355 | + if (function_exists('iconv')) { |
|
| 356 | + $other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd']))); |
|
| 357 | + } |
|
| 346 | 358 | |
| 347 | 359 | // Say it aint so, iconv failed! |
| 348 | - if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding')) |
|
| 349 | - $other_passwords[] = sha1(strtolower(mb_convert_encoding($user_settings['member_name'], 'UTF-8', $modSettings['previousCharacterSet'])) . un_htmlspecialchars(mb_convert_encoding($_POST['passwrd'], 'UTF-8', $modSettings['previousCharacterSet']))); |
|
| 360 | + if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding')) { |
|
| 361 | + $other_passwords[] = sha1(strtolower(mb_convert_encoding($user_settings['member_name'], 'UTF-8', $modSettings['previousCharacterSet'])) . un_htmlspecialchars(mb_convert_encoding($_POST['passwrd'], 'UTF-8', $modSettings['previousCharacterSet']))); |
|
| 362 | + } |
|
| 350 | 363 | } |
| 351 | 364 | } |
| 352 | 365 | |
@@ -376,8 +389,9 @@ discard block |
||
| 376 | 389 | $_SESSION['failed_login'] = isset($_SESSION['failed_login']) ? ($_SESSION['failed_login'] + 1) : 1; |
| 377 | 390 | |
| 378 | 391 | // Hmm... don't remember it, do you? Here, try the password reminder ;). |
| 379 | - if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold']) |
|
| 380 | - redirectexit('action=reminder'); |
|
| 392 | + if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold']) { |
|
| 393 | + redirectexit('action=reminder'); |
|
| 394 | + } |
|
| 381 | 395 | // We'll give you another chance... |
| 382 | 396 | else |
| 383 | 397 | { |
@@ -388,8 +402,7 @@ discard block |
||
| 388 | 402 | return; |
| 389 | 403 | } |
| 390 | 404 | } |
| 391 | - } |
|
| 392 | - elseif (!empty($user_settings['passwd_flood'])) |
|
| 405 | + } elseif (!empty($user_settings['passwd_flood'])) |
|
| 393 | 406 | { |
| 394 | 407 | // Let's be sure they weren't a little hacker. |
| 395 | 408 | validatePasswordFlood($user_settings['id_member'], $user_settings['member_name'], $user_settings['passwd_flood'], true); |
@@ -406,8 +419,9 @@ discard block |
||
| 406 | 419 | } |
| 407 | 420 | |
| 408 | 421 | // Check their activation status. |
| 409 | - if (!checkActivation()) |
|
| 410 | - return; |
|
| 422 | + if (!checkActivation()) { |
|
| 423 | + return; |
|
| 424 | + } |
|
| 411 | 425 | |
| 412 | 426 | DoLogin(); |
| 413 | 427 | } |
@@ -419,8 +433,9 @@ discard block |
||
| 419 | 433 | { |
| 420 | 434 | global $sourcedir, $txt, $context, $user_info, $modSettings, $scripturl; |
| 421 | 435 | |
| 422 | - if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode'])) |
|
| 423 | - fatal_lang_error('no_access', false); |
|
| 436 | + if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode'])) { |
|
| 437 | + fatal_lang_error('no_access', false); |
|
| 438 | + } |
|
| 424 | 439 | |
| 425 | 440 | loadLanguage('Profile'); |
| 426 | 441 | require_once($sourcedir . '/Class-TOTP.php'); |
@@ -428,8 +443,9 @@ discard block |
||
| 428 | 443 | $member = $context['tfa_member']; |
| 429 | 444 | |
| 430 | 445 | // Prevent replay attacks by limiting at least 2 minutes before they can log in again via 2FA |
| 431 | - if (time() - $member['last_login'] < 120) |
|
| 432 | - fatal_lang_error('tfa_wait', false); |
|
| 446 | + if (time() - $member['last_login'] < 120) { |
|
| 447 | + fatal_lang_error('tfa_wait', false); |
|
| 448 | + } |
|
| 433 | 449 | |
| 434 | 450 | $totp = new \TOTP\Auth($member['tfa_secret']); |
| 435 | 451 | $totp->setRange(1); |
@@ -443,8 +459,9 @@ discard block |
||
| 443 | 459 | if (!empty($_POST['tfa_code']) && empty($_POST['tfa_backup'])) |
| 444 | 460 | { |
| 445 | 461 | // Check to ensure we're forcing SSL for authentication |
| 446 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) |
|
| 447 | - fatal_lang_error('login_ssl_required'); |
|
| 462 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) { |
|
| 463 | + fatal_lang_error('login_ssl_required'); |
|
| 464 | + } |
|
| 448 | 465 | |
| 449 | 466 | $code = $_POST['tfa_code']; |
| 450 | 467 | |
@@ -454,20 +471,19 @@ discard block |
||
| 454 | 471 | |
| 455 | 472 | setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt']), !empty($_POST['tfa_preserve'])); |
| 456 | 473 | redirectexit(); |
| 457 | - } |
|
| 458 | - else |
|
| 474 | + } else |
|
| 459 | 475 | { |
| 460 | 476 | validatePasswordFlood($member['id_member'], $member['member_name'], $member['passwd_flood'], false, true); |
| 461 | 477 | |
| 462 | 478 | $context['tfa_error'] = true; |
| 463 | 479 | $context['tfa_value'] = $_POST['tfa_code']; |
| 464 | 480 | } |
| 465 | - } |
|
| 466 | - elseif (!empty($_POST['tfa_backup'])) |
|
| 481 | + } elseif (!empty($_POST['tfa_backup'])) |
|
| 467 | 482 | { |
| 468 | 483 | // Check to ensure we're forcing SSL for authentication |
| 469 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) |
|
| 470 | - fatal_lang_error('login_ssl_required'); |
|
| 484 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) { |
|
| 485 | + fatal_lang_error('login_ssl_required'); |
|
| 486 | + } |
|
| 471 | 487 | |
| 472 | 488 | $backup = $_POST['tfa_backup']; |
| 473 | 489 | |
@@ -481,8 +497,7 @@ discard block |
||
| 481 | 497 | )); |
| 482 | 498 | setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt'])); |
| 483 | 499 | redirectexit('action=profile;area=tfasetup;backup'); |
| 484 | - } |
|
| 485 | - else |
|
| 500 | + } else |
|
| 486 | 501 | { |
| 487 | 502 | validatePasswordFlood($member['id_member'], $member['member_name'], $member['passwd_flood'], false, true); |
| 488 | 503 | |
@@ -505,8 +520,9 @@ discard block |
||
| 505 | 520 | { |
| 506 | 521 | global $context, $txt, $scripturl, $user_settings, $modSettings; |
| 507 | 522 | |
| 508 | - if (!isset($context['login_errors'])) |
|
| 509 | - $context['login_errors'] = array(); |
|
| 523 | + if (!isset($context['login_errors'])) { |
|
| 524 | + $context['login_errors'] = array(); |
|
| 525 | + } |
|
| 510 | 526 | |
| 511 | 527 | // What is the true activation status of this account? |
| 512 | 528 | $activation_status = $user_settings['is_activated'] > 10 ? $user_settings['is_activated'] - 10 : $user_settings['is_activated']; |
@@ -518,8 +534,9 @@ discard block |
||
| 518 | 534 | return false; |
| 519 | 535 | } |
| 520 | 536 | // Awaiting approval still? |
| 521 | - elseif ($activation_status == 3) |
|
| 522 | - fatal_lang_error('still_awaiting_approval', 'user'); |
|
| 537 | + elseif ($activation_status == 3) { |
|
| 538 | + fatal_lang_error('still_awaiting_approval', 'user'); |
|
| 539 | + } |
|
| 523 | 540 | // Awaiting deletion, changed their mind? |
| 524 | 541 | elseif ($activation_status == 4) |
| 525 | 542 | { |
@@ -527,8 +544,7 @@ discard block |
||
| 527 | 544 | { |
| 528 | 545 | updateMemberData($user_settings['id_member'], array('is_activated' => 1)); |
| 529 | 546 | updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 0 ? $modSettings['unapprovedMembers'] - 1 : 0))); |
| 530 | - } |
|
| 531 | - else |
|
| 547 | + } else |
|
| 532 | 548 | { |
| 533 | 549 | $context['disable_login_hashing'] = true; |
| 534 | 550 | $context['login_errors'][] = $txt['awaiting_delete_account']; |
@@ -568,8 +584,9 @@ discard block |
||
| 568 | 584 | setLoginCookie(60 * $modSettings['cookieTime'], $user_settings['id_member'], hash_salt($user_settings['passwd'], $user_settings['password_salt'])); |
| 569 | 585 | |
| 570 | 586 | // Reset the login threshold. |
| 571 | - if (isset($_SESSION['failed_login'])) |
|
| 572 | - unset($_SESSION['failed_login']); |
|
| 587 | + if (isset($_SESSION['failed_login'])) { |
|
| 588 | + unset($_SESSION['failed_login']); |
|
| 589 | + } |
|
| 573 | 590 | |
| 574 | 591 | $user_info['is_guest'] = false; |
| 575 | 592 | $user_settings['additional_groups'] = explode(',', $user_settings['additional_groups']); |
@@ -591,16 +608,18 @@ discard block |
||
| 591 | 608 | 'id_member' => $user_info['id'], |
| 592 | 609 | ) |
| 593 | 610 | ); |
| 594 | - if ($smcFunc['db_num_rows']($request) == 1) |
|
| 595 | - $_SESSION['first_login'] = true; |
|
| 596 | - else |
|
| 597 | - unset($_SESSION['first_login']); |
|
| 611 | + if ($smcFunc['db_num_rows']($request) == 1) { |
|
| 612 | + $_SESSION['first_login'] = true; |
|
| 613 | + } else { |
|
| 614 | + unset($_SESSION['first_login']); |
|
| 615 | + } |
|
| 598 | 616 | $smcFunc['db_free_result']($request); |
| 599 | 617 | |
| 600 | 618 | // You've logged in, haven't you? |
| 601 | 619 | $update = array('member_ip' => $user_info['ip'], 'member_ip2' => $_SERVER['BAN_CHECK_IP']); |
| 602 | - if (empty($user_settings['tfa_secret'])) |
|
| 603 | - $update['last_login'] = time(); |
|
| 620 | + if (empty($user_settings['tfa_secret'])) { |
|
| 621 | + $update['last_login'] = time(); |
|
| 622 | + } |
|
| 604 | 623 | updateMemberData($user_info['id'], $update); |
| 605 | 624 | |
| 606 | 625 | // Get rid of the online entry for that old guest.... |
@@ -614,8 +633,8 @@ discard block |
||
| 614 | 633 | $_SESSION['log_time'] = 0; |
| 615 | 634 | |
| 616 | 635 | // Log this entry, only if we have it enabled. |
| 617 | - if (!empty($modSettings['loginHistoryDays'])) |
|
| 618 | - $smcFunc['db_insert']('insert', |
|
| 636 | + if (!empty($modSettings['loginHistoryDays'])) { |
|
| 637 | + $smcFunc['db_insert']('insert', |
|
| 619 | 638 | '{db_prefix}member_logins', |
| 620 | 639 | array( |
| 621 | 640 | 'id_member' => 'int', 'time' => 'int', 'ip' => 'inet', 'ip2' => 'inet', |
@@ -627,13 +646,15 @@ discard block |
||
| 627 | 646 | 'id_member', 'time' |
| 628 | 647 | ) |
| 629 | 648 | ); |
| 649 | + } |
|
| 630 | 650 | |
| 631 | 651 | // Just log you back out if it's in maintenance mode and you AREN'T an admin. |
| 632 | - if (empty($maintenance) || allowedTo('admin_forum')) |
|
| 633 | - redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']); |
|
| 634 | - else |
|
| 635 | - redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']); |
|
| 636 | -} |
|
| 652 | + if (empty($maintenance) || allowedTo('admin_forum')) { |
|
| 653 | + redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']); |
|
| 654 | + } else { |
|
| 655 | + redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']); |
|
| 656 | + } |
|
| 657 | + } |
|
| 637 | 658 | |
| 638 | 659 | /** |
| 639 | 660 | * Logs the current user out of their account. |
@@ -649,13 +670,15 @@ discard block |
||
| 649 | 670 | global $sourcedir, $user_info, $user_settings, $context, $smcFunc, $cookiename, $modSettings; |
| 650 | 671 | |
| 651 | 672 | // Make sure they aren't being auto-logged out. |
| 652 | - if (!$internal) |
|
| 653 | - checkSession('get'); |
|
| 673 | + if (!$internal) { |
|
| 674 | + checkSession('get'); |
|
| 675 | + } |
|
| 654 | 676 | |
| 655 | 677 | require_once($sourcedir . '/Subs-Auth.php'); |
| 656 | 678 | |
| 657 | - if (isset($_SESSION['pack_ftp'])) |
|
| 658 | - $_SESSION['pack_ftp'] = null; |
|
| 679 | + if (isset($_SESSION['pack_ftp'])) { |
|
| 680 | + $_SESSION['pack_ftp'] = null; |
|
| 681 | + } |
|
| 659 | 682 | |
| 660 | 683 | // It won't be first login anymore. |
| 661 | 684 | unset($_SESSION['first_login']); |
@@ -683,8 +706,9 @@ discard block |
||
| 683 | 706 | |
| 684 | 707 | // And some other housekeeping while we're at it. |
| 685 | 708 | $salt = substr(md5(mt_rand()), 0, 4); |
| 686 | - if (!empty($user_info['id'])) |
|
| 687 | - updateMemberData($user_info['id'], array('password_salt' => $salt)); |
|
| 709 | + if (!empty($user_info['id'])) { |
|
| 710 | + updateMemberData($user_info['id'], array('password_salt' => $salt)); |
|
| 711 | + } |
|
| 688 | 712 | |
| 689 | 713 | if (!empty($modSettings['tfa_mode']) && !empty($user_info['id']) && !empty($_COOKIE[$cookiename . '_tfa'])) |
| 690 | 714 | { |
@@ -693,10 +717,11 @@ discard block |
||
| 693 | 717 | list ($tfamember, $tfasecret, $exp, $state, $preserve) = $tfadata; |
| 694 | 718 | |
| 695 | 719 | // If we're preserving the cookie, reset it with updated salt |
| 696 | - if (isset($tfamember, $tfasecret, $exp, $state, $preserve) && $preserve && time() < $exp) |
|
| 697 | - setTFACookie(3153600, $user_info['id'], hash_salt($user_settings['tfa_backup'], $salt), true); |
|
| 698 | - else |
|
| 699 | - setTFACookie(-3600, 0, ''); |
|
| 720 | + if (isset($tfamember, $tfasecret, $exp, $state, $preserve) && $preserve && time() < $exp) { |
|
| 721 | + setTFACookie(3153600, $user_info['id'], hash_salt($user_settings['tfa_backup'], $salt), true); |
|
| 722 | + } else { |
|
| 723 | + setTFACookie(-3600, 0, ''); |
|
| 724 | + } |
|
| 700 | 725 | } |
| 701 | 726 | |
| 702 | 727 | session_destroy(); |
@@ -704,14 +729,13 @@ discard block |
||
| 704 | 729 | // Off to the merry board index we go! |
| 705 | 730 | if ($redirect) |
| 706 | 731 | { |
| 707 | - if (empty($_SESSION['logout_url'])) |
|
| 708 | - redirectexit('', $context['server']['needs_login_fix']); |
|
| 709 | - elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false)) |
|
| 732 | + if (empty($_SESSION['logout_url'])) { |
|
| 733 | + redirectexit('', $context['server']['needs_login_fix']); |
|
| 734 | + } elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false)) |
|
| 710 | 735 | { |
| 711 | 736 | unset ($_SESSION['logout_url']); |
| 712 | 737 | redirectexit(); |
| 713 | - } |
|
| 714 | - else |
|
| 738 | + } else |
|
| 715 | 739 | { |
| 716 | 740 | $temp = $_SESSION['logout_url']; |
| 717 | 741 | unset($_SESSION['logout_url']); |
@@ -744,8 +768,9 @@ discard block |
||
| 744 | 768 | function phpBB3_password_check($passwd, $passwd_hash) |
| 745 | 769 | { |
| 746 | 770 | // Too long or too short? |
| 747 | - if (strlen($passwd_hash) != 34) |
|
| 748 | - return; |
|
| 771 | + if (strlen($passwd_hash) != 34) { |
|
| 772 | + return; |
|
| 773 | + } |
|
| 749 | 774 | |
| 750 | 775 | // Range of characters allowed. |
| 751 | 776 | $range = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; |
@@ -756,8 +781,9 @@ discard block |
||
| 756 | 781 | $salt = substr($passwd_hash, 4, 8); |
| 757 | 782 | |
| 758 | 783 | $hash = md5($salt . $passwd, true); |
| 759 | - for (; $count != 0; --$count) |
|
| 760 | - $hash = md5($hash . $passwd, true); |
|
| 784 | + for (; $count != 0; --$count) { |
|
| 785 | + $hash = md5($hash . $passwd, true); |
|
| 786 | + } |
|
| 761 | 787 | |
| 762 | 788 | $output = substr($passwd_hash, 0, 12); |
| 763 | 789 | $i = 0; |
@@ -766,21 +792,25 @@ discard block |
||
| 766 | 792 | $value = ord($hash[$i++]); |
| 767 | 793 | $output .= $range[$value & 0x3f]; |
| 768 | 794 | |
| 769 | - if ($i < 16) |
|
| 770 | - $value |= ord($hash[$i]) << 8; |
|
| 795 | + if ($i < 16) { |
|
| 796 | + $value |= ord($hash[$i]) << 8; |
|
| 797 | + } |
|
| 771 | 798 | |
| 772 | 799 | $output .= $range[($value >> 6) & 0x3f]; |
| 773 | 800 | |
| 774 | - if ($i++ >= 16) |
|
| 775 | - break; |
|
| 801 | + if ($i++ >= 16) { |
|
| 802 | + break; |
|
| 803 | + } |
|
| 776 | 804 | |
| 777 | - if ($i < 16) |
|
| 778 | - $value |= ord($hash[$i]) << 16; |
|
| 805 | + if ($i < 16) { |
|
| 806 | + $value |= ord($hash[$i]) << 16; |
|
| 807 | + } |
|
| 779 | 808 | |
| 780 | 809 | $output .= $range[($value >> 12) & 0x3f]; |
| 781 | 810 | |
| 782 | - if ($i++ >= 16) |
|
| 783 | - break; |
|
| 811 | + if ($i++ >= 16) { |
|
| 812 | + break; |
|
| 813 | + } |
|
| 784 | 814 | |
| 785 | 815 | $output .= $range[($value >> 18) & 0x3f]; |
| 786 | 816 | } |
@@ -812,8 +842,9 @@ discard block |
||
| 812 | 842 | require_once($sourcedir . '/Subs-Auth.php'); |
| 813 | 843 | setLoginCookie(-3600, 0); |
| 814 | 844 | |
| 815 | - if (isset($_SESSION['login_' . $cookiename])) |
|
| 816 | - unset($_SESSION['login_' . $cookiename]); |
|
| 845 | + if (isset($_SESSION['login_' . $cookiename])) { |
|
| 846 | + unset($_SESSION['login_' . $cookiename]); |
|
| 847 | + } |
|
| 817 | 848 | } |
| 818 | 849 | |
| 819 | 850 | // We need a member! |
@@ -827,8 +858,9 @@ discard block |
||
| 827 | 858 | } |
| 828 | 859 | |
| 829 | 860 | // Right, have we got a flood value? |
| 830 | - if ($password_flood_value !== false) |
|
| 831 | - @list ($time_stamp, $number_tries) = explode('|', $password_flood_value); |
|
| 861 | + if ($password_flood_value !== false) { |
|
| 862 | + @list ($time_stamp, $number_tries) = explode('|', $password_flood_value); |
|
| 863 | + } |
|
| 832 | 864 | |
| 833 | 865 | // Timestamp or number of tries invalid? |
| 834 | 866 | if (empty($number_tries) || empty($time_stamp)) |
@@ -844,15 +876,17 @@ discard block |
||
| 844 | 876 | $number_tries = $time_stamp < time() - 20 ? 2 : $number_tries; |
| 845 | 877 | |
| 846 | 878 | // They are trying too fast, make them wait longer |
| 847 | - if ($time_stamp < time() - 10) |
|
| 848 | - $time_stamp = time(); |
|
| 879 | + if ($time_stamp < time() - 10) { |
|
| 880 | + $time_stamp = time(); |
|
| 881 | + } |
|
| 849 | 882 | } |
| 850 | 883 | |
| 851 | 884 | $number_tries++; |
| 852 | 885 | |
| 853 | 886 | // Broken the law? |
| 854 | - if ($number_tries > 5) |
|
| 855 | - fatal_lang_error('login_threshold_brute_fail', 'login', [$member_name]); |
|
| 887 | + if ($number_tries > 5) { |
|
| 888 | + fatal_lang_error('login_threshold_brute_fail', 'login', [$member_name]); |
|
| 889 | + } |
|
| 856 | 890 | |
| 857 | 891 | // Otherwise set the members data. If they correct on their first attempt then we actually clear it, otherwise we set it! |
| 858 | 892 | updateMemberData($id_member, array('passwd_flood' => $was_correct && $number_tries == 1 ? '' : $time_stamp . '|' . $number_tries)); |
@@ -15,8 +15,9 @@ discard block |
||
| 15 | 15 | * @version 2.1 Beta 4 |
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | -if (!defined('SMF')) |
|
| 18 | +if (!defined('SMF')) { |
|
| 19 | 19 | die('No direct access...'); |
| 20 | +} |
|
| 20 | 21 | |
| 21 | 22 | /** |
| 22 | 23 | * Begin the registration process. |
@@ -29,19 +30,23 @@ discard block |
||
| 29 | 30 | global $language, $scripturl, $smcFunc, $sourcedir, $cur_profile; |
| 30 | 31 | |
| 31 | 32 | // Is this an incoming AJAX check? |
| 32 | - if (isset($_GET['sa']) && $_GET['sa'] == 'usernamecheck') |
|
| 33 | - return RegisterCheckUsername(); |
|
| 33 | + if (isset($_GET['sa']) && $_GET['sa'] == 'usernamecheck') { |
|
| 34 | + return RegisterCheckUsername(); |
|
| 35 | + } |
|
| 34 | 36 | |
| 35 | 37 | // Check if the administrator has it disabled. |
| 36 | - if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == '3') |
|
| 37 | - fatal_lang_error('registration_disabled', false); |
|
| 38 | + if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == '3') { |
|
| 39 | + fatal_lang_error('registration_disabled', false); |
|
| 40 | + } |
|
| 38 | 41 | |
| 39 | 42 | // If this user is an admin - redirect them to the admin registration page. |
| 40 | - if (allowedTo('moderate_forum') && !$user_info['is_guest']) |
|
| 41 | - redirectexit('action=admin;area=regcenter;sa=register'); |
|
| 43 | + if (allowedTo('moderate_forum') && !$user_info['is_guest']) { |
|
| 44 | + redirectexit('action=admin;area=regcenter;sa=register'); |
|
| 45 | + } |
|
| 42 | 46 | // You are not a guest, so you are a member - and members don't get to register twice! |
| 43 | - elseif (empty($user_info['is_guest'])) |
|
| 44 | - redirectexit(); |
|
| 47 | + elseif (empty($user_info['is_guest'])) { |
|
| 48 | + redirectexit(); |
|
| 49 | + } |
|
| 45 | 50 | |
| 46 | 51 | loadLanguage('Login'); |
| 47 | 52 | loadTemplate('Register'); |
@@ -82,16 +87,18 @@ discard block |
||
| 82 | 87 | } |
| 83 | 88 | } |
| 84 | 89 | // Make sure they don't squeeze through without agreeing. |
| 85 | - elseif ($current_step > 1 && $context['require_agreement'] && !$context['registration_passed_agreement']) |
|
| 86 | - $current_step = 1; |
|
| 90 | + elseif ($current_step > 1 && $context['require_agreement'] && !$context['registration_passed_agreement']) { |
|
| 91 | + $current_step = 1; |
|
| 92 | + } |
|
| 87 | 93 | |
| 88 | 94 | // Show the user the right form. |
| 89 | 95 | $context['sub_template'] = $current_step == 1 ? 'registration_agreement' : 'registration_form'; |
| 90 | 96 | $context['page_title'] = $current_step == 1 ? $txt['registration_agreement'] : $txt['registration_form']; |
| 91 | 97 | |
| 92 | 98 | // Kinda need this. |
| 93 | - if ($context['sub_template'] == 'registration_form') |
|
| 94 | - loadJavaScriptFile('register.js', array('defer' => false), 'smf_register'); |
|
| 99 | + if ($context['sub_template'] == 'registration_form') { |
|
| 100 | + loadJavaScriptFile('register.js', array('defer' => false), 'smf_register'); |
|
| 101 | + } |
|
| 95 | 102 | |
| 96 | 103 | // Add the register chain to the link tree. |
| 97 | 104 | $context['linktree'][] = array( |
@@ -100,24 +107,26 @@ discard block |
||
| 100 | 107 | ); |
| 101 | 108 | |
| 102 | 109 | // Prepare the time gate! Do it like so, in case later steps want to reset the limit for any reason, but make sure the time is the current one. |
| 103 | - if (!isset($_SESSION['register'])) |
|
| 104 | - $_SESSION['register'] = array( |
|
| 110 | + if (!isset($_SESSION['register'])) { |
|
| 111 | + $_SESSION['register'] = array( |
|
| 105 | 112 | 'timenow' => time(), |
| 106 | 113 | 'limit' => 10, // minimum number of seconds required on this page for registration |
| 107 | 114 | ); |
| 108 | - else |
|
| 109 | - $_SESSION['register']['timenow'] = time(); |
|
| 115 | + } else { |
|
| 116 | + $_SESSION['register']['timenow'] = time(); |
|
| 117 | + } |
|
| 110 | 118 | |
| 111 | 119 | // If you have to agree to the agreement, it needs to be fetched from the file. |
| 112 | 120 | if ($context['require_agreement']) |
| 113 | 121 | { |
| 114 | 122 | // Have we got a localized one? |
| 115 | - if (file_exists($boarddir . '/agreement.' . $user_info['language'] . '.txt')) |
|
| 116 | - $context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.' . $user_info['language'] . '.txt'), true, 'agreement_' . $user_info['language']); |
|
| 117 | - elseif (file_exists($boarddir . '/agreement.txt')) |
|
| 118 | - $context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.txt'), true, 'agreement'); |
|
| 119 | - else |
|
| 120 | - $context['agreement'] = ''; |
|
| 123 | + if (file_exists($boarddir . '/agreement.' . $user_info['language'] . '.txt')) { |
|
| 124 | + $context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.' . $user_info['language'] . '.txt'), true, 'agreement_' . $user_info['language']); |
|
| 125 | + } elseif (file_exists($boarddir . '/agreement.txt')) { |
|
| 126 | + $context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.txt'), true, 'agreement'); |
|
| 127 | + } else { |
|
| 128 | + $context['agreement'] = ''; |
|
| 129 | + } |
|
| 121 | 130 | |
| 122 | 131 | // Nothing to show, lets disable registration and inform the admin of this error |
| 123 | 132 | if (empty($context['agreement'])) |
@@ -133,8 +142,9 @@ discard block |
||
| 133 | 142 | $selectedLanguage = empty($_SESSION['language']) ? $language : $_SESSION['language']; |
| 134 | 143 | |
| 135 | 144 | // Do we have any languages? |
| 136 | - if (empty($context['languages'])) |
|
| 137 | - getLanguages(); |
|
| 145 | + if (empty($context['languages'])) { |
|
| 146 | + getLanguages(); |
|
| 147 | + } |
|
| 138 | 148 | |
| 139 | 149 | // Try to find our selected language. |
| 140 | 150 | foreach ($context['languages'] as $key => $lang) |
@@ -142,8 +152,9 @@ discard block |
||
| 142 | 152 | $context['languages'][$key]['name'] = strtr($lang['name'], array('-utf8' => '')); |
| 143 | 153 | |
| 144 | 154 | // Found it! |
| 145 | - if ($selectedLanguage == $lang['filename']) |
|
| 146 | - $context['languages'][$key]['selected'] = true; |
|
| 155 | + if ($selectedLanguage == $lang['filename']) { |
|
| 156 | + $context['languages'][$key]['selected'] = true; |
|
| 157 | + } |
|
| 147 | 158 | } |
| 148 | 159 | } |
| 149 | 160 | |
@@ -167,9 +178,10 @@ discard block |
||
| 167 | 178 | $reg_fields = explode(',', $modSettings['registration_fields']); |
| 168 | 179 | |
| 169 | 180 | // We might have had some submissions on this front - go check. |
| 170 | - foreach ($reg_fields as $field) |
|
| 171 | - if (isset($_POST[$field])) |
|
| 181 | + foreach ($reg_fields as $field) { |
|
| 182 | + if (isset($_POST[$field])) |
|
| 172 | 183 | $cur_profile[$field] = $smcFunc['htmlspecialchars']($_POST[$field]); |
| 184 | + } |
|
| 173 | 185 | |
| 174 | 186 | // Load all the fields in question. |
| 175 | 187 | setupProfileContext($reg_fields); |
@@ -186,8 +198,9 @@ discard block |
||
| 186 | 198 | $context['visual_verification_id'] = $verificationOptions['id']; |
| 187 | 199 | } |
| 188 | 200 | // Otherwise we have nothing to show. |
| 189 | - else |
|
| 190 | - $context['visual_verification'] = false; |
|
| 201 | + else { |
|
| 202 | + $context['visual_verification'] = false; |
|
| 203 | + } |
|
| 191 | 204 | |
| 192 | 205 | |
| 193 | 206 | $context += array( |
@@ -198,8 +211,9 @@ discard block |
||
| 198 | 211 | |
| 199 | 212 | // Were there any errors? |
| 200 | 213 | $context['registration_errors'] = array(); |
| 201 | - if (!empty($reg_errors)) |
|
| 202 | - $context['registration_errors'] = $reg_errors; |
|
| 214 | + if (!empty($reg_errors)) { |
|
| 215 | + $context['registration_errors'] = $reg_errors; |
|
| 216 | + } |
|
| 203 | 217 | |
| 204 | 218 | createToken('register'); |
| 205 | 219 | } |
@@ -216,27 +230,32 @@ discard block |
||
| 216 | 230 | validateToken('register'); |
| 217 | 231 | |
| 218 | 232 | // Check to ensure we're forcing SSL for authentication |
| 219 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) |
|
| 220 | - fatal_lang_error('register_ssl_required'); |
|
| 233 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) { |
|
| 234 | + fatal_lang_error('register_ssl_required'); |
|
| 235 | + } |
|
| 221 | 236 | |
| 222 | 237 | // Start collecting together any errors. |
| 223 | 238 | $reg_errors = array(); |
| 224 | 239 | |
| 225 | 240 | // You can't register if it's disabled. |
| 226 | - if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 3) |
|
| 227 | - fatal_lang_error('registration_disabled', false); |
|
| 241 | + if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 3) { |
|
| 242 | + fatal_lang_error('registration_disabled', false); |
|
| 243 | + } |
|
| 228 | 244 | |
| 229 | 245 | // Well, if you don't agree, you can't register. |
| 230 | - if (!empty($modSettings['requireAgreement']) && empty($_SESSION['registration_agreed'])) |
|
| 231 | - redirectexit(); |
|
| 246 | + if (!empty($modSettings['requireAgreement']) && empty($_SESSION['registration_agreed'])) { |
|
| 247 | + redirectexit(); |
|
| 248 | + } |
|
| 232 | 249 | |
| 233 | 250 | // Make sure they came from *somewhere*, have a session. |
| 234 | - if (!isset($_SESSION['old_url'])) |
|
| 235 | - redirectexit('action=signup'); |
|
| 251 | + if (!isset($_SESSION['old_url'])) { |
|
| 252 | + redirectexit('action=signup'); |
|
| 253 | + } |
|
| 236 | 254 | |
| 237 | 255 | // If we don't require an agreement, we need a extra check for coppa. |
| 238 | - if (empty($modSettings['requireAgreement']) && !empty($modSettings['coppaAge'])) |
|
| 239 | - $_SESSION['skip_coppa'] = !empty($_POST['accept_agreement']); |
|
| 256 | + if (empty($modSettings['requireAgreement']) && !empty($modSettings['coppaAge'])) { |
|
| 257 | + $_SESSION['skip_coppa'] = !empty($_POST['accept_agreement']); |
|
| 258 | + } |
|
| 240 | 259 | // Are they under age, and under age users are banned? |
| 241 | 260 | if (!empty($modSettings['coppaAge']) && empty($modSettings['coppaType']) && empty($_SESSION['skip_coppa'])) |
| 242 | 261 | { |
@@ -245,8 +264,9 @@ discard block |
||
| 245 | 264 | } |
| 246 | 265 | |
| 247 | 266 | // Check the time gate for miscreants. First make sure they came from somewhere that actually set it up. |
| 248 | - if (empty($_SESSION['register']['timenow']) || empty($_SESSION['register']['limit'])) |
|
| 249 | - redirectexit('action=signup'); |
|
| 267 | + if (empty($_SESSION['register']['timenow']) || empty($_SESSION['register']['limit'])) { |
|
| 268 | + redirectexit('action=signup'); |
|
| 269 | + } |
|
| 250 | 270 | // Failing that, check the time on it. |
| 251 | 271 | if (time() - $_SESSION['register']['timenow'] < $_SESSION['register']['limit']) |
| 252 | 272 | { |
@@ -266,15 +286,17 @@ discard block |
||
| 266 | 286 | if (is_array($context['visual_verification'])) |
| 267 | 287 | { |
| 268 | 288 | loadLanguage('Errors'); |
| 269 | - foreach ($context['visual_verification'] as $error) |
|
| 270 | - $reg_errors[] = $txt['error_' . $error]; |
|
| 289 | + foreach ($context['visual_verification'] as $error) { |
|
| 290 | + $reg_errors[] = $txt['error_' . $error]; |
|
| 291 | + } |
|
| 271 | 292 | } |
| 272 | 293 | } |
| 273 | 294 | |
| 274 | 295 | foreach ($_POST as $key => $value) |
| 275 | 296 | { |
| 276 | - if (!is_array($_POST[$key])) |
|
| 277 | - $_POST[$key] = htmltrim__recursive(str_replace(array("\n", "\r"), '', $_POST[$key])); |
|
| 297 | + if (!is_array($_POST[$key])) { |
|
| 298 | + $_POST[$key] = htmltrim__recursive(str_replace(array("\n", "\r"), '', $_POST[$key])); |
|
| 299 | + } |
|
| 278 | 300 | } |
| 279 | 301 | |
| 280 | 302 | // Collect all extra registration fields someone might have filled in. |
@@ -304,12 +326,14 @@ discard block |
||
| 304 | 326 | $reg_fields = explode(',', $modSettings['registration_fields']); |
| 305 | 327 | |
| 306 | 328 | // Website is a little different |
| 307 | - if (in_array('website', $reg_fields)) |
|
| 308 | - $possible_strings = array_merge(array('website_url', 'website_title'), $possible_strings); |
|
| 329 | + if (in_array('website', $reg_fields)) { |
|
| 330 | + $possible_strings = array_merge(array('website_url', 'website_title'), $possible_strings); |
|
| 331 | + } |
|
| 309 | 332 | } |
| 310 | 333 | |
| 311 | - if (isset($_POST['secret_answer']) && $_POST['secret_answer'] != '') |
|
| 312 | - $_POST['secret_answer'] = md5($_POST['secret_answer']); |
|
| 334 | + if (isset($_POST['secret_answer']) && $_POST['secret_answer'] != '') { |
|
| 335 | + $_POST['secret_answer'] = md5($_POST['secret_answer']); |
|
| 336 | + } |
|
| 313 | 337 | |
| 314 | 338 | // Needed for isReservedName() and registerMember(). |
| 315 | 339 | require_once($sourcedir . '/Subs-Members.php'); |
@@ -318,8 +342,9 @@ discard block |
||
| 318 | 342 | if (isset($_POST['real_name'])) |
| 319 | 343 | { |
| 320 | 344 | // Are you already allowed to edit the displayed name? |
| 321 | - if (allowedTo('profile_displayed_name') || allowedTo('moderate_forum')) |
|
| 322 | - $canEditDisplayName = true; |
|
| 345 | + if (allowedTo('profile_displayed_name') || allowedTo('moderate_forum')) { |
|
| 346 | + $canEditDisplayName = true; |
|
| 347 | + } |
|
| 323 | 348 | |
| 324 | 349 | // If you are a guest, will you be allowed to once you register? |
| 325 | 350 | else |
@@ -343,33 +368,38 @@ discard block |
||
| 343 | 368 | $_POST['real_name'] = trim(preg_replace('~[\t\n\r \x0B\0' . ($context['utf8'] ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : '\x00-\x08\x0B\x0C\x0E-\x19\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $_POST['real_name'])); |
| 344 | 369 | |
| 345 | 370 | // Only set it if we are sure it is good |
| 346 | - if (trim($_POST['real_name']) != '' && !isReservedName($_POST['real_name']) && $smcFunc['strlen']($_POST['real_name']) < 60) |
|
| 347 | - $possible_strings[] = 'real_name'; |
|
| 371 | + if (trim($_POST['real_name']) != '' && !isReservedName($_POST['real_name']) && $smcFunc['strlen']($_POST['real_name']) < 60) { |
|
| 372 | + $possible_strings[] = 'real_name'; |
|
| 373 | + } |
|
| 348 | 374 | } |
| 349 | 375 | } |
| 350 | 376 | |
| 351 | 377 | // Handle a string as a birthdate... |
| 352 | - if (isset($_POST['birthdate']) && $_POST['birthdate'] != '') |
|
| 353 | - $_POST['birthdate'] = strftime('%Y-%m-%d', strtotime($_POST['birthdate'])); |
|
| 378 | + if (isset($_POST['birthdate']) && $_POST['birthdate'] != '') { |
|
| 379 | + $_POST['birthdate'] = strftime('%Y-%m-%d', strtotime($_POST['birthdate'])); |
|
| 380 | + } |
|
| 354 | 381 | // Or birthdate parts... |
| 355 | - elseif (!empty($_POST['bday1']) && !empty($_POST['bday2'])) |
|
| 356 | - $_POST['birthdate'] = sprintf('%04d-%02d-%02d', empty($_POST['bday3']) ? 0 : (int) $_POST['bday3'], (int) $_POST['bday1'], (int) $_POST['bday2']); |
|
| 382 | + elseif (!empty($_POST['bday1']) && !empty($_POST['bday2'])) { |
|
| 383 | + $_POST['birthdate'] = sprintf('%04d-%02d-%02d', empty($_POST['bday3']) ? 0 : (int) $_POST['bday3'], (int) $_POST['bday1'], (int) $_POST['bday2']); |
|
| 384 | + } |
|
| 357 | 385 | |
| 358 | 386 | // Validate the passed language file. |
| 359 | 387 | if (isset($_POST['lngfile']) && !empty($modSettings['userLanguage'])) |
| 360 | 388 | { |
| 361 | 389 | // Do we have any languages? |
| 362 | - if (empty($context['languages'])) |
|
| 363 | - getLanguages(); |
|
| 390 | + if (empty($context['languages'])) { |
|
| 391 | + getLanguages(); |
|
| 392 | + } |
|
| 364 | 393 | |
| 365 | 394 | // Did we find it? |
| 366 | - if (isset($context['languages'][$_POST['lngfile']])) |
|
| 367 | - $_SESSION['language'] = $_POST['lngfile']; |
|
| 368 | - else |
|
| 395 | + if (isset($context['languages'][$_POST['lngfile']])) { |
|
| 396 | + $_SESSION['language'] = $_POST['lngfile']; |
|
| 397 | + } else { |
|
| 398 | + unset($_POST['lngfile']); |
|
| 399 | + } |
|
| 400 | + } else { |
|
| 369 | 401 | unset($_POST['lngfile']); |
| 370 | 402 | } |
| 371 | - else |
|
| 372 | - unset($_POST['lngfile']); |
|
| 373 | 403 | |
| 374 | 404 | // Set the options needed for registration. |
| 375 | 405 | $regOptions = array( |
@@ -389,22 +419,27 @@ discard block |
||
| 389 | 419 | ); |
| 390 | 420 | |
| 391 | 421 | // Include the additional options that might have been filled in. |
| 392 | - foreach ($possible_strings as $var) |
|
| 393 | - if (isset($_POST[$var])) |
|
| 422 | + foreach ($possible_strings as $var) { |
|
| 423 | + if (isset($_POST[$var])) |
|
| 394 | 424 | $regOptions['extra_register_vars'][$var] = $smcFunc['htmlspecialchars']($_POST[$var], ENT_QUOTES); |
| 395 | - foreach ($possible_ints as $var) |
|
| 396 | - if (isset($_POST[$var])) |
|
| 425 | + } |
|
| 426 | + foreach ($possible_ints as $var) { |
|
| 427 | + if (isset($_POST[$var])) |
|
| 397 | 428 | $regOptions['extra_register_vars'][$var] = (int) $_POST[$var]; |
| 398 | - foreach ($possible_floats as $var) |
|
| 399 | - if (isset($_POST[$var])) |
|
| 429 | + } |
|
| 430 | + foreach ($possible_floats as $var) { |
|
| 431 | + if (isset($_POST[$var])) |
|
| 400 | 432 | $regOptions['extra_register_vars'][$var] = (float) $_POST[$var]; |
| 401 | - foreach ($possible_bools as $var) |
|
| 402 | - if (isset($_POST[$var])) |
|
| 433 | + } |
|
| 434 | + foreach ($possible_bools as $var) { |
|
| 435 | + if (isset($_POST[$var])) |
|
| 403 | 436 | $regOptions['extra_register_vars'][$var] = empty($_POST[$var]) ? 0 : 1; |
| 437 | + } |
|
| 404 | 438 | |
| 405 | 439 | // Registration options are always default options... |
| 406 | - if (isset($_POST['default_options'])) |
|
| 407 | - $_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options']; |
|
| 440 | + if (isset($_POST['default_options'])) { |
|
| 441 | + $_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options']; |
|
| 442 | + } |
|
| 408 | 443 | $regOptions['theme_vars'] = isset($_POST['options']) && is_array($_POST['options']) ? $_POST['options'] : array(); |
| 409 | 444 | |
| 410 | 445 | // Make sure they are clean, dammit! |
@@ -424,12 +459,14 @@ discard block |
||
| 424 | 459 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 425 | 460 | { |
| 426 | 461 | // Don't allow overriding of the theme variables. |
| 427 | - if (isset($regOptions['theme_vars'][$row['col_name']])) |
|
| 428 | - unset($regOptions['theme_vars'][$row['col_name']]); |
|
| 462 | + if (isset($regOptions['theme_vars'][$row['col_name']])) { |
|
| 463 | + unset($regOptions['theme_vars'][$row['col_name']]); |
|
| 464 | + } |
|
| 429 | 465 | |
| 430 | 466 | // Not actually showing it then? |
| 431 | - if (!$row['show_reg']) |
|
| 432 | - continue; |
|
| 467 | + if (!$row['show_reg']) { |
|
| 468 | + continue; |
|
| 469 | + } |
|
| 433 | 470 | |
| 434 | 471 | // Prepare the value! |
| 435 | 472 | $value = isset($_POST['customfield'][$row['col_name']]) ? trim($_POST['customfield'][$row['col_name']]) : ''; |
@@ -438,24 +475,27 @@ discard block |
||
| 438 | 475 | if (!in_array($row['field_type'], array('check', 'select', 'radio'))) |
| 439 | 476 | { |
| 440 | 477 | // Is it too long? |
| 441 | - if ($row['field_length'] && $row['field_length'] < $smcFunc['strlen']($value)) |
|
| 442 | - $custom_field_errors[] = array('custom_field_too_long', array($row['field_name'], $row['field_length'])); |
|
| 478 | + if ($row['field_length'] && $row['field_length'] < $smcFunc['strlen']($value)) { |
|
| 479 | + $custom_field_errors[] = array('custom_field_too_long', array($row['field_name'], $row['field_length'])); |
|
| 480 | + } |
|
| 443 | 481 | |
| 444 | 482 | // Any masks to apply? |
| 445 | 483 | if ($row['field_type'] == 'text' && !empty($row['mask']) && $row['mask'] != 'none') |
| 446 | 484 | { |
| 447 | - if ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255)) |
|
| 448 | - $custom_field_errors[] = array('custom_field_invalid_email', array($row['field_name'])); |
|
| 449 | - elseif ($row['mask'] == 'number' && preg_match('~[^\d]~', $value)) |
|
| 450 | - $custom_field_errors[] = array('custom_field_not_number', array($row['field_name'])); |
|
| 451 | - elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0) |
|
| 452 | - $custom_field_errors[] = array('custom_field_inproper_format', array($row['field_name'])); |
|
| 485 | + if ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255)) { |
|
| 486 | + $custom_field_errors[] = array('custom_field_invalid_email', array($row['field_name'])); |
|
| 487 | + } elseif ($row['mask'] == 'number' && preg_match('~[^\d]~', $value)) { |
|
| 488 | + $custom_field_errors[] = array('custom_field_not_number', array($row['field_name'])); |
|
| 489 | + } elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0) { |
|
| 490 | + $custom_field_errors[] = array('custom_field_inproper_format', array($row['field_name'])); |
|
| 491 | + } |
|
| 453 | 492 | } |
| 454 | 493 | } |
| 455 | 494 | |
| 456 | 495 | // Is this required but not there? |
| 457 | - if (trim($value) == '' && $row['show_reg'] > 1) |
|
| 458 | - $custom_field_errors[] = array('custom_field_empty', array($row['field_name'])); |
|
| 496 | + if (trim($value) == '' && $row['show_reg'] > 1) { |
|
| 497 | + $custom_field_errors[] = array('custom_field_empty', array($row['field_name'])); |
|
| 498 | + } |
|
| 459 | 499 | } |
| 460 | 500 | $smcFunc['db_free_result']($request); |
| 461 | 501 | |
@@ -463,8 +503,9 @@ discard block |
||
| 463 | 503 | if (!empty($custom_field_errors)) |
| 464 | 504 | { |
| 465 | 505 | loadLanguage('Errors'); |
| 466 | - foreach ($custom_field_errors as $error) |
|
| 467 | - $reg_errors[] = vsprintf($txt['error_' . $error[0]], $error[1]); |
|
| 506 | + foreach ($custom_field_errors as $error) { |
|
| 507 | + $reg_errors[] = vsprintf($txt['error_' . $error[0]], $error[1]); |
|
| 508 | + } |
|
| 468 | 509 | } |
| 469 | 510 | |
| 470 | 511 | // Lets check for other errors before trying to register the member. |
@@ -509,8 +550,9 @@ discard block |
||
| 509 | 550 | } |
| 510 | 551 | |
| 511 | 552 | // If COPPA has been selected then things get complicated, setup the template. |
| 512 | - if (!empty($modSettings['coppaAge']) && empty($_SESSION['skip_coppa'])) |
|
| 513 | - redirectexit('action=coppa;member=' . $memberID); |
|
| 553 | + if (!empty($modSettings['coppaAge']) && empty($_SESSION['skip_coppa'])) { |
|
| 554 | + redirectexit('action=coppa;member=' . $memberID); |
|
| 555 | + } |
|
| 514 | 556 | // Basic template variable setup. |
| 515 | 557 | elseif (!empty($modSettings['registration_method'])) |
| 516 | 558 | { |
@@ -522,8 +564,7 @@ discard block |
||
| 522 | 564 | 'sub_template' => 'after', |
| 523 | 565 | 'description' => $modSettings['registration_method'] == 2 ? $txt['approval_after_registration'] : $txt['activate_after_registration'] |
| 524 | 566 | ); |
| 525 | - } |
|
| 526 | - else |
|
| 567 | + } else |
|
| 527 | 568 | { |
| 528 | 569 | call_integration_hook('integrate_activate', array($regOptions['username'])); |
| 529 | 570 | |
@@ -543,16 +584,18 @@ discard block |
||
| 543 | 584 | global $context, $txt, $modSettings, $scripturl, $sourcedir, $smcFunc, $language, $user_info; |
| 544 | 585 | |
| 545 | 586 | // Logged in users should not bother to activate their accounts |
| 546 | - if (!empty($user_info['id'])) |
|
| 547 | - redirectexit(); |
|
| 587 | + if (!empty($user_info['id'])) { |
|
| 588 | + redirectexit(); |
|
| 589 | + } |
|
| 548 | 590 | |
| 549 | 591 | loadLanguage('Login'); |
| 550 | 592 | loadTemplate('Login'); |
| 551 | 593 | |
| 552 | 594 | if (empty($_REQUEST['u']) && empty($_POST['user'])) |
| 553 | 595 | { |
| 554 | - if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == '3') |
|
| 555 | - fatal_lang_error('no_access', false); |
|
| 596 | + if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == '3') { |
|
| 597 | + fatal_lang_error('no_access', false); |
|
| 598 | + } |
|
| 556 | 599 | |
| 557 | 600 | $context['member_id'] = 0; |
| 558 | 601 | $context['sub_template'] = 'resend'; |
@@ -592,11 +635,13 @@ discard block |
||
| 592 | 635 | // Change their email address? (they probably tried a fake one first :P.) |
| 593 | 636 | if (isset($_POST['new_email'], $_REQUEST['passwd']) && hash_password($row['member_name'], $_REQUEST['passwd']) == $row['passwd'] && ($row['is_activated'] == 0 || $row['is_activated'] == 2)) |
| 594 | 637 | { |
| 595 | - if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == 3) |
|
| 596 | - fatal_lang_error('no_access', false); |
|
| 638 | + if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == 3) { |
|
| 639 | + fatal_lang_error('no_access', false); |
|
| 640 | + } |
|
| 597 | 641 | |
| 598 | - if (!filter_var($_POST['new_email'], FILTER_VALIDATE_EMAIL)) |
|
| 599 | - fatal_error(sprintf($txt['valid_email_needed'], $smcFunc['htmlspecialchars']($_POST['new_email'])), false); |
|
| 642 | + if (!filter_var($_POST['new_email'], FILTER_VALIDATE_EMAIL)) { |
|
| 643 | + fatal_error(sprintf($txt['valid_email_needed'], $smcFunc['htmlspecialchars']($_POST['new_email'])), false); |
|
| 644 | + } |
|
| 600 | 645 | |
| 601 | 646 | // Make sure their email isn't banned. |
| 602 | 647 | isBannedEmail($_POST['new_email'], 'cannot_register', $txt['ban_register_prohibited']); |
@@ -612,8 +657,9 @@ discard block |
||
| 612 | 657 | ) |
| 613 | 658 | ); |
| 614 | 659 | |
| 615 | - if ($smcFunc['db_num_rows']($request) != 0) |
|
| 616 | - fatal_lang_error('email_in_use', false, array($smcFunc['htmlspecialchars']($_POST['new_email']))); |
|
| 660 | + if ($smcFunc['db_num_rows']($request) != 0) { |
|
| 661 | + fatal_lang_error('email_in_use', false, array($smcFunc['htmlspecialchars']($_POST['new_email']))); |
|
| 662 | + } |
|
| 617 | 663 | $smcFunc['db_free_result']($request); |
| 618 | 664 | |
| 619 | 665 | updateMemberData($row['id_member'], array('email_address' => $_POST['new_email'])); |
@@ -651,9 +697,9 @@ discard block |
||
| 651 | 697 | // Quit if this code is not right. |
| 652 | 698 | if (empty($_REQUEST['code']) || $row['validation_code'] != $_REQUEST['code']) |
| 653 | 699 | { |
| 654 | - if (!empty($row['is_activated'])) |
|
| 655 | - fatal_lang_error('already_activated', false); |
|
| 656 | - elseif ($row['validation_code'] == '') |
|
| 700 | + if (!empty($row['is_activated'])) { |
|
| 701 | + fatal_lang_error('already_activated', false); |
|
| 702 | + } elseif ($row['validation_code'] == '') |
|
| 657 | 703 | { |
| 658 | 704 | loadLanguage('Profile'); |
| 659 | 705 | fatal_error(sprintf($txt['registration_not_approved'], $scripturl . '?action=activate;user=' . $row['member_name']), false); |
@@ -703,8 +749,9 @@ discard block |
||
| 703 | 749 | loadTemplate('Register'); |
| 704 | 750 | |
| 705 | 751 | // No User ID?? |
| 706 | - if (!isset($_GET['member'])) |
|
| 707 | - fatal_lang_error('no_access', false); |
|
| 752 | + if (!isset($_GET['member'])) { |
|
| 753 | + fatal_lang_error('no_access', false); |
|
| 754 | + } |
|
| 708 | 755 | |
| 709 | 756 | // Get the user details... |
| 710 | 757 | $request = $smcFunc['db_query']('', ' |
@@ -717,8 +764,9 @@ discard block |
||
| 717 | 764 | 'is_coppa' => 5, |
| 718 | 765 | ) |
| 719 | 766 | ); |
| 720 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 721 | - fatal_lang_error('no_access', false); |
|
| 767 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 768 | + fatal_lang_error('no_access', false); |
|
| 769 | + } |
|
| 722 | 770 | list ($username) = $smcFunc['db_fetch_row']($request); |
| 723 | 771 | $smcFunc['db_free_result']($request); |
| 724 | 772 | |
@@ -756,8 +804,7 @@ discard block |
||
| 756 | 804 | echo $data; |
| 757 | 805 | obExit(false); |
| 758 | 806 | } |
| 759 | - } |
|
| 760 | - else |
|
| 807 | + } else |
|
| 761 | 808 | { |
| 762 | 809 | $context += array( |
| 763 | 810 | 'page_title' => $txt['coppa_title'], |
@@ -810,8 +857,9 @@ discard block |
||
| 810 | 857 | { |
| 811 | 858 | require_once($sourcedir . '/Subs-Graphics.php'); |
| 812 | 859 | |
| 813 | - if (in_array('gd', get_loaded_extensions()) && !showCodeImage($code)) |
|
| 814 | - header('HTTP/1.1 400 Bad Request'); |
|
| 860 | + if (in_array('gd', get_loaded_extensions()) && !showCodeImage($code)) { |
|
| 861 | + header('HTTP/1.1 400 Bad Request'); |
|
| 862 | + } |
|
| 815 | 863 | |
| 816 | 864 | // Otherwise just show a pre-defined letter. |
| 817 | 865 | elseif (isset($_REQUEST['letter'])) |
@@ -829,14 +877,13 @@ discard block |
||
| 829 | 877 | header('Content-Type: image/gif'); |
| 830 | 878 | die("\x47\x49\x46\x38\x39\x61\x01\x00\x01\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x21\xF9\x04\x01\x00\x00\x00\x00\x2C\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02\x44\x01\x00\x3B"); |
| 831 | 879 | } |
| 832 | - } |
|
| 833 | - |
|
| 834 | - elseif ($_REQUEST['format'] === '.wav') |
|
| 880 | + } elseif ($_REQUEST['format'] === '.wav') |
|
| 835 | 881 | { |
| 836 | 882 | require_once($sourcedir . '/Subs-Sound.php'); |
| 837 | 883 | |
| 838 | - if (!createWaveFile($code)) |
|
| 839 | - header('HTTP/1.1 400 Bad Request'); |
|
| 884 | + if (!createWaveFile($code)) { |
|
| 885 | + header('HTTP/1.1 400 Bad Request'); |
|
| 886 | + } |
|
| 840 | 887 | } |
| 841 | 888 | |
| 842 | 889 | // We all die one day... |
@@ -15,8 +15,9 @@ discard block |
||
| 15 | 15 | * @version 2.1 Beta 4 |
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | -if (!defined('SMF')) |
|
| 18 | +if (!defined('SMF')) { |
|
| 19 | 19 | die('No direct access...'); |
| 20 | +} |
|
| 20 | 21 | |
| 21 | 22 | /** |
| 22 | 23 | * The main designating function for modifying profiles. Loads up info, determins what to do, etc. |
@@ -29,18 +30,21 @@ discard block |
||
| 29 | 30 | global $modSettings, $memberContext, $profile_vars, $post_errors, $smcFunc; |
| 30 | 31 | |
| 31 | 32 | // Don't reload this as we may have processed error strings. |
| 32 | - if (empty($post_errors)) |
|
| 33 | - loadLanguage('Profile+Drafts'); |
|
| 33 | + if (empty($post_errors)) { |
|
| 34 | + loadLanguage('Profile+Drafts'); |
|
| 35 | + } |
|
| 34 | 36 | loadTemplate('Profile'); |
| 35 | 37 | |
| 36 | 38 | require_once($sourcedir . '/Subs-Menu.php'); |
| 37 | 39 | |
| 38 | 40 | // Did we get the user by name... |
| 39 | - if (isset($_REQUEST['user'])) |
|
| 40 | - $memberResult = loadMemberData($_REQUEST['user'], true, 'profile'); |
|
| 41 | + if (isset($_REQUEST['user'])) { |
|
| 42 | + $memberResult = loadMemberData($_REQUEST['user'], true, 'profile'); |
|
| 43 | + } |
|
| 41 | 44 | // ... or by id_member? |
| 42 | - elseif (!empty($_REQUEST['u'])) |
|
| 43 | - $memberResult = loadMemberData((int) $_REQUEST['u'], false, 'profile'); |
|
| 45 | + elseif (!empty($_REQUEST['u'])) { |
|
| 46 | + $memberResult = loadMemberData((int) $_REQUEST['u'], false, 'profile'); |
|
| 47 | + } |
|
| 44 | 48 | // If it was just ?action=profile, edit your own profile, but only if you're not a guest. |
| 45 | 49 | else |
| 46 | 50 | { |
@@ -50,8 +54,9 @@ discard block |
||
| 50 | 54 | } |
| 51 | 55 | |
| 52 | 56 | // Check if loadMemberData() has returned a valid result. |
| 53 | - if (!$memberResult) |
|
| 54 | - fatal_lang_error('not_a_user', false, 404); |
|
| 57 | + if (!$memberResult) { |
|
| 58 | + fatal_lang_error('not_a_user', false, 404); |
|
| 59 | + } |
|
| 55 | 60 | |
| 56 | 61 | // If all went well, we have a valid member ID! |
| 57 | 62 | list ($memID) = $memberResult; |
@@ -67,8 +72,9 @@ discard block |
||
| 67 | 72 | |
| 68 | 73 | // Group management isn't actually a permission. But we need it to be for this, so we need a phantom permission. |
| 69 | 74 | // And we care about what the current user can do, not what the user whose profile it is. |
| 70 | - if ($user_info['mod_cache']['gq'] != '0=1') |
|
| 71 | - $user_info['permissions'][] = 'approve_group_requests'; |
|
| 75 | + if ($user_info['mod_cache']['gq'] != '0=1') { |
|
| 76 | + $user_info['permissions'][] = 'approve_group_requests'; |
|
| 77 | + } |
|
| 72 | 78 | |
| 73 | 79 | // If paid subscriptions are enabled, make sure we actually have at least one subscription available... |
| 74 | 80 | $context['subs_available'] = false; |
@@ -436,21 +442,25 @@ discard block |
||
| 436 | 442 | foreach ($section['areas'] as $area_id => $area) |
| 437 | 443 | { |
| 438 | 444 | // If it said no permissions that meant it wasn't valid! |
| 439 | - if (empty($area['permission'][$context['user']['is_owner'] ? 'own' : 'any'])) |
|
| 440 | - $profile_areas[$section_id]['areas'][$area_id]['enabled'] = false; |
|
| 445 | + if (empty($area['permission'][$context['user']['is_owner'] ? 'own' : 'any'])) { |
|
| 446 | + $profile_areas[$section_id]['areas'][$area_id]['enabled'] = false; |
|
| 447 | + } |
|
| 441 | 448 | // Otherwise pick the right set. |
| 442 | - else |
|
| 443 | - $profile_areas[$section_id]['areas'][$area_id]['permission'] = $area['permission'][$context['user']['is_owner'] ? 'own' : 'any']; |
|
| 449 | + else { |
|
| 450 | + $profile_areas[$section_id]['areas'][$area_id]['permission'] = $area['permission'][$context['user']['is_owner'] ? 'own' : 'any']; |
|
| 451 | + } |
|
| 444 | 452 | |
| 445 | 453 | // Password required in most cases |
| 446 | - if (!empty($area['password'])) |
|
| 447 | - $context['password_areas'][] = $area_id; |
|
| 454 | + if (!empty($area['password'])) { |
|
| 455 | + $context['password_areas'][] = $area_id; |
|
| 456 | + } |
|
| 448 | 457 | } |
| 449 | 458 | } |
| 450 | 459 | |
| 451 | 460 | // Is there an updated message to show? |
| 452 | - if (isset($_GET['updated'])) |
|
| 453 | - $context['profile_updated'] = $txt['profile_updated_own']; |
|
| 461 | + if (isset($_GET['updated'])) { |
|
| 462 | + $context['profile_updated'] = $txt['profile_updated_own']; |
|
| 463 | + } |
|
| 454 | 464 | |
| 455 | 465 | // Set a few options for the menu. |
| 456 | 466 | $menuOptions = array( |
@@ -465,8 +475,9 @@ discard block |
||
| 465 | 475 | $profile_include_data = createMenu($profile_areas, $menuOptions); |
| 466 | 476 | |
| 467 | 477 | // No menu means no access. |
| 468 | - if (!$profile_include_data && (!$user_info['is_guest'] || validateSession())) |
|
| 469 | - fatal_lang_error('no_access', false); |
|
| 478 | + if (!$profile_include_data && (!$user_info['is_guest'] || validateSession())) { |
|
| 479 | + fatal_lang_error('no_access', false); |
|
| 480 | + } |
|
| 470 | 481 | |
| 471 | 482 | // Make a note of the Unique ID for this menu. |
| 472 | 483 | $context['profile_menu_id'] = $context['max_menu_id']; |
@@ -492,8 +503,9 @@ discard block |
||
| 492 | 503 | if ($current_area == $area_id) |
| 493 | 504 | { |
| 494 | 505 | // This can't happen - but is a security check. |
| 495 | - if ((isset($section['enabled']) && $section['enabled'] == false) || (isset($area['enabled']) && $area['enabled'] == false)) |
|
| 496 | - fatal_lang_error('no_access', false); |
|
| 506 | + if ((isset($section['enabled']) && $section['enabled'] == false) || (isset($area['enabled']) && $area['enabled'] == false)) { |
|
| 507 | + fatal_lang_error('no_access', false); |
|
| 508 | + } |
|
| 497 | 509 | |
| 498 | 510 | // Are we saving data in a valid area? |
| 499 | 511 | if (isset($area['sc']) && (isset($_REQUEST['save']) || $context['do_preview'])) |
@@ -512,12 +524,14 @@ discard block |
||
| 512 | 524 | } |
| 513 | 525 | |
| 514 | 526 | // Does this require session validating? |
| 515 | - if (!empty($area['validate']) || (isset($_REQUEST['save']) && !$context['user']['is_owner'])) |
|
| 516 | - $security_checks['validate'] = true; |
|
| 527 | + if (!empty($area['validate']) || (isset($_REQUEST['save']) && !$context['user']['is_owner'])) { |
|
| 528 | + $security_checks['validate'] = true; |
|
| 529 | + } |
|
| 517 | 530 | |
| 518 | 531 | // Permissions for good measure. |
| 519 | - if (!empty($profile_include_data['permission'])) |
|
| 520 | - $security_checks['permission'] = $profile_include_data['permission']; |
|
| 532 | + if (!empty($profile_include_data['permission'])) { |
|
| 533 | + $security_checks['permission'] = $profile_include_data['permission']; |
|
| 534 | + } |
|
| 521 | 535 | |
| 522 | 536 | // Either way got something. |
| 523 | 537 | $found_area = true; |
@@ -526,21 +540,26 @@ discard block |
||
| 526 | 540 | } |
| 527 | 541 | |
| 528 | 542 | // Oh dear, some serious security lapse is going on here... we'll put a stop to that! |
| 529 | - if (!$found_area) |
|
| 530 | - fatal_lang_error('no_access', false); |
|
| 543 | + if (!$found_area) { |
|
| 544 | + fatal_lang_error('no_access', false); |
|
| 545 | + } |
|
| 531 | 546 | |
| 532 | 547 | // Release this now. |
| 533 | 548 | unset($profile_areas); |
| 534 | 549 | |
| 535 | 550 | // Now the context is setup have we got any security checks to carry out additional to that above? |
| 536 | - if (isset($security_checks['session'])) |
|
| 537 | - checkSession($security_checks['session']); |
|
| 538 | - if (isset($security_checks['validate'])) |
|
| 539 | - validateSession(); |
|
| 540 | - if (isset($security_checks['validateToken'])) |
|
| 541 | - validateToken($token_name, $token_type); |
|
| 542 | - if (isset($security_checks['permission'])) |
|
| 543 | - isAllowedTo($security_checks['permission']); |
|
| 551 | + if (isset($security_checks['session'])) { |
|
| 552 | + checkSession($security_checks['session']); |
|
| 553 | + } |
|
| 554 | + if (isset($security_checks['validate'])) { |
|
| 555 | + validateSession(); |
|
| 556 | + } |
|
| 557 | + if (isset($security_checks['validateToken'])) { |
|
| 558 | + validateToken($token_name, $token_type); |
|
| 559 | + } |
|
| 560 | + if (isset($security_checks['permission'])) { |
|
| 561 | + isAllowedTo($security_checks['permission']); |
|
| 562 | + } |
|
| 544 | 563 | |
| 545 | 564 | // Create a token if needed. |
| 546 | 565 | if (isset($security_checks['needsToken']) || isset($security_checks['validateToken'])) |
@@ -550,8 +569,9 @@ discard block |
||
| 550 | 569 | } |
| 551 | 570 | |
| 552 | 571 | // File to include? |
| 553 | - if (isset($profile_include_data['file'])) |
|
| 554 | - require_once($sourcedir . '/' . $profile_include_data['file']); |
|
| 572 | + if (isset($profile_include_data['file'])) { |
|
| 573 | + require_once($sourcedir . '/' . $profile_include_data['file']); |
|
| 574 | + } |
|
| 555 | 575 | |
| 556 | 576 | // Build the link tree. |
| 557 | 577 | $context['linktree'][] = array( |
@@ -559,17 +579,19 @@ discard block |
||
| 559 | 579 | 'name' => sprintf($txt['profile_of_username'], $context['member']['name']), |
| 560 | 580 | ); |
| 561 | 581 | |
| 562 | - if (!empty($profile_include_data['label'])) |
|
| 563 | - $context['linktree'][] = array( |
|
| 582 | + if (!empty($profile_include_data['label'])) { |
|
| 583 | + $context['linktree'][] = array( |
|
| 564 | 584 | 'url' => $scripturl . '?action=profile' . ($memID != $user_info['id'] ? ';u=' . $memID : '') . ';area=' . $profile_include_data['current_area'], |
| 565 | 585 | 'name' => $profile_include_data['label'], |
| 566 | 586 | ); |
| 587 | + } |
|
| 567 | 588 | |
| 568 | - if (!empty($profile_include_data['current_subsection']) && $profile_include_data['subsections'][$profile_include_data['current_subsection']][0] != $profile_include_data['label']) |
|
| 569 | - $context['linktree'][] = array( |
|
| 589 | + if (!empty($profile_include_data['current_subsection']) && $profile_include_data['subsections'][$profile_include_data['current_subsection']][0] != $profile_include_data['label']) { |
|
| 590 | + $context['linktree'][] = array( |
|
| 570 | 591 | 'url' => $scripturl . '?action=profile' . ($memID != $user_info['id'] ? ';u=' . $memID : '') . ';area=' . $profile_include_data['current_area'] . ';sa=' . $profile_include_data['current_subsection'], |
| 571 | 592 | 'name' => $profile_include_data['subsections'][$profile_include_data['current_subsection']][0], |
| 572 | 593 | ); |
| 594 | + } |
|
| 573 | 595 | |
| 574 | 596 | // Set the template for this area and add the profile layer. |
| 575 | 597 | $context['sub_template'] = $profile_include_data['function']; |
@@ -595,12 +617,14 @@ discard block |
||
| 595 | 617 | if ($check_password) |
| 596 | 618 | { |
| 597 | 619 | // Check to ensure we're forcing SSL for authentication |
| 598 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) |
|
| 599 | - fatal_lang_error('login_ssl_required'); |
|
| 620 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) { |
|
| 621 | + fatal_lang_error('login_ssl_required'); |
|
| 622 | + } |
|
| 600 | 623 | |
| 601 | 624 | // You didn't even enter a password! |
| 602 | - if (trim($_POST['oldpasswrd']) == '') |
|
| 603 | - $post_errors[] = 'no_password'; |
|
| 625 | + if (trim($_POST['oldpasswrd']) == '') { |
|
| 626 | + $post_errors[] = 'no_password'; |
|
| 627 | + } |
|
| 604 | 628 | |
| 605 | 629 | // Since the password got modified due to all the $_POST cleaning, lets undo it so we can get the correct password |
| 606 | 630 | $_POST['oldpasswrd'] = un_htmlspecialchars($_POST['oldpasswrd']); |
@@ -609,42 +633,43 @@ discard block |
||
| 609 | 633 | $good_password = in_array(true, call_integration_hook('integrate_verify_password', array($cur_profile['member_name'], $_POST['oldpasswrd'], false)), true); |
| 610 | 634 | |
| 611 | 635 | // Bad password!!! |
| 612 | - if (!$good_password && !hash_verify_password($user_profile[$memID]['member_name'], un_htmlspecialchars(stripslashes($_POST['oldpasswrd'])), $user_info['passwd'])) |
|
| 613 | - $post_errors[] = 'bad_password'; |
|
| 636 | + if (!$good_password && !hash_verify_password($user_profile[$memID]['member_name'], un_htmlspecialchars(stripslashes($_POST['oldpasswrd'])), $user_info['passwd'])) { |
|
| 637 | + $post_errors[] = 'bad_password'; |
|
| 638 | + } |
|
| 614 | 639 | |
| 615 | 640 | // Warn other elements not to jump the gun and do custom changes! |
| 616 | - if (in_array('bad_password', $post_errors)) |
|
| 617 | - $context['password_auth_failed'] = true; |
|
| 641 | + if (in_array('bad_password', $post_errors)) { |
|
| 642 | + $context['password_auth_failed'] = true; |
|
| 643 | + } |
|
| 618 | 644 | } |
| 619 | 645 | |
| 620 | 646 | // Change the IP address in the database. |
| 621 | - if ($context['user']['is_owner']) |
|
| 622 | - $profile_vars['member_ip'] = $user_info['ip']; |
|
| 647 | + if ($context['user']['is_owner']) { |
|
| 648 | + $profile_vars['member_ip'] = $user_info['ip']; |
|
| 649 | + } |
|
| 623 | 650 | |
| 624 | 651 | // Now call the sub-action function... |
| 625 | 652 | if ($current_area == 'activateaccount') |
| 626 | 653 | { |
| 627 | - if (empty($post_errors)) |
|
| 628 | - activateAccount($memID); |
|
| 629 | - } |
|
| 630 | - elseif ($current_area == 'deleteaccount') |
|
| 654 | + if (empty($post_errors)) { |
|
| 655 | + activateAccount($memID); |
|
| 656 | + } |
|
| 657 | + } elseif ($current_area == 'deleteaccount') |
|
| 631 | 658 | { |
| 632 | 659 | if (empty($post_errors)) |
| 633 | 660 | { |
| 634 | 661 | deleteAccount2($memID); |
| 635 | 662 | redirectexit(); |
| 636 | 663 | } |
| 637 | - } |
|
| 638 | - elseif ($current_area == 'groupmembership' && empty($post_errors)) |
|
| 664 | + } elseif ($current_area == 'groupmembership' && empty($post_errors)) |
|
| 639 | 665 | { |
| 640 | 666 | $msg = groupMembership2($profile_vars, $post_errors, $memID); |
| 641 | 667 | |
| 642 | 668 | // Whatever we've done, we have nothing else to do here... |
| 643 | 669 | redirectexit('action=profile' . ($context['user']['is_owner'] ? '' : ';u=' . $memID) . ';area=groupmembership' . (!empty($msg) ? ';msg=' . $msg : '')); |
| 644 | - } |
|
| 645 | - elseif (in_array($current_area, array('account', 'forumprofile', 'theme'))) |
|
| 646 | - saveProfileFields(); |
|
| 647 | - else |
|
| 670 | + } elseif (in_array($current_area, array('account', 'forumprofile', 'theme'))) { |
|
| 671 | + saveProfileFields(); |
|
| 672 | + } else |
|
| 648 | 673 | { |
| 649 | 674 | $force_redirect = true; |
| 650 | 675 | // Ensure we include this. |
@@ -660,34 +685,36 @@ discard block |
||
| 660 | 685 | // Load the language file so we can give a nice explanation of the errors. |
| 661 | 686 | loadLanguage('Errors'); |
| 662 | 687 | $context['post_errors'] = $post_errors; |
| 663 | - } |
|
| 664 | - elseif (!empty($profile_vars)) |
|
| 688 | + } elseif (!empty($profile_vars)) |
|
| 665 | 689 | { |
| 666 | 690 | // If we've changed the password, notify any integration that may be listening in. |
| 667 | - if (isset($profile_vars['passwd'])) |
|
| 668 | - call_integration_hook('integrate_reset_pass', array($cur_profile['member_name'], $cur_profile['member_name'], $_POST['passwrd2'])); |
|
| 691 | + if (isset($profile_vars['passwd'])) { |
|
| 692 | + call_integration_hook('integrate_reset_pass', array($cur_profile['member_name'], $cur_profile['member_name'], $_POST['passwrd2'])); |
|
| 693 | + } |
|
| 669 | 694 | |
| 670 | 695 | updateMemberData($memID, $profile_vars); |
| 671 | 696 | |
| 672 | 697 | // What if this is the newest member? |
| 673 | - if ($modSettings['latestMember'] == $memID) |
|
| 674 | - updateStats('member'); |
|
| 675 | - elseif (isset($profile_vars['real_name'])) |
|
| 676 | - updateSettings(array('memberlist_updated' => time())); |
|
| 698 | + if ($modSettings['latestMember'] == $memID) { |
|
| 699 | + updateStats('member'); |
|
| 700 | + } elseif (isset($profile_vars['real_name'])) { |
|
| 701 | + updateSettings(array('memberlist_updated' => time())); |
|
| 702 | + } |
|
| 677 | 703 | |
| 678 | 704 | // If the member changed his/her birthdate, update calendar statistics. |
| 679 | - if (isset($profile_vars['birthdate']) || isset($profile_vars['real_name'])) |
|
| 680 | - updateSettings(array( |
|
| 705 | + if (isset($profile_vars['birthdate']) || isset($profile_vars['real_name'])) { |
|
| 706 | + updateSettings(array( |
|
| 681 | 707 | 'calendar_updated' => time(), |
| 682 | 708 | )); |
| 709 | + } |
|
| 683 | 710 | |
| 684 | 711 | // Anything worth logging? |
| 685 | 712 | if (!empty($context['log_changes']) && !empty($modSettings['modlog_enabled'])) |
| 686 | 713 | { |
| 687 | 714 | $log_changes = array(); |
| 688 | 715 | require_once($sourcedir . '/Logging.php'); |
| 689 | - foreach ($context['log_changes'] as $k => $v) |
|
| 690 | - $log_changes[] = array( |
|
| 716 | + foreach ($context['log_changes'] as $k => $v) { |
|
| 717 | + $log_changes[] = array( |
|
| 691 | 718 | 'action' => $k, |
| 692 | 719 | 'log_type' => 'user', |
| 693 | 720 | 'extra' => array_merge($v, array( |
@@ -695,14 +722,16 @@ discard block |
||
| 695 | 722 | 'member_affected' => $memID, |
| 696 | 723 | )), |
| 697 | 724 | ); |
| 725 | + } |
|
| 698 | 726 | |
| 699 | 727 | logActions($log_changes); |
| 700 | 728 | } |
| 701 | 729 | |
| 702 | 730 | // Have we got any post save functions to execute? |
| 703 | - if (!empty($context['profile_execute_on_save'])) |
|
| 704 | - foreach ($context['profile_execute_on_save'] as $saveFunc) |
|
| 731 | + if (!empty($context['profile_execute_on_save'])) { |
|
| 732 | + foreach ($context['profile_execute_on_save'] as $saveFunc) |
|
| 705 | 733 | $saveFunc(); |
| 734 | + } |
|
| 706 | 735 | |
| 707 | 736 | // Let them know it worked! |
| 708 | 737 | $context['profile_updated'] = $context['user']['is_owner'] ? $txt['profile_updated_own'] : sprintf($txt['profile_updated_else'], $cur_profile['member_name']); |
@@ -716,27 +745,31 @@ discard block |
||
| 716 | 745 | if (!empty($post_errors)) |
| 717 | 746 | { |
| 718 | 747 | // Set all the errors so the template knows what went wrong. |
| 719 | - foreach ($post_errors as $error_type) |
|
| 720 | - $context['modify_error'][$error_type] = true; |
|
| 748 | + foreach ($post_errors as $error_type) { |
|
| 749 | + $context['modify_error'][$error_type] = true; |
|
| 750 | + } |
|
| 721 | 751 | } |
| 722 | 752 | // If it's you then we should redirect upon save. |
| 723 | - elseif (!empty($profile_vars) && $context['user']['is_owner'] && !$context['do_preview']) |
|
| 724 | - redirectexit('action=profile;area=' . $current_area . (!empty($current_sa) ? ';sa=' . $current_sa : '') . ';updated'); |
|
| 725 | - elseif (!empty($force_redirect)) |
|
| 726 | - redirectexit('action=profile' . ($context['user']['is_owner'] ? '' : ';u=' . $memID) . ';area=' . $current_area); |
|
| 753 | + elseif (!empty($profile_vars) && $context['user']['is_owner'] && !$context['do_preview']) { |
|
| 754 | + redirectexit('action=profile;area=' . $current_area . (!empty($current_sa) ? ';sa=' . $current_sa : '') . ';updated'); |
|
| 755 | + } elseif (!empty($force_redirect)) { |
|
| 756 | + redirectexit('action=profile' . ($context['user']['is_owner'] ? '' : ';u=' . $memID) . ';area=' . $current_area); |
|
| 757 | + } |
|
| 727 | 758 | |
| 728 | 759 | |
| 729 | 760 | // Get the right callable. |
| 730 | 761 | $call = call_helper($profile_include_data['function'], true); |
| 731 | 762 | |
| 732 | 763 | // Is it valid? |
| 733 | - if (!empty($call)) |
|
| 734 | - call_user_func($call, $memID); |
|
| 764 | + if (!empty($call)) { |
|
| 765 | + call_user_func($call, $memID); |
|
| 766 | + } |
|
| 735 | 767 | |
| 736 | 768 | // Set the page title if it's not already set... |
| 737 | - if (!isset($context['page_title'])) |
|
| 738 | - $context['page_title'] = $txt['profile'] . (isset($txt[$current_area]) ? ' - ' . $txt[$current_area] : ''); |
|
| 739 | -} |
|
| 769 | + if (!isset($context['page_title'])) { |
|
| 770 | + $context['page_title'] = $txt['profile'] . (isset($txt[$current_area]) ? ' - ' . $txt[$current_area] : ''); |
|
| 771 | + } |
|
| 772 | + } |
|
| 740 | 773 | |
| 741 | 774 | /** |
| 742 | 775 | * Set up the requirements for the profile popup - the area that is shown as the popup menu for the current user. |
@@ -859,16 +892,18 @@ discard block |
||
| 859 | 892 | if (!allowedTo('admin_forum') && $area != 'register') |
| 860 | 893 | { |
| 861 | 894 | // If it's the owner they can see two types of private fields, regardless. |
| 862 | - if ($memID == $user_info['id']) |
|
| 863 | - $where .= $area == 'summary' ? ' AND private < 3' : ' AND (private = 0 OR private = 2)'; |
|
| 864 | - else |
|
| 865 | - $where .= $area == 'summary' ? ' AND private < 2' : ' AND private = 0'; |
|
| 895 | + if ($memID == $user_info['id']) { |
|
| 896 | + $where .= $area == 'summary' ? ' AND private < 3' : ' AND (private = 0 OR private = 2)'; |
|
| 897 | + } else { |
|
| 898 | + $where .= $area == 'summary' ? ' AND private < 2' : ' AND private = 0'; |
|
| 899 | + } |
|
| 866 | 900 | } |
| 867 | 901 | |
| 868 | - if ($area == 'register') |
|
| 869 | - $where .= ' AND show_reg != 0'; |
|
| 870 | - elseif ($area != 'summary') |
|
| 871 | - $where .= ' AND show_profile = {string:area}'; |
|
| 902 | + if ($area == 'register') { |
|
| 903 | + $where .= ' AND show_reg != 0'; |
|
| 904 | + } elseif ($area != 'summary') { |
|
| 905 | + $where .= ' AND show_profile = {string:area}'; |
|
| 906 | + } |
|
| 872 | 907 | |
| 873 | 908 | // Load all the relevant fields - and data. |
| 874 | 909 | $request = $smcFunc['db_query']('', ' |
@@ -894,13 +929,15 @@ discard block |
||
| 894 | 929 | if (isset($_POST['customfield']) && isset($_POST['customfield'][$row['col_name']])) |
| 895 | 930 | { |
| 896 | 931 | $value = $smcFunc['htmlspecialchars']($_POST['customfield'][$row['col_name']]); |
| 897 | - if (in_array($row['field_type'], array('select', 'radio'))) |
|
| 898 | - $value = ($options = explode(',', $row['field_options'])) && isset($options[$value]) ? $options[$value] : ''; |
|
| 932 | + if (in_array($row['field_type'], array('select', 'radio'))) { |
|
| 933 | + $value = ($options = explode(',', $row['field_options'])) && isset($options[$value]) ? $options[$value] : ''; |
|
| 934 | + } |
|
| 899 | 935 | } |
| 900 | 936 | |
| 901 | 937 | // Don't show the "disabled" option for the "gender" field if we are on the "summary" area. |
| 902 | - if ($area == 'summary' && $row['col_name'] == 'cust_gender' && $value == 'None') |
|
| 903 | - continue; |
|
| 938 | + if ($area == 'summary' && $row['col_name'] == 'cust_gender' && $value == 'None') { |
|
| 939 | + continue; |
|
| 940 | + } |
|
| 904 | 941 | |
| 905 | 942 | // HTML for the input form. |
| 906 | 943 | $output_html = $value; |
@@ -909,8 +946,7 @@ discard block |
||
| 909 | 946 | $true = (!$exists && $row['default_value']) || $value; |
| 910 | 947 | $input_html = '<input type="checkbox" name="customfield[' . $row['col_name'] . ']" id="customfield[' . $row['col_name'] . ']"' . ($true ? ' checked' : '') . '>'; |
| 911 | 948 | $output_html = $true ? $txt['yes'] : $txt['no']; |
| 912 | - } |
|
| 913 | - elseif ($row['field_type'] == 'select') |
|
| 949 | + } elseif ($row['field_type'] == 'select') |
|
| 914 | 950 | { |
| 915 | 951 | $input_html = '<select name="customfield[' . $row['col_name'] . ']" id="customfield[' . $row['col_name'] . ']"><option value="-1"></option>'; |
| 916 | 952 | $options = explode(',', $row['field_options']); |
@@ -918,13 +954,13 @@ discard block |
||
| 918 | 954 | { |
| 919 | 955 | $true = (!$exists && $row['default_value'] == $v) || $value == $v; |
| 920 | 956 | $input_html .= '<option value="' . $k . '"' . ($true ? ' selected' : '') . '>' . $v . '</option>'; |
| 921 | - if ($true) |
|
| 922 | - $output_html = $v; |
|
| 957 | + if ($true) { |
|
| 958 | + $output_html = $v; |
|
| 959 | + } |
|
| 923 | 960 | } |
| 924 | 961 | |
| 925 | 962 | $input_html .= '</select>'; |
| 926 | - } |
|
| 927 | - elseif ($row['field_type'] == 'radio') |
|
| 963 | + } elseif ($row['field_type'] == 'radio') |
|
| 928 | 964 | { |
| 929 | 965 | $input_html = '<fieldset>'; |
| 930 | 966 | $options = explode(',', $row['field_options']); |
@@ -932,36 +968,37 @@ discard block |
||
| 932 | 968 | { |
| 933 | 969 | $true = (!$exists && $row['default_value'] == $v) || $value == $v; |
| 934 | 970 | $input_html .= '<label for="customfield_' . $row['col_name'] . '_' . $k . '"><input type="radio" name="customfield[' . $row['col_name'] . ']" id="customfield_' . $row['col_name'] . '_' . $k . '" value="' . $k . '"' . ($true ? ' checked' : '') . '>' . $v . '</label><br>'; |
| 935 | - if ($true) |
|
| 936 | - $output_html = $v; |
|
| 971 | + if ($true) { |
|
| 972 | + $output_html = $v; |
|
| 973 | + } |
|
| 937 | 974 | } |
| 938 | 975 | $input_html .= '</fieldset>'; |
| 939 | - } |
|
| 940 | - elseif ($row['field_type'] == 'text') |
|
| 976 | + } elseif ($row['field_type'] == 'text') |
|
| 941 | 977 | { |
| 942 | 978 | $input_html = '<input type="text" name="customfield[' . $row['col_name'] . ']" id="customfield[' . $row['col_name'] . ']"' . ($row['field_length'] != 0 ? ' maxlength="' . $row['field_length'] . '"' : '') . ' size="' . ($row['field_length'] == 0 || $row['field_length'] >= 50 ? 50 : ($row['field_length'] > 30 ? 30 : ($row['field_length'] > 10 ? 20 : 10))) . '" value="' . un_htmlspecialchars($value) . '"' . ($row['show_reg'] == 2 ? ' required' : '') . '>'; |
| 943 | - } |
|
| 944 | - else |
|
| 979 | + } else |
|
| 945 | 980 | { |
| 946 | 981 | @list ($rows, $cols) = @explode(',', $row['default_value']); |
| 947 | 982 | $input_html = '<textarea name="customfield[' . $row['col_name'] . ']" id="customfield[' . $row['col_name'] . ']"' . (!empty($rows) ? ' rows="' . $rows . '"' : '') . (!empty($cols) ? ' cols="' . $cols . '"' : '') . ($row['show_reg'] == 2 ? ' required' : '') . '>' . un_htmlspecialchars($value) . '</textarea>'; |
| 948 | 983 | } |
| 949 | 984 | |
| 950 | 985 | // Parse BBCode |
| 951 | - if ($row['bbc']) |
|
| 952 | - $output_html = parse_bbc($output_html); |
|
| 953 | - elseif ($row['field_type'] == 'textarea') |
|
| 954 | - // Allow for newlines at least |
|
| 986 | + if ($row['bbc']) { |
|
| 987 | + $output_html = parse_bbc($output_html); |
|
| 988 | + } elseif ($row['field_type'] == 'textarea') { |
|
| 989 | + // Allow for newlines at least |
|
| 955 | 990 | $output_html = strtr($output_html, array("\n" => '<br>')); |
| 991 | + } |
|
| 956 | 992 | |
| 957 | 993 | // Enclosing the user input within some other text? |
| 958 | - if (!empty($row['enclose']) && !empty($output_html)) |
|
| 959 | - $output_html = strtr($row['enclose'], array( |
|
| 994 | + if (!empty($row['enclose']) && !empty($output_html)) { |
|
| 995 | + $output_html = strtr($row['enclose'], array( |
|
| 960 | 996 | '{SCRIPTURL}' => $scripturl, |
| 961 | 997 | '{IMAGES_URL}' => $settings['images_url'], |
| 962 | 998 | '{DEFAULT_IMAGES_URL}' => $settings['default_images_url'], |
| 963 | 999 | '{INPUT}' => un_htmlspecialchars($output_html), |
| 964 | 1000 | )); |
| 1001 | + } |
|
| 965 | 1002 | |
| 966 | 1003 | $context['custom_fields'][] = array( |
| 967 | 1004 | 'name' => $row['field_name'], |
@@ -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 | * Update some basic statistics. |
@@ -122,10 +123,11 @@ discard block |
||
| 122 | 123 | $smcFunc['db_free_result']($result); |
| 123 | 124 | |
| 124 | 125 | // Add this to the number of unapproved members |
| 125 | - if (!empty($changes['unapprovedMembers'])) |
|
| 126 | - $changes['unapprovedMembers'] += $coppa_approvals; |
|
| 127 | - else |
|
| 128 | - $changes['unapprovedMembers'] = $coppa_approvals; |
|
| 126 | + if (!empty($changes['unapprovedMembers'])) { |
|
| 127 | + $changes['unapprovedMembers'] += $coppa_approvals; |
|
| 128 | + } else { |
|
| 129 | + $changes['unapprovedMembers'] = $coppa_approvals; |
|
| 130 | + } |
|
| 129 | 131 | } |
| 130 | 132 | } |
| 131 | 133 | } |
@@ -133,9 +135,9 @@ discard block |
||
| 133 | 135 | break; |
| 134 | 136 | |
| 135 | 137 | case 'message': |
| 136 | - if ($parameter1 === true && $parameter2 !== null) |
|
| 137 | - updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true); |
|
| 138 | - else |
|
| 138 | + if ($parameter1 === true && $parameter2 !== null) { |
|
| 139 | + updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true); |
|
| 140 | + } else |
|
| 139 | 141 | { |
| 140 | 142 | // SUM and MAX on a smaller table is better for InnoDB tables. |
| 141 | 143 | $result = $smcFunc['db_query']('', ' |
@@ -175,23 +177,25 @@ discard block |
||
| 175 | 177 | $parameter2 = text2words($parameter2); |
| 176 | 178 | |
| 177 | 179 | $inserts = array(); |
| 178 | - foreach ($parameter2 as $word) |
|
| 179 | - $inserts[] = array($word, $parameter1); |
|
| 180 | + foreach ($parameter2 as $word) { |
|
| 181 | + $inserts[] = array($word, $parameter1); |
|
| 182 | + } |
|
| 180 | 183 | |
| 181 | - if (!empty($inserts)) |
|
| 182 | - $smcFunc['db_insert']('ignore', |
|
| 184 | + if (!empty($inserts)) { |
|
| 185 | + $smcFunc['db_insert']('ignore', |
|
| 183 | 186 | '{db_prefix}log_search_subjects', |
| 184 | 187 | array('word' => 'string', 'id_topic' => 'int'), |
| 185 | 188 | $inserts, |
| 186 | 189 | array('word', 'id_topic') |
| 187 | 190 | ); |
| 191 | + } |
|
| 188 | 192 | } |
| 189 | 193 | break; |
| 190 | 194 | |
| 191 | 195 | case 'topic': |
| 192 | - if ($parameter1 === true) |
|
| 193 | - updateSettings(array('totalTopics' => true), true); |
|
| 194 | - else |
|
| 196 | + if ($parameter1 === true) { |
|
| 197 | + updateSettings(array('totalTopics' => true), true); |
|
| 198 | + } else |
|
| 195 | 199 | { |
| 196 | 200 | // Get the number of topics - a SUM is better for InnoDB tables. |
| 197 | 201 | // We also ignore the recycle bin here because there will probably be a bunch of one-post topics there. |
@@ -212,8 +216,9 @@ discard block |
||
| 212 | 216 | |
| 213 | 217 | case 'postgroups': |
| 214 | 218 | // Parameter two is the updated columns: we should check to see if we base groups off any of these. |
| 215 | - if ($parameter2 !== null && !in_array('posts', $parameter2)) |
|
| 216 | - return; |
|
| 219 | + if ($parameter2 !== null && !in_array('posts', $parameter2)) { |
|
| 220 | + return; |
|
| 221 | + } |
|
| 217 | 222 | |
| 218 | 223 | $postgroups = cache_get_data('updateStats:postgroups', 360); |
| 219 | 224 | if ($postgroups == null || $parameter1 == null) |
@@ -228,8 +233,9 @@ discard block |
||
| 228 | 233 | ) |
| 229 | 234 | ); |
| 230 | 235 | $postgroups = array(); |
| 231 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 232 | - $postgroups[$row['id_group']] = $row['min_posts']; |
|
| 236 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 237 | + $postgroups[$row['id_group']] = $row['min_posts']; |
|
| 238 | + } |
|
| 233 | 239 | $smcFunc['db_free_result']($request); |
| 234 | 240 | |
| 235 | 241 | // Sort them this way because if it's done with MySQL it causes a filesort :(. |
@@ -239,8 +245,9 @@ discard block |
||
| 239 | 245 | } |
| 240 | 246 | |
| 241 | 247 | // Oh great, they've screwed their post groups. |
| 242 | - if (empty($postgroups)) |
|
| 243 | - return; |
|
| 248 | + if (empty($postgroups)) { |
|
| 249 | + return; |
|
| 250 | + } |
|
| 244 | 251 | |
| 245 | 252 | // Set all membergroups from most posts to least posts. |
| 246 | 253 | $conditions = ''; |
@@ -298,10 +305,9 @@ discard block |
||
| 298 | 305 | { |
| 299 | 306 | $condition = 'id_member IN ({array_int:members})'; |
| 300 | 307 | $parameters['members'] = $members; |
| 301 | - } |
|
| 302 | - elseif ($members === null) |
|
| 303 | - $condition = '1=1'; |
|
| 304 | - else |
|
| 308 | + } elseif ($members === null) { |
|
| 309 | + $condition = '1=1'; |
|
| 310 | + } else |
|
| 305 | 311 | { |
| 306 | 312 | $condition = 'id_member = {int:member}'; |
| 307 | 313 | $parameters['member'] = $members; |
@@ -341,9 +347,9 @@ discard block |
||
| 341 | 347 | if (count($vars_to_integrate) != 0) |
| 342 | 348 | { |
| 343 | 349 | // Fetch a list of member_names if necessary |
| 344 | - if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) |
|
| 345 | - $member_names = array($user_info['username']); |
|
| 346 | - else |
|
| 350 | + if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) { |
|
| 351 | + $member_names = array($user_info['username']); |
|
| 352 | + } else |
|
| 347 | 353 | { |
| 348 | 354 | $member_names = array(); |
| 349 | 355 | $request = $smcFunc['db_query']('', ' |
@@ -352,14 +358,16 @@ discard block |
||
| 352 | 358 | WHERE ' . $condition, |
| 353 | 359 | $parameters |
| 354 | 360 | ); |
| 355 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 356 | - $member_names[] = $row['member_name']; |
|
| 361 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 362 | + $member_names[] = $row['member_name']; |
|
| 363 | + } |
|
| 357 | 364 | $smcFunc['db_free_result']($request); |
| 358 | 365 | } |
| 359 | 366 | |
| 360 | - if (!empty($member_names)) |
|
| 361 | - foreach ($vars_to_integrate as $var) |
|
| 367 | + if (!empty($member_names)) { |
|
| 368 | + foreach ($vars_to_integrate as $var) |
|
| 362 | 369 | call_integration_hook('integrate_change_member_data', array($member_names, $var, &$data[$var], &$knownInts, &$knownFloats)); |
| 370 | + } |
|
| 363 | 371 | } |
| 364 | 372 | } |
| 365 | 373 | |
@@ -367,16 +375,17 @@ discard block |
||
| 367 | 375 | foreach ($data as $var => $val) |
| 368 | 376 | { |
| 369 | 377 | $type = 'string'; |
| 370 | - if (in_array($var, $knownInts)) |
|
| 371 | - $type = 'int'; |
|
| 372 | - elseif (in_array($var, $knownFloats)) |
|
| 373 | - $type = 'float'; |
|
| 374 | - elseif ($var == 'birthdate') |
|
| 375 | - $type = 'date'; |
|
| 376 | - elseif ($var == 'member_ip') |
|
| 377 | - $type = 'inet'; |
|
| 378 | - elseif ($var == 'member_ip2') |
|
| 379 | - $type = 'inet'; |
|
| 378 | + if (in_array($var, $knownInts)) { |
|
| 379 | + $type = 'int'; |
|
| 380 | + } elseif (in_array($var, $knownFloats)) { |
|
| 381 | + $type = 'float'; |
|
| 382 | + } elseif ($var == 'birthdate') { |
|
| 383 | + $type = 'date'; |
|
| 384 | + } elseif ($var == 'member_ip') { |
|
| 385 | + $type = 'inet'; |
|
| 386 | + } elseif ($var == 'member_ip2') { |
|
| 387 | + $type = 'inet'; |
|
| 388 | + } |
|
| 380 | 389 | |
| 381 | 390 | // Doing an increment? |
| 382 | 391 | if ($var == 'alerts' && ($val === '+' || $val === '-')) |
@@ -385,18 +394,17 @@ discard block |
||
| 385 | 394 | if (is_array($members)) |
| 386 | 395 | { |
| 387 | 396 | $val = 'CASE '; |
| 388 | - foreach ($members as $k => $v) |
|
| 389 | - $val .= 'WHEN id_member = ' . $v . ' THEN '. count(fetch_alerts($v, false, 0, array(), false)) . ' '; |
|
| 397 | + foreach ($members as $k => $v) { |
|
| 398 | + $val .= 'WHEN id_member = ' . $v . ' THEN '. count(fetch_alerts($v, false, 0, array(), false)) . ' '; |
|
| 399 | + } |
|
| 390 | 400 | $val = $val . ' END'; |
| 391 | 401 | $type = 'raw'; |
| 392 | - } |
|
| 393 | - else |
|
| 402 | + } else |
|
| 394 | 403 | { |
| 395 | 404 | $blub = fetch_alerts($members, false, 0, array(), false); |
| 396 | 405 | $val = count($blub); |
| 397 | 406 | } |
| 398 | - } |
|
| 399 | - else if ($type == 'int' && ($val === '+' || $val === '-')) |
|
| 407 | + } else if ($type == 'int' && ($val === '+' || $val === '-')) |
|
| 400 | 408 | { |
| 401 | 409 | $val = $var . ' ' . $val . ' 1'; |
| 402 | 410 | $type = 'raw'; |
@@ -407,8 +415,9 @@ discard block |
||
| 407 | 415 | { |
| 408 | 416 | if (preg_match('~^' . $var . ' (\+ |- |\+ -)([\d]+)~', $val, $match)) |
| 409 | 417 | { |
| 410 | - if ($match[1] != '+ ') |
|
| 411 | - $val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END'; |
|
| 418 | + if ($match[1] != '+ ') { |
|
| 419 | + $val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END'; |
|
| 420 | + } |
|
| 412 | 421 | $type = 'raw'; |
| 413 | 422 | } |
| 414 | 423 | } |
@@ -429,8 +438,9 @@ discard block |
||
| 429 | 438 | // Clear any caching? |
| 430 | 439 | if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && !empty($members)) |
| 431 | 440 | { |
| 432 | - if (!is_array($members)) |
|
| 433 | - $members = array($members); |
|
| 441 | + if (!is_array($members)) { |
|
| 442 | + $members = array($members); |
|
| 443 | + } |
|
| 434 | 444 | |
| 435 | 445 | foreach ($members as $member) |
| 436 | 446 | { |
@@ -463,29 +473,32 @@ discard block |
||
| 463 | 473 | { |
| 464 | 474 | global $modSettings, $smcFunc; |
| 465 | 475 | |
| 466 | - if (empty($changeArray) || !is_array($changeArray)) |
|
| 467 | - return; |
|
| 476 | + if (empty($changeArray) || !is_array($changeArray)) { |
|
| 477 | + return; |
|
| 478 | + } |
|
| 468 | 479 | |
| 469 | 480 | $toRemove = array(); |
| 470 | 481 | |
| 471 | 482 | // Go check if there is any setting to be removed. |
| 472 | - foreach ($changeArray as $k => $v) |
|
| 473 | - if ($v === null) |
|
| 483 | + foreach ($changeArray as $k => $v) { |
|
| 484 | + if ($v === null) |
|
| 474 | 485 | { |
| 475 | 486 | // Found some, remove them from the original array and add them to ours. |
| 476 | 487 | unset($changeArray[$k]); |
| 488 | + } |
|
| 477 | 489 | $toRemove[] = $k; |
| 478 | 490 | } |
| 479 | 491 | |
| 480 | 492 | // Proceed with the deletion. |
| 481 | - if (!empty($toRemove)) |
|
| 482 | - $smcFunc['db_query']('', ' |
|
| 493 | + if (!empty($toRemove)) { |
|
| 494 | + $smcFunc['db_query']('', ' |
|
| 483 | 495 | DELETE FROM {db_prefix}settings |
| 484 | 496 | WHERE variable IN ({array_string:remove})', |
| 485 | 497 | array( |
| 486 | 498 | 'remove' => $toRemove, |
| 487 | 499 | ) |
| 488 | 500 | ); |
| 501 | + } |
|
| 489 | 502 | |
| 490 | 503 | // In some cases, this may be better and faster, but for large sets we don't want so many UPDATEs. |
| 491 | 504 | if ($update) |
@@ -514,19 +527,22 @@ discard block |
||
| 514 | 527 | foreach ($changeArray as $variable => $value) |
| 515 | 528 | { |
| 516 | 529 | // Don't bother if it's already like that ;). |
| 517 | - if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) |
|
| 518 | - continue; |
|
| 530 | + if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) { |
|
| 531 | + continue; |
|
| 532 | + } |
|
| 519 | 533 | // If the variable isn't set, but would only be set to nothing'ness, then don't bother setting it. |
| 520 | - elseif (!isset($modSettings[$variable]) && empty($value)) |
|
| 521 | - continue; |
|
| 534 | + elseif (!isset($modSettings[$variable]) && empty($value)) { |
|
| 535 | + continue; |
|
| 536 | + } |
|
| 522 | 537 | |
| 523 | 538 | $replaceArray[] = array($variable, $value); |
| 524 | 539 | |
| 525 | 540 | $modSettings[$variable] = $value; |
| 526 | 541 | } |
| 527 | 542 | |
| 528 | - if (empty($replaceArray)) |
|
| 529 | - return; |
|
| 543 | + if (empty($replaceArray)) { |
|
| 544 | + return; |
|
| 545 | + } |
|
| 530 | 546 | |
| 531 | 547 | $smcFunc['db_insert']('replace', |
| 532 | 548 | '{db_prefix}settings', |
@@ -572,14 +588,17 @@ discard block |
||
| 572 | 588 | $start_invalid = $start < 0; |
| 573 | 589 | |
| 574 | 590 | // Make sure $start is a proper variable - not less than 0. |
| 575 | - if ($start_invalid) |
|
| 576 | - $start = 0; |
|
| 591 | + if ($start_invalid) { |
|
| 592 | + $start = 0; |
|
| 593 | + } |
|
| 577 | 594 | // Not greater than the upper bound. |
| 578 | - elseif ($start >= $max_value) |
|
| 579 | - $start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page))); |
|
| 595 | + elseif ($start >= $max_value) { |
|
| 596 | + $start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page))); |
|
| 597 | + } |
|
| 580 | 598 | // And it has to be a multiple of $num_per_page! |
| 581 | - else |
|
| 582 | - $start = max(0, (int) $start - ((int) $start % (int) $num_per_page)); |
|
| 599 | + else { |
|
| 600 | + $start = max(0, (int) $start - ((int) $start % (int) $num_per_page)); |
|
| 601 | + } |
|
| 583 | 602 | |
| 584 | 603 | $context['current_page'] = $start / $num_per_page; |
| 585 | 604 | |
@@ -609,77 +628,87 @@ discard block |
||
| 609 | 628 | |
| 610 | 629 | // Show all the pages. |
| 611 | 630 | $display_page = 1; |
| 612 | - for ($counter = 0; $counter < $max_value; $counter += $num_per_page) |
|
| 613 | - $pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++); |
|
| 631 | + for ($counter = 0; $counter < $max_value; $counter += $num_per_page) { |
|
| 632 | + $pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++); |
|
| 633 | + } |
|
| 614 | 634 | |
| 615 | 635 | // Show the right arrow. |
| 616 | 636 | $display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page); |
| 617 | - if ($start != $counter - $max_value && !$start_invalid) |
|
| 618 | - $pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']); |
|
| 619 | - } |
|
| 620 | - else |
|
| 637 | + if ($start != $counter - $max_value && !$start_invalid) { |
|
| 638 | + $pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']); |
|
| 639 | + } |
|
| 640 | + } else |
|
| 621 | 641 | { |
| 622 | 642 | // If they didn't enter an odd value, pretend they did. |
| 623 | 643 | $PageContiguous = (int) ($modSettings['compactTopicPagesContiguous'] - ($modSettings['compactTopicPagesContiguous'] % 2)) / 2; |
| 624 | 644 | |
| 625 | 645 | // Show the "prev page" link. (>prev page< 1 ... 6 7 [8] 9 10 ... 15 next page) |
| 626 | - if (!empty($start) && $show_prevnext) |
|
| 627 | - $pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']); |
|
| 628 | - else |
|
| 629 | - $pageindex .= ''; |
|
| 646 | + if (!empty($start) && $show_prevnext) { |
|
| 647 | + $pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']); |
|
| 648 | + } else { |
|
| 649 | + $pageindex .= ''; |
|
| 650 | + } |
|
| 630 | 651 | |
| 631 | 652 | // Show the first page. (prev page >1< ... 6 7 [8] 9 10 ... 15) |
| 632 | - if ($start > $num_per_page * $PageContiguous) |
|
| 633 | - $pageindex .= sprintf($base_link, 0, '1'); |
|
| 653 | + if ($start > $num_per_page * $PageContiguous) { |
|
| 654 | + $pageindex .= sprintf($base_link, 0, '1'); |
|
| 655 | + } |
|
| 634 | 656 | |
| 635 | 657 | // Show the ... after the first page. (prev page 1 >...< 6 7 [8] 9 10 ... 15 next page) |
| 636 | - if ($start > $num_per_page * ($PageContiguous + 1)) |
|
| 637 | - $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
| 658 | + if ($start > $num_per_page * ($PageContiguous + 1)) { |
|
| 659 | + $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
| 638 | 660 | '{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)), |
| 639 | 661 | '{FIRST_PAGE}' => $num_per_page, |
| 640 | 662 | '{LAST_PAGE}' => $start - $num_per_page * $PageContiguous, |
| 641 | 663 | '{PER_PAGE}' => $num_per_page, |
| 642 | 664 | )); |
| 665 | + } |
|
| 643 | 666 | |
| 644 | 667 | // Show the pages before the current one. (prev page 1 ... >6 7< [8] 9 10 ... 15 next page) |
| 645 | - for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) |
|
| 646 | - if ($start >= $num_per_page * $nCont) |
|
| 668 | + for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) { |
|
| 669 | + if ($start >= $num_per_page * $nCont) |
|
| 647 | 670 | { |
| 648 | 671 | $tmpStart = $start - $num_per_page * $nCont; |
| 672 | + } |
|
| 649 | 673 | $pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1); |
| 650 | 674 | } |
| 651 | 675 | |
| 652 | 676 | // Show the current page. (prev page 1 ... 6 7 >[8]< 9 10 ... 15 next page) |
| 653 | - if (!$start_invalid) |
|
| 654 | - $pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1); |
|
| 655 | - else |
|
| 656 | - $pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1); |
|
| 677 | + if (!$start_invalid) { |
|
| 678 | + $pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1); |
|
| 679 | + } else { |
|
| 680 | + $pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1); |
|
| 681 | + } |
|
| 657 | 682 | |
| 658 | 683 | // Show the pages after the current one... (prev page 1 ... 6 7 [8] >9 10< ... 15 next page) |
| 659 | 684 | $tmpMaxPages = (int) (($max_value - 1) / $num_per_page) * $num_per_page; |
| 660 | - for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) |
|
| 661 | - if ($start + $num_per_page * $nCont <= $tmpMaxPages) |
|
| 685 | + for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) { |
|
| 686 | + if ($start + $num_per_page * $nCont <= $tmpMaxPages) |
|
| 662 | 687 | { |
| 663 | 688 | $tmpStart = $start + $num_per_page * $nCont; |
| 689 | + } |
|
| 664 | 690 | $pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1); |
| 665 | 691 | } |
| 666 | 692 | |
| 667 | 693 | // Show the '...' part near the end. (prev page 1 ... 6 7 [8] 9 10 >...< 15 next page) |
| 668 | - if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) |
|
| 669 | - $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
| 694 | + if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) { |
|
| 695 | + $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
| 670 | 696 | '{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)), |
| 671 | 697 | '{FIRST_PAGE}' => $start + $num_per_page * ($PageContiguous + 1), |
| 672 | 698 | '{LAST_PAGE}' => $tmpMaxPages, |
| 673 | 699 | '{PER_PAGE}' => $num_per_page, |
| 674 | 700 | )); |
| 701 | + } |
|
| 675 | 702 | |
| 676 | 703 | // Show the last number in the list. (prev page 1 ... 6 7 [8] 9 10 ... >15< next page) |
| 677 | - if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) |
|
| 678 | - $pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1); |
|
| 704 | + if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) { |
|
| 705 | + $pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1); |
|
| 706 | + } |
|
| 679 | 707 | |
| 680 | 708 | // Show the "next page" link. (prev page 1 ... 6 7 [8] 9 10 ... 15 >next page<) |
| 681 | - if ($start != $tmpMaxPages && $show_prevnext) |
|
| 682 | - $pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']); |
|
| 709 | + if ($start != $tmpMaxPages && $show_prevnext) { |
|
| 710 | + $pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']); |
|
| 711 | + } |
|
| 683 | 712 | } |
| 684 | 713 | $pageindex .= $settings['page_index']['extra_after']; |
| 685 | 714 | |
@@ -705,8 +734,9 @@ discard block |
||
| 705 | 734 | if ($decimal_separator === null) |
| 706 | 735 | { |
| 707 | 736 | // Not set for whatever reason? |
| 708 | - if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) |
|
| 709 | - return $number; |
|
| 737 | + if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) { |
|
| 738 | + return $number; |
|
| 739 | + } |
|
| 710 | 740 | |
| 711 | 741 | // Cache these each load... |
| 712 | 742 | $thousands_separator = $matches[1]; |
@@ -740,17 +770,20 @@ discard block |
||
| 740 | 770 | static $unsupportedFormats, $finalizedFormats; |
| 741 | 771 | |
| 742 | 772 | // Offset the time. |
| 743 | - if (!$offset_type) |
|
| 744 | - $time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600; |
|
| 773 | + if (!$offset_type) { |
|
| 774 | + $time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600; |
|
| 775 | + } |
|
| 745 | 776 | // Just the forum offset? |
| 746 | - elseif ($offset_type == 'forum') |
|
| 747 | - $time = $log_time + $modSettings['time_offset'] * 3600; |
|
| 748 | - else |
|
| 749 | - $time = $log_time; |
|
| 777 | + elseif ($offset_type == 'forum') { |
|
| 778 | + $time = $log_time + $modSettings['time_offset'] * 3600; |
|
| 779 | + } else { |
|
| 780 | + $time = $log_time; |
|
| 781 | + } |
|
| 750 | 782 | |
| 751 | 783 | // We can't have a negative date (on Windows, at least.) |
| 752 | - if ($log_time < 0) |
|
| 753 | - $log_time = 0; |
|
| 784 | + if ($log_time < 0) { |
|
| 785 | + $log_time = 0; |
|
| 786 | + } |
|
| 754 | 787 | |
| 755 | 788 | // Today and Yesterday? |
| 756 | 789 | if ($modSettings['todayMod'] >= 1 && $show_today === true) |
@@ -767,24 +800,27 @@ discard block |
||
| 767 | 800 | { |
| 768 | 801 | $h = strpos($user_info['time_format'], '%l') === false ? '%I' : '%l'; |
| 769 | 802 | $today_fmt = $h . ':%M' . $s . ' %p'; |
| 803 | + } else { |
|
| 804 | + $today_fmt = '%H:%M' . $s; |
|
| 770 | 805 | } |
| 771 | - else |
|
| 772 | - $today_fmt = '%H:%M' . $s; |
|
| 773 | 806 | |
| 774 | 807 | // Same day of the year, same year.... Today! |
| 775 | - if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) |
|
| 776 | - return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type); |
|
| 808 | + if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) { |
|
| 809 | + return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type); |
|
| 810 | + } |
|
| 777 | 811 | |
| 778 | 812 | // Day-of-year is one less and same year, or it's the first of the year and that's the last of the year... |
| 779 | - if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31)) |
|
| 780 | - return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type); |
|
| 813 | + if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31)) { |
|
| 814 | + return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type); |
|
| 815 | + } |
|
| 781 | 816 | } |
| 782 | 817 | |
| 783 | 818 | $str = !is_bool($show_today) ? $show_today : $user_info['time_format']; |
| 784 | 819 | |
| 785 | 820 | // Use the cached formats if available |
| 786 | - if (is_null($finalizedFormats)) |
|
| 787 | - $finalizedFormats = (array) cache_get_data('timeformatstrings', 86400); |
|
| 821 | + if (is_null($finalizedFormats)) { |
|
| 822 | + $finalizedFormats = (array) cache_get_data('timeformatstrings', 86400); |
|
| 823 | + } |
|
| 788 | 824 | |
| 789 | 825 | // Make a supported version for this format if we don't already have one |
| 790 | 826 | if (empty($finalizedFormats[$str])) |
@@ -813,8 +849,9 @@ discard block |
||
| 813 | 849 | ); |
| 814 | 850 | |
| 815 | 851 | // No need to do this part again if we already did it once |
| 816 | - if (is_null($unsupportedFormats)) |
|
| 817 | - $unsupportedFormats = (array) cache_get_data('unsupportedtimeformats', 86400); |
|
| 852 | + if (is_null($unsupportedFormats)) { |
|
| 853 | + $unsupportedFormats = (array) cache_get_data('unsupportedtimeformats', 86400); |
|
| 854 | + } |
|
| 818 | 855 | if (empty($unsupportedFormats)) |
| 819 | 856 | { |
| 820 | 857 | foreach($strftimeFormatSubstitutions as $format => $substitution) |
@@ -823,20 +860,23 @@ discard block |
||
| 823 | 860 | |
| 824 | 861 | // Windows will return false for unsupported formats |
| 825 | 862 | // Other operating systems return the format string as a literal |
| 826 | - if ($value === false || $value === $format) |
|
| 827 | - $unsupportedFormats[] = $format; |
|
| 863 | + if ($value === false || $value === $format) { |
|
| 864 | + $unsupportedFormats[] = $format; |
|
| 865 | + } |
|
| 828 | 866 | } |
| 829 | 867 | cache_put_data('unsupportedtimeformats', $unsupportedFormats, 86400); |
| 830 | 868 | } |
| 831 | 869 | |
| 832 | 870 | // Windows needs extra help if $timeformat contains something completely invalid, e.g. '%Q' |
| 833 | - if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') |
|
| 834 | - $timeformat = preg_replace('~%(?!' . implode('|', array_keys($strftimeFormatSubstitutions)) . ')~', '%', $timeformat); |
|
| 871 | + if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') { |
|
| 872 | + $timeformat = preg_replace('~%(?!' . implode('|', array_keys($strftimeFormatSubstitutions)) . ')~', '%', $timeformat); |
|
| 873 | + } |
|
| 835 | 874 | |
| 836 | 875 | // Substitute unsupported formats with supported ones |
| 837 | - if (!empty($unsupportedFormats)) |
|
| 838 | - while (preg_match('~%(' . implode('|', $unsupportedFormats) . ')~', $timeformat, $matches)) |
|
| 876 | + if (!empty($unsupportedFormats)) { |
|
| 877 | + while (preg_match('~%(' . implode('|', $unsupportedFormats) . ')~', $timeformat, $matches)) |
|
| 839 | 878 | $timeformat = str_replace($matches[0], $strftimeFormatSubstitutions[$matches[1]], $timeformat); |
| 879 | + } |
|
| 840 | 880 | |
| 841 | 881 | // Remember this so we don't need to do it again |
| 842 | 882 | $finalizedFormats[$str] = $timeformat; |
@@ -845,33 +885,39 @@ discard block |
||
| 845 | 885 | |
| 846 | 886 | $str = $finalizedFormats[$str]; |
| 847 | 887 | |
| 848 | - if (!isset($locale_cache)) |
|
| 849 | - $locale_cache = setlocale(LC_TIME, $txt['lang_locale']); |
|
| 888 | + if (!isset($locale_cache)) { |
|
| 889 | + $locale_cache = setlocale(LC_TIME, $txt['lang_locale']); |
|
| 890 | + } |
|
| 850 | 891 | |
| 851 | 892 | if ($locale_cache !== false) |
| 852 | 893 | { |
| 853 | 894 | // Check if another process changed the locale |
| 854 | - if ($process_safe === true && setlocale(LC_TIME, '0') != $locale_cache) |
|
| 855 | - setlocale(LC_TIME, $txt['lang_locale']); |
|
| 895 | + if ($process_safe === true && setlocale(LC_TIME, '0') != $locale_cache) { |
|
| 896 | + setlocale(LC_TIME, $txt['lang_locale']); |
|
| 897 | + } |
|
| 856 | 898 | |
| 857 | - if (!isset($non_twelve_hour)) |
|
| 858 | - $non_twelve_hour = trim(strftime('%p')) === ''; |
|
| 859 | - if ($non_twelve_hour && strpos($str, '%p') !== false) |
|
| 860 | - $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
| 899 | + if (!isset($non_twelve_hour)) { |
|
| 900 | + $non_twelve_hour = trim(strftime('%p')) === ''; |
|
| 901 | + } |
|
| 902 | + if ($non_twelve_hour && strpos($str, '%p') !== false) { |
|
| 903 | + $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
| 904 | + } |
|
| 861 | 905 | |
| 862 | - foreach (array('%a', '%A', '%b', '%B') as $token) |
|
| 863 | - if (strpos($str, $token) !== false) |
|
| 906 | + foreach (array('%a', '%A', '%b', '%B') as $token) { |
|
| 907 | + if (strpos($str, $token) !== false) |
|
| 864 | 908 | $str = str_replace($token, strftime($token, $time), $str); |
| 865 | - } |
|
| 866 | - else |
|
| 909 | + } |
|
| 910 | + } else |
|
| 867 | 911 | { |
| 868 | 912 | // Do-it-yourself time localization. Fun. |
| 869 | - foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) |
|
| 870 | - if (strpos($str, $token) !== false) |
|
| 913 | + foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) { |
|
| 914 | + if (strpos($str, $token) !== false) |
|
| 871 | 915 | $str = str_replace($token, $txt[$text_label][(int) strftime($token === '%a' || $token === '%A' ? '%w' : '%m', $time)], $str); |
| 916 | + } |
|
| 872 | 917 | |
| 873 | - if (strpos($str, '%p') !== false) |
|
| 874 | - $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
| 918 | + if (strpos($str, '%p') !== false) { |
|
| 919 | + $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
| 920 | + } |
|
| 875 | 921 | } |
| 876 | 922 | |
| 877 | 923 | // Format the time and then restore any literal percent characters |
@@ -894,16 +940,19 @@ discard block |
||
| 894 | 940 | static $translation = array(); |
| 895 | 941 | |
| 896 | 942 | // Determine the character set... Default to UTF-8 |
| 897 | - if (empty($context['character_set'])) |
|
| 898 | - $charset = 'UTF-8'; |
|
| 943 | + if (empty($context['character_set'])) { |
|
| 944 | + $charset = 'UTF-8'; |
|
| 945 | + } |
|
| 899 | 946 | // Use ISO-8859-1 in place of non-supported ISO-8859 charsets... |
| 900 | - elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) |
|
| 901 | - $charset = 'ISO-8859-1'; |
|
| 902 | - else |
|
| 903 | - $charset = $context['character_set']; |
|
| 947 | + elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) { |
|
| 948 | + $charset = 'ISO-8859-1'; |
|
| 949 | + } else { |
|
| 950 | + $charset = $context['character_set']; |
|
| 951 | + } |
|
| 904 | 952 | |
| 905 | - if (empty($translation)) |
|
| 906 | - $translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array(''' => '\'', ''' => '\'', ' ' => ' '); |
|
| 953 | + if (empty($translation)) { |
|
| 954 | + $translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array(''' => '\'', ''' => '\'', ' ' => ' '); |
|
| 955 | + } |
|
| 907 | 956 | |
| 908 | 957 | return strtr($string, $translation); |
| 909 | 958 | } |
@@ -925,8 +974,9 @@ discard block |
||
| 925 | 974 | global $smcFunc; |
| 926 | 975 | |
| 927 | 976 | // It was already short enough! |
| 928 | - if ($smcFunc['strlen']($subject) <= $len) |
|
| 929 | - return $subject; |
|
| 977 | + if ($smcFunc['strlen']($subject) <= $len) { |
|
| 978 | + return $subject; |
|
| 979 | + } |
|
| 930 | 980 | |
| 931 | 981 | // Shorten it by the length it was too long, and strip off junk from the end. |
| 932 | 982 | return $smcFunc['substr']($subject, 0, $len) . '...'; |
@@ -945,10 +995,11 @@ discard block |
||
| 945 | 995 | { |
| 946 | 996 | global $user_info, $modSettings; |
| 947 | 997 | |
| 948 | - if ($timestamp === null) |
|
| 949 | - $timestamp = time(); |
|
| 950 | - elseif ($timestamp == 0) |
|
| 951 | - return 0; |
|
| 998 | + if ($timestamp === null) { |
|
| 999 | + $timestamp = time(); |
|
| 1000 | + } elseif ($timestamp == 0) { |
|
| 1001 | + return 0; |
|
| 1002 | + } |
|
| 952 | 1003 | |
| 953 | 1004 | return $timestamp + ($modSettings['time_offset'] + ($use_user_offset ? $user_info['time_offset'] : 0)) * 3600; |
| 954 | 1005 | } |
@@ -977,8 +1028,9 @@ discard block |
||
| 977 | 1028 | $array[$i] = $array[$j]; |
| 978 | 1029 | $array[$j] = $temp; |
| 979 | 1030 | |
| 980 | - for ($i = 1; $p[$i] == 0; $i++) |
|
| 981 | - $p[$i] = 1; |
|
| 1031 | + for ($i = 1; $p[$i] == 0; $i++) { |
|
| 1032 | + $p[$i] = 1; |
|
| 1033 | + } |
|
| 982 | 1034 | |
| 983 | 1035 | $orders[] = $array; |
| 984 | 1036 | } |
@@ -1010,12 +1062,14 @@ discard block |
||
| 1010 | 1062 | static $disabled; |
| 1011 | 1063 | |
| 1012 | 1064 | // Don't waste cycles |
| 1013 | - if ($message === '') |
|
| 1014 | - return ''; |
|
| 1065 | + if ($message === '') { |
|
| 1066 | + return ''; |
|
| 1067 | + } |
|
| 1015 | 1068 | |
| 1016 | 1069 | // Just in case it wasn't determined yet whether UTF-8 is enabled. |
| 1017 | - if (!isset($context['utf8'])) |
|
| 1018 | - $context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8'; |
|
| 1070 | + if (!isset($context['utf8'])) { |
|
| 1071 | + $context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8'; |
|
| 1072 | + } |
|
| 1019 | 1073 | |
| 1020 | 1074 | // Clean up any cut/paste issues we may have |
| 1021 | 1075 | $message = sanitizeMSCutPaste($message); |
@@ -1027,13 +1081,15 @@ discard block |
||
| 1027 | 1081 | return $message; |
| 1028 | 1082 | } |
| 1029 | 1083 | |
| 1030 | - if ($smileys !== null && ($smileys == '1' || $smileys == '0')) |
|
| 1031 | - $smileys = (bool) $smileys; |
|
| 1084 | + if ($smileys !== null && ($smileys == '1' || $smileys == '0')) { |
|
| 1085 | + $smileys = (bool) $smileys; |
|
| 1086 | + } |
|
| 1032 | 1087 | |
| 1033 | 1088 | if (empty($modSettings['enableBBC']) && $message !== false) |
| 1034 | 1089 | { |
| 1035 | - if ($smileys === true) |
|
| 1036 | - parsesmileys($message); |
|
| 1090 | + if ($smileys === true) { |
|
| 1091 | + parsesmileys($message); |
|
| 1092 | + } |
|
| 1037 | 1093 | |
| 1038 | 1094 | return $message; |
| 1039 | 1095 | } |
@@ -1046,8 +1102,9 @@ discard block |
||
| 1046 | 1102 | } |
| 1047 | 1103 | |
| 1048 | 1104 | // Ensure $modSettings['tld_regex'] contains a valid regex for the autolinker |
| 1049 | - if (!empty($modSettings['autoLinkUrls'])) |
|
| 1050 | - set_tld_regex(); |
|
| 1105 | + if (!empty($modSettings['autoLinkUrls'])) { |
|
| 1106 | + set_tld_regex(); |
|
| 1107 | + } |
|
| 1051 | 1108 | |
| 1052 | 1109 | // Allow mods access before entering the main parse_bbc loop |
| 1053 | 1110 | call_integration_hook('integrate_pre_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags)); |
@@ -1061,12 +1118,14 @@ discard block |
||
| 1061 | 1118 | |
| 1062 | 1119 | $temp = explode(',', strtolower($modSettings['disabledBBC'])); |
| 1063 | 1120 | |
| 1064 | - foreach ($temp as $tag) |
|
| 1065 | - $disabled[trim($tag)] = true; |
|
| 1121 | + foreach ($temp as $tag) { |
|
| 1122 | + $disabled[trim($tag)] = true; |
|
| 1123 | + } |
|
| 1066 | 1124 | } |
| 1067 | 1125 | |
| 1068 | - if (empty($modSettings['enableEmbeddedFlash'])) |
|
| 1069 | - $disabled['flash'] = true; |
|
| 1126 | + if (empty($modSettings['enableEmbeddedFlash'])) { |
|
| 1127 | + $disabled['flash'] = true; |
|
| 1128 | + } |
|
| 1070 | 1129 | |
| 1071 | 1130 | /* The following bbc are formatted as an array, with keys as follows: |
| 1072 | 1131 | |
@@ -1187,8 +1246,9 @@ discard block |
||
| 1187 | 1246 | $returnContext = ''; |
| 1188 | 1247 | |
| 1189 | 1248 | // BBC or the entire attachments feature is disabled |
| 1190 | - if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) |
|
| 1191 | - return $data; |
|
| 1249 | + if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) { |
|
| 1250 | + return $data; |
|
| 1251 | + } |
|
| 1192 | 1252 | |
| 1193 | 1253 | // Save the attach ID. |
| 1194 | 1254 | $attachID = $data; |
@@ -1199,8 +1259,9 @@ discard block |
||
| 1199 | 1259 | $currentAttachment = parseAttachBBC($attachID); |
| 1200 | 1260 | |
| 1201 | 1261 | // parseAttachBBC will return a string ($txt key) rather than diying with a fatal_error. Up to you to decide what to do. |
| 1202 | - if (is_string($currentAttachment)) |
|
| 1203 | - return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment; |
|
| 1262 | + if (is_string($currentAttachment)) { |
|
| 1263 | + return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment; |
|
| 1264 | + } |
|
| 1204 | 1265 | |
| 1205 | 1266 | if (!empty($currentAttachment['is_image'])) |
| 1206 | 1267 | { |
@@ -1216,15 +1277,17 @@ discard block |
||
| 1216 | 1277 | $height = ' height="' . $currentAttachment['height'] . '"'; |
| 1217 | 1278 | } |
| 1218 | 1279 | |
| 1219 | - if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) |
|
| 1220 | - $returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>'; |
|
| 1221 | - else |
|
| 1222 | - $returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>'; |
|
| 1280 | + if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) { |
|
| 1281 | + $returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>'; |
|
| 1282 | + } else { |
|
| 1283 | + $returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>'; |
|
| 1284 | + } |
|
| 1223 | 1285 | } |
| 1224 | 1286 | |
| 1225 | 1287 | // No image. Show a link. |
| 1226 | - else |
|
| 1227 | - $returnContext .= $currentAttachment['link']; |
|
| 1288 | + else { |
|
| 1289 | + $returnContext .= $currentAttachment['link']; |
|
| 1290 | + } |
|
| 1228 | 1291 | |
| 1229 | 1292 | // Gotta append what we just did. |
| 1230 | 1293 | $data = $returnContext; |
@@ -1255,8 +1318,9 @@ discard block |
||
| 1255 | 1318 | for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++) |
| 1256 | 1319 | { |
| 1257 | 1320 | // Do PHP code coloring? |
| 1258 | - if ($php_parts[$php_i] != '<?php') |
|
| 1259 | - continue; |
|
| 1321 | + if ($php_parts[$php_i] != '<?php') { |
|
| 1322 | + continue; |
|
| 1323 | + } |
|
| 1260 | 1324 | |
| 1261 | 1325 | $php_string = ''; |
| 1262 | 1326 | while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?>') |
@@ -1272,8 +1336,9 @@ discard block |
||
| 1272 | 1336 | $data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data); |
| 1273 | 1337 | |
| 1274 | 1338 | // Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection. |
| 1275 | - if ($context['browser']['is_opera']) |
|
| 1276 | - $data .= ' '; |
|
| 1339 | + if ($context['browser']['is_opera']) { |
|
| 1340 | + $data .= ' '; |
|
| 1341 | + } |
|
| 1277 | 1342 | } |
| 1278 | 1343 | }, |
| 1279 | 1344 | 'block_level' => true, |
@@ -1292,8 +1357,9 @@ discard block |
||
| 1292 | 1357 | for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++) |
| 1293 | 1358 | { |
| 1294 | 1359 | // Do PHP code coloring? |
| 1295 | - if ($php_parts[$php_i] != '<?php') |
|
| 1296 | - continue; |
|
| 1360 | + if ($php_parts[$php_i] != '<?php') { |
|
| 1361 | + continue; |
|
| 1362 | + } |
|
| 1297 | 1363 | |
| 1298 | 1364 | $php_string = ''; |
| 1299 | 1365 | while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?>') |
@@ -1309,8 +1375,9 @@ discard block |
||
| 1309 | 1375 | $data[0] = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data[0]); |
| 1310 | 1376 | |
| 1311 | 1377 | // Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection. |
| 1312 | - if ($context['browser']['is_opera']) |
|
| 1313 | - $data[0] .= ' '; |
|
| 1378 | + if ($context['browser']['is_opera']) { |
|
| 1379 | + $data[0] .= ' '; |
|
| 1380 | + } |
|
| 1314 | 1381 | } |
| 1315 | 1382 | }, |
| 1316 | 1383 | 'block_level' => true, |
@@ -1348,11 +1415,13 @@ discard block |
||
| 1348 | 1415 | 'content' => '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never">', |
| 1349 | 1416 | 'validate' => function (&$tag, &$data, $disabled) |
| 1350 | 1417 | { |
| 1351 | - if (isset($disabled['url'])) |
|
| 1352 | - $tag['content'] = '$1'; |
|
| 1418 | + if (isset($disabled['url'])) { |
|
| 1419 | + $tag['content'] = '$1'; |
|
| 1420 | + } |
|
| 1353 | 1421 | $scheme = parse_url($data[0], PHP_URL_SCHEME); |
| 1354 | - if (empty($scheme)) |
|
| 1355 | - $data[0] = '//' . ltrim($data[0], ':/'); |
|
| 1422 | + if (empty($scheme)) { |
|
| 1423 | + $data[0] = '//' . ltrim($data[0], ':/'); |
|
| 1424 | + } |
|
| 1356 | 1425 | }, |
| 1357 | 1426 | 'disabled_content' => '<a href="$1" target="_blank" rel="noopener">$1</a>', |
| 1358 | 1427 | ), |
@@ -1366,10 +1435,11 @@ discard block |
||
| 1366 | 1435 | { |
| 1367 | 1436 | $class = 'class="bbc_float float' . (strpos($data, 'left') === 0 ? 'left' : 'right') . '"'; |
| 1368 | 1437 | |
| 1369 | - if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches)) |
|
| 1370 | - $css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"'; |
|
| 1371 | - else |
|
| 1372 | - $css = ''; |
|
| 1438 | + if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches)) { |
|
| 1439 | + $css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"'; |
|
| 1440 | + } else { |
|
| 1441 | + $css = ''; |
|
| 1442 | + } |
|
| 1373 | 1443 | |
| 1374 | 1444 | $data = $class . $css; |
| 1375 | 1445 | }, |
@@ -1419,14 +1489,16 @@ discard block |
||
| 1419 | 1489 | $scheme = parse_url($data, PHP_URL_SCHEME); |
| 1420 | 1490 | if ($image_proxy_enabled) |
| 1421 | 1491 | { |
| 1422 | - if (empty($scheme)) |
|
| 1423 | - $data = 'http://' . ltrim($data, ':/'); |
|
| 1492 | + if (empty($scheme)) { |
|
| 1493 | + $data = 'http://' . ltrim($data, ':/'); |
|
| 1494 | + } |
|
| 1424 | 1495 | |
| 1425 | - if ($scheme != 'https') |
|
| 1426 | - $data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret); |
|
| 1496 | + if ($scheme != 'https') { |
|
| 1497 | + $data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret); |
|
| 1498 | + } |
|
| 1499 | + } elseif (empty($scheme)) { |
|
| 1500 | + $data = '//' . ltrim($data, ':/'); |
|
| 1427 | 1501 | } |
| 1428 | - elseif (empty($scheme)) |
|
| 1429 | - $data = '//' . ltrim($data, ':/'); |
|
| 1430 | 1502 | }, |
| 1431 | 1503 | 'disabled_content' => '($1)', |
| 1432 | 1504 | ), |
@@ -1442,14 +1514,16 @@ discard block |
||
| 1442 | 1514 | $scheme = parse_url($data, PHP_URL_SCHEME); |
| 1443 | 1515 | if ($image_proxy_enabled) |
| 1444 | 1516 | { |
| 1445 | - if (empty($scheme)) |
|
| 1446 | - $data = 'http://' . ltrim($data, ':/'); |
|
| 1517 | + if (empty($scheme)) { |
|
| 1518 | + $data = 'http://' . ltrim($data, ':/'); |
|
| 1519 | + } |
|
| 1447 | 1520 | |
| 1448 | - if ($scheme != 'https') |
|
| 1449 | - $data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret); |
|
| 1521 | + if ($scheme != 'https') { |
|
| 1522 | + $data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret); |
|
| 1523 | + } |
|
| 1524 | + } elseif (empty($scheme)) { |
|
| 1525 | + $data = '//' . ltrim($data, ':/'); |
|
| 1450 | 1526 | } |
| 1451 | - elseif (empty($scheme)) |
|
| 1452 | - $data = '//' . ltrim($data, ':/'); |
|
| 1453 | 1527 | }, |
| 1454 | 1528 | 'disabled_content' => '($1)', |
| 1455 | 1529 | ), |
@@ -1461,8 +1535,9 @@ discard block |
||
| 1461 | 1535 | { |
| 1462 | 1536 | $data = strtr($data, array('<br>' => '')); |
| 1463 | 1537 | $scheme = parse_url($data, PHP_URL_SCHEME); |
| 1464 | - if (empty($scheme)) |
|
| 1465 | - $data = '//' . ltrim($data, ':/'); |
|
| 1538 | + if (empty($scheme)) { |
|
| 1539 | + $data = '//' . ltrim($data, ':/'); |
|
| 1540 | + } |
|
| 1466 | 1541 | }, |
| 1467 | 1542 | ), |
| 1468 | 1543 | array( |
@@ -1473,13 +1548,14 @@ discard block |
||
| 1473 | 1548 | 'after' => '</a>', |
| 1474 | 1549 | 'validate' => function (&$tag, &$data, $disabled) |
| 1475 | 1550 | { |
| 1476 | - if (substr($data, 0, 1) == '#') |
|
| 1477 | - $data = '#post_' . substr($data, 1); |
|
| 1478 | - else |
|
| 1551 | + if (substr($data, 0, 1) == '#') { |
|
| 1552 | + $data = '#post_' . substr($data, 1); |
|
| 1553 | + } else |
|
| 1479 | 1554 | { |
| 1480 | 1555 | $scheme = parse_url($data, PHP_URL_SCHEME); |
| 1481 | - if (empty($scheme)) |
|
| 1482 | - $data = '//' . ltrim($data, ':/'); |
|
| 1556 | + if (empty($scheme)) { |
|
| 1557 | + $data = '//' . ltrim($data, ':/'); |
|
| 1558 | + } |
|
| 1483 | 1559 | } |
| 1484 | 1560 | }, |
| 1485 | 1561 | 'disallow_children' => array('email', 'ftp', 'url', 'iurl'), |
@@ -1557,8 +1633,9 @@ discard block |
||
| 1557 | 1633 | { |
| 1558 | 1634 | $add_begin = substr(trim($data), 0, 5) != '<?'; |
| 1559 | 1635 | $data = highlight_php_code($add_begin ? '<?php ' . $data . '?>' : $data); |
| 1560 | - if ($add_begin) |
|
| 1561 | - $data = preg_replace(array('~^(.+?)<\?.{0,40}?php(?: |\s)~', '~\?>((?:</(font|span)>)*)$~'), '$1', $data, 2); |
|
| 1636 | + if ($add_begin) { |
|
| 1637 | + $data = preg_replace(array('~^(.+?)<\?.{0,40}?php(?: |\s)~', '~\?>((?:</(font|span)>)*)$~'), '$1', $data, 2); |
|
| 1638 | + } |
|
| 1562 | 1639 | } |
| 1563 | 1640 | }, |
| 1564 | 1641 | 'block_level' => false, |
@@ -1689,10 +1766,11 @@ discard block |
||
| 1689 | 1766 | 'content' => '$1', |
| 1690 | 1767 | 'validate' => function (&$tag, &$data, $disabled) |
| 1691 | 1768 | { |
| 1692 | - if (is_numeric($data)) |
|
| 1693 | - $data = timeformat($data); |
|
| 1694 | - else |
|
| 1695 | - $tag['content'] = '[time]$1[/time]'; |
|
| 1769 | + if (is_numeric($data)) { |
|
| 1770 | + $data = timeformat($data); |
|
| 1771 | + } else { |
|
| 1772 | + $tag['content'] = '[time]$1[/time]'; |
|
| 1773 | + } |
|
| 1696 | 1774 | }, |
| 1697 | 1775 | ), |
| 1698 | 1776 | array( |
@@ -1719,8 +1797,9 @@ discard block |
||
| 1719 | 1797 | { |
| 1720 | 1798 | $data = strtr($data, array('<br>' => '')); |
| 1721 | 1799 | $scheme = parse_url($data, PHP_URL_SCHEME); |
| 1722 | - if (empty($scheme)) |
|
| 1723 | - $data = '//' . ltrim($data, ':/'); |
|
| 1800 | + if (empty($scheme)) { |
|
| 1801 | + $data = '//' . ltrim($data, ':/'); |
|
| 1802 | + } |
|
| 1724 | 1803 | }, |
| 1725 | 1804 | ), |
| 1726 | 1805 | array( |
@@ -1732,8 +1811,9 @@ discard block |
||
| 1732 | 1811 | 'validate' => function (&$tag, &$data, $disabled) |
| 1733 | 1812 | { |
| 1734 | 1813 | $scheme = parse_url($data, PHP_URL_SCHEME); |
| 1735 | - if (empty($scheme)) |
|
| 1736 | - $data = '//' . ltrim($data, ':/'); |
|
| 1814 | + if (empty($scheme)) { |
|
| 1815 | + $data = '//' . ltrim($data, ':/'); |
|
| 1816 | + } |
|
| 1737 | 1817 | }, |
| 1738 | 1818 | 'disallow_children' => array('email', 'ftp', 'url', 'iurl'), |
| 1739 | 1819 | 'disabled_after' => ' ($1)', |
@@ -1753,8 +1833,9 @@ discard block |
||
| 1753 | 1833 | // This is mainly for the bbc manager, so it's easy to add tags above. Custom BBC should be added above this line. |
| 1754 | 1834 | if ($message === false) |
| 1755 | 1835 | { |
| 1756 | - if (isset($temp_bbc)) |
|
| 1757 | - $bbc_codes = $temp_bbc; |
|
| 1836 | + if (isset($temp_bbc)) { |
|
| 1837 | + $bbc_codes = $temp_bbc; |
|
| 1838 | + } |
|
| 1758 | 1839 | usort($codes, function ($a, $b) { |
| 1759 | 1840 | return strcmp($a['tag'], $b['tag']); |
| 1760 | 1841 | }); |
@@ -1774,8 +1855,9 @@ discard block |
||
| 1774 | 1855 | ); |
| 1775 | 1856 | if (!isset($disabled['li']) && !isset($disabled['list'])) |
| 1776 | 1857 | { |
| 1777 | - foreach ($itemcodes as $c => $dummy) |
|
| 1778 | - $bbc_codes[$c] = array(); |
|
| 1858 | + foreach ($itemcodes as $c => $dummy) { |
|
| 1859 | + $bbc_codes[$c] = array(); |
|
| 1860 | + } |
|
| 1779 | 1861 | } |
| 1780 | 1862 | |
| 1781 | 1863 | // Shhhh! |
@@ -1796,12 +1878,14 @@ discard block |
||
| 1796 | 1878 | foreach ($codes as $code) |
| 1797 | 1879 | { |
| 1798 | 1880 | // Make it easier to process parameters later |
| 1799 | - if (!empty($code['parameters'])) |
|
| 1800 | - ksort($code['parameters'], SORT_STRING); |
|
| 1881 | + if (!empty($code['parameters'])) { |
|
| 1882 | + ksort($code['parameters'], SORT_STRING); |
|
| 1883 | + } |
|
| 1801 | 1884 | |
| 1802 | 1885 | // If we are not doing every tag only do ones we are interested in. |
| 1803 | - if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) |
|
| 1804 | - $bbc_codes[substr($code['tag'], 0, 1)][] = $code; |
|
| 1886 | + if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) { |
|
| 1887 | + $bbc_codes[substr($code['tag'], 0, 1)][] = $code; |
|
| 1888 | + } |
|
| 1805 | 1889 | } |
| 1806 | 1890 | $codes = null; |
| 1807 | 1891 | } |
@@ -1812,8 +1896,9 @@ discard block |
||
| 1812 | 1896 | // It's likely this will change if the message is modified. |
| 1813 | 1897 | $cache_key = 'parse:' . $cache_id . '-' . md5(md5($message) . '-' . $smileys . (empty($disabled) ? '' : implode(',', array_keys($disabled))) . $smcFunc['json_encode']($context['browser']) . $txt['lang_locale'] . $user_info['time_offset'] . $user_info['time_format']); |
| 1814 | 1898 | |
| 1815 | - if (($temp = cache_get_data($cache_key, 240)) != null) |
|
| 1816 | - return $temp; |
|
| 1899 | + if (($temp = cache_get_data($cache_key, 240)) != null) { |
|
| 1900 | + return $temp; |
|
| 1901 | + } |
|
| 1817 | 1902 | |
| 1818 | 1903 | $cache_t = microtime(); |
| 1819 | 1904 | } |
@@ -1845,8 +1930,9 @@ discard block |
||
| 1845 | 1930 | $disabled['flash'] = true; |
| 1846 | 1931 | |
| 1847 | 1932 | // @todo Change maybe? |
| 1848 | - if (!isset($_GET['images'])) |
|
| 1849 | - $disabled['img'] = true; |
|
| 1933 | + if (!isset($_GET['images'])) { |
|
| 1934 | + $disabled['img'] = true; |
|
| 1935 | + } |
|
| 1850 | 1936 | |
| 1851 | 1937 | // @todo Interface/setting to add more? |
| 1852 | 1938 | } |
@@ -1870,8 +1956,9 @@ discard block |
||
| 1870 | 1956 | $pos = isset($matches[0][1]) ? $matches[0][1] : false; |
| 1871 | 1957 | |
| 1872 | 1958 | // Failsafe. |
| 1873 | - if ($pos === false || $last_pos > $pos) |
|
| 1874 | - $pos = strlen($message) + 1; |
|
| 1959 | + if ($pos === false || $last_pos > $pos) { |
|
| 1960 | + $pos = strlen($message) + 1; |
|
| 1961 | + } |
|
| 1875 | 1962 | |
| 1876 | 1963 | // Can't have a one letter smiley, URL, or email! (sorry.) |
| 1877 | 1964 | if ($last_pos < $pos - 1) |
@@ -1889,8 +1976,9 @@ discard block |
||
| 1889 | 1976 | |
| 1890 | 1977 | // <br> should be empty. |
| 1891 | 1978 | $empty_tags = array('br', 'hr'); |
| 1892 | - foreach ($empty_tags as $tag) |
|
| 1893 | - $data = str_replace(array('<' . $tag . '>', '<' . $tag . '/>', '<' . $tag . ' />'), '<' . $tag . '>', $data); |
|
| 1979 | + foreach ($empty_tags as $tag) { |
|
| 1980 | + $data = str_replace(array('<' . $tag . '>', '<' . $tag . '/>', '<' . $tag . ' />'), '<' . $tag . '>', $data); |
|
| 1981 | + } |
|
| 1894 | 1982 | |
| 1895 | 1983 | // b, u, i, s, pre... basic tags. |
| 1896 | 1984 | $closable_tags = array('b', 'u', 'i', 's', 'em', 'ins', 'del', 'pre', 'blockquote', 'strong'); |
@@ -1899,8 +1987,9 @@ discard block |
||
| 1899 | 1987 | $diff = substr_count($data, '<' . $tag . '>') - substr_count($data, '</' . $tag . '>'); |
| 1900 | 1988 | $data = strtr($data, array('<' . $tag . '>' => '<' . $tag . '>', '</' . $tag . '>' => '</' . $tag . '>')); |
| 1901 | 1989 | |
| 1902 | - if ($diff > 0) |
|
| 1903 | - $data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1); |
|
| 1990 | + if ($diff > 0) { |
|
| 1991 | + $data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1); |
|
| 1992 | + } |
|
| 1904 | 1993 | } |
| 1905 | 1994 | |
| 1906 | 1995 | // Do <img ...> - with security... action= -> action-. |
@@ -1913,8 +2002,9 @@ discard block |
||
| 1913 | 2002 | $alt = empty($matches[3][$match]) ? '' : ' alt=' . preg_replace('~^"|"$~', '', $matches[3][$match]); |
| 1914 | 2003 | |
| 1915 | 2004 | // Remove action= from the URL - no funny business, now. |
| 1916 | - if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) |
|
| 1917 | - $imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag); |
|
| 2005 | + if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) { |
|
| 2006 | + $imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag); |
|
| 2007 | + } |
|
| 1918 | 2008 | |
| 1919 | 2009 | // Check if the image is larger than allowed. |
| 1920 | 2010 | if (!empty($modSettings['max_image_width']) && !empty($modSettings['max_image_height'])) |
@@ -1935,9 +2025,9 @@ discard block |
||
| 1935 | 2025 | |
| 1936 | 2026 | // Set the new image tag. |
| 1937 | 2027 | $replaces[$matches[0][$match]] = '[img width=' . $width . ' height=' . $height . $alt . ']' . $imgtag . '[/img]'; |
| 2028 | + } else { |
|
| 2029 | + $replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]'; |
|
| 1938 | 2030 | } |
| 1939 | - else |
|
| 1940 | - $replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]'; |
|
| 1941 | 2031 | } |
| 1942 | 2032 | |
| 1943 | 2033 | $data = strtr($data, $replaces); |
@@ -1950,16 +2040,18 @@ discard block |
||
| 1950 | 2040 | $no_autolink_area = false; |
| 1951 | 2041 | if (!empty($open_tags)) |
| 1952 | 2042 | { |
| 1953 | - foreach ($open_tags as $open_tag) |
|
| 1954 | - if (in_array($open_tag['tag'], $no_autolink_tags)) |
|
| 2043 | + foreach ($open_tags as $open_tag) { |
|
| 2044 | + if (in_array($open_tag['tag'], $no_autolink_tags)) |
|
| 1955 | 2045 | $no_autolink_area = true; |
| 2046 | + } |
|
| 1956 | 2047 | } |
| 1957 | 2048 | |
| 1958 | 2049 | // Don't go backwards. |
| 1959 | 2050 | // @todo Don't think is the real solution.... |
| 1960 | 2051 | $lastAutoPos = isset($lastAutoPos) ? $lastAutoPos : 0; |
| 1961 | - if ($pos < $lastAutoPos) |
|
| 1962 | - $no_autolink_area = true; |
|
| 2052 | + if ($pos < $lastAutoPos) { |
|
| 2053 | + $no_autolink_area = true; |
|
| 2054 | + } |
|
| 1963 | 2055 | $lastAutoPos = $pos; |
| 1964 | 2056 | |
| 1965 | 2057 | if (!$no_autolink_area) |
@@ -2068,17 +2160,19 @@ discard block |
||
| 2068 | 2160 | if ($scheme == 'mailto') |
| 2069 | 2161 | { |
| 2070 | 2162 | $email_address = str_replace('mailto:', '', $url); |
| 2071 | - if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) |
|
| 2072 | - return '[email=' . $email_address . ']' . $url . '[/email]'; |
|
| 2073 | - else |
|
| 2074 | - return $url; |
|
| 2163 | + if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) { |
|
| 2164 | + return '[email=' . $email_address . ']' . $url . '[/email]'; |
|
| 2165 | + } else { |
|
| 2166 | + return $url; |
|
| 2167 | + } |
|
| 2075 | 2168 | } |
| 2076 | 2169 | |
| 2077 | 2170 | // Are we linking a schemeless URL or naked domain name (e.g. "example.com")? |
| 2078 | - if (empty($scheme)) |
|
| 2079 | - $fullUrl = '//' . ltrim($url, ':/'); |
|
| 2080 | - else |
|
| 2081 | - $fullUrl = $url; |
|
| 2171 | + if (empty($scheme)) { |
|
| 2172 | + $fullUrl = '//' . ltrim($url, ':/'); |
|
| 2173 | + } else { |
|
| 2174 | + $fullUrl = $url; |
|
| 2175 | + } |
|
| 2082 | 2176 | |
| 2083 | 2177 | return '[url="' . str_replace(array('[', ']'), array('[', ']'), $fullUrl) . '"]' . $url . '[/url]'; |
| 2084 | 2178 | }, $data); |
@@ -2127,16 +2221,18 @@ discard block |
||
| 2127 | 2221 | } |
| 2128 | 2222 | |
| 2129 | 2223 | // Are we there yet? Are we there yet? |
| 2130 | - if ($pos >= strlen($message) - 1) |
|
| 2131 | - break; |
|
| 2224 | + if ($pos >= strlen($message) - 1) { |
|
| 2225 | + break; |
|
| 2226 | + } |
|
| 2132 | 2227 | |
| 2133 | 2228 | $tags = strtolower($message[$pos + 1]); |
| 2134 | 2229 | |
| 2135 | 2230 | if ($tags == '/' && !empty($open_tags)) |
| 2136 | 2231 | { |
| 2137 | 2232 | $pos2 = strpos($message, ']', $pos + 1); |
| 2138 | - if ($pos2 == $pos + 2) |
|
| 2139 | - continue; |
|
| 2233 | + if ($pos2 == $pos + 2) { |
|
| 2234 | + continue; |
|
| 2235 | + } |
|
| 2140 | 2236 | |
| 2141 | 2237 | $look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2)); |
| 2142 | 2238 | |
@@ -2146,8 +2242,9 @@ discard block |
||
| 2146 | 2242 | do |
| 2147 | 2243 | { |
| 2148 | 2244 | $tag = array_pop($open_tags); |
| 2149 | - if (!$tag) |
|
| 2150 | - break; |
|
| 2245 | + if (!$tag) { |
|
| 2246 | + break; |
|
| 2247 | + } |
|
| 2151 | 2248 | |
| 2152 | 2249 | if (!empty($tag['block_level'])) |
| 2153 | 2250 | { |
@@ -2161,10 +2258,11 @@ discard block |
||
| 2161 | 2258 | // The idea is, if we are LOOKING for a block level tag, we can close them on the way. |
| 2162 | 2259 | if (strlen($look_for) > 0 && isset($bbc_codes[$look_for[0]])) |
| 2163 | 2260 | { |
| 2164 | - foreach ($bbc_codes[$look_for[0]] as $temp) |
|
| 2165 | - if ($temp['tag'] == $look_for) |
|
| 2261 | + foreach ($bbc_codes[$look_for[0]] as $temp) { |
|
| 2262 | + if ($temp['tag'] == $look_for) |
|
| 2166 | 2263 | { |
| 2167 | 2264 | $block_level = !empty($temp['block_level']); |
| 2265 | + } |
|
| 2168 | 2266 | break; |
| 2169 | 2267 | } |
| 2170 | 2268 | } |
@@ -2186,15 +2284,15 @@ discard block |
||
| 2186 | 2284 | { |
| 2187 | 2285 | $open_tags = $to_close; |
| 2188 | 2286 | continue; |
| 2189 | - } |
|
| 2190 | - elseif (!empty($to_close) && $tag['tag'] != $look_for) |
|
| 2287 | + } elseif (!empty($to_close) && $tag['tag'] != $look_for) |
|
| 2191 | 2288 | { |
| 2192 | 2289 | if ($block_level === null && isset($look_for[0], $bbc_codes[$look_for[0]])) |
| 2193 | 2290 | { |
| 2194 | - foreach ($bbc_codes[$look_for[0]] as $temp) |
|
| 2195 | - if ($temp['tag'] == $look_for) |
|
| 2291 | + foreach ($bbc_codes[$look_for[0]] as $temp) { |
|
| 2292 | + if ($temp['tag'] == $look_for) |
|
| 2196 | 2293 | { |
| 2197 | 2294 | $block_level = !empty($temp['block_level']); |
| 2295 | + } |
|
| 2198 | 2296 | break; |
| 2199 | 2297 | } |
| 2200 | 2298 | } |
@@ -2202,8 +2300,9 @@ discard block |
||
| 2202 | 2300 | // We're not looking for a block level tag (or maybe even a tag that exists...) |
| 2203 | 2301 | if (!$block_level) |
| 2204 | 2302 | { |
| 2205 | - foreach ($to_close as $tag) |
|
| 2206 | - array_push($open_tags, $tag); |
|
| 2303 | + foreach ($to_close as $tag) { |
|
| 2304 | + array_push($open_tags, $tag); |
|
| 2305 | + } |
|
| 2207 | 2306 | continue; |
| 2208 | 2307 | } |
| 2209 | 2308 | } |
@@ -2216,14 +2315,17 @@ discard block |
||
| 2216 | 2315 | |
| 2217 | 2316 | // See the comment at the end of the big loop - just eating whitespace ;). |
| 2218 | 2317 | $whitespace_regex = ''; |
| 2219 | - if (!empty($tag['block_level'])) |
|
| 2220 | - $whitespace_regex .= '( |\s)*(<br>)?'; |
|
| 2318 | + if (!empty($tag['block_level'])) { |
|
| 2319 | + $whitespace_regex .= '( |\s)*(<br>)?'; |
|
| 2320 | + } |
|
| 2221 | 2321 | // Trim one line of whitespace after unnested tags, but all of it after nested ones |
| 2222 | - if (!empty($tag['trim']) && $tag['trim'] != 'inside') |
|
| 2223 | - $whitespace_regex .= empty($tag['require_parents']) ? '( |\s)*' : '(<br>| |\s)*'; |
|
| 2322 | + if (!empty($tag['trim']) && $tag['trim'] != 'inside') { |
|
| 2323 | + $whitespace_regex .= empty($tag['require_parents']) ? '( |\s)*' : '(<br>| |\s)*'; |
|
| 2324 | + } |
|
| 2224 | 2325 | |
| 2225 | - if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) |
|
| 2226 | - $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
| 2326 | + if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) { |
|
| 2327 | + $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
| 2328 | + } |
|
| 2227 | 2329 | } |
| 2228 | 2330 | |
| 2229 | 2331 | if (!empty($to_close)) |
@@ -2236,8 +2338,9 @@ discard block |
||
| 2236 | 2338 | } |
| 2237 | 2339 | |
| 2238 | 2340 | // No tags for this character, so just keep going (fastest possible course.) |
| 2239 | - if (!isset($bbc_codes[$tags])) |
|
| 2240 | - continue; |
|
| 2341 | + if (!isset($bbc_codes[$tags])) { |
|
| 2342 | + continue; |
|
| 2343 | + } |
|
| 2241 | 2344 | |
| 2242 | 2345 | $inside = empty($open_tags) ? null : $open_tags[count($open_tags) - 1]; |
| 2243 | 2346 | $tag = null; |
@@ -2246,44 +2349,52 @@ discard block |
||
| 2246 | 2349 | $pt_strlen = strlen($possible['tag']); |
| 2247 | 2350 | |
| 2248 | 2351 | // Not a match? |
| 2249 | - if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) |
|
| 2250 | - continue; |
|
| 2352 | + if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) { |
|
| 2353 | + continue; |
|
| 2354 | + } |
|
| 2251 | 2355 | |
| 2252 | 2356 | $next_c = $message[$pos + 1 + $pt_strlen]; |
| 2253 | 2357 | |
| 2254 | 2358 | // A test validation? |
| 2255 | - if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) |
|
| 2256 | - continue; |
|
| 2359 | + if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) { |
|
| 2360 | + continue; |
|
| 2361 | + } |
|
| 2257 | 2362 | // Do we want parameters? |
| 2258 | 2363 | elseif (!empty($possible['parameters'])) |
| 2259 | 2364 | { |
| 2260 | - if ($next_c != ' ') |
|
| 2261 | - continue; |
|
| 2262 | - } |
|
| 2263 | - elseif (isset($possible['type'])) |
|
| 2365 | + if ($next_c != ' ') { |
|
| 2366 | + continue; |
|
| 2367 | + } |
|
| 2368 | + } elseif (isset($possible['type'])) |
|
| 2264 | 2369 | { |
| 2265 | 2370 | // Do we need an equal sign? |
| 2266 | - if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') |
|
| 2267 | - continue; |
|
| 2371 | + if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') { |
|
| 2372 | + continue; |
|
| 2373 | + } |
|
| 2268 | 2374 | // Maybe we just want a /... |
| 2269 | - if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') |
|
| 2270 | - continue; |
|
| 2375 | + if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') { |
|
| 2376 | + continue; |
|
| 2377 | + } |
|
| 2271 | 2378 | // An immediate ]? |
| 2272 | - if ($possible['type'] == 'unparsed_content' && $next_c != ']') |
|
| 2273 | - continue; |
|
| 2379 | + if ($possible['type'] == 'unparsed_content' && $next_c != ']') { |
|
| 2380 | + continue; |
|
| 2381 | + } |
|
| 2274 | 2382 | } |
| 2275 | 2383 | // No type means 'parsed_content', which demands an immediate ] without parameters! |
| 2276 | - elseif ($next_c != ']') |
|
| 2277 | - continue; |
|
| 2384 | + elseif ($next_c != ']') { |
|
| 2385 | + continue; |
|
| 2386 | + } |
|
| 2278 | 2387 | |
| 2279 | 2388 | // Check allowed tree? |
| 2280 | - if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) |
|
| 2281 | - continue; |
|
| 2282 | - elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) |
|
| 2283 | - continue; |
|
| 2389 | + if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) { |
|
| 2390 | + continue; |
|
| 2391 | + } elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) { |
|
| 2392 | + continue; |
|
| 2393 | + } |
|
| 2284 | 2394 | // If this is in the list of disallowed child tags, don't parse it. |
| 2285 | - elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) |
|
| 2286 | - continue; |
|
| 2395 | + elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) { |
|
| 2396 | + continue; |
|
| 2397 | + } |
|
| 2287 | 2398 | |
| 2288 | 2399 | $pos1 = $pos + 1 + $pt_strlen + 1; |
| 2289 | 2400 | |
@@ -2295,8 +2406,9 @@ discard block |
||
| 2295 | 2406 | foreach ($open_tags as $open_quote) |
| 2296 | 2407 | { |
| 2297 | 2408 | // Every parent quote this quote has flips the styling |
| 2298 | - if ($open_quote['tag'] == 'quote') |
|
| 2299 | - $quote_alt = !$quote_alt; |
|
| 2409 | + if ($open_quote['tag'] == 'quote') { |
|
| 2410 | + $quote_alt = !$quote_alt; |
|
| 2411 | + } |
|
| 2300 | 2412 | } |
| 2301 | 2413 | // Add a class to the quote to style alternating blockquotes |
| 2302 | 2414 | $possible['before'] = strtr($possible['before'], array('<blockquote>' => '<blockquote class="bbc_' . ($quote_alt ? 'alternate' : 'standard') . '_quote">')); |
@@ -2307,8 +2419,9 @@ discard block |
||
| 2307 | 2419 | { |
| 2308 | 2420 | // Build a regular expression for each parameter for the current tag. |
| 2309 | 2421 | $preg = array(); |
| 2310 | - foreach ($possible['parameters'] as $p => $info) |
|
| 2311 | - $preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '"') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '"') . '\s*)' . (empty($info['optional']) ? '' : '?'); |
|
| 2422 | + foreach ($possible['parameters'] as $p => $info) { |
|
| 2423 | + $preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '"') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '"') . '\s*)' . (empty($info['optional']) ? '' : '?'); |
|
| 2424 | + } |
|
| 2312 | 2425 | |
| 2313 | 2426 | // Extract the string that potentially holds our parameters. |
| 2314 | 2427 | $blob = preg_split('~\[/?(?:' . $alltags_regex . ')~i', substr($message, $pos)); |
@@ -2328,24 +2441,27 @@ discard block |
||
| 2328 | 2441 | |
| 2329 | 2442 | $match = preg_match('~^' . implode('', $preg) . '$~i', implode(' ', $given_params), $matches) !== 0; |
| 2330 | 2443 | |
| 2331 | - if ($match) |
|
| 2332 | - $blob_counter = count($blobs) + 1; |
|
| 2444 | + if ($match) { |
|
| 2445 | + $blob_counter = count($blobs) + 1; |
|
| 2446 | + } |
|
| 2333 | 2447 | } |
| 2334 | 2448 | |
| 2335 | 2449 | // Didn't match our parameter list, try the next possible. |
| 2336 | - if (!$match) |
|
| 2337 | - continue; |
|
| 2450 | + if (!$match) { |
|
| 2451 | + continue; |
|
| 2452 | + } |
|
| 2338 | 2453 | |
| 2339 | 2454 | $params = array(); |
| 2340 | 2455 | for ($i = 1, $n = count($matches); $i < $n; $i += 2) |
| 2341 | 2456 | { |
| 2342 | 2457 | $key = strtok(ltrim($matches[$i]), '='); |
| 2343 | - if (isset($possible['parameters'][$key]['value'])) |
|
| 2344 | - $params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1])); |
|
| 2345 | - elseif (isset($possible['parameters'][$key]['validate'])) |
|
| 2346 | - $params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]); |
|
| 2347 | - else |
|
| 2348 | - $params['{' . $key . '}'] = $matches[$i + 1]; |
|
| 2458 | + if (isset($possible['parameters'][$key]['value'])) { |
|
| 2459 | + $params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1])); |
|
| 2460 | + } elseif (isset($possible['parameters'][$key]['validate'])) { |
|
| 2461 | + $params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]); |
|
| 2462 | + } else { |
|
| 2463 | + $params['{' . $key . '}'] = $matches[$i + 1]; |
|
| 2464 | + } |
|
| 2349 | 2465 | |
| 2350 | 2466 | // Just to make sure: replace any $ or { so they can't interpolate wrongly. |
| 2351 | 2467 | $params['{' . $key . '}'] = strtr($params['{' . $key . '}'], array('$' => '$', '{' => '{')); |
@@ -2353,23 +2469,26 @@ discard block |
||
| 2353 | 2469 | |
| 2354 | 2470 | foreach ($possible['parameters'] as $p => $info) |
| 2355 | 2471 | { |
| 2356 | - if (!isset($params['{' . $p . '}'])) |
|
| 2357 | - $params['{' . $p . '}'] = ''; |
|
| 2472 | + if (!isset($params['{' . $p . '}'])) { |
|
| 2473 | + $params['{' . $p . '}'] = ''; |
|
| 2474 | + } |
|
| 2358 | 2475 | } |
| 2359 | 2476 | |
| 2360 | 2477 | $tag = $possible; |
| 2361 | 2478 | |
| 2362 | 2479 | // Put the parameters into the string. |
| 2363 | - if (isset($tag['before'])) |
|
| 2364 | - $tag['before'] = strtr($tag['before'], $params); |
|
| 2365 | - if (isset($tag['after'])) |
|
| 2366 | - $tag['after'] = strtr($tag['after'], $params); |
|
| 2367 | - if (isset($tag['content'])) |
|
| 2368 | - $tag['content'] = strtr($tag['content'], $params); |
|
| 2480 | + if (isset($tag['before'])) { |
|
| 2481 | + $tag['before'] = strtr($tag['before'], $params); |
|
| 2482 | + } |
|
| 2483 | + if (isset($tag['after'])) { |
|
| 2484 | + $tag['after'] = strtr($tag['after'], $params); |
|
| 2485 | + } |
|
| 2486 | + if (isset($tag['content'])) { |
|
| 2487 | + $tag['content'] = strtr($tag['content'], $params); |
|
| 2488 | + } |
|
| 2369 | 2489 | |
| 2370 | 2490 | $pos1 += strlen($given_param_string); |
| 2371 | - } |
|
| 2372 | - else |
|
| 2491 | + } else |
|
| 2373 | 2492 | { |
| 2374 | 2493 | $tag = $possible; |
| 2375 | 2494 | $params = array(); |
@@ -2380,8 +2499,9 @@ discard block |
||
| 2380 | 2499 | // Item codes are complicated buggers... they are implicit [li]s and can make [list]s! |
| 2381 | 2500 | if ($smileys !== false && $tag === null && isset($itemcodes[$message[$pos + 1]]) && $message[$pos + 2] == ']' && !isset($disabled['list']) && !isset($disabled['li'])) |
| 2382 | 2501 | { |
| 2383 | - if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) |
|
| 2384 | - continue; |
|
| 2502 | + if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) { |
|
| 2503 | + continue; |
|
| 2504 | + } |
|
| 2385 | 2505 | |
| 2386 | 2506 | $tag = $itemcodes[$message[$pos + 1]]; |
| 2387 | 2507 | |
@@ -2402,9 +2522,9 @@ discard block |
||
| 2402 | 2522 | { |
| 2403 | 2523 | array_pop($open_tags); |
| 2404 | 2524 | $code = '</li>'; |
| 2525 | + } else { |
|
| 2526 | + $code = ''; |
|
| 2405 | 2527 | } |
| 2406 | - else |
|
| 2407 | - $code = ''; |
|
| 2408 | 2528 | |
| 2409 | 2529 | // Now we open a new tag. |
| 2410 | 2530 | $open_tags[] = array( |
@@ -2451,12 +2571,14 @@ discard block |
||
| 2451 | 2571 | } |
| 2452 | 2572 | |
| 2453 | 2573 | // No tag? Keep looking, then. Silly people using brackets without actual tags. |
| 2454 | - if ($tag === null) |
|
| 2455 | - continue; |
|
| 2574 | + if ($tag === null) { |
|
| 2575 | + continue; |
|
| 2576 | + } |
|
| 2456 | 2577 | |
| 2457 | 2578 | // Propagate the list to the child (so wrapping the disallowed tag won't work either.) |
| 2458 | - if (isset($inside['disallow_children'])) |
|
| 2459 | - $tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children']; |
|
| 2579 | + if (isset($inside['disallow_children'])) { |
|
| 2580 | + $tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children']; |
|
| 2581 | + } |
|
| 2460 | 2582 | |
| 2461 | 2583 | // Is this tag disabled? |
| 2462 | 2584 | if (isset($disabled[$tag['tag']])) |
@@ -2466,14 +2588,13 @@ discard block |
||
| 2466 | 2588 | $tag['before'] = !empty($tag['block_level']) ? '<div>' : ''; |
| 2467 | 2589 | $tag['after'] = !empty($tag['block_level']) ? '</div>' : ''; |
| 2468 | 2590 | $tag['content'] = isset($tag['type']) && $tag['type'] == 'closed' ? '' : (!empty($tag['block_level']) ? '<div>$1</div>' : '$1'); |
| 2469 | - } |
|
| 2470 | - elseif (isset($tag['disabled_before']) || isset($tag['disabled_after'])) |
|
| 2591 | + } elseif (isset($tag['disabled_before']) || isset($tag['disabled_after'])) |
|
| 2471 | 2592 | { |
| 2472 | 2593 | $tag['before'] = isset($tag['disabled_before']) ? $tag['disabled_before'] : (!empty($tag['block_level']) ? '<div>' : ''); |
| 2473 | 2594 | $tag['after'] = isset($tag['disabled_after']) ? $tag['disabled_after'] : (!empty($tag['block_level']) ? '</div>' : ''); |
| 2595 | + } else { |
|
| 2596 | + $tag['content'] = $tag['disabled_content']; |
|
| 2474 | 2597 | } |
| 2475 | - else |
|
| 2476 | - $tag['content'] = $tag['disabled_content']; |
|
| 2477 | 2598 | } |
| 2478 | 2599 | |
| 2479 | 2600 | // we use this a lot |
@@ -2483,8 +2604,9 @@ discard block |
||
| 2483 | 2604 | if (!empty($tag['block_level']) && $tag['tag'] != 'html' && empty($inside['block_level'])) |
| 2484 | 2605 | { |
| 2485 | 2606 | $n = count($open_tags) - 1; |
| 2486 | - while (empty($open_tags[$n]['block_level']) && $n >= 0) |
|
| 2487 | - $n--; |
|
| 2607 | + while (empty($open_tags[$n]['block_level']) && $n >= 0) { |
|
| 2608 | + $n--; |
|
| 2609 | + } |
|
| 2488 | 2610 | |
| 2489 | 2611 | // Close all the non block level tags so this tag isn't surrounded by them. |
| 2490 | 2612 | for ($i = count($open_tags) - 1; $i > $n; $i--) |
@@ -2496,12 +2618,15 @@ discard block |
||
| 2496 | 2618 | |
| 2497 | 2619 | // Trim or eat trailing stuff... see comment at the end of the big loop. |
| 2498 | 2620 | $whitespace_regex = ''; |
| 2499 | - if (!empty($tag['block_level'])) |
|
| 2500 | - $whitespace_regex .= '( |\s)*(<br>)?'; |
|
| 2501 | - if (!empty($tag['trim']) && $tag['trim'] != 'inside') |
|
| 2502 | - $whitespace_regex .= empty($tag['require_parents']) ? '( |\s)*' : '(<br>| |\s)*'; |
|
| 2503 | - if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) |
|
| 2504 | - $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
| 2621 | + if (!empty($tag['block_level'])) { |
|
| 2622 | + $whitespace_regex .= '( |\s)*(<br>)?'; |
|
| 2623 | + } |
|
| 2624 | + if (!empty($tag['trim']) && $tag['trim'] != 'inside') { |
|
| 2625 | + $whitespace_regex .= empty($tag['require_parents']) ? '( |\s)*' : '(<br>| |\s)*'; |
|
| 2626 | + } |
|
| 2627 | + if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) { |
|
| 2628 | + $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
| 2629 | + } |
|
| 2505 | 2630 | |
| 2506 | 2631 | array_pop($open_tags); |
| 2507 | 2632 | } |
@@ -2522,16 +2647,19 @@ discard block |
||
| 2522 | 2647 | elseif ($tag['type'] == 'unparsed_content') |
| 2523 | 2648 | { |
| 2524 | 2649 | $pos2 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos1); |
| 2525 | - if ($pos2 === false) |
|
| 2526 | - continue; |
|
| 2650 | + if ($pos2 === false) { |
|
| 2651 | + continue; |
|
| 2652 | + } |
|
| 2527 | 2653 | |
| 2528 | 2654 | $data = substr($message, $pos1, $pos2 - $pos1); |
| 2529 | 2655 | |
| 2530 | - if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') |
|
| 2531 | - $data = substr($data, 4); |
|
| 2656 | + if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') { |
|
| 2657 | + $data = substr($data, 4); |
|
| 2658 | + } |
|
| 2532 | 2659 | |
| 2533 | - if (isset($tag['validate'])) |
|
| 2534 | - $tag['validate']($tag, $data, $disabled, $params); |
|
| 2660 | + if (isset($tag['validate'])) { |
|
| 2661 | + $tag['validate']($tag, $data, $disabled, $params); |
|
| 2662 | + } |
|
| 2535 | 2663 | |
| 2536 | 2664 | $code = strtr($tag['content'], array('$1' => $data)); |
| 2537 | 2665 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 3 + $tag_strlen); |
@@ -2547,34 +2675,40 @@ discard block |
||
| 2547 | 2675 | if (isset($tag['quoted'])) |
| 2548 | 2676 | { |
| 2549 | 2677 | $quoted = substr($message, $pos1, 6) == '"'; |
| 2550 | - if ($tag['quoted'] != 'optional' && !$quoted) |
|
| 2551 | - continue; |
|
| 2678 | + if ($tag['quoted'] != 'optional' && !$quoted) { |
|
| 2679 | + continue; |
|
| 2680 | + } |
|
| 2552 | 2681 | |
| 2553 | - if ($quoted) |
|
| 2554 | - $pos1 += 6; |
|
| 2682 | + if ($quoted) { |
|
| 2683 | + $pos1 += 6; |
|
| 2684 | + } |
|
| 2685 | + } else { |
|
| 2686 | + $quoted = false; |
|
| 2555 | 2687 | } |
| 2556 | - else |
|
| 2557 | - $quoted = false; |
|
| 2558 | 2688 | |
| 2559 | 2689 | $pos2 = strpos($message, $quoted == false ? ']' : '"]', $pos1); |
| 2560 | - if ($pos2 === false) |
|
| 2561 | - continue; |
|
| 2690 | + if ($pos2 === false) { |
|
| 2691 | + continue; |
|
| 2692 | + } |
|
| 2562 | 2693 | |
| 2563 | 2694 | $pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2); |
| 2564 | - if ($pos3 === false) |
|
| 2565 | - continue; |
|
| 2695 | + if ($pos3 === false) { |
|
| 2696 | + continue; |
|
| 2697 | + } |
|
| 2566 | 2698 | |
| 2567 | 2699 | $data = array( |
| 2568 | 2700 | substr($message, $pos2 + ($quoted == false ? 1 : 7), $pos3 - ($pos2 + ($quoted == false ? 1 : 7))), |
| 2569 | 2701 | substr($message, $pos1, $pos2 - $pos1) |
| 2570 | 2702 | ); |
| 2571 | 2703 | |
| 2572 | - if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') |
|
| 2573 | - $data[0] = substr($data[0], 4); |
|
| 2704 | + if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') { |
|
| 2705 | + $data[0] = substr($data[0], 4); |
|
| 2706 | + } |
|
| 2574 | 2707 | |
| 2575 | 2708 | // Validation for my parking, please! |
| 2576 | - if (isset($tag['validate'])) |
|
| 2577 | - $tag['validate']($tag, $data, $disabled, $params); |
|
| 2709 | + if (isset($tag['validate'])) { |
|
| 2710 | + $tag['validate']($tag, $data, $disabled, $params); |
|
| 2711 | + } |
|
| 2578 | 2712 | |
| 2579 | 2713 | $code = strtr($tag['content'], array('$1' => $data[0], '$2' => $data[1])); |
| 2580 | 2714 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen); |
@@ -2591,23 +2725,27 @@ discard block |
||
| 2591 | 2725 | elseif ($tag['type'] == 'unparsed_commas_content') |
| 2592 | 2726 | { |
| 2593 | 2727 | $pos2 = strpos($message, ']', $pos1); |
| 2594 | - if ($pos2 === false) |
|
| 2595 | - continue; |
|
| 2728 | + if ($pos2 === false) { |
|
| 2729 | + continue; |
|
| 2730 | + } |
|
| 2596 | 2731 | |
| 2597 | 2732 | $pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2); |
| 2598 | - if ($pos3 === false) |
|
| 2599 | - continue; |
|
| 2733 | + if ($pos3 === false) { |
|
| 2734 | + continue; |
|
| 2735 | + } |
|
| 2600 | 2736 | |
| 2601 | 2737 | // We want $1 to be the content, and the rest to be csv. |
| 2602 | 2738 | $data = explode(',', ',' . substr($message, $pos1, $pos2 - $pos1)); |
| 2603 | 2739 | $data[0] = substr($message, $pos2 + 1, $pos3 - $pos2 - 1); |
| 2604 | 2740 | |
| 2605 | - if (isset($tag['validate'])) |
|
| 2606 | - $tag['validate']($tag, $data, $disabled, $params); |
|
| 2741 | + if (isset($tag['validate'])) { |
|
| 2742 | + $tag['validate']($tag, $data, $disabled, $params); |
|
| 2743 | + } |
|
| 2607 | 2744 | |
| 2608 | 2745 | $code = $tag['content']; |
| 2609 | - foreach ($data as $k => $d) |
|
| 2610 | - $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
| 2746 | + foreach ($data as $k => $d) { |
|
| 2747 | + $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
| 2748 | + } |
|
| 2611 | 2749 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen); |
| 2612 | 2750 | $pos += strlen($code) - 1 + 2; |
| 2613 | 2751 | } |
@@ -2615,24 +2753,28 @@ discard block |
||
| 2615 | 2753 | elseif ($tag['type'] == 'unparsed_commas') |
| 2616 | 2754 | { |
| 2617 | 2755 | $pos2 = strpos($message, ']', $pos1); |
| 2618 | - if ($pos2 === false) |
|
| 2619 | - continue; |
|
| 2756 | + if ($pos2 === false) { |
|
| 2757 | + continue; |
|
| 2758 | + } |
|
| 2620 | 2759 | |
| 2621 | 2760 | $data = explode(',', substr($message, $pos1, $pos2 - $pos1)); |
| 2622 | 2761 | |
| 2623 | - if (isset($tag['validate'])) |
|
| 2624 | - $tag['validate']($tag, $data, $disabled, $params); |
|
| 2762 | + if (isset($tag['validate'])) { |
|
| 2763 | + $tag['validate']($tag, $data, $disabled, $params); |
|
| 2764 | + } |
|
| 2625 | 2765 | |
| 2626 | 2766 | // Fix after, for disabled code mainly. |
| 2627 | - foreach ($data as $k => $d) |
|
| 2628 | - $tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d))); |
|
| 2767 | + foreach ($data as $k => $d) { |
|
| 2768 | + $tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d))); |
|
| 2769 | + } |
|
| 2629 | 2770 | |
| 2630 | 2771 | $open_tags[] = $tag; |
| 2631 | 2772 | |
| 2632 | 2773 | // Replace them out, $1, $2, $3, $4, etc. |
| 2633 | 2774 | $code = $tag['before']; |
| 2634 | - foreach ($data as $k => $d) |
|
| 2635 | - $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
| 2775 | + foreach ($data as $k => $d) { |
|
| 2776 | + $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
| 2777 | + } |
|
| 2636 | 2778 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 1); |
| 2637 | 2779 | $pos += strlen($code) - 1 + 2; |
| 2638 | 2780 | } |
@@ -2643,28 +2785,33 @@ discard block |
||
| 2643 | 2785 | if (isset($tag['quoted'])) |
| 2644 | 2786 | { |
| 2645 | 2787 | $quoted = substr($message, $pos1, 6) == '"'; |
| 2646 | - if ($tag['quoted'] != 'optional' && !$quoted) |
|
| 2647 | - continue; |
|
| 2788 | + if ($tag['quoted'] != 'optional' && !$quoted) { |
|
| 2789 | + continue; |
|
| 2790 | + } |
|
| 2648 | 2791 | |
| 2649 | - if ($quoted) |
|
| 2650 | - $pos1 += 6; |
|
| 2792 | + if ($quoted) { |
|
| 2793 | + $pos1 += 6; |
|
| 2794 | + } |
|
| 2795 | + } else { |
|
| 2796 | + $quoted = false; |
|
| 2651 | 2797 | } |
| 2652 | - else |
|
| 2653 | - $quoted = false; |
|
| 2654 | 2798 | |
| 2655 | 2799 | $pos2 = strpos($message, $quoted == false ? ']' : '"]', $pos1); |
| 2656 | - if ($pos2 === false) |
|
| 2657 | - continue; |
|
| 2800 | + if ($pos2 === false) { |
|
| 2801 | + continue; |
|
| 2802 | + } |
|
| 2658 | 2803 | |
| 2659 | 2804 | $data = substr($message, $pos1, $pos2 - $pos1); |
| 2660 | 2805 | |
| 2661 | 2806 | // Validation for my parking, please! |
| 2662 | - if (isset($tag['validate'])) |
|
| 2663 | - $tag['validate']($tag, $data, $disabled, $params); |
|
| 2807 | + if (isset($tag['validate'])) { |
|
| 2808 | + $tag['validate']($tag, $data, $disabled, $params); |
|
| 2809 | + } |
|
| 2664 | 2810 | |
| 2665 | 2811 | // For parsed content, we must recurse to avoid security problems. |
| 2666 | - if ($tag['type'] != 'unparsed_equals') |
|
| 2667 | - $data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array()); |
|
| 2812 | + if ($tag['type'] != 'unparsed_equals') { |
|
| 2813 | + $data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array()); |
|
| 2814 | + } |
|
| 2668 | 2815 | |
| 2669 | 2816 | $tag['after'] = strtr($tag['after'], array('$1' => $data)); |
| 2670 | 2817 | |
@@ -2676,34 +2823,40 @@ discard block |
||
| 2676 | 2823 | } |
| 2677 | 2824 | |
| 2678 | 2825 | // If this is block level, eat any breaks after it. |
| 2679 | - if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') |
|
| 2680 | - $message = substr($message, 0, $pos + 1) . substr($message, $pos + 5); |
|
| 2826 | + if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') { |
|
| 2827 | + $message = substr($message, 0, $pos + 1) . substr($message, $pos + 5); |
|
| 2828 | + } |
|
| 2681 | 2829 | |
| 2682 | 2830 | // Are we trimming outside this tag? |
| 2683 | - if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>| |\s)*~', substr($message, $pos + 1), $matches) != 0) |
|
| 2684 | - $message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0])); |
|
| 2831 | + if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>| |\s)*~', substr($message, $pos + 1), $matches) != 0) { |
|
| 2832 | + $message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0])); |
|
| 2833 | + } |
|
| 2685 | 2834 | } |
| 2686 | 2835 | |
| 2687 | 2836 | // Close any remaining tags. |
| 2688 | - while ($tag = array_pop($open_tags)) |
|
| 2689 | - $message .= "\n" . $tag['after'] . "\n"; |
|
| 2837 | + while ($tag = array_pop($open_tags)) { |
|
| 2838 | + $message .= "\n" . $tag['after'] . "\n"; |
|
| 2839 | + } |
|
| 2690 | 2840 | |
| 2691 | 2841 | // Parse the smileys within the parts where it can be done safely. |
| 2692 | 2842 | if ($smileys === true) |
| 2693 | 2843 | { |
| 2694 | 2844 | $message_parts = explode("\n", $message); |
| 2695 | - for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) |
|
| 2696 | - parsesmileys($message_parts[$i]); |
|
| 2845 | + for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) { |
|
| 2846 | + parsesmileys($message_parts[$i]); |
|
| 2847 | + } |
|
| 2697 | 2848 | |
| 2698 | 2849 | $message = implode('', $message_parts); |
| 2699 | 2850 | } |
| 2700 | 2851 | |
| 2701 | 2852 | // No smileys, just get rid of the markers. |
| 2702 | - else |
|
| 2703 | - $message = strtr($message, array("\n" => '')); |
|
| 2853 | + else { |
|
| 2854 | + $message = strtr($message, array("\n" => '')); |
|
| 2855 | + } |
|
| 2704 | 2856 | |
| 2705 | - if ($message !== '' && $message[0] === ' ') |
|
| 2706 | - $message = ' ' . substr($message, 1); |
|
| 2857 | + if ($message !== '' && $message[0] === ' ') { |
|
| 2858 | + $message = ' ' . substr($message, 1); |
|
| 2859 | + } |
|
| 2707 | 2860 | |
| 2708 | 2861 | // Cleanup whitespace. |
| 2709 | 2862 | $message = strtr($message, array(' ' => ' ', "\r" => '', "\n" => '<br>', '<br> ' => '<br> ', ' ' => "\n")); |
@@ -2712,15 +2865,16 @@ discard block |
||
| 2712 | 2865 | call_integration_hook('integrate_post_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags)); |
| 2713 | 2866 | |
| 2714 | 2867 | // Cache the output if it took some time... |
| 2715 | - if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) |
|
| 2716 | - cache_put_data($cache_key, $message, 240); |
|
| 2868 | + if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) { |
|
| 2869 | + cache_put_data($cache_key, $message, 240); |
|
| 2870 | + } |
|
| 2717 | 2871 | |
| 2718 | 2872 | // If this was a force parse revert if needed. |
| 2719 | 2873 | if (!empty($parse_tags)) |
| 2720 | 2874 | { |
| 2721 | - if (empty($temp_bbc)) |
|
| 2722 | - $bbc_codes = array(); |
|
| 2723 | - else |
|
| 2875 | + if (empty($temp_bbc)) { |
|
| 2876 | + $bbc_codes = array(); |
|
| 2877 | + } else |
|
| 2724 | 2878 | { |
| 2725 | 2879 | $bbc_codes = $temp_bbc; |
| 2726 | 2880 | unset($temp_bbc); |
@@ -2747,8 +2901,9 @@ discard block |
||
| 2747 | 2901 | static $smileyPregSearch = null, $smileyPregReplacements = array(); |
| 2748 | 2902 | |
| 2749 | 2903 | // No smiley set at all?! |
| 2750 | - if ($user_info['smiley_set'] == 'none' || trim($message) == '') |
|
| 2751 | - return; |
|
| 2904 | + if ($user_info['smiley_set'] == 'none' || trim($message) == '') { |
|
| 2905 | + return; |
|
| 2906 | + } |
|
| 2752 | 2907 | |
| 2753 | 2908 | // If smileyPregSearch hasn't been set, do it now. |
| 2754 | 2909 | if (empty($smileyPregSearch)) |
@@ -2759,8 +2914,7 @@ discard block |
||
| 2759 | 2914 | $smileysfrom = array('>:D', ':D', '::)', '>:(', ':))', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', '0:)'); |
| 2760 | 2915 | $smileysto = array('evil.gif', 'cheesy.gif', 'rolleyes.gif', 'angry.gif', 'laugh.gif', 'smiley.gif', 'wink.gif', 'grin.gif', 'sad.gif', 'shocked.gif', 'cool.gif', 'tongue.gif', 'huh.gif', 'embarrassed.gif', 'lipsrsealed.gif', 'kiss.gif', 'cry.gif', 'undecided.gif', 'azn.gif', 'afro.gif', 'police.gif', 'angel.gif'); |
| 2761 | 2916 | $smileysdescs = array('', $txt['icon_cheesy'], $txt['icon_rolleyes'], $txt['icon_angry'], '', $txt['icon_smiley'], $txt['icon_wink'], $txt['icon_grin'], $txt['icon_sad'], $txt['icon_shocked'], $txt['icon_cool'], $txt['icon_tongue'], $txt['icon_huh'], $txt['icon_embarrassed'], $txt['icon_lips'], $txt['icon_kiss'], $txt['icon_cry'], $txt['icon_undecided'], '', '', '', ''); |
| 2762 | - } |
|
| 2763 | - else |
|
| 2917 | + } else |
|
| 2764 | 2918 | { |
| 2765 | 2919 | // Load the smileys in reverse order by length so they don't get parsed wrong. |
| 2766 | 2920 | if (($temp = cache_get_data('parsing_smileys', 480)) == null) |
@@ -2784,9 +2938,9 @@ discard block |
||
| 2784 | 2938 | $smcFunc['db_free_result']($result); |
| 2785 | 2939 | |
| 2786 | 2940 | cache_put_data('parsing_smileys', array($smileysfrom, $smileysto, $smileysdescs), 480); |
| 2941 | + } else { |
|
| 2942 | + list ($smileysfrom, $smileysto, $smileysdescs) = $temp; |
|
| 2787 | 2943 | } |
| 2788 | - else |
|
| 2789 | - list ($smileysfrom, $smileysto, $smileysdescs) = $temp; |
|
| 2790 | 2944 | } |
| 2791 | 2945 | |
| 2792 | 2946 | // The non-breaking-space is a complex thing... |
@@ -2863,35 +3017,41 @@ discard block |
||
| 2863 | 3017 | global $scripturl, $context, $modSettings, $db_show_debug, $db_cache; |
| 2864 | 3018 | |
| 2865 | 3019 | // In case we have mail to send, better do that - as obExit doesn't always quite make it... |
| 2866 | - if (!empty($context['flush_mail'])) |
|
| 2867 | - // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
| 3020 | + if (!empty($context['flush_mail'])) { |
|
| 3021 | + // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
| 2868 | 3022 | AddMailQueue(true); |
| 3023 | + } |
|
| 2869 | 3024 | |
| 2870 | 3025 | $add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && substr($setLocation, 0, 6) != 'about:'; |
| 2871 | 3026 | |
| 2872 | - if ($add) |
|
| 2873 | - $setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : ''); |
|
| 3027 | + if ($add) { |
|
| 3028 | + $setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : ''); |
|
| 3029 | + } |
|
| 2874 | 3030 | |
| 2875 | 3031 | // Put the session ID in. |
| 2876 | - if (defined('SID') && SID != '') |
|
| 2877 | - $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation); |
|
| 3032 | + if (defined('SID') && SID != '') { |
|
| 3033 | + $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation); |
|
| 3034 | + } |
|
| 2878 | 3035 | // Keep that debug in their for template debugging! |
| 2879 | - elseif (isset($_GET['debug'])) |
|
| 2880 | - $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation); |
|
| 3036 | + elseif (isset($_GET['debug'])) { |
|
| 3037 | + $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation); |
|
| 3038 | + } |
|
| 2881 | 3039 | |
| 2882 | 3040 | if (!empty($modSettings['queryless_urls']) && (empty($context['server']['is_cgi']) || ini_get('cgi.fix_pathinfo') == 1 || @get_cfg_var('cgi.fix_pathinfo') == 1) && (!empty($context['server']['is_apache']) || !empty($context['server']['is_lighttpd']) || !empty($context['server']['is_litespeed']))) |
| 2883 | 3041 | { |
| 2884 | - if (defined('SID') && SID != '') |
|
| 2885 | - $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#]+?)(#[^"]*?)?$~', |
|
| 3042 | + if (defined('SID') && SID != '') { |
|
| 3043 | + $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#]+?)(#[^"]*?)?$~', |
|
| 2886 | 3044 | function ($m) use ($scripturl) |
| 2887 | 3045 | { |
| 2888 | 3046 | return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : ""); |
| 3047 | + } |
|
| 2889 | 3048 | }, $setLocation); |
| 2890 | - else |
|
| 2891 | - $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~', |
|
| 3049 | + else { |
|
| 3050 | + $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~', |
|
| 2892 | 3051 | function ($m) use ($scripturl) |
| 2893 | 3052 | { |
| 2894 | 3053 | return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : ""); |
| 3054 | + } |
|
| 2895 | 3055 | }, $setLocation); |
| 2896 | 3056 | } |
| 2897 | 3057 | |
@@ -2902,8 +3062,9 @@ discard block |
||
| 2902 | 3062 | header('Location: ' . str_replace(' ', '%20', $setLocation), true, $permanent ? 301 : 302); |
| 2903 | 3063 | |
| 2904 | 3064 | // Debugging. |
| 2905 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
| 2906 | - $_SESSION['debug_redirect'] = $db_cache; |
|
| 3065 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
| 3066 | + $_SESSION['debug_redirect'] = $db_cache; |
|
| 3067 | + } |
|
| 2907 | 3068 | |
| 2908 | 3069 | obExit(false); |
| 2909 | 3070 | } |
@@ -2922,51 +3083,60 @@ discard block |
||
| 2922 | 3083 | |
| 2923 | 3084 | // Attempt to prevent a recursive loop. |
| 2924 | 3085 | ++$level; |
| 2925 | - if ($level > 1 && !$from_fatal_error && !$has_fatal_error) |
|
| 2926 | - exit; |
|
| 2927 | - if ($from_fatal_error) |
|
| 2928 | - $has_fatal_error = true; |
|
| 3086 | + if ($level > 1 && !$from_fatal_error && !$has_fatal_error) { |
|
| 3087 | + exit; |
|
| 3088 | + } |
|
| 3089 | + if ($from_fatal_error) { |
|
| 3090 | + $has_fatal_error = true; |
|
| 3091 | + } |
|
| 2929 | 3092 | |
| 2930 | 3093 | // Clear out the stat cache. |
| 2931 | 3094 | trackStats(); |
| 2932 | 3095 | |
| 2933 | 3096 | // If we have mail to send, send it. |
| 2934 | - if (!empty($context['flush_mail'])) |
|
| 2935 | - // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
| 3097 | + if (!empty($context['flush_mail'])) { |
|
| 3098 | + // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
| 2936 | 3099 | AddMailQueue(true); |
| 3100 | + } |
|
| 2937 | 3101 | |
| 2938 | 3102 | $do_header = $header === null ? !$header_done : $header; |
| 2939 | - if ($do_footer === null) |
|
| 2940 | - $do_footer = $do_header; |
|
| 3103 | + if ($do_footer === null) { |
|
| 3104 | + $do_footer = $do_header; |
|
| 3105 | + } |
|
| 2941 | 3106 | |
| 2942 | 3107 | // Has the template/header been done yet? |
| 2943 | 3108 | if ($do_header) |
| 2944 | 3109 | { |
| 2945 | 3110 | // Was the page title set last minute? Also update the HTML safe one. |
| 2946 | - if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) |
|
| 2947 | - $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); |
|
| 3111 | + if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) { |
|
| 3112 | + $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); |
|
| 3113 | + } |
|
| 2948 | 3114 | |
| 2949 | 3115 | // Start up the session URL fixer. |
| 2950 | 3116 | ob_start('ob_sessrewrite'); |
| 2951 | 3117 | |
| 2952 | - if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) |
|
| 2953 | - $buffers = explode(',', $settings['output_buffers']); |
|
| 2954 | - elseif (!empty($settings['output_buffers'])) |
|
| 2955 | - $buffers = $settings['output_buffers']; |
|
| 2956 | - else |
|
| 2957 | - $buffers = array(); |
|
| 3118 | + if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) { |
|
| 3119 | + $buffers = explode(',', $settings['output_buffers']); |
|
| 3120 | + } elseif (!empty($settings['output_buffers'])) { |
|
| 3121 | + $buffers = $settings['output_buffers']; |
|
| 3122 | + } else { |
|
| 3123 | + $buffers = array(); |
|
| 3124 | + } |
|
| 2958 | 3125 | |
| 2959 | - if (isset($modSettings['integrate_buffer'])) |
|
| 2960 | - $buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers); |
|
| 3126 | + if (isset($modSettings['integrate_buffer'])) { |
|
| 3127 | + $buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers); |
|
| 3128 | + } |
|
| 2961 | 3129 | |
| 2962 | - if (!empty($buffers)) |
|
| 2963 | - foreach ($buffers as $function) |
|
| 3130 | + if (!empty($buffers)) { |
|
| 3131 | + foreach ($buffers as $function) |
|
| 2964 | 3132 | { |
| 2965 | 3133 | $call = call_helper($function, true); |
| 3134 | + } |
|
| 2966 | 3135 | |
| 2967 | 3136 | // Is it valid? |
| 2968 | - if (!empty($call)) |
|
| 2969 | - ob_start($call); |
|
| 3137 | + if (!empty($call)) { |
|
| 3138 | + ob_start($call); |
|
| 3139 | + } |
|
| 2970 | 3140 | } |
| 2971 | 3141 | |
| 2972 | 3142 | // Display the screen in the logical order. |
@@ -2978,8 +3148,9 @@ discard block |
||
| 2978 | 3148 | loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main'); |
| 2979 | 3149 | |
| 2980 | 3150 | // Anything special to put out? |
| 2981 | - if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) |
|
| 2982 | - echo $context['insert_after_template']; |
|
| 3151 | + if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) { |
|
| 3152 | + echo $context['insert_after_template']; |
|
| 3153 | + } |
|
| 2983 | 3154 | |
| 2984 | 3155 | // Just so we don't get caught in an endless loop of errors from the footer... |
| 2985 | 3156 | if (!$footer_done) |
@@ -2988,14 +3159,16 @@ discard block |
||
| 2988 | 3159 | template_footer(); |
| 2989 | 3160 | |
| 2990 | 3161 | // (since this is just debugging... it's okay that it's after </html>.) |
| 2991 | - if (!isset($_REQUEST['xml'])) |
|
| 2992 | - displayDebug(); |
|
| 3162 | + if (!isset($_REQUEST['xml'])) { |
|
| 3163 | + displayDebug(); |
|
| 3164 | + } |
|
| 2993 | 3165 | } |
| 2994 | 3166 | } |
| 2995 | 3167 | |
| 2996 | 3168 | // Remember this URL in case someone doesn't like sending HTTP_REFERER. |
| 2997 | - if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) |
|
| 2998 | - $_SESSION['old_url'] = $_SERVER['REQUEST_URL']; |
|
| 3169 | + if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) { |
|
| 3170 | + $_SESSION['old_url'] = $_SERVER['REQUEST_URL']; |
|
| 3171 | + } |
|
| 2999 | 3172 | |
| 3000 | 3173 | // For session check verification.... don't switch browsers... |
| 3001 | 3174 | $_SESSION['USER_AGENT'] = empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT']; |
@@ -3004,9 +3177,10 @@ discard block |
||
| 3004 | 3177 | call_integration_hook('integrate_exit', array($do_footer)); |
| 3005 | 3178 | |
| 3006 | 3179 | // Don't exit if we're coming from index.php; that will pass through normally. |
| 3007 | - if (!$from_index) |
|
| 3008 | - exit; |
|
| 3009 | -} |
|
| 3180 | + if (!$from_index) { |
|
| 3181 | + exit; |
|
| 3182 | + } |
|
| 3183 | + } |
|
| 3010 | 3184 | |
| 3011 | 3185 | /** |
| 3012 | 3186 | * Get the size of a specified image with better error handling. |
@@ -3025,8 +3199,9 @@ discard block |
||
| 3025 | 3199 | $url = str_replace(' ', '%20', $url); |
| 3026 | 3200 | |
| 3027 | 3201 | // Can we pull this from the cache... please please? |
| 3028 | - if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) |
|
| 3029 | - return $temp; |
|
| 3202 | + if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) { |
|
| 3203 | + return $temp; |
|
| 3204 | + } |
|
| 3030 | 3205 | $t = microtime(); |
| 3031 | 3206 | |
| 3032 | 3207 | // Get the host to pester... |
@@ -3036,12 +3211,10 @@ discard block |
||
| 3036 | 3211 | if ($url == '' || $url == 'http://' || $url == 'https://') |
| 3037 | 3212 | { |
| 3038 | 3213 | return false; |
| 3039 | - } |
|
| 3040 | - elseif (!isset($match[1])) |
|
| 3214 | + } elseif (!isset($match[1])) |
|
| 3041 | 3215 | { |
| 3042 | 3216 | $size = @getimagesize($url); |
| 3043 | - } |
|
| 3044 | - else |
|
| 3217 | + } else |
|
| 3045 | 3218 | { |
| 3046 | 3219 | // Try to connect to the server... give it half a second. |
| 3047 | 3220 | $temp = 0; |
@@ -3080,12 +3253,14 @@ discard block |
||
| 3080 | 3253 | } |
| 3081 | 3254 | |
| 3082 | 3255 | // If we didn't get it, we failed. |
| 3083 | - if (!isset($size)) |
|
| 3084 | - $size = false; |
|
| 3256 | + if (!isset($size)) { |
|
| 3257 | + $size = false; |
|
| 3258 | + } |
|
| 3085 | 3259 | |
| 3086 | 3260 | // If this took a long time, we may never have to do it again, but then again we might... |
| 3087 | - if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) |
|
| 3088 | - cache_put_data('url_image_size-' . md5($url), $size, 240); |
|
| 3261 | + if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) { |
|
| 3262 | + cache_put_data('url_image_size-' . md5($url), $size, 240); |
|
| 3263 | + } |
|
| 3089 | 3264 | |
| 3090 | 3265 | // Didn't work. |
| 3091 | 3266 | return $size; |
@@ -3103,8 +3278,9 @@ discard block |
||
| 3103 | 3278 | |
| 3104 | 3279 | // Under SSI this function can be called more then once. That can cause some problems. |
| 3105 | 3280 | // So only run the function once unless we are forced to run it again. |
| 3106 | - if ($loaded && !$forceload) |
|
| 3107 | - return; |
|
| 3281 | + if ($loaded && !$forceload) { |
|
| 3282 | + return; |
|
| 3283 | + } |
|
| 3108 | 3284 | |
| 3109 | 3285 | $loaded = true; |
| 3110 | 3286 | |
@@ -3116,14 +3292,16 @@ discard block |
||
| 3116 | 3292 | $context['news_lines'] = array_filter(explode("\n", str_replace("\r", '', trim(addslashes($modSettings['news']))))); |
| 3117 | 3293 | for ($i = 0, $n = count($context['news_lines']); $i < $n; $i++) |
| 3118 | 3294 | { |
| 3119 | - if (trim($context['news_lines'][$i]) == '') |
|
| 3120 | - continue; |
|
| 3295 | + if (trim($context['news_lines'][$i]) == '') { |
|
| 3296 | + continue; |
|
| 3297 | + } |
|
| 3121 | 3298 | |
| 3122 | 3299 | // Clean it up for presentation ;). |
| 3123 | 3300 | $context['news_lines'][$i] = parse_bbc(stripslashes(trim($context['news_lines'][$i])), true, 'news' . $i); |
| 3124 | 3301 | } |
| 3125 | - if (!empty($context['news_lines'])) |
|
| 3126 | - $context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)]; |
|
| 3302 | + if (!empty($context['news_lines'])) { |
|
| 3303 | + $context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)]; |
|
| 3304 | + } |
|
| 3127 | 3305 | |
| 3128 | 3306 | if (!$user_info['is_guest']) |
| 3129 | 3307 | { |
@@ -3132,40 +3310,48 @@ discard block |
||
| 3132 | 3310 | $context['user']['alerts'] = &$user_info['alerts']; |
| 3133 | 3311 | |
| 3134 | 3312 | // Personal message popup... |
| 3135 | - if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) |
|
| 3136 | - $context['user']['popup_messages'] = true; |
|
| 3137 | - else |
|
| 3138 | - $context['user']['popup_messages'] = false; |
|
| 3313 | + if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) { |
|
| 3314 | + $context['user']['popup_messages'] = true; |
|
| 3315 | + } else { |
|
| 3316 | + $context['user']['popup_messages'] = false; |
|
| 3317 | + } |
|
| 3139 | 3318 | $_SESSION['unread_messages'] = $user_info['unread_messages']; |
| 3140 | 3319 | |
| 3141 | - if (allowedTo('moderate_forum')) |
|
| 3142 | - $context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0; |
|
| 3320 | + if (allowedTo('moderate_forum')) { |
|
| 3321 | + $context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0; |
|
| 3322 | + } |
|
| 3143 | 3323 | |
| 3144 | 3324 | $context['user']['avatar'] = array(); |
| 3145 | 3325 | |
| 3146 | 3326 | // Check for gravatar first since we might be forcing them... |
| 3147 | 3327 | if (($modSettings['gravatarEnabled'] && substr($user_info['avatar']['url'], 0, 11) == 'gravatar://') || !empty($modSettings['gravatarOverride'])) |
| 3148 | 3328 | { |
| 3149 | - if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) |
|
| 3150 | - $context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11)); |
|
| 3151 | - else |
|
| 3152 | - $context['user']['avatar']['href'] = get_gravatar_url($user_info['email']); |
|
| 3329 | + if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) { |
|
| 3330 | + $context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11)); |
|
| 3331 | + } else { |
|
| 3332 | + $context['user']['avatar']['href'] = get_gravatar_url($user_info['email']); |
|
| 3333 | + } |
|
| 3153 | 3334 | } |
| 3154 | 3335 | // Uploaded? |
| 3155 | - elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) |
|
| 3156 | - $context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar'; |
|
| 3336 | + elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) { |
|
| 3337 | + $context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar'; |
|
| 3338 | + } |
|
| 3157 | 3339 | // Full URL? |
| 3158 | - elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) |
|
| 3159 | - $context['user']['avatar']['href'] = $user_info['avatar']['url']; |
|
| 3340 | + elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) { |
|
| 3341 | + $context['user']['avatar']['href'] = $user_info['avatar']['url']; |
|
| 3342 | + } |
|
| 3160 | 3343 | // Otherwise we assume it's server stored. |
| 3161 | - elseif ($user_info['avatar']['url'] != '') |
|
| 3162 | - $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']); |
|
| 3344 | + elseif ($user_info['avatar']['url'] != '') { |
|
| 3345 | + $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']); |
|
| 3346 | + } |
|
| 3163 | 3347 | // No avatar at all? Fine, we have a big fat default avatar ;) |
| 3164 | - else |
|
| 3165 | - $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png'; |
|
| 3348 | + else { |
|
| 3349 | + $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png'; |
|
| 3350 | + } |
|
| 3166 | 3351 | |
| 3167 | - if (!empty($context['user']['avatar'])) |
|
| 3168 | - $context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">'; |
|
| 3352 | + if (!empty($context['user']['avatar'])) { |
|
| 3353 | + $context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">'; |
|
| 3354 | + } |
|
| 3169 | 3355 | |
| 3170 | 3356 | // Figure out how long they've been logged in. |
| 3171 | 3357 | $context['user']['total_time_logged_in'] = array( |
@@ -3173,8 +3359,7 @@ discard block |
||
| 3173 | 3359 | 'hours' => floor(($user_info['total_time_logged_in'] % 86400) / 3600), |
| 3174 | 3360 | 'minutes' => floor(($user_info['total_time_logged_in'] % 3600) / 60) |
| 3175 | 3361 | ); |
| 3176 | - } |
|
| 3177 | - else |
|
| 3362 | + } else |
|
| 3178 | 3363 | { |
| 3179 | 3364 | $context['user']['messages'] = 0; |
| 3180 | 3365 | $context['user']['unread_messages'] = 0; |
@@ -3182,12 +3367,14 @@ discard block |
||
| 3182 | 3367 | $context['user']['total_time_logged_in'] = array('days' => 0, 'hours' => 0, 'minutes' => 0); |
| 3183 | 3368 | $context['user']['popup_messages'] = false; |
| 3184 | 3369 | |
| 3185 | - if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) |
|
| 3186 | - $txt['welcome_guest'] .= $txt['welcome_guest_activate']; |
|
| 3370 | + if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) { |
|
| 3371 | + $txt['welcome_guest'] .= $txt['welcome_guest_activate']; |
|
| 3372 | + } |
|
| 3187 | 3373 | |
| 3188 | 3374 | // If we've upgraded recently, go easy on the passwords. |
| 3189 | - if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) |
|
| 3190 | - $context['disable_login_hashing'] = true; |
|
| 3375 | + if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) { |
|
| 3376 | + $context['disable_login_hashing'] = true; |
|
| 3377 | + } |
|
| 3191 | 3378 | } |
| 3192 | 3379 | |
| 3193 | 3380 | // Setup the main menu items. |
@@ -3200,8 +3387,8 @@ discard block |
||
| 3200 | 3387 | $context['show_pm_popup'] = $context['user']['popup_messages'] && !empty($options['popup_messages']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'pm'); |
| 3201 | 3388 | |
| 3202 | 3389 | // 2.1+: Add the PM popup here instead. Theme authors can still override it simply by editing/removing the 'fPmPopup' in the array. |
| 3203 | - if ($context['show_pm_popup']) |
|
| 3204 | - addInlineJavaScript(' |
|
| 3390 | + if ($context['show_pm_popup']) { |
|
| 3391 | + addInlineJavaScript(' |
|
| 3205 | 3392 | jQuery(document).ready(function($) { |
| 3206 | 3393 | new smc_Popup({ |
| 3207 | 3394 | heading: ' . JavaScriptEscape($txt['show_personal_messages_heading']) . ', |
@@ -3209,15 +3396,17 @@ discard block |
||
| 3209 | 3396 | icon_class: \'generic_icons mail_new\' |
| 3210 | 3397 | }); |
| 3211 | 3398 | });'); |
| 3399 | + } |
|
| 3212 | 3400 | |
| 3213 | 3401 | // Add a generic "Are you sure?" confirmation message. |
| 3214 | 3402 | addInlineJavaScript(' |
| 3215 | 3403 | var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';'); |
| 3216 | 3404 | |
| 3217 | 3405 | // Now add the capping code for avatars. |
| 3218 | - if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize') |
|
| 3219 | - addInlineCss(' |
|
| 3406 | + if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize') { |
|
| 3407 | + addInlineCss(' |
|
| 3220 | 3408 | img.avatar { max-width: ' . $modSettings['avatar_max_width_external'] . 'px; max-height: ' . $modSettings['avatar_max_height_external'] . 'px; }'); |
| 3409 | + } |
|
| 3221 | 3410 | |
| 3222 | 3411 | // This looks weird, but it's because BoardIndex.php references the variable. |
| 3223 | 3412 | $context['common_stats']['latest_member'] = array( |
@@ -3234,11 +3423,13 @@ discard block |
||
| 3234 | 3423 | ); |
| 3235 | 3424 | $context['common_stats']['boardindex_total_posts'] = sprintf($txt['boardindex_total_posts'], $context['common_stats']['total_posts'], $context['common_stats']['total_topics'], $context['common_stats']['total_members']); |
| 3236 | 3425 | |
| 3237 | - if (empty($settings['theme_version'])) |
|
| 3238 | - addJavaScriptVar('smf_scripturl', $scripturl); |
|
| 3426 | + if (empty($settings['theme_version'])) { |
|
| 3427 | + addJavaScriptVar('smf_scripturl', $scripturl); |
|
| 3428 | + } |
|
| 3239 | 3429 | |
| 3240 | - if (!isset($context['page_title'])) |
|
| 3241 | - $context['page_title'] = ''; |
|
| 3430 | + if (!isset($context['page_title'])) { |
|
| 3431 | + $context['page_title'] = ''; |
|
| 3432 | + } |
|
| 3242 | 3433 | |
| 3243 | 3434 | // Set some specific vars. |
| 3244 | 3435 | $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); |
@@ -3248,21 +3439,23 @@ discard block |
||
| 3248 | 3439 | $context['meta_tags'][] = array('property' => 'og:site_name', 'content' => $context['forum_name']); |
| 3249 | 3440 | $context['meta_tags'][] = array('property' => 'og:title', 'content' => $context['page_title_html_safe']); |
| 3250 | 3441 | |
| 3251 | - if (!empty($context['meta_keywords'])) |
|
| 3252 | - $context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']); |
|
| 3442 | + if (!empty($context['meta_keywords'])) { |
|
| 3443 | + $context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']); |
|
| 3444 | + } |
|
| 3253 | 3445 | |
| 3254 | - if (!empty($context['canonical_url'])) |
|
| 3255 | - $context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']); |
|
| 3446 | + if (!empty($context['canonical_url'])) { |
|
| 3447 | + $context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']); |
|
| 3448 | + } |
|
| 3256 | 3449 | |
| 3257 | - if (!empty($settings['og_image'])) |
|
| 3258 | - $context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']); |
|
| 3450 | + if (!empty($settings['og_image'])) { |
|
| 3451 | + $context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']); |
|
| 3452 | + } |
|
| 3259 | 3453 | |
| 3260 | 3454 | if (!empty($context['meta_description'])) |
| 3261 | 3455 | { |
| 3262 | 3456 | $context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['meta_description']); |
| 3263 | 3457 | $context['meta_tags'][] = array('name' => 'description', 'content' => $context['meta_description']); |
| 3264 | - } |
|
| 3265 | - else |
|
| 3458 | + } else |
|
| 3266 | 3459 | { |
| 3267 | 3460 | $context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['page_title_html_safe']); |
| 3268 | 3461 | $context['meta_tags'][] = array('name' => 'description', 'content' => $context['page_title_html_safe']); |
@@ -3287,8 +3480,9 @@ discard block |
||
| 3287 | 3480 | $memory_needed = memoryReturnBytes($needed); |
| 3288 | 3481 | |
| 3289 | 3482 | // should we account for how much is currently being used? |
| 3290 | - if ($in_use) |
|
| 3291 | - $memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576); |
|
| 3483 | + if ($in_use) { |
|
| 3484 | + $memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576); |
|
| 3485 | + } |
|
| 3292 | 3486 | |
| 3293 | 3487 | // if more is needed, request it |
| 3294 | 3488 | if ($memory_current < $memory_needed) |
@@ -3311,8 +3505,9 @@ discard block |
||
| 3311 | 3505 | */ |
| 3312 | 3506 | function memoryReturnBytes($val) |
| 3313 | 3507 | { |
| 3314 | - if (is_integer($val)) |
|
| 3315 | - return $val; |
|
| 3508 | + if (is_integer($val)) { |
|
| 3509 | + return $val; |
|
| 3510 | + } |
|
| 3316 | 3511 | |
| 3317 | 3512 | // Separate the number from the designator |
| 3318 | 3513 | $val = trim($val); |
@@ -3348,10 +3543,11 @@ discard block |
||
| 3348 | 3543 | header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); |
| 3349 | 3544 | |
| 3350 | 3545 | // Are we debugging the template/html content? |
| 3351 | - if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) |
|
| 3352 | - header('Content-Type: application/xhtml+xml'); |
|
| 3353 | - elseif (!isset($_REQUEST['xml'])) |
|
| 3354 | - header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
| 3546 | + if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) { |
|
| 3547 | + header('Content-Type: application/xhtml+xml'); |
|
| 3548 | + } elseif (!isset($_REQUEST['xml'])) { |
|
| 3549 | + header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
| 3550 | + } |
|
| 3355 | 3551 | } |
| 3356 | 3552 | |
| 3357 | 3553 | header('Content-Type: text/' . (isset($_REQUEST['xml']) ? 'xml' : 'html') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
@@ -3360,8 +3556,9 @@ discard block |
||
| 3360 | 3556 | if ($context['in_maintenance'] && $context['user']['is_admin']) |
| 3361 | 3557 | { |
| 3362 | 3558 | $position = array_search('body', $context['template_layers']); |
| 3363 | - if ($position === false) |
|
| 3364 | - $position = array_search('main', $context['template_layers']); |
|
| 3559 | + if ($position === false) { |
|
| 3560 | + $position = array_search('main', $context['template_layers']); |
|
| 3561 | + } |
|
| 3365 | 3562 | |
| 3366 | 3563 | if ($position !== false) |
| 3367 | 3564 | { |
@@ -3389,23 +3586,25 @@ discard block |
||
| 3389 | 3586 | |
| 3390 | 3587 | foreach ($securityFiles as $i => $securityFile) |
| 3391 | 3588 | { |
| 3392 | - if (!file_exists($boarddir . '/' . $securityFile)) |
|
| 3393 | - unset($securityFiles[$i]); |
|
| 3589 | + if (!file_exists($boarddir . '/' . $securityFile)) { |
|
| 3590 | + unset($securityFiles[$i]); |
|
| 3591 | + } |
|
| 3394 | 3592 | } |
| 3395 | 3593 | |
| 3396 | 3594 | // We are already checking so many files...just few more doesn't make any difference! :P |
| 3397 | - if (!empty($modSettings['currentAttachmentUploadDir'])) |
|
| 3398 | - $path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; |
|
| 3399 | - |
|
| 3400 | - else |
|
| 3401 | - $path = $modSettings['attachmentUploadDir']; |
|
| 3595 | + if (!empty($modSettings['currentAttachmentUploadDir'])) { |
|
| 3596 | + $path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; |
|
| 3597 | + } else { |
|
| 3598 | + $path = $modSettings['attachmentUploadDir']; |
|
| 3599 | + } |
|
| 3402 | 3600 | |
| 3403 | 3601 | secureDirectory($path, true); |
| 3404 | 3602 | secureDirectory($cachedir); |
| 3405 | 3603 | |
| 3406 | 3604 | // If agreement is enabled, at least the english version shall exists |
| 3407 | - if ($modSettings['requireAgreement']) |
|
| 3408 | - $agreement = !file_exists($boarddir . '/agreement.txt'); |
|
| 3605 | + if ($modSettings['requireAgreement']) { |
|
| 3606 | + $agreement = !file_exists($boarddir . '/agreement.txt'); |
|
| 3607 | + } |
|
| 3409 | 3608 | |
| 3410 | 3609 | if (!empty($securityFiles) || (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) || !empty($agreement)) |
| 3411 | 3610 | { |
@@ -3420,18 +3619,21 @@ discard block |
||
| 3420 | 3619 | echo ' |
| 3421 | 3620 | ', $txt['not_removed'], '<strong>', $securityFile, '</strong>!<br>'; |
| 3422 | 3621 | |
| 3423 | - if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') |
|
| 3424 | - echo ' |
|
| 3622 | + if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') { |
|
| 3623 | + echo ' |
|
| 3425 | 3624 | ', sprintf($txt['not_removed_extra'], $securityFile, substr($securityFile, 0, -1)), '<br>'; |
| 3625 | + } |
|
| 3426 | 3626 | } |
| 3427 | 3627 | |
| 3428 | - if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) |
|
| 3429 | - echo ' |
|
| 3628 | + if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) { |
|
| 3629 | + echo ' |
|
| 3430 | 3630 | <strong>', $txt['cache_writable'], '</strong><br>'; |
| 3631 | + } |
|
| 3431 | 3632 | |
| 3432 | - if (!empty($agreement)) |
|
| 3433 | - echo ' |
|
| 3633 | + if (!empty($agreement)) { |
|
| 3634 | + echo ' |
|
| 3434 | 3635 | <strong>', $txt['agreement_missing'], '</strong><br>'; |
| 3636 | + } |
|
| 3435 | 3637 | |
| 3436 | 3638 | echo ' |
| 3437 | 3639 | </p> |
@@ -3446,16 +3648,18 @@ discard block |
||
| 3446 | 3648 | <div class="windowbg alert" style="margin: 2ex; padding: 2ex; border: 2px dashed red;"> |
| 3447 | 3649 | ', sprintf($txt['you_are_post_banned'], $user_info['is_guest'] ? $txt['guest_title'] : $user_info['name']); |
| 3448 | 3650 | |
| 3449 | - if (!empty($_SESSION['ban']['cannot_post']['reason'])) |
|
| 3450 | - echo ' |
|
| 3651 | + if (!empty($_SESSION['ban']['cannot_post']['reason'])) { |
|
| 3652 | + echo ' |
|
| 3451 | 3653 | <div style="padding-left: 4ex; padding-top: 1ex;">', $_SESSION['ban']['cannot_post']['reason'], '</div>'; |
| 3654 | + } |
|
| 3452 | 3655 | |
| 3453 | - if (!empty($_SESSION['ban']['expire_time'])) |
|
| 3454 | - echo ' |
|
| 3656 | + if (!empty($_SESSION['ban']['expire_time'])) { |
|
| 3657 | + echo ' |
|
| 3455 | 3658 | <div>', sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)), '</div>'; |
| 3456 | - else |
|
| 3457 | - echo ' |
|
| 3659 | + } else { |
|
| 3660 | + echo ' |
|
| 3458 | 3661 | <div>', $txt['your_ban_expires_never'], '</div>'; |
| 3662 | + } |
|
| 3459 | 3663 | |
| 3460 | 3664 | echo ' |
| 3461 | 3665 | </div>'; |
@@ -3471,8 +3675,9 @@ discard block |
||
| 3471 | 3675 | global $forum_copyright, $software_year, $forum_version; |
| 3472 | 3676 | |
| 3473 | 3677 | // Don't display copyright for things like SSI. |
| 3474 | - if (!isset($forum_version) || !isset($software_year)) |
|
| 3475 | - return; |
|
| 3678 | + if (!isset($forum_version) || !isset($software_year)) { |
|
| 3679 | + return; |
|
| 3680 | + } |
|
| 3476 | 3681 | |
| 3477 | 3682 | // Put in the version... |
| 3478 | 3683 | printf($forum_copyright, $forum_version, $software_year); |
@@ -3490,9 +3695,10 @@ discard block |
||
| 3490 | 3695 | $context['load_time'] = round(microtime(true) - $time_start, 3); |
| 3491 | 3696 | $context['load_queries'] = $db_count; |
| 3492 | 3697 | |
| 3493 | - foreach (array_reverse($context['template_layers']) as $layer) |
|
| 3494 | - loadSubTemplate($layer . '_below', true); |
|
| 3495 | -} |
|
| 3698 | + foreach (array_reverse($context['template_layers']) as $layer) { |
|
| 3699 | + loadSubTemplate($layer . '_below', true); |
|
| 3700 | + } |
|
| 3701 | + } |
|
| 3496 | 3702 | |
| 3497 | 3703 | /** |
| 3498 | 3704 | * Output the Javascript files |
@@ -3523,8 +3729,7 @@ discard block |
||
| 3523 | 3729 | { |
| 3524 | 3730 | echo ' |
| 3525 | 3731 | var ', $key, ';'; |
| 3526 | - } |
|
| 3527 | - else |
|
| 3732 | + } else |
|
| 3528 | 3733 | { |
| 3529 | 3734 | echo ' |
| 3530 | 3735 | var ', $key, ' = ', $value, ';'; |
@@ -3539,26 +3744,27 @@ discard block |
||
| 3539 | 3744 | foreach ($context['javascript_files'] as $id => $js_file) |
| 3540 | 3745 | { |
| 3541 | 3746 | // Last minute call! allow theme authors to disable single files. |
| 3542 | - if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) |
|
| 3543 | - continue; |
|
| 3747 | + if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) { |
|
| 3748 | + continue; |
|
| 3749 | + } |
|
| 3544 | 3750 | |
| 3545 | 3751 | // By default all files don't get minimized unless the file explicitly says so! |
| 3546 | 3752 | if (!empty($js_file['options']['minimize']) && !empty($modSettings['minimize_files'])) |
| 3547 | 3753 | { |
| 3548 | - if ($do_deferred && !empty($js_file['options']['defer'])) |
|
| 3549 | - $toMinifyDefer[] = $js_file; |
|
| 3550 | - |
|
| 3551 | - elseif (!$do_deferred && empty($js_file['options']['defer'])) |
|
| 3552 | - $toMinify[] = $js_file; |
|
| 3754 | + if ($do_deferred && !empty($js_file['options']['defer'])) { |
|
| 3755 | + $toMinifyDefer[] = $js_file; |
|
| 3756 | + } elseif (!$do_deferred && empty($js_file['options']['defer'])) { |
|
| 3757 | + $toMinify[] = $js_file; |
|
| 3758 | + } |
|
| 3553 | 3759 | |
| 3554 | 3760 | // Grab a random seed. |
| 3555 | - if (!isset($minSeed)) |
|
| 3556 | - $minSeed = $js_file['options']['seed']; |
|
| 3557 | - } |
|
| 3558 | - |
|
| 3559 | - elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer']))) |
|
| 3560 | - echo ' |
|
| 3761 | + if (!isset($minSeed)) { |
|
| 3762 | + $minSeed = $js_file['options']['seed']; |
|
| 3763 | + } |
|
| 3764 | + } elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer']))) { |
|
| 3765 | + echo ' |
|
| 3561 | 3766 | <script src="', $js_file['fileUrl'], '"', !empty($js_file['options']['async']) ? ' async="async"' : '', '></script>'; |
| 3767 | + } |
|
| 3562 | 3768 | } |
| 3563 | 3769 | |
| 3564 | 3770 | if ((!$do_deferred && !empty($toMinify)) || ($do_deferred && !empty($toMinifyDefer))) |
@@ -3566,14 +3772,14 @@ discard block |
||
| 3566 | 3772 | $result = custMinify(($do_deferred ? $toMinifyDefer : $toMinify), 'js', $do_deferred); |
| 3567 | 3773 | |
| 3568 | 3774 | // Minify process couldn't work, print each individual files. |
| 3569 | - if (!empty($result) && is_array($result)) |
|
| 3570 | - foreach ($result as $minFailedFile) |
|
| 3775 | + if (!empty($result) && is_array($result)) { |
|
| 3776 | + foreach ($result as $minFailedFile) |
|
| 3571 | 3777 | echo ' |
| 3572 | 3778 | <script src="', $minFailedFile['fileUrl'], '"', !empty($minFailedFile['options']['async']) ? ' async="async"' : '', '></script>'; |
| 3573 | - |
|
| 3574 | - else |
|
| 3575 | - echo ' |
|
| 3779 | + } else { |
|
| 3780 | + echo ' |
|
| 3576 | 3781 | <script src="', $settings['theme_url'] ,'/scripts/minified', ($do_deferred ? '_deferred' : '') ,'.js', $minSeed ,'"></script>'; |
| 3782 | + } |
|
| 3577 | 3783 | } |
| 3578 | 3784 | |
| 3579 | 3785 | // Inline JavaScript - Actually useful some times! |
@@ -3584,8 +3790,9 @@ discard block |
||
| 3584 | 3790 | echo ' |
| 3585 | 3791 | <script>'; |
| 3586 | 3792 | |
| 3587 | - foreach ($context['javascript_inline']['defer'] as $js_code) |
|
| 3588 | - echo $js_code; |
|
| 3793 | + foreach ($context['javascript_inline']['defer'] as $js_code) { |
|
| 3794 | + echo $js_code; |
|
| 3795 | + } |
|
| 3589 | 3796 | |
| 3590 | 3797 | echo ' |
| 3591 | 3798 | </script>'; |
@@ -3596,8 +3803,9 @@ discard block |
||
| 3596 | 3803 | echo ' |
| 3597 | 3804 | <script>'; |
| 3598 | 3805 | |
| 3599 | - foreach ($context['javascript_inline']['standard'] as $js_code) |
|
| 3600 | - echo $js_code; |
|
| 3806 | + foreach ($context['javascript_inline']['standard'] as $js_code) { |
|
| 3807 | + echo $js_code; |
|
| 3808 | + } |
|
| 3601 | 3809 | |
| 3602 | 3810 | echo ' |
| 3603 | 3811 | </script>'; |
@@ -3622,8 +3830,9 @@ discard block |
||
| 3622 | 3830 | foreach ($context['css_files'] as $id => $file) |
| 3623 | 3831 | { |
| 3624 | 3832 | // Last minute call! allow theme authors to disable single files. |
| 3625 | - if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) |
|
| 3626 | - continue; |
|
| 3833 | + if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) { |
|
| 3834 | + continue; |
|
| 3835 | + } |
|
| 3627 | 3836 | |
| 3628 | 3837 | // By default all files don't get minimized unless the file explicitly says so! |
| 3629 | 3838 | if (!empty($file['options']['minimize']) && !empty($modSettings['minimize_files'])) |
@@ -3631,12 +3840,12 @@ discard block |
||
| 3631 | 3840 | $toMinify[] = $file; |
| 3632 | 3841 | |
| 3633 | 3842 | // Grab a random seed. |
| 3634 | - if (!isset($minSeed)) |
|
| 3635 | - $minSeed = $file['options']['seed']; |
|
| 3843 | + if (!isset($minSeed)) { |
|
| 3844 | + $minSeed = $file['options']['seed']; |
|
| 3845 | + } |
|
| 3846 | + } else { |
|
| 3847 | + $normal[] = $file['fileUrl']; |
|
| 3636 | 3848 | } |
| 3637 | - |
|
| 3638 | - else |
|
| 3639 | - $normal[] = $file['fileUrl']; |
|
| 3640 | 3849 | } |
| 3641 | 3850 | |
| 3642 | 3851 | if (!empty($toMinify)) |
@@ -3644,28 +3853,30 @@ discard block |
||
| 3644 | 3853 | $result = custMinify($toMinify, 'css'); |
| 3645 | 3854 | |
| 3646 | 3855 | // Minify process couldn't work, print each individual files. |
| 3647 | - if (!empty($result) && is_array($result)) |
|
| 3648 | - foreach ($result as $minFailedFile) |
|
| 3856 | + if (!empty($result) && is_array($result)) { |
|
| 3857 | + foreach ($result as $minFailedFile) |
|
| 3649 | 3858 | echo ' |
| 3650 | 3859 | <link rel="stylesheet" href="', $minFailedFile['fileUrl'], '">'; |
| 3651 | - |
|
| 3652 | - else |
|
| 3653 | - echo ' |
|
| 3860 | + } else { |
|
| 3861 | + echo ' |
|
| 3654 | 3862 | <link rel="stylesheet" href="', $settings['theme_url'] ,'/css/minified.css', $minSeed ,'">'; |
| 3863 | + } |
|
| 3655 | 3864 | } |
| 3656 | 3865 | |
| 3657 | 3866 | // Print the rest after the minified files. |
| 3658 | - if (!empty($normal)) |
|
| 3659 | - foreach ($normal as $nf) |
|
| 3867 | + if (!empty($normal)) { |
|
| 3868 | + foreach ($normal as $nf) |
|
| 3660 | 3869 | echo ' |
| 3661 | 3870 | <link rel="stylesheet" href="', $nf ,'">'; |
| 3871 | + } |
|
| 3662 | 3872 | |
| 3663 | 3873 | if ($db_show_debug === true) |
| 3664 | 3874 | { |
| 3665 | 3875 | // Try to keep only what's useful. |
| 3666 | 3876 | $repl = array($boardurl . '/Themes/' => '', $boardurl . '/' => ''); |
| 3667 | - foreach ($context['css_files'] as $file) |
|
| 3668 | - $context['debug']['sheets'][] = strtr($file['fileName'], $repl); |
|
| 3877 | + foreach ($context['css_files'] as $file) { |
|
| 3878 | + $context['debug']['sheets'][] = strtr($file['fileName'], $repl); |
|
| 3879 | + } |
|
| 3669 | 3880 | } |
| 3670 | 3881 | |
| 3671 | 3882 | if (!empty($context['css_header'])) |
@@ -3673,9 +3884,10 @@ discard block |
||
| 3673 | 3884 | echo ' |
| 3674 | 3885 | <style>'; |
| 3675 | 3886 | |
| 3676 | - foreach ($context['css_header'] as $css) |
|
| 3677 | - echo $css .' |
|
| 3887 | + foreach ($context['css_header'] as $css) { |
|
| 3888 | + echo $css .' |
|
| 3678 | 3889 | '; |
| 3890 | + } |
|
| 3679 | 3891 | |
| 3680 | 3892 | echo' |
| 3681 | 3893 | </style>'; |
@@ -3699,15 +3911,17 @@ discard block |
||
| 3699 | 3911 | $type = !empty($type) && in_array($type, $types) ? $type : false; |
| 3700 | 3912 | $data = !empty($data) ? $data : false; |
| 3701 | 3913 | |
| 3702 | - if (empty($type) || empty($data)) |
|
| 3703 | - return false; |
|
| 3914 | + if (empty($type) || empty($data)) { |
|
| 3915 | + return false; |
|
| 3916 | + } |
|
| 3704 | 3917 | |
| 3705 | 3918 | // Did we already did this? |
| 3706 | 3919 | $toCache = cache_get_data('minimized_'. $settings['theme_id'] .'_'. $type, 86400); |
| 3707 | 3920 | |
| 3708 | 3921 | // Already done? |
| 3709 | - if (!empty($toCache)) |
|
| 3710 | - return true; |
|
| 3922 | + if (!empty($toCache)) { |
|
| 3923 | + return true; |
|
| 3924 | + } |
|
| 3711 | 3925 | |
| 3712 | 3926 | // No namespaces, sorry! |
| 3713 | 3927 | $classType = 'MatthiasMullie\\Minify\\'. strtoupper($type); |
@@ -3789,8 +4003,9 @@ discard block |
||
| 3789 | 4003 | global $modSettings, $smcFunc; |
| 3790 | 4004 | |
| 3791 | 4005 | // Just make up a nice hash... |
| 3792 | - if ($new) |
|
| 3793 | - return sha1(md5($filename . time()) . mt_rand()); |
|
| 4006 | + if ($new) { |
|
| 4007 | + return sha1(md5($filename . time()) . mt_rand()); |
|
| 4008 | + } |
|
| 3794 | 4009 | |
| 3795 | 4010 | // Just make sure that attachment id is only a int |
| 3796 | 4011 | $attachment_id = (int) $attachment_id; |
@@ -3807,23 +4022,25 @@ discard block |
||
| 3807 | 4022 | 'id_attach' => $attachment_id, |
| 3808 | 4023 | )); |
| 3809 | 4024 | |
| 3810 | - if ($smcFunc['db_num_rows']($request) === 0) |
|
| 3811 | - return false; |
|
| 4025 | + if ($smcFunc['db_num_rows']($request) === 0) { |
|
| 4026 | + return false; |
|
| 4027 | + } |
|
| 3812 | 4028 | |
| 3813 | 4029 | list ($file_hash) = $smcFunc['db_fetch_row']($request); |
| 3814 | 4030 | $smcFunc['db_free_result']($request); |
| 3815 | 4031 | } |
| 3816 | 4032 | |
| 3817 | 4033 | // Still no hash? mmm... |
| 3818 | - if (empty($file_hash)) |
|
| 3819 | - $file_hash = sha1(md5($filename . time()) . mt_rand()); |
|
| 4034 | + if (empty($file_hash)) { |
|
| 4035 | + $file_hash = sha1(md5($filename . time()) . mt_rand()); |
|
| 4036 | + } |
|
| 3820 | 4037 | |
| 3821 | 4038 | // Are we using multiple directories? |
| 3822 | - if (is_array($modSettings['attachmentUploadDir'])) |
|
| 3823 | - $path = $modSettings['attachmentUploadDir'][$dir]; |
|
| 3824 | - |
|
| 3825 | - else |
|
| 3826 | - $path = $modSettings['attachmentUploadDir']; |
|
| 4039 | + if (is_array($modSettings['attachmentUploadDir'])) { |
|
| 4040 | + $path = $modSettings['attachmentUploadDir'][$dir]; |
|
| 4041 | + } else { |
|
| 4042 | + $path = $modSettings['attachmentUploadDir']; |
|
| 4043 | + } |
|
| 3827 | 4044 | |
| 3828 | 4045 | return $path . '/' . $attachment_id . '_' . $file_hash .'.dat'; |
| 3829 | 4046 | } |
@@ -3838,8 +4055,9 @@ discard block |
||
| 3838 | 4055 | function ip2range($fullip) |
| 3839 | 4056 | { |
| 3840 | 4057 | // Pretend that 'unknown' is 255.255.255.255. (since that can't be an IP anyway.) |
| 3841 | - if ($fullip == 'unknown') |
|
| 3842 | - $fullip = '255.255.255.255'; |
|
| 4058 | + if ($fullip == 'unknown') { |
|
| 4059 | + $fullip = '255.255.255.255'; |
|
| 4060 | + } |
|
| 3843 | 4061 | |
| 3844 | 4062 | $ip_parts = explode('-', $fullip); |
| 3845 | 4063 | $ip_array = array(); |
@@ -3863,10 +4081,11 @@ discard block |
||
| 3863 | 4081 | $ip_array['low'] = $ip_parts[0]; |
| 3864 | 4082 | $ip_array['high'] = $ip_parts[1]; |
| 3865 | 4083 | return $ip_array; |
| 3866 | - } |
|
| 3867 | - elseif (count($ip_parts) == 2) // if ip 22.22.*-22.22.* |
|
| 4084 | + } elseif (count($ip_parts) == 2) { |
|
| 4085 | + // if ip 22.22.*-22.22.* |
|
| 3868 | 4086 | { |
| 3869 | 4087 | $valid_low = isValidIP($ip_parts[0]); |
| 4088 | + } |
|
| 3870 | 4089 | $valid_high = isValidIP($ip_parts[1]); |
| 3871 | 4090 | $count = 0; |
| 3872 | 4091 | $mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.'); |
@@ -3881,7 +4100,9 @@ discard block |
||
| 3881 | 4100 | $ip_parts[0] .= $mode . $min; |
| 3882 | 4101 | $valid_low = isValidIP($ip_parts[0]); |
| 3883 | 4102 | $count++; |
| 3884 | - if ($count > 9) break; |
|
| 4103 | + if ($count > 9) { |
|
| 4104 | + break; |
|
| 4105 | + } |
|
| 3885 | 4106 | } |
| 3886 | 4107 | } |
| 3887 | 4108 | |
@@ -3895,7 +4116,9 @@ discard block |
||
| 3895 | 4116 | $ip_parts[1] .= $mode . $max; |
| 3896 | 4117 | $valid_high = isValidIP($ip_parts[1]); |
| 3897 | 4118 | $count++; |
| 3898 | - if ($count > 9) break; |
|
| 4119 | + if ($count > 9) { |
|
| 4120 | + break; |
|
| 4121 | + } |
|
| 3899 | 4122 | } |
| 3900 | 4123 | } |
| 3901 | 4124 | |
@@ -3920,46 +4143,54 @@ discard block |
||
| 3920 | 4143 | { |
| 3921 | 4144 | global $modSettings; |
| 3922 | 4145 | |
| 3923 | - if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) |
|
| 3924 | - return $host; |
|
| 4146 | + if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) { |
|
| 4147 | + return $host; |
|
| 4148 | + } |
|
| 3925 | 4149 | $t = microtime(); |
| 3926 | 4150 | |
| 3927 | 4151 | // Try the Linux host command, perhaps? |
| 3928 | 4152 | if (!isset($host) && (strpos(strtolower(PHP_OS), 'win') === false || strpos(strtolower(PHP_OS), 'darwin') !== false) && mt_rand(0, 1) == 1) |
| 3929 | 4153 | { |
| 3930 | - if (!isset($modSettings['host_to_dis'])) |
|
| 3931 | - $test = @shell_exec('host -W 1 ' . @escapeshellarg($ip)); |
|
| 3932 | - else |
|
| 3933 | - $test = @shell_exec('host ' . @escapeshellarg($ip)); |
|
| 4154 | + if (!isset($modSettings['host_to_dis'])) { |
|
| 4155 | + $test = @shell_exec('host -W 1 ' . @escapeshellarg($ip)); |
|
| 4156 | + } else { |
|
| 4157 | + $test = @shell_exec('host ' . @escapeshellarg($ip)); |
|
| 4158 | + } |
|
| 3934 | 4159 | |
| 3935 | 4160 | // Did host say it didn't find anything? |
| 3936 | - if (strpos($test, 'not found') !== false) |
|
| 3937 | - $host = ''; |
|
| 4161 | + if (strpos($test, 'not found') !== false) { |
|
| 4162 | + $host = ''; |
|
| 4163 | + } |
|
| 3938 | 4164 | // Invalid server option? |
| 3939 | - elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) |
|
| 3940 | - updateSettings(array('host_to_dis' => 1)); |
|
| 4165 | + elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) { |
|
| 4166 | + updateSettings(array('host_to_dis' => 1)); |
|
| 4167 | + } |
|
| 3941 | 4168 | // Maybe it found something, after all? |
| 3942 | - elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) |
|
| 3943 | - $host = $match[1]; |
|
| 4169 | + elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) { |
|
| 4170 | + $host = $match[1]; |
|
| 4171 | + } |
|
| 3944 | 4172 | } |
| 3945 | 4173 | |
| 3946 | 4174 | // This is nslookup; usually only Windows, but possibly some Unix? |
| 3947 | 4175 | if (!isset($host) && stripos(PHP_OS, 'win') !== false && strpos(strtolower(PHP_OS), 'darwin') === false && mt_rand(0, 1) == 1) |
| 3948 | 4176 | { |
| 3949 | 4177 | $test = @shell_exec('nslookup -timeout=1 ' . @escapeshellarg($ip)); |
| 3950 | - if (strpos($test, 'Non-existent domain') !== false) |
|
| 3951 | - $host = ''; |
|
| 3952 | - elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) |
|
| 3953 | - $host = $match[1]; |
|
| 4178 | + if (strpos($test, 'Non-existent domain') !== false) { |
|
| 4179 | + $host = ''; |
|
| 4180 | + } elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) { |
|
| 4181 | + $host = $match[1]; |
|
| 4182 | + } |
|
| 3954 | 4183 | } |
| 3955 | 4184 | |
| 3956 | 4185 | // This is the last try :/. |
| 3957 | - if (!isset($host) || $host === false) |
|
| 3958 | - $host = @gethostbyaddr($ip); |
|
| 4186 | + if (!isset($host) || $host === false) { |
|
| 4187 | + $host = @gethostbyaddr($ip); |
|
| 4188 | + } |
|
| 3959 | 4189 | |
| 3960 | 4190 | // It took a long time, so let's cache it! |
| 3961 | - if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) |
|
| 3962 | - cache_put_data('hostlookup-' . $ip, $host, 600); |
|
| 4191 | + if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) { |
|
| 4192 | + cache_put_data('hostlookup-' . $ip, $host, 600); |
|
| 4193 | + } |
|
| 3963 | 4194 | |
| 3964 | 4195 | return $host; |
| 3965 | 4196 | } |
@@ -3995,20 +4226,21 @@ discard block |
||
| 3995 | 4226 | { |
| 3996 | 4227 | $encrypted = substr(crypt($word, 'uk'), 2, $max_chars); |
| 3997 | 4228 | $total = 0; |
| 3998 | - for ($i = 0; $i < $max_chars; $i++) |
|
| 3999 | - $total += $possible_chars[ord($encrypted{$i})] * pow(63, $i); |
|
| 4229 | + for ($i = 0; $i < $max_chars; $i++) { |
|
| 4230 | + $total += $possible_chars[ord($encrypted{$i})] * pow(63, $i); |
|
| 4231 | + } |
|
| 4000 | 4232 | $returned_ints[] = $max_chars == 4 ? min($total, 16777215) : $total; |
| 4001 | 4233 | } |
| 4002 | 4234 | } |
| 4003 | 4235 | return array_unique($returned_ints); |
| 4004 | - } |
|
| 4005 | - else |
|
| 4236 | + } else |
|
| 4006 | 4237 | { |
| 4007 | 4238 | // Trim characters before and after and add slashes for database insertion. |
| 4008 | 4239 | $returned_words = array(); |
| 4009 | - foreach ($words as $word) |
|
| 4010 | - if (($word = trim($word, '-_\'')) !== '') |
|
| 4240 | + foreach ($words as $word) { |
|
| 4241 | + if (($word = trim($word, '-_\'')) !== '') |
|
| 4011 | 4242 | $returned_words[] = $max_chars === null ? $word : substr($word, 0, $max_chars); |
| 4243 | + } |
|
| 4012 | 4244 | |
| 4013 | 4245 | // Filter out all words that occur more than once. |
| 4014 | 4246 | return array_unique($returned_words); |
@@ -4030,16 +4262,18 @@ discard block |
||
| 4030 | 4262 | global $settings, $txt; |
| 4031 | 4263 | |
| 4032 | 4264 | // Does the current loaded theme have this and we are not forcing the usage of this function? |
| 4033 | - if (function_exists('template_create_button') && !$force_use) |
|
| 4034 | - return template_create_button($name, $alt, $label = '', $custom = ''); |
|
| 4265 | + if (function_exists('template_create_button') && !$force_use) { |
|
| 4266 | + return template_create_button($name, $alt, $label = '', $custom = ''); |
|
| 4267 | + } |
|
| 4035 | 4268 | |
| 4036 | - if (!$settings['use_image_buttons']) |
|
| 4037 | - return $txt[$alt]; |
|
| 4038 | - elseif (!empty($settings['use_buttons'])) |
|
| 4039 | - return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? ' <strong>' . $txt[$label] . '</strong>' : ''); |
|
| 4040 | - else |
|
| 4041 | - return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>'; |
|
| 4042 | -} |
|
| 4269 | + if (!$settings['use_image_buttons']) { |
|
| 4270 | + return $txt[$alt]; |
|
| 4271 | + } elseif (!empty($settings['use_buttons'])) { |
|
| 4272 | + return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? ' <strong>' . $txt[$label] . '</strong>' : ''); |
|
| 4273 | + } else { |
|
| 4274 | + return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>'; |
|
| 4275 | + } |
|
| 4276 | + } |
|
| 4043 | 4277 | |
| 4044 | 4278 | /** |
| 4045 | 4279 | * Sets up all of the top menu buttons |
@@ -4082,9 +4316,10 @@ discard block |
||
| 4082 | 4316 | var user_menus = new smc_PopupMenu(); |
| 4083 | 4317 | user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup"); |
| 4084 | 4318 | user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true); |
| 4085 | - if ($context['allow_pm']) |
|
| 4086 | - addInlineJavaScript(' |
|
| 4319 | + if ($context['allow_pm']) { |
|
| 4320 | + addInlineJavaScript(' |
|
| 4087 | 4321 | user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true); |
| 4322 | + } |
|
| 4088 | 4323 | |
| 4089 | 4324 | if (!empty($modSettings['enable_ajax_alerts'])) |
| 4090 | 4325 | { |
@@ -4244,88 +4479,96 @@ discard block |
||
| 4244 | 4479 | |
| 4245 | 4480 | // Now we put the buttons in the context so the theme can use them. |
| 4246 | 4481 | $menu_buttons = array(); |
| 4247 | - foreach ($buttons as $act => $button) |
|
| 4248 | - if (!empty($button['show'])) |
|
| 4482 | + foreach ($buttons as $act => $button) { |
|
| 4483 | + if (!empty($button['show'])) |
|
| 4249 | 4484 | { |
| 4250 | 4485 | $button['active_button'] = false; |
| 4486 | + } |
|
| 4251 | 4487 | |
| 4252 | 4488 | // This button needs some action. |
| 4253 | - if (isset($button['action_hook'])) |
|
| 4254 | - $needs_action_hook = true; |
|
| 4489 | + if (isset($button['action_hook'])) { |
|
| 4490 | + $needs_action_hook = true; |
|
| 4491 | + } |
|
| 4255 | 4492 | |
| 4256 | 4493 | // Make sure the last button truly is the last button. |
| 4257 | 4494 | if (!empty($button['is_last'])) |
| 4258 | 4495 | { |
| 4259 | - if (isset($last_button)) |
|
| 4260 | - unset($menu_buttons[$last_button]['is_last']); |
|
| 4496 | + if (isset($last_button)) { |
|
| 4497 | + unset($menu_buttons[$last_button]['is_last']); |
|
| 4498 | + } |
|
| 4261 | 4499 | $last_button = $act; |
| 4262 | 4500 | } |
| 4263 | 4501 | |
| 4264 | 4502 | // Go through the sub buttons if there are any. |
| 4265 | - if (!empty($button['sub_buttons'])) |
|
| 4266 | - foreach ($button['sub_buttons'] as $key => $subbutton) |
|
| 4503 | + if (!empty($button['sub_buttons'])) { |
|
| 4504 | + foreach ($button['sub_buttons'] as $key => $subbutton) |
|
| 4267 | 4505 | { |
| 4268 | 4506 | if (empty($subbutton['show'])) |
| 4269 | 4507 | unset($button['sub_buttons'][$key]); |
| 4508 | + } |
|
| 4270 | 4509 | |
| 4271 | 4510 | // 2nd level sub buttons next... |
| 4272 | 4511 | if (!empty($subbutton['sub_buttons'])) |
| 4273 | 4512 | { |
| 4274 | 4513 | foreach ($subbutton['sub_buttons'] as $key2 => $sub_button2) |
| 4275 | 4514 | { |
| 4276 | - if (empty($sub_button2['show'])) |
|
| 4277 | - unset($button['sub_buttons'][$key]['sub_buttons'][$key2]); |
|
| 4515 | + if (empty($sub_button2['show'])) { |
|
| 4516 | + unset($button['sub_buttons'][$key]['sub_buttons'][$key2]); |
|
| 4517 | + } |
|
| 4278 | 4518 | } |
| 4279 | 4519 | } |
| 4280 | 4520 | } |
| 4281 | 4521 | |
| 4282 | 4522 | // Does this button have its own icon? |
| 4283 | - if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) |
|
| 4284 | - $button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
| 4285 | - elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) |
|
| 4286 | - $button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
| 4287 | - elseif (isset($button['icon'])) |
|
| 4288 | - $button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>'; |
|
| 4289 | - else |
|
| 4290 | - $button['icon'] = '<span class="generic_icons ' . $act . '"></span>'; |
|
| 4523 | + if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) { |
|
| 4524 | + $button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
| 4525 | + } elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) { |
|
| 4526 | + $button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
| 4527 | + } elseif (isset($button['icon'])) { |
|
| 4528 | + $button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>'; |
|
| 4529 | + } else { |
|
| 4530 | + $button['icon'] = '<span class="generic_icons ' . $act . '"></span>'; |
|
| 4531 | + } |
|
| 4291 | 4532 | |
| 4292 | 4533 | $menu_buttons[$act] = $button; |
| 4293 | 4534 | } |
| 4294 | 4535 | |
| 4295 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
| 4296 | - cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime); |
|
| 4536 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
| 4537 | + cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime); |
|
| 4538 | + } |
|
| 4297 | 4539 | } |
| 4298 | 4540 | |
| 4299 | 4541 | $context['menu_buttons'] = $menu_buttons; |
| 4300 | 4542 | |
| 4301 | 4543 | // Logging out requires the session id in the url. |
| 4302 | - if (isset($context['menu_buttons']['logout'])) |
|
| 4303 | - $context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']); |
|
| 4544 | + if (isset($context['menu_buttons']['logout'])) { |
|
| 4545 | + $context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']); |
|
| 4546 | + } |
|
| 4304 | 4547 | |
| 4305 | 4548 | // Figure out which action we are doing so we can set the active tab. |
| 4306 | 4549 | // Default to home. |
| 4307 | 4550 | $current_action = 'home'; |
| 4308 | 4551 | |
| 4309 | - if (isset($context['menu_buttons'][$context['current_action']])) |
|
| 4310 | - $current_action = $context['current_action']; |
|
| 4311 | - elseif ($context['current_action'] == 'search2') |
|
| 4312 | - $current_action = 'search'; |
|
| 4313 | - elseif ($context['current_action'] == 'theme') |
|
| 4314 | - $current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin'; |
|
| 4315 | - elseif ($context['current_action'] == 'register2') |
|
| 4316 | - $current_action = 'register'; |
|
| 4317 | - elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) |
|
| 4318 | - $current_action = 'login'; |
|
| 4319 | - elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) |
|
| 4320 | - $current_action = 'moderate'; |
|
| 4552 | + if (isset($context['menu_buttons'][$context['current_action']])) { |
|
| 4553 | + $current_action = $context['current_action']; |
|
| 4554 | + } elseif ($context['current_action'] == 'search2') { |
|
| 4555 | + $current_action = 'search'; |
|
| 4556 | + } elseif ($context['current_action'] == 'theme') { |
|
| 4557 | + $current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin'; |
|
| 4558 | + } elseif ($context['current_action'] == 'register2') { |
|
| 4559 | + $current_action = 'register'; |
|
| 4560 | + } elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) { |
|
| 4561 | + $current_action = 'login'; |
|
| 4562 | + } elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) { |
|
| 4563 | + $current_action = 'moderate'; |
|
| 4564 | + } |
|
| 4321 | 4565 | |
| 4322 | 4566 | // There are certain exceptions to the above where we don't want anything on the menu highlighted. |
| 4323 | 4567 | if ($context['current_action'] == 'profile' && !empty($context['user']['is_owner'])) |
| 4324 | 4568 | { |
| 4325 | 4569 | $current_action = !empty($_GET['area']) && $_GET['area'] == 'showalerts' ? 'self_alerts' : 'self_profile'; |
| 4326 | 4570 | $context[$current_action] = true; |
| 4327 | - } |
|
| 4328 | - elseif ($context['current_action'] == 'pm') |
|
| 4571 | + } elseif ($context['current_action'] == 'pm') |
|
| 4329 | 4572 | { |
| 4330 | 4573 | $current_action = 'self_pm'; |
| 4331 | 4574 | $context['self_pm'] = true; |
@@ -4366,12 +4609,14 @@ discard block |
||
| 4366 | 4609 | } |
| 4367 | 4610 | |
| 4368 | 4611 | // Not all actions are simple. |
| 4369 | - if (!empty($needs_action_hook)) |
|
| 4370 | - call_integration_hook('integrate_current_action', array(&$current_action)); |
|
| 4612 | + if (!empty($needs_action_hook)) { |
|
| 4613 | + call_integration_hook('integrate_current_action', array(&$current_action)); |
|
| 4614 | + } |
|
| 4371 | 4615 | |
| 4372 | - if (isset($context['menu_buttons'][$current_action])) |
|
| 4373 | - $context['menu_buttons'][$current_action]['active_button'] = true; |
|
| 4374 | -} |
|
| 4616 | + if (isset($context['menu_buttons'][$current_action])) { |
|
| 4617 | + $context['menu_buttons'][$current_action]['active_button'] = true; |
|
| 4618 | + } |
|
| 4619 | + } |
|
| 4375 | 4620 | |
| 4376 | 4621 | /** |
| 4377 | 4622 | * Generate a random seed and ensure it's stored in settings. |
@@ -4395,30 +4640,35 @@ discard block |
||
| 4395 | 4640 | global $modSettings, $settings, $boarddir, $sourcedir, $db_show_debug; |
| 4396 | 4641 | global $context, $txt; |
| 4397 | 4642 | |
| 4398 | - if ($db_show_debug === true) |
|
| 4399 | - $context['debug']['hooks'][] = $hook; |
|
| 4643 | + if ($db_show_debug === true) { |
|
| 4644 | + $context['debug']['hooks'][] = $hook; |
|
| 4645 | + } |
|
| 4400 | 4646 | |
| 4401 | 4647 | // Need to have some control. |
| 4402 | - if (!isset($context['instances'])) |
|
| 4403 | - $context['instances'] = array(); |
|
| 4648 | + if (!isset($context['instances'])) { |
|
| 4649 | + $context['instances'] = array(); |
|
| 4650 | + } |
|
| 4404 | 4651 | |
| 4405 | 4652 | $results = array(); |
| 4406 | - if (empty($modSettings[$hook])) |
|
| 4407 | - return $results; |
|
| 4653 | + if (empty($modSettings[$hook])) { |
|
| 4654 | + return $results; |
|
| 4655 | + } |
|
| 4408 | 4656 | |
| 4409 | 4657 | $functions = explode(',', $modSettings[$hook]); |
| 4410 | 4658 | // Loop through each function. |
| 4411 | 4659 | foreach ($functions as $function) |
| 4412 | 4660 | { |
| 4413 | 4661 | // Hook has been marked as "disabled". Skip it! |
| 4414 | - if (strpos($function, '!') !== false) |
|
| 4415 | - continue; |
|
| 4662 | + if (strpos($function, '!') !== false) { |
|
| 4663 | + continue; |
|
| 4664 | + } |
|
| 4416 | 4665 | |
| 4417 | 4666 | $call = call_helper($function, true); |
| 4418 | 4667 | |
| 4419 | 4668 | // Is it valid? |
| 4420 | - if (!empty($call)) |
|
| 4421 | - $results[$function] = call_user_func_array($call, $parameters); |
|
| 4669 | + if (!empty($call)) { |
|
| 4670 | + $results[$function] = call_user_func_array($call, $parameters); |
|
| 4671 | + } |
|
| 4422 | 4672 | |
| 4423 | 4673 | // Whatever it was suppose to call, it failed :( |
| 4424 | 4674 | elseif (!empty($function)) |
@@ -4434,8 +4684,9 @@ discard block |
||
| 4434 | 4684 | } |
| 4435 | 4685 | |
| 4436 | 4686 | // "Assume" the file resides on $boarddir somewhere... |
| 4437 | - else |
|
| 4438 | - log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general'); |
|
| 4687 | + else { |
|
| 4688 | + log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general'); |
|
| 4689 | + } |
|
| 4439 | 4690 | } |
| 4440 | 4691 | } |
| 4441 | 4692 | |
@@ -4457,12 +4708,14 @@ discard block |
||
| 4457 | 4708 | global $smcFunc, $modSettings; |
| 4458 | 4709 | |
| 4459 | 4710 | // Any objects? |
| 4460 | - if ($object) |
|
| 4461 | - $function = $function . '#'; |
|
| 4711 | + if ($object) { |
|
| 4712 | + $function = $function . '#'; |
|
| 4713 | + } |
|
| 4462 | 4714 | |
| 4463 | 4715 | // Any files to load? |
| 4464 | - if (!empty($file) && is_string($file)) |
|
| 4465 | - $function = $file . (!empty($function) ? '|' . $function : ''); |
|
| 4716 | + if (!empty($file) && is_string($file)) { |
|
| 4717 | + $function = $file . (!empty($function) ? '|' . $function : ''); |
|
| 4718 | + } |
|
| 4466 | 4719 | |
| 4467 | 4720 | // Get the correct string. |
| 4468 | 4721 | $integration_call = $function; |
@@ -4484,13 +4737,14 @@ discard block |
||
| 4484 | 4737 | if (!empty($current_functions)) |
| 4485 | 4738 | { |
| 4486 | 4739 | $current_functions = explode(',', $current_functions); |
| 4487 | - if (in_array($integration_call, $current_functions)) |
|
| 4488 | - return; |
|
| 4740 | + if (in_array($integration_call, $current_functions)) { |
|
| 4741 | + return; |
|
| 4742 | + } |
|
| 4489 | 4743 | |
| 4490 | 4744 | $permanent_functions = array_merge($current_functions, array($integration_call)); |
| 4745 | + } else { |
|
| 4746 | + $permanent_functions = array($integration_call); |
|
| 4491 | 4747 | } |
| 4492 | - else |
|
| 4493 | - $permanent_functions = array($integration_call); |
|
| 4494 | 4748 | |
| 4495 | 4749 | updateSettings(array($hook => implode(',', $permanent_functions))); |
| 4496 | 4750 | } |
@@ -4499,8 +4753,9 @@ discard block |
||
| 4499 | 4753 | $functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]); |
| 4500 | 4754 | |
| 4501 | 4755 | // Do nothing, if it's already there. |
| 4502 | - if (in_array($integration_call, $functions)) |
|
| 4503 | - return; |
|
| 4756 | + if (in_array($integration_call, $functions)) { |
|
| 4757 | + return; |
|
| 4758 | + } |
|
| 4504 | 4759 | |
| 4505 | 4760 | $functions[] = $integration_call; |
| 4506 | 4761 | $modSettings[$hook] = implode(',', $functions); |
@@ -4523,12 +4778,14 @@ discard block |
||
| 4523 | 4778 | global $smcFunc, $modSettings; |
| 4524 | 4779 | |
| 4525 | 4780 | // Any objects? |
| 4526 | - if ($object) |
|
| 4527 | - $function = $function . '#'; |
|
| 4781 | + if ($object) { |
|
| 4782 | + $function = $function . '#'; |
|
| 4783 | + } |
|
| 4528 | 4784 | |
| 4529 | 4785 | // Any files to load? |
| 4530 | - if (!empty($file) && is_string($file)) |
|
| 4531 | - $function = $file . '|' . $function; |
|
| 4786 | + if (!empty($file) && is_string($file)) { |
|
| 4787 | + $function = $file . '|' . $function; |
|
| 4788 | + } |
|
| 4532 | 4789 | |
| 4533 | 4790 | // Get the correct string. |
| 4534 | 4791 | $integration_call = $function; |
@@ -4549,16 +4806,18 @@ discard block |
||
| 4549 | 4806 | { |
| 4550 | 4807 | $current_functions = explode(',', $current_functions); |
| 4551 | 4808 | |
| 4552 | - if (in_array($integration_call, $current_functions)) |
|
| 4553 | - updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call))))); |
|
| 4809 | + if (in_array($integration_call, $current_functions)) { |
|
| 4810 | + updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call))))); |
|
| 4811 | + } |
|
| 4554 | 4812 | } |
| 4555 | 4813 | |
| 4556 | 4814 | // Turn the function list into something usable. |
| 4557 | 4815 | $functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]); |
| 4558 | 4816 | |
| 4559 | 4817 | // You can only remove it if it's available. |
| 4560 | - if (!in_array($integration_call, $functions)) |
|
| 4561 | - return; |
|
| 4818 | + if (!in_array($integration_call, $functions)) { |
|
| 4819 | + return; |
|
| 4820 | + } |
|
| 4562 | 4821 | |
| 4563 | 4822 | $functions = array_diff($functions, array($integration_call)); |
| 4564 | 4823 | $modSettings[$hook] = implode(',', $functions); |
@@ -4579,17 +4838,20 @@ discard block |
||
| 4579 | 4838 | global $context, $smcFunc, $txt, $db_show_debug; |
| 4580 | 4839 | |
| 4581 | 4840 | // Really? |
| 4582 | - if (empty($string)) |
|
| 4583 | - return false; |
|
| 4841 | + if (empty($string)) { |
|
| 4842 | + return false; |
|
| 4843 | + } |
|
| 4584 | 4844 | |
| 4585 | 4845 | // An array? should be a "callable" array IE array(object/class, valid_callable). |
| 4586 | 4846 | // A closure? should be a callable one. |
| 4587 | - if (is_array($string) || $string instanceof Closure) |
|
| 4588 | - return $return ? $string : (is_callable($string) ? call_user_func($string) : false); |
|
| 4847 | + if (is_array($string) || $string instanceof Closure) { |
|
| 4848 | + return $return ? $string : (is_callable($string) ? call_user_func($string) : false); |
|
| 4849 | + } |
|
| 4589 | 4850 | |
| 4590 | 4851 | // No full objects, sorry! pass a method or a property instead! |
| 4591 | - if (is_object($string)) |
|
| 4592 | - return false; |
|
| 4852 | + if (is_object($string)) { |
|
| 4853 | + return false; |
|
| 4854 | + } |
|
| 4593 | 4855 | |
| 4594 | 4856 | // Stay vitaminized my friends... |
| 4595 | 4857 | $string = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($string)); |
@@ -4598,8 +4860,9 @@ discard block |
||
| 4598 | 4860 | $string = load_file($string); |
| 4599 | 4861 | |
| 4600 | 4862 | // Loaded file failed |
| 4601 | - if (empty($string)) |
|
| 4602 | - return false; |
|
| 4863 | + if (empty($string)) { |
|
| 4864 | + return false; |
|
| 4865 | + } |
|
| 4603 | 4866 | |
| 4604 | 4867 | // Found a method. |
| 4605 | 4868 | if (strpos($string, '::') !== false) |
@@ -4620,8 +4883,9 @@ discard block |
||
| 4620 | 4883 | // Add another one to the list. |
| 4621 | 4884 | if ($db_show_debug === true) |
| 4622 | 4885 | { |
| 4623 | - if (!isset($context['debug']['instances'])) |
|
| 4624 | - $context['debug']['instances'] = array(); |
|
| 4886 | + if (!isset($context['debug']['instances'])) { |
|
| 4887 | + $context['debug']['instances'] = array(); |
|
| 4888 | + } |
|
| 4625 | 4889 | |
| 4626 | 4890 | $context['debug']['instances'][$class] = $class; |
| 4627 | 4891 | } |
@@ -4631,13 +4895,15 @@ discard block |
||
| 4631 | 4895 | } |
| 4632 | 4896 | |
| 4633 | 4897 | // Right then. This is a call to a static method. |
| 4634 | - else |
|
| 4635 | - $func = array($class, $method); |
|
| 4898 | + else { |
|
| 4899 | + $func = array($class, $method); |
|
| 4900 | + } |
|
| 4636 | 4901 | } |
| 4637 | 4902 | |
| 4638 | 4903 | // Nope! just a plain regular function. |
| 4639 | - else |
|
| 4640 | - $func = $string; |
|
| 4904 | + else { |
|
| 4905 | + $func = $string; |
|
| 4906 | + } |
|
| 4641 | 4907 | |
| 4642 | 4908 | // Right, we got what we need, time to do some checks. |
| 4643 | 4909 | if (!is_callable($func, false, $callable_name)) |
@@ -4653,17 +4919,18 @@ discard block |
||
| 4653 | 4919 | else |
| 4654 | 4920 | { |
| 4655 | 4921 | // What are we gonna do about it? |
| 4656 | - if ($return) |
|
| 4657 | - return $func; |
|
| 4922 | + if ($return) { |
|
| 4923 | + return $func; |
|
| 4924 | + } |
|
| 4658 | 4925 | |
| 4659 | 4926 | // If this is a plain function, avoid the heat of calling call_user_func(). |
| 4660 | 4927 | else |
| 4661 | 4928 | { |
| 4662 | - if (is_array($func)) |
|
| 4663 | - call_user_func($func); |
|
| 4664 | - |
|
| 4665 | - else |
|
| 4666 | - $func(); |
|
| 4929 | + if (is_array($func)) { |
|
| 4930 | + call_user_func($func); |
|
| 4931 | + } else { |
|
| 4932 | + $func(); |
|
| 4933 | + } |
|
| 4667 | 4934 | } |
| 4668 | 4935 | } |
| 4669 | 4936 | } |
@@ -4680,31 +4947,34 @@ discard block |
||
| 4680 | 4947 | { |
| 4681 | 4948 | global $sourcedir, $txt, $boarddir, $settings; |
| 4682 | 4949 | |
| 4683 | - if (empty($string)) |
|
| 4684 | - return false; |
|
| 4950 | + if (empty($string)) { |
|
| 4951 | + return false; |
|
| 4952 | + } |
|
| 4685 | 4953 | |
| 4686 | 4954 | if (strpos($string, '|') !== false) |
| 4687 | 4955 | { |
| 4688 | 4956 | list ($file, $string) = explode('|', $string); |
| 4689 | 4957 | |
| 4690 | 4958 | // Match the wildcards to their regular vars. |
| 4691 | - if (empty($settings['theme_dir'])) |
|
| 4692 | - $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
|
| 4693 | - |
|
| 4694 | - else |
|
| 4695 | - $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
|
| 4959 | + if (empty($settings['theme_dir'])) { |
|
| 4960 | + $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
|
| 4961 | + } else { |
|
| 4962 | + $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
|
| 4963 | + } |
|
| 4696 | 4964 | |
| 4697 | 4965 | // Load the file if it can be loaded. |
| 4698 | - if (file_exists($absPath)) |
|
| 4699 | - require_once($absPath); |
|
| 4966 | + if (file_exists($absPath)) { |
|
| 4967 | + require_once($absPath); |
|
| 4968 | + } |
|
| 4700 | 4969 | |
| 4701 | 4970 | // No? try a fallback to $sourcedir |
| 4702 | 4971 | else |
| 4703 | 4972 | { |
| 4704 | 4973 | $absPath = $sourcedir .'/'. $file; |
| 4705 | 4974 | |
| 4706 | - if (file_exists($absPath)) |
|
| 4707 | - require_once($absPath); |
|
| 4975 | + if (file_exists($absPath)) { |
|
| 4976 | + require_once($absPath); |
|
| 4977 | + } |
|
| 4708 | 4978 | |
| 4709 | 4979 | // Sorry, can't do much for you at this point. |
| 4710 | 4980 | else |
@@ -4731,8 +5001,9 @@ discard block |
||
| 4731 | 5001 | global $user_info, $smcFunc; |
| 4732 | 5002 | |
| 4733 | 5003 | // Make sure we have something to work with. |
| 4734 | - if (empty($topic)) |
|
| 4735 | - return array(); |
|
| 5004 | + if (empty($topic)) { |
|
| 5005 | + return array(); |
|
| 5006 | + } |
|
| 4736 | 5007 | |
| 4737 | 5008 | |
| 4738 | 5009 | // We already know the number of likes per message, we just want to know whether the current user liked it or not. |
@@ -4755,8 +5026,9 @@ discard block |
||
| 4755 | 5026 | 'topic' => $topic, |
| 4756 | 5027 | ) |
| 4757 | 5028 | ); |
| 4758 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 4759 | - $temp[] = (int) $row['content_id']; |
|
| 5029 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 5030 | + $temp[] = (int) $row['content_id']; |
|
| 5031 | + } |
|
| 4760 | 5032 | |
| 4761 | 5033 | cache_put_data($cache_key, $temp, $ttl); |
| 4762 | 5034 | } |
@@ -4777,8 +5049,9 @@ discard block |
||
| 4777 | 5049 | { |
| 4778 | 5050 | global $context; |
| 4779 | 5051 | |
| 4780 | - if (empty($string)) |
|
| 4781 | - return $string; |
|
| 5052 | + if (empty($string)) { |
|
| 5053 | + return $string; |
|
| 5054 | + } |
|
| 4782 | 5055 | |
| 4783 | 5056 | // UTF-8 occurences of MS special characters |
| 4784 | 5057 | $findchars_utf8 = array( |
@@ -4819,10 +5092,11 @@ discard block |
||
| 4819 | 5092 | '--', // — |
| 4820 | 5093 | ); |
| 4821 | 5094 | |
| 4822 | - if ($context['utf8']) |
|
| 4823 | - $string = str_replace($findchars_utf8, $replacechars, $string); |
|
| 4824 | - else |
|
| 4825 | - $string = str_replace($findchars_iso, $replacechars, $string); |
|
| 5095 | + if ($context['utf8']) { |
|
| 5096 | + $string = str_replace($findchars_utf8, $replacechars, $string); |
|
| 5097 | + } else { |
|
| 5098 | + $string = str_replace($findchars_iso, $replacechars, $string); |
|
| 5099 | + } |
|
| 4826 | 5100 | |
| 4827 | 5101 | return $string; |
| 4828 | 5102 | } |
@@ -4841,49 +5115,59 @@ discard block |
||
| 4841 | 5115 | { |
| 4842 | 5116 | global $context; |
| 4843 | 5117 | |
| 4844 | - if (!isset($matches[2])) |
|
| 4845 | - return ''; |
|
| 5118 | + if (!isset($matches[2])) { |
|
| 5119 | + return ''; |
|
| 5120 | + } |
|
| 4846 | 5121 | |
| 4847 | 5122 | $num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2]; |
| 4848 | 5123 | |
| 4849 | 5124 | // remove left to right / right to left overrides |
| 4850 | - if ($num === 0x202D || $num === 0x202E) |
|
| 4851 | - return ''; |
|
| 5125 | + if ($num === 0x202D || $num === 0x202E) { |
|
| 5126 | + return ''; |
|
| 5127 | + } |
|
| 4852 | 5128 | |
| 4853 | 5129 | // Quote, Ampersand, Apostrophe, Less/Greater Than get html replaced |
| 4854 | - if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) |
|
| 4855 | - return '&#' . $num . ';'; |
|
| 5130 | + if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) { |
|
| 5131 | + return '&#' . $num . ';'; |
|
| 5132 | + } |
|
| 4856 | 5133 | |
| 4857 | 5134 | if (empty($context['utf8'])) |
| 4858 | 5135 | { |
| 4859 | 5136 | // no control characters |
| 4860 | - if ($num < 0x20) |
|
| 4861 | - return ''; |
|
| 5137 | + if ($num < 0x20) { |
|
| 5138 | + return ''; |
|
| 5139 | + } |
|
| 4862 | 5140 | // text is text |
| 4863 | - elseif ($num < 0x80) |
|
| 4864 | - return chr($num); |
|
| 5141 | + elseif ($num < 0x80) { |
|
| 5142 | + return chr($num); |
|
| 5143 | + } |
|
| 4865 | 5144 | // all others get html-ised |
| 4866 | - else |
|
| 4867 | - return '&#' . $matches[2] . ';'; |
|
| 4868 | - } |
|
| 4869 | - else |
|
| 5145 | + else { |
|
| 5146 | + return '&#' . $matches[2] . ';'; |
|
| 5147 | + } |
|
| 5148 | + } else |
|
| 4870 | 5149 | { |
| 4871 | 5150 | // <0x20 are control characters, 0x20 is a space, > 0x10FFFF is past the end of the utf8 character set |
| 4872 | 5151 | // 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text) |
| 4873 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) |
|
| 4874 | - return ''; |
|
| 5152 | + if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) { |
|
| 5153 | + return ''; |
|
| 5154 | + } |
|
| 4875 | 5155 | // <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation |
| 4876 | - elseif ($num < 0x80) |
|
| 4877 | - return chr($num); |
|
| 5156 | + elseif ($num < 0x80) { |
|
| 5157 | + return chr($num); |
|
| 5158 | + } |
|
| 4878 | 5159 | // <0x800 (2048) |
| 4879 | - elseif ($num < 0x800) |
|
| 4880 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 5160 | + elseif ($num < 0x800) { |
|
| 5161 | + return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 5162 | + } |
|
| 4881 | 5163 | // < 0x10000 (65536) |
| 4882 | - elseif ($num < 0x10000) |
|
| 4883 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 5164 | + elseif ($num < 0x10000) { |
|
| 5165 | + return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 5166 | + } |
|
| 4884 | 5167 | // <= 0x10FFFF (1114111) |
| 4885 | - else |
|
| 4886 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 5168 | + else { |
|
| 5169 | + return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 5170 | + } |
|
| 4887 | 5171 | } |
| 4888 | 5172 | } |
| 4889 | 5173 | |
@@ -4899,28 +5183,34 @@ discard block |
||
| 4899 | 5183 | */ |
| 4900 | 5184 | function fixchar__callback($matches) |
| 4901 | 5185 | { |
| 4902 | - if (!isset($matches[1])) |
|
| 4903 | - return ''; |
|
| 5186 | + if (!isset($matches[1])) { |
|
| 5187 | + return ''; |
|
| 5188 | + } |
|
| 4904 | 5189 | |
| 4905 | 5190 | $num = $matches[1][0] === 'x' ? hexdec(substr($matches[1], 1)) : (int) $matches[1]; |
| 4906 | 5191 | |
| 4907 | 5192 | // <0x20 are control characters, > 0x10FFFF is past the end of the utf8 character set |
| 4908 | 5193 | // 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text), 0x202D-E are left to right overrides |
| 4909 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) |
|
| 4910 | - return ''; |
|
| 5194 | + if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) { |
|
| 5195 | + return ''; |
|
| 5196 | + } |
|
| 4911 | 5197 | // <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation |
| 4912 | - elseif ($num < 0x80) |
|
| 4913 | - return chr($num); |
|
| 5198 | + elseif ($num < 0x80) { |
|
| 5199 | + return chr($num); |
|
| 5200 | + } |
|
| 4914 | 5201 | // <0x800 (2048) |
| 4915 | - elseif ($num < 0x800) |
|
| 4916 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 5202 | + elseif ($num < 0x800) { |
|
| 5203 | + return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 5204 | + } |
|
| 4917 | 5205 | // < 0x10000 (65536) |
| 4918 | - elseif ($num < 0x10000) |
|
| 4919 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 5206 | + elseif ($num < 0x10000) { |
|
| 5207 | + return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 5208 | + } |
|
| 4920 | 5209 | // <= 0x10FFFF (1114111) |
| 4921 | - else |
|
| 4922 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 4923 | -} |
|
| 5210 | + else { |
|
| 5211 | + return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 5212 | + } |
|
| 5213 | + } |
|
| 4924 | 5214 | |
| 4925 | 5215 | /** |
| 4926 | 5216 | * Strips out invalid html entities, replaces others with html style { codes |
@@ -4933,17 +5223,19 @@ discard block |
||
| 4933 | 5223 | */ |
| 4934 | 5224 | function entity_fix__callback($matches) |
| 4935 | 5225 | { |
| 4936 | - if (!isset($matches[2])) |
|
| 4937 | - return ''; |
|
| 5226 | + if (!isset($matches[2])) { |
|
| 5227 | + return ''; |
|
| 5228 | + } |
|
| 4938 | 5229 | |
| 4939 | 5230 | $num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2]; |
| 4940 | 5231 | |
| 4941 | 5232 | // we don't allow control characters, characters out of range, byte markers, etc |
| 4942 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) |
|
| 4943 | - return ''; |
|
| 4944 | - else |
|
| 4945 | - return '&#' . $num . ';'; |
|
| 4946 | -} |
|
| 5233 | + if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) { |
|
| 5234 | + return ''; |
|
| 5235 | + } else { |
|
| 5236 | + return '&#' . $num . ';'; |
|
| 5237 | + } |
|
| 5238 | + } |
|
| 4947 | 5239 | |
| 4948 | 5240 | /** |
| 4949 | 5241 | * Return a Gravatar URL based on |
@@ -4967,18 +5259,23 @@ discard block |
||
| 4967 | 5259 | $ratings = array('G', 'PG', 'R', 'X'); |
| 4968 | 5260 | $defaults = array('mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank'); |
| 4969 | 5261 | $url_params = array(); |
| 4970 | - if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) |
|
| 4971 | - $url_params[] = 'rating=' . $modSettings['gravatarMaxRating']; |
|
| 4972 | - if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) |
|
| 4973 | - $url_params[] = 'default=' . $modSettings['gravatarDefault']; |
|
| 4974 | - if (!empty($modSettings['avatar_max_width_external'])) |
|
| 4975 | - $size_string = (int) $modSettings['avatar_max_width_external']; |
|
| 4976 | - if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) |
|
| 4977 | - if ((int) $modSettings['avatar_max_height_external'] < $size_string) |
|
| 5262 | + if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) { |
|
| 5263 | + $url_params[] = 'rating=' . $modSettings['gravatarMaxRating']; |
|
| 5264 | + } |
|
| 5265 | + if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) { |
|
| 5266 | + $url_params[] = 'default=' . $modSettings['gravatarDefault']; |
|
| 5267 | + } |
|
| 5268 | + if (!empty($modSettings['avatar_max_width_external'])) { |
|
| 5269 | + $size_string = (int) $modSettings['avatar_max_width_external']; |
|
| 5270 | + } |
|
| 5271 | + if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) { |
|
| 5272 | + if ((int) $modSettings['avatar_max_height_external'] < $size_string) |
|
| 4978 | 5273 | $size_string = $modSettings['avatar_max_height_external']; |
| 5274 | + } |
|
| 4979 | 5275 | |
| 4980 | - if (!empty($size_string)) |
|
| 4981 | - $url_params[] = 's=' . $size_string; |
|
| 5276 | + if (!empty($size_string)) { |
|
| 5277 | + $url_params[] = 's=' . $size_string; |
|
| 5278 | + } |
|
| 4982 | 5279 | } |
| 4983 | 5280 | $http_method = !empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 ? 'https://secure' : 'http://www'; |
| 4984 | 5281 | |
@@ -4997,22 +5294,26 @@ discard block |
||
| 4997 | 5294 | static $timezones = null, $lastwhen = null; |
| 4998 | 5295 | |
| 4999 | 5296 | // No point doing this over if we already did it once |
| 5000 | - if (!empty($timezones) && $when == $lastwhen) |
|
| 5001 | - return $timezones; |
|
| 5002 | - else |
|
| 5003 | - $lastwhen = $when; |
|
| 5297 | + if (!empty($timezones) && $when == $lastwhen) { |
|
| 5298 | + return $timezones; |
|
| 5299 | + } else { |
|
| 5300 | + $lastwhen = $when; |
|
| 5301 | + } |
|
| 5004 | 5302 | |
| 5005 | 5303 | // Parseable datetime string? |
| 5006 | - if (is_int($timestamp = strtotime($when))) |
|
| 5007 | - $when = $timestamp; |
|
| 5304 | + if (is_int($timestamp = strtotime($when))) { |
|
| 5305 | + $when = $timestamp; |
|
| 5306 | + } |
|
| 5008 | 5307 | |
| 5009 | 5308 | // A Unix timestamp? |
| 5010 | - elseif (is_numeric($when)) |
|
| 5011 | - $when = intval($when); |
|
| 5309 | + elseif (is_numeric($when)) { |
|
| 5310 | + $when = intval($when); |
|
| 5311 | + } |
|
| 5012 | 5312 | |
| 5013 | 5313 | // Invalid value? Just get current Unix timestamp. |
| 5014 | - else |
|
| 5015 | - $when = time(); |
|
| 5314 | + else { |
|
| 5315 | + $when = time(); |
|
| 5316 | + } |
|
| 5016 | 5317 | |
| 5017 | 5318 | // We'll need these too |
| 5018 | 5319 | $date_when = date_create('@' . $when); |
@@ -5076,8 +5377,9 @@ discard block |
||
| 5076 | 5377 | foreach ($priority_countries as $country) |
| 5077 | 5378 | { |
| 5078 | 5379 | $country_tzids = @timezone_identifiers_list(DateTimeZone::PER_COUNTRY, strtoupper(trim($country))); |
| 5079 | - if (!empty($country_tzids)) |
|
| 5080 | - $priority_tzids = array_merge($priority_tzids, $country_tzids); |
|
| 5380 | + if (!empty($country_tzids)) { |
|
| 5381 | + $priority_tzids = array_merge($priority_tzids, $country_tzids); |
|
| 5382 | + } |
|
| 5081 | 5383 | } |
| 5082 | 5384 | |
| 5083 | 5385 | // Process the preferred timezones first, then the rest. |
@@ -5087,8 +5389,9 @@ discard block |
||
| 5087 | 5389 | foreach ($tzids as $tzid) |
| 5088 | 5390 | { |
| 5089 | 5391 | // We don't want UTC right now |
| 5090 | - if ($tzid == 'UTC') |
|
| 5091 | - continue; |
|
| 5392 | + if ($tzid == 'UTC') { |
|
| 5393 | + continue; |
|
| 5394 | + } |
|
| 5092 | 5395 | |
| 5093 | 5396 | $tz = timezone_open($tzid); |
| 5094 | 5397 | |
@@ -5109,8 +5412,9 @@ discard block |
||
| 5109 | 5412 | } |
| 5110 | 5413 | |
| 5111 | 5414 | // A time zone from a prioritized country? |
| 5112 | - if (in_array($tzid, $priority_tzids)) |
|
| 5113 | - $priority_zones[$tzkey] = true; |
|
| 5415 | + if (in_array($tzid, $priority_tzids)) { |
|
| 5416 | + $priority_zones[$tzkey] = true; |
|
| 5417 | + } |
|
| 5114 | 5418 | |
| 5115 | 5419 | // Keep track of the location and offset for this tzid |
| 5116 | 5420 | $tzid_parts = explode('/', $tzid); |
@@ -5129,15 +5433,17 @@ discard block |
||
| 5129 | 5433 | { |
| 5130 | 5434 | date_timezone_set($date_when, timezone_open($tzvalue['tzid'])); |
| 5131 | 5435 | |
| 5132 | - if (!empty($timezone_descriptions[$tzvalue['tzid']])) |
|
| 5133 | - $desc = $timezone_descriptions[$tzvalue['tzid']]; |
|
| 5134 | - else |
|
| 5135 | - $desc = implode(', ', array_unique($tzvalue['locations'])); |
|
| 5436 | + if (!empty($timezone_descriptions[$tzvalue['tzid']])) { |
|
| 5437 | + $desc = $timezone_descriptions[$tzvalue['tzid']]; |
|
| 5438 | + } else { |
|
| 5439 | + $desc = implode(', ', array_unique($tzvalue['locations'])); |
|
| 5440 | + } |
|
| 5136 | 5441 | |
| 5137 | - if (isset($priority_zones[$tzkey])) |
|
| 5138 | - $priority_timezones[$tzvalue['tzid']] = $tzvalue['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']'; |
|
| 5139 | - else |
|
| 5140 | - $timezones[$tzvalue['tzid']] = $tzvalue['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']'; |
|
| 5442 | + if (isset($priority_zones[$tzkey])) { |
|
| 5443 | + $priority_timezones[$tzvalue['tzid']] = $tzvalue['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']'; |
|
| 5444 | + } else { |
|
| 5445 | + $timezones[$tzvalue['tzid']] = $tzvalue['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']'; |
|
| 5446 | + } |
|
| 5141 | 5447 | } |
| 5142 | 5448 | |
| 5143 | 5449 | $timezones = array_merge( |
@@ -5191,9 +5497,9 @@ discard block |
||
| 5191 | 5497 | 'Indian/Kerguelen' => 'TFT', |
| 5192 | 5498 | ); |
| 5193 | 5499 | |
| 5194 | - if (!empty($missing_tz_abbrs[$tzid])) |
|
| 5195 | - $tz_abbrev = $missing_tz_abbrs[$tzid]; |
|
| 5196 | - else |
|
| 5500 | + if (!empty($missing_tz_abbrs[$tzid])) { |
|
| 5501 | + $tz_abbrev = $missing_tz_abbrs[$tzid]; |
|
| 5502 | + } else |
|
| 5197 | 5503 | { |
| 5198 | 5504 | // Russia likes to experiment with time zones often, and names them as offsets from Moscow |
| 5199 | 5505 | $tz_location = timezone_location_get(timezone_open($tzid)); |
@@ -5221,8 +5527,9 @@ discard block |
||
| 5221 | 5527 | */ |
| 5222 | 5528 | function inet_ptod($ip_address) |
| 5223 | 5529 | { |
| 5224 | - if (!isValidIP($ip_address)) |
|
| 5225 | - return $ip_address; |
|
| 5530 | + if (!isValidIP($ip_address)) { |
|
| 5531 | + return $ip_address; |
|
| 5532 | + } |
|
| 5226 | 5533 | |
| 5227 | 5534 | $bin = inet_pton($ip_address); |
| 5228 | 5535 | return $bin; |
@@ -5234,13 +5541,15 @@ discard block |
||
| 5234 | 5541 | */ |
| 5235 | 5542 | function inet_dtop($bin) |
| 5236 | 5543 | { |
| 5237 | - if(empty($bin)) |
|
| 5238 | - return ''; |
|
| 5544 | + if(empty($bin)) { |
|
| 5545 | + return ''; |
|
| 5546 | + } |
|
| 5239 | 5547 | |
| 5240 | 5548 | global $db_type; |
| 5241 | 5549 | |
| 5242 | - if ($db_type == 'postgresql') |
|
| 5243 | - return $bin; |
|
| 5550 | + if ($db_type == 'postgresql') { |
|
| 5551 | + return $bin; |
|
| 5552 | + } |
|
| 5244 | 5553 | |
| 5245 | 5554 | $ip_address = inet_ntop($bin); |
| 5246 | 5555 | |
@@ -5265,26 +5574,32 @@ discard block |
||
| 5265 | 5574 | */ |
| 5266 | 5575 | function _safe_serialize($value) |
| 5267 | 5576 | { |
| 5268 | - if(is_null($value)) |
|
| 5269 | - return 'N;'; |
|
| 5577 | + if(is_null($value)) { |
|
| 5578 | + return 'N;'; |
|
| 5579 | + } |
|
| 5270 | 5580 | |
| 5271 | - if(is_bool($value)) |
|
| 5272 | - return 'b:'. (int) $value .';'; |
|
| 5581 | + if(is_bool($value)) { |
|
| 5582 | + return 'b:'. (int) $value .';'; |
|
| 5583 | + } |
|
| 5273 | 5584 | |
| 5274 | - if(is_int($value)) |
|
| 5275 | - return 'i:'. $value .';'; |
|
| 5585 | + if(is_int($value)) { |
|
| 5586 | + return 'i:'. $value .';'; |
|
| 5587 | + } |
|
| 5276 | 5588 | |
| 5277 | - if(is_float($value)) |
|
| 5278 | - return 'd:'. str_replace(',', '.', $value) .';'; |
|
| 5589 | + if(is_float($value)) { |
|
| 5590 | + return 'd:'. str_replace(',', '.', $value) .';'; |
|
| 5591 | + } |
|
| 5279 | 5592 | |
| 5280 | - if(is_string($value)) |
|
| 5281 | - return 's:'. strlen($value) .':"'. $value .'";'; |
|
| 5593 | + if(is_string($value)) { |
|
| 5594 | + return 's:'. strlen($value) .':"'. $value .'";'; |
|
| 5595 | + } |
|
| 5282 | 5596 | |
| 5283 | 5597 | if(is_array($value)) |
| 5284 | 5598 | { |
| 5285 | 5599 | $out = ''; |
| 5286 | - foreach($value as $k => $v) |
|
| 5287 | - $out .= _safe_serialize($k) . _safe_serialize($v); |
|
| 5600 | + foreach($value as $k => $v) { |
|
| 5601 | + $out .= _safe_serialize($k) . _safe_serialize($v); |
|
| 5602 | + } |
|
| 5288 | 5603 | |
| 5289 | 5604 | return 'a:'. count($value) .':{'. $out .'}'; |
| 5290 | 5605 | } |
@@ -5310,8 +5625,9 @@ discard block |
||
| 5310 | 5625 | |
| 5311 | 5626 | $out = _safe_serialize($value); |
| 5312 | 5627 | |
| 5313 | - if (isset($mbIntEnc)) |
|
| 5314 | - mb_internal_encoding($mbIntEnc); |
|
| 5628 | + if (isset($mbIntEnc)) { |
|
| 5629 | + mb_internal_encoding($mbIntEnc); |
|
| 5630 | + } |
|
| 5315 | 5631 | |
| 5316 | 5632 | return $out; |
| 5317 | 5633 | } |
@@ -5328,8 +5644,9 @@ discard block |
||
| 5328 | 5644 | function _safe_unserialize($str) |
| 5329 | 5645 | { |
| 5330 | 5646 | // Input is not a string. |
| 5331 | - if(empty($str) || !is_string($str)) |
|
| 5332 | - return false; |
|
| 5647 | + if(empty($str) || !is_string($str)) { |
|
| 5648 | + return false; |
|
| 5649 | + } |
|
| 5333 | 5650 | |
| 5334 | 5651 | $stack = array(); |
| 5335 | 5652 | $expected = array(); |
@@ -5345,43 +5662,38 @@ discard block |
||
| 5345 | 5662 | while($state != 1) |
| 5346 | 5663 | { |
| 5347 | 5664 | $type = isset($str[0]) ? $str[0] : ''; |
| 5348 | - if($type == '}') |
|
| 5349 | - $str = substr($str, 1); |
|
| 5350 | - |
|
| 5351 | - else if($type == 'N' && $str[1] == ';') |
|
| 5665 | + if($type == '}') { |
|
| 5666 | + $str = substr($str, 1); |
|
| 5667 | + } else if($type == 'N' && $str[1] == ';') |
|
| 5352 | 5668 | { |
| 5353 | 5669 | $value = null; |
| 5354 | 5670 | $str = substr($str, 2); |
| 5355 | - } |
|
| 5356 | - else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches)) |
|
| 5671 | + } else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches)) |
|
| 5357 | 5672 | { |
| 5358 | 5673 | $value = $matches[1] == '1' ? true : false; |
| 5359 | 5674 | $str = substr($str, 4); |
| 5360 | - } |
|
| 5361 | - else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches)) |
|
| 5675 | + } else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches)) |
|
| 5362 | 5676 | { |
| 5363 | 5677 | $value = (int)$matches[1]; |
| 5364 | 5678 | $str = $matches[2]; |
| 5365 | - } |
|
| 5366 | - else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches)) |
|
| 5679 | + } else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches)) |
|
| 5367 | 5680 | { |
| 5368 | 5681 | $value = (float)$matches[1]; |
| 5369 | 5682 | $str = $matches[3]; |
| 5370 | - } |
|
| 5371 | - else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";') |
|
| 5683 | + } else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";') |
|
| 5372 | 5684 | { |
| 5373 | 5685 | $value = substr($matches[2], 0, (int)$matches[1]); |
| 5374 | 5686 | $str = substr($matches[2], (int)$matches[1] + 2); |
| 5375 | - } |
|
| 5376 | - else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches)) |
|
| 5687 | + } else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches)) |
|
| 5377 | 5688 | { |
| 5378 | 5689 | $expectedLength = (int)$matches[1]; |
| 5379 | 5690 | $str = $matches[2]; |
| 5380 | 5691 | } |
| 5381 | 5692 | |
| 5382 | 5693 | // Object or unknown/malformed type. |
| 5383 | - else |
|
| 5384 | - return false; |
|
| 5694 | + else { |
|
| 5695 | + return false; |
|
| 5696 | + } |
|
| 5385 | 5697 | |
| 5386 | 5698 | switch($state) |
| 5387 | 5699 | { |
@@ -5409,8 +5721,9 @@ discard block |
||
| 5409 | 5721 | if($type == '}') |
| 5410 | 5722 | { |
| 5411 | 5723 | // Array size is less than expected. |
| 5412 | - if(count($list) < end($expected)) |
|
| 5413 | - return false; |
|
| 5724 | + if(count($list) < end($expected)) { |
|
| 5725 | + return false; |
|
| 5726 | + } |
|
| 5414 | 5727 | |
| 5415 | 5728 | unset($list); |
| 5416 | 5729 | $list = &$stack[count($stack)-1]; |
@@ -5419,8 +5732,9 @@ discard block |
||
| 5419 | 5732 | // Go to terminal state if we're at the end of the root array. |
| 5420 | 5733 | array_pop($expected); |
| 5421 | 5734 | |
| 5422 | - if(count($expected) == 0) |
|
| 5423 | - $state = 1; |
|
| 5735 | + if(count($expected) == 0) { |
|
| 5736 | + $state = 1; |
|
| 5737 | + } |
|
| 5424 | 5738 | |
| 5425 | 5739 | break; |
| 5426 | 5740 | } |
@@ -5428,8 +5742,9 @@ discard block |
||
| 5428 | 5742 | if($type == 'i' || $type == 's') |
| 5429 | 5743 | { |
| 5430 | 5744 | // Array size exceeds expected length. |
| 5431 | - if(count($list) >= end($expected)) |
|
| 5432 | - return false; |
|
| 5745 | + if(count($list) >= end($expected)) { |
|
| 5746 | + return false; |
|
| 5747 | + } |
|
| 5433 | 5748 | |
| 5434 | 5749 | $key = $value; |
| 5435 | 5750 | $state = 3; |
@@ -5463,8 +5778,9 @@ discard block |
||
| 5463 | 5778 | } |
| 5464 | 5779 | |
| 5465 | 5780 | // Trailing data in input. |
| 5466 | - if(!empty($str)) |
|
| 5467 | - return false; |
|
| 5781 | + if(!empty($str)) { |
|
| 5782 | + return false; |
|
| 5783 | + } |
|
| 5468 | 5784 | |
| 5469 | 5785 | return $data; |
| 5470 | 5786 | } |
@@ -5487,8 +5803,9 @@ discard block |
||
| 5487 | 5803 | |
| 5488 | 5804 | $out = _safe_unserialize($str); |
| 5489 | 5805 | |
| 5490 | - if (isset($mbIntEnc)) |
|
| 5491 | - mb_internal_encoding($mbIntEnc); |
|
| 5806 | + if (isset($mbIntEnc)) { |
|
| 5807 | + mb_internal_encoding($mbIntEnc); |
|
| 5808 | + } |
|
| 5492 | 5809 | |
| 5493 | 5810 | return $out; |
| 5494 | 5811 | } |
@@ -5503,12 +5820,14 @@ discard block |
||
| 5503 | 5820 | function smf_chmod($file, $value = 0) |
| 5504 | 5821 | { |
| 5505 | 5822 | // No file? no checks! |
| 5506 | - if (empty($file)) |
|
| 5507 | - return false; |
|
| 5823 | + if (empty($file)) { |
|
| 5824 | + return false; |
|
| 5825 | + } |
|
| 5508 | 5826 | |
| 5509 | 5827 | // Already writable? |
| 5510 | - if (is_writable($file)) |
|
| 5511 | - return true; |
|
| 5828 | + if (is_writable($file)) { |
|
| 5829 | + return true; |
|
| 5830 | + } |
|
| 5512 | 5831 | |
| 5513 | 5832 | // Do we have a file or a dir? |
| 5514 | 5833 | $isDir = is_dir($file); |
@@ -5524,10 +5843,9 @@ discard block |
||
| 5524 | 5843 | { |
| 5525 | 5844 | $isWritable = true; |
| 5526 | 5845 | break; |
| 5846 | + } else { |
|
| 5847 | + @chmod($file, $val); |
|
| 5527 | 5848 | } |
| 5528 | - |
|
| 5529 | - else |
|
| 5530 | - @chmod($file, $val); |
|
| 5531 | 5849 | } |
| 5532 | 5850 | |
| 5533 | 5851 | return $isWritable; |
@@ -5546,8 +5864,9 @@ discard block |
||
| 5546 | 5864 | global $txt; |
| 5547 | 5865 | |
| 5548 | 5866 | // Come on... |
| 5549 | - if (empty($json) || !is_string($json)) |
|
| 5550 | - return array(); |
|
| 5867 | + if (empty($json) || !is_string($json)) { |
|
| 5868 | + return array(); |
|
| 5869 | + } |
|
| 5551 | 5870 | |
| 5552 | 5871 | $returnArray = @json_decode($json, $returnAsArray); |
| 5553 | 5872 | |
@@ -5585,11 +5904,11 @@ discard block |
||
| 5585 | 5904 | $jsonDebug = $jsonDebug[0]; |
| 5586 | 5905 | loadLanguage('Errors'); |
| 5587 | 5906 | |
| 5588 | - if (!empty($jsonDebug)) |
|
| 5589 | - log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']); |
|
| 5590 | - |
|
| 5591 | - else |
|
| 5592 | - log_error($txt['json_'. $jsonError], 'critical'); |
|
| 5907 | + if (!empty($jsonDebug)) { |
|
| 5908 | + log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']); |
|
| 5909 | + } else { |
|
| 5910 | + log_error($txt['json_'. $jsonError], 'critical'); |
|
| 5911 | + } |
|
| 5593 | 5912 | |
| 5594 | 5913 | // Everyone expects an array. |
| 5595 | 5914 | return array(); |
@@ -5623,8 +5942,9 @@ discard block |
||
| 5623 | 5942 | global $db_show_debug, $modSettings; |
| 5624 | 5943 | |
| 5625 | 5944 | // Defensive programming anyone? |
| 5626 | - if (empty($data)) |
|
| 5627 | - return false; |
|
| 5945 | + if (empty($data)) { |
|
| 5946 | + return false; |
|
| 5947 | + } |
|
| 5628 | 5948 | |
| 5629 | 5949 | // Don't need extra stuff... |
| 5630 | 5950 | $db_show_debug = false; |
@@ -5632,11 +5952,11 @@ discard block |
||
| 5632 | 5952 | // Kill anything else. |
| 5633 | 5953 | ob_end_clean(); |
| 5634 | 5954 | |
| 5635 | - if (!empty($modSettings['CompressedOutput'])) |
|
| 5636 | - @ob_start('ob_gzhandler'); |
|
| 5637 | - |
|
| 5638 | - else |
|
| 5639 | - ob_start(); |
|
| 5955 | + if (!empty($modSettings['CompressedOutput'])) { |
|
| 5956 | + @ob_start('ob_gzhandler'); |
|
| 5957 | + } else { |
|
| 5958 | + ob_start(); |
|
| 5959 | + } |
|
| 5640 | 5960 | |
| 5641 | 5961 | // Set the header. |
| 5642 | 5962 | header($type); |
@@ -5668,8 +5988,9 @@ discard block |
||
| 5668 | 5988 | static $done = false; |
| 5669 | 5989 | |
| 5670 | 5990 | // If we don't need to do anything, don't |
| 5671 | - if (!$update && $done) |
|
| 5672 | - return; |
|
| 5991 | + if (!$update && $done) { |
|
| 5992 | + return; |
|
| 5993 | + } |
|
| 5673 | 5994 | |
| 5674 | 5995 | // Should we get a new copy of the official list of TLDs? |
| 5675 | 5996 | if ($update) |
@@ -5678,8 +5999,9 @@ discard block |
||
| 5678 | 5999 | $tlds = fetch_web_data('https://data.iana.org/TLD/tlds-alpha-by-domain.txt'); |
| 5679 | 6000 | |
| 5680 | 6001 | // If the Internet Assigned Numbers Authority can't be reached, the Internet is gone. We're probably running on a server hidden in a bunker deep underground to protect it from marauding bandits roaming on the surface. We don't want to waste precious electricity on pointlessly repeating background tasks, so we'll wait until the next regularly scheduled update to see if civilization has been restored. |
| 5681 | - if ($tlds === false) |
|
| 5682 | - $postapocalypticNightmare = true; |
|
| 6002 | + if ($tlds === false) { |
|
| 6003 | + $postapocalypticNightmare = true; |
|
| 6004 | + } |
|
| 5683 | 6005 | } |
| 5684 | 6006 | // If we aren't updating and the regex is valid, we're done |
| 5685 | 6007 | elseif (!empty($modSettings['tld_regex']) && @preg_match('~' . $modSettings['tld_regex'] . '~', null) !== false) |
@@ -5694,10 +6016,11 @@ discard block |
||
| 5694 | 6016 | // Clean $tlds and convert it to an array |
| 5695 | 6017 | $tlds = array_filter(explode("\n", strtolower($tlds)), function($line) { |
| 5696 | 6018 | $line = trim($line); |
| 5697 | - if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) |
|
| 5698 | - return false; |
|
| 5699 | - else |
|
| 5700 | - return true; |
|
| 6019 | + if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) { |
|
| 6020 | + return false; |
|
| 6021 | + } else { |
|
| 6022 | + return true; |
|
| 6023 | + } |
|
| 5701 | 6024 | }); |
| 5702 | 6025 | |
| 5703 | 6026 | // Convert Punycode to Unicode |
@@ -5751,8 +6074,9 @@ discard block |
||
| 5751 | 6074 | $idx += $digit * $w; |
| 5752 | 6075 | $t = ($k <= $bias) ? $tmin : (($k >= $bias + $tmax) ? $tmax : ($k - $bias)); |
| 5753 | 6076 | |
| 5754 | - if ($digit < $t) |
|
| 5755 | - break; |
|
| 6077 | + if ($digit < $t) { |
|
| 6078 | + break; |
|
| 6079 | + } |
|
| 5756 | 6080 | |
| 5757 | 6081 | $w = (int) ($w * ($base - $t)); |
| 5758 | 6082 | } |
@@ -5761,8 +6085,9 @@ discard block |
||
| 5761 | 6085 | $delta = intval($is_first ? ($delta / $damp) : ($delta / 2)); |
| 5762 | 6086 | $delta += intval($delta / ($deco_len + 1)); |
| 5763 | 6087 | |
| 5764 | - for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base) |
|
| 5765 | - $delta = intval($delta / ($base - $tmin)); |
|
| 6088 | + for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base) { |
|
| 6089 | + $delta = intval($delta / ($base - $tmin)); |
|
| 6090 | + } |
|
| 5766 | 6091 | |
| 5767 | 6092 | $bias = intval($k + ($base - $tmin + 1) * $delta / ($delta + $skew)); |
| 5768 | 6093 | $is_first = false; |
@@ -5771,8 +6096,9 @@ discard block |
||
| 5771 | 6096 | |
| 5772 | 6097 | if ($deco_len > 0) |
| 5773 | 6098 | { |
| 5774 | - for ($i = $deco_len; $i > $idx; $i--) |
|
| 5775 | - $decoded[$i] = $decoded[($i - 1)]; |
|
| 6099 | + for ($i = $deco_len; $i > $idx; $i--) { |
|
| 6100 | + $decoded[$i] = $decoded[($i - 1)]; |
|
| 6101 | + } |
|
| 5776 | 6102 | } |
| 5777 | 6103 | $decoded[$idx++] = $char; |
| 5778 | 6104 | } |
@@ -5780,24 +6106,29 @@ discard block |
||
| 5780 | 6106 | foreach ($decoded as $k => $v) |
| 5781 | 6107 | { |
| 5782 | 6108 | // 7bit are transferred literally |
| 5783 | - if ($v < 128) |
|
| 5784 | - $output .= chr($v); |
|
| 6109 | + if ($v < 128) { |
|
| 6110 | + $output .= chr($v); |
|
| 6111 | + } |
|
| 5785 | 6112 | |
| 5786 | 6113 | // 2 bytes |
| 5787 | - elseif ($v < (1 << 11)) |
|
| 5788 | - $output .= chr(192+($v >> 6)) . chr(128+($v & 63)); |
|
| 6114 | + elseif ($v < (1 << 11)) { |
|
| 6115 | + $output .= chr(192+($v >> 6)) . chr(128+($v & 63)); |
|
| 6116 | + } |
|
| 5789 | 6117 | |
| 5790 | 6118 | // 3 bytes |
| 5791 | - elseif ($v < (1 << 16)) |
|
| 5792 | - $output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
| 6119 | + elseif ($v < (1 << 16)) { |
|
| 6120 | + $output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
| 6121 | + } |
|
| 5793 | 6122 | |
| 5794 | 6123 | // 4 bytes |
| 5795 | - elseif ($v < (1 << 21)) |
|
| 5796 | - $output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
| 6124 | + elseif ($v < (1 << 21)) { |
|
| 6125 | + $output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
| 6126 | + } |
|
| 5797 | 6127 | |
| 5798 | 6128 | // 'Conversion from UCS-4 to UTF-8 failed: malformed input at byte '.$k |
| 5799 | - else |
|
| 5800 | - $output .= $safe_char; |
|
| 6129 | + else { |
|
| 6130 | + $output .= $safe_char; |
|
| 6131 | + } |
|
| 5801 | 6132 | } |
| 5802 | 6133 | |
| 5803 | 6134 | $output_parts[] = $output; |
@@ -5890,8 +6221,7 @@ discard block |
||
| 5890 | 6221 | |
| 5891 | 6222 | $strlen = 'mb_strlen'; |
| 5892 | 6223 | $substr = 'mb_substr'; |
| 5893 | - } |
|
| 5894 | - else |
|
| 6224 | + } else |
|
| 5895 | 6225 | { |
| 5896 | 6226 | $strlen = $smcFunc['strlen']; |
| 5897 | 6227 | $substr = $smcFunc['substr']; |
@@ -5905,20 +6235,21 @@ discard block |
||
| 5905 | 6235 | |
| 5906 | 6236 | $first = $substr($string, 0, 1); |
| 5907 | 6237 | |
| 5908 | - if (empty($index[$first])) |
|
| 5909 | - $index[$first] = array(); |
|
| 6238 | + if (empty($index[$first])) { |
|
| 6239 | + $index[$first] = array(); |
|
| 6240 | + } |
|
| 5910 | 6241 | |
| 5911 | 6242 | if ($strlen($string) > 1) |
| 5912 | 6243 | { |
| 5913 | 6244 | // Sanity check on recursion |
| 5914 | - if ($depth > 99) |
|
| 5915 | - $index[$first][$substr($string, 1)] = ''; |
|
| 5916 | - |
|
| 5917 | - else |
|
| 5918 | - $index[$first] = $add_string_to_index($substr($string, 1), $index[$first]); |
|
| 6245 | + if ($depth > 99) { |
|
| 6246 | + $index[$first][$substr($string, 1)] = ''; |
|
| 6247 | + } else { |
|
| 6248 | + $index[$first] = $add_string_to_index($substr($string, 1), $index[$first]); |
|
| 6249 | + } |
|
| 6250 | + } else { |
|
| 6251 | + $index[$first][''] = ''; |
|
| 5919 | 6252 | } |
| 5920 | - else |
|
| 5921 | - $index[$first][''] = ''; |
|
| 5922 | 6253 | |
| 5923 | 6254 | $depth--; |
| 5924 | 6255 | return $index; |
@@ -5941,9 +6272,9 @@ discard block |
||
| 5941 | 6272 | $key_regex = preg_quote($key, $delim); |
| 5942 | 6273 | $new_key = $key; |
| 5943 | 6274 | |
| 5944 | - if (empty($value)) |
|
| 5945 | - $sub_regex = ''; |
|
| 5946 | - else |
|
| 6275 | + if (empty($value)) { |
|
| 6276 | + $sub_regex = ''; |
|
| 6277 | + } else |
|
| 5947 | 6278 | { |
| 5948 | 6279 | $sub_regex = $index_to_regex($value, $delim); |
| 5949 | 6280 | |
@@ -5951,22 +6282,22 @@ discard block |
||
| 5951 | 6282 | { |
| 5952 | 6283 | $new_key_array = explode('(?'.'>', $sub_regex); |
| 5953 | 6284 | $new_key .= $new_key_array[0]; |
| 6285 | + } else { |
|
| 6286 | + $sub_regex = '(?'.'>' . $sub_regex . ')'; |
|
| 5954 | 6287 | } |
| 5955 | - else |
|
| 5956 | - $sub_regex = '(?'.'>' . $sub_regex . ')'; |
|
| 5957 | 6288 | } |
| 5958 | 6289 | |
| 5959 | - if ($depth > 1) |
|
| 5960 | - $regex[$new_key] = $key_regex . $sub_regex; |
|
| 5961 | - else |
|
| 6290 | + if ($depth > 1) { |
|
| 6291 | + $regex[$new_key] = $key_regex . $sub_regex; |
|
| 6292 | + } else |
|
| 5962 | 6293 | { |
| 5963 | 6294 | if (($length += strlen($key_regex) + 1) < $max_length || empty($regex)) |
| 5964 | 6295 | { |
| 5965 | 6296 | $regex[$new_key] = $key_regex . $sub_regex; |
| 5966 | 6297 | unset($index[$key]); |
| 6298 | + } else { |
|
| 6299 | + break; |
|
| 5967 | 6300 | } |
| 5968 | - else |
|
| 5969 | - break; |
|
| 5970 | 6301 | } |
| 5971 | 6302 | } |
| 5972 | 6303 | |
@@ -5975,10 +6306,11 @@ discard block |
||
| 5975 | 6306 | $l1 = $strlen($k1); |
| 5976 | 6307 | $l2 = $strlen($k2); |
| 5977 | 6308 | |
| 5978 | - if ($l1 == $l2) |
|
| 5979 | - return strcmp($k1, $k2) > 0 ? 1 : -1; |
|
| 5980 | - else |
|
| 5981 | - return $l1 > $l2 ? -1 : 1; |
|
| 6309 | + if ($l1 == $l2) { |
|
| 6310 | + return strcmp($k1, $k2) > 0 ? 1 : -1; |
|
| 6311 | + } else { |
|
| 6312 | + return $l1 > $l2 ? -1 : 1; |
|
| 6313 | + } |
|
| 5982 | 6314 | }); |
| 5983 | 6315 | |
| 5984 | 6316 | $depth--; |
@@ -5989,21 +6321,24 @@ discard block |
||
| 5989 | 6321 | $index = array(); |
| 5990 | 6322 | $regex = ''; |
| 5991 | 6323 | |
| 5992 | - foreach ($strings as $string) |
|
| 5993 | - $index = $add_string_to_index($string, $index); |
|
| 6324 | + foreach ($strings as $string) { |
|
| 6325 | + $index = $add_string_to_index($string, $index); |
|
| 6326 | + } |
|
| 5994 | 6327 | |
| 5995 | 6328 | if ($returnArray === true) |
| 5996 | 6329 | { |
| 5997 | 6330 | $regex = array(); |
| 5998 | - while (!empty($index)) |
|
| 5999 | - $regex[] = '(?'.'>' . $index_to_regex($index, $delim) . ')'; |
|
| 6331 | + while (!empty($index)) { |
|
| 6332 | + $regex[] = '(?'.'>' . $index_to_regex($index, $delim) . ')'; |
|
| 6333 | + } |
|
| 6334 | + } else { |
|
| 6335 | + $regex = '(?'.'>' . $index_to_regex($index, $delim) . ')'; |
|
| 6000 | 6336 | } |
| 6001 | - else |
|
| 6002 | - $regex = '(?'.'>' . $index_to_regex($index, $delim) . ')'; |
|
| 6003 | 6337 | |
| 6004 | 6338 | // Restore PHP's internal character encoding to whatever it was originally |
| 6005 | - if (!empty($current_encoding)) |
|
| 6006 | - mb_internal_encoding($current_encoding); |
|
| 6339 | + if (!empty($current_encoding)) { |
|
| 6340 | + mb_internal_encoding($current_encoding); |
|
| 6341 | + } |
|
| 6007 | 6342 | |
| 6008 | 6343 | return $regex; |
| 6009 | 6344 | } |
@@ -6046,13 +6381,15 @@ discard block |
||
| 6046 | 6381 | // Need to add the trailing slash, or it puts it there & thinks there's a redirect when there isn't... |
| 6047 | 6382 | $url = str_ireplace('https://', 'http://', $url) . '/'; |
| 6048 | 6383 | $headers = @get_headers($url); |
| 6049 | - if ($headers === false) |
|
| 6050 | - return false; |
|
| 6384 | + if ($headers === false) { |
|
| 6385 | + return false; |
|
| 6386 | + } |
|
| 6051 | 6387 | |
| 6052 | 6388 | // Now to see if it came back https... |
| 6053 | 6389 | // First check for a redirect status code in first row (301, 302, 307) |
| 6054 | - if (strstr($headers[0], '301') === false && strstr($headers[0], '302') === false && strstr($headers[0], '307') === false) |
|
| 6055 | - return false; |
|
| 6390 | + if (strstr($headers[0], '301') === false && strstr($headers[0], '302') === false && strstr($headers[0], '307') === false) { |
|
| 6391 | + return false; |
|
| 6392 | + } |
|
| 6056 | 6393 | |
| 6057 | 6394 | // Search for the location entry to confirm https |
| 6058 | 6395 | $result = false; |
@@ -6088,8 +6425,7 @@ discard block |
||
| 6088 | 6425 | $is_admin = $user_info['is_admin']; |
| 6089 | 6426 | $mod_cache = !empty($user_info['mod_cache']) ? $user_info['mod_cache'] : null; |
| 6090 | 6427 | $ignoreboards = !empty($user_info['ignoreboards']) ? $user_info['ignoreboards'] : null; |
| 6091 | - } |
|
| 6092 | - else |
|
| 6428 | + } else |
|
| 6093 | 6429 | { |
| 6094 | 6430 | $request = $smcFunc['db_query']('', ' |
| 6095 | 6431 | SELECT mem.ignore_boards, mem.id_group, mem.additional_groups, mem.id_post_group |
@@ -6103,17 +6439,19 @@ discard block |
||
| 6103 | 6439 | |
| 6104 | 6440 | $row = $smcFunc['db_fetch_assoc']($request); |
| 6105 | 6441 | |
| 6106 | - if (empty($row['additional_groups'])) |
|
| 6107 | - $groups = array($row['id_group'], $row['id_post_group']); |
|
| 6108 | - else |
|
| 6109 | - $groups = array_merge( |
|
| 6442 | + if (empty($row['additional_groups'])) { |
|
| 6443 | + $groups = array($row['id_group'], $row['id_post_group']); |
|
| 6444 | + } else { |
|
| 6445 | + $groups = array_merge( |
|
| 6110 | 6446 | array($row['id_group'], $row['id_post_group']), |
| 6111 | 6447 | explode(',', $row['additional_groups']) |
| 6112 | 6448 | ); |
| 6449 | + } |
|
| 6113 | 6450 | |
| 6114 | 6451 | // Because history has proven that it is possible for groups to go bad - clean up in case. |
| 6115 | - foreach ($groups as $k => $v) |
|
| 6116 | - $groups[$k] = (int) $v; |
|
| 6452 | + foreach ($groups as $k => $v) { |
|
| 6453 | + $groups[$k] = (int) $v; |
|
| 6454 | + } |
|
| 6117 | 6455 | |
| 6118 | 6456 | $is_admin = in_array(1, $groups); |
| 6119 | 6457 | |
@@ -6130,8 +6468,9 @@ discard block |
||
| 6130 | 6468 | 'current_member' => $userid, |
| 6131 | 6469 | ) |
| 6132 | 6470 | ); |
| 6133 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 6134 | - $boards_mod[] = $row['id_board']; |
|
| 6471 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 6472 | + $boards_mod[] = $row['id_board']; |
|
| 6473 | + } |
|
| 6135 | 6474 | $smcFunc['db_free_result']($request); |
| 6136 | 6475 | |
| 6137 | 6476 | // Can any of the groups they're in moderate any of the boards? |
@@ -6143,8 +6482,9 @@ discard block |
||
| 6143 | 6482 | 'groups' => $groups, |
| 6144 | 6483 | ) |
| 6145 | 6484 | ); |
| 6146 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 6147 | - $boards_mod[] = $row['id_board']; |
|
| 6485 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 6486 | + $boards_mod[] = $row['id_board']; |
|
| 6487 | + } |
|
| 6148 | 6488 | $smcFunc['db_free_result']($request); |
| 6149 | 6489 | |
| 6150 | 6490 | // Just in case we've got duplicates here... |
@@ -6154,21 +6494,25 @@ discard block |
||
| 6154 | 6494 | } |
| 6155 | 6495 | |
| 6156 | 6496 | // Just build this here, it makes it easier to change/use - administrators can see all boards. |
| 6157 | - if ($is_admin) |
|
| 6158 | - $query_part['query_see_board'] = '1=1'; |
|
| 6497 | + if ($is_admin) { |
|
| 6498 | + $query_part['query_see_board'] = '1=1'; |
|
| 6499 | + } |
|
| 6159 | 6500 | // Otherwise just the groups in $user_info['groups']. |
| 6160 | - else |
|
| 6161 | - $query_part['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $groups) . ', b.member_groups) != 0)' . (!empty($deny_boards_access) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $groups) . ', b.deny_member_groups) = 0)' : '') . (isset($mod_cache) ? ' OR ' . $mod_cache['mq'] : '') . ')'; |
|
| 6501 | + else { |
|
| 6502 | + $query_part['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $groups) . ', b.member_groups) != 0)' . (!empty($deny_boards_access) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $groups) . ', b.deny_member_groups) = 0)' : '') . (isset($mod_cache) ? ' OR ' . $mod_cache['mq'] : '') . ')'; |
|
| 6503 | + } |
|
| 6162 | 6504 | |
| 6163 | 6505 | // Build the list of boards they WANT to see. |
| 6164 | 6506 | // This will take the place of query_see_boards in certain spots, so it better include the boards they can see also |
| 6165 | 6507 | |
| 6166 | 6508 | // If they aren't ignoring any boards then they want to see all the boards they can see |
| 6167 | - if (empty($ignoreboards)) |
|
| 6168 | - $query_part['query_wanna_see_board'] = $query_part['query_see_board']; |
|
| 6509 | + if (empty($ignoreboards)) { |
|
| 6510 | + $query_part['query_wanna_see_board'] = $query_part['query_see_board']; |
|
| 6511 | + } |
|
| 6169 | 6512 | // Ok I guess they don't want to see all the boards |
| 6170 | - else |
|
| 6171 | - $query_part['query_wanna_see_board'] = '(' . $query_part['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $ignoreboards) . '))'; |
|
| 6513 | + else { |
|
| 6514 | + $query_part['query_wanna_see_board'] = '(' . $query_part['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $ignoreboards) . '))'; |
|
| 6515 | + } |
|
| 6172 | 6516 | |
| 6173 | 6517 | return $query_part; |
| 6174 | 6518 | } |
@@ -6182,10 +6526,11 @@ discard block |
||
| 6182 | 6526 | { |
| 6183 | 6527 | $secure = false; |
| 6184 | 6528 | |
| 6185 | - if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') |
|
| 6186 | - $secure = true; |
|
| 6187 | - elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') |
|
| 6188 | - $secure = true; |
|
| 6529 | + if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { |
|
| 6530 | + $secure = true; |
|
| 6531 | + } elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') { |
|
| 6532 | + $secure = true; |
|
| 6533 | + } |
|
| 6189 | 6534 | |
| 6190 | 6535 | return $secure; |
| 6191 | 6536 | } |
@@ -15,8 +15,9 @@ discard block |
||
| 15 | 15 | * @version 2.1 Beta 4 |
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | -if (!defined('SMF')) |
|
| 18 | +if (!defined('SMF')) { |
|
| 19 | 19 | die('No direct access...'); |
| 20 | +} |
|
| 20 | 21 | |
| 21 | 22 | /** |
| 22 | 23 | * This defines every profile field known to man. |
@@ -29,8 +30,9 @@ discard block |
||
| 29 | 30 | global $sourcedir, $profile_vars; |
| 30 | 31 | |
| 31 | 32 | // Don't load this twice! |
| 32 | - if (!empty($profile_fields) && !$force_reload) |
|
| 33 | - return; |
|
| 33 | + if (!empty($profile_fields) && !$force_reload) { |
|
| 34 | + return; |
|
| 35 | + } |
|
| 34 | 36 | |
| 35 | 37 | /* This horrific array defines all the profile fields in the whole world! |
| 36 | 38 | In general each "field" has one array - the key of which is the database column name associated with said field. Each item |
@@ -103,13 +105,14 @@ discard block |
||
| 103 | 105 | if (isset($_POST['bday2'], $_POST['bday3']) && $value > 0 && $_POST['bday2'] > 0) |
| 104 | 106 | { |
| 105 | 107 | // Set to blank? |
| 106 | - if ((int) $_POST['bday3'] == 1 && (int) $_POST['bday2'] == 1 && (int) $value == 1) |
|
| 107 | - $value = '1004-01-01'; |
|
| 108 | - else |
|
| 109 | - $value = checkdate($value, $_POST['bday2'], $_POST['bday3'] < 1004 ? 1004 : $_POST['bday3']) ? sprintf('%04d-%02d-%02d', $_POST['bday3'] < 1004 ? 1004 : $_POST['bday3'], $_POST['bday1'], $_POST['bday2']) : '1004-01-01'; |
|
| 108 | + if ((int) $_POST['bday3'] == 1 && (int) $_POST['bday2'] == 1 && (int) $value == 1) { |
|
| 109 | + $value = '1004-01-01'; |
|
| 110 | + } else { |
|
| 111 | + $value = checkdate($value, $_POST['bday2'], $_POST['bday3'] < 1004 ? 1004 : $_POST['bday3']) ? sprintf('%04d-%02d-%02d', $_POST['bday3'] < 1004 ? 1004 : $_POST['bday3'], $_POST['bday1'], $_POST['bday2']) : '1004-01-01'; |
|
| 112 | + } |
|
| 113 | + } else { |
|
| 114 | + $value = '1004-01-01'; |
|
| 110 | 115 | } |
| 111 | - else |
|
| 112 | - $value = '1004-01-01'; |
|
| 113 | 116 | |
| 114 | 117 | $profile_vars['birthdate'] = $value; |
| 115 | 118 | $cur_profile['birthdate'] = $value; |
@@ -127,8 +130,7 @@ discard block |
||
| 127 | 130 | { |
| 128 | 131 | $value = checkdate($dates[2], $dates[3], $dates[1] < 4 ? 4 : $dates[1]) ? sprintf('%04d-%02d-%02d', $dates[1] < 4 ? 4 : $dates[1], $dates[2], $dates[3]) : '1004-01-01'; |
| 129 | 132 | return true; |
| 130 | - } |
|
| 131 | - else |
|
| 133 | + } else |
|
| 132 | 134 | { |
| 133 | 135 | $value = empty($cur_profile['birthdate']) ? '1004-01-01' : $cur_profile['birthdate']; |
| 134 | 136 | return false; |
@@ -150,10 +152,11 @@ discard block |
||
| 150 | 152 | return $txt['invalid_registration'] . ' ' . strftime('%d %b %Y ' . (strpos($user_info['time_format'], '%H') !== false ? '%I:%M:%S %p' : '%H:%M:%S'), forum_time(false)); |
| 151 | 153 | } |
| 152 | 154 | // As long as it doesn't equal "N/A"... |
| 153 | - elseif ($value != $txt['not_applicable'] && $value != strtotime(strftime('%Y-%m-%d', $cur_profile['date_registered'] + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600))) |
|
| 154 | - $value = $value - ($user_info['time_offset'] + $modSettings['time_offset']) * 3600; |
|
| 155 | - else |
|
| 156 | - $value = $cur_profile['date_registered']; |
|
| 155 | + elseif ($value != $txt['not_applicable'] && $value != strtotime(strftime('%Y-%m-%d', $cur_profile['date_registered'] + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600))) { |
|
| 156 | + $value = $value - ($user_info['time_offset'] + $modSettings['time_offset']) * 3600; |
|
| 157 | + } else { |
|
| 158 | + $value = $cur_profile['date_registered']; |
|
| 159 | + } |
|
| 157 | 160 | |
| 158 | 161 | return true; |
| 159 | 162 | }, |
@@ -177,8 +180,9 @@ discard block |
||
| 177 | 180 | { |
| 178 | 181 | global $context, $old_profile, $profile_vars, $sourcedir, $modSettings; |
| 179 | 182 | |
| 180 | - if (strtolower($value) == strtolower($old_profile['email_address'])) |
|
| 181 | - return false; |
|
| 183 | + if (strtolower($value) == strtolower($old_profile['email_address'])) { |
|
| 184 | + return false; |
|
| 185 | + } |
|
| 182 | 186 | |
| 183 | 187 | $isValid = profileValidateEmail($value, $context['id_member']); |
| 184 | 188 | |
@@ -254,11 +258,11 @@ discard block |
||
| 254 | 258 | |
| 255 | 259 | if (isset($context['profile_languages'][$value])) |
| 256 | 260 | { |
| 257 | - if ($context['user']['is_owner'] && empty($context['password_auth_failed'])) |
|
| 258 | - $_SESSION['language'] = $value; |
|
| 261 | + if ($context['user']['is_owner'] && empty($context['password_auth_failed'])) { |
|
| 262 | + $_SESSION['language'] = $value; |
|
| 263 | + } |
|
| 259 | 264 | return true; |
| 260 | - } |
|
| 261 | - else |
|
| 265 | + } else |
|
| 262 | 266 | { |
| 263 | 267 | $value = $cur_profile['lngfile']; |
| 264 | 268 | return false; |
@@ -282,13 +286,14 @@ discard block |
||
| 282 | 286 | |
| 283 | 287 | // Maybe they are trying to change their password as well? |
| 284 | 288 | $resetPassword = true; |
| 285 | - if (isset($_POST['passwrd1']) && $_POST['passwrd1'] != '' && isset($_POST['passwrd2']) && $_POST['passwrd1'] == $_POST['passwrd2'] && validatePassword($_POST['passwrd1'], $value, array($cur_profile['real_name'], $user_info['username'], $user_info['name'], $user_info['email'])) == null) |
|
| 286 | - $resetPassword = false; |
|
| 289 | + if (isset($_POST['passwrd1']) && $_POST['passwrd1'] != '' && isset($_POST['passwrd2']) && $_POST['passwrd1'] == $_POST['passwrd2'] && validatePassword($_POST['passwrd1'], $value, array($cur_profile['real_name'], $user_info['username'], $user_info['name'], $user_info['email'])) == null) { |
|
| 290 | + $resetPassword = false; |
|
| 291 | + } |
|
| 287 | 292 | |
| 288 | 293 | // Do the reset... this will send them an email too. |
| 289 | - if ($resetPassword) |
|
| 290 | - resetPassword($context['id_member'], $value); |
|
| 291 | - elseif ($value !== null) |
|
| 294 | + if ($resetPassword) { |
|
| 295 | + resetPassword($context['id_member'], $value); |
|
| 296 | + } elseif ($value !== null) |
|
| 292 | 297 | { |
| 293 | 298 | validateUsername($context['id_member'], trim(preg_replace('~[\t\n\r \x0B\0' . ($context['utf8'] ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : '\x00-\x08\x0B\x0C\x0E-\x19\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $value))); |
| 294 | 299 | updateMemberData($context['id_member'], array('member_name' => $value)); |
@@ -312,20 +317,23 @@ discard block |
||
| 312 | 317 | 'input_validate' => function(&$value) use ($sourcedir, $user_info, $smcFunc, $cur_profile) |
| 313 | 318 | { |
| 314 | 319 | // If we didn't try it then ignore it! |
| 315 | - if ($value == '') |
|
| 316 | - return false; |
|
| 320 | + if ($value == '') { |
|
| 321 | + return false; |
|
| 322 | + } |
|
| 317 | 323 | |
| 318 | 324 | // Do the two entries for the password even match? |
| 319 | - if (!isset($_POST['passwrd2']) || $value != $_POST['passwrd2']) |
|
| 320 | - return 'bad_new_password'; |
|
| 325 | + if (!isset($_POST['passwrd2']) || $value != $_POST['passwrd2']) { |
|
| 326 | + return 'bad_new_password'; |
|
| 327 | + } |
|
| 321 | 328 | |
| 322 | 329 | // Let's get the validation function into play... |
| 323 | 330 | require_once($sourcedir . '/Subs-Auth.php'); |
| 324 | 331 | $passwordErrors = validatePassword($value, $cur_profile['member_name'], array($cur_profile['real_name'], $user_info['username'], $user_info['name'], $user_info['email'])); |
| 325 | 332 | |
| 326 | 333 | // Were there errors? |
| 327 | - if ($passwordErrors != null) |
|
| 328 | - return 'password_' . $passwordErrors; |
|
| 334 | + if ($passwordErrors != null) { |
|
| 335 | + return 'password_' . $passwordErrors; |
|
| 336 | + } |
|
| 329 | 337 | |
| 330 | 338 | // Set up the new password variable... ready for storage. |
| 331 | 339 | $value = hash_password($cur_profile['member_name'], un_htmlspecialchars($value)); |
@@ -350,8 +358,9 @@ discard block |
||
| 350 | 358 | 'permission' => 'profile_blurb', |
| 351 | 359 | 'input_validate' => function(&$value) use ($smcFunc) |
| 352 | 360 | { |
| 353 | - if ($smcFunc['strlen']($value) > 50) |
|
| 354 | - return 'personal_text_too_long'; |
|
| 361 | + if ($smcFunc['strlen']($value) > 50) { |
|
| 362 | + return 'personal_text_too_long'; |
|
| 363 | + } |
|
| 355 | 364 | |
| 356 | 365 | return true; |
| 357 | 366 | }, |
@@ -386,10 +395,11 @@ discard block |
||
| 386 | 395 | 'permission' => 'moderate_forum', |
| 387 | 396 | 'input_validate' => function(&$value) |
| 388 | 397 | { |
| 389 | - if (!is_numeric($value)) |
|
| 390 | - return 'digits_only'; |
|
| 391 | - else |
|
| 392 | - $value = $value != '' ? strtr($value, array(',' => '', '.' => '', ' ' => '')) : 0; |
|
| 398 | + if (!is_numeric($value)) { |
|
| 399 | + return 'digits_only'; |
|
| 400 | + } else { |
|
| 401 | + $value = $value != '' ? strtr($value, array(',' => '', '.' => '', ' ' => '')) : 0; |
|
| 402 | + } |
|
| 393 | 403 | return true; |
| 394 | 404 | }, |
| 395 | 405 | ), |
@@ -405,15 +415,16 @@ discard block |
||
| 405 | 415 | { |
| 406 | 416 | $value = trim(preg_replace('~[\t\n\r \x0B\0' . ($context['utf8'] ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : '\x00-\x08\x0B\x0C\x0E-\x19\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $value)); |
| 407 | 417 | |
| 408 | - if (trim($value) == '') |
|
| 409 | - return 'no_name'; |
|
| 410 | - elseif ($smcFunc['strlen']($value) > 60) |
|
| 411 | - return 'name_too_long'; |
|
| 412 | - elseif ($cur_profile['real_name'] != $value) |
|
| 418 | + if (trim($value) == '') { |
|
| 419 | + return 'no_name'; |
|
| 420 | + } elseif ($smcFunc['strlen']($value) > 60) { |
|
| 421 | + return 'name_too_long'; |
|
| 422 | + } elseif ($cur_profile['real_name'] != $value) |
|
| 413 | 423 | { |
| 414 | 424 | require_once($sourcedir . '/Subs-Members.php'); |
| 415 | - if (isReservedName($value, $context['id_member'])) |
|
| 416 | - return 'name_taken'; |
|
| 425 | + if (isReservedName($value, $context['id_member'])) { |
|
| 426 | + return 'name_taken'; |
|
| 427 | + } |
|
| 417 | 428 | } |
| 418 | 429 | return true; |
| 419 | 430 | }, |
@@ -471,8 +482,9 @@ discard block |
||
| 471 | 482 | 'selected' => $set == $context['member']['smiley_set']['id'] |
| 472 | 483 | ); |
| 473 | 484 | |
| 474 | - if ($context['smiley_sets'][$i]['selected']) |
|
| 475 | - $context['member']['smiley_set']['name'] = $set_names[$i]; |
|
| 485 | + if ($context['smiley_sets'][$i]['selected']) { |
|
| 486 | + $context['member']['smiley_set']['name'] = $set_names[$i]; |
|
| 487 | + } |
|
| 476 | 488 | } |
| 477 | 489 | return true; |
| 478 | 490 | }, |
@@ -481,8 +493,9 @@ discard block |
||
| 481 | 493 | global $modSettings; |
| 482 | 494 | |
| 483 | 495 | $smiley_sets = explode(',', $modSettings['smiley_sets_known']); |
| 484 | - if (!in_array($value, $smiley_sets) && $value != 'none') |
|
| 485 | - $value = ''; |
|
| 496 | + if (!in_array($value, $smiley_sets) && $value != 'none') { |
|
| 497 | + $value = ''; |
|
| 498 | + } |
|
| 486 | 499 | return true; |
| 487 | 500 | }, |
| 488 | 501 | ), |
@@ -497,8 +510,9 @@ discard block |
||
| 497 | 510 | loadLanguage('Settings'); |
| 498 | 511 | |
| 499 | 512 | $context['allow_no_censored'] = false; |
| 500 | - if ($user_info['is_admin'] || $context['user']['is_owner']) |
|
| 501 | - $context['allow_no_censored'] = !empty($modSettings['allow_no_censored']); |
|
| 513 | + if ($user_info['is_admin'] || $context['user']['is_owner']) { |
|
| 514 | + $context['allow_no_censored'] = !empty($modSettings['allow_no_censored']); |
|
| 515 | + } |
|
| 502 | 516 | |
| 503 | 517 | return true; |
| 504 | 518 | }, |
@@ -545,8 +559,9 @@ discard block |
||
| 545 | 559 | 'input_validate' => function($value) |
| 546 | 560 | { |
| 547 | 561 | $tz = smf_list_timezones(); |
| 548 | - if (!isset($tz[$value])) |
|
| 549 | - return 'bad_timezone'; |
|
| 562 | + if (!isset($tz[$value])) { |
|
| 563 | + return 'bad_timezone'; |
|
| 564 | + } |
|
| 550 | 565 | |
| 551 | 566 | return true; |
| 552 | 567 | }, |
@@ -561,8 +576,9 @@ discard block |
||
| 561 | 576 | 'enabled' => !empty($modSettings['titlesEnable']), |
| 562 | 577 | 'input_validate' => function(&$value) use ($smcFunc) |
| 563 | 578 | { |
| 564 | - if ($smcFunc['strlen']($value) > 50) |
|
| 565 | - return 'user_title_too_long'; |
|
| 579 | + if ($smcFunc['strlen']($value) > 50) { |
|
| 580 | + return 'user_title_too_long'; |
|
| 581 | + } |
|
| 566 | 582 | |
| 567 | 583 | return true; |
| 568 | 584 | }, |
@@ -584,10 +600,12 @@ discard block |
||
| 584 | 600 | // Fix the URL... |
| 585 | 601 | 'input_validate' => function(&$value) |
| 586 | 602 | { |
| 587 | - if (strlen(trim($value)) > 0 && strpos($value, '://') === false) |
|
| 588 | - $value = 'http://' . $value; |
|
| 589 | - if (strlen($value) < 8 || (substr($value, 0, 7) !== 'http://' && substr($value, 0, 8) !== 'https://')) |
|
| 590 | - $value = ''; |
|
| 603 | + if (strlen(trim($value)) > 0 && strpos($value, '://') === false) { |
|
| 604 | + $value = 'http://' . $value; |
|
| 605 | + } |
|
| 606 | + if (strlen($value) < 8 || (substr($value, 0, 7) !== 'http://' && substr($value, 0, 8) !== 'https://')) { |
|
| 607 | + $value = ''; |
|
| 608 | + } |
|
| 591 | 609 | return true; |
| 592 | 610 | }, |
| 593 | 611 | 'link_with' => 'website', |
@@ -601,16 +619,19 @@ discard block |
||
| 601 | 619 | foreach ($profile_fields as $key => $field) |
| 602 | 620 | { |
| 603 | 621 | // Do we have permission to do this? |
| 604 | - if (isset($field['permission']) && !allowedTo(($context['user']['is_owner'] ? array($field['permission'] . '_own', $field['permission'] . '_any') : $field['permission'] . '_any')) && !allowedTo($field['permission'])) |
|
| 605 | - unset($profile_fields[$key]); |
|
| 622 | + if (isset($field['permission']) && !allowedTo(($context['user']['is_owner'] ? array($field['permission'] . '_own', $field['permission'] . '_any') : $field['permission'] . '_any')) && !allowedTo($field['permission'])) { |
|
| 623 | + unset($profile_fields[$key]); |
|
| 624 | + } |
|
| 606 | 625 | |
| 607 | 626 | // Is it enabled? |
| 608 | - if (isset($field['enabled']) && !$field['enabled']) |
|
| 609 | - unset($profile_fields[$key]); |
|
| 627 | + if (isset($field['enabled']) && !$field['enabled']) { |
|
| 628 | + unset($profile_fields[$key]); |
|
| 629 | + } |
|
| 610 | 630 | |
| 611 | 631 | // Is it specifically disabled? |
| 612 | - if (in_array($key, $disabled_fields) || (isset($field['link_with']) && in_array($field['link_with'], $disabled_fields))) |
|
| 613 | - unset($profile_fields[$key]); |
|
| 632 | + if (in_array($key, $disabled_fields) || (isset($field['link_with']) && in_array($field['link_with'], $disabled_fields))) { |
|
| 633 | + unset($profile_fields[$key]); |
|
| 634 | + } |
|
| 614 | 635 | } |
| 615 | 636 | } |
| 616 | 637 | |
@@ -635,9 +656,10 @@ discard block |
||
| 635 | 656 | loadProfileFields(true); |
| 636 | 657 | |
| 637 | 658 | // First check for any linked sets. |
| 638 | - foreach ($profile_fields as $key => $field) |
|
| 639 | - if (isset($field['link_with']) && in_array($field['link_with'], $fields)) |
|
| 659 | + foreach ($profile_fields as $key => $field) { |
|
| 660 | + if (isset($field['link_with']) && in_array($field['link_with'], $fields)) |
|
| 640 | 661 | $fields[] = $key; |
| 662 | + } |
|
| 641 | 663 | |
| 642 | 664 | $i = 0; |
| 643 | 665 | $last_type = ''; |
@@ -649,38 +671,46 @@ discard block |
||
| 649 | 671 | $cur_field = &$profile_fields[$field]; |
| 650 | 672 | |
| 651 | 673 | // Does it have a preload and does that preload succeed? |
| 652 | - if (isset($cur_field['preload']) && !$cur_field['preload']()) |
|
| 653 | - continue; |
|
| 674 | + if (isset($cur_field['preload']) && !$cur_field['preload']()) { |
|
| 675 | + continue; |
|
| 676 | + } |
|
| 654 | 677 | |
| 655 | 678 | // If this is anything but complex we need to do more cleaning! |
| 656 | 679 | if ($cur_field['type'] != 'callback' && $cur_field['type'] != 'hidden') |
| 657 | 680 | { |
| 658 | - if (!isset($cur_field['label'])) |
|
| 659 | - $cur_field['label'] = isset($txt[$field]) ? $txt[$field] : $field; |
|
| 681 | + if (!isset($cur_field['label'])) { |
|
| 682 | + $cur_field['label'] = isset($txt[$field]) ? $txt[$field] : $field; |
|
| 683 | + } |
|
| 660 | 684 | |
| 661 | 685 | // Everything has a value! |
| 662 | - if (!isset($cur_field['value'])) |
|
| 663 | - $cur_field['value'] = isset($cur_profile[$field]) ? $cur_profile[$field] : ''; |
|
| 686 | + if (!isset($cur_field['value'])) { |
|
| 687 | + $cur_field['value'] = isset($cur_profile[$field]) ? $cur_profile[$field] : ''; |
|
| 688 | + } |
|
| 664 | 689 | |
| 665 | 690 | // Any input attributes? |
| 666 | 691 | $cur_field['input_attr'] = !empty($cur_field['input_attr']) ? implode(',', $cur_field['input_attr']) : ''; |
| 667 | 692 | } |
| 668 | 693 | |
| 669 | 694 | // Was there an error with this field on posting? |
| 670 | - if (isset($context['profile_errors'][$field])) |
|
| 671 | - $cur_field['is_error'] = true; |
|
| 695 | + if (isset($context['profile_errors'][$field])) { |
|
| 696 | + $cur_field['is_error'] = true; |
|
| 697 | + } |
|
| 672 | 698 | |
| 673 | 699 | // Any javascript stuff? |
| 674 | - if (!empty($cur_field['js_submit'])) |
|
| 675 | - $context['profile_onsubmit_javascript'] .= $cur_field['js_submit']; |
|
| 676 | - if (!empty($cur_field['js'])) |
|
| 677 | - $context['profile_javascript'] .= $cur_field['js']; |
|
| 700 | + if (!empty($cur_field['js_submit'])) { |
|
| 701 | + $context['profile_onsubmit_javascript'] .= $cur_field['js_submit']; |
|
| 702 | + } |
|
| 703 | + if (!empty($cur_field['js'])) { |
|
| 704 | + $context['profile_javascript'] .= $cur_field['js']; |
|
| 705 | + } |
|
| 678 | 706 | |
| 679 | 707 | // Any template stuff? |
| 680 | - if (!empty($cur_field['prehtml'])) |
|
| 681 | - $context['profile_prehtml'] .= $cur_field['prehtml']; |
|
| 682 | - if (!empty($cur_field['posthtml'])) |
|
| 683 | - $context['profile_posthtml'] .= $cur_field['posthtml']; |
|
| 708 | + if (!empty($cur_field['prehtml'])) { |
|
| 709 | + $context['profile_prehtml'] .= $cur_field['prehtml']; |
|
| 710 | + } |
|
| 711 | + if (!empty($cur_field['posthtml'])) { |
|
| 712 | + $context['profile_posthtml'] .= $cur_field['posthtml']; |
|
| 713 | + } |
|
| 684 | 714 | |
| 685 | 715 | // Finally put it into context? |
| 686 | 716 | if ($cur_field['type'] != 'hidden') |
@@ -713,12 +743,14 @@ discard block |
||
| 713 | 743 | }, false);' : ''), true); |
| 714 | 744 | |
| 715 | 745 | // Any onsubmit javascript? |
| 716 | - if (!empty($context['profile_onsubmit_javascript'])) |
|
| 717 | - addInlineJavaScript($context['profile_onsubmit_javascript'], true); |
|
| 746 | + if (!empty($context['profile_onsubmit_javascript'])) { |
|
| 747 | + addInlineJavaScript($context['profile_onsubmit_javascript'], true); |
|
| 748 | + } |
|
| 718 | 749 | |
| 719 | 750 | // Any totally custom stuff? |
| 720 | - if (!empty($context['profile_javascript'])) |
|
| 721 | - addInlineJavaScript($context['profile_javascript'], true); |
|
| 751 | + if (!empty($context['profile_javascript'])) { |
|
| 752 | + addInlineJavaScript($context['profile_javascript'], true); |
|
| 753 | + } |
|
| 722 | 754 | |
| 723 | 755 | // Free up some memory. |
| 724 | 756 | unset($profile_fields); |
@@ -739,8 +771,9 @@ discard block |
||
| 739 | 771 | |
| 740 | 772 | // This allows variables to call activities when they save - by default just to reload their settings |
| 741 | 773 | $context['profile_execute_on_save'] = array(); |
| 742 | - if ($context['user']['is_owner']) |
|
| 743 | - $context['profile_execute_on_save']['reload_user'] = 'profileReloadUser'; |
|
| 774 | + if ($context['user']['is_owner']) { |
|
| 775 | + $context['profile_execute_on_save']['reload_user'] = 'profileReloadUser'; |
|
| 776 | + } |
|
| 744 | 777 | |
| 745 | 778 | // Assume we log nothing. |
| 746 | 779 | $context['log_changes'] = array(); |
@@ -748,8 +781,9 @@ discard block |
||
| 748 | 781 | // Cycle through the profile fields working out what to do! |
| 749 | 782 | foreach ($profile_fields as $key => $field) |
| 750 | 783 | { |
| 751 | - if (!isset($_POST[$key]) || !empty($field['is_dummy']) || (isset($_POST['preview_signature']) && $key == 'signature')) |
|
| 752 | - continue; |
|
| 784 | + if (!isset($_POST[$key]) || !empty($field['is_dummy']) || (isset($_POST['preview_signature']) && $key == 'signature')) { |
|
| 785 | + continue; |
|
| 786 | + } |
|
| 753 | 787 | |
| 754 | 788 | // What gets updated? |
| 755 | 789 | $db_key = isset($field['save_key']) ? $field['save_key'] : $key; |
@@ -777,12 +811,13 @@ discard block |
||
| 777 | 811 | $field['cast_type'] = empty($field['cast_type']) ? $field['type'] : $field['cast_type']; |
| 778 | 812 | |
| 779 | 813 | // Finally, clean up certain types. |
| 780 | - if ($field['cast_type'] == 'int') |
|
| 781 | - $_POST[$key] = (int) $_POST[$key]; |
|
| 782 | - elseif ($field['cast_type'] == 'float') |
|
| 783 | - $_POST[$key] = (float) $_POST[$key]; |
|
| 784 | - elseif ($field['cast_type'] == 'check') |
|
| 785 | - $_POST[$key] = !empty($_POST[$key]) ? 1 : 0; |
|
| 814 | + if ($field['cast_type'] == 'int') { |
|
| 815 | + $_POST[$key] = (int) $_POST[$key]; |
|
| 816 | + } elseif ($field['cast_type'] == 'float') { |
|
| 817 | + $_POST[$key] = (float) $_POST[$key]; |
|
| 818 | + } elseif ($field['cast_type'] == 'check') { |
|
| 819 | + $_POST[$key] = !empty($_POST[$key]) ? 1 : 0; |
|
| 820 | + } |
|
| 786 | 821 | |
| 787 | 822 | // If we got here we're doing OK. |
| 788 | 823 | if ($field['type'] != 'hidden' && (!isset($old_profile[$key]) || $_POST[$key] != $old_profile[$key])) |
@@ -793,11 +828,12 @@ discard block |
||
| 793 | 828 | $cur_profile[$key] = $_POST[$key]; |
| 794 | 829 | |
| 795 | 830 | // Are we logging it? |
| 796 | - if (!empty($field['log_change']) && isset($old_profile[$key])) |
|
| 797 | - $context['log_changes'][$key] = array( |
|
| 831 | + if (!empty($field['log_change']) && isset($old_profile[$key])) { |
|
| 832 | + $context['log_changes'][$key] = array( |
|
| 798 | 833 | 'previous' => $old_profile[$key], |
| 799 | 834 | 'new' => $_POST[$key], |
| 800 | 835 | ); |
| 836 | + } |
|
| 801 | 837 | } |
| 802 | 838 | |
| 803 | 839 | // Logging group changes are a bit different... |
@@ -830,10 +866,11 @@ discard block |
||
| 830 | 866 | { |
| 831 | 867 | foreach ($groups as $id => $group) |
| 832 | 868 | { |
| 833 | - if (isset($context['member_groups'][$group])) |
|
| 834 | - $additional_groups[$type][$id] = $context['member_groups'][$group]['name']; |
|
| 835 | - else |
|
| 836 | - unset($additional_groups[$type][$id]); |
|
| 869 | + if (isset($context['member_groups'][$group])) { |
|
| 870 | + $additional_groups[$type][$id] = $context['member_groups'][$group]['name']; |
|
| 871 | + } else { |
|
| 872 | + unset($additional_groups[$type][$id]); |
|
| 873 | + } |
|
| 837 | 874 | } |
| 838 | 875 | $additional_groups[$type] = implode(', ', $additional_groups[$type]); |
| 839 | 876 | } |
@@ -844,10 +881,11 @@ discard block |
||
| 844 | 881 | } |
| 845 | 882 | |
| 846 | 883 | // @todo Temporary |
| 847 | - if ($context['user']['is_owner']) |
|
| 848 | - $changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own')); |
|
| 849 | - else |
|
| 850 | - $changeOther = allowedTo('profile_extra_any'); |
|
| 884 | + if ($context['user']['is_owner']) { |
|
| 885 | + $changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own')); |
|
| 886 | + } else { |
|
| 887 | + $changeOther = allowedTo('profile_extra_any'); |
|
| 888 | + } |
|
| 851 | 889 | if ($changeOther && empty($post_errors)) |
| 852 | 890 | { |
| 853 | 891 | makeThemeChanges($context['id_member'], isset($_POST['id_theme']) ? (int) $_POST['id_theme'] : $old_profile['id_theme']); |
@@ -855,8 +893,9 @@ discard block |
||
| 855 | 893 | { |
| 856 | 894 | $custom_fields_errors = makeCustomFieldChanges($context['id_member'], $_REQUEST['sa'], false, true); |
| 857 | 895 | |
| 858 | - if (!empty($custom_fields_errors)) |
|
| 859 | - $post_errors = array_merge($post_errors, $custom_fields_errors); |
|
| 896 | + if (!empty($custom_fields_errors)) { |
|
| 897 | + $post_errors = array_merge($post_errors, $custom_fields_errors); |
|
| 898 | + } |
|
| 860 | 899 | } |
| 861 | 900 | } |
| 862 | 901 | |
@@ -882,9 +921,9 @@ discard block |
||
| 882 | 921 | if ($context['user']['is_owner']) |
| 883 | 922 | { |
| 884 | 923 | $changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own', 'profile_website_any', 'profile_website_own', 'profile_signature_any', 'profile_signature_own')); |
| 924 | + } else { |
|
| 925 | + $changeOther = allowedTo(array('profile_extra_any', 'profile_website_any', 'profile_signature_any')); |
|
| 885 | 926 | } |
| 886 | - else |
|
| 887 | - $changeOther = allowedTo(array('profile_extra_any', 'profile_website_any', 'profile_signature_any')); |
|
| 888 | 927 | |
| 889 | 928 | // Arrays of all the changes - makes things easier. |
| 890 | 929 | $profile_bools = array(); |
@@ -895,22 +934,25 @@ discard block |
||
| 895 | 934 | 'ignore_boards', |
| 896 | 935 | ); |
| 897 | 936 | |
| 898 | - if (isset($_POST['sa']) && $_POST['sa'] == 'ignoreboards' && empty($_POST['ignore_brd'])) |
|
| 899 | - $_POST['ignore_brd'] = array(); |
|
| 937 | + if (isset($_POST['sa']) && $_POST['sa'] == 'ignoreboards' && empty($_POST['ignore_brd'])) { |
|
| 938 | + $_POST['ignore_brd'] = array(); |
|
| 939 | + } |
|
| 900 | 940 | |
| 901 | 941 | unset($_POST['ignore_boards']); // Whatever it is set to is a dirty filthy thing. Kinda like our minds. |
| 902 | 942 | if (isset($_POST['ignore_brd'])) |
| 903 | 943 | { |
| 904 | - if (!is_array($_POST['ignore_brd'])) |
|
| 905 | - $_POST['ignore_brd'] = array($_POST['ignore_brd']); |
|
| 944 | + if (!is_array($_POST['ignore_brd'])) { |
|
| 945 | + $_POST['ignore_brd'] = array($_POST['ignore_brd']); |
|
| 946 | + } |
|
| 906 | 947 | |
| 907 | 948 | foreach ($_POST['ignore_brd'] as $k => $d) |
| 908 | 949 | { |
| 909 | 950 | $d = (int) $d; |
| 910 | - if ($d != 0) |
|
| 911 | - $_POST['ignore_brd'][$k] = $d; |
|
| 912 | - else |
|
| 913 | - unset($_POST['ignore_brd'][$k]); |
|
| 951 | + if ($d != 0) { |
|
| 952 | + $_POST['ignore_brd'][$k] = $d; |
|
| 953 | + } else { |
|
| 954 | + unset($_POST['ignore_brd'][$k]); |
|
| 955 | + } |
|
| 914 | 956 | } |
| 915 | 957 | $_POST['ignore_boards'] = implode(',', $_POST['ignore_brd']); |
| 916 | 958 | unset($_POST['ignore_brd']); |
@@ -923,21 +965,26 @@ discard block |
||
| 923 | 965 | makeThemeChanges($memID, isset($_POST['id_theme']) ? (int) $_POST['id_theme'] : $old_profile['id_theme']); |
| 924 | 966 | //makeAvatarChanges($memID, $post_errors); |
| 925 | 967 | |
| 926 | - if (!empty($_REQUEST['sa'])) |
|
| 927 | - makeCustomFieldChanges($memID, $_REQUEST['sa'], false); |
|
| 968 | + if (!empty($_REQUEST['sa'])) { |
|
| 969 | + makeCustomFieldChanges($memID, $_REQUEST['sa'], false); |
|
| 970 | + } |
|
| 928 | 971 | |
| 929 | - foreach ($profile_bools as $var) |
|
| 930 | - if (isset($_POST[$var])) |
|
| 972 | + foreach ($profile_bools as $var) { |
|
| 973 | + if (isset($_POST[$var])) |
|
| 931 | 974 | $profile_vars[$var] = empty($_POST[$var]) ? '0' : '1'; |
| 932 | - foreach ($profile_ints as $var) |
|
| 933 | - if (isset($_POST[$var])) |
|
| 975 | + } |
|
| 976 | + foreach ($profile_ints as $var) { |
|
| 977 | + if (isset($_POST[$var])) |
|
| 934 | 978 | $profile_vars[$var] = $_POST[$var] != '' ? (int) $_POST[$var] : ''; |
| 935 | - foreach ($profile_floats as $var) |
|
| 936 | - if (isset($_POST[$var])) |
|
| 979 | + } |
|
| 980 | + foreach ($profile_floats as $var) { |
|
| 981 | + if (isset($_POST[$var])) |
|
| 937 | 982 | $profile_vars[$var] = (float) $_POST[$var]; |
| 938 | - foreach ($profile_strings as $var) |
|
| 939 | - if (isset($_POST[$var])) |
|
| 983 | + } |
|
| 984 | + foreach ($profile_strings as $var) { |
|
| 985 | + if (isset($_POST[$var])) |
|
| 940 | 986 | $profile_vars[$var] = $_POST[$var]; |
| 987 | + } |
|
| 941 | 988 | } |
| 942 | 989 | } |
| 943 | 990 | |
@@ -971,8 +1018,9 @@ discard block |
||
| 971 | 1018 | ); |
| 972 | 1019 | |
| 973 | 1020 | // Can't change reserved vars. |
| 974 | - if ((isset($_POST['options']) && count(array_intersect(array_keys($_POST['options']), $reservedVars)) != 0) || (isset($_POST['default_options']) && count(array_intersect(array_keys($_POST['default_options']), $reservedVars)) != 0)) |
|
| 975 | - fatal_lang_error('no_access', false); |
|
| 1021 | + if ((isset($_POST['options']) && count(array_intersect(array_keys($_POST['options']), $reservedVars)) != 0) || (isset($_POST['default_options']) && count(array_intersect(array_keys($_POST['default_options']), $reservedVars)) != 0)) { |
|
| 1022 | + fatal_lang_error('no_access', false); |
|
| 1023 | + } |
|
| 976 | 1024 | |
| 977 | 1025 | // Don't allow any overriding of custom fields with default or non-default options. |
| 978 | 1026 | $request = $smcFunc['db_query']('', ' |
@@ -984,8 +1032,9 @@ discard block |
||
| 984 | 1032 | ) |
| 985 | 1033 | ); |
| 986 | 1034 | $custom_fields = array(); |
| 987 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 988 | - $custom_fields[] = $row['col_name']; |
|
| 1035 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1036 | + $custom_fields[] = $row['col_name']; |
|
| 1037 | + } |
|
| 989 | 1038 | $smcFunc['db_free_result']($request); |
| 990 | 1039 | |
| 991 | 1040 | // These are the theme changes... |
@@ -994,33 +1043,39 @@ discard block |
||
| 994 | 1043 | { |
| 995 | 1044 | foreach ($_POST['options'] as $opt => $val) |
| 996 | 1045 | { |
| 997 | - if (in_array($opt, $custom_fields)) |
|
| 998 | - continue; |
|
| 1046 | + if (in_array($opt, $custom_fields)) { |
|
| 1047 | + continue; |
|
| 1048 | + } |
|
| 999 | 1049 | |
| 1000 | 1050 | // These need to be controlled. |
| 1001 | - if ($opt == 'topics_per_page' || $opt == 'messages_per_page') |
|
| 1002 | - $val = max(0, min($val, 50)); |
|
| 1051 | + if ($opt == 'topics_per_page' || $opt == 'messages_per_page') { |
|
| 1052 | + $val = max(0, min($val, 50)); |
|
| 1053 | + } |
|
| 1003 | 1054 | // We don't set this per theme anymore. |
| 1004 | - elseif ($opt == 'allow_no_censored') |
|
| 1005 | - continue; |
|
| 1055 | + elseif ($opt == 'allow_no_censored') { |
|
| 1056 | + continue; |
|
| 1057 | + } |
|
| 1006 | 1058 | |
| 1007 | 1059 | $themeSetArray[] = array($memID, $id_theme, $opt, is_array($val) ? implode(',', $val) : $val); |
| 1008 | 1060 | } |
| 1009 | 1061 | } |
| 1010 | 1062 | |
| 1011 | 1063 | $erase_options = array(); |
| 1012 | - if (isset($_POST['default_options']) && is_array($_POST['default_options'])) |
|
| 1013 | - foreach ($_POST['default_options'] as $opt => $val) |
|
| 1064 | + if (isset($_POST['default_options']) && is_array($_POST['default_options'])) { |
|
| 1065 | + foreach ($_POST['default_options'] as $opt => $val) |
|
| 1014 | 1066 | { |
| 1015 | 1067 | if (in_array($opt, $custom_fields)) |
| 1016 | 1068 | continue; |
| 1069 | + } |
|
| 1017 | 1070 | |
| 1018 | 1071 | // These need to be controlled. |
| 1019 | - if ($opt == 'topics_per_page' || $opt == 'messages_per_page') |
|
| 1020 | - $val = max(0, min($val, 50)); |
|
| 1072 | + if ($opt == 'topics_per_page' || $opt == 'messages_per_page') { |
|
| 1073 | + $val = max(0, min($val, 50)); |
|
| 1074 | + } |
|
| 1021 | 1075 | // Only let admins and owners change the censor. |
| 1022 | - elseif ($opt == 'allow_no_censored' && !$user_info['is_admin'] && !$context['user']['is_owner']) |
|
| 1023 | - continue; |
|
| 1076 | + elseif ($opt == 'allow_no_censored' && !$user_info['is_admin'] && !$context['user']['is_owner']) { |
|
| 1077 | + continue; |
|
| 1078 | + } |
|
| 1024 | 1079 | |
| 1025 | 1080 | $themeSetArray[] = array($memID, 1, $opt, is_array($val) ? implode(',', $val) : $val); |
| 1026 | 1081 | $erase_options[] = $opt; |
@@ -1056,8 +1111,9 @@ discard block |
||
| 1056 | 1111 | |
| 1057 | 1112 | // Admins can choose any theme, even if it's not enabled... |
| 1058 | 1113 | $themes = allowedTo('admin_forum') ? explode(',', $modSettings['knownThemes']) : explode(',', $modSettings['enableThemes']); |
| 1059 | - foreach ($themes as $t) |
|
| 1060 | - cache_put_data('theme_settings-' . $t . ':' . $memID, null, 60); |
|
| 1114 | + foreach ($themes as $t) { |
|
| 1115 | + cache_put_data('theme_settings-' . $t . ':' . $memID, null, 60); |
|
| 1116 | + } |
|
| 1061 | 1117 | } |
| 1062 | 1118 | } |
| 1063 | 1119 | |
@@ -1076,8 +1132,9 @@ discard block |
||
| 1076 | 1132 | if (isset($_POST['edit_notify_boards']) && !empty($_POST['notify_boards'])) |
| 1077 | 1133 | { |
| 1078 | 1134 | // Make sure only integers are deleted. |
| 1079 | - foreach ($_POST['notify_boards'] as $index => $id) |
|
| 1080 | - $_POST['notify_boards'][$index] = (int) $id; |
|
| 1135 | + foreach ($_POST['notify_boards'] as $index => $id) { |
|
| 1136 | + $_POST['notify_boards'][$index] = (int) $id; |
|
| 1137 | + } |
|
| 1081 | 1138 | |
| 1082 | 1139 | // id_board = 0 is reserved for topic notifications. |
| 1083 | 1140 | $_POST['notify_boards'] = array_diff($_POST['notify_boards'], array(0)); |
@@ -1096,8 +1153,9 @@ discard block |
||
| 1096 | 1153 | // We are editing topic notifications...... |
| 1097 | 1154 | elseif (isset($_POST['edit_notify_topics']) && !empty($_POST['notify_topics'])) |
| 1098 | 1155 | { |
| 1099 | - foreach ($_POST['notify_topics'] as $index => $id) |
|
| 1100 | - $_POST['notify_topics'][$index] = (int) $id; |
|
| 1156 | + foreach ($_POST['notify_topics'] as $index => $id) { |
|
| 1157 | + $_POST['notify_topics'][$index] = (int) $id; |
|
| 1158 | + } |
|
| 1101 | 1159 | |
| 1102 | 1160 | // Make sure there are no zeros left. |
| 1103 | 1161 | $_POST['notify_topics'] = array_diff($_POST['notify_topics'], array(0)); |
@@ -1111,16 +1169,18 @@ discard block |
||
| 1111 | 1169 | 'selected_member' => $memID, |
| 1112 | 1170 | ) |
| 1113 | 1171 | ); |
| 1114 | - foreach ($_POST['notify_topics'] as $topic) |
|
| 1115 | - setNotifyPrefs($memID, array('topic_notify_' . $topic => 0)); |
|
| 1172 | + foreach ($_POST['notify_topics'] as $topic) { |
|
| 1173 | + setNotifyPrefs($memID, array('topic_notify_' . $topic => 0)); |
|
| 1174 | + } |
|
| 1116 | 1175 | } |
| 1117 | 1176 | |
| 1118 | 1177 | // We are removing topic preferences |
| 1119 | 1178 | elseif (isset($_POST['remove_notify_topics']) && !empty($_POST['notify_topics'])) |
| 1120 | 1179 | { |
| 1121 | 1180 | $prefs = array(); |
| 1122 | - foreach ($_POST['notify_topics'] as $topic) |
|
| 1123 | - $prefs[] = 'topic_notify_' . $topic; |
|
| 1181 | + foreach ($_POST['notify_topics'] as $topic) { |
|
| 1182 | + $prefs[] = 'topic_notify_' . $topic; |
|
| 1183 | + } |
|
| 1124 | 1184 | deleteNotifyPrefs($memID, $prefs); |
| 1125 | 1185 | } |
| 1126 | 1186 | |
@@ -1128,8 +1188,9 @@ discard block |
||
| 1128 | 1188 | elseif (isset($_POST['remove_notify_board']) && !empty($_POST['notify_boards'])) |
| 1129 | 1189 | { |
| 1130 | 1190 | $prefs = array(); |
| 1131 | - foreach ($_POST['notify_boards'] as $board) |
|
| 1132 | - $prefs[] = 'board_notify_' . $board; |
|
| 1191 | + foreach ($_POST['notify_boards'] as $board) { |
|
| 1192 | + $prefs[] = 'board_notify_' . $board; |
|
| 1193 | + } |
|
| 1133 | 1194 | deleteNotifyPrefs($memID, $prefs); |
| 1134 | 1195 | } |
| 1135 | 1196 | } |
@@ -1150,8 +1211,9 @@ discard block |
||
| 1150 | 1211 | |
| 1151 | 1212 | $errors = array(); |
| 1152 | 1213 | |
| 1153 | - if ($sanitize && isset($_POST['customfield'])) |
|
| 1154 | - $_POST['customfield'] = htmlspecialchars__recursive($_POST['customfield']); |
|
| 1214 | + if ($sanitize && isset($_POST['customfield'])) { |
|
| 1215 | + $_POST['customfield'] = htmlspecialchars__recursive($_POST['customfield']); |
|
| 1216 | + } |
|
| 1155 | 1217 | |
| 1156 | 1218 | $where = $area == 'register' ? 'show_reg != 0' : 'show_profile = {string:area}'; |
| 1157 | 1219 | |
@@ -1176,26 +1238,29 @@ discard block |
||
| 1176 | 1238 | - The data is not invisible to users but editable by the owner (or if it is the user is not the owner) |
| 1177 | 1239 | - The area isn't registration, and if it is that the field is not supposed to be shown there. |
| 1178 | 1240 | */ |
| 1179 | - if ($row['private'] != 0 && !allowedTo('admin_forum') && ($memID != $user_info['id'] || $row['private'] != 2) && ($area != 'register' || $row['show_reg'] == 0)) |
|
| 1180 | - continue; |
|
| 1241 | + if ($row['private'] != 0 && !allowedTo('admin_forum') && ($memID != $user_info['id'] || $row['private'] != 2) && ($area != 'register' || $row['show_reg'] == 0)) { |
|
| 1242 | + continue; |
|
| 1243 | + } |
|
| 1181 | 1244 | |
| 1182 | 1245 | // Validate the user data. |
| 1183 | - if ($row['field_type'] == 'check') |
|
| 1184 | - $value = isset($_POST['customfield'][$row['col_name']]) ? 1 : 0; |
|
| 1185 | - elseif ($row['field_type'] == 'select' || $row['field_type'] == 'radio') |
|
| 1246 | + if ($row['field_type'] == 'check') { |
|
| 1247 | + $value = isset($_POST['customfield'][$row['col_name']]) ? 1 : 0; |
|
| 1248 | + } elseif ($row['field_type'] == 'select' || $row['field_type'] == 'radio') |
|
| 1186 | 1249 | { |
| 1187 | 1250 | $value = $row['default_value']; |
| 1188 | - foreach (explode(',', $row['field_options']) as $k => $v) |
|
| 1189 | - if (isset($_POST['customfield'][$row['col_name']]) && $_POST['customfield'][$row['col_name']] == $k) |
|
| 1251 | + foreach (explode(',', $row['field_options']) as $k => $v) { |
|
| 1252 | + if (isset($_POST['customfield'][$row['col_name']]) && $_POST['customfield'][$row['col_name']] == $k) |
|
| 1190 | 1253 | $value = $v; |
| 1254 | + } |
|
| 1191 | 1255 | } |
| 1192 | 1256 | // Otherwise some form of text! |
| 1193 | 1257 | else |
| 1194 | 1258 | { |
| 1195 | 1259 | $value = isset($_POST['customfield'][$row['col_name']]) ? $_POST['customfield'][$row['col_name']] : ''; |
| 1196 | 1260 | |
| 1197 | - if ($row['field_length']) |
|
| 1198 | - $value = $smcFunc['substr']($value, 0, $row['field_length']); |
|
| 1261 | + if ($row['field_length']) { |
|
| 1262 | + $value = $smcFunc['substr']($value, 0, $row['field_length']); |
|
| 1263 | + } |
|
| 1199 | 1264 | |
| 1200 | 1265 | // Any masks? |
| 1201 | 1266 | if ($row['field_type'] == 'text' && !empty($row['mask']) && $row['mask'] != 'none') |
@@ -1204,36 +1269,34 @@ discard block |
||
| 1204 | 1269 | $valueReference = un_htmlspecialchars($value); |
| 1205 | 1270 | |
| 1206 | 1271 | // Try and avoid some checks. '0' could be a valid non-empty value. |
| 1207 | - if (empty($value) && !is_numeric($value)) |
|
| 1208 | - $value = ''; |
|
| 1272 | + if (empty($value) && !is_numeric($value)) { |
|
| 1273 | + $value = ''; |
|
| 1274 | + } |
|
| 1209 | 1275 | |
| 1210 | 1276 | if ($row['mask'] == 'nohtml' && ($valueReference != strip_tags($valueReference) || $value != filter_var($value, FILTER_SANITIZE_STRING) || preg_match('/<(.+?)[\s]*\/?[\s]*>/si', $valueReference))) |
| 1211 | 1277 | { |
| 1212 | - if ($returnErrors) |
|
| 1213 | - $errors[] = 'custom_field_nohtml_fail'; |
|
| 1214 | - |
|
| 1215 | - else |
|
| 1216 | - $value = ''; |
|
| 1217 | - } |
|
| 1218 | - elseif ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255)) |
|
| 1278 | + if ($returnErrors) { |
|
| 1279 | + $errors[] = 'custom_field_nohtml_fail'; |
|
| 1280 | + } else { |
|
| 1281 | + $value = ''; |
|
| 1282 | + } |
|
| 1283 | + } elseif ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255)) |
|
| 1219 | 1284 | { |
| 1220 | - if ($returnErrors) |
|
| 1221 | - $errors[] = 'custom_field_mail_fail'; |
|
| 1222 | - |
|
| 1223 | - else |
|
| 1224 | - $value = ''; |
|
| 1225 | - } |
|
| 1226 | - elseif ($row['mask'] == 'number') |
|
| 1285 | + if ($returnErrors) { |
|
| 1286 | + $errors[] = 'custom_field_mail_fail'; |
|
| 1287 | + } else { |
|
| 1288 | + $value = ''; |
|
| 1289 | + } |
|
| 1290 | + } elseif ($row['mask'] == 'number') |
|
| 1227 | 1291 | { |
| 1228 | 1292 | $value = (int) $value; |
| 1229 | - } |
|
| 1230 | - elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0) |
|
| 1293 | + } elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0) |
|
| 1231 | 1294 | { |
| 1232 | - if ($returnErrors) |
|
| 1233 | - $errors[] = 'custom_field_regex_fail'; |
|
| 1234 | - |
|
| 1235 | - else |
|
| 1236 | - $value = ''; |
|
| 1295 | + if ($returnErrors) { |
|
| 1296 | + $errors[] = 'custom_field_regex_fail'; |
|
| 1297 | + } else { |
|
| 1298 | + $value = ''; |
|
| 1299 | + } |
|
| 1237 | 1300 | } |
| 1238 | 1301 | |
| 1239 | 1302 | unset($valueReference); |
@@ -1261,8 +1324,9 @@ discard block |
||
| 1261 | 1324 | |
| 1262 | 1325 | $hook_errors = call_integration_hook('integrate_save_custom_profile_fields', array(&$changes, &$log_changes, &$errors, $returnErrors, $memID, $area, $sanitize)); |
| 1263 | 1326 | |
| 1264 | - if (!empty($hook_errors) && is_array($hook_errors)) |
|
| 1265 | - $errors = array_merge($errors, $hook_errors); |
|
| 1327 | + if (!empty($hook_errors) && is_array($hook_errors)) { |
|
| 1328 | + $errors = array_merge($errors, $hook_errors); |
|
| 1329 | + } |
|
| 1266 | 1330 | |
| 1267 | 1331 | // Make those changes! |
| 1268 | 1332 | if (!empty($changes) && empty($context['password_auth_failed']) && empty($errors)) |
@@ -1280,9 +1344,10 @@ discard block |
||
| 1280 | 1344 | } |
| 1281 | 1345 | } |
| 1282 | 1346 | |
| 1283 | - if ($returnErrors) |
|
| 1284 | - return $errors; |
|
| 1285 | -} |
|
| 1347 | + if ($returnErrors) { |
|
| 1348 | + return $errors; |
|
| 1349 | + } |
|
| 1350 | + } |
|
| 1286 | 1351 | |
| 1287 | 1352 | /** |
| 1288 | 1353 | * Show all the users buddies, as well as a add/delete interface. |
@@ -1294,8 +1359,9 @@ discard block |
||
| 1294 | 1359 | global $context, $txt, $modSettings; |
| 1295 | 1360 | |
| 1296 | 1361 | // Do a quick check to ensure people aren't getting here illegally! |
| 1297 | - if (!$context['user']['is_owner'] || empty($modSettings['enable_buddylist'])) |
|
| 1298 | - fatal_lang_error('no_access', false); |
|
| 1362 | + if (!$context['user']['is_owner'] || empty($modSettings['enable_buddylist'])) { |
|
| 1363 | + fatal_lang_error('no_access', false); |
|
| 1364 | + } |
|
| 1299 | 1365 | |
| 1300 | 1366 | // Can we email the user direct? |
| 1301 | 1367 | $context['can_moderate_forum'] = allowedTo('moderate_forum'); |
@@ -1325,9 +1391,10 @@ discard block |
||
| 1325 | 1391 | $context['sub_template'] = $subActions[$context['list_area']][0]; |
| 1326 | 1392 | $call = call_helper($subActions[$context['list_area']][0], true); |
| 1327 | 1393 | |
| 1328 | - if (!empty($call)) |
|
| 1329 | - call_user_func($call, $memID); |
|
| 1330 | -} |
|
| 1394 | + if (!empty($call)) { |
|
| 1395 | + call_user_func($call, $memID); |
|
| 1396 | + } |
|
| 1397 | + } |
|
| 1331 | 1398 | |
| 1332 | 1399 | /** |
| 1333 | 1400 | * Show all the users buddies, as well as a add/delete interface. |
@@ -1341,9 +1408,10 @@ discard block |
||
| 1341 | 1408 | |
| 1342 | 1409 | // For making changes! |
| 1343 | 1410 | $buddiesArray = explode(',', $user_profile[$memID]['buddy_list']); |
| 1344 | - foreach ($buddiesArray as $k => $dummy) |
|
| 1345 | - if ($dummy == '') |
|
| 1411 | + foreach ($buddiesArray as $k => $dummy) { |
|
| 1412 | + if ($dummy == '') |
|
| 1346 | 1413 | unset($buddiesArray[$k]); |
| 1414 | + } |
|
| 1347 | 1415 | |
| 1348 | 1416 | // Removing a buddy? |
| 1349 | 1417 | if (isset($_GET['remove'])) |
@@ -1355,10 +1423,11 @@ discard block |
||
| 1355 | 1423 | $_SESSION['prf-save'] = $txt['could_not_remove_person']; |
| 1356 | 1424 | |
| 1357 | 1425 | // Heh, I'm lazy, do it the easy way... |
| 1358 | - foreach ($buddiesArray as $key => $buddy) |
|
| 1359 | - if ($buddy == (int) $_GET['remove']) |
|
| 1426 | + foreach ($buddiesArray as $key => $buddy) { |
|
| 1427 | + if ($buddy == (int) $_GET['remove']) |
|
| 1360 | 1428 | { |
| 1361 | 1429 | unset($buddiesArray[$key]); |
| 1430 | + } |
|
| 1362 | 1431 | $_SESSION['prf-save'] = true; |
| 1363 | 1432 | } |
| 1364 | 1433 | |
@@ -1368,8 +1437,7 @@ discard block |
||
| 1368 | 1437 | |
| 1369 | 1438 | // Redirect off the page because we don't like all this ugly query stuff to stick in the history. |
| 1370 | 1439 | redirectexit('action=profile;area=lists;sa=buddies;u=' . $memID); |
| 1371 | - } |
|
| 1372 | - elseif (isset($_POST['new_buddy'])) |
|
| 1440 | + } elseif (isset($_POST['new_buddy'])) |
|
| 1373 | 1441 | { |
| 1374 | 1442 | checkSession(); |
| 1375 | 1443 | |
@@ -1382,8 +1450,9 @@ discard block |
||
| 1382 | 1450 | { |
| 1383 | 1451 | $new_buddies[$k] = strtr(trim($new_buddies[$k]), array('\'' => ''')); |
| 1384 | 1452 | |
| 1385 | - if (strlen($new_buddies[$k]) == 0 || in_array($new_buddies[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name']))) |
|
| 1386 | - unset($new_buddies[$k]); |
|
| 1453 | + if (strlen($new_buddies[$k]) == 0 || in_array($new_buddies[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name']))) { |
|
| 1454 | + unset($new_buddies[$k]); |
|
| 1455 | + } |
|
| 1387 | 1456 | } |
| 1388 | 1457 | |
| 1389 | 1458 | call_integration_hook('integrate_add_buddies', array($memID, &$new_buddies)); |
@@ -1403,16 +1472,18 @@ discard block |
||
| 1403 | 1472 | ) |
| 1404 | 1473 | ); |
| 1405 | 1474 | |
| 1406 | - if ($smcFunc['db_num_rows']($request) != 0) |
|
| 1407 | - $_SESSION['prf-save'] = true; |
|
| 1475 | + if ($smcFunc['db_num_rows']($request) != 0) { |
|
| 1476 | + $_SESSION['prf-save'] = true; |
|
| 1477 | + } |
|
| 1408 | 1478 | |
| 1409 | 1479 | // Add the new member to the buddies array. |
| 1410 | 1480 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1411 | 1481 | { |
| 1412 | - if (in_array($row['id_member'], $buddiesArray)) |
|
| 1413 | - continue; |
|
| 1414 | - else |
|
| 1415 | - $buddiesArray[] = (int) $row['id_member']; |
|
| 1482 | + if (in_array($row['id_member'], $buddiesArray)) { |
|
| 1483 | + continue; |
|
| 1484 | + } else { |
|
| 1485 | + $buddiesArray[] = (int) $row['id_member']; |
|
| 1486 | + } |
|
| 1416 | 1487 | } |
| 1417 | 1488 | $smcFunc['db_free_result']($request); |
| 1418 | 1489 | |
@@ -1442,18 +1513,20 @@ discard block |
||
| 1442 | 1513 | |
| 1443 | 1514 | $context['custom_pf'] = array(); |
| 1444 | 1515 | $disabled_fields = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array(); |
| 1445 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1446 | - if (!isset($disabled_fields[$row['col_name']])) |
|
| 1516 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1517 | + if (!isset($disabled_fields[$row['col_name']])) |
|
| 1447 | 1518 | $context['custom_pf'][$row['col_name']] = array( |
| 1448 | 1519 | 'label' => $row['field_name'], |
| 1449 | 1520 | 'type' => $row['field_type'], |
| 1450 | 1521 | 'bbc' => !empty($row['bbc']), |
| 1451 | 1522 | 'enclose' => $row['enclose'], |
| 1452 | 1523 | ); |
| 1524 | + } |
|
| 1453 | 1525 | |
| 1454 | 1526 | // Gotta disable the gender option. |
| 1455 | - if (isset($context['custom_pf']['cust_gender']) && $context['custom_pf']['cust_gender'] == 'None') |
|
| 1456 | - unset($context['custom_pf']['cust_gender']); |
|
| 1527 | + if (isset($context['custom_pf']['cust_gender']) && $context['custom_pf']['cust_gender'] == 'None') { |
|
| 1528 | + unset($context['custom_pf']['cust_gender']); |
|
| 1529 | + } |
|
| 1457 | 1530 | |
| 1458 | 1531 | $smcFunc['db_free_result']($request); |
| 1459 | 1532 | |
@@ -1470,8 +1543,9 @@ discard block |
||
| 1470 | 1543 | 'buddy_list_count' => substr_count($user_profile[$memID]['buddy_list'], ',') + 1, |
| 1471 | 1544 | ) |
| 1472 | 1545 | ); |
| 1473 | - while ($row = $smcFunc['db_fetch_assoc']($result)) |
|
| 1474 | - $buddies[] = $row['id_member']; |
|
| 1546 | + while ($row = $smcFunc['db_fetch_assoc']($result)) { |
|
| 1547 | + $buddies[] = $row['id_member']; |
|
| 1548 | + } |
|
| 1475 | 1549 | $smcFunc['db_free_result']($result); |
| 1476 | 1550 | } |
| 1477 | 1551 | |
@@ -1499,30 +1573,32 @@ discard block |
||
| 1499 | 1573 | continue; |
| 1500 | 1574 | } |
| 1501 | 1575 | |
| 1502 | - if ($column['bbc'] && !empty($context['buddies'][$buddy]['options'][$key])) |
|
| 1503 | - $context['buddies'][$buddy]['options'][$key] = strip_tags(parse_bbc($context['buddies'][$buddy]['options'][$key])); |
|
| 1504 | - |
|
| 1505 | - elseif ($column['type'] == 'check') |
|
| 1506 | - $context['buddies'][$buddy]['options'][$key] = $context['buddies'][$buddy]['options'][$key] == 0 ? $txt['no'] : $txt['yes']; |
|
| 1576 | + if ($column['bbc'] && !empty($context['buddies'][$buddy]['options'][$key])) { |
|
| 1577 | + $context['buddies'][$buddy]['options'][$key] = strip_tags(parse_bbc($context['buddies'][$buddy]['options'][$key])); |
|
| 1578 | + } elseif ($column['type'] == 'check') { |
|
| 1579 | + $context['buddies'][$buddy]['options'][$key] = $context['buddies'][$buddy]['options'][$key] == 0 ? $txt['no'] : $txt['yes']; |
|
| 1580 | + } |
|
| 1507 | 1581 | |
| 1508 | 1582 | // Enclosing the user input within some other text? |
| 1509 | - if (!empty($column['enclose']) && !empty($context['buddies'][$buddy]['options'][$key])) |
|
| 1510 | - $context['buddies'][$buddy]['options'][$key] = strtr($column['enclose'], array( |
|
| 1583 | + if (!empty($column['enclose']) && !empty($context['buddies'][$buddy]['options'][$key])) { |
|
| 1584 | + $context['buddies'][$buddy]['options'][$key] = strtr($column['enclose'], array( |
|
| 1511 | 1585 | '{SCRIPTURL}' => $scripturl, |
| 1512 | 1586 | '{IMAGES_URL}' => $settings['images_url'], |
| 1513 | 1587 | '{DEFAULT_IMAGES_URL}' => $settings['default_images_url'], |
| 1514 | 1588 | '{INPUT}' => $context['buddies'][$buddy]['options'][$key], |
| 1515 | 1589 | )); |
| 1590 | + } |
|
| 1516 | 1591 | } |
| 1517 | 1592 | } |
| 1518 | 1593 | } |
| 1519 | 1594 | |
| 1520 | 1595 | if (isset($_SESSION['prf-save'])) |
| 1521 | 1596 | { |
| 1522 | - if ($_SESSION['prf-save'] === true) |
|
| 1523 | - $context['saved_successful'] = true; |
|
| 1524 | - else |
|
| 1525 | - $context['saved_failed'] = $_SESSION['prf-save']; |
|
| 1597 | + if ($_SESSION['prf-save'] === true) { |
|
| 1598 | + $context['saved_successful'] = true; |
|
| 1599 | + } else { |
|
| 1600 | + $context['saved_failed'] = $_SESSION['prf-save']; |
|
| 1601 | + } |
|
| 1526 | 1602 | |
| 1527 | 1603 | unset($_SESSION['prf-save']); |
| 1528 | 1604 | } |
@@ -1542,9 +1618,10 @@ discard block |
||
| 1542 | 1618 | |
| 1543 | 1619 | // For making changes! |
| 1544 | 1620 | $ignoreArray = explode(',', $user_profile[$memID]['pm_ignore_list']); |
| 1545 | - foreach ($ignoreArray as $k => $dummy) |
|
| 1546 | - if ($dummy == '') |
|
| 1621 | + foreach ($ignoreArray as $k => $dummy) { |
|
| 1622 | + if ($dummy == '') |
|
| 1547 | 1623 | unset($ignoreArray[$k]); |
| 1624 | + } |
|
| 1548 | 1625 | |
| 1549 | 1626 | // Removing a member from the ignore list? |
| 1550 | 1627 | if (isset($_GET['remove'])) |
@@ -1554,10 +1631,11 @@ discard block |
||
| 1554 | 1631 | $_SESSION['prf-save'] = $txt['could_not_remove_person']; |
| 1555 | 1632 | |
| 1556 | 1633 | // Heh, I'm lazy, do it the easy way... |
| 1557 | - foreach ($ignoreArray as $key => $id_remove) |
|
| 1558 | - if ($id_remove == (int) $_GET['remove']) |
|
| 1634 | + foreach ($ignoreArray as $key => $id_remove) { |
|
| 1635 | + if ($id_remove == (int) $_GET['remove']) |
|
| 1559 | 1636 | { |
| 1560 | 1637 | unset($ignoreArray[$key]); |
| 1638 | + } |
|
| 1561 | 1639 | $_SESSION['prf-save'] = true; |
| 1562 | 1640 | } |
| 1563 | 1641 | |
@@ -1567,8 +1645,7 @@ discard block |
||
| 1567 | 1645 | |
| 1568 | 1646 | // Redirect off the page because we don't like all this ugly query stuff to stick in the history. |
| 1569 | 1647 | redirectexit('action=profile;area=lists;sa=ignore;u=' . $memID); |
| 1570 | - } |
|
| 1571 | - elseif (isset($_POST['new_ignore'])) |
|
| 1648 | + } elseif (isset($_POST['new_ignore'])) |
|
| 1572 | 1649 | { |
| 1573 | 1650 | checkSession(); |
| 1574 | 1651 | // Prepare the string for extraction... |
@@ -1580,8 +1657,9 @@ discard block |
||
| 1580 | 1657 | { |
| 1581 | 1658 | $new_entries[$k] = strtr(trim($new_entries[$k]), array('\'' => ''')); |
| 1582 | 1659 | |
| 1583 | - if (strlen($new_entries[$k]) == 0 || in_array($new_entries[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name']))) |
|
| 1584 | - unset($new_entries[$k]); |
|
| 1660 | + if (strlen($new_entries[$k]) == 0 || in_array($new_entries[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name']))) { |
|
| 1661 | + unset($new_entries[$k]); |
|
| 1662 | + } |
|
| 1585 | 1663 | } |
| 1586 | 1664 | |
| 1587 | 1665 | $_SESSION['prf-save'] = $txt['could_not_add_person']; |
@@ -1599,16 +1677,18 @@ discard block |
||
| 1599 | 1677 | ) |
| 1600 | 1678 | ); |
| 1601 | 1679 | |
| 1602 | - if ($smcFunc['db_num_rows']($request) != 0) |
|
| 1603 | - $_SESSION['prf-save'] = true; |
|
| 1680 | + if ($smcFunc['db_num_rows']($request) != 0) { |
|
| 1681 | + $_SESSION['prf-save'] = true; |
|
| 1682 | + } |
|
| 1604 | 1683 | |
| 1605 | 1684 | // Add the new member to the buddies array. |
| 1606 | 1685 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1607 | 1686 | { |
| 1608 | - if (in_array($row['id_member'], $ignoreArray)) |
|
| 1609 | - continue; |
|
| 1610 | - else |
|
| 1611 | - $ignoreArray[] = (int) $row['id_member']; |
|
| 1687 | + if (in_array($row['id_member'], $ignoreArray)) { |
|
| 1688 | + continue; |
|
| 1689 | + } else { |
|
| 1690 | + $ignoreArray[] = (int) $row['id_member']; |
|
| 1691 | + } |
|
| 1612 | 1692 | } |
| 1613 | 1693 | $smcFunc['db_free_result']($request); |
| 1614 | 1694 | |
@@ -1637,8 +1717,9 @@ discard block |
||
| 1637 | 1717 | 'ignore_list_count' => substr_count($user_profile[$memID]['pm_ignore_list'], ',') + 1, |
| 1638 | 1718 | ) |
| 1639 | 1719 | ); |
| 1640 | - while ($row = $smcFunc['db_fetch_assoc']($result)) |
|
| 1641 | - $ignored[] = $row['id_member']; |
|
| 1720 | + while ($row = $smcFunc['db_fetch_assoc']($result)) { |
|
| 1721 | + $ignored[] = $row['id_member']; |
|
| 1722 | + } |
|
| 1642 | 1723 | $smcFunc['db_free_result']($result); |
| 1643 | 1724 | } |
| 1644 | 1725 | |
@@ -1657,10 +1738,11 @@ discard block |
||
| 1657 | 1738 | |
| 1658 | 1739 | if (isset($_SESSION['prf-save'])) |
| 1659 | 1740 | { |
| 1660 | - if ($_SESSION['prf-save'] === true) |
|
| 1661 | - $context['saved_successful'] = true; |
|
| 1662 | - else |
|
| 1663 | - $context['saved_failed'] = $_SESSION['prf-save']; |
|
| 1741 | + if ($_SESSION['prf-save'] === true) { |
|
| 1742 | + $context['saved_successful'] = true; |
|
| 1743 | + } else { |
|
| 1744 | + $context['saved_failed'] = $_SESSION['prf-save']; |
|
| 1745 | + } |
|
| 1664 | 1746 | |
| 1665 | 1747 | unset($_SESSION['prf-save']); |
| 1666 | 1748 | } |
@@ -1676,8 +1758,9 @@ discard block |
||
| 1676 | 1758 | global $context, $txt; |
| 1677 | 1759 | |
| 1678 | 1760 | loadThemeOptions($memID); |
| 1679 | - if (allowedTo(array('profile_identity_own', 'profile_identity_any', 'profile_password_own', 'profile_password_any'))) |
|
| 1680 | - loadCustomFields($memID, 'account'); |
|
| 1761 | + if (allowedTo(array('profile_identity_own', 'profile_identity_any', 'profile_password_own', 'profile_password_any'))) { |
|
| 1762 | + loadCustomFields($memID, 'account'); |
|
| 1763 | + } |
|
| 1681 | 1764 | |
| 1682 | 1765 | $context['sub_template'] = 'edit_options'; |
| 1683 | 1766 | $context['page_desc'] = $txt['account_info']; |
@@ -1704,8 +1787,9 @@ discard block |
||
| 1704 | 1787 | global $context, $txt; |
| 1705 | 1788 | |
| 1706 | 1789 | loadThemeOptions($memID); |
| 1707 | - if (allowedTo(array('profile_forum_own', 'profile_forum_any'))) |
|
| 1708 | - loadCustomFields($memID, 'forumprofile'); |
|
| 1790 | + if (allowedTo(array('profile_forum_own', 'profile_forum_any'))) { |
|
| 1791 | + loadCustomFields($memID, 'forumprofile'); |
|
| 1792 | + } |
|
| 1709 | 1793 | |
| 1710 | 1794 | $context['sub_template'] = 'edit_options'; |
| 1711 | 1795 | $context['page_desc'] = $txt['forumProfile_info']; |
@@ -1738,18 +1822,21 @@ discard block |
||
| 1738 | 1822 | $dirs = array(); |
| 1739 | 1823 | $files = array(); |
| 1740 | 1824 | |
| 1741 | - if (!$dir) |
|
| 1742 | - return array(); |
|
| 1825 | + if (!$dir) { |
|
| 1826 | + return array(); |
|
| 1827 | + } |
|
| 1743 | 1828 | |
| 1744 | 1829 | while ($line = $dir->read()) |
| 1745 | 1830 | { |
| 1746 | - if (in_array($line, array('.', '..', 'blank.png', 'index.php'))) |
|
| 1747 | - continue; |
|
| 1831 | + if (in_array($line, array('.', '..', 'blank.png', 'index.php'))) { |
|
| 1832 | + continue; |
|
| 1833 | + } |
|
| 1748 | 1834 | |
| 1749 | - if (is_dir($modSettings['avatar_directory'] . '/' . $directory . (!empty($directory) ? '/' : '') . $line)) |
|
| 1750 | - $dirs[] = $line; |
|
| 1751 | - else |
|
| 1752 | - $files[] = $line; |
|
| 1835 | + if (is_dir($modSettings['avatar_directory'] . '/' . $directory . (!empty($directory) ? '/' : '') . $line)) { |
|
| 1836 | + $dirs[] = $line; |
|
| 1837 | + } else { |
|
| 1838 | + $files[] = $line; |
|
| 1839 | + } |
|
| 1753 | 1840 | } |
| 1754 | 1841 | $dir->close(); |
| 1755 | 1842 | |
@@ -1770,14 +1857,15 @@ discard block |
||
| 1770 | 1857 | foreach ($dirs as $line) |
| 1771 | 1858 | { |
| 1772 | 1859 | $tmp = getAvatars($directory . (!empty($directory) ? '/' : '') . $line, $level + 1); |
| 1773 | - if (!empty($tmp)) |
|
| 1774 | - $result[] = array( |
|
| 1860 | + if (!empty($tmp)) { |
|
| 1861 | + $result[] = array( |
|
| 1775 | 1862 | 'filename' => $smcFunc['htmlspecialchars']($line), |
| 1776 | 1863 | 'checked' => strpos($context['member']['avatar']['server_pic'], $line . '/') !== false, |
| 1777 | 1864 | 'name' => '[' . $smcFunc['htmlspecialchars'](str_replace('_', ' ', $line)) . ']', |
| 1778 | 1865 | 'is_dir' => true, |
| 1779 | 1866 | 'files' => $tmp |
| 1780 | 1867 | ); |
| 1868 | + } |
|
| 1781 | 1869 | unset($tmp); |
| 1782 | 1870 | } |
| 1783 | 1871 | |
@@ -1787,8 +1875,9 @@ discard block |
||
| 1787 | 1875 | $extension = substr(strrchr($line, '.'), 1); |
| 1788 | 1876 | |
| 1789 | 1877 | // Make sure it is an image. |
| 1790 | - if (strcasecmp($extension, 'gif') != 0 && strcasecmp($extension, 'jpg') != 0 && strcasecmp($extension, 'jpeg') != 0 && strcasecmp($extension, 'png') != 0 && strcasecmp($extension, 'bmp') != 0) |
|
| 1791 | - continue; |
|
| 1878 | + if (strcasecmp($extension, 'gif') != 0 && strcasecmp($extension, 'jpg') != 0 && strcasecmp($extension, 'jpeg') != 0 && strcasecmp($extension, 'png') != 0 && strcasecmp($extension, 'bmp') != 0) { |
|
| 1879 | + continue; |
|
| 1880 | + } |
|
| 1792 | 1881 | |
| 1793 | 1882 | $result[] = array( |
| 1794 | 1883 | 'filename' => $smcFunc['htmlspecialchars']($line), |
@@ -1796,8 +1885,9 @@ discard block |
||
| 1796 | 1885 | 'name' => $smcFunc['htmlspecialchars'](str_replace('_', ' ', $filename)), |
| 1797 | 1886 | 'is_dir' => false |
| 1798 | 1887 | ); |
| 1799 | - if ($level == 1) |
|
| 1800 | - $context['avatar_list'][] = $directory . '/' . $line; |
|
| 1888 | + if ($level == 1) { |
|
| 1889 | + $context['avatar_list'][] = $directory . '/' . $line; |
|
| 1890 | + } |
|
| 1801 | 1891 | } |
| 1802 | 1892 | |
| 1803 | 1893 | return $result; |
@@ -1816,8 +1906,9 @@ discard block |
||
| 1816 | 1906 | loadSubTemplate('options'); |
| 1817 | 1907 | |
| 1818 | 1908 | loadThemeOptions($memID); |
| 1819 | - if (allowedTo(array('profile_extra_own', 'profile_extra_any'))) |
|
| 1820 | - loadCustomFields($memID, 'theme'); |
|
| 1909 | + if (allowedTo(array('profile_extra_own', 'profile_extra_any'))) { |
|
| 1910 | + loadCustomFields($memID, 'theme'); |
|
| 1911 | + } |
|
| 1821 | 1912 | |
| 1822 | 1913 | $context['sub_template'] = 'edit_options'; |
| 1823 | 1914 | $context['page_desc'] = $txt['theme_info']; |
@@ -1871,16 +1962,19 @@ discard block |
||
| 1871 | 1962 | { |
| 1872 | 1963 | global $txt, $context, $modSettings, $smcFunc, $sourcedir; |
| 1873 | 1964 | |
| 1874 | - if (!isset($context['token_check'])) |
|
| 1875 | - $context['token_check'] = 'profile-nt' . $memID; |
|
| 1965 | + if (!isset($context['token_check'])) { |
|
| 1966 | + $context['token_check'] = 'profile-nt' . $memID; |
|
| 1967 | + } |
|
| 1876 | 1968 | |
| 1877 | 1969 | is_not_guest(); |
| 1878 | - if (!$context['user']['is_owner']) |
|
| 1879 | - isAllowedTo('profile_extra_any'); |
|
| 1970 | + if (!$context['user']['is_owner']) { |
|
| 1971 | + isAllowedTo('profile_extra_any'); |
|
| 1972 | + } |
|
| 1880 | 1973 | |
| 1881 | 1974 | // Set the post action if we're coming from the profile... |
| 1882 | - if (!isset($context['action'])) |
|
| 1883 | - $context['action'] = 'action=profile;area=notification;sa=alerts;u=' . $memID; |
|
| 1975 | + if (!isset($context['action'])) { |
|
| 1976 | + $context['action'] = 'action=profile;area=notification;sa=alerts;u=' . $memID; |
|
| 1977 | + } |
|
| 1884 | 1978 | |
| 1885 | 1979 | // What options are set |
| 1886 | 1980 | loadThemeOptions($memID); |
@@ -1967,28 +2061,34 @@ discard block |
||
| 1967 | 2061 | ); |
| 1968 | 2062 | |
| 1969 | 2063 | // There are certain things that are disabled at the group level. |
| 1970 | - if (empty($modSettings['cal_enabled'])) |
|
| 1971 | - unset($alert_types['calendar']); |
|
| 2064 | + if (empty($modSettings['cal_enabled'])) { |
|
| 2065 | + unset($alert_types['calendar']); |
|
| 2066 | + } |
|
| 1972 | 2067 | |
| 1973 | 2068 | // Disable paid subscriptions at group level if they're disabled |
| 1974 | - if (empty($modSettings['paid_enabled'])) |
|
| 1975 | - unset($alert_types['paidsubs']); |
|
| 2069 | + if (empty($modSettings['paid_enabled'])) { |
|
| 2070 | + unset($alert_types['paidsubs']); |
|
| 2071 | + } |
|
| 1976 | 2072 | |
| 1977 | 2073 | // Disable membergroup requests at group level if they're disabled |
| 1978 | - if (empty($modSettings['show_group_membership'])) |
|
| 1979 | - unset($alert_types['groupr'], $alert_types['members']['request_group']); |
|
| 2074 | + if (empty($modSettings['show_group_membership'])) { |
|
| 2075 | + unset($alert_types['groupr'], $alert_types['members']['request_group']); |
|
| 2076 | + } |
|
| 1980 | 2077 | |
| 1981 | 2078 | // Disable mentions if they're disabled |
| 1982 | - if (empty($modSettings['enable_mentions'])) |
|
| 1983 | - unset($alert_types['msg']['msg_mention']); |
|
| 2079 | + if (empty($modSettings['enable_mentions'])) { |
|
| 2080 | + unset($alert_types['msg']['msg_mention']); |
|
| 2081 | + } |
|
| 1984 | 2082 | |
| 1985 | 2083 | // Disable likes if they're disabled |
| 1986 | - if (empty($modSettings['enable_likes'])) |
|
| 1987 | - unset($alert_types['msg']['msg_like']); |
|
| 2084 | + if (empty($modSettings['enable_likes'])) { |
|
| 2085 | + unset($alert_types['msg']['msg_like']); |
|
| 2086 | + } |
|
| 1988 | 2087 | |
| 1989 | 2088 | // Disable buddy requests if they're disabled |
| 1990 | - if (empty($modSettings['enable_buddylist'])) |
|
| 1991 | - unset($alert_types['members']['buddy_request']); |
|
| 2089 | + if (empty($modSettings['enable_buddylist'])) { |
|
| 2090 | + unset($alert_types['members']['buddy_request']); |
|
| 2091 | + } |
|
| 1992 | 2092 | |
| 1993 | 2093 | // Now, now, we could pass this through global but we should really get into the habit of |
| 1994 | 2094 | // passing content to hooks, not expecting hooks to splatter everything everywhere. |
@@ -2016,15 +2116,17 @@ discard block |
||
| 2016 | 2116 | $perms_cache['manage_membergroups'] = in_array($memID, $members); |
| 2017 | 2117 | } |
| 2018 | 2118 | |
| 2019 | - if (!($perms_cache['manage_membergroups'] || $can_mod != 0)) |
|
| 2020 | - unset($alert_types['members']['request_group']); |
|
| 2119 | + if (!($perms_cache['manage_membergroups'] || $can_mod != 0)) { |
|
| 2120 | + unset($alert_types['members']['request_group']); |
|
| 2121 | + } |
|
| 2021 | 2122 | |
| 2022 | 2123 | foreach ($alert_types as $group => $items) |
| 2023 | 2124 | { |
| 2024 | 2125 | foreach ($items as $alert_key => $alert_value) |
| 2025 | 2126 | { |
| 2026 | - if (!isset($alert_value['permission'])) |
|
| 2027 | - continue; |
|
| 2127 | + if (!isset($alert_value['permission'])) { |
|
| 2128 | + continue; |
|
| 2129 | + } |
|
| 2028 | 2130 | if (!isset($perms_cache[$alert_value['permission']['name']])) |
| 2029 | 2131 | { |
| 2030 | 2132 | $in_board = !empty($alert_value['permission']['is_board']) ? 0 : null; |
@@ -2032,12 +2134,14 @@ discard block |
||
| 2032 | 2134 | $perms_cache[$alert_value['permission']['name']] = in_array($memID, $members); |
| 2033 | 2135 | } |
| 2034 | 2136 | |
| 2035 | - if (!$perms_cache[$alert_value['permission']['name']]) |
|
| 2036 | - unset ($alert_types[$group][$alert_key]); |
|
| 2137 | + if (!$perms_cache[$alert_value['permission']['name']]) { |
|
| 2138 | + unset ($alert_types[$group][$alert_key]); |
|
| 2139 | + } |
|
| 2037 | 2140 | } |
| 2038 | 2141 | |
| 2039 | - if (empty($alert_types[$group])) |
|
| 2040 | - unset ($alert_types[$group]); |
|
| 2142 | + if (empty($alert_types[$group])) { |
|
| 2143 | + unset ($alert_types[$group]); |
|
| 2144 | + } |
|
| 2041 | 2145 | } |
| 2042 | 2146 | } |
| 2043 | 2147 | |
@@ -2069,9 +2173,9 @@ discard block |
||
| 2069 | 2173 | $update_prefs[$this_option[1]] = !empty($_POST['opt_' . $this_option[1]]) ? 1 : 0; |
| 2070 | 2174 | break; |
| 2071 | 2175 | case 'select': |
| 2072 | - if (isset($_POST['opt_' . $this_option[1]], $this_option['opts'][$_POST['opt_' . $this_option[1]]])) |
|
| 2073 | - $update_prefs[$this_option[1]] = $_POST['opt_' . $this_option[1]]; |
|
| 2074 | - else |
|
| 2176 | + if (isset($_POST['opt_' . $this_option[1]], $this_option['opts'][$_POST['opt_' . $this_option[1]]])) { |
|
| 2177 | + $update_prefs[$this_option[1]] = $_POST['opt_' . $this_option[1]]; |
|
| 2178 | + } else |
|
| 2075 | 2179 | { |
| 2076 | 2180 | // We didn't have a sane value. Let's grab the first item from the possibles. |
| 2077 | 2181 | $keys = array_keys($this_option['opts']); |
@@ -2091,23 +2195,28 @@ discard block |
||
| 2091 | 2195 | $this_value = 0; |
| 2092 | 2196 | foreach ($context['alert_bits'] as $type => $bitvalue) |
| 2093 | 2197 | { |
| 2094 | - if ($this_options[$type] == 'yes' && !empty($_POST[$type . '_' . $item_key]) || $this_options[$type] == 'always') |
|
| 2095 | - $this_value |= $bitvalue; |
|
| 2198 | + if ($this_options[$type] == 'yes' && !empty($_POST[$type . '_' . $item_key]) || $this_options[$type] == 'always') { |
|
| 2199 | + $this_value |= $bitvalue; |
|
| 2200 | + } |
|
| 2201 | + } |
|
| 2202 | + if (!isset($context['alert_prefs'][$item_key]) || $context['alert_prefs'][$item_key] != $this_value) { |
|
| 2203 | + $update_prefs[$item_key] = $this_value; |
|
| 2096 | 2204 | } |
| 2097 | - if (!isset($context['alert_prefs'][$item_key]) || $context['alert_prefs'][$item_key] != $this_value) |
|
| 2098 | - $update_prefs[$item_key] = $this_value; |
|
| 2099 | 2205 | } |
| 2100 | 2206 | } |
| 2101 | 2207 | |
| 2102 | - if (!empty($_POST['opt_alert_timeout'])) |
|
| 2103 | - $update_prefs['alert_timeout'] = $context['member']['alert_timeout'] = (int) $_POST['opt_alert_timeout']; |
|
| 2208 | + if (!empty($_POST['opt_alert_timeout'])) { |
|
| 2209 | + $update_prefs['alert_timeout'] = $context['member']['alert_timeout'] = (int) $_POST['opt_alert_timeout']; |
|
| 2210 | + } |
|
| 2104 | 2211 | |
| 2105 | - if (!empty($_POST['notify_announcements'])) |
|
| 2106 | - $update_prefs['announcements'] = $context['member']['notify_announcements'] = (int) $_POST['notify_announcements']; |
|
| 2212 | + if (!empty($_POST['notify_announcements'])) { |
|
| 2213 | + $update_prefs['announcements'] = $context['member']['notify_announcements'] = (int) $_POST['notify_announcements']; |
|
| 2214 | + } |
|
| 2107 | 2215 | |
| 2108 | 2216 | setNotifyPrefs((int) $memID, $update_prefs); |
| 2109 | - foreach ($update_prefs as $pref => $value) |
|
| 2110 | - $context['alert_prefs'][$pref] = $value; |
|
| 2217 | + foreach ($update_prefs as $pref => $value) { |
|
| 2218 | + $context['alert_prefs'][$pref] = $value; |
|
| 2219 | + } |
|
| 2111 | 2220 | |
| 2112 | 2221 | makeNotificationChanges($memID); |
| 2113 | 2222 | |
@@ -2137,8 +2246,9 @@ discard block |
||
| 2137 | 2246 | |
| 2138 | 2247 | // Now we're all set up. |
| 2139 | 2248 | is_not_guest(); |
| 2140 | - if (!$context['user']['is_owner']) |
|
| 2141 | - fatal_error('no_access'); |
|
| 2249 | + if (!$context['user']['is_owner']) { |
|
| 2250 | + fatal_error('no_access'); |
|
| 2251 | + } |
|
| 2142 | 2252 | |
| 2143 | 2253 | checkSession('get'); |
| 2144 | 2254 | |
@@ -2170,8 +2280,9 @@ discard block |
||
| 2170 | 2280 | { |
| 2171 | 2281 | global $smcFunc; |
| 2172 | 2282 | |
| 2173 | - if (empty($toMark) || empty($memID)) |
|
| 2174 | - return false; |
|
| 2283 | + if (empty($toMark) || empty($memID)) { |
|
| 2284 | + return false; |
|
| 2285 | + } |
|
| 2175 | 2286 | |
| 2176 | 2287 | $toMark = (array) $toMark; |
| 2177 | 2288 | |
@@ -2205,8 +2316,9 @@ discard block |
||
| 2205 | 2316 | { |
| 2206 | 2317 | global $smcFunc; |
| 2207 | 2318 | |
| 2208 | - if (empty($toDelete)) |
|
| 2209 | - return false; |
|
| 2319 | + if (empty($toDelete)) { |
|
| 2320 | + return false; |
|
| 2321 | + } |
|
| 2210 | 2322 | |
| 2211 | 2323 | $toDelete = (array) $toDelete; |
| 2212 | 2324 | |
@@ -2241,8 +2353,9 @@ discard block |
||
| 2241 | 2353 | { |
| 2242 | 2354 | global $smcFunc; |
| 2243 | 2355 | |
| 2244 | - if (empty($memID)) |
|
| 2245 | - return false; |
|
| 2356 | + if (empty($memID)) { |
|
| 2357 | + return false; |
|
| 2358 | + } |
|
| 2246 | 2359 | |
| 2247 | 2360 | $request = $smcFunc['db_query']('', ' |
| 2248 | 2361 | SELECT id_alert |
@@ -2319,8 +2432,9 @@ discard block |
||
| 2319 | 2432 | { |
| 2320 | 2433 | $link = $topic['link']; |
| 2321 | 2434 | |
| 2322 | - if ($topic['new']) |
|
| 2323 | - $link .= ' <a href="' . $topic['new_href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>'; |
|
| 2435 | + if ($topic['new']) { |
|
| 2436 | + $link .= ' <a href="' . $topic['new_href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>'; |
|
| 2437 | + } |
|
| 2324 | 2438 | |
| 2325 | 2439 | $link .= '<br><span class="smalltext"><em>' . $txt['in'] . ' ' . $topic['board_link'] . '</em></span>'; |
| 2326 | 2440 | |
@@ -2471,8 +2585,9 @@ discard block |
||
| 2471 | 2585 | { |
| 2472 | 2586 | $link = $board['link']; |
| 2473 | 2587 | |
| 2474 | - if ($board['new']) |
|
| 2475 | - $link .= ' <a href="' . $board['href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>'; |
|
| 2588 | + if ($board['new']) { |
|
| 2589 | + $link .= ' <a href="' . $board['href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>'; |
|
| 2590 | + } |
|
| 2476 | 2591 | |
| 2477 | 2592 | return $link; |
| 2478 | 2593 | }, |
@@ -2672,8 +2787,8 @@ discard block |
||
| 2672 | 2787 | ) |
| 2673 | 2788 | ); |
| 2674 | 2789 | $notification_boards = array(); |
| 2675 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 2676 | - $notification_boards[] = array( |
|
| 2790 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 2791 | + $notification_boards[] = array( |
|
| 2677 | 2792 | 'id' => $row['id_board'], |
| 2678 | 2793 | 'name' => $row['name'], |
| 2679 | 2794 | 'href' => $scripturl . '?board=' . $row['id_board'] . '.0', |
@@ -2681,6 +2796,7 @@ discard block |
||
| 2681 | 2796 | 'new' => $row['board_read'] < $row['id_msg_updated'], |
| 2682 | 2797 | 'notify_pref' => isset($prefs['board_notify_' . $row['id_board']]) ? $prefs['board_notify_' . $row['id_board']] : (!empty($prefs['board_notify']) ? $prefs['board_notify'] : 0), |
| 2683 | 2798 | ); |
| 2799 | + } |
|
| 2684 | 2800 | $smcFunc['db_free_result']($request); |
| 2685 | 2801 | |
| 2686 | 2802 | return $notification_boards; |
@@ -2695,17 +2811,18 @@ discard block |
||
| 2695 | 2811 | { |
| 2696 | 2812 | global $context, $options, $cur_profile, $smcFunc; |
| 2697 | 2813 | |
| 2698 | - if (isset($_POST['default_options'])) |
|
| 2699 | - $_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options']; |
|
| 2814 | + if (isset($_POST['default_options'])) { |
|
| 2815 | + $_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options']; |
|
| 2816 | + } |
|
| 2700 | 2817 | |
| 2701 | 2818 | if ($context['user']['is_owner']) |
| 2702 | 2819 | { |
| 2703 | 2820 | $context['member']['options'] = $options; |
| 2704 | - if (isset($_POST['options']) && is_array($_POST['options'])) |
|
| 2705 | - foreach ($_POST['options'] as $k => $v) |
|
| 2821 | + if (isset($_POST['options']) && is_array($_POST['options'])) { |
|
| 2822 | + foreach ($_POST['options'] as $k => $v) |
|
| 2706 | 2823 | $context['member']['options'][$k] = $v; |
| 2707 | - } |
|
| 2708 | - else |
|
| 2824 | + } |
|
| 2825 | + } else |
|
| 2709 | 2826 | { |
| 2710 | 2827 | $request = $smcFunc['db_query']('', ' |
| 2711 | 2828 | SELECT id_member, variable, value |
@@ -2726,8 +2843,9 @@ discard block |
||
| 2726 | 2843 | continue; |
| 2727 | 2844 | } |
| 2728 | 2845 | |
| 2729 | - if (isset($_POST['options'][$row['variable']])) |
|
| 2730 | - $row['value'] = $_POST['options'][$row['variable']]; |
|
| 2846 | + if (isset($_POST['options'][$row['variable']])) { |
|
| 2847 | + $row['value'] = $_POST['options'][$row['variable']]; |
|
| 2848 | + } |
|
| 2731 | 2849 | $context['member']['options'][$row['variable']] = $row['value']; |
| 2732 | 2850 | } |
| 2733 | 2851 | $smcFunc['db_free_result']($request); |
@@ -2735,8 +2853,9 @@ discard block |
||
| 2735 | 2853 | // Load up the default theme options for any missing. |
| 2736 | 2854 | foreach ($temp as $k => $v) |
| 2737 | 2855 | { |
| 2738 | - if (!isset($context['member']['options'][$k])) |
|
| 2739 | - $context['member']['options'][$k] = $v; |
|
| 2856 | + if (!isset($context['member']['options'][$k])) { |
|
| 2857 | + $context['member']['options'][$k] = $v; |
|
| 2858 | + } |
|
| 2740 | 2859 | } |
| 2741 | 2860 | } |
| 2742 | 2861 | } |
@@ -2751,8 +2870,9 @@ discard block |
||
| 2751 | 2870 | global $context, $modSettings, $smcFunc, $cur_profile, $sourcedir; |
| 2752 | 2871 | |
| 2753 | 2872 | // Have the admins enabled this option? |
| 2754 | - if (empty($modSettings['allow_ignore_boards'])) |
|
| 2755 | - fatal_lang_error('ignoreboards_disallowed', 'user'); |
|
| 2873 | + if (empty($modSettings['allow_ignore_boards'])) { |
|
| 2874 | + fatal_lang_error('ignoreboards_disallowed', 'user'); |
|
| 2875 | + } |
|
| 2756 | 2876 | |
| 2757 | 2877 | // Find all the boards this user is allowed to see. |
| 2758 | 2878 | $request = $smcFunc['db_query']('order_by_board_order', ' |
@@ -2772,12 +2892,13 @@ discard block |
||
| 2772 | 2892 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 2773 | 2893 | { |
| 2774 | 2894 | // This category hasn't been set up yet.. |
| 2775 | - if (!isset($context['categories'][$row['id_cat']])) |
|
| 2776 | - $context['categories'][$row['id_cat']] = array( |
|
| 2895 | + if (!isset($context['categories'][$row['id_cat']])) { |
|
| 2896 | + $context['categories'][$row['id_cat']] = array( |
|
| 2777 | 2897 | 'id' => $row['id_cat'], |
| 2778 | 2898 | 'name' => $row['cat_name'], |
| 2779 | 2899 | 'boards' => array() |
| 2780 | 2900 | ); |
| 2901 | + } |
|
| 2781 | 2902 | |
| 2782 | 2903 | // Set this board up, and let the template know when it's a child. (indent them..) |
| 2783 | 2904 | $context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array( |
@@ -2807,18 +2928,20 @@ discard block |
||
| 2807 | 2928 | } |
| 2808 | 2929 | |
| 2809 | 2930 | $max_boards = ceil(count($temp_boards) / 2); |
| 2810 | - if ($max_boards == 1) |
|
| 2811 | - $max_boards = 2; |
|
| 2931 | + if ($max_boards == 1) { |
|
| 2932 | + $max_boards = 2; |
|
| 2933 | + } |
|
| 2812 | 2934 | |
| 2813 | 2935 | // Now, alternate them so they can be shown left and right ;). |
| 2814 | 2936 | $context['board_columns'] = array(); |
| 2815 | 2937 | for ($i = 0; $i < $max_boards; $i++) |
| 2816 | 2938 | { |
| 2817 | 2939 | $context['board_columns'][] = $temp_boards[$i]; |
| 2818 | - if (isset($temp_boards[$i + $max_boards])) |
|
| 2819 | - $context['board_columns'][] = $temp_boards[$i + $max_boards]; |
|
| 2820 | - else |
|
| 2821 | - $context['board_columns'][] = array(); |
|
| 2940 | + if (isset($temp_boards[$i + $max_boards])) { |
|
| 2941 | + $context['board_columns'][] = $temp_boards[$i + $max_boards]; |
|
| 2942 | + } else { |
|
| 2943 | + $context['board_columns'][] = array(); |
|
| 2944 | + } |
|
| 2822 | 2945 | } |
| 2823 | 2946 | |
| 2824 | 2947 | loadThemeOptions($memID); |
@@ -2887,8 +3010,9 @@ discard block |
||
| 2887 | 3010 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 2888 | 3011 | { |
| 2889 | 3012 | // We should skip the administrator group if they don't have the admin_forum permission! |
| 2890 | - if ($row['id_group'] == 1 && !allowedTo('admin_forum')) |
|
| 2891 | - continue; |
|
| 3013 | + if ($row['id_group'] == 1 && !allowedTo('admin_forum')) { |
|
| 3014 | + continue; |
|
| 3015 | + } |
|
| 2892 | 3016 | |
| 2893 | 3017 | $context['member_groups'][$row['id_group']] = array( |
| 2894 | 3018 | 'id' => $row['id_group'], |
@@ -2934,16 +3058,17 @@ discard block |
||
| 2934 | 3058 | $context['max_signature_length'] = $context['signature_limits']['max_length']; |
| 2935 | 3059 | // Warning message for signature image limits? |
| 2936 | 3060 | $context['signature_warning'] = ''; |
| 2937 | - if ($context['signature_limits']['max_image_width'] && $context['signature_limits']['max_image_height']) |
|
| 2938 | - $context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_size'], $context['signature_limits']['max_image_width'], $context['signature_limits']['max_image_height']); |
|
| 2939 | - elseif ($context['signature_limits']['max_image_width'] || $context['signature_limits']['max_image_height']) |
|
| 2940 | - $context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_' . ($context['signature_limits']['max_image_width'] ? 'width' : 'height')], $context['signature_limits'][$context['signature_limits']['max_image_width'] ? 'max_image_width' : 'max_image_height']); |
|
| 3061 | + if ($context['signature_limits']['max_image_width'] && $context['signature_limits']['max_image_height']) { |
|
| 3062 | + $context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_size'], $context['signature_limits']['max_image_width'], $context['signature_limits']['max_image_height']); |
|
| 3063 | + } elseif ($context['signature_limits']['max_image_width'] || $context['signature_limits']['max_image_height']) { |
|
| 3064 | + $context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_' . ($context['signature_limits']['max_image_width'] ? 'width' : 'height')], $context['signature_limits'][$context['signature_limits']['max_image_width'] ? 'max_image_width' : 'max_image_height']); |
|
| 3065 | + } |
|
| 2941 | 3066 | |
| 2942 | 3067 | $context['show_spellchecking'] = !empty($modSettings['enableSpellChecking']) && (function_exists('pspell_new') || (function_exists('enchant_broker_init') && ($txt['lang_charset'] == 'UTF-8' || function_exists('iconv')))); |
| 2943 | 3068 | |
| 2944 | - if (empty($context['do_preview'])) |
|
| 2945 | - $context['member']['signature'] = empty($cur_profile['signature']) ? '' : str_replace(array('<br>', '<', '>', '"', '\''), array("\n", '<', '>', '"', '''), $cur_profile['signature']); |
|
| 2946 | - else |
|
| 3069 | + if (empty($context['do_preview'])) { |
|
| 3070 | + $context['member']['signature'] = empty($cur_profile['signature']) ? '' : str_replace(array('<br>', '<', '>', '"', '\''), array("\n", '<', '>', '"', '''), $cur_profile['signature']); |
|
| 3071 | + } else |
|
| 2947 | 3072 | { |
| 2948 | 3073 | $signature = !empty($_POST['signature']) ? $_POST['signature'] : ''; |
| 2949 | 3074 | $validation = profileValidateSignature($signature); |
@@ -2953,8 +3078,9 @@ discard block |
||
| 2953 | 3078 | $context['post_errors'] = array(); |
| 2954 | 3079 | } |
| 2955 | 3080 | $context['post_errors'][] = 'signature_not_yet_saved'; |
| 2956 | - if ($validation !== true && $validation !== false) |
|
| 2957 | - $context['post_errors'][] = $validation; |
|
| 3081 | + if ($validation !== true && $validation !== false) { |
|
| 3082 | + $context['post_errors'][] = $validation; |
|
| 3083 | + } |
|
| 2958 | 3084 | |
| 2959 | 3085 | censorText($context['member']['signature']); |
| 2960 | 3086 | $context['member']['current_signature'] = $context['member']['signature']; |
@@ -2964,8 +3090,9 @@ discard block |
||
| 2964 | 3090 | } |
| 2965 | 3091 | |
| 2966 | 3092 | // Load the spell checker? |
| 2967 | - if ($context['show_spellchecking']) |
|
| 2968 | - loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck'); |
|
| 3093 | + if ($context['show_spellchecking']) { |
|
| 3094 | + loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck'); |
|
| 3095 | + } |
|
| 2969 | 3096 | |
| 2970 | 3097 | return true; |
| 2971 | 3098 | } |
@@ -2999,8 +3126,7 @@ discard block |
||
| 2999 | 3126 | 'external' => $cur_profile['avatar'] == 'gravatar://' || empty($modSettings['gravatarAllowExtraEmail']) || !empty($modSettings['gravatarOverride']) ? $cur_profile['email_address'] : substr($cur_profile['avatar'], 11) |
| 3000 | 3127 | ); |
| 3001 | 3128 | $context['member']['avatar']['href'] = get_gravatar_url($context['member']['avatar']['external']); |
| 3002 | - } |
|
| 3003 | - elseif ($cur_profile['avatar'] == '' && $cur_profile['id_attach'] > 0 && $context['member']['avatar']['allow_upload']) |
|
| 3129 | + } elseif ($cur_profile['avatar'] == '' && $cur_profile['id_attach'] > 0 && $context['member']['avatar']['allow_upload']) |
|
| 3004 | 3130 | { |
| 3005 | 3131 | $context['member']['avatar'] += array( |
| 3006 | 3132 | 'choice' => 'upload', |
@@ -3010,33 +3136,34 @@ discard block |
||
| 3010 | 3136 | $context['member']['avatar']['href'] = empty($cur_profile['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $cur_profile['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $cur_profile['filename']; |
| 3011 | 3137 | } |
| 3012 | 3138 | // Use "avatar_original" here so we show what the user entered even if the image proxy is enabled |
| 3013 | - elseif ((stristr($cur_profile['avatar'], 'http://') || stristr($cur_profile['avatar'], 'https://')) && $context['member']['avatar']['allow_external']) |
|
| 3014 | - $context['member']['avatar'] += array( |
|
| 3139 | + elseif ((stristr($cur_profile['avatar'], 'http://') || stristr($cur_profile['avatar'], 'https://')) && $context['member']['avatar']['allow_external']) { |
|
| 3140 | + $context['member']['avatar'] += array( |
|
| 3015 | 3141 | 'choice' => 'external', |
| 3016 | 3142 | 'server_pic' => 'blank.png', |
| 3017 | 3143 | 'external' => $cur_profile['avatar_original'] |
| 3018 | 3144 | ); |
| 3019 | - elseif ($cur_profile['avatar'] != '' && file_exists($modSettings['avatar_directory'] . '/' . $cur_profile['avatar']) && $context['member']['avatar']['allow_server_stored']) |
|
| 3020 | - $context['member']['avatar'] += array( |
|
| 3145 | + } elseif ($cur_profile['avatar'] != '' && file_exists($modSettings['avatar_directory'] . '/' . $cur_profile['avatar']) && $context['member']['avatar']['allow_server_stored']) { |
|
| 3146 | + $context['member']['avatar'] += array( |
|
| 3021 | 3147 | 'choice' => 'server_stored', |
| 3022 | 3148 | 'server_pic' => $cur_profile['avatar'] == '' ? 'blank.png' : $cur_profile['avatar'], |
| 3023 | 3149 | 'external' => 'http://' |
| 3024 | 3150 | ); |
| 3025 | - else |
|
| 3026 | - $context['member']['avatar'] += array( |
|
| 3151 | + } else { |
|
| 3152 | + $context['member']['avatar'] += array( |
|
| 3027 | 3153 | 'choice' => 'none', |
| 3028 | 3154 | 'server_pic' => 'blank.png', |
| 3029 | 3155 | 'external' => 'http://' |
| 3030 | 3156 | ); |
| 3157 | + } |
|
| 3031 | 3158 | |
| 3032 | 3159 | // Get a list of all the avatars. |
| 3033 | 3160 | if ($context['member']['avatar']['allow_server_stored']) |
| 3034 | 3161 | { |
| 3035 | 3162 | $context['avatar_list'] = array(); |
| 3036 | 3163 | $context['avatars'] = is_dir($modSettings['avatar_directory']) ? getAvatars('', 0) : array(); |
| 3164 | + } else { |
|
| 3165 | + $context['avatars'] = array(); |
|
| 3037 | 3166 | } |
| 3038 | - else |
|
| 3039 | - $context['avatars'] = array(); |
|
| 3040 | 3167 | |
| 3041 | 3168 | // Second level selected avatar... |
| 3042 | 3169 | $context['avatar_selected'] = substr(strrchr($context['member']['avatar']['server_pic'], '/'), 1); |
@@ -3065,19 +3192,22 @@ discard block |
||
| 3065 | 3192 | ) |
| 3066 | 3193 | ); |
| 3067 | 3194 | $protected_groups = array(1); |
| 3068 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 3069 | - $protected_groups[] = $row['id_group']; |
|
| 3195 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 3196 | + $protected_groups[] = $row['id_group']; |
|
| 3197 | + } |
|
| 3070 | 3198 | $smcFunc['db_free_result']($request); |
| 3071 | 3199 | |
| 3072 | 3200 | $protected_groups = array_unique($protected_groups); |
| 3073 | 3201 | } |
| 3074 | 3202 | |
| 3075 | 3203 | // The account page allows the change of your id_group - but not to a protected group! |
| 3076 | - if (empty($protected_groups) || count(array_intersect(array((int) $value, $old_profile['id_group']), $protected_groups)) == 0) |
|
| 3077 | - $value = (int) $value; |
|
| 3204 | + if (empty($protected_groups) || count(array_intersect(array((int) $value, $old_profile['id_group']), $protected_groups)) == 0) { |
|
| 3205 | + $value = (int) $value; |
|
| 3206 | + } |
|
| 3078 | 3207 | // ... otherwise it's the old group sir. |
| 3079 | - else |
|
| 3080 | - $value = $old_profile['id_group']; |
|
| 3208 | + else { |
|
| 3209 | + $value = $old_profile['id_group']; |
|
| 3210 | + } |
|
| 3081 | 3211 | |
| 3082 | 3212 | // Find the additional membergroups (if any) |
| 3083 | 3213 | if (isset($_POST['additional_groups']) && is_array($_POST['additional_groups'])) |
@@ -3086,16 +3216,18 @@ discard block |
||
| 3086 | 3216 | foreach ($_POST['additional_groups'] as $group_id) |
| 3087 | 3217 | { |
| 3088 | 3218 | $group_id = (int) $group_id; |
| 3089 | - if (!empty($group_id) && (empty($protected_groups) || !in_array($group_id, $protected_groups))) |
|
| 3090 | - $additional_groups[] = $group_id; |
|
| 3219 | + if (!empty($group_id) && (empty($protected_groups) || !in_array($group_id, $protected_groups))) { |
|
| 3220 | + $additional_groups[] = $group_id; |
|
| 3221 | + } |
|
| 3091 | 3222 | } |
| 3092 | 3223 | |
| 3093 | 3224 | // Put the protected groups back in there if you don't have permission to take them away. |
| 3094 | 3225 | $old_additional_groups = explode(',', $old_profile['additional_groups']); |
| 3095 | 3226 | foreach ($old_additional_groups as $group_id) |
| 3096 | 3227 | { |
| 3097 | - if (!empty($protected_groups) && in_array($group_id, $protected_groups)) |
|
| 3098 | - $additional_groups[] = $group_id; |
|
| 3228 | + if (!empty($protected_groups) && in_array($group_id, $protected_groups)) { |
|
| 3229 | + $additional_groups[] = $group_id; |
|
| 3230 | + } |
|
| 3099 | 3231 | } |
| 3100 | 3232 | |
| 3101 | 3233 | if (implode(',', $additional_groups) !== $old_profile['additional_groups']) |
@@ -3127,18 +3259,20 @@ discard block |
||
| 3127 | 3259 | list ($another) = $smcFunc['db_fetch_row']($request); |
| 3128 | 3260 | $smcFunc['db_free_result']($request); |
| 3129 | 3261 | |
| 3130 | - if (empty($another)) |
|
| 3131 | - fatal_lang_error('at_least_one_admin', 'critical'); |
|
| 3262 | + if (empty($another)) { |
|
| 3263 | + fatal_lang_error('at_least_one_admin', 'critical'); |
|
| 3264 | + } |
|
| 3132 | 3265 | } |
| 3133 | 3266 | } |
| 3134 | 3267 | |
| 3135 | 3268 | // If we are changing group status, update permission cache as necessary. |
| 3136 | 3269 | if ($value != $old_profile['id_group'] || isset($profile_vars['additional_groups'])) |
| 3137 | 3270 | { |
| 3138 | - if ($context['user']['is_owner']) |
|
| 3139 | - $_SESSION['mc']['time'] = 0; |
|
| 3140 | - else |
|
| 3141 | - updateSettings(array('settings_updated' => time())); |
|
| 3271 | + if ($context['user']['is_owner']) { |
|
| 3272 | + $_SESSION['mc']['time'] = 0; |
|
| 3273 | + } else { |
|
| 3274 | + updateSettings(array('settings_updated' => time())); |
|
| 3275 | + } |
|
| 3142 | 3276 | } |
| 3143 | 3277 | |
| 3144 | 3278 | // Announce to any hooks that we have changed groups, but don't allow them to change it. |
@@ -3159,8 +3293,9 @@ discard block |
||
| 3159 | 3293 | global $modSettings, $sourcedir, $smcFunc, $profile_vars, $cur_profile, $context; |
| 3160 | 3294 | |
| 3161 | 3295 | $memID = $context['id_member']; |
| 3162 | - if (empty($memID) && !empty($context['password_auth_failed'])) |
|
| 3163 | - return false; |
|
| 3296 | + if (empty($memID) && !empty($context['password_auth_failed'])) { |
|
| 3297 | + return false; |
|
| 3298 | + } |
|
| 3164 | 3299 | |
| 3165 | 3300 | require_once($sourcedir . '/ManageAttachments.php'); |
| 3166 | 3301 | |
@@ -3171,8 +3306,9 @@ discard block |
||
| 3171 | 3306 | $downloadedExternalAvatar = false; |
| 3172 | 3307 | if ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && strlen($_POST['userpicpersonal']) > 7 && !empty($modSettings['avatar_download_external'])) |
| 3173 | 3308 | { |
| 3174 | - if (!is_writable($uploadDir)) |
|
| 3175 | - fatal_lang_error('attachments_no_write', 'critical'); |
|
| 3309 | + if (!is_writable($uploadDir)) { |
|
| 3310 | + fatal_lang_error('attachments_no_write', 'critical'); |
|
| 3311 | + } |
|
| 3176 | 3312 | |
| 3177 | 3313 | require_once($sourcedir . '/Subs-Package.php'); |
| 3178 | 3314 | |
@@ -3216,19 +3352,18 @@ discard block |
||
| 3216 | 3352 | |
| 3217 | 3353 | // Get rid of their old avatar. (if uploaded.) |
| 3218 | 3354 | removeAttachments(array('id_member' => $memID)); |
| 3219 | - } |
|
| 3220 | - elseif ($value == 'gravatar' && !empty($modSettings['gravatarEnabled'])) |
|
| 3355 | + } elseif ($value == 'gravatar' && !empty($modSettings['gravatarEnabled'])) |
|
| 3221 | 3356 | { |
| 3222 | 3357 | // One wasn't specified, or it's not allowed to use extra email addresses, or it's not a valid one, reset to default Gravatar. |
| 3223 | - if (empty($_POST['gravatarEmail']) || empty($modSettings['gravatarAllowExtraEmail']) || !filter_var($_POST['gravatarEmail'], FILTER_VALIDATE_EMAIL)) |
|
| 3224 | - $profile_vars['avatar'] = 'gravatar://'; |
|
| 3225 | - else |
|
| 3226 | - $profile_vars['avatar'] = 'gravatar://' . ($_POST['gravatarEmail'] != $cur_profile['email_address'] ? $_POST['gravatarEmail'] : ''); |
|
| 3358 | + if (empty($_POST['gravatarEmail']) || empty($modSettings['gravatarAllowExtraEmail']) || !filter_var($_POST['gravatarEmail'], FILTER_VALIDATE_EMAIL)) { |
|
| 3359 | + $profile_vars['avatar'] = 'gravatar://'; |
|
| 3360 | + } else { |
|
| 3361 | + $profile_vars['avatar'] = 'gravatar://' . ($_POST['gravatarEmail'] != $cur_profile['email_address'] ? $_POST['gravatarEmail'] : ''); |
|
| 3362 | + } |
|
| 3227 | 3363 | |
| 3228 | 3364 | // Get rid of their old avatar. (if uploaded.) |
| 3229 | 3365 | removeAttachments(array('id_member' => $memID)); |
| 3230 | - } |
|
| 3231 | - elseif ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && empty($modSettings['avatar_download_external'])) |
|
| 3366 | + } elseif ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && empty($modSettings['avatar_download_external'])) |
|
| 3232 | 3367 | { |
| 3233 | 3368 | // We need these clean... |
| 3234 | 3369 | $cur_profile['id_attach'] = 0; |
@@ -3240,11 +3375,13 @@ discard block |
||
| 3240 | 3375 | |
| 3241 | 3376 | $profile_vars['avatar'] = str_replace(' ', '%20', preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $_POST['userpicpersonal'])); |
| 3242 | 3377 | |
| 3243 | - if ($profile_vars['avatar'] == 'http://' || $profile_vars['avatar'] == 'http:///') |
|
| 3244 | - $profile_vars['avatar'] = ''; |
|
| 3378 | + if ($profile_vars['avatar'] == 'http://' || $profile_vars['avatar'] == 'http:///') { |
|
| 3379 | + $profile_vars['avatar'] = ''; |
|
| 3380 | + } |
|
| 3245 | 3381 | // Trying to make us do something we'll regret? |
| 3246 | - elseif (substr($profile_vars['avatar'], 0, 7) != 'http://' && substr($profile_vars['avatar'], 0, 8) != 'https://') |
|
| 3247 | - return 'bad_avatar_invalid_url'; |
|
| 3382 | + elseif (substr($profile_vars['avatar'], 0, 7) != 'http://' && substr($profile_vars['avatar'], 0, 8) != 'https://') { |
|
| 3383 | + return 'bad_avatar_invalid_url'; |
|
| 3384 | + } |
|
| 3248 | 3385 | // Should we check dimensions? |
| 3249 | 3386 | elseif (!empty($modSettings['avatar_max_height_external']) || !empty($modSettings['avatar_max_width_external'])) |
| 3250 | 3387 | { |
@@ -3254,9 +3391,9 @@ discard block |
||
| 3254 | 3391 | if (is_array($sizes) && (($sizes[0] > $modSettings['avatar_max_width_external'] && !empty($modSettings['avatar_max_width_external'])) || ($sizes[1] > $modSettings['avatar_max_height_external'] && !empty($modSettings['avatar_max_height_external'])))) |
| 3255 | 3392 | { |
| 3256 | 3393 | // Houston, we have a problem. The avatar is too large!! |
| 3257 | - if ($modSettings['avatar_action_too_large'] == 'option_refuse') |
|
| 3258 | - return 'bad_avatar_too_large'; |
|
| 3259 | - elseif ($modSettings['avatar_action_too_large'] == 'option_download_and_resize') |
|
| 3394 | + if ($modSettings['avatar_action_too_large'] == 'option_refuse') { |
|
| 3395 | + return 'bad_avatar_too_large'; |
|
| 3396 | + } elseif ($modSettings['avatar_action_too_large'] == 'option_download_and_resize') |
|
| 3260 | 3397 | { |
| 3261 | 3398 | // @todo remove this if appropriate |
| 3262 | 3399 | require_once($sourcedir . '/Subs-Graphics.php'); |
@@ -3266,26 +3403,27 @@ discard block |
||
| 3266 | 3403 | $cur_profile['id_attach'] = $modSettings['new_avatar_data']['id']; |
| 3267 | 3404 | $cur_profile['filename'] = $modSettings['new_avatar_data']['filename']; |
| 3268 | 3405 | $cur_profile['attachment_type'] = $modSettings['new_avatar_data']['type']; |
| 3406 | + } else { |
|
| 3407 | + return 'bad_avatar'; |
|
| 3269 | 3408 | } |
| 3270 | - else |
|
| 3271 | - return 'bad_avatar'; |
|
| 3272 | 3409 | } |
| 3273 | 3410 | } |
| 3274 | 3411 | } |
| 3275 | - } |
|
| 3276 | - elseif (($value == 'upload' && allowedTo('profile_upload_avatar')) || $downloadedExternalAvatar) |
|
| 3412 | + } elseif (($value == 'upload' && allowedTo('profile_upload_avatar')) || $downloadedExternalAvatar) |
|
| 3277 | 3413 | { |
| 3278 | 3414 | if ((isset($_FILES['attachment']['name']) && $_FILES['attachment']['name'] != '') || $downloadedExternalAvatar) |
| 3279 | 3415 | { |
| 3280 | 3416 | // Get the dimensions of the image. |
| 3281 | 3417 | if (!$downloadedExternalAvatar) |
| 3282 | 3418 | { |
| 3283 | - if (!is_writable($uploadDir)) |
|
| 3284 | - fatal_lang_error('attachments_no_write', 'critical'); |
|
| 3419 | + if (!is_writable($uploadDir)) { |
|
| 3420 | + fatal_lang_error('attachments_no_write', 'critical'); |
|
| 3421 | + } |
|
| 3285 | 3422 | |
| 3286 | 3423 | $new_filename = $uploadDir . '/' . getAttachmentFilename('avatar_tmp_' . $memID, false, null, true); |
| 3287 | - if (!move_uploaded_file($_FILES['attachment']['tmp_name'], $new_filename)) |
|
| 3288 | - fatal_lang_error('attach_timeout', 'critical'); |
|
| 3424 | + if (!move_uploaded_file($_FILES['attachment']['tmp_name'], $new_filename)) { |
|
| 3425 | + fatal_lang_error('attach_timeout', 'critical'); |
|
| 3426 | + } |
|
| 3289 | 3427 | |
| 3290 | 3428 | $_FILES['attachment']['tmp_name'] = $new_filename; |
| 3291 | 3429 | } |
@@ -3398,17 +3536,19 @@ discard block |
||
| 3398 | 3536 | $profile_vars['avatar'] = ''; |
| 3399 | 3537 | |
| 3400 | 3538 | // Delete any temporary file. |
| 3401 | - if (file_exists($_FILES['attachment']['tmp_name'])) |
|
| 3402 | - @unlink($_FILES['attachment']['tmp_name']); |
|
| 3539 | + if (file_exists($_FILES['attachment']['tmp_name'])) { |
|
| 3540 | + @unlink($_FILES['attachment']['tmp_name']); |
|
| 3541 | + } |
|
| 3403 | 3542 | } |
| 3404 | 3543 | // Selected the upload avatar option and had one already uploaded before or didn't upload one. |
| 3405 | - else |
|
| 3544 | + else { |
|
| 3545 | + $profile_vars['avatar'] = ''; |
|
| 3546 | + } |
|
| 3547 | + } elseif ($value == 'gravatar' && allowedTo('profile_gravatar_avatar')) { |
|
| 3548 | + $profile_vars['avatar'] = 'gravatar://www.gravatar.com/avatar/' . md5(strtolower(trim($cur_profile['email_address']))); |
|
| 3549 | + } else { |
|
| 3406 | 3550 | $profile_vars['avatar'] = ''; |
| 3407 | 3551 | } |
| 3408 | - elseif ($value == 'gravatar' && allowedTo('profile_gravatar_avatar')) |
|
| 3409 | - $profile_vars['avatar'] = 'gravatar://www.gravatar.com/avatar/' . md5(strtolower(trim($cur_profile['email_address']))); |
|
| 3410 | - else |
|
| 3411 | - $profile_vars['avatar'] = ''; |
|
| 3412 | 3552 | |
| 3413 | 3553 | // Setup the profile variables so it shows things right on display! |
| 3414 | 3554 | $cur_profile['avatar'] = $profile_vars['avatar']; |
@@ -3456,9 +3596,9 @@ discard block |
||
| 3456 | 3596 | $smiley_parsed = $unparsed_signature; |
| 3457 | 3597 | parsesmileys($smiley_parsed); |
| 3458 | 3598 | $smiley_count = substr_count(strtolower($smiley_parsed), '<img') - substr_count(strtolower($unparsed_signature), '<img'); |
| 3459 | - if (!empty($sig_limits[4]) && $sig_limits[4] == -1 && $smiley_count > 0) |
|
| 3460 | - return 'signature_allow_smileys'; |
|
| 3461 | - elseif (!empty($sig_limits[4]) && $sig_limits[4] > 0 && $smiley_count > $sig_limits[4]) |
|
| 3599 | + if (!empty($sig_limits[4]) && $sig_limits[4] == -1 && $smiley_count > 0) { |
|
| 3600 | + return 'signature_allow_smileys'; |
|
| 3601 | + } elseif (!empty($sig_limits[4]) && $sig_limits[4] > 0 && $smiley_count > $sig_limits[4]) |
|
| 3462 | 3602 | { |
| 3463 | 3603 | $txt['profile_error_signature_max_smileys'] = sprintf($txt['profile_error_signature_max_smileys'], $sig_limits[4]); |
| 3464 | 3604 | return 'signature_max_smileys'; |
@@ -3471,14 +3611,15 @@ discard block |
||
| 3471 | 3611 | { |
| 3472 | 3612 | $limit_broke = 0; |
| 3473 | 3613 | // Attempt to allow all sizes of abuse, so to speak. |
| 3474 | - if ($matches[2][$ind] == 'px' && $size > $sig_limits[7]) |
|
| 3475 | - $limit_broke = $sig_limits[7] . 'px'; |
|
| 3476 | - elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75)) |
|
| 3477 | - $limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt'; |
|
| 3478 | - elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16)) |
|
| 3479 | - $limit_broke = ((float) $sig_limits[7] / 16) . 'em'; |
|
| 3480 | - elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18) |
|
| 3481 | - $limit_broke = 'large'; |
|
| 3614 | + if ($matches[2][$ind] == 'px' && $size > $sig_limits[7]) { |
|
| 3615 | + $limit_broke = $sig_limits[7] . 'px'; |
|
| 3616 | + } elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75)) { |
|
| 3617 | + $limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt'; |
|
| 3618 | + } elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16)) { |
|
| 3619 | + $limit_broke = ((float) $sig_limits[7] / 16) . 'em'; |
|
| 3620 | + } elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18) { |
|
| 3621 | + $limit_broke = 'large'; |
|
| 3622 | + } |
|
| 3482 | 3623 | |
| 3483 | 3624 | if ($limit_broke) |
| 3484 | 3625 | { |
@@ -3520,24 +3661,26 @@ discard block |
||
| 3520 | 3661 | $width = -1; $height = -1; |
| 3521 | 3662 | |
| 3522 | 3663 | // Does it have predefined restraints? Width first. |
| 3523 | - if ($matches[6][$key]) |
|
| 3524 | - $matches[2][$key] = $matches[6][$key]; |
|
| 3664 | + if ($matches[6][$key]) { |
|
| 3665 | + $matches[2][$key] = $matches[6][$key]; |
|
| 3666 | + } |
|
| 3525 | 3667 | if ($matches[2][$key] && $sig_limits[5] && $matches[2][$key] > $sig_limits[5]) |
| 3526 | 3668 | { |
| 3527 | 3669 | $width = $sig_limits[5]; |
| 3528 | 3670 | $matches[4][$key] = $matches[4][$key] * ($width / $matches[2][$key]); |
| 3671 | + } elseif ($matches[2][$key]) { |
|
| 3672 | + $width = $matches[2][$key]; |
|
| 3529 | 3673 | } |
| 3530 | - elseif ($matches[2][$key]) |
|
| 3531 | - $width = $matches[2][$key]; |
|
| 3532 | 3674 | // ... and height. |
| 3533 | 3675 | if ($matches[4][$key] && $sig_limits[6] && $matches[4][$key] > $sig_limits[6]) |
| 3534 | 3676 | { |
| 3535 | 3677 | $height = $sig_limits[6]; |
| 3536 | - if ($width != -1) |
|
| 3537 | - $width = $width * ($height / $matches[4][$key]); |
|
| 3678 | + if ($width != -1) { |
|
| 3679 | + $width = $width * ($height / $matches[4][$key]); |
|
| 3680 | + } |
|
| 3681 | + } elseif ($matches[4][$key]) { |
|
| 3682 | + $height = $matches[4][$key]; |
|
| 3538 | 3683 | } |
| 3539 | - elseif ($matches[4][$key]) |
|
| 3540 | - $height = $matches[4][$key]; |
|
| 3541 | 3684 | |
| 3542 | 3685 | // If the dimensions are still not fixed - we need to check the actual image. |
| 3543 | 3686 | if (($width == -1 && $sig_limits[5]) || ($height == -1 && $sig_limits[6])) |
@@ -3555,21 +3698,24 @@ discard block |
||
| 3555 | 3698 | if ($sizes[1] > $sig_limits[6] && $sig_limits[6]) |
| 3556 | 3699 | { |
| 3557 | 3700 | $height = $sig_limits[6]; |
| 3558 | - if ($width == -1) |
|
| 3559 | - $width = $sizes[0]; |
|
| 3701 | + if ($width == -1) { |
|
| 3702 | + $width = $sizes[0]; |
|
| 3703 | + } |
|
| 3560 | 3704 | $width = $width * ($height / $sizes[1]); |
| 3705 | + } elseif ($width != -1) { |
|
| 3706 | + $height = $sizes[1]; |
|
| 3561 | 3707 | } |
| 3562 | - elseif ($width != -1) |
|
| 3563 | - $height = $sizes[1]; |
|
| 3564 | 3708 | } |
| 3565 | 3709 | } |
| 3566 | 3710 | |
| 3567 | 3711 | // Did we come up with some changes? If so remake the string. |
| 3568 | - if ($width != -1 || $height != -1) |
|
| 3569 | - $replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]'; |
|
| 3712 | + if ($width != -1 || $height != -1) { |
|
| 3713 | + $replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]'; |
|
| 3714 | + } |
|
| 3715 | + } |
|
| 3716 | + if (!empty($replaces)) { |
|
| 3717 | + $value = str_replace(array_keys($replaces), array_values($replaces), $value); |
|
| 3570 | 3718 | } |
| 3571 | - if (!empty($replaces)) |
|
| 3572 | - $value = str_replace(array_keys($replaces), array_values($replaces), $value); |
|
| 3573 | 3719 | } |
| 3574 | 3720 | } |
| 3575 | 3721 | |
@@ -3613,10 +3759,12 @@ discard block |
||
| 3613 | 3759 | $email = strtr($email, array(''' => '\'')); |
| 3614 | 3760 | |
| 3615 | 3761 | // Check the name and email for validity. |
| 3616 | - if (trim($email) == '') |
|
| 3617 | - return 'no_email'; |
|
| 3618 | - if (!filter_var($email, FILTER_VALIDATE_EMAIL)) |
|
| 3619 | - return 'bad_email'; |
|
| 3762 | + if (trim($email) == '') { |
|
| 3763 | + return 'no_email'; |
|
| 3764 | + } |
|
| 3765 | + if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { |
|
| 3766 | + return 'bad_email'; |
|
| 3767 | + } |
|
| 3620 | 3768 | |
| 3621 | 3769 | // Email addresses should be and stay unique. |
| 3622 | 3770 | $request = $smcFunc['db_query']('', ' |
@@ -3631,8 +3779,9 @@ discard block |
||
| 3631 | 3779 | ) |
| 3632 | 3780 | ); |
| 3633 | 3781 | |
| 3634 | - if ($smcFunc['db_num_rows']($request) > 0) |
|
| 3635 | - return 'email_taken'; |
|
| 3782 | + if ($smcFunc['db_num_rows']($request) > 0) { |
|
| 3783 | + return 'email_taken'; |
|
| 3784 | + } |
|
| 3636 | 3785 | $smcFunc['db_free_result']($request); |
| 3637 | 3786 | |
| 3638 | 3787 | return true; |
@@ -3645,8 +3794,9 @@ discard block |
||
| 3645 | 3794 | { |
| 3646 | 3795 | global $modSettings, $context, $cur_profile; |
| 3647 | 3796 | |
| 3648 | - if (isset($_POST['passwrd2']) && $_POST['passwrd2'] != '') |
|
| 3649 | - setLoginCookie(60 * $modSettings['cookieTime'], $context['id_member'], hash_salt($_POST['passwrd1'], $cur_profile['password_salt'])); |
|
| 3797 | + if (isset($_POST['passwrd2']) && $_POST['passwrd2'] != '') { |
|
| 3798 | + setLoginCookie(60 * $modSettings['cookieTime'], $context['id_member'], hash_salt($_POST['passwrd1'], $cur_profile['password_salt'])); |
|
| 3799 | + } |
|
| 3650 | 3800 | |
| 3651 | 3801 | loadUserSettings(); |
| 3652 | 3802 | writeLog(); |
@@ -3662,8 +3812,9 @@ discard block |
||
| 3662 | 3812 | require_once($sourcedir . '/Subs-Post.php'); |
| 3663 | 3813 | |
| 3664 | 3814 | // Shouldn't happen but just in case. |
| 3665 | - if (empty($profile_vars['email_address'])) |
|
| 3666 | - return; |
|
| 3815 | + if (empty($profile_vars['email_address'])) { |
|
| 3816 | + return; |
|
| 3817 | + } |
|
| 3667 | 3818 | |
| 3668 | 3819 | $replacements = array( |
| 3669 | 3820 | 'ACTIVATIONLINK' => $scripturl . '?action=activate;u=' . $context['id_member'] . ';code=' . $profile_vars['validation_code'], |
@@ -3686,8 +3837,9 @@ discard block |
||
| 3686 | 3837 | $_SESSION['log_time'] = 0; |
| 3687 | 3838 | $_SESSION['login_' . $cookiename] = $smcFunc['json_encode'](array(0, '', 0)); |
| 3688 | 3839 | |
| 3689 | - if (isset($_COOKIE[$cookiename])) |
|
| 3690 | - $_COOKIE[$cookiename] = ''; |
|
| 3840 | + if (isset($_COOKIE[$cookiename])) { |
|
| 3841 | + $_COOKIE[$cookiename] = ''; |
|
| 3842 | + } |
|
| 3691 | 3843 | |
| 3692 | 3844 | loadUserSettings(); |
| 3693 | 3845 | |
@@ -3720,11 +3872,13 @@ discard block |
||
| 3720 | 3872 | $groups[] = $curMember['id_group']; |
| 3721 | 3873 | |
| 3722 | 3874 | // Ensure the query doesn't croak! |
| 3723 | - if (empty($groups)) |
|
| 3724 | - $groups = array(0); |
|
| 3875 | + if (empty($groups)) { |
|
| 3876 | + $groups = array(0); |
|
| 3877 | + } |
|
| 3725 | 3878 | // Just to be sure... |
| 3726 | - foreach ($groups as $k => $v) |
|
| 3727 | - $groups[$k] = (int) $v; |
|
| 3879 | + foreach ($groups as $k => $v) { |
|
| 3880 | + $groups[$k] = (int) $v; |
|
| 3881 | + } |
|
| 3728 | 3882 | |
| 3729 | 3883 | // Get all the membergroups they can join. |
| 3730 | 3884 | $request = $smcFunc['db_query']('', ' |
@@ -3754,12 +3908,14 @@ discard block |
||
| 3754 | 3908 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 3755 | 3909 | { |
| 3756 | 3910 | // Can they edit their primary group? |
| 3757 | - if (($row['id_group'] == $context['primary_group'] && $row['group_type'] > 1) || ($row['hidden'] != 2 && $context['primary_group'] == 0 && in_array($row['id_group'], $groups))) |
|
| 3758 | - $context['can_edit_primary'] = true; |
|
| 3911 | + if (($row['id_group'] == $context['primary_group'] && $row['group_type'] > 1) || ($row['hidden'] != 2 && $context['primary_group'] == 0 && in_array($row['id_group'], $groups))) { |
|
| 3912 | + $context['can_edit_primary'] = true; |
|
| 3913 | + } |
|
| 3759 | 3914 | |
| 3760 | 3915 | // If they can't manage (protected) groups, and it's not publically joinable or already assigned, they can't see it. |
| 3761 | - if (((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) && $row['id_group'] != $context['primary_group']) |
|
| 3762 | - continue; |
|
| 3916 | + if (((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) && $row['id_group'] != $context['primary_group']) { |
|
| 3917 | + continue; |
|
| 3918 | + } |
|
| 3763 | 3919 | |
| 3764 | 3920 | $context['groups'][in_array($row['id_group'], $groups) ? 'member' : 'available'][$row['id_group']] = array( |
| 3765 | 3921 | 'id' => $row['id_group'], |
@@ -3788,13 +3944,15 @@ discard block |
||
| 3788 | 3944 | ); |
| 3789 | 3945 | |
| 3790 | 3946 | // No changing primary one unless you have enough groups! |
| 3791 | - if (count($context['groups']['member']) < 2) |
|
| 3792 | - $context['can_edit_primary'] = false; |
|
| 3947 | + if (count($context['groups']['member']) < 2) { |
|
| 3948 | + $context['can_edit_primary'] = false; |
|
| 3949 | + } |
|
| 3793 | 3950 | |
| 3794 | 3951 | // In the special case that someone is requesting membership of a group, setup some special context vars. |
| 3795 | - if (isset($_REQUEST['request']) && isset($context['groups']['available'][(int) $_REQUEST['request']]) && $context['groups']['available'][(int) $_REQUEST['request']]['type'] == 2) |
|
| 3796 | - $context['group_request'] = $context['groups']['available'][(int) $_REQUEST['request']]; |
|
| 3797 | -} |
|
| 3952 | + if (isset($_REQUEST['request']) && isset($context['groups']['available'][(int) $_REQUEST['request']]) && $context['groups']['available'][(int) $_REQUEST['request']]['type'] == 2) { |
|
| 3953 | + $context['group_request'] = $context['groups']['available'][(int) $_REQUEST['request']]; |
|
| 3954 | + } |
|
| 3955 | + } |
|
| 3798 | 3956 | |
| 3799 | 3957 | /** |
| 3800 | 3958 | * This function actually makes all the group changes |
@@ -3809,10 +3967,12 @@ discard block |
||
| 3809 | 3967 | global $user_info, $context, $user_profile, $modSettings, $smcFunc; |
| 3810 | 3968 | |
| 3811 | 3969 | // Let's be extra cautious... |
| 3812 | - if (!$context['user']['is_owner'] || empty($modSettings['show_group_membership'])) |
|
| 3813 | - isAllowedTo('manage_membergroups'); |
|
| 3814 | - if (!isset($_REQUEST['gid']) && !isset($_POST['primary'])) |
|
| 3815 | - fatal_lang_error('no_access', false); |
|
| 3970 | + if (!$context['user']['is_owner'] || empty($modSettings['show_group_membership'])) { |
|
| 3971 | + isAllowedTo('manage_membergroups'); |
|
| 3972 | + } |
|
| 3973 | + if (!isset($_REQUEST['gid']) && !isset($_POST['primary'])) { |
|
| 3974 | + fatal_lang_error('no_access', false); |
|
| 3975 | + } |
|
| 3816 | 3976 | |
| 3817 | 3977 | checkSession(isset($_GET['gid']) ? 'get' : 'post'); |
| 3818 | 3978 | |
@@ -3831,8 +3991,9 @@ discard block |
||
| 3831 | 3991 | $foundTarget = $changeType == 'primary' && $group_id == 0 ? true : false; |
| 3832 | 3992 | |
| 3833 | 3993 | // Sanity check!! |
| 3834 | - if ($group_id == 1) |
|
| 3835 | - isAllowedTo('admin_forum'); |
|
| 3994 | + if ($group_id == 1) { |
|
| 3995 | + isAllowedTo('admin_forum'); |
|
| 3996 | + } |
|
| 3836 | 3997 | // Protected groups too! |
| 3837 | 3998 | else |
| 3838 | 3999 | { |
@@ -3849,8 +4010,9 @@ discard block |
||
| 3849 | 4010 | list ($is_protected) = $smcFunc['db_fetch_row']($request); |
| 3850 | 4011 | $smcFunc['db_free_result']($request); |
| 3851 | 4012 | |
| 3852 | - if ($is_protected == 1) |
|
| 3853 | - isAllowedTo('admin_forum'); |
|
| 4013 | + if ($is_protected == 1) { |
|
| 4014 | + isAllowedTo('admin_forum'); |
|
| 4015 | + } |
|
| 3854 | 4016 | } |
| 3855 | 4017 | |
| 3856 | 4018 | // What ever we are doing, we need to determine if changing primary is possible! |
@@ -3872,36 +4034,43 @@ discard block |
||
| 3872 | 4034 | $group_name = $row['group_name']; |
| 3873 | 4035 | |
| 3874 | 4036 | // Does the group type match what we're doing - are we trying to request a non-requestable group? |
| 3875 | - if ($changeType == 'request' && $row['group_type'] != 2) |
|
| 3876 | - fatal_lang_error('no_access', false); |
|
| 4037 | + if ($changeType == 'request' && $row['group_type'] != 2) { |
|
| 4038 | + fatal_lang_error('no_access', false); |
|
| 4039 | + } |
|
| 3877 | 4040 | // What about leaving a requestable group we are not a member of? |
| 3878 | - elseif ($changeType == 'free' && $row['group_type'] == 2 && $old_profile['id_group'] != $row['id_group'] && !isset($addGroups[$row['id_group']])) |
|
| 3879 | - fatal_lang_error('no_access', false); |
|
| 3880 | - elseif ($changeType == 'free' && $row['group_type'] != 3 && $row['group_type'] != 2) |
|
| 3881 | - fatal_lang_error('no_access', false); |
|
| 4041 | + elseif ($changeType == 'free' && $row['group_type'] == 2 && $old_profile['id_group'] != $row['id_group'] && !isset($addGroups[$row['id_group']])) { |
|
| 4042 | + fatal_lang_error('no_access', false); |
|
| 4043 | + } elseif ($changeType == 'free' && $row['group_type'] != 3 && $row['group_type'] != 2) { |
|
| 4044 | + fatal_lang_error('no_access', false); |
|
| 4045 | + } |
|
| 3882 | 4046 | |
| 3883 | 4047 | // We can't change the primary group if this is hidden! |
| 3884 | - if ($row['hidden'] == 2) |
|
| 3885 | - $canChangePrimary = false; |
|
| 4048 | + if ($row['hidden'] == 2) { |
|
| 4049 | + $canChangePrimary = false; |
|
| 4050 | + } |
|
| 3886 | 4051 | } |
| 3887 | 4052 | |
| 3888 | 4053 | // If this is their old primary, can we change it? |
| 3889 | - if ($row['id_group'] == $old_profile['id_group'] && ($row['group_type'] > 1 || $context['can_manage_membergroups']) && $canChangePrimary !== false) |
|
| 3890 | - $canChangePrimary = 1; |
|
| 4054 | + if ($row['id_group'] == $old_profile['id_group'] && ($row['group_type'] > 1 || $context['can_manage_membergroups']) && $canChangePrimary !== false) { |
|
| 4055 | + $canChangePrimary = 1; |
|
| 4056 | + } |
|
| 3891 | 4057 | |
| 3892 | 4058 | // If we are not doing a force primary move, don't do it automatically if current primary is not 0. |
| 3893 | - if ($changeType != 'primary' && $old_profile['id_group'] != 0) |
|
| 3894 | - $canChangePrimary = false; |
|
| 4059 | + if ($changeType != 'primary' && $old_profile['id_group'] != 0) { |
|
| 4060 | + $canChangePrimary = false; |
|
| 4061 | + } |
|
| 3895 | 4062 | |
| 3896 | 4063 | // If this is the one we are acting on, can we even act? |
| 3897 | - if ((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) |
|
| 3898 | - $canChangePrimary = false; |
|
| 4064 | + if ((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) { |
|
| 4065 | + $canChangePrimary = false; |
|
| 4066 | + } |
|
| 3899 | 4067 | } |
| 3900 | 4068 | $smcFunc['db_free_result']($request); |
| 3901 | 4069 | |
| 3902 | 4070 | // Didn't find the target? |
| 3903 | - if (!$foundTarget) |
|
| 3904 | - fatal_lang_error('no_access', false); |
|
| 4071 | + if (!$foundTarget) { |
|
| 4072 | + fatal_lang_error('no_access', false); |
|
| 4073 | + } |
|
| 3905 | 4074 | |
| 3906 | 4075 | // Final security check, don't allow users to promote themselves to admin. |
| 3907 | 4076 | if ($context['can_manage_membergroups'] && !allowedTo('admin_forum')) |
@@ -3921,8 +4090,9 @@ discard block |
||
| 3921 | 4090 | list ($disallow) = $smcFunc['db_fetch_row']($request); |
| 3922 | 4091 | $smcFunc['db_free_result']($request); |
| 3923 | 4092 | |
| 3924 | - if ($disallow) |
|
| 3925 | - isAllowedTo('admin_forum'); |
|
| 4093 | + if ($disallow) { |
|
| 4094 | + isAllowedTo('admin_forum'); |
|
| 4095 | + } |
|
| 3926 | 4096 | } |
| 3927 | 4097 | |
| 3928 | 4098 | // If we're requesting, add the note then return. |
@@ -3940,8 +4110,9 @@ discard block |
||
| 3940 | 4110 | 'status_open' => 0, |
| 3941 | 4111 | ) |
| 3942 | 4112 | ); |
| 3943 | - if ($smcFunc['db_num_rows']($request) != 0) |
|
| 3944 | - fatal_lang_error('profile_error_already_requested_group'); |
|
| 4113 | + if ($smcFunc['db_num_rows']($request) != 0) { |
|
| 4114 | + fatal_lang_error('profile_error_already_requested_group'); |
|
| 4115 | + } |
|
| 3945 | 4116 | $smcFunc['db_free_result']($request); |
| 3946 | 4117 | |
| 3947 | 4118 | // Log the request. |
@@ -3975,10 +4146,11 @@ discard block |
||
| 3975 | 4146 | // Are we leaving? |
| 3976 | 4147 | if ($old_profile['id_group'] == $group_id || isset($addGroups[$group_id])) |
| 3977 | 4148 | { |
| 3978 | - if ($old_profile['id_group'] == $group_id) |
|
| 3979 | - $newPrimary = 0; |
|
| 3980 | - else |
|
| 3981 | - unset($addGroups[$group_id]); |
|
| 4149 | + if ($old_profile['id_group'] == $group_id) { |
|
| 4150 | + $newPrimary = 0; |
|
| 4151 | + } else { |
|
| 4152 | + unset($addGroups[$group_id]); |
|
| 4153 | + } |
|
| 3982 | 4154 | } |
| 3983 | 4155 | // ... if not, must be joining. |
| 3984 | 4156 | else |
@@ -3986,36 +4158,42 @@ discard block |
||
| 3986 | 4158 | // Can we change the primary, and do we want to? |
| 3987 | 4159 | if ($canChangePrimary) |
| 3988 | 4160 | { |
| 3989 | - if ($old_profile['id_group'] != 0) |
|
| 3990 | - $addGroups[$old_profile['id_group']] = -1; |
|
| 4161 | + if ($old_profile['id_group'] != 0) { |
|
| 4162 | + $addGroups[$old_profile['id_group']] = -1; |
|
| 4163 | + } |
|
| 3991 | 4164 | $newPrimary = $group_id; |
| 3992 | 4165 | } |
| 3993 | 4166 | // Otherwise it's an additional group... |
| 3994 | - else |
|
| 3995 | - $addGroups[$group_id] = -1; |
|
| 4167 | + else { |
|
| 4168 | + $addGroups[$group_id] = -1; |
|
| 4169 | + } |
|
| 3996 | 4170 | } |
| 3997 | 4171 | } |
| 3998 | 4172 | // Finally, we must be setting the primary. |
| 3999 | 4173 | elseif ($canChangePrimary) |
| 4000 | 4174 | { |
| 4001 | - if ($old_profile['id_group'] != 0) |
|
| 4002 | - $addGroups[$old_profile['id_group']] = -1; |
|
| 4003 | - if (isset($addGroups[$group_id])) |
|
| 4004 | - unset($addGroups[$group_id]); |
|
| 4175 | + if ($old_profile['id_group'] != 0) { |
|
| 4176 | + $addGroups[$old_profile['id_group']] = -1; |
|
| 4177 | + } |
|
| 4178 | + if (isset($addGroups[$group_id])) { |
|
| 4179 | + unset($addGroups[$group_id]); |
|
| 4180 | + } |
|
| 4005 | 4181 | $newPrimary = $group_id; |
| 4006 | 4182 | } |
| 4007 | 4183 | |
| 4008 | 4184 | // Finally, we can make the changes! |
| 4009 | - foreach ($addGroups as $id => $dummy) |
|
| 4010 | - if (empty($id)) |
|
| 4185 | + foreach ($addGroups as $id => $dummy) { |
|
| 4186 | + if (empty($id)) |
|
| 4011 | 4187 | unset($addGroups[$id]); |
| 4188 | + } |
|
| 4012 | 4189 | $addGroups = implode(',', array_flip($addGroups)); |
| 4013 | 4190 | |
| 4014 | 4191 | // Ensure that we don't cache permissions if the group is changing. |
| 4015 | - if ($context['user']['is_owner']) |
|
| 4016 | - $_SESSION['mc']['time'] = 0; |
|
| 4017 | - else |
|
| 4018 | - updateSettings(array('settings_updated' => time())); |
|
| 4192 | + if ($context['user']['is_owner']) { |
|
| 4193 | + $_SESSION['mc']['time'] = 0; |
|
| 4194 | + } else { |
|
| 4195 | + updateSettings(array('settings_updated' => time())); |
|
| 4196 | + } |
|
| 4019 | 4197 | |
| 4020 | 4198 | updateMemberData($memID, array('id_group' => $newPrimary, 'additional_groups' => $addGroups)); |
| 4021 | 4199 | |
@@ -4038,8 +4216,9 @@ discard block |
||
| 4038 | 4216 | if (empty($user_settings['tfa_secret']) && $context['user']['is_owner']) |
| 4039 | 4217 | { |
| 4040 | 4218 | // Check to ensure we're forcing SSL for authentication |
| 4041 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) |
|
| 4042 | - fatal_lang_error('login_ssl_required'); |
|
| 4219 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) { |
|
| 4220 | + fatal_lang_error('login_ssl_required'); |
|
| 4221 | + } |
|
| 4043 | 4222 | |
| 4044 | 4223 | // In some cases (forced 2FA or backup code) they would be forced to be redirected here, |
| 4045 | 4224 | // we do not want too much AJAX to confuse them. |
@@ -4076,8 +4255,7 @@ discard block |
||
| 4076 | 4255 | $context['sub_template'] = 'tfasetup_backup'; |
| 4077 | 4256 | |
| 4078 | 4257 | return; |
| 4079 | - } |
|
| 4080 | - else |
|
| 4258 | + } else |
|
| 4081 | 4259 | { |
| 4082 | 4260 | $context['tfa_secret'] = $_SESSION['tfa_secret']; |
| 4083 | 4261 | $context['tfa_error'] = !$valid_code; |
@@ -4085,8 +4263,7 @@ discard block |
||
| 4085 | 4263 | $context['tfa_pass_value'] = $_POST['passwd']; |
| 4086 | 4264 | $context['tfa_value'] = $_POST['tfa_code']; |
| 4087 | 4265 | } |
| 4088 | - } |
|
| 4089 | - else |
|
| 4266 | + } else |
|
| 4090 | 4267 | { |
| 4091 | 4268 | $totp = new \TOTP\Auth(); |
| 4092 | 4269 | $secret = $totp->generateCode(); |
@@ -4096,17 +4273,16 @@ discard block |
||
| 4096 | 4273 | } |
| 4097 | 4274 | |
| 4098 | 4275 | $context['tfa_qr_url'] = $totp->getQrCodeUrl($context['forum_name'] . ':' . $user_info['name'], $context['tfa_secret']); |
| 4099 | - } |
|
| 4100 | - elseif (isset($_REQUEST['disable'])) |
|
| 4276 | + } elseif (isset($_REQUEST['disable'])) |
|
| 4101 | 4277 | { |
| 4102 | 4278 | updateMemberData($memID, array( |
| 4103 | 4279 | 'tfa_secret' => '', |
| 4104 | 4280 | 'tfa_backup' => '', |
| 4105 | 4281 | )); |
| 4106 | 4282 | redirectexit('action=profile;area=account;u=' . $memID); |
| 4283 | + } else { |
|
| 4284 | + redirectexit('action=profile;area=account;u=' . $memID); |
|
| 4285 | + } |
|
| 4107 | 4286 | } |
| 4108 | - else |
|
| 4109 | - redirectexit('action=profile;area=account;u=' . $memID); |
|
| 4110 | -} |
|
| 4111 | 4287 | |
| 4112 | 4288 | ?> |
| 4113 | 4289 | \ No newline at end of file |
@@ -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 | * Load the $modSettings array. |
@@ -25,13 +26,14 @@ discard block |
||
| 25 | 26 | global $cache_enable, $sourcedir, $context; |
| 26 | 27 | |
| 27 | 28 | // Most database systems have not set UTF-8 as their default input charset. |
| 28 | - if (!empty($db_character_set)) |
|
| 29 | - $smcFunc['db_query']('', ' |
|
| 29 | + if (!empty($db_character_set)) { |
|
| 30 | + $smcFunc['db_query']('', ' |
|
| 30 | 31 | SET NAMES {string:db_character_set}', |
| 31 | 32 | array( |
| 32 | 33 | 'db_character_set' => $db_character_set, |
| 33 | 34 | ) |
| 34 | 35 | ); |
| 36 | + } |
|
| 35 | 37 | |
| 36 | 38 | // We need some caching support, maybe. |
| 37 | 39 | loadCacheAccelerator(); |
@@ -46,28 +48,36 @@ discard block |
||
| 46 | 48 | ) |
| 47 | 49 | ); |
| 48 | 50 | $modSettings = array(); |
| 49 | - if (!$request) |
|
| 50 | - display_db_error(); |
|
| 51 | - while ($row = $smcFunc['db_fetch_row']($request)) |
|
| 52 | - $modSettings[$row[0]] = $row[1]; |
|
| 51 | + if (!$request) { |
|
| 52 | + display_db_error(); |
|
| 53 | + } |
|
| 54 | + while ($row = $smcFunc['db_fetch_row']($request)) { |
|
| 55 | + $modSettings[$row[0]] = $row[1]; |
|
| 56 | + } |
|
| 53 | 57 | $smcFunc['db_free_result']($request); |
| 54 | 58 | |
| 55 | 59 | // Do a few things to protect against missing settings or settings with invalid values... |
| 56 | - if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999) |
|
| 57 | - $modSettings['defaultMaxTopics'] = 20; |
|
| 58 | - if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999) |
|
| 59 | - $modSettings['defaultMaxMessages'] = 15; |
|
| 60 | - if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999) |
|
| 61 | - $modSettings['defaultMaxMembers'] = 30; |
|
| 62 | - if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999) |
|
| 63 | - $modSettings['defaultMaxListItems'] = 15; |
|
| 60 | + if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999) { |
|
| 61 | + $modSettings['defaultMaxTopics'] = 20; |
|
| 62 | + } |
|
| 63 | + if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999) { |
|
| 64 | + $modSettings['defaultMaxMessages'] = 15; |
|
| 65 | + } |
|
| 66 | + if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999) { |
|
| 67 | + $modSettings['defaultMaxMembers'] = 30; |
|
| 68 | + } |
|
| 69 | + if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999) { |
|
| 70 | + $modSettings['defaultMaxListItems'] = 15; |
|
| 71 | + } |
|
| 64 | 72 | |
| 65 | 73 | // We excpiclity do not use $smcFunc['json_decode'] here yet, as $smcFunc is not fully loaded. |
| 66 | - if (!is_array($modSettings['attachmentUploadDir'])) |
|
| 67 | - $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
| 74 | + if (!is_array($modSettings['attachmentUploadDir'])) { |
|
| 75 | + $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
| 76 | + } |
|
| 68 | 77 | |
| 69 | - if (!empty($cache_enable)) |
|
| 70 | - cache_put_data('modSettings', $modSettings, 90); |
|
| 78 | + if (!empty($cache_enable)) { |
|
| 79 | + cache_put_data('modSettings', $modSettings, 90); |
|
| 80 | + } |
|
| 71 | 81 | } |
| 72 | 82 | |
| 73 | 83 | $modSettings['cache_enable'] = $cache_enable; |
@@ -87,8 +97,9 @@ discard block |
||
| 87 | 97 | }; |
| 88 | 98 | $fix_utf8mb4 = function($string) use ($utf8, $smcFunc) |
| 89 | 99 | { |
| 90 | - if (!$utf8 || $smcFunc['db_mb4']) |
|
| 91 | - return $string; |
|
| 100 | + if (!$utf8 || $smcFunc['db_mb4']) { |
|
| 101 | + return $string; |
|
| 102 | + } |
|
| 92 | 103 | |
| 93 | 104 | $i = 0; |
| 94 | 105 | $len = strlen($string); |
@@ -100,18 +111,15 @@ discard block |
||
| 100 | 111 | { |
| 101 | 112 | $new_string .= $string[$i]; |
| 102 | 113 | $i++; |
| 103 | - } |
|
| 104 | - elseif ($ord < 224) |
|
| 114 | + } elseif ($ord < 224) |
|
| 105 | 115 | { |
| 106 | 116 | $new_string .= $string[$i] . $string[$i + 1]; |
| 107 | 117 | $i += 2; |
| 108 | - } |
|
| 109 | - elseif ($ord < 240) |
|
| 118 | + } elseif ($ord < 240) |
|
| 110 | 119 | { |
| 111 | 120 | $new_string .= $string[$i] . $string[$i + 1] . $string[$i + 2]; |
| 112 | 121 | $i += 3; |
| 113 | - } |
|
| 114 | - elseif ($ord < 248) |
|
| 122 | + } elseif ($ord < 248) |
|
| 115 | 123 | { |
| 116 | 124 | // Magic happens. |
| 117 | 125 | $val = (ord($string[$i]) & 0x07) << 18; |
@@ -155,8 +163,7 @@ discard block |
||
| 155 | 163 | { |
| 156 | 164 | $result = array_search($needle, array_slice($haystack_arr, $offset)); |
| 157 | 165 | return is_int($result) ? $result + $offset : false; |
| 158 | - } |
|
| 159 | - else |
|
| 166 | + } else |
|
| 160 | 167 | { |
| 161 | 168 | $needle_arr = preg_split('~(&#' . (empty($modSettings['disableEntityCheck']) ? '\d{1,7}' : '021') . ';|"|&|<|>| |.)~' . ($utf8 ? 'u' : '') . '', $ent_check($needle), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); |
| 162 | 169 | $needle_size = count($needle_arr); |
@@ -165,8 +172,9 @@ discard block |
||
| 165 | 172 | while ((int) $result === $result) |
| 166 | 173 | { |
| 167 | 174 | $offset += $result; |
| 168 | - if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) |
|
| 169 | - return $offset; |
|
| 175 | + if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) { |
|
| 176 | + return $offset; |
|
| 177 | + } |
|
| 170 | 178 | $result = array_search($needle_arr[0], array_slice($haystack_arr, ++$offset)); |
| 171 | 179 | } |
| 172 | 180 | return false; |
@@ -204,8 +212,9 @@ discard block |
||
| 204 | 212 | $string = $ent_check($string); |
| 205 | 213 | preg_match('~^(' . $ent_list . '|.){' . $smcFunc['strlen'](substr($string, 0, $length)) . '}~' . ($utf8 ? 'u' : ''), $string, $matches); |
| 206 | 214 | $string = $matches[0]; |
| 207 | - while (strlen($string) > $length) |
|
| 208 | - $string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string); |
|
| 215 | + while (strlen($string) > $length) { |
|
| 216 | + $string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string); |
|
| 217 | + } |
|
| 209 | 218 | return $string; |
| 210 | 219 | }, |
| 211 | 220 | 'ucfirst' => $utf8 ? function($string) use (&$smcFunc) |
@@ -215,8 +224,9 @@ discard block |
||
| 215 | 224 | 'ucwords' => $utf8 ? function($string) use (&$smcFunc) |
| 216 | 225 | { |
| 217 | 226 | $words = preg_split('~([\s\r\n\t]+)~', $string, -1, PREG_SPLIT_DELIM_CAPTURE); |
| 218 | - for ($i = 0, $n = count($words); $i < $n; $i += 2) |
|
| 219 | - $words[$i] = $smcFunc['ucfirst']($words[$i]); |
|
| 227 | + for ($i = 0, $n = count($words); $i < $n; $i += 2) { |
|
| 228 | + $words[$i] = $smcFunc['ucfirst']($words[$i]); |
|
| 229 | + } |
|
| 220 | 230 | return implode('', $words); |
| 221 | 231 | } : 'ucwords', |
| 222 | 232 | 'json_decode' => 'smf_json_decode', |
@@ -224,16 +234,17 @@ discard block |
||
| 224 | 234 | ); |
| 225 | 235 | |
| 226 | 236 | // Setting the timezone is a requirement for some functions. |
| 227 | - if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list())) |
|
| 228 | - date_default_timezone_set($modSettings['default_timezone']); |
|
| 229 | - else |
|
| 237 | + if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list())) { |
|
| 238 | + date_default_timezone_set($modSettings['default_timezone']); |
|
| 239 | + } else |
|
| 230 | 240 | { |
| 231 | 241 | // Get PHP's default timezone, if set |
| 232 | 242 | $ini_tz = ini_get('date.timezone'); |
| 233 | - if (!empty($ini_tz)) |
|
| 234 | - $modSettings['default_timezone'] = $ini_tz; |
|
| 235 | - else |
|
| 236 | - $modSettings['default_timezone'] = ''; |
|
| 243 | + if (!empty($ini_tz)) { |
|
| 244 | + $modSettings['default_timezone'] = $ini_tz; |
|
| 245 | + } else { |
|
| 246 | + $modSettings['default_timezone'] = ''; |
|
| 247 | + } |
|
| 237 | 248 | |
| 238 | 249 | // If date.timezone is unset, invalid, or just plain weird, make a best guess |
| 239 | 250 | if (!in_array($modSettings['default_timezone'], timezone_identifiers_list())) |
@@ -251,22 +262,26 @@ discard block |
||
| 251 | 262 | if (($modSettings['load_average'] = cache_get_data('loadavg', 90)) == null) |
| 252 | 263 | { |
| 253 | 264 | $modSettings['load_average'] = @file_get_contents('/proc/loadavg'); |
| 254 | - if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) |
|
| 255 | - $modSettings['load_average'] = (float) $matches[1]; |
|
| 256 | - elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) |
|
| 257 | - $modSettings['load_average'] = (float) $matches[1]; |
|
| 258 | - else |
|
| 259 | - unset($modSettings['load_average']); |
|
| 265 | + if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) { |
|
| 266 | + $modSettings['load_average'] = (float) $matches[1]; |
|
| 267 | + } elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) { |
|
| 268 | + $modSettings['load_average'] = (float) $matches[1]; |
|
| 269 | + } else { |
|
| 270 | + unset($modSettings['load_average']); |
|
| 271 | + } |
|
| 260 | 272 | |
| 261 | - if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) |
|
| 262 | - cache_put_data('loadavg', $modSettings['load_average'], 90); |
|
| 273 | + if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) { |
|
| 274 | + cache_put_data('loadavg', $modSettings['load_average'], 90); |
|
| 275 | + } |
|
| 263 | 276 | } |
| 264 | 277 | |
| 265 | - if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) |
|
| 266 | - call_integration_hook('integrate_load_average', array($modSettings['load_average'])); |
|
| 278 | + if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) { |
|
| 279 | + call_integration_hook('integrate_load_average', array($modSettings['load_average'])); |
|
| 280 | + } |
|
| 267 | 281 | |
| 268 | - if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) |
|
| 269 | - display_loadavg_error(); |
|
| 282 | + if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) { |
|
| 283 | + display_loadavg_error(); |
|
| 284 | + } |
|
| 270 | 285 | } |
| 271 | 286 | |
| 272 | 287 | // Is post moderation alive and well? Everywhere else assumes this has been defined, so let's make sure it is. |
@@ -287,8 +302,9 @@ discard block |
||
| 287 | 302 | if (defined('SMF_INTEGRATION_SETTINGS')) |
| 288 | 303 | { |
| 289 | 304 | $integration_settings = $smcFunc['json_decode'](SMF_INTEGRATION_SETTINGS, true); |
| 290 | - foreach ($integration_settings as $hook => $function) |
|
| 291 | - add_integration_function($hook, $function, '', false); |
|
| 305 | + foreach ($integration_settings as $hook => $function) { |
|
| 306 | + add_integration_function($hook, $function, '', false); |
|
| 307 | + } |
|
| 292 | 308 | } |
| 293 | 309 | |
| 294 | 310 | // Any files to pre include? |
@@ -298,8 +314,9 @@ discard block |
||
| 298 | 314 | foreach ($pre_includes as $include) |
| 299 | 315 | { |
| 300 | 316 | $include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
| 301 | - if (file_exists($include)) |
|
| 302 | - require_once($include); |
|
| 317 | + if (file_exists($include)) { |
|
| 318 | + require_once($include); |
|
| 319 | + } |
|
| 303 | 320 | } |
| 304 | 321 | } |
| 305 | 322 | |
@@ -405,27 +422,28 @@ discard block |
||
| 405 | 422 | break; |
| 406 | 423 | } |
| 407 | 424 | } |
| 425 | + } else { |
|
| 426 | + $id_member = 0; |
|
| 408 | 427 | } |
| 409 | - else |
|
| 410 | - $id_member = 0; |
|
| 411 | 428 | |
| 412 | 429 | if (empty($id_member) && isset($_COOKIE[$cookiename])) |
| 413 | 430 | { |
| 414 | 431 | $cookie_data = $smcFunc['json_decode']($_COOKIE[$cookiename], true, false); |
| 415 | 432 | |
| 416 | - if (empty($cookie_data)) |
|
| 417 | - $cookie_data = safe_unserialize($_COOKIE[$cookiename]); |
|
| 433 | + if (empty($cookie_data)) { |
|
| 434 | + $cookie_data = safe_unserialize($_COOKIE[$cookiename]); |
|
| 435 | + } |
|
| 418 | 436 | |
| 419 | 437 | list ($id_member, $password) = $cookie_data; |
| 420 | 438 | $id_member = !empty($id_member) && strlen($password) > 0 ? (int) $id_member : 0; |
| 421 | - } |
|
| 422 | - elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA']))) |
|
| 439 | + } elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA']))) |
|
| 423 | 440 | { |
| 424 | 441 | // @todo Perhaps we can do some more checking on this, such as on the first octet of the IP? |
| 425 | 442 | $cookie_data = $smcFunc['json_decode']($_SESSION['login_' . $cookiename]); |
| 426 | 443 | |
| 427 | - if (empty($cookie_data)) |
|
| 428 | - $cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]); |
|
| 444 | + if (empty($cookie_data)) { |
|
| 445 | + $cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]); |
|
| 446 | + } |
|
| 429 | 447 | |
| 430 | 448 | list ($id_member, $password, $login_span) = $cookie_data; |
| 431 | 449 | $id_member = !empty($id_member) && strlen($password) == 128 && $login_span > time() ? (int) $id_member : 0; |
@@ -450,30 +468,34 @@ discard block |
||
| 450 | 468 | $user_settings = $smcFunc['db_fetch_assoc']($request); |
| 451 | 469 | $smcFunc['db_free_result']($request); |
| 452 | 470 | |
| 453 | - if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false) |
|
| 454 | - $user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret); |
|
| 471 | + if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false) { |
|
| 472 | + $user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret); |
|
| 473 | + } |
|
| 455 | 474 | |
| 456 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
| 457 | - cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
| 475 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
| 476 | + cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
| 477 | + } |
|
| 458 | 478 | } |
| 459 | 479 | |
| 460 | 480 | // Did we find 'im? If not, junk it. |
| 461 | 481 | if (!empty($user_settings)) |
| 462 | 482 | { |
| 463 | 483 | // As much as the password should be right, we can assume the integration set things up. |
| 464 | - if (!empty($already_verified) && $already_verified === true) |
|
| 465 | - $check = true; |
|
| 484 | + if (!empty($already_verified) && $already_verified === true) { |
|
| 485 | + $check = true; |
|
| 486 | + } |
|
| 466 | 487 | // SHA-512 hash should be 128 characters long. |
| 467 | - elseif (strlen($password) == 128) |
|
| 468 | - $check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password; |
|
| 469 | - else |
|
| 470 | - $check = false; |
|
| 488 | + elseif (strlen($password) == 128) { |
|
| 489 | + $check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password; |
|
| 490 | + } else { |
|
| 491 | + $check = false; |
|
| 492 | + } |
|
| 471 | 493 | |
| 472 | 494 | // Wrong password or not activated - either way, you're going nowhere. |
| 473 | 495 | $id_member = $check && ($user_settings['is_activated'] == 1 || $user_settings['is_activated'] == 11) ? (int) $user_settings['id_member'] : 0; |
| 496 | + } else { |
|
| 497 | + $id_member = 0; |
|
| 474 | 498 | } |
| 475 | - else |
|
| 476 | - $id_member = 0; |
|
| 477 | 499 | |
| 478 | 500 | // If we no longer have the member maybe they're being all hackey, stop brute force! |
| 479 | 501 | if (!$id_member) |
@@ -502,8 +524,9 @@ discard block |
||
| 502 | 524 | |
| 503 | 525 | list ($tfamember, $tfasecret) = $tfa_data; |
| 504 | 526 | |
| 505 | - if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member) |
|
| 506 | - $tfasecret = null; |
|
| 527 | + if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member) { |
|
| 528 | + $tfasecret = null; |
|
| 529 | + } |
|
| 507 | 530 | } |
| 508 | 531 | |
| 509 | 532 | if (empty($tfasecret) || hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']) != $tfasecret) |
@@ -523,10 +546,12 @@ discard block |
||
| 523 | 546 | // Are we forcing 2FA? Need to check if the user groups actually require 2FA |
| 524 | 547 | elseif (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] >= 2 && $id_member && empty($user_settings['tfa_secret'])) |
| 525 | 548 | { |
| 526 | - if ($modSettings['tfa_mode'] == 2) //only do this if we are just forcing SOME membergroups |
|
| 549 | + if ($modSettings['tfa_mode'] == 2) { |
|
| 550 | + //only do this if we are just forcing SOME membergroups |
|
| 527 | 551 | { |
| 528 | 552 | //Build an array of ALL user membergroups. |
| 529 | 553 | $full_groups = array($user_settings['id_group']); |
| 554 | + } |
|
| 530 | 555 | if (!empty($user_settings['additional_groups'])) |
| 531 | 556 | { |
| 532 | 557 | $full_groups = array_merge($full_groups, explode(',', $user_settings['additional_groups'])); |
@@ -546,15 +571,17 @@ discard block |
||
| 546 | 571 | ); |
| 547 | 572 | $row = $smcFunc['db_fetch_assoc']($request); |
| 548 | 573 | $smcFunc['db_free_result']($request); |
| 574 | + } else { |
|
| 575 | + $row['total'] = 1; |
|
| 549 | 576 | } |
| 550 | - else |
|
| 551 | - $row['total'] = 1; //simplifies logics in the next "if" |
|
| 577 | + //simplifies logics in the next "if" |
|
| 552 | 578 | |
| 553 | 579 | $area = !empty($_REQUEST['area']) ? $_REQUEST['area'] : ''; |
| 554 | 580 | $action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : ''; |
| 555 | 581 | |
| 556 | - if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) |
|
| 557 | - redirectexit('action=profile;area=tfasetup;forced'); |
|
| 582 | + if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) { |
|
| 583 | + redirectexit('action=profile;area=tfasetup;forced'); |
|
| 584 | + } |
|
| 558 | 585 | } |
| 559 | 586 | } |
| 560 | 587 | |
@@ -591,33 +618,37 @@ discard block |
||
| 591 | 618 | updateMemberData($id_member, array('id_msg_last_visit' => (int) $modSettings['maxMsgID'], 'last_login' => time(), 'member_ip' => $_SERVER['REMOTE_ADDR'], 'member_ip2' => $_SERVER['BAN_CHECK_IP'])); |
| 592 | 619 | $user_settings['last_login'] = time(); |
| 593 | 620 | |
| 594 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
| 595 | - cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
| 621 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
| 622 | + cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
| 623 | + } |
|
| 596 | 624 | |
| 597 | - if (!empty($modSettings['cache_enable'])) |
|
| 598 | - cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600); |
|
| 625 | + if (!empty($modSettings['cache_enable'])) { |
|
| 626 | + cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600); |
|
| 627 | + } |
|
| 599 | 628 | } |
| 629 | + } elseif (empty($_SESSION['id_msg_last_visit'])) { |
|
| 630 | + $_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit']; |
|
| 600 | 631 | } |
| 601 | - elseif (empty($_SESSION['id_msg_last_visit'])) |
|
| 602 | - $_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit']; |
|
| 603 | 632 | |
| 604 | 633 | $username = $user_settings['member_name']; |
| 605 | 634 | |
| 606 | - if (empty($user_settings['additional_groups'])) |
|
| 607 | - $user_info = array( |
|
| 635 | + if (empty($user_settings['additional_groups'])) { |
|
| 636 | + $user_info = array( |
|
| 608 | 637 | 'groups' => array($user_settings['id_group'], $user_settings['id_post_group']) |
| 609 | 638 | ); |
| 610 | - else |
|
| 611 | - $user_info = array( |
|
| 639 | + } else { |
|
| 640 | + $user_info = array( |
|
| 612 | 641 | 'groups' => array_merge( |
| 613 | 642 | array($user_settings['id_group'], $user_settings['id_post_group']), |
| 614 | 643 | explode(',', $user_settings['additional_groups']) |
| 615 | 644 | ) |
| 616 | 645 | ); |
| 646 | + } |
|
| 617 | 647 | |
| 618 | 648 | // Because history has proven that it is possible for groups to go bad - clean up in case. |
| 619 | - foreach ($user_info['groups'] as $k => $v) |
|
| 620 | - $user_info['groups'][$k] = (int) $v; |
|
| 649 | + foreach ($user_info['groups'] as $k => $v) { |
|
| 650 | + $user_info['groups'][$k] = (int) $v; |
|
| 651 | + } |
|
| 621 | 652 | |
| 622 | 653 | // This is a logged in user, so definitely not a spider. |
| 623 | 654 | $user_info['possibly_robot'] = false; |
@@ -631,8 +662,7 @@ discard block |
||
| 631 | 662 | $time_system = new DateTime('now', $tz_system); |
| 632 | 663 | $time_user = new DateTime('now', $tz_user); |
| 633 | 664 | $user_info['time_offset'] = ($tz_user->getOffset($time_user) - $tz_system->getOffset($time_system)) / 3600; |
| 634 | - } |
|
| 635 | - else |
|
| 665 | + } else |
|
| 636 | 666 | { |
| 637 | 667 | // !!! Compatibility. |
| 638 | 668 | $user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 : $user_settings['time_offset']; |
@@ -646,8 +676,9 @@ discard block |
||
| 646 | 676 | $user_info = array('groups' => array(-1)); |
| 647 | 677 | $user_settings = array(); |
| 648 | 678 | |
| 649 | - if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) |
|
| 650 | - $_COOKIE[$cookiename] = ''; |
|
| 679 | + if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) { |
|
| 680 | + $_COOKIE[$cookiename] = ''; |
|
| 681 | + } |
|
| 651 | 682 | |
| 652 | 683 | // Expire the 2FA cookie |
| 653 | 684 | if (isset($_COOKIE[$cookiename . '_tfa']) && empty($context['tfa_member'])) |
@@ -664,19 +695,20 @@ discard block |
||
| 664 | 695 | } |
| 665 | 696 | |
| 666 | 697 | // Create a login token if it doesn't exist yet. |
| 667 | - if (!isset($_SESSION['token']['post-login'])) |
|
| 668 | - createToken('login'); |
|
| 669 | - else |
|
| 670 | - list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login']; |
|
| 698 | + if (!isset($_SESSION['token']['post-login'])) { |
|
| 699 | + createToken('login'); |
|
| 700 | + } else { |
|
| 701 | + list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login']; |
|
| 702 | + } |
|
| 671 | 703 | |
| 672 | 704 | // Do we perhaps think this is a search robot? Check every five minutes just in case... |
| 673 | 705 | if ((!empty($modSettings['spider_mode']) || !empty($modSettings['spider_group'])) && (!isset($_SESSION['robot_check']) || $_SESSION['robot_check'] < time() - 300)) |
| 674 | 706 | { |
| 675 | 707 | require_once($sourcedir . '/ManageSearchEngines.php'); |
| 676 | 708 | $user_info['possibly_robot'] = SpiderCheck(); |
| 709 | + } elseif (!empty($modSettings['spider_mode'])) { |
|
| 710 | + $user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0; |
|
| 677 | 711 | } |
| 678 | - elseif (!empty($modSettings['spider_mode'])) |
|
| 679 | - $user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0; |
|
| 680 | 712 | // If we haven't turned on proper spider hunts then have a guess! |
| 681 | 713 | else |
| 682 | 714 | { |
@@ -724,8 +756,9 @@ discard block |
||
| 724 | 756 | $user_info['groups'] = array_unique($user_info['groups']); |
| 725 | 757 | |
| 726 | 758 | // Make sure that the last item in the ignore boards array is valid. If the list was too long it could have an ending comma that could cause problems. |
| 727 | - if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) |
|
| 728 | - unset($user_info['ignoreboards'][$tmp]); |
|
| 759 | + if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) { |
|
| 760 | + unset($user_info['ignoreboards'][$tmp]); |
|
| 761 | + } |
|
| 729 | 762 | |
| 730 | 763 | // Allow the user to change their language. |
| 731 | 764 | if (!empty($modSettings['userLanguage'])) |
@@ -738,13 +771,14 @@ discard block |
||
| 738 | 771 | $user_info['language'] = strtr($_GET['language'], './\\:', '____'); |
| 739 | 772 | |
| 740 | 773 | // Make it permanent for members. |
| 741 | - if (!empty($user_info['id'])) |
|
| 742 | - updateMemberData($user_info['id'], array('lngfile' => $user_info['language'])); |
|
| 743 | - else |
|
| 744 | - $_SESSION['language'] = $user_info['language']; |
|
| 774 | + if (!empty($user_info['id'])) { |
|
| 775 | + updateMemberData($user_info['id'], array('lngfile' => $user_info['language'])); |
|
| 776 | + } else { |
|
| 777 | + $_SESSION['language'] = $user_info['language']; |
|
| 778 | + } |
|
| 779 | + } elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) { |
|
| 780 | + $user_info['language'] = strtr($_SESSION['language'], './\\:', '____'); |
|
| 745 | 781 | } |
| 746 | - elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) |
|
| 747 | - $user_info['language'] = strtr($_SESSION['language'], './\\:', '____'); |
|
| 748 | 782 | } |
| 749 | 783 | |
| 750 | 784 | $temp = build_query_board($user_info['id']); |
@@ -807,9 +841,9 @@ discard block |
||
| 807 | 841 | } |
| 808 | 842 | |
| 809 | 843 | // Remember redirection is the key to avoiding fallout from your bosses. |
| 810 | - if (!empty($topic)) |
|
| 811 | - redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']); |
|
| 812 | - else |
|
| 844 | + if (!empty($topic)) { |
|
| 845 | + redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']); |
|
| 846 | + } else |
|
| 813 | 847 | { |
| 814 | 848 | loadPermissions(); |
| 815 | 849 | loadTheme(); |
@@ -827,10 +861,11 @@ discard block |
||
| 827 | 861 | if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3)) |
| 828 | 862 | { |
| 829 | 863 | // @todo SLOW? |
| 830 | - if (!empty($topic)) |
|
| 831 | - $temp = cache_get_data('topic_board-' . $topic, 120); |
|
| 832 | - else |
|
| 833 | - $temp = cache_get_data('board-' . $board, 120); |
|
| 864 | + if (!empty($topic)) { |
|
| 865 | + $temp = cache_get_data('topic_board-' . $topic, 120); |
|
| 866 | + } else { |
|
| 867 | + $temp = cache_get_data('board-' . $board, 120); |
|
| 868 | + } |
|
| 834 | 869 | |
| 835 | 870 | if (!empty($temp)) |
| 836 | 871 | { |
@@ -868,8 +903,9 @@ discard block |
||
| 868 | 903 | $row = $smcFunc['db_fetch_assoc']($request); |
| 869 | 904 | |
| 870 | 905 | // Set the current board. |
| 871 | - if (!empty($row['id_board'])) |
|
| 872 | - $board = $row['id_board']; |
|
| 906 | + if (!empty($row['id_board'])) { |
|
| 907 | + $board = $row['id_board']; |
|
| 908 | + } |
|
| 873 | 909 | |
| 874 | 910 | // Basic operating information. (globals... :/) |
| 875 | 911 | $board_info = array( |
@@ -905,21 +941,23 @@ discard block |
||
| 905 | 941 | |
| 906 | 942 | do |
| 907 | 943 | { |
| 908 | - if (!empty($row['id_moderator'])) |
|
| 909 | - $board_info['moderators'][$row['id_moderator']] = array( |
|
| 944 | + if (!empty($row['id_moderator'])) { |
|
| 945 | + $board_info['moderators'][$row['id_moderator']] = array( |
|
| 910 | 946 | 'id' => $row['id_moderator'], |
| 911 | 947 | 'name' => $row['real_name'], |
| 912 | 948 | 'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'], |
| 913 | 949 | 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>' |
| 914 | 950 | ); |
| 951 | + } |
|
| 915 | 952 | |
| 916 | - if (!empty($row['id_moderator_group'])) |
|
| 917 | - $board_info['moderator_groups'][$row['id_moderator_group']] = array( |
|
| 953 | + if (!empty($row['id_moderator_group'])) { |
|
| 954 | + $board_info['moderator_groups'][$row['id_moderator_group']] = array( |
|
| 918 | 955 | 'id' => $row['id_moderator_group'], |
| 919 | 956 | 'name' => $row['group_name'], |
| 920 | 957 | 'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'], |
| 921 | 958 | 'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>' |
| 922 | 959 | ); |
| 960 | + } |
|
| 923 | 961 | } |
| 924 | 962 | while ($row = $smcFunc['db_fetch_assoc']($request)); |
| 925 | 963 | |
@@ -951,12 +989,12 @@ discard block |
||
| 951 | 989 | if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3)) |
| 952 | 990 | { |
| 953 | 991 | // @todo SLOW? |
| 954 | - if (!empty($topic)) |
|
| 955 | - cache_put_data('topic_board-' . $topic, $board_info, 120); |
|
| 992 | + if (!empty($topic)) { |
|
| 993 | + cache_put_data('topic_board-' . $topic, $board_info, 120); |
|
| 994 | + } |
|
| 956 | 995 | cache_put_data('board-' . $board, $board_info, 120); |
| 957 | 996 | } |
| 958 | - } |
|
| 959 | - else |
|
| 997 | + } else |
|
| 960 | 998 | { |
| 961 | 999 | // Otherwise the topic is invalid, there are no moderators, etc. |
| 962 | 1000 | $board_info = array( |
@@ -970,8 +1008,9 @@ discard block |
||
| 970 | 1008 | $smcFunc['db_free_result']($request); |
| 971 | 1009 | } |
| 972 | 1010 | |
| 973 | - if (!empty($topic)) |
|
| 974 | - $_GET['board'] = (int) $board; |
|
| 1011 | + if (!empty($topic)) { |
|
| 1012 | + $_GET['board'] = (int) $board; |
|
| 1013 | + } |
|
| 975 | 1014 | |
| 976 | 1015 | if (!empty($board)) |
| 977 | 1016 | { |
@@ -981,10 +1020,12 @@ discard block |
||
| 981 | 1020 | // Now check if the user is a moderator. |
| 982 | 1021 | $user_info['is_mod'] = isset($board_info['moderators'][$user_info['id']]) || count(array_intersect($user_info['groups'], $moderator_groups)) != 0; |
| 983 | 1022 | |
| 984 | - if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) |
|
| 985 | - $board_info['error'] = 'access'; |
|
| 986 | - if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) |
|
| 987 | - $board_info['error'] = 'access'; |
|
| 1023 | + if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) { |
|
| 1024 | + $board_info['error'] = 'access'; |
|
| 1025 | + } |
|
| 1026 | + if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) { |
|
| 1027 | + $board_info['error'] = 'access'; |
|
| 1028 | + } |
|
| 988 | 1029 | |
| 989 | 1030 | // Build up the linktree. |
| 990 | 1031 | $context['linktree'] = array_merge( |
@@ -1007,8 +1048,9 @@ discard block |
||
| 1007 | 1048 | $context['current_board'] = $board; |
| 1008 | 1049 | |
| 1009 | 1050 | // No posting in redirection boards! |
| 1010 | - if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) |
|
| 1011 | - $board_info['error'] == 'post_in_redirect'; |
|
| 1051 | + if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) { |
|
| 1052 | + $board_info['error'] == 'post_in_redirect'; |
|
| 1053 | + } |
|
| 1012 | 1054 | |
| 1013 | 1055 | // Hacker... you can't see this topic, I'll tell you that. (but moderators can!) |
| 1014 | 1056 | if (!empty($board_info['error']) && (!empty($modSettings['deny_boards_access']) || $board_info['error'] != 'access' || !$user_info['is_mod'])) |
@@ -1034,24 +1076,23 @@ discard block |
||
| 1034 | 1076 | ob_end_clean(); |
| 1035 | 1077 | header('HTTP/1.1 403 Forbidden'); |
| 1036 | 1078 | die; |
| 1037 | - } |
|
| 1038 | - elseif ($board_info['error'] == 'post_in_redirect') |
|
| 1079 | + } elseif ($board_info['error'] == 'post_in_redirect') |
|
| 1039 | 1080 | { |
| 1040 | 1081 | // Slightly different error message here... |
| 1041 | 1082 | fatal_lang_error('cannot_post_redirect', false); |
| 1042 | - } |
|
| 1043 | - elseif ($user_info['is_guest']) |
|
| 1083 | + } elseif ($user_info['is_guest']) |
|
| 1044 | 1084 | { |
| 1045 | 1085 | loadLanguage('Errors'); |
| 1046 | 1086 | is_not_guest($txt['topic_gone']); |
| 1087 | + } else { |
|
| 1088 | + fatal_lang_error('topic_gone', false); |
|
| 1047 | 1089 | } |
| 1048 | - else |
|
| 1049 | - fatal_lang_error('topic_gone', false); |
|
| 1050 | 1090 | } |
| 1051 | 1091 | |
| 1052 | - if ($user_info['is_mod']) |
|
| 1053 | - $user_info['groups'][] = 3; |
|
| 1054 | -} |
|
| 1092 | + if ($user_info['is_mod']) { |
|
| 1093 | + $user_info['groups'][] = 3; |
|
| 1094 | + } |
|
| 1095 | + } |
|
| 1055 | 1096 | |
| 1056 | 1097 | /** |
| 1057 | 1098 | * Load this user's permissions. |
@@ -1072,8 +1113,9 @@ discard block |
||
| 1072 | 1113 | asort($cache_groups); |
| 1073 | 1114 | $cache_groups = implode(',', $cache_groups); |
| 1074 | 1115 | // If it's a spider then cache it different. |
| 1075 | - if ($user_info['possibly_robot']) |
|
| 1076 | - $cache_groups .= '-spider'; |
|
| 1116 | + if ($user_info['possibly_robot']) { |
|
| 1117 | + $cache_groups .= '-spider'; |
|
| 1118 | + } |
|
| 1077 | 1119 | |
| 1078 | 1120 | if ($modSettings['cache_enable'] >= 2 && !empty($board) && ($temp = cache_get_data('permissions:' . $cache_groups . ':' . $board, 240)) != null && time() - 240 > $modSettings['settings_updated']) |
| 1079 | 1121 | { |
@@ -1081,9 +1123,9 @@ discard block |
||
| 1081 | 1123 | banPermissions(); |
| 1082 | 1124 | |
| 1083 | 1125 | return; |
| 1126 | + } elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) { |
|
| 1127 | + list ($user_info['permissions'], $removals) = $temp; |
|
| 1084 | 1128 | } |
| 1085 | - elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) |
|
| 1086 | - list ($user_info['permissions'], $removals) = $temp; |
|
| 1087 | 1129 | } |
| 1088 | 1130 | |
| 1089 | 1131 | // If it is detected as a robot, and we are restricting permissions as a special group - then implement this. |
@@ -1105,23 +1147,26 @@ discard block |
||
| 1105 | 1147 | $removals = array(); |
| 1106 | 1148 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1107 | 1149 | { |
| 1108 | - if (empty($row['add_deny'])) |
|
| 1109 | - $removals[] = $row['permission']; |
|
| 1110 | - else |
|
| 1111 | - $user_info['permissions'][] = $row['permission']; |
|
| 1150 | + if (empty($row['add_deny'])) { |
|
| 1151 | + $removals[] = $row['permission']; |
|
| 1152 | + } else { |
|
| 1153 | + $user_info['permissions'][] = $row['permission']; |
|
| 1154 | + } |
|
| 1112 | 1155 | } |
| 1113 | 1156 | $smcFunc['db_free_result']($request); |
| 1114 | 1157 | |
| 1115 | - if (isset($cache_groups)) |
|
| 1116 | - cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240); |
|
| 1158 | + if (isset($cache_groups)) { |
|
| 1159 | + cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240); |
|
| 1160 | + } |
|
| 1117 | 1161 | } |
| 1118 | 1162 | |
| 1119 | 1163 | // Get the board permissions. |
| 1120 | 1164 | if (!empty($board)) |
| 1121 | 1165 | { |
| 1122 | 1166 | // Make sure the board (if any) has been loaded by loadBoard(). |
| 1123 | - if (!isset($board_info['profile'])) |
|
| 1124 | - fatal_lang_error('no_board'); |
|
| 1167 | + if (!isset($board_info['profile'])) { |
|
| 1168 | + fatal_lang_error('no_board'); |
|
| 1169 | + } |
|
| 1125 | 1170 | |
| 1126 | 1171 | $request = $smcFunc['db_query']('', ' |
| 1127 | 1172 | SELECT permission, add_deny |
@@ -1137,20 +1182,23 @@ discard block |
||
| 1137 | 1182 | ); |
| 1138 | 1183 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1139 | 1184 | { |
| 1140 | - if (empty($row['add_deny'])) |
|
| 1141 | - $removals[] = $row['permission']; |
|
| 1142 | - else |
|
| 1143 | - $user_info['permissions'][] = $row['permission']; |
|
| 1185 | + if (empty($row['add_deny'])) { |
|
| 1186 | + $removals[] = $row['permission']; |
|
| 1187 | + } else { |
|
| 1188 | + $user_info['permissions'][] = $row['permission']; |
|
| 1189 | + } |
|
| 1144 | 1190 | } |
| 1145 | 1191 | $smcFunc['db_free_result']($request); |
| 1146 | 1192 | } |
| 1147 | 1193 | |
| 1148 | 1194 | // Remove all the permissions they shouldn't have ;). |
| 1149 | - if (!empty($modSettings['permission_enable_deny'])) |
|
| 1150 | - $user_info['permissions'] = array_diff($user_info['permissions'], $removals); |
|
| 1195 | + if (!empty($modSettings['permission_enable_deny'])) { |
|
| 1196 | + $user_info['permissions'] = array_diff($user_info['permissions'], $removals); |
|
| 1197 | + } |
|
| 1151 | 1198 | |
| 1152 | - if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) |
|
| 1153 | - cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240); |
|
| 1199 | + if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) { |
|
| 1200 | + cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240); |
|
| 1201 | + } |
|
| 1154 | 1202 | |
| 1155 | 1203 | // Banned? Watch, don't touch.. |
| 1156 | 1204 | banPermissions(); |
@@ -1162,17 +1210,18 @@ discard block |
||
| 1162 | 1210 | { |
| 1163 | 1211 | require_once($sourcedir . '/Subs-Auth.php'); |
| 1164 | 1212 | rebuildModCache(); |
| 1213 | + } else { |
|
| 1214 | + $user_info['mod_cache'] = $_SESSION['mc']; |
|
| 1165 | 1215 | } |
| 1166 | - else |
|
| 1167 | - $user_info['mod_cache'] = $_SESSION['mc']; |
|
| 1168 | 1216 | |
| 1169 | 1217 | // This is a useful phantom permission added to the current user, and only the current user while they are logged in. |
| 1170 | 1218 | // For example this drastically simplifies certain changes to the profile area. |
| 1171 | 1219 | $user_info['permissions'][] = 'is_not_guest'; |
| 1172 | 1220 | // And now some backwards compatibility stuff for mods and whatnot that aren't expecting the new permissions. |
| 1173 | 1221 | $user_info['permissions'][] = 'profile_view_own'; |
| 1174 | - if (in_array('profile_view', $user_info['permissions'])) |
|
| 1175 | - $user_info['permissions'][] = 'profile_view_any'; |
|
| 1222 | + if (in_array('profile_view', $user_info['permissions'])) { |
|
| 1223 | + $user_info['permissions'][] = 'profile_view_any'; |
|
| 1224 | + } |
|
| 1176 | 1225 | } |
| 1177 | 1226 | } |
| 1178 | 1227 | |
@@ -1190,8 +1239,9 @@ discard block |
||
| 1190 | 1239 | global $image_proxy_enabled, $image_proxy_secret, $boardurl; |
| 1191 | 1240 | |
| 1192 | 1241 | // Can't just look for no users :P. |
| 1193 | - if (empty($users)) |
|
| 1194 | - return array(); |
|
| 1242 | + if (empty($users)) { |
|
| 1243 | + return array(); |
|
| 1244 | + } |
|
| 1195 | 1245 | |
| 1196 | 1246 | // Pass the set value |
| 1197 | 1247 | $context['loadMemberContext_set'] = $set; |
@@ -1206,8 +1256,9 @@ discard block |
||
| 1206 | 1256 | for ($i = 0, $n = count($users); $i < $n; $i++) |
| 1207 | 1257 | { |
| 1208 | 1258 | $data = cache_get_data('member_data-' . $set . '-' . $users[$i], 240); |
| 1209 | - if ($data == null) |
|
| 1210 | - continue; |
|
| 1259 | + if ($data == null) { |
|
| 1260 | + continue; |
|
| 1261 | + } |
|
| 1211 | 1262 | |
| 1212 | 1263 | $loaded_ids[] = $data['id_member']; |
| 1213 | 1264 | $user_profile[$data['id_member']] = $data; |
@@ -1274,16 +1325,19 @@ discard block |
||
| 1274 | 1325 | $row['avatar_original'] = !empty($row['avatar']) ? $row['avatar'] : ''; |
| 1275 | 1326 | |
| 1276 | 1327 | // Take care of proxying avatar if required, do this here for maximum reach |
| 1277 | - if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false) |
|
| 1278 | - $row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret); |
|
| 1328 | + if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false) { |
|
| 1329 | + $row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret); |
|
| 1330 | + } |
|
| 1279 | 1331 | |
| 1280 | 1332 | // Keep track of the member's normal member group |
| 1281 | 1333 | $row['primary_group'] = $row['member_group']; |
| 1282 | 1334 | |
| 1283 | - if (isset($row['member_ip'])) |
|
| 1284 | - $row['member_ip'] = inet_dtop($row['member_ip']); |
|
| 1285 | - if (isset($row['member_ip2'])) |
|
| 1286 | - $row['member_ip2'] = inet_dtop($row['member_ip2']); |
|
| 1335 | + if (isset($row['member_ip'])) { |
|
| 1336 | + $row['member_ip'] = inet_dtop($row['member_ip']); |
|
| 1337 | + } |
|
| 1338 | + if (isset($row['member_ip2'])) { |
|
| 1339 | + $row['member_ip2'] = inet_dtop($row['member_ip2']); |
|
| 1340 | + } |
|
| 1287 | 1341 | $new_loaded_ids[] = $row['id_member']; |
| 1288 | 1342 | $loaded_ids[] = $row['id_member']; |
| 1289 | 1343 | $row['options'] = array(); |
@@ -1302,8 +1356,9 @@ discard block |
||
| 1302 | 1356 | 'loaded_ids' => $new_loaded_ids, |
| 1303 | 1357 | ) |
| 1304 | 1358 | ); |
| 1305 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1306 | - $user_profile[$row['id_member']]['options'][$row['variable']] = $row['value']; |
|
| 1359 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1360 | + $user_profile[$row['id_member']]['options'][$row['variable']] = $row['value']; |
|
| 1361 | + } |
|
| 1307 | 1362 | $smcFunc['db_free_result']($request); |
| 1308 | 1363 | } |
| 1309 | 1364 | |
@@ -1314,10 +1369,11 @@ discard block |
||
| 1314 | 1369 | { |
| 1315 | 1370 | foreach ($loaded_ids as $a_member) |
| 1316 | 1371 | { |
| 1317 | - if (!empty($user_profile[$a_member]['additional_groups'])) |
|
| 1318 | - $groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups'])); |
|
| 1319 | - else |
|
| 1320 | - $groups = array($user_profile[$a_member]['id_group']); |
|
| 1372 | + if (!empty($user_profile[$a_member]['additional_groups'])) { |
|
| 1373 | + $groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups'])); |
|
| 1374 | + } else { |
|
| 1375 | + $groups = array($user_profile[$a_member]['id_group']); |
|
| 1376 | + } |
|
| 1321 | 1377 | |
| 1322 | 1378 | $temp = array_intersect($groups, array_keys($board_info['moderator_groups'])); |
| 1323 | 1379 | |
@@ -1330,8 +1386,9 @@ discard block |
||
| 1330 | 1386 | |
| 1331 | 1387 | if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3) |
| 1332 | 1388 | { |
| 1333 | - for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) |
|
| 1334 | - cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240); |
|
| 1389 | + for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) { |
|
| 1390 | + cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240); |
|
| 1391 | + } |
|
| 1335 | 1392 | } |
| 1336 | 1393 | |
| 1337 | 1394 | // Are we loading any moderators? If so, fix their group data... |
@@ -1357,14 +1414,17 @@ discard block |
||
| 1357 | 1414 | foreach ($temp_mods as $id) |
| 1358 | 1415 | { |
| 1359 | 1416 | // By popular demand, don't show admins or global moderators as moderators. |
| 1360 | - if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) |
|
| 1361 | - $user_profile[$id]['member_group'] = $row['member_group']; |
|
| 1417 | + if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) { |
|
| 1418 | + $user_profile[$id]['member_group'] = $row['member_group']; |
|
| 1419 | + } |
|
| 1362 | 1420 | |
| 1363 | 1421 | // If the Moderator group has no color or icons, but their group does... don't overwrite. |
| 1364 | - if (!empty($row['icons'])) |
|
| 1365 | - $user_profile[$id]['icons'] = $row['icons']; |
|
| 1366 | - if (!empty($row['member_group_color'])) |
|
| 1367 | - $user_profile[$id]['member_group_color'] = $row['member_group_color']; |
|
| 1422 | + if (!empty($row['icons'])) { |
|
| 1423 | + $user_profile[$id]['icons'] = $row['icons']; |
|
| 1424 | + } |
|
| 1425 | + if (!empty($row['member_group_color'])) { |
|
| 1426 | + $user_profile[$id]['member_group_color'] = $row['member_group_color']; |
|
| 1427 | + } |
|
| 1368 | 1428 | } |
| 1369 | 1429 | } |
| 1370 | 1430 | |
@@ -1386,12 +1446,14 @@ discard block |
||
| 1386 | 1446 | static $loadedLanguages = array(); |
| 1387 | 1447 | |
| 1388 | 1448 | // If this person's data is already loaded, skip it. |
| 1389 | - if (isset($dataLoaded[$user])) |
|
| 1390 | - return true; |
|
| 1449 | + if (isset($dataLoaded[$user])) { |
|
| 1450 | + return true; |
|
| 1451 | + } |
|
| 1391 | 1452 | |
| 1392 | 1453 | // We can't load guests or members not loaded by loadMemberData()! |
| 1393 | - if ($user == 0) |
|
| 1394 | - return false; |
|
| 1454 | + if ($user == 0) { |
|
| 1455 | + return false; |
|
| 1456 | + } |
|
| 1395 | 1457 | if (!isset($user_profile[$user])) |
| 1396 | 1458 | { |
| 1397 | 1459 | trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING); |
@@ -1417,12 +1479,16 @@ discard block |
||
| 1417 | 1479 | $buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array(); |
| 1418 | 1480 | |
| 1419 | 1481 | //We need a little fallback for the membergroup icons. If it doesn't exist in the current theme, fallback to default theme |
| 1420 | - if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) //icon is set and exists |
|
| 1482 | + if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) { |
|
| 1483 | + //icon is set and exists |
|
| 1421 | 1484 | $group_icon_url = $settings['images_url'] . '/membericons/' . $profile['icons'][1]; |
| 1422 | - elseif (isset($profile['icons'][1])) //icon is set and doesn't exist, fallback to default |
|
| 1485 | + } elseif (isset($profile['icons'][1])) { |
|
| 1486 | + //icon is set and doesn't exist, fallback to default |
|
| 1423 | 1487 | $group_icon_url = $settings['default_images_url'] . '/membericons/' . $profile['icons'][1]; |
| 1424 | - else //not set, bye bye |
|
| 1488 | + } else { |
|
| 1489 | + //not set, bye bye |
|
| 1425 | 1490 | $group_icon_url = ''; |
| 1491 | + } |
|
| 1426 | 1492 | |
| 1427 | 1493 | // These minimal values are always loaded |
| 1428 | 1494 | $memberContext[$user] = array( |
@@ -1441,8 +1507,9 @@ discard block |
||
| 1441 | 1507 | if ($context['loadMemberContext_set'] != 'minimal') |
| 1442 | 1508 | { |
| 1443 | 1509 | // Go the extra mile and load the user's native language name. |
| 1444 | - if (empty($loadedLanguages)) |
|
| 1445 | - $loadedLanguages = getLanguages(); |
|
| 1510 | + if (empty($loadedLanguages)) { |
|
| 1511 | + $loadedLanguages = getLanguages(); |
|
| 1512 | + } |
|
| 1446 | 1513 | |
| 1447 | 1514 | $memberContext[$user] += array( |
| 1448 | 1515 | 'username_color' => '<span ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['member_name'] . '</span>', |
@@ -1497,31 +1564,33 @@ discard block |
||
| 1497 | 1564 | { |
| 1498 | 1565 | if (!empty($modSettings['gravatarOverride']) || (!empty($modSettings['gravatarEnabled']) && stristr($profile['avatar'], 'gravatar://'))) |
| 1499 | 1566 | { |
| 1500 | - if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) |
|
| 1501 | - $image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11)); |
|
| 1502 | - else |
|
| 1503 | - $image = get_gravatar_url($profile['email_address']); |
|
| 1504 | - } |
|
| 1505 | - else |
|
| 1567 | + if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) { |
|
| 1568 | + $image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11)); |
|
| 1569 | + } else { |
|
| 1570 | + $image = get_gravatar_url($profile['email_address']); |
|
| 1571 | + } |
|
| 1572 | + } else |
|
| 1506 | 1573 | { |
| 1507 | 1574 | // So it's stored in the member table? |
| 1508 | 1575 | if (!empty($profile['avatar'])) |
| 1509 | 1576 | { |
| 1510 | 1577 | $image = (stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar']; |
| 1578 | + } elseif (!empty($profile['filename'])) { |
|
| 1579 | + $image = $modSettings['custom_avatar_url'] . '/' . $profile['filename']; |
|
| 1511 | 1580 | } |
| 1512 | - elseif (!empty($profile['filename'])) |
|
| 1513 | - $image = $modSettings['custom_avatar_url'] . '/' . $profile['filename']; |
|
| 1514 | 1581 | // Right... no avatar...use the default one |
| 1515 | - else |
|
| 1516 | - $image = $modSettings['avatar_url'] . '/default.png'; |
|
| 1582 | + else { |
|
| 1583 | + $image = $modSettings['avatar_url'] . '/default.png'; |
|
| 1584 | + } |
|
| 1517 | 1585 | } |
| 1518 | - if (!empty($image)) |
|
| 1519 | - $memberContext[$user]['avatar'] = array( |
|
| 1586 | + if (!empty($image)) { |
|
| 1587 | + $memberContext[$user]['avatar'] = array( |
|
| 1520 | 1588 | 'name' => $profile['avatar'], |
| 1521 | 1589 | 'image' => '<img class="avatar" src="' . $image . '" alt="avatar_' . $profile['member_name'] . '">', |
| 1522 | 1590 | 'href' => $image, |
| 1523 | 1591 | 'url' => $image, |
| 1524 | 1592 | ); |
| 1593 | + } |
|
| 1525 | 1594 | } |
| 1526 | 1595 | |
| 1527 | 1596 | // Are we also loading the members custom fields into context? |
@@ -1529,13 +1598,15 @@ discard block |
||
| 1529 | 1598 | { |
| 1530 | 1599 | $memberContext[$user]['custom_fields'] = array(); |
| 1531 | 1600 | |
| 1532 | - if (!isset($context['display_fields'])) |
|
| 1533 | - $context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true); |
|
| 1601 | + if (!isset($context['display_fields'])) { |
|
| 1602 | + $context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true); |
|
| 1603 | + } |
|
| 1534 | 1604 | |
| 1535 | 1605 | foreach ($context['display_fields'] as $custom) |
| 1536 | 1606 | { |
| 1537 | - if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) |
|
| 1538 | - continue; |
|
| 1607 | + if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) { |
|
| 1608 | + continue; |
|
| 1609 | + } |
|
| 1539 | 1610 | |
| 1540 | 1611 | $value = $profile['options'][$custom['col_name']]; |
| 1541 | 1612 | |
@@ -1543,31 +1614,36 @@ discard block |
||
| 1543 | 1614 | $currentKey = 0; |
| 1544 | 1615 | |
| 1545 | 1616 | // Create a key => value array for multiple options fields |
| 1546 | - if (!empty($custom['options'])) |
|
| 1547 | - foreach ($custom['options'] as $k => $v) |
|
| 1617 | + if (!empty($custom['options'])) { |
|
| 1618 | + foreach ($custom['options'] as $k => $v) |
|
| 1548 | 1619 | { |
| 1549 | 1620 | $fieldOptions[] = $v; |
| 1550 | - if (empty($currentKey)) |
|
| 1551 | - $currentKey = $v == $value ? $k : 0; |
|
| 1621 | + } |
|
| 1622 | + if (empty($currentKey)) { |
|
| 1623 | + $currentKey = $v == $value ? $k : 0; |
|
| 1624 | + } |
|
| 1552 | 1625 | } |
| 1553 | 1626 | |
| 1554 | 1627 | // BBC? |
| 1555 | - if ($custom['bbc']) |
|
| 1556 | - $value = parse_bbc($value); |
|
| 1628 | + if ($custom['bbc']) { |
|
| 1629 | + $value = parse_bbc($value); |
|
| 1630 | + } |
|
| 1557 | 1631 | |
| 1558 | 1632 | // ... or checkbox? |
| 1559 | - elseif (isset($custom['type']) && $custom['type'] == 'check') |
|
| 1560 | - $value = $value ? $txt['yes'] : $txt['no']; |
|
| 1633 | + elseif (isset($custom['type']) && $custom['type'] == 'check') { |
|
| 1634 | + $value = $value ? $txt['yes'] : $txt['no']; |
|
| 1635 | + } |
|
| 1561 | 1636 | |
| 1562 | 1637 | // Enclosing the user input within some other text? |
| 1563 | - if (!empty($custom['enclose'])) |
|
| 1564 | - $value = strtr($custom['enclose'], array( |
|
| 1638 | + if (!empty($custom['enclose'])) { |
|
| 1639 | + $value = strtr($custom['enclose'], array( |
|
| 1565 | 1640 | '{SCRIPTURL}' => $scripturl, |
| 1566 | 1641 | '{IMAGES_URL}' => $settings['images_url'], |
| 1567 | 1642 | '{DEFAULT_IMAGES_URL}' => $settings['default_images_url'], |
| 1568 | 1643 | '{INPUT}' => $value, |
| 1569 | 1644 | '{KEY}' => $currentKey, |
| 1570 | 1645 | )); |
| 1646 | + } |
|
| 1571 | 1647 | |
| 1572 | 1648 | $memberContext[$user]['custom_fields'][] = array( |
| 1573 | 1649 | 'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'], |
@@ -1594,8 +1670,9 @@ discard block |
||
| 1594 | 1670 | global $smcFunc, $txt, $scripturl, $settings; |
| 1595 | 1671 | |
| 1596 | 1672 | // Do not waste my time... |
| 1597 | - if (empty($users) || empty($params)) |
|
| 1598 | - return false; |
|
| 1673 | + if (empty($users) || empty($params)) { |
|
| 1674 | + return false; |
|
| 1675 | + } |
|
| 1599 | 1676 | |
| 1600 | 1677 | // Make sure it's an array. |
| 1601 | 1678 | $users = !is_array($users) ? array($users) : array_unique($users); |
@@ -1622,41 +1699,48 @@ discard block |
||
| 1622 | 1699 | $currentKey = 0; |
| 1623 | 1700 | |
| 1624 | 1701 | // Create a key => value array for multiple options fields |
| 1625 | - if (!empty($row['field_options'])) |
|
| 1626 | - foreach (explode(',', $row['field_options']) as $k => $v) |
|
| 1702 | + if (!empty($row['field_options'])) { |
|
| 1703 | + foreach (explode(',', $row['field_options']) as $k => $v) |
|
| 1627 | 1704 | { |
| 1628 | 1705 | $fieldOptions[] = $v; |
| 1629 | - if (empty($currentKey)) |
|
| 1630 | - $currentKey = $v == $row['value'] ? $k : 0; |
|
| 1706 | + } |
|
| 1707 | + if (empty($currentKey)) { |
|
| 1708 | + $currentKey = $v == $row['value'] ? $k : 0; |
|
| 1709 | + } |
|
| 1631 | 1710 | } |
| 1632 | 1711 | |
| 1633 | 1712 | // BBC? |
| 1634 | - if (!empty($row['bbc'])) |
|
| 1635 | - $row['value'] = parse_bbc($row['value']); |
|
| 1713 | + if (!empty($row['bbc'])) { |
|
| 1714 | + $row['value'] = parse_bbc($row['value']); |
|
| 1715 | + } |
|
| 1636 | 1716 | |
| 1637 | 1717 | // ... or checkbox? |
| 1638 | - elseif (isset($row['type']) && $row['type'] == 'check') |
|
| 1639 | - $row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no']; |
|
| 1718 | + elseif (isset($row['type']) && $row['type'] == 'check') { |
|
| 1719 | + $row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no']; |
|
| 1720 | + } |
|
| 1640 | 1721 | |
| 1641 | 1722 | // Enclosing the user input within some other text? |
| 1642 | - if (!empty($row['enclose'])) |
|
| 1643 | - $row['value'] = strtr($row['enclose'], array( |
|
| 1723 | + if (!empty($row['enclose'])) { |
|
| 1724 | + $row['value'] = strtr($row['enclose'], array( |
|
| 1644 | 1725 | '{SCRIPTURL}' => $scripturl, |
| 1645 | 1726 | '{IMAGES_URL}' => $settings['images_url'], |
| 1646 | 1727 | '{DEFAULT_IMAGES_URL}' => $settings['default_images_url'], |
| 1647 | 1728 | '{INPUT}' => un_htmlspecialchars($row['value']), |
| 1648 | 1729 | '{KEY}' => $currentKey, |
| 1649 | 1730 | )); |
| 1731 | + } |
|
| 1650 | 1732 | |
| 1651 | 1733 | // Send a simple array if there is just 1 param |
| 1652 | - if (count($params) == 1) |
|
| 1653 | - $return[$row['id_member']] = $row; |
|
| 1734 | + if (count($params) == 1) { |
|
| 1735 | + $return[$row['id_member']] = $row; |
|
| 1736 | + } |
|
| 1654 | 1737 | |
| 1655 | 1738 | // More than 1? knock yourself out... |
| 1656 | 1739 | else |
| 1657 | 1740 | { |
| 1658 | - if (!isset($return[$row['id_member']])) |
|
| 1659 | - $return[$row['id_member']] = array(); |
|
| 1741 | + if (!isset($return[$row['id_member']])) { |
|
| 1742 | + $return[$row['id_member']] = array(); |
|
| 1743 | + } |
|
| 1660 | 1744 | |
| 1661 | 1745 | $return[$row['id_member']][$row['variable']] = $row; |
| 1662 | 1746 | } |
@@ -1690,8 +1774,9 @@ discard block |
||
| 1690 | 1774 | global $context; |
| 1691 | 1775 | |
| 1692 | 1776 | // Don't know any browser! |
| 1693 | - if (empty($context['browser'])) |
|
| 1694 | - detectBrowser(); |
|
| 1777 | + if (empty($context['browser'])) { |
|
| 1778 | + detectBrowser(); |
|
| 1779 | + } |
|
| 1695 | 1780 | |
| 1696 | 1781 | return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false; |
| 1697 | 1782 | } |
@@ -1709,8 +1794,9 @@ discard block |
||
| 1709 | 1794 | global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled; |
| 1710 | 1795 | |
| 1711 | 1796 | // The theme was specified by parameter. |
| 1712 | - if (!empty($id_theme)) |
|
| 1713 | - $id_theme = (int) $id_theme; |
|
| 1797 | + if (!empty($id_theme)) { |
|
| 1798 | + $id_theme = (int) $id_theme; |
|
| 1799 | + } |
|
| 1714 | 1800 | // The theme was specified by REQUEST. |
| 1715 | 1801 | elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) |
| 1716 | 1802 | { |
@@ -1718,54 +1804,61 @@ discard block |
||
| 1718 | 1804 | $_SESSION['id_theme'] = $id_theme; |
| 1719 | 1805 | } |
| 1720 | 1806 | // The theme was specified by REQUEST... previously. |
| 1721 | - elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) |
|
| 1722 | - $id_theme = (int) $_SESSION['id_theme']; |
|
| 1807 | + elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) { |
|
| 1808 | + $id_theme = (int) $_SESSION['id_theme']; |
|
| 1809 | + } |
|
| 1723 | 1810 | // The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.) |
| 1724 | - elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) |
|
| 1725 | - $id_theme = $user_info['theme']; |
|
| 1811 | + elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) { |
|
| 1812 | + $id_theme = $user_info['theme']; |
|
| 1813 | + } |
|
| 1726 | 1814 | // The theme was specified by the board. |
| 1727 | - elseif (!empty($board_info['theme'])) |
|
| 1728 | - $id_theme = $board_info['theme']; |
|
| 1815 | + elseif (!empty($board_info['theme'])) { |
|
| 1816 | + $id_theme = $board_info['theme']; |
|
| 1817 | + } |
|
| 1729 | 1818 | // The theme is the forum's default. |
| 1730 | - else |
|
| 1731 | - $id_theme = $modSettings['theme_guests']; |
|
| 1819 | + else { |
|
| 1820 | + $id_theme = $modSettings['theme_guests']; |
|
| 1821 | + } |
|
| 1732 | 1822 | |
| 1733 | 1823 | // We already load the basic stuff? |
| 1734 | 1824 | if (empty($settings['theme_id']) || $settings['theme_id'] != $id_theme ) |
| 1735 | 1825 | { |
| 1736 | 1826 | // Verify the id_theme... no foul play. |
| 1737 | 1827 | // Always allow the board specific theme, if they are overriding. |
| 1738 | - if (!empty($board_info['theme']) && $board_info['override_theme']) |
|
| 1739 | - $id_theme = $board_info['theme']; |
|
| 1828 | + if (!empty($board_info['theme']) && $board_info['override_theme']) { |
|
| 1829 | + $id_theme = $board_info['theme']; |
|
| 1830 | + } |
|
| 1740 | 1831 | // If they have specified a particular theme to use with SSI allow it to be used. |
| 1741 | - elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) |
|
| 1742 | - $id_theme = (int) $id_theme; |
|
| 1743 | - elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum')) |
|
| 1832 | + elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) { |
|
| 1833 | + $id_theme = (int) $id_theme; |
|
| 1834 | + } elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum')) |
|
| 1744 | 1835 | { |
| 1745 | 1836 | $themes = explode(',', $modSettings['enableThemes']); |
| 1746 | - if (!in_array($id_theme, $themes)) |
|
| 1747 | - $id_theme = $modSettings['theme_guests']; |
|
| 1748 | - else |
|
| 1749 | - $id_theme = (int) $id_theme; |
|
| 1837 | + if (!in_array($id_theme, $themes)) { |
|
| 1838 | + $id_theme = $modSettings['theme_guests']; |
|
| 1839 | + } else { |
|
| 1840 | + $id_theme = (int) $id_theme; |
|
| 1841 | + } |
|
| 1842 | + } else { |
|
| 1843 | + $id_theme = (int) $id_theme; |
|
| 1750 | 1844 | } |
| 1751 | - else |
|
| 1752 | - $id_theme = (int) $id_theme; |
|
| 1753 | 1845 | |
| 1754 | 1846 | $member = empty($user_info['id']) ? -1 : $user_info['id']; |
| 1755 | 1847 | |
| 1756 | 1848 | // Disable image proxy if we don't have SSL enabled |
| 1757 | - if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2) |
|
| 1758 | - $image_proxy_enabled = false; |
|
| 1849 | + if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2) { |
|
| 1850 | + $image_proxy_enabled = false; |
|
| 1851 | + } |
|
| 1759 | 1852 | |
| 1760 | 1853 | if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && ($temp = cache_get_data('theme_settings-' . $id_theme . ':' . $member, 60)) != null && time() - 60 > $modSettings['settings_updated']) |
| 1761 | 1854 | { |
| 1762 | 1855 | $themeData = $temp; |
| 1763 | 1856 | $flag = true; |
| 1857 | + } elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) { |
|
| 1858 | + $themeData = $temp + array($member => array()); |
|
| 1859 | + } else { |
|
| 1860 | + $themeData = array(-1 => array(), 0 => array(), $member => array()); |
|
| 1764 | 1861 | } |
| 1765 | - elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) |
|
| 1766 | - $themeData = $temp + array($member => array()); |
|
| 1767 | - else |
|
| 1768 | - $themeData = array(-1 => array(), 0 => array(), $member => array()); |
|
| 1769 | 1862 | |
| 1770 | 1863 | if (empty($flag)) |
| 1771 | 1864 | { |
@@ -1784,31 +1877,37 @@ discard block |
||
| 1784 | 1877 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
| 1785 | 1878 | { |
| 1786 | 1879 | // There are just things we shouldn't be able to change as members. |
| 1787 | - if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url'))) |
|
| 1788 | - continue; |
|
| 1880 | + if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url'))) { |
|
| 1881 | + continue; |
|
| 1882 | + } |
|
| 1789 | 1883 | |
| 1790 | 1884 | // If this is the theme_dir of the default theme, store it. |
| 1791 | - if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) |
|
| 1792 | - $themeData[0]['default_' . $row['variable']] = $row['value']; |
|
| 1885 | + if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) { |
|
| 1886 | + $themeData[0]['default_' . $row['variable']] = $row['value']; |
|
| 1887 | + } |
|
| 1793 | 1888 | |
| 1794 | 1889 | // If this isn't set yet, is a theme option, or is not the default theme.. |
| 1795 | - if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') |
|
| 1796 | - $themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value']; |
|
| 1890 | + if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') { |
|
| 1891 | + $themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value']; |
|
| 1892 | + } |
|
| 1797 | 1893 | } |
| 1798 | 1894 | $smcFunc['db_free_result']($result); |
| 1799 | 1895 | |
| 1800 | - if (!empty($themeData[-1])) |
|
| 1801 | - foreach ($themeData[-1] as $k => $v) |
|
| 1896 | + if (!empty($themeData[-1])) { |
|
| 1897 | + foreach ($themeData[-1] as $k => $v) |
|
| 1802 | 1898 | { |
| 1803 | 1899 | if (!isset($themeData[$member][$k])) |
| 1804 | 1900 | $themeData[$member][$k] = $v; |
| 1901 | + } |
|
| 1805 | 1902 | } |
| 1806 | 1903 | |
| 1807 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
| 1808 | - cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60); |
|
| 1904 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
| 1905 | + cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60); |
|
| 1906 | + } |
|
| 1809 | 1907 | // Only if we didn't already load that part of the cache... |
| 1810 | - elseif (!isset($temp)) |
|
| 1811 | - cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90); |
|
| 1908 | + elseif (!isset($temp)) { |
|
| 1909 | + cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90); |
|
| 1910 | + } |
|
| 1812 | 1911 | } |
| 1813 | 1912 | |
| 1814 | 1913 | $settings = $themeData[0]; |
@@ -1825,17 +1924,20 @@ discard block |
||
| 1825 | 1924 | $settings['template_dirs'][] = $settings['theme_dir']; |
| 1826 | 1925 | |
| 1827 | 1926 | // Based on theme (if there is one). |
| 1828 | - if (!empty($settings['base_theme_dir'])) |
|
| 1829 | - $settings['template_dirs'][] = $settings['base_theme_dir']; |
|
| 1927 | + if (!empty($settings['base_theme_dir'])) { |
|
| 1928 | + $settings['template_dirs'][] = $settings['base_theme_dir']; |
|
| 1929 | + } |
|
| 1830 | 1930 | |
| 1831 | 1931 | // Lastly the default theme. |
| 1832 | - if ($settings['theme_dir'] != $settings['default_theme_dir']) |
|
| 1833 | - $settings['template_dirs'][] = $settings['default_theme_dir']; |
|
| 1932 | + if ($settings['theme_dir'] != $settings['default_theme_dir']) { |
|
| 1933 | + $settings['template_dirs'][] = $settings['default_theme_dir']; |
|
| 1934 | + } |
|
| 1834 | 1935 | } |
| 1835 | 1936 | |
| 1836 | 1937 | |
| 1837 | - if (!$initialize) |
|
| 1838 | - return; |
|
| 1938 | + if (!$initialize) { |
|
| 1939 | + return; |
|
| 1940 | + } |
|
| 1839 | 1941 | |
| 1840 | 1942 | // Check to see if we're forcing SSL |
| 1841 | 1943 | if (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 && empty($maintenance) && |
@@ -1856,8 +1958,9 @@ discard block |
||
| 1856 | 1958 | $detected_url = httpsOn() ? 'https://' : 'http://'; |
| 1857 | 1959 | $detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST']; |
| 1858 | 1960 | $temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/')); |
| 1859 | - if ($temp != '/') |
|
| 1860 | - $detected_url .= $temp; |
|
| 1961 | + if ($temp != '/') { |
|
| 1962 | + $detected_url .= $temp; |
|
| 1963 | + } |
|
| 1861 | 1964 | } |
| 1862 | 1965 | if (isset($detected_url) && $detected_url != $boardurl) |
| 1863 | 1966 | { |
@@ -1869,8 +1972,9 @@ discard block |
||
| 1869 | 1972 | foreach ($aliases as $alias) |
| 1870 | 1973 | { |
| 1871 | 1974 | // Rip off all the boring parts, spaces, etc. |
| 1872 | - if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) |
|
| 1873 | - $do_fix = true; |
|
| 1975 | + if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) { |
|
| 1976 | + $do_fix = true; |
|
| 1977 | + } |
|
| 1874 | 1978 | } |
| 1875 | 1979 | } |
| 1876 | 1980 | |
@@ -1878,21 +1982,23 @@ discard block |
||
| 1878 | 1982 | if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI') |
| 1879 | 1983 | { |
| 1880 | 1984 | // Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;). |
| 1881 | - if (empty($_GET)) |
|
| 1882 | - redirectexit('wwwRedirect'); |
|
| 1883 | - else |
|
| 1985 | + if (empty($_GET)) { |
|
| 1986 | + redirectexit('wwwRedirect'); |
|
| 1987 | + } else |
|
| 1884 | 1988 | { |
| 1885 | 1989 | $k = key($_GET); |
| 1886 | 1990 | $v = current($_GET); |
| 1887 | 1991 | |
| 1888 | - if ($k != 'wwwRedirect') |
|
| 1889 | - redirectexit('wwwRedirect;' . $k . '=' . $v); |
|
| 1992 | + if ($k != 'wwwRedirect') { |
|
| 1993 | + redirectexit('wwwRedirect;' . $k . '=' . $v); |
|
| 1994 | + } |
|
| 1890 | 1995 | } |
| 1891 | 1996 | } |
| 1892 | 1997 | |
| 1893 | 1998 | // #3 is just a check for SSL... |
| 1894 | - if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) |
|
| 1895 | - $do_fix = true; |
|
| 1999 | + if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) { |
|
| 2000 | + $do_fix = true; |
|
| 2001 | + } |
|
| 1896 | 2002 | |
| 1897 | 2003 | // Okay, #4 - perhaps it's an IP address? We're gonna want to use that one, then. (assuming it's the IP or something...) |
| 1898 | 2004 | if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1) |
@@ -1927,8 +2033,9 @@ discard block |
||
| 1927 | 2033 | $board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl)); |
| 1928 | 2034 | } |
| 1929 | 2035 | } |
| 1930 | - foreach ($context['linktree'] as $k => $dummy) |
|
| 1931 | - $context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl)); |
|
| 2036 | + foreach ($context['linktree'] as $k => $dummy) { |
|
| 2037 | + $context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl)); |
|
| 2038 | + } |
|
| 1932 | 2039 | } |
| 1933 | 2040 | } |
| 1934 | 2041 | // Set up the contextual user array. |
@@ -1947,16 +2054,16 @@ discard block |
||
| 1947 | 2054 | 'email' => $user_info['email'], |
| 1948 | 2055 | 'ignoreusers' => $user_info['ignoreusers'], |
| 1949 | 2056 | ); |
| 1950 | - if (!$context['user']['is_guest']) |
|
| 1951 | - $context['user']['name'] = $user_info['name']; |
|
| 1952 | - elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) |
|
| 1953 | - $context['user']['name'] = $txt['guest_title']; |
|
| 2057 | + if (!$context['user']['is_guest']) { |
|
| 2058 | + $context['user']['name'] = $user_info['name']; |
|
| 2059 | + } elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) { |
|
| 2060 | + $context['user']['name'] = $txt['guest_title']; |
|
| 2061 | + } |
|
| 1954 | 2062 | |
| 1955 | 2063 | // Determine the current smiley set. |
| 1956 | 2064 | $user_info['smiley_set'] = (!in_array($user_info['smiley_set'], explode(',', $modSettings['smiley_sets_known'])) && $user_info['smiley_set'] != 'none') || empty($modSettings['smiley_sets_enable']) ? (!empty($settings['smiley_sets_default']) ? $settings['smiley_sets_default'] : $modSettings['smiley_sets_default']) : $user_info['smiley_set']; |
| 1957 | 2065 | $context['user']['smiley_set'] = $user_info['smiley_set']; |
| 1958 | - } |
|
| 1959 | - else |
|
| 2066 | + } else |
|
| 1960 | 2067 | { |
| 1961 | 2068 | // What to do when there is no $user_info (e.g., an error very early in the login process) |
| 1962 | 2069 | $context['user'] = array( |
@@ -1990,18 +2097,24 @@ discard block |
||
| 1990 | 2097 | } |
| 1991 | 2098 | |
| 1992 | 2099 | // Some basic information... |
| 1993 | - if (!isset($context['html_headers'])) |
|
| 1994 | - $context['html_headers'] = ''; |
|
| 1995 | - if (!isset($context['javascript_files'])) |
|
| 1996 | - $context['javascript_files'] = array(); |
|
| 1997 | - if (!isset($context['css_files'])) |
|
| 1998 | - $context['css_files'] = array(); |
|
| 1999 | - if (!isset($context['css_header'])) |
|
| 2000 | - $context['css_header'] = array(); |
|
| 2001 | - if (!isset($context['javascript_inline'])) |
|
| 2002 | - $context['javascript_inline'] = array('standard' => array(), 'defer' => array()); |
|
| 2003 | - if (!isset($context['javascript_vars'])) |
|
| 2004 | - $context['javascript_vars'] = array(); |
|
| 2100 | + if (!isset($context['html_headers'])) { |
|
| 2101 | + $context['html_headers'] = ''; |
|
| 2102 | + } |
|
| 2103 | + if (!isset($context['javascript_files'])) { |
|
| 2104 | + $context['javascript_files'] = array(); |
|
| 2105 | + } |
|
| 2106 | + if (!isset($context['css_files'])) { |
|
| 2107 | + $context['css_files'] = array(); |
|
| 2108 | + } |
|
| 2109 | + if (!isset($context['css_header'])) { |
|
| 2110 | + $context['css_header'] = array(); |
|
| 2111 | + } |
|
| 2112 | + if (!isset($context['javascript_inline'])) { |
|
| 2113 | + $context['javascript_inline'] = array('standard' => array(), 'defer' => array()); |
|
| 2114 | + } |
|
| 2115 | + if (!isset($context['javascript_vars'])) { |
|
| 2116 | + $context['javascript_vars'] = array(); |
|
| 2117 | + } |
|
| 2005 | 2118 | |
| 2006 | 2119 | $context['login_url'] = (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] < 2 ? strtr($scripturl, array('http://' => 'https://')) : $scripturl) . '?action=login2'; |
| 2007 | 2120 | $context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | '; |
@@ -2013,16 +2126,18 @@ discard block |
||
| 2013 | 2126 | $context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null; |
| 2014 | 2127 | $context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null; |
| 2015 | 2128 | $context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3; |
| 2016 | - if (isset($modSettings['load_average'])) |
|
| 2017 | - $context['load_average'] = $modSettings['load_average']; |
|
| 2129 | + if (isset($modSettings['load_average'])) { |
|
| 2130 | + $context['load_average'] = $modSettings['load_average']; |
|
| 2131 | + } |
|
| 2018 | 2132 | |
| 2019 | 2133 | // Detect the browser. This is separated out because it's also used in attachment downloads |
| 2020 | 2134 | detectBrowser(); |
| 2021 | 2135 | |
| 2022 | 2136 | // Set the top level linktree up. |
| 2023 | 2137 | // Note that if we're dealing with certain very early errors (e.g., login) the linktree might not be set yet... |
| 2024 | - if (empty($context['linktree'])) |
|
| 2025 | - $context['linktree'] = array(); |
|
| 2138 | + if (empty($context['linktree'])) { |
|
| 2139 | + $context['linktree'] = array(); |
|
| 2140 | + } |
|
| 2026 | 2141 | array_unshift($context['linktree'], array( |
| 2027 | 2142 | 'url' => $scripturl, |
| 2028 | 2143 | 'name' => $context['forum_name_html_safe'] |
@@ -2031,8 +2146,9 @@ discard block |
||
| 2031 | 2146 | // This allows sticking some HTML on the page output - useful for controls. |
| 2032 | 2147 | $context['insert_after_template'] = ''; |
| 2033 | 2148 | |
| 2034 | - if (!isset($txt)) |
|
| 2035 | - $txt = array(); |
|
| 2149 | + if (!isset($txt)) { |
|
| 2150 | + $txt = array(); |
|
| 2151 | + } |
|
| 2036 | 2152 | |
| 2037 | 2153 | $simpleActions = array( |
| 2038 | 2154 | 'findmember', |
@@ -2078,9 +2194,10 @@ discard block |
||
| 2078 | 2194 | |
| 2079 | 2195 | // See if theres any extra param to check. |
| 2080 | 2196 | $requiresXML = false; |
| 2081 | - foreach ($extraParams as $key => $extra) |
|
| 2082 | - if (isset($_REQUEST[$extra])) |
|
| 2197 | + foreach ($extraParams as $key => $extra) { |
|
| 2198 | + if (isset($_REQUEST[$extra])) |
|
| 2083 | 2199 | $requiresXML = true; |
| 2200 | + } |
|
| 2084 | 2201 | |
| 2085 | 2202 | // Output is fully XML, so no need for the index template. |
| 2086 | 2203 | if (isset($_REQUEST['xml']) && (in_array($context['current_action'], $xmlActions) || $requiresXML)) |
@@ -2095,37 +2212,39 @@ discard block |
||
| 2095 | 2212 | { |
| 2096 | 2213 | loadLanguage('index+Modifications'); |
| 2097 | 2214 | $context['template_layers'] = array(); |
| 2098 | - } |
|
| 2099 | - |
|
| 2100 | - else |
|
| 2215 | + } else |
|
| 2101 | 2216 | { |
| 2102 | 2217 | // Custom templates to load, or just default? |
| 2103 | - if (isset($settings['theme_templates'])) |
|
| 2104 | - $templates = explode(',', $settings['theme_templates']); |
|
| 2105 | - else |
|
| 2106 | - $templates = array('index'); |
|
| 2218 | + if (isset($settings['theme_templates'])) { |
|
| 2219 | + $templates = explode(',', $settings['theme_templates']); |
|
| 2220 | + } else { |
|
| 2221 | + $templates = array('index'); |
|
| 2222 | + } |
|
| 2107 | 2223 | |
| 2108 | 2224 | // Load each template... |
| 2109 | - foreach ($templates as $template) |
|
| 2110 | - loadTemplate($template); |
|
| 2225 | + foreach ($templates as $template) { |
|
| 2226 | + loadTemplate($template); |
|
| 2227 | + } |
|
| 2111 | 2228 | |
| 2112 | 2229 | // ...and attempt to load their associated language files. |
| 2113 | 2230 | $required_files = implode('+', array_merge($templates, array('Modifications'))); |
| 2114 | 2231 | loadLanguage($required_files, '', false); |
| 2115 | 2232 | |
| 2116 | 2233 | // Custom template layers? |
| 2117 | - if (isset($settings['theme_layers'])) |
|
| 2118 | - $context['template_layers'] = explode(',', $settings['theme_layers']); |
|
| 2119 | - else |
|
| 2120 | - $context['template_layers'] = array('html', 'body'); |
|
| 2234 | + if (isset($settings['theme_layers'])) { |
|
| 2235 | + $context['template_layers'] = explode(',', $settings['theme_layers']); |
|
| 2236 | + } else { |
|
| 2237 | + $context['template_layers'] = array('html', 'body'); |
|
| 2238 | + } |
|
| 2121 | 2239 | } |
| 2122 | 2240 | |
| 2123 | 2241 | // Initialize the theme. |
| 2124 | 2242 | loadSubTemplate('init', 'ignore'); |
| 2125 | 2243 | |
| 2126 | 2244 | // Allow overriding the board wide time/number formats. |
| 2127 | - if (empty($user_settings['time_format']) && !empty($txt['time_format'])) |
|
| 2128 | - $user_info['time_format'] = $txt['time_format']; |
|
| 2245 | + if (empty($user_settings['time_format']) && !empty($txt['time_format'])) { |
|
| 2246 | + $user_info['time_format'] = $txt['time_format']; |
|
| 2247 | + } |
|
| 2129 | 2248 | |
| 2130 | 2249 | // Set the character set from the template. |
| 2131 | 2250 | $context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']; |
@@ -2133,12 +2252,14 @@ discard block |
||
| 2133 | 2252 | $context['right_to_left'] = !empty($txt['lang_rtl']); |
| 2134 | 2253 | |
| 2135 | 2254 | // Guests may still need a name. |
| 2136 | - if ($context['user']['is_guest'] && empty($context['user']['name'])) |
|
| 2137 | - $context['user']['name'] = $txt['guest_title']; |
|
| 2255 | + if ($context['user']['is_guest'] && empty($context['user']['name'])) { |
|
| 2256 | + $context['user']['name'] = $txt['guest_title']; |
|
| 2257 | + } |
|
| 2138 | 2258 | |
| 2139 | 2259 | // Any theme-related strings that need to be loaded? |
| 2140 | - if (!empty($settings['require_theme_strings'])) |
|
| 2141 | - loadLanguage('ThemeStrings', '', false); |
|
| 2260 | + if (!empty($settings['require_theme_strings'])) { |
|
| 2261 | + loadLanguage('ThemeStrings', '', false); |
|
| 2262 | + } |
|
| 2142 | 2263 | |
| 2143 | 2264 | // Make a special URL for the language. |
| 2144 | 2265 | $settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']); |
@@ -2149,8 +2270,9 @@ discard block |
||
| 2149 | 2270 | // Here is my luvly Responsive CSS |
| 2150 | 2271 | loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true), 'smf_responsive'); |
| 2151 | 2272 | |
| 2152 | - if ($context['right_to_left']) |
|
| 2153 | - loadCSSFile('rtl.css', array(), 'smf_rtl'); |
|
| 2273 | + if ($context['right_to_left']) { |
|
| 2274 | + loadCSSFile('rtl.css', array(), 'smf_rtl'); |
|
| 2275 | + } |
|
| 2154 | 2276 | |
| 2155 | 2277 | // We allow theme variants, because we're cool. |
| 2156 | 2278 | $context['theme_variant'] = ''; |
@@ -2158,14 +2280,17 @@ discard block |
||
| 2158 | 2280 | if (!empty($settings['theme_variants'])) |
| 2159 | 2281 | { |
| 2160 | 2282 | // Overriding - for previews and that ilk. |
| 2161 | - if (!empty($_REQUEST['variant'])) |
|
| 2162 | - $_SESSION['id_variant'] = $_REQUEST['variant']; |
|
| 2283 | + if (!empty($_REQUEST['variant'])) { |
|
| 2284 | + $_SESSION['id_variant'] = $_REQUEST['variant']; |
|
| 2285 | + } |
|
| 2163 | 2286 | // User selection? |
| 2164 | - if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) |
|
| 2165 | - $context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : ''); |
|
| 2287 | + if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) { |
|
| 2288 | + $context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : ''); |
|
| 2289 | + } |
|
| 2166 | 2290 | // If not a user variant, select the default. |
| 2167 | - if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) |
|
| 2168 | - $context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0]; |
|
| 2291 | + if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) { |
|
| 2292 | + $context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0]; |
|
| 2293 | + } |
|
| 2169 | 2294 | |
| 2170 | 2295 | // Do this to keep things easier in the templates. |
| 2171 | 2296 | $context['theme_variant'] = '_' . $context['theme_variant']; |
@@ -2174,20 +2299,23 @@ discard block |
||
| 2174 | 2299 | if (!empty($context['theme_variant'])) |
| 2175 | 2300 | { |
| 2176 | 2301 | loadCSSFile('index' . $context['theme_variant'] . '.css', array(), 'smf_index' . $context['theme_variant']); |
| 2177 | - if ($context['right_to_left']) |
|
| 2178 | - loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']); |
|
| 2302 | + if ($context['right_to_left']) { |
|
| 2303 | + loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']); |
|
| 2304 | + } |
|
| 2179 | 2305 | } |
| 2180 | 2306 | } |
| 2181 | 2307 | |
| 2182 | 2308 | // Let's be compatible with old themes! |
| 2183 | - if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) |
|
| 2184 | - $context['template_layers'] = array('main'); |
|
| 2309 | + if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) { |
|
| 2310 | + $context['template_layers'] = array('main'); |
|
| 2311 | + } |
|
| 2185 | 2312 | |
| 2186 | 2313 | $context['tabindex'] = 1; |
| 2187 | 2314 | |
| 2188 | 2315 | // Compatibility. |
| 2189 | - if (!isset($settings['theme_version'])) |
|
| 2190 | - $modSettings['memberCount'] = $modSettings['totalMembers']; |
|
| 2316 | + if (!isset($settings['theme_version'])) { |
|
| 2317 | + $modSettings['memberCount'] = $modSettings['totalMembers']; |
|
| 2318 | + } |
|
| 2191 | 2319 | |
| 2192 | 2320 | // Default JS variables for use in every theme |
| 2193 | 2321 | $context['javascript_vars'] = array( |
@@ -2206,18 +2334,18 @@ discard block |
||
| 2206 | 2334 | ); |
| 2207 | 2335 | |
| 2208 | 2336 | // Add the JQuery library to the list of files to load. |
| 2209 | - if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') |
|
| 2210 | - loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
| 2211 | - |
|
| 2212 | - elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') |
|
| 2213 | - loadJavaScriptFile('jquery-3.2.1.min.js', array('seed' => false), 'smf_jquery'); |
|
| 2214 | - |
|
| 2215 | - elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') |
|
| 2216 | - loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery'); |
|
| 2337 | + if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') { |
|
| 2338 | + loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
| 2339 | + } elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') { |
|
| 2340 | + loadJavaScriptFile('jquery-3.2.1.min.js', array('seed' => false), 'smf_jquery'); |
|
| 2341 | + } elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') { |
|
| 2342 | + loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery'); |
|
| 2343 | + } |
|
| 2217 | 2344 | |
| 2218 | 2345 | // Auto loading? template_javascript() will take care of the local half of this. |
| 2219 | - else |
|
| 2220 | - loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
| 2346 | + else { |
|
| 2347 | + loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
| 2348 | + } |
|
| 2221 | 2349 | |
| 2222 | 2350 | // Queue our JQuery plugins! |
| 2223 | 2351 | loadJavaScriptFile('smf_jquery_plugins.js', array('minimize' => true), 'smf_jquery_plugins'); |
@@ -2240,12 +2368,12 @@ discard block |
||
| 2240 | 2368 | require_once($sourcedir . '/ScheduledTasks.php'); |
| 2241 | 2369 | |
| 2242 | 2370 | // What to do, what to do?! |
| 2243 | - if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) |
|
| 2244 | - AutoTask(); |
|
| 2245 | - else |
|
| 2246 | - ReduceMailQueue(); |
|
| 2247 | - } |
|
| 2248 | - else |
|
| 2371 | + if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) { |
|
| 2372 | + AutoTask(); |
|
| 2373 | + } else { |
|
| 2374 | + ReduceMailQueue(); |
|
| 2375 | + } |
|
| 2376 | + } else |
|
| 2249 | 2377 | { |
| 2250 | 2378 | $type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq'; |
| 2251 | 2379 | $ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time']; |
@@ -2296,8 +2424,9 @@ discard block |
||
| 2296 | 2424 | foreach ($theme_includes as $include) |
| 2297 | 2425 | { |
| 2298 | 2426 | $include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
| 2299 | - if (file_exists($include)) |
|
| 2300 | - require_once($include); |
|
| 2427 | + if (file_exists($include)) { |
|
| 2428 | + require_once($include); |
|
| 2429 | + } |
|
| 2301 | 2430 | } |
| 2302 | 2431 | } |
| 2303 | 2432 | |
@@ -2327,16 +2456,19 @@ discard block |
||
| 2327 | 2456 | // Do any style sheets first, cause we're easy with those. |
| 2328 | 2457 | if (!empty($style_sheets)) |
| 2329 | 2458 | { |
| 2330 | - if (!is_array($style_sheets)) |
|
| 2331 | - $style_sheets = array($style_sheets); |
|
| 2459 | + if (!is_array($style_sheets)) { |
|
| 2460 | + $style_sheets = array($style_sheets); |
|
| 2461 | + } |
|
| 2332 | 2462 | |
| 2333 | - foreach ($style_sheets as $sheet) |
|
| 2334 | - loadCSSFile($sheet . '.css', array(), $sheet); |
|
| 2463 | + foreach ($style_sheets as $sheet) { |
|
| 2464 | + loadCSSFile($sheet . '.css', array(), $sheet); |
|
| 2465 | + } |
|
| 2335 | 2466 | } |
| 2336 | 2467 | |
| 2337 | 2468 | // No template to load? |
| 2338 | - if ($template_name === false) |
|
| 2339 | - return true; |
|
| 2469 | + if ($template_name === false) { |
|
| 2470 | + return true; |
|
| 2471 | + } |
|
| 2340 | 2472 | |
| 2341 | 2473 | $loaded = false; |
| 2342 | 2474 | foreach ($settings['template_dirs'] as $template_dir) |
@@ -2351,12 +2483,14 @@ discard block |
||
| 2351 | 2483 | |
| 2352 | 2484 | if ($loaded) |
| 2353 | 2485 | { |
| 2354 | - if ($db_show_debug === true) |
|
| 2355 | - $context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')'; |
|
| 2486 | + if ($db_show_debug === true) { |
|
| 2487 | + $context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')'; |
|
| 2488 | + } |
|
| 2356 | 2489 | |
| 2357 | 2490 | // If they have specified an initialization function for this template, go ahead and call it now. |
| 2358 | - if (function_exists('template_' . $template_name . '_init')) |
|
| 2359 | - call_user_func('template_' . $template_name . '_init'); |
|
| 2491 | + if (function_exists('template_' . $template_name . '_init')) { |
|
| 2492 | + call_user_func('template_' . $template_name . '_init'); |
|
| 2493 | + } |
|
| 2360 | 2494 | } |
| 2361 | 2495 | // Hmmm... doesn't exist?! I don't suppose the directory is wrong, is it? |
| 2362 | 2496 | elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default')) |
@@ -2376,13 +2510,14 @@ discard block |
||
| 2376 | 2510 | loadTemplate($template_name); |
| 2377 | 2511 | } |
| 2378 | 2512 | // Cause an error otherwise. |
| 2379 | - elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) |
|
| 2380 | - fatal_lang_error('theme_template_error', 'template', array((string) $template_name)); |
|
| 2381 | - elseif ($fatal) |
|
| 2382 | - die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template')); |
|
| 2383 | - else |
|
| 2384 | - return false; |
|
| 2385 | -} |
|
| 2513 | + elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) { |
|
| 2514 | + fatal_lang_error('theme_template_error', 'template', array((string) $template_name)); |
|
| 2515 | + } elseif ($fatal) { |
|
| 2516 | + die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template')); |
|
| 2517 | + } else { |
|
| 2518 | + return false; |
|
| 2519 | + } |
|
| 2520 | + } |
|
| 2386 | 2521 | |
| 2387 | 2522 | /** |
| 2388 | 2523 | * Load a sub-template. |
@@ -2400,17 +2535,19 @@ discard block |
||
| 2400 | 2535 | { |
| 2401 | 2536 | global $context, $txt, $db_show_debug; |
| 2402 | 2537 | |
| 2403 | - if ($db_show_debug === true) |
|
| 2404 | - $context['debug']['sub_templates'][] = $sub_template_name; |
|
| 2538 | + if ($db_show_debug === true) { |
|
| 2539 | + $context['debug']['sub_templates'][] = $sub_template_name; |
|
| 2540 | + } |
|
| 2405 | 2541 | |
| 2406 | 2542 | // Figure out what the template function is named. |
| 2407 | 2543 | $theme_function = 'template_' . $sub_template_name; |
| 2408 | - if (function_exists($theme_function)) |
|
| 2409 | - $theme_function(); |
|
| 2410 | - elseif ($fatal === false) |
|
| 2411 | - fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name)); |
|
| 2412 | - elseif ($fatal !== 'ignore') |
|
| 2413 | - die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template')); |
|
| 2544 | + if (function_exists($theme_function)) { |
|
| 2545 | + $theme_function(); |
|
| 2546 | + } elseif ($fatal === false) { |
|
| 2547 | + fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name)); |
|
| 2548 | + } elseif ($fatal !== 'ignore') { |
|
| 2549 | + die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template')); |
|
| 2550 | + } |
|
| 2414 | 2551 | |
| 2415 | 2552 | // Are we showing debugging for templates? Just make sure not to do it before the doctype... |
| 2416 | 2553 | if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml'])) |
@@ -2447,8 +2584,9 @@ discard block |
||
| 2447 | 2584 | $params['validate'] = isset($params['validate']) ? $params['validate'] : true; |
| 2448 | 2585 | |
| 2449 | 2586 | // If this is an external file, automatically set this to false. |
| 2450 | - if (!empty($params['external'])) |
|
| 2451 | - $params['minimize'] = false; |
|
| 2587 | + if (!empty($params['external'])) { |
|
| 2588 | + $params['minimize'] = false; |
|
| 2589 | + } |
|
| 2452 | 2590 | |
| 2453 | 2591 | // Account for shorthand like admin.css?alp21 filenames |
| 2454 | 2592 | $has_seed = strpos($fileName, '.css?'); |
@@ -2465,13 +2603,10 @@ discard block |
||
| 2465 | 2603 | { |
| 2466 | 2604 | $fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
| 2467 | 2605 | $filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
| 2606 | + } else { |
|
| 2607 | + $fileUrl = false; |
|
| 2468 | 2608 | } |
| 2469 | - |
|
| 2470 | - else |
|
| 2471 | - $fileUrl = false; |
|
| 2472 | - } |
|
| 2473 | - |
|
| 2474 | - else |
|
| 2609 | + } else |
|
| 2475 | 2610 | { |
| 2476 | 2611 | $fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
| 2477 | 2612 | $filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
@@ -2486,12 +2621,14 @@ discard block |
||
| 2486 | 2621 | } |
| 2487 | 2622 | |
| 2488 | 2623 | // Add it to the array for use in the template |
| 2489 | - if (!empty($fileName)) |
|
| 2490 | - $context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params); |
|
| 2624 | + if (!empty($fileName)) { |
|
| 2625 | + $context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params); |
|
| 2626 | + } |
|
| 2491 | 2627 | |
| 2492 | - if (!empty($context['right_to_left']) && !empty($params['rtl'])) |
|
| 2493 | - loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0))); |
|
| 2494 | -} |
|
| 2628 | + if (!empty($context['right_to_left']) && !empty($params['rtl'])) { |
|
| 2629 | + loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0))); |
|
| 2630 | + } |
|
| 2631 | + } |
|
| 2495 | 2632 | |
| 2496 | 2633 | /** |
| 2497 | 2634 | * Add a block of inline css code to be executed later |
@@ -2508,8 +2645,9 @@ discard block |
||
| 2508 | 2645 | global $context; |
| 2509 | 2646 | |
| 2510 | 2647 | // Gotta add something... |
| 2511 | - if (empty($css)) |
|
| 2512 | - return false; |
|
| 2648 | + if (empty($css)) { |
|
| 2649 | + return false; |
|
| 2650 | + } |
|
| 2513 | 2651 | |
| 2514 | 2652 | $context['css_header'][] = $css; |
| 2515 | 2653 | } |
@@ -2544,8 +2682,9 @@ discard block |
||
| 2544 | 2682 | $params['validate'] = isset($params['validate']) ? $params['validate'] : true; |
| 2545 | 2683 | |
| 2546 | 2684 | // If this is an external file, automatically set this to false. |
| 2547 | - if (!empty($params['external'])) |
|
| 2548 | - $params['minimize'] = false; |
|
| 2685 | + if (!empty($params['external'])) { |
|
| 2686 | + $params['minimize'] = false; |
|
| 2687 | + } |
|
| 2549 | 2688 | |
| 2550 | 2689 | // Account for shorthand like admin.js?alp21 filenames |
| 2551 | 2690 | $has_seed = strpos($fileName, '.js?'); |
@@ -2562,16 +2701,12 @@ discard block |
||
| 2562 | 2701 | { |
| 2563 | 2702 | $fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
| 2564 | 2703 | $filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
| 2565 | - } |
|
| 2566 | - |
|
| 2567 | - else |
|
| 2704 | + } else |
|
| 2568 | 2705 | { |
| 2569 | 2706 | $fileUrl = false; |
| 2570 | 2707 | $filePath = false; |
| 2571 | 2708 | } |
| 2572 | - } |
|
| 2573 | - |
|
| 2574 | - else |
|
| 2709 | + } else |
|
| 2575 | 2710 | { |
| 2576 | 2711 | $fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
| 2577 | 2712 | $filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
@@ -2586,9 +2721,10 @@ discard block |
||
| 2586 | 2721 | } |
| 2587 | 2722 | |
| 2588 | 2723 | // Add it to the array for use in the template |
| 2589 | - if (!empty($fileName)) |
|
| 2590 | - $context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params); |
|
| 2591 | -} |
|
| 2724 | + if (!empty($fileName)) { |
|
| 2725 | + $context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params); |
|
| 2726 | + } |
|
| 2727 | + } |
|
| 2592 | 2728 | |
| 2593 | 2729 | /** |
| 2594 | 2730 | * Add a Javascript variable for output later (for feeding text strings and similar to JS) |
@@ -2602,9 +2738,10 @@ discard block |
||
| 2602 | 2738 | { |
| 2603 | 2739 | global $context; |
| 2604 | 2740 | |
| 2605 | - if (!empty($key) && (!empty($value) || $value === '0')) |
|
| 2606 | - $context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value; |
|
| 2607 | -} |
|
| 2741 | + if (!empty($key) && (!empty($value) || $value === '0')) { |
|
| 2742 | + $context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value; |
|
| 2743 | + } |
|
| 2744 | + } |
|
| 2608 | 2745 | |
| 2609 | 2746 | /** |
| 2610 | 2747 | * Add a block of inline Javascript code to be executed later |
@@ -2621,8 +2758,9 @@ discard block |
||
| 2621 | 2758 | { |
| 2622 | 2759 | global $context; |
| 2623 | 2760 | |
| 2624 | - if (empty($javascript)) |
|
| 2625 | - return false; |
|
| 2761 | + if (empty($javascript)) { |
|
| 2762 | + return false; |
|
| 2763 | + } |
|
| 2626 | 2764 | |
| 2627 | 2765 | $context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript; |
| 2628 | 2766 | } |
@@ -2643,15 +2781,18 @@ discard block |
||
| 2643 | 2781 | static $already_loaded = array(); |
| 2644 | 2782 | |
| 2645 | 2783 | // Default to the user's language. |
| 2646 | - if ($lang == '') |
|
| 2647 | - $lang = isset($user_info['language']) ? $user_info['language'] : $language; |
|
| 2784 | + if ($lang == '') { |
|
| 2785 | + $lang = isset($user_info['language']) ? $user_info['language'] : $language; |
|
| 2786 | + } |
|
| 2648 | 2787 | |
| 2649 | 2788 | // Do we want the English version of language file as fallback? |
| 2650 | - if (empty($modSettings['disable_language_fallback']) && $lang != 'english') |
|
| 2651 | - loadLanguage($template_name, 'english', false); |
|
| 2789 | + if (empty($modSettings['disable_language_fallback']) && $lang != 'english') { |
|
| 2790 | + loadLanguage($template_name, 'english', false); |
|
| 2791 | + } |
|
| 2652 | 2792 | |
| 2653 | - if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) |
|
| 2654 | - return $lang; |
|
| 2793 | + if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) { |
|
| 2794 | + return $lang; |
|
| 2795 | + } |
|
| 2655 | 2796 | |
| 2656 | 2797 | // Make sure we have $settings - if not we're in trouble and need to find it! |
| 2657 | 2798 | if (empty($settings['default_theme_dir'])) |
@@ -2662,8 +2803,9 @@ discard block |
||
| 2662 | 2803 | |
| 2663 | 2804 | // What theme are we in? |
| 2664 | 2805 | $theme_name = basename($settings['theme_url']); |
| 2665 | - if (empty($theme_name)) |
|
| 2666 | - $theme_name = 'unknown'; |
|
| 2806 | + if (empty($theme_name)) { |
|
| 2807 | + $theme_name = 'unknown'; |
|
| 2808 | + } |
|
| 2667 | 2809 | |
| 2668 | 2810 | // For each file open it up and write it out! |
| 2669 | 2811 | foreach (explode('+', $template_name) as $template) |
@@ -2705,8 +2847,9 @@ discard block |
||
| 2705 | 2847 | $found = true; |
| 2706 | 2848 | |
| 2707 | 2849 | // setlocale is required for basename() & pathinfo() to work properly on the selected language |
| 2708 | - if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set'])) |
|
| 2709 | - setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']); |
|
| 2850 | + if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set'])) { |
|
| 2851 | + setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']); |
|
| 2852 | + } |
|
| 2710 | 2853 | |
| 2711 | 2854 | break; |
| 2712 | 2855 | } |
@@ -2746,8 +2889,9 @@ discard block |
||
| 2746 | 2889 | } |
| 2747 | 2890 | |
| 2748 | 2891 | // Keep track of what we're up to soldier. |
| 2749 | - if ($db_show_debug === true) |
|
| 2750 | - $context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')'; |
|
| 2892 | + if ($db_show_debug === true) { |
|
| 2893 | + $context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')'; |
|
| 2894 | + } |
|
| 2751 | 2895 | |
| 2752 | 2896 | // Remember what we have loaded, and in which language. |
| 2753 | 2897 | $already_loaded[$template_name] = $lang; |
@@ -2793,8 +2937,9 @@ discard block |
||
| 2793 | 2937 | ) |
| 2794 | 2938 | ); |
| 2795 | 2939 | // In the EXTREMELY unlikely event this happens, give an error message. |
| 2796 | - if ($smcFunc['db_num_rows']($result) == 0) |
|
| 2797 | - fatal_lang_error('parent_not_found', 'critical'); |
|
| 2940 | + if ($smcFunc['db_num_rows']($result) == 0) { |
|
| 2941 | + fatal_lang_error('parent_not_found', 'critical'); |
|
| 2942 | + } |
|
| 2798 | 2943 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
| 2799 | 2944 | { |
| 2800 | 2945 | if (!isset($boards[$row['id_board']])) |
@@ -2811,8 +2956,8 @@ discard block |
||
| 2811 | 2956 | ); |
| 2812 | 2957 | } |
| 2813 | 2958 | // If a moderator exists for this board, add that moderator for all children too. |
| 2814 | - if (!empty($row['id_moderator'])) |
|
| 2815 | - foreach ($boards as $id => $dummy) |
|
| 2959 | + if (!empty($row['id_moderator'])) { |
|
| 2960 | + foreach ($boards as $id => $dummy) |
|
| 2816 | 2961 | { |
| 2817 | 2962 | $boards[$id]['moderators'][$row['id_moderator']] = array( |
| 2818 | 2963 | 'id' => $row['id_moderator'], |
@@ -2820,11 +2965,12 @@ discard block |
||
| 2820 | 2965 | 'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'], |
| 2821 | 2966 | 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>' |
| 2822 | 2967 | ); |
| 2968 | + } |
|
| 2823 | 2969 | } |
| 2824 | 2970 | |
| 2825 | 2971 | // If a moderator group exists for this board, add that moderator group for all children too |
| 2826 | - if (!empty($row['id_moderator_group'])) |
|
| 2827 | - foreach ($boards as $id => $dummy) |
|
| 2972 | + if (!empty($row['id_moderator_group'])) { |
|
| 2973 | + foreach ($boards as $id => $dummy) |
|
| 2828 | 2974 | { |
| 2829 | 2975 | $boards[$id]['moderator_groups'][$row['id_moderator_group']] = array( |
| 2830 | 2976 | 'id' => $row['id_moderator_group'], |
@@ -2832,6 +2978,7 @@ discard block |
||
| 2832 | 2978 | 'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'], |
| 2833 | 2979 | 'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>' |
| 2834 | 2980 | ); |
| 2981 | + } |
|
| 2835 | 2982 | } |
| 2836 | 2983 | } |
| 2837 | 2984 | $smcFunc['db_free_result']($result); |
@@ -2858,23 +3005,27 @@ discard block |
||
| 2858 | 3005 | if (!$use_cache || ($context['languages'] = cache_get_data('known_languages', !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null) |
| 2859 | 3006 | { |
| 2860 | 3007 | // If we don't have our ucwords function defined yet, let's load the settings data. |
| 2861 | - if (empty($smcFunc['ucwords'])) |
|
| 2862 | - reloadSettings(); |
|
| 3008 | + if (empty($smcFunc['ucwords'])) { |
|
| 3009 | + reloadSettings(); |
|
| 3010 | + } |
|
| 2863 | 3011 | |
| 2864 | 3012 | // If we don't have our theme information yet, let's get it. |
| 2865 | - if (empty($settings['default_theme_dir'])) |
|
| 2866 | - loadTheme(0, false); |
|
| 3013 | + if (empty($settings['default_theme_dir'])) { |
|
| 3014 | + loadTheme(0, false); |
|
| 3015 | + } |
|
| 2867 | 3016 | |
| 2868 | 3017 | // Default language directories to try. |
| 2869 | 3018 | $language_directories = array( |
| 2870 | 3019 | $settings['default_theme_dir'] . '/languages', |
| 2871 | 3020 | ); |
| 2872 | - if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) |
|
| 2873 | - $language_directories[] = $settings['actual_theme_dir'] . '/languages'; |
|
| 3021 | + if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) { |
|
| 3022 | + $language_directories[] = $settings['actual_theme_dir'] . '/languages'; |
|
| 3023 | + } |
|
| 2874 | 3024 | |
| 2875 | 3025 | // We possibly have a base theme directory. |
| 2876 | - if (!empty($settings['base_theme_dir'])) |
|
| 2877 | - $language_directories[] = $settings['base_theme_dir'] . '/languages'; |
|
| 3026 | + if (!empty($settings['base_theme_dir'])) { |
|
| 3027 | + $language_directories[] = $settings['base_theme_dir'] . '/languages'; |
|
| 3028 | + } |
|
| 2878 | 3029 | |
| 2879 | 3030 | // Remove any duplicates. |
| 2880 | 3031 | $language_directories = array_unique($language_directories); |
@@ -2888,20 +3039,21 @@ discard block |
||
| 2888 | 3039 | foreach ($language_directories as $language_dir) |
| 2889 | 3040 | { |
| 2890 | 3041 | // Can't look in here... doesn't exist! |
| 2891 | - if (!file_exists($language_dir)) |
|
| 2892 | - continue; |
|
| 3042 | + if (!file_exists($language_dir)) { |
|
| 3043 | + continue; |
|
| 3044 | + } |
|
| 2893 | 3045 | |
| 2894 | 3046 | $dir = dir($language_dir); |
| 2895 | 3047 | while ($entry = $dir->read()) |
| 2896 | 3048 | { |
| 2897 | 3049 | // Look for the index language file... For good measure skip any "index.language-utf8.php" files |
| 2898 | - if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) |
|
| 2899 | - continue; |
|
| 2900 | - |
|
| 2901 | - if (!empty($langList) && !empty($langList[$matches[1]])) |
|
| 2902 | - $langName = $langList[$matches[1]]; |
|
| 3050 | + if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) { |
|
| 3051 | + continue; |
|
| 3052 | + } |
|
| 2903 | 3053 | |
| 2904 | - else |
|
| 3054 | + if (!empty($langList) && !empty($langList[$matches[1]])) { |
|
| 3055 | + $langName = $langList[$matches[1]]; |
|
| 3056 | + } else |
|
| 2905 | 3057 | { |
| 2906 | 3058 | $langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' '))); |
| 2907 | 3059 | |
@@ -2942,12 +3094,14 @@ discard block |
||
| 2942 | 3094 | } |
| 2943 | 3095 | |
| 2944 | 3096 | // Do we need to store the lang list? |
| 2945 | - if (empty($langList)) |
|
| 2946 | - updateSettings(array('langList' => $smcFunc['json_encode']($catchLang))); |
|
| 3097 | + if (empty($langList)) { |
|
| 3098 | + updateSettings(array('langList' => $smcFunc['json_encode']($catchLang))); |
|
| 3099 | + } |
|
| 2947 | 3100 | |
| 2948 | 3101 | // Let's cash in on this deal. |
| 2949 | - if (!empty($modSettings['cache_enable'])) |
|
| 2950 | - cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600); |
|
| 3102 | + if (!empty($modSettings['cache_enable'])) { |
|
| 3103 | + cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600); |
|
| 3104 | + } |
|
| 2951 | 3105 | } |
| 2952 | 3106 | |
| 2953 | 3107 | return $context['languages']; |
@@ -2970,8 +3124,9 @@ discard block |
||
| 2970 | 3124 | global $modSettings, $options, $txt; |
| 2971 | 3125 | static $censor_vulgar = null, $censor_proper; |
| 2972 | 3126 | |
| 2973 | - if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') |
|
| 2974 | - return $text; |
|
| 3127 | + if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') { |
|
| 3128 | + return $text; |
|
| 3129 | + } |
|
| 2975 | 3130 | |
| 2976 | 3131 | // If they haven't yet been loaded, load them. |
| 2977 | 3132 | if ($censor_vulgar == null) |
@@ -2999,9 +3154,9 @@ discard block |
||
| 2999 | 3154 | { |
| 3000 | 3155 | $func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace'; |
| 3001 | 3156 | $text = $func($censor_vulgar, $censor_proper, $text); |
| 3157 | + } else { |
|
| 3158 | + $text = preg_replace($censor_vulgar, $censor_proper, $text); |
|
| 3002 | 3159 | } |
| 3003 | - else |
|
| 3004 | - $text = preg_replace($censor_vulgar, $censor_proper, $text); |
|
| 3005 | 3160 | |
| 3006 | 3161 | return $text; |
| 3007 | 3162 | } |
@@ -3027,38 +3182,42 @@ discard block |
||
| 3027 | 3182 | @ini_set('track_errors', '1'); |
| 3028 | 3183 | |
| 3029 | 3184 | // Don't include the file more than once, if $once is true. |
| 3030 | - if ($once && in_array($filename, $templates)) |
|
| 3031 | - return; |
|
| 3185 | + if ($once && in_array($filename, $templates)) { |
|
| 3186 | + return; |
|
| 3187 | + } |
|
| 3032 | 3188 | // Add this file to the include list, whether $once is true or not. |
| 3033 | - else |
|
| 3034 | - $templates[] = $filename; |
|
| 3189 | + else { |
|
| 3190 | + $templates[] = $filename; |
|
| 3191 | + } |
|
| 3035 | 3192 | |
| 3036 | 3193 | // Are we going to use eval? |
| 3037 | 3194 | if (empty($modSettings['disableTemplateEval'])) |
| 3038 | 3195 | { |
| 3039 | 3196 | $file_found = file_exists($filename) && eval('?' . '>' . rtrim(file_get_contents($filename))) !== false; |
| 3040 | 3197 | $settings['current_include_filename'] = $filename; |
| 3041 | - } |
|
| 3042 | - else |
|
| 3198 | + } else |
|
| 3043 | 3199 | { |
| 3044 | 3200 | $file_found = file_exists($filename); |
| 3045 | 3201 | |
| 3046 | - if ($once && $file_found) |
|
| 3047 | - require_once($filename); |
|
| 3048 | - elseif ($file_found) |
|
| 3049 | - require($filename); |
|
| 3202 | + if ($once && $file_found) { |
|
| 3203 | + require_once($filename); |
|
| 3204 | + } elseif ($file_found) { |
|
| 3205 | + require($filename); |
|
| 3206 | + } |
|
| 3050 | 3207 | } |
| 3051 | 3208 | |
| 3052 | 3209 | if ($file_found !== true) |
| 3053 | 3210 | { |
| 3054 | 3211 | ob_end_clean(); |
| 3055 | - if (!empty($modSettings['enableCompressedOutput'])) |
|
| 3056 | - @ob_start('ob_gzhandler'); |
|
| 3057 | - else |
|
| 3058 | - ob_start(); |
|
| 3212 | + if (!empty($modSettings['enableCompressedOutput'])) { |
|
| 3213 | + @ob_start('ob_gzhandler'); |
|
| 3214 | + } else { |
|
| 3215 | + ob_start(); |
|
| 3216 | + } |
|
| 3059 | 3217 | |
| 3060 | - if (isset($_GET['debug'])) |
|
| 3061 | - header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
| 3218 | + if (isset($_GET['debug'])) { |
|
| 3219 | + header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
| 3220 | + } |
|
| 3062 | 3221 | |
| 3063 | 3222 | // Don't cache error pages!! |
| 3064 | 3223 | header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); |
@@ -3077,12 +3236,13 @@ discard block |
||
| 3077 | 3236 | echo '<!DOCTYPE html> |
| 3078 | 3237 | <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '> |
| 3079 | 3238 | <head>'; |
| 3080 | - if (isset($context['character_set'])) |
|
| 3081 | - echo ' |
|
| 3239 | + if (isset($context['character_set'])) { |
|
| 3240 | + echo ' |
|
| 3082 | 3241 | <meta charset="', $context['character_set'], '">'; |
| 3242 | + } |
|
| 3083 | 3243 | |
| 3084 | - if (!empty($maintenance) && !allowedTo('admin_forum')) |
|
| 3085 | - echo ' |
|
| 3244 | + if (!empty($maintenance) && !allowedTo('admin_forum')) { |
|
| 3245 | + echo ' |
|
| 3086 | 3246 | <title>', $mtitle, '</title> |
| 3087 | 3247 | </head> |
| 3088 | 3248 | <body> |
@@ -3090,8 +3250,8 @@ discard block |
||
| 3090 | 3250 | ', $mmessage, ' |
| 3091 | 3251 | </body> |
| 3092 | 3252 | </html>'; |
| 3093 | - elseif (!allowedTo('admin_forum')) |
|
| 3094 | - echo ' |
|
| 3253 | + } elseif (!allowedTo('admin_forum')) { |
|
| 3254 | + echo ' |
|
| 3095 | 3255 | <title>', $txt['template_parse_error'], '</title> |
| 3096 | 3256 | </head> |
| 3097 | 3257 | <body> |
@@ -3099,16 +3259,18 @@ discard block |
||
| 3099 | 3259 | ', $txt['template_parse_error_message'], ' |
| 3100 | 3260 | </body> |
| 3101 | 3261 | </html>'; |
| 3102 | - else |
|
| 3262 | + } else |
|
| 3103 | 3263 | { |
| 3104 | 3264 | require_once($sourcedir . '/Subs-Package.php'); |
| 3105 | 3265 | |
| 3106 | 3266 | $error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => ''))); |
| 3107 | 3267 | $error_array = error_get_last(); |
| 3108 | - if (empty($error) && ini_get('track_errors') && !empty($error_array)) |
|
| 3109 | - $error = $error_array['message']; |
|
| 3110 | - if (empty($error)) |
|
| 3111 | - $error = $txt['template_parse_errmsg']; |
|
| 3268 | + if (empty($error) && ini_get('track_errors') && !empty($error_array)) { |
|
| 3269 | + $error = $error_array['message']; |
|
| 3270 | + } |
|
| 3271 | + if (empty($error)) { |
|
| 3272 | + $error = $txt['template_parse_errmsg']; |
|
| 3273 | + } |
|
| 3112 | 3274 | |
| 3113 | 3275 | $error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>')); |
| 3114 | 3276 | |
@@ -3119,11 +3281,12 @@ discard block |
||
| 3119 | 3281 | <h3>', $txt['template_parse_error'], '</h3> |
| 3120 | 3282 | ', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => ''))); |
| 3121 | 3283 | |
| 3122 | - if (!empty($error)) |
|
| 3123 | - echo ' |
|
| 3284 | + if (!empty($error)) { |
|
| 3285 | + echo ' |
|
| 3124 | 3286 | <hr> |
| 3125 | 3287 | |
| 3126 | 3288 | <div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>'; |
| 3289 | + } |
|
| 3127 | 3290 | |
| 3128 | 3291 | // I know, I know... this is VERY COMPLICATED. Still, it's good. |
| 3129 | 3292 | if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0) |
@@ -3133,10 +3296,11 @@ discard block |
||
| 3133 | 3296 | $data2 = preg_split('~\<br( /)?\>~', $data2); |
| 3134 | 3297 | |
| 3135 | 3298 | // Fix the PHP code stuff... |
| 3136 | - if (!isBrowser('gecko')) |
|
| 3137 | - $data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2); |
|
| 3138 | - else |
|
| 3139 | - $data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2); |
|
| 3299 | + if (!isBrowser('gecko')) { |
|
| 3300 | + $data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2); |
|
| 3301 | + } else { |
|
| 3302 | + $data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2); |
|
| 3303 | + } |
|
| 3140 | 3304 | |
| 3141 | 3305 | // Now we get to work around a bug in PHP where it doesn't escape <br>s! |
| 3142 | 3306 | $j = -1; |
@@ -3144,8 +3308,9 @@ discard block |
||
| 3144 | 3308 | { |
| 3145 | 3309 | $j++; |
| 3146 | 3310 | |
| 3147 | - if (substr_count($line, '<br>') == 0) |
|
| 3148 | - continue; |
|
| 3311 | + if (substr_count($line, '<br>') == 0) { |
|
| 3312 | + continue; |
|
| 3313 | + } |
|
| 3149 | 3314 | |
| 3150 | 3315 | $n = substr_count($line, '<br>'); |
| 3151 | 3316 | for ($i = 0; $i < $n; $i++) |
@@ -3164,38 +3329,42 @@ discard block |
||
| 3164 | 3329 | // Figure out what the color coding was before... |
| 3165 | 3330 | $line = max($match[1] - 9, 1); |
| 3166 | 3331 | $last_line = ''; |
| 3167 | - for ($line2 = $line - 1; $line2 > 1; $line2--) |
|
| 3168 | - if (strpos($data2[$line2], '<') !== false) |
|
| 3332 | + for ($line2 = $line - 1; $line2 > 1; $line2--) { |
|
| 3333 | + if (strpos($data2[$line2], '<') !== false) |
|
| 3169 | 3334 | { |
| 3170 | 3335 | if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0) |
| 3171 | 3336 | $last_line = $color_match[1]; |
| 3337 | + } |
|
| 3172 | 3338 | break; |
| 3173 | 3339 | } |
| 3174 | 3340 | |
| 3175 | 3341 | // Show the relevant lines... |
| 3176 | 3342 | for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++) |
| 3177 | 3343 | { |
| 3178 | - if ($line == $match[1]) |
|
| 3179 | - echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">'; |
|
| 3344 | + if ($line == $match[1]) { |
|
| 3345 | + echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">'; |
|
| 3346 | + } |
|
| 3180 | 3347 | |
| 3181 | 3348 | echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> '; |
| 3182 | - if (isset($data2[$line]) && $data2[$line] != '') |
|
| 3183 | - echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line]; |
|
| 3349 | + if (isset($data2[$line]) && $data2[$line] != '') { |
|
| 3350 | + echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line]; |
|
| 3351 | + } |
|
| 3184 | 3352 | |
| 3185 | 3353 | if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0) |
| 3186 | 3354 | { |
| 3187 | 3355 | $last_line = $color_match[1]; |
| 3188 | 3356 | echo '</', substr($last_line, 1, 4), '>'; |
| 3357 | + } elseif ($last_line != '' && strpos($data2[$line], '<') !== false) { |
|
| 3358 | + $last_line = ''; |
|
| 3359 | + } elseif ($last_line != '' && $data2[$line] != '') { |
|
| 3360 | + echo '</', substr($last_line, 1, 4), '>'; |
|
| 3189 | 3361 | } |
| 3190 | - elseif ($last_line != '' && strpos($data2[$line], '<') !== false) |
|
| 3191 | - $last_line = ''; |
|
| 3192 | - elseif ($last_line != '' && $data2[$line] != '') |
|
| 3193 | - echo '</', substr($last_line, 1, 4), '>'; |
|
| 3194 | 3362 | |
| 3195 | - if ($line == $match[1]) |
|
| 3196 | - echo '</pre></div><pre style="margin: 0;">'; |
|
| 3197 | - else |
|
| 3198 | - echo "\n"; |
|
| 3363 | + if ($line == $match[1]) { |
|
| 3364 | + echo '</pre></div><pre style="margin: 0;">'; |
|
| 3365 | + } else { |
|
| 3366 | + echo "\n"; |
|
| 3367 | + } |
|
| 3199 | 3368 | } |
| 3200 | 3369 | |
| 3201 | 3370 | echo '</pre></div>'; |
@@ -3219,8 +3388,9 @@ discard block |
||
| 3219 | 3388 | global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port; |
| 3220 | 3389 | |
| 3221 | 3390 | // Figure out what type of database we are using. |
| 3222 | - if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) |
|
| 3223 | - $db_type = 'mysql'; |
|
| 3391 | + if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) { |
|
| 3392 | + $db_type = 'mysql'; |
|
| 3393 | + } |
|
| 3224 | 3394 | |
| 3225 | 3395 | // Load the file for the database. |
| 3226 | 3396 | require_once($sourcedir . '/Subs-Db-' . $db_type . '.php'); |
@@ -3228,8 +3398,9 @@ discard block |
||
| 3228 | 3398 | $db_options = array(); |
| 3229 | 3399 | |
| 3230 | 3400 | // Add in the port if needed |
| 3231 | - if (!empty($db_port)) |
|
| 3232 | - $db_options['port'] = $db_port; |
|
| 3401 | + if (!empty($db_port)) { |
|
| 3402 | + $db_options['port'] = $db_port; |
|
| 3403 | + } |
|
| 3233 | 3404 | |
| 3234 | 3405 | // If we are in SSI try them first, but don't worry if it doesn't work, we have the normal username and password we can use. |
| 3235 | 3406 | if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd)) |
@@ -3248,13 +3419,15 @@ discard block |
||
| 3248 | 3419 | } |
| 3249 | 3420 | |
| 3250 | 3421 | // Safe guard here, if there isn't a valid connection lets put a stop to it. |
| 3251 | - if (!$db_connection) |
|
| 3252 | - display_db_error(); |
|
| 3422 | + if (!$db_connection) { |
|
| 3423 | + display_db_error(); |
|
| 3424 | + } |
|
| 3253 | 3425 | |
| 3254 | 3426 | // If in SSI mode fix up the prefix. |
| 3255 | - if (SMF == 'SSI') |
|
| 3256 | - db_fix_prefix($db_prefix, $db_name); |
|
| 3257 | -} |
|
| 3427 | + if (SMF == 'SSI') { |
|
| 3428 | + db_fix_prefix($db_prefix, $db_name); |
|
| 3429 | + } |
|
| 3430 | + } |
|
| 3258 | 3431 | |
| 3259 | 3432 | /** |
| 3260 | 3433 | * Try to load up a supported caching method. This is saved in $cacheAPI if we are not overriding it. |
@@ -3268,10 +3441,11 @@ discard block |
||
| 3268 | 3441 | global $sourcedir, $cacheAPI, $cache_accelerator; |
| 3269 | 3442 | |
| 3270 | 3443 | // Not overriding this and we have a cacheAPI, send it back. |
| 3271 | - if (empty($overrideCache) && is_object($cacheAPI)) |
|
| 3272 | - return $cacheAPI; |
|
| 3273 | - elseif (is_null($cacheAPI)) |
|
| 3274 | - $cacheAPI = false; |
|
| 3444 | + if (empty($overrideCache) && is_object($cacheAPI)) { |
|
| 3445 | + return $cacheAPI; |
|
| 3446 | + } elseif (is_null($cacheAPI)) { |
|
| 3447 | + $cacheAPI = false; |
|
| 3448 | + } |
|
| 3275 | 3449 | |
| 3276 | 3450 | // Make sure our class is in session. |
| 3277 | 3451 | require_once($sourcedir . '/Class-CacheAPI.php'); |
@@ -3292,8 +3466,9 @@ discard block |
||
| 3292 | 3466 | if (!$testAPI->isSupported()) |
| 3293 | 3467 | { |
| 3294 | 3468 | // Can we save ourselves? |
| 3295 | - if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') |
|
| 3296 | - return loadCacheAccelerator(null, false); |
|
| 3469 | + if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') { |
|
| 3470 | + return loadCacheAccelerator(null, false); |
|
| 3471 | + } |
|
| 3297 | 3472 | return false; |
| 3298 | 3473 | } |
| 3299 | 3474 | |
@@ -3305,9 +3480,9 @@ discard block |
||
| 3305 | 3480 | { |
| 3306 | 3481 | $cacheAPI = $testAPI; |
| 3307 | 3482 | return $cacheAPI; |
| 3483 | + } else { |
|
| 3484 | + return $testAPI; |
|
| 3308 | 3485 | } |
| 3309 | - else |
|
| 3310 | - return $testAPI; |
|
| 3311 | 3486 | } |
| 3312 | 3487 | } |
| 3313 | 3488 | |
@@ -3327,8 +3502,9 @@ discard block |
||
| 3327 | 3502 | |
| 3328 | 3503 | // @todo Why are we doing this if caching is disabled? |
| 3329 | 3504 | |
| 3330 | - if (function_exists('call_integration_hook')) |
|
| 3331 | - call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level)); |
|
| 3505 | + if (function_exists('call_integration_hook')) { |
|
| 3506 | + call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level)); |
|
| 3507 | + } |
|
| 3332 | 3508 | |
| 3333 | 3509 | /* Refresh the cache if either: |
| 3334 | 3510 | 1. Caching is disabled. |
@@ -3342,16 +3518,19 @@ discard block |
||
| 3342 | 3518 | require_once($sourcedir . '/' . $file); |
| 3343 | 3519 | $cache_block = call_user_func_array($function, $params); |
| 3344 | 3520 | |
| 3345 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) |
|
| 3346 | - cache_put_data($key, $cache_block, $cache_block['expires'] - time()); |
|
| 3521 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) { |
|
| 3522 | + cache_put_data($key, $cache_block, $cache_block['expires'] - time()); |
|
| 3523 | + } |
|
| 3347 | 3524 | } |
| 3348 | 3525 | |
| 3349 | 3526 | // Some cached data may need a freshening up after retrieval. |
| 3350 | - if (!empty($cache_block['post_retri_eval'])) |
|
| 3351 | - eval($cache_block['post_retri_eval']); |
|
| 3527 | + if (!empty($cache_block['post_retri_eval'])) { |
|
| 3528 | + eval($cache_block['post_retri_eval']); |
|
| 3529 | + } |
|
| 3352 | 3530 | |
| 3353 | - if (function_exists('call_integration_hook')) |
|
| 3354 | - call_integration_hook('post_cache_quick_get', array(&$cache_block)); |
|
| 3531 | + if (function_exists('call_integration_hook')) { |
|
| 3532 | + call_integration_hook('post_cache_quick_get', array(&$cache_block)); |
|
| 3533 | + } |
|
| 3355 | 3534 | |
| 3356 | 3535 | return $cache_block['data']; |
| 3357 | 3536 | } |
@@ -3378,8 +3557,9 @@ discard block |
||
| 3378 | 3557 | global $smcFunc, $cache_enable, $cacheAPI; |
| 3379 | 3558 | global $cache_hits, $cache_count, $db_show_debug; |
| 3380 | 3559 | |
| 3381 | - if (empty($cache_enable) || empty($cacheAPI)) |
|
| 3382 | - return; |
|
| 3560 | + if (empty($cache_enable) || empty($cacheAPI)) { |
|
| 3561 | + return; |
|
| 3562 | + } |
|
| 3383 | 3563 | |
| 3384 | 3564 | $cache_count = isset($cache_count) ? $cache_count + 1 : 1; |
| 3385 | 3565 | if (isset($db_show_debug) && $db_show_debug === true) |
@@ -3392,12 +3572,14 @@ discard block |
||
| 3392 | 3572 | $value = $value === null ? null : (isset($smcFunc['json_encode']) ? $smcFunc['json_encode']($value) : json_encode($value)); |
| 3393 | 3573 | $cacheAPI->putData($key, $value, $ttl); |
| 3394 | 3574 | |
| 3395 | - if (function_exists('call_integration_hook')) |
|
| 3396 | - call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl)); |
|
| 3575 | + if (function_exists('call_integration_hook')) { |
|
| 3576 | + call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl)); |
|
| 3577 | + } |
|
| 3397 | 3578 | |
| 3398 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
| 3399 | - $cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 3400 | -} |
|
| 3579 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
| 3580 | + $cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 3581 | + } |
|
| 3582 | + } |
|
| 3401 | 3583 | |
| 3402 | 3584 | /** |
| 3403 | 3585 | * Gets the value from the cache specified by key, so long as it is not older than ttl seconds. |
@@ -3413,8 +3595,9 @@ discard block |
||
| 3413 | 3595 | global $smcFunc, $cache_enable, $cacheAPI; |
| 3414 | 3596 | global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug; |
| 3415 | 3597 | |
| 3416 | - if (empty($cache_enable) || empty($cacheAPI)) |
|
| 3417 | - return; |
|
| 3598 | + if (empty($cache_enable) || empty($cacheAPI)) { |
|
| 3599 | + return; |
|
| 3600 | + } |
|
| 3418 | 3601 | |
| 3419 | 3602 | $cache_count = isset($cache_count) ? $cache_count + 1 : 1; |
| 3420 | 3603 | if (isset($db_show_debug) && $db_show_debug === true) |
@@ -3434,16 +3617,18 @@ discard block |
||
| 3434 | 3617 | |
| 3435 | 3618 | if (empty($value)) |
| 3436 | 3619 | { |
| 3437 | - if (!is_array($cache_misses)) |
|
| 3438 | - $cache_misses = array(); |
|
| 3620 | + if (!is_array($cache_misses)) { |
|
| 3621 | + $cache_misses = array(); |
|
| 3622 | + } |
|
| 3439 | 3623 | |
| 3440 | 3624 | $cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1; |
| 3441 | 3625 | $cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get'); |
| 3442 | 3626 | } |
| 3443 | 3627 | } |
| 3444 | 3628 | |
| 3445 | - if (function_exists('call_integration_hook') && isset($value)) |
|
| 3446 | - call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value)); |
|
| 3629 | + if (function_exists('call_integration_hook') && isset($value)) { |
|
| 3630 | + call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value)); |
|
| 3631 | + } |
|
| 3447 | 3632 | |
| 3448 | 3633 | return empty($value) ? null : (isset($smcFunc['json_encode']) ? $smcFunc['json_decode']($value, true) : smf_json_decode($value, true)); |
| 3449 | 3634 | } |
@@ -3465,8 +3650,9 @@ discard block |
||
| 3465 | 3650 | global $cacheAPI; |
| 3466 | 3651 | |
| 3467 | 3652 | // If we can't get to the API, can't do this. |
| 3468 | - if (empty($cacheAPI)) |
|
| 3469 | - return; |
|
| 3653 | + if (empty($cacheAPI)) { |
|
| 3654 | + return; |
|
| 3655 | + } |
|
| 3470 | 3656 | |
| 3471 | 3657 | // Ask the API to do the heavy lifting. cleanCache also calls invalidateCache to be sure. |
| 3472 | 3658 | $cacheAPI->cleanCache($type); |
@@ -3491,8 +3677,9 @@ discard block |
||
| 3491 | 3677 | global $modSettings, $boardurl, $smcFunc, $image_proxy_enabled, $image_proxy_secret; |
| 3492 | 3678 | |
| 3493 | 3679 | // Come on! |
| 3494 | - if (empty($data)) |
|
| 3495 | - return array(); |
|
| 3680 | + if (empty($data)) { |
|
| 3681 | + return array(); |
|
| 3682 | + } |
|
| 3496 | 3683 | |
| 3497 | 3684 | // Set a nice default var. |
| 3498 | 3685 | $image = ''; |
@@ -3500,11 +3687,11 @@ discard block |
||
| 3500 | 3687 | // Gravatar has been set as mandatory! |
| 3501 | 3688 | if (!empty($modSettings['gravatarOverride'])) |
| 3502 | 3689 | { |
| 3503 | - if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) |
|
| 3504 | - $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
| 3505 | - |
|
| 3506 | - else if (!empty($data['email'])) |
|
| 3507 | - $image = get_gravatar_url($data['email']); |
|
| 3690 | + if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) { |
|
| 3691 | + $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
| 3692 | + } else if (!empty($data['email'])) { |
|
| 3693 | + $image = get_gravatar_url($data['email']); |
|
| 3694 | + } |
|
| 3508 | 3695 | } |
| 3509 | 3696 | |
| 3510 | 3697 | // Look if the user has a gravatar field or has set an external url as avatar. |
@@ -3516,54 +3703,60 @@ discard block |
||
| 3516 | 3703 | // Gravatar. |
| 3517 | 3704 | if (stristr($data['avatar'], 'gravatar://')) |
| 3518 | 3705 | { |
| 3519 | - if ($data['avatar'] == 'gravatar://') |
|
| 3520 | - $image = get_gravatar_url($data['email']); |
|
| 3521 | - |
|
| 3522 | - elseif (!empty($modSettings['gravatarAllowExtraEmail'])) |
|
| 3523 | - $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
| 3706 | + if ($data['avatar'] == 'gravatar://') { |
|
| 3707 | + $image = get_gravatar_url($data['email']); |
|
| 3708 | + } elseif (!empty($modSettings['gravatarAllowExtraEmail'])) { |
|
| 3709 | + $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
| 3710 | + } |
|
| 3524 | 3711 | } |
| 3525 | 3712 | |
| 3526 | 3713 | // External url. |
| 3527 | 3714 | else |
| 3528 | 3715 | { |
| 3529 | 3716 | // Using ssl? |
| 3530 | - if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false) |
|
| 3531 | - $image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret); |
|
| 3717 | + if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false) { |
|
| 3718 | + $image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret); |
|
| 3719 | + } |
|
| 3532 | 3720 | |
| 3533 | 3721 | // Just a plain external url. |
| 3534 | - else |
|
| 3535 | - $image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar']; |
|
| 3722 | + else { |
|
| 3723 | + $image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar']; |
|
| 3724 | + } |
|
| 3536 | 3725 | } |
| 3537 | 3726 | } |
| 3538 | 3727 | |
| 3539 | 3728 | // Perhaps this user has an attachment as avatar... |
| 3540 | - else if (!empty($data['filename'])) |
|
| 3541 | - $image = $modSettings['custom_avatar_url'] . '/' . $data['filename']; |
|
| 3729 | + else if (!empty($data['filename'])) { |
|
| 3730 | + $image = $modSettings['custom_avatar_url'] . '/' . $data['filename']; |
|
| 3731 | + } |
|
| 3542 | 3732 | |
| 3543 | 3733 | // Right... no avatar... use our default image. |
| 3544 | - else |
|
| 3545 | - $image = $modSettings['avatar_url'] . '/default.png'; |
|
| 3734 | + else { |
|
| 3735 | + $image = $modSettings['avatar_url'] . '/default.png'; |
|
| 3736 | + } |
|
| 3546 | 3737 | } |
| 3547 | 3738 | |
| 3548 | 3739 | call_integration_hook('integrate_set_avatar_data', array(&$image, &$data)); |
| 3549 | 3740 | |
| 3550 | 3741 | // At this point in time $image has to be filled unless you chose to force gravatar and the user doesn't have the needed data to retrieve it... thus a check for !empty() is still needed. |
| 3551 | - if (!empty($image)) |
|
| 3552 | - return array( |
|
| 3742 | + if (!empty($image)) { |
|
| 3743 | + return array( |
|
| 3553 | 3744 | 'name' => !empty($data['avatar']) ? $data['avatar'] : '', |
| 3554 | 3745 | 'image' => '<img class="avatar" src="' . $image . '" />', |
| 3555 | 3746 | 'href' => $image, |
| 3556 | 3747 | 'url' => $image, |
| 3557 | 3748 | ); |
| 3749 | + } |
|
| 3558 | 3750 | |
| 3559 | 3751 | // Fallback to make life easier for everyone... |
| 3560 | - else |
|
| 3561 | - return array( |
|
| 3752 | + else { |
|
| 3753 | + return array( |
|
| 3562 | 3754 | 'name' => '', |
| 3563 | 3755 | 'image' => '', |
| 3564 | 3756 | 'href' => '', |
| 3565 | 3757 | 'url' => '', |
| 3566 | 3758 | ); |
| 3567 | -} |
|
| 3759 | + } |
|
| 3760 | + } |
|
| 3568 | 3761 | |
| 3569 | 3762 | ?> |
| 3570 | 3763 | \ No newline at end of file |
@@ -14,8 +14,9 @@ discard block |
||
| 14 | 14 | * @version 2.1 Beta 4 |
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | -if (!defined('SMF')) |
|
| 17 | +if (!defined('SMF')) { |
|
| 18 | 18 | die('No direct access...'); |
| 19 | +} |
|
| 19 | 20 | |
| 20 | 21 | /** |
| 21 | 22 | * Check if the user is who he/she says he is |
@@ -42,12 +43,14 @@ discard block |
||
| 42 | 43 | $refreshTime = isset($_GET['xml']) ? 4200 : 3600; |
| 43 | 44 | |
| 44 | 45 | // Is the security option off? |
| 45 | - if (!empty($modSettings['securityDisable' . ($type != 'admin' ? '_' . $type : '')])) |
|
| 46 | - return; |
|
| 46 | + if (!empty($modSettings['securityDisable' . ($type != 'admin' ? '_' . $type : '')])) { |
|
| 47 | + return; |
|
| 48 | + } |
|
| 47 | 49 | |
| 48 | 50 | // Or are they already logged in?, Moderator or admin session is need for this area |
| 49 | - if ((!empty($_SESSION[$type . '_time']) && $_SESSION[$type . '_time'] + $refreshTime >= time()) || (!empty($_SESSION['admin_time']) && $_SESSION['admin_time'] + $refreshTime >= time())) |
|
| 50 | - return; |
|
| 51 | + if ((!empty($_SESSION[$type . '_time']) && $_SESSION[$type . '_time'] + $refreshTime >= time()) || (!empty($_SESSION['admin_time']) && $_SESSION['admin_time'] + $refreshTime >= time())) { |
|
| 52 | + return; |
|
| 53 | + } |
|
| 51 | 54 | |
| 52 | 55 | require_once($sourcedir . '/Subs-Auth.php'); |
| 53 | 56 | |
@@ -55,8 +58,9 @@ discard block |
||
| 55 | 58 | if (isset($_POST[$type . '_pass'])) |
| 56 | 59 | { |
| 57 | 60 | // Check to ensure we're forcing SSL for authentication |
| 58 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) |
|
| 59 | - fatal_lang_error('login_ssl_required'); |
|
| 61 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) { |
|
| 62 | + fatal_lang_error('login_ssl_required'); |
|
| 63 | + } |
|
| 60 | 64 | |
| 61 | 65 | checkSession(); |
| 62 | 66 | |
@@ -72,17 +76,19 @@ discard block |
||
| 72 | 76 | } |
| 73 | 77 | |
| 74 | 78 | // Better be sure to remember the real referer |
| 75 | - if (empty($_SESSION['request_referer'])) |
|
| 76 | - $_SESSION['request_referer'] = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array(); |
|
| 77 | - elseif (empty($_POST)) |
|
| 78 | - unset($_SESSION['request_referer']); |
|
| 79 | + if (empty($_SESSION['request_referer'])) { |
|
| 80 | + $_SESSION['request_referer'] = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array(); |
|
| 81 | + } elseif (empty($_POST)) { |
|
| 82 | + unset($_SESSION['request_referer']); |
|
| 83 | + } |
|
| 79 | 84 | |
| 80 | 85 | // Need to type in a password for that, man. |
| 81 | - if (!isset($_GET['xml'])) |
|
| 82 | - adminLogin($type); |
|
| 83 | - else |
|
| 84 | - return 'session_verify_fail'; |
|
| 85 | -} |
|
| 86 | + if (!isset($_GET['xml'])) { |
|
| 87 | + adminLogin($type); |
|
| 88 | + } else { |
|
| 89 | + return 'session_verify_fail'; |
|
| 90 | + } |
|
| 91 | + } |
|
| 86 | 92 | |
| 87 | 93 | /** |
| 88 | 94 | * Require a user who is logged in. (not a guest.) |
@@ -96,25 +102,30 @@ discard block |
||
| 96 | 102 | global $user_info, $txt, $context, $scripturl, $modSettings; |
| 97 | 103 | |
| 98 | 104 | // Luckily, this person isn't a guest. |
| 99 | - if (!$user_info['is_guest']) |
|
| 100 | - return; |
|
| 105 | + if (!$user_info['is_guest']) { |
|
| 106 | + return; |
|
| 107 | + } |
|
| 101 | 108 | |
| 102 | 109 | // Log what they were trying to do didn't work) |
| 103 | - if (!empty($modSettings['who_enabled'])) |
|
| 104 | - $_GET['error'] = 'guest_login'; |
|
| 110 | + if (!empty($modSettings['who_enabled'])) { |
|
| 111 | + $_GET['error'] = 'guest_login'; |
|
| 112 | + } |
|
| 105 | 113 | writeLog(true); |
| 106 | 114 | |
| 107 | 115 | // Just die. |
| 108 | - if (isset($_REQUEST['xml'])) |
|
| 109 | - obExit(false); |
|
| 116 | + if (isset($_REQUEST['xml'])) { |
|
| 117 | + obExit(false); |
|
| 118 | + } |
|
| 110 | 119 | |
| 111 | 120 | // Attempt to detect if they came from dlattach. |
| 112 | - if (SMF != 'SSI' && empty($context['theme_loaded'])) |
|
| 113 | - loadTheme(); |
|
| 121 | + if (SMF != 'SSI' && empty($context['theme_loaded'])) { |
|
| 122 | + loadTheme(); |
|
| 123 | + } |
|
| 114 | 124 | |
| 115 | 125 | // Never redirect to an attachment |
| 116 | - if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) |
|
| 117 | - $_SESSION['login_url'] = $_SERVER['REQUEST_URL']; |
|
| 126 | + if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) { |
|
| 127 | + $_SESSION['login_url'] = $_SERVER['REQUEST_URL']; |
|
| 128 | + } |
|
| 118 | 129 | |
| 119 | 130 | // Load the Login template and language file. |
| 120 | 131 | loadLanguage('Login'); |
@@ -124,8 +135,7 @@ discard block |
||
| 124 | 135 | { |
| 125 | 136 | $_SESSION['login_url'] = $scripturl . '?' . $_SERVER['QUERY_STRING']; |
| 126 | 137 | redirectexit('action=login'); |
| 127 | - } |
|
| 128 | - else |
|
| 138 | + } else |
|
| 129 | 139 | { |
| 130 | 140 | loadTemplate('Login'); |
| 131 | 141 | $context['sub_template'] = 'kick_guest'; |
@@ -155,8 +165,9 @@ discard block |
||
| 155 | 165 | global $sourcedir, $cookiename, $user_settings, $smcFunc; |
| 156 | 166 | |
| 157 | 167 | // You cannot be banned if you are an admin - doesn't help if you log out. |
| 158 | - if ($user_info['is_admin']) |
|
| 159 | - return; |
|
| 168 | + if ($user_info['is_admin']) { |
|
| 169 | + return; |
|
| 170 | + } |
|
| 160 | 171 | |
| 161 | 172 | // Only check the ban every so often. (to reduce load.) |
| 162 | 173 | if ($forceCheck || !isset($_SESSION['ban']) || empty($modSettings['banLastUpdated']) || ($_SESSION['ban']['last_checked'] < $modSettings['banLastUpdated']) || $_SESSION['ban']['id_member'] != $user_info['id'] || $_SESSION['ban']['ip'] != $user_info['ip'] || $_SESSION['ban']['ip2'] != $user_info['ip2'] || (isset($user_info['email'], $_SESSION['ban']['email']) && $_SESSION['ban']['email'] != $user_info['email'])) |
@@ -177,8 +188,9 @@ discard block |
||
| 177 | 188 | // Check both IP addresses. |
| 178 | 189 | foreach (array('ip', 'ip2') as $ip_number) |
| 179 | 190 | { |
| 180 | - if ($ip_number == 'ip2' && $user_info['ip2'] == $user_info['ip']) |
|
| 181 | - continue; |
|
| 191 | + if ($ip_number == 'ip2' && $user_info['ip2'] == $user_info['ip']) { |
|
| 192 | + continue; |
|
| 193 | + } |
|
| 182 | 194 | $ban_query[] = ' {inet:' . $ip_number . '} BETWEEN bi.ip_low and bi.ip_high'; |
| 183 | 195 | $ban_query_vars[$ip_number] = $user_info[$ip_number]; |
| 184 | 196 | // IP was valid, maybe there's also a hostname... |
@@ -228,24 +240,28 @@ discard block |
||
| 228 | 240 | // Store every type of ban that applies to you in your session. |
| 229 | 241 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 230 | 242 | { |
| 231 | - foreach ($restrictions as $restriction) |
|
| 232 | - if (!empty($row[$restriction])) |
|
| 243 | + foreach ($restrictions as $restriction) { |
|
| 244 | + if (!empty($row[$restriction])) |
|
| 233 | 245 | { |
| 234 | 246 | $_SESSION['ban'][$restriction]['reason'] = $row['reason']; |
| 247 | + } |
|
| 235 | 248 | $_SESSION['ban'][$restriction]['ids'][] = $row['id_ban']; |
| 236 | - if (!isset($_SESSION['ban']['expire_time']) || ($_SESSION['ban']['expire_time'] != 0 && ($row['expire_time'] == 0 || $row['expire_time'] > $_SESSION['ban']['expire_time']))) |
|
| 237 | - $_SESSION['ban']['expire_time'] = $row['expire_time']; |
|
| 249 | + if (!isset($_SESSION['ban']['expire_time']) || ($_SESSION['ban']['expire_time'] != 0 && ($row['expire_time'] == 0 || $row['expire_time'] > $_SESSION['ban']['expire_time']))) { |
|
| 250 | + $_SESSION['ban']['expire_time'] = $row['expire_time']; |
|
| 251 | + } |
|
| 238 | 252 | |
| 239 | - if (!$user_info['is_guest'] && $restriction == 'cannot_access' && ($row['id_member'] == $user_info['id'] || $row['email_address'] == $user_info['email'])) |
|
| 240 | - $flag_is_activated = true; |
|
| 253 | + if (!$user_info['is_guest'] && $restriction == 'cannot_access' && ($row['id_member'] == $user_info['id'] || $row['email_address'] == $user_info['email'])) { |
|
| 254 | + $flag_is_activated = true; |
|
| 255 | + } |
|
| 241 | 256 | } |
| 242 | 257 | } |
| 243 | 258 | $smcFunc['db_free_result']($request); |
| 244 | 259 | } |
| 245 | 260 | |
| 246 | 261 | // Mark the cannot_access and cannot_post bans as being 'hit'. |
| 247 | - if (isset($_SESSION['ban']['cannot_access']) || isset($_SESSION['ban']['cannot_post']) || isset($_SESSION['ban']['cannot_login'])) |
|
| 248 | - log_ban(array_merge(isset($_SESSION['ban']['cannot_access']) ? $_SESSION['ban']['cannot_access']['ids'] : array(), isset($_SESSION['ban']['cannot_post']) ? $_SESSION['ban']['cannot_post']['ids'] : array(), isset($_SESSION['ban']['cannot_login']) ? $_SESSION['ban']['cannot_login']['ids'] : array())); |
|
| 262 | + if (isset($_SESSION['ban']['cannot_access']) || isset($_SESSION['ban']['cannot_post']) || isset($_SESSION['ban']['cannot_login'])) { |
|
| 263 | + log_ban(array_merge(isset($_SESSION['ban']['cannot_access']) ? $_SESSION['ban']['cannot_access']['ids'] : array(), isset($_SESSION['ban']['cannot_post']) ? $_SESSION['ban']['cannot_post']['ids'] : array(), isset($_SESSION['ban']['cannot_login']) ? $_SESSION['ban']['cannot_login']['ids'] : array())); |
|
| 264 | + } |
|
| 249 | 265 | |
| 250 | 266 | // If for whatever reason the is_activated flag seems wrong, do a little work to clear it up. |
| 251 | 267 | if ($user_info['id'] && (($user_settings['is_activated'] >= 10 && !$flag_is_activated) |
@@ -260,8 +276,9 @@ discard block |
||
| 260 | 276 | if (!isset($_SESSION['ban']['cannot_access']) && !empty($_COOKIE[$cookiename . '_'])) |
| 261 | 277 | { |
| 262 | 278 | $bans = explode(',', $_COOKIE[$cookiename . '_']); |
| 263 | - foreach ($bans as $key => $value) |
|
| 264 | - $bans[$key] = (int) $value; |
|
| 279 | + foreach ($bans as $key => $value) { |
|
| 280 | + $bans[$key] = (int) $value; |
|
| 281 | + } |
|
| 265 | 282 | $request = $smcFunc['db_query']('', ' |
| 266 | 283 | SELECT bi.id_ban, bg.reason |
| 267 | 284 | FROM {db_prefix}ban_items AS bi |
@@ -297,14 +314,15 @@ discard block |
||
| 297 | 314 | if (isset($_SESSION['ban']['cannot_access'])) |
| 298 | 315 | { |
| 299 | 316 | // We don't wanna see you! |
| 300 | - if (!$user_info['is_guest']) |
|
| 301 | - $smcFunc['db_query']('', ' |
|
| 317 | + if (!$user_info['is_guest']) { |
|
| 318 | + $smcFunc['db_query']('', ' |
|
| 302 | 319 | DELETE FROM {db_prefix}log_online |
| 303 | 320 | WHERE id_member = {int:current_member}', |
| 304 | 321 | array( |
| 305 | 322 | 'current_member' => $user_info['id'], |
| 306 | 323 | ) |
| 307 | 324 | ); |
| 325 | + } |
|
| 308 | 326 | |
| 309 | 327 | // 'Log' the user out. Can't have any funny business... (save the name!) |
| 310 | 328 | $old_name = isset($user_info['name']) && $user_info['name'] != '' ? $user_info['name'] : $txt['guest_title']; |
@@ -390,9 +408,10 @@ discard block |
||
| 390 | 408 | } |
| 391 | 409 | |
| 392 | 410 | // Fix up the banning permissions. |
| 393 | - if (isset($user_info['permissions'])) |
|
| 394 | - banPermissions(); |
|
| 395 | -} |
|
| 411 | + if (isset($user_info['permissions'])) { |
|
| 412 | + banPermissions(); |
|
| 413 | + } |
|
| 414 | + } |
|
| 396 | 415 | |
| 397 | 416 | /** |
| 398 | 417 | * Fix permissions according to ban status. |
@@ -403,8 +422,9 @@ discard block |
||
| 403 | 422 | global $user_info, $sourcedir, $modSettings, $context; |
| 404 | 423 | |
| 405 | 424 | // Somehow they got here, at least take away all permissions... |
| 406 | - if (isset($_SESSION['ban']['cannot_access'])) |
|
| 407 | - $user_info['permissions'] = array(); |
|
| 425 | + if (isset($_SESSION['ban']['cannot_access'])) { |
|
| 426 | + $user_info['permissions'] = array(); |
|
| 427 | + } |
|
| 408 | 428 | // Okay, well, you can watch, but don't touch a thing. |
| 409 | 429 | elseif (isset($_SESSION['ban']['cannot_post']) || (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $user_info['warning'])) |
| 410 | 430 | { |
@@ -446,19 +466,20 @@ discard block |
||
| 446 | 466 | call_integration_hook('integrate_warn_permissions', array(&$permission_change)); |
| 447 | 467 | foreach ($permission_change as $old => $new) |
| 448 | 468 | { |
| 449 | - if (!in_array($old, $user_info['permissions'])) |
|
| 450 | - unset($permission_change[$old]); |
|
| 451 | - else |
|
| 452 | - $user_info['permissions'][] = $new; |
|
| 469 | + if (!in_array($old, $user_info['permissions'])) { |
|
| 470 | + unset($permission_change[$old]); |
|
| 471 | + } else { |
|
| 472 | + $user_info['permissions'][] = $new; |
|
| 473 | + } |
|
| 453 | 474 | } |
| 454 | 475 | $user_info['permissions'] = array_diff($user_info['permissions'], array_keys($permission_change)); |
| 455 | 476 | } |
| 456 | 477 | |
| 457 | 478 | // @todo Find a better place to call this? Needs to be after permissions loaded! |
| 458 | 479 | // Finally, some bits we cache in the session because it saves queries. |
| 459 | - if (isset($_SESSION['mc']) && $_SESSION['mc']['time'] > $modSettings['settings_updated'] && $_SESSION['mc']['id'] == $user_info['id']) |
|
| 460 | - $user_info['mod_cache'] = $_SESSION['mc']; |
|
| 461 | - else |
|
| 480 | + if (isset($_SESSION['mc']) && $_SESSION['mc']['time'] > $modSettings['settings_updated'] && $_SESSION['mc']['id'] == $user_info['id']) { |
|
| 481 | + $user_info['mod_cache'] = $_SESSION['mc']; |
|
| 482 | + } else |
|
| 462 | 483 | { |
| 463 | 484 | require_once($sourcedir . '/Subs-Auth.php'); |
| 464 | 485 | rebuildModCache(); |
@@ -469,14 +490,12 @@ discard block |
||
| 469 | 490 | { |
| 470 | 491 | $context['open_mod_reports'] = $_SESSION['rc']['reports']; |
| 471 | 492 | $context['open_member_reports'] = $_SESSION['rc']['member_reports']; |
| 472 | - } |
|
| 473 | - elseif ($_SESSION['mc']['bq'] != '0=1') |
|
| 493 | + } elseif ($_SESSION['mc']['bq'] != '0=1') |
|
| 474 | 494 | { |
| 475 | 495 | require_once($sourcedir . '/Subs-ReportedContent.php'); |
| 476 | 496 | $context['open_mod_reports'] = recountOpenReports('posts'); |
| 477 | 497 | $context['open_member_reports'] = recountOpenReports('members'); |
| 478 | - } |
|
| 479 | - else |
|
| 498 | + } else |
|
| 480 | 499 | { |
| 481 | 500 | $context['open_mod_reports'] = 0; |
| 482 | 501 | $context['open_member_reports'] = 0; |
@@ -496,8 +515,9 @@ discard block |
||
| 496 | 515 | global $user_info, $smcFunc; |
| 497 | 516 | |
| 498 | 517 | // Don't log web accelerators, it's very confusing... |
| 499 | - if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') |
|
| 500 | - return; |
|
| 518 | + if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') { |
|
| 519 | + return; |
|
| 520 | + } |
|
| 501 | 521 | |
| 502 | 522 | $smcFunc['db_insert']('', |
| 503 | 523 | '{db_prefix}log_banned', |
@@ -507,8 +527,8 @@ discard block |
||
| 507 | 527 | ); |
| 508 | 528 | |
| 509 | 529 | // One extra point for these bans. |
| 510 | - if (!empty($ban_ids)) |
|
| 511 | - $smcFunc['db_query']('', ' |
|
| 530 | + if (!empty($ban_ids)) { |
|
| 531 | + $smcFunc['db_query']('', ' |
|
| 512 | 532 | UPDATE {db_prefix}ban_items |
| 513 | 533 | SET hits = hits + 1 |
| 514 | 534 | WHERE id_ban IN ({array_int:ban_ids})', |
@@ -516,7 +536,8 @@ discard block |
||
| 516 | 536 | 'ban_ids' => $ban_ids, |
| 517 | 537 | ) |
| 518 | 538 | ); |
| 519 | -} |
|
| 539 | + } |
|
| 540 | + } |
|
| 520 | 541 | |
| 521 | 542 | /** |
| 522 | 543 | * Checks if a given email address might be banned. |
@@ -532,8 +553,9 @@ discard block |
||
| 532 | 553 | global $txt, $smcFunc; |
| 533 | 554 | |
| 534 | 555 | // Can't ban an empty email |
| 535 | - if (empty($email) || trim($email) == '') |
|
| 536 | - return; |
|
| 556 | + if (empty($email) || trim($email) == '') { |
|
| 557 | + return; |
|
| 558 | + } |
|
| 537 | 559 | |
| 538 | 560 | // Let's start with the bans based on your IP/hostname/memberID... |
| 539 | 561 | $ban_ids = isset($_SESSION['ban'][$restriction]) ? $_SESSION['ban'][$restriction]['ids'] : array(); |
@@ -606,16 +628,18 @@ discard block |
||
| 606 | 628 | if ($type == 'post') |
| 607 | 629 | { |
| 608 | 630 | $check = isset($_POST[$_SESSION['session_var']]) ? $_POST[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_POST['sc']) ? $_POST['sc'] : null); |
| 609 | - if ($check !== $sc) |
|
| 610 | - $error = 'session_timeout'; |
|
| 631 | + if ($check !== $sc) { |
|
| 632 | + $error = 'session_timeout'; |
|
| 633 | + } |
|
| 611 | 634 | } |
| 612 | 635 | |
| 613 | 636 | // How about $_GET['sesc']? |
| 614 | 637 | elseif ($type == 'get') |
| 615 | 638 | { |
| 616 | 639 | $check = isset($_GET[$_SESSION['session_var']]) ? $_GET[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_GET['sesc']) ? $_GET['sesc'] : null); |
| 617 | - if ($check !== $sc) |
|
| 618 | - $error = 'session_verify_fail'; |
|
| 640 | + if ($check !== $sc) { |
|
| 641 | + $error = 'session_verify_fail'; |
|
| 642 | + } |
|
| 619 | 643 | } |
| 620 | 644 | |
| 621 | 645 | // Or can it be in either? |
@@ -623,13 +647,15 @@ discard block |
||
| 623 | 647 | { |
| 624 | 648 | $check = isset($_GET[$_SESSION['session_var']]) ? $_GET[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_GET['sesc']) ? $_GET['sesc'] : (isset($_POST[$_SESSION['session_var']]) ? $_POST[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_POST['sc']) ? $_POST['sc'] : null))); |
| 625 | 649 | |
| 626 | - if ($check !== $sc) |
|
| 627 | - $error = 'session_verify_fail'; |
|
| 650 | + if ($check !== $sc) { |
|
| 651 | + $error = 'session_verify_fail'; |
|
| 652 | + } |
|
| 628 | 653 | } |
| 629 | 654 | |
| 630 | 655 | // Verify that they aren't changing user agents on us - that could be bad. |
| 631 | - if ((!isset($_SESSION['USER_AGENT']) || $_SESSION['USER_AGENT'] != $_SERVER['HTTP_USER_AGENT']) && empty($modSettings['disableCheckUA'])) |
|
| 632 | - $error = 'session_verify_fail'; |
|
| 656 | + if ((!isset($_SESSION['USER_AGENT']) || $_SESSION['USER_AGENT'] != $_SERVER['HTTP_USER_AGENT']) && empty($modSettings['disableCheckUA'])) { |
|
| 657 | + $error = 'session_verify_fail'; |
|
| 658 | + } |
|
| 633 | 659 | |
| 634 | 660 | // Make sure a page with session check requirement is not being prefetched. |
| 635 | 661 | if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') |
@@ -640,30 +666,35 @@ discard block |
||
| 640 | 666 | } |
| 641 | 667 | |
| 642 | 668 | // Check the referring site - it should be the same server at least! |
| 643 | - if (isset($_SESSION['request_referer'])) |
|
| 644 | - $referrer = $_SESSION['request_referer']; |
|
| 645 | - else |
|
| 646 | - $referrer = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array(); |
|
| 669 | + if (isset($_SESSION['request_referer'])) { |
|
| 670 | + $referrer = $_SESSION['request_referer']; |
|
| 671 | + } else { |
|
| 672 | + $referrer = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array(); |
|
| 673 | + } |
|
| 647 | 674 | if (!empty($referrer['host'])) |
| 648 | 675 | { |
| 649 | - if (strpos($_SERVER['HTTP_HOST'], ':') !== false) |
|
| 650 | - $real_host = substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], ':')); |
|
| 651 | - else |
|
| 652 | - $real_host = $_SERVER['HTTP_HOST']; |
|
| 676 | + if (strpos($_SERVER['HTTP_HOST'], ':') !== false) { |
|
| 677 | + $real_host = substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], ':')); |
|
| 678 | + } else { |
|
| 679 | + $real_host = $_SERVER['HTTP_HOST']; |
|
| 680 | + } |
|
| 653 | 681 | |
| 654 | 682 | $parsed_url = parse_url($boardurl); |
| 655 | 683 | |
| 656 | 684 | // Are global cookies on? If so, let's check them ;). |
| 657 | 685 | if (!empty($modSettings['globalCookies'])) |
| 658 | 686 | { |
| 659 | - if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $parsed_url['host'], $parts) == 1) |
|
| 660 | - $parsed_url['host'] = $parts[1]; |
|
| 687 | + if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $parsed_url['host'], $parts) == 1) { |
|
| 688 | + $parsed_url['host'] = $parts[1]; |
|
| 689 | + } |
|
| 661 | 690 | |
| 662 | - if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $referrer['host'], $parts) == 1) |
|
| 663 | - $referrer['host'] = $parts[1]; |
|
| 691 | + if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $referrer['host'], $parts) == 1) { |
|
| 692 | + $referrer['host'] = $parts[1]; |
|
| 693 | + } |
|
| 664 | 694 | |
| 665 | - if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $real_host, $parts) == 1) |
|
| 666 | - $real_host = $parts[1]; |
|
| 695 | + if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $real_host, $parts) == 1) { |
|
| 696 | + $real_host = $parts[1]; |
|
| 697 | + } |
|
| 667 | 698 | } |
| 668 | 699 | |
| 669 | 700 | // Okay: referrer must either match parsed_url or real_host. |
@@ -681,12 +712,14 @@ discard block |
||
| 681 | 712 | $log_error = true; |
| 682 | 713 | } |
| 683 | 714 | |
| 684 | - if (strtolower($_SERVER['HTTP_USER_AGENT']) == 'hacker') |
|
| 685 | - fatal_error('Sound the alarm! It\'s a hacker! Close the castle gates!!', false); |
|
| 715 | + if (strtolower($_SERVER['HTTP_USER_AGENT']) == 'hacker') { |
|
| 716 | + fatal_error('Sound the alarm! It\'s a hacker! Close the castle gates!!', false); |
|
| 717 | + } |
|
| 686 | 718 | |
| 687 | 719 | // Everything is ok, return an empty string. |
| 688 | - if (!isset($error)) |
|
| 689 | - return ''; |
|
| 720 | + if (!isset($error)) { |
|
| 721 | + return ''; |
|
| 722 | + } |
|
| 690 | 723 | // A session error occurred, show the error. |
| 691 | 724 | elseif ($is_fatal) |
| 692 | 725 | { |
@@ -695,13 +728,14 @@ discard block |
||
| 695 | 728 | ob_end_clean(); |
| 696 | 729 | header('HTTP/1.1 403 Forbidden - Session timeout'); |
| 697 | 730 | die; |
| 731 | + } else { |
|
| 732 | + fatal_lang_error($error, isset($log_error) ? 'user' : false); |
|
| 698 | 733 | } |
| 699 | - else |
|
| 700 | - fatal_lang_error($error, isset($log_error) ? 'user' : false); |
|
| 701 | 734 | } |
| 702 | 735 | // A session error occurred, return the error to the calling function. |
| 703 | - else |
|
| 704 | - return $error; |
|
| 736 | + else { |
|
| 737 | + return $error; |
|
| 738 | + } |
|
| 705 | 739 | |
| 706 | 740 | // We really should never fall through here, for very important reasons. Let's make sure. |
| 707 | 741 | trigger_error('Hacking attempt...', E_USER_ERROR); |
@@ -717,10 +751,9 @@ discard block |
||
| 717 | 751 | { |
| 718 | 752 | global $modSettings; |
| 719 | 753 | |
| 720 | - if (isset($_GET['confirm']) && isset($_SESSION['confirm_' . $action]) && md5($_GET['confirm'] . $_SERVER['HTTP_USER_AGENT']) == $_SESSION['confirm_' . $action]) |
|
| 721 | - return true; |
|
| 722 | - |
|
| 723 | - else |
|
| 754 | + if (isset($_GET['confirm']) && isset($_SESSION['confirm_' . $action]) && md5($_GET['confirm'] . $_SERVER['HTTP_USER_AGENT']) == $_SESSION['confirm_' . $action]) { |
|
| 755 | + return true; |
|
| 756 | + } else |
|
| 724 | 757 | { |
| 725 | 758 | $token = md5(mt_rand() . session_id() . (string) microtime() . $modSettings['rand_seed']); |
| 726 | 759 | $_SESSION['confirm_' . $action] = md5($token . $_SERVER['HTTP_USER_AGENT']); |
@@ -771,9 +804,9 @@ discard block |
||
| 771 | 804 | $return = $_SESSION['token'][$type . '-' . $action][3]; |
| 772 | 805 | unset($_SESSION['token'][$type . '-' . $action]); |
| 773 | 806 | return $return; |
| 807 | + } else { |
|
| 808 | + return ''; |
|
| 774 | 809 | } |
| 775 | - else |
|
| 776 | - return ''; |
|
| 777 | 810 | } |
| 778 | 811 | |
| 779 | 812 | // This nasty piece of code validates a token. |
@@ -804,12 +837,14 @@ discard block |
||
| 804 | 837 | fatal_lang_error('token_verify_fail', false); |
| 805 | 838 | } |
| 806 | 839 | // Remove this token as its useless |
| 807 | - else |
|
| 808 | - unset($_SESSION['token'][$type . '-' . $action]); |
|
| 840 | + else { |
|
| 841 | + unset($_SESSION['token'][$type . '-' . $action]); |
|
| 842 | + } |
|
| 809 | 843 | |
| 810 | 844 | // Randomly check if we should remove some older tokens. |
| 811 | - if (mt_rand(0, 138) == 23) |
|
| 812 | - cleanTokens(); |
|
| 845 | + if (mt_rand(0, 138) == 23) { |
|
| 846 | + cleanTokens(); |
|
| 847 | + } |
|
| 813 | 848 | |
| 814 | 849 | return false; |
| 815 | 850 | } |
@@ -824,14 +859,16 @@ discard block |
||
| 824 | 859 | function cleanTokens($complete = false) |
| 825 | 860 | { |
| 826 | 861 | // We appreciate cleaning up after yourselves. |
| 827 | - if (!isset($_SESSION['token'])) |
|
| 828 | - return; |
|
| 862 | + if (!isset($_SESSION['token'])) { |
|
| 863 | + return; |
|
| 864 | + } |
|
| 829 | 865 | |
| 830 | 866 | // Clean up tokens, trying to give enough time still. |
| 831 | - foreach ($_SESSION['token'] as $key => $data) |
|
| 832 | - if ($data[2] + 10800 < time() || $complete) |
|
| 867 | + foreach ($_SESSION['token'] as $key => $data) { |
|
| 868 | + if ($data[2] + 10800 < time() || $complete) |
|
| 833 | 869 | unset($_SESSION['token'][$key]); |
| 834 | -} |
|
| 870 | + } |
|
| 871 | + } |
|
| 835 | 872 | |
| 836 | 873 | /** |
| 837 | 874 | * Check whether a form has been submitted twice. |
@@ -849,37 +886,40 @@ discard block |
||
| 849 | 886 | { |
| 850 | 887 | global $context; |
| 851 | 888 | |
| 852 | - if (!isset($_SESSION['forms'])) |
|
| 853 | - $_SESSION['forms'] = array(); |
|
| 889 | + if (!isset($_SESSION['forms'])) { |
|
| 890 | + $_SESSION['forms'] = array(); |
|
| 891 | + } |
|
| 854 | 892 | |
| 855 | 893 | // Register a form number and store it in the session stack. (use this on the page that has the form.) |
| 856 | 894 | if ($action == 'register') |
| 857 | 895 | { |
| 858 | 896 | $context['form_sequence_number'] = 0; |
| 859 | - while (empty($context['form_sequence_number']) || in_array($context['form_sequence_number'], $_SESSION['forms'])) |
|
| 860 | - $context['form_sequence_number'] = mt_rand(1, 16000000); |
|
| 897 | + while (empty($context['form_sequence_number']) || in_array($context['form_sequence_number'], $_SESSION['forms'])) { |
|
| 898 | + $context['form_sequence_number'] = mt_rand(1, 16000000); |
|
| 899 | + } |
|
| 861 | 900 | } |
| 862 | 901 | // Check whether the submitted number can be found in the session. |
| 863 | 902 | elseif ($action == 'check') |
| 864 | 903 | { |
| 865 | - if (!isset($_REQUEST['seqnum'])) |
|
| 866 | - return true; |
|
| 867 | - elseif (!in_array($_REQUEST['seqnum'], $_SESSION['forms'])) |
|
| 904 | + if (!isset($_REQUEST['seqnum'])) { |
|
| 905 | + return true; |
|
| 906 | + } elseif (!in_array($_REQUEST['seqnum'], $_SESSION['forms'])) |
|
| 868 | 907 | { |
| 869 | 908 | $_SESSION['forms'][] = (int) $_REQUEST['seqnum']; |
| 870 | 909 | return true; |
| 910 | + } elseif ($is_fatal) { |
|
| 911 | + fatal_lang_error('error_form_already_submitted', false); |
|
| 912 | + } else { |
|
| 913 | + return false; |
|
| 871 | 914 | } |
| 872 | - elseif ($is_fatal) |
|
| 873 | - fatal_lang_error('error_form_already_submitted', false); |
|
| 874 | - else |
|
| 875 | - return false; |
|
| 876 | 915 | } |
| 877 | 916 | // Don't check, just free the stack number. |
| 878 | - elseif ($action == 'free' && isset($_REQUEST['seqnum']) && in_array($_REQUEST['seqnum'], $_SESSION['forms'])) |
|
| 879 | - $_SESSION['forms'] = array_diff($_SESSION['forms'], array($_REQUEST['seqnum'])); |
|
| 880 | - elseif ($action != 'free') |
|
| 881 | - trigger_error('checkSubmitOnce(): Invalid action \'' . $action . '\'', E_USER_WARNING); |
|
| 882 | -} |
|
| 917 | + elseif ($action == 'free' && isset($_REQUEST['seqnum']) && in_array($_REQUEST['seqnum'], $_SESSION['forms'])) { |
|
| 918 | + $_SESSION['forms'] = array_diff($_SESSION['forms'], array($_REQUEST['seqnum'])); |
|
| 919 | + } elseif ($action != 'free') { |
|
| 920 | + trigger_error('checkSubmitOnce(): Invalid action \'' . $action . '\'', E_USER_WARNING); |
|
| 921 | + } |
|
| 922 | + } |
|
| 883 | 923 | |
| 884 | 924 | /** |
| 885 | 925 | * Check the user's permissions. |
@@ -896,16 +936,19 @@ discard block |
||
| 896 | 936 | global $user_info, $smcFunc; |
| 897 | 937 | |
| 898 | 938 | // You're always allowed to do nothing. (unless you're a working man, MR. LAZY :P!) |
| 899 | - if (empty($permission)) |
|
| 900 | - return true; |
|
| 939 | + if (empty($permission)) { |
|
| 940 | + return true; |
|
| 941 | + } |
|
| 901 | 942 | |
| 902 | 943 | // You're never allowed to do something if your data hasn't been loaded yet! |
| 903 | - if (empty($user_info)) |
|
| 904 | - return false; |
|
| 944 | + if (empty($user_info)) { |
|
| 945 | + return false; |
|
| 946 | + } |
|
| 905 | 947 | |
| 906 | 948 | // Administrators are supermen :P. |
| 907 | - if ($user_info['is_admin']) |
|
| 908 | - return true; |
|
| 949 | + if ($user_info['is_admin']) { |
|
| 950 | + return true; |
|
| 951 | + } |
|
| 909 | 952 | |
| 910 | 953 | // Let's ensure this is an array. |
| 911 | 954 | $permission = (array) $permission; |
@@ -913,14 +956,16 @@ discard block |
||
| 913 | 956 | // Are we checking the _current_ board, or some other boards? |
| 914 | 957 | if ($boards === null) |
| 915 | 958 | { |
| 916 | - if (count(array_intersect($permission, $user_info['permissions'])) != 0) |
|
| 917 | - return true; |
|
| 959 | + if (count(array_intersect($permission, $user_info['permissions'])) != 0) { |
|
| 960 | + return true; |
|
| 961 | + } |
|
| 918 | 962 | // You aren't allowed, by default. |
| 919 | - else |
|
| 920 | - return false; |
|
| 963 | + else { |
|
| 964 | + return false; |
|
| 965 | + } |
|
| 966 | + } elseif (!is_array($boards)) { |
|
| 967 | + $boards = array($boards); |
|
| 921 | 968 | } |
| 922 | - elseif (!is_array($boards)) |
|
| 923 | - $boards = array($boards); |
|
| 924 | 969 | |
| 925 | 970 | $request = $smcFunc['db_query']('', ' |
| 926 | 971 | SELECT MIN(bp.add_deny) AS add_deny |
@@ -943,12 +988,14 @@ discard block |
||
| 943 | 988 | ); |
| 944 | 989 | |
| 945 | 990 | // Make sure they can do it on all of the boards. |
| 946 | - if ($smcFunc['db_num_rows']($request) != count($boards)) |
|
| 947 | - return false; |
|
| 991 | + if ($smcFunc['db_num_rows']($request) != count($boards)) { |
|
| 992 | + return false; |
|
| 993 | + } |
|
| 948 | 994 | |
| 949 | 995 | $result = true; |
| 950 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 951 | - $result &= !empty($row['add_deny']); |
|
| 996 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 997 | + $result &= !empty($row['add_deny']); |
|
| 998 | + } |
|
| 952 | 999 | $smcFunc['db_free_result']($request); |
| 953 | 1000 | |
| 954 | 1001 | // If the query returned 1, they can do it... otherwise, they can't. |
@@ -1013,9 +1060,10 @@ discard block |
||
| 1013 | 1060 | |
| 1014 | 1061 | // If you're doing something on behalf of some "heavy" permissions, validate your session. |
| 1015 | 1062 | // (take out the heavy permissions, and if you can't do anything but those, you need a validated session.) |
| 1016 | - if (!allowedTo(array_diff($permission, $heavy_permissions), $boards)) |
|
| 1017 | - validateSession(); |
|
| 1018 | -} |
|
| 1063 | + if (!allowedTo(array_diff($permission, $heavy_permissions), $boards)) { |
|
| 1064 | + validateSession(); |
|
| 1065 | + } |
|
| 1066 | + } |
|
| 1019 | 1067 | |
| 1020 | 1068 | /** |
| 1021 | 1069 | * Return the boards a user has a certain (board) permission on. (array(0) if all.) |
@@ -1034,8 +1082,9 @@ discard block |
||
| 1034 | 1082 | global $user_info, $smcFunc; |
| 1035 | 1083 | |
| 1036 | 1084 | // Arrays are nice, most of the time. |
| 1037 | - if (!is_array($permissions)) |
|
| 1038 | - $permissions = array($permissions); |
|
| 1085 | + if (!is_array($permissions)) { |
|
| 1086 | + $permissions = array($permissions); |
|
| 1087 | + } |
|
| 1039 | 1088 | |
| 1040 | 1089 | /* |
| 1041 | 1090 | * Set $simple to true to use this function as it were in SMF 2.0.x. |
@@ -1047,13 +1096,14 @@ discard block |
||
| 1047 | 1096 | // Administrators are all powerful, sorry. |
| 1048 | 1097 | if ($user_info['is_admin']) |
| 1049 | 1098 | { |
| 1050 | - if ($simple) |
|
| 1051 | - return array(0); |
|
| 1052 | - else |
|
| 1099 | + if ($simple) { |
|
| 1100 | + return array(0); |
|
| 1101 | + } else |
|
| 1053 | 1102 | { |
| 1054 | 1103 | $boards = array(); |
| 1055 | - foreach ($permissions as $permission) |
|
| 1056 | - $boards[$permission] = array(0); |
|
| 1104 | + foreach ($permissions as $permission) { |
|
| 1105 | + $boards[$permission] = array(0); |
|
| 1106 | + } |
|
| 1057 | 1107 | |
| 1058 | 1108 | return $boards; |
| 1059 | 1109 | } |
@@ -1085,31 +1135,32 @@ discard block |
||
| 1085 | 1135 | { |
| 1086 | 1136 | if ($simple) |
| 1087 | 1137 | { |
| 1088 | - if (empty($row['add_deny'])) |
|
| 1089 | - $deny_boards[] = $row['id_board']; |
|
| 1090 | - else |
|
| 1091 | - $boards[] = $row['id_board']; |
|
| 1092 | - } |
|
| 1093 | - else |
|
| 1138 | + if (empty($row['add_deny'])) { |
|
| 1139 | + $deny_boards[] = $row['id_board']; |
|
| 1140 | + } else { |
|
| 1141 | + $boards[] = $row['id_board']; |
|
| 1142 | + } |
|
| 1143 | + } else |
|
| 1094 | 1144 | { |
| 1095 | - if (empty($row['add_deny'])) |
|
| 1096 | - $deny_boards[$row['permission']][] = $row['id_board']; |
|
| 1097 | - else |
|
| 1098 | - $boards[$row['permission']][] = $row['id_board']; |
|
| 1145 | + if (empty($row['add_deny'])) { |
|
| 1146 | + $deny_boards[$row['permission']][] = $row['id_board']; |
|
| 1147 | + } else { |
|
| 1148 | + $boards[$row['permission']][] = $row['id_board']; |
|
| 1149 | + } |
|
| 1099 | 1150 | } |
| 1100 | 1151 | } |
| 1101 | 1152 | $smcFunc['db_free_result']($request); |
| 1102 | 1153 | |
| 1103 | - if ($simple) |
|
| 1104 | - $boards = array_unique(array_values(array_diff($boards, $deny_boards))); |
|
| 1105 | - else |
|
| 1154 | + if ($simple) { |
|
| 1155 | + $boards = array_unique(array_values(array_diff($boards, $deny_boards))); |
|
| 1156 | + } else |
|
| 1106 | 1157 | { |
| 1107 | 1158 | foreach ($permissions as $permission) |
| 1108 | 1159 | { |
| 1109 | 1160 | // never had it to start with |
| 1110 | - if (empty($boards[$permission])) |
|
| 1111 | - $boards[$permission] = array(); |
|
| 1112 | - else |
|
| 1161 | + if (empty($boards[$permission])) { |
|
| 1162 | + $boards[$permission] = array(); |
|
| 1163 | + } else |
|
| 1113 | 1164 | { |
| 1114 | 1165 | // Or it may have been removed |
| 1115 | 1166 | $deny_boards[$permission] = isset($deny_boards[$permission]) ? $deny_boards[$permission] : array(); |
@@ -1145,10 +1196,11 @@ discard block |
||
| 1145 | 1196 | |
| 1146 | 1197 | |
| 1147 | 1198 | // Moderators are free... |
| 1148 | - if (!allowedTo('moderate_board')) |
|
| 1149 | - $timeLimit = isset($timeOverrides[$error_type]) ? $timeOverrides[$error_type] : $modSettings['spamWaitTime']; |
|
| 1150 | - else |
|
| 1151 | - $timeLimit = 2; |
|
| 1199 | + if (!allowedTo('moderate_board')) { |
|
| 1200 | + $timeLimit = isset($timeOverrides[$error_type]) ? $timeOverrides[$error_type] : $modSettings['spamWaitTime']; |
|
| 1201 | + } else { |
|
| 1202 | + $timeLimit = 2; |
|
| 1203 | + } |
|
| 1152 | 1204 | |
| 1153 | 1205 | call_integration_hook('integrate_spam_protection', array(&$timeOverrides, &$timeLimit)); |
| 1154 | 1206 | |
@@ -1175,8 +1227,9 @@ discard block |
||
| 1175 | 1227 | if ($smcFunc['db_affected_rows']() != 1) |
| 1176 | 1228 | { |
| 1177 | 1229 | // Spammer! You only have to wait a *few* seconds! |
| 1178 | - if (!$only_return_result) |
|
| 1179 | - fatal_lang_error($error_type . '_WaitTime_broken', false, array($timeLimit)); |
|
| 1230 | + if (!$only_return_result) { |
|
| 1231 | + fatal_lang_error($error_type . '_WaitTime_broken', false, array($timeLimit)); |
|
| 1232 | + } |
|
| 1180 | 1233 | |
| 1181 | 1234 | return true; |
| 1182 | 1235 | } |
@@ -1194,11 +1247,13 @@ discard block |
||
| 1194 | 1247 | */ |
| 1195 | 1248 | function secureDirectory($path, $attachments = false) |
| 1196 | 1249 | { |
| 1197 | - if (empty($path)) |
|
| 1198 | - return 'empty_path'; |
|
| 1250 | + if (empty($path)) { |
|
| 1251 | + return 'empty_path'; |
|
| 1252 | + } |
|
| 1199 | 1253 | |
| 1200 | - if (!is_writable($path)) |
|
| 1201 | - return 'path_not_writable'; |
|
| 1254 | + if (!is_writable($path)) { |
|
| 1255 | + return 'path_not_writable'; |
|
| 1256 | + } |
|
| 1202 | 1257 | |
| 1203 | 1258 | $directoryname = basename($path); |
| 1204 | 1259 | |
@@ -1210,9 +1265,9 @@ discard block |
||
| 1210 | 1265 | |
| 1211 | 1266 | RemoveHandler .php .php3 .phtml .cgi .fcgi .pl .fpl .shtml'; |
| 1212 | 1267 | |
| 1213 | - if (file_exists($path . '/.htaccess')) |
|
| 1214 | - $errors[] = 'htaccess_exists'; |
|
| 1215 | - else |
|
| 1268 | + if (file_exists($path . '/.htaccess')) { |
|
| 1269 | + $errors[] = 'htaccess_exists'; |
|
| 1270 | + } else |
|
| 1216 | 1271 | { |
| 1217 | 1272 | $fh = @fopen($path . '/.htaccess', 'w'); |
| 1218 | 1273 | if ($fh) { |
@@ -1224,9 +1279,9 @@ discard block |
||
| 1224 | 1279 | $errors[] = 'htaccess_cannot_create_file'; |
| 1225 | 1280 | } |
| 1226 | 1281 | |
| 1227 | - if (file_exists($path . '/index.php')) |
|
| 1228 | - $errors[] = 'index-php_exists'; |
|
| 1229 | - else |
|
| 1282 | + if (file_exists($path . '/index.php')) { |
|
| 1283 | + $errors[] = 'index-php_exists'; |
|
| 1284 | + } else |
|
| 1230 | 1285 | { |
| 1231 | 1286 | $fh = @fopen($path . '/index.php', 'w'); |
| 1232 | 1287 | if ($fh) { |
@@ -1253,11 +1308,12 @@ discard block |
||
| 1253 | 1308 | $errors[] = 'index-php_cannot_create_file'; |
| 1254 | 1309 | } |
| 1255 | 1310 | |
| 1256 | - if (!empty($errors)) |
|
| 1257 | - return $errors; |
|
| 1258 | - else |
|
| 1259 | - return true; |
|
| 1260 | -} |
|
| 1311 | + if (!empty($errors)) { |
|
| 1312 | + return $errors; |
|
| 1313 | + } else { |
|
| 1314 | + return true; |
|
| 1315 | + } |
|
| 1316 | + } |
|
| 1261 | 1317 | |
| 1262 | 1318 | /** |
| 1263 | 1319 | * This sets the X-Frame-Options header. |
@@ -1270,14 +1326,16 @@ discard block |
||
| 1270 | 1326 | global $modSettings; |
| 1271 | 1327 | |
| 1272 | 1328 | $option = 'SAMEORIGIN'; |
| 1273 | - if (is_null($override) && !empty($modSettings['frame_security'])) |
|
| 1274 | - $option = $modSettings['frame_security']; |
|
| 1275 | - elseif (in_array($override, array('SAMEORIGIN', 'DENY'))) |
|
| 1276 | - $option = $override; |
|
| 1329 | + if (is_null($override) && !empty($modSettings['frame_security'])) { |
|
| 1330 | + $option = $modSettings['frame_security']; |
|
| 1331 | + } elseif (in_array($override, array('SAMEORIGIN', 'DENY'))) { |
|
| 1332 | + $option = $override; |
|
| 1333 | + } |
|
| 1277 | 1334 | |
| 1278 | 1335 | // Don't bother setting the header if we have disabled it. |
| 1279 | - if ($option == 'DISABLE') |
|
| 1280 | - return; |
|
| 1336 | + if ($option == 'DISABLE') { |
|
| 1337 | + return; |
|
| 1338 | + } |
|
| 1281 | 1339 | |
| 1282 | 1340 | // Finally set it. |
| 1283 | 1341 | header('X-Frame-Options: ' . $option); |