@@ -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,8 +201,9 @@ 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 | 208 | elseif (strpos($_REQUEST['topic'], '.') !== false) |
| 194 | 209 | { |
@@ -199,19 +214,22 @@ discard block |
||
| 199 | 214 | |
| 200 | 215 | // Now make sure the online log gets the right number. |
| 201 | 216 | $_GET['topic'] = $topic; |
| 217 | + } else { |
|
| 218 | + $topic = 0; |
|
| 202 | 219 | } |
| 203 | - else |
|
| 204 | - $topic = 0; |
|
| 205 | 220 | |
| 206 | 221 | // There should be a $_REQUEST['start'], some at least. If you need to default to other than 0, use $_GET['start']. |
| 207 | - if (empty($_REQUEST['start']) || $_REQUEST['start'] < 0 || (int) $_REQUEST['start'] > 2147473647) |
|
| 208 | - $_REQUEST['start'] = 0; |
|
| 222 | + if (empty($_REQUEST['start']) || $_REQUEST['start'] < 0 || (int) $_REQUEST['start'] > 2147473647) { |
|
| 223 | + $_REQUEST['start'] = 0; |
|
| 224 | + } |
|
| 209 | 225 | |
| 210 | 226 | // The action needs to be a string and not an array or anything else |
| 211 | - if (isset($_REQUEST['action'])) |
|
| 212 | - $_REQUEST['action'] = (string) $_REQUEST['action']; |
|
| 213 | - if (isset($_GET['action'])) |
|
| 214 | - $_GET['action'] = (string) $_GET['action']; |
|
| 227 | + if (isset($_REQUEST['action'])) { |
|
| 228 | + $_REQUEST['action'] = (string) $_REQUEST['action']; |
|
| 229 | + } |
|
| 230 | + if (isset($_GET['action'])) { |
|
| 231 | + $_GET['action'] = (string) $_GET['action']; |
|
| 232 | + } |
|
| 215 | 233 | |
| 216 | 234 | // Some mail providers like to encode semicolons in activation URLs... |
| 217 | 235 | if (!empty($_REQUEST['action']) && substr($_SERVER['QUERY_STRING'], 0, 18) == 'action=activate%3b') |
@@ -237,29 +255,33 @@ discard block |
||
| 237 | 255 | $_SERVER['BAN_CHECK_IP'] = $_SERVER['REMOTE_ADDR']; |
| 238 | 256 | |
| 239 | 257 | // If we haven't specified how to handle Reverse Proxy IP headers, lets do what we always used to do. |
| 240 | - if (!isset($modSettings['proxy_ip_header'])) |
|
| 241 | - $modSettings['proxy_ip_header'] = 'autodetect'; |
|
| 258 | + if (!isset($modSettings['proxy_ip_header'])) { |
|
| 259 | + $modSettings['proxy_ip_header'] = 'autodetect'; |
|
| 260 | + } |
|
| 242 | 261 | |
| 243 | 262 | // Which headers are we going to check for Reverse Proxy IP headers? |
| 244 | - if ($modSettings['proxy_ip_header'] == 'disabled') |
|
| 245 | - $reverseIPheaders = array(); |
|
| 246 | - elseif ($modSettings['proxy_ip_header'] == 'autodetect') |
|
| 247 | - $reverseIPheaders = array('HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP'); |
|
| 248 | - else |
|
| 249 | - $reverseIPheaders = array($modSettings['proxy_ip_header']); |
|
| 263 | + if ($modSettings['proxy_ip_header'] == 'disabled') { |
|
| 264 | + $reverseIPheaders = array(); |
|
| 265 | + } elseif ($modSettings['proxy_ip_header'] == 'autodetect') { |
|
| 266 | + $reverseIPheaders = array('HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP'); |
|
| 267 | + } else { |
|
| 268 | + $reverseIPheaders = array($modSettings['proxy_ip_header']); |
|
| 269 | + } |
|
| 250 | 270 | |
| 251 | 271 | // Find the user's IP address. (but don't let it give you 'unknown'!) |
| 252 | 272 | foreach ($reverseIPheaders as $proxyIPheader) |
| 253 | 273 | { |
| 254 | 274 | // Ignore if this is not set. |
| 255 | - if (!isset($_SERVER[$proxyIPheader])) |
|
| 256 | - continue; |
|
| 275 | + if (!isset($_SERVER[$proxyIPheader])) { |
|
| 276 | + continue; |
|
| 277 | + } |
|
| 257 | 278 | |
| 258 | 279 | if (!empty($modSettings['proxy_ip_servers'])) |
| 259 | 280 | { |
| 260 | - foreach (explode(',', $modSettings['proxy_ip_servers']) as $proxy) |
|
| 261 | - if ($proxy == $_SERVER['REMOTE_ADDR'] || matchIPtoCIDR($_SERVER['REMOTE_ADDR'], $proxy)) |
|
| 281 | + foreach (explode(',', $modSettings['proxy_ip_servers']) as $proxy) { |
|
| 282 | + if ($proxy == $_SERVER['REMOTE_ADDR'] || matchIPtoCIDR($_SERVER['REMOTE_ADDR'], $proxy)) |
|
| 262 | 283 | continue; |
| 284 | + } |
|
| 263 | 285 | } |
| 264 | 286 | |
| 265 | 287 | // If there are commas, get the last one.. probably. |
@@ -279,8 +301,9 @@ discard block |
||
| 279 | 301 | |
| 280 | 302 | // Just incase we have a legacy IPv4 address. |
| 281 | 303 | // @ TODO: Convert to IPv6. |
| 282 | - 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) |
|
| 283 | - continue; |
|
| 304 | + 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) { |
|
| 305 | + continue; |
|
| 306 | + } |
|
| 284 | 307 | } |
| 285 | 308 | |
| 286 | 309 | continue; |
@@ -292,36 +315,40 @@ discard block |
||
| 292 | 315 | } |
| 293 | 316 | } |
| 294 | 317 | // Otherwise just use the only one. |
| 295 | - 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) |
|
| 296 | - $_SERVER['BAN_CHECK_IP'] = $_SERVER[$proxyIPheader]; |
|
| 297 | - elseif (!isValidIPv6($_SERVER[$proxyIPheader]) || preg_match('~::ffff:\d+\.\d+\.\d+\.\d+~', $_SERVER[$proxyIPheader]) !== 0) |
|
| 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) |
|
| 298 | 321 | { |
| 299 | 322 | $_SERVER[$proxyIPheader] = preg_replace('~^::ffff:(\d+\.\d+\.\d+\.\d+)~', '\1', $_SERVER[$proxyIPheader]); |
| 300 | 323 | |
| 301 | 324 | // Just incase we have a legacy IPv4 address. |
| 302 | 325 | // @ TODO: Convert to IPv6. |
| 303 | - 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) |
|
| 304 | - continue; |
|
| 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; |
|
| 328 | + } |
|
| 305 | 329 | } |
| 306 | 330 | } |
| 307 | 331 | |
| 308 | 332 | // Make sure we know the URL of the current request. |
| 309 | - if (empty($_SERVER['REQUEST_URI'])) |
|
| 310 | - $_SERVER['REQUEST_URL'] = $scripturl . (!empty($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : ''); |
|
| 311 | - elseif (preg_match('~^([^/]+//[^/]+)~', $scripturl, $match) == 1) |
|
| 312 | - $_SERVER['REQUEST_URL'] = $match[1] . $_SERVER['REQUEST_URI']; |
|
| 313 | - else |
|
| 314 | - $_SERVER['REQUEST_URL'] = $_SERVER['REQUEST_URI']; |
|
| 333 | + if (empty($_SERVER['REQUEST_URI'])) { |
|
| 334 | + $_SERVER['REQUEST_URL'] = $scripturl . (!empty($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : ''); |
|
| 335 | + } elseif (preg_match('~^([^/]+//[^/]+)~', $scripturl, $match) == 1) { |
|
| 336 | + $_SERVER['REQUEST_URL'] = $match[1] . $_SERVER['REQUEST_URI']; |
|
| 337 | + } else { |
|
| 338 | + $_SERVER['REQUEST_URL'] = $_SERVER['REQUEST_URI']; |
|
| 339 | + } |
|
| 315 | 340 | |
| 316 | 341 | // And make sure HTTP_USER_AGENT is set. |
| 317 | 342 | $_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)) : ''; |
| 318 | 343 | |
| 319 | 344 | // Some final checking. |
| 320 | - if (!isValidIP($_SERVER['BAN_CHECK_IP'])) |
|
| 321 | - $_SERVER['BAN_CHECK_IP'] = ''; |
|
| 322 | - if ($_SERVER['REMOTE_ADDR'] == 'unknown') |
|
| 323 | - $_SERVER['REMOTE_ADDR'] = ''; |
|
| 324 | -} |
|
| 345 | + if (!isValidIP($_SERVER['BAN_CHECK_IP'])) { |
|
| 346 | + $_SERVER['BAN_CHECK_IP'] = ''; |
|
| 347 | + } |
|
| 348 | + if ($_SERVER['REMOTE_ADDR'] == 'unknown') { |
|
| 349 | + $_SERVER['REMOTE_ADDR'] = ''; |
|
| 350 | + } |
|
| 351 | + } |
|
| 325 | 352 | |
| 326 | 353 | /** |
| 327 | 354 | * Validates a IPv6 address. returns true if it is ipv6. |
@@ -332,8 +359,9 @@ discard block |
||
| 332 | 359 | function isValidIPv6($ip) |
| 333 | 360 | { |
| 334 | 361 | //looking for : |
| 335 | - if (strpos($ip, ':') === false) |
|
| 336 | - return false; |
|
| 362 | + if (strpos($ip, ':') === false) { |
|
| 363 | + return false; |
|
| 364 | + } |
|
| 337 | 365 | |
| 338 | 366 | //check valid address |
| 339 | 367 | return inet_pton($ip); |
@@ -350,15 +378,17 @@ discard block |
||
| 350 | 378 | static $expanded = array(); |
| 351 | 379 | |
| 352 | 380 | // Check if we have done this already. |
| 353 | - if (isset($expanded[$ip])) |
|
| 354 | - return $expanded[$ip]; |
|
| 381 | + if (isset($expanded[$ip])) { |
|
| 382 | + return $expanded[$ip]; |
|
| 383 | + } |
|
| 355 | 384 | |
| 356 | 385 | // Expand the IP out. |
| 357 | 386 | $expanded_ip = explode(':', expandIPv6($ip)); |
| 358 | 387 | |
| 359 | 388 | $new_ip = array(); |
| 360 | - foreach ($expanded_ip as $int) |
|
| 361 | - $new_ip[] = hexdec($int); |
|
| 389 | + foreach ($expanded_ip as $int) { |
|
| 390 | + $new_ip[] = hexdec($int); |
|
| 391 | + } |
|
| 362 | 392 | |
| 363 | 393 | // Save this incase of repeated use. |
| 364 | 394 | $expanded[$ip] = $new_ip; |
@@ -378,8 +408,9 @@ discard block |
||
| 378 | 408 | static $converted = array(); |
| 379 | 409 | |
| 380 | 410 | // Check if we have done this already. |
| 381 | - if (isset($converted[$addr])) |
|
| 382 | - return $converted[$addr]; |
|
| 411 | + if (isset($converted[$addr])) { |
|
| 412 | + return $converted[$addr]; |
|
| 413 | + } |
|
| 383 | 414 | |
| 384 | 415 | // Check if there are segments missing, insert if necessary. |
| 385 | 416 | if (strpos($addr, '::') !== false) |
@@ -389,18 +420,20 @@ discard block |
||
| 389 | 420 | $part[1] = explode(':', $part[1]); |
| 390 | 421 | $missing = array(); |
| 391 | 422 | |
| 392 | - for ($i = 0; $i < (8 - (count($part[0]) + count($part[1]))); $i++) |
|
| 393 | - array_push($missing, '0000'); |
|
| 423 | + for ($i = 0; $i < (8 - (count($part[0]) + count($part[1]))); $i++) { |
|
| 424 | + array_push($missing, '0000'); |
|
| 425 | + } |
|
| 394 | 426 | |
| 395 | 427 | $part = array_merge($part[0], $missing, $part[1]); |
| 428 | + } else { |
|
| 429 | + $part = explode(':', $addr); |
|
| 396 | 430 | } |
| 397 | - else |
|
| 398 | - $part = explode(':', $addr); |
|
| 399 | 431 | |
| 400 | 432 | // Pad each segment until it has 4 digits. |
| 401 | - foreach ($part as &$p) |
|
| 402 | - while (strlen($p) < 4) |
|
| 433 | + foreach ($part as &$p) { |
|
| 434 | + while (strlen($p) < 4) |
|
| 403 | 435 | $p = '0' . $p; |
| 436 | + } |
|
| 404 | 437 | |
| 405 | 438 | unset($p); |
| 406 | 439 | |
@@ -411,11 +444,12 @@ discard block |
||
| 411 | 444 | $converted[$addr] = $result; |
| 412 | 445 | |
| 413 | 446 | // Quick check to make sure the length is as expected. |
| 414 | - if (!$strict_check || strlen($result) == 39) |
|
| 415 | - return $result; |
|
| 416 | - else |
|
| 417 | - return false; |
|
| 418 | -} |
|
| 447 | + if (!$strict_check || strlen($result) == 39) { |
|
| 448 | + return $result; |
|
| 449 | + } else { |
|
| 450 | + return false; |
|
| 451 | + } |
|
| 452 | + } |
|
| 419 | 453 | |
| 420 | 454 | |
| 421 | 455 | /** |
@@ -446,15 +480,17 @@ discard block |
||
| 446 | 480 | { |
| 447 | 481 | global $smcFunc; |
| 448 | 482 | |
| 449 | - if (!is_array($var)) |
|
| 450 | - return $smcFunc['db_escape_string']($var); |
|
| 483 | + if (!is_array($var)) { |
|
| 484 | + return $smcFunc['db_escape_string']($var); |
|
| 485 | + } |
|
| 451 | 486 | |
| 452 | 487 | // Reindex the array with slashes. |
| 453 | 488 | $new_var = array(); |
| 454 | 489 | |
| 455 | 490 | // Add slashes to every element, even the indexes! |
| 456 | - foreach ($var as $k => $v) |
|
| 457 | - $new_var[$smcFunc['db_escape_string']($k)] = escapestring__recursive($v); |
|
| 491 | + foreach ($var as $k => $v) { |
|
| 492 | + $new_var[$smcFunc['db_escape_string']($k)] = escapestring__recursive($v); |
|
| 493 | + } |
|
| 458 | 494 | |
| 459 | 495 | return $new_var; |
| 460 | 496 | } |
@@ -474,12 +510,14 @@ discard block |
||
| 474 | 510 | { |
| 475 | 511 | global $smcFunc; |
| 476 | 512 | |
| 477 | - if (!is_array($var)) |
|
| 478 | - return isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($var, ENT_QUOTES) : htmlspecialchars($var, ENT_QUOTES); |
|
| 513 | + if (!is_array($var)) { |
|
| 514 | + return isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($var, ENT_QUOTES) : htmlspecialchars($var, ENT_QUOTES); |
|
| 515 | + } |
|
| 479 | 516 | |
| 480 | 517 | // Add the htmlspecialchars to every element. |
| 481 | - foreach ($var as $k => $v) |
|
| 482 | - $var[$k] = $level > 25 ? null : htmlspecialchars__recursive($v, $level + 1); |
|
| 518 | + foreach ($var as $k => $v) { |
|
| 519 | + $var[$k] = $level > 25 ? null : htmlspecialchars__recursive($v, $level + 1); |
|
| 520 | + } |
|
| 483 | 521 | |
| 484 | 522 | return $var; |
| 485 | 523 | } |
@@ -497,15 +535,17 @@ discard block |
||
| 497 | 535 | */ |
| 498 | 536 | function urldecode__recursive($var, $level = 0) |
| 499 | 537 | { |
| 500 | - if (!is_array($var)) |
|
| 501 | - return urldecode($var); |
|
| 538 | + if (!is_array($var)) { |
|
| 539 | + return urldecode($var); |
|
| 540 | + } |
|
| 502 | 541 | |
| 503 | 542 | // Reindex the array... |
| 504 | 543 | $new_var = array(); |
| 505 | 544 | |
| 506 | 545 | // Add the htmlspecialchars to every element. |
| 507 | - foreach ($var as $k => $v) |
|
| 508 | - $new_var[urldecode($k)] = $level > 25 ? null : urldecode__recursive($v, $level + 1); |
|
| 546 | + foreach ($var as $k => $v) { |
|
| 547 | + $new_var[urldecode($k)] = $level > 25 ? null : urldecode__recursive($v, $level + 1); |
|
| 548 | + } |
|
| 509 | 549 | |
| 510 | 550 | return $new_var; |
| 511 | 551 | } |
@@ -523,15 +563,17 @@ discard block |
||
| 523 | 563 | { |
| 524 | 564 | global $smcFunc; |
| 525 | 565 | |
| 526 | - if (!is_array($var)) |
|
| 527 | - return $smcFunc['db_unescape_string']($var); |
|
| 566 | + if (!is_array($var)) { |
|
| 567 | + return $smcFunc['db_unescape_string']($var); |
|
| 568 | + } |
|
| 528 | 569 | |
| 529 | 570 | // Reindex the array without slashes, this time. |
| 530 | 571 | $new_var = array(); |
| 531 | 572 | |
| 532 | 573 | // Strip the slashes from every element. |
| 533 | - foreach ($var as $k => $v) |
|
| 534 | - $new_var[$smcFunc['db_unescape_string']($k)] = unescapestring__recursive($v); |
|
| 574 | + foreach ($var as $k => $v) { |
|
| 575 | + $new_var[$smcFunc['db_unescape_string']($k)] = unescapestring__recursive($v); |
|
| 576 | + } |
|
| 535 | 577 | |
| 536 | 578 | return $new_var; |
| 537 | 579 | } |
@@ -549,15 +591,17 @@ discard block |
||
| 549 | 591 | */ |
| 550 | 592 | function stripslashes__recursive($var, $level = 0) |
| 551 | 593 | { |
| 552 | - if (!is_array($var)) |
|
| 553 | - return stripslashes($var); |
|
| 594 | + if (!is_array($var)) { |
|
| 595 | + return stripslashes($var); |
|
| 596 | + } |
|
| 554 | 597 | |
| 555 | 598 | // Reindex the array without slashes, this time. |
| 556 | 599 | $new_var = array(); |
| 557 | 600 | |
| 558 | 601 | // Strip the slashes from every element. |
| 559 | - foreach ($var as $k => $v) |
|
| 560 | - $new_var[stripslashes($k)] = $level > 25 ? null : stripslashes__recursive($v, $level + 1); |
|
| 602 | + foreach ($var as $k => $v) { |
|
| 603 | + $new_var[stripslashes($k)] = $level > 25 ? null : stripslashes__recursive($v, $level + 1); |
|
| 604 | + } |
|
| 561 | 605 | |
| 562 | 606 | return $new_var; |
| 563 | 607 | } |
@@ -578,12 +622,14 @@ discard block |
||
| 578 | 622 | global $smcFunc; |
| 579 | 623 | |
| 580 | 624 | // Remove spaces (32), tabs (9), returns (13, 10, and 11), nulls (0), and hard spaces. (160) |
| 581 | - if (!is_array($var)) |
|
| 582 | - return isset($smcFunc) ? $smcFunc['htmltrim']($var) : trim($var, ' ' . "\t\n\r\x0B" . '\0' . "\xA0"); |
|
| 625 | + if (!is_array($var)) { |
|
| 626 | + return isset($smcFunc) ? $smcFunc['htmltrim']($var) : trim($var, ' ' . "\t\n\r\x0B" . '\0' . "\xA0"); |
|
| 627 | + } |
|
| 583 | 628 | |
| 584 | 629 | // Go through all the elements and remove the whitespace. |
| 585 | - foreach ($var as $k => $v) |
|
| 586 | - $var[$k] = $level > 25 ? null : htmltrim__recursive($v, $level + 1); |
|
| 630 | + foreach ($var as $k => $v) { |
|
| 631 | + $var[$k] = $level > 25 ? null : htmltrim__recursive($v, $level + 1); |
|
| 632 | + } |
|
| 587 | 633 | |
| 588 | 634 | return $var; |
| 589 | 635 | } |
@@ -648,30 +694,37 @@ discard block |
||
| 648 | 694 | global $scripturl, $modSettings, $context; |
| 649 | 695 | |
| 650 | 696 | // If $scripturl is set to nothing, or the SID is not defined (SSI?) just quit. |
| 651 | - if ($scripturl == '' || !defined('SID')) |
|
| 652 | - return $buffer; |
|
| 697 | + if ($scripturl == '' || !defined('SID')) { |
|
| 698 | + return $buffer; |
|
| 699 | + } |
|
| 653 | 700 | |
| 654 | 701 | // 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. |
| 655 | 702 | // @todo smflib |
| 656 | - if (empty($_COOKIE) && SID != '' && !isBrowser('possibly_robot')) |
|
| 657 | - $buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', '"' . $scripturl . '?' . SID . '&', $buffer); |
|
| 703 | + if (empty($_COOKIE) && SID != '' && !isBrowser('possibly_robot')) { |
|
| 704 | + $buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', '"' . $scripturl . '?' . SID . '&', $buffer); |
|
| 705 | + } |
|
| 658 | 706 | // Debugging templates, are we? |
| 659 | - elseif (isset($_GET['debug'])) |
|
| 660 | - $buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '\\??/', '"' . $scripturl . '?debug;', $buffer); |
|
| 707 | + elseif (isset($_GET['debug'])) { |
|
| 708 | + $buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '\\??/', '"' . $scripturl . '?debug;', $buffer); |
|
| 709 | + } |
|
| 661 | 710 | |
| 662 | 711 | // This should work even in 4.2.x, just not CGI without cgi.fix_pathinfo. |
| 663 | 712 | 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'])) |
| 664 | 713 | { |
| 665 | 714 | // Let's do something special for session ids! |
| 666 | - if (defined('SID') && SID != '') |
|
| 667 | - $buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m) |
|
| 715 | + if (defined('SID') && SID != '') { |
|
| 716 | + $buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m) |
|
| 668 | 717 | { |
| 669 | - global $scripturl; return '"' . $scripturl . "/" . strtr("$m[1]", '&;=', '//,') . ".html?" . SID . (isset($m[2]) ? $m[2] : "") . '"'; |
|
| 718 | + global $scripturl; |
|
| 719 | + } |
|
| 720 | + return '"' . $scripturl . "/" . strtr("$m[1]", '&;=', '//,') . ".html?" . SID . (isset($m[2]) ? $m[2] : "") . '"'; |
|
| 670 | 721 | }, $buffer); |
| 671 | - else |
|
| 672 | - $buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m) |
|
| 722 | + else { |
|
| 723 | + $buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m) |
|
| 673 | 724 | { |
| 674 | - global $scripturl; return '"' . $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? $m[2] : "") . '"'; |
|
| 725 | + global $scripturl; |
|
| 726 | + } |
|
| 727 | + return '"' . $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? $m[2] : "") . '"'; |
|
| 675 | 728 | }, $buffer); |
| 676 | 729 | } |
| 677 | 730 | |