@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 3 |
| 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 | * Maps the implementations in this file (smf_db_function_name) |
@@ -34,8 +35,8 @@ discard block |
||
| 34 | 35 | global $smcFunc; |
| 35 | 36 | |
| 36 | 37 | // Map some database specific functions, only do this once. |
| 37 | - if (!isset($smcFunc['db_fetch_assoc']) || $smcFunc['db_fetch_assoc'] != 'postg_fetch_assoc') |
|
| 38 | - $smcFunc += array( |
|
| 38 | + if (!isset($smcFunc['db_fetch_assoc']) || $smcFunc['db_fetch_assoc'] != 'postg_fetch_assoc') { |
|
| 39 | + $smcFunc += array( |
|
| 39 | 40 | 'db_query' => 'smf_db_query', |
| 40 | 41 | 'db_quote' => 'smf_db_quote', |
| 41 | 42 | 'db_insert' => 'smf_db_insert', |
@@ -59,11 +60,13 @@ discard block |
||
| 59 | 60 | 'db_escape_wildcard_string' => 'smf_db_escape_wildcard_string', |
| 60 | 61 | 'db_is_resource' => 'is_resource', |
| 61 | 62 | ); |
| 63 | + } |
|
| 62 | 64 | |
| 63 | - if (!empty($db_options['persist'])) |
|
| 64 | - $connection = @pg_pconnect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
| 65 | - else |
|
| 66 | - $connection = @pg_connect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
| 65 | + if (!empty($db_options['persist'])) { |
|
| 66 | + $connection = @pg_pconnect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
| 67 | + } else { |
|
| 68 | + $connection = @pg_connect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
| 69 | + } |
|
| 67 | 70 | |
| 68 | 71 | // Something's wrong, show an error if its fatal (which we assume it is) |
| 69 | 72 | if (!$connection) |
@@ -71,8 +74,7 @@ discard block |
||
| 71 | 74 | if (!empty($db_options['non_fatal'])) |
| 72 | 75 | { |
| 73 | 76 | return null; |
| 74 | - } |
|
| 75 | - else |
|
| 77 | + } else |
|
| 76 | 78 | { |
| 77 | 79 | display_db_error(); |
| 78 | 80 | } |
@@ -123,34 +125,42 @@ discard block |
||
| 123 | 125 | |
| 124 | 126 | list ($values, $connection) = $db_callback; |
| 125 | 127 | |
| 126 | - if ($matches[1] === 'db_prefix') |
|
| 127 | - return $db_prefix; |
|
| 128 | + if ($matches[1] === 'db_prefix') { |
|
| 129 | + return $db_prefix; |
|
| 130 | + } |
|
| 128 | 131 | |
| 129 | - if ($matches[1] === 'query_see_board') |
|
| 130 | - return $user_info['query_see_board']; |
|
| 132 | + if ($matches[1] === 'query_see_board') { |
|
| 133 | + return $user_info['query_see_board']; |
|
| 134 | + } |
|
| 131 | 135 | |
| 132 | - if ($matches[1] === 'query_wanna_see_board') |
|
| 133 | - return $user_info['query_wanna_see_board']; |
|
| 136 | + if ($matches[1] === 'query_wanna_see_board') { |
|
| 137 | + return $user_info['query_wanna_see_board']; |
|
| 138 | + } |
|
| 134 | 139 | |
| 135 | - if ($matches[1] === 'empty') |
|
| 136 | - return '\'\''; |
|
| 140 | + if ($matches[1] === 'empty') { |
|
| 141 | + return '\'\''; |
|
| 142 | + } |
|
| 137 | 143 | |
| 138 | - if (!isset($matches[2])) |
|
| 139 | - smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 144 | + if (!isset($matches[2])) { |
|
| 145 | + smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 146 | + } |
|
| 140 | 147 | |
| 141 | - if ($matches[1] === 'literal') |
|
| 142 | - return '\'' . pg_escape_string($matches[2]) . '\''; |
|
| 148 | + if ($matches[1] === 'literal') { |
|
| 149 | + return '\'' . pg_escape_string($matches[2]) . '\''; |
|
| 150 | + } |
|
| 143 | 151 | |
| 144 | - if (!isset($values[$matches[2]])) |
|
| 145 | - smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 152 | + if (!isset($values[$matches[2]])) { |
|
| 153 | + smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 154 | + } |
|
| 146 | 155 | |
| 147 | 156 | $replacement = $values[$matches[2]]; |
| 148 | 157 | |
| 149 | 158 | switch ($matches[1]) |
| 150 | 159 | { |
| 151 | 160 | case 'int': |
| 152 | - if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) |
|
| 153 | - smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 161 | + if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) { |
|
| 162 | + smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 163 | + } |
|
| 154 | 164 | return (string) (int) $replacement; |
| 155 | 165 | break; |
| 156 | 166 | |
@@ -162,56 +172,63 @@ discard block |
||
| 162 | 172 | case 'array_int': |
| 163 | 173 | if (is_array($replacement)) |
| 164 | 174 | { |
| 165 | - if (empty($replacement)) |
|
| 166 | - smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 175 | + if (empty($replacement)) { |
|
| 176 | + smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 177 | + } |
|
| 167 | 178 | |
| 168 | 179 | foreach ($replacement as $key => $value) |
| 169 | 180 | { |
| 170 | - if (!is_numeric($value) || (string) $value !== (string) (int) $value) |
|
| 171 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 181 | + if (!is_numeric($value) || (string) $value !== (string) (int) $value) { |
|
| 182 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 183 | + } |
|
| 172 | 184 | |
| 173 | 185 | $replacement[$key] = (string) (int) $value; |
| 174 | 186 | } |
| 175 | 187 | |
| 176 | 188 | return implode(', ', $replacement); |
| 189 | + } else { |
|
| 190 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 177 | 191 | } |
| 178 | - else |
|
| 179 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 180 | 192 | |
| 181 | 193 | break; |
| 182 | 194 | |
| 183 | 195 | case 'array_string': |
| 184 | 196 | if (is_array($replacement)) |
| 185 | 197 | { |
| 186 | - if (empty($replacement)) |
|
| 187 | - smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 198 | + if (empty($replacement)) { |
|
| 199 | + smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 200 | + } |
|
| 188 | 201 | |
| 189 | - foreach ($replacement as $key => $value) |
|
| 190 | - $replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value)); |
|
| 202 | + foreach ($replacement as $key => $value) { |
|
| 203 | + $replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value)); |
|
| 204 | + } |
|
| 191 | 205 | |
| 192 | 206 | return implode(', ', $replacement); |
| 207 | + } else { |
|
| 208 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 193 | 209 | } |
| 194 | - else |
|
| 195 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 196 | 210 | break; |
| 197 | 211 | |
| 198 | 212 | case 'date': |
| 199 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) |
|
| 200 | - return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
|
| 201 | - else |
|
| 202 | - smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 213 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) { |
|
| 214 | + return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
|
| 215 | + } else { |
|
| 216 | + smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 217 | + } |
|
| 203 | 218 | break; |
| 204 | 219 | |
| 205 | 220 | case 'time': |
| 206 | - if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) |
|
| 207 | - return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]); |
|
| 208 | - else |
|
| 209 | - smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 221 | + if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) { |
|
| 222 | + return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]); |
|
| 223 | + } else { |
|
| 224 | + smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 225 | + } |
|
| 210 | 226 | break; |
| 211 | 227 | |
| 212 | 228 | case 'float': |
| 213 | - if (!is_numeric($replacement)) |
|
| 214 | - smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 229 | + if (!is_numeric($replacement)) { |
|
| 230 | + smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 231 | + } |
|
| 215 | 232 | return (string) (float) $replacement; |
| 216 | 233 | break; |
| 217 | 234 | |
@@ -224,31 +241,36 @@ discard block |
||
| 224 | 241 | break; |
| 225 | 242 | |
| 226 | 243 | case 'inet': |
| 227 | - if ($replacement == 'null' || $replacement == '') |
|
| 228 | - return 'null'; |
|
| 229 | - if (inet_pton($replacement) === false) |
|
| 230 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 244 | + if ($replacement == 'null' || $replacement == '') { |
|
| 245 | + return 'null'; |
|
| 246 | + } |
|
| 247 | + if (inet_pton($replacement) === false) { |
|
| 248 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 249 | + } |
|
| 231 | 250 | return sprintf('\'%1$s\'::inet', pg_escape_string($replacement)); |
| 232 | 251 | |
| 233 | 252 | case 'array_inet': |
| 234 | 253 | if (is_array($replacement)) |
| 235 | 254 | { |
| 236 | - if (empty($replacement)) |
|
| 237 | - smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 255 | + if (empty($replacement)) { |
|
| 256 | + smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 257 | + } |
|
| 238 | 258 | |
| 239 | 259 | foreach ($replacement as $key => $value) |
| 240 | 260 | { |
| 241 | - if ($replacement == 'null' || $replacement == '') |
|
| 242 | - $replacement[$key] = 'null'; |
|
| 243 | - if (!isValidIP($value)) |
|
| 244 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 261 | + if ($replacement == 'null' || $replacement == '') { |
|
| 262 | + $replacement[$key] = 'null'; |
|
| 263 | + } |
|
| 264 | + if (!isValidIP($value)) { |
|
| 265 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 266 | + } |
|
| 245 | 267 | $replacement[$key] = sprintf('\'%1$s\'::inet', pg_escape_string($value)); |
| 246 | 268 | } |
| 247 | 269 | |
| 248 | 270 | return implode(', ', $replacement); |
| 271 | + } else { |
|
| 272 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 249 | 273 | } |
| 250 | - else |
|
| 251 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 252 | 274 | break; |
| 253 | 275 | |
| 254 | 276 | default: |
@@ -335,14 +357,16 @@ discard block |
||
| 335 | 357 | ), |
| 336 | 358 | ); |
| 337 | 359 | |
| 338 | - if (isset($replacements[$identifier])) |
|
| 339 | - $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string); |
|
| 360 | + if (isset($replacements[$identifier])) { |
|
| 361 | + $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string); |
|
| 362 | + } |
|
| 340 | 363 | |
| 341 | 364 | // Limits need to be a little different. |
| 342 | 365 | $db_string = preg_replace('~\sLIMIT\s(\d+|{int:.+}),\s*(\d+|{int:.+})\s*$~i', 'LIMIT $2 OFFSET $1', $db_string); |
| 343 | 366 | |
| 344 | - if (trim($db_string) == '') |
|
| 345 | - return false; |
|
| 367 | + if (trim($db_string) == '') { |
|
| 368 | + return false; |
|
| 369 | + } |
|
| 346 | 370 | |
| 347 | 371 | // Comments that are allowed in a query are preg_removed. |
| 348 | 372 | static $allowed_comments_from = array( |
@@ -362,8 +386,9 @@ discard block |
||
| 362 | 386 | $db_count = !isset($db_count) ? 1 : $db_count + 1; |
| 363 | 387 | $db_replace_result = 0; |
| 364 | 388 | |
| 365 | - if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) |
|
| 366 | - smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
| 389 | + if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) { |
|
| 390 | + smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
| 391 | + } |
|
| 367 | 392 | |
| 368 | 393 | if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false)) |
| 369 | 394 | { |
@@ -384,8 +409,9 @@ discard block |
||
| 384 | 409 | list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__); |
| 385 | 410 | |
| 386 | 411 | // Initialize $db_cache if not already initialized. |
| 387 | - if (!isset($db_cache)) |
|
| 388 | - $db_cache = array(); |
|
| 412 | + if (!isset($db_cache)) { |
|
| 413 | + $db_cache = array(); |
|
| 414 | + } |
|
| 389 | 415 | |
| 390 | 416 | if (!empty($_SESSION['debug_redirect'])) |
| 391 | 417 | { |
@@ -411,17 +437,18 @@ discard block |
||
| 411 | 437 | while (true) |
| 412 | 438 | { |
| 413 | 439 | $pos = strpos($db_string, '\'', $pos + 1); |
| 414 | - if ($pos === false) |
|
| 415 | - break; |
|
| 440 | + if ($pos === false) { |
|
| 441 | + break; |
|
| 442 | + } |
|
| 416 | 443 | $clean .= substr($db_string, $old_pos, $pos - $old_pos); |
| 417 | 444 | |
| 418 | 445 | while (true) |
| 419 | 446 | { |
| 420 | 447 | $pos1 = strpos($db_string, '\'', $pos + 1); |
| 421 | 448 | $pos2 = strpos($db_string, '\\', $pos + 1); |
| 422 | - if ($pos1 === false) |
|
| 423 | - break; |
|
| 424 | - elseif ($pos2 === false || $pos2 > $pos1) |
|
| 449 | + if ($pos1 === false) { |
|
| 450 | + break; |
|
| 451 | + } elseif ($pos2 === false || $pos2 > $pos1) |
|
| 425 | 452 | { |
| 426 | 453 | $pos = $pos1; |
| 427 | 454 | break; |
@@ -437,26 +464,31 @@ discard block |
||
| 437 | 464 | $clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean))); |
| 438 | 465 | |
| 439 | 466 | // Comments? We don't use comments in our queries, we leave 'em outside! |
| 440 | - if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) |
|
| 441 | - $fail = true; |
|
| 467 | + if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) { |
|
| 468 | + $fail = true; |
|
| 469 | + } |
|
| 442 | 470 | // Trying to change passwords, slow us down, or something? |
| 443 | - elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) |
|
| 444 | - $fail = true; |
|
| 445 | - elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) |
|
| 446 | - $fail = true; |
|
| 471 | + elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) { |
|
| 472 | + $fail = true; |
|
| 473 | + } elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) { |
|
| 474 | + $fail = true; |
|
| 475 | + } |
|
| 447 | 476 | |
| 448 | - if (!empty($fail) && function_exists('log_error')) |
|
| 449 | - smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
| 477 | + if (!empty($fail) && function_exists('log_error')) { |
|
| 478 | + smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
| 479 | + } |
|
| 450 | 480 | } |
| 451 | 481 | |
| 452 | 482 | $db_last_result = @pg_query($connection, $db_string); |
| 453 | 483 | |
| 454 | - if ($db_last_result === false && empty($db_values['db_error_skip'])) |
|
| 455 | - $db_last_result = smf_db_error($db_string, $connection); |
|
| 484 | + if ($db_last_result === false && empty($db_values['db_error_skip'])) { |
|
| 485 | + $db_last_result = smf_db_error($db_string, $connection); |
|
| 486 | + } |
|
| 456 | 487 | |
| 457 | 488 | // Debugging. |
| 458 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
| 459 | - $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 489 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
| 490 | + $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 491 | + } |
|
| 460 | 492 | |
| 461 | 493 | return $db_last_result; |
| 462 | 494 | } |
@@ -469,10 +501,11 @@ discard block |
||
| 469 | 501 | { |
| 470 | 502 | global $db_last_result, $db_replace_result; |
| 471 | 503 | |
| 472 | - if ($db_replace_result) |
|
| 473 | - return $db_replace_result; |
|
| 474 | - elseif ($result === null && !$db_last_result) |
|
| 475 | - return 0; |
|
| 504 | + if ($db_replace_result) { |
|
| 505 | + return $db_replace_result; |
|
| 506 | + } elseif ($result === null && !$db_last_result) { |
|
| 507 | + return 0; |
|
| 508 | + } |
|
| 476 | 509 | |
| 477 | 510 | return pg_affected_rows($result === null ? $db_last_result : $result); |
| 478 | 511 | } |
@@ -496,8 +529,9 @@ discard block |
||
| 496 | 529 | array( |
| 497 | 530 | ) |
| 498 | 531 | ); |
| 499 | - if (!$request) |
|
| 500 | - return false; |
|
| 532 | + if (!$request) { |
|
| 533 | + return false; |
|
| 534 | + } |
|
| 501 | 535 | list ($lastID) = $smcFunc['db_fetch_row']($request); |
| 502 | 536 | $smcFunc['db_free_result']($request); |
| 503 | 537 | |
@@ -518,12 +552,13 @@ discard block |
||
| 518 | 552 | // Decide which connection to use |
| 519 | 553 | $connection = $connection === null ? $db_connection : $connection; |
| 520 | 554 | |
| 521 | - if ($type == 'begin') |
|
| 522 | - return @pg_query($connection, 'BEGIN'); |
|
| 523 | - elseif ($type == 'rollback') |
|
| 524 | - return @pg_query($connection, 'ROLLBACK'); |
|
| 525 | - elseif ($type == 'commit') |
|
| 526 | - return @pg_query($connection, 'COMMIT'); |
|
| 555 | + if ($type == 'begin') { |
|
| 556 | + return @pg_query($connection, 'BEGIN'); |
|
| 557 | + } elseif ($type == 'rollback') { |
|
| 558 | + return @pg_query($connection, 'ROLLBACK'); |
|
| 559 | + } elseif ($type == 'commit') { |
|
| 560 | + return @pg_query($connection, 'COMMIT'); |
|
| 561 | + } |
|
| 527 | 562 | |
| 528 | 563 | return false; |
| 529 | 564 | } |
@@ -551,19 +586,22 @@ discard block |
||
| 551 | 586 | $query_error = @pg_last_error($connection); |
| 552 | 587 | |
| 553 | 588 | // Log the error. |
| 554 | - if (function_exists('log_error')) |
|
| 555 | - log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line); |
|
| 589 | + if (function_exists('log_error')) { |
|
| 590 | + log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line); |
|
| 591 | + } |
|
| 556 | 592 | |
| 557 | 593 | // Nothing's defined yet... just die with it. |
| 558 | - if (empty($context) || empty($txt)) |
|
| 559 | - die($query_error); |
|
| 594 | + if (empty($context) || empty($txt)) { |
|
| 595 | + die($query_error); |
|
| 596 | + } |
|
| 560 | 597 | |
| 561 | 598 | // Show an error message, if possible. |
| 562 | 599 | $context['error_title'] = $txt['database_error']; |
| 563 | - if (allowedTo('admin_forum')) |
|
| 564 | - $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
| 565 | - else |
|
| 566 | - $context['error_message'] = $txt['try_again']; |
|
| 600 | + if (allowedTo('admin_forum')) { |
|
| 601 | + $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
| 602 | + } else { |
|
| 603 | + $context['error_message'] = $txt['try_again']; |
|
| 604 | + } |
|
| 567 | 605 | |
| 568 | 606 | if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true) |
| 569 | 607 | { |
@@ -585,12 +623,14 @@ discard block |
||
| 585 | 623 | { |
| 586 | 624 | global $db_row_count; |
| 587 | 625 | |
| 588 | - if ($counter !== false) |
|
| 589 | - return pg_fetch_row($request, $counter); |
|
| 626 | + if ($counter !== false) { |
|
| 627 | + return pg_fetch_row($request, $counter); |
|
| 628 | + } |
|
| 590 | 629 | |
| 591 | 630 | // Reset the row counter... |
| 592 | - if (!isset($db_row_count[(int) $request])) |
|
| 593 | - $db_row_count[(int) $request] = 0; |
|
| 631 | + if (!isset($db_row_count[(int) $request])) { |
|
| 632 | + $db_row_count[(int) $request] = 0; |
|
| 633 | + } |
|
| 594 | 634 | |
| 595 | 635 | // Return the right row. |
| 596 | 636 | return @pg_fetch_row($request, $db_row_count[(int) $request]++); |
@@ -607,12 +647,14 @@ discard block |
||
| 607 | 647 | { |
| 608 | 648 | global $db_row_count; |
| 609 | 649 | |
| 610 | - if ($counter !== false) |
|
| 611 | - return pg_fetch_assoc($request, $counter); |
|
| 650 | + if ($counter !== false) { |
|
| 651 | + return pg_fetch_assoc($request, $counter); |
|
| 652 | + } |
|
| 612 | 653 | |
| 613 | 654 | // Reset the row counter... |
| 614 | - if (!isset($db_row_count[(int) $request])) |
|
| 615 | - $db_row_count[(int) $request] = 0; |
|
| 655 | + if (!isset($db_row_count[(int) $request])) { |
|
| 656 | + $db_row_count[(int) $request] = 0; |
|
| 657 | + } |
|
| 616 | 658 | |
| 617 | 659 | // Return the right row. |
| 618 | 660 | return @pg_fetch_assoc($request, $db_row_count[(int) $request]++); |
@@ -664,11 +706,13 @@ discard block |
||
| 664 | 706 | |
| 665 | 707 | $replace = ''; |
| 666 | 708 | |
| 667 | - if (empty($data)) |
|
| 668 | - return; |
|
| 709 | + if (empty($data)) { |
|
| 710 | + return; |
|
| 711 | + } |
|
| 669 | 712 | |
| 670 | - if (!is_array($data[array_rand($data)])) |
|
| 671 | - $data = array($data); |
|
| 713 | + if (!is_array($data[array_rand($data)])) { |
|
| 714 | + $data = array($data); |
|
| 715 | + } |
|
| 672 | 716 | |
| 673 | 717 | // Replace the prefix holder with the actual prefix. |
| 674 | 718 | $table = str_replace('{db_prefix}', $db_prefix, $table); |
@@ -694,11 +738,13 @@ discard block |
||
| 694 | 738 | //pg 9.5 got replace support |
| 695 | 739 | $pg_version = $smcFunc['db_get_version'](); |
| 696 | 740 | // if we got a Beta Version |
| 697 | - if (stripos($pg_version, 'beta') !== false) |
|
| 698 | - $pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0'; |
|
| 741 | + if (stripos($pg_version, 'beta') !== false) { |
|
| 742 | + $pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0'; |
|
| 743 | + } |
|
| 699 | 744 | // or RC |
| 700 | - if (stripos($pg_version, 'rc') !== false) |
|
| 701 | - $pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0'; |
|
| 745 | + if (stripos($pg_version, 'rc') !== false) { |
|
| 746 | + $pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0'; |
|
| 747 | + } |
|
| 702 | 748 | |
| 703 | 749 | $replace_support = (version_compare($pg_version, '9.5.0', '>=') ? true : false); |
| 704 | 750 | } |
@@ -717,8 +763,7 @@ discard block |
||
| 717 | 763 | $key_str .= ($count_pk > 0 ? ',' : ''); |
| 718 | 764 | $key_str .= $columnName; |
| 719 | 765 | $count_pk++; |
| 720 | - } |
|
| 721 | - else //normal field |
|
| 766 | + } else //normal field |
|
| 722 | 767 | { |
| 723 | 768 | $col_str .= ($count > 0 ? ',' : ''); |
| 724 | 769 | $col_str .= $columnName . ' = EXCLUDED.' . $columnName; |
@@ -726,20 +771,21 @@ discard block |
||
| 726 | 771 | } |
| 727 | 772 | } |
| 728 | 773 | $replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str; |
| 729 | - } |
|
| 730 | - else |
|
| 774 | + } else |
|
| 731 | 775 | { |
| 732 | 776 | foreach ($columns as $columnName => $type) |
| 733 | 777 | { |
| 734 | 778 | // Are we restricting the length? |
| 735 | - if (strpos($type, 'string-') !== false) |
|
| 736 | - $actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count); |
|
| 737 | - else |
|
| 738 | - $actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count); |
|
| 779 | + if (strpos($type, 'string-') !== false) { |
|
| 780 | + $actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count); |
|
| 781 | + } else { |
|
| 782 | + $actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count); |
|
| 783 | + } |
|
| 739 | 784 | |
| 740 | 785 | // A key? That's what we were looking for. |
| 741 | - if (in_array($columnName, $keys)) |
|
| 742 | - $where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2); |
|
| 786 | + if (in_array($columnName, $keys)) { |
|
| 787 | + $where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2); |
|
| 788 | + } |
|
| 743 | 789 | $count++; |
| 744 | 790 | } |
| 745 | 791 | |
@@ -765,10 +811,11 @@ discard block |
||
| 765 | 811 | foreach ($columns as $columnName => $type) |
| 766 | 812 | { |
| 767 | 813 | // Are we restricting the length? |
| 768 | - if (strpos($type, 'string-') !== false) |
|
| 769 | - $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
| 770 | - else |
|
| 771 | - $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
| 814 | + if (strpos($type, 'string-') !== false) { |
|
| 815 | + $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
| 816 | + } else { |
|
| 817 | + $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
| 818 | + } |
|
| 772 | 819 | } |
| 773 | 820 | $insertData = substr($insertData, 0, -2) . ')'; |
| 774 | 821 | |
@@ -777,11 +824,12 @@ discard block |
||
| 777 | 824 | |
| 778 | 825 | // Here's where the variables are injected to the query. |
| 779 | 826 | $insertRows = array(); |
| 780 | - foreach ($data as $dataRow) |
|
| 781 | - $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
| 827 | + foreach ($data as $dataRow) { |
|
| 828 | + $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
| 829 | + } |
|
| 782 | 830 | |
| 783 | - foreach ($insertRows as $entry) |
|
| 784 | - // Do the insert. |
|
| 831 | + foreach ($insertRows as $entry) { |
|
| 832 | + // Do the insert. |
|
| 785 | 833 | $smcFunc['db_query']('', ' |
| 786 | 834 | INSERT INTO ' . $table . '("' . implode('", "', $indexed_columns) . '") |
| 787 | 835 | VALUES |
@@ -792,11 +840,13 @@ discard block |
||
| 792 | 840 | ), |
| 793 | 841 | $connection |
| 794 | 842 | ); |
| 843 | + } |
|
| 795 | 844 | } |
| 796 | 845 | |
| 797 | - if ($priv_trans) |
|
| 798 | - $smcFunc['db_transaction']('commit', $connection); |
|
| 799 | -} |
|
| 846 | + if ($priv_trans) { |
|
| 847 | + $smcFunc['db_transaction']('commit', $connection); |
|
| 848 | + } |
|
| 849 | + } |
|
| 800 | 850 | |
| 801 | 851 | /** |
| 802 | 852 | * Dummy function really. Doesn't do anything on PostgreSQL. |
@@ -833,8 +883,9 @@ discard block |
||
| 833 | 883 | */ |
| 834 | 884 | function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null) |
| 835 | 885 | { |
| 836 | - if (empty($log_message)) |
|
| 837 | - $log_message = $error_message; |
|
| 886 | + if (empty($log_message)) { |
|
| 887 | + $log_message = $error_message; |
|
| 888 | + } |
|
| 838 | 889 | |
| 839 | 890 | foreach (debug_backtrace() as $step) |
| 840 | 891 | { |
@@ -853,12 +904,14 @@ discard block |
||
| 853 | 904 | } |
| 854 | 905 | |
| 855 | 906 | // A special case - we want the file and line numbers for debugging. |
| 856 | - if ($error_type == 'return') |
|
| 857 | - return array($file, $line); |
|
| 907 | + if ($error_type == 'return') { |
|
| 908 | + return array($file, $line); |
|
| 909 | + } |
|
| 858 | 910 | |
| 859 | 911 | // Is always a critical error. |
| 860 | - if (function_exists('log_error')) |
|
| 861 | - log_error($log_message, 'critical', $file, $line); |
|
| 912 | + if (function_exists('log_error')) { |
|
| 913 | + log_error($log_message, 'critical', $file, $line); |
|
| 914 | + } |
|
| 862 | 915 | |
| 863 | 916 | if (function_exists('fatal_error')) |
| 864 | 917 | { |
@@ -866,12 +919,12 @@ discard block |
||
| 866 | 919 | |
| 867 | 920 | // Cannot continue... |
| 868 | 921 | exit; |
| 922 | + } elseif ($error_type) { |
|
| 923 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
| 924 | + } else { |
|
| 925 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
| 926 | + } |
|
| 869 | 927 | } |
| 870 | - elseif ($error_type) |
|
| 871 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
| 872 | - else |
|
| 873 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
| 874 | -} |
|
| 875 | 928 | |
| 876 | 929 | /** |
| 877 | 930 | * Escape the LIKE wildcards so that they match the character and not the wildcard. |
@@ -888,10 +941,11 @@ discard block |
||
| 888 | 941 | '\\' => '\\\\', |
| 889 | 942 | ); |
| 890 | 943 | |
| 891 | - if ($translate_human_wildcards) |
|
| 892 | - $replacements += array( |
|
| 944 | + if ($translate_human_wildcards) { |
|
| 945 | + $replacements += array( |
|
| 893 | 946 | '*' => '%', |
| 894 | 947 | ); |
| 948 | + } |
|
| 895 | 949 | |
| 896 | 950 | return strtr($string, $replacements); |
| 897 | 951 | } |
@@ -20,8 +20,9 @@ discard block |
||
| 20 | 20 | // ><html dir="ltr"><head><title>Error!</title></head><body>Sorry, this installer requires PHP!<div style="display: none;"> |
| 21 | 21 | |
| 22 | 22 | // Let's pull in useful classes |
| 23 | -if (!defined('SMF')) |
|
| 23 | +if (!defined('SMF')) { |
|
| 24 | 24 | define('SMF', 1); |
| 25 | +} |
|
| 25 | 26 | |
| 26 | 27 | require_once('Sources/Class-Package.php'); |
| 27 | 28 | |
@@ -83,12 +84,14 @@ discard block |
||
| 83 | 84 | $value = preg_replace('~[^A-Za-z0-9_\$]~', '', $value); |
| 84 | 85 | |
| 85 | 86 | // Is it reserved? |
| 86 | - if ($value == 'pg_') |
|
| 87 | - return $txt['error_db_prefix_reserved']; |
|
| 87 | + if ($value == 'pg_') { |
|
| 88 | + return $txt['error_db_prefix_reserved']; |
|
| 89 | + } |
|
| 88 | 90 | |
| 89 | 91 | // Is the prefix numeric? |
| 90 | - if (preg_match('~^\d~', $value)) |
|
| 91 | - return $txt['error_db_prefix_numeric']; |
|
| 92 | + if (preg_match('~^\d~', $value)) { |
|
| 93 | + return $txt['error_db_prefix_numeric']; |
|
| 94 | + } |
|
| 92 | 95 | |
| 93 | 96 | return true; |
| 94 | 97 | }, |
@@ -135,10 +138,11 @@ discard block |
||
| 135 | 138 | $incontext['skip'] = false; |
| 136 | 139 | |
| 137 | 140 | // Call the step and if it returns false that means pause! |
| 138 | - if (function_exists($step[2]) && $step[2]() === false) |
|
| 139 | - break; |
|
| 140 | - elseif (function_exists($step[2])) |
|
| 141 | - $incontext['current_step']++; |
|
| 141 | + if (function_exists($step[2]) && $step[2]() === false) { |
|
| 142 | + break; |
|
| 143 | + } elseif (function_exists($step[2])) { |
|
| 144 | + $incontext['current_step']++; |
|
| 145 | + } |
|
| 142 | 146 | |
| 143 | 147 | // No warnings pass on. |
| 144 | 148 | $incontext['warning'] = ''; |
@@ -154,12 +158,14 @@ discard block |
||
| 154 | 158 | global $databases, $incontext; |
| 155 | 159 | |
| 156 | 160 | // Just so people using older versions of PHP aren't left in the cold. |
| 157 | - if (!isset($_SERVER['PHP_SELF'])) |
|
| 158 | - $_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php'; |
|
| 161 | + if (!isset($_SERVER['PHP_SELF'])) { |
|
| 162 | + $_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php'; |
|
| 163 | + } |
|
| 159 | 164 | |
| 160 | 165 | // Turn off magic quotes runtime and enable error reporting. |
| 161 | - if (function_exists('set_magic_quotes_runtime')) |
|
| 162 | - @set_magic_quotes_runtime(0); |
|
| 166 | + if (function_exists('set_magic_quotes_runtime')) { |
|
| 167 | + @set_magic_quotes_runtime(0); |
|
| 168 | + } |
|
| 163 | 169 | error_reporting(E_ALL); |
| 164 | 170 | |
| 165 | 171 | // Fun. Low PHP version... |
@@ -173,21 +179,23 @@ discard block |
||
| 173 | 179 | { |
| 174 | 180 | ob_start(); |
| 175 | 181 | |
| 176 | - if (ini_get('session.save_handler') == 'user') |
|
| 177 | - @ini_set('session.save_handler', 'files'); |
|
| 178 | - if (function_exists('session_start')) |
|
| 179 | - @session_start(); |
|
| 180 | - } |
|
| 181 | - else |
|
| 182 | + if (ini_get('session.save_handler') == 'user') { |
|
| 183 | + @ini_set('session.save_handler', 'files'); |
|
| 184 | + } |
|
| 185 | + if (function_exists('session_start')) { |
|
| 186 | + @session_start(); |
|
| 187 | + } |
|
| 188 | + } else |
|
| 182 | 189 | { |
| 183 | 190 | ob_start('ob_gzhandler'); |
| 184 | 191 | |
| 185 | - if (ini_get('session.save_handler') == 'user') |
|
| 186 | - @ini_set('session.save_handler', 'files'); |
|
| 192 | + if (ini_get('session.save_handler') == 'user') { |
|
| 193 | + @ini_set('session.save_handler', 'files'); |
|
| 194 | + } |
|
| 187 | 195 | session_start(); |
| 188 | 196 | |
| 189 | - if (!headers_sent()) |
|
| 190 | - echo '<!DOCTYPE html> |
|
| 197 | + if (!headers_sent()) { |
|
| 198 | + echo '<!DOCTYPE html> |
|
| 191 | 199 | <html> |
| 192 | 200 | <head> |
| 193 | 201 | <title>', htmlspecialchars($_GET['pass_string']), '</title> |
@@ -196,6 +204,7 @@ discard block |
||
| 196 | 204 | <strong>', htmlspecialchars($_GET['pass_string']), '</strong> |
| 197 | 205 | </body> |
| 198 | 206 | </html>'; |
| 207 | + } |
|
| 199 | 208 | exit; |
| 200 | 209 | } |
| 201 | 210 | |
@@ -204,16 +213,18 @@ discard block |
||
| 204 | 213 | { |
| 205 | 214 | $incontext['remote_files_available'] = false; |
| 206 | 215 | $test = @fsockopen('www.simplemachines.org', 80, $errno, $errstr, 1); |
| 207 | - if ($test) |
|
| 208 | - $incontext['remote_files_available'] = true; |
|
| 216 | + if ($test) { |
|
| 217 | + $incontext['remote_files_available'] = true; |
|
| 218 | + } |
|
| 209 | 219 | @fclose($test); |
| 210 | 220 | } |
| 211 | 221 | |
| 212 | 222 | // Add slashes, as long as they aren't already being added. |
| 213 | - if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0) |
|
| 214 | - foreach ($_POST as $k => $v) |
|
| 223 | + if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0) { |
|
| 224 | + foreach ($_POST as $k => $v) |
|
| 215 | 225 | if (strpos($k, 'password') === false && strpos($k, 'db_passwd') === false) |
| 216 | 226 | $_POST[$k] = addslashes($v); |
| 227 | + } |
|
| 217 | 228 | |
| 218 | 229 | // This is really quite simple; if ?delete is on the URL, delete the installer... |
| 219 | 230 | if (isset($_GET['delete'])) |
@@ -234,8 +245,7 @@ discard block |
||
| 234 | 245 | $ftp->close(); |
| 235 | 246 | |
| 236 | 247 | unset($_SESSION['installer_temp_ftp']); |
| 237 | - } |
|
| 238 | - else |
|
| 248 | + } else |
|
| 239 | 249 | { |
| 240 | 250 | @unlink(__FILE__); |
| 241 | 251 | |
@@ -256,10 +266,11 @@ discard block |
||
| 256 | 266 | { |
| 257 | 267 | // Get PHP's default timezone, if set |
| 258 | 268 | $ini_tz = ini_get('date.timezone'); |
| 259 | - if (!empty($ini_tz)) |
|
| 260 | - $timezone_id = $ini_tz; |
|
| 261 | - else |
|
| 262 | - $timezone_id = ''; |
|
| 269 | + if (!empty($ini_tz)) { |
|
| 270 | + $timezone_id = $ini_tz; |
|
| 271 | + } else { |
|
| 272 | + $timezone_id = ''; |
|
| 273 | + } |
|
| 263 | 274 | |
| 264 | 275 | // If date.timezone is unset, invalid, or just plain weird, make a best guess |
| 265 | 276 | if (!in_array($timezone_id, timezone_identifiers_list())) |
@@ -289,8 +300,9 @@ discard block |
||
| 289 | 300 | $dir = dir(dirname(__FILE__) . '/Themes/default/languages'); |
| 290 | 301 | while ($entry = $dir->read()) |
| 291 | 302 | { |
| 292 | - if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') |
|
| 293 | - $incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12)); |
|
| 303 | + if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') { |
|
| 304 | + $incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12)); |
|
| 305 | + } |
|
| 294 | 306 | } |
| 295 | 307 | $dir->close(); |
| 296 | 308 | } |
@@ -325,10 +337,11 @@ discard block |
||
| 325 | 337 | } |
| 326 | 338 | |
| 327 | 339 | // Override the language file? |
| 328 | - if (isset($_GET['lang_file'])) |
|
| 329 | - $_SESSION['installer_temp_lang'] = $_GET['lang_file']; |
|
| 330 | - elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) |
|
| 331 | - $_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file']; |
|
| 340 | + if (isset($_GET['lang_file'])) { |
|
| 341 | + $_SESSION['installer_temp_lang'] = $_GET['lang_file']; |
|
| 342 | + } elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) { |
|
| 343 | + $_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file']; |
|
| 344 | + } |
|
| 332 | 345 | |
| 333 | 346 | // Make sure it exists, if it doesn't reset it. |
| 334 | 347 | if (!isset($_SESSION['installer_temp_lang']) || preg_match('~[^\\w_\\-.]~', $_SESSION['installer_temp_lang']) === 1 || !file_exists(dirname(__FILE__) . '/Themes/default/languages/' . $_SESSION['installer_temp_lang'])) |
@@ -337,8 +350,9 @@ discard block |
||
| 337 | 350 | list ($_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']); |
| 338 | 351 | |
| 339 | 352 | // If we have english and some other language, use the other language. We Americans hate english :P. |
| 340 | - if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) |
|
| 341 | - list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']); |
|
| 353 | + if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) { |
|
| 354 | + list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']); |
|
| 355 | + } |
|
| 342 | 356 | } |
| 343 | 357 | |
| 344 | 358 | // And now include the actual language file itself. |
@@ -351,15 +365,18 @@ discard block |
||
| 351 | 365 | global $db_prefix, $db_connection, $sourcedir; |
| 352 | 366 | global $smcFunc, $modSettings, $db_type, $db_name, $db_user, $db_persist; |
| 353 | 367 | |
| 354 | - if (empty($sourcedir)) |
|
| 355 | - $sourcedir = dirname(__FILE__) . '/Sources'; |
|
| 368 | + if (empty($sourcedir)) { |
|
| 369 | + $sourcedir = dirname(__FILE__) . '/Sources'; |
|
| 370 | + } |
|
| 356 | 371 | |
| 357 | 372 | // Need this to check whether we need the database password. |
| 358 | 373 | require(dirname(__FILE__) . '/Settings.php'); |
| 359 | - if (!defined('SMF')) |
|
| 360 | - define('SMF', 1); |
|
| 361 | - if (empty($smcFunc)) |
|
| 362 | - $smcFunc = array(); |
|
| 374 | + if (!defined('SMF')) { |
|
| 375 | + define('SMF', 1); |
|
| 376 | + } |
|
| 377 | + if (empty($smcFunc)) { |
|
| 378 | + $smcFunc = array(); |
|
| 379 | + } |
|
| 363 | 380 | |
| 364 | 381 | $modSettings['disableQueryCheck'] = true; |
| 365 | 382 | |
@@ -367,8 +384,9 @@ discard block |
||
| 367 | 384 | if (!$db_connection) |
| 368 | 385 | { |
| 369 | 386 | require_once($sourcedir . '/Subs-Db-' . $db_type . '.php'); |
| 370 | - if (version_compare(PHP_VERSION, '5', '<')) |
|
| 371 | - require_once($sourcedir . '/Subs-Compat.php'); |
|
| 387 | + if (version_compare(PHP_VERSION, '5', '<')) { |
|
| 388 | + require_once($sourcedir . '/Subs-Compat.php'); |
|
| 389 | + } |
|
| 372 | 390 | |
| 373 | 391 | $db_options = array('persist' => $db_persist); |
| 374 | 392 | $port = ''; |
@@ -379,19 +397,20 @@ discard block |
||
| 379 | 397 | if ($db_type == 'mysql' || $db_type == 'mysqli') |
| 380 | 398 | { |
| 381 | 399 | $port = ((int) $_POST['db_port'] == ini_get($db_type . 'default_port')) ? '' : (int) $_POST['db_port']; |
| 382 | - } |
|
| 383 | - elseif ($db_type == 'postgresql') |
|
| 400 | + } elseif ($db_type == 'postgresql') |
|
| 384 | 401 | { |
| 385 | 402 | // PostgreSQL doesn't have a default port setting in php.ini, so just check against the default |
| 386 | 403 | $port = ((int) $_POST['db_port'] == 5432) ? '' : (int) $_POST['db_port']; |
| 387 | 404 | } |
| 388 | 405 | } |
| 389 | 406 | |
| 390 | - if (!empty($port)) |
|
| 391 | - $db_options['port'] = $port; |
|
| 407 | + if (!empty($port)) { |
|
| 408 | + $db_options['port'] = $port; |
|
| 409 | + } |
|
| 392 | 410 | |
| 393 | - if (!$db_connection) |
|
| 394 | - $db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options); |
|
| 411 | + if (!$db_connection) { |
|
| 412 | + $db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options); |
|
| 413 | + } |
|
| 395 | 414 | } |
| 396 | 415 | } |
| 397 | 416 | |
@@ -419,8 +438,9 @@ discard block |
||
| 419 | 438 | // @todo REMOVE THIS!! |
| 420 | 439 | else |
| 421 | 440 | { |
| 422 | - if (function_exists('doStep' . $_GET['step'])) |
|
| 423 | - call_user_func('doStep' . $_GET['step']); |
|
| 441 | + if (function_exists('doStep' . $_GET['step'])) { |
|
| 442 | + call_user_func('doStep' . $_GET['step']); |
|
| 443 | + } |
|
| 424 | 444 | } |
| 425 | 445 | // Show the footer. |
| 426 | 446 | template_install_below(); |
@@ -438,8 +458,9 @@ discard block |
||
| 438 | 458 | $incontext['sub_template'] = 'welcome_message'; |
| 439 | 459 | |
| 440 | 460 | // Done the submission? |
| 441 | - if (isset($_POST['contbutt'])) |
|
| 442 | - return true; |
|
| 461 | + if (isset($_POST['contbutt'])) { |
|
| 462 | + return true; |
|
| 463 | + } |
|
| 443 | 464 | |
| 444 | 465 | // See if we think they have already installed it? |
| 445 | 466 | if (is_readable(dirname(__FILE__) . '/Settings.php')) |
@@ -447,14 +468,17 @@ discard block |
||
| 447 | 468 | $probably_installed = 0; |
| 448 | 469 | foreach (file(dirname(__FILE__) . '/Settings.php') as $line) |
| 449 | 470 | { |
| 450 | - if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line)) |
|
| 451 | - $probably_installed++; |
|
| 452 | - if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line)) |
|
| 453 | - $probably_installed++; |
|
| 471 | + if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line)) { |
|
| 472 | + $probably_installed++; |
|
| 473 | + } |
|
| 474 | + if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line)) { |
|
| 475 | + $probably_installed++; |
|
| 476 | + } |
|
| 454 | 477 | } |
| 455 | 478 | |
| 456 | - if ($probably_installed == 2) |
|
| 457 | - $incontext['warning'] = $txt['error_already_installed']; |
|
| 479 | + if ($probably_installed == 2) { |
|
| 480 | + $incontext['warning'] = $txt['error_already_installed']; |
|
| 481 | + } |
|
| 458 | 482 | } |
| 459 | 483 | |
| 460 | 484 | // Is some database support even compiled in? |
@@ -469,36 +493,43 @@ discard block |
||
| 469 | 493 | $databases[$key]['supported'] = false; |
| 470 | 494 | $notFoundSQLFile = true; |
| 471 | 495 | $txt['error_db_script_missing'] = sprintf($txt['error_db_script_missing'], 'install_' . $GLOBALS['db_script_version'] . '_' . $type . '.sql'); |
| 496 | + } else { |
|
| 497 | + $incontext['supported_databases'][] = $db; |
|
| 472 | 498 | } |
| 473 | - else |
|
| 474 | - $incontext['supported_databases'][] = $db; |
|
| 475 | 499 | } |
| 476 | 500 | } |
| 477 | 501 | |
| 478 | 502 | // Check the PHP version. |
| 479 | - if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>'))) |
|
| 480 | - $error = 'error_php_too_low'; |
|
| 503 | + if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>'))) { |
|
| 504 | + $error = 'error_php_too_low'; |
|
| 505 | + } |
|
| 481 | 506 | // Make sure we have a supported database |
| 482 | - elseif (empty($incontext['supported_databases'])) |
|
| 483 | - $error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing'; |
|
| 507 | + elseif (empty($incontext['supported_databases'])) { |
|
| 508 | + $error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing'; |
|
| 509 | + } |
|
| 484 | 510 | // How about session support? Some crazy sysadmin remove it? |
| 485 | - elseif (!function_exists('session_start')) |
|
| 486 | - $error = 'error_session_missing'; |
|
| 511 | + elseif (!function_exists('session_start')) { |
|
| 512 | + $error = 'error_session_missing'; |
|
| 513 | + } |
|
| 487 | 514 | // Make sure they uploaded all the files. |
| 488 | - elseif (!file_exists(dirname(__FILE__) . '/index.php')) |
|
| 489 | - $error = 'error_missing_files'; |
|
| 515 | + elseif (!file_exists(dirname(__FILE__) . '/index.php')) { |
|
| 516 | + $error = 'error_missing_files'; |
|
| 517 | + } |
|
| 490 | 518 | // Very simple check on the session.save_path for Windows. |
| 491 | 519 | // @todo Move this down later if they don't use database-driven sessions? |
| 492 | - elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\') |
|
| 493 | - $error = 'error_session_save_path'; |
|
| 520 | + elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\') { |
|
| 521 | + $error = 'error_session_save_path'; |
|
| 522 | + } |
|
| 494 | 523 | |
| 495 | 524 | // Since each of the three messages would look the same, anyway... |
| 496 | - if (isset($error)) |
|
| 497 | - $incontext['error'] = $txt[$error]; |
|
| 525 | + if (isset($error)) { |
|
| 526 | + $incontext['error'] = $txt[$error]; |
|
| 527 | + } |
|
| 498 | 528 | |
| 499 | 529 | // Mod_security blocks everything that smells funny. Let SMF handle security. |
| 500 | - if (!fixModSecurity() && !isset($_GET['overmodsecurity'])) |
|
| 501 | - $incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again']; |
|
| 530 | + if (!fixModSecurity() && !isset($_GET['overmodsecurity'])) { |
|
| 531 | + $incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again']; |
|
| 532 | + } |
|
| 502 | 533 | |
| 503 | 534 | return false; |
| 504 | 535 | } |
@@ -521,15 +552,18 @@ discard block |
||
| 521 | 552 | 'agreement.txt', |
| 522 | 553 | 'Settings.php' |
| 523 | 554 | ); |
| 524 | - if (file_exists(dirname(__FILE__) . '/Settings_bak.php')) |
|
| 525 | - $writable_files[] = 'Settings_bak.php'; |
|
| 555 | + if (file_exists(dirname(__FILE__) . '/Settings_bak.php')) { |
|
| 556 | + $writable_files[] = 'Settings_bak.php'; |
|
| 557 | + } |
|
| 526 | 558 | |
| 527 | - foreach ($incontext['detected_languages'] as $lang => $temp) |
|
| 528 | - $extra_files[] = 'Themes/default/languages/' . $lang; |
|
| 559 | + foreach ($incontext['detected_languages'] as $lang => $temp) { |
|
| 560 | + $extra_files[] = 'Themes/default/languages/' . $lang; |
|
| 561 | + } |
|
| 529 | 562 | |
| 530 | 563 | // With mod_security installed, we could attempt to fix it with .htaccess. |
| 531 | - if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules())) |
|
| 532 | - $writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.'; |
|
| 564 | + if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules())) { |
|
| 565 | + $writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.'; |
|
| 566 | + } |
|
| 533 | 567 | |
| 534 | 568 | $failed_files = array(); |
| 535 | 569 | |
@@ -545,12 +579,14 @@ discard block |
||
| 545 | 579 | @chmod(dirname(__FILE__) . '/' . $file, 0755); |
| 546 | 580 | |
| 547 | 581 | // Well, 755 hopefully worked... if not, try 777. |
| 548 | - if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777)) |
|
| 549 | - $failed_files[] = $file; |
|
| 582 | + if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777)) { |
|
| 583 | + $failed_files[] = $file; |
|
| 584 | + } |
|
| 550 | 585 | } |
| 551 | 586 | } |
| 552 | - foreach ($extra_files as $file) |
|
| 553 | - @chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777); |
|
| 587 | + foreach ($extra_files as $file) { |
|
| 588 | + @chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777); |
|
| 589 | + } |
|
| 554 | 590 | } |
| 555 | 591 | // Windows is trickier. Let's try opening for r+... |
| 556 | 592 | else |
@@ -560,30 +596,35 @@ discard block |
||
| 560 | 596 | foreach ($writable_files as $file) |
| 561 | 597 | { |
| 562 | 598 | // Folders can't be opened for write... but the index.php in them can ;) |
| 563 | - if (is_dir(dirname(__FILE__) . '/' . $file)) |
|
| 564 | - $file .= '/index.php'; |
|
| 599 | + if (is_dir(dirname(__FILE__) . '/' . $file)) { |
|
| 600 | + $file .= '/index.php'; |
|
| 601 | + } |
|
| 565 | 602 | |
| 566 | 603 | // Funny enough, chmod actually does do something on windows - it removes the read only attribute. |
| 567 | 604 | @chmod(dirname(__FILE__) . '/' . $file, 0777); |
| 568 | 605 | $fp = @fopen(dirname(__FILE__) . '/' . $file, 'r+'); |
| 569 | 606 | |
| 570 | 607 | // Hmm, okay, try just for write in that case... |
| 571 | - if (!is_resource($fp)) |
|
| 572 | - $fp = @fopen(dirname(__FILE__) . '/' . $file, 'w'); |
|
| 608 | + if (!is_resource($fp)) { |
|
| 609 | + $fp = @fopen(dirname(__FILE__) . '/' . $file, 'w'); |
|
| 610 | + } |
|
| 573 | 611 | |
| 574 | - if (!is_resource($fp)) |
|
| 575 | - $failed_files[] = $file; |
|
| 612 | + if (!is_resource($fp)) { |
|
| 613 | + $failed_files[] = $file; |
|
| 614 | + } |
|
| 576 | 615 | |
| 577 | 616 | @fclose($fp); |
| 578 | 617 | } |
| 579 | - foreach ($extra_files as $file) |
|
| 580 | - @chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777); |
|
| 618 | + foreach ($extra_files as $file) { |
|
| 619 | + @chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777); |
|
| 620 | + } |
|
| 581 | 621 | } |
| 582 | 622 | |
| 583 | 623 | $failure = count($failed_files) >= 1; |
| 584 | 624 | |
| 585 | - if (!isset($_SERVER)) |
|
| 586 | - return !$failure; |
|
| 625 | + if (!isset($_SERVER)) { |
|
| 626 | + return !$failure; |
|
| 627 | + } |
|
| 587 | 628 | |
| 588 | 629 | // Put the list into context. |
| 589 | 630 | $incontext['failed_files'] = $failed_files; |
@@ -631,19 +672,23 @@ discard block |
||
| 631 | 672 | |
| 632 | 673 | if (!isset($ftp) || $ftp->error !== false) |
| 633 | 674 | { |
| 634 | - if (!isset($ftp)) |
|
| 635 | - $ftp = new ftp_connection(null); |
|
| 675 | + if (!isset($ftp)) { |
|
| 676 | + $ftp = new ftp_connection(null); |
|
| 677 | + } |
|
| 636 | 678 | // Save the error so we can mess with listing... |
| 637 | - elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message)) |
|
| 638 | - $incontext['ftp_errors'][] = $ftp->last_message; |
|
| 679 | + elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message)) { |
|
| 680 | + $incontext['ftp_errors'][] = $ftp->last_message; |
|
| 681 | + } |
|
| 639 | 682 | |
| 640 | 683 | list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__)); |
| 641 | 684 | |
| 642 | - if (empty($_POST['ftp_path']) && $found_path) |
|
| 643 | - $_POST['ftp_path'] = $detect_path; |
|
| 685 | + if (empty($_POST['ftp_path']) && $found_path) { |
|
| 686 | + $_POST['ftp_path'] = $detect_path; |
|
| 687 | + } |
|
| 644 | 688 | |
| 645 | - if (!isset($_POST['ftp_username'])) |
|
| 646 | - $_POST['ftp_username'] = $username; |
|
| 689 | + if (!isset($_POST['ftp_username'])) { |
|
| 690 | + $_POST['ftp_username'] = $username; |
|
| 691 | + } |
|
| 647 | 692 | |
| 648 | 693 | // Set the username etc, into context. |
| 649 | 694 | $incontext['ftp'] = array( |
@@ -655,8 +700,7 @@ discard block |
||
| 655 | 700 | ); |
| 656 | 701 | |
| 657 | 702 | return false; |
| 658 | - } |
|
| 659 | - else |
|
| 703 | + } else |
|
| 660 | 704 | { |
| 661 | 705 | $_SESSION['installer_temp_ftp'] = array( |
| 662 | 706 | 'server' => $_POST['ftp_server'], |
@@ -670,10 +714,12 @@ discard block |
||
| 670 | 714 | |
| 671 | 715 | foreach ($failed_files as $file) |
| 672 | 716 | { |
| 673 | - if (!is_writable(dirname(__FILE__) . '/' . $file)) |
|
| 674 | - $ftp->chmod($file, 0755); |
|
| 675 | - if (!is_writable(dirname(__FILE__) . '/' . $file)) |
|
| 676 | - $ftp->chmod($file, 0777); |
|
| 717 | + if (!is_writable(dirname(__FILE__) . '/' . $file)) { |
|
| 718 | + $ftp->chmod($file, 0755); |
|
| 719 | + } |
|
| 720 | + if (!is_writable(dirname(__FILE__) . '/' . $file)) { |
|
| 721 | + $ftp->chmod($file, 0777); |
|
| 722 | + } |
|
| 677 | 723 | if (!is_writable(dirname(__FILE__) . '/' . $file)) |
| 678 | 724 | { |
| 679 | 725 | $failed_files_updated[] = $file; |
@@ -728,15 +774,17 @@ discard block |
||
| 728 | 774 | |
| 729 | 775 | if (!$foundOne) |
| 730 | 776 | { |
| 731 | - if (isset($db['default_host'])) |
|
| 732 | - $incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost'; |
|
| 777 | + if (isset($db['default_host'])) { |
|
| 778 | + $incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost'; |
|
| 779 | + } |
|
| 733 | 780 | if (isset($db['default_user'])) |
| 734 | 781 | { |
| 735 | 782 | $incontext['db']['user'] = ini_get($db['default_user']); |
| 736 | 783 | $incontext['db']['name'] = ini_get($db['default_user']); |
| 737 | 784 | } |
| 738 | - if (isset($db['default_password'])) |
|
| 739 | - $incontext['db']['pass'] = ini_get($db['default_password']); |
|
| 785 | + if (isset($db['default_password'])) { |
|
| 786 | + $incontext['db']['pass'] = ini_get($db['default_password']); |
|
| 787 | + } |
|
| 740 | 788 | |
| 741 | 789 | // For simplicity and less confusion, leave the port blank by default |
| 742 | 790 | $incontext['db']['port'] = ''; |
@@ -755,10 +803,10 @@ discard block |
||
| 755 | 803 | $incontext['db']['server'] = $_POST['db_server']; |
| 756 | 804 | $incontext['db']['prefix'] = $_POST['db_prefix']; |
| 757 | 805 | |
| 758 | - if (!empty($_POST['db_port'])) |
|
| 759 | - $incontext['db']['port'] = $_POST['db_port']; |
|
| 760 | - } |
|
| 761 | - else |
|
| 806 | + if (!empty($_POST['db_port'])) { |
|
| 807 | + $incontext['db']['port'] = $_POST['db_port']; |
|
| 808 | + } |
|
| 809 | + } else |
|
| 762 | 810 | { |
| 763 | 811 | $incontext['db']['prefix'] = 'smf_'; |
| 764 | 812 | } |
@@ -794,10 +842,11 @@ discard block |
||
| 794 | 842 | if (!empty($_POST['db_port'])) |
| 795 | 843 | { |
| 796 | 844 | // For MySQL, we can get the "default port" from PHP. PostgreSQL has no such option though. |
| 797 | - if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port')) |
|
| 798 | - $vars['db_port'] = (int) $_POST['db_port']; |
|
| 799 | - elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432) |
|
| 800 | - $vars['db_port'] = (int) $_POST['db_port']; |
|
| 845 | + if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port')) { |
|
| 846 | + $vars['db_port'] = (int) $_POST['db_port']; |
|
| 847 | + } elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432) { |
|
| 848 | + $vars['db_port'] = (int) $_POST['db_port']; |
|
| 849 | + } |
|
| 801 | 850 | } |
| 802 | 851 | |
| 803 | 852 | // God I hope it saved! |
@@ -810,8 +859,9 @@ discard block |
||
| 810 | 859 | // Make sure it works. |
| 811 | 860 | require(dirname(__FILE__) . '/Settings.php'); |
| 812 | 861 | |
| 813 | - if (empty($sourcedir)) |
|
| 814 | - $sourcedir = dirname(__FILE__) . '/Sources'; |
|
| 862 | + if (empty($sourcedir)) { |
|
| 863 | + $sourcedir = dirname(__FILE__) . '/Sources'; |
|
| 864 | + } |
|
| 815 | 865 | |
| 816 | 866 | // Better find the database file! |
| 817 | 867 | if (!file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) |
@@ -821,18 +871,21 @@ discard block |
||
| 821 | 871 | } |
| 822 | 872 | |
| 823 | 873 | // Now include it for database functions! |
| 824 | - if (!defined('SMF')) |
|
| 825 | - define('SMF', 1); |
|
| 874 | + if (!defined('SMF')) { |
|
| 875 | + define('SMF', 1); |
|
| 876 | + } |
|
| 826 | 877 | |
| 827 | 878 | $modSettings['disableQueryCheck'] = true; |
| 828 | - if (empty($smcFunc)) |
|
| 829 | - $smcFunc = array(); |
|
| 879 | + if (empty($smcFunc)) { |
|
| 880 | + $smcFunc = array(); |
|
| 881 | + } |
|
| 830 | 882 | |
| 831 | 883 | require_once($sourcedir . '/Subs-Db-' . $db_type . '.php'); |
| 832 | 884 | |
| 833 | 885 | // What - running PHP4? The shame! |
| 834 | - if (version_compare(PHP_VERSION, '5', '<')) |
|
| 835 | - require_once($sourcedir . '/Subs-Compat.php'); |
|
| 886 | + if (version_compare(PHP_VERSION, '5', '<')) { |
|
| 887 | + require_once($sourcedir . '/Subs-Compat.php'); |
|
| 888 | + } |
|
| 836 | 889 | |
| 837 | 890 | // Attempt a connection. |
| 838 | 891 | $needsDB = !empty($databases[$db_type]['always_has_db']); |
@@ -920,12 +973,14 @@ discard block |
||
| 920 | 973 | $incontext['page_title'] = $txt['install_settings']; |
| 921 | 974 | |
| 922 | 975 | // Let's see if we got the database type correct. |
| 923 | - if (isset($_POST['db_type'], $databases[$_POST['db_type']])) |
|
| 924 | - $db_type = $_POST['db_type']; |
|
| 976 | + if (isset($_POST['db_type'], $databases[$_POST['db_type']])) { |
|
| 977 | + $db_type = $_POST['db_type']; |
|
| 978 | + } |
|
| 925 | 979 | |
| 926 | 980 | // Else we'd better be able to get the connection. |
| 927 | - else |
|
| 928 | - load_database(); |
|
| 981 | + else { |
|
| 982 | + load_database(); |
|
| 983 | + } |
|
| 929 | 984 | |
| 930 | 985 | $db_type = isset($_POST['db_type']) ? $_POST['db_type'] : $db_type; |
| 931 | 986 | |
@@ -945,12 +1000,14 @@ discard block |
||
| 945 | 1000 | // Submitting? |
| 946 | 1001 | if (isset($_POST['boardurl'])) |
| 947 | 1002 | { |
| 948 | - if (substr($_POST['boardurl'], -10) == '/index.php') |
|
| 949 | - $_POST['boardurl'] = substr($_POST['boardurl'], 0, -10); |
|
| 950 | - elseif (substr($_POST['boardurl'], -1) == '/') |
|
| 951 | - $_POST['boardurl'] = substr($_POST['boardurl'], 0, -1); |
|
| 952 | - if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') |
|
| 953 | - $_POST['boardurl'] = 'http://' . $_POST['boardurl']; |
|
| 1003 | + if (substr($_POST['boardurl'], -10) == '/index.php') { |
|
| 1004 | + $_POST['boardurl'] = substr($_POST['boardurl'], 0, -10); |
|
| 1005 | + } elseif (substr($_POST['boardurl'], -1) == '/') { |
|
| 1006 | + $_POST['boardurl'] = substr($_POST['boardurl'], 0, -1); |
|
| 1007 | + } |
|
| 1008 | + if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') { |
|
| 1009 | + $_POST['boardurl'] = 'http://' . $_POST['boardurl']; |
|
| 1010 | + } |
|
| 954 | 1011 | |
| 955 | 1012 | // Save these variables. |
| 956 | 1013 | $vars = array( |
@@ -981,10 +1038,10 @@ discard block |
||
| 981 | 1038 | { |
| 982 | 1039 | $incontext['error'] = sprintf($txt['error_utf8_version'], $databases[$db_type]['utf8_version']); |
| 983 | 1040 | return false; |
| 984 | - } |
|
| 985 | - else |
|
| 986 | - // Set the character set here. |
|
| 1041 | + } else { |
|
| 1042 | + // Set the character set here. |
|
| 987 | 1043 | updateSettingsFile(array('db_character_set' => 'utf8')); |
| 1044 | + } |
|
| 988 | 1045 | } |
| 989 | 1046 | |
| 990 | 1047 | // Good, skip on. |
@@ -1004,8 +1061,9 @@ discard block |
||
| 1004 | 1061 | $incontext['continue'] = 1; |
| 1005 | 1062 | |
| 1006 | 1063 | // Already done? |
| 1007 | - if (isset($_POST['pop_done'])) |
|
| 1008 | - return true; |
|
| 1064 | + if (isset($_POST['pop_done'])) { |
|
| 1065 | + return true; |
|
| 1066 | + } |
|
| 1009 | 1067 | |
| 1010 | 1068 | // Reload settings. |
| 1011 | 1069 | require(dirname(__FILE__) . '/Settings.php'); |
@@ -1023,8 +1081,9 @@ discard block |
||
| 1023 | 1081 | $modSettings = array(); |
| 1024 | 1082 | if ($result !== false) |
| 1025 | 1083 | { |
| 1026 | - while ($row = $smcFunc['db_fetch_assoc']($result)) |
|
| 1027 | - $modSettings[$row['variable']] = $row['value']; |
|
| 1084 | + while ($row = $smcFunc['db_fetch_assoc']($result)) { |
|
| 1085 | + $modSettings[$row['variable']] = $row['value']; |
|
| 1086 | + } |
|
| 1028 | 1087 | $smcFunc['db_free_result']($result); |
| 1029 | 1088 | |
| 1030 | 1089 | // Do they match? If so, this is just a refresh so charge on! |
@@ -1037,20 +1096,22 @@ discard block |
||
| 1037 | 1096 | $modSettings['disableQueryCheck'] = true; |
| 1038 | 1097 | |
| 1039 | 1098 | // If doing UTF8, select it. PostgreSQL requires passing it as a string... |
| 1040 | - if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support'])) |
|
| 1041 | - $smcFunc['db_query']('', ' |
|
| 1099 | + if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support'])) { |
|
| 1100 | + $smcFunc['db_query']('', ' |
|
| 1042 | 1101 | SET NAMES {string:utf8}', |
| 1043 | 1102 | array( |
| 1044 | 1103 | 'db_error_skip' => true, |
| 1045 | 1104 | 'utf8' => 'utf8', |
| 1046 | 1105 | ) |
| 1047 | 1106 | ); |
| 1107 | + } |
|
| 1048 | 1108 | |
| 1049 | 1109 | // Windows likes to leave the trailing slash, which yields to C:\path\to\SMF\/attachments... |
| 1050 | - if (substr(__DIR__, -1) == '\\') |
|
| 1051 | - $attachdir = __DIR__ . 'attachments'; |
|
| 1052 | - else |
|
| 1053 | - $attachdir = __DIR__ . '/attachments'; |
|
| 1110 | + if (substr(__DIR__, -1) == '\\') { |
|
| 1111 | + $attachdir = __DIR__ . 'attachments'; |
|
| 1112 | + } else { |
|
| 1113 | + $attachdir = __DIR__ . '/attachments'; |
|
| 1114 | + } |
|
| 1054 | 1115 | |
| 1055 | 1116 | $replaces = array( |
| 1056 | 1117 | '{$db_prefix}' => $db_prefix, |
@@ -1067,8 +1128,9 @@ discard block |
||
| 1067 | 1128 | |
| 1068 | 1129 | foreach ($txt as $key => $value) |
| 1069 | 1130 | { |
| 1070 | - if (substr($key, 0, 8) == 'default_') |
|
| 1071 | - $replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value); |
|
| 1131 | + if (substr($key, 0, 8) == 'default_') { |
|
| 1132 | + $replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value); |
|
| 1133 | + } |
|
| 1072 | 1134 | } |
| 1073 | 1135 | $replaces['{$default_reserved_names}'] = strtr($replaces['{$default_reserved_names}'], array('\\\\n' => '\\n')); |
| 1074 | 1136 | |
@@ -1083,8 +1145,9 @@ discard block |
||
| 1083 | 1145 | |
| 1084 | 1146 | while ($row = $smcFunc['db_fetch_assoc']($get_engines)) |
| 1085 | 1147 | { |
| 1086 | - if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') |
|
| 1087 | - $engines[] = $row['Engine']; |
|
| 1148 | + if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') { |
|
| 1149 | + $engines[] = $row['Engine']; |
|
| 1150 | + } |
|
| 1088 | 1151 | } |
| 1089 | 1152 | |
| 1090 | 1153 | // Done with this now |
@@ -1108,8 +1171,7 @@ discard block |
||
| 1108 | 1171 | $replaces['START TRANSACTION;'] = ''; |
| 1109 | 1172 | $replaces['COMMIT;'] = ''; |
| 1110 | 1173 | } |
| 1111 | - } |
|
| 1112 | - else |
|
| 1174 | + } else |
|
| 1113 | 1175 | { |
| 1114 | 1176 | $has_innodb = false; |
| 1115 | 1177 | } |
@@ -1131,21 +1193,24 @@ discard block |
||
| 1131 | 1193 | foreach ($sql_lines as $count => $line) |
| 1132 | 1194 | { |
| 1133 | 1195 | // No comments allowed! |
| 1134 | - if (substr(trim($line), 0, 1) != '#') |
|
| 1135 | - $current_statement .= "\n" . rtrim($line); |
|
| 1196 | + if (substr(trim($line), 0, 1) != '#') { |
|
| 1197 | + $current_statement .= "\n" . rtrim($line); |
|
| 1198 | + } |
|
| 1136 | 1199 | |
| 1137 | 1200 | // Is this the end of the query string? |
| 1138 | - if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines))) |
|
| 1139 | - continue; |
|
| 1201 | + if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines))) { |
|
| 1202 | + continue; |
|
| 1203 | + } |
|
| 1140 | 1204 | |
| 1141 | 1205 | // Does this table already exist? If so, don't insert more data into it! |
| 1142 | 1206 | if (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) != 0 && in_array($match[1], $exists)) |
| 1143 | 1207 | { |
| 1144 | 1208 | preg_match_all('~\)[,;]~', $current_statement, $matches); |
| 1145 | - if (!empty($matches[0])) |
|
| 1146 | - $incontext['sql_results']['insert_dups'] += count($matches[0]); |
|
| 1147 | - else |
|
| 1148 | - $incontext['sql_results']['insert_dups']++; |
|
| 1209 | + if (!empty($matches[0])) { |
|
| 1210 | + $incontext['sql_results']['insert_dups'] += count($matches[0]); |
|
| 1211 | + } else { |
|
| 1212 | + $incontext['sql_results']['insert_dups']++; |
|
| 1213 | + } |
|
| 1149 | 1214 | |
| 1150 | 1215 | $current_statement = ''; |
| 1151 | 1216 | continue; |
@@ -1154,8 +1219,9 @@ discard block |
||
| 1154 | 1219 | if ($smcFunc['db_query']('', $current_statement, array('security_override' => true, 'db_error_skip' => true), $db_connection) === false) |
| 1155 | 1220 | { |
| 1156 | 1221 | // Use the appropriate function based on the DB type |
| 1157 | - if ($db_type == 'mysql' || $db_type == 'mysqli') |
|
| 1158 | - $db_errorno = $db_type . '_errno'; |
|
| 1222 | + if ($db_type == 'mysql' || $db_type == 'mysqli') { |
|
| 1223 | + $db_errorno = $db_type . '_errno'; |
|
| 1224 | + } |
|
| 1159 | 1225 | |
| 1160 | 1226 | // Error 1050: Table already exists! |
| 1161 | 1227 | // @todo Needs to be made better! |
@@ -1170,18 +1236,18 @@ discard block |
||
| 1170 | 1236 | // MySQLi requires a connection object. It's optional with MySQL and Postgres |
| 1171 | 1237 | $incontext['failures'][$count] = $smcFunc['db_error']($db_connection); |
| 1172 | 1238 | } |
| 1173 | - } |
|
| 1174 | - else |
|
| 1239 | + } else |
|
| 1175 | 1240 | { |
| 1176 | - if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1) |
|
| 1177 | - $incontext['sql_results']['tables']++; |
|
| 1178 | - elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1) |
|
| 1241 | + if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1) { |
|
| 1242 | + $incontext['sql_results']['tables']++; |
|
| 1243 | + } elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1) |
|
| 1179 | 1244 | { |
| 1180 | 1245 | preg_match_all('~\)[,;]~', $current_statement, $matches); |
| 1181 | - if (!empty($matches[0])) |
|
| 1182 | - $incontext['sql_results']['inserts'] += count($matches[0]); |
|
| 1183 | - else |
|
| 1184 | - $incontext['sql_results']['inserts']++; |
|
| 1246 | + if (!empty($matches[0])) { |
|
| 1247 | + $incontext['sql_results']['inserts'] += count($matches[0]); |
|
| 1248 | + } else { |
|
| 1249 | + $incontext['sql_results']['inserts']++; |
|
| 1250 | + } |
|
| 1185 | 1251 | } |
| 1186 | 1252 | } |
| 1187 | 1253 | |
@@ -1194,15 +1260,17 @@ discard block |
||
| 1194 | 1260 | // Sort out the context for the SQL. |
| 1195 | 1261 | foreach ($incontext['sql_results'] as $key => $number) |
| 1196 | 1262 | { |
| 1197 | - if ($number == 0) |
|
| 1198 | - unset($incontext['sql_results'][$key]); |
|
| 1199 | - else |
|
| 1200 | - $incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number); |
|
| 1263 | + if ($number == 0) { |
|
| 1264 | + unset($incontext['sql_results'][$key]); |
|
| 1265 | + } else { |
|
| 1266 | + $incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number); |
|
| 1267 | + } |
|
| 1201 | 1268 | } |
| 1202 | 1269 | |
| 1203 | 1270 | // Make sure UTF will be used globally. |
| 1204 | - if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8']))) |
|
| 1205 | - $newSettings[] = array('global_character_set', 'UTF-8'); |
|
| 1271 | + if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8']))) { |
|
| 1272 | + $newSettings[] = array('global_character_set', 'UTF-8'); |
|
| 1273 | + } |
|
| 1206 | 1274 | |
| 1207 | 1275 | // Maybe we can auto-detect better cookie settings? |
| 1208 | 1276 | preg_match('~^http[s]?://([^\.]+?)([^/]*?)(/.*)?$~', $boardurl, $matches); |
@@ -1213,16 +1281,20 @@ discard block |
||
| 1213 | 1281 | $globalCookies = false; |
| 1214 | 1282 | |
| 1215 | 1283 | // Okay... let's see. Using a subdomain other than www.? (not a perfect check.) |
| 1216 | - if ($matches[2] != '' && (strpos(substr($matches[2], 1), '.') === false || in_array($matches[1], array('forum', 'board', 'community', 'forums', 'support', 'chat', 'help', 'talk', 'boards', 'www')))) |
|
| 1217 | - $globalCookies = true; |
|
| 1284 | + if ($matches[2] != '' && (strpos(substr($matches[2], 1), '.') === false || in_array($matches[1], array('forum', 'board', 'community', 'forums', 'support', 'chat', 'help', 'talk', 'boards', 'www')))) { |
|
| 1285 | + $globalCookies = true; |
|
| 1286 | + } |
|
| 1218 | 1287 | // If there's a / in the middle of the path, or it starts with ~... we want local. |
| 1219 | - if (isset($matches[3]) && strlen($matches[3]) > 3 && (substr($matches[3], 0, 2) == '/~' || strpos(substr($matches[3], 1), '/') !== false)) |
|
| 1220 | - $localCookies = true; |
|
| 1288 | + if (isset($matches[3]) && strlen($matches[3]) > 3 && (substr($matches[3], 0, 2) == '/~' || strpos(substr($matches[3], 1), '/') !== false)) { |
|
| 1289 | + $localCookies = true; |
|
| 1290 | + } |
|
| 1221 | 1291 | |
| 1222 | - if ($globalCookies) |
|
| 1223 | - $newSettings[] = array('globalCookies', '1'); |
|
| 1224 | - if ($localCookies) |
|
| 1225 | - $newSettings[] = array('localCookies', '1'); |
|
| 1292 | + if ($globalCookies) { |
|
| 1293 | + $newSettings[] = array('globalCookies', '1'); |
|
| 1294 | + } |
|
| 1295 | + if ($localCookies) { |
|
| 1296 | + $newSettings[] = array('localCookies', '1'); |
|
| 1297 | + } |
|
| 1226 | 1298 | } |
| 1227 | 1299 | |
| 1228 | 1300 | // Are we allowing stat collection? |
@@ -1238,32 +1310,36 @@ discard block |
||
| 1238 | 1310 | fwrite($fp, $out); |
| 1239 | 1311 | |
| 1240 | 1312 | $return_data = ''; |
| 1241 | - while (!feof($fp)) |
|
| 1242 | - $return_data .= fgets($fp, 128); |
|
| 1313 | + while (!feof($fp)) { |
|
| 1314 | + $return_data .= fgets($fp, 128); |
|
| 1315 | + } |
|
| 1243 | 1316 | |
| 1244 | 1317 | fclose($fp); |
| 1245 | 1318 | |
| 1246 | 1319 | // Get the unique site ID. |
| 1247 | 1320 | preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID); |
| 1248 | 1321 | |
| 1249 | - if (!empty($ID[1])) |
|
| 1250 | - $newSettings[] = array('allow_sm_stats', $ID[1]); |
|
| 1322 | + if (!empty($ID[1])) { |
|
| 1323 | + $newSettings[] = array('allow_sm_stats', $ID[1]); |
|
| 1324 | + } |
|
| 1251 | 1325 | } |
| 1252 | 1326 | } |
| 1253 | 1327 | |
| 1254 | 1328 | // Are we enabling SSL? |
| 1255 | - if (!empty($_POST['force_ssl'])) |
|
| 1256 | - $newSettings[] = array('force_ssl', 2); |
|
| 1329 | + if (!empty($_POST['force_ssl'])) { |
|
| 1330 | + $newSettings[] = array('force_ssl', 2); |
|
| 1331 | + } |
|
| 1257 | 1332 | |
| 1258 | 1333 | // Setting a timezone is required. |
| 1259 | 1334 | if (!isset($modSettings['default_timezone']) && function_exists('date_default_timezone_set')) |
| 1260 | 1335 | { |
| 1261 | 1336 | // Get PHP's default timezone, if set |
| 1262 | 1337 | $ini_tz = ini_get('date.timezone'); |
| 1263 | - if (!empty($ini_tz)) |
|
| 1264 | - $timezone_id = $ini_tz; |
|
| 1265 | - else |
|
| 1266 | - $timezone_id = ''; |
|
| 1338 | + if (!empty($ini_tz)) { |
|
| 1339 | + $timezone_id = $ini_tz; |
|
| 1340 | + } else { |
|
| 1341 | + $timezone_id = ''; |
|
| 1342 | + } |
|
| 1267 | 1343 | |
| 1268 | 1344 | // If date.timezone is unset, invalid, or just plain weird, make a best guess |
| 1269 | 1345 | if (!in_array($timezone_id, timezone_identifiers_list())) |
@@ -1272,8 +1348,9 @@ discard block |
||
| 1272 | 1348 | $timezone_id = timezone_name_from_abbr('', $server_offset, 0); |
| 1273 | 1349 | } |
| 1274 | 1350 | |
| 1275 | - if (date_default_timezone_set($timezone_id)) |
|
| 1276 | - $newSettings[] = array('default_timezone', $timezone_id); |
|
| 1351 | + if (date_default_timezone_set($timezone_id)) { |
|
| 1352 | + $newSettings[] = array('default_timezone', $timezone_id); |
|
| 1353 | + } |
|
| 1277 | 1354 | } |
| 1278 | 1355 | |
| 1279 | 1356 | if (!empty($newSettings)) |
@@ -1304,16 +1381,18 @@ discard block |
||
| 1304 | 1381 | } |
| 1305 | 1382 | |
| 1306 | 1383 | // MySQL specific stuff |
| 1307 | - if (substr($db_type, 0, 5) != 'mysql') |
|
| 1308 | - return false; |
|
| 1384 | + if (substr($db_type, 0, 5) != 'mysql') { |
|
| 1385 | + return false; |
|
| 1386 | + } |
|
| 1309 | 1387 | |
| 1310 | 1388 | // Find database user privileges. |
| 1311 | 1389 | $privs = array(); |
| 1312 | 1390 | $get_privs = $smcFunc['db_query']('', 'SHOW PRIVILEGES', array()); |
| 1313 | 1391 | while ($row = $smcFunc['db_fetch_assoc']($get_privs)) |
| 1314 | 1392 | { |
| 1315 | - if ($row['Privilege'] == 'Alter') |
|
| 1316 | - $privs[] = $row['Privilege']; |
|
| 1393 | + if ($row['Privilege'] == 'Alter') { |
|
| 1394 | + $privs[] = $row['Privilege']; |
|
| 1395 | + } |
|
| 1317 | 1396 | } |
| 1318 | 1397 | $smcFunc['db_free_result']($get_privs); |
| 1319 | 1398 | |
@@ -1343,8 +1422,9 @@ discard block |
||
| 1343 | 1422 | $incontext['continue'] = 1; |
| 1344 | 1423 | |
| 1345 | 1424 | // Skipping? |
| 1346 | - if (!empty($_POST['skip'])) |
|
| 1347 | - return true; |
|
| 1425 | + if (!empty($_POST['skip'])) { |
|
| 1426 | + return true; |
|
| 1427 | + } |
|
| 1348 | 1428 | |
| 1349 | 1429 | // Need this to check whether we need the database password. |
| 1350 | 1430 | require(dirname(__FILE__) . '/Settings.php'); |
@@ -1357,18 +1437,22 @@ discard block |
||
| 1357 | 1437 | // We need this to properly hash the password for Admin |
| 1358 | 1438 | $smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' : function($string) { |
| 1359 | 1439 | global $sourcedir; |
| 1360 | - if (function_exists('mb_strtolower')) |
|
| 1361 | - return mb_strtolower($string, 'UTF-8'); |
|
| 1440 | + if (function_exists('mb_strtolower')) { |
|
| 1441 | + return mb_strtolower($string, 'UTF-8'); |
|
| 1442 | + } |
|
| 1362 | 1443 | require_once($sourcedir . '/Subs-Charset.php'); |
| 1363 | 1444 | return utf8_strtolower($string); |
| 1364 | 1445 | }; |
| 1365 | 1446 | |
| 1366 | - if (!isset($_POST['username'])) |
|
| 1367 | - $_POST['username'] = ''; |
|
| 1368 | - if (!isset($_POST['email'])) |
|
| 1369 | - $_POST['email'] = ''; |
|
| 1370 | - if (!isset($_POST['server_email'])) |
|
| 1371 | - $_POST['server_email'] = ''; |
|
| 1447 | + if (!isset($_POST['username'])) { |
|
| 1448 | + $_POST['username'] = ''; |
|
| 1449 | + } |
|
| 1450 | + if (!isset($_POST['email'])) { |
|
| 1451 | + $_POST['email'] = ''; |
|
| 1452 | + } |
|
| 1453 | + if (!isset($_POST['server_email'])) { |
|
| 1454 | + $_POST['server_email'] = ''; |
|
| 1455 | + } |
|
| 1372 | 1456 | |
| 1373 | 1457 | $incontext['username'] = htmlspecialchars(stripslashes($_POST['username'])); |
| 1374 | 1458 | $incontext['email'] = htmlspecialchars(stripslashes($_POST['email'])); |
@@ -1387,8 +1471,9 @@ discard block |
||
| 1387 | 1471 | 'admin_group' => 1, |
| 1388 | 1472 | ) |
| 1389 | 1473 | ); |
| 1390 | - if ($smcFunc['db_num_rows']($request) != 0) |
|
| 1391 | - $incontext['skip'] = 1; |
|
| 1474 | + if ($smcFunc['db_num_rows']($request) != 0) { |
|
| 1475 | + $incontext['skip'] = 1; |
|
| 1476 | + } |
|
| 1392 | 1477 | $smcFunc['db_free_result']($request); |
| 1393 | 1478 | |
| 1394 | 1479 | // Trying to create an account? |
@@ -1419,8 +1504,9 @@ discard block |
||
| 1419 | 1504 | } |
| 1420 | 1505 | |
| 1421 | 1506 | // Update the webmaster's email? |
| 1422 | - if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]')) |
|
| 1423 | - updateSettingsFile(array('webmaster_email' => $_POST['server_email'])); |
|
| 1507 | + if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]')) { |
|
| 1508 | + updateSettingsFile(array('webmaster_email' => $_POST['server_email'])); |
|
| 1509 | + } |
|
| 1424 | 1510 | |
| 1425 | 1511 | // Work out whether we're going to have dodgy characters and remove them. |
| 1426 | 1512 | $invalid_characters = preg_match('~[<>&"\'=\\\]~', $_POST['username']) != 0; |
@@ -1443,32 +1529,27 @@ discard block |
||
| 1443 | 1529 | $smcFunc['db_free_result']($result); |
| 1444 | 1530 | |
| 1445 | 1531 | $incontext['account_existed'] = $txt['error_user_settings_taken']; |
| 1446 | - } |
|
| 1447 | - elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25) |
|
| 1532 | + } elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25) |
|
| 1448 | 1533 | { |
| 1449 | 1534 | // Try the previous step again. |
| 1450 | 1535 | $incontext['error'] = $_POST['username'] == '' ? $txt['error_username_left_empty'] : $txt['error_username_too_long']; |
| 1451 | 1536 | return false; |
| 1452 | - } |
|
| 1453 | - elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false) |
|
| 1537 | + } elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false) |
|
| 1454 | 1538 | { |
| 1455 | 1539 | // Try the previous step again. |
| 1456 | 1540 | $incontext['error'] = $txt['error_invalid_characters_username']; |
| 1457 | 1541 | return false; |
| 1458 | - } |
|
| 1459 | - elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255) |
|
| 1542 | + } elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255) |
|
| 1460 | 1543 | { |
| 1461 | 1544 | // One step back, this time fill out a proper admin email address. |
| 1462 | 1545 | $incontext['error'] = sprintf($txt['error_valid_admin_email_needed'], $_POST['username']); |
| 1463 | 1546 | return false; |
| 1464 | - } |
|
| 1465 | - elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255) |
|
| 1547 | + } elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255) |
|
| 1466 | 1548 | { |
| 1467 | 1549 | // One step back, this time fill out a proper admin email address. |
| 1468 | 1550 | $incontext['error'] = $txt['error_valid_server_email_needed']; |
| 1469 | 1551 | return false; |
| 1470 | - } |
|
| 1471 | - elseif ($_POST['username'] != '') |
|
| 1552 | + } elseif ($_POST['username'] != '') |
|
| 1472 | 1553 | { |
| 1473 | 1554 | $incontext['member_salt'] = substr(md5(mt_rand()), 0, 4); |
| 1474 | 1555 | |
@@ -1543,17 +1624,19 @@ discard block |
||
| 1543 | 1624 | require_once($sourcedir . '/Subs-Auth.php'); |
| 1544 | 1625 | |
| 1545 | 1626 | // Bring a warning over. |
| 1546 | - if (!empty($incontext['account_existed'])) |
|
| 1547 | - $incontext['warning'] = $incontext['account_existed']; |
|
| 1627 | + if (!empty($incontext['account_existed'])) { |
|
| 1628 | + $incontext['warning'] = $incontext['account_existed']; |
|
| 1629 | + } |
|
| 1548 | 1630 | |
| 1549 | - if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support'])) |
|
| 1550 | - $smcFunc['db_query']('', ' |
|
| 1631 | + if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support'])) { |
|
| 1632 | + $smcFunc['db_query']('', ' |
|
| 1551 | 1633 | SET NAMES {string:db_character_set}', |
| 1552 | 1634 | array( |
| 1553 | 1635 | 'db_character_set' => $db_character_set, |
| 1554 | 1636 | 'db_error_skip' => true, |
| 1555 | 1637 | ) |
| 1556 | 1638 | ); |
| 1639 | + } |
|
| 1557 | 1640 | |
| 1558 | 1641 | // As track stats is by default enabled let's add some activity. |
| 1559 | 1642 | $smcFunc['db_insert']('ignore', |
@@ -1574,14 +1657,16 @@ discard block |
||
| 1574 | 1657 | // Only proceed if we can load the data. |
| 1575 | 1658 | if ($request) |
| 1576 | 1659 | { |
| 1577 | - while ($row = $smcFunc['db_fetch_row']($request)) |
|
| 1578 | - $modSettings[$row[0]] = $row[1]; |
|
| 1660 | + while ($row = $smcFunc['db_fetch_row']($request)) { |
|
| 1661 | + $modSettings[$row[0]] = $row[1]; |
|
| 1662 | + } |
|
| 1579 | 1663 | $smcFunc['db_free_result']($request); |
| 1580 | 1664 | } |
| 1581 | 1665 | |
| 1582 | 1666 | // Automatically log them in ;) |
| 1583 | - if (isset($incontext['member_id']) && isset($incontext['member_salt'])) |
|
| 1584 | - setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt'])); |
|
| 1667 | + if (isset($incontext['member_id']) && isset($incontext['member_salt'])) { |
|
| 1668 | + setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt'])); |
|
| 1669 | + } |
|
| 1585 | 1670 | |
| 1586 | 1671 | $result = $smcFunc['db_query']('', ' |
| 1587 | 1672 | SELECT value |
@@ -1592,13 +1677,14 @@ discard block |
||
| 1592 | 1677 | 'db_error_skip' => true, |
| 1593 | 1678 | ) |
| 1594 | 1679 | ); |
| 1595 | - if ($smcFunc['db_num_rows']($result) != 0) |
|
| 1596 | - list ($db_sessions) = $smcFunc['db_fetch_row']($result); |
|
| 1680 | + if ($smcFunc['db_num_rows']($result) != 0) { |
|
| 1681 | + list ($db_sessions) = $smcFunc['db_fetch_row']($result); |
|
| 1682 | + } |
|
| 1597 | 1683 | $smcFunc['db_free_result']($result); |
| 1598 | 1684 | |
| 1599 | - if (empty($db_sessions)) |
|
| 1600 | - $_SESSION['admin_time'] = time(); |
|
| 1601 | - else |
|
| 1685 | + if (empty($db_sessions)) { |
|
| 1686 | + $_SESSION['admin_time'] = time(); |
|
| 1687 | + } else |
|
| 1602 | 1688 | { |
| 1603 | 1689 | $_SERVER['HTTP_USER_AGENT'] = substr($_SERVER['HTTP_USER_AGENT'], 0, 211); |
| 1604 | 1690 | |
@@ -1622,8 +1708,9 @@ discard block |
||
| 1622 | 1708 | $smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' : |
| 1623 | 1709 | function($string){ |
| 1624 | 1710 | global $sourcedir; |
| 1625 | - if (function_exists('mb_strtolower')) |
|
| 1626 | - return mb_strtolower($string, 'UTF-8'); |
|
| 1711 | + if (function_exists('mb_strtolower')) { |
|
| 1712 | + return mb_strtolower($string, 'UTF-8'); |
|
| 1713 | + } |
|
| 1627 | 1714 | require_once($sourcedir . '/Subs-Charset.php'); |
| 1628 | 1715 | return utf8_strtolower($string); |
| 1629 | 1716 | }; |
@@ -1639,8 +1726,9 @@ discard block |
||
| 1639 | 1726 | ) |
| 1640 | 1727 | ); |
| 1641 | 1728 | $context['utf8'] = $db_character_set === 'utf8' || $txt['lang_character_set'] === 'UTF-8'; |
| 1642 | - if ($smcFunc['db_num_rows']($request) > 0) |
|
| 1643 | - updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject'])); |
|
| 1729 | + if ($smcFunc['db_num_rows']($request) > 0) { |
|
| 1730 | + updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject'])); |
|
| 1731 | + } |
|
| 1644 | 1732 | $smcFunc['db_free_result']($request); |
| 1645 | 1733 | |
| 1646 | 1734 | // Now is the perfect time to fetch the SM files. |
@@ -1659,8 +1747,9 @@ discard block |
||
| 1659 | 1747 | |
| 1660 | 1748 | // Check if we need some stupid MySQL fix. |
| 1661 | 1749 | $server_version = $smcFunc['db_server_info'](); |
| 1662 | - if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) |
|
| 1663 | - updateSettings(array('db_mysql_group_by_fix' => '1')); |
|
| 1750 | + if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) { |
|
| 1751 | + updateSettings(array('db_mysql_group_by_fix' => '1')); |
|
| 1752 | + } |
|
| 1664 | 1753 | |
| 1665 | 1754 | // Some final context for the template. |
| 1666 | 1755 | $incontext['dir_still_writable'] = is_writable(dirname(__FILE__)) && substr(__FILE__, 1, 2) != ':\\'; |
@@ -1680,8 +1769,9 @@ discard block |
||
| 1680 | 1769 | $settingsArray = file(dirname(__FILE__) . '/Settings.php'); |
| 1681 | 1770 | |
| 1682 | 1771 | // @todo Do we just want to read the file in clean, and split it this way always? |
| 1683 | - if (count($settingsArray) == 1) |
|
| 1684 | - $settingsArray = preg_split('~[\r\n]~', $settingsArray[0]); |
|
| 1772 | + if (count($settingsArray) == 1) { |
|
| 1773 | + $settingsArray = preg_split('~[\r\n]~', $settingsArray[0]); |
|
| 1774 | + } |
|
| 1685 | 1775 | |
| 1686 | 1776 | for ($i = 0, $n = count($settingsArray); $i < $n; $i++) |
| 1687 | 1777 | { |
@@ -1696,19 +1786,22 @@ discard block |
||
| 1696 | 1786 | continue; |
| 1697 | 1787 | } |
| 1698 | 1788 | |
| 1699 | - if (trim($settingsArray[$i]) == '?' . '>') |
|
| 1700 | - $settingsArray[$i] = ''; |
|
| 1789 | + if (trim($settingsArray[$i]) == '?' . '>') { |
|
| 1790 | + $settingsArray[$i] = ''; |
|
| 1791 | + } |
|
| 1701 | 1792 | |
| 1702 | 1793 | // Don't trim or bother with it if it's not a variable. |
| 1703 | - if (substr($settingsArray[$i], 0, 1) != '$') |
|
| 1704 | - continue; |
|
| 1794 | + if (substr($settingsArray[$i], 0, 1) != '$') { |
|
| 1795 | + continue; |
|
| 1796 | + } |
|
| 1705 | 1797 | |
| 1706 | 1798 | $settingsArray[$i] = rtrim($settingsArray[$i]) . "\n"; |
| 1707 | 1799 | |
| 1708 | - foreach ($vars as $var => $val) |
|
| 1709 | - if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0) |
|
| 1800 | + foreach ($vars as $var => $val) { |
|
| 1801 | + if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0) |
|
| 1710 | 1802 | { |
| 1711 | 1803 | $comment = strstr($settingsArray[$i], '#'); |
| 1804 | + } |
|
| 1712 | 1805 | $settingsArray[$i] = '$' . $var . ' = \'' . $val . '\';' . ($comment != '' ? "\t\t" . $comment : "\n"); |
| 1713 | 1806 | unset($vars[$var]); |
| 1714 | 1807 | } |
@@ -1718,36 +1811,41 @@ discard block |
||
| 1718 | 1811 | if (!empty($vars)) |
| 1719 | 1812 | { |
| 1720 | 1813 | $settingsArray[$i++] = ''; |
| 1721 | - foreach ($vars as $var => $val) |
|
| 1722 | - $settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n"; |
|
| 1814 | + foreach ($vars as $var => $val) { |
|
| 1815 | + $settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n"; |
|
| 1816 | + } |
|
| 1723 | 1817 | } |
| 1724 | 1818 | |
| 1725 | 1819 | // Blank out the file - done to fix a oddity with some servers. |
| 1726 | 1820 | $fp = @fopen(dirname(__FILE__) . '/Settings.php', 'w'); |
| 1727 | - if (!$fp) |
|
| 1728 | - return false; |
|
| 1821 | + if (!$fp) { |
|
| 1822 | + return false; |
|
| 1823 | + } |
|
| 1729 | 1824 | fclose($fp); |
| 1730 | 1825 | |
| 1731 | 1826 | $fp = fopen(dirname(__FILE__) . '/Settings.php', 'r+'); |
| 1732 | 1827 | |
| 1733 | 1828 | // Gotta have one of these ;) |
| 1734 | - if (trim($settingsArray[0]) != '<?php') |
|
| 1735 | - fwrite($fp, "<?php\n"); |
|
| 1829 | + if (trim($settingsArray[0]) != '<?php') { |
|
| 1830 | + fwrite($fp, "<?php\n"); |
|
| 1831 | + } |
|
| 1736 | 1832 | |
| 1737 | 1833 | $lines = count($settingsArray); |
| 1738 | 1834 | for ($i = 0; $i < $lines - 1; $i++) |
| 1739 | 1835 | { |
| 1740 | 1836 | // Don't just write a bunch of blank lines. |
| 1741 | - if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '') |
|
| 1742 | - fwrite($fp, strtr($settingsArray[$i], "\r", '')); |
|
| 1837 | + if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '') { |
|
| 1838 | + fwrite($fp, strtr($settingsArray[$i], "\r", '')); |
|
| 1839 | + } |
|
| 1743 | 1840 | } |
| 1744 | 1841 | fwrite($fp, $settingsArray[$i] . '?' . '>'); |
| 1745 | 1842 | fclose($fp); |
| 1746 | 1843 | |
| 1747 | 1844 | // Even though on normal installations the filemtime should prevent this being used by the installer incorrectly |
| 1748 | 1845 | // it seems that there are times it might not. So let's MAKE it dump the cache. |
| 1749 | - if (function_exists('opcache_invalidate')) |
|
| 1750 | - opcache_invalidate(dirname(__FILE__) . '/Settings.php', true); |
|
| 1846 | + if (function_exists('opcache_invalidate')) { |
|
| 1847 | + opcache_invalidate(dirname(__FILE__) . '/Settings.php', true); |
|
| 1848 | + } |
|
| 1751 | 1849 | |
| 1752 | 1850 | return true; |
| 1753 | 1851 | } |
@@ -1772,9 +1870,9 @@ discard block |
||
| 1772 | 1870 | SecFilterScanPOST Off |
| 1773 | 1871 | </IfModule>'; |
| 1774 | 1872 | |
| 1775 | - if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules())) |
|
| 1776 | - return true; |
|
| 1777 | - elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess')) |
|
| 1873 | + if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules())) { |
|
| 1874 | + return true; |
|
| 1875 | + } elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess')) |
|
| 1778 | 1876 | { |
| 1779 | 1877 | $current_htaccess = implode('', file(dirname(__FILE__) . '/.htaccess')); |
| 1780 | 1878 | |
@@ -1786,29 +1884,28 @@ discard block |
||
| 1786 | 1884 | fwrite($ht_handle, $htaccess_addition); |
| 1787 | 1885 | fclose($ht_handle); |
| 1788 | 1886 | return true; |
| 1887 | + } else { |
|
| 1888 | + return false; |
|
| 1789 | 1889 | } |
| 1790 | - else |
|
| 1791 | - return false; |
|
| 1890 | + } else { |
|
| 1891 | + return true; |
|
| 1792 | 1892 | } |
| 1793 | - else |
|
| 1794 | - return true; |
|
| 1795 | - } |
|
| 1796 | - elseif (file_exists(dirname(__FILE__) . '/.htaccess')) |
|
| 1797 | - return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false; |
|
| 1798 | - elseif (is_writable(dirname(__FILE__))) |
|
| 1893 | + } elseif (file_exists(dirname(__FILE__) . '/.htaccess')) { |
|
| 1894 | + return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false; |
|
| 1895 | + } elseif (is_writable(dirname(__FILE__))) |
|
| 1799 | 1896 | { |
| 1800 | 1897 | if ($ht_handle = fopen(dirname(__FILE__) . '/.htaccess', 'w')) |
| 1801 | 1898 | { |
| 1802 | 1899 | fwrite($ht_handle, $htaccess_addition); |
| 1803 | 1900 | fclose($ht_handle); |
| 1804 | 1901 | return true; |
| 1902 | + } else { |
|
| 1903 | + return false; |
|
| 1805 | 1904 | } |
| 1806 | - else |
|
| 1905 | + } else { |
|
| 1807 | 1906 | return false; |
| 1808 | 1907 | } |
| 1809 | - else |
|
| 1810 | - return false; |
|
| 1811 | -} |
|
| 1908 | + } |
|
| 1812 | 1909 | |
| 1813 | 1910 | function template_install_above() |
| 1814 | 1911 | { |
@@ -1846,9 +1943,10 @@ discard block |
||
| 1846 | 1943 | <label for="installer_language">', $txt['installer_language'], ':</label> |
| 1847 | 1944 | <select id="installer_language" name="lang_file" onchange="location.href = \'', $installurl, '?lang_file=\' + this.options[this.selectedIndex].value;">'; |
| 1848 | 1945 | |
| 1849 | - foreach ($incontext['detected_languages'] as $lang => $name) |
|
| 1850 | - echo ' |
|
| 1946 | + foreach ($incontext['detected_languages'] as $lang => $name) { |
|
| 1947 | + echo ' |
|
| 1851 | 1948 | <option', isset($_SESSION['installer_temp_lang']) && $_SESSION['installer_temp_lang'] == $lang ? ' selected' : '', ' value="', $lang, '">', $name, '</option>'; |
| 1949 | + } |
|
| 1852 | 1950 | |
| 1853 | 1951 | echo ' |
| 1854 | 1952 | </select> |
@@ -1868,9 +1966,10 @@ discard block |
||
| 1868 | 1966 | <h2>', $txt['upgrade_progress'], '</h2> |
| 1869 | 1967 | <ul>'; |
| 1870 | 1968 | |
| 1871 | - foreach ($incontext['steps'] as $num => $step) |
|
| 1872 | - echo ' |
|
| 1969 | + foreach ($incontext['steps'] as $num => $step) { |
|
| 1970 | + echo ' |
|
| 1873 | 1971 | <li class="', $num < $incontext['current_step'] ? 'stepdone' : ($num == $incontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>'; |
| 1972 | + } |
|
| 1874 | 1973 | |
| 1875 | 1974 | echo ' |
| 1876 | 1975 | </ul> |
@@ -1895,20 +1994,23 @@ discard block |
||
| 1895 | 1994 | echo ' |
| 1896 | 1995 | <div>'; |
| 1897 | 1996 | |
| 1898 | - if (!empty($incontext['continue'])) |
|
| 1899 | - echo ' |
|
| 1997 | + if (!empty($incontext['continue'])) { |
|
| 1998 | + echo ' |
|
| 1900 | 1999 | <input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '" onclick="return submitThisOnce(this);" class="button_submit" />'; |
| 1901 | - if (!empty($incontext['skip'])) |
|
| 1902 | - echo ' |
|
| 2000 | + } |
|
| 2001 | + if (!empty($incontext['skip'])) { |
|
| 2002 | + echo ' |
|
| 1903 | 2003 | <input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="return submitThisOnce(this);" class="button_submit" />'; |
| 2004 | + } |
|
| 1904 | 2005 | echo ' |
| 1905 | 2006 | </div>'; |
| 1906 | 2007 | } |
| 1907 | 2008 | |
| 1908 | 2009 | // Show the closing form tag and other data only if not in the last step |
| 1909 | - if (count($incontext['steps']) - 1 !== (int) $incontext['current_step']) |
|
| 1910 | - echo ' |
|
| 2010 | + if (count($incontext['steps']) - 1 !== (int) $incontext['current_step']) { |
|
| 2011 | + echo ' |
|
| 1911 | 2012 | </form>'; |
| 2013 | + } |
|
| 1912 | 2014 | |
| 1913 | 2015 | echo ' |
| 1914 | 2016 | </div> |
@@ -1943,13 +2045,15 @@ discard block |
||
| 1943 | 2045 | </div>'; |
| 1944 | 2046 | |
| 1945 | 2047 | // Show the warnings, or not. |
| 1946 | - if (template_warning_divs()) |
|
| 1947 | - echo ' |
|
| 2048 | + if (template_warning_divs()) { |
|
| 2049 | + echo ' |
|
| 1948 | 2050 | <h3>', $txt['install_all_lovely'], '</h3>'; |
| 2051 | + } |
|
| 1949 | 2052 | |
| 1950 | 2053 | // Say we want the continue button! |
| 1951 | - if (empty($incontext['error'])) |
|
| 1952 | - $incontext['continue'] = 1; |
|
| 2054 | + if (empty($incontext['error'])) { |
|
| 2055 | + $incontext['continue'] = 1; |
|
| 2056 | + } |
|
| 1953 | 2057 | |
| 1954 | 2058 | // For the latest version stuff. |
| 1955 | 2059 | echo ' |
@@ -1983,8 +2087,8 @@ discard block |
||
| 1983 | 2087 | global $txt, $incontext; |
| 1984 | 2088 | |
| 1985 | 2089 | // Errors are very serious.. |
| 1986 | - if (!empty($incontext['error'])) |
|
| 1987 | - echo ' |
|
| 2090 | + if (!empty($incontext['error'])) { |
|
| 2091 | + echo ' |
|
| 1988 | 2092 | <div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;"> |
| 1989 | 2093 | <div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div> |
| 1990 | 2094 | <strong style="text-decoration: underline;">', $txt['upgrade_critical_error'], '</strong><br> |
@@ -1992,9 +2096,10 @@ discard block |
||
| 1992 | 2096 | ', $incontext['error'], ' |
| 1993 | 2097 | </div> |
| 1994 | 2098 | </div>'; |
| 2099 | + } |
|
| 1995 | 2100 | // A warning message? |
| 1996 | - elseif (!empty($incontext['warning'])) |
|
| 1997 | - echo ' |
|
| 2101 | + elseif (!empty($incontext['warning'])) { |
|
| 2102 | + echo ' |
|
| 1998 | 2103 | <div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;"> |
| 1999 | 2104 | <div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div> |
| 2000 | 2105 | <strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br> |
@@ -2002,6 +2107,7 @@ discard block |
||
| 2002 | 2107 | ', $incontext['warning'], ' |
| 2003 | 2108 | </div> |
| 2004 | 2109 | </div>'; |
| 2110 | + } |
|
| 2005 | 2111 | |
| 2006 | 2112 | return empty($incontext['error']) && empty($incontext['warning']); |
| 2007 | 2113 | } |
@@ -2017,27 +2123,30 @@ discard block |
||
| 2017 | 2123 | <li>', $incontext['failed_files']), '</li> |
| 2018 | 2124 | </ul>'; |
| 2019 | 2125 | |
| 2020 | - if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux') |
|
| 2021 | - echo ' |
|
| 2126 | + if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux') { |
|
| 2127 | + echo ' |
|
| 2022 | 2128 | <hr> |
| 2023 | 2129 | <p>', $txt['chmod_linux_info'], '</p> |
| 2024 | 2130 | <tt># chmod a+w ', implode(' ' . $incontext['detected_path'] . '/', $incontext['failed_files']), '</tt>'; |
| 2131 | + } |
|
| 2025 | 2132 | |
| 2026 | 2133 | // This is serious! |
| 2027 | - if (!template_warning_divs()) |
|
| 2028 | - return; |
|
| 2134 | + if (!template_warning_divs()) { |
|
| 2135 | + return; |
|
| 2136 | + } |
|
| 2029 | 2137 | |
| 2030 | 2138 | echo ' |
| 2031 | 2139 | <hr> |
| 2032 | 2140 | <p>', $txt['ftp_setup_info'], '</p>'; |
| 2033 | 2141 | |
| 2034 | - if (!empty($incontext['ftp_errors'])) |
|
| 2035 | - echo ' |
|
| 2142 | + if (!empty($incontext['ftp_errors'])) { |
|
| 2143 | + echo ' |
|
| 2036 | 2144 | <div class="error_message"> |
| 2037 | 2145 | ', $txt['error_ftp_no_connect'], '<br><br> |
| 2038 | 2146 | <code>', implode('<br>', $incontext['ftp_errors']), '</code> |
| 2039 | 2147 | </div> |
| 2040 | 2148 | <br>'; |
| 2149 | + } |
|
| 2041 | 2150 | |
| 2042 | 2151 | echo ' |
| 2043 | 2152 | <form action="', $incontext['form_url'], '" method="post"> |
@@ -2097,17 +2206,17 @@ discard block |
||
| 2097 | 2206 | <td> |
| 2098 | 2207 | <select name="db_type" id="db_type_input" onchange="toggleDBInput();">'; |
| 2099 | 2208 | |
| 2100 | - foreach ($incontext['supported_databases'] as $key => $db) |
|
| 2101 | - echo ' |
|
| 2209 | + foreach ($incontext['supported_databases'] as $key => $db) { |
|
| 2210 | + echo ' |
|
| 2102 | 2211 | <option value="', $key, '"', isset($_POST['db_type']) && $_POST['db_type'] == $key ? ' selected' : '', '>', $db['name'], '</option>'; |
| 2212 | + } |
|
| 2103 | 2213 | |
| 2104 | 2214 | echo ' |
| 2105 | 2215 | </select> |
| 2106 | 2216 | <div class="smalltext block">', $txt['db_settings_type_info'], '</div> |
| 2107 | 2217 | </td> |
| 2108 | 2218 | </tr>'; |
| 2109 | - } |
|
| 2110 | - else |
|
| 2219 | + } else |
|
| 2111 | 2220 | { |
| 2112 | 2221 | echo ' |
| 2113 | 2222 | <tr style="display: none;"> |
@@ -2299,9 +2408,10 @@ discard block |
||
| 2299 | 2408 | <div style="color: red;">', $txt['error_db_queries'], '</div> |
| 2300 | 2409 | <ul>'; |
| 2301 | 2410 | |
| 2302 | - foreach ($incontext['failures'] as $line => $fail) |
|
| 2303 | - echo ' |
|
| 2411 | + foreach ($incontext['failures'] as $line => $fail) { |
|
| 2412 | + echo ' |
|
| 2304 | 2413 | <li><strong>', $txt['error_db_queries_line'], $line + 1, ':</strong> ', nl2br(htmlspecialchars($fail)), '</li>'; |
| 2414 | + } |
|
| 2305 | 2415 | |
| 2306 | 2416 | echo ' |
| 2307 | 2417 | </ul>'; |
@@ -2362,15 +2472,16 @@ discard block |
||
| 2362 | 2472 | </tr> |
| 2363 | 2473 | </table>'; |
| 2364 | 2474 | |
| 2365 | - if ($incontext['require_db_confirm']) |
|
| 2366 | - echo ' |
|
| 2475 | + if ($incontext['require_db_confirm']) { |
|
| 2476 | + echo ' |
|
| 2367 | 2477 | <h2>', $txt['user_settings_database'], '</h2> |
| 2368 | 2478 | <p>', $txt['user_settings_database_info'], '</p> |
| 2369 | 2479 | |
| 2370 | 2480 | <div style="margin-bottom: 2ex; padding-', $txt['lang_rtl'] == false ? 'left' : 'right', ': 50px;"> |
| 2371 | 2481 | <input type="password" name="password3" size="30" class="input_password" /> |
| 2372 | 2482 | </div>'; |
| 2373 | -} |
|
| 2483 | + } |
|
| 2484 | + } |
|
| 2374 | 2485 | |
| 2375 | 2486 | // Tell them it's done, and to delete. |
| 2376 | 2487 | function template_delete_install() |
@@ -2383,14 +2494,15 @@ discard block |
||
| 2383 | 2494 | template_warning_divs(); |
| 2384 | 2495 | |
| 2385 | 2496 | // Install directory still writable? |
| 2386 | - if ($incontext['dir_still_writable']) |
|
| 2387 | - echo ' |
|
| 2497 | + if ($incontext['dir_still_writable']) { |
|
| 2498 | + echo ' |
|
| 2388 | 2499 | <em>', $txt['still_writable'], '</em><br> |
| 2389 | 2500 | <br>'; |
| 2501 | + } |
|
| 2390 | 2502 | |
| 2391 | 2503 | // Don't show the box if it's like 99% sure it won't work :P. |
| 2392 | - if ($incontext['probably_delete_install']) |
|
| 2393 | - echo ' |
|
| 2504 | + if ($incontext['probably_delete_install']) { |
|
| 2505 | + echo ' |
|
| 2394 | 2506 | <div style="margin: 1ex; font-weight: bold;"> |
| 2395 | 2507 | <label for="delete_self"><input type="checkbox" id="delete_self" onclick="doTheDelete();" class="input_check" /> ', $txt['delete_installer'], !isset($_SESSION['installer_temp_ftp']) ? ' ' . $txt['delete_installer_maybe'] : '', '</label> |
| 2396 | 2508 | </div> |
@@ -2406,6 +2518,7 @@ discard block |
||
| 2406 | 2518 | } |
| 2407 | 2519 | </script> |
| 2408 | 2520 | <br>'; |
| 2521 | + } |
|
| 2409 | 2522 | |
| 2410 | 2523 | echo ' |
| 2411 | 2524 | ', sprintf($txt['go_to_your_forum'], $boardurl . '/index.php'), '<br> |