@@ -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 | * Clean the request variables - add html entities to GET and slashes if magic_quotes_gpc is Off. |
@@ -44,22 +45,26 @@ discard block |
||
| 44 | 45 | unset($GLOBALS['HTTP_POST_FILES'], $GLOBALS['HTTP_POST_FILES']); |
| 45 | 46 | |
| 46 | 47 | // These keys shouldn't be set...ever. |
| 47 | - if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS'])) |
|
| 48 | - die('Invalid request variable.'); |
|
| 48 | + if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS'])) { |
|
| 49 | + die('Invalid request variable.'); |
|
| 50 | + } |
|
| 49 | 51 | |
| 50 | 52 | // Same goes for numeric keys. |
| 51 | - foreach (array_merge(array_keys($_POST), array_keys($_GET), array_keys($_FILES)) as $key) |
|
| 52 | - if (is_numeric($key)) |
|
| 53 | + foreach (array_merge(array_keys($_POST), array_keys($_GET), array_keys($_FILES)) as $key) { |
|
| 54 | + if (is_numeric($key)) |
|
| 53 | 55 | die('Numeric request keys are invalid.'); |
| 56 | + } |
|
| 54 | 57 | |
| 55 | 58 | // Numeric keys in cookies are less of a problem. Just unset those. |
| 56 | - foreach ($_COOKIE as $key => $value) |
|
| 57 | - if (is_numeric($key)) |
|
| 59 | + foreach ($_COOKIE as $key => $value) { |
|
| 60 | + if (is_numeric($key)) |
|
| 58 | 61 | unset($_COOKIE[$key]); |
| 62 | + } |
|
| 59 | 63 | |
| 60 | 64 | // Get the correct query string. It may be in an environment variable... |
| 61 | - if (!isset($_SERVER['QUERY_STRING'])) |
|
| 62 | - $_SERVER['QUERY_STRING'] = getenv('QUERY_STRING'); |
|
| 65 | + if (!isset($_SERVER['QUERY_STRING'])) { |
|
| 66 | + $_SERVER['QUERY_STRING'] = getenv('QUERY_STRING'); |
|
| 67 | + } |
|
| 63 | 68 | |
| 64 | 69 | // It seems that sticking a URL after the query string is mighty common, well, it's evil - don't. |
| 65 | 70 | if (strpos($_SERVER['QUERY_STRING'], 'http') === 0) |
@@ -83,13 +88,14 @@ discard block |
||
| 83 | 88 | parse_str(preg_replace('/&(\w+)(?=&|$)/', '&$1=', strtr($_SERVER['QUERY_STRING'], array(';?' => '&', ';' => '&', '%00' => '', "\0" => ''))), $_GET); |
| 84 | 89 | |
| 85 | 90 | // Magic quotes still applies with parse_str - so clean it up. |
| 86 | - if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes'])) |
|
| 87 | - $_GET = $removeMagicQuoteFunction($_GET); |
|
| 88 | - } |
|
| 89 | - elseif (strpos(ini_get('arg_separator.input'), ';') !== false) |
|
| 91 | + if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes'])) { |
|
| 92 | + $_GET = $removeMagicQuoteFunction($_GET); |
|
| 93 | + } |
|
| 94 | + } elseif (strpos(ini_get('arg_separator.input'), ';') !== false) |
|
| 90 | 95 | { |
| 91 | - if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes'])) |
|
| 92 | - $_GET = $removeMagicQuoteFunction($_GET); |
|
| 96 | + if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes'])) { |
|
| 97 | + $_GET = $removeMagicQuoteFunction($_GET); |
|
| 98 | + } |
|
| 93 | 99 | |
| 94 | 100 | // Search engines will send action=profile%3Bu=1, which confuses PHP. |
| 95 | 101 | foreach ($_GET as $k => $v) |
@@ -102,8 +108,9 @@ discard block |
||
| 102 | 108 | for ($i = 1, $n = count($temp); $i < $n; $i++) |
| 103 | 109 | { |
| 104 | 110 | @list ($key, $val) = @explode('=', $temp[$i], 2); |
| 105 | - if (!isset($_GET[$key])) |
|
| 106 | - $_GET[$key] = $val; |
|
| 111 | + if (!isset($_GET[$key])) { |
|
| 112 | + $_GET[$key] = $val; |
|
| 113 | + } |
|
| 107 | 114 | } |
| 108 | 115 | } |
| 109 | 116 | |
@@ -120,18 +127,20 @@ discard block |
||
| 120 | 127 | if (!empty($_SERVER['REQUEST_URI'])) |
| 121 | 128 | { |
| 122 | 129 | // Remove the .html, assuming there is one. |
| 123 | - if (substr($_SERVER['REQUEST_URI'], strrpos($_SERVER['REQUEST_URI'], '.'), 4) == '.htm') |
|
| 124 | - $request = substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], '.')); |
|
| 125 | - else |
|
| 126 | - $request = $_SERVER['REQUEST_URI']; |
|
| 130 | + if (substr($_SERVER['REQUEST_URI'], strrpos($_SERVER['REQUEST_URI'], '.'), 4) == '.htm') { |
|
| 131 | + $request = substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], '.')); |
|
| 132 | + } else { |
|
| 133 | + $request = $_SERVER['REQUEST_URI']; |
|
| 134 | + } |
|
| 127 | 135 | |
| 128 | 136 | // @todo smflib. |
| 129 | 137 | // Replace 'index.php/a,b,c/d/e,f' with 'a=b,c&d=&e=f' and parse it into $_GET. |
| 130 | 138 | if (strpos($request, basename($scripturl) . '/') !== false) |
| 131 | 139 | { |
| 132 | 140 | parse_str(substr(preg_replace('/&(\w+)(?=&|$)/', '&$1=', strtr(preg_replace('~/([^,/]+),~', '/$1=', substr($request, strpos($request, basename($scripturl)) + strlen(basename($scripturl)))), '/', '&')), 1), $temp); |
| 133 | - if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes'])) |
|
| 134 | - $temp = $removeMagicQuoteFunction($temp); |
|
| 141 | + if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes'])) { |
|
| 142 | + $temp = $removeMagicQuoteFunction($temp); |
|
| 143 | + } |
|
| 135 | 144 | $_GET += $temp; |
| 136 | 145 | } |
| 137 | 146 | } |
@@ -142,9 +151,10 @@ discard block |
||
| 142 | 151 | $_ENV = $removeMagicQuoteFunction($_ENV); |
| 143 | 152 | $_POST = $removeMagicQuoteFunction($_POST); |
| 144 | 153 | $_COOKIE = $removeMagicQuoteFunction($_COOKIE); |
| 145 | - foreach ($_FILES as $k => $dummy) |
|
| 146 | - if (isset($_FILES[$k]['name'])) |
|
| 154 | + foreach ($_FILES as $k => $dummy) { |
|
| 155 | + if (isset($_FILES[$k]['name'])) |
|
| 147 | 156 | $_FILES[$k]['name'] = $removeMagicQuoteFunction($_FILES[$k]['name']); |
| 157 | + } |
|
| 148 | 158 | } |
| 149 | 159 | |
| 150 | 160 | // Add entities to GET. This is kinda like the slashes on everything else. |
@@ -160,11 +170,13 @@ discard block |
||
| 160 | 170 | $_REQUEST['board'] = (string) $_REQUEST['board']; |
| 161 | 171 | |
| 162 | 172 | // If there's a slash in it, we've got a start value! (old, compatible links.) |
| 163 | - if (strpos($_REQUEST['board'], '/') !== false) |
|
| 164 | - list ($_REQUEST['board'], $_REQUEST['start']) = explode('/', $_REQUEST['board']); |
|
| 173 | + if (strpos($_REQUEST['board'], '/') !== false) { |
|
| 174 | + list ($_REQUEST['board'], $_REQUEST['start']) = explode('/', $_REQUEST['board']); |
|
| 175 | + } |
|
| 165 | 176 | // Same idea, but dots. This is the currently used format - ?board=1.0... |
| 166 | - elseif (strpos($_REQUEST['board'], '.') !== false) |
|
| 167 | - list ($_REQUEST['board'], $_REQUEST['start']) = explode('.', $_REQUEST['board']); |
|
| 177 | + elseif (strpos($_REQUEST['board'], '.') !== false) { |
|
| 178 | + list ($_REQUEST['board'], $_REQUEST['start']) = explode('.', $_REQUEST['board']); |
|
| 179 | + } |
|
| 168 | 180 | // Now make absolutely sure it's a number. |
| 169 | 181 | $board = (int) $_REQUEST['board']; |
| 170 | 182 | $_REQUEST['start'] = isset($_REQUEST['start']) ? (int) $_REQUEST['start'] : 0; |
@@ -173,12 +185,14 @@ discard block |
||
| 173 | 185 | $_GET['board'] = $board; |
| 174 | 186 | } |
| 175 | 187 | // Well, $board is going to be a number no matter what. |
| 176 | - else |
|
| 177 | - $board = 0; |
|
| 188 | + else { |
|
| 189 | + $board = 0; |
|
| 190 | + } |
|
| 178 | 191 | |
| 179 | 192 | // If there's a threadid, it's probably an old YaBB SE link. Flow with it. |
| 180 | - if (isset($_REQUEST['threadid']) && !isset($_REQUEST['topic'])) |
|
| 181 | - $_REQUEST['topic'] = $_REQUEST['threadid']; |
|
| 193 | + if (isset($_REQUEST['threadid']) && !isset($_REQUEST['topic'])) { |
|
| 194 | + $_REQUEST['topic'] = $_REQUEST['threadid']; |
|
| 195 | + } |
|
| 182 | 196 | |
| 183 | 197 | // We've got topic! |
| 184 | 198 | if (isset($_REQUEST['topic'])) |
@@ -187,11 +201,13 @@ discard block |
||
| 187 | 201 | $_REQUEST['topic'] = (string) $_REQUEST['topic']; |
| 188 | 202 | |
| 189 | 203 | // Slash means old, beta style, formatting. That's okay though, the link should still work. |
| 190 | - if (strpos($_REQUEST['topic'], '/') !== false) |
|
| 191 | - list ($_REQUEST['topic'], $_REQUEST['start']) = explode('/', $_REQUEST['topic']); |
|
| 204 | + if (strpos($_REQUEST['topic'], '/') !== false) { |
|
| 205 | + list ($_REQUEST['topic'], $_REQUEST['start']) = explode('/', $_REQUEST['topic']); |
|
| 206 | + } |
|
| 192 | 207 | // Dots are useful and fun ;). This is ?topic=1.15. |
| 193 | - elseif (strpos($_REQUEST['topic'], '.') !== false) |
|
| 194 | - list ($_REQUEST['topic'], $_REQUEST['start']) = explode('.', $_REQUEST['topic']); |
|
| 208 | + elseif (strpos($_REQUEST['topic'], '.') !== false) { |
|
| 209 | + list ($_REQUEST['topic'], $_REQUEST['start']) = explode('.', $_REQUEST['topic']); |
|
| 210 | + } |
|
| 195 | 211 | |
| 196 | 212 | // Topic should always be an integer |
| 197 | 213 | $topic = $_GET['topic'] = $_REQUEST['topic'] = (int) $_REQUEST['topic']; |
@@ -220,21 +236,25 @@ discard block |
||
| 220 | 236 | $_REQUEST['start'] = $timestamp === 0 ? 0 : 'from' . $timestamp; |
| 221 | 237 | } |
| 222 | 238 | // ... or something invalid, in which case we reset it to 0. |
| 223 | - else |
|
| 224 | - $_REQUEST['start'] = 0; |
|
| 239 | + else { |
|
| 240 | + $_REQUEST['start'] = 0; |
|
| 241 | + } |
|
| 242 | + } else { |
|
| 243 | + $topic = 0; |
|
| 225 | 244 | } |
| 226 | - else |
|
| 227 | - $topic = 0; |
|
| 228 | 245 | |
| 229 | 246 | // There should be a $_REQUEST['start'], some at least. If you need to default to other than 0, use $_GET['start']. |
| 230 | - if (empty($_REQUEST['start']) || $_REQUEST['start'] < 0 || (int) $_REQUEST['start'] > 2147473647) |
|
| 231 | - $_REQUEST['start'] = 0; |
|
| 247 | + if (empty($_REQUEST['start']) || $_REQUEST['start'] < 0 || (int) $_REQUEST['start'] > 2147473647) { |
|
| 248 | + $_REQUEST['start'] = 0; |
|
| 249 | + } |
|
| 232 | 250 | |
| 233 | 251 | // The action needs to be a string and not an array or anything else |
| 234 | - if (isset($_REQUEST['action'])) |
|
| 235 | - $_REQUEST['action'] = (string) $_REQUEST['action']; |
|
| 236 | - if (isset($_GET['action'])) |
|
| 237 | - $_GET['action'] = (string) $_GET['action']; |
|
| 252 | + if (isset($_REQUEST['action'])) { |
|
| 253 | + $_REQUEST['action'] = (string) $_REQUEST['action']; |
|
| 254 | + } |
|
| 255 | + if (isset($_GET['action'])) { |
|
| 256 | + $_GET['action'] = (string) $_GET['action']; |
|
| 257 | + } |
|
| 238 | 258 | |
| 239 | 259 | // Some mail providers like to encode semicolons in activation URLs... |
| 240 | 260 | if (!empty($_REQUEST['action']) && substr($_SERVER['QUERY_STRING'], 0, 18) == 'action=activate%3b') |
@@ -260,29 +280,33 @@ discard block |
||
| 260 | 280 | $_SERVER['BAN_CHECK_IP'] = $_SERVER['REMOTE_ADDR']; |
| 261 | 281 | |
| 262 | 282 | // If we haven't specified how to handle Reverse Proxy IP headers, lets do what we always used to do. |
| 263 | - if (!isset($modSettings['proxy_ip_header'])) |
|
| 264 | - $modSettings['proxy_ip_header'] = 'autodetect'; |
|
| 283 | + if (!isset($modSettings['proxy_ip_header'])) { |
|
| 284 | + $modSettings['proxy_ip_header'] = 'autodetect'; |
|
| 285 | + } |
|
| 265 | 286 | |
| 266 | 287 | // Which headers are we going to check for Reverse Proxy IP headers? |
| 267 | - if ($modSettings['proxy_ip_header'] == 'disabled') |
|
| 268 | - $reverseIPheaders = array(); |
|
| 269 | - elseif ($modSettings['proxy_ip_header'] == 'autodetect') |
|
| 270 | - $reverseIPheaders = array('HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP'); |
|
| 271 | - else |
|
| 272 | - $reverseIPheaders = array($modSettings['proxy_ip_header']); |
|
| 288 | + if ($modSettings['proxy_ip_header'] == 'disabled') { |
|
| 289 | + $reverseIPheaders = array(); |
|
| 290 | + } elseif ($modSettings['proxy_ip_header'] == 'autodetect') { |
|
| 291 | + $reverseIPheaders = array('HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP'); |
|
| 292 | + } else { |
|
| 293 | + $reverseIPheaders = array($modSettings['proxy_ip_header']); |
|
| 294 | + } |
|
| 273 | 295 | |
| 274 | 296 | // Find the user's IP address. (but don't let it give you 'unknown'!) |
| 275 | 297 | foreach ($reverseIPheaders as $proxyIPheader) |
| 276 | 298 | { |
| 277 | 299 | // Ignore if this is not set. |
| 278 | - if (!isset($_SERVER[$proxyIPheader])) |
|
| 279 | - continue; |
|
| 300 | + if (!isset($_SERVER[$proxyIPheader])) { |
|
| 301 | + continue; |
|
| 302 | + } |
|
| 280 | 303 | |
| 281 | 304 | if (!empty($modSettings['proxy_ip_servers'])) |
| 282 | 305 | { |
| 283 | - foreach (explode(',', $modSettings['proxy_ip_servers']) as $proxy) |
|
| 284 | - if ($proxy == $_SERVER['REMOTE_ADDR'] || matchIPtoCIDR($_SERVER['REMOTE_ADDR'], $proxy)) |
|
| 306 | + foreach (explode(',', $modSettings['proxy_ip_servers']) as $proxy) { |
|
| 307 | + if ($proxy == $_SERVER['REMOTE_ADDR'] || matchIPtoCIDR($_SERVER['REMOTE_ADDR'], $proxy)) |
|
| 285 | 308 | continue; |
| 309 | + } |
|
| 286 | 310 | } |
| 287 | 311 | |
| 288 | 312 | // If there are commas, get the last one.. probably. |
@@ -302,8 +326,9 @@ discard block |
||
| 302 | 326 | |
| 303 | 327 | // Just incase we have a legacy IPv4 address. |
| 304 | 328 | // @ TODO: Convert to IPv6. |
| 305 | - if (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER[$proxyIPheader]) === 0) |
|
| 306 | - continue; |
|
| 329 | + if (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER[$proxyIPheader]) === 0) { |
|
| 330 | + continue; |
|
| 331 | + } |
|
| 307 | 332 | } |
| 308 | 333 | |
| 309 | 334 | continue; |
@@ -315,36 +340,40 @@ discard block |
||
| 315 | 340 | } |
| 316 | 341 | } |
| 317 | 342 | // Otherwise just use the only one. |
| 318 | - elseif (preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown|::1|fe80::|fc00::)~', $_SERVER[$proxyIPheader]) == 0 || preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown|::1|fe80::|fc00::)~', $_SERVER['REMOTE_ADDR']) != 0) |
|
| 319 | - $_SERVER['BAN_CHECK_IP'] = $_SERVER[$proxyIPheader]; |
|
| 320 | - elseif (!isValidIPv6($_SERVER[$proxyIPheader]) || preg_match('~::ffff:\d+\.\d+\.\d+\.\d+~', $_SERVER[$proxyIPheader]) !== 0) |
|
| 343 | + elseif (preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown|::1|fe80::|fc00::)~', $_SERVER[$proxyIPheader]) == 0 || preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown|::1|fe80::|fc00::)~', $_SERVER['REMOTE_ADDR']) != 0) { |
|
| 344 | + $_SERVER['BAN_CHECK_IP'] = $_SERVER[$proxyIPheader]; |
|
| 345 | + } elseif (!isValidIPv6($_SERVER[$proxyIPheader]) || preg_match('~::ffff:\d+\.\d+\.\d+\.\d+~', $_SERVER[$proxyIPheader]) !== 0) |
|
| 321 | 346 | { |
| 322 | 347 | $_SERVER[$proxyIPheader] = preg_replace('~^::ffff:(\d+\.\d+\.\d+\.\d+)~', '\1', $_SERVER[$proxyIPheader]); |
| 323 | 348 | |
| 324 | 349 | // Just incase we have a legacy IPv4 address. |
| 325 | 350 | // @ TODO: Convert to IPv6. |
| 326 | - if (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER[$proxyIPheader]) === 0) |
|
| 327 | - continue; |
|
| 351 | + if (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER[$proxyIPheader]) === 0) { |
|
| 352 | + continue; |
|
| 353 | + } |
|
| 328 | 354 | } |
| 329 | 355 | } |
| 330 | 356 | |
| 331 | 357 | // Make sure we know the URL of the current request. |
| 332 | - if (empty($_SERVER['REQUEST_URI'])) |
|
| 333 | - $_SERVER['REQUEST_URL'] = $scripturl . (!empty($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : ''); |
|
| 334 | - elseif (preg_match('~^([^/]+//[^/]+)~', $scripturl, $match) == 1) |
|
| 335 | - $_SERVER['REQUEST_URL'] = $match[1] . $_SERVER['REQUEST_URI']; |
|
| 336 | - else |
|
| 337 | - $_SERVER['REQUEST_URL'] = $_SERVER['REQUEST_URI']; |
|
| 358 | + if (empty($_SERVER['REQUEST_URI'])) { |
|
| 359 | + $_SERVER['REQUEST_URL'] = $scripturl . (!empty($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : ''); |
|
| 360 | + } elseif (preg_match('~^([^/]+//[^/]+)~', $scripturl, $match) == 1) { |
|
| 361 | + $_SERVER['REQUEST_URL'] = $match[1] . $_SERVER['REQUEST_URI']; |
|
| 362 | + } else { |
|
| 363 | + $_SERVER['REQUEST_URL'] = $_SERVER['REQUEST_URI']; |
|
| 364 | + } |
|
| 338 | 365 | |
| 339 | 366 | // And make sure HTTP_USER_AGENT is set. |
| 340 | 367 | $_SERVER['HTTP_USER_AGENT'] = isset($_SERVER['HTTP_USER_AGENT']) ? (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($smcFunc['db_unescape_string']($_SERVER['HTTP_USER_AGENT']), ENT_QUOTES) : htmlspecialchars($smcFunc['db_unescape_string']($_SERVER['HTTP_USER_AGENT']), ENT_QUOTES)) : ''; |
| 341 | 368 | |
| 342 | 369 | // Some final checking. |
| 343 | - if (!isValidIP($_SERVER['BAN_CHECK_IP'])) |
|
| 344 | - $_SERVER['BAN_CHECK_IP'] = ''; |
|
| 345 | - if ($_SERVER['REMOTE_ADDR'] == 'unknown') |
|
| 346 | - $_SERVER['REMOTE_ADDR'] = ''; |
|
| 347 | -} |
|
| 370 | + if (!isValidIP($_SERVER['BAN_CHECK_IP'])) { |
|
| 371 | + $_SERVER['BAN_CHECK_IP'] = ''; |
|
| 372 | + } |
|
| 373 | + if ($_SERVER['REMOTE_ADDR'] == 'unknown') { |
|
| 374 | + $_SERVER['REMOTE_ADDR'] = ''; |
|
| 375 | + } |
|
| 376 | + } |
|
| 348 | 377 | |
| 349 | 378 | /** |
| 350 | 379 | * Validates a IPv6 address. returns true if it is ipv6. |
@@ -355,8 +384,9 @@ discard block |
||
| 355 | 384 | function isValidIPv6($ip) |
| 356 | 385 | { |
| 357 | 386 | //looking for : |
| 358 | - if (strpos($ip, ':') === false) |
|
| 359 | - return false; |
|
| 387 | + if (strpos($ip, ':') === false) { |
|
| 388 | + return false; |
|
| 389 | + } |
|
| 360 | 390 | |
| 361 | 391 | //check valid address |
| 362 | 392 | return inet_pton($ip); |
@@ -373,15 +403,17 @@ discard block |
||
| 373 | 403 | static $expanded = array(); |
| 374 | 404 | |
| 375 | 405 | // Check if we have done this already. |
| 376 | - if (isset($expanded[$ip])) |
|
| 377 | - return $expanded[$ip]; |
|
| 406 | + if (isset($expanded[$ip])) { |
|
| 407 | + return $expanded[$ip]; |
|
| 408 | + } |
|
| 378 | 409 | |
| 379 | 410 | // Expand the IP out. |
| 380 | 411 | $expanded_ip = explode(':', expandIPv6($ip)); |
| 381 | 412 | |
| 382 | 413 | $new_ip = array(); |
| 383 | - foreach ($expanded_ip as $int) |
|
| 384 | - $new_ip[] = hexdec($int); |
|
| 414 | + foreach ($expanded_ip as $int) { |
|
| 415 | + $new_ip[] = hexdec($int); |
|
| 416 | + } |
|
| 385 | 417 | |
| 386 | 418 | // Save this incase of repeated use. |
| 387 | 419 | $expanded[$ip] = $new_ip; |
@@ -401,8 +433,9 @@ discard block |
||
| 401 | 433 | static $converted = array(); |
| 402 | 434 | |
| 403 | 435 | // Check if we have done this already. |
| 404 | - if (isset($converted[$addr])) |
|
| 405 | - return $converted[$addr]; |
|
| 436 | + if (isset($converted[$addr])) { |
|
| 437 | + return $converted[$addr]; |
|
| 438 | + } |
|
| 406 | 439 | |
| 407 | 440 | // Check if there are segments missing, insert if necessary. |
| 408 | 441 | if (strpos($addr, '::') !== false) |
@@ -412,18 +445,20 @@ discard block |
||
| 412 | 445 | $part[1] = explode(':', $part[1]); |
| 413 | 446 | $missing = array(); |
| 414 | 447 | |
| 415 | - for ($i = 0; $i < (8 - (count($part[0]) + count($part[1]))); $i++) |
|
| 416 | - array_push($missing, '0000'); |
|
| 448 | + for ($i = 0; $i < (8 - (count($part[0]) + count($part[1]))); $i++) { |
|
| 449 | + array_push($missing, '0000'); |
|
| 450 | + } |
|
| 417 | 451 | |
| 418 | 452 | $part = array_merge($part[0], $missing, $part[1]); |
| 453 | + } else { |
|
| 454 | + $part = explode(':', $addr); |
|
| 419 | 455 | } |
| 420 | - else |
|
| 421 | - $part = explode(':', $addr); |
|
| 422 | 456 | |
| 423 | 457 | // Pad each segment until it has 4 digits. |
| 424 | - foreach ($part as &$p) |
|
| 425 | - while (strlen($p) < 4) |
|
| 458 | + foreach ($part as &$p) { |
|
| 459 | + while (strlen($p) < 4) |
|
| 426 | 460 | $p = '0' . $p; |
| 461 | + } |
|
| 427 | 462 | |
| 428 | 463 | unset($p); |
| 429 | 464 | |
@@ -434,11 +469,12 @@ discard block |
||
| 434 | 469 | $converted[$addr] = $result; |
| 435 | 470 | |
| 436 | 471 | // Quick check to make sure the length is as expected. |
| 437 | - if (!$strict_check || strlen($result) == 39) |
|
| 438 | - return $result; |
|
| 439 | - else |
|
| 440 | - return false; |
|
| 441 | -} |
|
| 472 | + if (!$strict_check || strlen($result) == 39) { |
|
| 473 | + return $result; |
|
| 474 | + } else { |
|
| 475 | + return false; |
|
| 476 | + } |
|
| 477 | + } |
|
| 442 | 478 | |
| 443 | 479 | |
| 444 | 480 | /** |
@@ -469,15 +505,17 @@ discard block |
||
| 469 | 505 | { |
| 470 | 506 | global $smcFunc; |
| 471 | 507 | |
| 472 | - if (!is_array($var)) |
|
| 473 | - return $smcFunc['db_escape_string']($var); |
|
| 508 | + if (!is_array($var)) { |
|
| 509 | + return $smcFunc['db_escape_string']($var); |
|
| 510 | + } |
|
| 474 | 511 | |
| 475 | 512 | // Reindex the array with slashes. |
| 476 | 513 | $new_var = array(); |
| 477 | 514 | |
| 478 | 515 | // Add slashes to every element, even the indexes! |
| 479 | - foreach ($var as $k => $v) |
|
| 480 | - $new_var[$smcFunc['db_escape_string']($k)] = escapestring__recursive($v); |
|
| 516 | + foreach ($var as $k => $v) { |
|
| 517 | + $new_var[$smcFunc['db_escape_string']($k)] = escapestring__recursive($v); |
|
| 518 | + } |
|
| 481 | 519 | |
| 482 | 520 | return $new_var; |
| 483 | 521 | } |
@@ -497,12 +535,14 @@ discard block |
||
| 497 | 535 | { |
| 498 | 536 | global $smcFunc; |
| 499 | 537 | |
| 500 | - if (!is_array($var)) |
|
| 501 | - return isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($var, ENT_QUOTES) : htmlspecialchars($var, ENT_QUOTES); |
|
| 538 | + if (!is_array($var)) { |
|
| 539 | + return isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($var, ENT_QUOTES) : htmlspecialchars($var, ENT_QUOTES); |
|
| 540 | + } |
|
| 502 | 541 | |
| 503 | 542 | // Add the htmlspecialchars to every element. |
| 504 | - foreach ($var as $k => $v) |
|
| 505 | - $var[$k] = $level > 25 ? null : htmlspecialchars__recursive($v, $level + 1); |
|
| 543 | + foreach ($var as $k => $v) { |
|
| 544 | + $var[$k] = $level > 25 ? null : htmlspecialchars__recursive($v, $level + 1); |
|
| 545 | + } |
|
| 506 | 546 | |
| 507 | 547 | return $var; |
| 508 | 548 | } |
@@ -520,15 +560,17 @@ discard block |
||
| 520 | 560 | */ |
| 521 | 561 | function urldecode__recursive($var, $level = 0) |
| 522 | 562 | { |
| 523 | - if (!is_array($var)) |
|
| 524 | - return urldecode($var); |
|
| 563 | + if (!is_array($var)) { |
|
| 564 | + return urldecode($var); |
|
| 565 | + } |
|
| 525 | 566 | |
| 526 | 567 | // Reindex the array... |
| 527 | 568 | $new_var = array(); |
| 528 | 569 | |
| 529 | 570 | // Add the htmlspecialchars to every element. |
| 530 | - foreach ($var as $k => $v) |
|
| 531 | - $new_var[urldecode($k)] = $level > 25 ? null : urldecode__recursive($v, $level + 1); |
|
| 571 | + foreach ($var as $k => $v) { |
|
| 572 | + $new_var[urldecode($k)] = $level > 25 ? null : urldecode__recursive($v, $level + 1); |
|
| 573 | + } |
|
| 532 | 574 | |
| 533 | 575 | return $new_var; |
| 534 | 576 | } |
@@ -546,15 +588,17 @@ discard block |
||
| 546 | 588 | { |
| 547 | 589 | global $smcFunc; |
| 548 | 590 | |
| 549 | - if (!is_array($var)) |
|
| 550 | - return $smcFunc['db_unescape_string']($var); |
|
| 591 | + if (!is_array($var)) { |
|
| 592 | + return $smcFunc['db_unescape_string']($var); |
|
| 593 | + } |
|
| 551 | 594 | |
| 552 | 595 | // Reindex the array without slashes, this time. |
| 553 | 596 | $new_var = array(); |
| 554 | 597 | |
| 555 | 598 | // Strip the slashes from every element. |
| 556 | - foreach ($var as $k => $v) |
|
| 557 | - $new_var[$smcFunc['db_unescape_string']($k)] = unescapestring__recursive($v); |
|
| 599 | + foreach ($var as $k => $v) { |
|
| 600 | + $new_var[$smcFunc['db_unescape_string']($k)] = unescapestring__recursive($v); |
|
| 601 | + } |
|
| 558 | 602 | |
| 559 | 603 | return $new_var; |
| 560 | 604 | } |
@@ -572,15 +616,17 @@ discard block |
||
| 572 | 616 | */ |
| 573 | 617 | function stripslashes__recursive($var, $level = 0) |
| 574 | 618 | { |
| 575 | - if (!is_array($var)) |
|
| 576 | - return stripslashes($var); |
|
| 619 | + if (!is_array($var)) { |
|
| 620 | + return stripslashes($var); |
|
| 621 | + } |
|
| 577 | 622 | |
| 578 | 623 | // Reindex the array without slashes, this time. |
| 579 | 624 | $new_var = array(); |
| 580 | 625 | |
| 581 | 626 | // Strip the slashes from every element. |
| 582 | - foreach ($var as $k => $v) |
|
| 583 | - $new_var[stripslashes($k)] = $level > 25 ? null : stripslashes__recursive($v, $level + 1); |
|
| 627 | + foreach ($var as $k => $v) { |
|
| 628 | + $new_var[stripslashes($k)] = $level > 25 ? null : stripslashes__recursive($v, $level + 1); |
|
| 629 | + } |
|
| 584 | 630 | |
| 585 | 631 | return $new_var; |
| 586 | 632 | } |
@@ -601,12 +647,14 @@ discard block |
||
| 601 | 647 | global $smcFunc; |
| 602 | 648 | |
| 603 | 649 | // Remove spaces (32), tabs (9), returns (13, 10, and 11), nulls (0), and hard spaces. (160) |
| 604 | - if (!is_array($var)) |
|
| 605 | - return isset($smcFunc) ? $smcFunc['htmltrim']($var) : trim($var, ' ' . "\t\n\r\x0B" . '\0' . "\xA0"); |
|
| 650 | + if (!is_array($var)) { |
|
| 651 | + return isset($smcFunc) ? $smcFunc['htmltrim']($var) : trim($var, ' ' . "\t\n\r\x0B" . '\0' . "\xA0"); |
|
| 652 | + } |
|
| 606 | 653 | |
| 607 | 654 | // Go through all the elements and remove the whitespace. |
| 608 | - foreach ($var as $k => $v) |
|
| 609 | - $var[$k] = $level > 25 ? null : htmltrim__recursive($v, $level + 1); |
|
| 655 | + foreach ($var as $k => $v) { |
|
| 656 | + $var[$k] = $level > 25 ? null : htmltrim__recursive($v, $level + 1); |
|
| 657 | + } |
|
| 610 | 658 | |
| 611 | 659 | return $var; |
| 612 | 660 | } |
@@ -671,30 +719,37 @@ discard block |
||
| 671 | 719 | global $scripturl, $modSettings, $context; |
| 672 | 720 | |
| 673 | 721 | // If $scripturl is set to nothing, or the SID is not defined (SSI?) just quit. |
| 674 | - if ($scripturl == '' || !defined('SID')) |
|
| 675 | - return $buffer; |
|
| 722 | + if ($scripturl == '' || !defined('SID')) { |
|
| 723 | + return $buffer; |
|
| 724 | + } |
|
| 676 | 725 | |
| 677 | 726 | // Do nothing if the session is cookied, or they are a crawler - guests are caught by redirectexit(). This doesn't work below PHP 4.3.0, because it makes the output buffer bigger. |
| 678 | 727 | // @todo smflib |
| 679 | - if (empty($_COOKIE) && SID != '' && !isBrowser('possibly_robot')) |
|
| 680 | - $buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', '"' . $scripturl . '?' . SID . '&', $buffer); |
|
| 728 | + if (empty($_COOKIE) && SID != '' && !isBrowser('possibly_robot')) { |
|
| 729 | + $buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', '"' . $scripturl . '?' . SID . '&', $buffer); |
|
| 730 | + } |
|
| 681 | 731 | // Debugging templates, are we? |
| 682 | - elseif (isset($_GET['debug'])) |
|
| 683 | - $buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '\\??/', '"' . $scripturl . '?debug;', $buffer); |
|
| 732 | + elseif (isset($_GET['debug'])) { |
|
| 733 | + $buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '\\??/', '"' . $scripturl . '?debug;', $buffer); |
|
| 734 | + } |
|
| 684 | 735 | |
| 685 | 736 | // This should work even in 4.2.x, just not CGI without cgi.fix_pathinfo. |
| 686 | 737 | if (!empty($modSettings['queryless_urls']) && (!$context['server']['is_cgi'] || ini_get('cgi.fix_pathinfo') == 1 || @get_cfg_var('cgi.fix_pathinfo') == 1) && ($context['server']['is_apache'] || $context['server']['is_lighttpd'] || $context['server']['is_litespeed'])) |
| 687 | 738 | { |
| 688 | 739 | // Let's do something special for session ids! |
| 689 | - if (defined('SID') && SID != '') |
|
| 690 | - $buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m) |
|
| 740 | + if (defined('SID') && SID != '') { |
|
| 741 | + $buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m) |
|
| 691 | 742 | { |
| 692 | - global $scripturl; return '"' . $scripturl . "/" . strtr("$m[1]", '&;=', '//,') . ".html?" . SID . (isset($m[2]) ? $m[2] : "") . '"'; |
|
| 743 | + global $scripturl; |
|
| 744 | + } |
|
| 745 | + return '"' . $scripturl . "/" . strtr("$m[1]", '&;=', '//,') . ".html?" . SID . (isset($m[2]) ? $m[2] : "") . '"'; |
|
| 693 | 746 | }, $buffer); |
| 694 | - else |
|
| 695 | - $buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m) |
|
| 747 | + else { |
|
| 748 | + $buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m) |
|
| 696 | 749 | { |
| 697 | - global $scripturl; return '"' . $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? $m[2] : "") . '"'; |
|
| 750 | + global $scripturl; |
|
| 751 | + } |
|
| 752 | + return '"' . $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? $m[2] : "") . '"'; |
|
| 698 | 753 | }, $buffer); |
| 699 | 754 | } |
| 700 | 755 | |
@@ -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 | * This function makes sure the requested subaction does exists, if it doesn't, it sets a default action or. |
@@ -206,16 +207,18 @@ discard block |
||
| 206 | 207 | { |
| 207 | 208 | $all_zones = timezone_identifiers_list(); |
| 208 | 209 | // Make sure we set the value to the same as the printed value. |
| 209 | - foreach ($all_zones as $zone) |
|
| 210 | - $config_vars['default_timezone'][2][$zone] = $zone; |
|
| 210 | + foreach ($all_zones as $zone) { |
|
| 211 | + $config_vars['default_timezone'][2][$zone] = $zone; |
|
| 212 | + } |
|
| 213 | + } else { |
|
| 214 | + unset($config_vars['default_timezone']); |
|
| 211 | 215 | } |
| 212 | - else |
|
| 213 | - unset($config_vars['default_timezone']); |
|
| 214 | 216 | |
| 215 | 217 | call_integration_hook('integrate_modify_basic_settings', array(&$config_vars)); |
| 216 | 218 | |
| 217 | - if ($return_config) |
|
| 218 | - return $config_vars; |
|
| 219 | + if ($return_config) { |
|
| 220 | + return $config_vars; |
|
| 221 | + } |
|
| 219 | 222 | |
| 220 | 223 | // Saving? |
| 221 | 224 | if (isset($_GET['save'])) |
@@ -223,8 +226,9 @@ discard block |
||
| 223 | 226 | checkSession(); |
| 224 | 227 | |
| 225 | 228 | // Prevent absurd boundaries here - make it a day tops. |
| 226 | - if (isset($_POST['lastActive'])) |
|
| 227 | - $_POST['lastActive'] = min((int) $_POST['lastActive'], 1440); |
|
| 229 | + if (isset($_POST['lastActive'])) { |
|
| 230 | + $_POST['lastActive'] = min((int) $_POST['lastActive'], 1440); |
|
| 231 | + } |
|
| 228 | 232 | |
| 229 | 233 | call_integration_hook('integrate_save_basic_settings'); |
| 230 | 234 | |
@@ -269,8 +273,9 @@ discard block |
||
| 269 | 273 | |
| 270 | 274 | call_integration_hook('integrate_modify_bbc_settings', array(&$config_vars)); |
| 271 | 275 | |
| 272 | - if ($return_config) |
|
| 273 | - return $config_vars; |
|
| 276 | + if ($return_config) { |
|
| 277 | + return $config_vars; |
|
| 278 | + } |
|
| 274 | 279 | |
| 275 | 280 | // Setup the template. |
| 276 | 281 | require_once($sourcedir . '/ManageServer.php'); |
@@ -287,13 +292,15 @@ discard block |
||
| 287 | 292 | |
| 288 | 293 | // Clean up the tags. |
| 289 | 294 | $bbcTags = array(); |
| 290 | - foreach (parse_bbc(false) as $tag) |
|
| 291 | - $bbcTags[] = $tag['tag']; |
|
| 295 | + foreach (parse_bbc(false) as $tag) { |
|
| 296 | + $bbcTags[] = $tag['tag']; |
|
| 297 | + } |
|
| 292 | 298 | |
| 293 | - if (!isset($_POST['disabledBBC_enabledTags'])) |
|
| 294 | - $_POST['disabledBBC_enabledTags'] = array(); |
|
| 295 | - elseif (!is_array($_POST['disabledBBC_enabledTags'])) |
|
| 296 | - $_POST['disabledBBC_enabledTags'] = array($_POST['disabledBBC_enabledTags']); |
|
| 299 | + if (!isset($_POST['disabledBBC_enabledTags'])) { |
|
| 300 | + $_POST['disabledBBC_enabledTags'] = array(); |
|
| 301 | + } elseif (!is_array($_POST['disabledBBC_enabledTags'])) { |
|
| 302 | + $_POST['disabledBBC_enabledTags'] = array($_POST['disabledBBC_enabledTags']); |
|
| 303 | + } |
|
| 297 | 304 | // Work out what is actually disabled! |
| 298 | 305 | $_POST['disabledBBC'] = implode(',', array_diff($bbcTags, $_POST['disabledBBC_enabledTags'])); |
| 299 | 306 | |
@@ -337,8 +344,9 @@ discard block |
||
| 337 | 344 | |
| 338 | 345 | call_integration_hook('integrate_layout_settings', array(&$config_vars)); |
| 339 | 346 | |
| 340 | - if ($return_config) |
|
| 341 | - return $config_vars; |
|
| 347 | + if ($return_config) { |
|
| 348 | + return $config_vars; |
|
| 349 | + } |
|
| 342 | 350 | |
| 343 | 351 | // Saving? |
| 344 | 352 | if (isset($_GET['save'])) |
@@ -379,8 +387,9 @@ discard block |
||
| 379 | 387 | |
| 380 | 388 | call_integration_hook('integrate_likes_settings', array(&$config_vars)); |
| 381 | 389 | |
| 382 | - if ($return_config) |
|
| 383 | - return $config_vars; |
|
| 390 | + if ($return_config) { |
|
| 391 | + return $config_vars; |
|
| 392 | + } |
|
| 384 | 393 | |
| 385 | 394 | // Saving? |
| 386 | 395 | if (isset($_GET['save'])) |
@@ -418,8 +427,9 @@ discard block |
||
| 418 | 427 | |
| 419 | 428 | call_integration_hook('integrate_mentions_settings', array(&$config_vars)); |
| 420 | 429 | |
| 421 | - if ($return_config) |
|
| 422 | - return $config_vars; |
|
| 430 | + if ($return_config) { |
|
| 431 | + return $config_vars; |
|
| 432 | + } |
|
| 423 | 433 | |
| 424 | 434 | // Saving? |
| 425 | 435 | if (isset($_GET['save'])) |
@@ -463,8 +473,8 @@ discard block |
||
| 463 | 473 | 'enable' => array('check', 'warning_enable'), |
| 464 | 474 | ); |
| 465 | 475 | |
| 466 | - if (!empty($modSettings['warning_settings']) && $currently_enabled) |
|
| 467 | - $config_vars += array( |
|
| 476 | + if (!empty($modSettings['warning_settings']) && $currently_enabled) { |
|
| 477 | + $config_vars += array( |
|
| 468 | 478 | '', |
| 469 | 479 | array('int', 'warning_watch', 'subtext' => $txt['setting_warning_watch_note'] . ' ' . $txt['zero_to_disable']), |
| 470 | 480 | 'moderate' => array('int', 'warning_moderate', 'subtext' => $txt['setting_warning_moderate_note'] . ' ' . $txt['zero_to_disable']), |
@@ -473,15 +483,18 @@ discard block |
||
| 473 | 483 | 'rem2' => array('int', 'warning_decrement', 'subtext' => $txt['setting_warning_decrement_note'] . ' ' . $txt['zero_to_disable']), |
| 474 | 484 | array('permissions', 'view_warning'), |
| 475 | 485 | ); |
| 486 | + } |
|
| 476 | 487 | |
| 477 | 488 | call_integration_hook('integrate_warning_settings', array(&$config_vars)); |
| 478 | 489 | |
| 479 | - if ($return_config) |
|
| 480 | - return $config_vars; |
|
| 490 | + if ($return_config) { |
|
| 491 | + return $config_vars; |
|
| 492 | + } |
|
| 481 | 493 | |
| 482 | 494 | // Cannot use moderation if post moderation is not enabled. |
| 483 | - if (!$modSettings['postmod_active']) |
|
| 484 | - unset($config_vars['moderate']); |
|
| 495 | + if (!$modSettings['postmod_active']) { |
|
| 496 | + unset($config_vars['moderate']); |
|
| 497 | + } |
|
| 485 | 498 | |
| 486 | 499 | // Will need the utility functions from here. |
| 487 | 500 | require_once($sourcedir . '/ManageServer.php'); |
@@ -506,16 +519,16 @@ discard block |
||
| 506 | 519 | 'warning_watch' => 10, |
| 507 | 520 | 'warning_mute' => 60, |
| 508 | 521 | ); |
| 509 | - if ($modSettings['postmod_active']) |
|
| 510 | - $vars['warning_moderate'] = 35; |
|
| 522 | + if ($modSettings['postmod_active']) { |
|
| 523 | + $vars['warning_moderate'] = 35; |
|
| 524 | + } |
|
| 511 | 525 | |
| 512 | 526 | foreach ($vars as $var => $value) |
| 513 | 527 | { |
| 514 | 528 | $config_vars[] = array('int', $var); |
| 515 | 529 | $_POST[$var] = $value; |
| 516 | 530 | } |
| 517 | - } |
|
| 518 | - else |
|
| 531 | + } else |
|
| 519 | 532 | { |
| 520 | 533 | $_POST['warning_watch'] = min($_POST['warning_watch'], 100); |
| 521 | 534 | $_POST['warning_moderate'] = $modSettings['postmod_active'] ? min($_POST['warning_moderate'], 100) : 0; |
@@ -603,8 +616,9 @@ discard block |
||
| 603 | 616 | |
| 604 | 617 | call_integration_hook('integrate_spam_settings', array(&$config_vars)); |
| 605 | 618 | |
| 606 | - if ($return_config) |
|
| 607 | - return $config_vars; |
|
| 619 | + if ($return_config) { |
|
| 620 | + return $config_vars; |
|
| 621 | + } |
|
| 608 | 622 | |
| 609 | 623 | // You need to be an admin to edit settings! |
| 610 | 624 | isAllowedTo('admin_forum'); |
@@ -638,8 +652,9 @@ discard block |
||
| 638 | 652 | |
| 639 | 653 | if (empty($context['qa_by_lang'][strtr($language, array('-utf8' => ''))]) && !empty($context['question_answers'])) |
| 640 | 654 | { |
| 641 | - if (empty($context['settings_insert_above'])) |
|
| 642 | - $context['settings_insert_above'] = ''; |
|
| 655 | + if (empty($context['settings_insert_above'])) { |
|
| 656 | + $context['settings_insert_above'] = ''; |
|
| 657 | + } |
|
| 643 | 658 | |
| 644 | 659 | $context['settings_insert_above'] .= '<div class="noticebox">' . sprintf($txt['question_not_defined'], $context['languages'][$language]['name']) . '</div>'; |
| 645 | 660 | } |
@@ -682,8 +697,9 @@ discard block |
||
| 682 | 697 | $_POST['pm_spam_settings'] = (int) $_POST['max_pm_recipients'] . ',' . (int) $_POST['pm_posts_verification'] . ',' . (int) $_POST['pm_posts_per_hour']; |
| 683 | 698 | |
| 684 | 699 | // Hack in guest requiring verification! |
| 685 | - if (empty($_POST['posts_require_captcha']) && !empty($_POST['guests_require_captcha'])) |
|
| 686 | - $_POST['posts_require_captcha'] = -1; |
|
| 700 | + if (empty($_POST['posts_require_captcha']) && !empty($_POST['guests_require_captcha'])) { |
|
| 701 | + $_POST['posts_require_captcha'] = -1; |
|
| 702 | + } |
|
| 687 | 703 | |
| 688 | 704 | $save_vars = $config_vars; |
| 689 | 705 | unset($save_vars['pm1'], $save_vars['pm2'], $save_vars['pm3'], $save_vars['guest_verify']); |
@@ -700,14 +716,16 @@ discard block |
||
| 700 | 716 | foreach ($context['qa_languages'] as $lang_id => $dummy) |
| 701 | 717 | { |
| 702 | 718 | // If we had some questions for this language before, but don't now, delete everything from that language. |
| 703 | - if ((!isset($_POST['question'][$lang_id]) || !is_array($_POST['question'][$lang_id])) && !empty($context['qa_by_lang'][$lang_id])) |
|
| 704 | - $changes['delete'] = array_merge($questions['delete'], $context['qa_by_lang'][$lang_id]); |
|
| 719 | + if ((!isset($_POST['question'][$lang_id]) || !is_array($_POST['question'][$lang_id])) && !empty($context['qa_by_lang'][$lang_id])) { |
|
| 720 | + $changes['delete'] = array_merge($questions['delete'], $context['qa_by_lang'][$lang_id]); |
|
| 721 | + } |
|
| 705 | 722 | |
| 706 | 723 | // Now step through and see if any existing questions no longer exist. |
| 707 | - if (!empty($context['qa_by_lang'][$lang_id])) |
|
| 708 | - foreach ($context['qa_by_lang'][$lang_id] as $q_id) |
|
| 724 | + if (!empty($context['qa_by_lang'][$lang_id])) { |
|
| 725 | + foreach ($context['qa_by_lang'][$lang_id] as $q_id) |
|
| 709 | 726 | if (empty($_POST['question'][$lang_id][$q_id])) |
| 710 | 727 | $changes['delete'][] = $q_id; |
| 728 | + } |
|
| 711 | 729 | |
| 712 | 730 | // Now let's see if there are new questions or ones that need updating. |
| 713 | 731 | if (isset($_POST['question'][$lang_id])) |
@@ -716,14 +734,16 @@ discard block |
||
| 716 | 734 | { |
| 717 | 735 | // Ignore junky ids. |
| 718 | 736 | $q_id = (int) $q_id; |
| 719 | - if ($q_id <= 0) |
|
| 720 | - continue; |
|
| 737 | + if ($q_id <= 0) { |
|
| 738 | + continue; |
|
| 739 | + } |
|
| 721 | 740 | |
| 722 | 741 | // Check the question isn't empty (because they want to delete it?) |
| 723 | 742 | if (empty($question) || trim($question) == '') |
| 724 | 743 | { |
| 725 | - if (isset($context['question_answers'][$q_id])) |
|
| 726 | - $changes['delete'][] = $q_id; |
|
| 744 | + if (isset($context['question_answers'][$q_id])) { |
|
| 745 | + $changes['delete'][] = $q_id; |
|
| 746 | + } |
|
| 727 | 747 | continue; |
| 728 | 748 | } |
| 729 | 749 | $question = $smcFunc['htmlspecialchars'](trim($question)); |
@@ -731,19 +751,22 @@ discard block |
||
| 731 | 751 | // Get the answers. Firstly check there actually might be some. |
| 732 | 752 | if (!isset($_POST['answer'][$lang_id][$q_id]) || !is_array($_POST['answer'][$lang_id][$q_id])) |
| 733 | 753 | { |
| 734 | - if (isset($context['question_answers'][$q_id])) |
|
| 735 | - $changes['delete'][] = $q_id; |
|
| 754 | + if (isset($context['question_answers'][$q_id])) { |
|
| 755 | + $changes['delete'][] = $q_id; |
|
| 756 | + } |
|
| 736 | 757 | continue; |
| 737 | 758 | } |
| 738 | 759 | // Now get them and check that they might be viable. |
| 739 | 760 | $answers = array(); |
| 740 | - foreach ($_POST['answer'][$lang_id][$q_id] as $answer) |
|
| 741 | - if (!empty($answer) && trim($answer) !== '') |
|
| 761 | + foreach ($_POST['answer'][$lang_id][$q_id] as $answer) { |
|
| 762 | + if (!empty($answer) && trim($answer) !== '') |
|
| 742 | 763 | $answers[] = $smcFunc['htmlspecialchars'](trim($answer)); |
| 764 | + } |
|
| 743 | 765 | if (empty($answers)) |
| 744 | 766 | { |
| 745 | - if (isset($context['question_answers'][$q_id])) |
|
| 746 | - $changes['delete'][] = $q_id; |
|
| 767 | + if (isset($context['question_answers'][$q_id])) { |
|
| 768 | + $changes['delete'][] = $q_id; |
|
| 769 | + } |
|
| 747 | 770 | continue; |
| 748 | 771 | } |
| 749 | 772 | $answers = $smcFunc['json_encode']($answers); |
@@ -753,16 +776,17 @@ discard block |
||
| 753 | 776 | { |
| 754 | 777 | // New question. Now, we don't want to randomly consume ids, so we'll set those, rather than trusting the browser's supplied ids. |
| 755 | 778 | $changes['insert'][] = array($lang_id, $question, $answers); |
| 756 | - } |
|
| 757 | - else |
|
| 779 | + } else |
|
| 758 | 780 | { |
| 759 | 781 | // It's an existing question. Let's see what's changed, if anything. |
| 760 | - if ($lang_id != $context['question_answers'][$q_id]['lngfile'] || $question != $context['question_answers'][$q_id]['question'] || $answers != $context['question_answers'][$q_id]['answers']) |
|
| 761 | - $changes['replace'][$q_id] = array('lngfile' => $lang_id, 'question' => $question, 'answers' => $answers); |
|
| 782 | + if ($lang_id != $context['question_answers'][$q_id]['lngfile'] || $question != $context['question_answers'][$q_id]['question'] || $answers != $context['question_answers'][$q_id]['answers']) { |
|
| 783 | + $changes['replace'][$q_id] = array('lngfile' => $lang_id, 'question' => $question, 'answers' => $answers); |
|
| 784 | + } |
|
| 762 | 785 | } |
| 763 | 786 | |
| 764 | - if (!isset($qs_per_lang[$lang_id])) |
|
| 765 | - $qs_per_lang[$lang_id] = 0; |
|
| 787 | + if (!isset($qs_per_lang[$lang_id])) { |
|
| 788 | + $qs_per_lang[$lang_id] = 0; |
|
| 789 | + } |
|
| 766 | 790 | $qs_per_lang[$lang_id]++; |
| 767 | 791 | } |
| 768 | 792 | } |
@@ -812,8 +836,9 @@ discard block |
||
| 812 | 836 | |
| 813 | 837 | // Lastly, the count of messages needs to be no more than the lowest number of questions for any one language. |
| 814 | 838 | $count_questions = empty($qs_per_lang) ? 0 : min($qs_per_lang); |
| 815 | - if (empty($count_questions) || $_POST['qa_verification_number'] > $count_questions) |
|
| 816 | - $_POST['qa_verification_number'] = $count_questions; |
|
| 839 | + if (empty($count_questions) || $_POST['qa_verification_number'] > $count_questions) { |
|
| 840 | + $_POST['qa_verification_number'] = $count_questions; |
|
| 841 | + } |
|
| 817 | 842 | |
| 818 | 843 | call_integration_hook('integrate_save_spam_settings', array(&$save_vars)); |
| 819 | 844 | |
@@ -828,24 +853,27 @@ discard block |
||
| 828 | 853 | |
| 829 | 854 | $character_range = array_merge(range('A', 'H'), array('K', 'M', 'N', 'P', 'R'), range('T', 'Y')); |
| 830 | 855 | $_SESSION['visual_verification_code'] = ''; |
| 831 | - for ($i = 0; $i < 6; $i++) |
|
| 832 | - $_SESSION['visual_verification_code'] .= $character_range[array_rand($character_range)]; |
|
| 856 | + for ($i = 0; $i < 6; $i++) { |
|
| 857 | + $_SESSION['visual_verification_code'] .= $character_range[array_rand($character_range)]; |
|
| 858 | + } |
|
| 833 | 859 | |
| 834 | 860 | // Some javascript for CAPTCHA. |
| 835 | 861 | $context['settings_post_javascript'] = ''; |
| 836 | - if ($context['use_graphic_library']) |
|
| 837 | - $context['settings_post_javascript'] .= ' |
|
| 862 | + if ($context['use_graphic_library']) { |
|
| 863 | + $context['settings_post_javascript'] .= ' |
|
| 838 | 864 | function refreshImages() |
| 839 | 865 | { |
| 840 | 866 | var imageType = document.getElementById(\'visual_verification_type\').value; |
| 841 | 867 | document.getElementById(\'verification_image\').src = \'' . $context['verification_image_href'] . ';type=\' + imageType; |
| 842 | 868 | }'; |
| 869 | + } |
|
| 843 | 870 | |
| 844 | 871 | // Show the image itself, or text saying we can't. |
| 845 | - if ($context['use_graphic_library']) |
|
| 846 | - $config_vars['vv']['postinput'] = '<br><img src="' . $context['verification_image_href'] . ';type=' . (empty($modSettings['visual_verification_type']) ? 0 : $modSettings['visual_verification_type']) . '" alt="' . $txt['setting_image_verification_sample'] . '" id="verification_image"><br>'; |
|
| 847 | - else |
|
| 848 | - $config_vars['vv']['postinput'] = '<br><span class="smalltext">' . $txt['setting_image_verification_nogd'] . '</span>'; |
|
| 872 | + if ($context['use_graphic_library']) { |
|
| 873 | + $config_vars['vv']['postinput'] = '<br><img src="' . $context['verification_image_href'] . ';type=' . (empty($modSettings['visual_verification_type']) ? 0 : $modSettings['visual_verification_type']) . '" alt="' . $txt['setting_image_verification_sample'] . '" id="verification_image"><br>'; |
|
| 874 | + } else { |
|
| 875 | + $config_vars['vv']['postinput'] = '<br><span class="smalltext">' . $txt['setting_image_verification_nogd'] . '</span>'; |
|
| 876 | + } |
|
| 849 | 877 | |
| 850 | 878 | // Hack for PM spam settings. |
| 851 | 879 | list ($modSettings['max_pm_recipients'], $modSettings['pm_posts_verification'], $modSettings['pm_posts_per_hour']) = explode(',', $modSettings['pm_spam_settings']); |
@@ -855,9 +883,10 @@ discard block |
||
| 855 | 883 | $modSettings['posts_require_captcha'] = !isset($modSettings['posts_require_captcha']) || $modSettings['posts_require_captcha'] == -1 ? 0 : $modSettings['posts_require_captcha']; |
| 856 | 884 | |
| 857 | 885 | // Some minor javascript for the guest post setting. |
| 858 | - if ($modSettings['posts_require_captcha']) |
|
| 859 | - $context['settings_post_javascript'] .= ' |
|
| 886 | + if ($modSettings['posts_require_captcha']) { |
|
| 887 | + $context['settings_post_javascript'] .= ' |
|
| 860 | 888 | document.getElementById(\'guests_require_captcha\').disabled = true;'; |
| 889 | + } |
|
| 861 | 890 | |
| 862 | 891 | // And everything else. |
| 863 | 892 | $context['post_url'] = $scripturl . '?action=admin;area=antispam;save'; |
@@ -904,8 +933,9 @@ discard block |
||
| 904 | 933 | |
| 905 | 934 | call_integration_hook('integrate_signature_settings', array(&$config_vars)); |
| 906 | 935 | |
| 907 | - if ($return_config) |
|
| 908 | - return $config_vars; |
|
| 936 | + if ($return_config) { |
|
| 937 | + return $config_vars; |
|
| 938 | + } |
|
| 909 | 939 | |
| 910 | 940 | // Setup the template. |
| 911 | 941 | $context['page_title'] = $txt['signature_settings']; |
@@ -960,8 +990,9 @@ discard block |
||
| 960 | 990 | $sig = strtr($row['signature'], array('<br>' => "\n")); |
| 961 | 991 | |
| 962 | 992 | // Max characters... |
| 963 | - if (!empty($sig_limits[1])) |
|
| 964 | - $sig = $smcFunc['substr']($sig, 0, $sig_limits[1]); |
|
| 993 | + if (!empty($sig_limits[1])) { |
|
| 994 | + $sig = $smcFunc['substr']($sig, 0, $sig_limits[1]); |
|
| 995 | + } |
|
| 965 | 996 | // Max lines... |
| 966 | 997 | if (!empty($sig_limits[2])) |
| 967 | 998 | { |
@@ -971,8 +1002,9 @@ discard block |
||
| 971 | 1002 | if ($sig[$i] == "\n") |
| 972 | 1003 | { |
| 973 | 1004 | $count++; |
| 974 | - if ($count >= $sig_limits[2]) |
|
| 975 | - $sig = substr($sig, 0, $i) . strtr(substr($sig, $i), array("\n" => ' ')); |
|
| 1005 | + if ($count >= $sig_limits[2]) { |
|
| 1006 | + $sig = substr($sig, 0, $i) . strtr(substr($sig, $i), array("\n" => ' ')); |
|
| 1007 | + } |
|
| 976 | 1008 | } |
| 977 | 1009 | } |
| 978 | 1010 | } |
@@ -983,17 +1015,19 @@ discard block |
||
| 983 | 1015 | { |
| 984 | 1016 | $limit_broke = 0; |
| 985 | 1017 | // Attempt to allow all sizes of abuse, so to speak. |
| 986 | - if ($matches[2][$ind] == 'px' && $size > $sig_limits[7]) |
|
| 987 | - $limit_broke = $sig_limits[7] . 'px'; |
|
| 988 | - elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75)) |
|
| 989 | - $limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt'; |
|
| 990 | - elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16)) |
|
| 991 | - $limit_broke = ((float) $sig_limits[7] / 16) . 'em'; |
|
| 992 | - elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18) |
|
| 993 | - $limit_broke = 'large'; |
|
| 994 | - |
|
| 995 | - if ($limit_broke) |
|
| 996 | - $sig = str_replace($matches[0][$ind], '[size=' . $sig_limits[7] . 'px', $sig); |
|
| 1018 | + if ($matches[2][$ind] == 'px' && $size > $sig_limits[7]) { |
|
| 1019 | + $limit_broke = $sig_limits[7] . 'px'; |
|
| 1020 | + } elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75)) { |
|
| 1021 | + $limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt'; |
|
| 1022 | + } elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16)) { |
|
| 1023 | + $limit_broke = ((float) $sig_limits[7] / 16) . 'em'; |
|
| 1024 | + } elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18) { |
|
| 1025 | + $limit_broke = 'large'; |
|
| 1026 | + } |
|
| 1027 | + |
|
| 1028 | + if ($limit_broke) { |
|
| 1029 | + $sig = str_replace($matches[0][$ind], '[size=' . $sig_limits[7] . 'px', $sig); |
|
| 1030 | + } |
|
| 997 | 1031 | } |
| 998 | 1032 | } |
| 999 | 1033 | |
@@ -1049,32 +1083,34 @@ discard block |
||
| 1049 | 1083 | $img_offset = false; |
| 1050 | 1084 | } |
| 1051 | 1085 | } |
| 1086 | + } else { |
|
| 1087 | + $replaces[$image] = ''; |
|
| 1052 | 1088 | } |
| 1053 | - else |
|
| 1054 | - $replaces[$image] = ''; |
|
| 1055 | 1089 | |
| 1056 | 1090 | continue; |
| 1057 | 1091 | } |
| 1058 | 1092 | |
| 1059 | 1093 | // Does it have predefined restraints? Width first. |
| 1060 | - if ($matches[6][$key]) |
|
| 1061 | - $matches[2][$key] = $matches[6][$key]; |
|
| 1094 | + if ($matches[6][$key]) { |
|
| 1095 | + $matches[2][$key] = $matches[6][$key]; |
|
| 1096 | + } |
|
| 1062 | 1097 | if ($matches[2][$key] && $sig_limits[5] && $matches[2][$key] > $sig_limits[5]) |
| 1063 | 1098 | { |
| 1064 | 1099 | $width = $sig_limits[5]; |
| 1065 | 1100 | $matches[4][$key] = $matches[4][$key] * ($width / $matches[2][$key]); |
| 1101 | + } elseif ($matches[2][$key]) { |
|
| 1102 | + $width = $matches[2][$key]; |
|
| 1066 | 1103 | } |
| 1067 | - elseif ($matches[2][$key]) |
|
| 1068 | - $width = $matches[2][$key]; |
|
| 1069 | 1104 | // ... and height. |
| 1070 | 1105 | if ($matches[4][$key] && $sig_limits[6] && $matches[4][$key] > $sig_limits[6]) |
| 1071 | 1106 | { |
| 1072 | 1107 | $height = $sig_limits[6]; |
| 1073 | - if ($width != -1) |
|
| 1074 | - $width = $width * ($height / $matches[4][$key]); |
|
| 1108 | + if ($width != -1) { |
|
| 1109 | + $width = $width * ($height / $matches[4][$key]); |
|
| 1110 | + } |
|
| 1111 | + } elseif ($matches[4][$key]) { |
|
| 1112 | + $height = $matches[4][$key]; |
|
| 1075 | 1113 | } |
| 1076 | - elseif ($matches[4][$key]) |
|
| 1077 | - $height = $matches[4][$key]; |
|
| 1078 | 1114 | |
| 1079 | 1115 | // If the dimensions are still not fixed - we need to check the actual image. |
| 1080 | 1116 | if (($width == -1 && $sig_limits[5]) || ($height == -1 && $sig_limits[6])) |
@@ -1092,12 +1128,13 @@ discard block |
||
| 1092 | 1128 | if ($sizes[1] > $sig_limits[6] && $sig_limits[6]) |
| 1093 | 1129 | { |
| 1094 | 1130 | $height = $sig_limits[6]; |
| 1095 | - if ($width == -1) |
|
| 1096 | - $width = $sizes[0]; |
|
| 1131 | + if ($width == -1) { |
|
| 1132 | + $width = $sizes[0]; |
|
| 1133 | + } |
|
| 1097 | 1134 | $width = $width * ($height / $sizes[1]); |
| 1135 | + } elseif ($width != -1) { |
|
| 1136 | + $height = $sizes[1]; |
|
| 1098 | 1137 | } |
| 1099 | - elseif ($width != -1) |
|
| 1100 | - $height = $sizes[1]; |
|
| 1101 | 1138 | } |
| 1102 | 1139 | } |
| 1103 | 1140 | |
@@ -1110,8 +1147,9 @@ discard block |
||
| 1110 | 1147 | // Record that we got one. |
| 1111 | 1148 | $image_count_holder[$image] = isset($image_count_holder[$image]) ? $image_count_holder[$image] + 1 : 1; |
| 1112 | 1149 | } |
| 1113 | - if (!empty($replaces)) |
|
| 1114 | - $sig = str_replace(array_keys($replaces), array_values($replaces), $sig); |
|
| 1150 | + if (!empty($replaces)) { |
|
| 1151 | + $sig = str_replace(array_keys($replaces), array_values($replaces), $sig); |
|
| 1152 | + } |
|
| 1115 | 1153 | } |
| 1116 | 1154 | } |
| 1117 | 1155 | // Try to fix disabled tags. |
@@ -1123,18 +1161,20 @@ discard block |
||
| 1123 | 1161 | |
| 1124 | 1162 | $sig = strtr($sig, array("\n" => '<br>')); |
| 1125 | 1163 | call_integration_hook('integrate_apply_signature_settings', array(&$sig, $sig_limits, $disabledTags)); |
| 1126 | - if ($sig != $row['signature']) |
|
| 1127 | - $changes[$row['id_member']] = $sig; |
|
| 1164 | + if ($sig != $row['signature']) { |
|
| 1165 | + $changes[$row['id_member']] = $sig; |
|
| 1166 | + } |
|
| 1167 | + } |
|
| 1168 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 1169 | + $done = true; |
|
| 1128 | 1170 | } |
| 1129 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 1130 | - $done = true; |
|
| 1131 | 1171 | $smcFunc['db_free_result']($request); |
| 1132 | 1172 | |
| 1133 | 1173 | // Do we need to delete what we have? |
| 1134 | 1174 | if (!empty($changes)) |
| 1135 | 1175 | { |
| 1136 | - foreach ($changes as $id => $sig) |
|
| 1137 | - $smcFunc['db_query']('', ' |
|
| 1176 | + foreach ($changes as $id => $sig) { |
|
| 1177 | + $smcFunc['db_query']('', ' |
|
| 1138 | 1178 | UPDATE {db_prefix}members |
| 1139 | 1179 | SET signature = {string:signature} |
| 1140 | 1180 | WHERE id_member = {int:id_member}', |
@@ -1143,11 +1183,13 @@ discard block |
||
| 1143 | 1183 | 'signature' => $sig, |
| 1144 | 1184 | ) |
| 1145 | 1185 | ); |
| 1186 | + } |
|
| 1146 | 1187 | } |
| 1147 | 1188 | |
| 1148 | 1189 | $_GET['step'] += 50; |
| 1149 | - if (!$done) |
|
| 1150 | - pauseSignatureApplySettings(); |
|
| 1190 | + if (!$done) { |
|
| 1191 | + pauseSignatureApplySettings(); |
|
| 1192 | + } |
|
| 1151 | 1193 | } |
| 1152 | 1194 | $settings_applied = true; |
| 1153 | 1195 | } |
@@ -1165,8 +1207,9 @@ discard block |
||
| 1165 | 1207 | ); |
| 1166 | 1208 | |
| 1167 | 1209 | // Temporarily make each setting a modSetting! |
| 1168 | - foreach ($context['signature_settings'] as $key => $value) |
|
| 1169 | - $modSettings['signature_' . $key] = $value; |
|
| 1210 | + foreach ($context['signature_settings'] as $key => $value) { |
|
| 1211 | + $modSettings['signature_' . $key] = $value; |
|
| 1212 | + } |
|
| 1170 | 1213 | |
| 1171 | 1214 | // Make sure we check the right tags! |
| 1172 | 1215 | $modSettings['bbc_disabled_signature_bbc'] = $disabledTags; |
@@ -1178,23 +1221,26 @@ discard block |
||
| 1178 | 1221 | |
| 1179 | 1222 | // Clean up the tag stuff! |
| 1180 | 1223 | $bbcTags = array(); |
| 1181 | - foreach (parse_bbc(false) as $tag) |
|
| 1182 | - $bbcTags[] = $tag['tag']; |
|
| 1224 | + foreach (parse_bbc(false) as $tag) { |
|
| 1225 | + $bbcTags[] = $tag['tag']; |
|
| 1226 | + } |
|
| 1183 | 1227 | |
| 1184 | - if (!isset($_POST['signature_bbc_enabledTags'])) |
|
| 1185 | - $_POST['signature_bbc_enabledTags'] = array(); |
|
| 1186 | - elseif (!is_array($_POST['signature_bbc_enabledTags'])) |
|
| 1187 | - $_POST['signature_bbc_enabledTags'] = array($_POST['signature_bbc_enabledTags']); |
|
| 1228 | + if (!isset($_POST['signature_bbc_enabledTags'])) { |
|
| 1229 | + $_POST['signature_bbc_enabledTags'] = array(); |
|
| 1230 | + } elseif (!is_array($_POST['signature_bbc_enabledTags'])) { |
|
| 1231 | + $_POST['signature_bbc_enabledTags'] = array($_POST['signature_bbc_enabledTags']); |
|
| 1232 | + } |
|
| 1188 | 1233 | |
| 1189 | 1234 | $sig_limits = array(); |
| 1190 | 1235 | foreach ($context['signature_settings'] as $key => $value) |
| 1191 | 1236 | { |
| 1192 | - if ($key == 'allow_smileys') |
|
| 1193 | - continue; |
|
| 1194 | - elseif ($key == 'max_smileys' && empty($_POST['signature_allow_smileys'])) |
|
| 1195 | - $sig_limits[] = -1; |
|
| 1196 | - else |
|
| 1197 | - $sig_limits[] = !empty($_POST['signature_' . $key]) ? max(1, (int) $_POST['signature_' . $key]) : 0; |
|
| 1237 | + if ($key == 'allow_smileys') { |
|
| 1238 | + continue; |
|
| 1239 | + } elseif ($key == 'max_smileys' && empty($_POST['signature_allow_smileys'])) { |
|
| 1240 | + $sig_limits[] = -1; |
|
| 1241 | + } else { |
|
| 1242 | + $sig_limits[] = !empty($_POST['signature_' . $key]) ? max(1, (int) $_POST['signature_' . $key]) : 0; |
|
| 1243 | + } |
|
| 1198 | 1244 | } |
| 1199 | 1245 | |
| 1200 | 1246 | call_integration_hook('integrate_save_signature_settings', array(&$sig_limits, &$bbcTags)); |
@@ -1227,12 +1273,14 @@ discard block |
||
| 1227 | 1273 | |
| 1228 | 1274 | // Try get more time... |
| 1229 | 1275 | @set_time_limit(600); |
| 1230 | - if (function_exists('apache_reset_timeout')) |
|
| 1231 | - @apache_reset_timeout(); |
|
| 1276 | + if (function_exists('apache_reset_timeout')) { |
|
| 1277 | + @apache_reset_timeout(); |
|
| 1278 | + } |
|
| 1232 | 1279 | |
| 1233 | 1280 | // Have we exhausted all the time we allowed? |
| 1234 | - if (time() - array_sum(explode(' ', $sig_start)) < 3) |
|
| 1235 | - return; |
|
| 1281 | + if (time() - array_sum(explode(' ', $sig_start)) < 3) { |
|
| 1282 | + return; |
|
| 1283 | + } |
|
| 1236 | 1284 | |
| 1237 | 1285 | $context['continue_get_data'] = '?action=admin;area=featuresettings;sa=sig;apply;step=' . $_GET['step'] . ';' . $context['session_var'] . '=' . $context['session_id']; |
| 1238 | 1286 | $context['page_title'] = $txt['not_done_title']; |
@@ -1278,9 +1326,10 @@ discard block |
||
| 1278 | 1326 | $disable_fields = array_flip($standard_fields); |
| 1279 | 1327 | if (!empty($_POST['active'])) |
| 1280 | 1328 | { |
| 1281 | - foreach ($_POST['active'] as $value) |
|
| 1282 | - if (isset($disable_fields[$value])) |
|
| 1329 | + foreach ($_POST['active'] as $value) { |
|
| 1330 | + if (isset($disable_fields[$value])) |
|
| 1283 | 1331 | unset($disable_fields[$value]); |
| 1332 | + } |
|
| 1284 | 1333 | } |
| 1285 | 1334 | // What we have left! |
| 1286 | 1335 | $changes['disabled_profile_fields'] = empty($disable_fields) ? '' : implode(',', array_keys($disable_fields)); |
@@ -1289,16 +1338,18 @@ discard block |
||
| 1289 | 1338 | $reg_fields = array(); |
| 1290 | 1339 | if (!empty($_POST['reg'])) |
| 1291 | 1340 | { |
| 1292 | - foreach ($_POST['reg'] as $value) |
|
| 1293 | - if (in_array($value, $standard_fields) && !isset($disable_fields[$value])) |
|
| 1341 | + foreach ($_POST['reg'] as $value) { |
|
| 1342 | + if (in_array($value, $standard_fields) && !isset($disable_fields[$value])) |
|
| 1294 | 1343 | $reg_fields[] = $value; |
| 1344 | + } |
|
| 1295 | 1345 | } |
| 1296 | 1346 | // What we have left! |
| 1297 | 1347 | $changes['registration_fields'] = empty($reg_fields) ? '' : implode(',', $reg_fields); |
| 1298 | 1348 | |
| 1299 | 1349 | $_SESSION['adm-save'] = true; |
| 1300 | - if (!empty($changes)) |
|
| 1301 | - updateSettings($changes); |
|
| 1350 | + if (!empty($changes)) { |
|
| 1351 | + updateSettings($changes); |
|
| 1352 | + } |
|
| 1302 | 1353 | } |
| 1303 | 1354 | |
| 1304 | 1355 | createToken('admin-scp'); |
@@ -1401,11 +1452,13 @@ discard block |
||
| 1401 | 1452 | { |
| 1402 | 1453 | $return = '<p class="centertext bold_text">'. $rowData['field_order'] .'<br>'; |
| 1403 | 1454 | |
| 1404 | - if ($rowData['field_order'] > 1) |
|
| 1405 | - $return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=up"><span class="toggle_up" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_up'] .'"></span></a>'; |
|
| 1455 | + if ($rowData['field_order'] > 1) { |
|
| 1456 | + $return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=up"><span class="toggle_up" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_up'] .'"></span></a>'; |
|
| 1457 | + } |
|
| 1406 | 1458 | |
| 1407 | - if ($rowData['field_order'] < $context['custFieldsMaxOrder']) |
|
| 1408 | - $return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=down"><span class="toggle_down" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_down'] .'"></span></a>'; |
|
| 1459 | + if ($rowData['field_order'] < $context['custFieldsMaxOrder']) { |
|
| 1460 | + $return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=down"><span class="toggle_down" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_down'] .'"></span></a>'; |
|
| 1461 | + } |
|
| 1409 | 1462 | |
| 1410 | 1463 | $return .= '</p>'; |
| 1411 | 1464 | |
@@ -1543,16 +1596,16 @@ discard block |
||
| 1543 | 1596 | $disabled_fields = isset($modSettings['disabled_profile_fields']) ? explode(',', $modSettings['disabled_profile_fields']) : array(); |
| 1544 | 1597 | $registration_fields = isset($modSettings['registration_fields']) ? explode(',', $modSettings['registration_fields']) : array(); |
| 1545 | 1598 | |
| 1546 | - foreach ($standard_fields as $field) |
|
| 1547 | - $list[] = array( |
|
| 1599 | + foreach ($standard_fields as $field) { |
|
| 1600 | + $list[] = array( |
|
| 1548 | 1601 | 'id' => $field, |
| 1549 | 1602 | 'label' => isset($txt['standard_profile_field_' . $field]) ? $txt['standard_profile_field_' . $field] : (isset($txt[$field]) ? $txt[$field] : $field), |
| 1550 | 1603 | 'disabled' => in_array($field, $disabled_fields), |
| 1551 | 1604 | 'on_register' => in_array($field, $registration_fields) && !in_array($field, $fields_no_registration), |
| 1552 | 1605 | 'can_show_register' => !in_array($field, $fields_no_registration), |
| 1553 | 1606 | ); |
| 1554 | - } |
|
| 1555 | - else |
|
| 1607 | + } |
|
| 1608 | + } else |
|
| 1556 | 1609 | { |
| 1557 | 1610 | // Load all the fields. |
| 1558 | 1611 | $request = $smcFunc['db_query']('', ' |
@@ -1566,8 +1619,9 @@ discard block |
||
| 1566 | 1619 | 'items_per_page' => $items_per_page, |
| 1567 | 1620 | ) |
| 1568 | 1621 | ); |
| 1569 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1570 | - $list[] = $row; |
|
| 1622 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1623 | + $list[] = $row; |
|
| 1624 | + } |
|
| 1571 | 1625 | $smcFunc['db_free_result']($request); |
| 1572 | 1626 | } |
| 1573 | 1627 | |
@@ -1633,9 +1687,9 @@ discard block |
||
| 1633 | 1687 | $context['field'] = array(); |
| 1634 | 1688 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1635 | 1689 | { |
| 1636 | - if ($row['field_type'] == 'textarea') |
|
| 1637 | - @list ($rows, $cols) = @explode(',', $row['default_value']); |
|
| 1638 | - else |
|
| 1690 | + if ($row['field_type'] == 'textarea') { |
|
| 1691 | + @list ($rows, $cols) = @explode(',', $row['default_value']); |
|
| 1692 | + } else |
|
| 1639 | 1693 | { |
| 1640 | 1694 | $rows = 3; |
| 1641 | 1695 | $cols = 30; |
@@ -1671,8 +1725,8 @@ discard block |
||
| 1671 | 1725 | } |
| 1672 | 1726 | |
| 1673 | 1727 | // Setup the default values as needed. |
| 1674 | - if (empty($context['field'])) |
|
| 1675 | - $context['field'] = array( |
|
| 1728 | + if (empty($context['field'])) { |
|
| 1729 | + $context['field'] = array( |
|
| 1676 | 1730 | 'name' => '', |
| 1677 | 1731 | 'col_name' => '???', |
| 1678 | 1732 | 'desc' => '', |
@@ -1697,6 +1751,7 @@ discard block |
||
| 1697 | 1751 | 'enclose' => '', |
| 1698 | 1752 | 'placement' => 0, |
| 1699 | 1753 | ); |
| 1754 | + } |
|
| 1700 | 1755 | |
| 1701 | 1756 | // Are we moving it? |
| 1702 | 1757 | if (isset($_GET['move']) && in_array($smcFunc['htmlspecialchars']($_GET['move']), $move_to)) |
@@ -1705,8 +1760,10 @@ discard block |
||
| 1705 | 1760 | $new_order = ($_GET['move'] == 'up' ? ($context['field']['order'] - 1) : ($context['field']['order'] + 1)); |
| 1706 | 1761 | |
| 1707 | 1762 | // Is this a valid position? |
| 1708 | - if ($new_order <= 0 || $new_order > $order_count) |
|
| 1709 | - redirectexit('action=admin;area=featuresettings;sa=profile'); // @todo implement an error handler |
|
| 1763 | + if ($new_order <= 0 || $new_order > $order_count) { |
|
| 1764 | + redirectexit('action=admin;area=featuresettings;sa=profile'); |
|
| 1765 | + } |
|
| 1766 | + // @todo implement an error handler |
|
| 1710 | 1767 | |
| 1711 | 1768 | // All good, proceed. |
| 1712 | 1769 | $smcFunc['db_query']('',' |
@@ -1737,12 +1794,14 @@ discard block |
||
| 1737 | 1794 | validateToken('admin-ecp'); |
| 1738 | 1795 | |
| 1739 | 1796 | // Everyone needs a name - even the (bracket) unknown... |
| 1740 | - if (trim($_POST['field_name']) == '') |
|
| 1741 | - redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=need_name'); |
|
| 1797 | + if (trim($_POST['field_name']) == '') { |
|
| 1798 | + redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=need_name'); |
|
| 1799 | + } |
|
| 1742 | 1800 | |
| 1743 | 1801 | // Regex you say? Do a very basic test to see if the pattern is valid |
| 1744 | - if (!empty($_POST['regex']) && @preg_match($_POST['regex'], 'dummy') === false) |
|
| 1745 | - redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=regex_error'); |
|
| 1802 | + if (!empty($_POST['regex']) && @preg_match($_POST['regex'], 'dummy') === false) { |
|
| 1803 | + redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=regex_error'); |
|
| 1804 | + } |
|
| 1746 | 1805 | |
| 1747 | 1806 | $_POST['field_name'] = $smcFunc['htmlspecialchars']($_POST['field_name']); |
| 1748 | 1807 | $_POST['field_desc'] = $smcFunc['htmlspecialchars']($_POST['field_desc']); |
@@ -1759,8 +1818,9 @@ discard block |
||
| 1759 | 1818 | |
| 1760 | 1819 | // Some masking stuff... |
| 1761 | 1820 | $mask = isset($_POST['mask']) ? $_POST['mask'] : ''; |
| 1762 | - if ($mask == 'regex' && isset($_POST['regex'])) |
|
| 1763 | - $mask .= $_POST['regex']; |
|
| 1821 | + if ($mask == 'regex' && isset($_POST['regex'])) { |
|
| 1822 | + $mask .= $_POST['regex']; |
|
| 1823 | + } |
|
| 1764 | 1824 | |
| 1765 | 1825 | $field_length = isset($_POST['max_length']) ? (int) $_POST['max_length'] : 255; |
| 1766 | 1826 | $enclose = isset($_POST['enclose']) ? $_POST['enclose'] : ''; |
@@ -1779,8 +1839,9 @@ discard block |
||
| 1779 | 1839 | $v = strtr($v, array(',' => '')); |
| 1780 | 1840 | |
| 1781 | 1841 | // Nada, zip, etc... |
| 1782 | - if (trim($v) == '') |
|
| 1783 | - continue; |
|
| 1842 | + if (trim($v) == '') { |
|
| 1843 | + continue; |
|
| 1844 | + } |
|
| 1784 | 1845 | |
| 1785 | 1846 | // Otherwise, save it boy. |
| 1786 | 1847 | $field_options .= $v . ','; |
@@ -1788,15 +1849,17 @@ discard block |
||
| 1788 | 1849 | $newOptions[$k] = $v; |
| 1789 | 1850 | |
| 1790 | 1851 | // Is it default? |
| 1791 | - if (isset($_POST['default_select']) && $_POST['default_select'] == $k) |
|
| 1792 | - $default = $v; |
|
| 1852 | + if (isset($_POST['default_select']) && $_POST['default_select'] == $k) { |
|
| 1853 | + $default = $v; |
|
| 1854 | + } |
|
| 1793 | 1855 | } |
| 1794 | 1856 | $field_options = substr($field_options, 0, -1); |
| 1795 | 1857 | } |
| 1796 | 1858 | |
| 1797 | 1859 | // Text area has default has dimensions |
| 1798 | - if ($_POST['field_type'] == 'textarea') |
|
| 1799 | - $default = (int) $_POST['rows'] . ',' . (int) $_POST['cols']; |
|
| 1860 | + if ($_POST['field_type'] == 'textarea') { |
|
| 1861 | + $default = (int) $_POST['rows'] . ',' . (int) $_POST['cols']; |
|
| 1862 | + } |
|
| 1800 | 1863 | |
| 1801 | 1864 | // Come up with the unique name? |
| 1802 | 1865 | if (empty($context['fid'])) |
@@ -1805,32 +1868,36 @@ discard block |
||
| 1805 | 1868 | preg_match('~([\w\d_-]+)~', $col_name, $matches); |
| 1806 | 1869 | |
| 1807 | 1870 | // If there is nothing to the name, then let's start out own - for foreign languages etc. |
| 1808 | - if (isset($matches[1])) |
|
| 1809 | - $col_name = $initial_col_name = 'cust_' . strtolower($matches[1]); |
|
| 1810 | - else |
|
| 1811 | - $col_name = $initial_col_name = 'cust_' . mt_rand(1, 9999); |
|
| 1871 | + if (isset($matches[1])) { |
|
| 1872 | + $col_name = $initial_col_name = 'cust_' . strtolower($matches[1]); |
|
| 1873 | + } else { |
|
| 1874 | + $col_name = $initial_col_name = 'cust_' . mt_rand(1, 9999); |
|
| 1875 | + } |
|
| 1812 | 1876 | |
| 1813 | 1877 | // Make sure this is unique. |
| 1814 | 1878 | $current_fields = array(); |
| 1815 | 1879 | $request = $smcFunc['db_query']('', ' |
| 1816 | 1880 | SELECT id_field, col_name |
| 1817 | 1881 | FROM {db_prefix}custom_fields'); |
| 1818 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1819 | - $current_fields[$row['id_field']] = $row['col_name']; |
|
| 1882 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1883 | + $current_fields[$row['id_field']] = $row['col_name']; |
|
| 1884 | + } |
|
| 1820 | 1885 | $smcFunc['db_free_result']($request); |
| 1821 | 1886 | |
| 1822 | 1887 | $unique = false; |
| 1823 | 1888 | for ($i = 0; !$unique && $i < 9; $i ++) |
| 1824 | 1889 | { |
| 1825 | - if (!in_array($col_name, $current_fields)) |
|
| 1826 | - $unique = true; |
|
| 1827 | - else |
|
| 1828 | - $col_name = $initial_col_name . $i; |
|
| 1890 | + if (!in_array($col_name, $current_fields)) { |
|
| 1891 | + $unique = true; |
|
| 1892 | + } else { |
|
| 1893 | + $col_name = $initial_col_name . $i; |
|
| 1894 | + } |
|
| 1829 | 1895 | } |
| 1830 | 1896 | |
| 1831 | 1897 | // Still not a unique column name? Leave it up to the user, then. |
| 1832 | - if (!$unique) |
|
| 1833 | - fatal_lang_error('custom_option_not_unique'); |
|
| 1898 | + if (!$unique) { |
|
| 1899 | + fatal_lang_error('custom_option_not_unique'); |
|
| 1900 | + } |
|
| 1834 | 1901 | } |
| 1835 | 1902 | // Work out what to do with the user data otherwise... |
| 1836 | 1903 | else |
@@ -1858,8 +1925,9 @@ discard block |
||
| 1858 | 1925 | // Work out what's changed! |
| 1859 | 1926 | foreach ($context['field']['options'] as $k => $option) |
| 1860 | 1927 | { |
| 1861 | - if (trim($option) == '') |
|
| 1862 | - continue; |
|
| 1928 | + if (trim($option) == '') { |
|
| 1929 | + continue; |
|
| 1930 | + } |
|
| 1863 | 1931 | |
| 1864 | 1932 | // Still exists? |
| 1865 | 1933 | if (in_array($option, $newOptions)) |
@@ -1873,8 +1941,8 @@ discard block |
||
| 1873 | 1941 | foreach ($optionChanges as $k => $option) |
| 1874 | 1942 | { |
| 1875 | 1943 | // Just been renamed? |
| 1876 | - if (!in_array($k, $takenKeys) && !empty($newOptions[$k])) |
|
| 1877 | - $smcFunc['db_query']('', ' |
|
| 1944 | + if (!in_array($k, $takenKeys) && !empty($newOptions[$k])) { |
|
| 1945 | + $smcFunc['db_query']('', ' |
|
| 1878 | 1946 | UPDATE {db_prefix}themes |
| 1879 | 1947 | SET value = {string:new_value} |
| 1880 | 1948 | WHERE variable = {string:current_column} |
@@ -1887,6 +1955,7 @@ discard block |
||
| 1887 | 1955 | 'old_value' => $option, |
| 1888 | 1956 | ) |
| 1889 | 1957 | ); |
| 1958 | + } |
|
| 1890 | 1959 | } |
| 1891 | 1960 | } |
| 1892 | 1961 | // @todo Maybe we should adjust based on new text length limits? |
@@ -1929,8 +1998,8 @@ discard block |
||
| 1929 | 1998 | ); |
| 1930 | 1999 | |
| 1931 | 2000 | // Just clean up any old selects - these are a pain! |
| 1932 | - if (($_POST['field_type'] == 'select' || $_POST['field_type'] == 'radio') && !empty($newOptions)) |
|
| 1933 | - $smcFunc['db_query']('', ' |
|
| 2001 | + if (($_POST['field_type'] == 'select' || $_POST['field_type'] == 'radio') && !empty($newOptions)) { |
|
| 2002 | + $smcFunc['db_query']('', ' |
|
| 1934 | 2003 | DELETE FROM {db_prefix}themes |
| 1935 | 2004 | WHERE variable = {string:current_column} |
| 1936 | 2005 | AND value NOT IN ({array_string:new_option_values}) |
@@ -1941,8 +2010,8 @@ discard block |
||
| 1941 | 2010 | 'current_column' => $context['field']['col_name'], |
| 1942 | 2011 | ) |
| 1943 | 2012 | ); |
| 1944 | - } |
|
| 1945 | - else |
|
| 2013 | + } |
|
| 2014 | + } else |
|
| 1946 | 2015 | { |
| 1947 | 2016 | // Gotta figure it out the order. |
| 1948 | 2017 | $new_order = $order_count > 1 ? ($order_count + 1) : 1; |
@@ -2116,11 +2185,13 @@ discard block |
||
| 2116 | 2185 | call_integration_hook('integrate_prune_settings', array(&$config_vars, &$prune_toggle, false)); |
| 2117 | 2186 | |
| 2118 | 2187 | $prune_toggle_dt = array(); |
| 2119 | - foreach ($prune_toggle as $item) |
|
| 2120 | - $prune_toggle_dt[] = 'setting_' . $item; |
|
| 2188 | + foreach ($prune_toggle as $item) { |
|
| 2189 | + $prune_toggle_dt[] = 'setting_' . $item; |
|
| 2190 | + } |
|
| 2121 | 2191 | |
| 2122 | - if ($return_config) |
|
| 2123 | - return $config_vars; |
|
| 2192 | + if ($return_config) { |
|
| 2193 | + return $config_vars; |
|
| 2194 | + } |
|
| 2124 | 2195 | |
| 2125 | 2196 | addInlineJavaScript(' |
| 2126 | 2197 | function togglePruned() |
@@ -2158,15 +2229,16 @@ discard block |
||
| 2158 | 2229 | $vals = array(); |
| 2159 | 2230 | foreach ($config_vars as $index => $dummy) |
| 2160 | 2231 | { |
| 2161 | - if (!is_array($dummy) || $index == 'pruningOptions' || !in_array($dummy[1], $prune_toggle)) |
|
| 2162 | - continue; |
|
| 2232 | + if (!is_array($dummy) || $index == 'pruningOptions' || !in_array($dummy[1], $prune_toggle)) { |
|
| 2233 | + continue; |
|
| 2234 | + } |
|
| 2163 | 2235 | |
| 2164 | 2236 | $vals[] = empty($_POST[$dummy[1]]) || $_POST[$dummy[1]] < 0 ? 0 : (int) $_POST[$dummy[1]]; |
| 2165 | 2237 | } |
| 2166 | 2238 | $_POST['pruningOptions'] = implode(',', $vals); |
| 2239 | + } else { |
|
| 2240 | + $_POST['pruningOptions'] = ''; |
|
| 2167 | 2241 | } |
| 2168 | - else |
|
| 2169 | - $_POST['pruningOptions'] = ''; |
|
| 2170 | 2242 | |
| 2171 | 2243 | saveDBSettings($savevar); |
| 2172 | 2244 | $_SESSION['adm-save'] = true; |
@@ -2178,10 +2250,11 @@ discard block |
||
| 2178 | 2250 | $context['sub_template'] = 'show_settings'; |
| 2179 | 2251 | |
| 2180 | 2252 | // Get the actual values |
| 2181 | - if (!empty($modSettings['pruningOptions'])) |
|
| 2182 | - @list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']); |
|
| 2183 | - else |
|
| 2184 | - $modSettings['pruneErrorLog'] = $modSettings['pruneModLog'] = $modSettings['pruneBanLog'] = $modSettings['pruneReportLog'] = $modSettings['pruneScheduledTaskLog'] = $modSettings['pruneSpiderHitLog'] = 0; |
|
| 2253 | + if (!empty($modSettings['pruningOptions'])) { |
|
| 2254 | + @list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']); |
|
| 2255 | + } else { |
|
| 2256 | + $modSettings['pruneErrorLog'] = $modSettings['pruneModLog'] = $modSettings['pruneBanLog'] = $modSettings['pruneReportLog'] = $modSettings['pruneScheduledTaskLog'] = $modSettings['pruneSpiderHitLog'] = 0; |
|
| 2257 | + } |
|
| 2185 | 2258 | |
| 2186 | 2259 | prepareDBSettingContext($config_vars); |
| 2187 | 2260 | } |
@@ -2203,8 +2276,9 @@ discard block |
||
| 2203 | 2276 | // Make it even easier to add new settings. |
| 2204 | 2277 | call_integration_hook('integrate_general_mod_settings', array(&$config_vars)); |
| 2205 | 2278 | |
| 2206 | - if ($return_config) |
|
| 2207 | - return $config_vars; |
|
| 2279 | + if ($return_config) { |
|
| 2280 | + return $config_vars; |
|
| 2281 | + } |
|
| 2208 | 2282 | |
| 2209 | 2283 | $context['post_url'] = $scripturl . '?action=admin;area=modsettings;save;sa=general'; |
| 2210 | 2284 | $context['settings_title'] = $txt['mods_cat_modifications_misc']; |
@@ -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('Hacking attempt...'); |
| 16 | +} |
|
| 16 | 17 | |
| 17 | 18 | /** |
| 18 | 19 | * Our Cache API class |
@@ -34,8 +35,9 @@ discard block |
||
| 34 | 35 | |
| 35 | 36 | $supported = class_exists('memcached'); |
| 36 | 37 | |
| 37 | - if ($test) |
|
| 38 | - return $supported; |
|
| 38 | + if ($test) { |
|
| 39 | + return $supported; |
|
| 40 | + } |
|
| 39 | 41 | return parent::isSupported() && $supported && !empty($cache_memcached); |
| 40 | 42 | } |
| 41 | 43 | |
@@ -53,9 +55,9 @@ discard block |
||
| 53 | 55 | $currentServers = $this->memcached->getServerList(); |
| 54 | 56 | foreach ($servers as $server) |
| 55 | 57 | { |
| 56 | - if (strpos($server,'/') !== false) |
|
| 57 | - $tempServer = array($server, 0); |
|
| 58 | - else |
|
| 58 | + if (strpos($server,'/') !== false) { |
|
| 59 | + $tempServer = array($server, 0); |
|
| 60 | + } else |
|
| 59 | 61 | { |
| 60 | 62 | $server = explode(':', $server); |
| 61 | 63 | $tempServer = array($server[0], isset($server[1]) ? $server[1] : 11211); |
@@ -73,8 +75,9 @@ discard block |
||
| 73 | 75 | } |
| 74 | 76 | |
| 75 | 77 | // Found it? |
| 76 | - if (empty($foundServer)) |
|
| 77 | - $this->memcached->addServer($tempServer[0], $tempServer[1]); |
|
| 78 | + if (empty($foundServer)) { |
|
| 79 | + $this->memcached->addServer($tempServer[0], $tempServer[1]); |
|
| 80 | + } |
|
| 78 | 81 | } |
| 79 | 82 | |
| 80 | 83 | // Best guess is this worked. |
@@ -91,8 +94,9 @@ discard block |
||
| 91 | 94 | $value = $this->memcached->get($key); |
| 92 | 95 | |
| 93 | 96 | // $value should return either data or false (from failure, key not found or empty array). |
| 94 | - if ($value === false) |
|
| 95 | - return null; |
|
| 97 | + if ($value === false) { |
|
| 98 | + return null; |
|
| 99 | + } |
|
| 96 | 100 | return $value; |
| 97 | 101 | } |
| 98 | 102 | |
@@ -135,8 +139,9 @@ discard block |
||
| 135 | 139 | $config_vars[] = $txt['cache_memcache_settings']; |
| 136 | 140 | $config_vars[] = array('cache_memcached', $txt['cache_memcache_servers'], 'file', 'text', 0, 'cache_memcached', 'postinput' => '<br><div class="smalltext"><em>' . $txt['cache_memcache_servers_subtext'] . '</em></div>'); |
| 137 | 141 | |
| 138 | - if (!isset($context['settings_post_javascript'])) |
|
| 139 | - $context['settings_post_javascript'] = ''; |
|
| 142 | + if (!isset($context['settings_post_javascript'])) { |
|
| 143 | + $context['settings_post_javascript'] = ''; |
|
| 144 | + } |
|
| 140 | 145 | |
| 141 | 146 | $context['settings_post_javascript'] .= ' |
| 142 | 147 | $("#cache_accelerator").change(function (e) { |
@@ -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('Hacking attempt...'); |
| 16 | +} |
|
| 16 | 17 | |
| 17 | 18 | /** |
| 18 | 19 | * Our Cache API class |
@@ -34,8 +35,9 @@ discard block |
||
| 34 | 35 | |
| 35 | 36 | $supported = class_exists('memcache'); |
| 36 | 37 | |
| 37 | - if ($test) |
|
| 38 | - return $supported; |
|
| 38 | + if ($test) { |
|
| 39 | + return $supported; |
|
| 40 | + } |
|
| 39 | 41 | return parent::isSupported() && $supported && !empty($cache_memcached); |
| 40 | 42 | } |
| 41 | 43 | |
@@ -61,9 +63,9 @@ discard block |
||
| 61 | 63 | $server = trim($servers[array_rand($servers)]); |
| 62 | 64 | |
| 63 | 65 | // Normal host names do not contain slashes, while e.g. unix sockets do. Assume alternative transport pipe with port 0. |
| 64 | - if (strpos($server,'/') !== false) |
|
| 65 | - $host = $server; |
|
| 66 | - else |
|
| 66 | + if (strpos($server,'/') !== false) { |
|
| 67 | + $host = $server; |
|
| 68 | + } else |
|
| 67 | 69 | { |
| 68 | 70 | $server = explode(':', $server); |
| 69 | 71 | $host = $server[0]; |
@@ -71,10 +73,11 @@ discard block |
||
| 71 | 73 | } |
| 72 | 74 | |
| 73 | 75 | // Don't wait too long: yes, we want the server, but we might be able to run the query faster! |
| 74 | - if (empty($db_persist)) |
|
| 75 | - $connected = $this->memcache->connect($host, $port); |
|
| 76 | - else |
|
| 77 | - $connected = $this->memcache->pconnect($host, $port); |
|
| 76 | + if (empty($db_persist)) { |
|
| 77 | + $connected = $this->memcache->connect($host, $port); |
|
| 78 | + } else { |
|
| 79 | + $connected = $this->memcache->pconnect($host, $port); |
|
| 80 | + } |
|
| 78 | 81 | } |
| 79 | 82 | |
| 80 | 83 | return $connected; |
@@ -90,8 +93,9 @@ discard block |
||
| 90 | 93 | $value = $this->memcache->get($key); |
| 91 | 94 | |
| 92 | 95 | // $value should return either data or false (from failure, key not found or empty array). |
| 93 | - if ($value === false) |
|
| 94 | - return null; |
|
| 96 | + if ($value === false) { |
|
| 97 | + return null; |
|
| 98 | + } |
|
| 95 | 99 | return $value; |
| 96 | 100 | } |
| 97 | 101 | |
@@ -132,8 +136,9 @@ discard block |
||
| 132 | 136 | $config_vars[] = $txt['cache_memcache_settings']; |
| 133 | 137 | $config_vars[] = array('cache_memcached', $txt['cache_memcache_servers'], 'file', 'text', 0, 'cache_memcached', 'postinput' => '<br><div class="smalltext"><em>' . $txt['cache_memcache_servers_subtext'] . '</em></div>'); |
| 134 | 138 | |
| 135 | - if (!isset($context['settings_post_javascript'])) |
|
| 136 | - $context['settings_post_javascript'] = ''; |
|
| 139 | + if (!isset($context['settings_post_javascript'])) { |
|
| 140 | + $context['settings_post_javascript'] = ''; |
|
| 141 | + } |
|
| 137 | 142 | |
| 138 | 143 | $context['settings_post_javascript'] .= ' |
| 139 | 144 | $("#cache_accelerator").change(function (e) { |
@@ -32,16 +32,18 @@ discard block |
||
| 32 | 32 | ob_start(); |
| 33 | 33 | |
| 34 | 34 | // Do some cleaning, just in case. |
| 35 | -foreach (array('db_character_set', 'cachedir') as $variable) |
|
| 35 | +foreach (array('db_character_set', 'cachedir') as $variable) { |
|
| 36 | 36 | if (isset($GLOBALS[$variable])) |
| 37 | 37 | unset($GLOBALS[$variable], $GLOBALS[$variable]); |
| 38 | +} |
|
| 38 | 39 | |
| 39 | 40 | // Load the settings... |
| 40 | 41 | require_once(dirname(__FILE__) . '/Settings.php'); |
| 41 | 42 | |
| 42 | 43 | // Make absolutely sure the cache directory is defined. |
| 43 | -if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) |
|
| 44 | +if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) { |
|
| 44 | 45 | $cachedir = $boarddir . '/cache'; |
| 46 | +} |
|
| 45 | 47 | |
| 46 | 48 | // Without those we can't go anywhere |
| 47 | 49 | require_once($sourcedir . '/QueryString.php'); |
@@ -51,8 +53,9 @@ discard block |
||
| 51 | 53 | require_once($sourcedir . '/Load.php'); |
| 52 | 54 | |
| 53 | 55 | // If $maintenance is set specifically to 2, then we're upgrading or something. |
| 54 | -if (!empty($maintenance) && $maintenance == 2) |
|
| 56 | +if (!empty($maintenance) && $maintenance == 2) { |
|
| 55 | 57 | display_maintenance_message(); |
| 58 | +} |
|
| 56 | 59 | |
| 57 | 60 | // Create a variable to store some SMF specific functions in. |
| 58 | 61 | $smcFunc = array(); |
@@ -67,8 +70,9 @@ discard block |
||
| 67 | 70 | cleanRequest(); |
| 68 | 71 | |
| 69 | 72 | // Seed the random generator. |
| 70 | -if (empty($modSettings['rand_seed']) || mt_rand(1, 250) == 69) |
|
| 73 | +if (empty($modSettings['rand_seed']) || mt_rand(1, 250) == 69) { |
|
| 71 | 74 | smf_seed_generator(); |
| 75 | +} |
|
| 72 | 76 | |
| 73 | 77 | // Before we get carried away, are we doing a scheduled task? If so save CPU cycles by jumping out! |
| 74 | 78 | if (isset($_GET['scheduled'])) |
@@ -88,9 +92,9 @@ discard block |
||
| 88 | 92 | if (!empty($modSettings['enableCompressedOutput']) && !headers_sent()) |
| 89 | 93 | { |
| 90 | 94 | // If zlib is being used, turn off output compression. |
| 91 | - if (ini_get('zlib.output_compression') >= 1 || ini_get('output_handler') == 'ob_gzhandler') |
|
| 92 | - $modSettings['enableCompressedOutput'] = '0'; |
|
| 93 | - else |
|
| 95 | + if (ini_get('zlib.output_compression') >= 1 || ini_get('output_handler') == 'ob_gzhandler') { |
|
| 96 | + $modSettings['enableCompressedOutput'] = '0'; |
|
| 97 | + } else |
|
| 94 | 98 | { |
| 95 | 99 | ob_end_clean(); |
| 96 | 100 | ob_start('ob_gzhandler'); |
@@ -182,18 +186,21 @@ discard block |
||
| 182 | 186 | loadPermissions(); |
| 183 | 187 | |
| 184 | 188 | // Attachments don't require the entire theme to be loaded. |
| 185 | - if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'dlattach') |
|
| 186 | - detectBrowser(); |
|
| 189 | + if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'dlattach') { |
|
| 190 | + detectBrowser(); |
|
| 191 | + } |
|
| 187 | 192 | // Load the current theme. (note that ?theme=1 will also work, may be used for guest theming.) |
| 188 | - else |
|
| 189 | - loadTheme(); |
|
| 193 | + else { |
|
| 194 | + loadTheme(); |
|
| 195 | + } |
|
| 190 | 196 | |
| 191 | 197 | // Check if the user should be disallowed access. |
| 192 | 198 | is_not_banned(); |
| 193 | 199 | |
| 194 | 200 | // If we are in a topic and don't have permission to approve it then duck out now. |
| 195 | - if (!empty($topic) && empty($board_info['cur_topic_approved']) && !allowedTo('approve_posts') && ($user_info['id'] != $board_info['cur_topic_starter'] || $user_info['is_guest'])) |
|
| 196 | - fatal_lang_error('not_a_topic', false); |
|
| 201 | + if (!empty($topic) && empty($board_info['cur_topic_approved']) && !allowedTo('approve_posts') && ($user_info['id'] != $board_info['cur_topic_starter'] || $user_info['is_guest'])) { |
|
| 202 | + fatal_lang_error('not_a_topic', false); |
|
| 203 | + } |
|
| 197 | 204 | |
| 198 | 205 | $no_stat_actions = array('clock', 'dlattach', 'findmember', 'jsoption', 'likes', 'loadeditorlocale', 'modifycat', 'requestmembers', 'smstats', 'suggest', 'about:unknown', '.xml', 'xmlhttp', 'verificationcode', 'viewquery', 'viewsmfile'); |
| 199 | 206 | call_integration_hook('integrate_pre_log_stats', array(&$no_stat_actions)); |
@@ -204,8 +211,9 @@ discard block |
||
| 204 | 211 | writeLog(); |
| 205 | 212 | |
| 206 | 213 | // Track forum statistics and hits...? |
| 207 | - if (!empty($modSettings['hitStats'])) |
|
| 208 | - trackStats(array('hits' => '+')); |
|
| 214 | + if (!empty($modSettings['hitStats'])) { |
|
| 215 | + trackStats(array('hits' => '+')); |
|
| 216 | + } |
|
| 209 | 217 | } |
| 210 | 218 | unset($no_stat_actions); |
| 211 | 219 | |
@@ -219,13 +227,14 @@ discard block |
||
| 219 | 227 | return ($_REQUEST['action'] == 'login2' ? 'Login2' : ($_REQUEST['action'] == 'logintfa' ? 'LoginTFA' : 'Logout')); |
| 220 | 228 | } |
| 221 | 229 | // Don't even try it, sonny. |
| 222 | - else |
|
| 223 | - return 'InMaintenance'; |
|
| 230 | + else { |
|
| 231 | + return 'InMaintenance'; |
|
| 232 | + } |
|
| 224 | 233 | } |
| 225 | 234 | // If guest access is off, a guest can only do one of the very few following actions. |
| 226 | - elseif (empty($modSettings['allow_guestAccess']) && $user_info['is_guest'] && (!isset($_REQUEST['action']) || !in_array($_REQUEST['action'], array('coppa', 'login', 'login2', 'logintfa', 'reminder', 'activate', 'help', 'helpadmin', 'smstats', 'verificationcode', 'signup', 'signup2')))) |
|
| 227 | - return 'KickGuest'; |
|
| 228 | - elseif (empty($_REQUEST['action'])) |
|
| 235 | + elseif (empty($modSettings['allow_guestAccess']) && $user_info['is_guest'] && (!isset($_REQUEST['action']) || !in_array($_REQUEST['action'], array('coppa', 'login', 'login2', 'logintfa', 'reminder', 'activate', 'help', 'helpadmin', 'smstats', 'verificationcode', 'signup', 'signup2')))) { |
|
| 236 | + return 'KickGuest'; |
|
| 237 | + } elseif (empty($_REQUEST['action'])) |
|
| 229 | 238 | { |
| 230 | 239 | // Action and board are both empty... BoardIndex! Unless someone else wants to do something different. |
| 231 | 240 | if (empty($board) && empty($topic)) |
@@ -239,8 +248,9 @@ discard block |
||
| 239 | 248 | |
| 240 | 249 | $call = call_helper($defaultAction, true); |
| 241 | 250 | |
| 242 | - if (!empty($call)) |
|
| 243 | - return $call; |
|
| 251 | + if (!empty($call)) { |
|
| 252 | + return $call; |
|
| 253 | + } |
|
| 244 | 254 | } |
| 245 | 255 | |
| 246 | 256 | // No default action huh? then go to our good old BoardIndex. |
@@ -370,8 +380,9 @@ discard block |
||
| 370 | 380 | |
| 371 | 381 | $call = call_helper($fallbackAction, true); |
| 372 | 382 | |
| 373 | - if (!empty($call)) |
|
| 374 | - return $call; |
|
| 383 | + if (!empty($call)) { |
|
| 384 | + return $call; |
|
| 385 | + } |
|
| 375 | 386 | } |
| 376 | 387 | |
| 377 | 388 | // No fallback action, huh? |
@@ -382,8 +393,9 @@ discard block |
||
| 382 | 393 | } |
| 383 | 394 | |
| 384 | 395 | // Otherwise, it was set - so let's go to that action. |
| 385 | - if (!empty($actionArray[$_REQUEST['action']][0])) |
|
| 386 | - require_once($sourcedir . '/' . $actionArray[$_REQUEST['action']][0]); |
|
| 396 | + if (!empty($actionArray[$_REQUEST['action']][0])) { |
|
| 397 | + require_once($sourcedir . '/' . $actionArray[$_REQUEST['action']][0]); |
|
| 398 | + } |
|
| 387 | 399 | |
| 388 | 400 | // Do the right thing. |
| 389 | 401 | return call_helper($actionArray[$_REQUEST['action']][1], true); |
@@ -14,8 +14,9 @@ discard block |
||
| 14 | 14 | // This won't be dedicated without this - this must exist in each gateway! |
| 15 | 15 | // SMF Payment Gateway: paypal |
| 16 | 16 | |
| 17 | -if (!defined('SMF')) |
|
| 17 | +if (!defined('SMF')) { |
|
| 18 | 18 | die('No direct access...'); |
| 19 | +} |
|
| 19 | 20 | |
| 20 | 21 | /** |
| 21 | 22 | * Class for returning available form data for this gateway |
@@ -118,8 +119,7 @@ discard block |
||
| 118 | 119 | { |
| 119 | 120 | $return_data['hidden']['p3'] = 1; |
| 120 | 121 | $return_data['hidden']['t3'] = strtoupper(substr($period, 0, 1)); |
| 121 | - } |
|
| 122 | - else |
|
| 122 | + } else |
|
| 123 | 123 | { |
| 124 | 124 | preg_match('~(\d*)(\w)~', $sub_data['real_length'], $match); |
| 125 | 125 | $unit = $match[1]; |
@@ -130,14 +130,15 @@ discard block |
||
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | // If it's repeatable do some javascript to respect this idea. |
| 133 | - if (!empty($sub_data['repeatable'])) |
|
| 134 | - $return_data['javascript'] = ' |
|
| 133 | + if (!empty($sub_data['repeatable'])) { |
|
| 134 | + $return_data['javascript'] = ' |
|
| 135 | 135 | document.write(\'<label for="do_paypal_recur"><input type="checkbox" name="do_paypal_recur" id="do_paypal_recur" checked onclick="switchPaypalRecur();">' . $txt['paid_make_recurring'] . '</label><br>\'); |
| 136 | 136 | |
| 137 | 137 | function switchPaypalRecur() |
| 138 | 138 | { |
| 139 | 139 | document.getElementById("paypal_cmd").value = document.getElementById("do_paypal_recur").checked ? "_xclick-subscriptions" : "_xclick"; |
| 140 | 140 | }'; |
| 141 | + } |
|
| 141 | 142 | |
| 142 | 143 | return $return_data; |
| 143 | 144 | } |
@@ -160,20 +161,24 @@ discard block |
||
| 160 | 161 | global $modSettings; |
| 161 | 162 | |
| 162 | 163 | // Has the user set up an email address? |
| 163 | - if ((empty($modSettings['paidsubs_test']) && empty($modSettings['paypal_email'])) || (!empty($modSettings['paidsubs_test']) && empty($modSettings['paypal_sandbox_email']))) |
|
| 164 | - return false; |
|
| 164 | + if ((empty($modSettings['paidsubs_test']) && empty($modSettings['paypal_email'])) || (!empty($modSettings['paidsubs_test']) && empty($modSettings['paypal_sandbox_email']))) { |
|
| 165 | + return false; |
|
| 166 | + } |
|
| 165 | 167 | // Check the correct transaction types are even here. |
| 166 | - if ((!isset($_POST['txn_type']) && !isset($_POST['payment_status'])) || (!isset($_POST['business']) && !isset($_POST['receiver_email']))) |
|
| 167 | - return false; |
|
| 168 | + if ((!isset($_POST['txn_type']) && !isset($_POST['payment_status'])) || (!isset($_POST['business']) && !isset($_POST['receiver_email']))) { |
|
| 169 | + return false; |
|
| 170 | + } |
|
| 168 | 171 | // Correct email address? |
| 169 | - if (!isset($_POST['business'])) |
|
| 170 | - $_POST['business'] = $_POST['receiver_email']; |
|
| 172 | + if (!isset($_POST['business'])) { |
|
| 173 | + $_POST['business'] = $_POST['receiver_email']; |
|
| 174 | + } |
|
| 171 | 175 | |
| 172 | 176 | // Are we testing? |
| 173 | - if (empty($modSettings['paidsubs_test']) && strtolower($modSettings['paypal_sandbox_email']) != strtolower($_POST['business']) && (empty($modSettings['paypal_additional_emails']) || !in_array(strtolower($_POST['business']), explode(',', strtolower($modSettings['paypal_additional_emails']))))) |
|
| 174 | - return false; |
|
| 175 | - elseif (strtolower($modSettings['paypal_email']) != strtolower($_POST['business']) && (empty($modSettings['paypal_additional_emails']) || !in_array(strtolower($_POST['business']), explode(',', $modSettings['paypal_additional_emails'])))) |
|
| 176 | - return false; |
|
| 177 | + if (empty($modSettings['paidsubs_test']) && strtolower($modSettings['paypal_sandbox_email']) != strtolower($_POST['business']) && (empty($modSettings['paypal_additional_emails']) || !in_array(strtolower($_POST['business']), explode(',', strtolower($modSettings['paypal_additional_emails']))))) { |
|
| 178 | + return false; |
|
| 179 | + } elseif (strtolower($modSettings['paypal_email']) != strtolower($_POST['business']) && (empty($modSettings['paypal_additional_emails']) || !in_array(strtolower($_POST['business']), explode(',', $modSettings['paypal_additional_emails'])))) { |
|
| 180 | + return false; |
|
| 181 | + } |
|
| 177 | 182 | return true; |
| 178 | 183 | } |
| 179 | 184 | |
@@ -192,15 +197,17 @@ discard block |
||
| 192 | 197 | global $modSettings, $txt; |
| 193 | 198 | |
| 194 | 199 | // Put this to some default value. |
| 195 | - if (!isset($_POST['txn_type'])) |
|
| 196 | - $_POST['txn_type'] = ''; |
|
| 200 | + if (!isset($_POST['txn_type'])) { |
|
| 201 | + $_POST['txn_type'] = ''; |
|
| 202 | + } |
|
| 197 | 203 | |
| 198 | 204 | // Build the request string - starting with the minimum requirement. |
| 199 | 205 | $requestString = 'cmd=_notify-validate'; |
| 200 | 206 | |
| 201 | 207 | // Now my dear, add all the posted bits in the order we got them |
| 202 | - foreach ($_POST as $k => $v) |
|
| 203 | - $requestString .= '&' . $k . '=' . urlencode($v); |
|
| 208 | + foreach ($_POST as $k => $v) { |
|
| 209 | + $requestString .= '&' . $k . '=' . urlencode($v); |
|
| 210 | + } |
|
| 204 | 211 | |
| 205 | 212 | // Can we use curl? |
| 206 | 213 | if (function_exists('curl_init') && $curl = curl_init((!empty($modSettings['paidsubs_test']) ? 'https://www.sandbox.' : 'https://www.') . 'paypal.com/cgi-bin/webscr')) |
@@ -240,14 +247,16 @@ discard block |
||
| 240 | 247 | $header .= 'Connection: close' . "\r\n\r\n"; |
| 241 | 248 | |
| 242 | 249 | // Open the connection. |
| 243 | - if (!empty($modSettings['paidsubs_test'])) |
|
| 244 | - $fp = fsockopen('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30); |
|
| 245 | - else |
|
| 246 | - $fp = fsockopen('www.paypal.com', 80, $errno, $errstr, 30); |
|
| 250 | + if (!empty($modSettings['paidsubs_test'])) { |
|
| 251 | + $fp = fsockopen('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30); |
|
| 252 | + } else { |
|
| 253 | + $fp = fsockopen('www.paypal.com', 80, $errno, $errstr, 30); |
|
| 254 | + } |
|
| 247 | 255 | |
| 248 | 256 | // Did it work? |
| 249 | - if (!$fp) |
|
| 250 | - generateSubscriptionError($txt['paypal_could_not_connect']); |
|
| 257 | + if (!$fp) { |
|
| 258 | + generateSubscriptionError($txt['paypal_could_not_connect']); |
|
| 259 | + } |
|
| 251 | 260 | |
| 252 | 261 | // Put the data to the port. |
| 253 | 262 | fputs($fp, $header . $requestString); |
@@ -256,8 +265,9 @@ discard block |
||
| 256 | 265 | while (!feof($fp)) |
| 257 | 266 | { |
| 258 | 267 | $this->return_data = fgets($fp, 1024); |
| 259 | - if (strcmp(trim($this->return_data), 'VERIFIED') === 0) |
|
| 260 | - break; |
|
| 268 | + if (strcmp(trim($this->return_data), 'VERIFIED') === 0) { |
|
| 269 | + break; |
|
| 270 | + } |
|
| 261 | 271 | } |
| 262 | 272 | |
| 263 | 273 | // Clean up. |
@@ -265,28 +275,34 @@ discard block |
||
| 265 | 275 | } |
| 266 | 276 | |
| 267 | 277 | // If this isn't verified then give up... |
| 268 | - if (strcmp(trim($this->return_data), 'VERIFIED') !== 0) |
|
| 269 | - exit; |
|
| 278 | + if (strcmp(trim($this->return_data), 'VERIFIED') !== 0) { |
|
| 279 | + exit; |
|
| 280 | + } |
|
| 270 | 281 | |
| 271 | 282 | // Check that this is intended for us. |
| 272 | - if (strtolower($modSettings['paypal_email']) != strtolower($_POST['business']) && (empty($modSettings['paypal_additional_emails']) || !in_array(strtolower($_POST['business']), explode(',', strtolower($modSettings['paypal_additional_emails']))))) |
|
| 273 | - exit; |
|
| 283 | + if (strtolower($modSettings['paypal_email']) != strtolower($_POST['business']) && (empty($modSettings['paypal_additional_emails']) || !in_array(strtolower($_POST['business']), explode(',', strtolower($modSettings['paypal_additional_emails']))))) { |
|
| 284 | + exit; |
|
| 285 | + } |
|
| 274 | 286 | |
| 275 | 287 | // Is this a subscription - and if so is it a secondary payment that we need to process? |
| 276 | 288 | // If so, make sure we get it in the expected format. Seems PayPal sometimes sends it without urlencoding. |
| 277 | - if (!empty($_POST['item_number']) && strpos($_POST['item_number'], ' ') !== false) |
|
| 278 | - $_POST['item_number'] = str_replace(' ', '+', $_POST['item_number']); |
|
| 279 | - if ($this->isSubscription() && (empty($_POST['item_number']) || strpos($_POST['item_number'], '+') === false)) |
|
| 280 | - // Calculate the subscription it relates to! |
|
| 289 | + if (!empty($_POST['item_number']) && strpos($_POST['item_number'], ' ') !== false) { |
|
| 290 | + $_POST['item_number'] = str_replace(' ', '+', $_POST['item_number']); |
|
| 291 | + } |
|
| 292 | + if ($this->isSubscription() && (empty($_POST['item_number']) || strpos($_POST['item_number'], '+') === false)) { |
|
| 293 | + // Calculate the subscription it relates to! |
|
| 281 | 294 | $this->_findSubscription(); |
| 295 | + } |
|
| 282 | 296 | |
| 283 | 297 | // Verify the currency! |
| 284 | - if (strtolower($_POST['mc_currency']) !== strtolower($modSettings['paid_currency_code'])) |
|
| 285 | - exit; |
|
| 298 | + if (strtolower($_POST['mc_currency']) !== strtolower($modSettings['paid_currency_code'])) { |
|
| 299 | + exit; |
|
| 300 | + } |
|
| 286 | 301 | |
| 287 | 302 | // Can't exist if it doesn't contain anything. |
| 288 | - if (empty($_POST['item_number'])) |
|
| 289 | - exit; |
|
| 303 | + if (empty($_POST['item_number'])) { |
|
| 304 | + exit; |
|
| 305 | + } |
|
| 290 | 306 | |
| 291 | 307 | // Return the id_sub and id_member |
| 292 | 308 | return explode('+', $_POST['item_number']); |
@@ -299,10 +315,11 @@ discard block |
||
| 299 | 315 | */ |
| 300 | 316 | public function isRefund() |
| 301 | 317 | { |
| 302 | - if ($_POST['payment_status'] === 'Refunded' || $_POST['payment_status'] === 'Reversed' || $_POST['txn_type'] === 'Refunded' || ($_POST['txn_type'] === 'reversal' && $_POST['payment_status'] === 'Completed')) |
|
| 303 | - return true; |
|
| 304 | - else |
|
| 305 | - return false; |
|
| 318 | + if ($_POST['payment_status'] === 'Refunded' || $_POST['payment_status'] === 'Reversed' || $_POST['txn_type'] === 'Refunded' || ($_POST['txn_type'] === 'reversal' && $_POST['payment_status'] === 'Completed')) { |
|
| 319 | + return true; |
|
| 320 | + } else { |
|
| 321 | + return false; |
|
| 322 | + } |
|
| 306 | 323 | } |
| 307 | 324 | |
| 308 | 325 | /** |
@@ -312,10 +329,11 @@ discard block |
||
| 312 | 329 | */ |
| 313 | 330 | public function isSubscription() |
| 314 | 331 | { |
| 315 | - if (substr($_POST['txn_type'], 0, 14) === 'subscr_payment' && $_POST['payment_status'] === 'Completed') |
|
| 316 | - return true; |
|
| 317 | - else |
|
| 318 | - return false; |
|
| 332 | + if (substr($_POST['txn_type'], 0, 14) === 'subscr_payment' && $_POST['payment_status'] === 'Completed') { |
|
| 333 | + return true; |
|
| 334 | + } else { |
|
| 335 | + return false; |
|
| 336 | + } |
|
| 319 | 337 | } |
| 320 | 338 | |
| 321 | 339 | /** |
@@ -325,10 +343,11 @@ discard block |
||
| 325 | 343 | */ |
| 326 | 344 | public function isPayment() |
| 327 | 345 | { |
| 328 | - if ($_POST['payment_status'] === 'Completed' && $_POST['txn_type'] === 'web_accept') |
|
| 329 | - return true; |
|
| 330 | - else |
|
| 331 | - return false; |
|
| 346 | + if ($_POST['payment_status'] === 'Completed' && $_POST['txn_type'] === 'web_accept') { |
|
| 347 | + return true; |
|
| 348 | + } else { |
|
| 349 | + return false; |
|
| 350 | + } |
|
| 332 | 351 | } |
| 333 | 352 | |
| 334 | 353 | /** |
@@ -341,10 +360,11 @@ discard block |
||
| 341 | 360 | // subscr_cancel is sent when the user cancels, subscr_eot is sent when the subscription reaches final payment |
| 342 | 361 | // Neither require us to *do* anything as per performCancel(). |
| 343 | 362 | // subscr_eot, if sent, indicates an end of payments term. |
| 344 | - if (substr($_POST['txn_type'], 0, 13) === 'subscr_cancel' || substr($_POST['txn_type'], 0, 10) === 'subscr_eot') |
|
| 345 | - return true; |
|
| 346 | - else |
|
| 347 | - return false; |
|
| 363 | + if (substr($_POST['txn_type'], 0, 13) === 'subscr_cancel' || substr($_POST['txn_type'], 0, 10) === 'subscr_eot') { |
|
| 364 | + return true; |
|
| 365 | + } else { |
|
| 366 | + return false; |
|
| 367 | + } |
|
| 348 | 368 | } |
| 349 | 369 | |
| 350 | 370 | /** |
@@ -408,8 +428,9 @@ discard block |
||
| 408 | 428 | global $smcFunc; |
| 409 | 429 | |
| 410 | 430 | // Assume we have this? |
| 411 | - if (empty($_POST['subscr_id'])) |
|
| 412 | - return false; |
|
| 431 | + if (empty($_POST['subscr_id'])) { |
|
| 432 | + return false; |
|
| 433 | + } |
|
| 413 | 434 | |
| 414 | 435 | // Do we have this in the database? |
| 415 | 436 | $request = $smcFunc['db_query']('', ' |
@@ -438,11 +459,12 @@ discard block |
||
| 438 | 459 | 'payer_email' => $_POST['payer_email'], |
| 439 | 460 | ) |
| 440 | 461 | ); |
| 441 | - if ($smcFunc['db_num_rows']($request) === 0) |
|
| 442 | - return false; |
|
| 462 | + if ($smcFunc['db_num_rows']($request) === 0) { |
|
| 463 | + return false; |
|
| 464 | + } |
|
| 465 | + } else { |
|
| 466 | + return false; |
|
| 443 | 467 | } |
| 444 | - else |
|
| 445 | - return false; |
|
| 446 | 468 | } |
| 447 | 469 | list ($member_id, $subscription_id) = $smcFunc['db_fetch_row']($request); |
| 448 | 470 | $_POST['item_number'] = $member_id . '+' . $subscription_id; |
@@ -11,8 +11,9 @@ |
||
| 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. |
@@ -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,59 +116,57 @@ 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 | 132 | if (!isset($area['force_menu_into_arms_of_another_menu']) && $user_info['name'] == 'iamanoompaloompa') |
| 125 | 133 | { |
| 126 | 134 | $menu_context['sections'][$section_id]['areas'][$area_id] = $smcFunc['json_decode'](base64_decode('eyJsYWJlbCI6Ik9vbXBhIExvb21wYSIsInVybCI6Imh0dHBzOlwvXC9lbi53aWtpcGVkaWEub3JnXC93aWtpXC9Pb21wYV9Mb29tcGFzPyIsImljb24iOiI8aW1nIHNyYz1cImh0dHBzOlwvXC93d3cuc2ltcGxlbWFjaGluZXMub3JnXC9pbWFnZXNcL29vbXBhLmdpZlwiIGFsdD1cIkknbSBhbiBPb21wYSBMb29tcGFcIiBcLz4ifQ=='), true); |
| 127 | - } |
|
| 128 | - elseif (isset($area['icon'])) |
|
| 135 | + } elseif (isset($area['icon'])) |
|
| 129 | 136 | { |
| 130 | 137 | if (file_exists($settings['theme_dir'] . '/images/admin/' . $area['icon'])) |
| 131 | 138 | { |
| 132 | 139 | $menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<img src="' . $settings['images_url'] . '/admin/' . $area['icon'] . '" alt="">'; |
| 133 | - } |
|
| 134 | - elseif (file_exists($settings['default_theme_dir'] . '/images/admin/' . $area['icon'])) |
|
| 140 | + } elseif (file_exists($settings['default_theme_dir'] . '/images/admin/' . $area['icon'])) |
|
| 135 | 141 | { |
| 136 | 142 | $menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<img src="' . $settings['default_images_url'] . '/admin/' . $area['icon'] . '" alt="">'; |
| 143 | + } else { |
|
| 144 | + $menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<span class="generic_icons ' . $area['icon'] . '"></span>'; |
|
| 137 | 145 | } |
| 138 | - else |
|
| 139 | - $menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<span class="generic_icons ' . $area['icon'] . '"></span>'; |
|
| 146 | + } else { |
|
| 147 | + $menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<span class="generic_icons ' . $area_id . '"></span>'; |
|
| 140 | 148 | } |
| 141 | - else |
|
| 142 | - $menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<span class="generic_icons ' . $area_id . '"></span>'; |
|
| 143 | 149 | |
| 144 | 150 | if (isset($area['icon_class']) && empty($menu_context['sections'][$section_id]['areas'][$area_id]['icon'])) |
| 145 | 151 | { |
| 146 | 152 | $menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . $area['icon_class']; |
| 147 | - } |
|
| 148 | - elseif (isset($area['icon'])) |
|
| 153 | + } elseif (isset($area['icon'])) |
|
| 149 | 154 | { |
| 150 | 155 | if (substr($area['icon'], -4) === '.png' || substr($area['icon'], -4) === '.gif') |
| 151 | 156 | { |
| 152 | 157 | if (file_exists($settings['theme_dir'] . '/images/admin/big/' . $area['icon'])) |
| 153 | 158 | { |
| 154 | 159 | $menu_context['sections'][$section_id]['areas'][$area_id]['icon_file'] = $settings['theme_url'] . '/images/admin/big/' . $area['icon']; |
| 155 | - } |
|
| 156 | - elseif (file_exists($settings['default_theme_dir'] . '/images/admin/big/' . $area['icon'])) |
|
| 160 | + } elseif (file_exists($settings['default_theme_dir'] . '/images/admin/big/' . $area['icon'])) |
|
| 157 | 161 | { |
| 158 | 162 | $menu_context['sections'][$section_id]['areas'][$area_id]['icon_file'] = $settings['default_theme_url'] . '/images/admin/big/' . $area['icon']; |
| 159 | 163 | } |
| 160 | 164 | } |
| 161 | 165 | |
| 162 | 166 | $menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . str_replace(array('.png', '.gif'), '', $area['icon']); |
| 167 | + } else { |
|
| 168 | + $menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . str_replace(array('.png', '.gif'), '', $area_id); |
|
| 163 | 169 | } |
| 164 | - else |
|
| 165 | - $menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . str_replace(array('.png', '.gif'), '', $area_id); |
|
| 166 | 170 | |
| 167 | 171 | // This is a shortcut for Font-Icon users so they don't have to re-do whole CSS. |
| 168 | 172 | $menu_context['sections'][$section_id]['areas'][$area_id]['plain_class'] = !empty($area['icon']) ? $area['icon'] : ''; |
@@ -179,35 +183,41 @@ discard block |
||
| 179 | 183 | { |
| 180 | 184 | if ((empty($sub[1]) || allowedTo($sub[1])) && (!isset($sub['enabled']) || !empty($sub['enabled']))) |
| 181 | 185 | { |
| 182 | - if ($first_sa == null) |
|
| 183 | - $first_sa = $sa; |
|
| 186 | + if ($first_sa == null) { |
|
| 187 | + $first_sa = $sa; |
|
| 188 | + } |
|
| 184 | 189 | |
| 185 | 190 | $menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa] = array('label' => $sub[0]); |
| 186 | 191 | // Custom URL? |
| 187 | - if (isset($sub['url'])) |
|
| 188 | - $menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa]['url'] = $sub['url']; |
|
| 192 | + if (isset($sub['url'])) { |
|
| 193 | + $menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa]['url'] = $sub['url']; |
|
| 194 | + } |
|
| 189 | 195 | |
| 190 | 196 | // A bit complicated - but is this set? |
| 191 | 197 | if ($menu_context['current_area'] == $area_id) |
| 192 | 198 | { |
| 193 | 199 | // Save which is the first... |
| 194 | - if (empty($first_sa)) |
|
| 195 | - $first_sa = $sa; |
|
| 200 | + if (empty($first_sa)) { |
|
| 201 | + $first_sa = $sa; |
|
| 202 | + } |
|
| 196 | 203 | |
| 197 | 204 | // Is this the current subsection? |
| 198 | - if (isset($_REQUEST['sa']) && $_REQUEST['sa'] == $sa) |
|
| 199 | - $menu_context['current_subsection'] = $sa; |
|
| 205 | + if (isset($_REQUEST['sa']) && $_REQUEST['sa'] == $sa) { |
|
| 206 | + $menu_context['current_subsection'] = $sa; |
|
| 207 | + } |
|
| 200 | 208 | // Otherwise is it the default? |
| 201 | - elseif (!isset($menu_context['current_subsection']) && !empty($sub[2])) |
|
| 202 | - $menu_context['current_subsection'] = $sa; |
|
| 209 | + elseif (!isset($menu_context['current_subsection']) && !empty($sub[2])) { |
|
| 210 | + $menu_context['current_subsection'] = $sa; |
|
| 211 | + } |
|
| 203 | 212 | } |
| 204 | 213 | |
| 205 | 214 | // Let's assume this is the last, for now. |
| 206 | 215 | $last_sa = $sa; |
| 207 | 216 | } |
| 208 | 217 | // Mark it as disabled... |
| 209 | - else |
|
| 210 | - $menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa]['disabled'] = true; |
|
| 218 | + else { |
|
| 219 | + $menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa]['disabled'] = true; |
|
| 220 | + } |
|
| 211 | 221 | } |
| 212 | 222 | |
| 213 | 223 | // Set which one is first, last and selected in the group. |
@@ -216,8 +226,9 @@ discard block |
||
| 216 | 226 | $menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$context['right_to_left'] ? $last_sa : $first_sa]['is_first'] = true; |
| 217 | 227 | $menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$context['right_to_left'] ? $first_sa : $last_sa]['is_last'] = true; |
| 218 | 228 | |
| 219 | - if ($menu_context['current_area'] == $area_id && !isset($menu_context['current_subsection'])) |
|
| 220 | - $menu_context['current_subsection'] = $first_sa; |
|
| 229 | + if ($menu_context['current_area'] == $area_id && !isset($menu_context['current_subsection'])) { |
|
| 230 | + $menu_context['current_subsection'] = $first_sa; |
|
| 231 | + } |
|
| 221 | 232 | } |
| 222 | 233 | } |
| 223 | 234 | } |
@@ -251,23 +262,26 @@ discard block |
||
| 251 | 262 | $menu_context['base_url'] = isset($menuOptions['base_url']) ? $menuOptions['base_url'] : $scripturl . '?action=' . $menu_context['current_action']; |
| 252 | 263 | |
| 253 | 264 | // If we didn't find the area we were looking for go to a default one. |
| 254 | - if (isset($backup_area) && empty($found_section)) |
|
| 255 | - $menu_context['current_area'] = $backup_area; |
|
| 265 | + if (isset($backup_area) && empty($found_section)) { |
|
| 266 | + $menu_context['current_area'] = $backup_area; |
|
| 267 | + } |
|
| 256 | 268 | |
| 257 | 269 | // If there are sections quickly goes through all the sections to check if the base menu has an url |
| 258 | 270 | if (!empty($menu_context['current_section'])) |
| 259 | 271 | { |
| 260 | 272 | $menu_context['sections'][$menu_context['current_section']]['selected'] = true; |
| 261 | 273 | $menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['selected'] = true; |
| 262 | - if (!empty($menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['subsections'][$context['current_subaction']])) |
|
| 263 | - $menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['subsections'][$context['current_subaction']]['selected'] = true; |
|
| 274 | + if (!empty($menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['subsections'][$context['current_subaction']])) { |
|
| 275 | + $menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['subsections'][$context['current_subaction']]['selected'] = true; |
|
| 276 | + } |
|
| 264 | 277 | |
| 265 | - foreach ($menu_context['sections'] as $section_id => $section) |
|
| 266 | - foreach ($section['areas'] as $area_id => $area) |
|
| 278 | + foreach ($menu_context['sections'] as $section_id => $section) { |
|
| 279 | + foreach ($section['areas'] as $area_id => $area) |
|
| 267 | 280 | { |
| 268 | 281 | if (!isset($menu_context['sections'][$section_id]['url'])) |
| 269 | 282 | { |
| 270 | 283 | $menu_context['sections'][$section_id]['url'] = isset($area['url']) ? $area['url'] : $menu_context['base_url'] . ';area=' . $area_id; |
| 284 | + } |
|
| 271 | 285 | break; |
| 272 | 286 | } |
| 273 | 287 | } |
@@ -278,8 +292,9 @@ discard block |
||
| 278 | 292 | { |
| 279 | 293 | // Never happened! |
| 280 | 294 | $context['max_menu_id']--; |
| 281 | - if ($context['max_menu_id'] == 0) |
|
| 282 | - unset($context['max_menu_id']); |
|
| 295 | + if ($context['max_menu_id'] == 0) { |
|
| 296 | + unset($context['max_menu_id']); |
|
| 297 | + } |
|
| 283 | 298 | |
| 284 | 299 | return false; |
| 285 | 300 | } |
@@ -290,8 +305,9 @@ discard block |
||
| 290 | 305 | $context['template_layers'][] = $menu_context['layer_name']; |
| 291 | 306 | |
| 292 | 307 | // Check we had something - for sanity sake. |
| 293 | - if (empty($include_data)) |
|
| 294 | - return false; |
|
| 308 | + if (empty($include_data)) { |
|
| 309 | + return false; |
|
| 310 | + } |
|
| 295 | 311 | |
| 296 | 312 | // Finally - return information on the selected item. |
| 297 | 313 | $include_data += array( |
@@ -314,12 +330,14 @@ discard block |
||
| 314 | 330 | global $context; |
| 315 | 331 | |
| 316 | 332 | $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; |
| 317 | - if (!isset($context[$menu_name])) |
|
| 318 | - return false; |
|
| 333 | + if (!isset($context[$menu_name])) { |
|
| 334 | + return false; |
|
| 335 | + } |
|
| 319 | 336 | |
| 320 | 337 | $layer_index = array_search($context[$menu_name]['layer_name'], $context['template_layers']); |
| 321 | - if ($layer_index !== false) |
|
| 322 | - unset($context['template_layers'][$layer_index]); |
|
| 338 | + if ($layer_index !== false) { |
|
| 339 | + unset($context['template_layers'][$layer_index]); |
|
| 340 | + } |
|
| 323 | 341 | |
| 324 | 342 | unset($context[$menu_name]); |
| 325 | 343 | } |
@@ -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) = $smcFunc['json_decode']($_COOKIE[$cookiename], true); |
| 103 | 107 | |
| 104 | 108 | // That didn't work... Maybe it's using serialize? |
| 105 | - if (is_null($timeout)) |
|
| 106 | - list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]); |
|
| 107 | - } |
|
| 108 | - elseif (isset($_SESSION['login_' . $cookiename])) |
|
| 109 | + if (is_null($timeout)) { |
|
| 110 | + list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]); |
|
| 111 | + } |
|
| 112 | + } elseif (isset($_SESSION['login_' . $cookiename])) |
|
| 109 | 113 | { |
| 110 | 114 | list (,, $timeout) = $smcFunc['json_decode']($_SESSION['login_' . $cookiename]); |
| 111 | 115 | |
| 112 | 116 | // Try for old format |
| 113 | - if (is_null($timeout)) |
|
| 114 | - list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]); |
|
| 117 | + if (is_null($timeout)) { |
|
| 118 | + list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]); |
|
| 119 | + } |
|
| 120 | + } else { |
|
| 121 | + trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR); |
|
| 115 | 122 | } |
| 116 | - else |
|
| 117 | - trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR); |
|
| 118 | 123 | |
| 119 | 124 | $user_settings['password_salt'] = substr(md5(mt_rand()), 0, 4); |
| 120 | 125 | updateMemberData($user_info['id'], array('password_salt' => $user_settings['password_salt'])); |
@@ -127,10 +132,11 @@ discard block |
||
| 127 | 132 | list ($tfamember, $tfasecret, $exp, $state, $preserve) = $tfadata; |
| 128 | 133 | |
| 129 | 134 | // If we're preserving the cookie, reset it with updated salt |
| 130 | - if (isset($tfamember, $tfasecret, $exp, $state, $preserve) && $preserve && time() < $exp) |
|
| 131 | - setTFACookie(3153600, $user_info['password_salt'], hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']), true); |
|
| 132 | - else |
|
| 133 | - setTFACookie(-3600, 0, ''); |
|
| 135 | + if (isset($tfamember, $tfasecret, $exp, $state, $preserve) && $preserve && time() < $exp) { |
|
| 136 | + setTFACookie(3153600, $user_info['password_salt'], hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']), true); |
|
| 137 | + } else { |
|
| 138 | + setTFACookie(-3600, 0, ''); |
|
| 139 | + } |
|
| 134 | 140 | } |
| 135 | 141 | |
| 136 | 142 | setLoginCookie($timeout - time(), $user_info['id'], hash_salt($user_settings['passwd'], $user_settings['password_salt'])); |
@@ -141,20 +147,20 @@ discard block |
||
| 141 | 147 | elseif (isset($_GET['sa']) && $_GET['sa'] == 'check') |
| 142 | 148 | { |
| 143 | 149 | // Strike! You're outta there! |
| 144 | - if ($_GET['member'] != $user_info['id']) |
|
| 145 | - fatal_lang_error('login_cookie_error', false); |
|
| 150 | + if ($_GET['member'] != $user_info['id']) { |
|
| 151 | + fatal_lang_error('login_cookie_error', false); |
|
| 152 | + } |
|
| 146 | 153 | |
| 147 | 154 | $user_info['can_mod'] = allowedTo('access_mod_center') || (!$user_info['is_guest'] && ($user_info['mod_cache']['gq'] != '0=1' || $user_info['mod_cache']['bq'] != '0=1' || ($modSettings['postmod_active'] && !empty($user_info['mod_cache']['ap'])))); |
| 148 | 155 | |
| 149 | 156 | // Some whitelisting for login_url... |
| 150 | - if (empty($_SESSION['login_url'])) |
|
| 151 | - redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa'); |
|
| 152 | - elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false)) |
|
| 157 | + if (empty($_SESSION['login_url'])) { |
|
| 158 | + redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa'); |
|
| 159 | + } elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false)) |
|
| 153 | 160 | { |
| 154 | 161 | unset ($_SESSION['login_url']); |
| 155 | 162 | redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa'); |
| 156 | - } |
|
| 157 | - else |
|
| 163 | + } else |
|
| 158 | 164 | { |
| 159 | 165 | // Best not to clutter the session data too much... |
| 160 | 166 | $temp = $_SESSION['login_url']; |
@@ -165,8 +171,9 @@ discard block |
||
| 165 | 171 | } |
| 166 | 172 | |
| 167 | 173 | // Beyond this point you are assumed to be a guest trying to login. |
| 168 | - if (!$user_info['is_guest']) |
|
| 169 | - redirectexit(); |
|
| 174 | + if (!$user_info['is_guest']) { |
|
| 175 | + redirectexit(); |
|
| 176 | + } |
|
| 170 | 177 | |
| 171 | 178 | // Are you guessing with a script? |
| 172 | 179 | checkSession(); |
@@ -174,18 +181,21 @@ discard block |
||
| 174 | 181 | spamProtection('login'); |
| 175 | 182 | |
| 176 | 183 | // Set the login_url if it's not already set (but careful not to send us to an attachment). |
| 177 | - if ((empty($_SESSION['login_url']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) || (isset($_GET['quicklogin']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'login') === false)) |
|
| 178 | - $_SESSION['login_url'] = $_SESSION['old_url']; |
|
| 184 | + if ((empty($_SESSION['login_url']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) || (isset($_GET['quicklogin']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'login') === false)) { |
|
| 185 | + $_SESSION['login_url'] = $_SESSION['old_url']; |
|
| 186 | + } |
|
| 179 | 187 | |
| 180 | 188 | // Been guessing a lot, haven't we? |
| 181 | - if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3) |
|
| 182 | - fatal_lang_error('login_threshold_fail', 'login'); |
|
| 189 | + if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3) { |
|
| 190 | + fatal_lang_error('login_threshold_fail', 'login'); |
|
| 191 | + } |
|
| 183 | 192 | |
| 184 | 193 | // Set up the cookie length. (if it's invalid, just fall through and use the default.) |
| 185 | - if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1)) |
|
| 186 | - $modSettings['cookieTime'] = 3153600; |
|
| 187 | - elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 525600)) |
|
| 188 | - $modSettings['cookieTime'] = (int) $_POST['cookielength']; |
|
| 194 | + if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1)) { |
|
| 195 | + $modSettings['cookieTime'] = 3153600; |
|
| 196 | + } elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 525600)) { |
|
| 197 | + $modSettings['cookieTime'] = (int) $_POST['cookielength']; |
|
| 198 | + } |
|
| 189 | 199 | |
| 190 | 200 | loadLanguage('Login'); |
| 191 | 201 | // Load the template stuff. |
@@ -305,8 +315,9 @@ discard block |
||
| 305 | 315 | $other_passwords[] = crypt(md5($_POST['passwrd']), md5($_POST['passwrd'])); |
| 306 | 316 | |
| 307 | 317 | // Snitz style - SHA-256. Technically, this is a downgrade, but most PHP configurations don't support sha256 anyway. |
| 308 | - if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256')) |
|
| 309 | - $other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd'])); |
|
| 318 | + if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256')) { |
|
| 319 | + $other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd'])); |
|
| 320 | + } |
|
| 310 | 321 | |
| 311 | 322 | // phpBB3 users new hashing. We now support it as well ;). |
| 312 | 323 | $other_passwords[] = phpBB3_password_check($_POST['passwrd'], $user_settings['passwd']); |
@@ -326,27 +337,29 @@ discard block |
||
| 326 | 337 | // Some common md5 ones. |
| 327 | 338 | $other_passwords[] = md5($user_settings['password_salt'] . $_POST['passwrd']); |
| 328 | 339 | $other_passwords[] = md5($_POST['passwrd'] . $user_settings['password_salt']); |
| 329 | - } |
|
| 330 | - elseif (strlen($user_settings['passwd']) == 40) |
|
| 340 | + } elseif (strlen($user_settings['passwd']) == 40) |
|
| 331 | 341 | { |
| 332 | 342 | // Maybe they are using a hash from before the password fix. |
| 333 | 343 | // This is also valid for SMF 1.1 to 2.0 style of hashing, changed to bcrypt in SMF 2.1 |
| 334 | 344 | $other_passwords[] = sha1(strtolower($user_settings['member_name']) . un_htmlspecialchars($_POST['passwrd'])); |
| 335 | 345 | |
| 336 | 346 | // BurningBoard3 style of hashing. |
| 337 | - if (!empty($modSettings['enable_password_conversion'])) |
|
| 338 | - $other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd']))); |
|
| 347 | + if (!empty($modSettings['enable_password_conversion'])) { |
|
| 348 | + $other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd']))); |
|
| 349 | + } |
|
| 339 | 350 | |
| 340 | 351 | // Perhaps we converted to UTF-8 and have a valid password being hashed differently. |
| 341 | 352 | if ($context['character_set'] == 'UTF-8' && !empty($modSettings['previousCharacterSet']) && $modSettings['previousCharacterSet'] != 'utf8') |
| 342 | 353 | { |
| 343 | 354 | // Try iconv first, for no particular reason. |
| 344 | - if (function_exists('iconv')) |
|
| 345 | - $other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd']))); |
|
| 355 | + if (function_exists('iconv')) { |
|
| 356 | + $other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd']))); |
|
| 357 | + } |
|
| 346 | 358 | |
| 347 | 359 | // Say it aint so, iconv failed! |
| 348 | - if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding')) |
|
| 349 | - $other_passwords[] = sha1(strtolower(mb_convert_encoding($user_settings['member_name'], 'UTF-8', $modSettings['previousCharacterSet'])) . un_htmlspecialchars(mb_convert_encoding($_POST['passwrd'], 'UTF-8', $modSettings['previousCharacterSet']))); |
|
| 360 | + if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding')) { |
|
| 361 | + $other_passwords[] = sha1(strtolower(mb_convert_encoding($user_settings['member_name'], 'UTF-8', $modSettings['previousCharacterSet'])) . un_htmlspecialchars(mb_convert_encoding($_POST['passwrd'], 'UTF-8', $modSettings['previousCharacterSet']))); |
|
| 362 | + } |
|
| 350 | 363 | } |
| 351 | 364 | } |
| 352 | 365 | |
@@ -376,8 +389,9 @@ discard block |
||
| 376 | 389 | $_SESSION['failed_login'] = isset($_SESSION['failed_login']) ? ($_SESSION['failed_login'] + 1) : 1; |
| 377 | 390 | |
| 378 | 391 | // Hmm... don't remember it, do you? Here, try the password reminder ;). |
| 379 | - if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold']) |
|
| 380 | - redirectexit('action=reminder'); |
|
| 392 | + if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold']) { |
|
| 393 | + redirectexit('action=reminder'); |
|
| 394 | + } |
|
| 381 | 395 | // We'll give you another chance... |
| 382 | 396 | else |
| 383 | 397 | { |
@@ -388,8 +402,7 @@ discard block |
||
| 388 | 402 | return; |
| 389 | 403 | } |
| 390 | 404 | } |
| 391 | - } |
|
| 392 | - elseif (!empty($user_settings['passwd_flood'])) |
|
| 405 | + } elseif (!empty($user_settings['passwd_flood'])) |
|
| 393 | 406 | { |
| 394 | 407 | // Let's be sure they weren't a little hacker. |
| 395 | 408 | validatePasswordFlood($user_settings['id_member'], $user_settings['member_name'], $user_settings['passwd_flood'], true); |
@@ -406,8 +419,9 @@ discard block |
||
| 406 | 419 | } |
| 407 | 420 | |
| 408 | 421 | // Check their activation status. |
| 409 | - if (!checkActivation()) |
|
| 410 | - return; |
|
| 422 | + if (!checkActivation()) { |
|
| 423 | + return; |
|
| 424 | + } |
|
| 411 | 425 | |
| 412 | 426 | DoLogin(); |
| 413 | 427 | } |
@@ -419,8 +433,9 @@ discard block |
||
| 419 | 433 | { |
| 420 | 434 | global $sourcedir, $txt, $context, $user_info, $modSettings, $scripturl; |
| 421 | 435 | |
| 422 | - if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode'])) |
|
| 423 | - fatal_lang_error('no_access', false); |
|
| 436 | + if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode'])) { |
|
| 437 | + fatal_lang_error('no_access', false); |
|
| 438 | + } |
|
| 424 | 439 | |
| 425 | 440 | loadLanguage('Profile'); |
| 426 | 441 | require_once($sourcedir . '/Class-TOTP.php'); |
@@ -428,8 +443,9 @@ discard block |
||
| 428 | 443 | $member = $context['tfa_member']; |
| 429 | 444 | |
| 430 | 445 | // Prevent replay attacks by limiting at least 2 minutes before they can log in again via 2FA |
| 431 | - if (time() - $member['last_login'] < 120) |
|
| 432 | - fatal_lang_error('tfa_wait', false); |
|
| 446 | + if (time() - $member['last_login'] < 120) { |
|
| 447 | + fatal_lang_error('tfa_wait', false); |
|
| 448 | + } |
|
| 433 | 449 | |
| 434 | 450 | $totp = new \TOTP\Auth($member['tfa_secret']); |
| 435 | 451 | $totp->setRange(1); |
@@ -443,8 +459,9 @@ discard block |
||
| 443 | 459 | if (!empty($_POST['tfa_code']) && empty($_POST['tfa_backup'])) |
| 444 | 460 | { |
| 445 | 461 | // Check to ensure we're forcing SSL for authentication |
| 446 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) |
|
| 447 | - fatal_lang_error('login_ssl_required'); |
|
| 462 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) { |
|
| 463 | + fatal_lang_error('login_ssl_required'); |
|
| 464 | + } |
|
| 448 | 465 | |
| 449 | 466 | $code = $_POST['tfa_code']; |
| 450 | 467 | |
@@ -454,20 +471,19 @@ discard block |
||
| 454 | 471 | |
| 455 | 472 | setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt']), !empty($_POST['tfa_preserve'])); |
| 456 | 473 | redirectexit(); |
| 457 | - } |
|
| 458 | - else |
|
| 474 | + } else |
|
| 459 | 475 | { |
| 460 | 476 | validatePasswordFlood($member['id_member'], $member['member_name'], $member['passwd_flood'], false, true); |
| 461 | 477 | |
| 462 | 478 | $context['tfa_error'] = true; |
| 463 | 479 | $context['tfa_value'] = $_POST['tfa_code']; |
| 464 | 480 | } |
| 465 | - } |
|
| 466 | - elseif (!empty($_POST['tfa_backup'])) |
|
| 481 | + } elseif (!empty($_POST['tfa_backup'])) |
|
| 467 | 482 | { |
| 468 | 483 | // Check to ensure we're forcing SSL for authentication |
| 469 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) |
|
| 470 | - fatal_lang_error('login_ssl_required'); |
|
| 484 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) { |
|
| 485 | + fatal_lang_error('login_ssl_required'); |
|
| 486 | + } |
|
| 471 | 487 | |
| 472 | 488 | $backup = $_POST['tfa_backup']; |
| 473 | 489 | |
@@ -481,8 +497,7 @@ discard block |
||
| 481 | 497 | )); |
| 482 | 498 | setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt'])); |
| 483 | 499 | redirectexit('action=profile;area=tfasetup;backup'); |
| 484 | - } |
|
| 485 | - else |
|
| 500 | + } else |
|
| 486 | 501 | { |
| 487 | 502 | validatePasswordFlood($member['id_member'], $member['member_name'], $member['passwd_flood'], false, true); |
| 488 | 503 | |
@@ -505,8 +520,9 @@ discard block |
||
| 505 | 520 | { |
| 506 | 521 | global $context, $txt, $scripturl, $user_settings, $modSettings; |
| 507 | 522 | |
| 508 | - if (!isset($context['login_errors'])) |
|
| 509 | - $context['login_errors'] = array(); |
|
| 523 | + if (!isset($context['login_errors'])) { |
|
| 524 | + $context['login_errors'] = array(); |
|
| 525 | + } |
|
| 510 | 526 | |
| 511 | 527 | // What is the true activation status of this account? |
| 512 | 528 | $activation_status = $user_settings['is_activated'] > 10 ? $user_settings['is_activated'] - 10 : $user_settings['is_activated']; |
@@ -518,8 +534,9 @@ discard block |
||
| 518 | 534 | return false; |
| 519 | 535 | } |
| 520 | 536 | // Awaiting approval still? |
| 521 | - elseif ($activation_status == 3) |
|
| 522 | - fatal_lang_error('still_awaiting_approval', 'user'); |
|
| 537 | + elseif ($activation_status == 3) { |
|
| 538 | + fatal_lang_error('still_awaiting_approval', 'user'); |
|
| 539 | + } |
|
| 523 | 540 | // Awaiting deletion, changed their mind? |
| 524 | 541 | elseif ($activation_status == 4) |
| 525 | 542 | { |
@@ -527,8 +544,7 @@ discard block |
||
| 527 | 544 | { |
| 528 | 545 | updateMemberData($user_settings['id_member'], array('is_activated' => 1)); |
| 529 | 546 | updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 0 ? $modSettings['unapprovedMembers'] - 1 : 0))); |
| 530 | - } |
|
| 531 | - else |
|
| 547 | + } else |
|
| 532 | 548 | { |
| 533 | 549 | $context['disable_login_hashing'] = true; |
| 534 | 550 | $context['login_errors'][] = $txt['awaiting_delete_account']; |
@@ -568,8 +584,9 @@ discard block |
||
| 568 | 584 | setLoginCookie(60 * $modSettings['cookieTime'], $user_settings['id_member'], hash_salt($user_settings['passwd'], $user_settings['password_salt'])); |
| 569 | 585 | |
| 570 | 586 | // Reset the login threshold. |
| 571 | - if (isset($_SESSION['failed_login'])) |
|
| 572 | - unset($_SESSION['failed_login']); |
|
| 587 | + if (isset($_SESSION['failed_login'])) { |
|
| 588 | + unset($_SESSION['failed_login']); |
|
| 589 | + } |
|
| 573 | 590 | |
| 574 | 591 | $user_info['is_guest'] = false; |
| 575 | 592 | $user_settings['additional_groups'] = explode(',', $user_settings['additional_groups']); |
@@ -591,16 +608,18 @@ discard block |
||
| 591 | 608 | 'id_member' => $user_info['id'], |
| 592 | 609 | ) |
| 593 | 610 | ); |
| 594 | - if ($smcFunc['db_num_rows']($request) == 1) |
|
| 595 | - $_SESSION['first_login'] = true; |
|
| 596 | - else |
|
| 597 | - unset($_SESSION['first_login']); |
|
| 611 | + if ($smcFunc['db_num_rows']($request) == 1) { |
|
| 612 | + $_SESSION['first_login'] = true; |
|
| 613 | + } else { |
|
| 614 | + unset($_SESSION['first_login']); |
|
| 615 | + } |
|
| 598 | 616 | $smcFunc['db_free_result']($request); |
| 599 | 617 | |
| 600 | 618 | // You've logged in, haven't you? |
| 601 | 619 | $update = array('member_ip' => $user_info['ip'], 'member_ip2' => $_SERVER['BAN_CHECK_IP']); |
| 602 | - if (empty($user_settings['tfa_secret'])) |
|
| 603 | - $update['last_login'] = time(); |
|
| 620 | + if (empty($user_settings['tfa_secret'])) { |
|
| 621 | + $update['last_login'] = time(); |
|
| 622 | + } |
|
| 604 | 623 | updateMemberData($user_info['id'], $update); |
| 605 | 624 | |
| 606 | 625 | // Get rid of the online entry for that old guest.... |
@@ -614,8 +633,8 @@ discard block |
||
| 614 | 633 | $_SESSION['log_time'] = 0; |
| 615 | 634 | |
| 616 | 635 | // Log this entry, only if we have it enabled. |
| 617 | - if (!empty($modSettings['loginHistoryDays'])) |
|
| 618 | - $smcFunc['db_insert']('insert', |
|
| 636 | + if (!empty($modSettings['loginHistoryDays'])) { |
|
| 637 | + $smcFunc['db_insert']('insert', |
|
| 619 | 638 | '{db_prefix}member_logins', |
| 620 | 639 | array( |
| 621 | 640 | 'id_member' => 'int', 'time' => 'int', 'ip' => 'inet', 'ip2' => 'inet', |
@@ -627,13 +646,15 @@ discard block |
||
| 627 | 646 | 'id_member', 'time' |
| 628 | 647 | ) |
| 629 | 648 | ); |
| 649 | + } |
|
| 630 | 650 | |
| 631 | 651 | // Just log you back out if it's in maintenance mode and you AREN'T an admin. |
| 632 | - if (empty($maintenance) || allowedTo('admin_forum')) |
|
| 633 | - redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']); |
|
| 634 | - else |
|
| 635 | - redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']); |
|
| 636 | -} |
|
| 652 | + if (empty($maintenance) || allowedTo('admin_forum')) { |
|
| 653 | + redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']); |
|
| 654 | + } else { |
|
| 655 | + redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']); |
|
| 656 | + } |
|
| 657 | + } |
|
| 637 | 658 | |
| 638 | 659 | /** |
| 639 | 660 | * Logs the current user out of their account. |
@@ -649,13 +670,15 @@ discard block |
||
| 649 | 670 | global $sourcedir, $user_info, $user_settings, $context, $smcFunc, $cookiename, $modSettings; |
| 650 | 671 | |
| 651 | 672 | // Make sure they aren't being auto-logged out. |
| 652 | - if (!$internal) |
|
| 653 | - checkSession('get'); |
|
| 673 | + if (!$internal) { |
|
| 674 | + checkSession('get'); |
|
| 675 | + } |
|
| 654 | 676 | |
| 655 | 677 | require_once($sourcedir . '/Subs-Auth.php'); |
| 656 | 678 | |
| 657 | - if (isset($_SESSION['pack_ftp'])) |
|
| 658 | - $_SESSION['pack_ftp'] = null; |
|
| 679 | + if (isset($_SESSION['pack_ftp'])) { |
|
| 680 | + $_SESSION['pack_ftp'] = null; |
|
| 681 | + } |
|
| 659 | 682 | |
| 660 | 683 | // It won't be first login anymore. |
| 661 | 684 | unset($_SESSION['first_login']); |
@@ -683,8 +706,9 @@ discard block |
||
| 683 | 706 | |
| 684 | 707 | // And some other housekeeping while we're at it. |
| 685 | 708 | $salt = substr(md5(mt_rand()), 0, 4); |
| 686 | - if (!empty($user_info['id'])) |
|
| 687 | - updateMemberData($user_info['id'], array('password_salt' => $salt)); |
|
| 709 | + if (!empty($user_info['id'])) { |
|
| 710 | + updateMemberData($user_info['id'], array('password_salt' => $salt)); |
|
| 711 | + } |
|
| 688 | 712 | |
| 689 | 713 | if (!empty($modSettings['tfa_mode']) && !empty($user_info['id']) && !empty($_COOKIE[$cookiename . '_tfa'])) |
| 690 | 714 | { |
@@ -693,10 +717,11 @@ discard block |
||
| 693 | 717 | list ($tfamember, $tfasecret, $exp, $state, $preserve) = $tfadata; |
| 694 | 718 | |
| 695 | 719 | // If we're preserving the cookie, reset it with updated salt |
| 696 | - if (isset($tfamember, $tfasecret, $exp, $state, $preserve) && $preserve && time() < $exp) |
|
| 697 | - setTFACookie(3153600, $user_info['id'], hash_salt($user_settings['tfa_backup'], $salt), true); |
|
| 698 | - else |
|
| 699 | - setTFACookie(-3600, 0, ''); |
|
| 720 | + if (isset($tfamember, $tfasecret, $exp, $state, $preserve) && $preserve && time() < $exp) { |
|
| 721 | + setTFACookie(3153600, $user_info['id'], hash_salt($user_settings['tfa_backup'], $salt), true); |
|
| 722 | + } else { |
|
| 723 | + setTFACookie(-3600, 0, ''); |
|
| 724 | + } |
|
| 700 | 725 | } |
| 701 | 726 | |
| 702 | 727 | session_destroy(); |
@@ -704,14 +729,13 @@ discard block |
||
| 704 | 729 | // Off to the merry board index we go! |
| 705 | 730 | if ($redirect) |
| 706 | 731 | { |
| 707 | - if (empty($_SESSION['logout_url'])) |
|
| 708 | - redirectexit('', $context['server']['needs_login_fix']); |
|
| 709 | - elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false)) |
|
| 732 | + if (empty($_SESSION['logout_url'])) { |
|
| 733 | + redirectexit('', $context['server']['needs_login_fix']); |
|
| 734 | + } elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false)) |
|
| 710 | 735 | { |
| 711 | 736 | unset ($_SESSION['logout_url']); |
| 712 | 737 | redirectexit(); |
| 713 | - } |
|
| 714 | - else |
|
| 738 | + } else |
|
| 715 | 739 | { |
| 716 | 740 | $temp = $_SESSION['logout_url']; |
| 717 | 741 | unset($_SESSION['logout_url']); |
@@ -744,8 +768,9 @@ discard block |
||
| 744 | 768 | function phpBB3_password_check($passwd, $passwd_hash) |
| 745 | 769 | { |
| 746 | 770 | // Too long or too short? |
| 747 | - if (strlen($passwd_hash) != 34) |
|
| 748 | - return; |
|
| 771 | + if (strlen($passwd_hash) != 34) { |
|
| 772 | + return; |
|
| 773 | + } |
|
| 749 | 774 | |
| 750 | 775 | // Range of characters allowed. |
| 751 | 776 | $range = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; |
@@ -756,8 +781,9 @@ discard block |
||
| 756 | 781 | $salt = substr($passwd_hash, 4, 8); |
| 757 | 782 | |
| 758 | 783 | $hash = md5($salt . $passwd, true); |
| 759 | - for (; $count != 0; --$count) |
|
| 760 | - $hash = md5($hash . $passwd, true); |
|
| 784 | + for (; $count != 0; --$count) { |
|
| 785 | + $hash = md5($hash . $passwd, true); |
|
| 786 | + } |
|
| 761 | 787 | |
| 762 | 788 | $output = substr($passwd_hash, 0, 12); |
| 763 | 789 | $i = 0; |
@@ -766,21 +792,25 @@ discard block |
||
| 766 | 792 | $value = ord($hash[$i++]); |
| 767 | 793 | $output .= $range[$value & 0x3f]; |
| 768 | 794 | |
| 769 | - if ($i < 16) |
|
| 770 | - $value |= ord($hash[$i]) << 8; |
|
| 795 | + if ($i < 16) { |
|
| 796 | + $value |= ord($hash[$i]) << 8; |
|
| 797 | + } |
|
| 771 | 798 | |
| 772 | 799 | $output .= $range[($value >> 6) & 0x3f]; |
| 773 | 800 | |
| 774 | - if ($i++ >= 16) |
|
| 775 | - break; |
|
| 801 | + if ($i++ >= 16) { |
|
| 802 | + break; |
|
| 803 | + } |
|
| 776 | 804 | |
| 777 | - if ($i < 16) |
|
| 778 | - $value |= ord($hash[$i]) << 16; |
|
| 805 | + if ($i < 16) { |
|
| 806 | + $value |= ord($hash[$i]) << 16; |
|
| 807 | + } |
|
| 779 | 808 | |
| 780 | 809 | $output .= $range[($value >> 12) & 0x3f]; |
| 781 | 810 | |
| 782 | - if ($i++ >= 16) |
|
| 783 | - break; |
|
| 811 | + if ($i++ >= 16) { |
|
| 812 | + break; |
|
| 813 | + } |
|
| 784 | 814 | |
| 785 | 815 | $output .= $range[($value >> 18) & 0x3f]; |
| 786 | 816 | } |
@@ -812,8 +842,9 @@ discard block |
||
| 812 | 842 | require_once($sourcedir . '/Subs-Auth.php'); |
| 813 | 843 | setLoginCookie(-3600, 0); |
| 814 | 844 | |
| 815 | - if (isset($_SESSION['login_' . $cookiename])) |
|
| 816 | - unset($_SESSION['login_' . $cookiename]); |
|
| 845 | + if (isset($_SESSION['login_' . $cookiename])) { |
|
| 846 | + unset($_SESSION['login_' . $cookiename]); |
|
| 847 | + } |
|
| 817 | 848 | } |
| 818 | 849 | |
| 819 | 850 | // We need a member! |
@@ -827,8 +858,9 @@ discard block |
||
| 827 | 858 | } |
| 828 | 859 | |
| 829 | 860 | // Right, have we got a flood value? |
| 830 | - if ($password_flood_value !== false) |
|
| 831 | - @list ($time_stamp, $number_tries) = explode('|', $password_flood_value); |
|
| 861 | + if ($password_flood_value !== false) { |
|
| 862 | + @list ($time_stamp, $number_tries) = explode('|', $password_flood_value); |
|
| 863 | + } |
|
| 832 | 864 | |
| 833 | 865 | // Timestamp or number of tries invalid? |
| 834 | 866 | if (empty($number_tries) || empty($time_stamp)) |
@@ -844,15 +876,17 @@ discard block |
||
| 844 | 876 | $number_tries = $time_stamp < time() - 20 ? 2 : $number_tries; |
| 845 | 877 | |
| 846 | 878 | // They are trying too fast, make them wait longer |
| 847 | - if ($time_stamp < time() - 10) |
|
| 848 | - $time_stamp = time(); |
|
| 879 | + if ($time_stamp < time() - 10) { |
|
| 880 | + $time_stamp = time(); |
|
| 881 | + } |
|
| 849 | 882 | } |
| 850 | 883 | |
| 851 | 884 | $number_tries++; |
| 852 | 885 | |
| 853 | 886 | // Broken the law? |
| 854 | - if ($number_tries > 5) |
|
| 855 | - fatal_lang_error('login_threshold_brute_fail', 'login', [$member_name]); |
|
| 887 | + if ($number_tries > 5) { |
|
| 888 | + fatal_lang_error('login_threshold_brute_fail', 'login', [$member_name]); |
|
| 889 | + } |
|
| 856 | 890 | |
| 857 | 891 | // Otherwise set the members data. If they correct on their first attempt then we actually clear it, otherwise we set it! |
| 858 | 892 | updateMemberData($id_member, array('passwd_flood' => $was_correct && $number_tries == 1 ? '' : $time_stamp . '|' . $number_tries)); |