@@ -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,27 +48,35 @@ 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 | - if (!is_array($modSettings['attachmentUploadDir'])) |
|
| 66 | - $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
| 73 | + if (!is_array($modSettings['attachmentUploadDir'])) { |
|
| 74 | + $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
| 75 | + } |
|
| 67 | 76 | |
| 68 | - if (!empty($cache_enable)) |
|
| 69 | - cache_put_data('modSettings', $modSettings, 90); |
|
| 77 | + if (!empty($cache_enable)) { |
|
| 78 | + cache_put_data('modSettings', $modSettings, 90); |
|
| 79 | + } |
|
| 70 | 80 | } |
| 71 | 81 | |
| 72 | 82 | $modSettings['cache_enable'] = $cache_enable; |
@@ -86,8 +96,9 @@ discard block |
||
| 86 | 96 | }; |
| 87 | 97 | $fix_utf8mb4 = function($string) use ($utf8, $smcFunc) |
| 88 | 98 | { |
| 89 | - if (!$utf8 || $smcFunc['db_mb4']) |
|
| 90 | - return $string; |
|
| 99 | + if (!$utf8 || $smcFunc['db_mb4']) { |
|
| 100 | + return $string; |
|
| 101 | + } |
|
| 91 | 102 | |
| 92 | 103 | $i = 0; |
| 93 | 104 | $len = strlen($string); |
@@ -99,18 +110,15 @@ discard block |
||
| 99 | 110 | { |
| 100 | 111 | $new_string .= $string[$i]; |
| 101 | 112 | $i++; |
| 102 | - } |
|
| 103 | - elseif ($ord < 224) |
|
| 113 | + } elseif ($ord < 224) |
|
| 104 | 114 | { |
| 105 | 115 | $new_string .= $string[$i] . $string[$i + 1]; |
| 106 | 116 | $i += 2; |
| 107 | - } |
|
| 108 | - elseif ($ord < 240) |
|
| 117 | + } elseif ($ord < 240) |
|
| 109 | 118 | { |
| 110 | 119 | $new_string .= $string[$i] . $string[$i + 1] . $string[$i + 2]; |
| 111 | 120 | $i += 3; |
| 112 | - } |
|
| 113 | - elseif ($ord < 248) |
|
| 121 | + } elseif ($ord < 248) |
|
| 114 | 122 | { |
| 115 | 123 | // Magic happens. |
| 116 | 124 | $val = (ord($string[$i]) & 0x07) << 18; |
@@ -154,8 +162,7 @@ discard block |
||
| 154 | 162 | { |
| 155 | 163 | $result = array_search($needle, array_slice($haystack_arr, $offset)); |
| 156 | 164 | return is_int($result) ? $result + $offset : false; |
| 157 | - } |
|
| 158 | - else |
|
| 165 | + } else |
|
| 159 | 166 | { |
| 160 | 167 | $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); |
| 161 | 168 | $needle_size = count($needle_arr); |
@@ -164,8 +171,9 @@ discard block |
||
| 164 | 171 | while ((int) $result === $result) |
| 165 | 172 | { |
| 166 | 173 | $offset += $result; |
| 167 | - if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) |
|
| 168 | - return $offset; |
|
| 174 | + if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) { |
|
| 175 | + return $offset; |
|
| 176 | + } |
|
| 169 | 177 | $result = array_search($needle_arr[0], array_slice($haystack_arr, ++$offset)); |
| 170 | 178 | } |
| 171 | 179 | return false; |
@@ -203,8 +211,9 @@ discard block |
||
| 203 | 211 | $string = $ent_check($string); |
| 204 | 212 | preg_match('~^(' . $ent_list . '|.){' . $smcFunc['strlen'](substr($string, 0, $length)) . '}~' . ($utf8 ? 'u' : ''), $string, $matches); |
| 205 | 213 | $string = $matches[0]; |
| 206 | - while (strlen($string) > $length) |
|
| 207 | - $string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string); |
|
| 214 | + while (strlen($string) > $length) { |
|
| 215 | + $string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string); |
|
| 216 | + } |
|
| 208 | 217 | return $string; |
| 209 | 218 | }, |
| 210 | 219 | 'ucfirst' => $utf8 ? function($string) use (&$smcFunc) |
@@ -214,23 +223,25 @@ discard block |
||
| 214 | 223 | 'ucwords' => $utf8 ? function($string) use (&$smcFunc) |
| 215 | 224 | { |
| 216 | 225 | $words = preg_split('~([\s\r\n\t]+)~', $string, -1, PREG_SPLIT_DELIM_CAPTURE); |
| 217 | - for ($i = 0, $n = count($words); $i < $n; $i += 2) |
|
| 218 | - $words[$i] = $smcFunc['ucfirst']($words[$i]); |
|
| 226 | + for ($i = 0, $n = count($words); $i < $n; $i += 2) { |
|
| 227 | + $words[$i] = $smcFunc['ucfirst']($words[$i]); |
|
| 228 | + } |
|
| 219 | 229 | return implode('', $words); |
| 220 | 230 | } : 'ucwords', |
| 221 | 231 | ); |
| 222 | 232 | |
| 223 | 233 | // Setting the timezone is a requirement for some functions. |
| 224 | - if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list())) |
|
| 225 | - date_default_timezone_set($modSettings['default_timezone']); |
|
| 226 | - else |
|
| 234 | + if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list())) { |
|
| 235 | + date_default_timezone_set($modSettings['default_timezone']); |
|
| 236 | + } else |
|
| 227 | 237 | { |
| 228 | 238 | // Get PHP's default timezone, if set |
| 229 | 239 | $ini_tz = ini_get('date.timezone'); |
| 230 | - if (!empty($ini_tz)) |
|
| 231 | - $modSettings['default_timezone'] = $ini_tz; |
|
| 232 | - else |
|
| 233 | - $modSettings['default_timezone'] = ''; |
|
| 240 | + if (!empty($ini_tz)) { |
|
| 241 | + $modSettings['default_timezone'] = $ini_tz; |
|
| 242 | + } else { |
|
| 243 | + $modSettings['default_timezone'] = ''; |
|
| 244 | + } |
|
| 234 | 245 | |
| 235 | 246 | // If date.timezone is unset, invalid, or just plain weird, make a best guess |
| 236 | 247 | if (!in_array($modSettings['default_timezone'], timezone_identifiers_list())) |
@@ -248,22 +259,26 @@ discard block |
||
| 248 | 259 | if (($modSettings['load_average'] = cache_get_data('loadavg', 90)) == null) |
| 249 | 260 | { |
| 250 | 261 | $modSettings['load_average'] = @file_get_contents('/proc/loadavg'); |
| 251 | - if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) |
|
| 252 | - $modSettings['load_average'] = (float) $matches[1]; |
|
| 253 | - elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) |
|
| 254 | - $modSettings['load_average'] = (float) $matches[1]; |
|
| 255 | - else |
|
| 256 | - unset($modSettings['load_average']); |
|
| 262 | + if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) { |
|
| 263 | + $modSettings['load_average'] = (float) $matches[1]; |
|
| 264 | + } elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) { |
|
| 265 | + $modSettings['load_average'] = (float) $matches[1]; |
|
| 266 | + } else { |
|
| 267 | + unset($modSettings['load_average']); |
|
| 268 | + } |
|
| 257 | 269 | |
| 258 | - if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) |
|
| 259 | - cache_put_data('loadavg', $modSettings['load_average'], 90); |
|
| 270 | + if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) { |
|
| 271 | + cache_put_data('loadavg', $modSettings['load_average'], 90); |
|
| 272 | + } |
|
| 260 | 273 | } |
| 261 | 274 | |
| 262 | - if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) |
|
| 263 | - call_integration_hook('integrate_load_average', array($modSettings['load_average'])); |
|
| 275 | + if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) { |
|
| 276 | + call_integration_hook('integrate_load_average', array($modSettings['load_average'])); |
|
| 277 | + } |
|
| 264 | 278 | |
| 265 | - if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) |
|
| 266 | - display_loadavg_error(); |
|
| 279 | + if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) { |
|
| 280 | + display_loadavg_error(); |
|
| 281 | + } |
|
| 267 | 282 | } |
| 268 | 283 | |
| 269 | 284 | // Is post moderation alive and well? Everywhere else assumes this has been defined, so let's make sure it is. |
@@ -284,8 +299,9 @@ discard block |
||
| 284 | 299 | if (defined('SMF_INTEGRATION_SETTINGS')) |
| 285 | 300 | { |
| 286 | 301 | $integration_settings = smf_json_decode(SMF_INTEGRATION_SETTINGS, true); |
| 287 | - foreach ($integration_settings as $hook => $function) |
|
| 288 | - add_integration_function($hook, $function, '', false); |
|
| 302 | + foreach ($integration_settings as $hook => $function) { |
|
| 303 | + add_integration_function($hook, $function, '', false); |
|
| 304 | + } |
|
| 289 | 305 | } |
| 290 | 306 | |
| 291 | 307 | // Any files to pre include? |
@@ -295,8 +311,9 @@ discard block |
||
| 295 | 311 | foreach ($pre_includes as $include) |
| 296 | 312 | { |
| 297 | 313 | $include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
| 298 | - if (file_exists($include)) |
|
| 299 | - require_once($include); |
|
| 314 | + if (file_exists($include)) { |
|
| 315 | + require_once($include); |
|
| 316 | + } |
|
| 300 | 317 | } |
| 301 | 318 | } |
| 302 | 319 | |
@@ -400,27 +417,28 @@ discard block |
||
| 400 | 417 | break; |
| 401 | 418 | } |
| 402 | 419 | } |
| 420 | + } else { |
|
| 421 | + $id_member = 0; |
|
| 403 | 422 | } |
| 404 | - else |
|
| 405 | - $id_member = 0; |
|
| 406 | 423 | |
| 407 | 424 | if (empty($id_member) && isset($_COOKIE[$cookiename])) |
| 408 | 425 | { |
| 409 | 426 | $cookie_data = smf_json_decode($_COOKIE[$cookiename], true, false); |
| 410 | 427 | |
| 411 | - if (empty($cookie_data)) |
|
| 412 | - $cookie_data = safe_unserialize($_COOKIE[$cookiename]); |
|
| 428 | + if (empty($cookie_data)) { |
|
| 429 | + $cookie_data = safe_unserialize($_COOKIE[$cookiename]); |
|
| 430 | + } |
|
| 413 | 431 | |
| 414 | 432 | list ($id_member, $password) = $cookie_data; |
| 415 | 433 | $id_member = !empty($id_member) && strlen($password) > 0 ? (int) $id_member : 0; |
| 416 | - } |
|
| 417 | - elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA']))) |
|
| 434 | + } elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA']))) |
|
| 418 | 435 | { |
| 419 | 436 | // @todo Perhaps we can do some more checking on this, such as on the first octet of the IP? |
| 420 | 437 | $cookie_data = smf_json_decode($_SESSION['login_' . $cookiename]); |
| 421 | 438 | |
| 422 | - if (empty($cookie_data)) |
|
| 423 | - $cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]); |
|
| 439 | + if (empty($cookie_data)) { |
|
| 440 | + $cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]); |
|
| 441 | + } |
|
| 424 | 442 | |
| 425 | 443 | list ($id_member, $password, $login_span) = $cookie_data; |
| 426 | 444 | $id_member = !empty($id_member) && strlen($password) == 128 && $login_span > time() ? (int) $id_member : 0; |
@@ -445,30 +463,34 @@ discard block |
||
| 445 | 463 | $user_settings = $smcFunc['db_fetch_assoc']($request); |
| 446 | 464 | $smcFunc['db_free_result']($request); |
| 447 | 465 | |
| 448 | - if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false) |
|
| 449 | - $user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret); |
|
| 466 | + if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false) { |
|
| 467 | + $user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret); |
|
| 468 | + } |
|
| 450 | 469 | |
| 451 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
| 452 | - cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
| 470 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
| 471 | + cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
| 472 | + } |
|
| 453 | 473 | } |
| 454 | 474 | |
| 455 | 475 | // Did we find 'im? If not, junk it. |
| 456 | 476 | if (!empty($user_settings)) |
| 457 | 477 | { |
| 458 | 478 | // As much as the password should be right, we can assume the integration set things up. |
| 459 | - if (!empty($already_verified) && $already_verified === true) |
|
| 460 | - $check = true; |
|
| 479 | + if (!empty($already_verified) && $already_verified === true) { |
|
| 480 | + $check = true; |
|
| 481 | + } |
|
| 461 | 482 | // SHA-512 hash should be 128 characters long. |
| 462 | - elseif (strlen($password) == 128) |
|
| 463 | - $check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password; |
|
| 464 | - else |
|
| 465 | - $check = false; |
|
| 483 | + elseif (strlen($password) == 128) { |
|
| 484 | + $check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password; |
|
| 485 | + } else { |
|
| 486 | + $check = false; |
|
| 487 | + } |
|
| 466 | 488 | |
| 467 | 489 | // Wrong password or not activated - either way, you're going nowhere. |
| 468 | 490 | $id_member = $check && ($user_settings['is_activated'] == 1 || $user_settings['is_activated'] == 11) ? (int) $user_settings['id_member'] : 0; |
| 491 | + } else { |
|
| 492 | + $id_member = 0; |
|
| 469 | 493 | } |
| 470 | - else |
|
| 471 | - $id_member = 0; |
|
| 472 | 494 | |
| 473 | 495 | // If we no longer have the member maybe they're being all hackey, stop brute force! |
| 474 | 496 | if (!$id_member) |
@@ -492,8 +514,9 @@ discard block |
||
| 492 | 514 | |
| 493 | 515 | list ($tfamember, $tfasecret) = $tfa_data; |
| 494 | 516 | |
| 495 | - if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member) |
|
| 496 | - $tfasecret = null; |
|
| 517 | + if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member) { |
|
| 518 | + $tfasecret = null; |
|
| 519 | + } |
|
| 497 | 520 | } |
| 498 | 521 | |
| 499 | 522 | if (empty($tfasecret) || hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']) != $tfasecret) |
@@ -513,10 +536,12 @@ discard block |
||
| 513 | 536 | // Are we forcing 2FA? Need to check if the user groups actually require 2FA |
| 514 | 537 | elseif (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] >= 2 && $id_member && empty($user_settings['tfa_secret'])) |
| 515 | 538 | { |
| 516 | - if ($modSettings['tfa_mode'] == 2) //only do this if we are just forcing SOME membergroups |
|
| 539 | + if ($modSettings['tfa_mode'] == 2) { |
|
| 540 | + //only do this if we are just forcing SOME membergroups |
|
| 517 | 541 | { |
| 518 | 542 | //Build an array of ALL user membergroups. |
| 519 | 543 | $full_groups = array($user_settings['id_group']); |
| 544 | + } |
|
| 520 | 545 | if (!empty($user_settings['additional_groups'])) |
| 521 | 546 | { |
| 522 | 547 | $full_groups = array_merge($full_groups, explode(',', $user_settings['additional_groups'])); |
@@ -536,15 +561,17 @@ discard block |
||
| 536 | 561 | ); |
| 537 | 562 | $row = $smcFunc['db_fetch_assoc']($request); |
| 538 | 563 | $smcFunc['db_free_result']($request); |
| 564 | + } else { |
|
| 565 | + $row['total'] = 1; |
|
| 539 | 566 | } |
| 540 | - else |
|
| 541 | - $row['total'] = 1; //simplifies logics in the next "if" |
|
| 567 | + //simplifies logics in the next "if" |
|
| 542 | 568 | |
| 543 | 569 | $area = !empty($_REQUEST['area']) ? $_REQUEST['area'] : ''; |
| 544 | 570 | $action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : ''; |
| 545 | 571 | |
| 546 | - if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) |
|
| 547 | - redirectexit('action=profile;area=tfasetup;forced'); |
|
| 572 | + if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) { |
|
| 573 | + redirectexit('action=profile;area=tfasetup;forced'); |
|
| 574 | + } |
|
| 548 | 575 | } |
| 549 | 576 | } |
| 550 | 577 | |
@@ -581,33 +608,37 @@ discard block |
||
| 581 | 608 | 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'])); |
| 582 | 609 | $user_settings['last_login'] = time(); |
| 583 | 610 | |
| 584 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
| 585 | - cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
| 611 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
| 612 | + cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
| 613 | + } |
|
| 586 | 614 | |
| 587 | - if (!empty($modSettings['cache_enable'])) |
|
| 588 | - cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600); |
|
| 615 | + if (!empty($modSettings['cache_enable'])) { |
|
| 616 | + cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600); |
|
| 617 | + } |
|
| 589 | 618 | } |
| 619 | + } elseif (empty($_SESSION['id_msg_last_visit'])) { |
|
| 620 | + $_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit']; |
|
| 590 | 621 | } |
| 591 | - elseif (empty($_SESSION['id_msg_last_visit'])) |
|
| 592 | - $_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit']; |
|
| 593 | 622 | |
| 594 | 623 | $username = $user_settings['member_name']; |
| 595 | 624 | |
| 596 | - if (empty($user_settings['additional_groups'])) |
|
| 597 | - $user_info = array( |
|
| 625 | + if (empty($user_settings['additional_groups'])) { |
|
| 626 | + $user_info = array( |
|
| 598 | 627 | 'groups' => array($user_settings['id_group'], $user_settings['id_post_group']) |
| 599 | 628 | ); |
| 600 | - else |
|
| 601 | - $user_info = array( |
|
| 629 | + } else { |
|
| 630 | + $user_info = array( |
|
| 602 | 631 | 'groups' => array_merge( |
| 603 | 632 | array($user_settings['id_group'], $user_settings['id_post_group']), |
| 604 | 633 | explode(',', $user_settings['additional_groups']) |
| 605 | 634 | ) |
| 606 | 635 | ); |
| 636 | + } |
|
| 607 | 637 | |
| 608 | 638 | // Because history has proven that it is possible for groups to go bad - clean up in case. |
| 609 | - foreach ($user_info['groups'] as $k => $v) |
|
| 610 | - $user_info['groups'][$k] = (int) $v; |
|
| 639 | + foreach ($user_info['groups'] as $k => $v) { |
|
| 640 | + $user_info['groups'][$k] = (int) $v; |
|
| 641 | + } |
|
| 611 | 642 | |
| 612 | 643 | // This is a logged in user, so definitely not a spider. |
| 613 | 644 | $user_info['possibly_robot'] = false; |
@@ -621,8 +652,7 @@ discard block |
||
| 621 | 652 | $time_system = new DateTime('now', $tz_system); |
| 622 | 653 | $time_user = new DateTime('now', $tz_user); |
| 623 | 654 | $user_info['time_offset'] = ($tz_user->getOffset($time_user) - $tz_system->getOffset($time_system)) / 3600; |
| 624 | - } |
|
| 625 | - else |
|
| 655 | + } else |
|
| 626 | 656 | { |
| 627 | 657 | // !!! Compatibility. |
| 628 | 658 | $user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 : $user_settings['time_offset']; |
@@ -636,8 +666,9 @@ discard block |
||
| 636 | 666 | $user_info = array('groups' => array(-1)); |
| 637 | 667 | $user_settings = array(); |
| 638 | 668 | |
| 639 | - if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) |
|
| 640 | - $_COOKIE[$cookiename] = ''; |
|
| 669 | + if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) { |
|
| 670 | + $_COOKIE[$cookiename] = ''; |
|
| 671 | + } |
|
| 641 | 672 | |
| 642 | 673 | // Expire the 2FA cookie |
| 643 | 674 | if (isset($_COOKIE[$cookiename . '_tfa']) && empty($context['tfa_member'])) |
@@ -654,19 +685,20 @@ discard block |
||
| 654 | 685 | } |
| 655 | 686 | |
| 656 | 687 | // Create a login token if it doesn't exist yet. |
| 657 | - if (!isset($_SESSION['token']['post-login'])) |
|
| 658 | - createToken('login'); |
|
| 659 | - else |
|
| 660 | - list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login']; |
|
| 688 | + if (!isset($_SESSION['token']['post-login'])) { |
|
| 689 | + createToken('login'); |
|
| 690 | + } else { |
|
| 691 | + list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login']; |
|
| 692 | + } |
|
| 661 | 693 | |
| 662 | 694 | // Do we perhaps think this is a search robot? Check every five minutes just in case... |
| 663 | 695 | if ((!empty($modSettings['spider_mode']) || !empty($modSettings['spider_group'])) && (!isset($_SESSION['robot_check']) || $_SESSION['robot_check'] < time() - 300)) |
| 664 | 696 | { |
| 665 | 697 | require_once($sourcedir . '/ManageSearchEngines.php'); |
| 666 | 698 | $user_info['possibly_robot'] = SpiderCheck(); |
| 699 | + } elseif (!empty($modSettings['spider_mode'])) { |
|
| 700 | + $user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0; |
|
| 667 | 701 | } |
| 668 | - elseif (!empty($modSettings['spider_mode'])) |
|
| 669 | - $user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0; |
|
| 670 | 702 | // If we haven't turned on proper spider hunts then have a guess! |
| 671 | 703 | else |
| 672 | 704 | { |
@@ -714,8 +746,9 @@ discard block |
||
| 714 | 746 | $user_info['groups'] = array_unique($user_info['groups']); |
| 715 | 747 | |
| 716 | 748 | // 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. |
| 717 | - if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) |
|
| 718 | - unset($user_info['ignoreboards'][$tmp]); |
|
| 749 | + if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) { |
|
| 750 | + unset($user_info['ignoreboards'][$tmp]); |
|
| 751 | + } |
|
| 719 | 752 | |
| 720 | 753 | // Allow the user to change their language. |
| 721 | 754 | if (!empty($modSettings['userLanguage'])) |
@@ -728,31 +761,36 @@ discard block |
||
| 728 | 761 | $user_info['language'] = strtr($_GET['language'], './\\:', '____'); |
| 729 | 762 | |
| 730 | 763 | // Make it permanent for members. |
| 731 | - if (!empty($user_info['id'])) |
|
| 732 | - updateMemberData($user_info['id'], array('lngfile' => $user_info['language'])); |
|
| 733 | - else |
|
| 734 | - $_SESSION['language'] = $user_info['language']; |
|
| 764 | + if (!empty($user_info['id'])) { |
|
| 765 | + updateMemberData($user_info['id'], array('lngfile' => $user_info['language'])); |
|
| 766 | + } else { |
|
| 767 | + $_SESSION['language'] = $user_info['language']; |
|
| 768 | + } |
|
| 769 | + } elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) { |
|
| 770 | + $user_info['language'] = strtr($_SESSION['language'], './\\:', '____'); |
|
| 735 | 771 | } |
| 736 | - elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) |
|
| 737 | - $user_info['language'] = strtr($_SESSION['language'], './\\:', '____'); |
|
| 738 | 772 | } |
| 739 | 773 | |
| 740 | 774 | // Just build this here, it makes it easier to change/use - administrators can see all boards. |
| 741 | - if ($user_info['is_admin']) |
|
| 742 | - $user_info['query_see_board'] = '1=1'; |
|
| 775 | + if ($user_info['is_admin']) { |
|
| 776 | + $user_info['query_see_board'] = '1=1'; |
|
| 777 | + } |
|
| 743 | 778 | // Otherwise just the groups in $user_info['groups']. |
| 744 | - else |
|
| 745 | - $user_info['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $user_info['groups']) . ', b.member_groups) != 0)' . (!empty($modSettings['deny_boards_access']) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $user_info['groups']) . ', b.deny_member_groups) = 0)' : '') . (isset($user_info['mod_cache']) ? ' OR ' . $user_info['mod_cache']['mq'] : '') . ')'; |
|
| 779 | + else { |
|
| 780 | + $user_info['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $user_info['groups']) . ', b.member_groups) != 0)' . (!empty($modSettings['deny_boards_access']) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $user_info['groups']) . ', b.deny_member_groups) = 0)' : '') . (isset($user_info['mod_cache']) ? ' OR ' . $user_info['mod_cache']['mq'] : '') . ')'; |
|
| 781 | + } |
|
| 746 | 782 | |
| 747 | 783 | // Build the list of boards they WANT to see. |
| 748 | 784 | // This will take the place of query_see_boards in certain spots, so it better include the boards they can see also |
| 749 | 785 | |
| 750 | 786 | // If they aren't ignoring any boards then they want to see all the boards they can see |
| 751 | - if (empty($user_info['ignoreboards'])) |
|
| 752 | - $user_info['query_wanna_see_board'] = $user_info['query_see_board']; |
|
| 787 | + if (empty($user_info['ignoreboards'])) { |
|
| 788 | + $user_info['query_wanna_see_board'] = $user_info['query_see_board']; |
|
| 789 | + } |
|
| 753 | 790 | // Ok I guess they don't want to see all the boards |
| 754 | - else |
|
| 755 | - $user_info['query_wanna_see_board'] = '(' . $user_info['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $user_info['ignoreboards']) . '))'; |
|
| 791 | + else { |
|
| 792 | + $user_info['query_wanna_see_board'] = '(' . $user_info['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $user_info['ignoreboards']) . '))'; |
|
| 793 | + } |
|
| 756 | 794 | |
| 757 | 795 | call_integration_hook('integrate_user_info'); |
| 758 | 796 | } |
@@ -810,9 +848,9 @@ discard block |
||
| 810 | 848 | } |
| 811 | 849 | |
| 812 | 850 | // Remember redirection is the key to avoiding fallout from your bosses. |
| 813 | - if (!empty($topic)) |
|
| 814 | - redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']); |
|
| 815 | - else |
|
| 851 | + if (!empty($topic)) { |
|
| 852 | + redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']); |
|
| 853 | + } else |
|
| 816 | 854 | { |
| 817 | 855 | loadPermissions(); |
| 818 | 856 | loadTheme(); |
@@ -830,10 +868,11 @@ discard block |
||
| 830 | 868 | if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3)) |
| 831 | 869 | { |
| 832 | 870 | // @todo SLOW? |
| 833 | - if (!empty($topic)) |
|
| 834 | - $temp = cache_get_data('topic_board-' . $topic, 120); |
|
| 835 | - else |
|
| 836 | - $temp = cache_get_data('board-' . $board, 120); |
|
| 871 | + if (!empty($topic)) { |
|
| 872 | + $temp = cache_get_data('topic_board-' . $topic, 120); |
|
| 873 | + } else { |
|
| 874 | + $temp = cache_get_data('board-' . $board, 120); |
|
| 875 | + } |
|
| 837 | 876 | |
| 838 | 877 | if (!empty($temp)) |
| 839 | 878 | { |
@@ -871,8 +910,9 @@ discard block |
||
| 871 | 910 | $row = $smcFunc['db_fetch_assoc']($request); |
| 872 | 911 | |
| 873 | 912 | // Set the current board. |
| 874 | - if (!empty($row['id_board'])) |
|
| 875 | - $board = $row['id_board']; |
|
| 913 | + if (!empty($row['id_board'])) { |
|
| 914 | + $board = $row['id_board']; |
|
| 915 | + } |
|
| 876 | 916 | |
| 877 | 917 | // Basic operating information. (globals... :/) |
| 878 | 918 | $board_info = array( |
@@ -908,21 +948,23 @@ discard block |
||
| 908 | 948 | |
| 909 | 949 | do |
| 910 | 950 | { |
| 911 | - if (!empty($row['id_moderator'])) |
|
| 912 | - $board_info['moderators'][$row['id_moderator']] = array( |
|
| 951 | + if (!empty($row['id_moderator'])) { |
|
| 952 | + $board_info['moderators'][$row['id_moderator']] = array( |
|
| 913 | 953 | 'id' => $row['id_moderator'], |
| 914 | 954 | 'name' => $row['real_name'], |
| 915 | 955 | 'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'], |
| 916 | 956 | 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>' |
| 917 | 957 | ); |
| 958 | + } |
|
| 918 | 959 | |
| 919 | - if (!empty($row['id_moderator_group'])) |
|
| 920 | - $board_info['moderator_groups'][$row['id_moderator_group']] = array( |
|
| 960 | + if (!empty($row['id_moderator_group'])) { |
|
| 961 | + $board_info['moderator_groups'][$row['id_moderator_group']] = array( |
|
| 921 | 962 | 'id' => $row['id_moderator_group'], |
| 922 | 963 | 'name' => $row['group_name'], |
| 923 | 964 | 'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'], |
| 924 | 965 | 'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>' |
| 925 | 966 | ); |
| 967 | + } |
|
| 926 | 968 | } |
| 927 | 969 | while ($row = $smcFunc['db_fetch_assoc']($request)); |
| 928 | 970 | |
@@ -954,12 +996,12 @@ discard block |
||
| 954 | 996 | if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3)) |
| 955 | 997 | { |
| 956 | 998 | // @todo SLOW? |
| 957 | - if (!empty($topic)) |
|
| 958 | - cache_put_data('topic_board-' . $topic, $board_info, 120); |
|
| 999 | + if (!empty($topic)) { |
|
| 1000 | + cache_put_data('topic_board-' . $topic, $board_info, 120); |
|
| 1001 | + } |
|
| 959 | 1002 | cache_put_data('board-' . $board, $board_info, 120); |
| 960 | 1003 | } |
| 961 | - } |
|
| 962 | - else |
|
| 1004 | + } else |
|
| 963 | 1005 | { |
| 964 | 1006 | // Otherwise the topic is invalid, there are no moderators, etc. |
| 965 | 1007 | $board_info = array( |
@@ -973,8 +1015,9 @@ discard block |
||
| 973 | 1015 | $smcFunc['db_free_result']($request); |
| 974 | 1016 | } |
| 975 | 1017 | |
| 976 | - if (!empty($topic)) |
|
| 977 | - $_GET['board'] = (int) $board; |
|
| 1018 | + if (!empty($topic)) { |
|
| 1019 | + $_GET['board'] = (int) $board; |
|
| 1020 | + } |
|
| 978 | 1021 | |
| 979 | 1022 | if (!empty($board)) |
| 980 | 1023 | { |
@@ -984,10 +1027,12 @@ discard block |
||
| 984 | 1027 | // Now check if the user is a moderator. |
| 985 | 1028 | $user_info['is_mod'] = isset($board_info['moderators'][$user_info['id']]) || count(array_intersect($user_info['groups'], $moderator_groups)) != 0; |
| 986 | 1029 | |
| 987 | - if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) |
|
| 988 | - $board_info['error'] = 'access'; |
|
| 989 | - if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) |
|
| 990 | - $board_info['error'] = 'access'; |
|
| 1030 | + if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) { |
|
| 1031 | + $board_info['error'] = 'access'; |
|
| 1032 | + } |
|
| 1033 | + if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) { |
|
| 1034 | + $board_info['error'] = 'access'; |
|
| 1035 | + } |
|
| 991 | 1036 | |
| 992 | 1037 | // Build up the linktree. |
| 993 | 1038 | $context['linktree'] = array_merge( |
@@ -1010,8 +1055,9 @@ discard block |
||
| 1010 | 1055 | $context['current_board'] = $board; |
| 1011 | 1056 | |
| 1012 | 1057 | // No posting in redirection boards! |
| 1013 | - if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) |
|
| 1014 | - $board_info['error'] == 'post_in_redirect'; |
|
| 1058 | + if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) { |
|
| 1059 | + $board_info['error'] == 'post_in_redirect'; |
|
| 1060 | + } |
|
| 1015 | 1061 | |
| 1016 | 1062 | // Hacker... you can't see this topic, I'll tell you that. (but moderators can!) |
| 1017 | 1063 | if (!empty($board_info['error']) && (!empty($modSettings['deny_boards_access']) || $board_info['error'] != 'access' || !$user_info['is_mod'])) |
@@ -1037,24 +1083,23 @@ discard block |
||
| 1037 | 1083 | ob_end_clean(); |
| 1038 | 1084 | header('HTTP/1.1 403 Forbidden'); |
| 1039 | 1085 | die; |
| 1040 | - } |
|
| 1041 | - elseif ($board_info['error'] == 'post_in_redirect') |
|
| 1086 | + } elseif ($board_info['error'] == 'post_in_redirect') |
|
| 1042 | 1087 | { |
| 1043 | 1088 | // Slightly different error message here... |
| 1044 | 1089 | fatal_lang_error('cannot_post_redirect', false); |
| 1045 | - } |
|
| 1046 | - elseif ($user_info['is_guest']) |
|
| 1090 | + } elseif ($user_info['is_guest']) |
|
| 1047 | 1091 | { |
| 1048 | 1092 | loadLanguage('Errors'); |
| 1049 | 1093 | is_not_guest($txt['topic_gone']); |
| 1094 | + } else { |
|
| 1095 | + fatal_lang_error('topic_gone', false); |
|
| 1050 | 1096 | } |
| 1051 | - else |
|
| 1052 | - fatal_lang_error('topic_gone', false); |
|
| 1053 | 1097 | } |
| 1054 | 1098 | |
| 1055 | - if ($user_info['is_mod']) |
|
| 1056 | - $user_info['groups'][] = 3; |
|
| 1057 | -} |
|
| 1099 | + if ($user_info['is_mod']) { |
|
| 1100 | + $user_info['groups'][] = 3; |
|
| 1101 | + } |
|
| 1102 | + } |
|
| 1058 | 1103 | |
| 1059 | 1104 | /** |
| 1060 | 1105 | * Load this user's permissions. |
@@ -1075,8 +1120,9 @@ discard block |
||
| 1075 | 1120 | asort($cache_groups); |
| 1076 | 1121 | $cache_groups = implode(',', $cache_groups); |
| 1077 | 1122 | // If it's a spider then cache it different. |
| 1078 | - if ($user_info['possibly_robot']) |
|
| 1079 | - $cache_groups .= '-spider'; |
|
| 1123 | + if ($user_info['possibly_robot']) { |
|
| 1124 | + $cache_groups .= '-spider'; |
|
| 1125 | + } |
|
| 1080 | 1126 | |
| 1081 | 1127 | if ($modSettings['cache_enable'] >= 2 && !empty($board) && ($temp = cache_get_data('permissions:' . $cache_groups . ':' . $board, 240)) != null && time() - 240 > $modSettings['settings_updated']) |
| 1082 | 1128 | { |
@@ -1084,9 +1130,9 @@ discard block |
||
| 1084 | 1130 | banPermissions(); |
| 1085 | 1131 | |
| 1086 | 1132 | return; |
| 1133 | + } elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) { |
|
| 1134 | + list ($user_info['permissions'], $removals) = $temp; |
|
| 1087 | 1135 | } |
| 1088 | - elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) |
|
| 1089 | - list ($user_info['permissions'], $removals) = $temp; |
|
| 1090 | 1136 | } |
| 1091 | 1137 | |
| 1092 | 1138 | // If it is detected as a robot, and we are restricting permissions as a special group - then implement this. |
@@ -1108,23 +1154,26 @@ discard block |
||
| 1108 | 1154 | $removals = array(); |
| 1109 | 1155 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1110 | 1156 | { |
| 1111 | - if (empty($row['add_deny'])) |
|
| 1112 | - $removals[] = $row['permission']; |
|
| 1113 | - else |
|
| 1114 | - $user_info['permissions'][] = $row['permission']; |
|
| 1157 | + if (empty($row['add_deny'])) { |
|
| 1158 | + $removals[] = $row['permission']; |
|
| 1159 | + } else { |
|
| 1160 | + $user_info['permissions'][] = $row['permission']; |
|
| 1161 | + } |
|
| 1115 | 1162 | } |
| 1116 | 1163 | $smcFunc['db_free_result']($request); |
| 1117 | 1164 | |
| 1118 | - if (isset($cache_groups)) |
|
| 1119 | - cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240); |
|
| 1165 | + if (isset($cache_groups)) { |
|
| 1166 | + cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240); |
|
| 1167 | + } |
|
| 1120 | 1168 | } |
| 1121 | 1169 | |
| 1122 | 1170 | // Get the board permissions. |
| 1123 | 1171 | if (!empty($board)) |
| 1124 | 1172 | { |
| 1125 | 1173 | // Make sure the board (if any) has been loaded by loadBoard(). |
| 1126 | - if (!isset($board_info['profile'])) |
|
| 1127 | - fatal_lang_error('no_board'); |
|
| 1174 | + if (!isset($board_info['profile'])) { |
|
| 1175 | + fatal_lang_error('no_board'); |
|
| 1176 | + } |
|
| 1128 | 1177 | |
| 1129 | 1178 | $request = $smcFunc['db_query']('', ' |
| 1130 | 1179 | SELECT permission, add_deny |
@@ -1140,20 +1189,23 @@ discard block |
||
| 1140 | 1189 | ); |
| 1141 | 1190 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1142 | 1191 | { |
| 1143 | - if (empty($row['add_deny'])) |
|
| 1144 | - $removals[] = $row['permission']; |
|
| 1145 | - else |
|
| 1146 | - $user_info['permissions'][] = $row['permission']; |
|
| 1192 | + if (empty($row['add_deny'])) { |
|
| 1193 | + $removals[] = $row['permission']; |
|
| 1194 | + } else { |
|
| 1195 | + $user_info['permissions'][] = $row['permission']; |
|
| 1196 | + } |
|
| 1147 | 1197 | } |
| 1148 | 1198 | $smcFunc['db_free_result']($request); |
| 1149 | 1199 | } |
| 1150 | 1200 | |
| 1151 | 1201 | // Remove all the permissions they shouldn't have ;). |
| 1152 | - if (!empty($modSettings['permission_enable_deny'])) |
|
| 1153 | - $user_info['permissions'] = array_diff($user_info['permissions'], $removals); |
|
| 1202 | + if (!empty($modSettings['permission_enable_deny'])) { |
|
| 1203 | + $user_info['permissions'] = array_diff($user_info['permissions'], $removals); |
|
| 1204 | + } |
|
| 1154 | 1205 | |
| 1155 | - if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) |
|
| 1156 | - cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240); |
|
| 1206 | + if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) { |
|
| 1207 | + cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240); |
|
| 1208 | + } |
|
| 1157 | 1209 | |
| 1158 | 1210 | // Banned? Watch, don't touch.. |
| 1159 | 1211 | banPermissions(); |
@@ -1165,17 +1217,18 @@ discard block |
||
| 1165 | 1217 | { |
| 1166 | 1218 | require_once($sourcedir . '/Subs-Auth.php'); |
| 1167 | 1219 | rebuildModCache(); |
| 1220 | + } else { |
|
| 1221 | + $user_info['mod_cache'] = $_SESSION['mc']; |
|
| 1168 | 1222 | } |
| 1169 | - else |
|
| 1170 | - $user_info['mod_cache'] = $_SESSION['mc']; |
|
| 1171 | 1223 | |
| 1172 | 1224 | // This is a useful phantom permission added to the current user, and only the current user while they are logged in. |
| 1173 | 1225 | // For example this drastically simplifies certain changes to the profile area. |
| 1174 | 1226 | $user_info['permissions'][] = 'is_not_guest'; |
| 1175 | 1227 | // And now some backwards compatibility stuff for mods and whatnot that aren't expecting the new permissions. |
| 1176 | 1228 | $user_info['permissions'][] = 'profile_view_own'; |
| 1177 | - if (in_array('profile_view', $user_info['permissions'])) |
|
| 1178 | - $user_info['permissions'][] = 'profile_view_any'; |
|
| 1229 | + if (in_array('profile_view', $user_info['permissions'])) { |
|
| 1230 | + $user_info['permissions'][] = 'profile_view_any'; |
|
| 1231 | + } |
|
| 1179 | 1232 | } |
| 1180 | 1233 | } |
| 1181 | 1234 | |
@@ -1193,8 +1246,9 @@ discard block |
||
| 1193 | 1246 | global $image_proxy_enabled, $image_proxy_secret, $boardurl; |
| 1194 | 1247 | |
| 1195 | 1248 | // Can't just look for no users :P. |
| 1196 | - if (empty($users)) |
|
| 1197 | - return array(); |
|
| 1249 | + if (empty($users)) { |
|
| 1250 | + return array(); |
|
| 1251 | + } |
|
| 1198 | 1252 | |
| 1199 | 1253 | // Pass the set value |
| 1200 | 1254 | $context['loadMemberContext_set'] = $set; |
@@ -1209,8 +1263,9 @@ discard block |
||
| 1209 | 1263 | for ($i = 0, $n = count($users); $i < $n; $i++) |
| 1210 | 1264 | { |
| 1211 | 1265 | $data = cache_get_data('member_data-' . $set . '-' . $users[$i], 240); |
| 1212 | - if ($data == null) |
|
| 1213 | - continue; |
|
| 1266 | + if ($data == null) { |
|
| 1267 | + continue; |
|
| 1268 | + } |
|
| 1214 | 1269 | |
| 1215 | 1270 | $loaded_ids[] = $data['id_member']; |
| 1216 | 1271 | $user_profile[$data['id_member']] = $data; |
@@ -1277,13 +1332,16 @@ discard block |
||
| 1277 | 1332 | $row['avatar_original'] = !empty($row['avatar']) ? $row['avatar'] : ''; |
| 1278 | 1333 | |
| 1279 | 1334 | // Take care of proxying avatar if required, do this here for maximum reach |
| 1280 | - if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false) |
|
| 1281 | - $row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret); |
|
| 1335 | + if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false) { |
|
| 1336 | + $row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret); |
|
| 1337 | + } |
|
| 1282 | 1338 | |
| 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']); |
|
| 1339 | + if (isset($row['member_ip'])) { |
|
| 1340 | + $row['member_ip'] = inet_dtop($row['member_ip']); |
|
| 1341 | + } |
|
| 1342 | + if (isset($row['member_ip2'])) { |
|
| 1343 | + $row['member_ip2'] = inet_dtop($row['member_ip2']); |
|
| 1344 | + } |
|
| 1287 | 1345 | $new_loaded_ids[] = $row['id_member']; |
| 1288 | 1346 | $loaded_ids[] = $row['id_member']; |
| 1289 | 1347 | $row['options'] = array(); |
@@ -1302,8 +1360,9 @@ discard block |
||
| 1302 | 1360 | 'loaded_ids' => $new_loaded_ids, |
| 1303 | 1361 | ) |
| 1304 | 1362 | ); |
| 1305 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1306 | - $user_profile[$row['id_member']]['options'][$row['variable']] = $row['value']; |
|
| 1363 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1364 | + $user_profile[$row['id_member']]['options'][$row['variable']] = $row['value']; |
|
| 1365 | + } |
|
| 1307 | 1366 | $smcFunc['db_free_result']($request); |
| 1308 | 1367 | } |
| 1309 | 1368 | |
@@ -1314,10 +1373,11 @@ discard block |
||
| 1314 | 1373 | { |
| 1315 | 1374 | foreach ($loaded_ids as $a_member) |
| 1316 | 1375 | { |
| 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']); |
|
| 1376 | + if (!empty($user_profile[$a_member]['additional_groups'])) { |
|
| 1377 | + $groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups'])); |
|
| 1378 | + } else { |
|
| 1379 | + $groups = array($user_profile[$a_member]['id_group']); |
|
| 1380 | + } |
|
| 1321 | 1381 | |
| 1322 | 1382 | $temp = array_intersect($groups, array_keys($board_info['moderator_groups'])); |
| 1323 | 1383 | |
@@ -1330,8 +1390,9 @@ discard block |
||
| 1330 | 1390 | |
| 1331 | 1391 | if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3) |
| 1332 | 1392 | { |
| 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); |
|
| 1393 | + for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) { |
|
| 1394 | + cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240); |
|
| 1395 | + } |
|
| 1335 | 1396 | } |
| 1336 | 1397 | |
| 1337 | 1398 | // Are we loading any moderators? If so, fix their group data... |
@@ -1357,14 +1418,17 @@ discard block |
||
| 1357 | 1418 | foreach ($temp_mods as $id) |
| 1358 | 1419 | { |
| 1359 | 1420 | // 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']; |
|
| 1421 | + if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) { |
|
| 1422 | + $user_profile[$id]['member_group'] = $row['member_group']; |
|
| 1423 | + } |
|
| 1362 | 1424 | |
| 1363 | 1425 | // 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']; |
|
| 1426 | + if (!empty($row['icons'])) { |
|
| 1427 | + $user_profile[$id]['icons'] = $row['icons']; |
|
| 1428 | + } |
|
| 1429 | + if (!empty($row['member_group_color'])) { |
|
| 1430 | + $user_profile[$id]['member_group_color'] = $row['member_group_color']; |
|
| 1431 | + } |
|
| 1368 | 1432 | } |
| 1369 | 1433 | } |
| 1370 | 1434 | |
@@ -1386,12 +1450,14 @@ discard block |
||
| 1386 | 1450 | static $loadedLanguages = array(); |
| 1387 | 1451 | |
| 1388 | 1452 | // If this person's data is already loaded, skip it. |
| 1389 | - if (isset($dataLoaded[$user])) |
|
| 1390 | - return true; |
|
| 1453 | + if (isset($dataLoaded[$user])) { |
|
| 1454 | + return true; |
|
| 1455 | + } |
|
| 1391 | 1456 | |
| 1392 | 1457 | // We can't load guests or members not loaded by loadMemberData()! |
| 1393 | - if ($user == 0) |
|
| 1394 | - return false; |
|
| 1458 | + if ($user == 0) { |
|
| 1459 | + return false; |
|
| 1460 | + } |
|
| 1395 | 1461 | if (!isset($user_profile[$user])) |
| 1396 | 1462 | { |
| 1397 | 1463 | trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING); |
@@ -1417,12 +1483,16 @@ discard block |
||
| 1417 | 1483 | $buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array(); |
| 1418 | 1484 | |
| 1419 | 1485 | //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 |
|
| 1486 | + if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) { |
|
| 1487 | + //icon is set and exists |
|
| 1421 | 1488 | $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 |
|
| 1489 | + } elseif (isset($profile['icons'][1])) { |
|
| 1490 | + //icon is set and doesn't exist, fallback to default |
|
| 1423 | 1491 | $group_icon_url = $settings['default_images_url'] . '/membericons/' . $profile['icons'][1]; |
| 1424 | - else //not set, bye bye |
|
| 1492 | + } else { |
|
| 1493 | + //not set, bye bye |
|
| 1425 | 1494 | $group_icon_url = ''; |
| 1495 | + } |
|
| 1426 | 1496 | |
| 1427 | 1497 | // These minimal values are always loaded |
| 1428 | 1498 | $memberContext[$user] = array( |
@@ -1441,8 +1511,9 @@ discard block |
||
| 1441 | 1511 | if ($context['loadMemberContext_set'] != 'minimal') |
| 1442 | 1512 | { |
| 1443 | 1513 | // Go the extra mile and load the user's native language name. |
| 1444 | - if (empty($loadedLanguages)) |
|
| 1445 | - $loadedLanguages = getLanguages(); |
|
| 1514 | + if (empty($loadedLanguages)) { |
|
| 1515 | + $loadedLanguages = getLanguages(); |
|
| 1516 | + } |
|
| 1446 | 1517 | |
| 1447 | 1518 | $memberContext[$user] += array( |
| 1448 | 1519 | 'username_color' => '<span ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['member_name'] . '</span>', |
@@ -1496,31 +1567,33 @@ discard block |
||
| 1496 | 1567 | { |
| 1497 | 1568 | if (!empty($modSettings['gravatarOverride']) || (!empty($modSettings['gravatarEnabled']) && stristr($profile['avatar'], 'gravatar://'))) |
| 1498 | 1569 | { |
| 1499 | - if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) |
|
| 1500 | - $image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11)); |
|
| 1501 | - else |
|
| 1502 | - $image = get_gravatar_url($profile['email_address']); |
|
| 1503 | - } |
|
| 1504 | - else |
|
| 1570 | + if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) { |
|
| 1571 | + $image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11)); |
|
| 1572 | + } else { |
|
| 1573 | + $image = get_gravatar_url($profile['email_address']); |
|
| 1574 | + } |
|
| 1575 | + } else |
|
| 1505 | 1576 | { |
| 1506 | 1577 | // So it's stored in the member table? |
| 1507 | 1578 | if (!empty($profile['avatar'])) |
| 1508 | 1579 | { |
| 1509 | 1580 | $image = (stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar']; |
| 1581 | + } elseif (!empty($profile['filename'])) { |
|
| 1582 | + $image = $modSettings['custom_avatar_url'] . '/' . $profile['filename']; |
|
| 1510 | 1583 | } |
| 1511 | - elseif (!empty($profile['filename'])) |
|
| 1512 | - $image = $modSettings['custom_avatar_url'] . '/' . $profile['filename']; |
|
| 1513 | 1584 | // Right... no avatar...use the default one |
| 1514 | - else |
|
| 1515 | - $image = $modSettings['avatar_url'] . '/default.png'; |
|
| 1585 | + else { |
|
| 1586 | + $image = $modSettings['avatar_url'] . '/default.png'; |
|
| 1587 | + } |
|
| 1516 | 1588 | } |
| 1517 | - if (!empty($image)) |
|
| 1518 | - $memberContext[$user]['avatar'] = array( |
|
| 1589 | + if (!empty($image)) { |
|
| 1590 | + $memberContext[$user]['avatar'] = array( |
|
| 1519 | 1591 | 'name' => $profile['avatar'], |
| 1520 | 1592 | 'image' => '<img class="avatar" src="' . $image . '" alt="avatar_' . $profile['member_name'] . '">', |
| 1521 | 1593 | 'href' => $image, |
| 1522 | 1594 | 'url' => $image, |
| 1523 | 1595 | ); |
| 1596 | + } |
|
| 1524 | 1597 | } |
| 1525 | 1598 | |
| 1526 | 1599 | // Are we also loading the members custom fields into context? |
@@ -1528,35 +1601,41 @@ discard block |
||
| 1528 | 1601 | { |
| 1529 | 1602 | $memberContext[$user]['custom_fields'] = array(); |
| 1530 | 1603 | |
| 1531 | - if (!isset($context['display_fields'])) |
|
| 1532 | - $context['display_fields'] = smf_json_decode($modSettings['displayFields'], true); |
|
| 1604 | + if (!isset($context['display_fields'])) { |
|
| 1605 | + $context['display_fields'] = smf_json_decode($modSettings['displayFields'], true); |
|
| 1606 | + } |
|
| 1533 | 1607 | |
| 1534 | 1608 | foreach ($context['display_fields'] as $custom) |
| 1535 | 1609 | { |
| 1536 | - if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) |
|
| 1537 | - continue; |
|
| 1610 | + if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) { |
|
| 1611 | + continue; |
|
| 1612 | + } |
|
| 1538 | 1613 | |
| 1539 | 1614 | $value = $profile['options'][$custom['col_name']]; |
| 1540 | 1615 | |
| 1541 | 1616 | // Don't show the "disabled" option for the "gender" field. |
| 1542 | - if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled') |
|
| 1543 | - continue; |
|
| 1617 | + if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled') { |
|
| 1618 | + continue; |
|
| 1619 | + } |
|
| 1544 | 1620 | |
| 1545 | 1621 | // BBC? |
| 1546 | - if ($custom['bbc']) |
|
| 1547 | - $value = parse_bbc($value); |
|
| 1622 | + if ($custom['bbc']) { |
|
| 1623 | + $value = parse_bbc($value); |
|
| 1624 | + } |
|
| 1548 | 1625 | // ... or checkbox? |
| 1549 | - elseif (isset($custom['type']) && $custom['type'] == 'check') |
|
| 1550 | - $value = $value ? $txt['yes'] : $txt['no']; |
|
| 1626 | + elseif (isset($custom['type']) && $custom['type'] == 'check') { |
|
| 1627 | + $value = $value ? $txt['yes'] : $txt['no']; |
|
| 1628 | + } |
|
| 1551 | 1629 | |
| 1552 | 1630 | // Enclosing the user input within some other text? |
| 1553 | - if (!empty($custom['enclose'])) |
|
| 1554 | - $value = strtr($custom['enclose'], array( |
|
| 1631 | + if (!empty($custom['enclose'])) { |
|
| 1632 | + $value = strtr($custom['enclose'], array( |
|
| 1555 | 1633 | '{SCRIPTURL}' => $scripturl, |
| 1556 | 1634 | '{IMAGES_URL}' => $settings['images_url'], |
| 1557 | 1635 | '{DEFAULT_IMAGES_URL}' => $settings['default_images_url'], |
| 1558 | 1636 | '{INPUT}' => $value, |
| 1559 | 1637 | )); |
| 1638 | + } |
|
| 1560 | 1639 | |
| 1561 | 1640 | $memberContext[$user]['custom_fields'][] = array( |
| 1562 | 1641 | 'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'], |
@@ -1583,8 +1662,9 @@ discard block |
||
| 1583 | 1662 | global $smcFunc, $txt, $scripturl, $settings; |
| 1584 | 1663 | |
| 1585 | 1664 | // Do not waste my time... |
| 1586 | - if (empty($users) || empty($params)) |
|
| 1587 | - return false; |
|
| 1665 | + if (empty($users) || empty($params)) { |
|
| 1666 | + return false; |
|
| 1667 | + } |
|
| 1588 | 1668 | |
| 1589 | 1669 | // Make sure it's an array. |
| 1590 | 1670 | $users = !is_array($users) ? array($users) : array_unique($users); |
@@ -1608,31 +1688,36 @@ discard block |
||
| 1608 | 1688 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1609 | 1689 | { |
| 1610 | 1690 | // BBC? |
| 1611 | - if (!empty($row['bbc'])) |
|
| 1612 | - $row['value'] = parse_bbc($row['value']); |
|
| 1691 | + if (!empty($row['bbc'])) { |
|
| 1692 | + $row['value'] = parse_bbc($row['value']); |
|
| 1693 | + } |
|
| 1613 | 1694 | |
| 1614 | 1695 | // ... or checkbox? |
| 1615 | - elseif (isset($row['type']) && $row['type'] == 'check') |
|
| 1616 | - $row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no']; |
|
| 1696 | + elseif (isset($row['type']) && $row['type'] == 'check') { |
|
| 1697 | + $row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no']; |
|
| 1698 | + } |
|
| 1617 | 1699 | |
| 1618 | 1700 | // Enclosing the user input within some other text? |
| 1619 | - if (!empty($row['enclose'])) |
|
| 1620 | - $row['value'] = strtr($row['enclose'], array( |
|
| 1701 | + if (!empty($row['enclose'])) { |
|
| 1702 | + $row['value'] = strtr($row['enclose'], array( |
|
| 1621 | 1703 | '{SCRIPTURL}' => $scripturl, |
| 1622 | 1704 | '{IMAGES_URL}' => $settings['images_url'], |
| 1623 | 1705 | '{DEFAULT_IMAGES_URL}' => $settings['default_images_url'], |
| 1624 | 1706 | '{INPUT}' => un_htmlspecialchars($row['value']), |
| 1625 | 1707 | )); |
| 1708 | + } |
|
| 1626 | 1709 | |
| 1627 | 1710 | // Send a simple array if there is just 1 param |
| 1628 | - if (count($params) == 1) |
|
| 1629 | - $return[$row['id_member']] = $row; |
|
| 1711 | + if (count($params) == 1) { |
|
| 1712 | + $return[$row['id_member']] = $row; |
|
| 1713 | + } |
|
| 1630 | 1714 | |
| 1631 | 1715 | // More than 1? knock yourself out... |
| 1632 | 1716 | else |
| 1633 | 1717 | { |
| 1634 | - if (!isset($return[$row['id_member']])) |
|
| 1635 | - $return[$row['id_member']] = array(); |
|
| 1718 | + if (!isset($return[$row['id_member']])) { |
|
| 1719 | + $return[$row['id_member']] = array(); |
|
| 1720 | + } |
|
| 1636 | 1721 | |
| 1637 | 1722 | $return[$row['id_member']][$row['variable']] = $row; |
| 1638 | 1723 | } |
@@ -1666,8 +1751,9 @@ discard block |
||
| 1666 | 1751 | global $context; |
| 1667 | 1752 | |
| 1668 | 1753 | // Don't know any browser! |
| 1669 | - if (empty($context['browser'])) |
|
| 1670 | - detectBrowser(); |
|
| 1754 | + if (empty($context['browser'])) { |
|
| 1755 | + detectBrowser(); |
|
| 1756 | + } |
|
| 1671 | 1757 | |
| 1672 | 1758 | return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false; |
| 1673 | 1759 | } |
@@ -1685,8 +1771,9 @@ discard block |
||
| 1685 | 1771 | global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled; |
| 1686 | 1772 | |
| 1687 | 1773 | // The theme was specified by parameter. |
| 1688 | - if (!empty($id_theme)) |
|
| 1689 | - $id_theme = (int) $id_theme; |
|
| 1774 | + if (!empty($id_theme)) { |
|
| 1775 | + $id_theme = (int) $id_theme; |
|
| 1776 | + } |
|
| 1690 | 1777 | // The theme was specified by REQUEST. |
| 1691 | 1778 | elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) |
| 1692 | 1779 | { |
@@ -1694,51 +1781,58 @@ discard block |
||
| 1694 | 1781 | $_SESSION['id_theme'] = $id_theme; |
| 1695 | 1782 | } |
| 1696 | 1783 | // The theme was specified by REQUEST... previously. |
| 1697 | - elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) |
|
| 1698 | - $id_theme = (int) $_SESSION['id_theme']; |
|
| 1784 | + elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) { |
|
| 1785 | + $id_theme = (int) $_SESSION['id_theme']; |
|
| 1786 | + } |
|
| 1699 | 1787 | // The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.) |
| 1700 | - elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) |
|
| 1701 | - $id_theme = $user_info['theme']; |
|
| 1788 | + elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) { |
|
| 1789 | + $id_theme = $user_info['theme']; |
|
| 1790 | + } |
|
| 1702 | 1791 | // The theme was specified by the board. |
| 1703 | - elseif (!empty($board_info['theme'])) |
|
| 1704 | - $id_theme = $board_info['theme']; |
|
| 1792 | + elseif (!empty($board_info['theme'])) { |
|
| 1793 | + $id_theme = $board_info['theme']; |
|
| 1794 | + } |
|
| 1705 | 1795 | // The theme is the forum's default. |
| 1706 | - else |
|
| 1707 | - $id_theme = $modSettings['theme_guests']; |
|
| 1796 | + else { |
|
| 1797 | + $id_theme = $modSettings['theme_guests']; |
|
| 1798 | + } |
|
| 1708 | 1799 | |
| 1709 | 1800 | // Verify the id_theme... no foul play. |
| 1710 | 1801 | // Always allow the board specific theme, if they are overriding. |
| 1711 | - if (!empty($board_info['theme']) && $board_info['override_theme']) |
|
| 1712 | - $id_theme = $board_info['theme']; |
|
| 1802 | + if (!empty($board_info['theme']) && $board_info['override_theme']) { |
|
| 1803 | + $id_theme = $board_info['theme']; |
|
| 1804 | + } |
|
| 1713 | 1805 | // If they have specified a particular theme to use with SSI allow it to be used. |
| 1714 | - elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) |
|
| 1715 | - $id_theme = (int) $id_theme; |
|
| 1716 | - elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum')) |
|
| 1806 | + elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) { |
|
| 1807 | + $id_theme = (int) $id_theme; |
|
| 1808 | + } elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum')) |
|
| 1717 | 1809 | { |
| 1718 | 1810 | $themes = explode(',', $modSettings['enableThemes']); |
| 1719 | - if (!in_array($id_theme, $themes)) |
|
| 1720 | - $id_theme = $modSettings['theme_guests']; |
|
| 1721 | - else |
|
| 1811 | + if (!in_array($id_theme, $themes)) { |
|
| 1812 | + $id_theme = $modSettings['theme_guests']; |
|
| 1813 | + } else { |
|
| 1814 | + $id_theme = (int) $id_theme; |
|
| 1815 | + } |
|
| 1816 | + } else { |
|
| 1722 | 1817 | $id_theme = (int) $id_theme; |
| 1723 | 1818 | } |
| 1724 | - else |
|
| 1725 | - $id_theme = (int) $id_theme; |
|
| 1726 | 1819 | |
| 1727 | 1820 | $member = empty($user_info['id']) ? -1 : $user_info['id']; |
| 1728 | 1821 | |
| 1729 | 1822 | // Disable image proxy if we don't have SSL enabled |
| 1730 | - if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2) |
|
| 1731 | - $image_proxy_enabled = false; |
|
| 1823 | + if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2) { |
|
| 1824 | + $image_proxy_enabled = false; |
|
| 1825 | + } |
|
| 1732 | 1826 | |
| 1733 | 1827 | 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']) |
| 1734 | 1828 | { |
| 1735 | 1829 | $themeData = $temp; |
| 1736 | 1830 | $flag = true; |
| 1831 | + } elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) { |
|
| 1832 | + $themeData = $temp + array($member => array()); |
|
| 1833 | + } else { |
|
| 1834 | + $themeData = array(-1 => array(), 0 => array(), $member => array()); |
|
| 1737 | 1835 | } |
| 1738 | - elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) |
|
| 1739 | - $themeData = $temp + array($member => array()); |
|
| 1740 | - else |
|
| 1741 | - $themeData = array(-1 => array(), 0 => array(), $member => array()); |
|
| 1742 | 1836 | |
| 1743 | 1837 | if (empty($flag)) |
| 1744 | 1838 | { |
@@ -1757,31 +1851,37 @@ discard block |
||
| 1757 | 1851 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
| 1758 | 1852 | { |
| 1759 | 1853 | // There are just things we shouldn't be able to change as members. |
| 1760 | - 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'))) |
|
| 1761 | - continue; |
|
| 1854 | + 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'))) { |
|
| 1855 | + continue; |
|
| 1856 | + } |
|
| 1762 | 1857 | |
| 1763 | 1858 | // If this is the theme_dir of the default theme, store it. |
| 1764 | - if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) |
|
| 1765 | - $themeData[0]['default_' . $row['variable']] = $row['value']; |
|
| 1859 | + if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) { |
|
| 1860 | + $themeData[0]['default_' . $row['variable']] = $row['value']; |
|
| 1861 | + } |
|
| 1766 | 1862 | |
| 1767 | 1863 | // If this isn't set yet, is a theme option, or is not the default theme.. |
| 1768 | - if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') |
|
| 1769 | - $themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value']; |
|
| 1864 | + if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') { |
|
| 1865 | + $themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value']; |
|
| 1866 | + } |
|
| 1770 | 1867 | } |
| 1771 | 1868 | $smcFunc['db_free_result']($result); |
| 1772 | 1869 | |
| 1773 | - if (!empty($themeData[-1])) |
|
| 1774 | - foreach ($themeData[-1] as $k => $v) |
|
| 1870 | + if (!empty($themeData[-1])) { |
|
| 1871 | + foreach ($themeData[-1] as $k => $v) |
|
| 1775 | 1872 | { |
| 1776 | 1873 | if (!isset($themeData[$member][$k])) |
| 1777 | 1874 | $themeData[$member][$k] = $v; |
| 1875 | + } |
|
| 1778 | 1876 | } |
| 1779 | 1877 | |
| 1780 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
| 1781 | - cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60); |
|
| 1878 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
| 1879 | + cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60); |
|
| 1880 | + } |
|
| 1782 | 1881 | // Only if we didn't already load that part of the cache... |
| 1783 | - elseif (!isset($temp)) |
|
| 1784 | - cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90); |
|
| 1882 | + elseif (!isset($temp)) { |
|
| 1883 | + cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90); |
|
| 1884 | + } |
|
| 1785 | 1885 | } |
| 1786 | 1886 | |
| 1787 | 1887 | $settings = $themeData[0]; |
@@ -1798,20 +1898,24 @@ discard block |
||
| 1798 | 1898 | $settings['template_dirs'][] = $settings['theme_dir']; |
| 1799 | 1899 | |
| 1800 | 1900 | // Based on theme (if there is one). |
| 1801 | - if (!empty($settings['base_theme_dir'])) |
|
| 1802 | - $settings['template_dirs'][] = $settings['base_theme_dir']; |
|
| 1901 | + if (!empty($settings['base_theme_dir'])) { |
|
| 1902 | + $settings['template_dirs'][] = $settings['base_theme_dir']; |
|
| 1903 | + } |
|
| 1803 | 1904 | |
| 1804 | 1905 | // Lastly the default theme. |
| 1805 | - if ($settings['theme_dir'] != $settings['default_theme_dir']) |
|
| 1806 | - $settings['template_dirs'][] = $settings['default_theme_dir']; |
|
| 1906 | + if ($settings['theme_dir'] != $settings['default_theme_dir']) { |
|
| 1907 | + $settings['template_dirs'][] = $settings['default_theme_dir']; |
|
| 1908 | + } |
|
| 1807 | 1909 | |
| 1808 | - if (!$initialize) |
|
| 1809 | - return; |
|
| 1910 | + if (!$initialize) { |
|
| 1911 | + return; |
|
| 1912 | + } |
|
| 1810 | 1913 | |
| 1811 | 1914 | // Check to see if we're forcing SSL |
| 1812 | 1915 | if (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 && empty($maintenance) && |
| 1813 | - (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI') |
|
| 1814 | - redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://'))); |
|
| 1916 | + (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI') { |
|
| 1917 | + redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://'))); |
|
| 1918 | + } |
|
| 1815 | 1919 | |
| 1816 | 1920 | // Check to see if they're accessing it from the wrong place. |
| 1817 | 1921 | if (isset($_SERVER['HTTP_HOST']) || isset($_SERVER['SERVER_NAME'])) |
@@ -1819,8 +1923,9 @@ discard block |
||
| 1819 | 1923 | $detected_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https://' : 'http://'; |
| 1820 | 1924 | $detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST']; |
| 1821 | 1925 | $temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/')); |
| 1822 | - if ($temp != '/') |
|
| 1823 | - $detected_url .= $temp; |
|
| 1926 | + if ($temp != '/') { |
|
| 1927 | + $detected_url .= $temp; |
|
| 1928 | + } |
|
| 1824 | 1929 | } |
| 1825 | 1930 | if (isset($detected_url) && $detected_url != $boardurl) |
| 1826 | 1931 | { |
@@ -1832,8 +1937,9 @@ discard block |
||
| 1832 | 1937 | foreach ($aliases as $alias) |
| 1833 | 1938 | { |
| 1834 | 1939 | // Rip off all the boring parts, spaces, etc. |
| 1835 | - if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) |
|
| 1836 | - $do_fix = true; |
|
| 1940 | + if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) { |
|
| 1941 | + $do_fix = true; |
|
| 1942 | + } |
|
| 1837 | 1943 | } |
| 1838 | 1944 | } |
| 1839 | 1945 | |
@@ -1841,20 +1947,22 @@ discard block |
||
| 1841 | 1947 | if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI') |
| 1842 | 1948 | { |
| 1843 | 1949 | // Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;). |
| 1844 | - if (empty($_GET)) |
|
| 1845 | - redirectexit('wwwRedirect'); |
|
| 1846 | - else |
|
| 1950 | + if (empty($_GET)) { |
|
| 1951 | + redirectexit('wwwRedirect'); |
|
| 1952 | + } else |
|
| 1847 | 1953 | { |
| 1848 | 1954 | list ($k, $v) = each($_GET); |
| 1849 | 1955 | |
| 1850 | - if ($k != 'wwwRedirect') |
|
| 1851 | - redirectexit('wwwRedirect;' . $k . '=' . $v); |
|
| 1956 | + if ($k != 'wwwRedirect') { |
|
| 1957 | + redirectexit('wwwRedirect;' . $k . '=' . $v); |
|
| 1958 | + } |
|
| 1852 | 1959 | } |
| 1853 | 1960 | } |
| 1854 | 1961 | |
| 1855 | 1962 | // #3 is just a check for SSL... |
| 1856 | - if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) |
|
| 1857 | - $do_fix = true; |
|
| 1963 | + if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) { |
|
| 1964 | + $do_fix = true; |
|
| 1965 | + } |
|
| 1858 | 1966 | |
| 1859 | 1967 | // Okay, #4 - perhaps it's an IP address? We're gonna want to use that one, then. (assuming it's the IP or something...) |
| 1860 | 1968 | if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1) |
@@ -1888,8 +1996,9 @@ discard block |
||
| 1888 | 1996 | $board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl)); |
| 1889 | 1997 | } |
| 1890 | 1998 | } |
| 1891 | - foreach ($context['linktree'] as $k => $dummy) |
|
| 1892 | - $context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl)); |
|
| 1999 | + foreach ($context['linktree'] as $k => $dummy) { |
|
| 2000 | + $context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl)); |
|
| 2001 | + } |
|
| 1893 | 2002 | } |
| 1894 | 2003 | } |
| 1895 | 2004 | // Set up the contextual user array. |
@@ -1908,16 +2017,16 @@ discard block |
||
| 1908 | 2017 | 'email' => $user_info['email'], |
| 1909 | 2018 | 'ignoreusers' => $user_info['ignoreusers'], |
| 1910 | 2019 | ); |
| 1911 | - if (!$context['user']['is_guest']) |
|
| 1912 | - $context['user']['name'] = $user_info['name']; |
|
| 1913 | - elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) |
|
| 1914 | - $context['user']['name'] = $txt['guest_title']; |
|
| 2020 | + if (!$context['user']['is_guest']) { |
|
| 2021 | + $context['user']['name'] = $user_info['name']; |
|
| 2022 | + } elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) { |
|
| 2023 | + $context['user']['name'] = $txt['guest_title']; |
|
| 2024 | + } |
|
| 1915 | 2025 | |
| 1916 | 2026 | // Determine the current smiley set. |
| 1917 | 2027 | $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']; |
| 1918 | 2028 | $context['user']['smiley_set'] = $user_info['smiley_set']; |
| 1919 | - } |
|
| 1920 | - else |
|
| 2029 | + } else |
|
| 1921 | 2030 | { |
| 1922 | 2031 | $context['user'] = array( |
| 1923 | 2032 | 'id' => -1, |
@@ -1933,18 +2042,24 @@ discard block |
||
| 1933 | 2042 | } |
| 1934 | 2043 | |
| 1935 | 2044 | // Some basic information... |
| 1936 | - if (!isset($context['html_headers'])) |
|
| 1937 | - $context['html_headers'] = ''; |
|
| 1938 | - if (!isset($context['javascript_files'])) |
|
| 1939 | - $context['javascript_files'] = array(); |
|
| 1940 | - if (!isset($context['css_files'])) |
|
| 1941 | - $context['css_files'] = array(); |
|
| 1942 | - if (!isset($context['css_header'])) |
|
| 1943 | - $context['css_header'] = array(); |
|
| 1944 | - if (!isset($context['javascript_inline'])) |
|
| 1945 | - $context['javascript_inline'] = array('standard' => array(), 'defer' => array()); |
|
| 1946 | - if (!isset($context['javascript_vars'])) |
|
| 1947 | - $context['javascript_vars'] = array(); |
|
| 2045 | + if (!isset($context['html_headers'])) { |
|
| 2046 | + $context['html_headers'] = ''; |
|
| 2047 | + } |
|
| 2048 | + if (!isset($context['javascript_files'])) { |
|
| 2049 | + $context['javascript_files'] = array(); |
|
| 2050 | + } |
|
| 2051 | + if (!isset($context['css_files'])) { |
|
| 2052 | + $context['css_files'] = array(); |
|
| 2053 | + } |
|
| 2054 | + if (!isset($context['css_header'])) { |
|
| 2055 | + $context['css_header'] = array(); |
|
| 2056 | + } |
|
| 2057 | + if (!isset($context['javascript_inline'])) { |
|
| 2058 | + $context['javascript_inline'] = array('standard' => array(), 'defer' => array()); |
|
| 2059 | + } |
|
| 2060 | + if (!isset($context['javascript_vars'])) { |
|
| 2061 | + $context['javascript_vars'] = array(); |
|
| 2062 | + } |
|
| 1948 | 2063 | |
| 1949 | 2064 | $context['login_url'] = (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] < 2 ? strtr($scripturl, array('http://' => 'https://')) : $scripturl) . '?action=login2'; |
| 1950 | 2065 | $context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | '; |
@@ -1956,8 +2071,9 @@ discard block |
||
| 1956 | 2071 | $context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null; |
| 1957 | 2072 | $context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null; |
| 1958 | 2073 | $context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3; |
| 1959 | - if (isset($modSettings['load_average'])) |
|
| 1960 | - $context['load_average'] = $modSettings['load_average']; |
|
| 2074 | + if (isset($modSettings['load_average'])) { |
|
| 2075 | + $context['load_average'] = $modSettings['load_average']; |
|
| 2076 | + } |
|
| 1961 | 2077 | |
| 1962 | 2078 | // Detect the browser. This is separated out because it's also used in attachment downloads |
| 1963 | 2079 | detectBrowser(); |
@@ -1971,8 +2087,9 @@ discard block |
||
| 1971 | 2087 | // This allows sticking some HTML on the page output - useful for controls. |
| 1972 | 2088 | $context['insert_after_template'] = ''; |
| 1973 | 2089 | |
| 1974 | - if (!isset($txt)) |
|
| 1975 | - $txt = array(); |
|
| 2090 | + if (!isset($txt)) { |
|
| 2091 | + $txt = array(); |
|
| 2092 | + } |
|
| 1976 | 2093 | |
| 1977 | 2094 | $simpleActions = array( |
| 1978 | 2095 | 'findmember', |
@@ -2018,9 +2135,10 @@ discard block |
||
| 2018 | 2135 | |
| 2019 | 2136 | // See if theres any extra param to check. |
| 2020 | 2137 | $requiresXML = false; |
| 2021 | - foreach ($extraParams as $key => $extra) |
|
| 2022 | - if (isset($_REQUEST[$extra])) |
|
| 2138 | + foreach ($extraParams as $key => $extra) { |
|
| 2139 | + if (isset($_REQUEST[$extra])) |
|
| 2023 | 2140 | $requiresXML = true; |
| 2141 | + } |
|
| 2024 | 2142 | |
| 2025 | 2143 | // Output is fully XML, so no need for the index template. |
| 2026 | 2144 | if (isset($_REQUEST['xml']) && (in_array($context['current_action'], $xmlActions) || $requiresXML)) |
@@ -2035,37 +2153,39 @@ discard block |
||
| 2035 | 2153 | { |
| 2036 | 2154 | loadLanguage('index+Modifications'); |
| 2037 | 2155 | $context['template_layers'] = array(); |
| 2038 | - } |
|
| 2039 | - |
|
| 2040 | - else |
|
| 2156 | + } else |
|
| 2041 | 2157 | { |
| 2042 | 2158 | // Custom templates to load, or just default? |
| 2043 | - if (isset($settings['theme_templates'])) |
|
| 2044 | - $templates = explode(',', $settings['theme_templates']); |
|
| 2045 | - else |
|
| 2046 | - $templates = array('index'); |
|
| 2159 | + if (isset($settings['theme_templates'])) { |
|
| 2160 | + $templates = explode(',', $settings['theme_templates']); |
|
| 2161 | + } else { |
|
| 2162 | + $templates = array('index'); |
|
| 2163 | + } |
|
| 2047 | 2164 | |
| 2048 | 2165 | // Load each template... |
| 2049 | - foreach ($templates as $template) |
|
| 2050 | - loadTemplate($template); |
|
| 2166 | + foreach ($templates as $template) { |
|
| 2167 | + loadTemplate($template); |
|
| 2168 | + } |
|
| 2051 | 2169 | |
| 2052 | 2170 | // ...and attempt to load their associated language files. |
| 2053 | 2171 | $required_files = implode('+', array_merge($templates, array('Modifications'))); |
| 2054 | 2172 | loadLanguage($required_files, '', false); |
| 2055 | 2173 | |
| 2056 | 2174 | // Custom template layers? |
| 2057 | - if (isset($settings['theme_layers'])) |
|
| 2058 | - $context['template_layers'] = explode(',', $settings['theme_layers']); |
|
| 2059 | - else |
|
| 2060 | - $context['template_layers'] = array('html', 'body'); |
|
| 2175 | + if (isset($settings['theme_layers'])) { |
|
| 2176 | + $context['template_layers'] = explode(',', $settings['theme_layers']); |
|
| 2177 | + } else { |
|
| 2178 | + $context['template_layers'] = array('html', 'body'); |
|
| 2179 | + } |
|
| 2061 | 2180 | } |
| 2062 | 2181 | |
| 2063 | 2182 | // Initialize the theme. |
| 2064 | 2183 | loadSubTemplate('init', 'ignore'); |
| 2065 | 2184 | |
| 2066 | 2185 | // Allow overriding the board wide time/number formats. |
| 2067 | - if (empty($user_settings['time_format']) && !empty($txt['time_format'])) |
|
| 2068 | - $user_info['time_format'] = $txt['time_format']; |
|
| 2186 | + if (empty($user_settings['time_format']) && !empty($txt['time_format'])) { |
|
| 2187 | + $user_info['time_format'] = $txt['time_format']; |
|
| 2188 | + } |
|
| 2069 | 2189 | |
| 2070 | 2190 | // Set the character set from the template. |
| 2071 | 2191 | $context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']; |
@@ -2073,12 +2193,14 @@ discard block |
||
| 2073 | 2193 | $context['right_to_left'] = !empty($txt['lang_rtl']); |
| 2074 | 2194 | |
| 2075 | 2195 | // Guests may still need a name. |
| 2076 | - if ($context['user']['is_guest'] && empty($context['user']['name'])) |
|
| 2077 | - $context['user']['name'] = $txt['guest_title']; |
|
| 2196 | + if ($context['user']['is_guest'] && empty($context['user']['name'])) { |
|
| 2197 | + $context['user']['name'] = $txt['guest_title']; |
|
| 2198 | + } |
|
| 2078 | 2199 | |
| 2079 | 2200 | // Any theme-related strings that need to be loaded? |
| 2080 | - if (!empty($settings['require_theme_strings'])) |
|
| 2081 | - loadLanguage('ThemeStrings', '', false); |
|
| 2201 | + if (!empty($settings['require_theme_strings'])) { |
|
| 2202 | + loadLanguage('ThemeStrings', '', false); |
|
| 2203 | + } |
|
| 2082 | 2204 | |
| 2083 | 2205 | // Make a special URL for the language. |
| 2084 | 2206 | $settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']); |
@@ -2089,8 +2211,9 @@ discard block |
||
| 2089 | 2211 | // Here is my luvly Responsive CSS |
| 2090 | 2212 | loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true), 'smf_responsive'); |
| 2091 | 2213 | |
| 2092 | - if ($context['right_to_left']) |
|
| 2093 | - loadCSSFile('rtl.css', array(), 'smf_rtl'); |
|
| 2214 | + if ($context['right_to_left']) { |
|
| 2215 | + loadCSSFile('rtl.css', array(), 'smf_rtl'); |
|
| 2216 | + } |
|
| 2094 | 2217 | |
| 2095 | 2218 | // We allow theme variants, because we're cool. |
| 2096 | 2219 | $context['theme_variant'] = ''; |
@@ -2098,14 +2221,17 @@ discard block |
||
| 2098 | 2221 | if (!empty($settings['theme_variants'])) |
| 2099 | 2222 | { |
| 2100 | 2223 | // Overriding - for previews and that ilk. |
| 2101 | - if (!empty($_REQUEST['variant'])) |
|
| 2102 | - $_SESSION['id_variant'] = $_REQUEST['variant']; |
|
| 2224 | + if (!empty($_REQUEST['variant'])) { |
|
| 2225 | + $_SESSION['id_variant'] = $_REQUEST['variant']; |
|
| 2226 | + } |
|
| 2103 | 2227 | // User selection? |
| 2104 | - if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) |
|
| 2105 | - $context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : ''); |
|
| 2228 | + if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) { |
|
| 2229 | + $context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : ''); |
|
| 2230 | + } |
|
| 2106 | 2231 | // If not a user variant, select the default. |
| 2107 | - if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) |
|
| 2108 | - $context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0]; |
|
| 2232 | + if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) { |
|
| 2233 | + $context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0]; |
|
| 2234 | + } |
|
| 2109 | 2235 | |
| 2110 | 2236 | // Do this to keep things easier in the templates. |
| 2111 | 2237 | $context['theme_variant'] = '_' . $context['theme_variant']; |
@@ -2114,20 +2240,23 @@ discard block |
||
| 2114 | 2240 | if (!empty($context['theme_variant'])) |
| 2115 | 2241 | { |
| 2116 | 2242 | loadCSSFile('index' . $context['theme_variant'] . '.css', array(), 'smf_index' . $context['theme_variant']); |
| 2117 | - if ($context['right_to_left']) |
|
| 2118 | - loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']); |
|
| 2243 | + if ($context['right_to_left']) { |
|
| 2244 | + loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']); |
|
| 2245 | + } |
|
| 2119 | 2246 | } |
| 2120 | 2247 | } |
| 2121 | 2248 | |
| 2122 | 2249 | // Let's be compatible with old themes! |
| 2123 | - if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) |
|
| 2124 | - $context['template_layers'] = array('main'); |
|
| 2250 | + if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) { |
|
| 2251 | + $context['template_layers'] = array('main'); |
|
| 2252 | + } |
|
| 2125 | 2253 | |
| 2126 | 2254 | $context['tabindex'] = 1; |
| 2127 | 2255 | |
| 2128 | 2256 | // Compatibility. |
| 2129 | - if (!isset($settings['theme_version'])) |
|
| 2130 | - $modSettings['memberCount'] = $modSettings['totalMembers']; |
|
| 2257 | + if (!isset($settings['theme_version'])) { |
|
| 2258 | + $modSettings['memberCount'] = $modSettings['totalMembers']; |
|
| 2259 | + } |
|
| 2131 | 2260 | |
| 2132 | 2261 | // Default JS variables for use in every theme |
| 2133 | 2262 | $context['javascript_vars'] = array( |
@@ -2146,18 +2275,18 @@ discard block |
||
| 2146 | 2275 | ); |
| 2147 | 2276 | |
| 2148 | 2277 | // Add the JQuery library to the list of files to load. |
| 2149 | - if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') |
|
| 2150 | - loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
| 2151 | - |
|
| 2152 | - elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') |
|
| 2153 | - loadJavaScriptFile('jquery-3.1.1.min.js', array('seed' => false), 'smf_jquery'); |
|
| 2154 | - |
|
| 2155 | - elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') |
|
| 2156 | - loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery'); |
|
| 2278 | + if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') { |
|
| 2279 | + loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
| 2280 | + } elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') { |
|
| 2281 | + loadJavaScriptFile('jquery-3.1.1.min.js', array('seed' => false), 'smf_jquery'); |
|
| 2282 | + } elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') { |
|
| 2283 | + loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery'); |
|
| 2284 | + } |
|
| 2157 | 2285 | |
| 2158 | 2286 | // Auto loading? template_javascript() will take care of the local half of this. |
| 2159 | - else |
|
| 2160 | - loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
| 2287 | + else { |
|
| 2288 | + loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
| 2289 | + } |
|
| 2161 | 2290 | |
| 2162 | 2291 | // Queue our JQuery plugins! |
| 2163 | 2292 | loadJavaScriptFile('smf_jquery_plugins.js', array('minimize' => true), 'smf_jquery_plugins'); |
@@ -2180,12 +2309,12 @@ discard block |
||
| 2180 | 2309 | require_once($sourcedir . '/ScheduledTasks.php'); |
| 2181 | 2310 | |
| 2182 | 2311 | // What to do, what to do?! |
| 2183 | - if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) |
|
| 2184 | - AutoTask(); |
|
| 2185 | - else |
|
| 2186 | - ReduceMailQueue(); |
|
| 2187 | - } |
|
| 2188 | - else |
|
| 2312 | + if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) { |
|
| 2313 | + AutoTask(); |
|
| 2314 | + } else { |
|
| 2315 | + ReduceMailQueue(); |
|
| 2316 | + } |
|
| 2317 | + } else |
|
| 2189 | 2318 | { |
| 2190 | 2319 | $type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq'; |
| 2191 | 2320 | $ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time']; |
@@ -2236,8 +2365,9 @@ discard block |
||
| 2236 | 2365 | foreach ($theme_includes as $include) |
| 2237 | 2366 | { |
| 2238 | 2367 | $include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
| 2239 | - if (file_exists($include)) |
|
| 2240 | - require_once($include); |
|
| 2368 | + if (file_exists($include)) { |
|
| 2369 | + require_once($include); |
|
| 2370 | + } |
|
| 2241 | 2371 | } |
| 2242 | 2372 | } |
| 2243 | 2373 | |
@@ -2267,16 +2397,19 @@ discard block |
||
| 2267 | 2397 | // Do any style sheets first, cause we're easy with those. |
| 2268 | 2398 | if (!empty($style_sheets)) |
| 2269 | 2399 | { |
| 2270 | - if (!is_array($style_sheets)) |
|
| 2271 | - $style_sheets = array($style_sheets); |
|
| 2400 | + if (!is_array($style_sheets)) { |
|
| 2401 | + $style_sheets = array($style_sheets); |
|
| 2402 | + } |
|
| 2272 | 2403 | |
| 2273 | - foreach ($style_sheets as $sheet) |
|
| 2274 | - loadCSSFile($sheet . '.css', array(), $sheet); |
|
| 2404 | + foreach ($style_sheets as $sheet) { |
|
| 2405 | + loadCSSFile($sheet . '.css', array(), $sheet); |
|
| 2406 | + } |
|
| 2275 | 2407 | } |
| 2276 | 2408 | |
| 2277 | 2409 | // No template to load? |
| 2278 | - if ($template_name === false) |
|
| 2279 | - return true; |
|
| 2410 | + if ($template_name === false) { |
|
| 2411 | + return true; |
|
| 2412 | + } |
|
| 2280 | 2413 | |
| 2281 | 2414 | $loaded = false; |
| 2282 | 2415 | foreach ($settings['template_dirs'] as $template_dir) |
@@ -2291,12 +2424,14 @@ discard block |
||
| 2291 | 2424 | |
| 2292 | 2425 | if ($loaded) |
| 2293 | 2426 | { |
| 2294 | - if ($db_show_debug === true) |
|
| 2295 | - $context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')'; |
|
| 2427 | + if ($db_show_debug === true) { |
|
| 2428 | + $context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')'; |
|
| 2429 | + } |
|
| 2296 | 2430 | |
| 2297 | 2431 | // If they have specified an initialization function for this template, go ahead and call it now. |
| 2298 | - if (function_exists('template_' . $template_name . '_init')) |
|
| 2299 | - call_user_func('template_' . $template_name . '_init'); |
|
| 2432 | + if (function_exists('template_' . $template_name . '_init')) { |
|
| 2433 | + call_user_func('template_' . $template_name . '_init'); |
|
| 2434 | + } |
|
| 2300 | 2435 | } |
| 2301 | 2436 | // Hmmm... doesn't exist?! I don't suppose the directory is wrong, is it? |
| 2302 | 2437 | elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default')) |
@@ -2316,13 +2451,14 @@ discard block |
||
| 2316 | 2451 | loadTemplate($template_name); |
| 2317 | 2452 | } |
| 2318 | 2453 | // Cause an error otherwise. |
| 2319 | - elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) |
|
| 2320 | - fatal_lang_error('theme_template_error', 'template', array((string) $template_name)); |
|
| 2321 | - elseif ($fatal) |
|
| 2322 | - 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')); |
|
| 2323 | - else |
|
| 2324 | - return false; |
|
| 2325 | -} |
|
| 2454 | + elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) { |
|
| 2455 | + fatal_lang_error('theme_template_error', 'template', array((string) $template_name)); |
|
| 2456 | + } elseif ($fatal) { |
|
| 2457 | + 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')); |
|
| 2458 | + } else { |
|
| 2459 | + return false; |
|
| 2460 | + } |
|
| 2461 | + } |
|
| 2326 | 2462 | |
| 2327 | 2463 | /** |
| 2328 | 2464 | * Load a sub-template. |
@@ -2340,17 +2476,19 @@ discard block |
||
| 2340 | 2476 | { |
| 2341 | 2477 | global $context, $txt, $db_show_debug; |
| 2342 | 2478 | |
| 2343 | - if ($db_show_debug === true) |
|
| 2344 | - $context['debug']['sub_templates'][] = $sub_template_name; |
|
| 2479 | + if ($db_show_debug === true) { |
|
| 2480 | + $context['debug']['sub_templates'][] = $sub_template_name; |
|
| 2481 | + } |
|
| 2345 | 2482 | |
| 2346 | 2483 | // Figure out what the template function is named. |
| 2347 | 2484 | $theme_function = 'template_' . $sub_template_name; |
| 2348 | - if (function_exists($theme_function)) |
|
| 2349 | - $theme_function(); |
|
| 2350 | - elseif ($fatal === false) |
|
| 2351 | - fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name)); |
|
| 2352 | - elseif ($fatal !== 'ignore') |
|
| 2353 | - 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')); |
|
| 2485 | + if (function_exists($theme_function)) { |
|
| 2486 | + $theme_function(); |
|
| 2487 | + } elseif ($fatal === false) { |
|
| 2488 | + fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name)); |
|
| 2489 | + } elseif ($fatal !== 'ignore') { |
|
| 2490 | + 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')); |
|
| 2491 | + } |
|
| 2354 | 2492 | |
| 2355 | 2493 | // Are we showing debugging for templates? Just make sure not to do it before the doctype... |
| 2356 | 2494 | if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml'])) |
@@ -2387,8 +2525,9 @@ discard block |
||
| 2387 | 2525 | $params['validate'] = isset($params['validate']) ? $params['validate'] : true; |
| 2388 | 2526 | |
| 2389 | 2527 | // If this is an external file, automatically set this to false. |
| 2390 | - if (!empty($params['external'])) |
|
| 2391 | - $params['minimize'] = false; |
|
| 2528 | + if (!empty($params['external'])) { |
|
| 2529 | + $params['minimize'] = false; |
|
| 2530 | + } |
|
| 2392 | 2531 | |
| 2393 | 2532 | // Account for shorthand like admin.css?alp21 filenames |
| 2394 | 2533 | $has_seed = strpos($fileName, '.css?'); |
@@ -2405,13 +2544,10 @@ discard block |
||
| 2405 | 2544 | { |
| 2406 | 2545 | $fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
| 2407 | 2546 | $filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
| 2547 | + } else { |
|
| 2548 | + $fileUrl = false; |
|
| 2408 | 2549 | } |
| 2409 | - |
|
| 2410 | - else |
|
| 2411 | - $fileUrl = false; |
|
| 2412 | - } |
|
| 2413 | - |
|
| 2414 | - else |
|
| 2550 | + } else |
|
| 2415 | 2551 | { |
| 2416 | 2552 | $fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
| 2417 | 2553 | $filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
@@ -2426,12 +2562,14 @@ discard block |
||
| 2426 | 2562 | } |
| 2427 | 2563 | |
| 2428 | 2564 | // Add it to the array for use in the template |
| 2429 | - if (!empty($fileName)) |
|
| 2430 | - $context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params); |
|
| 2565 | + if (!empty($fileName)) { |
|
| 2566 | + $context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params); |
|
| 2567 | + } |
|
| 2431 | 2568 | |
| 2432 | - if (!empty($context['right_to_left']) && !empty($params['rtl'])) |
|
| 2433 | - loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0))); |
|
| 2434 | -} |
|
| 2569 | + if (!empty($context['right_to_left']) && !empty($params['rtl'])) { |
|
| 2570 | + loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0))); |
|
| 2571 | + } |
|
| 2572 | + } |
|
| 2435 | 2573 | |
| 2436 | 2574 | /** |
| 2437 | 2575 | * Add a block of inline css code to be executed later |
@@ -2448,8 +2586,9 @@ discard block |
||
| 2448 | 2586 | global $context; |
| 2449 | 2587 | |
| 2450 | 2588 | // Gotta add something... |
| 2451 | - if (empty($css)) |
|
| 2452 | - return false; |
|
| 2589 | + if (empty($css)) { |
|
| 2590 | + return false; |
|
| 2591 | + } |
|
| 2453 | 2592 | |
| 2454 | 2593 | $context['css_header'][] = $css; |
| 2455 | 2594 | } |
@@ -2484,8 +2623,9 @@ discard block |
||
| 2484 | 2623 | $params['validate'] = isset($params['validate']) ? $params['validate'] : true; |
| 2485 | 2624 | |
| 2486 | 2625 | // If this is an external file, automatically set this to false. |
| 2487 | - if (!empty($params['external'])) |
|
| 2488 | - $params['minimize'] = false; |
|
| 2626 | + if (!empty($params['external'])) { |
|
| 2627 | + $params['minimize'] = false; |
|
| 2628 | + } |
|
| 2489 | 2629 | |
| 2490 | 2630 | // Account for shorthand like admin.js?alp21 filenames |
| 2491 | 2631 | $has_seed = strpos($fileName, '.js?'); |
@@ -2502,16 +2642,12 @@ discard block |
||
| 2502 | 2642 | { |
| 2503 | 2643 | $fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
| 2504 | 2644 | $filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
| 2505 | - } |
|
| 2506 | - |
|
| 2507 | - else |
|
| 2645 | + } else |
|
| 2508 | 2646 | { |
| 2509 | 2647 | $fileUrl = false; |
| 2510 | 2648 | $filePath = false; |
| 2511 | 2649 | } |
| 2512 | - } |
|
| 2513 | - |
|
| 2514 | - else |
|
| 2650 | + } else |
|
| 2515 | 2651 | { |
| 2516 | 2652 | $fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
| 2517 | 2653 | $filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
@@ -2526,9 +2662,10 @@ discard block |
||
| 2526 | 2662 | } |
| 2527 | 2663 | |
| 2528 | 2664 | // Add it to the array for use in the template |
| 2529 | - if (!empty($fileName)) |
|
| 2530 | - $context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params); |
|
| 2531 | -} |
|
| 2665 | + if (!empty($fileName)) { |
|
| 2666 | + $context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params); |
|
| 2667 | + } |
|
| 2668 | + } |
|
| 2532 | 2669 | |
| 2533 | 2670 | /** |
| 2534 | 2671 | * Add a Javascript variable for output later (for feeding text strings and similar to JS) |
@@ -2542,9 +2679,10 @@ discard block |
||
| 2542 | 2679 | { |
| 2543 | 2680 | global $context; |
| 2544 | 2681 | |
| 2545 | - if (!empty($key) && (!empty($value) || $value === '0')) |
|
| 2546 | - $context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value; |
|
| 2547 | -} |
|
| 2682 | + if (!empty($key) && (!empty($value) || $value === '0')) { |
|
| 2683 | + $context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value; |
|
| 2684 | + } |
|
| 2685 | + } |
|
| 2548 | 2686 | |
| 2549 | 2687 | /** |
| 2550 | 2688 | * Add a block of inline Javascript code to be executed later |
@@ -2561,8 +2699,9 @@ discard block |
||
| 2561 | 2699 | { |
| 2562 | 2700 | global $context; |
| 2563 | 2701 | |
| 2564 | - if (empty($javascript)) |
|
| 2565 | - return false; |
|
| 2702 | + if (empty($javascript)) { |
|
| 2703 | + return false; |
|
| 2704 | + } |
|
| 2566 | 2705 | |
| 2567 | 2706 | $context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript; |
| 2568 | 2707 | } |
@@ -2583,15 +2722,18 @@ discard block |
||
| 2583 | 2722 | static $already_loaded = array(); |
| 2584 | 2723 | |
| 2585 | 2724 | // Default to the user's language. |
| 2586 | - if ($lang == '') |
|
| 2587 | - $lang = isset($user_info['language']) ? $user_info['language'] : $language; |
|
| 2725 | + if ($lang == '') { |
|
| 2726 | + $lang = isset($user_info['language']) ? $user_info['language'] : $language; |
|
| 2727 | + } |
|
| 2588 | 2728 | |
| 2589 | 2729 | // Do we want the English version of language file as fallback? |
| 2590 | - if (empty($modSettings['disable_language_fallback']) && $lang != 'english') |
|
| 2591 | - loadLanguage($template_name, 'english', false); |
|
| 2730 | + if (empty($modSettings['disable_language_fallback']) && $lang != 'english') { |
|
| 2731 | + loadLanguage($template_name, 'english', false); |
|
| 2732 | + } |
|
| 2592 | 2733 | |
| 2593 | - if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) |
|
| 2594 | - return $lang; |
|
| 2734 | + if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) { |
|
| 2735 | + return $lang; |
|
| 2736 | + } |
|
| 2595 | 2737 | |
| 2596 | 2738 | // Make sure we have $settings - if not we're in trouble and need to find it! |
| 2597 | 2739 | if (empty($settings['default_theme_dir'])) |
@@ -2602,8 +2744,9 @@ discard block |
||
| 2602 | 2744 | |
| 2603 | 2745 | // What theme are we in? |
| 2604 | 2746 | $theme_name = basename($settings['theme_url']); |
| 2605 | - if (empty($theme_name)) |
|
| 2606 | - $theme_name = 'unknown'; |
|
| 2747 | + if (empty($theme_name)) { |
|
| 2748 | + $theme_name = 'unknown'; |
|
| 2749 | + } |
|
| 2607 | 2750 | |
| 2608 | 2751 | // For each file open it up and write it out! |
| 2609 | 2752 | foreach (explode('+', $template_name) as $template) |
@@ -2645,8 +2788,9 @@ discard block |
||
| 2645 | 2788 | $found = true; |
| 2646 | 2789 | |
| 2647 | 2790 | // setlocale is required for basename() & pathinfo() to work properly on the selected language |
| 2648 | - if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set'])) |
|
| 2649 | - setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']); |
|
| 2791 | + if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set'])) { |
|
| 2792 | + setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']); |
|
| 2793 | + } |
|
| 2650 | 2794 | |
| 2651 | 2795 | break; |
| 2652 | 2796 | } |
@@ -2686,8 +2830,9 @@ discard block |
||
| 2686 | 2830 | } |
| 2687 | 2831 | |
| 2688 | 2832 | // Keep track of what we're up to soldier. |
| 2689 | - if ($db_show_debug === true) |
|
| 2690 | - $context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')'; |
|
| 2833 | + if ($db_show_debug === true) { |
|
| 2834 | + $context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')'; |
|
| 2835 | + } |
|
| 2691 | 2836 | |
| 2692 | 2837 | // Remember what we have loaded, and in which language. |
| 2693 | 2838 | $already_loaded[$template_name] = $lang; |
@@ -2733,8 +2878,9 @@ discard block |
||
| 2733 | 2878 | ) |
| 2734 | 2879 | ); |
| 2735 | 2880 | // In the EXTREMELY unlikely event this happens, give an error message. |
| 2736 | - if ($smcFunc['db_num_rows']($result) == 0) |
|
| 2737 | - fatal_lang_error('parent_not_found', 'critical'); |
|
| 2881 | + if ($smcFunc['db_num_rows']($result) == 0) { |
|
| 2882 | + fatal_lang_error('parent_not_found', 'critical'); |
|
| 2883 | + } |
|
| 2738 | 2884 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
| 2739 | 2885 | { |
| 2740 | 2886 | if (!isset($boards[$row['id_board']])) |
@@ -2751,8 +2897,8 @@ discard block |
||
| 2751 | 2897 | ); |
| 2752 | 2898 | } |
| 2753 | 2899 | // If a moderator exists for this board, add that moderator for all children too. |
| 2754 | - if (!empty($row['id_moderator'])) |
|
| 2755 | - foreach ($boards as $id => $dummy) |
|
| 2900 | + if (!empty($row['id_moderator'])) { |
|
| 2901 | + foreach ($boards as $id => $dummy) |
|
| 2756 | 2902 | { |
| 2757 | 2903 | $boards[$id]['moderators'][$row['id_moderator']] = array( |
| 2758 | 2904 | 'id' => $row['id_moderator'], |
@@ -2760,11 +2906,12 @@ discard block |
||
| 2760 | 2906 | 'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'], |
| 2761 | 2907 | 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>' |
| 2762 | 2908 | ); |
| 2909 | + } |
|
| 2763 | 2910 | } |
| 2764 | 2911 | |
| 2765 | 2912 | // If a moderator group exists for this board, add that moderator group for all children too |
| 2766 | - if (!empty($row['id_moderator_group'])) |
|
| 2767 | - foreach ($boards as $id => $dummy) |
|
| 2913 | + if (!empty($row['id_moderator_group'])) { |
|
| 2914 | + foreach ($boards as $id => $dummy) |
|
| 2768 | 2915 | { |
| 2769 | 2916 | $boards[$id]['moderator_groups'][$row['id_moderator_group']] = array( |
| 2770 | 2917 | 'id' => $row['id_moderator_group'], |
@@ -2772,6 +2919,7 @@ discard block |
||
| 2772 | 2919 | 'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'], |
| 2773 | 2920 | 'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>' |
| 2774 | 2921 | ); |
| 2922 | + } |
|
| 2775 | 2923 | } |
| 2776 | 2924 | } |
| 2777 | 2925 | $smcFunc['db_free_result']($result); |
@@ -2798,23 +2946,27 @@ discard block |
||
| 2798 | 2946 | if (!$use_cache || ($context['languages'] = cache_get_data('known_languages', !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null) |
| 2799 | 2947 | { |
| 2800 | 2948 | // If we don't have our ucwords function defined yet, let's load the settings data. |
| 2801 | - if (empty($smcFunc['ucwords'])) |
|
| 2802 | - reloadSettings(); |
|
| 2949 | + if (empty($smcFunc['ucwords'])) { |
|
| 2950 | + reloadSettings(); |
|
| 2951 | + } |
|
| 2803 | 2952 | |
| 2804 | 2953 | // If we don't have our theme information yet, let's get it. |
| 2805 | - if (empty($settings['default_theme_dir'])) |
|
| 2806 | - loadTheme(0, false); |
|
| 2954 | + if (empty($settings['default_theme_dir'])) { |
|
| 2955 | + loadTheme(0, false); |
|
| 2956 | + } |
|
| 2807 | 2957 | |
| 2808 | 2958 | // Default language directories to try. |
| 2809 | 2959 | $language_directories = array( |
| 2810 | 2960 | $settings['default_theme_dir'] . '/languages', |
| 2811 | 2961 | ); |
| 2812 | - if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) |
|
| 2813 | - $language_directories[] = $settings['actual_theme_dir'] . '/languages'; |
|
| 2962 | + if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) { |
|
| 2963 | + $language_directories[] = $settings['actual_theme_dir'] . '/languages'; |
|
| 2964 | + } |
|
| 2814 | 2965 | |
| 2815 | 2966 | // We possibly have a base theme directory. |
| 2816 | - if (!empty($settings['base_theme_dir'])) |
|
| 2817 | - $language_directories[] = $settings['base_theme_dir'] . '/languages'; |
|
| 2967 | + if (!empty($settings['base_theme_dir'])) { |
|
| 2968 | + $language_directories[] = $settings['base_theme_dir'] . '/languages'; |
|
| 2969 | + } |
|
| 2818 | 2970 | |
| 2819 | 2971 | // Remove any duplicates. |
| 2820 | 2972 | $language_directories = array_unique($language_directories); |
@@ -2828,20 +2980,21 @@ discard block |
||
| 2828 | 2980 | foreach ($language_directories as $language_dir) |
| 2829 | 2981 | { |
| 2830 | 2982 | // Can't look in here... doesn't exist! |
| 2831 | - if (!file_exists($language_dir)) |
|
| 2832 | - continue; |
|
| 2983 | + if (!file_exists($language_dir)) { |
|
| 2984 | + continue; |
|
| 2985 | + } |
|
| 2833 | 2986 | |
| 2834 | 2987 | $dir = dir($language_dir); |
| 2835 | 2988 | while ($entry = $dir->read()) |
| 2836 | 2989 | { |
| 2837 | 2990 | // Look for the index language file... For good measure skip any "index.language-utf8.php" files |
| 2838 | - if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) |
|
| 2839 | - continue; |
|
| 2840 | - |
|
| 2841 | - if (!empty($langList) && !empty($langList[$matches[1]])) |
|
| 2842 | - $langName = $langList[$matches[1]]; |
|
| 2991 | + if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) { |
|
| 2992 | + continue; |
|
| 2993 | + } |
|
| 2843 | 2994 | |
| 2844 | - else |
|
| 2995 | + if (!empty($langList) && !empty($langList[$matches[1]])) { |
|
| 2996 | + $langName = $langList[$matches[1]]; |
|
| 2997 | + } else |
|
| 2845 | 2998 | { |
| 2846 | 2999 | $langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' '))); |
| 2847 | 3000 | |
@@ -2882,12 +3035,14 @@ discard block |
||
| 2882 | 3035 | } |
| 2883 | 3036 | |
| 2884 | 3037 | // Do we need to store the lang list? |
| 2885 | - if (empty($langList)) |
|
| 2886 | - updateSettings(array('langList' => json_encode($catchLang))); |
|
| 3038 | + if (empty($langList)) { |
|
| 3039 | + updateSettings(array('langList' => json_encode($catchLang))); |
|
| 3040 | + } |
|
| 2887 | 3041 | |
| 2888 | 3042 | // Let's cash in on this deal. |
| 2889 | - if (!empty($modSettings['cache_enable'])) |
|
| 2890 | - cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600); |
|
| 3043 | + if (!empty($modSettings['cache_enable'])) { |
|
| 3044 | + cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600); |
|
| 3045 | + } |
|
| 2891 | 3046 | } |
| 2892 | 3047 | |
| 2893 | 3048 | return $context['languages']; |
@@ -2910,8 +3065,9 @@ discard block |
||
| 2910 | 3065 | global $modSettings, $options, $txt; |
| 2911 | 3066 | static $censor_vulgar = null, $censor_proper; |
| 2912 | 3067 | |
| 2913 | - if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') |
|
| 2914 | - return $text; |
|
| 3068 | + if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') { |
|
| 3069 | + return $text; |
|
| 3070 | + } |
|
| 2915 | 3071 | |
| 2916 | 3072 | // If they haven't yet been loaded, load them. |
| 2917 | 3073 | if ($censor_vulgar == null) |
@@ -2939,9 +3095,9 @@ discard block |
||
| 2939 | 3095 | { |
| 2940 | 3096 | $func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace'; |
| 2941 | 3097 | $text = $func($censor_vulgar, $censor_proper, $text); |
| 3098 | + } else { |
|
| 3099 | + $text = preg_replace($censor_vulgar, $censor_proper, $text); |
|
| 2942 | 3100 | } |
| 2943 | - else |
|
| 2944 | - $text = preg_replace($censor_vulgar, $censor_proper, $text); |
|
| 2945 | 3101 | |
| 2946 | 3102 | return $text; |
| 2947 | 3103 | } |
@@ -2967,38 +3123,42 @@ discard block |
||
| 2967 | 3123 | @ini_set('track_errors', '1'); |
| 2968 | 3124 | |
| 2969 | 3125 | // Don't include the file more than once, if $once is true. |
| 2970 | - if ($once && in_array($filename, $templates)) |
|
| 2971 | - return; |
|
| 3126 | + if ($once && in_array($filename, $templates)) { |
|
| 3127 | + return; |
|
| 3128 | + } |
|
| 2972 | 3129 | // Add this file to the include list, whether $once is true or not. |
| 2973 | - else |
|
| 2974 | - $templates[] = $filename; |
|
| 3130 | + else { |
|
| 3131 | + $templates[] = $filename; |
|
| 3132 | + } |
|
| 2975 | 3133 | |
| 2976 | 3134 | // Are we going to use eval? |
| 2977 | 3135 | if (empty($modSettings['disableTemplateEval'])) |
| 2978 | 3136 | { |
| 2979 | 3137 | $file_found = file_exists($filename) && eval('?' . '>' . rtrim(file_get_contents($filename))) !== false; |
| 2980 | 3138 | $settings['current_include_filename'] = $filename; |
| 2981 | - } |
|
| 2982 | - else |
|
| 3139 | + } else |
|
| 2983 | 3140 | { |
| 2984 | 3141 | $file_found = file_exists($filename); |
| 2985 | 3142 | |
| 2986 | - if ($once && $file_found) |
|
| 2987 | - require_once($filename); |
|
| 2988 | - elseif ($file_found) |
|
| 2989 | - require($filename); |
|
| 3143 | + if ($once && $file_found) { |
|
| 3144 | + require_once($filename); |
|
| 3145 | + } elseif ($file_found) { |
|
| 3146 | + require($filename); |
|
| 3147 | + } |
|
| 2990 | 3148 | } |
| 2991 | 3149 | |
| 2992 | 3150 | if ($file_found !== true) |
| 2993 | 3151 | { |
| 2994 | 3152 | ob_end_clean(); |
| 2995 | - if (!empty($modSettings['enableCompressedOutput'])) |
|
| 2996 | - @ob_start('ob_gzhandler'); |
|
| 2997 | - else |
|
| 2998 | - ob_start(); |
|
| 3153 | + if (!empty($modSettings['enableCompressedOutput'])) { |
|
| 3154 | + @ob_start('ob_gzhandler'); |
|
| 3155 | + } else { |
|
| 3156 | + ob_start(); |
|
| 3157 | + } |
|
| 2999 | 3158 | |
| 3000 | - if (isset($_GET['debug'])) |
|
| 3001 | - header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
| 3159 | + if (isset($_GET['debug'])) { |
|
| 3160 | + header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
| 3161 | + } |
|
| 3002 | 3162 | |
| 3003 | 3163 | // Don't cache error pages!! |
| 3004 | 3164 | header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); |
@@ -3017,12 +3177,13 @@ discard block |
||
| 3017 | 3177 | echo '<!DOCTYPE html> |
| 3018 | 3178 | <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '> |
| 3019 | 3179 | <head>'; |
| 3020 | - if (isset($context['character_set'])) |
|
| 3021 | - echo ' |
|
| 3180 | + if (isset($context['character_set'])) { |
|
| 3181 | + echo ' |
|
| 3022 | 3182 | <meta charset="', $context['character_set'], '">'; |
| 3183 | + } |
|
| 3023 | 3184 | |
| 3024 | - if (!empty($maintenance) && !allowedTo('admin_forum')) |
|
| 3025 | - echo ' |
|
| 3185 | + if (!empty($maintenance) && !allowedTo('admin_forum')) { |
|
| 3186 | + echo ' |
|
| 3026 | 3187 | <title>', $mtitle, '</title> |
| 3027 | 3188 | </head> |
| 3028 | 3189 | <body> |
@@ -3030,8 +3191,8 @@ discard block |
||
| 3030 | 3191 | ', $mmessage, ' |
| 3031 | 3192 | </body> |
| 3032 | 3193 | </html>'; |
| 3033 | - elseif (!allowedTo('admin_forum')) |
|
| 3034 | - echo ' |
|
| 3194 | + } elseif (!allowedTo('admin_forum')) { |
|
| 3195 | + echo ' |
|
| 3035 | 3196 | <title>', $txt['template_parse_error'], '</title> |
| 3036 | 3197 | </head> |
| 3037 | 3198 | <body> |
@@ -3039,16 +3200,18 @@ discard block |
||
| 3039 | 3200 | ', $txt['template_parse_error_message'], ' |
| 3040 | 3201 | </body> |
| 3041 | 3202 | </html>'; |
| 3042 | - else |
|
| 3203 | + } else |
|
| 3043 | 3204 | { |
| 3044 | 3205 | require_once($sourcedir . '/Subs-Package.php'); |
| 3045 | 3206 | |
| 3046 | 3207 | $error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => ''))); |
| 3047 | 3208 | $error_array = error_get_last(); |
| 3048 | - if (empty($error) && ini_get('track_errors') && !empty($error_array)) |
|
| 3049 | - $error = $error_array['message']; |
|
| 3050 | - if (empty($error)) |
|
| 3051 | - $error = $txt['template_parse_errmsg']; |
|
| 3209 | + if (empty($error) && ini_get('track_errors') && !empty($error_array)) { |
|
| 3210 | + $error = $error_array['message']; |
|
| 3211 | + } |
|
| 3212 | + if (empty($error)) { |
|
| 3213 | + $error = $txt['template_parse_errmsg']; |
|
| 3214 | + } |
|
| 3052 | 3215 | |
| 3053 | 3216 | $error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>')); |
| 3054 | 3217 | |
@@ -3059,11 +3222,12 @@ discard block |
||
| 3059 | 3222 | <h3>', $txt['template_parse_error'], '</h3> |
| 3060 | 3223 | ', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => ''))); |
| 3061 | 3224 | |
| 3062 | - if (!empty($error)) |
|
| 3063 | - echo ' |
|
| 3225 | + if (!empty($error)) { |
|
| 3226 | + echo ' |
|
| 3064 | 3227 | <hr> |
| 3065 | 3228 | |
| 3066 | 3229 | <div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>'; |
| 3230 | + } |
|
| 3067 | 3231 | |
| 3068 | 3232 | // I know, I know... this is VERY COMPLICATED. Still, it's good. |
| 3069 | 3233 | if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0) |
@@ -3073,10 +3237,11 @@ discard block |
||
| 3073 | 3237 | $data2 = preg_split('~\<br( /)?\>~', $data2); |
| 3074 | 3238 | |
| 3075 | 3239 | // Fix the PHP code stuff... |
| 3076 | - if (!isBrowser('gecko')) |
|
| 3077 | - $data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2); |
|
| 3078 | - else |
|
| 3079 | - $data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2); |
|
| 3240 | + if (!isBrowser('gecko')) { |
|
| 3241 | + $data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2); |
|
| 3242 | + } else { |
|
| 3243 | + $data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2); |
|
| 3244 | + } |
|
| 3080 | 3245 | |
| 3081 | 3246 | // Now we get to work around a bug in PHP where it doesn't escape <br>s! |
| 3082 | 3247 | $j = -1; |
@@ -3084,8 +3249,9 @@ discard block |
||
| 3084 | 3249 | { |
| 3085 | 3250 | $j++; |
| 3086 | 3251 | |
| 3087 | - if (substr_count($line, '<br>') == 0) |
|
| 3088 | - continue; |
|
| 3252 | + if (substr_count($line, '<br>') == 0) { |
|
| 3253 | + continue; |
|
| 3254 | + } |
|
| 3089 | 3255 | |
| 3090 | 3256 | $n = substr_count($line, '<br>'); |
| 3091 | 3257 | for ($i = 0; $i < $n; $i++) |
@@ -3104,38 +3270,42 @@ discard block |
||
| 3104 | 3270 | // Figure out what the color coding was before... |
| 3105 | 3271 | $line = max($match[1] - 9, 1); |
| 3106 | 3272 | $last_line = ''; |
| 3107 | - for ($line2 = $line - 1; $line2 > 1; $line2--) |
|
| 3108 | - if (strpos($data2[$line2], '<') !== false) |
|
| 3273 | + for ($line2 = $line - 1; $line2 > 1; $line2--) { |
|
| 3274 | + if (strpos($data2[$line2], '<') !== false) |
|
| 3109 | 3275 | { |
| 3110 | 3276 | if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0) |
| 3111 | 3277 | $last_line = $color_match[1]; |
| 3278 | + } |
|
| 3112 | 3279 | break; |
| 3113 | 3280 | } |
| 3114 | 3281 | |
| 3115 | 3282 | // Show the relevant lines... |
| 3116 | 3283 | for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++) |
| 3117 | 3284 | { |
| 3118 | - if ($line == $match[1]) |
|
| 3119 | - echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">'; |
|
| 3285 | + if ($line == $match[1]) { |
|
| 3286 | + echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">'; |
|
| 3287 | + } |
|
| 3120 | 3288 | |
| 3121 | 3289 | echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> '; |
| 3122 | - if (isset($data2[$line]) && $data2[$line] != '') |
|
| 3123 | - echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line]; |
|
| 3290 | + if (isset($data2[$line]) && $data2[$line] != '') { |
|
| 3291 | + echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line]; |
|
| 3292 | + } |
|
| 3124 | 3293 | |
| 3125 | 3294 | if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0) |
| 3126 | 3295 | { |
| 3127 | 3296 | $last_line = $color_match[1]; |
| 3128 | 3297 | echo '</', substr($last_line, 1, 4), '>'; |
| 3298 | + } elseif ($last_line != '' && strpos($data2[$line], '<') !== false) { |
|
| 3299 | + $last_line = ''; |
|
| 3300 | + } elseif ($last_line != '' && $data2[$line] != '') { |
|
| 3301 | + echo '</', substr($last_line, 1, 4), '>'; |
|
| 3129 | 3302 | } |
| 3130 | - elseif ($last_line != '' && strpos($data2[$line], '<') !== false) |
|
| 3131 | - $last_line = ''; |
|
| 3132 | - elseif ($last_line != '' && $data2[$line] != '') |
|
| 3133 | - echo '</', substr($last_line, 1, 4), '>'; |
|
| 3134 | 3303 | |
| 3135 | - if ($line == $match[1]) |
|
| 3136 | - echo '</pre></div><pre style="margin: 0;">'; |
|
| 3137 | - else |
|
| 3138 | - echo "\n"; |
|
| 3304 | + if ($line == $match[1]) { |
|
| 3305 | + echo '</pre></div><pre style="margin: 0;">'; |
|
| 3306 | + } else { |
|
| 3307 | + echo "\n"; |
|
| 3308 | + } |
|
| 3139 | 3309 | } |
| 3140 | 3310 | |
| 3141 | 3311 | echo '</pre></div>'; |
@@ -3159,8 +3329,9 @@ discard block |
||
| 3159 | 3329 | global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port; |
| 3160 | 3330 | |
| 3161 | 3331 | // Figure out what type of database we are using. |
| 3162 | - if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) |
|
| 3163 | - $db_type = 'mysql'; |
|
| 3332 | + if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) { |
|
| 3333 | + $db_type = 'mysql'; |
|
| 3334 | + } |
|
| 3164 | 3335 | |
| 3165 | 3336 | // Load the file for the database. |
| 3166 | 3337 | require_once($sourcedir . '/Subs-Db-' . $db_type . '.php'); |
@@ -3168,8 +3339,9 @@ discard block |
||
| 3168 | 3339 | $db_options = array(); |
| 3169 | 3340 | |
| 3170 | 3341 | // Add in the port if needed |
| 3171 | - if (!empty($db_port)) |
|
| 3172 | - $db_options['port'] = $db_port; |
|
| 3342 | + if (!empty($db_port)) { |
|
| 3343 | + $db_options['port'] = $db_port; |
|
| 3344 | + } |
|
| 3173 | 3345 | |
| 3174 | 3346 | // 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. |
| 3175 | 3347 | if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd)) |
@@ -3188,13 +3360,15 @@ discard block |
||
| 3188 | 3360 | } |
| 3189 | 3361 | |
| 3190 | 3362 | // Safe guard here, if there isn't a valid connection lets put a stop to it. |
| 3191 | - if (!$db_connection) |
|
| 3192 | - display_db_error(); |
|
| 3363 | + if (!$db_connection) { |
|
| 3364 | + display_db_error(); |
|
| 3365 | + } |
|
| 3193 | 3366 | |
| 3194 | 3367 | // If in SSI mode fix up the prefix. |
| 3195 | - if (SMF == 'SSI') |
|
| 3196 | - db_fix_prefix($db_prefix, $db_name); |
|
| 3197 | -} |
|
| 3368 | + if (SMF == 'SSI') { |
|
| 3369 | + db_fix_prefix($db_prefix, $db_name); |
|
| 3370 | + } |
|
| 3371 | + } |
|
| 3198 | 3372 | |
| 3199 | 3373 | /** |
| 3200 | 3374 | * Try to load up a supported caching method. This is saved in $cacheAPI if we are not overriding it. |
@@ -3208,10 +3382,11 @@ discard block |
||
| 3208 | 3382 | global $sourcedir, $cacheAPI, $cache_accelerator; |
| 3209 | 3383 | |
| 3210 | 3384 | // Not overriding this and we have a cacheAPI, send it back. |
| 3211 | - if (empty($overrideCache) && is_object($cacheAPI)) |
|
| 3212 | - return $cacheAPI; |
|
| 3213 | - elseif (is_null($cacheAPI)) |
|
| 3214 | - $cacheAPI = false; |
|
| 3385 | + if (empty($overrideCache) && is_object($cacheAPI)) { |
|
| 3386 | + return $cacheAPI; |
|
| 3387 | + } elseif (is_null($cacheAPI)) { |
|
| 3388 | + $cacheAPI = false; |
|
| 3389 | + } |
|
| 3215 | 3390 | |
| 3216 | 3391 | // Make sure our class is in session. |
| 3217 | 3392 | require_once($sourcedir . '/Class-CacheAPI.php'); |
@@ -3232,8 +3407,9 @@ discard block |
||
| 3232 | 3407 | if (!$testAPI->isSupported()) |
| 3233 | 3408 | { |
| 3234 | 3409 | // Can we save ourselves? |
| 3235 | - if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') |
|
| 3236 | - return loadCacheAccelerator(null, false); |
|
| 3410 | + if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') { |
|
| 3411 | + return loadCacheAccelerator(null, false); |
|
| 3412 | + } |
|
| 3237 | 3413 | return false; |
| 3238 | 3414 | } |
| 3239 | 3415 | |
@@ -3245,9 +3421,9 @@ discard block |
||
| 3245 | 3421 | { |
| 3246 | 3422 | $cacheAPI = $testAPI; |
| 3247 | 3423 | return $cacheAPI; |
| 3424 | + } else { |
|
| 3425 | + return $testAPI; |
|
| 3248 | 3426 | } |
| 3249 | - else |
|
| 3250 | - return $testAPI; |
|
| 3251 | 3427 | } |
| 3252 | 3428 | } |
| 3253 | 3429 | |
@@ -3267,8 +3443,9 @@ discard block |
||
| 3267 | 3443 | |
| 3268 | 3444 | // @todo Why are we doing this if caching is disabled? |
| 3269 | 3445 | |
| 3270 | - if (function_exists('call_integration_hook')) |
|
| 3271 | - call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level)); |
|
| 3446 | + if (function_exists('call_integration_hook')) { |
|
| 3447 | + call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level)); |
|
| 3448 | + } |
|
| 3272 | 3449 | |
| 3273 | 3450 | /* Refresh the cache if either: |
| 3274 | 3451 | 1. Caching is disabled. |
@@ -3282,16 +3459,19 @@ discard block |
||
| 3282 | 3459 | require_once($sourcedir . '/' . $file); |
| 3283 | 3460 | $cache_block = call_user_func_array($function, $params); |
| 3284 | 3461 | |
| 3285 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) |
|
| 3286 | - cache_put_data($key, $cache_block, $cache_block['expires'] - time()); |
|
| 3462 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) { |
|
| 3463 | + cache_put_data($key, $cache_block, $cache_block['expires'] - time()); |
|
| 3464 | + } |
|
| 3287 | 3465 | } |
| 3288 | 3466 | |
| 3289 | 3467 | // Some cached data may need a freshening up after retrieval. |
| 3290 | - if (!empty($cache_block['post_retri_eval'])) |
|
| 3291 | - eval($cache_block['post_retri_eval']); |
|
| 3468 | + if (!empty($cache_block['post_retri_eval'])) { |
|
| 3469 | + eval($cache_block['post_retri_eval']); |
|
| 3470 | + } |
|
| 3292 | 3471 | |
| 3293 | - if (function_exists('call_integration_hook')) |
|
| 3294 | - call_integration_hook('post_cache_quick_get', array(&$cache_block)); |
|
| 3472 | + if (function_exists('call_integration_hook')) { |
|
| 3473 | + call_integration_hook('post_cache_quick_get', array(&$cache_block)); |
|
| 3474 | + } |
|
| 3295 | 3475 | |
| 3296 | 3476 | return $cache_block['data']; |
| 3297 | 3477 | } |
@@ -3318,8 +3498,9 @@ discard block |
||
| 3318 | 3498 | global $cache_enable, $cacheAPI; |
| 3319 | 3499 | global $cache_hits, $cache_count, $db_show_debug; |
| 3320 | 3500 | |
| 3321 | - if (empty($cache_enable) || empty($cacheAPI)) |
|
| 3322 | - return; |
|
| 3501 | + if (empty($cache_enable) || empty($cacheAPI)) { |
|
| 3502 | + return; |
|
| 3503 | + } |
|
| 3323 | 3504 | |
| 3324 | 3505 | $cache_count = isset($cache_count) ? $cache_count + 1 : 1; |
| 3325 | 3506 | if (isset($db_show_debug) && $db_show_debug === true) |
@@ -3332,12 +3513,14 @@ discard block |
||
| 3332 | 3513 | $value = $value === null ? null : json_encode($value); |
| 3333 | 3514 | $cacheAPI->putData($key, $value, $ttl); |
| 3334 | 3515 | |
| 3335 | - if (function_exists('call_integration_hook')) |
|
| 3336 | - call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl)); |
|
| 3516 | + if (function_exists('call_integration_hook')) { |
|
| 3517 | + call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl)); |
|
| 3518 | + } |
|
| 3337 | 3519 | |
| 3338 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
| 3339 | - $cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 3340 | -} |
|
| 3520 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
| 3521 | + $cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 3522 | + } |
|
| 3523 | + } |
|
| 3341 | 3524 | |
| 3342 | 3525 | /** |
| 3343 | 3526 | * Gets the value from the cache specified by key, so long as it is not older than ttl seconds. |
@@ -3353,8 +3536,9 @@ discard block |
||
| 3353 | 3536 | global $cache_enable, $cacheAPI; |
| 3354 | 3537 | global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug; |
| 3355 | 3538 | |
| 3356 | - if (empty($cache_enable) || empty($cacheAPI)) |
|
| 3357 | - return; |
|
| 3539 | + if (empty($cache_enable) || empty($cacheAPI)) { |
|
| 3540 | + return; |
|
| 3541 | + } |
|
| 3358 | 3542 | |
| 3359 | 3543 | $cache_count = isset($cache_count) ? $cache_count + 1 : 1; |
| 3360 | 3544 | if (isset($db_show_debug) && $db_show_debug === true) |
@@ -3374,16 +3558,18 @@ discard block |
||
| 3374 | 3558 | |
| 3375 | 3559 | if (empty($value)) |
| 3376 | 3560 | { |
| 3377 | - if (!is_array($cache_misses)) |
|
| 3378 | - $cache_misses = array(); |
|
| 3561 | + if (!is_array($cache_misses)) { |
|
| 3562 | + $cache_misses = array(); |
|
| 3563 | + } |
|
| 3379 | 3564 | |
| 3380 | 3565 | $cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1; |
| 3381 | 3566 | $cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get'); |
| 3382 | 3567 | } |
| 3383 | 3568 | } |
| 3384 | 3569 | |
| 3385 | - if (function_exists('call_integration_hook') && isset($value)) |
|
| 3386 | - call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value)); |
|
| 3570 | + if (function_exists('call_integration_hook') && isset($value)) { |
|
| 3571 | + call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value)); |
|
| 3572 | + } |
|
| 3387 | 3573 | |
| 3388 | 3574 | return empty($value) ? null : smf_json_decode($value, true); |
| 3389 | 3575 | } |
@@ -3405,8 +3591,9 @@ discard block |
||
| 3405 | 3591 | global $cacheAPI; |
| 3406 | 3592 | |
| 3407 | 3593 | // If we can't get to the API, can't do this. |
| 3408 | - if (empty($cacheAPI)) |
|
| 3409 | - return; |
|
| 3594 | + if (empty($cacheAPI)) { |
|
| 3595 | + return; |
|
| 3596 | + } |
|
| 3410 | 3597 | |
| 3411 | 3598 | // Ask the API to do the heavy lifting. cleanCache also calls invalidateCache to be sure. |
| 3412 | 3599 | $cacheAPI->cleanCache($type); |
@@ -3431,8 +3618,9 @@ discard block |
||
| 3431 | 3618 | global $modSettings, $boardurl, $smcFunc, $image_proxy_enabled, $image_proxy_secret; |
| 3432 | 3619 | |
| 3433 | 3620 | // Come on! |
| 3434 | - if (empty($data)) |
|
| 3435 | - return array(); |
|
| 3621 | + if (empty($data)) { |
|
| 3622 | + return array(); |
|
| 3623 | + } |
|
| 3436 | 3624 | |
| 3437 | 3625 | // Set a nice default var. |
| 3438 | 3626 | $image = ''; |
@@ -3440,11 +3628,11 @@ discard block |
||
| 3440 | 3628 | // Gravatar has been set as mandatory! |
| 3441 | 3629 | if (!empty($modSettings['gravatarOverride'])) |
| 3442 | 3630 | { |
| 3443 | - if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) |
|
| 3444 | - $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
| 3445 | - |
|
| 3446 | - else if (!empty($data['email'])) |
|
| 3447 | - $image = get_gravatar_url($data['email']); |
|
| 3631 | + if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) { |
|
| 3632 | + $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
| 3633 | + } else if (!empty($data['email'])) { |
|
| 3634 | + $image = get_gravatar_url($data['email']); |
|
| 3635 | + } |
|
| 3448 | 3636 | } |
| 3449 | 3637 | |
| 3450 | 3638 | // Look if the user has a gravatar field or has set an external url as avatar. |
@@ -3456,54 +3644,60 @@ discard block |
||
| 3456 | 3644 | // Gravatar. |
| 3457 | 3645 | if (stristr($data['avatar'], 'gravatar://')) |
| 3458 | 3646 | { |
| 3459 | - if ($data['avatar'] == 'gravatar://') |
|
| 3460 | - $image = get_gravatar_url($data['email']); |
|
| 3461 | - |
|
| 3462 | - elseif (!empty($modSettings['gravatarAllowExtraEmail'])) |
|
| 3463 | - $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
| 3647 | + if ($data['avatar'] == 'gravatar://') { |
|
| 3648 | + $image = get_gravatar_url($data['email']); |
|
| 3649 | + } elseif (!empty($modSettings['gravatarAllowExtraEmail'])) { |
|
| 3650 | + $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
| 3651 | + } |
|
| 3464 | 3652 | } |
| 3465 | 3653 | |
| 3466 | 3654 | // External url. |
| 3467 | 3655 | else |
| 3468 | 3656 | { |
| 3469 | 3657 | // Using ssl? |
| 3470 | - if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false) |
|
| 3471 | - $image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret); |
|
| 3658 | + if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false) { |
|
| 3659 | + $image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret); |
|
| 3660 | + } |
|
| 3472 | 3661 | |
| 3473 | 3662 | // Just a plain external url. |
| 3474 | - else |
|
| 3475 | - $image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar']; |
|
| 3663 | + else { |
|
| 3664 | + $image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar']; |
|
| 3665 | + } |
|
| 3476 | 3666 | } |
| 3477 | 3667 | } |
| 3478 | 3668 | |
| 3479 | 3669 | // Perhaps this user has an attachment as avatar... |
| 3480 | - else if (!empty($data['filename'])) |
|
| 3481 | - $image = $modSettings['custom_avatar_url'] . '/' . $data['filename']; |
|
| 3670 | + else if (!empty($data['filename'])) { |
|
| 3671 | + $image = $modSettings['custom_avatar_url'] . '/' . $data['filename']; |
|
| 3672 | + } |
|
| 3482 | 3673 | |
| 3483 | 3674 | // Right... no avatar... use our default image. |
| 3484 | - else |
|
| 3485 | - $image = $modSettings['avatar_url'] . '/default.png'; |
|
| 3675 | + else { |
|
| 3676 | + $image = $modSettings['avatar_url'] . '/default.png'; |
|
| 3677 | + } |
|
| 3486 | 3678 | } |
| 3487 | 3679 | |
| 3488 | 3680 | call_integration_hook('integrate_set_avatar_data', array(&$image, &$data)); |
| 3489 | 3681 | |
| 3490 | 3682 | // 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. |
| 3491 | - if (!empty($image)) |
|
| 3492 | - return array( |
|
| 3683 | + if (!empty($image)) { |
|
| 3684 | + return array( |
|
| 3493 | 3685 | 'name' => !empty($data['avatar']) ? $data['avatar'] : '', |
| 3494 | 3686 | 'image' => '<img class="avatar" src="' . $image . '" />', |
| 3495 | 3687 | 'href' => $image, |
| 3496 | 3688 | 'url' => $image, |
| 3497 | 3689 | ); |
| 3690 | + } |
|
| 3498 | 3691 | |
| 3499 | 3692 | // Fallback to make life easier for everyone... |
| 3500 | - else |
|
| 3501 | - return array( |
|
| 3693 | + else { |
|
| 3694 | + return array( |
|
| 3502 | 3695 | 'name' => '', |
| 3503 | 3696 | 'image' => '', |
| 3504 | 3697 | 'href' => '', |
| 3505 | 3698 | 'url' => '', |
| 3506 | 3699 | ); |
| 3507 | -} |
|
| 3700 | + } |
|
| 3701 | + } |
|
| 3508 | 3702 | |
| 3509 | 3703 | ?> |
| 3510 | 3704 | \ 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 | * 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) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) |
|
| 87 | - fatal_lang_error('login_ssl_required'); |
|
| 89 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) { |
|
| 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) = smf_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) = smf_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'])); |
@@ -125,16 +130,18 @@ discard block |
||
| 125 | 130 | $tfadata = smf_json_decode($_COOKIE[$cookiename . '_tfa'], true); |
| 126 | 131 | |
| 127 | 132 | // If that didn't work, try unserialize instead... |
| 128 | - if (is_null($tfadata)) |
|
| 129 | - $tfadata = safe_unserialize($_COOKIE[$cookiename . '_tfa']); |
|
| 133 | + if (is_null($tfadata)) { |
|
| 134 | + $tfadata = safe_unserialize($_COOKIE[$cookiename . '_tfa']); |
|
| 135 | + } |
|
| 130 | 136 | |
| 131 | 137 | list ($tfamember, $tfasecret, $exp, $state, $preserve) = $tfadata; |
| 132 | 138 | |
| 133 | 139 | // If we're preserving the cookie, reset it with updated salt |
| 134 | - if ($preserve && time() < $exp) |
|
| 135 | - setTFACookie(3153600, $user_info['password_salt'], hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']), true); |
|
| 136 | - else |
|
| 137 | - setTFACookie(-3600, 0, ''); |
|
| 140 | + if ($preserve && time() < $exp) { |
|
| 141 | + setTFACookie(3153600, $user_info['password_salt'], hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']), true); |
|
| 142 | + } else { |
|
| 143 | + setTFACookie(-3600, 0, ''); |
|
| 144 | + } |
|
| 138 | 145 | } |
| 139 | 146 | |
| 140 | 147 | setLoginCookie($timeout - time(), $user_info['id'], hash_salt($user_settings['passwd'], $user_settings['password_salt'])); |
@@ -145,20 +152,20 @@ discard block |
||
| 145 | 152 | elseif (isset($_GET['sa']) && $_GET['sa'] == 'check') |
| 146 | 153 | { |
| 147 | 154 | // Strike! You're outta there! |
| 148 | - if ($_GET['member'] != $user_info['id']) |
|
| 149 | - fatal_lang_error('login_cookie_error', false); |
|
| 155 | + if ($_GET['member'] != $user_info['id']) { |
|
| 156 | + fatal_lang_error('login_cookie_error', false); |
|
| 157 | + } |
|
| 150 | 158 | |
| 151 | 159 | $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'])))); |
| 152 | 160 | |
| 153 | 161 | // Some whitelisting for login_url... |
| 154 | - if (empty($_SESSION['login_url'])) |
|
| 155 | - redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa'); |
|
| 156 | - elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false)) |
|
| 162 | + if (empty($_SESSION['login_url'])) { |
|
| 163 | + redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa'); |
|
| 164 | + } elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false)) |
|
| 157 | 165 | { |
| 158 | 166 | unset ($_SESSION['login_url']); |
| 159 | 167 | redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa'); |
| 160 | - } |
|
| 161 | - else |
|
| 168 | + } else |
|
| 162 | 169 | { |
| 163 | 170 | // Best not to clutter the session data too much... |
| 164 | 171 | $temp = $_SESSION['login_url']; |
@@ -169,8 +176,9 @@ discard block |
||
| 169 | 176 | } |
| 170 | 177 | |
| 171 | 178 | // Beyond this point you are assumed to be a guest trying to login. |
| 172 | - if (!$user_info['is_guest']) |
|
| 173 | - redirectexit(); |
|
| 179 | + if (!$user_info['is_guest']) { |
|
| 180 | + redirectexit(); |
|
| 181 | + } |
|
| 174 | 182 | |
| 175 | 183 | // Are you guessing with a script? |
| 176 | 184 | checkSession(); |
@@ -178,18 +186,21 @@ discard block |
||
| 178 | 186 | spamProtection('login'); |
| 179 | 187 | |
| 180 | 188 | // Set the login_url if it's not already set (but careful not to send us to an attachment). |
| 181 | - if ((empty($_SESSION['login_url']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) || (isset($_GET['quicklogin']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'login') === false)) |
|
| 182 | - $_SESSION['login_url'] = $_SESSION['old_url']; |
|
| 189 | + 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)) { |
|
| 190 | + $_SESSION['login_url'] = $_SESSION['old_url']; |
|
| 191 | + } |
|
| 183 | 192 | |
| 184 | 193 | // Been guessing a lot, haven't we? |
| 185 | - if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3) |
|
| 186 | - fatal_lang_error('login_threshold_fail', 'critical'); |
|
| 194 | + if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3) { |
|
| 195 | + fatal_lang_error('login_threshold_fail', 'critical'); |
|
| 196 | + } |
|
| 187 | 197 | |
| 188 | 198 | // Set up the cookie length. (if it's invalid, just fall through and use the default.) |
| 189 | - if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1)) |
|
| 190 | - $modSettings['cookieTime'] = 3153600; |
|
| 191 | - elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 525600)) |
|
| 192 | - $modSettings['cookieTime'] = (int) $_POST['cookielength']; |
|
| 199 | + if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1)) { |
|
| 200 | + $modSettings['cookieTime'] = 3153600; |
|
| 201 | + } elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 525600)) { |
|
| 202 | + $modSettings['cookieTime'] = (int) $_POST['cookielength']; |
|
| 203 | + } |
|
| 193 | 204 | |
| 194 | 205 | loadLanguage('Login'); |
| 195 | 206 | // Load the template stuff. |
@@ -309,8 +320,9 @@ discard block |
||
| 309 | 320 | $other_passwords[] = crypt(md5($_POST['passwrd']), md5($_POST['passwrd'])); |
| 310 | 321 | |
| 311 | 322 | // Snitz style - SHA-256. Technically, this is a downgrade, but most PHP configurations don't support sha256 anyway. |
| 312 | - if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256')) |
|
| 313 | - $other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd'])); |
|
| 323 | + if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256')) { |
|
| 324 | + $other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd'])); |
|
| 325 | + } |
|
| 314 | 326 | |
| 315 | 327 | // phpBB3 users new hashing. We now support it as well ;). |
| 316 | 328 | $other_passwords[] = phpBB3_password_check($_POST['passwrd'], $user_settings['passwd']); |
@@ -330,27 +342,29 @@ discard block |
||
| 330 | 342 | // Some common md5 ones. |
| 331 | 343 | $other_passwords[] = md5($user_settings['password_salt'] . $_POST['passwrd']); |
| 332 | 344 | $other_passwords[] = md5($_POST['passwrd'] . $user_settings['password_salt']); |
| 333 | - } |
|
| 334 | - elseif (strlen($user_settings['passwd']) == 40) |
|
| 345 | + } elseif (strlen($user_settings['passwd']) == 40) |
|
| 335 | 346 | { |
| 336 | 347 | // Maybe they are using a hash from before the password fix. |
| 337 | 348 | // This is also valid for SMF 1.1 to 2.0 style of hashing, changed to bcrypt in SMF 2.1 |
| 338 | 349 | $other_passwords[] = sha1(strtolower($user_settings['member_name']) . un_htmlspecialchars($_POST['passwrd'])); |
| 339 | 350 | |
| 340 | 351 | // BurningBoard3 style of hashing. |
| 341 | - if (!empty($modSettings['enable_password_conversion'])) |
|
| 342 | - $other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd']))); |
|
| 352 | + if (!empty($modSettings['enable_password_conversion'])) { |
|
| 353 | + $other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd']))); |
|
| 354 | + } |
|
| 343 | 355 | |
| 344 | 356 | // Perhaps we converted to UTF-8 and have a valid password being hashed differently. |
| 345 | 357 | if ($context['character_set'] == 'UTF-8' && !empty($modSettings['previousCharacterSet']) && $modSettings['previousCharacterSet'] != 'utf8') |
| 346 | 358 | { |
| 347 | 359 | // Try iconv first, for no particular reason. |
| 348 | - if (function_exists('iconv')) |
|
| 349 | - $other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd']))); |
|
| 360 | + if (function_exists('iconv')) { |
|
| 361 | + $other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd']))); |
|
| 362 | + } |
|
| 350 | 363 | |
| 351 | 364 | // Say it aint so, iconv failed! |
| 352 | - if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding')) |
|
| 353 | - $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']))); |
|
| 365 | + if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding')) { |
|
| 366 | + $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']))); |
|
| 367 | + } |
|
| 354 | 368 | } |
| 355 | 369 | } |
| 356 | 370 | |
@@ -380,8 +394,9 @@ discard block |
||
| 380 | 394 | $_SESSION['failed_login'] = isset($_SESSION['failed_login']) ? ($_SESSION['failed_login'] + 1) : 1; |
| 381 | 395 | |
| 382 | 396 | // Hmm... don't remember it, do you? Here, try the password reminder ;). |
| 383 | - if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold']) |
|
| 384 | - redirectexit('action=reminder'); |
|
| 397 | + if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold']) { |
|
| 398 | + redirectexit('action=reminder'); |
|
| 399 | + } |
|
| 385 | 400 | // We'll give you another chance... |
| 386 | 401 | else |
| 387 | 402 | { |
@@ -392,8 +407,7 @@ discard block |
||
| 392 | 407 | return; |
| 393 | 408 | } |
| 394 | 409 | } |
| 395 | - } |
|
| 396 | - elseif (!empty($user_settings['passwd_flood'])) |
|
| 410 | + } elseif (!empty($user_settings['passwd_flood'])) |
|
| 397 | 411 | { |
| 398 | 412 | // Let's be sure they weren't a little hacker. |
| 399 | 413 | validatePasswordFlood($user_settings['id_member'], $user_settings['passwd_flood'], true); |
@@ -410,8 +424,9 @@ discard block |
||
| 410 | 424 | } |
| 411 | 425 | |
| 412 | 426 | // Check their activation status. |
| 413 | - if (!checkActivation()) |
|
| 414 | - return; |
|
| 427 | + if (!checkActivation()) { |
|
| 428 | + return; |
|
| 429 | + } |
|
| 415 | 430 | |
| 416 | 431 | DoLogin(); |
| 417 | 432 | } |
@@ -423,8 +438,9 @@ discard block |
||
| 423 | 438 | { |
| 424 | 439 | global $sourcedir, $txt, $context, $user_info, $modSettings, $scripturl; |
| 425 | 440 | |
| 426 | - if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode'])) |
|
| 427 | - fatal_lang_error('no_access', false); |
|
| 441 | + if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode'])) { |
|
| 442 | + fatal_lang_error('no_access', false); |
|
| 443 | + } |
|
| 428 | 444 | |
| 429 | 445 | loadLanguage('Profile'); |
| 430 | 446 | require_once($sourcedir . '/Class-TOTP.php'); |
@@ -432,8 +448,9 @@ discard block |
||
| 432 | 448 | $member = $context['tfa_member']; |
| 433 | 449 | |
| 434 | 450 | // Prevent replay attacks by limiting at least 2 minutes before they can log in again via 2FA |
| 435 | - if (time() - $member['last_login'] < 120) |
|
| 436 | - fatal_lang_error('tfa_wait', false); |
|
| 451 | + if (time() - $member['last_login'] < 120) { |
|
| 452 | + fatal_lang_error('tfa_wait', false); |
|
| 453 | + } |
|
| 437 | 454 | |
| 438 | 455 | $totp = new \TOTP\Auth($member['tfa_secret']); |
| 439 | 456 | $totp->setRange(1); |
@@ -447,8 +464,9 @@ discard block |
||
| 447 | 464 | if (!empty($_POST['tfa_code']) && empty($_POST['tfa_backup'])) |
| 448 | 465 | { |
| 449 | 466 | // Check to ensure we're forcing SSL for authentication |
| 450 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) |
|
| 451 | - fatal_lang_error('login_ssl_required'); |
|
| 467 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) { |
|
| 468 | + fatal_lang_error('login_ssl_required'); |
|
| 469 | + } |
|
| 452 | 470 | |
| 453 | 471 | $code = $_POST['tfa_code']; |
| 454 | 472 | |
@@ -458,20 +476,19 @@ discard block |
||
| 458 | 476 | |
| 459 | 477 | setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt']), !empty($_POST['tfa_preserve'])); |
| 460 | 478 | redirectexit(); |
| 461 | - } |
|
| 462 | - else |
|
| 479 | + } else |
|
| 463 | 480 | { |
| 464 | 481 | validatePasswordFlood($member['id_member'], $member['passwd_flood'], false, true); |
| 465 | 482 | |
| 466 | 483 | $context['tfa_error'] = true; |
| 467 | 484 | $context['tfa_value'] = $_POST['tfa_code']; |
| 468 | 485 | } |
| 469 | - } |
|
| 470 | - elseif (!empty($_POST['tfa_backup'])) |
|
| 486 | + } elseif (!empty($_POST['tfa_backup'])) |
|
| 471 | 487 | { |
| 472 | 488 | // Check to ensure we're forcing SSL for authentication |
| 473 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) |
|
| 474 | - fatal_lang_error('login_ssl_required'); |
|
| 489 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) { |
|
| 490 | + fatal_lang_error('login_ssl_required'); |
|
| 491 | + } |
|
| 475 | 492 | |
| 476 | 493 | $backup = $_POST['tfa_backup']; |
| 477 | 494 | |
@@ -485,8 +502,7 @@ discard block |
||
| 485 | 502 | )); |
| 486 | 503 | setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt'])); |
| 487 | 504 | redirectexit('action=profile;area=tfasetup;backup'); |
| 488 | - } |
|
| 489 | - else |
|
| 505 | + } else |
|
| 490 | 506 | { |
| 491 | 507 | validatePasswordFlood($member['id_member'], $member['passwd_flood'], false, true); |
| 492 | 508 | |
@@ -509,8 +525,9 @@ discard block |
||
| 509 | 525 | { |
| 510 | 526 | global $context, $txt, $scripturl, $user_settings, $modSettings; |
| 511 | 527 | |
| 512 | - if (!isset($context['login_errors'])) |
|
| 513 | - $context['login_errors'] = array(); |
|
| 528 | + if (!isset($context['login_errors'])) { |
|
| 529 | + $context['login_errors'] = array(); |
|
| 530 | + } |
|
| 514 | 531 | |
| 515 | 532 | // What is the true activation status of this account? |
| 516 | 533 | $activation_status = $user_settings['is_activated'] > 10 ? $user_settings['is_activated'] - 10 : $user_settings['is_activated']; |
@@ -522,8 +539,9 @@ discard block |
||
| 522 | 539 | return false; |
| 523 | 540 | } |
| 524 | 541 | // Awaiting approval still? |
| 525 | - elseif ($activation_status == 3) |
|
| 526 | - fatal_lang_error('still_awaiting_approval', 'user'); |
|
| 542 | + elseif ($activation_status == 3) { |
|
| 543 | + fatal_lang_error('still_awaiting_approval', 'user'); |
|
| 544 | + } |
|
| 527 | 545 | // Awaiting deletion, changed their mind? |
| 528 | 546 | elseif ($activation_status == 4) |
| 529 | 547 | { |
@@ -531,8 +549,7 @@ discard block |
||
| 531 | 549 | { |
| 532 | 550 | updateMemberData($user_settings['id_member'], array('is_activated' => 1)); |
| 533 | 551 | updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 0 ? $modSettings['unapprovedMembers'] - 1 : 0))); |
| 534 | - } |
|
| 535 | - else |
|
| 552 | + } else |
|
| 536 | 553 | { |
| 537 | 554 | $context['disable_login_hashing'] = true; |
| 538 | 555 | $context['login_errors'][] = $txt['awaiting_delete_account']; |
@@ -572,8 +589,9 @@ discard block |
||
| 572 | 589 | setLoginCookie(60 * $modSettings['cookieTime'], $user_settings['id_member'], hash_salt($user_settings['passwd'], $user_settings['password_salt'])); |
| 573 | 590 | |
| 574 | 591 | // Reset the login threshold. |
| 575 | - if (isset($_SESSION['failed_login'])) |
|
| 576 | - unset($_SESSION['failed_login']); |
|
| 592 | + if (isset($_SESSION['failed_login'])) { |
|
| 593 | + unset($_SESSION['failed_login']); |
|
| 594 | + } |
|
| 577 | 595 | |
| 578 | 596 | $user_info['is_guest'] = false; |
| 579 | 597 | $user_settings['additional_groups'] = explode(',', $user_settings['additional_groups']); |
@@ -595,16 +613,18 @@ discard block |
||
| 595 | 613 | 'id_member' => $user_info['id'], |
| 596 | 614 | ) |
| 597 | 615 | ); |
| 598 | - if ($smcFunc['db_num_rows']($request) == 1) |
|
| 599 | - $_SESSION['first_login'] = true; |
|
| 600 | - else |
|
| 601 | - unset($_SESSION['first_login']); |
|
| 616 | + if ($smcFunc['db_num_rows']($request) == 1) { |
|
| 617 | + $_SESSION['first_login'] = true; |
|
| 618 | + } else { |
|
| 619 | + unset($_SESSION['first_login']); |
|
| 620 | + } |
|
| 602 | 621 | $smcFunc['db_free_result']($request); |
| 603 | 622 | |
| 604 | 623 | // You've logged in, haven't you? |
| 605 | 624 | $update = array('member_ip' => $user_info['ip'], 'member_ip2' => $_SERVER['BAN_CHECK_IP']); |
| 606 | - if (empty($user_settings['tfa_secret'])) |
|
| 607 | - $update['last_login'] = time(); |
|
| 625 | + if (empty($user_settings['tfa_secret'])) { |
|
| 626 | + $update['last_login'] = time(); |
|
| 627 | + } |
|
| 608 | 628 | updateMemberData($user_info['id'], $update); |
| 609 | 629 | |
| 610 | 630 | // Get rid of the online entry for that old guest.... |
@@ -618,8 +638,8 @@ discard block |
||
| 618 | 638 | $_SESSION['log_time'] = 0; |
| 619 | 639 | |
| 620 | 640 | // Log this entry, only if we have it enabled. |
| 621 | - if (!empty($modSettings['loginHistoryDays'])) |
|
| 622 | - $smcFunc['db_insert']('insert', |
|
| 641 | + if (!empty($modSettings['loginHistoryDays'])) { |
|
| 642 | + $smcFunc['db_insert']('insert', |
|
| 623 | 643 | '{db_prefix}member_logins', |
| 624 | 644 | array( |
| 625 | 645 | 'id_member' => 'int', 'time' => 'int', 'ip' => 'inet', 'ip2' => 'inet', |
@@ -631,13 +651,15 @@ discard block |
||
| 631 | 651 | 'id_member', 'time' |
| 632 | 652 | ) |
| 633 | 653 | ); |
| 654 | + } |
|
| 634 | 655 | |
| 635 | 656 | // Just log you back out if it's in maintenance mode and you AREN'T an admin. |
| 636 | - if (empty($maintenance) || allowedTo('admin_forum')) |
|
| 637 | - redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']); |
|
| 638 | - else |
|
| 639 | - redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']); |
|
| 640 | -} |
|
| 657 | + if (empty($maintenance) || allowedTo('admin_forum')) { |
|
| 658 | + redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']); |
|
| 659 | + } else { |
|
| 660 | + redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']); |
|
| 661 | + } |
|
| 662 | + } |
|
| 641 | 663 | |
| 642 | 664 | /** |
| 643 | 665 | * Logs the current user out of their account. |
@@ -653,13 +675,15 @@ discard block |
||
| 653 | 675 | global $sourcedir, $user_info, $user_settings, $context, $smcFunc, $cookiename, $modSettings; |
| 654 | 676 | |
| 655 | 677 | // Make sure they aren't being auto-logged out. |
| 656 | - if (!$internal) |
|
| 657 | - checkSession('get'); |
|
| 678 | + if (!$internal) { |
|
| 679 | + checkSession('get'); |
|
| 680 | + } |
|
| 658 | 681 | |
| 659 | 682 | require_once($sourcedir . '/Subs-Auth.php'); |
| 660 | 683 | |
| 661 | - if (isset($_SESSION['pack_ftp'])) |
|
| 662 | - $_SESSION['pack_ftp'] = null; |
|
| 684 | + if (isset($_SESSION['pack_ftp'])) { |
|
| 685 | + $_SESSION['pack_ftp'] = null; |
|
| 686 | + } |
|
| 663 | 687 | |
| 664 | 688 | // It won't be first login anymore. |
| 665 | 689 | unset($_SESSION['first_login']); |
@@ -687,8 +711,9 @@ discard block |
||
| 687 | 711 | |
| 688 | 712 | // And some other housekeeping while we're at it. |
| 689 | 713 | $salt = substr(md5(mt_rand()), 0, 4); |
| 690 | - if (!empty($user_info['id'])) |
|
| 691 | - updateMemberData($user_info['id'], array('password_salt' => $salt)); |
|
| 714 | + if (!empty($user_info['id'])) { |
|
| 715 | + updateMemberData($user_info['id'], array('password_salt' => $salt)); |
|
| 716 | + } |
|
| 692 | 717 | |
| 693 | 718 | if (!empty($modSettings['tfa_mode']) && !empty($user_info['id']) && !empty($_COOKIE[$cookiename . '_tfa'])) |
| 694 | 719 | { |
@@ -697,10 +722,11 @@ discard block |
||
| 697 | 722 | list ($tfamember, $tfasecret, $exp, $state, $preserve) = $tfadata; |
| 698 | 723 | |
| 699 | 724 | // If we're preserving the cookie, reset it with updated salt |
| 700 | - if (isset($tfamember, $tfasecret, $exp, $state, $preserve) && $preserve && time() < $exp) |
|
| 701 | - setTFACookie(3153600, $user_info['id'], hash_salt($user_settings['tfa_backup'], $salt), true); |
|
| 702 | - else |
|
| 703 | - setTFACookie(-3600, 0, ''); |
|
| 725 | + if (isset($tfamember, $tfasecret, $exp, $state, $preserve) && $preserve && time() < $exp) { |
|
| 726 | + setTFACookie(3153600, $user_info['id'], hash_salt($user_settings['tfa_backup'], $salt), true); |
|
| 727 | + } else { |
|
| 728 | + setTFACookie(-3600, 0, ''); |
|
| 729 | + } |
|
| 704 | 730 | } |
| 705 | 731 | |
| 706 | 732 | session_destroy(); |
@@ -708,14 +734,13 @@ discard block |
||
| 708 | 734 | // Off to the merry board index we go! |
| 709 | 735 | if ($redirect) |
| 710 | 736 | { |
| 711 | - if (empty($_SESSION['logout_url'])) |
|
| 712 | - redirectexit('', $context['server']['needs_login_fix']); |
|
| 713 | - elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false)) |
|
| 737 | + if (empty($_SESSION['logout_url'])) { |
|
| 738 | + redirectexit('', $context['server']['needs_login_fix']); |
|
| 739 | + } elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false)) |
|
| 714 | 740 | { |
| 715 | 741 | unset ($_SESSION['logout_url']); |
| 716 | 742 | redirectexit(); |
| 717 | - } |
|
| 718 | - else |
|
| 743 | + } else |
|
| 719 | 744 | { |
| 720 | 745 | $temp = $_SESSION['logout_url']; |
| 721 | 746 | unset($_SESSION['logout_url']); |
@@ -748,8 +773,9 @@ discard block |
||
| 748 | 773 | function phpBB3_password_check($passwd, $passwd_hash) |
| 749 | 774 | { |
| 750 | 775 | // Too long or too short? |
| 751 | - if (strlen($passwd_hash) != 34) |
|
| 752 | - return; |
|
| 776 | + if (strlen($passwd_hash) != 34) { |
|
| 777 | + return; |
|
| 778 | + } |
|
| 753 | 779 | |
| 754 | 780 | // Range of characters allowed. |
| 755 | 781 | $range = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; |
@@ -760,8 +786,9 @@ discard block |
||
| 760 | 786 | $salt = substr($passwd_hash, 4, 8); |
| 761 | 787 | |
| 762 | 788 | $hash = md5($salt . $passwd, true); |
| 763 | - for (; $count != 0; --$count) |
|
| 764 | - $hash = md5($hash . $passwd, true); |
|
| 789 | + for (; $count != 0; --$count) { |
|
| 790 | + $hash = md5($hash . $passwd, true); |
|
| 791 | + } |
|
| 765 | 792 | |
| 766 | 793 | $output = substr($passwd_hash, 0, 12); |
| 767 | 794 | $i = 0; |
@@ -770,21 +797,25 @@ discard block |
||
| 770 | 797 | $value = ord($hash[$i++]); |
| 771 | 798 | $output .= $range[$value & 0x3f]; |
| 772 | 799 | |
| 773 | - if ($i < 16) |
|
| 774 | - $value |= ord($hash[$i]) << 8; |
|
| 800 | + if ($i < 16) { |
|
| 801 | + $value |= ord($hash[$i]) << 8; |
|
| 802 | + } |
|
| 775 | 803 | |
| 776 | 804 | $output .= $range[($value >> 6) & 0x3f]; |
| 777 | 805 | |
| 778 | - if ($i++ >= 16) |
|
| 779 | - break; |
|
| 806 | + if ($i++ >= 16) { |
|
| 807 | + break; |
|
| 808 | + } |
|
| 780 | 809 | |
| 781 | - if ($i < 16) |
|
| 782 | - $value |= ord($hash[$i]) << 16; |
|
| 810 | + if ($i < 16) { |
|
| 811 | + $value |= ord($hash[$i]) << 16; |
|
| 812 | + } |
|
| 783 | 813 | |
| 784 | 814 | $output .= $range[($value >> 12) & 0x3f]; |
| 785 | 815 | |
| 786 | - if ($i++ >= 16) |
|
| 787 | - break; |
|
| 816 | + if ($i++ >= 16) { |
|
| 817 | + break; |
|
| 818 | + } |
|
| 788 | 819 | |
| 789 | 820 | $output .= $range[($value >> 18) & 0x3f]; |
| 790 | 821 | } |
@@ -815,8 +846,9 @@ discard block |
||
| 815 | 846 | require_once($sourcedir . '/Subs-Auth.php'); |
| 816 | 847 | setLoginCookie(-3600, 0); |
| 817 | 848 | |
| 818 | - if (isset($_SESSION['login_' . $cookiename])) |
|
| 819 | - unset($_SESSION['login_' . $cookiename]); |
|
| 849 | + if (isset($_SESSION['login_' . $cookiename])) { |
|
| 850 | + unset($_SESSION['login_' . $cookiename]); |
|
| 851 | + } |
|
| 820 | 852 | } |
| 821 | 853 | |
| 822 | 854 | // We need a member! |
@@ -830,8 +862,9 @@ discard block |
||
| 830 | 862 | } |
| 831 | 863 | |
| 832 | 864 | // Right, have we got a flood value? |
| 833 | - if ($password_flood_value !== false) |
|
| 834 | - @list ($time_stamp, $number_tries) = explode('|', $password_flood_value); |
|
| 865 | + if ($password_flood_value !== false) { |
|
| 866 | + @list ($time_stamp, $number_tries) = explode('|', $password_flood_value); |
|
| 867 | + } |
|
| 835 | 868 | |
| 836 | 869 | // Timestamp or number of tries invalid? |
| 837 | 870 | if (empty($number_tries) || empty($time_stamp)) |
@@ -847,15 +880,17 @@ discard block |
||
| 847 | 880 | $number_tries = $time_stamp < time() - 20 ? 2 : $number_tries; |
| 848 | 881 | |
| 849 | 882 | // They are trying too fast, make them wait longer |
| 850 | - if ($time_stamp < time() - 10) |
|
| 851 | - $time_stamp = time(); |
|
| 883 | + if ($time_stamp < time() - 10) { |
|
| 884 | + $time_stamp = time(); |
|
| 885 | + } |
|
| 852 | 886 | } |
| 853 | 887 | |
| 854 | 888 | $number_tries++; |
| 855 | 889 | |
| 856 | 890 | // Broken the law? |
| 857 | - if ($number_tries > 5) |
|
| 858 | - fatal_lang_error('login_threshold_brute_fail', 'critical'); |
|
| 891 | + if ($number_tries > 5) { |
|
| 892 | + fatal_lang_error('login_threshold_brute_fail', 'critical'); |
|
| 893 | + } |
|
| 859 | 894 | |
| 860 | 895 | // Otherwise set the members data. If they correct on their first attempt then we actually clear it, otherwise we set it! |
| 861 | 896 | updateMemberData($id_member, array('passwd_flood' => $was_correct && $number_tries == 1 ? '' : $time_stamp . '|' . $number_tries)); |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 4 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * Truncate the GET array to a specified length |
@@ -26,14 +27,15 @@ discard block |
||
| 26 | 27 | function truncateArray($arr, $max_length=1900) |
| 27 | 28 | { |
| 28 | 29 | $curr_length = array_sum(array_map("strlen", $arr)); |
| 29 | - if ($curr_length <= $max_length) |
|
| 30 | - return $arr; |
|
| 31 | - else |
|
| 30 | + if ($curr_length <= $max_length) { |
|
| 31 | + return $arr; |
|
| 32 | + } else |
|
| 32 | 33 | { |
| 33 | 34 | // Truncate each element's value to a reasonable length |
| 34 | 35 | $param_max = floor($max_length/count($arr)); |
| 35 | - foreach ($arr as $key => &$value) |
|
| 36 | - $value = substr($value, 0, $param_max - strlen($key) - 5); |
|
| 36 | + foreach ($arr as $key => &$value) { |
|
| 37 | + $value = substr($value, 0, $param_max - strlen($key) - 5); |
|
| 38 | + } |
|
| 37 | 39 | return $arr; |
| 38 | 40 | } |
| 39 | 41 | } |
@@ -55,8 +57,9 @@ discard block |
||
| 55 | 57 | // Don't update for every page - this isn't wholly accurate but who cares. |
| 56 | 58 | if ($topic) |
| 57 | 59 | { |
| 58 | - if (isset($_SESSION['last_topic_id']) && $_SESSION['last_topic_id'] == $topic) |
|
| 59 | - $force = false; |
|
| 60 | + if (isset($_SESSION['last_topic_id']) && $_SESSION['last_topic_id'] == $topic) { |
|
| 61 | + $force = false; |
|
| 62 | + } |
|
| 60 | 63 | $_SESSION['last_topic_id'] = $topic; |
| 61 | 64 | } |
| 62 | 65 | } |
@@ -69,22 +72,24 @@ discard block |
||
| 69 | 72 | } |
| 70 | 73 | |
| 71 | 74 | // Don't mark them as online more than every so often. |
| 72 | - if (!empty($_SESSION['log_time']) && $_SESSION['log_time'] >= (time() - 8) && !$force) |
|
| 73 | - return; |
|
| 75 | + if (!empty($_SESSION['log_time']) && $_SESSION['log_time'] >= (time() - 8) && !$force) { |
|
| 76 | + return; |
|
| 77 | + } |
|
| 74 | 78 | |
| 75 | 79 | if (!empty($modSettings['who_enabled'])) |
| 76 | 80 | { |
| 77 | 81 | $encoded_get = truncateArray($_GET) + array('USER_AGENT' => $_SERVER['HTTP_USER_AGENT']); |
| 78 | 82 | |
| 79 | 83 | // In the case of a dlattach action, session_var may not be set. |
| 80 | - if (!isset($context['session_var'])) |
|
| 81 | - $context['session_var'] = $_SESSION['session_var']; |
|
| 84 | + if (!isset($context['session_var'])) { |
|
| 85 | + $context['session_var'] = $_SESSION['session_var']; |
|
| 86 | + } |
|
| 82 | 87 | |
| 83 | 88 | unset($encoded_get['sesc'], $encoded_get[$context['session_var']]); |
| 84 | 89 | $encoded_get = json_encode($encoded_get); |
| 90 | + } else { |
|
| 91 | + $encoded_get = ''; |
|
| 85 | 92 | } |
| 86 | - else |
|
| 87 | - $encoded_get = ''; |
|
| 88 | 93 | |
| 89 | 94 | // Guests use 0, members use their session ID. |
| 90 | 95 | $session_id = $user_info['is_guest'] ? 'ip' . $user_info['ip'] : session_id(); |
@@ -124,17 +129,18 @@ discard block |
||
| 124 | 129 | ); |
| 125 | 130 | |
| 126 | 131 | // Guess it got deleted. |
| 127 | - if ($smcFunc['db_affected_rows']() == 0) |
|
| 132 | + if ($smcFunc['db_affected_rows']() == 0) { |
|
| 133 | + $_SESSION['log_time'] = 0; |
|
| 134 | + } |
|
| 135 | + } else { |
|
| 128 | 136 | $_SESSION['log_time'] = 0; |
| 129 | 137 | } |
| 130 | - else |
|
| 131 | - $_SESSION['log_time'] = 0; |
|
| 132 | 138 | |
| 133 | 139 | // Otherwise, we have to delete and insert. |
| 134 | 140 | if (empty($_SESSION['log_time'])) |
| 135 | 141 | { |
| 136 | - if ($do_delete || !empty($user_info['id'])) |
|
| 137 | - $smcFunc['db_query']('', ' |
|
| 142 | + if ($do_delete || !empty($user_info['id'])) { |
|
| 143 | + $smcFunc['db_query']('', ' |
|
| 138 | 144 | DELETE FROM {db_prefix}log_online |
| 139 | 145 | WHERE ' . ($do_delete ? 'log_time < {int:log_time}' : '') . ($do_delete && !empty($user_info['id']) ? ' OR ' : '') . (empty($user_info['id']) ? '' : 'id_member = {int:current_member}'), |
| 140 | 146 | array( |
@@ -142,6 +148,7 @@ discard block |
||
| 142 | 148 | 'log_time' => time() - $modSettings['lastActive'] * 60, |
| 143 | 149 | ) |
| 144 | 150 | ); |
| 151 | + } |
|
| 145 | 152 | |
| 146 | 153 | $smcFunc['db_insert']($do_delete ? 'ignore' : 'replace', |
| 147 | 154 | '{db_prefix}log_online', |
@@ -155,21 +162,24 @@ discard block |
||
| 155 | 162 | $_SESSION['log_time'] = time(); |
| 156 | 163 | |
| 157 | 164 | // Well, they are online now. |
| 158 | - if (empty($_SESSION['timeOnlineUpdated'])) |
|
| 159 | - $_SESSION['timeOnlineUpdated'] = time(); |
|
| 165 | + if (empty($_SESSION['timeOnlineUpdated'])) { |
|
| 166 | + $_SESSION['timeOnlineUpdated'] = time(); |
|
| 167 | + } |
|
| 160 | 168 | |
| 161 | 169 | // Set their login time, if not already done within the last minute. |
| 162 | 170 | if (SMF != 'SSI' && !empty($user_info['last_login']) && $user_info['last_login'] < time() - 60 && (!isset($_REQUEST['action']) || !in_array($_REQUEST['action'], array('.xml', 'login2', 'logintfa')))) |
| 163 | 171 | { |
| 164 | 172 | // Don't count longer than 15 minutes. |
| 165 | - if (time() - $_SESSION['timeOnlineUpdated'] > 60 * 15) |
|
| 166 | - $_SESSION['timeOnlineUpdated'] = time(); |
|
| 173 | + if (time() - $_SESSION['timeOnlineUpdated'] > 60 * 15) { |
|
| 174 | + $_SESSION['timeOnlineUpdated'] = time(); |
|
| 175 | + } |
|
| 167 | 176 | |
| 168 | 177 | $user_settings['total_time_logged_in'] += time() - $_SESSION['timeOnlineUpdated']; |
| 169 | 178 | updateMemberData($user_info['id'], array('last_login' => time(), 'member_ip' => $user_info['ip'], 'member_ip2' => $_SERVER['BAN_CHECK_IP'], 'total_time_logged_in' => $user_settings['total_time_logged_in'])); |
| 170 | 179 | |
| 171 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
| 172 | - cache_put_data('user_settings-' . $user_info['id'], $user_settings, 60); |
|
| 180 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
| 181 | + cache_put_data('user_settings-' . $user_info['id'], $user_settings, 60); |
|
| 182 | + } |
|
| 173 | 183 | |
| 174 | 184 | $user_info['total_time_logged_in'] += time() - $_SESSION['timeOnlineUpdated']; |
| 175 | 185 | $_SESSION['timeOnlineUpdated'] = time(); |
@@ -206,8 +216,7 @@ discard block |
||
| 206 | 216 | // Oops. maybe we have no more disk space left, or some other troubles, troubles... |
| 207 | 217 | // Copy the file back and run for your life! |
| 208 | 218 | @copy($boarddir . '/db_last_error_bak.php', $boarddir . '/db_last_error.php'); |
| 209 | - } |
|
| 210 | - else |
|
| 219 | + } else |
|
| 211 | 220 | { |
| 212 | 221 | @touch($boarddir . '/' . 'Settings.php'); |
| 213 | 222 | return true; |
@@ -227,22 +236,27 @@ discard block |
||
| 227 | 236 | global $db_cache, $db_count, $cache_misses, $cache_count_misses, $db_show_debug, $cache_count, $cache_hits, $smcFunc, $txt; |
| 228 | 237 | |
| 229 | 238 | // Add to Settings.php if you want to show the debugging information. |
| 230 | - if (!isset($db_show_debug) || $db_show_debug !== true || (isset($_GET['action']) && $_GET['action'] == 'viewquery')) |
|
| 231 | - return; |
|
| 239 | + if (!isset($db_show_debug) || $db_show_debug !== true || (isset($_GET['action']) && $_GET['action'] == 'viewquery')) { |
|
| 240 | + return; |
|
| 241 | + } |
|
| 232 | 242 | |
| 233 | - if (empty($_SESSION['view_queries'])) |
|
| 234 | - $_SESSION['view_queries'] = 0; |
|
| 235 | - if (empty($context['debug']['language_files'])) |
|
| 236 | - $context['debug']['language_files'] = array(); |
|
| 237 | - if (empty($context['debug']['sheets'])) |
|
| 238 | - $context['debug']['sheets'] = array(); |
|
| 243 | + if (empty($_SESSION['view_queries'])) { |
|
| 244 | + $_SESSION['view_queries'] = 0; |
|
| 245 | + } |
|
| 246 | + if (empty($context['debug']['language_files'])) { |
|
| 247 | + $context['debug']['language_files'] = array(); |
|
| 248 | + } |
|
| 249 | + if (empty($context['debug']['sheets'])) { |
|
| 250 | + $context['debug']['sheets'] = array(); |
|
| 251 | + } |
|
| 239 | 252 | |
| 240 | 253 | $files = get_included_files(); |
| 241 | 254 | $total_size = 0; |
| 242 | 255 | for ($i = 0, $n = count($files); $i < $n; $i++) |
| 243 | 256 | { |
| 244 | - if (file_exists($files[$i])) |
|
| 245 | - $total_size += filesize($files[$i]); |
|
| 257 | + if (file_exists($files[$i])) { |
|
| 258 | + $total_size += filesize($files[$i]); |
|
| 259 | + } |
|
| 246 | 260 | $files[$i] = strtr($files[$i], array($boarddir => '.', $sourcedir => '(Sources)', $cachedir => '(Cache)', $settings['actual_theme_dir'] => '(Current Theme)')); |
| 247 | 261 | } |
| 248 | 262 | |
@@ -251,8 +265,9 @@ discard block |
||
| 251 | 265 | { |
| 252 | 266 | foreach ($db_cache as $q => $qq) |
| 253 | 267 | { |
| 254 | - if (!empty($qq['w'])) |
|
| 255 | - $warnings += count($qq['w']); |
|
| 268 | + if (!empty($qq['w'])) { |
|
| 269 | + $warnings += count($qq['w']); |
|
| 270 | + } |
|
| 256 | 271 | } |
| 257 | 272 | |
| 258 | 273 | $_SESSION['debug'] = &$db_cache; |
@@ -273,12 +288,14 @@ discard block |
||
| 273 | 288 | ',(isset($context['debug']['instances']) ? ($txt['debug_instances'] . (empty($context['debug']['instances']) ? 0 : count($context['debug']['instances'])) . ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_instances\').style.display = \'inline\'; this.style.display = \'none\'; return false;">'. $txt['debug_show'] .'</a><span id="debug_instances" style="display: none;"><em>'. implode('</em>, <em>', array_keys($context['debug']['instances'])) .'</em></span>)'. '<br>') : ''),' |
| 274 | 289 | ', $txt['debug_files_included'], count($files), ' - ', round($total_size / 1024), $txt['debug_kb'], ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_include_info\').style.display = \'inline\'; this.style.display = \'none\'; return false;">', $txt['debug_show'], '</a><span id="debug_include_info" style="display: none;"><em>', implode('</em>, <em>', $files), '</em></span>)<br>'; |
| 275 | 290 | |
| 276 | - if (function_exists('memory_get_peak_usage')) |
|
| 277 | - echo $txt['debug_memory_use'], ceil(memory_get_peak_usage() / 1024), $txt['debug_kb'], '<br>'; |
|
| 291 | + if (function_exists('memory_get_peak_usage')) { |
|
| 292 | + echo $txt['debug_memory_use'], ceil(memory_get_peak_usage() / 1024), $txt['debug_kb'], '<br>'; |
|
| 293 | + } |
|
| 278 | 294 | |
| 279 | 295 | // What tokens are active? |
| 280 | - if (isset($_SESSION['token'])) |
|
| 281 | - echo $txt['debug_tokens'] . '<em>' . implode(',</em> <em>', array_keys($_SESSION['token'])), '</em>.<br>'; |
|
| 296 | + if (isset($_SESSION['token'])) { |
|
| 297 | + echo $txt['debug_tokens'] . '<em>' . implode(',</em> <em>', array_keys($_SESSION['token'])), '</em>.<br>'; |
|
| 298 | + } |
|
| 282 | 299 | |
| 283 | 300 | if (!empty($modSettings['cache_enable']) && !empty($cache_hits)) |
| 284 | 301 | { |
@@ -292,10 +309,12 @@ discard block |
||
| 292 | 309 | $total_t += $cache_hit['t']; |
| 293 | 310 | $total_s += $cache_hit['s']; |
| 294 | 311 | } |
| 295 | - if (!isset($cache_misses)) |
|
| 296 | - $cache_misses = array(); |
|
| 297 | - foreach ($cache_misses as $missed) |
|
| 298 | - $missed_entries[] = $missed['d'] . ' ' . $missed['k']; |
|
| 312 | + if (!isset($cache_misses)) { |
|
| 313 | + $cache_misses = array(); |
|
| 314 | + } |
|
| 315 | + foreach ($cache_misses as $missed) { |
|
| 316 | + $missed_entries[] = $missed['d'] . ' ' . $missed['k']; |
|
| 317 | + } |
|
| 299 | 318 | |
| 300 | 319 | echo ' |
| 301 | 320 | ', $txt['debug_cache_hits'], $cache_count, ': ', sprintf($txt['debug_cache_seconds_bytes_total'], comma_format($total_t, 5), comma_format($total_s)), ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_cache_info\').style.display = \'inline\'; this.style.display = \'none\'; return false;">', $txt['debug_show'], '</a><span id="debug_cache_info" style="display: none;"><em>', implode('</em>, <em>', $entries), '</em></span>)<br> |
@@ -306,38 +325,44 @@ discard block |
||
| 306 | 325 | <a href="', $scripturl, '?action=viewquery" target="_blank" class="new_win">', $warnings == 0 ? sprintf($txt['debug_queries_used'], (int) $db_count) : sprintf($txt['debug_queries_used_and_warnings'], (int) $db_count, $warnings), '</a><br> |
| 307 | 326 | <br>'; |
| 308 | 327 | |
| 309 | - if ($_SESSION['view_queries'] == 1 && !empty($db_cache)) |
|
| 310 | - foreach ($db_cache as $q => $qq) |
|
| 328 | + if ($_SESSION['view_queries'] == 1 && !empty($db_cache)) { |
|
| 329 | + foreach ($db_cache as $q => $qq) |
|
| 311 | 330 | { |
| 312 | 331 | $is_select = strpos(trim($qq['q']), 'SELECT') === 0 || preg_match('~^INSERT(?: IGNORE)? INTO \w+(?:\s+\([^)]+\))?\s+SELECT .+$~s', trim($qq['q'])) != 0; |
| 332 | + } |
|
| 313 | 333 | // Temporary tables created in earlier queries are not explainable. |
| 314 | 334 | if ($is_select) |
| 315 | 335 | { |
| 316 | - foreach (array('log_topics_unread', 'topics_posted_in', 'tmp_log_search_topics', 'tmp_log_search_messages') as $tmp) |
|
| 317 | - if (strpos(trim($qq['q']), $tmp) !== false) |
|
| 336 | + foreach (array('log_topics_unread', 'topics_posted_in', 'tmp_log_search_topics', 'tmp_log_search_messages') as $tmp) { |
|
| 337 | + if (strpos(trim($qq['q']), $tmp) !== false) |
|
| 318 | 338 | { |
| 319 | 339 | $is_select = false; |
| 340 | + } |
|
| 320 | 341 | break; |
| 321 | 342 | } |
| 322 | 343 | } |
| 323 | 344 | // But actual creation of the temporary tables are. |
| 324 | - elseif (preg_match('~^CREATE TEMPORARY TABLE .+?SELECT .+$~s', trim($qq['q'])) != 0) |
|
| 325 | - $is_select = true; |
|
| 345 | + elseif (preg_match('~^CREATE TEMPORARY TABLE .+?SELECT .+$~s', trim($qq['q'])) != 0) { |
|
| 346 | + $is_select = true; |
|
| 347 | + } |
|
| 326 | 348 | |
| 327 | 349 | // Make the filenames look a bit better. |
| 328 | - if (isset($qq['f'])) |
|
| 329 | - $qq['f'] = preg_replace('~^' . preg_quote($boarddir, '~') . '~', '...', $qq['f']); |
|
| 350 | + if (isset($qq['f'])) { |
|
| 351 | + $qq['f'] = preg_replace('~^' . preg_quote($boarddir, '~') . '~', '...', $qq['f']); |
|
| 352 | + } |
|
| 330 | 353 | |
| 331 | 354 | echo ' |
| 332 | 355 | <strong>', $is_select ? '<a href="' . $scripturl . '?action=viewquery;qq=' . ($q + 1) . '#qq' . $q . '" target="_blank" class="new_win" style="text-decoration: none;">' : '', nl2br(str_replace("\t", ' ', $smcFunc['htmlspecialchars'](ltrim($qq['q'], "\n\r")))) . ($is_select ? '</a></strong>' : '</strong>') . '<br> |
| 333 | 356 | '; |
| 334 | - if (!empty($qq['f']) && !empty($qq['l'])) |
|
| 335 | - echo sprintf($txt['debug_query_in_line'], $qq['f'], $qq['l']); |
|
| 357 | + if (!empty($qq['f']) && !empty($qq['l'])) { |
|
| 358 | + echo sprintf($txt['debug_query_in_line'], $qq['f'], $qq['l']); |
|
| 359 | + } |
|
| 336 | 360 | |
| 337 | - if (isset($qq['s'], $qq['t']) && isset($txt['debug_query_which_took_at'])) |
|
| 338 | - echo sprintf($txt['debug_query_which_took_at'], round($qq['t'], 8), round($qq['s'], 8)) . '<br>'; |
|
| 339 | - elseif (isset($qq['t'])) |
|
| 340 | - echo sprintf($txt['debug_query_which_took'], round($qq['t'], 8)) . '<br>'; |
|
| 361 | + if (isset($qq['s'], $qq['t']) && isset($txt['debug_query_which_took_at'])) { |
|
| 362 | + echo sprintf($txt['debug_query_which_took_at'], round($qq['t'], 8), round($qq['s'], 8)) . '<br>'; |
|
| 363 | + } elseif (isset($qq['t'])) { |
|
| 364 | + echo sprintf($txt['debug_query_which_took'], round($qq['t'], 8)) . '<br>'; |
|
| 365 | + } |
|
| 341 | 366 | echo ' |
| 342 | 367 | <br>'; |
| 343 | 368 | } |
@@ -362,12 +387,14 @@ discard block |
||
| 362 | 387 | global $modSettings, $smcFunc; |
| 363 | 388 | static $cache_stats = array(); |
| 364 | 389 | |
| 365 | - if (empty($modSettings['trackStats'])) |
|
| 366 | - return false; |
|
| 367 | - if (!empty($stats)) |
|
| 368 | - return $cache_stats = array_merge($cache_stats, $stats); |
|
| 369 | - elseif (empty($cache_stats)) |
|
| 370 | - return false; |
|
| 390 | + if (empty($modSettings['trackStats'])) { |
|
| 391 | + return false; |
|
| 392 | + } |
|
| 393 | + if (!empty($stats)) { |
|
| 394 | + return $cache_stats = array_merge($cache_stats, $stats); |
|
| 395 | + } elseif (empty($cache_stats)) { |
|
| 396 | + return false; |
|
| 397 | + } |
|
| 371 | 398 | |
| 372 | 399 | $setStringUpdate = ''; |
| 373 | 400 | $insert_keys = array(); |
@@ -380,10 +407,11 @@ discard block |
||
| 380 | 407 | $setStringUpdate .= ' |
| 381 | 408 | ' . $field . ' = ' . ($change === '+' ? $field . ' + 1' : '{int:' . $field . '}') . ','; |
| 382 | 409 | |
| 383 | - if ($change === '+') |
|
| 384 | - $cache_stats[$field] = 1; |
|
| 385 | - else |
|
| 386 | - $update_parameters[$field] = $change; |
|
| 410 | + if ($change === '+') { |
|
| 411 | + $cache_stats[$field] = 1; |
|
| 412 | + } else { |
|
| 413 | + $update_parameters[$field] = $change; |
|
| 414 | + } |
|
| 387 | 415 | $insert_keys[$field] = 'int'; |
| 388 | 416 | } |
| 389 | 417 | |
@@ -447,43 +475,50 @@ discard block |
||
| 447 | 475 | ); |
| 448 | 476 | |
| 449 | 477 | // Make sure this particular log is enabled first... |
| 450 | - if (empty($modSettings['modlog_enabled'])) |
|
| 451 | - unset ($log_types['moderate']); |
|
| 452 | - if (empty($modSettings['userlog_enabled'])) |
|
| 453 | - unset ($log_types['user']); |
|
| 454 | - if (empty($modSettings['adminlog_enabled'])) |
|
| 455 | - unset ($log_types['admin']); |
|
| 478 | + if (empty($modSettings['modlog_enabled'])) { |
|
| 479 | + unset ($log_types['moderate']); |
|
| 480 | + } |
|
| 481 | + if (empty($modSettings['userlog_enabled'])) { |
|
| 482 | + unset ($log_types['user']); |
|
| 483 | + } |
|
| 484 | + if (empty($modSettings['adminlog_enabled'])) { |
|
| 485 | + unset ($log_types['admin']); |
|
| 486 | + } |
|
| 456 | 487 | |
| 457 | 488 | call_integration_hook('integrate_log_types', array(&$log_types)); |
| 458 | 489 | |
| 459 | 490 | foreach ($logs as $log) |
| 460 | 491 | { |
| 461 | - if (!isset($log_types[$log['log_type']])) |
|
| 462 | - return false; |
|
| 492 | + if (!isset($log_types[$log['log_type']])) { |
|
| 493 | + return false; |
|
| 494 | + } |
|
| 463 | 495 | |
| 464 | - if (!is_array($log['extra'])) |
|
| 465 | - trigger_error('logActions(): data is not an array with action \'' . $log['action'] . '\'', E_USER_NOTICE); |
|
| 496 | + if (!is_array($log['extra'])) { |
|
| 497 | + trigger_error('logActions(): data is not an array with action \'' . $log['action'] . '\'', E_USER_NOTICE); |
|
| 498 | + } |
|
| 466 | 499 | |
| 467 | 500 | // Pull out the parts we want to store separately, but also make sure that the data is proper |
| 468 | 501 | if (isset($log['extra']['topic'])) |
| 469 | 502 | { |
| 470 | - if (!is_numeric($log['extra']['topic'])) |
|
| 471 | - trigger_error('logActions(): data\'s topic is not a number', E_USER_NOTICE); |
|
| 503 | + if (!is_numeric($log['extra']['topic'])) { |
|
| 504 | + trigger_error('logActions(): data\'s topic is not a number', E_USER_NOTICE); |
|
| 505 | + } |
|
| 472 | 506 | $topic_id = empty($log['extra']['topic']) ? 0 : (int) $log['extra']['topic']; |
| 473 | 507 | unset($log['extra']['topic']); |
| 508 | + } else { |
|
| 509 | + $topic_id = 0; |
|
| 474 | 510 | } |
| 475 | - else |
|
| 476 | - $topic_id = 0; |
|
| 477 | 511 | |
| 478 | 512 | if (isset($log['extra']['message'])) |
| 479 | 513 | { |
| 480 | - if (!is_numeric($log['extra']['message'])) |
|
| 481 | - trigger_error('logActions(): data\'s message is not a number', E_USER_NOTICE); |
|
| 514 | + if (!is_numeric($log['extra']['message'])) { |
|
| 515 | + trigger_error('logActions(): data\'s message is not a number', E_USER_NOTICE); |
|
| 516 | + } |
|
| 482 | 517 | $msg_id = empty($log['extra']['message']) ? 0 : (int) $log['extra']['message']; |
| 483 | 518 | unset($log['extra']['message']); |
| 519 | + } else { |
|
| 520 | + $msg_id = 0; |
|
| 484 | 521 | } |
| 485 | - else |
|
| 486 | - $msg_id = 0; |
|
| 487 | 522 | |
| 488 | 523 | // @todo cache this? |
| 489 | 524 | // Is there an associated report on this? |
@@ -510,23 +545,26 @@ discard block |
||
| 510 | 545 | $smcFunc['db_free_result']($request); |
| 511 | 546 | } |
| 512 | 547 | |
| 513 | - if (isset($log['extra']['member']) && !is_numeric($log['extra']['member'])) |
|
| 514 | - trigger_error('logActions(): data\'s member is not a number', E_USER_NOTICE); |
|
| 548 | + if (isset($log['extra']['member']) && !is_numeric($log['extra']['member'])) { |
|
| 549 | + trigger_error('logActions(): data\'s member is not a number', E_USER_NOTICE); |
|
| 550 | + } |
|
| 515 | 551 | |
| 516 | 552 | if (isset($log['extra']['board'])) |
| 517 | 553 | { |
| 518 | - if (!is_numeric($log['extra']['board'])) |
|
| 519 | - trigger_error('logActions(): data\'s board is not a number', E_USER_NOTICE); |
|
| 554 | + if (!is_numeric($log['extra']['board'])) { |
|
| 555 | + trigger_error('logActions(): data\'s board is not a number', E_USER_NOTICE); |
|
| 556 | + } |
|
| 520 | 557 | $board_id = empty($log['extra']['board']) ? 0 : (int) $log['extra']['board']; |
| 521 | 558 | unset($log['extra']['board']); |
| 559 | + } else { |
|
| 560 | + $board_id = 0; |
|
| 522 | 561 | } |
| 523 | - else |
|
| 524 | - $board_id = 0; |
|
| 525 | 562 | |
| 526 | 563 | if (isset($log['extra']['board_to'])) |
| 527 | 564 | { |
| 528 | - if (!is_numeric($log['extra']['board_to'])) |
|
| 529 | - trigger_error('logActions(): data\'s board_to is not a number', E_USER_NOTICE); |
|
| 565 | + if (!is_numeric($log['extra']['board_to'])) { |
|
| 566 | + trigger_error('logActions(): data\'s board_to is not a number', E_USER_NOTICE); |
|
| 567 | + } |
|
| 530 | 568 | if (empty($board_id)) |
| 531 | 569 | { |
| 532 | 570 | $board_id = empty($log['extra']['board_to']) ? 0 : (int) $log['extra']['board_to']; |
@@ -534,10 +572,11 @@ discard block |
||
| 534 | 572 | } |
| 535 | 573 | } |
| 536 | 574 | |
| 537 | - if (isset($log['extra']['member_affected'])) |
|
| 538 | - $memID = $log['extra']['member_affected']; |
|
| 539 | - else |
|
| 540 | - $memID = $user_info['id']; |
|
| 575 | + if (isset($log['extra']['member_affected'])) { |
|
| 576 | + $memID = $log['extra']['member_affected']; |
|
| 577 | + } else { |
|
| 578 | + $memID = $user_info['id']; |
|
| 579 | + } |
|
| 541 | 580 | |
| 542 | 581 | $inserts[] = array( |
| 543 | 582 | time(), $log_types[$log['log_type']], $memID, $user_info['ip'], $log['action'], |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 4 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * Create a menu. |
@@ -64,22 +65,26 @@ discard block |
||
| 64 | 65 | $menu_context['current_action'] = isset($menuOptions['action']) ? $menuOptions['action'] : $context['current_action']; |
| 65 | 66 | |
| 66 | 67 | // Allow extend *any* menu with a single hook |
| 67 | - if (!empty($menu_context['current_action'])) |
|
| 68 | - call_integration_hook('integrate_' . $menu_context['current_action'] . '_areas', array(&$menuData)); |
|
| 68 | + if (!empty($menu_context['current_action'])) { |
|
| 69 | + call_integration_hook('integrate_' . $menu_context['current_action'] . '_areas', array(&$menuData)); |
|
| 70 | + } |
|
| 69 | 71 | |
| 70 | 72 | // What is the current area selected? |
| 71 | - if (isset($menuOptions['current_area']) || isset($_GET['area'])) |
|
| 72 | - $menu_context['current_area'] = isset($menuOptions['current_area']) ? $menuOptions['current_area'] : $_GET['area']; |
|
| 73 | + if (isset($menuOptions['current_area']) || isset($_GET['area'])) { |
|
| 74 | + $menu_context['current_area'] = isset($menuOptions['current_area']) ? $menuOptions['current_area'] : $_GET['area']; |
|
| 75 | + } |
|
| 73 | 76 | |
| 74 | 77 | // Build a list of additional parameters that should go in the URL. |
| 75 | 78 | $menu_context['extra_parameters'] = ''; |
| 76 | - if (!empty($menuOptions['extra_url_parameters'])) |
|
| 77 | - foreach ($menuOptions['extra_url_parameters'] as $key => $value) |
|
| 79 | + if (!empty($menuOptions['extra_url_parameters'])) { |
|
| 80 | + foreach ($menuOptions['extra_url_parameters'] as $key => $value) |
|
| 78 | 81 | $menu_context['extra_parameters'] .= ';' . $key . '=' . $value; |
| 82 | + } |
|
| 79 | 83 | |
| 80 | 84 | // Only include the session ID in the URL if it's strictly necessary. |
| 81 | - if (empty($menuOptions['disable_url_session_check'])) |
|
| 82 | - $menu_context['extra_parameters'] .= ';' . $context['session_var'] . '=' . $context['session_id']; |
|
| 85 | + if (empty($menuOptions['disable_url_session_check'])) { |
|
| 86 | + $menu_context['extra_parameters'] .= ';' . $context['session_var'] . '=' . $context['session_id']; |
|
| 87 | + } |
|
| 83 | 88 | |
| 84 | 89 | $include_data = array(); |
| 85 | 90 | |
@@ -87,8 +92,9 @@ discard block |
||
| 87 | 92 | foreach ($menuData as $section_id => $section) |
| 88 | 93 | { |
| 89 | 94 | // Is this enabled - or has as permission check - which fails? |
| 90 | - if ((isset($section['enabled']) && $section['enabled'] == false) || (isset($section['permission']) && !allowedTo($section['permission']))) |
|
| 91 | - continue; |
|
| 95 | + if ((isset($section['enabled']) && $section['enabled'] == false) || (isset($section['permission']) && !allowedTo($section['permission']))) { |
|
| 96 | + continue; |
|
| 97 | + } |
|
| 92 | 98 | |
| 93 | 99 | // Now we cycle through the sections to pick the right area. |
| 94 | 100 | foreach ($section['areas'] as $area_id => $area) |
@@ -110,41 +116,45 @@ discard block |
||
| 110 | 116 | if (empty($area['hidden'])) |
| 111 | 117 | { |
| 112 | 118 | // First time this section? |
| 113 | - if (!isset($menu_context['sections'][$section_id])) |
|
| 114 | - $menu_context['sections'][$section_id]['title'] = $section['title']; |
|
| 119 | + if (!isset($menu_context['sections'][$section_id])) { |
|
| 120 | + $menu_context['sections'][$section_id]['title'] = $section['title']; |
|
| 121 | + } |
|
| 115 | 122 | |
| 116 | 123 | $menu_context['sections'][$section_id]['areas'][$area_id] = array('label' => isset($area['label']) ? $area['label'] : $txt[$area_id]); |
| 117 | 124 | // We'll need the ID as well... |
| 118 | 125 | $menu_context['sections'][$section_id]['id'] = $section_id; |
| 119 | 126 | // Does it have a custom URL? |
| 120 | - if (isset($area['custom_url'])) |
|
| 121 | - $menu_context['sections'][$section_id]['areas'][$area_id]['url'] = $area['custom_url']; |
|
| 127 | + if (isset($area['custom_url'])) { |
|
| 128 | + $menu_context['sections'][$section_id]['areas'][$area_id]['url'] = $area['custom_url']; |
|
| 129 | + } |
|
| 122 | 130 | |
| 123 | 131 | // Does this area have its own icon? |
| 124 | - if (!isset($area['force_menu_into_arms_of_another_menu']) && $user_info['name'] == 'iamanoompaloompa') |
|
| 125 | - $menu_context['sections'][$section_id]['areas'][$area_id] = smf_json_decode(base64_decode('eyJsYWJlbCI6Ik9vbXBhIExvb21wYSIsInVybCI6Imh0dHBzOlwvXC9lbi53aWtpcGVkaWEub3JnXC93aWtpXC9Pb21wYV9Mb29tcGFzPyIsImljb24iOiI8aW1nIHNyYz1cImh0dHBzOlwvXC93d3cuc2ltcGxlbWFjaGluZXMub3JnXC9pbWFnZXNcL29vbXBhLmdpZlwiIGFsdD1cIkknbSBhbiBPb21wYSBMb29tcGFcIiBcLz4ifQ=='), true); |
|
| 126 | - elseif (isset($area['icon']) && file_exists($settings['theme_dir'] . '/images/admin/' . $area['icon'])) |
|
| 127 | - $menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<img src="' . $settings['images_url'] . '/admin/' . $area['icon'] . '" alt="">'; |
|
| 128 | - elseif (isset($area['icon']) && file_exists($settings['default_theme_dir'] . '/images/admin/' . $area['icon'])) |
|
| 129 | - $menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<img src="' . $settings['default_images_url'] . '/admin/' . $area['icon'] . '" alt="">'; |
|
| 130 | - elseif (isset($area['icon'])) |
|
| 131 | - $menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<span class="generic_icons ' . $area['icon'] . '"></span>'; |
|
| 132 | - else |
|
| 133 | - $menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<span class="generic_icons ' . $area_id . '"></span>'; |
|
| 134 | - |
|
| 135 | - if (isset($area['icon_class']) && empty($menu_context['sections'][$section_id]['areas'][$area_id]['icon'])) |
|
| 136 | - $menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . $area['icon_class']; |
|
| 137 | - elseif (isset($area['icon'])) |
|
| 132 | + if (!isset($area['force_menu_into_arms_of_another_menu']) && $user_info['name'] == 'iamanoompaloompa') { |
|
| 133 | + $menu_context['sections'][$section_id]['areas'][$area_id] = smf_json_decode(base64_decode('eyJsYWJlbCI6Ik9vbXBhIExvb21wYSIsInVybCI6Imh0dHBzOlwvXC9lbi53aWtpcGVkaWEub3JnXC93aWtpXC9Pb21wYV9Mb29tcGFzPyIsImljb24iOiI8aW1nIHNyYz1cImh0dHBzOlwvXC93d3cuc2ltcGxlbWFjaGluZXMub3JnXC9pbWFnZXNcL29vbXBhLmdpZlwiIGFsdD1cIkknbSBhbiBPb21wYSBMb29tcGFcIiBcLz4ifQ=='), true); |
|
| 134 | + } elseif (isset($area['icon']) && file_exists($settings['theme_dir'] . '/images/admin/' . $area['icon'])) { |
|
| 135 | + $menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<img src="' . $settings['images_url'] . '/admin/' . $area['icon'] . '" alt="">'; |
|
| 136 | + } elseif (isset($area['icon']) && file_exists($settings['default_theme_dir'] . '/images/admin/' . $area['icon'])) { |
|
| 137 | + $menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<img src="' . $settings['default_images_url'] . '/admin/' . $area['icon'] . '" alt="">'; |
|
| 138 | + } elseif (isset($area['icon'])) { |
|
| 139 | + $menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<span class="generic_icons ' . $area['icon'] . '"></span>'; |
|
| 140 | + } else { |
|
| 141 | + $menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<span class="generic_icons ' . $area_id . '"></span>'; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + if (isset($area['icon_class']) && empty($menu_context['sections'][$section_id]['areas'][$area_id]['icon'])) { |
|
| 145 | + $menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . $area['icon_class']; |
|
| 146 | + } elseif (isset($area['icon'])) |
|
| 138 | 147 | { |
| 139 | - if ((substr($area['icon'], -4) === '.png' || substr($area['icon'], -4) === '.gif') && file_exists($settings['theme_dir'] . '/images/admin/big/' . $area['icon'])) |
|
| 140 | - $menu_context['sections'][$section_id]['areas'][$area_id]['icon_file'] = $settings['theme_url'] . '/images/admin/big/' . $area['icon']; |
|
| 141 | - elseif ((substr($area['icon'], -4) === '.png' || substr($area['icon'], -4) === '.gif') && file_exists($settings['default_theme_dir'] . '/images/admin/big/' . $area['icon'])) |
|
| 142 | - $menu_context['sections'][$section_id]['areas'][$area_id]['icon_file'] = $settings['default_theme_url'] . '/images/admin/big/' . $area['icon']; |
|
| 148 | + if ((substr($area['icon'], -4) === '.png' || substr($area['icon'], -4) === '.gif') && file_exists($settings['theme_dir'] . '/images/admin/big/' . $area['icon'])) { |
|
| 149 | + $menu_context['sections'][$section_id]['areas'][$area_id]['icon_file'] = $settings['theme_url'] . '/images/admin/big/' . $area['icon']; |
|
| 150 | + } elseif ((substr($area['icon'], -4) === '.png' || substr($area['icon'], -4) === '.gif') && file_exists($settings['default_theme_dir'] . '/images/admin/big/' . $area['icon'])) { |
|
| 151 | + $menu_context['sections'][$section_id]['areas'][$area_id]['icon_file'] = $settings['default_theme_url'] . '/images/admin/big/' . $area['icon']; |
|
| 152 | + } |
|
| 143 | 153 | |
| 144 | 154 | $menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . str_replace(array('.png', '.gif'), '', $area['icon']); |
| 155 | + } else { |
|
| 156 | + $menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . str_replace(array('.png', '.gif'), '', $area_id); |
|
| 145 | 157 | } |
| 146 | - else |
|
| 147 | - $menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . str_replace(array('.png', '.gif'), '', $area_id); |
|
| 148 | 158 | |
| 149 | 159 | // Some areas may be listed but not active, which we show as greyed out. |
| 150 | 160 | $menu_context['sections'][$section_id]['areas'][$area_id]['inactive'] = !empty($area['inactive']); |
@@ -158,35 +168,41 @@ discard block |
||
| 158 | 168 | { |
| 159 | 169 | if ((empty($sub[1]) || allowedTo($sub[1])) && (!isset($sub['enabled']) || !empty($sub['enabled']))) |
| 160 | 170 | { |
| 161 | - if ($first_sa == null) |
|
| 162 | - $first_sa = $sa; |
|
| 171 | + if ($first_sa == null) { |
|
| 172 | + $first_sa = $sa; |
|
| 173 | + } |
|
| 163 | 174 | |
| 164 | 175 | $menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa] = array('label' => $sub[0]); |
| 165 | 176 | // Custom URL? |
| 166 | - if (isset($sub['url'])) |
|
| 167 | - $menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa]['url'] = $sub['url']; |
|
| 177 | + if (isset($sub['url'])) { |
|
| 178 | + $menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa]['url'] = $sub['url']; |
|
| 179 | + } |
|
| 168 | 180 | |
| 169 | 181 | // A bit complicated - but is this set? |
| 170 | 182 | if ($menu_context['current_area'] == $area_id) |
| 171 | 183 | { |
| 172 | 184 | // Save which is the first... |
| 173 | - if (empty($first_sa)) |
|
| 174 | - $first_sa = $sa; |
|
| 185 | + if (empty($first_sa)) { |
|
| 186 | + $first_sa = $sa; |
|
| 187 | + } |
|
| 175 | 188 | |
| 176 | 189 | // Is this the current subsection? |
| 177 | - if (isset($_REQUEST['sa']) && $_REQUEST['sa'] == $sa) |
|
| 178 | - $menu_context['current_subsection'] = $sa; |
|
| 190 | + if (isset($_REQUEST['sa']) && $_REQUEST['sa'] == $sa) { |
|
| 191 | + $menu_context['current_subsection'] = $sa; |
|
| 192 | + } |
|
| 179 | 193 | // Otherwise is it the default? |
| 180 | - elseif (!isset($menu_context['current_subsection']) && !empty($sub[2])) |
|
| 181 | - $menu_context['current_subsection'] = $sa; |
|
| 194 | + elseif (!isset($menu_context['current_subsection']) && !empty($sub[2])) { |
|
| 195 | + $menu_context['current_subsection'] = $sa; |
|
| 196 | + } |
|
| 182 | 197 | } |
| 183 | 198 | |
| 184 | 199 | // Let's assume this is the last, for now. |
| 185 | 200 | $last_sa = $sa; |
| 186 | 201 | } |
| 187 | 202 | // Mark it as disabled... |
| 188 | - else |
|
| 189 | - $menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa]['disabled'] = true; |
|
| 203 | + else { |
|
| 204 | + $menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa]['disabled'] = true; |
|
| 205 | + } |
|
| 190 | 206 | } |
| 191 | 207 | |
| 192 | 208 | // Set which one is first, last and selected in the group. |
@@ -195,8 +211,9 @@ discard block |
||
| 195 | 211 | $menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$context['right_to_left'] ? $last_sa : $first_sa]['is_first'] = true; |
| 196 | 212 | $menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$context['right_to_left'] ? $first_sa : $last_sa]['is_last'] = true; |
| 197 | 213 | |
| 198 | - if ($menu_context['current_area'] == $area_id && !isset($menu_context['current_subsection'])) |
|
| 199 | - $menu_context['current_subsection'] = $first_sa; |
|
| 214 | + if ($menu_context['current_area'] == $area_id && !isset($menu_context['current_subsection'])) { |
|
| 215 | + $menu_context['current_subsection'] = $first_sa; |
|
| 216 | + } |
|
| 200 | 217 | } |
| 201 | 218 | } |
| 202 | 219 | } |
@@ -230,23 +247,26 @@ discard block |
||
| 230 | 247 | $menu_context['base_url'] = isset($menuOptions['base_url']) ? $menuOptions['base_url'] : $scripturl . '?action=' . $menu_context['current_action']; |
| 231 | 248 | |
| 232 | 249 | // If we didn't find the area we were looking for go to a default one. |
| 233 | - if (isset($backup_area) && empty($found_section)) |
|
| 234 | - $menu_context['current_area'] = $backup_area; |
|
| 250 | + if (isset($backup_area) && empty($found_section)) { |
|
| 251 | + $menu_context['current_area'] = $backup_area; |
|
| 252 | + } |
|
| 235 | 253 | |
| 236 | 254 | // If there are sections quickly goes through all the sections to check if the base menu has an url |
| 237 | 255 | if (!empty($menu_context['current_section'])) |
| 238 | 256 | { |
| 239 | 257 | $menu_context['sections'][$menu_context['current_section']]['selected'] = true; |
| 240 | 258 | $menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['selected'] = true; |
| 241 | - if (!empty($menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['subsections'][$context['current_subaction']])) |
|
| 242 | - $menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['subsections'][$context['current_subaction']]['selected'] = true; |
|
| 259 | + if (!empty($menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['subsections'][$context['current_subaction']])) { |
|
| 260 | + $menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['subsections'][$context['current_subaction']]['selected'] = true; |
|
| 261 | + } |
|
| 243 | 262 | |
| 244 | - foreach ($menu_context['sections'] as $section_id => $section) |
|
| 245 | - foreach ($section['areas'] as $area_id => $area) |
|
| 263 | + foreach ($menu_context['sections'] as $section_id => $section) { |
|
| 264 | + foreach ($section['areas'] as $area_id => $area) |
|
| 246 | 265 | { |
| 247 | 266 | if (!isset($menu_context['sections'][$section_id]['url'])) |
| 248 | 267 | { |
| 249 | 268 | $menu_context['sections'][$section_id]['url'] = isset($area['url']) ? $area['url'] : $menu_context['base_url'] . ';area=' . $area_id; |
| 269 | + } |
|
| 250 | 270 | break; |
| 251 | 271 | } |
| 252 | 272 | } |
@@ -257,8 +277,9 @@ discard block |
||
| 257 | 277 | { |
| 258 | 278 | // Never happened! |
| 259 | 279 | $context['max_menu_id']--; |
| 260 | - if ($context['max_menu_id'] == 0) |
|
| 261 | - unset($context['max_menu_id']); |
|
| 280 | + if ($context['max_menu_id'] == 0) { |
|
| 281 | + unset($context['max_menu_id']); |
|
| 282 | + } |
|
| 262 | 283 | |
| 263 | 284 | return false; |
| 264 | 285 | } |
@@ -269,8 +290,9 @@ discard block |
||
| 269 | 290 | $context['template_layers'][] = $menu_context['layer_name']; |
| 270 | 291 | |
| 271 | 292 | // Check we had something - for sanity sake. |
| 272 | - if (empty($include_data)) |
|
| 273 | - return false; |
|
| 293 | + if (empty($include_data)) { |
|
| 294 | + return false; |
|
| 295 | + } |
|
| 274 | 296 | |
| 275 | 297 | // Finally - return information on the selected item. |
| 276 | 298 | $include_data += array( |
@@ -293,12 +315,14 @@ discard block |
||
| 293 | 315 | global $context; |
| 294 | 316 | |
| 295 | 317 | $menu_name = $menu_id == 'last' && isset($context['max_menu_id']) && isset($context['menu_data_' . $context['max_menu_id']]) ? 'menu_data_' . $context['max_menu_id'] : 'menu_data_' . $menu_id; |
| 296 | - if (!isset($context[$menu_name])) |
|
| 297 | - return false; |
|
| 318 | + if (!isset($context[$menu_name])) { |
|
| 319 | + return false; |
|
| 320 | + } |
|
| 298 | 321 | |
| 299 | 322 | $layer_index = array_search($context[$menu_name]['layer_name'], $context['template_layers']); |
| 300 | - if ($layer_index !== false) |
|
| 301 | - unset($context['template_layers'][$layer_index]); |
|
| 323 | + if ($layer_index !== false) { |
|
| 324 | + unset($context['template_layers'][$layer_index]); |
|
| 325 | + } |
|
| 302 | 326 | |
| 303 | 327 | unset($context[$menu_name]); |
| 304 | 328 | } |
@@ -11,8 +11,9 @@ discard block |
||
| 11 | 11 | * @version 2.1 Beta 4 |
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | -if (!defined('SMF')) |
|
| 14 | +if (!defined('SMF')) { |
|
| 15 | 15 | die('No direct access...'); |
| 16 | +} |
|
| 16 | 17 | |
| 17 | 18 | /** |
| 18 | 19 | * Converts the given UTF-8 string into lowercase. |
@@ -575,8 +576,8 @@ discard block |
||
| 575 | 576 | if (safe_unserialize($row['extra']) === false && preg_match('~^(a:3:{s:5:"topic";i:\d+;s:7:"subject";s:)(\d+):"(.+)"(;s:6:"member";s:5:"\d+";})$~', $row['extra'], $matches) === 1) |
| 576 | 577 | { |
| 577 | 578 | $temp = $matches[1] . strlen($matches[3]) . ':"' . $matches[3] . '"' . $matches[4]; |
| 578 | - if (safe_unserialize($temp) !== false) |
|
| 579 | - $smcFunc['db_query']('', ' |
|
| 579 | + if (safe_unserialize($temp) !== false) { |
|
| 580 | + $smcFunc['db_query']('', ' |
|
| 580 | 581 | UPDATE {db_prefix}log_actions |
| 581 | 582 | SET extra = {string:extra} |
| 582 | 583 | WHERE id_action = {int:current_action}', |
@@ -585,6 +586,7 @@ discard block |
||
| 585 | 586 | 'extra' => json_encode(safe_unserialize($temp)), |
| 586 | 587 | ) |
| 587 | 588 | ); |
| 589 | + } |
|
| 588 | 590 | } |
| 589 | 591 | } |
| 590 | 592 | $smcFunc['db_free_result']($request); |
@@ -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 | * Show the calendar. |
@@ -47,12 +48,14 @@ discard block |
||
| 47 | 48 | 'post' => 'CalendarPost', |
| 48 | 49 | ); |
| 49 | 50 | |
| 50 | - if (isset($_GET['sa']) && isset($subActions[$_GET['sa']])) |
|
| 51 | - return call_helper($subActions[$_GET['sa']]); |
|
| 51 | + if (isset($_GET['sa']) && isset($subActions[$_GET['sa']])) { |
|
| 52 | + return call_helper($subActions[$_GET['sa']]); |
|
| 53 | + } |
|
| 52 | 54 | |
| 53 | 55 | // You can't do anything if the calendar is off. |
| 54 | - if (empty($modSettings['cal_enabled'])) |
|
| 55 | - fatal_lang_error('calendar_off', false); |
|
| 56 | + if (empty($modSettings['cal_enabled'])) { |
|
| 57 | + fatal_lang_error('calendar_off', false); |
|
| 58 | + } |
|
| 56 | 59 | |
| 57 | 60 | // This is gonna be needed... |
| 58 | 61 | loadTemplate('Calendar'); |
@@ -88,22 +91,25 @@ discard block |
||
| 88 | 91 | $context['page_title'] = $txt['calendar']; |
| 89 | 92 | |
| 90 | 93 | // Ensure a default view is defined |
| 91 | - if (empty($modSettings['calendar_default_view'])) |
|
| 92 | - $modSettings['calendar_default_view'] = 'viewlist'; |
|
| 94 | + if (empty($modSettings['calendar_default_view'])) { |
|
| 95 | + $modSettings['calendar_default_view'] = 'viewlist'; |
|
| 96 | + } |
|
| 93 | 97 | |
| 94 | 98 | // What view do we want? |
| 95 | - if (isset($_GET['viewweek'])) |
|
| 96 | - $context['calendar_view'] = 'viewweek'; |
|
| 97 | - elseif (isset($_GET['viewmonth'])) |
|
| 98 | - $context['calendar_view'] = 'viewmonth'; |
|
| 99 | - elseif (isset($_GET['viewlist'])) |
|
| 100 | - $context['calendar_view'] = 'viewlist'; |
|
| 101 | - else |
|
| 102 | - $context['calendar_view'] = $modSettings['calendar_default_view']; |
|
| 99 | + if (isset($_GET['viewweek'])) { |
|
| 100 | + $context['calendar_view'] = 'viewweek'; |
|
| 101 | + } elseif (isset($_GET['viewmonth'])) { |
|
| 102 | + $context['calendar_view'] = 'viewmonth'; |
|
| 103 | + } elseif (isset($_GET['viewlist'])) { |
|
| 104 | + $context['calendar_view'] = 'viewlist'; |
|
| 105 | + } else { |
|
| 106 | + $context['calendar_view'] = $modSettings['calendar_default_view']; |
|
| 107 | + } |
|
| 103 | 108 | |
| 104 | 109 | // Don't let search engines index the non-default calendar pages |
| 105 | - if ($context['calendar_view'] !== $modSettings['calendar_default_view']) |
|
| 106 | - $context['robot_no_index'] = true; |
|
| 110 | + if ($context['calendar_view'] !== $modSettings['calendar_default_view']) { |
|
| 111 | + $context['robot_no_index'] = true; |
|
| 112 | + } |
|
| 107 | 113 | |
| 108 | 114 | // Get the current day of month... |
| 109 | 115 | require_once($sourcedir . '/Subs-Calendar.php'); |
@@ -164,16 +170,19 @@ discard block |
||
| 164 | 170 | ); |
| 165 | 171 | |
| 166 | 172 | // Make sure the year and month are in valid ranges. |
| 167 | - if ($curPage['month'] < 1 || $curPage['month'] > 12) |
|
| 168 | - fatal_lang_error('invalid_month', false); |
|
| 169 | - if ($curPage['year'] < $modSettings['cal_minyear'] || $curPage['year'] > $modSettings['cal_maxyear']) |
|
| 170 | - fatal_lang_error('invalid_year', false); |
|
| 173 | + if ($curPage['month'] < 1 || $curPage['month'] > 12) { |
|
| 174 | + fatal_lang_error('invalid_month', false); |
|
| 175 | + } |
|
| 176 | + if ($curPage['year'] < $modSettings['cal_minyear'] || $curPage['year'] > $modSettings['cal_maxyear']) { |
|
| 177 | + fatal_lang_error('invalid_year', false); |
|
| 178 | + } |
|
| 171 | 179 | // If we have a day clean that too. |
| 172 | 180 | if ($context['calendar_view'] != 'viewmonth') |
| 173 | 181 | { |
| 174 | 182 | $isValid = checkdate($curPage['month'], $curPage['day'], $curPage['year']); |
| 175 | - if (!$isValid) |
|
| 176 | - fatal_lang_error('invalid_day', false); |
|
| 183 | + if (!$isValid) { |
|
| 184 | + fatal_lang_error('invalid_day', false); |
|
| 185 | + } |
|
| 177 | 186 | } |
| 178 | 187 | |
| 179 | 188 | // Load all the context information needed to show the calendar grid. |
@@ -195,23 +204,26 @@ discard block |
||
| 195 | 204 | ); |
| 196 | 205 | |
| 197 | 206 | // Load up the main view. |
| 198 | - if ($context['calendar_view'] == 'viewlist') |
|
| 199 | - $context['calendar_grid_main'] = getCalendarList($curPage['start_date'], $curPage['end_date'], $calendarOptions); |
|
| 200 | - elseif ($context['calendar_view'] == 'viewweek') |
|
| 201 | - $context['calendar_grid_main'] = getCalendarWeek($curPage['month'], $curPage['year'], $curPage['day'], $calendarOptions); |
|
| 202 | - else |
|
| 203 | - $context['calendar_grid_main'] = getCalendarGrid($curPage['month'], $curPage['year'], $calendarOptions); |
|
| 207 | + if ($context['calendar_view'] == 'viewlist') { |
|
| 208 | + $context['calendar_grid_main'] = getCalendarList($curPage['start_date'], $curPage['end_date'], $calendarOptions); |
|
| 209 | + } elseif ($context['calendar_view'] == 'viewweek') { |
|
| 210 | + $context['calendar_grid_main'] = getCalendarWeek($curPage['month'], $curPage['year'], $curPage['day'], $calendarOptions); |
|
| 211 | + } else { |
|
| 212 | + $context['calendar_grid_main'] = getCalendarGrid($curPage['month'], $curPage['year'], $calendarOptions); |
|
| 213 | + } |
|
| 204 | 214 | |
| 205 | 215 | // Load up the previous and next months. |
| 206 | 216 | $context['calendar_grid_current'] = getCalendarGrid($curPage['month'], $curPage['year'], $calendarOptions); |
| 207 | 217 | |
| 208 | 218 | // Only show previous month if it isn't pre-January of the min-year |
| 209 | - if ($context['calendar_grid_current']['previous_calendar']['year'] > $modSettings['cal_minyear'] || $curPage['month'] != 1) |
|
| 210 | - $context['calendar_grid_prev'] = getCalendarGrid($context['calendar_grid_current']['previous_calendar']['month'], $context['calendar_grid_current']['previous_calendar']['year'], $calendarOptions, true); |
|
| 219 | + if ($context['calendar_grid_current']['previous_calendar']['year'] > $modSettings['cal_minyear'] || $curPage['month'] != 1) { |
|
| 220 | + $context['calendar_grid_prev'] = getCalendarGrid($context['calendar_grid_current']['previous_calendar']['month'], $context['calendar_grid_current']['previous_calendar']['year'], $calendarOptions, true); |
|
| 221 | + } |
|
| 211 | 222 | |
| 212 | 223 | // Only show next month if it isn't post-December of the max-year |
| 213 | - if ($context['calendar_grid_current']['next_calendar']['year'] < $modSettings['cal_maxyear'] || $curPage['month'] != 12) |
|
| 214 | - $context['calendar_grid_next'] = getCalendarGrid($context['calendar_grid_current']['next_calendar']['month'], $context['calendar_grid_current']['next_calendar']['year'], $calendarOptions); |
|
| 224 | + if ($context['calendar_grid_current']['next_calendar']['year'] < $modSettings['cal_maxyear'] || $curPage['month'] != 12) { |
|
| 225 | + $context['calendar_grid_next'] = getCalendarGrid($context['calendar_grid_current']['next_calendar']['month'], $context['calendar_grid_current']['next_calendar']['year'], $calendarOptions); |
|
| 226 | + } |
|
| 215 | 227 | |
| 216 | 228 | // Basic template stuff. |
| 217 | 229 | $context['allow_calendar_event'] = allowedTo('calendar_post'); |
@@ -231,8 +243,9 @@ discard block |
||
| 231 | 243 | $context['blocks_disabled'] = !empty($modSettings['cal_disable_prev_next']) ? 1 : 0; |
| 232 | 244 | |
| 233 | 245 | // Set the page title to mention the month or week, too |
| 234 | - if ($context['calendar_view'] != 'viewlist') |
|
| 235 | - $context['page_title'] .= ' - ' . ($context['calendar_view'] == 'viewweek' ? $context['calendar_grid_main']['week_title'] : $txt['months'][$context['current_month']] . ' ' . $context['current_year']); |
|
| 246 | + if ($context['calendar_view'] != 'viewlist') { |
|
| 247 | + $context['page_title'] .= ' - ' . ($context['calendar_view'] == 'viewweek' ? $context['calendar_grid_main']['week_title'] : $txt['months'][$context['current_month']] . ' ' . $context['current_year']); |
|
| 248 | + } |
|
| 236 | 249 | |
| 237 | 250 | // Load up the linktree! |
| 238 | 251 | $context['linktree'][] = array( |
@@ -245,17 +258,19 @@ discard block |
||
| 245 | 258 | 'name' => $txt['months'][$context['current_month']] . ' ' . $context['current_year'] |
| 246 | 259 | ); |
| 247 | 260 | // If applicable, add the current week to the linktree. |
| 248 | - if ($context['calendar_view'] == 'viewweek') |
|
| 249 | - $context['linktree'][] = array( |
|
| 261 | + if ($context['calendar_view'] == 'viewweek') { |
|
| 262 | + $context['linktree'][] = array( |
|
| 250 | 263 | 'url' => $scripturl . '?action=calendar;viewweek;year=' . $context['current_year'] . ';month=' . $context['current_month'] . ';day=' . $context['current_day'], |
| 251 | 264 | 'name' => $context['calendar_grid_main']['week_title'], |
| 252 | 265 | ); |
| 266 | + } |
|
| 253 | 267 | |
| 254 | 268 | // Build the calendar button array. |
| 255 | 269 | $context['calendar_buttons'] = array(); |
| 256 | 270 | |
| 257 | - if ($context['can_post']) |
|
| 258 | - $context['calendar_buttons']['post_event'] = array('text' => 'calendar_post_event', 'image' => 'calendarpe.png', 'url' => $scripturl . '?action=calendar;sa=post;month=' . $context['current_month'] . ';year=' . $context['current_year'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
| 271 | + if ($context['can_post']) { |
|
| 272 | + $context['calendar_buttons']['post_event'] = array('text' => 'calendar_post_event', 'image' => 'calendarpe.png', 'url' => $scripturl . '?action=calendar;sa=post;month=' . $context['current_month'] . ';year=' . $context['current_year'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
| 273 | + } |
|
| 259 | 274 | |
| 260 | 275 | // Allow mods to add additional buttons here |
| 261 | 276 | call_integration_hook('integrate_calendar_buttons'); |
@@ -284,14 +299,16 @@ discard block |
||
| 284 | 299 | require_once($sourcedir . '/Subs.php'); |
| 285 | 300 | |
| 286 | 301 | // Cast this for safety... |
| 287 | - if (isset($_REQUEST['eventid'])) |
|
| 288 | - $_REQUEST['eventid'] = (int) $_REQUEST['eventid']; |
|
| 302 | + if (isset($_REQUEST['eventid'])) { |
|
| 303 | + $_REQUEST['eventid'] = (int) $_REQUEST['eventid']; |
|
| 304 | + } |
|
| 289 | 305 | |
| 290 | 306 | // We want a fairly compact version of the time, but as close as possible to the user's settings. |
| 291 | - if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) |
|
| 292 | - $time_string = '%k:%M'; |
|
| 293 | - else |
|
| 294 | - $time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]); |
|
| 307 | + if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) { |
|
| 308 | + $time_string = '%k:%M'; |
|
| 309 | + } else { |
|
| 310 | + $time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]); |
|
| 311 | + } |
|
| 295 | 312 | |
| 296 | 313 | $js_time_string = str_replace( |
| 297 | 314 | array('%H', '%k', '%I', '%l', '%M', '%p', '%P', '%r', '%R', '%S', '%T', '%X'), |
@@ -305,12 +322,14 @@ discard block |
||
| 305 | 322 | checkSession(); |
| 306 | 323 | |
| 307 | 324 | // Validate the post... |
| 308 | - if (!isset($_POST['link_to_board'])) |
|
| 309 | - validateEventPost(); |
|
| 325 | + if (!isset($_POST['link_to_board'])) { |
|
| 326 | + validateEventPost(); |
|
| 327 | + } |
|
| 310 | 328 | |
| 311 | 329 | // If you're not allowed to edit any events, you have to be the poster. |
| 312 | - if ($_REQUEST['eventid'] > 0 && !allowedTo('calendar_edit_any')) |
|
| 313 | - isAllowedTo('calendar_edit_' . (!empty($user_info['id']) && getEventPoster($_REQUEST['eventid']) == $user_info['id'] ? 'own' : 'any')); |
|
| 330 | + if ($_REQUEST['eventid'] > 0 && !allowedTo('calendar_edit_any')) { |
|
| 331 | + isAllowedTo('calendar_edit_' . (!empty($user_info['id']) && getEventPoster($_REQUEST['eventid']) == $user_info['id'] ? 'own' : 'any')); |
|
| 332 | + } |
|
| 314 | 333 | |
| 315 | 334 | // New - and directing? |
| 316 | 335 | if (isset($_POST['link_to_board']) || empty($modSettings['cal_allow_unlinked'])) |
@@ -333,8 +352,9 @@ discard block |
||
| 333 | 352 | } |
| 334 | 353 | |
| 335 | 354 | // Deleting... |
| 336 | - elseif (isset($_REQUEST['deleteevent'])) |
|
| 337 | - removeEvent($_REQUEST['eventid']); |
|
| 355 | + elseif (isset($_REQUEST['deleteevent'])) { |
|
| 356 | + removeEvent($_REQUEST['eventid']); |
|
| 357 | + } |
|
| 338 | 358 | |
| 339 | 359 | // ... or just update it? |
| 340 | 360 | else |
@@ -357,15 +377,13 @@ discard block |
||
| 357 | 377 | $year = $d['year']; |
| 358 | 378 | $month = $d['month']; |
| 359 | 379 | $day = $d['day']; |
| 360 | - } |
|
| 361 | - elseif (isset($_POST['start_datetime'])) |
|
| 380 | + } elseif (isset($_POST['start_datetime'])) |
|
| 362 | 381 | { |
| 363 | 382 | $d = date_parse($_POST['start_datetime']); |
| 364 | 383 | $year = $d['year']; |
| 365 | 384 | $month = $d['month']; |
| 366 | 385 | $day = $d['day']; |
| 367 | - } |
|
| 368 | - else |
|
| 386 | + } else |
|
| 369 | 387 | { |
| 370 | 388 | $today = getdate(); |
| 371 | 389 | $year = isset($_POST['year']) ? $_POST['year'] : $today['year']; |
@@ -399,13 +417,13 @@ discard block |
||
| 399 | 417 | $context['event'] = array_merge($context['event'], $eventDatetimes); |
| 400 | 418 | |
| 401 | 419 | $context['event']['last_day'] = (int) strftime('%d', mktime(0, 0, 0, $context['event']['month'] == 12 ? 1 : $context['event']['month'] + 1, 0, $context['event']['month'] == 12 ? $context['event']['year'] + 1 : $context['event']['year'])); |
| 402 | - } |
|
| 403 | - else |
|
| 420 | + } else |
|
| 404 | 421 | { |
| 405 | 422 | $context['event'] = getEventProperties($_REQUEST['eventid']); |
| 406 | 423 | |
| 407 | - if ($context['event'] === false) |
|
| 408 | - fatal_lang_error('no_access', false); |
|
| 424 | + if ($context['event'] === false) { |
|
| 425 | + fatal_lang_error('no_access', false); |
|
| 426 | + } |
|
| 409 | 427 | |
| 410 | 428 | // If it has a board, then they should be editing it within the topic. |
| 411 | 429 | if (!empty($context['event']['topic']['id']) && !empty($context['event']['topic']['first_msg'])) |
@@ -416,10 +434,11 @@ discard block |
||
| 416 | 434 | } |
| 417 | 435 | |
| 418 | 436 | // Make sure the user is allowed to edit this event. |
| 419 | - if ($context['event']['member'] != $user_info['id']) |
|
| 420 | - isAllowedTo('calendar_edit_any'); |
|
| 421 | - elseif (!allowedTo('calendar_edit_any')) |
|
| 422 | - isAllowedTo('calendar_edit_own'); |
|
| 437 | + if ($context['event']['member'] != $user_info['id']) { |
|
| 438 | + isAllowedTo('calendar_edit_any'); |
|
| 439 | + } elseif (!allowedTo('calendar_edit_any')) { |
|
| 440 | + isAllowedTo('calendar_edit_own'); |
|
| 441 | + } |
|
| 423 | 442 | } |
| 424 | 443 | |
| 425 | 444 | // An all day event? Set up some nice defaults in case the user wants to change that |
@@ -453,8 +472,7 @@ discard block |
||
| 453 | 472 | { |
| 454 | 473 | // You can post new events but can't link them to anything... |
| 455 | 474 | $context['event']['categories'] = array(); |
| 456 | - } |
|
| 457 | - else |
|
| 475 | + } else |
|
| 458 | 476 | { |
| 459 | 477 | // Load the list of boards and categories in the context. |
| 460 | 478 | require_once($sourcedir . '/Subs-MessageIndex.php'); |
@@ -541,12 +559,14 @@ discard block |
||
| 541 | 559 | global $smcFunc, $sourcedir, $forum_version, $modSettings, $webmaster_email, $mbname; |
| 542 | 560 | |
| 543 | 561 | // You can't export if the calendar export feature is off. |
| 544 | - if (empty($modSettings['cal_export'])) |
|
| 545 | - fatal_lang_error('calendar_export_off', false); |
|
| 562 | + if (empty($modSettings['cal_export'])) { |
|
| 563 | + fatal_lang_error('calendar_export_off', false); |
|
| 564 | + } |
|
| 546 | 565 | |
| 547 | 566 | // Goes without saying that this is required. |
| 548 | - if (!isset($_REQUEST['eventid'])) |
|
| 549 | - fatal_lang_error('no_access', false); |
|
| 567 | + if (!isset($_REQUEST['eventid'])) { |
|
| 568 | + fatal_lang_error('no_access', false); |
|
| 569 | + } |
|
| 550 | 570 | |
| 551 | 571 | // This is kinda wanted. |
| 552 | 572 | require_once($sourcedir . '/Subs-Calendar.php'); |
@@ -554,15 +574,17 @@ discard block |
||
| 554 | 574 | // Load up the event in question and check it exists. |
| 555 | 575 | $event = getEventProperties($_REQUEST['eventid']); |
| 556 | 576 | |
| 557 | - if ($event === false) |
|
| 558 | - fatal_lang_error('no_access', false); |
|
| 577 | + if ($event === false) { |
|
| 578 | + fatal_lang_error('no_access', false); |
|
| 579 | + } |
|
| 559 | 580 | |
| 560 | 581 | // Check the title isn't too long - iCal requires some formatting if so. |
| 561 | 582 | $title = str_split($event['title'], 30); |
| 562 | 583 | foreach ($title as $id => $line) |
| 563 | 584 | { |
| 564 | - if ($id != 0) |
|
| 565 | - $title[$id] = ' ' . $title[$id]; |
|
| 585 | + if ($id != 0) { |
|
| 586 | + $title[$id] = ' ' . $title[$id]; |
|
| 587 | + } |
|
| 566 | 588 | $title[$id] .= "\n"; |
| 567 | 589 | } |
| 568 | 590 | |
@@ -575,8 +597,7 @@ discard block |
||
| 575 | 597 | { |
| 576 | 598 | $datestart = date_format($start_date, 'Ymd\THis'); |
| 577 | 599 | $dateend = date_format($end_date, 'Ymd\THis'); |
| 578 | - } |
|
| 579 | - else |
|
| 600 | + } else |
|
| 580 | 601 | { |
| 581 | 602 | $datestart = date_format($start_date, 'Ymd'); |
| 582 | 603 | |
@@ -597,15 +618,18 @@ discard block |
||
| 597 | 618 | $filecontents .= 'DTSTART' . (!empty($event['start_time']) ? ';TZID=' . $event['tz'] : ';VALUE=DATE') . ':' . $datestart . "\n"; |
| 598 | 619 | |
| 599 | 620 | // event has a duration |
| 600 | - if ($event['start_iso_gmdate'] != $event['end_iso_gmdate']) |
|
| 601 | - $filecontents .= 'DTEND' . (!empty($event['end_time']) ? ';TZID=' . $event['tz'] : ';VALUE=DATE') . ':' . $dateend . "\n"; |
|
| 621 | + if ($event['start_iso_gmdate'] != $event['end_iso_gmdate']) { |
|
| 622 | + $filecontents .= 'DTEND' . (!empty($event['end_time']) ? ';TZID=' . $event['tz'] : ';VALUE=DATE') . ':' . $dateend . "\n"; |
|
| 623 | + } |
|
| 602 | 624 | |
| 603 | 625 | // event has changed? advance the sequence for this UID |
| 604 | - if ($event['sequence'] > 0) |
|
| 605 | - $filecontents .= 'SEQUENCE:' . $event['sequence'] . "\n"; |
|
| 626 | + if ($event['sequence'] > 0) { |
|
| 627 | + $filecontents .= 'SEQUENCE:' . $event['sequence'] . "\n"; |
|
| 628 | + } |
|
| 606 | 629 | |
| 607 | - if (!empty($event['location'])) |
|
| 608 | - $filecontents .= 'LOCATION:' . str_replace(',', '\,', $event['location']) . "\n"; |
|
| 630 | + if (!empty($event['location'])) { |
|
| 631 | + $filecontents .= 'LOCATION:' . str_replace(',', '\,', $event['location']) . "\n"; |
|
| 632 | + } |
|
| 609 | 633 | |
| 610 | 634 | $filecontents .= 'SUMMARY:' . implode('', $title); |
| 611 | 635 | $filecontents .= 'UID:' . $event['eventid'] . '@' . str_replace(' ', '-', $mbname) . "\n"; |
@@ -614,23 +638,26 @@ discard block |
||
| 614 | 638 | |
| 615 | 639 | // Send some standard headers. |
| 616 | 640 | ob_end_clean(); |
| 617 | - if (!empty($modSettings['enableCompressedOutput'])) |
|
| 618 | - @ob_start('ob_gzhandler'); |
|
| 619 | - else |
|
| 620 | - ob_start(); |
|
| 641 | + if (!empty($modSettings['enableCompressedOutput'])) { |
|
| 642 | + @ob_start('ob_gzhandler'); |
|
| 643 | + } else { |
|
| 644 | + ob_start(); |
|
| 645 | + } |
|
| 621 | 646 | |
| 622 | 647 | // Send the file headers |
| 623 | 648 | header('Pragma: '); |
| 624 | 649 | header('Cache-Control: no-cache'); |
| 625 | - if (!isBrowser('gecko')) |
|
| 626 | - header('Content-Transfer-Encoding: binary'); |
|
| 650 | + if (!isBrowser('gecko')) { |
|
| 651 | + header('Content-Transfer-Encoding: binary'); |
|
| 652 | + } |
|
| 627 | 653 | header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 525600 * 60) . ' GMT'); |
| 628 | 654 | header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . 'GMT'); |
| 629 | 655 | header('Accept-Ranges: bytes'); |
| 630 | 656 | header('Connection: close'); |
| 631 | 657 | header('Content-Disposition: attachment; filename="' . $event['title'] . '.ics"'); |
| 632 | - if (empty($modSettings['enableCompressedOutput'])) |
|
| 633 | - header('Content-Length: ' . $smcFunc['strlen']($filecontents)); |
|
| 658 | + if (empty($modSettings['enableCompressedOutput'])) { |
|
| 659 | + header('Content-Length: ' . $smcFunc['strlen']($filecontents)); |
|
| 660 | + } |
|
| 634 | 661 | |
| 635 | 662 | // This is a calendar item! |
| 636 | 663 | header('Content-Type: text/calendar'); |
@@ -669,20 +696,17 @@ discard block |
||
| 669 | 696 | $context['sub_template'] = 'bcd'; |
| 670 | 697 | $context['linktree'][] = array('url' => $scripturl . '?action=clock;bcd', 'name' => 'BCD'); |
| 671 | 698 | $context['clockicons'] = smf_json_decode(base64_decode('eyJoMSI6WzIsMV0sImgyIjpbOCw0LDIsMV0sIm0xIjpbNCwyLDFdLCJtMiI6WzgsNCwyLDFdLCJzMSI6WzQsMiwxXSwiczIiOls4LDQsMiwxXX0='), true); |
| 672 | - } |
|
| 673 | - elseif (!$omfg && !isset($_REQUEST['time'])) |
|
| 699 | + } elseif (!$omfg && !isset($_REQUEST['time'])) |
|
| 674 | 700 | { |
| 675 | 701 | $context['sub_template'] = 'hms'; |
| 676 | 702 | $context['linktree'][] = array('url' => $scripturl . '?action=clock', 'name' => 'Binary'); |
| 677 | 703 | $context['clockicons'] = smf_json_decode(base64_decode('eyJoIjpbMTYsOCw0LDIsMV0sIm0iOlszMiwxNiw4LDQsMiwxXSwicyI6WzMyLDE2LDgsNCwyLDFdfQ'), true); |
| 678 | - } |
|
| 679 | - elseif ($omfg) |
|
| 704 | + } elseif ($omfg) |
|
| 680 | 705 | { |
| 681 | 706 | $context['sub_template'] = 'omfg'; |
| 682 | 707 | $context['linktree'][] = array('url' => $scripturl . '?action=clock;omfg', 'name' => 'OMFG'); |
| 683 | 708 | $context['clockicons'] = smf_json_decode(base64_decode('eyJ5ZWFyIjpbNjQsMzIsMTYsOCw0LDIsMV0sIm1vbnRoIjpbOCw0LDIsMV0sImRheSI6WzE2LDgsNCwyLDFdLCJob3VyIjpbMTYsOCw0LDIsMV0sIm1pbiI6WzMyLDE2LDgsNCwyLDFdLCJzZWMiOlszMiwxNiw4LDQsMiwxXX0='), true); |
| 684 | - } |
|
| 685 | - elseif (isset($_REQUEST['time'])) |
|
| 709 | + } elseif (isset($_REQUEST['time'])) |
|
| 686 | 710 | { |
| 687 | 711 | $context['sub_template'] = 'thetime'; |
| 688 | 712 | $time = getdate($_REQUEST['time'] == 'now' ? time() : (int) $_REQUEST['time']); |
@@ -736,12 +760,13 @@ discard block |
||
| 736 | 760 | ), |
| 737 | 761 | ); |
| 738 | 762 | |
| 739 | - foreach ($context['clockicons'] as $t => $vs) |
|
| 740 | - foreach ($vs as $v => $dumb) |
|
| 763 | + foreach ($context['clockicons'] as $t => $vs) { |
|
| 764 | + foreach ($vs as $v => $dumb) |
|
| 741 | 765 | { |
| 742 | 766 | if ($$t >= $v) |
| 743 | 767 | { |
| 744 | 768 | $$t -= $v; |
| 769 | + } |
|
| 745 | 770 | $context['clockicons'][$t][$v] = true; |
| 746 | 771 | } |
| 747 | 772 | } |