@@ -207,6 +207,9 @@ discard block |
||
207 | 207 | // MD5 Encryption. |
208 | 208 | if (!function_exists('md5_hmac')) |
209 | 209 | { |
210 | + /** |
|
211 | + * @param string $key |
|
212 | + */ |
|
210 | 213 | function md5_hmac($data, $key) |
211 | 214 | { |
212 | 215 | if (strlen($key) > 64) |
@@ -441,6 +444,9 @@ discard block |
||
441 | 444 | } |
442 | 445 | |
443 | 446 | // Used to direct the user to another location. |
447 | +/** |
|
448 | + * @param string $location |
|
449 | + */ |
|
444 | 450 | function redirectLocation($location, $addForm = true) |
445 | 451 | { |
446 | 452 | global $upgradeurl, $upcontext, $command_line; |
@@ -2128,6 +2134,9 @@ discard block |
||
2128 | 2134 | return addslashes(preg_replace(array('~^\.([/\\\]|$)~', '~[/]+~', '~[\\\]+~', '~[/\\\]$~'), array($install_path . '$1', '/', '\\', ''), $path)); |
2129 | 2135 | } |
2130 | 2136 | |
2137 | +/** |
|
2138 | + * @param string $filename |
|
2139 | + */ |
|
2131 | 2140 | function parse_sql($filename) |
2132 | 2141 | { |
2133 | 2142 | global $db_prefix, $db_collation, $boarddir, $boardurl, $command_line, $file_steps, $step_progress, $custom_warning; |
@@ -2414,6 +2423,9 @@ discard block |
||
2414 | 2423 | return true; |
2415 | 2424 | } |
2416 | 2425 | |
2426 | +/** |
|
2427 | + * @param string $string |
|
2428 | + */ |
|
2417 | 2429 | function upgrade_query($string, $unbuffered = false) |
2418 | 2430 | { |
2419 | 2431 | global $db_connection, $db_server, $db_user, $db_passwd, $db_type, $command_line, $upcontext, $upgradeurl, $modSettings; |
@@ -3043,6 +3055,9 @@ discard block |
||
3043 | 3055 | $upcontext['current_step'] = 1; |
3044 | 3056 | } |
3045 | 3057 | |
3058 | +/** |
|
3059 | + * @param string $message |
|
3060 | + */ |
|
3046 | 3061 | function print_error($message, $fatal = false) |
3047 | 3062 | { |
3048 | 3063 | static $fp = null; |
@@ -3056,6 +3071,9 @@ discard block |
||
3056 | 3071 | exit; |
3057 | 3072 | } |
3058 | 3073 | |
3074 | +/** |
|
3075 | + * @param string $message |
|
3076 | + */ |
|
3059 | 3077 | function throw_error($message) |
3060 | 3078 | { |
3061 | 3079 | global $upcontext; |
@@ -426,11 +426,11 @@ discard block |
||
426 | 426 | |
427 | 427 | $totalTime = ''; |
428 | 428 | if ($hours > 0) |
429 | - $totalTime .= $hours . ' hour' . ($hours > 1 ? 's':'') . ' '; |
|
429 | + $totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' '; |
|
430 | 430 | if ($minutes > 0) |
431 | - $totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's':'') . ' '; |
|
431 | + $totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' '; |
|
432 | 432 | if ($seconds > 0) |
433 | - $totalTime .= $seconds . ' second' . ($seconds > 1 ? 's':'') . ' '; |
|
433 | + $totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' '; |
|
434 | 434 | |
435 | 435 | if (!empty($totalTime)) |
436 | 436 | echo "\n" . 'Upgrade completed in ' . $totalTime . "\n"; |
@@ -710,14 +710,14 @@ discard block |
||
710 | 710 | // Do we need to add this setting? |
711 | 711 | $need_settings_update = empty($modSettings['custom_avatar_dir']); |
712 | 712 | |
713 | - $custom_av_dir = !empty($modSettings['custom_avatar_dir']) ? $modSettings['custom_avatar_dir'] : $GLOBALS['boarddir'] .'/custom_avatar'; |
|
714 | - $custom_av_url = !empty($modSettings['custom_avatar_url']) ? $modSettings['custom_avatar_url'] : $boardurl .'/custom_avatar'; |
|
713 | + $custom_av_dir = !empty($modSettings['custom_avatar_dir']) ? $modSettings['custom_avatar_dir'] : $GLOBALS['boarddir'] . '/custom_avatar'; |
|
714 | + $custom_av_url = !empty($modSettings['custom_avatar_url']) ? $modSettings['custom_avatar_url'] : $boardurl . '/custom_avatar'; |
|
715 | 715 | |
716 | 716 | // This little fellow has to cooperate... |
717 | 717 | quickFileWritable($custom_av_dir); |
718 | 718 | |
719 | 719 | // Are we good now? |
720 | - if(!is_writable($custom_av_dir)) |
|
720 | + if (!is_writable($custom_av_dir)) |
|
721 | 721 | return throw_error(sprintf('The directory: %1$s has to be writable to continue the upgrade. Please make sure permissions are correctly set to allow this.', $custom_av_dir)); |
722 | 722 | elseif ($need_settings_update) |
723 | 723 | { |
@@ -913,7 +913,7 @@ discard block |
||
913 | 913 | $upcontext['user']['id'] = 1; |
914 | 914 | $upcontext['user']['name'] = 'Administrator'; |
915 | 915 | } |
916 | - $upcontext['user']['pass'] = mt_rand(0,60000); |
|
916 | + $upcontext['user']['pass'] = mt_rand(0, 60000); |
|
917 | 917 | // This basically is used to match the GET variables to Settings.php. |
918 | 918 | $upcontext['upgrade_status']['pass'] = $upcontext['user']['pass']; |
919 | 919 | |
@@ -1124,7 +1124,7 @@ discard block |
||
1124 | 1124 | if ($db_port != ini_get('mysql' . ($db_type == 'mysqli' || !empty($_POST['convertMysql']) ? 'i' : '') . '.default_port')) |
1125 | 1125 | $changes['db_port'] = (int) $db_port; |
1126 | 1126 | } |
1127 | - elseif(!empty($db_port)) |
|
1127 | + elseif (!empty($db_port)) |
|
1128 | 1128 | { |
1129 | 1129 | // If db_port is set and is the same as the default, set it to '' |
1130 | 1130 | if ($db_type == 'mysql' || $db_type == 'mysqli') |
@@ -1728,7 +1728,7 @@ discard block |
||
1728 | 1728 | } |
1729 | 1729 | |
1730 | 1730 | if (!empty($deletes)) |
1731 | - upgrade_query( ' |
|
1731 | + upgrade_query(' |
|
1732 | 1732 | UPDATE ' . $db_prefix . 'log_packages |
1733 | 1733 | SET install_state = 0 |
1734 | 1734 | WHERE id_install IN (' . implode(',', $deletes) . ')'); |
@@ -1807,7 +1807,7 @@ discard block |
||
1807 | 1807 | else |
1808 | 1808 | { |
1809 | 1809 | require_once($sourcedir . '/ScheduledTasks.php'); |
1810 | - $forum_version = SMF_VERSION; // The variable is usually defined in index.php so lets just use the constant to do it for us. |
|
1810 | + $forum_version = SMF_VERSION; // The variable is usually defined in index.php so lets just use the constant to do it for us. |
|
1811 | 1811 | scheduled_fetchSMfiles(); // Now go get those files! |
1812 | 1812 | } |
1813 | 1813 | |
@@ -2625,7 +2625,7 @@ discard block |
||
2625 | 2625 | } |
2626 | 2626 | elseif ($change['type'] === 'index') |
2627 | 2627 | { |
2628 | - $request = upgrade_query( ' |
|
2628 | + $request = upgrade_query(' |
|
2629 | 2629 | SHOW INDEX |
2630 | 2630 | FROM ' . $db_prefix . $change['table']); |
2631 | 2631 | if ($request !== false) |
@@ -3272,7 +3272,7 @@ discard block |
||
3272 | 3272 | // Try 755 and 775 first since 777 doesn't always work and could be a risk... |
3273 | 3273 | $chmod_values = array(0755, 0775, 0777); |
3274 | 3274 | |
3275 | - foreach($chmod_values as $val) |
|
3275 | + foreach ($chmod_values as $val) |
|
3276 | 3276 | { |
3277 | 3277 | // If it's writable, break out of the loop |
3278 | 3278 | if (is_writable($file)) |
@@ -3482,95 +3482,95 @@ discard block |
||
3482 | 3482 | // Translation table for the character sets not native for MySQL. |
3483 | 3483 | $translation_tables = array( |
3484 | 3484 | 'windows-1255' => array( |
3485 | - '0x81' => '\'\'', '0x8A' => '\'\'', '0x8C' => '\'\'', |
|
3486 | - '0x8D' => '\'\'', '0x8E' => '\'\'', '0x8F' => '\'\'', |
|
3487 | - '0x90' => '\'\'', '0x9A' => '\'\'', '0x9C' => '\'\'', |
|
3488 | - '0x9D' => '\'\'', '0x9E' => '\'\'', '0x9F' => '\'\'', |
|
3489 | - '0xCA' => '\'\'', '0xD9' => '\'\'', '0xDA' => '\'\'', |
|
3490 | - '0xDB' => '\'\'', '0xDC' => '\'\'', '0xDD' => '\'\'', |
|
3491 | - '0xDE' => '\'\'', '0xDF' => '\'\'', '0xFB' => '\'\'', |
|
3492 | - '0xFC' => '\'\'', '0xFF' => '\'\'', '0xC2' => '0xFF', |
|
3493 | - '0x80' => '0xFC', '0xE2' => '0xFB', '0xA0' => '0xC2A0', |
|
3494 | - '0xA1' => '0xC2A1', '0xA2' => '0xC2A2', '0xA3' => '0xC2A3', |
|
3495 | - '0xA5' => '0xC2A5', '0xA6' => '0xC2A6', '0xA7' => '0xC2A7', |
|
3496 | - '0xA8' => '0xC2A8', '0xA9' => '0xC2A9', '0xAB' => '0xC2AB', |
|
3497 | - '0xAC' => '0xC2AC', '0xAD' => '0xC2AD', '0xAE' => '0xC2AE', |
|
3498 | - '0xAF' => '0xC2AF', '0xB0' => '0xC2B0', '0xB1' => '0xC2B1', |
|
3499 | - '0xB2' => '0xC2B2', '0xB3' => '0xC2B3', '0xB4' => '0xC2B4', |
|
3500 | - '0xB5' => '0xC2B5', '0xB6' => '0xC2B6', '0xB7' => '0xC2B7', |
|
3501 | - '0xB8' => '0xC2B8', '0xB9' => '0xC2B9', '0xBB' => '0xC2BB', |
|
3502 | - '0xBC' => '0xC2BC', '0xBD' => '0xC2BD', '0xBE' => '0xC2BE', |
|
3503 | - '0xBF' => '0xC2BF', '0xD7' => '0xD7B3', '0xD1' => '0xD781', |
|
3504 | - '0xD4' => '0xD7B0', '0xD5' => '0xD7B1', '0xD6' => '0xD7B2', |
|
3505 | - '0xE0' => '0xD790', '0xEA' => '0xD79A', '0xEC' => '0xD79C', |
|
3506 | - '0xED' => '0xD79D', '0xEE' => '0xD79E', '0xEF' => '0xD79F', |
|
3507 | - '0xF0' => '0xD7A0', '0xF1' => '0xD7A1', '0xF2' => '0xD7A2', |
|
3508 | - '0xF3' => '0xD7A3', '0xF5' => '0xD7A5', '0xF6' => '0xD7A6', |
|
3509 | - '0xF7' => '0xD7A7', '0xF8' => '0xD7A8', '0xF9' => '0xD7A9', |
|
3510 | - '0x82' => '0xE2809A', '0x84' => '0xE2809E', '0x85' => '0xE280A6', |
|
3511 | - '0x86' => '0xE280A0', '0x87' => '0xE280A1', '0x89' => '0xE280B0', |
|
3512 | - '0x8B' => '0xE280B9', '0x93' => '0xE2809C', '0x94' => '0xE2809D', |
|
3513 | - '0x95' => '0xE280A2', '0x97' => '0xE28094', '0x99' => '0xE284A2', |
|
3514 | - '0xC0' => '0xD6B0', '0xC1' => '0xD6B1', '0xC3' => '0xD6B3', |
|
3515 | - '0xC4' => '0xD6B4', '0xC5' => '0xD6B5', '0xC6' => '0xD6B6', |
|
3516 | - '0xC7' => '0xD6B7', '0xC8' => '0xD6B8', '0xC9' => '0xD6B9', |
|
3517 | - '0xCB' => '0xD6BB', '0xCC' => '0xD6BC', '0xCD' => '0xD6BD', |
|
3518 | - '0xCE' => '0xD6BE', '0xCF' => '0xD6BF', '0xD0' => '0xD780', |
|
3519 | - '0xD2' => '0xD782', '0xE3' => '0xD793', '0xE4' => '0xD794', |
|
3520 | - '0xE5' => '0xD795', '0xE7' => '0xD797', '0xE9' => '0xD799', |
|
3521 | - '0xFD' => '0xE2808E', '0xFE' => '0xE2808F', '0x92' => '0xE28099', |
|
3522 | - '0x83' => '0xC692', '0xD3' => '0xD783', '0x88' => '0xCB86', |
|
3523 | - '0x98' => '0xCB9C', '0x91' => '0xE28098', '0x96' => '0xE28093', |
|
3524 | - '0xBA' => '0xC3B7', '0x9B' => '0xE280BA', '0xAA' => '0xC397', |
|
3525 | - '0xA4' => '0xE282AA', '0xE1' => '0xD791', '0xE6' => '0xD796', |
|
3526 | - '0xE8' => '0xD798', '0xEB' => '0xD79B', '0xF4' => '0xD7A4', |
|
3527 | - '0xFA' => '0xD7AA', '0xFF' => '0xD6B2', '0xFC' => '0xE282AC', |
|
3485 | + '0x81' => '\'\'', '0x8A' => '\'\'', '0x8C' => '\'\'', |
|
3486 | + '0x8D' => '\'\'', '0x8E' => '\'\'', '0x8F' => '\'\'', |
|
3487 | + '0x90' => '\'\'', '0x9A' => '\'\'', '0x9C' => '\'\'', |
|
3488 | + '0x9D' => '\'\'', '0x9E' => '\'\'', '0x9F' => '\'\'', |
|
3489 | + '0xCA' => '\'\'', '0xD9' => '\'\'', '0xDA' => '\'\'', |
|
3490 | + '0xDB' => '\'\'', '0xDC' => '\'\'', '0xDD' => '\'\'', |
|
3491 | + '0xDE' => '\'\'', '0xDF' => '\'\'', '0xFB' => '\'\'', |
|
3492 | + '0xFC' => '\'\'', '0xFF' => '\'\'', '0xC2' => '0xFF', |
|
3493 | + '0x80' => '0xFC', '0xE2' => '0xFB', '0xA0' => '0xC2A0', |
|
3494 | + '0xA1' => '0xC2A1', '0xA2' => '0xC2A2', '0xA3' => '0xC2A3', |
|
3495 | + '0xA5' => '0xC2A5', '0xA6' => '0xC2A6', '0xA7' => '0xC2A7', |
|
3496 | + '0xA8' => '0xC2A8', '0xA9' => '0xC2A9', '0xAB' => '0xC2AB', |
|
3497 | + '0xAC' => '0xC2AC', '0xAD' => '0xC2AD', '0xAE' => '0xC2AE', |
|
3498 | + '0xAF' => '0xC2AF', '0xB0' => '0xC2B0', '0xB1' => '0xC2B1', |
|
3499 | + '0xB2' => '0xC2B2', '0xB3' => '0xC2B3', '0xB4' => '0xC2B4', |
|
3500 | + '0xB5' => '0xC2B5', '0xB6' => '0xC2B6', '0xB7' => '0xC2B7', |
|
3501 | + '0xB8' => '0xC2B8', '0xB9' => '0xC2B9', '0xBB' => '0xC2BB', |
|
3502 | + '0xBC' => '0xC2BC', '0xBD' => '0xC2BD', '0xBE' => '0xC2BE', |
|
3503 | + '0xBF' => '0xC2BF', '0xD7' => '0xD7B3', '0xD1' => '0xD781', |
|
3504 | + '0xD4' => '0xD7B0', '0xD5' => '0xD7B1', '0xD6' => '0xD7B2', |
|
3505 | + '0xE0' => '0xD790', '0xEA' => '0xD79A', '0xEC' => '0xD79C', |
|
3506 | + '0xED' => '0xD79D', '0xEE' => '0xD79E', '0xEF' => '0xD79F', |
|
3507 | + '0xF0' => '0xD7A0', '0xF1' => '0xD7A1', '0xF2' => '0xD7A2', |
|
3508 | + '0xF3' => '0xD7A3', '0xF5' => '0xD7A5', '0xF6' => '0xD7A6', |
|
3509 | + '0xF7' => '0xD7A7', '0xF8' => '0xD7A8', '0xF9' => '0xD7A9', |
|
3510 | + '0x82' => '0xE2809A', '0x84' => '0xE2809E', '0x85' => '0xE280A6', |
|
3511 | + '0x86' => '0xE280A0', '0x87' => '0xE280A1', '0x89' => '0xE280B0', |
|
3512 | + '0x8B' => '0xE280B9', '0x93' => '0xE2809C', '0x94' => '0xE2809D', |
|
3513 | + '0x95' => '0xE280A2', '0x97' => '0xE28094', '0x99' => '0xE284A2', |
|
3514 | + '0xC0' => '0xD6B0', '0xC1' => '0xD6B1', '0xC3' => '0xD6B3', |
|
3515 | + '0xC4' => '0xD6B4', '0xC5' => '0xD6B5', '0xC6' => '0xD6B6', |
|
3516 | + '0xC7' => '0xD6B7', '0xC8' => '0xD6B8', '0xC9' => '0xD6B9', |
|
3517 | + '0xCB' => '0xD6BB', '0xCC' => '0xD6BC', '0xCD' => '0xD6BD', |
|
3518 | + '0xCE' => '0xD6BE', '0xCF' => '0xD6BF', '0xD0' => '0xD780', |
|
3519 | + '0xD2' => '0xD782', '0xE3' => '0xD793', '0xE4' => '0xD794', |
|
3520 | + '0xE5' => '0xD795', '0xE7' => '0xD797', '0xE9' => '0xD799', |
|
3521 | + '0xFD' => '0xE2808E', '0xFE' => '0xE2808F', '0x92' => '0xE28099', |
|
3522 | + '0x83' => '0xC692', '0xD3' => '0xD783', '0x88' => '0xCB86', |
|
3523 | + '0x98' => '0xCB9C', '0x91' => '0xE28098', '0x96' => '0xE28093', |
|
3524 | + '0xBA' => '0xC3B7', '0x9B' => '0xE280BA', '0xAA' => '0xC397', |
|
3525 | + '0xA4' => '0xE282AA', '0xE1' => '0xD791', '0xE6' => '0xD796', |
|
3526 | + '0xE8' => '0xD798', '0xEB' => '0xD79B', '0xF4' => '0xD7A4', |
|
3527 | + '0xFA' => '0xD7AA', '0xFF' => '0xD6B2', '0xFC' => '0xE282AC', |
|
3528 | 3528 | '0xFB' => '0xD792', |
3529 | 3529 | ), |
3530 | 3530 | 'windows-1253' => array( |
3531 | - '0x81' => '\'\'', '0x88' => '\'\'', '0x8A' => '\'\'', |
|
3532 | - '0x8C' => '\'\'', '0x8D' => '\'\'', '0x8E' => '\'\'', |
|
3533 | - '0x8F' => '\'\'', '0x90' => '\'\'', '0x98' => '\'\'', |
|
3534 | - '0x9A' => '\'\'', '0x9C' => '\'\'', '0x9D' => '\'\'', |
|
3535 | - '0x9E' => '\'\'', '0x9F' => '\'\'', '0xAA' => '\'\'', |
|
3536 | - '0xD2' => '\'\'', '0xFF' => '\'\'', '0xCE' => '0xCE9E', |
|
3537 | - '0xB8' => '0xCE88', '0xBA' => '0xCE8A', '0xBC' => '0xCE8C', |
|
3538 | - '0xBE' => '0xCE8E', '0xBF' => '0xCE8F', '0xC0' => '0xCE90', |
|
3539 | - '0xC8' => '0xCE98', '0xCA' => '0xCE9A', '0xCC' => '0xCE9C', |
|
3540 | - '0xCD' => '0xCE9D', '0xCF' => '0xCE9F', '0xDA' => '0xCEAA', |
|
3541 | - '0xE8' => '0xCEB8', '0xEA' => '0xCEBA', '0xEC' => '0xCEBC', |
|
3542 | - '0xEE' => '0xCEBE', '0xEF' => '0xCEBF', '0xC2' => '0xFF', |
|
3543 | - '0xBD' => '0xC2BD', '0xED' => '0xCEBD', '0xB2' => '0xC2B2', |
|
3544 | - '0xA0' => '0xC2A0', '0xA3' => '0xC2A3', '0xA4' => '0xC2A4', |
|
3545 | - '0xA5' => '0xC2A5', '0xA6' => '0xC2A6', '0xA7' => '0xC2A7', |
|
3546 | - '0xA8' => '0xC2A8', '0xA9' => '0xC2A9', '0xAB' => '0xC2AB', |
|
3547 | - '0xAC' => '0xC2AC', '0xAD' => '0xC2AD', '0xAE' => '0xC2AE', |
|
3548 | - '0xB0' => '0xC2B0', '0xB1' => '0xC2B1', '0xB3' => '0xC2B3', |
|
3549 | - '0xB5' => '0xC2B5', '0xB6' => '0xC2B6', '0xB7' => '0xC2B7', |
|
3550 | - '0xBB' => '0xC2BB', '0xE2' => '0xCEB2', '0x80' => '0xD2', |
|
3551 | - '0x82' => '0xE2809A', '0x84' => '0xE2809E', '0x85' => '0xE280A6', |
|
3552 | - '0x86' => '0xE280A0', '0xA1' => '0xCE85', '0xA2' => '0xCE86', |
|
3553 | - '0x87' => '0xE280A1', '0x89' => '0xE280B0', '0xB9' => '0xCE89', |
|
3554 | - '0x8B' => '0xE280B9', '0x91' => '0xE28098', '0x99' => '0xE284A2', |
|
3555 | - '0x92' => '0xE28099', '0x93' => '0xE2809C', '0x94' => '0xE2809D', |
|
3556 | - '0x95' => '0xE280A2', '0x96' => '0xE28093', '0x97' => '0xE28094', |
|
3557 | - '0x9B' => '0xE280BA', '0xAF' => '0xE28095', '0xB4' => '0xCE84', |
|
3558 | - '0xC1' => '0xCE91', '0xC3' => '0xCE93', '0xC4' => '0xCE94', |
|
3559 | - '0xC5' => '0xCE95', '0xC6' => '0xCE96', '0x83' => '0xC692', |
|
3560 | - '0xC7' => '0xCE97', '0xC9' => '0xCE99', '0xCB' => '0xCE9B', |
|
3561 | - '0xD0' => '0xCEA0', '0xD1' => '0xCEA1', '0xD3' => '0xCEA3', |
|
3562 | - '0xD4' => '0xCEA4', '0xD5' => '0xCEA5', '0xD6' => '0xCEA6', |
|
3563 | - '0xD7' => '0xCEA7', '0xD8' => '0xCEA8', '0xD9' => '0xCEA9', |
|
3564 | - '0xDB' => '0xCEAB', '0xDC' => '0xCEAC', '0xDD' => '0xCEAD', |
|
3565 | - '0xDE' => '0xCEAE', '0xDF' => '0xCEAF', '0xE0' => '0xCEB0', |
|
3566 | - '0xE1' => '0xCEB1', '0xE3' => '0xCEB3', '0xE4' => '0xCEB4', |
|
3567 | - '0xE5' => '0xCEB5', '0xE6' => '0xCEB6', '0xE7' => '0xCEB7', |
|
3568 | - '0xE9' => '0xCEB9', '0xEB' => '0xCEBB', '0xF0' => '0xCF80', |
|
3569 | - '0xF1' => '0xCF81', '0xF2' => '0xCF82', '0xF3' => '0xCF83', |
|
3570 | - '0xF4' => '0xCF84', '0xF5' => '0xCF85', '0xF6' => '0xCF86', |
|
3571 | - '0xF7' => '0xCF87', '0xF8' => '0xCF88', '0xF9' => '0xCF89', |
|
3572 | - '0xFA' => '0xCF8A', '0xFB' => '0xCF8B', '0xFC' => '0xCF8C', |
|
3573 | - '0xFD' => '0xCF8D', '0xFE' => '0xCF8E', '0xFF' => '0xCE92', |
|
3531 | + '0x81' => '\'\'', '0x88' => '\'\'', '0x8A' => '\'\'', |
|
3532 | + '0x8C' => '\'\'', '0x8D' => '\'\'', '0x8E' => '\'\'', |
|
3533 | + '0x8F' => '\'\'', '0x90' => '\'\'', '0x98' => '\'\'', |
|
3534 | + '0x9A' => '\'\'', '0x9C' => '\'\'', '0x9D' => '\'\'', |
|
3535 | + '0x9E' => '\'\'', '0x9F' => '\'\'', '0xAA' => '\'\'', |
|
3536 | + '0xD2' => '\'\'', '0xFF' => '\'\'', '0xCE' => '0xCE9E', |
|
3537 | + '0xB8' => '0xCE88', '0xBA' => '0xCE8A', '0xBC' => '0xCE8C', |
|
3538 | + '0xBE' => '0xCE8E', '0xBF' => '0xCE8F', '0xC0' => '0xCE90', |
|
3539 | + '0xC8' => '0xCE98', '0xCA' => '0xCE9A', '0xCC' => '0xCE9C', |
|
3540 | + '0xCD' => '0xCE9D', '0xCF' => '0xCE9F', '0xDA' => '0xCEAA', |
|
3541 | + '0xE8' => '0xCEB8', '0xEA' => '0xCEBA', '0xEC' => '0xCEBC', |
|
3542 | + '0xEE' => '0xCEBE', '0xEF' => '0xCEBF', '0xC2' => '0xFF', |
|
3543 | + '0xBD' => '0xC2BD', '0xED' => '0xCEBD', '0xB2' => '0xC2B2', |
|
3544 | + '0xA0' => '0xC2A0', '0xA3' => '0xC2A3', '0xA4' => '0xC2A4', |
|
3545 | + '0xA5' => '0xC2A5', '0xA6' => '0xC2A6', '0xA7' => '0xC2A7', |
|
3546 | + '0xA8' => '0xC2A8', '0xA9' => '0xC2A9', '0xAB' => '0xC2AB', |
|
3547 | + '0xAC' => '0xC2AC', '0xAD' => '0xC2AD', '0xAE' => '0xC2AE', |
|
3548 | + '0xB0' => '0xC2B0', '0xB1' => '0xC2B1', '0xB3' => '0xC2B3', |
|
3549 | + '0xB5' => '0xC2B5', '0xB6' => '0xC2B6', '0xB7' => '0xC2B7', |
|
3550 | + '0xBB' => '0xC2BB', '0xE2' => '0xCEB2', '0x80' => '0xD2', |
|
3551 | + '0x82' => '0xE2809A', '0x84' => '0xE2809E', '0x85' => '0xE280A6', |
|
3552 | + '0x86' => '0xE280A0', '0xA1' => '0xCE85', '0xA2' => '0xCE86', |
|
3553 | + '0x87' => '0xE280A1', '0x89' => '0xE280B0', '0xB9' => '0xCE89', |
|
3554 | + '0x8B' => '0xE280B9', '0x91' => '0xE28098', '0x99' => '0xE284A2', |
|
3555 | + '0x92' => '0xE28099', '0x93' => '0xE2809C', '0x94' => '0xE2809D', |
|
3556 | + '0x95' => '0xE280A2', '0x96' => '0xE28093', '0x97' => '0xE28094', |
|
3557 | + '0x9B' => '0xE280BA', '0xAF' => '0xE28095', '0xB4' => '0xCE84', |
|
3558 | + '0xC1' => '0xCE91', '0xC3' => '0xCE93', '0xC4' => '0xCE94', |
|
3559 | + '0xC5' => '0xCE95', '0xC6' => '0xCE96', '0x83' => '0xC692', |
|
3560 | + '0xC7' => '0xCE97', '0xC9' => '0xCE99', '0xCB' => '0xCE9B', |
|
3561 | + '0xD0' => '0xCEA0', '0xD1' => '0xCEA1', '0xD3' => '0xCEA3', |
|
3562 | + '0xD4' => '0xCEA4', '0xD5' => '0xCEA5', '0xD6' => '0xCEA6', |
|
3563 | + '0xD7' => '0xCEA7', '0xD8' => '0xCEA8', '0xD9' => '0xCEA9', |
|
3564 | + '0xDB' => '0xCEAB', '0xDC' => '0xCEAC', '0xDD' => '0xCEAD', |
|
3565 | + '0xDE' => '0xCEAE', '0xDF' => '0xCEAF', '0xE0' => '0xCEB0', |
|
3566 | + '0xE1' => '0xCEB1', '0xE3' => '0xCEB3', '0xE4' => '0xCEB4', |
|
3567 | + '0xE5' => '0xCEB5', '0xE6' => '0xCEB6', '0xE7' => '0xCEB7', |
|
3568 | + '0xE9' => '0xCEB9', '0xEB' => '0xCEBB', '0xF0' => '0xCF80', |
|
3569 | + '0xF1' => '0xCF81', '0xF2' => '0xCF82', '0xF3' => '0xCF83', |
|
3570 | + '0xF4' => '0xCF84', '0xF5' => '0xCF85', '0xF6' => '0xCF86', |
|
3571 | + '0xF7' => '0xCF87', '0xF8' => '0xCF88', '0xF9' => '0xCF89', |
|
3572 | + '0xFA' => '0xCF8A', '0xFB' => '0xCF8B', '0xFC' => '0xCF8C', |
|
3573 | + '0xFD' => '0xCF8D', '0xFE' => '0xCF8E', '0xFF' => '0xCE92', |
|
3574 | 3574 | '0xD2' => '0xE282AC', |
3575 | 3575 | ), |
3576 | 3576 | ); |
@@ -3592,7 +3592,7 @@ discard block |
||
3592 | 3592 | $upcontext['table_count'] = count($queryTables); |
3593 | 3593 | $file_steps = $upcontext['table_count']; |
3594 | 3594 | |
3595 | - for($substep = $_GET['substep']; $substep < $upcontext['table_count']; $substep++) |
|
3595 | + for ($substep = $_GET['substep']; $substep < $upcontext['table_count']; $substep++) |
|
3596 | 3596 | { |
3597 | 3597 | $table = $queryTables[$_GET['substep']]; |
3598 | 3598 | |
@@ -3820,7 +3820,7 @@ discard block |
||
3820 | 3820 | $upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100); |
3821 | 3821 | $file_steps = $upcontext['table_count']; |
3822 | 3822 | |
3823 | - foreach($keys as $id => $table) |
|
3823 | + foreach ($keys as $id => $table) |
|
3824 | 3824 | if ($id < $_GET['substep']) |
3825 | 3825 | $upcontext['previous_tables'][] = $table; |
3826 | 3826 | |
@@ -3835,7 +3835,7 @@ discard block |
||
3835 | 3835 | $upcontext['cur_table_name'] = isset($keys[$substep + 1]) ? $keys[$substep + 1] : $keys[$substep]; |
3836 | 3836 | $upcontext['cur_table_num'] = $substep + 1; |
3837 | 3837 | |
3838 | - $upcontext['step_progress'] = (int)(($upcontext['cur_table_num'] / $upcontext['table_count']) * 100); |
|
3838 | + $upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100); |
|
3839 | 3839 | |
3840 | 3840 | // Do we need to pause? |
3841 | 3841 | nextSubstep($substep); |
@@ -4072,7 +4072,7 @@ discard block |
||
4072 | 4072 | The following files need to be writable to continue the upgrade. Please ensure the Windows permissions are correctly set to allow this:<br> |
4073 | 4073 | <ul style="margin: 2.5ex; font-family: monospace;"> |
4074 | 4074 | <li>' . implode('</li> |
4075 | - <li>', $upcontext['chmod']['files']). '</li> |
|
4075 | + <li>', $upcontext['chmod']['files']) . '</li> |
|
4076 | 4076 | </ul> |
4077 | 4077 | </div>'; |
4078 | 4078 | |
@@ -4168,7 +4168,7 @@ discard block |
||
4168 | 4168 | <title>', $txt['upgrade_upgrade_utility'], '</title> |
4169 | 4169 | <link rel="stylesheet" href="', $settings['default_theme_url'], '/css/index.css?alp21"> |
4170 | 4170 | <link rel="stylesheet" href="', $settings['default_theme_url'], '/css/install.css?alp21"> |
4171 | - ', $txt['lang_rtl'] == true ? '<link rel="stylesheet" href="' . $settings['default_theme_url'] . '/css/rtl.css?alp21">' : '' , ' |
|
4171 | + ', $txt['lang_rtl'] == true ? '<link rel="stylesheet" href="' . $settings['default_theme_url'] . '/css/rtl.css?alp21">' : '', ' |
|
4172 | 4172 | <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script> |
4173 | 4173 | <script src="', $settings['default_theme_url'], '/scripts/script.js"></script> |
4174 | 4174 | <script> |
@@ -4776,11 +4776,11 @@ discard block |
||
4776 | 4776 | |
4777 | 4777 | $totalTime = ''; |
4778 | 4778 | if ($hours > 0) |
4779 | - $totalTime .= $hours . ' hour' . ($hours > 1 ? 's':'') . ' '; |
|
4779 | + $totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' '; |
|
4780 | 4780 | if ($minutes > 0) |
4781 | - $totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's':'') . ' '; |
|
4781 | + $totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' '; |
|
4782 | 4782 | if ($seconds > 0) |
4783 | - $totalTime .= $seconds . ' second' . ($seconds > 1 ? 's':'') . ' '; |
|
4783 | + $totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' '; |
|
4784 | 4784 | } |
4785 | 4785 | |
4786 | 4786 | if ($is_debug && !empty($totalTime)) |
@@ -4813,11 +4813,11 @@ discard block |
||
4813 | 4813 | |
4814 | 4814 | $totalTime = ''; |
4815 | 4815 | if ($hours > 0) |
4816 | - $totalTime .= $hours . ' hour' . ($hours > 1 ? 's':'') . ' '; |
|
4816 | + $totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' '; |
|
4817 | 4817 | if ($minutes > 0) |
4818 | - $totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's':'') . ' '; |
|
4818 | + $totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' '; |
|
4819 | 4819 | if ($seconds > 0) |
4820 | - $totalTime .= $seconds . ' second' . ($seconds > 1 ? 's':'') . ' '; |
|
4820 | + $totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' '; |
|
4821 | 4821 | } |
4822 | 4822 | |
4823 | 4823 | echo ' |
@@ -5544,11 +5544,11 @@ discard block |
||
5544 | 5544 | { |
5545 | 5545 | $totalTime = ''; |
5546 | 5546 | if ($hours > 0) |
5547 | - $totalTime .= $hours . ' hour' . ($hours > 1 ? 's':'') . ' '; |
|
5547 | + $totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' '; |
|
5548 | 5548 | if ($minutes > 0) |
5549 | - $totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's':'') . ' '; |
|
5549 | + $totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' '; |
|
5550 | 5550 | if ($seconds > 0) |
5551 | - $totalTime .= $seconds . ' second' . ($seconds > 1 ? 's':'') . ' '; |
|
5551 | + $totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' '; |
|
5552 | 5552 | } |
5553 | 5553 | |
5554 | 5554 | if ($is_debug && !empty($totalTime)) |
@@ -78,11 +78,14 @@ discard block |
||
78 | 78 | ini_set('default_socket_timeout', 900); |
79 | 79 | } |
80 | 80 | // Clean the upgrade path if this is from the client. |
81 | -if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) |
|
82 | - for ($i = 1; $i < $_SERVER['argc']; $i++) |
|
81 | +if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) { |
|
82 | + for ($i = 1; |
|
83 | +} |
|
84 | +$i < $_SERVER['argc']; $i++) |
|
83 | 85 | { |
84 | - if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0) |
|
85 | - $upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1]; |
|
86 | + if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0) { |
|
87 | + $upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1]; |
|
88 | + } |
|
86 | 89 | } |
87 | 90 | |
88 | 91 | // Are we from the client? |
@@ -90,9 +93,9 @@ discard block |
||
90 | 93 | { |
91 | 94 | $command_line = true; |
92 | 95 | $disable_security = 1; |
93 | -} |
|
94 | -else |
|
96 | +} else { |
|
95 | 97 | $command_line = false; |
98 | +} |
|
96 | 99 | |
97 | 100 | // Load this now just because we can. |
98 | 101 | require_once($upgrade_path . '/Settings.php'); |
@@ -103,10 +106,12 @@ discard block |
||
103 | 106 | $upcontext['user'] = unserialize(base64_decode($upgradeData)); |
104 | 107 | |
105 | 108 | // Check for sensible values. |
106 | - if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400) |
|
107 | - $upcontext['user']['started'] = time(); |
|
108 | - if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400) |
|
109 | - $upcontext['user']['updated'] = 0; |
|
109 | + if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400) { |
|
110 | + $upcontext['user']['started'] = time(); |
|
111 | + } |
|
112 | + if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400) { |
|
113 | + $upcontext['user']['updated'] = 0; |
|
114 | + } |
|
110 | 115 | |
111 | 116 | $upcontext['started'] = $upcontext['user']['started']; |
112 | 117 | $upcontext['updated'] = $upcontext['user']['updated']; |
@@ -169,8 +174,9 @@ discard block |
||
169 | 174 | { |
170 | 175 | $word = trim($word, '-_\''); |
171 | 176 | |
172 | - if ($word != '') |
|
173 | - $returned_words[] = substr($word, 0, 20); |
|
177 | + if ($word != '') { |
|
178 | + $returned_words[] = substr($word, 0, 20); |
|
179 | + } |
|
174 | 180 | } |
175 | 181 | |
176 | 182 | return array_unique($returned_words); |
@@ -185,15 +191,17 @@ discard block |
||
185 | 191 | global $cachedir, $sourcedir; |
186 | 192 | |
187 | 193 | // No directory = no game. |
188 | - if (!is_dir($cachedir)) |
|
189 | - return; |
|
194 | + if (!is_dir($cachedir)) { |
|
195 | + return; |
|
196 | + } |
|
190 | 197 | |
191 | 198 | // Remove the files in SMF's own disk cache, if any |
192 | 199 | $dh = opendir($cachedir); |
193 | 200 | while ($file = readdir($dh)) |
194 | 201 | { |
195 | - if ($file != '.' && $file != '..' && $file != 'index.php' && $file != '.htaccess' && (!$type || substr($file, 0, strlen($type)) == $type)) |
|
196 | - @unlink($cachedir . '/' . $file); |
|
202 | + if ($file != '.' && $file != '..' && $file != 'index.php' && $file != '.htaccess' && (!$type || substr($file, 0, strlen($type)) == $type)) { |
|
203 | + @unlink($cachedir . '/' . $file); |
|
204 | + } |
|
197 | 205 | } |
198 | 206 | closedir($dh); |
199 | 207 | |
@@ -209,8 +217,9 @@ discard block |
||
209 | 217 | { |
210 | 218 | function md5_hmac($data, $key) |
211 | 219 | { |
212 | - if (strlen($key) > 64) |
|
213 | - $key = pack('H*', md5($key)); |
|
220 | + if (strlen($key) > 64) { |
|
221 | + $key = pack('H*', md5($key)); |
|
222 | + } |
|
214 | 223 | $key = str_pad($key, 64, chr(0x00)); |
215 | 224 | |
216 | 225 | $k_ipad = $key ^ str_repeat(chr(0x36), 64); |
@@ -221,8 +230,9 @@ discard block |
||
221 | 230 | } |
222 | 231 | |
223 | 232 | // Don't do security check if on Yabbse |
224 | -if (!isset($modSettings['smfVersion'])) |
|
233 | +if (!isset($modSettings['smfVersion'])) { |
|
225 | 234 | $disable_security = true; |
235 | +} |
|
226 | 236 | |
227 | 237 | // This only exists if we're on SMF ;) |
228 | 238 | if (isset($modSettings['smfVersion'])) |
@@ -240,8 +250,9 @@ discard block |
||
240 | 250 | 'db_error_skip' => true, |
241 | 251 | ) |
242 | 252 | ); |
243 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
244 | - $modSettings[$row['variable']] = $row['value']; |
|
253 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
254 | + $modSettings[$row['variable']] = $row['value']; |
|
255 | + } |
|
245 | 256 | $smcFunc['db_free_result']($request); |
246 | 257 | } |
247 | 258 | |
@@ -251,10 +262,12 @@ discard block |
||
251 | 262 | $modSettings['theme_url'] = 'Themes/default'; |
252 | 263 | $modSettings['images_url'] = 'Themes/default/images'; |
253 | 264 | } |
254 | -if (!isset($settings['default_theme_url'])) |
|
265 | +if (!isset($settings['default_theme_url'])) { |
|
255 | 266 | $settings['default_theme_url'] = $modSettings['theme_url']; |
256 | -if (!isset($settings['default_theme_dir'])) |
|
267 | +} |
|
268 | +if (!isset($settings['default_theme_dir'])) { |
|
257 | 269 | $settings['default_theme_dir'] = $modSettings['theme_dir']; |
270 | +} |
|
258 | 271 | |
259 | 272 | $upcontext['is_large_forum'] = (empty($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC1') && !empty($modSettings['totalMessages']) && $modSettings['totalMessages'] > 75000; |
260 | 273 | // Default title... |
@@ -272,13 +285,15 @@ discard block |
||
272 | 285 | $support_js = $upcontext['upgrade_status']['js']; |
273 | 286 | |
274 | 287 | // Only set this if the upgrader status says so. |
275 | - if (empty($is_debug)) |
|
276 | - $is_debug = $upcontext['upgrade_status']['debug']; |
|
288 | + if (empty($is_debug)) { |
|
289 | + $is_debug = $upcontext['upgrade_status']['debug']; |
|
290 | + } |
|
277 | 291 | |
278 | 292 | // Load the language. |
279 | - if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) |
|
280 | - require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'); |
|
281 | -} |
|
293 | + if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) { |
|
294 | + require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'); |
|
295 | + } |
|
296 | + } |
|
282 | 297 | // Set the defaults. |
283 | 298 | else |
284 | 299 | { |
@@ -296,15 +311,18 @@ discard block |
||
296 | 311 | } |
297 | 312 | |
298 | 313 | // If this isn't the first stage see whether they are logging in and resuming. |
299 | -if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step'])) |
|
314 | +if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step'])) { |
|
300 | 315 | checkLogin(); |
316 | +} |
|
301 | 317 | |
302 | -if ($command_line) |
|
318 | +if ($command_line) { |
|
303 | 319 | cmdStep0(); |
320 | +} |
|
304 | 321 | |
305 | 322 | // Don't error if we're using xml. |
306 | -if (isset($_GET['xml'])) |
|
323 | +if (isset($_GET['xml'])) { |
|
307 | 324 | $upcontext['return_error'] = true; |
325 | +} |
|
308 | 326 | |
309 | 327 | // Loop through all the steps doing each one as required. |
310 | 328 | $upcontext['overall_percent'] = 0; |
@@ -325,10 +343,11 @@ discard block |
||
325 | 343 | } |
326 | 344 | |
327 | 345 | // Call the step and if it returns false that means pause! |
328 | - if (function_exists($step[2]) && $step[2]() === false) |
|
329 | - break; |
|
330 | - elseif (function_exists($step[2])) |
|
331 | - $upcontext['current_step']++; |
|
346 | + if (function_exists($step[2]) && $step[2]() === false) { |
|
347 | + break; |
|
348 | + } elseif (function_exists($step[2])) { |
|
349 | + $upcontext['current_step']++; |
|
350 | + } |
|
332 | 351 | } |
333 | 352 | $upcontext['overall_percent'] += $step[3]; |
334 | 353 | } |
@@ -367,17 +386,18 @@ discard block |
||
367 | 386 | // This should not happen my dear... HELP ME DEVELOPERS!! |
368 | 387 | if (!empty($command_line)) |
369 | 388 | { |
370 | - if (function_exists('debug_print_backtrace')) |
|
371 | - debug_print_backtrace(); |
|
389 | + if (function_exists('debug_print_backtrace')) { |
|
390 | + debug_print_backtrace(); |
|
391 | + } |
|
372 | 392 | |
373 | 393 | echo "\n" . 'Error: Unexpected call to use the ' . (isset($upcontext['sub_template']) ? $upcontext['sub_template'] : '') . ' template. Please copy and paste all the text above and visit the SMF support forum to tell the Developers that they\'ve made a boo boo; they\'ll get you up and running again.'; |
374 | 394 | flush(); |
375 | 395 | die(); |
376 | 396 | } |
377 | 397 | |
378 | - if (!isset($_GET['xml'])) |
|
379 | - template_upgrade_above(); |
|
380 | - else |
|
398 | + if (!isset($_GET['xml'])) { |
|
399 | + template_upgrade_above(); |
|
400 | + } else |
|
381 | 401 | { |
382 | 402 | header('Content-Type: text/xml; charset=UTF-8'); |
383 | 403 | // Sadly we need to retain the $_GET data thanks to the old upgrade scripts. |
@@ -399,21 +419,24 @@ discard block |
||
399 | 419 | $upcontext['form_url'] = $upgradeurl . '?step=' . $upcontext['current_step'] . '&substep=' . $_GET['substep'] . '&data=' . base64_encode(safe_serialize($upcontext['upgrade_status'])); |
400 | 420 | |
401 | 421 | // Custom stuff to pass back? |
402 | - if (!empty($upcontext['query_string'])) |
|
403 | - $upcontext['form_url'] .= $upcontext['query_string']; |
|
422 | + if (!empty($upcontext['query_string'])) { |
|
423 | + $upcontext['form_url'] .= $upcontext['query_string']; |
|
424 | + } |
|
404 | 425 | |
405 | 426 | call_user_func('template_' . $upcontext['sub_template']); |
406 | 427 | } |
407 | 428 | |
408 | 429 | // Was there an error? |
409 | - if (!empty($upcontext['forced_error_message'])) |
|
410 | - echo $upcontext['forced_error_message']; |
|
430 | + if (!empty($upcontext['forced_error_message'])) { |
|
431 | + echo $upcontext['forced_error_message']; |
|
432 | + } |
|
411 | 433 | |
412 | 434 | // Show the footer. |
413 | - if (!isset($_GET['xml'])) |
|
414 | - template_upgrade_below(); |
|
415 | - else |
|
416 | - template_xml_below(); |
|
435 | + if (!isset($_GET['xml'])) { |
|
436 | + template_upgrade_below(); |
|
437 | + } else { |
|
438 | + template_xml_below(); |
|
439 | + } |
|
417 | 440 | } |
418 | 441 | |
419 | 442 | |
@@ -425,15 +448,19 @@ discard block |
||
425 | 448 | $seconds = intval($active % 60); |
426 | 449 | |
427 | 450 | $totalTime = ''; |
428 | - if ($hours > 0) |
|
429 | - $totalTime .= $hours . ' hour' . ($hours > 1 ? 's':'') . ' '; |
|
430 | - if ($minutes > 0) |
|
431 | - $totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's':'') . ' '; |
|
432 | - if ($seconds > 0) |
|
433 | - $totalTime .= $seconds . ' second' . ($seconds > 1 ? 's':'') . ' '; |
|
451 | + if ($hours > 0) { |
|
452 | + $totalTime .= $hours . ' hour' . ($hours > 1 ? 's':'') . ' '; |
|
453 | + } |
|
454 | + if ($minutes > 0) { |
|
455 | + $totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's':'') . ' '; |
|
456 | + } |
|
457 | + if ($seconds > 0) { |
|
458 | + $totalTime .= $seconds . ' second' . ($seconds > 1 ? 's':'') . ' '; |
|
459 | + } |
|
434 | 460 | |
435 | - if (!empty($totalTime)) |
|
436 | - echo "\n" . 'Upgrade completed in ' . $totalTime . "\n"; |
|
461 | + if (!empty($totalTime)) { |
|
462 | + echo "\n" . 'Upgrade completed in ' . $totalTime . "\n"; |
|
463 | + } |
|
437 | 464 | } |
438 | 465 | |
439 | 466 | // Bang - gone! |
@@ -446,8 +473,9 @@ discard block |
||
446 | 473 | global $upgradeurl, $upcontext, $command_line; |
447 | 474 | |
448 | 475 | // Command line users can't be redirected. |
449 | - if ($command_line) |
|
450 | - upgradeExit(true); |
|
476 | + if ($command_line) { |
|
477 | + upgradeExit(true); |
|
478 | + } |
|
451 | 479 | |
452 | 480 | // Are we providing the core info? |
453 | 481 | if ($addForm) |
@@ -470,19 +498,22 @@ discard block |
||
470 | 498 | global $modSettings, $sourcedir, $smcFunc; |
471 | 499 | |
472 | 500 | // Do the non-SSI stuff... |
473 | - if (function_exists('set_magic_quotes_runtime')) |
|
474 | - @set_magic_quotes_runtime(0); |
|
501 | + if (function_exists('set_magic_quotes_runtime')) { |
|
502 | + @set_magic_quotes_runtime(0); |
|
503 | + } |
|
475 | 504 | |
476 | 505 | error_reporting(E_ALL); |
477 | 506 | define('SMF', 1); |
478 | 507 | |
479 | 508 | // Start the session. |
480 | - if (@ini_get('session.save_handler') == 'user') |
|
481 | - @ini_set('session.save_handler', 'files'); |
|
509 | + if (@ini_get('session.save_handler') == 'user') { |
|
510 | + @ini_set('session.save_handler', 'files'); |
|
511 | + } |
|
482 | 512 | @session_start(); |
483 | 513 | |
484 | - if (empty($smcFunc)) |
|
485 | - $smcFunc = array(); |
|
514 | + if (empty($smcFunc)) { |
|
515 | + $smcFunc = array(); |
|
516 | + } |
|
486 | 517 | |
487 | 518 | // We need this for authentication and some upgrade code |
488 | 519 | require_once($sourcedir . '/Subs-Auth.php'); |
@@ -495,8 +526,9 @@ discard block |
||
495 | 526 | initialize_inputs(); |
496 | 527 | |
497 | 528 | // Get the database going! |
498 | - if (empty($db_type)) |
|
499 | - $db_type = 'mysql'; |
|
529 | + if (empty($db_type)) { |
|
530 | + $db_type = 'mysql'; |
|
531 | + } |
|
500 | 532 | if (file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) |
501 | 533 | { |
502 | 534 | require_once($sourcedir . '/Subs-Db-' . $db_type . '.php'); |
@@ -505,17 +537,19 @@ discard block |
||
505 | 537 | $db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true)); |
506 | 538 | |
507 | 539 | // Oh dear god!! |
508 | - if ($db_connection === null) |
|
509 | - die('Unable to connect to database - please check username and password are correct in Settings.php'); |
|
540 | + if ($db_connection === null) { |
|
541 | + die('Unable to connect to database - please check username and password are correct in Settings.php'); |
|
542 | + } |
|
510 | 543 | |
511 | - if (($db_type == 'mysql' || $db_type == 'mysqli') && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) |
|
512 | - $smcFunc['db_query']('', ' |
|
544 | + if (($db_type == 'mysql' || $db_type == 'mysqli') && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) { |
|
545 | + $smcFunc['db_query']('', ' |
|
513 | 546 | SET NAMES {string:db_character_set}', |
514 | 547 | array( |
515 | 548 | 'db_error_skip' => true, |
516 | 549 | 'db_character_set' => $db_character_set, |
517 | 550 | ) |
518 | 551 | ); |
552 | + } |
|
519 | 553 | |
520 | 554 | // Load the modSettings data... |
521 | 555 | $request = $smcFunc['db_query']('', ' |
@@ -526,11 +560,11 @@ discard block |
||
526 | 560 | ) |
527 | 561 | ); |
528 | 562 | $modSettings = array(); |
529 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
530 | - $modSettings[$row['variable']] = $row['value']; |
|
563 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
564 | + $modSettings[$row['variable']] = $row['value']; |
|
565 | + } |
|
531 | 566 | $smcFunc['db_free_result']($request); |
532 | - } |
|
533 | - else |
|
567 | + } else |
|
534 | 568 | { |
535 | 569 | return throw_error('Cannot find ' . $sourcedir . '/Subs-Db-' . $db_type . '.php' . '. Please check you have uploaded all source files and have the correct paths set.'); |
536 | 570 | } |
@@ -544,9 +578,10 @@ discard block |
||
544 | 578 | cleanRequest(); |
545 | 579 | } |
546 | 580 | |
547 | - if (!isset($_GET['substep'])) |
|
548 | - $_GET['substep'] = 0; |
|
549 | -} |
|
581 | + if (!isset($_GET['substep'])) { |
|
582 | + $_GET['substep'] = 0; |
|
583 | + } |
|
584 | + } |
|
550 | 585 | |
551 | 586 | function initialize_inputs() |
552 | 587 | { |
@@ -584,8 +619,9 @@ discard block |
||
584 | 619 | $dh = opendir(dirname(__FILE__)); |
585 | 620 | while ($file = readdir($dh)) |
586 | 621 | { |
587 | - if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) |
|
588 | - @unlink(dirname(__FILE__) . '/' . $file); |
|
622 | + if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) { |
|
623 | + @unlink(dirname(__FILE__) . '/' . $file); |
|
624 | + } |
|
589 | 625 | } |
590 | 626 | closedir($dh); |
591 | 627 | |
@@ -615,8 +651,9 @@ discard block |
||
615 | 651 | { |
616 | 652 | $upcontext['remote_files_available'] = false; |
617 | 653 | $test = @fsockopen('www.simplemachines.org', 80, $errno, $errstr, 1); |
618 | - if ($test) |
|
619 | - $upcontext['remote_files_available'] = true; |
|
654 | + if ($test) { |
|
655 | + $upcontext['remote_files_available'] = true; |
|
656 | + } |
|
620 | 657 | @fclose($test); |
621 | 658 | } |
622 | 659 | |
@@ -624,8 +661,9 @@ discard block |
||
624 | 661 | $temp = 'upgrade_php?step'; |
625 | 662 | while (strlen($temp) > 4) |
626 | 663 | { |
627 | - if (isset($_GET[$temp])) |
|
628 | - unset($_GET[$temp]); |
|
664 | + if (isset($_GET[$temp])) { |
|
665 | + unset($_GET[$temp]); |
|
666 | + } |
|
629 | 667 | $temp = substr($temp, 1); |
630 | 668 | } |
631 | 669 | |
@@ -651,29 +689,36 @@ discard block |
||
651 | 689 | && @file_exists(dirname(__FILE__) . '/upgrade_2-1_' . $type . '.sql'); |
652 | 690 | |
653 | 691 | // Need legacy scripts? |
654 | - if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1) |
|
655 | - $check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $type . '.sql'); |
|
656 | - if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) |
|
657 | - $check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql'); |
|
658 | - if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) |
|
659 | - $check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql'); |
|
692 | + if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1) { |
|
693 | + $check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $type . '.sql'); |
|
694 | + } |
|
695 | + if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) { |
|
696 | + $check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql'); |
|
697 | + } |
|
698 | + if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) { |
|
699 | + $check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql'); |
|
700 | + } |
|
660 | 701 | |
661 | 702 | // This needs to exist! |
662 | - if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) |
|
663 | - return throw_error('The upgrader could not find the "Install" language file for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded all the files included in the package, even the theme and language files for the default theme.<br> [<a href="' . $upgradeurl . '?lang=english">Try English</a>]'); |
|
664 | - else |
|
665 | - require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'); |
|
703 | + if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) { |
|
704 | + return throw_error('The upgrader could not find the "Install" language file for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded all the files included in the package, even the theme and language files for the default theme.<br> [<a href="' . $upgradeurl . '?lang=english">Try English</a>]'); |
|
705 | + } else { |
|
706 | + require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'); |
|
707 | + } |
|
666 | 708 | |
667 | - if (!$check) |
|
668 | - // Don't tell them what files exactly because it's a spot check - just like teachers don't tell which problems they are spot checking, that's dumb. |
|
709 | + if (!$check) { |
|
710 | + // Don't tell them what files exactly because it's a spot check - just like teachers don't tell which problems they are spot checking, that's dumb. |
|
669 | 711 | return throw_error('The upgrader was unable to find some crucial files.<br><br>Please make sure you uploaded all of the files included in the package, including the Themes, Sources, and other directories.'); |
712 | + } |
|
670 | 713 | |
671 | 714 | // Do they meet the install requirements? |
672 | - if (!php_version_check()) |
|
673 | - return throw_error('Warning! You do not appear to have a version of PHP installed on your webserver that meets SMF\'s minimum installations requirements.<br><br>Please ask your host to upgrade.'); |
|
715 | + if (!php_version_check()) { |
|
716 | + return throw_error('Warning! You do not appear to have a version of PHP installed on your webserver that meets SMF\'s minimum installations requirements.<br><br>Please ask your host to upgrade.'); |
|
717 | + } |
|
674 | 718 | |
675 | - if (!db_version_check()) |
|
676 | - return throw_error('Your ' . $databases[$db_type]['name'] . ' version does not meet the minimum requirements of SMF.<br><br>Please ask your host to upgrade.'); |
|
719 | + if (!db_version_check()) { |
|
720 | + return throw_error('Your ' . $databases[$db_type]['name'] . ' version does not meet the minimum requirements of SMF.<br><br>Please ask your host to upgrade.'); |
|
721 | + } |
|
677 | 722 | |
678 | 723 | // Do some checks to make sure they have proper privileges |
679 | 724 | db_extend('packages'); |
@@ -688,14 +733,16 @@ discard block |
||
688 | 733 | $drop = $smcFunc['db_drop_table']('{db_prefix}priv_check'); |
689 | 734 | |
690 | 735 | // Sorry... we need CREATE, ALTER and DROP |
691 | - if (!$create || !$alter || !$drop) |
|
692 | - return throw_error('The ' . $databases[$db_type]['name'] . ' user you have set in Settings.php does not have proper privileges.<br><br>Please ask your host to give this user the ALTER, CREATE, and DROP privileges.'); |
|
736 | + if (!$create || !$alter || !$drop) { |
|
737 | + return throw_error('The ' . $databases[$db_type]['name'] . ' user you have set in Settings.php does not have proper privileges.<br><br>Please ask your host to give this user the ALTER, CREATE, and DROP privileges.'); |
|
738 | + } |
|
693 | 739 | |
694 | 740 | // Do a quick version spot check. |
695 | 741 | $temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096); |
696 | 742 | preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match); |
697 | - if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) |
|
698 | - return throw_error('The upgrader found some old or outdated files.<br><br>Please make certain you uploaded the new versions of all the files included in the package.'); |
|
743 | + if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) { |
|
744 | + return throw_error('The upgrader found some old or outdated files.<br><br>Please make certain you uploaded the new versions of all the files included in the package.'); |
|
745 | + } |
|
699 | 746 | |
700 | 747 | // What absolutely needs to be writable? |
701 | 748 | $writable_files = array( |
@@ -717,12 +764,13 @@ discard block |
||
717 | 764 | quickFileWritable($custom_av_dir); |
718 | 765 | |
719 | 766 | // Are we good now? |
720 | - if(!is_writable($custom_av_dir)) |
|
721 | - return throw_error(sprintf('The directory: %1$s has to be writable to continue the upgrade. Please make sure permissions are correctly set to allow this.', $custom_av_dir)); |
|
722 | - elseif ($need_settings_update) |
|
767 | + if(!is_writable($custom_av_dir)) { |
|
768 | + return throw_error(sprintf('The directory: %1$s has to be writable to continue the upgrade. Please make sure permissions are correctly set to allow this.', $custom_av_dir)); |
|
769 | + } elseif ($need_settings_update) |
|
723 | 770 | { |
724 | - if (!function_exists('cache_put_data')) |
|
725 | - require_once($sourcedir . '/Load.php'); |
|
771 | + if (!function_exists('cache_put_data')) { |
|
772 | + require_once($sourcedir . '/Load.php'); |
|
773 | + } |
|
726 | 774 | updateSettings(array('custom_avatar_dir' => $custom_av_dir)); |
727 | 775 | updateSettings(array('custom_avatar_url' => $custom_av_url)); |
728 | 776 | } |
@@ -731,28 +779,33 @@ discard block |
||
731 | 779 | |
732 | 780 | // Check the cache directory. |
733 | 781 | $cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir; |
734 | - if (!file_exists($cachedir_temp)) |
|
735 | - @mkdir($cachedir_temp); |
|
736 | - if (!file_exists($cachedir_temp)) |
|
737 | - return throw_error('The cache directory could not be found.<br><br>Please make sure you have a directory called "cache" in your forum directory before continuing.'); |
|
738 | - |
|
739 | - if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) |
|
740 | - return throw_error('The upgrader was unable to find language files for the language specified in Settings.php.<br>SMF will not work without the primary language files installed.<br><br>Please either install them, or <a href="' . $upgradeurl . '?step=0;lang=english">use english instead</a>.'); |
|
741 | - elseif (!isset($_GET['skiplang'])) |
|
782 | + if (!file_exists($cachedir_temp)) { |
|
783 | + @mkdir($cachedir_temp); |
|
784 | + } |
|
785 | + if (!file_exists($cachedir_temp)) { |
|
786 | + return throw_error('The cache directory could not be found.<br><br>Please make sure you have a directory called "cache" in your forum directory before continuing.'); |
|
787 | + } |
|
788 | + |
|
789 | + if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) { |
|
790 | + return throw_error('The upgrader was unable to find language files for the language specified in Settings.php.<br>SMF will not work without the primary language files installed.<br><br>Please either install them, or <a href="' . $upgradeurl . '?step=0;lang=english">use english instead</a>.'); |
|
791 | + } elseif (!isset($_GET['skiplang'])) |
|
742 | 792 | { |
743 | 793 | $temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096); |
744 | 794 | preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match); |
745 | 795 | |
746 | - if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) |
|
747 | - return throw_error('The upgrader found some old or outdated language files, for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded the new versions of all the files included in the package, even the theme and language files for the default theme.<br> [<a href="' . $upgradeurl . '?skiplang">SKIP</a>] [<a href="' . $upgradeurl . '?lang=english">Try English</a>]'); |
|
796 | + if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) { |
|
797 | + return throw_error('The upgrader found some old or outdated language files, for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded the new versions of all the files included in the package, even the theme and language files for the default theme.<br> [<a href="' . $upgradeurl . '?skiplang">SKIP</a>] [<a href="' . $upgradeurl . '?lang=english">Try English</a>]'); |
|
798 | + } |
|
748 | 799 | } |
749 | 800 | |
750 | - if (!makeFilesWritable($writable_files)) |
|
751 | - return false; |
|
801 | + if (!makeFilesWritable($writable_files)) { |
|
802 | + return false; |
|
803 | + } |
|
752 | 804 | |
753 | 805 | // Check agreement.txt. (it may not exist, in which case $boarddir must be writable.) |
754 | - if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) |
|
755 | - return throw_error('The upgrader was unable to obtain write access to agreement.txt.<br><br>If you are using a linux or unix based server, please ensure that the file is chmod\'d to 777, or if it does not exist that the directory this upgrader is in is 777.<br>If your server is running Windows, please ensure that the internet guest account has the proper permissions on it or its folder.'); |
|
806 | + if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) { |
|
807 | + return throw_error('The upgrader was unable to obtain write access to agreement.txt.<br><br>If you are using a linux or unix based server, please ensure that the file is chmod\'d to 777, or if it does not exist that the directory this upgrader is in is 777.<br>If your server is running Windows, please ensure that the internet guest account has the proper permissions on it or its folder.'); |
|
808 | + } |
|
756 | 809 | |
757 | 810 | // Upgrade the agreement. |
758 | 811 | elseif (isset($modSettings['agreement'])) |
@@ -763,8 +816,8 @@ discard block |
||
763 | 816 | } |
764 | 817 | |
765 | 818 | // We're going to check that their board dir setting is right in case they've been moving stuff around. |
766 | - if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) |
|
767 | - $upcontext['warning'] = ' |
|
819 | + if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) { |
|
820 | + $upcontext['warning'] = ' |
|
768 | 821 | It looks as if your board directory settings <em>might</em> be incorrect. Your board directory is currently set to "' . $boarddir . '" but should probably be "' . dirname(__FILE__) . '". Settings.php currently lists your paths as:<br> |
769 | 822 | <ul> |
770 | 823 | <li>Board Directory: ' . $boarddir . '</li> |
@@ -772,10 +825,12 @@ discard block |
||
772 | 825 | <li>Cache Directory: ' . $cachedir_temp . '</li> |
773 | 826 | </ul> |
774 | 827 | If these seem incorrect please open Settings.php in a text editor before proceeding with this upgrade. If they are incorrect due to you moving your forum to a new location please download and execute the <a href="http://download.simplemachines.org/?tools">Repair Settings</a> tool from the Simple Machines website before continuing.'; |
828 | + } |
|
775 | 829 | |
776 | 830 | // Either we're logged in or we're going to present the login. |
777 | - if (checkLogin()) |
|
778 | - return true; |
|
831 | + if (checkLogin()) { |
|
832 | + return true; |
|
833 | + } |
|
779 | 834 | |
780 | 835 | $upcontext += createToken('login'); |
781 | 836 | |
@@ -792,8 +847,9 @@ discard block |
||
792 | 847 | if (isset($_POST['contbutt']) && (!empty($_POST['user']) || $disable_security)) |
793 | 848 | { |
794 | 849 | // If we've disabled security pick a suitable name! |
795 | - if (empty($_POST['user'])) |
|
796 | - $_POST['user'] = 'Administrator'; |
|
850 | + if (empty($_POST['user'])) { |
|
851 | + $_POST['user'] = 'Administrator'; |
|
852 | + } |
|
797 | 853 | |
798 | 854 | // Before 2.0 these column names were different! |
799 | 855 | $oldDB = false; |
@@ -808,16 +864,17 @@ discard block |
||
808 | 864 | 'db_error_skip' => true, |
809 | 865 | ) |
810 | 866 | ); |
811 | - if ($smcFunc['db_num_rows']($request) != 0) |
|
812 | - $oldDB = true; |
|
867 | + if ($smcFunc['db_num_rows']($request) != 0) { |
|
868 | + $oldDB = true; |
|
869 | + } |
|
813 | 870 | $smcFunc['db_free_result']($request); |
814 | 871 | } |
815 | 872 | |
816 | 873 | // Get what we believe to be their details. |
817 | 874 | if (!$disable_security) |
818 | 875 | { |
819 | - if ($oldDB) |
|
820 | - $request = $smcFunc['db_query']('', ' |
|
876 | + if ($oldDB) { |
|
877 | + $request = $smcFunc['db_query']('', ' |
|
821 | 878 | SELECT id_member, memberName AS member_name, passwd, id_group, |
822 | 879 | additionalGroups AS additional_groups, lngfile |
823 | 880 | FROM {db_prefix}members |
@@ -827,8 +884,8 @@ discard block |
||
827 | 884 | 'db_error_skip' => true, |
828 | 885 | ) |
829 | 886 | ); |
830 | - else |
|
831 | - $request = $smcFunc['db_query']('', ' |
|
887 | + } else { |
|
888 | + $request = $smcFunc['db_query']('', ' |
|
832 | 889 | SELECT id_member, member_name, passwd, id_group, additional_groups, lngfile |
833 | 890 | FROM {db_prefix}members |
834 | 891 | WHERE member_name = {string:member_name}', |
@@ -837,6 +894,7 @@ discard block |
||
837 | 894 | 'db_error_skip' => true, |
838 | 895 | ) |
839 | 896 | ); |
897 | + } |
|
840 | 898 | if ($smcFunc['db_num_rows']($request) != 0) |
841 | 899 | { |
842 | 900 | list ($id_member, $name, $password, $id_group, $addGroups, $user_language) = $smcFunc['db_fetch_row']($request); |
@@ -844,13 +902,14 @@ discard block |
||
844 | 902 | $groups = explode(',', $addGroups); |
845 | 903 | $groups[] = $id_group; |
846 | 904 | |
847 | - foreach ($groups as $k => $v) |
|
848 | - $groups[$k] = (int) $v; |
|
905 | + foreach ($groups as $k => $v) { |
|
906 | + $groups[$k] = (int) $v; |
|
907 | + } |
|
849 | 908 | |
850 | 909 | $sha_passwd = sha1(strtolower($name) . un_htmlspecialchars($_REQUEST['passwrd'])); |
910 | + } else { |
|
911 | + $upcontext['username_incorrect'] = true; |
|
851 | 912 | } |
852 | - else |
|
853 | - $upcontext['username_incorrect'] = true; |
|
854 | 913 | $smcFunc['db_free_result']($request); |
855 | 914 | } |
856 | 915 | $upcontext['username'] = $_POST['user']; |
@@ -860,13 +919,14 @@ discard block |
||
860 | 919 | { |
861 | 920 | $upcontext['upgrade_status']['js'] = 1; |
862 | 921 | $support_js = 1; |
922 | + } else { |
|
923 | + $support_js = 0; |
|
863 | 924 | } |
864 | - else |
|
865 | - $support_js = 0; |
|
866 | 925 | |
867 | 926 | // Note down the version we are coming from. |
868 | - if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) |
|
869 | - $upcontext['user']['version'] = $modSettings['smfVersion']; |
|
927 | + if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) { |
|
928 | + $upcontext['user']['version'] = $modSettings['smfVersion']; |
|
929 | + } |
|
870 | 930 | |
871 | 931 | // Didn't get anywhere? |
872 | 932 | if (!$disable_security && (empty($sha_passwd) || (!empty($password) ? $password : '') != $sha_passwd) && !hash_verify_password((!empty($name) ? $name : ''), $_REQUEST['passwrd'], (!empty($password) ? $password : '')) && empty($upcontext['username_incorrect'])) |
@@ -900,15 +960,15 @@ discard block |
||
900 | 960 | 'db_error_skip' => true, |
901 | 961 | ) |
902 | 962 | ); |
903 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
904 | - return throw_error('You need to be an admin to perform an upgrade!'); |
|
963 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
964 | + return throw_error('You need to be an admin to perform an upgrade!'); |
|
965 | + } |
|
905 | 966 | $smcFunc['db_free_result']($request); |
906 | 967 | } |
907 | 968 | |
908 | 969 | $upcontext['user']['id'] = $id_member; |
909 | 970 | $upcontext['user']['name'] = $name; |
910 | - } |
|
911 | - else |
|
971 | + } else |
|
912 | 972 | { |
913 | 973 | $upcontext['user']['id'] = 1; |
914 | 974 | $upcontext['user']['name'] = 'Administrator'; |
@@ -924,11 +984,11 @@ discard block |
||
924 | 984 | $temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $user_language . '.php')), 0, 4096); |
925 | 985 | preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match); |
926 | 986 | |
927 | - if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) |
|
928 | - $upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been updated to the latest version. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.'; |
|
929 | - elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) |
|
930 | - $upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been uploaded/updated as the "Install" language file is missing. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.'; |
|
931 | - else |
|
987 | + if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) { |
|
988 | + $upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been updated to the latest version. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.'; |
|
989 | + } elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) { |
|
990 | + $upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been uploaded/updated as the "Install" language file is missing. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.'; |
|
991 | + } else |
|
932 | 992 | { |
933 | 993 | // Set this as the new language. |
934 | 994 | $upcontext['language'] = $user_language; |
@@ -972,8 +1032,9 @@ discard block |
||
972 | 1032 | unset($member_columns); |
973 | 1033 | |
974 | 1034 | // If we've not submitted then we're done. |
975 | - if (empty($_POST['upcont'])) |
|
976 | - return false; |
|
1035 | + if (empty($_POST['upcont'])) { |
|
1036 | + return false; |
|
1037 | + } |
|
977 | 1038 | |
978 | 1039 | require_once($sourcedir . '/Subs-Admin.php'); |
979 | 1040 | updateSettingsFile(array('image_proxy_secret' => '\'' . substr(sha1(mt_rand()), 0, 20) . '\'')); |
@@ -991,25 +1052,26 @@ discard block |
||
991 | 1052 | fwrite($fp, $out); |
992 | 1053 | |
993 | 1054 | $return_data = ''; |
994 | - while (!feof($fp)) |
|
995 | - $return_data .= fgets($fp, 128); |
|
1055 | + while (!feof($fp)) { |
|
1056 | + $return_data .= fgets($fp, 128); |
|
1057 | + } |
|
996 | 1058 | |
997 | 1059 | fclose($fp); |
998 | 1060 | |
999 | 1061 | // Get the unique site ID. |
1000 | 1062 | preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID); |
1001 | 1063 | |
1002 | - if (!empty($ID[1])) |
|
1003 | - $smcFunc['db_insert']('replace', |
|
1064 | + if (!empty($ID[1])) { |
|
1065 | + $smcFunc['db_insert']('replace', |
|
1004 | 1066 | $db_prefix . 'settings', |
1005 | 1067 | array('variable' => 'string', 'value' => 'string'), |
1006 | 1068 | array('allow_sm_stats', $ID[1]), |
1007 | 1069 | array('variable') |
1008 | 1070 | ); |
1071 | + } |
|
1009 | 1072 | } |
1010 | - } |
|
1011 | - else |
|
1012 | - $smcFunc['db_query']('', ' |
|
1073 | + } else { |
|
1074 | + $smcFunc['db_query']('', ' |
|
1013 | 1075 | DELETE FROM {db_prefix}settings |
1014 | 1076 | WHERE variable = {string:allow_sm_stats}', |
1015 | 1077 | array( |
@@ -1017,6 +1079,7 @@ discard block |
||
1017 | 1079 | 'db_error_skip' => true, |
1018 | 1080 | ) |
1019 | 1081 | ); |
1082 | + } |
|
1020 | 1083 | |
1021 | 1084 | // Deleting old karma stuff? |
1022 | 1085 | if (!empty($_POST['delete_karma'])) |
@@ -1031,20 +1094,22 @@ discard block |
||
1031 | 1094 | ); |
1032 | 1095 | |
1033 | 1096 | // Cleaning up old karma member settings. |
1034 | - if ($upcontext['karma_installed']['good']) |
|
1035 | - $smcFunc['db_query']('', ' |
|
1097 | + if ($upcontext['karma_installed']['good']) { |
|
1098 | + $smcFunc['db_query']('', ' |
|
1036 | 1099 | ALTER TABLE {db_prefix}members |
1037 | 1100 | DROP karma_good', |
1038 | 1101 | array() |
1039 | 1102 | ); |
1103 | + } |
|
1040 | 1104 | |
1041 | 1105 | // Does karma bad was enable? |
1042 | - if ($upcontext['karma_installed']['bad']) |
|
1043 | - $smcFunc['db_query']('', ' |
|
1106 | + if ($upcontext['karma_installed']['bad']) { |
|
1107 | + $smcFunc['db_query']('', ' |
|
1044 | 1108 | ALTER TABLE {db_prefix}members |
1045 | 1109 | DROP karma_bad', |
1046 | 1110 | array() |
1047 | 1111 | ); |
1112 | + } |
|
1048 | 1113 | |
1049 | 1114 | // Cleaning up old karma permissions. |
1050 | 1115 | $smcFunc['db_query']('', ' |
@@ -1057,18 +1122,20 @@ discard block |
||
1057 | 1122 | } |
1058 | 1123 | |
1059 | 1124 | // Emptying the error log? |
1060 | - if (!empty($_POST['empty_error'])) |
|
1061 | - $smcFunc['db_query']('truncate_table', ' |
|
1125 | + if (!empty($_POST['empty_error'])) { |
|
1126 | + $smcFunc['db_query']('truncate_table', ' |
|
1062 | 1127 | TRUNCATE {db_prefix}log_errors', |
1063 | 1128 | array( |
1064 | 1129 | ) |
1065 | 1130 | ); |
1131 | + } |
|
1066 | 1132 | |
1067 | 1133 | $changes = array(); |
1068 | 1134 | |
1069 | 1135 | // If we're overriding the language follow it through. |
1070 | - if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) |
|
1071 | - $changes['language'] = '\'' . $_GET['lang'] . '\''; |
|
1136 | + if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) { |
|
1137 | + $changes['language'] = '\'' . $_GET['lang'] . '\''; |
|
1138 | + } |
|
1072 | 1139 | |
1073 | 1140 | if (!empty($_POST['maint'])) |
1074 | 1141 | { |
@@ -1080,37 +1147,42 @@ discard block |
||
1080 | 1147 | { |
1081 | 1148 | $changes['mtitle'] = '\'' . addslashes($_POST['maintitle']) . '\''; |
1082 | 1149 | $changes['mmessage'] = '\'' . addslashes($_POST['mainmessage']) . '\''; |
1083 | - } |
|
1084 | - else |
|
1150 | + } else |
|
1085 | 1151 | { |
1086 | 1152 | $changes['mtitle'] = '\'Upgrading the forum...\''; |
1087 | 1153 | $changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum. It will only be a minute ;).\''; |
1088 | 1154 | } |
1089 | 1155 | } |
1090 | 1156 | |
1091 | - if ($command_line) |
|
1092 | - echo ' * Updating Settings.php...'; |
|
1157 | + if ($command_line) { |
|
1158 | + echo ' * Updating Settings.php...'; |
|
1159 | + } |
|
1093 | 1160 | |
1094 | 1161 | // Backup the current one first. |
1095 | 1162 | copy($boarddir . '/Settings.php', $boarddir . '/Settings_bak.php'); |
1096 | 1163 | |
1097 | 1164 | // Fix some old paths. |
1098 | - if (substr($boarddir, 0, 1) == '.') |
|
1099 | - $changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\''; |
|
1165 | + if (substr($boarddir, 0, 1) == '.') { |
|
1166 | + $changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\''; |
|
1167 | + } |
|
1100 | 1168 | |
1101 | - if (substr($sourcedir, 0, 1) == '.') |
|
1102 | - $changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\''; |
|
1169 | + if (substr($sourcedir, 0, 1) == '.') { |
|
1170 | + $changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\''; |
|
1171 | + } |
|
1103 | 1172 | |
1104 | - if (empty($cachedir) || substr($cachedir, 0, 1) == '.') |
|
1105 | - $changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\''; |
|
1173 | + if (empty($cachedir) || substr($cachedir, 0, 1) == '.') { |
|
1174 | + $changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\''; |
|
1175 | + } |
|
1106 | 1176 | |
1107 | 1177 | // Not had the database type added before? |
1108 | - if (empty($db_type)) |
|
1109 | - $changes['db_type'] = 'mysql'; |
|
1178 | + if (empty($db_type)) { |
|
1179 | + $changes['db_type'] = 'mysql'; |
|
1180 | + } |
|
1110 | 1181 | |
1111 | 1182 | // For now we offer a option, this may change in future versions when mysql is completely removed. |
1112 | - if (!empty($_POST['convertMysql']) && $db_type == 'mysql') |
|
1113 | - $changes['db_type'] = '\'mysqli\''; |
|
1183 | + if (!empty($_POST['convertMysql']) && $db_type == 'mysql') { |
|
1184 | + $changes['db_type'] = '\'mysqli\''; |
|
1185 | + } |
|
1114 | 1186 | |
1115 | 1187 | // If they have a "host:port" setup for the host, split that into separate values |
1116 | 1188 | // You should never have a : in the hostname if you're not on MySQL, but better safe than sorry |
@@ -1121,28 +1193,31 @@ discard block |
||
1121 | 1193 | $changes['db_server'] = '\'' . $db_server . '\''; |
1122 | 1194 | |
1123 | 1195 | // Only set this if we're not using the default port |
1124 | - if ($db_port != ini_get('mysql' . ($db_type == 'mysqli' || !empty($_POST['convertMysql']) ? 'i' : '') . '.default_port')) |
|
1125 | - $changes['db_port'] = (int) $db_port; |
|
1126 | - } |
|
1127 | - elseif(!empty($db_port)) |
|
1196 | + if ($db_port != ini_get('mysql' . ($db_type == 'mysqli' || !empty($_POST['convertMysql']) ? 'i' : '') . '.default_port')) { |
|
1197 | + $changes['db_port'] = (int) $db_port; |
|
1198 | + } |
|
1199 | + } elseif(!empty($db_port)) |
|
1128 | 1200 | { |
1129 | 1201 | // If db_port is set and is the same as the default, set it to '' |
1130 | 1202 | if ($db_type == 'mysql' || $db_type == 'mysqli') |
1131 | 1203 | { |
1132 | - if ($db_port == ini_get('mysql' . ($db_type == 'mysqli' || !empty($_POST['convertMysql']) ? 'i' : '') . '.default_port')) |
|
1133 | - $changes['db_port'] = '\'\''; |
|
1134 | - elseif ($db_type == 'postgresql' && $db_port == 5432) |
|
1135 | - $changes['db_port'] = '\'\''; |
|
1204 | + if ($db_port == ini_get('mysql' . ($db_type == 'mysqli' || !empty($_POST['convertMysql']) ? 'i' : '') . '.default_port')) { |
|
1205 | + $changes['db_port'] = '\'\''; |
|
1206 | + } elseif ($db_type == 'postgresql' && $db_port == 5432) { |
|
1207 | + $changes['db_port'] = '\'\''; |
|
1208 | + } |
|
1136 | 1209 | } |
1137 | 1210 | } |
1138 | 1211 | |
1139 | 1212 | // Maybe we haven't had this option yet? |
1140 | - if (empty($packagesdir)) |
|
1141 | - $changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\''; |
|
1213 | + if (empty($packagesdir)) { |
|
1214 | + $changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\''; |
|
1215 | + } |
|
1142 | 1216 | |
1143 | 1217 | // Add support for $tasksdir var. |
1144 | - if (empty($tasksdir)) |
|
1145 | - $changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\''; |
|
1218 | + if (empty($tasksdir)) { |
|
1219 | + $changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\''; |
|
1220 | + } |
|
1146 | 1221 | |
1147 | 1222 | // @todo Maybe change the cookie name if going to 1.1, too? |
1148 | 1223 | |
@@ -1187,8 +1262,7 @@ discard block |
||
1187 | 1262 | $found_old = true; |
1188 | 1263 | // Replace the old line with the new code |
1189 | 1264 | $settings_file = str_replace('$db_last_error = ' . $db_last_error . ';', $error_catching_header . $error_catching, $settings_file); |
1190 | - } |
|
1191 | - else |
|
1265 | + } else |
|
1192 | 1266 | { |
1193 | 1267 | $found_old = false; |
1194 | 1268 | // We want the comments as well as the code... |
@@ -1219,8 +1293,9 @@ discard block |
||
1219 | 1293 | fclose($file); |
1220 | 1294 | } |
1221 | 1295 | |
1222 | - if ($command_line) |
|
1223 | - echo ' Successful.' . "\n"; |
|
1296 | + if ($command_line) { |
|
1297 | + echo ' Successful.' . "\n"; |
|
1298 | + } |
|
1224 | 1299 | |
1225 | 1300 | // Are we doing debug? |
1226 | 1301 | if (isset($_POST['debug'])) |
@@ -1230,8 +1305,9 @@ discard block |
||
1230 | 1305 | } |
1231 | 1306 | |
1232 | 1307 | // If we're not backing up then jump one. |
1233 | - if (empty($_POST['backup'])) |
|
1234 | - $upcontext['current_step']++; |
|
1308 | + if (empty($_POST['backup'])) { |
|
1309 | + $upcontext['current_step']++; |
|
1310 | + } |
|
1235 | 1311 | |
1236 | 1312 | // If we've got here then let's proceed to the next step! |
1237 | 1313 | return true; |
@@ -1246,8 +1322,9 @@ discard block |
||
1246 | 1322 | $upcontext['page_title'] = 'Backup Database'; |
1247 | 1323 | |
1248 | 1324 | // Done it already - js wise? |
1249 | - if (!empty($_POST['backup_done'])) |
|
1250 | - return true; |
|
1325 | + if (!empty($_POST['backup_done'])) { |
|
1326 | + return true; |
|
1327 | + } |
|
1251 | 1328 | |
1252 | 1329 | // Some useful stuff here. |
1253 | 1330 | db_extend(); |
@@ -1261,9 +1338,10 @@ discard block |
||
1261 | 1338 | $tables = $smcFunc['db_list_tables']($db, $filter); |
1262 | 1339 | |
1263 | 1340 | $table_names = array(); |
1264 | - foreach ($tables as $table) |
|
1265 | - if (substr($table, 0, 7) !== 'backup_') |
|
1341 | + foreach ($tables as $table) { |
|
1342 | + if (substr($table, 0, 7) !== 'backup_') |
|
1266 | 1343 | $table_names[] = $table; |
1344 | + } |
|
1267 | 1345 | |
1268 | 1346 | $upcontext['table_count'] = count($table_names); |
1269 | 1347 | $upcontext['cur_table_num'] = $_GET['substep']; |
@@ -1273,12 +1351,14 @@ discard block |
||
1273 | 1351 | $file_steps = $upcontext['table_count']; |
1274 | 1352 | |
1275 | 1353 | // What ones have we already done? |
1276 | - foreach ($table_names as $id => $table) |
|
1277 | - if ($id < $_GET['substep']) |
|
1354 | + foreach ($table_names as $id => $table) { |
|
1355 | + if ($id < $_GET['substep']) |
|
1278 | 1356 | $upcontext['previous_tables'][] = $table; |
1357 | + } |
|
1279 | 1358 | |
1280 | - if ($command_line) |
|
1281 | - echo 'Backing Up Tables.'; |
|
1359 | + if ($command_line) { |
|
1360 | + echo 'Backing Up Tables.'; |
|
1361 | + } |
|
1282 | 1362 | |
1283 | 1363 | // If we don't support javascript we backup here. |
1284 | 1364 | if (!$support_js || isset($_GET['xml'])) |
@@ -1297,8 +1377,9 @@ discard block |
||
1297 | 1377 | backupTable($table_names[$substep]); |
1298 | 1378 | |
1299 | 1379 | // If this is XML to keep it nice for the user do one table at a time anyway! |
1300 | - if (isset($_GET['xml'])) |
|
1301 | - return upgradeExit(); |
|
1380 | + if (isset($_GET['xml'])) { |
|
1381 | + return upgradeExit(); |
|
1382 | + } |
|
1302 | 1383 | } |
1303 | 1384 | |
1304 | 1385 | if ($is_debug && $command_line) |
@@ -1331,9 +1412,10 @@ discard block |
||
1331 | 1412 | |
1332 | 1413 | $smcFunc['db_backup_table']($table, 'backup_' . $table); |
1333 | 1414 | |
1334 | - if ($command_line) |
|
1335 | - echo ' done.'; |
|
1336 | -} |
|
1415 | + if ($command_line) { |
|
1416 | + echo ' done.'; |
|
1417 | + } |
|
1418 | + } |
|
1337 | 1419 | |
1338 | 1420 | // Step 2: Everything. |
1339 | 1421 | function DatabaseChanges() |
@@ -1342,8 +1424,9 @@ discard block |
||
1342 | 1424 | global $upcontext, $support_js, $db_type; |
1343 | 1425 | |
1344 | 1426 | // Have we just completed this? |
1345 | - if (!empty($_POST['database_done'])) |
|
1346 | - return true; |
|
1427 | + if (!empty($_POST['database_done'])) { |
|
1428 | + return true; |
|
1429 | + } |
|
1347 | 1430 | |
1348 | 1431 | $upcontext['sub_template'] = isset($_GET['xml']) ? 'database_xml' : 'database_changes'; |
1349 | 1432 | $upcontext['page_title'] = 'Database Changes'; |
@@ -1360,15 +1443,16 @@ discard block |
||
1360 | 1443 | ); |
1361 | 1444 | |
1362 | 1445 | // How many files are there in total? |
1363 | - if (isset($_GET['filecount'])) |
|
1364 | - $upcontext['file_count'] = (int) $_GET['filecount']; |
|
1365 | - else |
|
1446 | + if (isset($_GET['filecount'])) { |
|
1447 | + $upcontext['file_count'] = (int) $_GET['filecount']; |
|
1448 | + } else |
|
1366 | 1449 | { |
1367 | 1450 | $upcontext['file_count'] = 0; |
1368 | 1451 | foreach ($files as $file) |
1369 | 1452 | { |
1370 | - if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) |
|
1371 | - $upcontext['file_count']++; |
|
1453 | + if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) { |
|
1454 | + $upcontext['file_count']++; |
|
1455 | + } |
|
1372 | 1456 | } |
1373 | 1457 | } |
1374 | 1458 | |
@@ -1378,9 +1462,9 @@ discard block |
||
1378 | 1462 | $upcontext['cur_file_num'] = 0; |
1379 | 1463 | foreach ($files as $file) |
1380 | 1464 | { |
1381 | - if ($did_not_do) |
|
1382 | - $did_not_do--; |
|
1383 | - else |
|
1465 | + if ($did_not_do) { |
|
1466 | + $did_not_do--; |
|
1467 | + } else |
|
1384 | 1468 | { |
1385 | 1469 | $upcontext['cur_file_num']++; |
1386 | 1470 | $upcontext['cur_file_name'] = $file[0]; |
@@ -1407,12 +1491,13 @@ discard block |
||
1407 | 1491 | // Flag to move on to the next. |
1408 | 1492 | $upcontext['completed_step'] = true; |
1409 | 1493 | // Did we complete the whole file? |
1410 | - if ($nextFile) |
|
1411 | - $upcontext['current_debug_item_num'] = -1; |
|
1494 | + if ($nextFile) { |
|
1495 | + $upcontext['current_debug_item_num'] = -1; |
|
1496 | + } |
|
1412 | 1497 | return upgradeExit(); |
1498 | + } elseif ($support_js) { |
|
1499 | + break; |
|
1413 | 1500 | } |
1414 | - elseif ($support_js) |
|
1415 | - break; |
|
1416 | 1501 | } |
1417 | 1502 | // Set the progress bar to be right as if we had - even if we hadn't... |
1418 | 1503 | $upcontext['step_progress'] = ($upcontext['cur_file_num'] / $upcontext['file_count']) * 100; |
@@ -1436,8 +1521,9 @@ discard block |
||
1436 | 1521 | global $db_prefix, $upcontext, $boarddir, $packagesdir, $settings, $smcFunc, $command_line; |
1437 | 1522 | |
1438 | 1523 | // Sorry. Not supported for command line users. |
1439 | - if ($command_line) |
|
1440 | - return true; |
|
1524 | + if ($command_line) { |
|
1525 | + return true; |
|
1526 | + } |
|
1441 | 1527 | |
1442 | 1528 | // Skipping first? |
1443 | 1529 | if (!empty($_POST['skip'])) |
@@ -1447,8 +1533,9 @@ discard block |
||
1447 | 1533 | } |
1448 | 1534 | |
1449 | 1535 | // If we get here withOUT SSI we need to redirect to ensure we get it! |
1450 | - if (!isset($_GET['ssi']) || !function_exists('mktree')) |
|
1451 | - redirectLocation('&ssi=1'); |
|
1536 | + if (!isset($_GET['ssi']) || !function_exists('mktree')) { |
|
1537 | + redirectLocation('&ssi=1'); |
|
1538 | + } |
|
1452 | 1539 | |
1453 | 1540 | $upcontext['sub_template'] = 'clean_mods'; |
1454 | 1541 | $upcontext['page_title'] = 'Cleanup Modifications'; |
@@ -1457,8 +1544,9 @@ discard block |
||
1457 | 1544 | $upcontext['skip'] = true; |
1458 | 1545 | |
1459 | 1546 | // If we're on the second redirect continue... |
1460 | - if (isset($_POST['cleandone2'])) |
|
1461 | - return true; |
|
1547 | + if (isset($_POST['cleandone2'])) { |
|
1548 | + return true; |
|
1549 | + } |
|
1462 | 1550 | |
1463 | 1551 | // Do we already know about some writable files? |
1464 | 1552 | if (isset($_POST['writable_files'])) |
@@ -1473,8 +1561,9 @@ discard block |
||
1473 | 1561 | } |
1474 | 1562 | |
1475 | 1563 | // Make sure we have some sort of packages directory. |
1476 | - if (!isset($packagesdir)) |
|
1477 | - $packagesdir = $boarddir . '/Packages'; |
|
1564 | + if (!isset($packagesdir)) { |
|
1565 | + $packagesdir = $boarddir . '/Packages'; |
|
1566 | + } |
|
1478 | 1567 | |
1479 | 1568 | // Load all theme paths.... |
1480 | 1569 | $request = $smcFunc['db_query']('', ' |
@@ -1492,10 +1581,11 @@ discard block |
||
1492 | 1581 | $theme_paths = array(); |
1493 | 1582 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1494 | 1583 | { |
1495 | - if ($row['id_theme'] == 1) |
|
1496 | - $settings['default_' . $row['variable']] = $row['value']; |
|
1497 | - elseif ($row['variable'] == 'theme_dir') |
|
1498 | - $theme_paths[$row['id_theme']][$row['variable']] = $row['value']; |
|
1584 | + if ($row['id_theme'] == 1) { |
|
1585 | + $settings['default_' . $row['variable']] = $row['value']; |
|
1586 | + } elseif ($row['variable'] == 'theme_dir') { |
|
1587 | + $theme_paths[$row['id_theme']][$row['variable']] = $row['value']; |
|
1588 | + } |
|
1499 | 1589 | } |
1500 | 1590 | $smcFunc['db_free_result']($request); |
1501 | 1591 | |
@@ -1519,8 +1609,7 @@ discard block |
||
1519 | 1609 | $status = 'Missing'; |
1520 | 1610 | $status_color = 'red'; |
1521 | 1611 | $result = 'Removed'; |
1522 | - } |
|
1523 | - else |
|
1612 | + } else |
|
1524 | 1613 | { |
1525 | 1614 | $status = 'Installed'; |
1526 | 1615 | $status_color = 'green'; |
@@ -1545,12 +1634,14 @@ discard block |
||
1545 | 1634 | $smcFunc['db_free_result']($request); |
1546 | 1635 | |
1547 | 1636 | // Don't carry on if there are none. |
1548 | - if (empty($upcontext['packages'])) |
|
1549 | - return true; |
|
1637 | + if (empty($upcontext['packages'])) { |
|
1638 | + return true; |
|
1639 | + } |
|
1550 | 1640 | |
1551 | 1641 | // Setup some basics. |
1552 | - if (!empty($upcontext['user']['version'])) |
|
1553 | - $_SESSION['version_emulate'] = $upcontext['user']['version']; |
|
1642 | + if (!empty($upcontext['user']['version'])) { |
|
1643 | + $_SESSION['version_emulate'] = $upcontext['user']['version']; |
|
1644 | + } |
|
1554 | 1645 | |
1555 | 1646 | // Before we get started, don't report notice errors. |
1556 | 1647 | $oldErrorReporting = error_reporting(E_ALL ^ E_NOTICE); |
@@ -1573,34 +1664,40 @@ discard block |
||
1573 | 1664 | foreach ($upcontext['packages'] as $id => $package) |
1574 | 1665 | { |
1575 | 1666 | // Can't do anything about this.... |
1576 | - if ($package['missing_file']) |
|
1577 | - continue; |
|
1667 | + if ($package['missing_file']) { |
|
1668 | + continue; |
|
1669 | + } |
|
1578 | 1670 | |
1579 | 1671 | // Not testing *and* this wasn't checked? |
1580 | - if (!$test && (!isset($_POST['remove']) || !isset($_POST['remove'][$id]))) |
|
1581 | - continue; |
|
1672 | + if (!$test && (!isset($_POST['remove']) || !isset($_POST['remove'][$id]))) { |
|
1673 | + continue; |
|
1674 | + } |
|
1582 | 1675 | |
1583 | 1676 | // What are the themes this was installed into? |
1584 | 1677 | $cur_theme_paths = array(); |
1585 | - foreach ($theme_paths as $tid => $data) |
|
1586 | - if ($tid != 1 && in_array($tid, $package['themes'])) |
|
1678 | + foreach ($theme_paths as $tid => $data) { |
|
1679 | + if ($tid != 1 && in_array($tid, $package['themes'])) |
|
1587 | 1680 | $cur_theme_paths[$tid] = $data; |
1681 | + } |
|
1588 | 1682 | |
1589 | 1683 | // Get the modifications data if applicable. |
1590 | 1684 | $filename = $package['filename']; |
1591 | 1685 | $packageInfo = getPackageInfo($filename); |
1592 | - if (!is_array($packageInfo)) |
|
1593 | - continue; |
|
1686 | + if (!is_array($packageInfo)) { |
|
1687 | + continue; |
|
1688 | + } |
|
1594 | 1689 | |
1595 | 1690 | $info = parsePackageInfo($packageInfo['xml'], $test, 'uninstall'); |
1596 | 1691 | // Also get the reinstall details... |
1597 | - if (isset($_POST['remove'])) |
|
1598 | - $infoInstall = parsePackageInfo($packageInfo['xml'], true); |
|
1692 | + if (isset($_POST['remove'])) { |
|
1693 | + $infoInstall = parsePackageInfo($packageInfo['xml'], true); |
|
1694 | + } |
|
1599 | 1695 | |
1600 | - if (is_file($packagesdir . '/' . $filename)) |
|
1601 | - read_tgz_file($packagesdir . '/' . $filename, $packagesdir . '/temp'); |
|
1602 | - else |
|
1603 | - copytree($packagesdir . '/' . $filename, $packagesdir . '/temp'); |
|
1696 | + if (is_file($packagesdir . '/' . $filename)) { |
|
1697 | + read_tgz_file($packagesdir . '/' . $filename, $packagesdir . '/temp'); |
|
1698 | + } else { |
|
1699 | + copytree($packagesdir . '/' . $filename, $packagesdir . '/temp'); |
|
1700 | + } |
|
1604 | 1701 | |
1605 | 1702 | // Work out how we uninstall... |
1606 | 1703 | $files = array(); |
@@ -1612,16 +1709,18 @@ discard block |
||
1612 | 1709 | if ($change['type'] == 'modification') |
1613 | 1710 | { |
1614 | 1711 | $contents = @file_get_contents($packagesdir . '/temp/' . $upcontext['base_path'] . $change['filename']); |
1615 | - if ($change['boardmod']) |
|
1616 | - $results = parseBoardMod($contents, $test, $change['reverse'], $cur_theme_paths); |
|
1617 | - else |
|
1618 | - $results = parseModification($contents, $test, $change['reverse'], $cur_theme_paths); |
|
1712 | + if ($change['boardmod']) { |
|
1713 | + $results = parseBoardMod($contents, $test, $change['reverse'], $cur_theme_paths); |
|
1714 | + } else { |
|
1715 | + $results = parseModification($contents, $test, $change['reverse'], $cur_theme_paths); |
|
1716 | + } |
|
1619 | 1717 | |
1620 | 1718 | foreach ($results as $action) |
1621 | 1719 | { |
1622 | 1720 | // Something we can remove? Probably means it existed! |
1623 | - if (($action['type'] == 'replace' || $action['type'] == 'append' || (!empty($action['filename']) && $action['type'] == 'failure')) && !in_array($action['filename'], $files)) |
|
1624 | - $files[] = $action['filename']; |
|
1721 | + if (($action['type'] == 'replace' || $action['type'] == 'append' || (!empty($action['filename']) && $action['type'] == 'failure')) && !in_array($action['filename'], $files)) { |
|
1722 | + $files[] = $action['filename']; |
|
1723 | + } |
|
1625 | 1724 | if ($action['type'] == 'failure') |
1626 | 1725 | { |
1627 | 1726 | $upcontext['packages'][$id]['needs_removing'] = true; |
@@ -1637,17 +1736,19 @@ discard block |
||
1637 | 1736 | $upcontext['packages'][$id]['file_count'] = count($files); |
1638 | 1737 | |
1639 | 1738 | // If we've done something save the changes! |
1640 | - if (!$test) |
|
1641 | - package_flush_cache(); |
|
1739 | + if (!$test) { |
|
1740 | + package_flush_cache(); |
|
1741 | + } |
|
1642 | 1742 | |
1643 | 1743 | // Are we attempting to reinstall this thing? |
1644 | 1744 | if (isset($_POST['remove']) && !$test && isset($infoInstall)) |
1645 | 1745 | { |
1646 | 1746 | // Need to extract again I'm afraid. |
1647 | - if (is_file($packagesdir . '/' . $filename)) |
|
1648 | - read_tgz_file($packagesdir . '/' . $filename, $packagesdir . '/temp'); |
|
1649 | - else |
|
1650 | - copytree($packagesdir . '/' . $filename, $packagesdir . '/temp'); |
|
1747 | + if (is_file($packagesdir . '/' . $filename)) { |
|
1748 | + read_tgz_file($packagesdir . '/' . $filename, $packagesdir . '/temp'); |
|
1749 | + } else { |
|
1750 | + copytree($packagesdir . '/' . $filename, $packagesdir . '/temp'); |
|
1751 | + } |
|
1651 | 1752 | |
1652 | 1753 | $errors = false; |
1653 | 1754 | $upcontext['packages'][$id]['result'] = 'Removed'; |
@@ -1656,15 +1757,17 @@ discard block |
||
1656 | 1757 | if ($change['type'] == 'modification') |
1657 | 1758 | { |
1658 | 1759 | $contents = @file_get_contents($packagesdir . '/temp/' . $upcontext['base_path'] . $change['filename']); |
1659 | - if ($change['boardmod']) |
|
1660 | - $results = parseBoardMod($contents, true, $change['reverse'], $cur_theme_paths); |
|
1661 | - else |
|
1662 | - $results = parseModification($contents, true, $change['reverse'], $cur_theme_paths); |
|
1760 | + if ($change['boardmod']) { |
|
1761 | + $results = parseBoardMod($contents, true, $change['reverse'], $cur_theme_paths); |
|
1762 | + } else { |
|
1763 | + $results = parseModification($contents, true, $change['reverse'], $cur_theme_paths); |
|
1764 | + } |
|
1663 | 1765 | |
1664 | 1766 | // Are there any errors? |
1665 | - foreach ($results as $action) |
|
1666 | - if ($action['type'] == 'failure') |
|
1767 | + foreach ($results as $action) { |
|
1768 | + if ($action['type'] == 'failure') |
|
1667 | 1769 | $errors = true; |
1770 | + } |
|
1668 | 1771 | } |
1669 | 1772 | } |
1670 | 1773 | if (!$errors) |
@@ -1677,10 +1780,11 @@ discard block |
||
1677 | 1780 | if ($change['type'] == 'modification') |
1678 | 1781 | { |
1679 | 1782 | $contents = @file_get_contents($packagesdir . '/temp/' . $upcontext['base_path'] . $change['filename']); |
1680 | - if ($change['boardmod']) |
|
1681 | - $results = parseBoardMod($contents, false, $change['reverse'], $cur_theme_paths); |
|
1682 | - else |
|
1683 | - $results = parseModification($contents, false, $change['reverse'], $cur_theme_paths); |
|
1783 | + if ($change['boardmod']) { |
|
1784 | + $results = parseBoardMod($contents, false, $change['reverse'], $cur_theme_paths); |
|
1785 | + } else { |
|
1786 | + $results = parseModification($contents, false, $change['reverse'], $cur_theme_paths); |
|
1787 | + } |
|
1684 | 1788 | } |
1685 | 1789 | } |
1686 | 1790 | |
@@ -1699,9 +1803,10 @@ discard block |
||
1699 | 1803 | $writable_files = array(); |
1700 | 1804 | foreach ($upcontext['packages'] as $package) |
1701 | 1805 | { |
1702 | - if (!empty($package['files'])) |
|
1703 | - foreach ($package['files'] as $file) |
|
1806 | + if (!empty($package['files'])) { |
|
1807 | + foreach ($package['files'] as $file) |
|
1704 | 1808 | $writable_files[] = $file; |
1809 | + } |
|
1705 | 1810 | } |
1706 | 1811 | |
1707 | 1812 | if (!empty($writable_files)) |
@@ -1709,13 +1814,15 @@ discard block |
||
1709 | 1814 | $writable_files = array_unique($writable_files); |
1710 | 1815 | $upcontext['writable_files'] = $writable_files; |
1711 | 1816 | |
1712 | - if (!makeFilesWritable($writable_files)) |
|
1713 | - return false; |
|
1817 | + if (!makeFilesWritable($writable_files)) { |
|
1818 | + return false; |
|
1819 | + } |
|
1714 | 1820 | } |
1715 | 1821 | } |
1716 | 1822 | |
1717 | - if (file_exists($packagesdir . '/temp')) |
|
1718 | - deltree($packagesdir . '/temp'); |
|
1823 | + if (file_exists($packagesdir . '/temp')) { |
|
1824 | + deltree($packagesdir . '/temp'); |
|
1825 | + } |
|
1719 | 1826 | |
1720 | 1827 | // Removing/Reinstalling any packages? |
1721 | 1828 | if (isset($_POST['remove'])) |
@@ -1723,32 +1830,35 @@ discard block |
||
1723 | 1830 | $deletes = array(); |
1724 | 1831 | foreach ($_POST['remove'] as $id => $dummy) |
1725 | 1832 | { |
1726 | - if (!in_array((int) $id, $reinstall_worked)) |
|
1727 | - $deletes[] = (int) $id; |
|
1833 | + if (!in_array((int) $id, $reinstall_worked)) { |
|
1834 | + $deletes[] = (int) $id; |
|
1835 | + } |
|
1728 | 1836 | } |
1729 | 1837 | |
1730 | - if (!empty($deletes)) |
|
1731 | - upgrade_query( ' |
|
1838 | + if (!empty($deletes)) { |
|
1839 | + upgrade_query( ' |
|
1732 | 1840 | UPDATE ' . $db_prefix . 'log_packages |
1733 | 1841 | SET install_state = 0 |
1734 | 1842 | WHERE id_install IN (' . implode(',', $deletes) . ')'); |
1843 | + } |
|
1735 | 1844 | |
1736 | 1845 | // Ensure we don't lose our changes! |
1737 | 1846 | package_put_contents($packagesdir . '/installed.list', time()); |
1738 | 1847 | |
1739 | 1848 | $upcontext['sub_template'] = 'cleanup_done'; |
1740 | 1849 | return false; |
1741 | - } |
|
1742 | - else |
|
1850 | + } else |
|
1743 | 1851 | { |
1744 | 1852 | $allgood = true; |
1745 | 1853 | // Is there actually anything that needs our attention? |
1746 | - foreach ($upcontext['packages'] as $package) |
|
1747 | - if ($package['color'] != 'green') |
|
1854 | + foreach ($upcontext['packages'] as $package) { |
|
1855 | + if ($package['color'] != 'green') |
|
1748 | 1856 | $allgood = false; |
1857 | + } |
|
1749 | 1858 | |
1750 | - if ($allgood) |
|
1751 | - return true; |
|
1859 | + if ($allgood) { |
|
1860 | + return true; |
|
1861 | + } |
|
1752 | 1862 | } |
1753 | 1863 | |
1754 | 1864 | $_GET['substep'] = 0; |
@@ -1762,8 +1872,9 @@ discard block |
||
1762 | 1872 | global $command_line, $language, $upcontext, $boarddir, $sourcedir, $forum_version, $user_info, $maintenance, $smcFunc, $db_type; |
1763 | 1873 | |
1764 | 1874 | // Now it's nice to have some of the basic SMF source files. |
1765 | - if (!isset($_GET['ssi']) && !$command_line) |
|
1766 | - redirectLocation('&ssi=1'); |
|
1875 | + if (!isset($_GET['ssi']) && !$command_line) { |
|
1876 | + redirectLocation('&ssi=1'); |
|
1877 | + } |
|
1767 | 1878 | |
1768 | 1879 | $upcontext['sub_template'] = 'upgrade_complete'; |
1769 | 1880 | $upcontext['page_title'] = 'Upgrade Complete'; |
@@ -1779,14 +1890,16 @@ discard block |
||
1779 | 1890 | // Are we in maintenance mode? |
1780 | 1891 | if (isset($upcontext['user']['main'])) |
1781 | 1892 | { |
1782 | - if ($command_line) |
|
1783 | - echo ' * '; |
|
1893 | + if ($command_line) { |
|
1894 | + echo ' * '; |
|
1895 | + } |
|
1784 | 1896 | $upcontext['removed_maintenance'] = true; |
1785 | 1897 | $changes['maintenance'] = $upcontext['user']['main']; |
1786 | 1898 | } |
1787 | 1899 | // Otherwise if somehow we are in 2 let's go to 1. |
1788 | - elseif (!empty($maintenance) && $maintenance == 2) |
|
1789 | - $changes['maintenance'] = 1; |
|
1900 | + elseif (!empty($maintenance) && $maintenance == 2) { |
|
1901 | + $changes['maintenance'] = 1; |
|
1902 | + } |
|
1790 | 1903 | |
1791 | 1904 | // Wipe this out... |
1792 | 1905 | $upcontext['user'] = array(); |
@@ -1802,9 +1915,9 @@ discard block |
||
1802 | 1915 | $upcontext['can_delete_script'] = is_writable(dirname(__FILE__)) || is_writable(__FILE__); |
1803 | 1916 | |
1804 | 1917 | // Now is the perfect time to fetch the SM files. |
1805 | - if ($command_line) |
|
1806 | - cli_scheduled_fetchSMfiles(); |
|
1807 | - else |
|
1918 | + if ($command_line) { |
|
1919 | + cli_scheduled_fetchSMfiles(); |
|
1920 | + } else |
|
1808 | 1921 | { |
1809 | 1922 | require_once($sourcedir . '/ScheduledTasks.php'); |
1810 | 1923 | $forum_version = SMF_VERSION; // The variable is usually defined in index.php so lets just use the constant to do it for us. |
@@ -1812,8 +1925,9 @@ discard block |
||
1812 | 1925 | } |
1813 | 1926 | |
1814 | 1927 | // Log what we've done. |
1815 | - if (empty($user_info['id'])) |
|
1816 | - $user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0; |
|
1928 | + if (empty($user_info['id'])) { |
|
1929 | + $user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0; |
|
1930 | + } |
|
1817 | 1931 | |
1818 | 1932 | // Log the action manually, so CLI still works. |
1819 | 1933 | $smcFunc['db_insert']('', |
@@ -1832,8 +1946,9 @@ discard block |
||
1832 | 1946 | |
1833 | 1947 | // Save the current database version. |
1834 | 1948 | $server_version = $smcFunc['db_server_info'](); |
1835 | - if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) |
|
1836 | - updateSettings(array('db_mysql_group_by_fix' => '1')); |
|
1949 | + if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) { |
|
1950 | + updateSettings(array('db_mysql_group_by_fix' => '1')); |
|
1951 | + } |
|
1837 | 1952 | |
1838 | 1953 | if ($command_line) |
1839 | 1954 | { |
@@ -1845,8 +1960,9 @@ discard block |
||
1845 | 1960 | |
1846 | 1961 | // Make sure it says we're done. |
1847 | 1962 | $upcontext['overall_percent'] = 100; |
1848 | - if (isset($upcontext['step_progress'])) |
|
1849 | - unset($upcontext['step_progress']); |
|
1963 | + if (isset($upcontext['step_progress'])) { |
|
1964 | + unset($upcontext['step_progress']); |
|
1965 | + } |
|
1850 | 1966 | |
1851 | 1967 | $_GET['substep'] = 0; |
1852 | 1968 | return false; |
@@ -1857,8 +1973,9 @@ discard block |
||
1857 | 1973 | { |
1858 | 1974 | global $sourcedir, $language, $forum_version, $modSettings, $smcFunc; |
1859 | 1975 | |
1860 | - if (empty($modSettings['time_format'])) |
|
1861 | - $modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p'; |
|
1976 | + if (empty($modSettings['time_format'])) { |
|
1977 | + $modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p'; |
|
1978 | + } |
|
1862 | 1979 | |
1863 | 1980 | // What files do we want to get |
1864 | 1981 | $request = $smcFunc['db_query']('', ' |
@@ -1892,8 +2009,9 @@ discard block |
||
1892 | 2009 | $file_data = fetch_web_data($url); |
1893 | 2010 | |
1894 | 2011 | // If we got an error - give up - the site might be down. |
1895 | - if ($file_data === false) |
|
1896 | - return throw_error(sprintf('Could not retrieve the file %1$s.', $url)); |
|
2012 | + if ($file_data === false) { |
|
2013 | + return throw_error(sprintf('Could not retrieve the file %1$s.', $url)); |
|
2014 | + } |
|
1897 | 2015 | |
1898 | 2016 | // Save the file to the database. |
1899 | 2017 | $smcFunc['db_query']('substring', ' |
@@ -1935,8 +2053,9 @@ discard block |
||
1935 | 2053 | $themeData = array(); |
1936 | 2054 | foreach ($values as $variable => $value) |
1937 | 2055 | { |
1938 | - if (!isset($value) || $value === null) |
|
1939 | - $value = 0; |
|
2056 | + if (!isset($value) || $value === null) { |
|
2057 | + $value = 0; |
|
2058 | + } |
|
1940 | 2059 | |
1941 | 2060 | $themeData[] = array(0, 1, $variable, $value); |
1942 | 2061 | } |
@@ -1965,8 +2084,9 @@ discard block |
||
1965 | 2084 | |
1966 | 2085 | foreach ($values as $variable => $value) |
1967 | 2086 | { |
1968 | - if (empty($modSettings[$value[0]])) |
|
1969 | - continue; |
|
2087 | + if (empty($modSettings[$value[0]])) { |
|
2088 | + continue; |
|
2089 | + } |
|
1970 | 2090 | |
1971 | 2091 | $smcFunc['db_query']('', ' |
1972 | 2092 | INSERT IGNORE INTO {db_prefix}themes |
@@ -1999,8 +2119,9 @@ discard block |
||
1999 | 2119 | |
2000 | 2120 | $settingsArray = file($boarddir . '/Settings_bak.php'); |
2001 | 2121 | |
2002 | - if (count($settingsArray) == 1) |
|
2003 | - $settingsArray = preg_split('~[\r\n]~', $settingsArray[0]); |
|
2122 | + if (count($settingsArray) == 1) { |
|
2123 | + $settingsArray = preg_split('~[\r\n]~', $settingsArray[0]); |
|
2124 | + } |
|
2004 | 2125 | |
2005 | 2126 | for ($i = 0, $n = count($settingsArray); $i < $n; $i++) |
2006 | 2127 | { |
@@ -2013,9 +2134,9 @@ discard block |
||
2013 | 2134 | { |
2014 | 2135 | if (isset($settingsArray[$i]) && strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0) |
2015 | 2136 | { |
2016 | - if ($val == '#remove#') |
|
2017 | - unset($settingsArray[$i]); |
|
2018 | - else |
|
2137 | + if ($val == '#remove#') { |
|
2138 | + unset($settingsArray[$i]); |
|
2139 | + } else |
|
2019 | 2140 | { |
2020 | 2141 | $comment = strstr(substr($settingsArray[$i], strpos($settingsArray[$i], ';')), '#'); |
2021 | 2142 | $settingsArray[$i] = '$' . $var . ' = ' . $val . ';' . ($comment != '' ? "\t\t" . $comment : "\n"); |
@@ -2027,22 +2148,25 @@ discard block |
||
2027 | 2148 | } |
2028 | 2149 | if (isset($settingsArray[$i])) |
2029 | 2150 | { |
2030 | - if (trim(substr($settingsArray[$i], 0, 2)) == '?' . '>') |
|
2031 | - $end = $i; |
|
2151 | + if (trim(substr($settingsArray[$i], 0, 2)) == '?' . '>') { |
|
2152 | + $end = $i; |
|
2153 | + } |
|
2032 | 2154 | } |
2033 | 2155 | } |
2034 | 2156 | |
2035 | 2157 | // Assume end-of-file if the end wasn't found. |
2036 | - if (empty($end) || $end < 10) |
|
2037 | - $end = count($settingsArray); |
|
2158 | + if (empty($end) || $end < 10) { |
|
2159 | + $end = count($settingsArray); |
|
2160 | + } |
|
2038 | 2161 | |
2039 | 2162 | if (!empty($config_vars)) |
2040 | 2163 | { |
2041 | 2164 | $settingsArray[$end++] = ''; |
2042 | 2165 | foreach ($config_vars as $var => $val) |
2043 | 2166 | { |
2044 | - if ($val != '#remove#') |
|
2045 | - $settingsArray[$end++] = '$' . $var . ' = ' . $val . ';' . "\n"; |
|
2167 | + if ($val != '#remove#') { |
|
2168 | + $settingsArray[$end++] = '$' . $var . ' = ' . $val . ';' . "\n"; |
|
2169 | + } |
|
2046 | 2170 | } |
2047 | 2171 | } |
2048 | 2172 | // This should be the last line and even last bytes of the file. |
@@ -2055,8 +2179,9 @@ discard block |
||
2055 | 2179 | $fp = fopen($boarddir . '/Settings.php', 'r+'); |
2056 | 2180 | for ($i = 0; $i < $end; $i++) |
2057 | 2181 | { |
2058 | - if (isset($settingsArray[$i])) |
|
2059 | - fwrite($fp, strtr($settingsArray[$i], "\r", '')); |
|
2182 | + if (isset($settingsArray[$i])) { |
|
2183 | + fwrite($fp, strtr($settingsArray[$i], "\r", '')); |
|
2184 | + } |
|
2060 | 2185 | } |
2061 | 2186 | fwrite($fp, rtrim($settingsArray[$i])); |
2062 | 2187 | fclose($fp); |
@@ -2087,8 +2212,9 @@ discard block |
||
2087 | 2212 | global $smcFunc; |
2088 | 2213 | static $member_groups = array(); |
2089 | 2214 | |
2090 | - if (!empty($member_groups)) |
|
2091 | - return $member_groups; |
|
2215 | + if (!empty($member_groups)) { |
|
2216 | + return $member_groups; |
|
2217 | + } |
|
2092 | 2218 | |
2093 | 2219 | $request = $smcFunc['db_query']('', ' |
2094 | 2220 | SELECT group_name, id_group |
@@ -2113,8 +2239,9 @@ discard block |
||
2113 | 2239 | ) |
2114 | 2240 | ); |
2115 | 2241 | } |
2116 | - while ($row = $smcFunc['db_fetch_row']($request)) |
|
2117 | - $member_groups[trim($row[0])] = $row[1]; |
|
2242 | + while ($row = $smcFunc['db_fetch_row']($request)) { |
|
2243 | + $member_groups[trim($row[0])] = $row[1]; |
|
2244 | + } |
|
2118 | 2245 | $smcFunc['db_free_result']($request); |
2119 | 2246 | |
2120 | 2247 | return $member_groups; |
@@ -2167,10 +2294,11 @@ discard block |
||
2167 | 2294 | { |
2168 | 2295 | global $support_js; |
2169 | 2296 | |
2170 | - if ($support_js) |
|
2171 | - return true; |
|
2172 | - else |
|
2173 | - echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline; |
|
2297 | + if ($support_js) { |
|
2298 | + return true; |
|
2299 | + } else { |
|
2300 | + echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline; |
|
2301 | + } |
|
2174 | 2302 | } |
2175 | 2303 | } |
2176 | 2304 | |
@@ -2188,8 +2316,9 @@ discard block |
||
2188 | 2316 | 'db_error_skip' => true, |
2189 | 2317 | ) |
2190 | 2318 | ); |
2191 | - if ($smcFunc['db_num_rows']($request) === 0) |
|
2192 | - die('Unable to find members table!'); |
|
2319 | + if ($smcFunc['db_num_rows']($request) === 0) { |
|
2320 | + die('Unable to find members table!'); |
|
2321 | + } |
|
2193 | 2322 | $table_status = $smcFunc['db_fetch_assoc']($request); |
2194 | 2323 | $smcFunc['db_free_result']($request); |
2195 | 2324 | |
@@ -2204,17 +2333,20 @@ discard block |
||
2204 | 2333 | ) |
2205 | 2334 | ); |
2206 | 2335 | // Got something? |
2207 | - if ($smcFunc['db_num_rows']($request) !== 0) |
|
2208 | - $collation_info = $smcFunc['db_fetch_assoc']($request); |
|
2336 | + if ($smcFunc['db_num_rows']($request) !== 0) { |
|
2337 | + $collation_info = $smcFunc['db_fetch_assoc']($request); |
|
2338 | + } |
|
2209 | 2339 | $smcFunc['db_free_result']($request); |
2210 | 2340 | |
2211 | 2341 | // Excellent! |
2212 | - if (!empty($collation_info['Collation']) && !empty($collation_info['Charset'])) |
|
2213 | - $db_collation = ' CHARACTER SET ' . $collation_info['Charset'] . ' COLLATE ' . $collation_info['Collation']; |
|
2342 | + if (!empty($collation_info['Collation']) && !empty($collation_info['Charset'])) { |
|
2343 | + $db_collation = ' CHARACTER SET ' . $collation_info['Charset'] . ' COLLATE ' . $collation_info['Collation']; |
|
2344 | + } |
|
2214 | 2345 | } |
2215 | 2346 | } |
2216 | - if (empty($db_collation)) |
|
2217 | - $db_collation = ''; |
|
2347 | + if (empty($db_collation)) { |
|
2348 | + $db_collation = ''; |
|
2349 | + } |
|
2218 | 2350 | |
2219 | 2351 | $endl = $command_line ? "\n" : '<br>' . "\n"; |
2220 | 2352 | |
@@ -2226,8 +2358,9 @@ discard block |
||
2226 | 2358 | $last_step = ''; |
2227 | 2359 | |
2228 | 2360 | // Make sure all newly created tables will have the proper characters set. |
2229 | - if (isset($db_character_set) && $db_character_set === 'utf8') |
|
2230 | - $lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines); |
|
2361 | + if (isset($db_character_set) && $db_character_set === 'utf8') { |
|
2362 | + $lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines); |
|
2363 | + } |
|
2231 | 2364 | |
2232 | 2365 | // Count the total number of steps within this file - for progress. |
2233 | 2366 | $file_steps = substr_count(implode('', $lines), '---#'); |
@@ -2247,15 +2380,18 @@ discard block |
||
2247 | 2380 | $do_current = $substep >= $_GET['substep']; |
2248 | 2381 | |
2249 | 2382 | // Get rid of any comments in the beginning of the line... |
2250 | - if (substr(trim($line), 0, 2) === '/*') |
|
2251 | - $line = preg_replace('~/\*.+?\*/~', '', $line); |
|
2383 | + if (substr(trim($line), 0, 2) === '/*') { |
|
2384 | + $line = preg_replace('~/\*.+?\*/~', '', $line); |
|
2385 | + } |
|
2252 | 2386 | |
2253 | 2387 | // Always flush. Flush, flush, flush. Flush, flush, flush, flush! FLUSH! |
2254 | - if ($is_debug && !$support_js && $command_line) |
|
2255 | - flush(); |
|
2388 | + if ($is_debug && !$support_js && $command_line) { |
|
2389 | + flush(); |
|
2390 | + } |
|
2256 | 2391 | |
2257 | - if (trim($line) === '') |
|
2258 | - continue; |
|
2392 | + if (trim($line) === '') { |
|
2393 | + continue; |
|
2394 | + } |
|
2259 | 2395 | |
2260 | 2396 | if (trim(substr($line, 0, 3)) === '---') |
2261 | 2397 | { |
@@ -2265,8 +2401,9 @@ discard block |
||
2265 | 2401 | if (trim($current_data) != '' && $type !== '}') |
2266 | 2402 | { |
2267 | 2403 | $upcontext['error_message'] = 'Error in upgrade script - line ' . $line_number . '!' . $endl; |
2268 | - if ($command_line) |
|
2269 | - echo $upcontext['error_message']; |
|
2404 | + if ($command_line) { |
|
2405 | + echo $upcontext['error_message']; |
|
2406 | + } |
|
2270 | 2407 | } |
2271 | 2408 | |
2272 | 2409 | if ($type == ' ') |
@@ -2284,17 +2421,18 @@ discard block |
||
2284 | 2421 | if ($do_current) |
2285 | 2422 | { |
2286 | 2423 | $upcontext['actioned_items'][] = $last_step; |
2287 | - if ($command_line) |
|
2288 | - echo ' * '; |
|
2424 | + if ($command_line) { |
|
2425 | + echo ' * '; |
|
2426 | + } |
|
2289 | 2427 | } |
2290 | - } |
|
2291 | - elseif ($type == '#') |
|
2428 | + } elseif ($type == '#') |
|
2292 | 2429 | { |
2293 | 2430 | $upcontext['step_progress'] += (100 / $upcontext['file_count']) / $file_steps; |
2294 | 2431 | |
2295 | 2432 | $upcontext['current_debug_item_num']++; |
2296 | - if (trim($line) != '---#') |
|
2297 | - $upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4))); |
|
2433 | + if (trim($line) != '---#') { |
|
2434 | + $upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4))); |
|
2435 | + } |
|
2298 | 2436 | |
2299 | 2437 | // Have we already done something? |
2300 | 2438 | if (isset($_GET['xml']) && $done_something) |
@@ -2305,34 +2443,36 @@ discard block |
||
2305 | 2443 | |
2306 | 2444 | if ($do_current) |
2307 | 2445 | { |
2308 | - if (trim($line) == '---#' && $command_line) |
|
2309 | - echo ' done.', $endl; |
|
2310 | - elseif ($command_line) |
|
2311 | - echo ' +++ ', rtrim(substr($line, 4)); |
|
2312 | - elseif (trim($line) != '---#') |
|
2446 | + if (trim($line) == '---#' && $command_line) { |
|
2447 | + echo ' done.', $endl; |
|
2448 | + } elseif ($command_line) { |
|
2449 | + echo ' +++ ', rtrim(substr($line, 4)); |
|
2450 | + } elseif (trim($line) != '---#') |
|
2313 | 2451 | { |
2314 | - if ($is_debug) |
|
2315 | - $upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4))); |
|
2452 | + if ($is_debug) { |
|
2453 | + $upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4))); |
|
2454 | + } |
|
2316 | 2455 | } |
2317 | 2456 | } |
2318 | 2457 | |
2319 | 2458 | if ($substep < $_GET['substep'] && $substep + 1 >= $_GET['substep']) |
2320 | 2459 | { |
2321 | - if ($command_line) |
|
2322 | - echo ' * '; |
|
2323 | - else |
|
2324 | - $upcontext['actioned_items'][] = $last_step; |
|
2460 | + if ($command_line) { |
|
2461 | + echo ' * '; |
|
2462 | + } else { |
|
2463 | + $upcontext['actioned_items'][] = $last_step; |
|
2464 | + } |
|
2325 | 2465 | } |
2326 | 2466 | |
2327 | 2467 | // Small step - only if we're actually doing stuff. |
2328 | - if ($do_current) |
|
2329 | - nextSubstep(++$substep); |
|
2330 | - else |
|
2331 | - $substep++; |
|
2332 | - } |
|
2333 | - elseif ($type == '{') |
|
2334 | - $current_type = 'code'; |
|
2335 | - elseif ($type == '}') |
|
2468 | + if ($do_current) { |
|
2469 | + nextSubstep(++$substep); |
|
2470 | + } else { |
|
2471 | + $substep++; |
|
2472 | + } |
|
2473 | + } elseif ($type == '{') { |
|
2474 | + $current_type = 'code'; |
|
2475 | + } elseif ($type == '}') |
|
2336 | 2476 | { |
2337 | 2477 | $current_type = 'sql'; |
2338 | 2478 | |
@@ -2345,8 +2485,9 @@ discard block |
||
2345 | 2485 | if (eval('global $db_prefix, $modSettings, $smcFunc; ' . $current_data) === false) |
2346 | 2486 | { |
2347 | 2487 | $upcontext['error_message'] = 'Error in upgrade script ' . basename($filename) . ' on line ' . $line_number . '!' . $endl; |
2348 | - if ($command_line) |
|
2349 | - echo $upcontext['error_message']; |
|
2488 | + if ($command_line) { |
|
2489 | + echo $upcontext['error_message']; |
|
2490 | + } |
|
2350 | 2491 | } |
2351 | 2492 | |
2352 | 2493 | // Done with code! |
@@ -2426,8 +2567,9 @@ discard block |
||
2426 | 2567 | $db_unbuffered = false; |
2427 | 2568 | |
2428 | 2569 | // Failure?! |
2429 | - if ($result !== false) |
|
2430 | - return $result; |
|
2570 | + if ($result !== false) { |
|
2571 | + return $result; |
|
2572 | + } |
|
2431 | 2573 | |
2432 | 2574 | $db_error_message = $smcFunc['db_error']($db_connection); |
2433 | 2575 | // If MySQL we do something more clever. |
@@ -2457,17 +2599,16 @@ discard block |
||
2457 | 2599 | { |
2458 | 2600 | mysql_query('REPAIR TABLE `' . $match[1] . '`'); |
2459 | 2601 | $result = mysql_query($string); |
2460 | - } |
|
2461 | - else |
|
2602 | + } else |
|
2462 | 2603 | { |
2463 | 2604 | mysqli_query($db_connection, 'REPAIR TABLE `' . $match[1] . '`'); |
2464 | 2605 | $result = mysqli_query($db_connection, $string); |
2465 | 2606 | } |
2466 | - if ($result !== false) |
|
2467 | - return $result; |
|
2607 | + if ($result !== false) { |
|
2608 | + return $result; |
|
2609 | + } |
|
2468 | 2610 | } |
2469 | - } |
|
2470 | - elseif ($mysql_errno == 2013) |
|
2611 | + } elseif ($mysql_errno == 2013) |
|
2471 | 2612 | { |
2472 | 2613 | $db_connection = mysql_connect($db_server, $db_user, $db_passwd); |
2473 | 2614 | if ($db_type == 'mysql') |
@@ -2476,54 +2617,61 @@ discard block |
||
2476 | 2617 | if ($db_connection) |
2477 | 2618 | { |
2478 | 2619 | $result = mysql_query($string); |
2479 | - if ($result !== false) |
|
2480 | - return $result; |
|
2620 | + if ($result !== false) { |
|
2621 | + return $result; |
|
2622 | + } |
|
2481 | 2623 | } |
2482 | - } |
|
2483 | - else |
|
2624 | + } else |
|
2484 | 2625 | { |
2485 | 2626 | mysqli_select_db($db_connection, $db_name); |
2486 | 2627 | if ($db_connection) |
2487 | 2628 | { |
2488 | 2629 | $result = mysqli_query($db_connection, $string); |
2489 | - if ($result !== false) |
|
2490 | - return $result; |
|
2630 | + if ($result !== false) { |
|
2631 | + return $result; |
|
2632 | + } |
|
2491 | 2633 | } |
2492 | 2634 | } |
2493 | 2635 | } |
2494 | 2636 | // Duplicate column name... should be okay ;). |
2495 | - elseif (in_array($mysql_errno, array(1060, 1061, 1068, 1091))) |
|
2496 | - return false; |
|
2637 | + elseif (in_array($mysql_errno, array(1060, 1061, 1068, 1091))) { |
|
2638 | + return false; |
|
2639 | + } |
|
2497 | 2640 | // Duplicate insert... make sure it's the proper type of query ;). |
2498 | - elseif (in_array($mysql_errno, array(1054, 1062, 1146)) && $error_query) |
|
2499 | - return false; |
|
2641 | + elseif (in_array($mysql_errno, array(1054, 1062, 1146)) && $error_query) { |
|
2642 | + return false; |
|
2643 | + } |
|
2500 | 2644 | // Creating an index on a non-existent column. |
2501 | - elseif ($mysql_errno == 1072) |
|
2502 | - return false; |
|
2503 | - elseif ($mysql_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') |
|
2504 | - return false; |
|
2645 | + elseif ($mysql_errno == 1072) { |
|
2646 | + return false; |
|
2647 | + } elseif ($mysql_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') { |
|
2648 | + return false; |
|
2649 | + } |
|
2505 | 2650 | } |
2506 | 2651 | // If a table already exists don't go potty. |
2507 | 2652 | else |
2508 | 2653 | { |
2509 | 2654 | if (in_array(substr(trim($string), 0, 8), array('CREATE T', 'CREATE S', 'DROP TABL', 'ALTER TA', 'CREATE I', 'CREATE U'))) |
2510 | 2655 | { |
2511 | - if (strpos($db_error_message, 'exist') !== false) |
|
2512 | - return true; |
|
2513 | - } |
|
2514 | - elseif (strpos(trim($string), 'INSERT ') !== false) |
|
2656 | + if (strpos($db_error_message, 'exist') !== false) { |
|
2657 | + return true; |
|
2658 | + } |
|
2659 | + } elseif (strpos(trim($string), 'INSERT ') !== false) |
|
2515 | 2660 | { |
2516 | - if (strpos($db_error_message, 'duplicate') !== false) |
|
2517 | - return true; |
|
2661 | + if (strpos($db_error_message, 'duplicate') !== false) { |
|
2662 | + return true; |
|
2663 | + } |
|
2518 | 2664 | } |
2519 | 2665 | } |
2520 | 2666 | |
2521 | 2667 | // Get the query string so we pass everything. |
2522 | 2668 | $query_string = ''; |
2523 | - foreach ($_GET as $k => $v) |
|
2524 | - $query_string .= ';' . $k . '=' . $v; |
|
2525 | - if (strlen($query_string) != 0) |
|
2526 | - $query_string = '?' . substr($query_string, 1); |
|
2669 | + foreach ($_GET as $k => $v) { |
|
2670 | + $query_string .= ';' . $k . '=' . $v; |
|
2671 | + } |
|
2672 | + if (strlen($query_string) != 0) { |
|
2673 | + $query_string = '?' . substr($query_string, 1); |
|
2674 | + } |
|
2527 | 2675 | |
2528 | 2676 | if ($command_line) |
2529 | 2677 | { |
@@ -2614,16 +2762,18 @@ discard block |
||
2614 | 2762 | { |
2615 | 2763 | $found |= 1; |
2616 | 2764 | // Do some checks on the data if we have it set. |
2617 | - if (isset($change['col_type'])) |
|
2618 | - $found &= $change['col_type'] === $column['type']; |
|
2619 | - if (isset($change['null_allowed'])) |
|
2620 | - $found &= $column['null'] == $change['null_allowed']; |
|
2621 | - if (isset($change['default'])) |
|
2622 | - $found &= $change['default'] === $column['default']; |
|
2765 | + if (isset($change['col_type'])) { |
|
2766 | + $found &= $change['col_type'] === $column['type']; |
|
2767 | + } |
|
2768 | + if (isset($change['null_allowed'])) { |
|
2769 | + $found &= $column['null'] == $change['null_allowed']; |
|
2770 | + } |
|
2771 | + if (isset($change['default'])) { |
|
2772 | + $found &= $change['default'] === $column['default']; |
|
2773 | + } |
|
2623 | 2774 | } |
2624 | 2775 | } |
2625 | - } |
|
2626 | - elseif ($change['type'] === 'index') |
|
2776 | + } elseif ($change['type'] === 'index') |
|
2627 | 2777 | { |
2628 | 2778 | $request = upgrade_query( ' |
2629 | 2779 | SHOW INDEX |
@@ -2632,9 +2782,10 @@ discard block |
||
2632 | 2782 | { |
2633 | 2783 | $cur_index = array(); |
2634 | 2784 | |
2635 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2636 | - if ($row['Key_name'] === $change['name']) |
|
2785 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
2786 | + if ($row['Key_name'] === $change['name']) |
|
2637 | 2787 | $cur_index[(int) $row['Seq_in_index']] = $row['Column_name']; |
2788 | + } |
|
2638 | 2789 | |
2639 | 2790 | ksort($cur_index, SORT_NUMERIC); |
2640 | 2791 | $found = array_values($cur_index) === $change['target_columns']; |
@@ -2644,14 +2795,17 @@ discard block |
||
2644 | 2795 | } |
2645 | 2796 | |
2646 | 2797 | // If we're trying to add and it's added, we're done. |
2647 | - if ($found && in_array($change['method'], array('add', 'change'))) |
|
2648 | - return true; |
|
2798 | + if ($found && in_array($change['method'], array('add', 'change'))) { |
|
2799 | + return true; |
|
2800 | + } |
|
2649 | 2801 | // Otherwise if we're removing and it wasn't found we're also done. |
2650 | - elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) |
|
2651 | - return true; |
|
2802 | + elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) { |
|
2803 | + return true; |
|
2804 | + } |
|
2652 | 2805 | // Otherwise is it just a test? |
2653 | - elseif ($is_test) |
|
2654 | - return false; |
|
2806 | + elseif ($is_test) { |
|
2807 | + return false; |
|
2808 | + } |
|
2655 | 2809 | |
2656 | 2810 | // Not found it yet? Bummer! How about we see if we're currently doing it? |
2657 | 2811 | $running = false; |
@@ -2662,8 +2816,9 @@ discard block |
||
2662 | 2816 | SHOW FULL PROCESSLIST'); |
2663 | 2817 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
2664 | 2818 | { |
2665 | - if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) |
|
2666 | - $found = true; |
|
2819 | + if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) { |
|
2820 | + $found = true; |
|
2821 | + } |
|
2667 | 2822 | } |
2668 | 2823 | |
2669 | 2824 | // Can't find it? Then we need to run it fools! |
@@ -2675,8 +2830,9 @@ discard block |
||
2675 | 2830 | ALTER TABLE ' . $db_prefix . $change['table'] . ' |
2676 | 2831 | ' . $change['text'], true) !== false; |
2677 | 2832 | |
2678 | - if (!$success) |
|
2679 | - return false; |
|
2833 | + if (!$success) { |
|
2834 | + return false; |
|
2835 | + } |
|
2680 | 2836 | |
2681 | 2837 | // Return |
2682 | 2838 | $running = true; |
@@ -2709,8 +2865,7 @@ discard block |
||
2709 | 2865 | { |
2710 | 2866 | $column_fix = true; |
2711 | 2867 | $null_fix = !$change['null_allowed']; |
2712 | - } |
|
2713 | - else |
|
2868 | + } else |
|
2714 | 2869 | { |
2715 | 2870 | $request = $smcFunc['db_query']('', ' |
2716 | 2871 | SHOW FULL COLUMNS |
@@ -2721,8 +2876,9 @@ discard block |
||
2721 | 2876 | 'db_error_skip' => true, |
2722 | 2877 | ) |
2723 | 2878 | ); |
2724 | - if ($smcFunc['db_num_rows']($request) === 0) |
|
2725 | - die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']); |
|
2879 | + if ($smcFunc['db_num_rows']($request) === 0) { |
|
2880 | + die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']); |
|
2881 | + } |
|
2726 | 2882 | $table_row = $smcFunc['db_fetch_assoc']($request); |
2727 | 2883 | $smcFunc['db_free_result']($request); |
2728 | 2884 | |
@@ -2744,10 +2900,11 @@ discard block |
||
2744 | 2900 | ) |
2745 | 2901 | ); |
2746 | 2902 | // No results? Just forget it all together. |
2747 | - if ($smcFunc['db_num_rows']($request) === 0) |
|
2748 | - unset($table_row['Collation']); |
|
2749 | - else |
|
2750 | - $collation_info = $smcFunc['db_fetch_assoc']($request); |
|
2903 | + if ($smcFunc['db_num_rows']($request) === 0) { |
|
2904 | + unset($table_row['Collation']); |
|
2905 | + } else { |
|
2906 | + $collation_info = $smcFunc['db_fetch_assoc']($request); |
|
2907 | + } |
|
2751 | 2908 | $smcFunc['db_free_result']($request); |
2752 | 2909 | } |
2753 | 2910 | } |
@@ -2755,8 +2912,8 @@ discard block |
||
2755 | 2912 | if ($column_fix) |
2756 | 2913 | { |
2757 | 2914 | // Make sure there are no NULL's left. |
2758 | - if ($null_fix) |
|
2759 | - $smcFunc['db_query']('', ' |
|
2915 | + if ($null_fix) { |
|
2916 | + $smcFunc['db_query']('', ' |
|
2760 | 2917 | UPDATE {db_prefix}' . $change['table'] . ' |
2761 | 2918 | SET ' . $change['column'] . ' = {string:default} |
2762 | 2919 | WHERE ' . $change['column'] . ' IS NULL', |
@@ -2765,6 +2922,7 @@ discard block |
||
2765 | 2922 | 'db_error_skip' => true, |
2766 | 2923 | ) |
2767 | 2924 | ); |
2925 | + } |
|
2768 | 2926 | |
2769 | 2927 | // Do the actual alteration. |
2770 | 2928 | $smcFunc['db_query']('', ' |
@@ -2793,8 +2951,9 @@ discard block |
||
2793 | 2951 | } |
2794 | 2952 | |
2795 | 2953 | // Not a column we need to check on? |
2796 | - if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) |
|
2797 | - return; |
|
2954 | + if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) { |
|
2955 | + return; |
|
2956 | + } |
|
2798 | 2957 | |
2799 | 2958 | // Break it up you (six|seven). |
2800 | 2959 | $temp = explode(' ', str_replace('NOT NULL', 'NOT_NULL', $change['text'])); |
@@ -2813,13 +2972,13 @@ discard block |
||
2813 | 2972 | 'new_name' => $temp[2], |
2814 | 2973 | )); |
2815 | 2974 | // !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet. |
2816 | - if ($smcFunc['db_num_rows'] != 1) |
|
2817 | - return; |
|
2975 | + if ($smcFunc['db_num_rows'] != 1) { |
|
2976 | + return; |
|
2977 | + } |
|
2818 | 2978 | |
2819 | 2979 | list (, $current_type) = $smcFunc['db_fetch_assoc']($request); |
2820 | 2980 | $smcFunc['db_free_result']($request); |
2821 | - } |
|
2822 | - else |
|
2981 | + } else |
|
2823 | 2982 | { |
2824 | 2983 | // Do this the old fashion, sure method way. |
2825 | 2984 | $request = $smcFunc['db_query']('', ' |
@@ -2830,21 +2989,24 @@ discard block |
||
2830 | 2989 | )); |
2831 | 2990 | // Mayday! |
2832 | 2991 | // !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet. |
2833 | - if ($smcFunc['db_num_rows'] == 0) |
|
2834 | - return; |
|
2992 | + if ($smcFunc['db_num_rows'] == 0) { |
|
2993 | + return; |
|
2994 | + } |
|
2835 | 2995 | |
2836 | 2996 | // Oh where, oh where has my little field gone. Oh where can it be... |
2837 | - while ($row = $smcFunc['db_query']($request)) |
|
2838 | - if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2]) |
|
2997 | + while ($row = $smcFunc['db_query']($request)) { |
|
2998 | + if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2]) |
|
2839 | 2999 | { |
2840 | 3000 | $current_type = $row['Type']; |
3001 | + } |
|
2841 | 3002 | break; |
2842 | 3003 | } |
2843 | 3004 | } |
2844 | 3005 | |
2845 | 3006 | // If this doesn't match, the column may of been altered for a reason. |
2846 | - if (trim($current_type) != trim($temp[3])) |
|
2847 | - $temp[3] = $current_type; |
|
3007 | + if (trim($current_type) != trim($temp[3])) { |
|
3008 | + $temp[3] = $current_type; |
|
3009 | + } |
|
2848 | 3010 | |
2849 | 3011 | // Piece this back together. |
2850 | 3012 | $change['text'] = str_replace('NOT_NULL', 'NOT NULL', implode(' ', $temp)); |
@@ -2856,8 +3018,9 @@ discard block |
||
2856 | 3018 | global $start_time, $timeLimitThreshold, $command_line, $custom_warning; |
2857 | 3019 | global $step_progress, $is_debug, $upcontext; |
2858 | 3020 | |
2859 | - if ($_GET['substep'] < $substep) |
|
2860 | - $_GET['substep'] = $substep; |
|
3021 | + if ($_GET['substep'] < $substep) { |
|
3022 | + $_GET['substep'] = $substep; |
|
3023 | + } |
|
2861 | 3024 | |
2862 | 3025 | if ($command_line) |
2863 | 3026 | { |
@@ -2870,29 +3033,33 @@ discard block |
||
2870 | 3033 | } |
2871 | 3034 | |
2872 | 3035 | @set_time_limit(300); |
2873 | - if (function_exists('apache_reset_timeout')) |
|
2874 | - @apache_reset_timeout(); |
|
3036 | + if (function_exists('apache_reset_timeout')) { |
|
3037 | + @apache_reset_timeout(); |
|
3038 | + } |
|
2875 | 3039 | |
2876 | - if (time() - $start_time <= $timeLimitThreshold) |
|
2877 | - return; |
|
3040 | + if (time() - $start_time <= $timeLimitThreshold) { |
|
3041 | + return; |
|
3042 | + } |
|
2878 | 3043 | |
2879 | 3044 | // Do we have some custom step progress stuff? |
2880 | 3045 | if (!empty($step_progress)) |
2881 | 3046 | { |
2882 | 3047 | $upcontext['substep_progress'] = 0; |
2883 | 3048 | $upcontext['substep_progress_name'] = $step_progress['name']; |
2884 | - if ($step_progress['current'] > $step_progress['total']) |
|
2885 | - $upcontext['substep_progress'] = 99.9; |
|
2886 | - else |
|
2887 | - $upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100; |
|
3049 | + if ($step_progress['current'] > $step_progress['total']) { |
|
3050 | + $upcontext['substep_progress'] = 99.9; |
|
3051 | + } else { |
|
3052 | + $upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100; |
|
3053 | + } |
|
2888 | 3054 | |
2889 | 3055 | // Make it nicely rounded. |
2890 | 3056 | $upcontext['substep_progress'] = round($upcontext['substep_progress'], 1); |
2891 | 3057 | } |
2892 | 3058 | |
2893 | 3059 | // If this is XML we just exit right away! |
2894 | - if (isset($_GET['xml'])) |
|
2895 | - return upgradeExit(); |
|
3060 | + if (isset($_GET['xml'])) { |
|
3061 | + return upgradeExit(); |
|
3062 | + } |
|
2896 | 3063 | |
2897 | 3064 | // We're going to pause after this! |
2898 | 3065 | $upcontext['pause'] = true; |
@@ -2900,13 +3067,15 @@ discard block |
||
2900 | 3067 | $upcontext['query_string'] = ''; |
2901 | 3068 | foreach ($_GET as $k => $v) |
2902 | 3069 | { |
2903 | - if ($k != 'data' && $k != 'substep' && $k != 'step') |
|
2904 | - $upcontext['query_string'] .= ';' . $k . '=' . $v; |
|
3070 | + if ($k != 'data' && $k != 'substep' && $k != 'step') { |
|
3071 | + $upcontext['query_string'] .= ';' . $k . '=' . $v; |
|
3072 | + } |
|
2905 | 3073 | } |
2906 | 3074 | |
2907 | 3075 | // Custom warning? |
2908 | - if (!empty($custom_warning)) |
|
2909 | - $upcontext['custom_warning'] = $custom_warning; |
|
3076 | + if (!empty($custom_warning)) { |
|
3077 | + $upcontext['custom_warning'] = $custom_warning; |
|
3078 | + } |
|
2910 | 3079 | |
2911 | 3080 | upgradeExit(); |
2912 | 3081 | } |
@@ -2921,25 +3090,26 @@ discard block |
||
2921 | 3090 | ob_implicit_flush(true); |
2922 | 3091 | @set_time_limit(600); |
2923 | 3092 | |
2924 | - if (!isset($_SERVER['argv'])) |
|
2925 | - $_SERVER['argv'] = array(); |
|
3093 | + if (!isset($_SERVER['argv'])) { |
|
3094 | + $_SERVER['argv'] = array(); |
|
3095 | + } |
|
2926 | 3096 | $_GET['maint'] = 1; |
2927 | 3097 | |
2928 | 3098 | foreach ($_SERVER['argv'] as $i => $arg) |
2929 | 3099 | { |
2930 | - if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) |
|
2931 | - $_GET['lang'] = $match[1]; |
|
2932 | - elseif (preg_match('~^--path=(.+)$~', $arg) != 0) |
|
2933 | - continue; |
|
2934 | - elseif ($arg == '--no-maintenance') |
|
2935 | - $_GET['maint'] = 0; |
|
2936 | - elseif ($arg == '--debug') |
|
2937 | - $is_debug = true; |
|
2938 | - elseif ($arg == '--backup') |
|
2939 | - $_POST['backup'] = 1; |
|
2940 | - elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) |
|
2941 | - $_GET['conv'] = 1; |
|
2942 | - elseif ($i != 0) |
|
3100 | + if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) { |
|
3101 | + $_GET['lang'] = $match[1]; |
|
3102 | + } elseif (preg_match('~^--path=(.+)$~', $arg) != 0) { |
|
3103 | + continue; |
|
3104 | + } elseif ($arg == '--no-maintenance') { |
|
3105 | + $_GET['maint'] = 0; |
|
3106 | + } elseif ($arg == '--debug') { |
|
3107 | + $is_debug = true; |
|
3108 | + } elseif ($arg == '--backup') { |
|
3109 | + $_POST['backup'] = 1; |
|
3110 | + } elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) { |
|
3111 | + $_GET['conv'] = 1; |
|
3112 | + } elseif ($i != 0) |
|
2943 | 3113 | { |
2944 | 3114 | echo 'SMF Command-line Upgrader |
2945 | 3115 | Usage: /path/to/php -f ' . basename(__FILE__) . ' -- [OPTION]... |
@@ -2953,10 +3123,12 @@ discard block |
||
2953 | 3123 | } |
2954 | 3124 | } |
2955 | 3125 | |
2956 | - if (!php_version_check()) |
|
2957 | - print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true); |
|
2958 | - if (!db_version_check()) |
|
2959 | - print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true); |
|
3126 | + if (!php_version_check()) { |
|
3127 | + print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true); |
|
3128 | + } |
|
3129 | + if (!db_version_check()) { |
|
3130 | + print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true); |
|
3131 | + } |
|
2960 | 3132 | |
2961 | 3133 | // Do some checks to make sure they have proper privileges |
2962 | 3134 | db_extend('packages'); |
@@ -2971,34 +3143,39 @@ discard block |
||
2971 | 3143 | $drop = $smcFunc['db_drop_table']('{db_prefix}priv_check'); |
2972 | 3144 | |
2973 | 3145 | // Sorry... we need CREATE, ALTER and DROP |
2974 | - if (!$create || !$alter || !$drop) |
|
2975 | - print_error("The " . $databases[$db_type]['name'] . " user you have set in Settings.php does not have proper privileges.\n\nPlease ask your host to give this user the ALTER, CREATE, and DROP privileges.", true); |
|
3146 | + if (!$create || !$alter || !$drop) { |
|
3147 | + print_error("The " . $databases[$db_type]['name'] . " user you have set in Settings.php does not have proper privileges.\n\nPlease ask your host to give this user the ALTER, CREATE, and DROP privileges.", true); |
|
3148 | + } |
|
2976 | 3149 | |
2977 | 3150 | $check = @file_exists($modSettings['theme_dir'] . '/index.template.php') |
2978 | 3151 | && @file_exists($sourcedir . '/QueryString.php') |
2979 | 3152 | && @file_exists($sourcedir . '/ManageBoards.php'); |
2980 | - if (!$check && !isset($modSettings['smfVersion'])) |
|
2981 | - print_error('Error: Some files are missing or out-of-date.', true); |
|
3153 | + if (!$check && !isset($modSettings['smfVersion'])) { |
|
3154 | + print_error('Error: Some files are missing or out-of-date.', true); |
|
3155 | + } |
|
2982 | 3156 | |
2983 | 3157 | // Do a quick version spot check. |
2984 | 3158 | $temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096); |
2985 | 3159 | preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match); |
2986 | - if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) |
|
2987 | - print_error('Error: Some files have not yet been updated properly.'); |
|
3160 | + if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) { |
|
3161 | + print_error('Error: Some files have not yet been updated properly.'); |
|
3162 | + } |
|
2988 | 3163 | |
2989 | 3164 | // Make sure Settings.php is writable. |
2990 | 3165 | quickFileWritable($boarddir . '/Settings.php'); |
2991 | - if (!is_writable($boarddir . '/Settings.php')) |
|
2992 | - print_error('Error: Unable to obtain write access to "Settings.php".', true); |
|
3166 | + if (!is_writable($boarddir . '/Settings.php')) { |
|
3167 | + print_error('Error: Unable to obtain write access to "Settings.php".', true); |
|
3168 | + } |
|
2993 | 3169 | |
2994 | 3170 | // Make sure Settings_bak.php is writable. |
2995 | 3171 | quickFileWritable($boarddir . '/Settings_bak.php'); |
2996 | - if (!is_writable($boarddir . '/Settings_bak.php')) |
|
2997 | - print_error('Error: Unable to obtain write access to "Settings_bak.php".'); |
|
3172 | + if (!is_writable($boarddir . '/Settings_bak.php')) { |
|
3173 | + print_error('Error: Unable to obtain write access to "Settings_bak.php".'); |
|
3174 | + } |
|
2998 | 3175 | |
2999 | - if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) |
|
3000 | - print_error('Error: Unable to obtain write access to "agreement.txt".'); |
|
3001 | - elseif (isset($modSettings['agreement'])) |
|
3176 | + if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) { |
|
3177 | + print_error('Error: Unable to obtain write access to "agreement.txt".'); |
|
3178 | + } elseif (isset($modSettings['agreement'])) |
|
3002 | 3179 | { |
3003 | 3180 | $fp = fopen($boarddir . '/agreement.txt', 'w'); |
3004 | 3181 | fwrite($fp, $modSettings['agreement']); |
@@ -3008,31 +3185,36 @@ discard block |
||
3008 | 3185 | // Make sure Themes is writable. |
3009 | 3186 | quickFileWritable($modSettings['theme_dir']); |
3010 | 3187 | |
3011 | - if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) |
|
3012 | - print_error('Error: Unable to obtain write access to "Themes".'); |
|
3188 | + if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) { |
|
3189 | + print_error('Error: Unable to obtain write access to "Themes".'); |
|
3190 | + } |
|
3013 | 3191 | |
3014 | 3192 | // Make sure cache directory exists and is writable! |
3015 | 3193 | $cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir; |
3016 | - if (!file_exists($cachedir_temp)) |
|
3017 | - @mkdir($cachedir_temp); |
|
3194 | + if (!file_exists($cachedir_temp)) { |
|
3195 | + @mkdir($cachedir_temp); |
|
3196 | + } |
|
3018 | 3197 | |
3019 | 3198 | // Make sure the cache temp dir is writable. |
3020 | 3199 | quickFileWritable($cachedir_temp); |
3021 | 3200 | |
3022 | - if (!is_writable($cachedir_temp)) |
|
3023 | - print_error('Error: Unable to obtain write access to "cache".', true); |
|
3201 | + if (!is_writable($cachedir_temp)) { |
|
3202 | + print_error('Error: Unable to obtain write access to "cache".', true); |
|
3203 | + } |
|
3024 | 3204 | |
3025 | - if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) |
|
3026 | - print_error('Error: Unable to find language files!', true); |
|
3027 | - else |
|
3205 | + if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) { |
|
3206 | + print_error('Error: Unable to find language files!', true); |
|
3207 | + } else |
|
3028 | 3208 | { |
3029 | 3209 | $temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096); |
3030 | 3210 | preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match); |
3031 | 3211 | |
3032 | - if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) |
|
3033 | - print_error('Error: Language files out of date.', true); |
|
3034 | - if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) |
|
3035 | - print_error('Error: Install language is missing for selected language.', true); |
|
3212 | + if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) { |
|
3213 | + print_error('Error: Language files out of date.', true); |
|
3214 | + } |
|
3215 | + if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) { |
|
3216 | + print_error('Error: Install language is missing for selected language.', true); |
|
3217 | + } |
|
3036 | 3218 | |
3037 | 3219 | // Otherwise include it! |
3038 | 3220 | require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'); |
@@ -3047,14 +3229,16 @@ discard block |
||
3047 | 3229 | { |
3048 | 3230 | static $fp = null; |
3049 | 3231 | |
3050 | - if ($fp === null) |
|
3051 | - $fp = fopen('php://stderr', 'wb'); |
|
3232 | + if ($fp === null) { |
|
3233 | + $fp = fopen('php://stderr', 'wb'); |
|
3234 | + } |
|
3052 | 3235 | |
3053 | 3236 | fwrite($fp, $message . "\n"); |
3054 | 3237 | |
3055 | - if ($fatal) |
|
3056 | - exit; |
|
3057 | -} |
|
3238 | + if ($fatal) { |
|
3239 | + exit; |
|
3240 | + } |
|
3241 | + } |
|
3058 | 3242 | |
3059 | 3243 | function throw_error($message) |
3060 | 3244 | { |
@@ -3071,8 +3255,9 @@ discard block |
||
3071 | 3255 | { |
3072 | 3256 | global $upcontext, $boarddir; |
3073 | 3257 | |
3074 | - if (empty($files)) |
|
3075 | - return true; |
|
3258 | + if (empty($files)) { |
|
3259 | + return true; |
|
3260 | + } |
|
3076 | 3261 | |
3077 | 3262 | $failure = false; |
3078 | 3263 | // On linux, it's easy - just use is_writable! |
@@ -3087,14 +3272,16 @@ discard block |
||
3087 | 3272 | @chmod($file, 0755); |
3088 | 3273 | |
3089 | 3274 | // Well, 755 hopefully worked... if not, try 777. |
3090 | - if (!is_writable($file) && !@chmod($file, 0777)) |
|
3091 | - $failure = true; |
|
3275 | + if (!is_writable($file) && !@chmod($file, 0777)) { |
|
3276 | + $failure = true; |
|
3277 | + } |
|
3092 | 3278 | // Otherwise remove it as it's good! |
3093 | - else |
|
3094 | - unset($files[$k]); |
|
3279 | + else { |
|
3280 | + unset($files[$k]); |
|
3281 | + } |
|
3282 | + } else { |
|
3283 | + unset($files[$k]); |
|
3095 | 3284 | } |
3096 | - else |
|
3097 | - unset($files[$k]); |
|
3098 | 3285 | } |
3099 | 3286 | } |
3100 | 3287 | // Windows is trickier. Let's try opening for r+... |
@@ -3105,30 +3292,35 @@ discard block |
||
3105 | 3292 | foreach ($files as $k => $file) |
3106 | 3293 | { |
3107 | 3294 | // Folders can't be opened for write... but the index.php in them can ;). |
3108 | - if (is_dir($file)) |
|
3109 | - $file .= '/index.php'; |
|
3295 | + if (is_dir($file)) { |
|
3296 | + $file .= '/index.php'; |
|
3297 | + } |
|
3110 | 3298 | |
3111 | 3299 | // Funny enough, chmod actually does do something on windows - it removes the read only attribute. |
3112 | 3300 | @chmod($file, 0777); |
3113 | 3301 | $fp = @fopen($file, 'r+'); |
3114 | 3302 | |
3115 | 3303 | // Hmm, okay, try just for write in that case... |
3116 | - if (!$fp) |
|
3117 | - $fp = @fopen($file, 'w'); |
|
3304 | + if (!$fp) { |
|
3305 | + $fp = @fopen($file, 'w'); |
|
3306 | + } |
|
3118 | 3307 | |
3119 | - if (!$fp) |
|
3120 | - $failure = true; |
|
3121 | - else |
|
3122 | - unset($files[$k]); |
|
3308 | + if (!$fp) { |
|
3309 | + $failure = true; |
|
3310 | + } else { |
|
3311 | + unset($files[$k]); |
|
3312 | + } |
|
3123 | 3313 | @fclose($fp); |
3124 | 3314 | } |
3125 | 3315 | } |
3126 | 3316 | |
3127 | - if (empty($files)) |
|
3128 | - return true; |
|
3317 | + if (empty($files)) { |
|
3318 | + return true; |
|
3319 | + } |
|
3129 | 3320 | |
3130 | - if (!isset($_SERVER)) |
|
3131 | - return !$failure; |
|
3321 | + if (!isset($_SERVER)) { |
|
3322 | + return !$failure; |
|
3323 | + } |
|
3132 | 3324 | |
3133 | 3325 | // What still needs to be done? |
3134 | 3326 | $upcontext['chmod']['files'] = $files; |
@@ -3179,36 +3371,40 @@ discard block |
||
3179 | 3371 | |
3180 | 3372 | if (!isset($ftp) || $ftp->error !== false) |
3181 | 3373 | { |
3182 | - if (!isset($ftp)) |
|
3183 | - $ftp = new ftp_connection(null); |
|
3374 | + if (!isset($ftp)) { |
|
3375 | + $ftp = new ftp_connection(null); |
|
3376 | + } |
|
3184 | 3377 | // Save the error so we can mess with listing... |
3185 | - elseif ($ftp->error !== false && !isset($upcontext['chmod']['ftp_error'])) |
|
3186 | - $upcontext['chmod']['ftp_error'] = $ftp->last_message === null ? '' : $ftp->last_message; |
|
3378 | + elseif ($ftp->error !== false && !isset($upcontext['chmod']['ftp_error'])) { |
|
3379 | + $upcontext['chmod']['ftp_error'] = $ftp->last_message === null ? '' : $ftp->last_message; |
|
3380 | + } |
|
3187 | 3381 | |
3188 | 3382 | list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__)); |
3189 | 3383 | |
3190 | - if ($found_path || !isset($upcontext['chmod']['path'])) |
|
3191 | - $upcontext['chmod']['path'] = $detect_path; |
|
3384 | + if ($found_path || !isset($upcontext['chmod']['path'])) { |
|
3385 | + $upcontext['chmod']['path'] = $detect_path; |
|
3386 | + } |
|
3192 | 3387 | |
3193 | - if (!isset($upcontext['chmod']['username'])) |
|
3194 | - $upcontext['chmod']['username'] = $username; |
|
3388 | + if (!isset($upcontext['chmod']['username'])) { |
|
3389 | + $upcontext['chmod']['username'] = $username; |
|
3390 | + } |
|
3195 | 3391 | |
3196 | 3392 | // Don't forget the login token. |
3197 | 3393 | $upcontext += createToken('login'); |
3198 | 3394 | |
3199 | 3395 | return false; |
3200 | - } |
|
3201 | - else |
|
3396 | + } else |
|
3202 | 3397 | { |
3203 | 3398 | // We want to do a relative path for FTP. |
3204 | 3399 | if (!in_array($upcontext['chmod']['path'], array('', '/'))) |
3205 | 3400 | { |
3206 | 3401 | $ftp_root = strtr($boarddir, array($upcontext['chmod']['path'] => '')); |
3207 | - if (substr($ftp_root, -1) == '/' && ($upcontext['chmod']['path'] == '' || $upcontext['chmod']['path'][0] === '/')) |
|
3208 | - $ftp_root = substr($ftp_root, 0, -1); |
|
3402 | + if (substr($ftp_root, -1) == '/' && ($upcontext['chmod']['path'] == '' || $upcontext['chmod']['path'][0] === '/')) { |
|
3403 | + $ftp_root = substr($ftp_root, 0, -1); |
|
3404 | + } |
|
3405 | + } else { |
|
3406 | + $ftp_root = $boarddir; |
|
3209 | 3407 | } |
3210 | - else |
|
3211 | - $ftp_root = $boarddir; |
|
3212 | 3408 | |
3213 | 3409 | // Save the info for next time! |
3214 | 3410 | $_SESSION['installer_temp_ftp'] = array( |
@@ -3222,10 +3418,12 @@ discard block |
||
3222 | 3418 | |
3223 | 3419 | foreach ($files as $k => $file) |
3224 | 3420 | { |
3225 | - if (!is_writable($file)) |
|
3226 | - $ftp->chmod($file, 0755); |
|
3227 | - if (!is_writable($file)) |
|
3228 | - $ftp->chmod($file, 0777); |
|
3421 | + if (!is_writable($file)) { |
|
3422 | + $ftp->chmod($file, 0755); |
|
3423 | + } |
|
3424 | + if (!is_writable($file)) { |
|
3425 | + $ftp->chmod($file, 0777); |
|
3426 | + } |
|
3229 | 3427 | |
3230 | 3428 | // Assuming that didn't work calculate the path without the boarddir. |
3231 | 3429 | if (!is_writable($file)) |
@@ -3234,19 +3432,23 @@ discard block |
||
3234 | 3432 | { |
3235 | 3433 | $ftp_file = strtr($file, array($_SESSION['installer_temp_ftp']['root'] => '')); |
3236 | 3434 | $ftp->chmod($ftp_file, 0755); |
3237 | - if (!is_writable($file)) |
|
3238 | - $ftp->chmod($ftp_file, 0777); |
|
3435 | + if (!is_writable($file)) { |
|
3436 | + $ftp->chmod($ftp_file, 0777); |
|
3437 | + } |
|
3239 | 3438 | // Sometimes an extra slash can help... |
3240 | 3439 | $ftp_file = '/' . $ftp_file; |
3241 | - if (!is_writable($file)) |
|
3242 | - $ftp->chmod($ftp_file, 0755); |
|
3243 | - if (!is_writable($file)) |
|
3244 | - $ftp->chmod($ftp_file, 0777); |
|
3440 | + if (!is_writable($file)) { |
|
3441 | + $ftp->chmod($ftp_file, 0755); |
|
3442 | + } |
|
3443 | + if (!is_writable($file)) { |
|
3444 | + $ftp->chmod($ftp_file, 0777); |
|
3445 | + } |
|
3245 | 3446 | } |
3246 | 3447 | } |
3247 | 3448 | |
3248 | - if (is_writable($file)) |
|
3249 | - unset($files[$k]); |
|
3449 | + if (is_writable($file)) { |
|
3450 | + unset($files[$k]); |
|
3451 | + } |
|
3250 | 3452 | } |
3251 | 3453 | |
3252 | 3454 | $ftp->close(); |
@@ -3256,16 +3458,18 @@ discard block |
||
3256 | 3458 | // What remains? |
3257 | 3459 | $upcontext['chmod']['files'] = $files; |
3258 | 3460 | |
3259 | - if (empty($files)) |
|
3260 | - return true; |
|
3461 | + if (empty($files)) { |
|
3462 | + return true; |
|
3463 | + } |
|
3261 | 3464 | |
3262 | 3465 | return false; |
3263 | 3466 | } |
3264 | 3467 | |
3265 | 3468 | function quickFileWritable($file) |
3266 | 3469 | { |
3267 | - if (is_writable($file)) |
|
3268 | - return true; |
|
3470 | + if (is_writable($file)) { |
|
3471 | + return true; |
|
3472 | + } |
|
3269 | 3473 | |
3270 | 3474 | @chmod($file, 0755); |
3271 | 3475 | |
@@ -3275,17 +3479,19 @@ discard block |
||
3275 | 3479 | foreach($chmod_values as $val) |
3276 | 3480 | { |
3277 | 3481 | // If it's writable, break out of the loop |
3278 | - if (is_writable($file)) |
|
3279 | - break; |
|
3280 | - else |
|
3281 | - @chmod($file, $val); |
|
3482 | + if (is_writable($file)) { |
|
3483 | + break; |
|
3484 | + } else { |
|
3485 | + @chmod($file, $val); |
|
3486 | + } |
|
3282 | 3487 | } |
3283 | 3488 | } |
3284 | 3489 | function smf_strtolower($string) |
3285 | 3490 | { |
3286 | 3491 | global $sourcedir; |
3287 | - if (function_exists('mb_strtolower')) |
|
3288 | - return mb_strtolower($string, 'UTF-8'); |
|
3492 | + if (function_exists('mb_strtolower')) { |
|
3493 | + return mb_strtolower($string, 'UTF-8'); |
|
3494 | + } |
|
3289 | 3495 | require_once($sourcedir . '/Subs-Charset.php'); |
3290 | 3496 | return utf8_strtolower($string); |
3291 | 3497 | } |
@@ -3301,8 +3507,7 @@ discard block |
||
3301 | 3507 | if ($db_type == 'postgresql' || ($db_character_set === 'utf8' && !empty($modSettings['global_character_set']) && $modSettings['global_character_set'] === 'UTF-8')) |
3302 | 3508 | { |
3303 | 3509 | return true; |
3304 | - } |
|
3305 | - else |
|
3510 | + } else |
|
3306 | 3511 | { |
3307 | 3512 | $upcontext['page_title'] = 'Converting to UTF8'; |
3308 | 3513 | $upcontext['sub_template'] = isset($_GET['xml']) ? 'convert_xml' : 'convert_utf8'; |
@@ -3346,8 +3551,9 @@ discard block |
||
3346 | 3551 | ) |
3347 | 3552 | ); |
3348 | 3553 | $db_charsets = array(); |
3349 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
3350 | - $db_charsets[] = $row['Charset']; |
|
3554 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
3555 | + $db_charsets[] = $row['Charset']; |
|
3556 | + } |
|
3351 | 3557 | |
3352 | 3558 | $smcFunc['db_free_result']($request); |
3353 | 3559 | |
@@ -3383,13 +3589,15 @@ discard block |
||
3383 | 3589 | // If there's a fulltext index, we need to drop it first... |
3384 | 3590 | if ($request !== false || $smcFunc['db_num_rows']($request) != 0) |
3385 | 3591 | { |
3386 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
3387 | - if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT')) |
|
3592 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
3593 | + if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT')) |
|
3388 | 3594 | $upcontext['fulltext_index'][] = $row['Key_name']; |
3595 | + } |
|
3389 | 3596 | $smcFunc['db_free_result']($request); |
3390 | 3597 | |
3391 | - if (isset($upcontext['fulltext_index'])) |
|
3392 | - $upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']); |
|
3598 | + if (isset($upcontext['fulltext_index'])) { |
|
3599 | + $upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']); |
|
3600 | + } |
|
3393 | 3601 | } |
3394 | 3602 | |
3395 | 3603 | // Drop it and make a note... |
@@ -3581,8 +3789,9 @@ discard block |
||
3581 | 3789 | $replace = '%field%'; |
3582 | 3790 | |
3583 | 3791 | // Build a huge REPLACE statement... |
3584 | - foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) |
|
3585 | - $replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')'; |
|
3792 | + foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) { |
|
3793 | + $replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')'; |
|
3794 | + } |
|
3586 | 3795 | } |
3587 | 3796 | |
3588 | 3797 | // Get a list of table names ahead of time... This makes it easier to set our substep and such |
@@ -3616,8 +3825,9 @@ discard block |
||
3616 | 3825 | $upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100); |
3617 | 3826 | |
3618 | 3827 | // Just to make sure it doesn't time out. |
3619 | - if (function_exists('apache_reset_timeout')) |
|
3620 | - @apache_reset_timeout(); |
|
3828 | + if (function_exists('apache_reset_timeout')) { |
|
3829 | + @apache_reset_timeout(); |
|
3830 | + } |
|
3621 | 3831 | |
3622 | 3832 | $table_charsets = array(); |
3623 | 3833 | |
@@ -3638,8 +3848,9 @@ discard block |
||
3638 | 3848 | { |
3639 | 3849 | list($charset) = explode('_', $collation); |
3640 | 3850 | |
3641 | - if (!isset($table_charsets[$charset])) |
|
3642 | - $table_charsets[$charset] = array(); |
|
3851 | + if (!isset($table_charsets[$charset])) { |
|
3852 | + $table_charsets[$charset] = array(); |
|
3853 | + } |
|
3643 | 3854 | |
3644 | 3855 | $table_charsets[$charset][] = $column_info; |
3645 | 3856 | } |
@@ -3679,10 +3890,11 @@ discard block |
||
3679 | 3890 | if (isset($translation_tables[$upcontext['charset_detected']])) |
3680 | 3891 | { |
3681 | 3892 | $update = ''; |
3682 | - foreach ($table_charsets as $charset => $columns) |
|
3683 | - foreach ($columns as $column) |
|
3893 | + foreach ($table_charsets as $charset => $columns) { |
|
3894 | + foreach ($columns as $column) |
|
3684 | 3895 | $update .= ' |
3685 | 3896 | ' . $column['Field'] . ' = ' . strtr($replace, array('%field%' => $column['Field'])) . ','; |
3897 | + } |
|
3686 | 3898 | |
3687 | 3899 | $smcFunc['db_query']('', ' |
3688 | 3900 | UPDATE {raw:table_name} |
@@ -3707,8 +3919,9 @@ discard block |
||
3707 | 3919 | // Now do the actual conversion (if still needed). |
3708 | 3920 | if ($charsets[$upcontext['charset_detected']] !== 'utf8') |
3709 | 3921 | { |
3710 | - if ($command_line) |
|
3711 | - echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...'; |
|
3922 | + if ($command_line) { |
|
3923 | + echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...'; |
|
3924 | + } |
|
3712 | 3925 | |
3713 | 3926 | $smcFunc['db_query']('', ' |
3714 | 3927 | ALTER TABLE {raw:table_name} |
@@ -3718,8 +3931,9 @@ discard block |
||
3718 | 3931 | ) |
3719 | 3932 | ); |
3720 | 3933 | |
3721 | - if ($command_line) |
|
3722 | - echo " done.\n"; |
|
3934 | + if ($command_line) { |
|
3935 | + echo " done.\n"; |
|
3936 | + } |
|
3723 | 3937 | } |
3724 | 3938 | } |
3725 | 3939 | |
@@ -3749,8 +3963,8 @@ discard block |
||
3749 | 3963 | ); |
3750 | 3964 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
3751 | 3965 | { |
3752 | - if (@safe_unserialize($row['extra']) === false && preg_match('~^(a:3:{s:5:"topic";i:\d+;s:7:"subject";s:)(\d+):"(.+)"(;s:6:"member";s:5:"\d+";})$~', $row['extra'], $matches) === 1) |
|
3753 | - $smcFunc['db_query']('', ' |
|
3966 | + if (@safe_unserialize($row['extra']) === false && preg_match('~^(a:3:{s:5:"topic";i:\d+;s:7:"subject";s:)(\d+):"(.+)"(;s:6:"member";s:5:"\d+";})$~', $row['extra'], $matches) === 1) { |
|
3967 | + $smcFunc['db_query']('', ' |
|
3754 | 3968 | UPDATE {db_prefix}log_actions |
3755 | 3969 | SET extra = {string:extra} |
3756 | 3970 | WHERE id_action = {int:current_action}', |
@@ -3759,6 +3973,7 @@ discard block |
||
3759 | 3973 | 'extra' => $matches[1] . strlen($matches[3]) . ':"' . $matches[3] . '"' . $matches[4], |
3760 | 3974 | ) |
3761 | 3975 | ); |
3976 | + } |
|
3762 | 3977 | } |
3763 | 3978 | $smcFunc['db_free_result']($request); |
3764 | 3979 | |
@@ -3780,15 +3995,17 @@ discard block |
||
3780 | 3995 | // First thing's first - did we already do this? |
3781 | 3996 | if (!empty($modSettings['json_done'])) |
3782 | 3997 | { |
3783 | - if ($command_line) |
|
3784 | - return DeleteUpgrade(); |
|
3785 | - else |
|
3786 | - return true; |
|
3998 | + if ($command_line) { |
|
3999 | + return DeleteUpgrade(); |
|
4000 | + } else { |
|
4001 | + return true; |
|
4002 | + } |
|
3787 | 4003 | } |
3788 | 4004 | |
3789 | 4005 | // Done it already - js wise? |
3790 | - if (!empty($_POST['json_done'])) |
|
3791 | - return true; |
|
4006 | + if (!empty($_POST['json_done'])) { |
|
4007 | + return true; |
|
4008 | + } |
|
3792 | 4009 | |
3793 | 4010 | // List of tables affected by this function |
3794 | 4011 | // name => array('key', col1[,col2|true[,col3]]) |
@@ -3820,12 +4037,14 @@ discard block |
||
3820 | 4037 | $upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100); |
3821 | 4038 | $file_steps = $upcontext['table_count']; |
3822 | 4039 | |
3823 | - foreach($keys as $id => $table) |
|
3824 | - if ($id < $_GET['substep']) |
|
4040 | + foreach($keys as $id => $table) { |
|
4041 | + if ($id < $_GET['substep']) |
|
3825 | 4042 | $upcontext['previous_tables'][] = $table; |
4043 | + } |
|
3826 | 4044 | |
3827 | - if ($command_line) |
|
3828 | - echo 'Converting data from serialize() to json_encode().'; |
|
4045 | + if ($command_line) { |
|
4046 | + echo 'Converting data from serialize() to json_encode().'; |
|
4047 | + } |
|
3829 | 4048 | |
3830 | 4049 | if (!$support_js || isset($_GET['xml'])) |
3831 | 4050 | { |
@@ -3865,8 +4084,9 @@ discard block |
||
3865 | 4084 | |
3866 | 4085 | // Loop through and fix these... |
3867 | 4086 | $new_settings = array(); |
3868 | - if ($command_line) |
|
3869 | - echo "\n" . 'Fixing some settings...'; |
|
4087 | + if ($command_line) { |
|
4088 | + echo "\n" . 'Fixing some settings...'; |
|
4089 | + } |
|
3870 | 4090 | |
3871 | 4091 | foreach ($serialized_settings as $var) |
3872 | 4092 | { |
@@ -3874,22 +4094,24 @@ discard block |
||
3874 | 4094 | { |
3875 | 4095 | // Attempt to unserialize the setting |
3876 | 4096 | $temp = @safe_unserialize($modSettings[$var]); |
3877 | - if (!$temp && $command_line) |
|
3878 | - echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping."; |
|
3879 | - elseif ($temp !== false) |
|
3880 | - $new_settings[$var] = json_encode($temp); |
|
4097 | + if (!$temp && $command_line) { |
|
4098 | + echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping."; |
|
4099 | + } elseif ($temp !== false) { |
|
4100 | + $new_settings[$var] = json_encode($temp); |
|
4101 | + } |
|
3881 | 4102 | } |
3882 | 4103 | } |
3883 | 4104 | |
3884 | 4105 | // Update everything at once |
3885 | - if (!function_exists('cache_put_data')) |
|
3886 | - require_once($sourcedir . '/Load.php'); |
|
4106 | + if (!function_exists('cache_put_data')) { |
|
4107 | + require_once($sourcedir . '/Load.php'); |
|
4108 | + } |
|
3887 | 4109 | updateSettings($new_settings, true); |
3888 | 4110 | |
3889 | - if ($command_line) |
|
3890 | - echo ' done.'; |
|
3891 | - } |
|
3892 | - elseif ($table == 'themes') |
|
4111 | + if ($command_line) { |
|
4112 | + echo ' done.'; |
|
4113 | + } |
|
4114 | + } elseif ($table == 'themes') |
|
3893 | 4115 | { |
3894 | 4116 | // Finally, fix the admin prefs. Unfortunately this is stored per theme, but hopefully they only have one theme installed at this point... |
3895 | 4117 | $query = $smcFunc['db_query']('', ' |
@@ -3908,10 +4130,11 @@ discard block |
||
3908 | 4130 | |
3909 | 4131 | if ($command_line) |
3910 | 4132 | { |
3911 | - if ($temp === false) |
|
3912 | - echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.'; |
|
3913 | - else |
|
3914 | - echo "\n" . 'Fixing admin preferences...'; |
|
4133 | + if ($temp === false) { |
|
4134 | + echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.'; |
|
4135 | + } else { |
|
4136 | + echo "\n" . 'Fixing admin preferences...'; |
|
4137 | + } |
|
3915 | 4138 | } |
3916 | 4139 | |
3917 | 4140 | if ($temp !== false) |
@@ -3931,15 +4154,15 @@ discard block |
||
3931 | 4154 | ) |
3932 | 4155 | ); |
3933 | 4156 | |
3934 | - if ($is_debug || $command_line) |
|
3935 | - echo ' done.'; |
|
4157 | + if ($is_debug || $command_line) { |
|
4158 | + echo ' done.'; |
|
4159 | + } |
|
3936 | 4160 | } |
3937 | 4161 | } |
3938 | 4162 | |
3939 | 4163 | $smcFunc['db_free_result']($query); |
3940 | 4164 | } |
3941 | - } |
|
3942 | - else |
|
4165 | + } else |
|
3943 | 4166 | { |
3944 | 4167 | // First item is always the key... |
3945 | 4168 | $key = $info[0]; |
@@ -3950,8 +4173,7 @@ discard block |
||
3950 | 4173 | { |
3951 | 4174 | $col_select = $info[1]; |
3952 | 4175 | $where = ' WHERE ' . $info[1] . ' != {empty}'; |
3953 | - } |
|
3954 | - else |
|
4176 | + } else |
|
3955 | 4177 | { |
3956 | 4178 | $col_select = implode(', ', $info); |
3957 | 4179 | } |
@@ -3984,8 +4206,7 @@ discard block |
||
3984 | 4206 | if ($temp === false && $command_line) |
3985 | 4207 | { |
3986 | 4208 | echo "\nFailed to unserialize " . $row[$col] . "... Skipping\n"; |
3987 | - } |
|
3988 | - else |
|
4209 | + } else |
|
3989 | 4210 | { |
3990 | 4211 | $row[$col] = json_encode($temp); |
3991 | 4212 | |
@@ -4010,16 +4231,18 @@ discard block |
||
4010 | 4231 | } |
4011 | 4232 | } |
4012 | 4233 | |
4013 | - if ($command_line) |
|
4014 | - echo ' done.'; |
|
4234 | + if ($command_line) { |
|
4235 | + echo ' done.'; |
|
4236 | + } |
|
4015 | 4237 | |
4016 | 4238 | // Free up some memory... |
4017 | 4239 | $smcFunc['db_free_result']($query); |
4018 | 4240 | } |
4019 | 4241 | } |
4020 | 4242 | // If this is XML to keep it nice for the user do one table at a time anyway! |
4021 | - if (isset($_GET['xml'])) |
|
4022 | - return upgradeExit(); |
|
4243 | + if (isset($_GET['xml'])) { |
|
4244 | + return upgradeExit(); |
|
4245 | + } |
|
4023 | 4246 | } |
4024 | 4247 | |
4025 | 4248 | if ($command_line) |
@@ -4034,8 +4257,9 @@ discard block |
||
4034 | 4257 | |
4035 | 4258 | $_GET['substep'] = 0; |
4036 | 4259 | // Make sure we move on! |
4037 | - if ($command_line) |
|
4038 | - return DeleteUpgrade(); |
|
4260 | + if ($command_line) { |
|
4261 | + return DeleteUpgrade(); |
|
4262 | + } |
|
4039 | 4263 | |
4040 | 4264 | return true; |
4041 | 4265 | } |
@@ -4055,14 +4279,16 @@ discard block |
||
4055 | 4279 | global $upcontext, $txt, $settings; |
4056 | 4280 | |
4057 | 4281 | // Don't call me twice! |
4058 | - if (!empty($upcontext['chmod_called'])) |
|
4059 | - return; |
|
4282 | + if (!empty($upcontext['chmod_called'])) { |
|
4283 | + return; |
|
4284 | + } |
|
4060 | 4285 | |
4061 | 4286 | $upcontext['chmod_called'] = true; |
4062 | 4287 | |
4063 | 4288 | // Nothing? |
4064 | - if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) |
|
4065 | - return; |
|
4289 | + if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) { |
|
4290 | + return; |
|
4291 | + } |
|
4066 | 4292 | |
4067 | 4293 | // Was it a problem with Windows? |
4068 | 4294 | if (!empty($upcontext['chmod']['ftp_error']) && $upcontext['chmod']['ftp_error'] == 'total_mess') |
@@ -4094,11 +4320,12 @@ discard block |
||
4094 | 4320 | content.write(\'<div class="windowbg description">\n\t\t\t<h4>The following files needs to be made writable to continue:</h4>\n\t\t\t\'); |
4095 | 4321 | content.write(\'<p>', implode('<br>\n\t\t\t', $upcontext['chmod']['files']), '</p>\n\t\t\t\');'; |
4096 | 4322 | |
4097 | - if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') |
|
4098 | - echo ' |
|
4323 | + if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') { |
|
4324 | + echo ' |
|
4099 | 4325 | content.write(\'<hr>\n\t\t\t\'); |
4100 | 4326 | content.write(\'<p>If you have a shell account, the convenient below command can automatically correct permissions on these files</p>\n\t\t\t\'); |
4101 | 4327 | content.write(\'<tt># chmod a+w ', implode(' ', $upcontext['chmod']['files']), '</tt>\n\t\t\t\');'; |
4328 | + } |
|
4102 | 4329 | |
4103 | 4330 | echo ' |
4104 | 4331 | content.write(\'<a href="javascript:self.close();">close</a>\n\t\t</div>\n\t</body>\n</html>\'); |
@@ -4106,17 +4333,19 @@ discard block |
||
4106 | 4333 | } |
4107 | 4334 | </script>'; |
4108 | 4335 | |
4109 | - if (!empty($upcontext['chmod']['ftp_error'])) |
|
4110 | - echo ' |
|
4336 | + if (!empty($upcontext['chmod']['ftp_error'])) { |
|
4337 | + echo ' |
|
4111 | 4338 | <div class="error_message red"> |
4112 | 4339 | The following error was encountered when trying to connect:<br><br> |
4113 | 4340 | <code>', $upcontext['chmod']['ftp_error'], '</code> |
4114 | 4341 | </div> |
4115 | 4342 | <br>'; |
4343 | + } |
|
4116 | 4344 | |
4117 | - if (empty($upcontext['chmod_in_form'])) |
|
4118 | - echo ' |
|
4345 | + if (empty($upcontext['chmod_in_form'])) { |
|
4346 | + echo ' |
|
4119 | 4347 | <form action="', $upcontext['form_url'], '" method="post">'; |
4348 | + } |
|
4120 | 4349 | |
4121 | 4350 | echo ' |
4122 | 4351 | <table width="520" border="0" align="center" style="margin-bottom: 1ex;"> |
@@ -4151,10 +4380,11 @@ discard block |
||
4151 | 4380 | <div class="righttext" style="margin: 1ex;"><input type="submit" value="', $txt['ftp_connect'], '" class="button_submit"></div> |
4152 | 4381 | </div>'; |
4153 | 4382 | |
4154 | - if (empty($upcontext['chmod_in_form'])) |
|
4155 | - echo ' |
|
4383 | + if (empty($upcontext['chmod_in_form'])) { |
|
4384 | + echo ' |
|
4156 | 4385 | </form>'; |
4157 | -} |
|
4386 | + } |
|
4387 | + } |
|
4158 | 4388 | |
4159 | 4389 | function template_upgrade_above() |
4160 | 4390 | { |
@@ -4214,9 +4444,10 @@ discard block |
||
4214 | 4444 | <h2>', $txt['upgrade_progress'], '</h2> |
4215 | 4445 | <ul>'; |
4216 | 4446 | |
4217 | - foreach ($upcontext['steps'] as $num => $step) |
|
4218 | - echo ' |
|
4447 | + foreach ($upcontext['steps'] as $num => $step) { |
|
4448 | + echo ' |
|
4219 | 4449 | <li class="', $num < $upcontext['current_step'] ? 'stepdone' : ($num == $upcontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>'; |
4450 | + } |
|
4220 | 4451 | |
4221 | 4452 | echo ' |
4222 | 4453 | </ul> |
@@ -4229,8 +4460,8 @@ discard block |
||
4229 | 4460 | </div> |
4230 | 4461 | </div>'; |
4231 | 4462 | |
4232 | - if (isset($upcontext['step_progress'])) |
|
4233 | - echo ' |
|
4463 | + if (isset($upcontext['step_progress'])) { |
|
4464 | + echo ' |
|
4234 | 4465 | <br> |
4235 | 4466 | <br> |
4236 | 4467 | <div id="progress_bar_step"> |
@@ -4239,6 +4470,7 @@ discard block |
||
4239 | 4470 | <span>', $txt['upgrade_step_progress'], '</span> |
4240 | 4471 | </div> |
4241 | 4472 | </div>'; |
4473 | + } |
|
4242 | 4474 | |
4243 | 4475 | echo ' |
4244 | 4476 | <div id="substep_bar_div" class="smalltext" style="float: left;width: 50%;margin-top: 0.6em;display: ', isset($upcontext['substep_progress']) ? '' : 'none', ';">', isset($upcontext['substep_progress_name']) ? trim(strtr($upcontext['substep_progress_name'], array('.' => ''))) : '', ':</div> |
@@ -4269,32 +4501,36 @@ discard block |
||
4269 | 4501 | { |
4270 | 4502 | global $upcontext, $txt; |
4271 | 4503 | |
4272 | - if (!empty($upcontext['pause'])) |
|
4273 | - echo ' |
|
4504 | + if (!empty($upcontext['pause'])) { |
|
4505 | + echo ' |
|
4274 | 4506 | <em>', $txt['upgrade_incomplete'], '.</em><br> |
4275 | 4507 | |
4276 | 4508 | <h2 style="margin-top: 2ex;">', $txt['upgrade_not_quite_done'], '</h2> |
4277 | 4509 | <h3> |
4278 | 4510 | ', $txt['upgrade_paused_overload'], ' |
4279 | 4511 | </h3>'; |
4512 | + } |
|
4280 | 4513 | |
4281 | - if (!empty($upcontext['custom_warning'])) |
|
4282 | - echo ' |
|
4514 | + if (!empty($upcontext['custom_warning'])) { |
|
4515 | + echo ' |
|
4283 | 4516 | <div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;"> |
4284 | 4517 | <div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div> |
4285 | 4518 | <strong style="text-decoration: underline;">', $txt['upgrade_note'], '</strong><br> |
4286 | 4519 | <div style="padding-left: 6ex;">', $upcontext['custom_warning'], '</div> |
4287 | 4520 | </div>'; |
4521 | + } |
|
4288 | 4522 | |
4289 | 4523 | echo ' |
4290 | 4524 | <div class="righttext" style="margin: 1ex;">'; |
4291 | 4525 | |
4292 | - if (!empty($upcontext['continue'])) |
|
4293 | - echo ' |
|
4526 | + if (!empty($upcontext['continue'])) { |
|
4527 | + echo ' |
|
4294 | 4528 | <input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '"', $upcontext['continue'] == 2 ? ' disabled' : '', ' class="button_submit">'; |
4295 | - if (!empty($upcontext['skip'])) |
|
4296 | - echo ' |
|
4529 | + } |
|
4530 | + if (!empty($upcontext['skip'])) { |
|
4531 | + echo ' |
|
4297 | 4532 | <input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="dontSubmit = true; document.getElementById(\'contbutt\').disabled = \'disabled\'; return true;" class="button_submit">'; |
4533 | + } |
|
4298 | 4534 | |
4299 | 4535 | echo ' |
4300 | 4536 | </div> |
@@ -4344,11 +4580,12 @@ discard block |
||
4344 | 4580 | echo '<', '?xml version="1.0" encoding="UTF-8"?', '> |
4345 | 4581 | <smf>'; |
4346 | 4582 | |
4347 | - if (!empty($upcontext['get_data'])) |
|
4348 | - foreach ($upcontext['get_data'] as $k => $v) |
|
4583 | + if (!empty($upcontext['get_data'])) { |
|
4584 | + foreach ($upcontext['get_data'] as $k => $v) |
|
4349 | 4585 | echo ' |
4350 | 4586 | <get key="', $k, '">', $v, '</get>'; |
4351 | -} |
|
4587 | + } |
|
4588 | + } |
|
4352 | 4589 | |
4353 | 4590 | function template_xml_below() |
4354 | 4591 | { |
@@ -4389,8 +4626,8 @@ discard block |
||
4389 | 4626 | template_chmod(); |
4390 | 4627 | |
4391 | 4628 | // For large, pre 1.1 RC2 forums give them a warning about the possible impact of this upgrade! |
4392 | - if ($upcontext['is_large_forum']) |
|
4393 | - echo ' |
|
4629 | + if ($upcontext['is_large_forum']) { |
|
4630 | + echo ' |
|
4394 | 4631 | <div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;"> |
4395 | 4632 | <div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div> |
4396 | 4633 | <strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br> |
@@ -4398,10 +4635,11 @@ discard block |
||
4398 | 4635 | ', $txt['upgrade_warning_lots_data'], ' |
4399 | 4636 | </div> |
4400 | 4637 | </div>'; |
4638 | + } |
|
4401 | 4639 | |
4402 | 4640 | // A warning message? |
4403 | - if (!empty($upcontext['warning'])) |
|
4404 | - echo ' |
|
4641 | + if (!empty($upcontext['warning'])) { |
|
4642 | + echo ' |
|
4405 | 4643 | <div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;"> |
4406 | 4644 | <div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div> |
4407 | 4645 | <strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br> |
@@ -4409,6 +4647,7 @@ discard block |
||
4409 | 4647 | ', $upcontext['warning'], ' |
4410 | 4648 | </div> |
4411 | 4649 | </div>'; |
4650 | + } |
|
4412 | 4651 | |
4413 | 4652 | // Paths are incorrect? |
4414 | 4653 | echo ' |
@@ -4424,20 +4663,22 @@ discard block |
||
4424 | 4663 | if (!empty($upcontext['user']['id']) && (time() - $upcontext['started'] < 72600 || time() - $upcontext['updated'] < 3600)) |
4425 | 4664 | { |
4426 | 4665 | $ago = time() - $upcontext['started']; |
4427 | - if ($ago < 60) |
|
4428 | - $ago = $ago . ' seconds'; |
|
4429 | - elseif ($ago < 3600) |
|
4430 | - $ago = (int) ($ago / 60) . ' minutes'; |
|
4431 | - else |
|
4432 | - $ago = (int) ($ago / 3600) . ' hours'; |
|
4666 | + if ($ago < 60) { |
|
4667 | + $ago = $ago . ' seconds'; |
|
4668 | + } elseif ($ago < 3600) { |
|
4669 | + $ago = (int) ($ago / 60) . ' minutes'; |
|
4670 | + } else { |
|
4671 | + $ago = (int) ($ago / 3600) . ' hours'; |
|
4672 | + } |
|
4433 | 4673 | |
4434 | 4674 | $active = time() - $upcontext['updated']; |
4435 | - if ($active < 60) |
|
4436 | - $updated = $active . ' seconds'; |
|
4437 | - elseif ($active < 3600) |
|
4438 | - $updated = (int) ($active / 60) . ' minutes'; |
|
4439 | - else |
|
4440 | - $updated = (int) ($active / 3600) . ' hours'; |
|
4675 | + if ($active < 60) { |
|
4676 | + $updated = $active . ' seconds'; |
|
4677 | + } elseif ($active < 3600) { |
|
4678 | + $updated = (int) ($active / 60) . ' minutes'; |
|
4679 | + } else { |
|
4680 | + $updated = (int) ($active / 3600) . ' hours'; |
|
4681 | + } |
|
4441 | 4682 | |
4442 | 4683 | echo ' |
4443 | 4684 | <div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;"> |
@@ -4446,16 +4687,18 @@ discard block |
||
4446 | 4687 | <div style="padding-left: 6ex;"> |
4447 | 4688 | "', $upcontext['user']['name'], '" has been running the upgrade script for the last ', $ago, ' - and was last active ', $updated, ' ago.'; |
4448 | 4689 | |
4449 | - if ($active < 600) |
|
4450 | - echo ' |
|
4690 | + if ($active < 600) { |
|
4691 | + echo ' |
|
4451 | 4692 | We recommend that you do not run this script unless you are sure that ', $upcontext['user']['name'], ' has completed their upgrade.'; |
4693 | + } |
|
4452 | 4694 | |
4453 | - if ($active > $upcontext['inactive_timeout']) |
|
4454 | - echo ' |
|
4695 | + if ($active > $upcontext['inactive_timeout']) { |
|
4696 | + echo ' |
|
4455 | 4697 | <br><br>You can choose to either run the upgrade again from the beginning - or alternatively continue from the last step reached during the last upgrade.'; |
4456 | - else |
|
4457 | - echo ' |
|
4698 | + } else { |
|
4699 | + echo ' |
|
4458 | 4700 | <br><br>This upgrade script cannot be run until ', $upcontext['user']['name'], ' has been inactive for at least ', ($upcontext['inactive_timeout'] > 120 ? round($upcontext['inactive_timeout'] / 60, 1) . ' minutes!' : $upcontext['inactive_timeout'] . ' seconds!'); |
4701 | + } |
|
4459 | 4702 | |
4460 | 4703 | echo ' |
4461 | 4704 | </div> |
@@ -4471,9 +4714,10 @@ discard block |
||
4471 | 4714 | <td> |
4472 | 4715 | <input type="text" name="user" value="', !empty($upcontext['username']) ? $upcontext['username'] : '', '"', $disable_security ? ' disabled' : '', ' class="input_text">'; |
4473 | 4716 | |
4474 | - if (!empty($upcontext['username_incorrect'])) |
|
4475 | - echo ' |
|
4717 | + if (!empty($upcontext['username_incorrect'])) { |
|
4718 | + echo ' |
|
4476 | 4719 | <div class="smalltext" style="color: red;">Username Incorrect</div>'; |
4720 | + } |
|
4477 | 4721 | |
4478 | 4722 | echo ' |
4479 | 4723 | </td> |
@@ -4484,9 +4728,10 @@ discard block |
||
4484 | 4728 | <input type="password" name="passwrd" value=""', $disable_security ? ' disabled' : '', ' class="input_password"> |
4485 | 4729 | <input type="hidden" name="hash_passwrd" value="">'; |
4486 | 4730 | |
4487 | - if (!empty($upcontext['password_failed'])) |
|
4488 | - echo ' |
|
4731 | + if (!empty($upcontext['password_failed'])) { |
|
4732 | + echo ' |
|
4489 | 4733 | <div class="smalltext" style="color: red;">Password Incorrect</div>'; |
4734 | + } |
|
4490 | 4735 | |
4491 | 4736 | echo ' |
4492 | 4737 | </td> |
@@ -4557,8 +4802,8 @@ discard block |
||
4557 | 4802 | <form action="', $upcontext['form_url'], '" method="post" name="upform" id="upform">'; |
4558 | 4803 | |
4559 | 4804 | // Warning message? |
4560 | - if (!empty($upcontext['upgrade_options_warning'])) |
|
4561 | - echo ' |
|
4805 | + if (!empty($upcontext['upgrade_options_warning'])) { |
|
4806 | + echo ' |
|
4562 | 4807 | <div style="margin: 1ex; padding: 1ex; border: 1px dashed #cc3344; color: black; background-color: #ffe4e9;"> |
4563 | 4808 | <div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div> |
4564 | 4809 | <strong style="text-decoration: underline;">Warning!</strong><br> |
@@ -4566,6 +4811,7 @@ discard block |
||
4566 | 4811 | ', $upcontext['upgrade_options_warning'], ' |
4567 | 4812 | </div> |
4568 | 4813 | </div>'; |
4814 | + } |
|
4569 | 4815 | |
4570 | 4816 | echo ' |
4571 | 4817 | <table> |
@@ -4593,8 +4839,8 @@ discard block |
||
4593 | 4839 | </tr>'; |
4594 | 4840 | |
4595 | 4841 | // Offer mysql users to switch to mysqli |
4596 | - if ($db_type == 'mysql' && function_exists('mysqli_query')) |
|
4597 | - echo ' |
|
4842 | + if ($db_type == 'mysql' && function_exists('mysqli_query')) { |
|
4843 | + echo ' |
|
4598 | 4844 | <tr valign="top"> |
4599 | 4845 | <td width="2%"> |
4600 | 4846 | <input type="checkbox" name="convertMysql" id="convertMysql" value="1" checked class="input_check"> |
@@ -4604,6 +4850,7 @@ discard block |
||
4604 | 4850 | <strong class="smalltext"><a href="http://wiki.simplemachines.org/smf/Upgrading-MySQLi-Functionality" target="_blank">More information about MySQLi</a></strong><br> |
4605 | 4851 | </td> |
4606 | 4852 | </tr>'; |
4853 | + } |
|
4607 | 4854 | |
4608 | 4855 | echo ' |
4609 | 4856 | <tr valign="top"> |
@@ -4623,8 +4870,8 @@ discard block |
||
4623 | 4870 | </td> |
4624 | 4871 | </tr>'; |
4625 | 4872 | |
4626 | - if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) |
|
4627 | - echo ' |
|
4873 | + if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) { |
|
4874 | + echo ' |
|
4628 | 4875 | <tr valign="top"> |
4629 | 4876 | <td width="2%"> |
4630 | 4877 | <input type="checkbox" name="delete_karma" id="delete_karma" value="1" class="input_check"> |
@@ -4633,6 +4880,7 @@ discard block |
||
4633 | 4880 | <label for="delete_karma">Delete all karma settings and info from the DB</label> |
4634 | 4881 | </td> |
4635 | 4882 | </tr>'; |
4883 | + } |
|
4636 | 4884 | |
4637 | 4885 | echo ' |
4638 | 4886 | <tr valign="top"> |
@@ -4668,10 +4916,11 @@ discard block |
||
4668 | 4916 | <span id="debuginfo"></span>'; |
4669 | 4917 | |
4670 | 4918 | // Dont any tables so far? |
4671 | - if (!empty($upcontext['previous_tables'])) |
|
4672 | - foreach ($upcontext['previous_tables'] as $table) |
|
4919 | + if (!empty($upcontext['previous_tables'])) { |
|
4920 | + foreach ($upcontext['previous_tables'] as $table) |
|
4673 | 4921 | echo ' |
4674 | 4922 | <br>Completed Table: "', $table, '".'; |
4923 | + } |
|
4675 | 4924 | |
4676 | 4925 | echo ' |
4677 | 4926 | <h3 id="current_tab_div">Current Table: "<span id="current_table">', $upcontext['cur_table_name'], '</span>"</h3> |
@@ -4708,12 +4957,13 @@ discard block |
||
4708 | 4957 | updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');'; |
4709 | 4958 | |
4710 | 4959 | // If debug flood the screen. |
4711 | - if ($is_debug) |
|
4712 | - echo ' |
|
4960 | + if ($is_debug) { |
|
4961 | + echo ' |
|
4713 | 4962 | setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: "\' + sCompletedTableName + \'".<span id="debuginfo"><\' + \'/span>\'); |
4714 | 4963 | |
4715 | 4964 | if (document.getElementById(\'debuginfo\').scrollHeight) |
4716 | 4965 | document.getElementById(\'debuginfo\').scrollTop = document.getElementById(\'debuginfo\').scrollHeight;'; |
4966 | + } |
|
4717 | 4967 | |
4718 | 4968 | echo ' |
4719 | 4969 | // Get the next update... |
@@ -4745,8 +4995,9 @@ discard block |
||
4745 | 4995 | { |
4746 | 4996 | global $upcontext, $support_js, $is_debug, $timeLimitThreshold; |
4747 | 4997 | |
4748 | - if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) |
|
4749 | - $is_debug = true; |
|
4998 | + if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) { |
|
4999 | + $is_debug = true; |
|
5000 | + } |
|
4750 | 5001 | |
4751 | 5002 | echo ' |
4752 | 5003 | <h3>Executing database changes</h3> |
@@ -4761,8 +5012,9 @@ discard block |
||
4761 | 5012 | { |
4762 | 5013 | foreach ($upcontext['actioned_items'] as $num => $item) |
4763 | 5014 | { |
4764 | - if ($num != 0) |
|
4765 | - echo ' Successful!'; |
|
5015 | + if ($num != 0) { |
|
5016 | + echo ' Successful!'; |
|
5017 | + } |
|
4766 | 5018 | echo '<br>' . $item; |
4767 | 5019 | } |
4768 | 5020 | if (!empty($upcontext['changes_complete'])) |
@@ -4775,28 +5027,32 @@ discard block |
||
4775 | 5027 | $seconds = intval($active % 60); |
4776 | 5028 | |
4777 | 5029 | $totalTime = ''; |
4778 | - if ($hours > 0) |
|
4779 | - $totalTime .= $hours . ' hour' . ($hours > 1 ? 's':'') . ' '; |
|
4780 | - if ($minutes > 0) |
|
4781 | - $totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's':'') . ' '; |
|
4782 | - if ($seconds > 0) |
|
4783 | - $totalTime .= $seconds . ' second' . ($seconds > 1 ? 's':'') . ' '; |
|
5030 | + if ($hours > 0) { |
|
5031 | + $totalTime .= $hours . ' hour' . ($hours > 1 ? 's':'') . ' '; |
|
5032 | + } |
|
5033 | + if ($minutes > 0) { |
|
5034 | + $totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's':'') . ' '; |
|
5035 | + } |
|
5036 | + if ($seconds > 0) { |
|
5037 | + $totalTime .= $seconds . ' second' . ($seconds > 1 ? 's':'') . ' '; |
|
5038 | + } |
|
4784 | 5039 | } |
4785 | 5040 | |
4786 | - if ($is_debug && !empty($totalTime)) |
|
4787 | - echo ' Successful! Completed in ', $totalTime, '<br><br>'; |
|
4788 | - else |
|
4789 | - echo ' Successful!<br><br>'; |
|
5041 | + if ($is_debug && !empty($totalTime)) { |
|
5042 | + echo ' Successful! Completed in ', $totalTime, '<br><br>'; |
|
5043 | + } else { |
|
5044 | + echo ' Successful!<br><br>'; |
|
5045 | + } |
|
4790 | 5046 | |
4791 | 5047 | echo '<span id="commess" style="font-weight: bold;">1 Database Updates Complete! Click Continue to Proceed.</span><br>'; |
4792 | 5048 | } |
4793 | - } |
|
4794 | - else |
|
5049 | + } else |
|
4795 | 5050 | { |
4796 | 5051 | // Tell them how many files we have in total. |
4797 | - if ($upcontext['file_count'] > 1) |
|
4798 | - echo ' |
|
5052 | + if ($upcontext['file_count'] > 1) { |
|
5053 | + echo ' |
|
4799 | 5054 | <strong id="info1">Executing upgrade script <span id="file_done">', $upcontext['cur_file_num'], '</span> of ', $upcontext['file_count'], '.</strong>'; |
5055 | + } |
|
4800 | 5056 | |
4801 | 5057 | echo ' |
4802 | 5058 | <h3 id="info2"><strong>Executing:</strong> "<span id="cur_item_name">', $upcontext['current_item_name'], '</span>" (<span id="item_num">', $upcontext['current_item_num'], '</span> of <span id="total_items"><span id="item_count">', $upcontext['total_items'], '</span>', $upcontext['file_count'] > 1 ? ' - of this script' : '', ')</span></h3> |
@@ -4812,19 +5068,23 @@ discard block |
||
4812 | 5068 | $seconds = intval($active % 60); |
4813 | 5069 | |
4814 | 5070 | $totalTime = ''; |
4815 | - if ($hours > 0) |
|
4816 | - $totalTime .= $hours . ' hour' . ($hours > 1 ? 's':'') . ' '; |
|
4817 | - if ($minutes > 0) |
|
4818 | - $totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's':'') . ' '; |
|
4819 | - if ($seconds > 0) |
|
4820 | - $totalTime .= $seconds . ' second' . ($seconds > 1 ? 's':'') . ' '; |
|
5071 | + if ($hours > 0) { |
|
5072 | + $totalTime .= $hours . ' hour' . ($hours > 1 ? 's':'') . ' '; |
|
5073 | + } |
|
5074 | + if ($minutes > 0) { |
|
5075 | + $totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's':'') . ' '; |
|
5076 | + } |
|
5077 | + if ($seconds > 0) { |
|
5078 | + $totalTime .= $seconds . ' second' . ($seconds > 1 ? 's':'') . ' '; |
|
5079 | + } |
|
4821 | 5080 | } |
4822 | 5081 | |
4823 | 5082 | echo ' |
4824 | 5083 | <br><span id="upgradeCompleted">'; |
4825 | 5084 | |
4826 | - if (!empty($totalTime)) |
|
4827 | - echo 'Completed in ', $totalTime, '<br>'; |
|
5085 | + if (!empty($totalTime)) { |
|
5086 | + echo 'Completed in ', $totalTime, '<br>'; |
|
5087 | + } |
|
4828 | 5088 | |
4829 | 5089 | echo '</span> |
4830 | 5090 | <div id="debug_section" style="height: 200px; overflow: auto;"> |
@@ -4861,9 +5121,10 @@ discard block |
||
4861 | 5121 | var getData = ""; |
4862 | 5122 | var debugItems = ', $upcontext['debug_items'], ';'; |
4863 | 5123 | |
4864 | - if ($is_debug) |
|
4865 | - echo ' |
|
5124 | + if ($is_debug) { |
|
5125 | + echo ' |
|
4866 | 5126 | var upgradeStartTime = ' . $upcontext['started'] . ';'; |
5127 | + } |
|
4867 | 5128 | |
4868 | 5129 | echo ' |
4869 | 5130 | function getNextItem() |
@@ -4903,9 +5164,10 @@ discard block |
||
4903 | 5164 | document.getElementById("error_block").style.display = ""; |
4904 | 5165 | setInnerHTML(document.getElementById("error_message"), "Error retrieving information on step: " + (sDebugName == "" ? sLastString : sDebugName));'; |
4905 | 5166 | |
4906 | - if ($is_debug) |
|
4907 | - echo ' |
|
5167 | + if ($is_debug) { |
|
5168 | + echo ' |
|
4908 | 5169 | setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');'; |
5170 | + } |
|
4909 | 5171 | |
4910 | 5172 | echo ' |
4911 | 5173 | } |
@@ -4926,9 +5188,10 @@ discard block |
||
4926 | 5188 | document.getElementById("error_block").style.display = ""; |
4927 | 5189 | setInnerHTML(document.getElementById("error_message"), "Upgrade script appears to be going into a loop - step: " + sDebugName);'; |
4928 | 5190 | |
4929 | - if ($is_debug) |
|
4930 | - echo ' |
|
5191 | + if ($is_debug) { |
|
5192 | + echo ' |
|
4931 | 5193 | setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');'; |
5194 | + } |
|
4932 | 5195 | |
4933 | 5196 | echo ' |
4934 | 5197 | } |
@@ -4987,8 +5250,8 @@ discard block |
||
4987 | 5250 | if (bIsComplete && iDebugNum == -1 && curFile >= ', $upcontext['file_count'], ') |
4988 | 5251 | {'; |
4989 | 5252 | |
4990 | - if ($is_debug) |
|
4991 | - echo ' |
|
5253 | + if ($is_debug) { |
|
5254 | + echo ' |
|
4992 | 5255 | document.getElementById(\'debug_section\').style.display = "none"; |
4993 | 5256 | |
4994 | 5257 | var upgradeFinishedTime = parseInt(oXMLDoc.getElementsByTagName("curtime")[0].childNodes[0].nodeValue); |
@@ -5006,6 +5269,7 @@ discard block |
||
5006 | 5269 | totalTime = totalTime + diffSeconds + " second" + (diffSeconds > 1 ? "s" : ""); |
5007 | 5270 | |
5008 | 5271 | setInnerHTML(document.getElementById("upgradeCompleted"), "Completed in " + totalTime);'; |
5272 | + } |
|
5009 | 5273 | |
5010 | 5274 | echo ' |
5011 | 5275 | |
@@ -5013,9 +5277,10 @@ discard block |
||
5013 | 5277 | document.getElementById(\'contbutt\').disabled = 0; |
5014 | 5278 | document.getElementById(\'database_done\').value = 1;'; |
5015 | 5279 | |
5016 | - if ($upcontext['file_count'] > 1) |
|
5017 | - echo ' |
|
5280 | + if ($upcontext['file_count'] > 1) { |
|
5281 | + echo ' |
|
5018 | 5282 | document.getElementById(\'info1\').style.display = "none";'; |
5283 | + } |
|
5019 | 5284 | |
5020 | 5285 | echo ' |
5021 | 5286 | document.getElementById(\'info2\').style.display = "none"; |
@@ -5028,9 +5293,10 @@ discard block |
||
5028 | 5293 | lastItem = 0; |
5029 | 5294 | prevFile = curFile;'; |
5030 | 5295 | |
5031 | - if ($is_debug) |
|
5032 | - echo ' |
|
5296 | + if ($is_debug) { |
|
5297 | + echo ' |
|
5033 | 5298 | setOuterHTML(document.getElementById(\'debuginfo\'), \'Moving to next script file...done<br><span id="debuginfo"><\' + \'/span>\');'; |
5299 | + } |
|
5034 | 5300 | |
5035 | 5301 | echo ' |
5036 | 5302 | getNextItem(); |
@@ -5038,8 +5304,8 @@ discard block |
||
5038 | 5304 | }'; |
5039 | 5305 | |
5040 | 5306 | // If debug scroll the screen. |
5041 | - if ($is_debug) |
|
5042 | - echo ' |
|
5307 | + if ($is_debug) { |
|
5308 | + echo ' |
|
5043 | 5309 | if (iLastSubStepProgress == -1) |
5044 | 5310 | { |
5045 | 5311 | // Give it consistent dots. |
@@ -5058,6 +5324,7 @@ discard block |
||
5058 | 5324 | |
5059 | 5325 | if (document.getElementById(\'debug_section\').scrollHeight) |
5060 | 5326 | document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight'; |
5327 | + } |
|
5061 | 5328 | |
5062 | 5329 | echo ' |
5063 | 5330 | // Update the page. |
@@ -5118,9 +5385,10 @@ discard block |
||
5118 | 5385 | }'; |
5119 | 5386 | |
5120 | 5387 | // Start things off assuming we've not errored. |
5121 | - if (empty($upcontext['error_message'])) |
|
5122 | - echo ' |
|
5388 | + if (empty($upcontext['error_message'])) { |
|
5389 | + echo ' |
|
5123 | 5390 | getNextItem();'; |
5391 | + } |
|
5124 | 5392 | |
5125 | 5393 | echo ' |
5126 | 5394 | </script>'; |
@@ -5137,18 +5405,21 @@ discard block |
||
5137 | 5405 | <item num="', $upcontext['current_item_num'], '">', $upcontext['current_item_name'], '</item> |
5138 | 5406 | <debug num="', $upcontext['current_debug_item_num'], '" percent="', isset($upcontext['substep_progress']) ? $upcontext['substep_progress'] : '-1', '" complete="', empty($upcontext['completed_step']) ? 0 : 1, '">', $upcontext['current_debug_item_name'], '</debug>'; |
5139 | 5407 | |
5140 | - if (!empty($upcontext['error_message'])) |
|
5141 | - echo ' |
|
5408 | + if (!empty($upcontext['error_message'])) { |
|
5409 | + echo ' |
|
5142 | 5410 | <error>', $upcontext['error_message'], '</error>'; |
5411 | + } |
|
5143 | 5412 | |
5144 | - if (!empty($upcontext['error_string'])) |
|
5145 | - echo ' |
|
5413 | + if (!empty($upcontext['error_string'])) { |
|
5414 | + echo ' |
|
5146 | 5415 | <sql>', $upcontext['error_string'], '</sql>'; |
5416 | + } |
|
5147 | 5417 | |
5148 | - if ($is_debug) |
|
5149 | - echo ' |
|
5418 | + if ($is_debug) { |
|
5419 | + echo ' |
|
5150 | 5420 | <curtime>', time(), '</curtime>'; |
5151 | -} |
|
5421 | + } |
|
5422 | + } |
|
5152 | 5423 | |
5153 | 5424 | // Template for the UTF-8 conversion step. Basically a copy of the backup stuff with slight modifications.... |
5154 | 5425 | function template_convert_utf8() |
@@ -5165,18 +5436,20 @@ discard block |
||
5165 | 5436 | <span id="debuginfo"></span>'; |
5166 | 5437 | |
5167 | 5438 | // Done any tables so far? |
5168 | - if (!empty($upcontext['previous_tables'])) |
|
5169 | - foreach ($upcontext['previous_tables'] as $table) |
|
5439 | + if (!empty($upcontext['previous_tables'])) { |
|
5440 | + foreach ($upcontext['previous_tables'] as $table) |
|
5170 | 5441 | echo ' |
5171 | 5442 | <br>Completed Table: "', $table, '".'; |
5443 | + } |
|
5172 | 5444 | |
5173 | 5445 | echo ' |
5174 | 5446 | <h3 id="current_tab_div">Current Table: "<span id="current_table">', $upcontext['cur_table_name'], '</span>"</h3>'; |
5175 | 5447 | |
5176 | 5448 | // If we dropped their index, let's let them know |
5177 | - if ($upcontext['cur_table_num'] == $upcontext['table_count'] && $upcontext['dropping_index']) |
|
5178 | - echo ' |
|
5449 | + if ($upcontext['cur_table_num'] == $upcontext['table_count'] && $upcontext['dropping_index']) { |
|
5450 | + echo ' |
|
5179 | 5451 | <br><span style="display:inline;">Please note that your fulltext index was dropped to facilitate the conversion and will need to be recreated.</span>'; |
5452 | + } |
|
5180 | 5453 | |
5181 | 5454 | echo ' |
5182 | 5455 | <br><span id="commess" style="font-weight: bold; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">Conversion Complete! Click Continue to Proceed.</span>'; |
@@ -5212,9 +5485,10 @@ discard block |
||
5212 | 5485 | updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');'; |
5213 | 5486 | |
5214 | 5487 | // If debug flood the screen. |
5215 | - if ($is_debug) |
|
5216 | - echo ' |
|
5488 | + if ($is_debug) { |
|
5489 | + echo ' |
|
5217 | 5490 | setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: "\' + sCompletedTableName + \'".<span id="debuginfo"><\' + \'/span>\');'; |
5491 | + } |
|
5218 | 5492 | |
5219 | 5493 | echo ' |
5220 | 5494 | // Get the next update... |
@@ -5283,14 +5557,16 @@ discard block |
||
5283 | 5557 | <input type="hidden" name="cleandone" value="1">'; |
5284 | 5558 | |
5285 | 5559 | // Files to make writable? |
5286 | - if (!empty($upcontext['writable_files'])) |
|
5287 | - echo ' |
|
5560 | + if (!empty($upcontext['writable_files'])) { |
|
5561 | + echo ' |
|
5288 | 5562 | <input type="hidden" name="writable_files" value="', base64_encode(safe_serialize($upcontext['writable_files'])), '">'; |
5563 | + } |
|
5289 | 5564 | |
5290 | 5565 | // We'll want a continue button... |
5291 | - if (empty($upcontext['chmod']['files'])) |
|
5292 | - $upcontext['continue'] = 1; |
|
5293 | -} |
|
5566 | + if (empty($upcontext['chmod']['files'])) { |
|
5567 | + $upcontext['continue'] = 1; |
|
5568 | + } |
|
5569 | + } |
|
5294 | 5570 | |
5295 | 5571 | // Finished with the mods - let them know what we've done. |
5296 | 5572 | function template_cleanup_done() |
@@ -5352,8 +5628,9 @@ discard block |
||
5352 | 5628 | "', $language['name'], '" Language Pack |
5353 | 5629 | <div class="smalltext">('; |
5354 | 5630 | |
5355 | - foreach ($language['files'] as $k => $file) |
|
5356 | - echo $file['name'], $k + 1 != count($language['files']) ? ', ' : ')'; |
|
5631 | + foreach ($language['files'] as $k => $file) { |
|
5632 | + echo $file['name'], $k + 1 != count($language['files']) ? ', ' : ')'; |
|
5633 | + } |
|
5357 | 5634 | |
5358 | 5635 | echo ' |
5359 | 5636 | </div> |
@@ -5370,8 +5647,9 @@ discard block |
||
5370 | 5647 | "', $theme['name'], '" Theme |
5371 | 5648 | <div class="smalltext">('; |
5372 | 5649 | |
5373 | - foreach ($theme['files'] as $k => $file) |
|
5374 | - echo $file['name'], $k + 1 != count($theme['files']) ? ', ' : ')'; |
|
5650 | + foreach ($theme['files'] as $k => $file) { |
|
5651 | + echo $file['name'], $k + 1 != count($theme['files']) ? ', ' : ')'; |
|
5652 | + } |
|
5375 | 5653 | |
5376 | 5654 | echo ' |
5377 | 5655 | </div> |
@@ -5382,47 +5660,54 @@ discard block |
||
5382 | 5660 | |
5383 | 5661 | echo ' |
5384 | 5662 | </table>'; |
5385 | - } |
|
5386 | - else |
|
5663 | + } else |
|
5387 | 5664 | { |
5388 | 5665 | $langFiles = 0; |
5389 | 5666 | $themeFiles = 0; |
5390 | - if (!empty($upcontext['languages'])) |
|
5391 | - foreach ($upcontext['languages'] as $lang) |
|
5667 | + if (!empty($upcontext['languages'])) { |
|
5668 | + foreach ($upcontext['languages'] as $lang) |
|
5392 | 5669 | $langFiles += count($lang['files']); |
5393 | - if (!empty($upcontext['themes'])) |
|
5394 | - foreach ($upcontext['themes'] as $theme) |
|
5670 | + } |
|
5671 | + if (!empty($upcontext['themes'])) { |
|
5672 | + foreach ($upcontext['themes'] as $theme) |
|
5395 | 5673 | $themeFiles += count($theme['files']); |
5674 | + } |
|
5396 | 5675 | echo sprintf('Found <strong>%d</strong> language files and <strong>%d</strong> templates requiring an update so far.', $langFiles, $themeFiles) . '<br>'; |
5397 | 5676 | |
5398 | 5677 | // What we're currently doing? |
5399 | - if (!empty($upcontext['current_message'])) |
|
5400 | - echo ' |
|
5678 | + if (!empty($upcontext['current_message'])) { |
|
5679 | + echo ' |
|
5401 | 5680 | ', $upcontext['current_message']; |
5681 | + } |
|
5402 | 5682 | } |
5403 | 5683 | |
5404 | 5684 | echo ' |
5405 | 5685 | <input type="hidden" name="uptempdone" value="1">'; |
5406 | 5686 | |
5407 | - if (!empty($upcontext['languages'])) |
|
5408 | - echo ' |
|
5687 | + if (!empty($upcontext['languages'])) { |
|
5688 | + echo ' |
|
5409 | 5689 | <input type="hidden" name="languages" value="', base64_encode(safe_serialize($upcontext['languages'])), '">'; |
5410 | - if (!empty($upcontext['themes'])) |
|
5411 | - echo ' |
|
5690 | + } |
|
5691 | + if (!empty($upcontext['themes'])) { |
|
5692 | + echo ' |
|
5412 | 5693 | <input type="hidden" name="themes" value="', base64_encode(safe_serialize($upcontext['themes'])), '">'; |
5413 | - if (!empty($upcontext['writable_files'])) |
|
5414 | - echo ' |
|
5694 | + } |
|
5695 | + if (!empty($upcontext['writable_files'])) { |
|
5696 | + echo ' |
|
5415 | 5697 | <input type="hidden" name="writable_files" value="', base64_encode(safe_serialize($upcontext['writable_files'])), '">'; |
5698 | + } |
|
5416 | 5699 | |
5417 | 5700 | // Offer them the option to upgrade from YaBB SE? |
5418 | - if (!empty($upcontext['can_upgrade_yabbse'])) |
|
5419 | - echo ' |
|
5701 | + if (!empty($upcontext['can_upgrade_yabbse'])) { |
|
5702 | + echo ' |
|
5420 | 5703 | <br><label for="conv"><input type="checkbox" name="conv" id="conv" value="1" class="input_check"> Convert the existing YaBB SE template and set it as default.</label><br>'; |
5704 | + } |
|
5421 | 5705 | |
5422 | 5706 | // We'll want a continue button... assuming chmod is OK (Otherwise let them use connect!) |
5423 | - if (empty($upcontext['chmod']['files']) || $upcontext['is_test']) |
|
5424 | - $upcontext['continue'] = 1; |
|
5425 | -} |
|
5707 | + if (empty($upcontext['chmod']['files']) || $upcontext['is_test']) { |
|
5708 | + $upcontext['continue'] = 1; |
|
5709 | + } |
|
5710 | + } |
|
5426 | 5711 | |
5427 | 5712 | // Template for the database backup tool/ |
5428 | 5713 | function template_serialize_json() |
@@ -5439,19 +5724,21 @@ discard block |
||
5439 | 5724 | <span id="debuginfo"></span>'; |
5440 | 5725 | |
5441 | 5726 | // Dont any tables so far? |
5442 | - if (!empty($upcontext['previous_tables'])) |
|
5443 | - foreach ($upcontext['previous_tables'] as $table) |
|
5727 | + if (!empty($upcontext['previous_tables'])) { |
|
5728 | + foreach ($upcontext['previous_tables'] as $table) |
|
5444 | 5729 | echo ' |
5445 | 5730 | <br>Completed Table: "', $table, '".'; |
5731 | + } |
|
5446 | 5732 | |
5447 | 5733 | echo ' |
5448 | 5734 | <h3 id="current_tab_div">Current Table: "<span id="current_table">', $upcontext['cur_table_name'], '</span>"</h3> |
5449 | 5735 | <br><span id="commess" style="font-weight: bold; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">Convert to JSON Complete! Click Continue to Proceed.</span>'; |
5450 | 5736 | |
5451 | 5737 | // Try to make sure substep was reset. |
5452 | - if ($upcontext['cur_table_num'] == $upcontext['table_count']) |
|
5453 | - echo ' |
|
5738 | + if ($upcontext['cur_table_num'] == $upcontext['table_count']) { |
|
5739 | + echo ' |
|
5454 | 5740 | <input type="hidden" name="substep" id="substep" value="0">'; |
5741 | + } |
|
5455 | 5742 | |
5456 | 5743 | // Continue please! |
5457 | 5744 | $upcontext['continue'] = $support_js ? 2 : 1; |
@@ -5484,9 +5771,10 @@ discard block |
||
5484 | 5771 | updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');'; |
5485 | 5772 | |
5486 | 5773 | // If debug flood the screen. |
5487 | - if ($is_debug) |
|
5488 | - echo ' |
|
5774 | + if ($is_debug) { |
|
5775 | + echo ' |
|
5489 | 5776 | setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: "\' + sCompletedTableName + \'".<span id="debuginfo"><\' + \'/span>\');'; |
5777 | + } |
|
5490 | 5778 | |
5491 | 5779 | echo ' |
5492 | 5780 | // Get the next update... |
@@ -5521,8 +5809,8 @@ discard block |
||
5521 | 5809 | <h3>That wasn\'t so hard, was it? Now you are ready to use <a href="', $boardurl, '/index.php">your installation of SMF</a>. Hope you like it!</h3> |
5522 | 5810 | <form action="', $boardurl, '/index.php">'; |
5523 | 5811 | |
5524 | - if (!empty($upcontext['can_delete_script'])) |
|
5525 | - echo ' |
|
5812 | + if (!empty($upcontext['can_delete_script'])) { |
|
5813 | + echo ' |
|
5526 | 5814 | <label for="delete_self"><input type="checkbox" id="delete_self" onclick="doTheDelete(this);" class="input_check"> Delete upgrade.php and its data files now</label> <em>(doesn\'t work on all servers).</em> |
5527 | 5815 | <script> |
5528 | 5816 | function doTheDelete(theCheck) |
@@ -5534,6 +5822,7 @@ discard block |
||
5534 | 5822 | } |
5535 | 5823 | </script> |
5536 | 5824 | <img src="', $settings['default_theme_url'], '/images/blank.png" alt="" id="delete_upgrader"><br>'; |
5825 | + } |
|
5537 | 5826 | |
5538 | 5827 | $active = time() - $upcontext['started']; |
5539 | 5828 | $hours = floor($active / 3600); |
@@ -5543,16 +5832,20 @@ discard block |
||
5543 | 5832 | if ($is_debug) |
5544 | 5833 | { |
5545 | 5834 | $totalTime = ''; |
5546 | - if ($hours > 0) |
|
5547 | - $totalTime .= $hours . ' hour' . ($hours > 1 ? 's':'') . ' '; |
|
5548 | - if ($minutes > 0) |
|
5549 | - $totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's':'') . ' '; |
|
5550 | - if ($seconds > 0) |
|
5551 | - $totalTime .= $seconds . ' second' . ($seconds > 1 ? 's':'') . ' '; |
|
5835 | + if ($hours > 0) { |
|
5836 | + $totalTime .= $hours . ' hour' . ($hours > 1 ? 's':'') . ' '; |
|
5837 | + } |
|
5838 | + if ($minutes > 0) { |
|
5839 | + $totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's':'') . ' '; |
|
5840 | + } |
|
5841 | + if ($seconds > 0) { |
|
5842 | + $totalTime .= $seconds . ' second' . ($seconds > 1 ? 's':'') . ' '; |
|
5843 | + } |
|
5552 | 5844 | } |
5553 | 5845 | |
5554 | - if ($is_debug && !empty($totalTime)) |
|
5555 | - echo '<br> Upgrade completed in ', $totalTime, '<br><br>'; |
|
5846 | + if ($is_debug && !empty($totalTime)) { |
|
5847 | + echo '<br> Upgrade completed in ', $totalTime, '<br><br>'; |
|
5848 | + } |
|
5556 | 5849 | |
5557 | 5850 | echo '<br> |
5558 | 5851 | If you had any problems with this upgrade, or have any problems using SMF, please don\'t hesitate to <a href="http://www.simplemachines.org/community/index.php">look to us for assistance</a>.<br> |
@@ -5609,16 +5902,19 @@ discard block |
||
5609 | 5902 | 'empty' => '', |
5610 | 5903 | 'limit' => $limit, |
5611 | 5904 | )); |
5612 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
5613 | - $arIp[] = $row[$oldCol]; |
|
5905 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
5906 | + $arIp[] = $row[$oldCol]; |
|
5907 | + } |
|
5614 | 5908 | $smcFunc['db_free_result']($request); |
5615 | 5909 | |
5616 | 5910 | // Special case, null ip could keep us in a loop. |
5617 | - if (is_null($arIp[0])) |
|
5618 | - unset($arIp[0]); |
|
5911 | + if (is_null($arIp[0])) { |
|
5912 | + unset($arIp[0]); |
|
5913 | + } |
|
5619 | 5914 | |
5620 | - if (empty($arIp)) |
|
5621 | - $is_done = true; |
|
5915 | + if (empty($arIp)) { |
|
5916 | + $is_done = true; |
|
5917 | + } |
|
5622 | 5918 | |
5623 | 5919 | $updates = array(); |
5624 | 5920 | $cases = array(); |
@@ -5626,16 +5922,18 @@ discard block |
||
5626 | 5922 | { |
5627 | 5923 | $arIp[$i] = trim($arIp[$i]); |
5628 | 5924 | |
5629 | - if (empty($arIp[$i])) |
|
5630 | - continue; |
|
5925 | + if (empty($arIp[$i])) { |
|
5926 | + continue; |
|
5927 | + } |
|
5631 | 5928 | |
5632 | 5929 | $updates['ip' . $i] = trim($arIp[$i]); |
5633 | 5930 | $cases[trim($arIp[$i])] = 'WHEN ' . $oldCol . ' = {string:ip' . $i . '} THEN {inet:ip' . $i . '}'; |
5634 | 5931 | |
5635 | 5932 | if ($setSize > 0 && $i % $setSize === 0) |
5636 | 5933 | { |
5637 | - if (count($updates) == 1) |
|
5638 | - continue; |
|
5934 | + if (count($updates) == 1) { |
|
5935 | + continue; |
|
5936 | + } |
|
5639 | 5937 | |
5640 | 5938 | $updates['whereSet'] = array_values($updates); |
5641 | 5939 | $smcFunc['db_query']('', ' |
@@ -5669,8 +5967,7 @@ discard block |
||
5669 | 5967 | 'ip' => $ip |
5670 | 5968 | )); |
5671 | 5969 | } |
5672 | - } |
|
5673 | - else |
|
5970 | + } else |
|
5674 | 5971 | { |
5675 | 5972 | $updates['whereSet'] = array_values($updates); |
5676 | 5973 | $request = $smcFunc['db_query']('', ' |
@@ -5684,9 +5981,9 @@ discard block |
||
5684 | 5981 | $updates |
5685 | 5982 | ); |
5686 | 5983 | } |
5984 | + } else { |
|
5985 | + $is_done = true; |
|
5687 | 5986 | } |
5688 | - else |
|
5689 | - $is_done = true; |
|
5690 | 5987 | |
5691 | 5988 | $_GET['a'] += $limit; |
5692 | 5989 | $step_progress['current'] = $_GET['a']; |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | * Start the curl object |
63 | 63 | * - allow for user override values |
64 | 64 | * |
65 | - * @param array $options An array of cURL options |
|
65 | + * @param integer[] $options An array of cURL options |
|
66 | 66 | * @param int $max_redirect Maximum number of redirects |
67 | 67 | * @return void |
68 | 68 | */ |
@@ -81,8 +81,8 @@ discard block |
||
81 | 81 | * - calls set_options to set the curl opts array values based on the defaults and user input |
82 | 82 | * |
83 | 83 | * @param string $url the site we are going to fetch |
84 | - * @param array $post_data any post data as form name => value |
|
85 | - * @return object An instance of the curl_fetch_web_data class |
|
84 | + * @param string $post_data any post data as form name => value |
|
85 | + * @return curl_fetch_web_data An instance of the curl_fetch_web_data class |
|
86 | 86 | */ |
87 | 87 | public function get_url_data($url, $post_data = array()) |
88 | 88 | { |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | * |
107 | 107 | * @param string $url The site to fetch |
108 | 108 | * @param bool $redirect Whether or not this was a redirect request |
109 | - * @return void|bool Sets various properties of the class or returns false if the URL isn't specified |
|
109 | + * @return false|null Sets various properties of the class or returns false if the URL isn't specified |
|
110 | 110 | */ |
111 | 111 | private function curl_request($url, $redirect = false) |
112 | 112 | { |
@@ -59,13 +59,13 @@ discard block |
||
59 | 59 | ); |
60 | 60 | |
61 | 61 | /** |
62 | - * Start the curl object |
|
63 | - * - allow for user override values |
|
64 | - * |
|
65 | - * @param array $options An array of cURL options |
|
66 | - * @param int $max_redirect Maximum number of redirects |
|
67 | - * @return void |
|
68 | - */ |
|
62 | + * Start the curl object |
|
63 | + * - allow for user override values |
|
64 | + * |
|
65 | + * @param array $options An array of cURL options |
|
66 | + * @param int $max_redirect Maximum number of redirects |
|
67 | + * @return void |
|
68 | + */ |
|
69 | 69 | public function __construct($options = array(), $max_redirect = 3) |
70 | 70 | { |
71 | 71 | // Initialize class variables |
@@ -74,16 +74,16 @@ discard block |
||
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
77 | - * Main calling function, |
|
78 | - * - will request the page data from a given $url |
|
79 | - * - optionally will post data to the page form if post data is supplied |
|
80 | - * - passed arrays will be converted to a post string joined with &'s |
|
81 | - * - calls set_options to set the curl opts array values based on the defaults and user input |
|
82 | - * |
|
83 | - * @param string $url the site we are going to fetch |
|
84 | - * @param array $post_data any post data as form name => value |
|
85 | - * @return object An instance of the curl_fetch_web_data class |
|
86 | - */ |
|
77 | + * Main calling function, |
|
78 | + * - will request the page data from a given $url |
|
79 | + * - optionally will post data to the page form if post data is supplied |
|
80 | + * - passed arrays will be converted to a post string joined with &'s |
|
81 | + * - calls set_options to set the curl opts array values based on the defaults and user input |
|
82 | + * |
|
83 | + * @param string $url the site we are going to fetch |
|
84 | + * @param array $post_data any post data as form name => value |
|
85 | + * @return object An instance of the curl_fetch_web_data class |
|
86 | + */ |
|
87 | 87 | public function get_url_data($url, $post_data = array()) |
88 | 88 | { |
89 | 89 | // POSTing some data perhaps? |
@@ -100,14 +100,14 @@ discard block |
||
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
103 | - * Makes the actual cURL call |
|
104 | - * - stores responses (url, code, error, headers, body) in the response array |
|
105 | - * - detects 301, 302, 307 codes and will redirect to the given response header location |
|
106 | - * |
|
107 | - * @param string $url The site to fetch |
|
108 | - * @param bool $redirect Whether or not this was a redirect request |
|
109 | - * @return void|bool Sets various properties of the class or returns false if the URL isn't specified |
|
110 | - */ |
|
103 | + * Makes the actual cURL call |
|
104 | + * - stores responses (url, code, error, headers, body) in the response array |
|
105 | + * - detects 301, 302, 307 codes and will redirect to the given response header location |
|
106 | + * |
|
107 | + * @param string $url The site to fetch |
|
108 | + * @param bool $redirect Whether or not this was a redirect request |
|
109 | + * @return void|bool Sets various properties of the class or returns false if the URL isn't specified |
|
110 | + */ |
|
111 | 111 | private function curl_request($url, $redirect = false) |
112 | 112 | { |
113 | 113 | // we do have a url I hope |
@@ -159,12 +159,12 @@ discard block |
||
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
162 | - * Used if being redirected to ensure we have a fully qualified address |
|
163 | - * |
|
164 | - * @param string $last_url The URL we went to |
|
165 | - * @param string $new_url The URL we were redirected to |
|
166 | - * @return string The new URL that was in the HTTP header |
|
167 | - */ |
|
162 | + * Used if being redirected to ensure we have a fully qualified address |
|
163 | + * |
|
164 | + * @param string $last_url The URL we went to |
|
165 | + * @param string $new_url The URL we were redirected to |
|
166 | + * @return string The new URL that was in the HTTP header |
|
167 | + */ |
|
168 | 168 | private function get_redirect_url($last_url = '', $new_url = '') |
169 | 169 | { |
170 | 170 | // Get the elements for these urls |
@@ -182,13 +182,13 @@ discard block |
||
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
185 | - * Used to return the results to the calling program |
|
186 | - * - called as ->result() will return the full final array |
|
187 | - * - called as ->result('body') to just return the page source of the result |
|
188 | - * |
|
189 | - * @param string $area Used to return an area such as body, header, error |
|
190 | - * @return string The response |
|
191 | - */ |
|
185 | + * Used to return the results to the calling program |
|
186 | + * - called as ->result() will return the full final array |
|
187 | + * - called as ->result('body') to just return the page source of the result |
|
188 | + * |
|
189 | + * @param string $area Used to return an area such as body, header, error |
|
190 | + * @return string The response |
|
191 | + */ |
|
192 | 192 | public function result($area = '') |
193 | 193 | { |
194 | 194 | $max_result = count($this->response) - 1; |
@@ -201,13 +201,13 @@ discard block |
||
201 | 201 | } |
202 | 202 | |
203 | 203 | /** |
204 | - * Will return all results from all loops (redirects) |
|
205 | - * - Can be called as ->result_raw(x) where x is a specific loop results. |
|
206 | - * - Call as ->result_raw() for everything. |
|
207 | - * |
|
208 | - * @param string $response_number Which response we want to get |
|
209 | - * @return array|string The entire response array or just the specified response |
|
210 | - */ |
|
204 | + * Will return all results from all loops (redirects) |
|
205 | + * - Can be called as ->result_raw(x) where x is a specific loop results. |
|
206 | + * - Call as ->result_raw() for everything. |
|
207 | + * |
|
208 | + * @param string $response_number Which response we want to get |
|
209 | + * @return array|string The entire response array or just the specified response |
|
210 | + */ |
|
211 | 211 | public function result_raw($response_number = '') |
212 | 212 | { |
213 | 213 | if (!is_numeric($response_number)) |
@@ -220,13 +220,13 @@ discard block |
||
220 | 220 | } |
221 | 221 | |
222 | 222 | /** |
223 | - * Takes supplied POST data and url encodes it |
|
224 | - * - forms the date (for post) in to a string var=xyz&var2=abc&var3=123 |
|
225 | - * - drops vars with @ since we don't support sending files (uploading) |
|
226 | - * |
|
227 | - * @param array|string $post_data The raw POST data |
|
228 | - * @return string A string of post data |
|
229 | - */ |
|
223 | + * Takes supplied POST data and url encodes it |
|
224 | + * - forms the date (for post) in to a string var=xyz&var2=abc&var3=123 |
|
225 | + * - drops vars with @ since we don't support sending files (uploading) |
|
226 | + * |
|
227 | + * @param array|string $post_data The raw POST data |
|
228 | + * @return string A string of post data |
|
229 | + */ |
|
230 | 230 | private function build_post_data($post_data) |
231 | 231 | { |
232 | 232 | if (is_array($post_data)) |
@@ -245,11 +245,11 @@ discard block |
||
245 | 245 | } |
246 | 246 | |
247 | 247 | /** |
248 | - * Sets the final cURL options for the current call |
|
249 | - * - overwrites our default values with user supplied ones or appends new user ones to what we have |
|
250 | - * - sets the callback function now that $this is existing |
|
251 | - * @return void |
|
252 | - */ |
|
248 | + * Sets the final cURL options for the current call |
|
249 | + * - overwrites our default values with user supplied ones or appends new user ones to what we have |
|
250 | + * - sets the callback function now that $this is existing |
|
251 | + * @return void |
|
252 | + */ |
|
253 | 253 | private function set_options() |
254 | 254 | { |
255 | 255 | // Callback to parse the returned headers, if any |
@@ -274,12 +274,12 @@ discard block |
||
274 | 274 | } |
275 | 275 | |
276 | 276 | /** |
277 | - * Called to initiate a redirect from a 301, 302 or 307 header |
|
278 | - * - resets the cURL options for the loop, sets the referrer flag |
|
279 | - * |
|
280 | - * @param string $target_url The URL we want to redirect to |
|
281 | - * @param string $referer_url The URL that we're redirecting from |
|
282 | - */ |
|
277 | + * Called to initiate a redirect from a 301, 302 or 307 header |
|
278 | + * - resets the cURL options for the loop, sets the referrer flag |
|
279 | + * |
|
280 | + * @param string $target_url The URL we want to redirect to |
|
281 | + * @param string $referer_url The URL that we're redirecting from |
|
282 | + */ |
|
283 | 283 | private function redirect($target_url, $referer_url) |
284 | 284 | { |
285 | 285 | // no no I last saw that over there ... really, 301, 302, 307 |
@@ -289,13 +289,13 @@ discard block |
||
289 | 289 | } |
290 | 290 | |
291 | 291 | /** |
292 | - * Callback function to parse returned headers |
|
293 | - * - lowercases everything to make it consistent |
|
294 | - * |
|
295 | - * @param type $cr Not sure what this is used for? |
|
296 | - * @param string $header The header |
|
297 | - * @return int The length of the header |
|
298 | - */ |
|
292 | + * Callback function to parse returned headers |
|
293 | + * - lowercases everything to make it consistent |
|
294 | + * |
|
295 | + * @param type $cr Not sure what this is used for? |
|
296 | + * @param string $header The header |
|
297 | + * @return int The length of the header |
|
298 | + */ |
|
299 | 299 | private function header_callback($cr, $header) |
300 | 300 | { |
301 | 301 | $_header = trim($header); |
@@ -10,8 +10,9 @@ discard block |
||
10 | 10 | * @version 2.1 Beta 3 |
11 | 11 | */ |
12 | 12 | |
13 | -if (!defined('SMF')) |
|
13 | +if (!defined('SMF')) { |
|
14 | 14 | die('No direct access...'); |
15 | +} |
|
15 | 16 | |
16 | 17 | /** |
17 | 18 | * Class curl_fetch_web_data |
@@ -87,10 +88,11 @@ discard block |
||
87 | 88 | public function get_url_data($url, $post_data = array()) |
88 | 89 | { |
89 | 90 | // POSTing some data perhaps? |
90 | - if (!empty($post_data) && is_array($post_data)) |
|
91 | - $this->post_data = $this->build_post_data($post_data); |
|
92 | - elseif (!empty($post_data)) |
|
93 | - $this->post_data = trim($post_data); |
|
91 | + if (!empty($post_data) && is_array($post_data)) { |
|
92 | + $this->post_data = $this->build_post_data($post_data); |
|
93 | + } elseif (!empty($post_data)) { |
|
94 | + $this->post_data = trim($post_data); |
|
95 | + } |
|
94 | 96 | |
95 | 97 | // set the options and get it |
96 | 98 | $this->set_options(); |
@@ -111,10 +113,11 @@ discard block |
||
111 | 113 | private function curl_request($url, $redirect = false) |
112 | 114 | { |
113 | 115 | // we do have a url I hope |
114 | - if ($url == '') |
|
115 | - return false; |
|
116 | - else |
|
117 | - $this->options[CURLOPT_URL] = $url; |
|
116 | + if ($url == '') { |
|
117 | + return false; |
|
118 | + } else { |
|
119 | + $this->options[CURLOPT_URL] = $url; |
|
120 | + } |
|
118 | 121 | |
119 | 122 | // if we have not already been redirected, set it up so we can if needed |
120 | 123 | if (!$redirect) |
@@ -194,10 +197,11 @@ discard block |
||
194 | 197 | $max_result = count($this->response) - 1; |
195 | 198 | |
196 | 199 | // just return a specifed area or the entire result? |
197 | - if ($area == '') |
|
198 | - return $this->response[$max_result]; |
|
199 | - else |
|
200 | - return isset($this->response[$max_result][$area]) ? $this->response[$max_result][$area] : $this->response[$max_result]; |
|
200 | + if ($area == '') { |
|
201 | + return $this->response[$max_result]; |
|
202 | + } else { |
|
203 | + return isset($this->response[$max_result][$area]) ? $this->response[$max_result][$area] : $this->response[$max_result]; |
|
204 | + } |
|
201 | 205 | } |
202 | 206 | |
203 | 207 | /** |
@@ -210,9 +214,9 @@ discard block |
||
210 | 214 | */ |
211 | 215 | public function result_raw($response_number = '') |
212 | 216 | { |
213 | - if (!is_numeric($response_number)) |
|
214 | - return $this->response; |
|
215 | - else |
|
217 | + if (!is_numeric($response_number)) { |
|
218 | + return $this->response; |
|
219 | + } else |
|
216 | 220 | { |
217 | 221 | $response_number = min($response_number, count($this->response) - 1); |
218 | 222 | return $this->response[$response_number]; |
@@ -234,13 +238,14 @@ discard block |
||
234 | 238 | $postvars = array(); |
235 | 239 | |
236 | 240 | // build the post data, drop ones with leading @'s since those can be used to send files, we don't support that. |
237 | - foreach ($post_data as $name => $value) |
|
238 | - $postvars[] = $name . '=' . urlencode($value[0] == '@' ? '' : $value); |
|
241 | + foreach ($post_data as $name => $value) { |
|
242 | + $postvars[] = $name . '=' . urlencode($value[0] == '@' ? '' : $value); |
|
243 | + } |
|
239 | 244 | |
240 | 245 | return implode('&', $postvars); |
246 | + } else { |
|
247 | + return $post_data; |
|
241 | 248 | } |
242 | - else |
|
243 | - return $post_data; |
|
244 | 249 | |
245 | 250 | } |
246 | 251 | |
@@ -261,9 +266,9 @@ discard block |
||
261 | 266 | $keys = array_merge(array_keys($this->default_options), array_keys($this->user_options)); |
262 | 267 | $vals = array_merge($this->default_options, $this->user_options); |
263 | 268 | $this->options = array_combine($keys, $vals); |
269 | + } else { |
|
270 | + $this->options = $this->default_options; |
|
264 | 271 | } |
265 | - else |
|
266 | - $this->options = $this->default_options; |
|
267 | 272 | |
268 | 273 | // POST data options, here we don't allow any overide |
269 | 274 | if (isset($this->post_data)) |
@@ -302,8 +307,9 @@ discard block |
||
302 | 307 | $temp = explode(': ', $_header, 2); |
303 | 308 | |
304 | 309 | // set proper headers only |
305 | - if (isset($temp[0]) && isset($temp[1])) |
|
306 | - $this->headers[strtolower($temp[0])] = strtolower(trim($temp[1])); |
|
310 | + if (isset($temp[0]) && isset($temp[1])) { |
|
311 | + $this->headers[strtolower($temp[0])] = strtolower(trim($temp[1])); |
|
312 | + } |
|
307 | 313 | |
308 | 314 | // return the length of what was passed unless you want a Failed writing header error ;) |
309 | 315 | return strlen($header); |
@@ -44,6 +44,10 @@ discard block |
||
44 | 44 | $this->Buf = range(0, 279); |
45 | 45 | } |
46 | 46 | |
47 | + /** |
|
48 | + * @param string $data |
|
49 | + * @param integer $datLen |
|
50 | + */ |
|
47 | 51 | public function decompress($data, &$datLen) |
48 | 52 | { |
49 | 53 | $stLen = strlen($data); |
@@ -63,6 +67,11 @@ discard block |
||
63 | 67 | return $ret; |
64 | 68 | } |
65 | 69 | |
70 | + /** |
|
71 | + * @param boolean $bInit |
|
72 | + * |
|
73 | + * @return integer |
|
74 | + */ |
|
66 | 75 | public function LZWCommand(&$data, $bInit) |
67 | 76 | { |
68 | 77 | if ($bInit) |
@@ -253,6 +262,10 @@ discard block |
||
253 | 262 | unset($this->m_nColors, $this->m_arColors); |
254 | 263 | } |
255 | 264 | |
265 | + /** |
|
266 | + * @param string $lpData |
|
267 | + * @param integer $num |
|
268 | + */ |
|
256 | 269 | public function load($lpData, $num) |
257 | 270 | { |
258 | 271 | $this->m_nColors = 0; |
@@ -324,6 +337,9 @@ discard block |
||
324 | 337 | unset($this->m_bSorted, $this->m_nTableSize, $this->m_nBgColor, $this->m_nPixelRatio, $this->m_colorTable); |
325 | 338 | } |
326 | 339 | |
340 | + /** |
|
341 | + * @param integer $hdrLen |
|
342 | + */ |
|
327 | 343 | public function load($lpData, &$hdrLen) |
328 | 344 | { |
329 | 345 | $hdrLen = 0; |
@@ -370,6 +386,10 @@ discard block |
||
370 | 386 | unset($this->m_bInterlace, $this->m_bSorted, $this->m_nTableSize, $this->m_colorTable); |
371 | 387 | } |
372 | 388 | |
389 | + /** |
|
390 | + * @param string $lpData |
|
391 | + * @param integer $hdrLen |
|
392 | + */ |
|
373 | 393 | public function load($lpData, &$hdrLen) |
374 | 394 | { |
375 | 395 | $hdrLen = 0; |
@@ -412,6 +432,10 @@ discard block |
||
412 | 432 | $this->m_lzw = new gif_lzw_compression(); |
413 | 433 | } |
414 | 434 | |
435 | + /** |
|
436 | + * @param string $data |
|
437 | + * @param integer $datLen |
|
438 | + */ |
|
415 | 439 | public function load($data, &$datLen) |
416 | 440 | { |
417 | 441 | $datLen = 0; |
@@ -464,6 +488,10 @@ discard block |
||
464 | 488 | return false; |
465 | 489 | } |
466 | 490 | |
491 | + /** |
|
492 | + * @param string $data |
|
493 | + * @param integer $extLen |
|
494 | + */ |
|
467 | 495 | public function skipExt(&$data, &$extLen) |
468 | 496 | { |
469 | 497 | $extLen = 0; |
@@ -425,40 +425,40 @@ discard block |
||
425 | 425 | switch ($b) |
426 | 426 | { |
427 | 427 | // Extension... |
428 | - case 0x21: |
|
429 | - $len = 0; |
|
430 | - if (!$this->skipExt($data, $len)) |
|
431 | - return false; |
|
428 | + case 0x21: |
|
429 | + $len = 0; |
|
430 | + if (!$this->skipExt($data, $len)) |
|
431 | + return false; |
|
432 | 432 | |
433 | - $datLen += $len; |
|
434 | - break; |
|
433 | + $datLen += $len; |
|
434 | + break; |
|
435 | 435 | |
436 | - // Image... |
|
437 | - case 0x2C: |
|
438 | - // Load the header and color table. |
|
439 | - $len = 0; |
|
440 | - if (!$this->m_gih->load($data, $len)) |
|
441 | - return false; |
|
436 | + // Image... |
|
437 | + case 0x2C: |
|
438 | + // Load the header and color table. |
|
439 | + $len = 0; |
|
440 | + if (!$this->m_gih->load($data, $len)) |
|
441 | + return false; |
|
442 | 442 | |
443 | - $data = substr($data, $len); |
|
444 | - $datLen += $len; |
|
443 | + $data = substr($data, $len); |
|
444 | + $datLen += $len; |
|
445 | 445 | |
446 | - // Decompress the data, and ride on home ;). |
|
447 | - $len = 0; |
|
448 | - if (!($this->m_data = $this->m_lzw->decompress($data, $len))) |
|
449 | - return false; |
|
446 | + // Decompress the data, and ride on home ;). |
|
447 | + $len = 0; |
|
448 | + if (!($this->m_data = $this->m_lzw->decompress($data, $len))) |
|
449 | + return false; |
|
450 | 450 | |
451 | - $data = substr($data, $len); |
|
452 | - $datLen += $len; |
|
451 | + $data = substr($data, $len); |
|
452 | + $datLen += $len; |
|
453 | 453 | |
454 | - if ($this->m_gih->m_bInterlace) |
|
455 | - $this->deInterlace(); |
|
454 | + if ($this->m_gih->m_bInterlace) |
|
455 | + $this->deInterlace(); |
|
456 | 456 | |
457 | - return true; |
|
457 | + return true; |
|
458 | 458 | |
459 | - case 0x3B: // EOF |
|
460 | - default: |
|
461 | - return false; |
|
459 | + case 0x3B: // EOF |
|
460 | + default: |
|
461 | + return false; |
|
462 | 462 | } |
463 | 463 | } |
464 | 464 | return false; |
@@ -475,27 +475,27 @@ discard block |
||
475 | 475 | switch ($b) |
476 | 476 | { |
477 | 477 | // Graphic Control... |
478 | - case 0xF9: |
|
479 | - $b = ord($data[1]); |
|
480 | - $this->m_disp = ($b & 0x1C) >> 2; |
|
481 | - $this->m_bUser = ($b & 0x02) ? true : false; |
|
482 | - $this->m_bTrans = ($b & 0x01) ? true : false; |
|
483 | - list ($this->m_nDelay) = array_values(unpack('v', substr($data, 2, 2))); |
|
484 | - $this->m_nTrans = ord($data[4]); |
|
485 | - break; |
|
486 | - |
|
487 | - // Comment... |
|
488 | - case 0xFE: |
|
489 | - $this->m_lpComm = substr($data, 1, ord($data[0])); |
|
490 | - break; |
|
491 | - |
|
492 | - // Plain text... |
|
493 | - case 0x01: |
|
494 | - break; |
|
495 | - |
|
496 | - // Application... |
|
497 | - case 0xFF: |
|
498 | - break; |
|
478 | + case 0xF9: |
|
479 | + $b = ord($data[1]); |
|
480 | + $this->m_disp = ($b & 0x1C) >> 2; |
|
481 | + $this->m_bUser = ($b & 0x02) ? true : false; |
|
482 | + $this->m_bTrans = ($b & 0x01) ? true : false; |
|
483 | + list ($this->m_nDelay) = array_values(unpack('v', substr($data, 2, 2))); |
|
484 | + $this->m_nTrans = ord($data[4]); |
|
485 | + break; |
|
486 | + |
|
487 | + // Comment... |
|
488 | + case 0xFE: |
|
489 | + $this->m_lpComm = substr($data, 1, ord($data[0])); |
|
490 | + break; |
|
491 | + |
|
492 | + // Plain text... |
|
493 | + case 0x01: |
|
494 | + break; |
|
495 | + |
|
496 | + // Application... |
|
497 | + case 0xFF: |
|
498 | + break; |
|
499 | 499 | } |
500 | 500 | |
501 | 501 | // Skip default as defs may change. |
@@ -521,25 +521,25 @@ discard block |
||
521 | 521 | { |
522 | 522 | switch ($i) |
523 | 523 | { |
524 | - case 0: |
|
525 | - $s = 8; |
|
526 | - $y = 0; |
|
527 | - break; |
|
528 | - |
|
529 | - case 1: |
|
530 | - $s = 8; |
|
531 | - $y = 4; |
|
532 | - break; |
|
533 | - |
|
534 | - case 2: |
|
535 | - $s = 4; |
|
536 | - $y = 2; |
|
537 | - break; |
|
538 | - |
|
539 | - case 3: |
|
540 | - $s = 2; |
|
541 | - $y = 1; |
|
542 | - break; |
|
524 | + case 0: |
|
525 | + $s = 8; |
|
526 | + $y = 0; |
|
527 | + break; |
|
528 | + |
|
529 | + case 1: |
|
530 | + $s = 8; |
|
531 | + $y = 4; |
|
532 | + break; |
|
533 | + |
|
534 | + case 2: |
|
535 | + $s = 4; |
|
536 | + $y = 2; |
|
537 | + break; |
|
538 | + |
|
539 | + case 3: |
|
540 | + $s = 2; |
|
541 | + $y = 1; |
|
542 | + break; |
|
543 | 543 | } |
544 | 544 | |
545 | 545 | for (; $y < $this->m_gih->m_nHeight; $y += $s) |
@@ -38,8 +38,8 @@ discard block |
||
38 | 38 | $this->MAX_LZW_BITS = 12; |
39 | 39 | unset($this->Next, $this->Vals, $this->Stack, $this->Buf); |
40 | 40 | |
41 | - $this->Next = range(0, (1 << $this->MAX_LZW_BITS) - 1); |
|
42 | - $this->Vals = range(0, (1 << $this->MAX_LZW_BITS) - 1); |
|
41 | + $this->Next = range(0, (1 << $this->MAX_LZW_BITS) - 1); |
|
42 | + $this->Vals = range(0, (1 << $this->MAX_LZW_BITS) - 1); |
|
43 | 43 | $this->Stack = range(0, (1 << ($this->MAX_LZW_BITS + 1)) - 1); |
44 | 44 | $this->Buf = range(0, 279); |
45 | 45 | } |
@@ -278,9 +278,9 @@ discard block |
||
278 | 278 | for ($i = 0; $i < $this->m_nColors; $i++) |
279 | 279 | { |
280 | 280 | $ret .= |
281 | - chr(($this->m_arColors[$i] & 0x000000FF)) . // R |
|
282 | - chr(($this->m_arColors[$i] & 0x0000FF00) >> 8) . // G |
|
283 | - chr(($this->m_arColors[$i] & 0x00FF0000) >> 16); // B |
|
281 | + chr(($this->m_arColors[$i] & 0x000000FF)) . // R |
|
282 | + chr(($this->m_arColors[$i] & 0x0000FF00) >> 8) . // G |
|
283 | + chr(($this->m_arColors[$i] & 0x00FF0000) >> 16); // B |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | return $ret; |
@@ -290,14 +290,14 @@ discard block |
||
290 | 290 | { |
291 | 291 | $rgb = intval($rgb) & 0xFFFFFF; |
292 | 292 | $r1 = ($rgb & 0x0000FF); |
293 | - $g1 = ($rgb & 0x00FF00) >> 8; |
|
293 | + $g1 = ($rgb & 0x00FF00) >> 8; |
|
294 | 294 | $b1 = ($rgb & 0xFF0000) >> 16; |
295 | 295 | $idx = -1; |
296 | 296 | |
297 | 297 | for ($i = 0; $i < $this->m_nColors; $i++) |
298 | 298 | { |
299 | 299 | $r2 = ($this->m_arColors[$i] & 0x000000FF); |
300 | - $g2 = ($this->m_arColors[$i] & 0x0000FF00) >> 8; |
|
300 | + $g2 = ($this->m_arColors[$i] & 0x0000FF00) >> 8; |
|
301 | 301 | $b2 = ($this->m_arColors[$i] & 0x00FF0000) >> 16; |
302 | 302 | $d = abs($r2 - $r1) + abs($g2 - $g1) + abs($b2 - $b1); |
303 | 303 |
@@ -19,8 +19,9 @@ discard block |
||
19 | 19 | * @version 2.1 Beta 3 |
20 | 20 | */ |
21 | 21 | |
22 | -if (!defined('SMF')) |
|
22 | +if (!defined('SMF')) { |
|
23 | 23 | die('No direct access...'); |
24 | +} |
|
24 | 25 | |
25 | 26 | /** |
26 | 27 | * Class gif_lzw_compression |
@@ -52,13 +53,15 @@ discard block |
||
52 | 53 | |
53 | 54 | $this->LZWCommand($data, true); |
54 | 55 | |
55 | - while (($iIndex = $this->LZWCommand($data, false)) >= 0) |
|
56 | - $ret .= chr($iIndex); |
|
56 | + while (($iIndex = $this->LZWCommand($data, false)) >= 0) { |
|
57 | + $ret .= chr($iIndex); |
|
58 | + } |
|
57 | 59 | |
58 | 60 | $datLen = $stLen - strlen($data); |
59 | 61 | |
60 | - if ($iIndex != -2) |
|
61 | - return false; |
|
62 | + if ($iIndex != -2) { |
|
63 | + return false; |
|
64 | + } |
|
62 | 65 | |
63 | 66 | return $ret; |
64 | 67 | } |
@@ -140,8 +143,9 @@ discard block |
||
140 | 143 | return $this->FirstCode; |
141 | 144 | } |
142 | 145 | |
143 | - if ($Code == $this->EndCode) |
|
144 | - return -2; |
|
146 | + if ($Code == $this->EndCode) { |
|
147 | + return -2; |
|
148 | + } |
|
145 | 149 | |
146 | 150 | $InCode = $Code; |
147 | 151 | if ($Code >= $this->MaxCode) |
@@ -156,8 +160,10 @@ discard block |
||
156 | 160 | $this->Stack[$this->sp] = $this->Vals[$Code]; |
157 | 161 | $this->sp++; |
158 | 162 | |
159 | - if ($Code == $this->Next[$Code]) // Circular table entry, big GIF Error! |
|
163 | + if ($Code == $this->Next[$Code]) { |
|
164 | + // Circular table entry, big GIF Error! |
|
160 | 165 | return -1; |
166 | + } |
|
161 | 167 | |
162 | 168 | $Code = $this->Next[$Code]; |
163 | 169 | } |
@@ -207,8 +213,9 @@ discard block |
||
207 | 213 | if ($this->Done) |
208 | 214 | { |
209 | 215 | // Ran off the end of my bits... |
210 | - if ($this->CurBit >= $this->LastBit) |
|
211 | - return 0; |
|
216 | + if ($this->CurBit >= $this->LastBit) { |
|
217 | + return 0; |
|
218 | + } |
|
212 | 219 | |
213 | 220 | return -1; |
214 | 221 | } |
@@ -221,13 +228,14 @@ discard block |
||
221 | 228 | |
222 | 229 | if ($count) |
223 | 230 | { |
224 | - for ($i = 0; $i < $count; $i++) |
|
225 | - $this->Buf[2 + $i] = ord($data{$i}); |
|
231 | + for ($i = 0; $i < $count; $i++) { |
|
232 | + $this->Buf[2 + $i] = ord($data{$i}); |
|
233 | + } |
|
226 | 234 | |
227 | 235 | $data = substr($data, $count); |
236 | + } else { |
|
237 | + $this->Done = 1; |
|
228 | 238 | } |
229 | - else |
|
230 | - $this->Done = 1; |
|
231 | 239 | |
232 | 240 | $this->LastByte = 2 + $count; |
233 | 241 | $this->CurBit = ($this->CurBit - $this->LastBit) + 16; |
@@ -235,8 +243,9 @@ discard block |
||
235 | 243 | } |
236 | 244 | |
237 | 245 | $iRet = 0; |
238 | - for ($i = $this->CurBit, $j = 0; $j < $this->CodeSize; $i++, $j++) |
|
239 | - $iRet |= (($this->Buf[intval($i / 8)] & (1 << ($i % 8))) != 0) << $j; |
|
246 | + for ($i = $this->CurBit, $j = 0; $j < $this->CodeSize; $i++, $j++) { |
|
247 | + $iRet |= (($this->Buf[intval($i / 8)] & (1 << ($i % 8))) != 0) << $j; |
|
248 | + } |
|
240 | 249 | |
241 | 250 | $this->CurBit += $this->CodeSize; |
242 | 251 | return $iRet; |
@@ -261,8 +270,9 @@ discard block |
||
261 | 270 | for ($i = 0; $i < $num; $i++) |
262 | 271 | { |
263 | 272 | $rgb = substr($lpData, $i * 3, 3); |
264 | - if (strlen($rgb) < 3) |
|
265 | - return false; |
|
273 | + if (strlen($rgb) < 3) { |
|
274 | + return false; |
|
275 | + } |
|
266 | 276 | |
267 | 277 | $this->m_arColors[] = (ord($rgb[2]) << 16) + (ord($rgb[1]) << 8) + ord($rgb[0]); |
268 | 278 | $this->m_nColors++; |
@@ -329,13 +339,15 @@ discard block |
||
329 | 339 | $hdrLen = 0; |
330 | 340 | |
331 | 341 | $this->m_lpVer = substr($lpData, 0, 6); |
332 | - if (($this->m_lpVer != 'GIF87a') && ($this->m_lpVer != 'GIF89a')) |
|
333 | - return false; |
|
342 | + if (($this->m_lpVer != 'GIF87a') && ($this->m_lpVer != 'GIF89a')) { |
|
343 | + return false; |
|
344 | + } |
|
334 | 345 | |
335 | 346 | list ($this->m_nWidth, $this->m_nHeight) = array_values(unpack('v2', substr($lpData, 6, 4))); |
336 | 347 | |
337 | - if (!$this->m_nWidth || !$this->m_nHeight) |
|
338 | - return false; |
|
348 | + if (!$this->m_nWidth || !$this->m_nHeight) { |
|
349 | + return false; |
|
350 | + } |
|
339 | 351 | |
340 | 352 | $b = ord(substr($lpData, 10, 1)); |
341 | 353 | $this->m_bGlobalClr = ($b & 0x80) ? true : false; |
@@ -349,8 +361,9 @@ discard block |
||
349 | 361 | if ($this->m_bGlobalClr) |
350 | 362 | { |
351 | 363 | $this->m_colorTable = new gif_color_table(); |
352 | - if (!$this->m_colorTable->load(substr($lpData, $hdrLen), $this->m_nTableSize)) |
|
353 | - return false; |
|
364 | + if (!$this->m_colorTable->load(substr($lpData, $hdrLen), $this->m_nTableSize)) { |
|
365 | + return false; |
|
366 | + } |
|
354 | 367 | |
355 | 368 | $hdrLen += 3 * $this->m_nTableSize; |
356 | 369 | } |
@@ -377,8 +390,9 @@ discard block |
||
377 | 390 | // Get the width/height/etc. from the header. |
378 | 391 | list ($this->m_nLeft, $this->m_nTop, $this->m_nWidth, $this->m_nHeight) = array_values(unpack('v4', substr($lpData, 0, 8))); |
379 | 392 | |
380 | - if (!$this->m_nWidth || !$this->m_nHeight) |
|
381 | - return false; |
|
393 | + if (!$this->m_nWidth || !$this->m_nHeight) { |
|
394 | + return false; |
|
395 | + } |
|
382 | 396 | |
383 | 397 | $b = ord($lpData[8]); |
384 | 398 | $this->m_bLocalClr = ($b & 0x80) ? true : false; |
@@ -390,8 +404,9 @@ discard block |
||
390 | 404 | if ($this->m_bLocalClr) |
391 | 405 | { |
392 | 406 | $this->m_colorTable = new gif_color_table(); |
393 | - if (!$this->m_colorTable->load(substr($lpData, $hdrLen), $this->m_nTableSize)) |
|
394 | - return false; |
|
407 | + if (!$this->m_colorTable->load(substr($lpData, $hdrLen), $this->m_nTableSize)) { |
|
408 | + return false; |
|
409 | + } |
|
395 | 410 | |
396 | 411 | $hdrLen += 3 * $this->m_nTableSize; |
397 | 412 | } |
@@ -427,8 +442,9 @@ discard block |
||
427 | 442 | // Extension... |
428 | 443 | case 0x21: |
429 | 444 | $len = 0; |
430 | - if (!$this->skipExt($data, $len)) |
|
431 | - return false; |
|
445 | + if (!$this->skipExt($data, $len)) { |
|
446 | + return false; |
|
447 | + } |
|
432 | 448 | |
433 | 449 | $datLen += $len; |
434 | 450 | break; |
@@ -437,22 +453,25 @@ discard block |
||
437 | 453 | case 0x2C: |
438 | 454 | // Load the header and color table. |
439 | 455 | $len = 0; |
440 | - if (!$this->m_gih->load($data, $len)) |
|
441 | - return false; |
|
456 | + if (!$this->m_gih->load($data, $len)) { |
|
457 | + return false; |
|
458 | + } |
|
442 | 459 | |
443 | 460 | $data = substr($data, $len); |
444 | 461 | $datLen += $len; |
445 | 462 | |
446 | 463 | // Decompress the data, and ride on home ;). |
447 | 464 | $len = 0; |
448 | - if (!($this->m_data = $this->m_lzw->decompress($data, $len))) |
|
449 | - return false; |
|
465 | + if (!($this->m_data = $this->m_lzw->decompress($data, $len))) { |
|
466 | + return false; |
|
467 | + } |
|
450 | 468 | |
451 | 469 | $data = substr($data, $len); |
452 | 470 | $datLen += $len; |
453 | 471 | |
454 | - if ($this->m_gih->m_bInterlace) |
|
455 | - $this->deInterlace(); |
|
472 | + if ($this->m_gih->m_bInterlace) { |
|
473 | + $this->deInterlace(); |
|
474 | + } |
|
456 | 475 | |
457 | 476 | return true; |
458 | 477 | |
@@ -572,17 +591,20 @@ discard block |
||
572 | 591 | |
573 | 592 | public function loadFile($filename, $iIndex) |
574 | 593 | { |
575 | - if ($iIndex < 0) |
|
576 | - return false; |
|
594 | + if ($iIndex < 0) { |
|
595 | + return false; |
|
596 | + } |
|
577 | 597 | |
578 | 598 | $this->data = @file_get_contents($filename); |
579 | - if ($this->data === false) |
|
580 | - return false; |
|
599 | + if ($this->data === false) { |
|
600 | + return false; |
|
601 | + } |
|
581 | 602 | |
582 | 603 | // Tell the header to load up.... |
583 | 604 | $len = 0; |
584 | - if (!$this->header->load($this->data, $len)) |
|
585 | - return false; |
|
605 | + if (!$this->header->load($this->data, $len)) { |
|
606 | + return false; |
|
607 | + } |
|
586 | 608 | |
587 | 609 | $this->data = substr($this->data, $len); |
588 | 610 | |
@@ -590,8 +612,9 @@ discard block |
||
590 | 612 | for ($j = 0; $j <= $iIndex; $j++) |
591 | 613 | { |
592 | 614 | $imgLen = 0; |
593 | - if (!$this->image->load($this->data, $imgLen)) |
|
594 | - return false; |
|
615 | + if (!$this->image->load($this->data, $imgLen)) { |
|
616 | + return false; |
|
617 | + } |
|
595 | 618 | |
596 | 619 | $this->data = substr($this->data, $imgLen); |
597 | 620 | } |
@@ -602,8 +625,9 @@ discard block |
||
602 | 625 | |
603 | 626 | public function get_png_data($background_color) |
604 | 627 | { |
605 | - if (!$this->loaded) |
|
606 | - return false; |
|
628 | + if (!$this->loaded) { |
|
629 | + return false; |
|
630 | + } |
|
607 | 631 | |
608 | 632 | // Prepare the color table. |
609 | 633 | if ($this->image->m_gih->m_bLocalClr) |
@@ -611,25 +635,26 @@ discard block |
||
611 | 635 | $colors = $this->image->m_gih->m_nTableSize; |
612 | 636 | $pal = $this->image->m_gih->m_colorTable->toString(); |
613 | 637 | |
614 | - if ($background_color != -1) |
|
615 | - $background_color = $this->image->m_gih->m_colorTable->colorIndex($background_color); |
|
616 | - } |
|
617 | - elseif ($this->header->m_bGlobalClr) |
|
638 | + if ($background_color != -1) { |
|
639 | + $background_color = $this->image->m_gih->m_colorTable->colorIndex($background_color); |
|
640 | + } |
|
641 | + } elseif ($this->header->m_bGlobalClr) |
|
618 | 642 | { |
619 | 643 | $colors = $this->header->m_nTableSize; |
620 | 644 | $pal = $this->header->m_colorTable->toString(); |
621 | 645 | |
622 | - if ($background_color != -1) |
|
623 | - $background_color = $this->header->m_colorTable->colorIndex($background_color); |
|
624 | - } |
|
625 | - else |
|
646 | + if ($background_color != -1) { |
|
647 | + $background_color = $this->header->m_colorTable->colorIndex($background_color); |
|
648 | + } |
|
649 | + } else |
|
626 | 650 | { |
627 | 651 | $colors = 0; |
628 | 652 | $background_color = -1; |
629 | 653 | } |
630 | 654 | |
631 | - if ($background_color == -1) |
|
632 | - $background_color = $this->header->m_nBgColor; |
|
655 | + if ($background_color == -1) { |
|
656 | + $background_color = $this->header->m_nBgColor; |
|
657 | + } |
|
633 | 658 | |
634 | 659 | $data = &$this->image->m_data; |
635 | 660 | $header = &$this->image->m_gih; |
@@ -645,11 +670,13 @@ discard block |
||
645 | 670 | for ($x = 0; $x < $this->header->m_nWidth; $x++, $i++) |
646 | 671 | { |
647 | 672 | // Is this in the proper range? If so, get the specific pixel data... |
648 | - if ($x >= $header->m_nLeft && $y >= $header->m_nTop && $x < ($header->m_nLeft + $header->m_nWidth) && $y < ($header->m_nTop + $header->m_nHeight)) |
|
649 | - $bmp .= $data{$i}; |
|
673 | + if ($x >= $header->m_nLeft && $y >= $header->m_nTop && $x < ($header->m_nLeft + $header->m_nWidth) && $y < ($header->m_nTop + $header->m_nHeight)) { |
|
674 | + $bmp .= $data{$i}; |
|
675 | + } |
|
650 | 676 | // Otherwise, this is background... |
651 | - else |
|
652 | - $bmp .= chr($background_color); |
|
677 | + else { |
|
678 | + $bmp .= chr($background_color); |
|
679 | + } |
|
653 | 680 | } |
654 | 681 | } |
655 | 682 | |
@@ -678,8 +705,9 @@ discard block |
||
678 | 705 | $tmp = 'tRNS'; |
679 | 706 | |
680 | 707 | // Stick each color on - full transparency or none. |
681 | - for ($i = 0; $i < $colors; $i++) |
|
682 | - $tmp .= $i == $this->image->m_nTrans ? "\x00" : "\xFF"; |
|
708 | + for ($i = 0; $i < $colors; $i++) { |
|
709 | + $tmp .= $i == $this->image->m_nTrans ? "\x00" : "\xFF"; |
|
710 | + } |
|
683 | 711 | |
684 | 712 | $out .= $tmp . pack('N', smf_crc32($tmp)); |
685 | 713 | } |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | * of elements, an array of xmlArray's is returned for use with foreach. |
258 | 258 | * Example use: |
259 | 259 | * foreach ($xml->set('html/body/p') as $p) |
260 | - * @param $path string The path to search for. |
|
260 | + * @param string $path string The path to search for. |
|
261 | 261 | * @return array An array of xmlArray objects |
262 | 262 | */ |
263 | 263 | public function set($path) |
@@ -855,7 +855,7 @@ discard block |
||
855 | 855 | * Changes a files atrributes (chmod) |
856 | 856 | * |
857 | 857 | * @param string $ftp_file The file to CHMOD |
858 | - * @param int|string $chmod The value for the CHMOD operation |
|
858 | + * @param integer $chmod The value for the CHMOD operation |
|
859 | 859 | * @return boolean Whether or not the operation was successful |
860 | 860 | */ |
861 | 861 | public function chmod($ftp_file, $chmod) |
@@ -1025,7 +1025,7 @@ discard block |
||
1025 | 1025 | * |
1026 | 1026 | * @param string $ftp_path The path to the directory |
1027 | 1027 | * @param bool $search Whether or not to get a recursive directory listing |
1028 | - * @return string|boolean The results of the command or false if unsuccessful |
|
1028 | + * @return false|string The results of the command or false if unsuccessful |
|
1029 | 1029 | */ |
1030 | 1030 | public function list_dir($ftp_path = '', $search = false) |
1031 | 1031 | { |
@@ -1070,7 +1070,7 @@ discard block |
||
1070 | 1070 | * |
1071 | 1071 | * @param string $file The name of a file |
1072 | 1072 | * @param string $listing A directory listing or null to generate one |
1073 | - * @return string|boolean The name of the file or false if it wasn't found |
|
1073 | + * @return string|false The name of the file or false if it wasn't found |
|
1074 | 1074 | */ |
1075 | 1075 | public function locate($file, $listing = null) |
1076 | 1076 | { |
@@ -793,7 +793,7 @@ discard block |
||
793 | 793 | if (!$this->connection) |
794 | 794 | { |
795 | 795 | $this->error = 'bad_server'; |
796 | - $this->last_message = 'Invalid Server'; |
|
796 | + $this->last_message = 'Invalid Server'; |
|
797 | 797 | return; |
798 | 798 | } |
799 | 799 | |
@@ -801,7 +801,7 @@ discard block |
||
801 | 801 | if (!$this->check_response(220)) |
802 | 802 | { |
803 | 803 | $this->error = 'bad_response'; |
804 | - $this->last_message = 'Bad Response'; |
|
804 | + $this->last_message = 'Bad Response'; |
|
805 | 805 | return; |
806 | 806 | } |
807 | 807 |
@@ -424,7 +424,7 @@ discard block |
||
424 | 424 | if ((!isset($match[3]) || trim($match[3]) != '/') && (!isset($match[2]) || trim($match[2]) != '/')) |
425 | 425 | { |
426 | 426 | // Because PHP 5.2.0+ seems to croak using regex, we'll have to do this the less fun way. |
427 | - $last_tag_end = strpos($data, '</' . $match[1]. '>'); |
|
427 | + $last_tag_end = strpos($data, '</' . $match[1] . '>'); |
|
428 | 428 | if ($last_tag_end === false) |
429 | 429 | continue; |
430 | 430 | |
@@ -438,7 +438,7 @@ discard block |
||
438 | 438 | break; |
439 | 439 | |
440 | 440 | // If not then find the next ending tag. |
441 | - $next_tag_end = strpos($data, '</' . $match[1]. '>', $offset); |
|
441 | + $next_tag_end = strpos($data, '</' . $match[1] . '>', $offset); |
|
442 | 442 | |
443 | 443 | // Didn't find one? Then just use the last and sod it. |
444 | 444 | if ($next_tag_end === false) |
@@ -452,7 +452,7 @@ discard block |
||
452 | 452 | // Parse the insides. |
453 | 453 | $inner_match = substr($data, 0, $last_tag_end); |
454 | 454 | // Data now starts from where this section ends. |
455 | - $data = substr($data, $last_tag_end + strlen('</' . $match[1]. '>')); |
|
455 | + $data = substr($data, $last_tag_end + strlen('</' . $match[1] . '>')); |
|
456 | 456 | |
457 | 457 | if (!empty($inner_match)) |
458 | 458 | { |
@@ -618,7 +618,7 @@ discard block |
||
618 | 618 | $trans_tbl = array_flip(get_html_translation_table(HTML_ENTITIES, ENT_QUOTES)); |
619 | 619 | |
620 | 620 | // Translate all the entities out. |
621 | - $data = strtr(preg_replace_callback('~&#(\d{1,4});~', function ($m) |
|
621 | + $data = strtr(preg_replace_callback('~&#(\d{1,4});~', function($m) |
|
622 | 622 | { |
623 | 623 | return chr("$m[1]"); |
624 | 624 | }, $data), $trans_tbl); |
@@ -873,7 +873,7 @@ discard block |
||
873 | 873 | // Set different modes. |
874 | 874 | $chmod_values = $is_dir ? array(0750, 0755, 0775, 0777) : array(0644, 0664, 0666); |
875 | 875 | |
876 | - foreach($chmod_values as $val) |
|
876 | + foreach ($chmod_values as $val) |
|
877 | 877 | { |
878 | 878 | // If it's writable, break out of the loop. |
879 | 879 | if (is_writable($ftp_file)) |
@@ -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 | * Class xmlArray |
@@ -65,8 +66,9 @@ discard block |
||
65 | 66 | } |
66 | 67 | |
67 | 68 | // Is the input an array? (ie. passed from file()?) |
68 | - if (is_array($data)) |
|
69 | - $data = implode('', $data); |
|
69 | + if (is_array($data)) { |
|
70 | + $data = implode('', $data); |
|
71 | + } |
|
70 | 72 | |
71 | 73 | // Remove any xml declaration or doctype, and parse out comments and CDATA. |
72 | 74 | $data = preg_replace('/<!--.*?-->/s', '', $this->_to_cdata(preg_replace(array('/^<\?xml.+?\?' . '>/is', '/<!DOCTYPE[^>]+?' . '>/s'), '', $data))); |
@@ -101,8 +103,9 @@ discard block |
||
101 | 103 | // Get the element, in array form. |
102 | 104 | $array = $this->path($path); |
103 | 105 | |
104 | - if ($array === false) |
|
105 | - return false; |
|
106 | + if ($array === false) { |
|
107 | + return false; |
|
108 | + } |
|
106 | 109 | |
107 | 110 | // Getting elements into this is a bit complicated... |
108 | 111 | if ($get_elements && !is_string($array)) |
@@ -113,8 +116,9 @@ discard block |
||
113 | 116 | foreach ($array->array as $val) |
114 | 117 | { |
115 | 118 | // Skip the name and any attributes. |
116 | - if (is_array($val)) |
|
117 | - $temp .= $this->_xml($val, null); |
|
119 | + if (is_array($val)) { |
|
120 | + $temp .= $this->_xml($val, null); |
|
121 | + } |
|
118 | 122 | } |
119 | 123 | |
120 | 124 | // Just get the XML data and then take out the CDATAs. |
@@ -156,32 +160,35 @@ discard block |
||
156 | 160 | elseif (substr($el, 0, 1) == '@') |
157 | 161 | { |
158 | 162 | // It simplifies things if the attribute is already there ;). |
159 | - if (isset($array[$el])) |
|
160 | - return $array[$el]; |
|
161 | - else |
|
163 | + if (isset($array[$el])) { |
|
164 | + return $array[$el]; |
|
165 | + } else |
|
162 | 166 | { |
163 | 167 | $trace = debug_backtrace(); |
164 | 168 | $i = 0; |
165 | - while ($i < count($trace) && isset($trace[$i]['class']) && $trace[$i]['class'] == get_class($this)) |
|
166 | - $i++; |
|
169 | + while ($i < count($trace) && isset($trace[$i]['class']) && $trace[$i]['class'] == get_class($this)) { |
|
170 | + $i++; |
|
171 | + } |
|
167 | 172 | $debug = ' (from ' . $trace[$i - 1]['file'] . ' on line ' . $trace[$i - 1]['line'] . ')'; |
168 | 173 | |
169 | 174 | // Cause an error. |
170 | - if ($this->debug_level & E_NOTICE) |
|
171 | - trigger_error('Undefined XML attribute: ' . substr($el, 1) . $debug, E_USER_NOTICE); |
|
175 | + if ($this->debug_level & E_NOTICE) { |
|
176 | + trigger_error('Undefined XML attribute: ' . substr($el, 1) . $debug, E_USER_NOTICE); |
|
177 | + } |
|
172 | 178 | return false; |
173 | 179 | } |
180 | + } else { |
|
181 | + $lvl = null; |
|
174 | 182 | } |
175 | - else |
|
176 | - $lvl = null; |
|
177 | 183 | |
178 | 184 | // Find this element. |
179 | 185 | $array = $this->_path($array, $el, $lvl); |
180 | 186 | } |
181 | 187 | |
182 | 188 | // Clean up after $lvl, for $return_full. |
183 | - if ($return_full && (!isset($array['name']) || substr($array['name'], -1) != ']')) |
|
184 | - $array = array('name' => $el . '[]', $array); |
|
189 | + if ($return_full && (!isset($array['name']) || substr($array['name'], -1) != ']')) { |
|
190 | + $array = array('name' => $el . '[]', $array); |
|
191 | + } |
|
185 | 192 | |
186 | 193 | // Create the right type of class... |
187 | 194 | $newClass = get_class($this); |
@@ -216,10 +223,11 @@ discard block |
||
216 | 223 | $el = substr($el, 0, strpos($el, '[')); |
217 | 224 | } |
218 | 225 | // Find an attribute. |
219 | - elseif (substr($el, 0, 1) == '@') |
|
220 | - return isset($array[$el]); |
|
221 | - else |
|
222 | - $lvl = null; |
|
226 | + elseif (substr($el, 0, 1) == '@') { |
|
227 | + return isset($array[$el]); |
|
228 | + } else { |
|
229 | + $lvl = null; |
|
230 | + } |
|
223 | 231 | |
224 | 232 | // Find this element. |
225 | 233 | $array = $this->_path($array, $el, $lvl, true); |
@@ -244,8 +252,9 @@ discard block |
||
244 | 252 | $i = 0; |
245 | 253 | foreach ($temp->array as $item) |
246 | 254 | { |
247 | - if (is_array($item)) |
|
248 | - $i++; |
|
255 | + if (is_array($item)) { |
|
256 | + $i++; |
|
257 | + } |
|
249 | 258 | } |
250 | 259 | |
251 | 260 | return $i; |
@@ -269,8 +278,9 @@ discard block |
||
269 | 278 | foreach ($xml->array as $val) |
270 | 279 | { |
271 | 280 | // Skip these, they aren't elements. |
272 | - if (!is_array($val) || $val['name'] == '!') |
|
273 | - continue; |
|
281 | + if (!is_array($val) || $val['name'] == '!') { |
|
282 | + continue; |
|
283 | + } |
|
274 | 284 | |
275 | 285 | // Create the right type of class... |
276 | 286 | $newClass = get_class($this); |
@@ -297,14 +307,16 @@ discard block |
||
297 | 307 | $path = $this->path($path); |
298 | 308 | |
299 | 309 | // The path was not found |
300 | - if ($path === false) |
|
301 | - return false; |
|
310 | + if ($path === false) { |
|
311 | + return false; |
|
312 | + } |
|
302 | 313 | |
303 | 314 | $path = $path->array; |
304 | 315 | } |
305 | 316 | // Just use the current array. |
306 | - else |
|
307 | - $path = $this->array; |
|
317 | + else { |
|
318 | + $path = $this->array; |
|
319 | + } |
|
308 | 320 | |
309 | 321 | // Add the xml declaration to the front. |
310 | 322 | return '<?xml version="1.0"?' . '>' . $this->_xml($path, 0); |
@@ -326,14 +338,16 @@ discard block |
||
326 | 338 | $path = $this->path($path); |
327 | 339 | |
328 | 340 | // The path was not found |
329 | - if ($path === false) |
|
330 | - return false; |
|
341 | + if ($path === false) { |
|
342 | + return false; |
|
343 | + } |
|
331 | 344 | |
332 | 345 | $path = $path->array; |
333 | 346 | } |
334 | 347 | // No, so just use the current array. |
335 | - else |
|
336 | - $path = $this->array; |
|
348 | + else { |
|
349 | + $path = $this->array; |
|
350 | + } |
|
337 | 351 | |
338 | 352 | return $this->_array($path); |
339 | 353 | } |
@@ -355,8 +369,9 @@ discard block |
||
355 | 369 | { |
356 | 370 | // Find and remove the next tag. |
357 | 371 | preg_match('/\A<([\w\-:]+)((?:\s+.+?)?)([\s]?\/)?' . '>/', $data, $match); |
358 | - if (isset($match[0])) |
|
359 | - $data = preg_replace('/' . preg_quote($match[0], '/') . '/s', '', $data, 1); |
|
372 | + if (isset($match[0])) { |
|
373 | + $data = preg_replace('/' . preg_quote($match[0], '/') . '/s', '', $data, 1); |
|
374 | + } |
|
360 | 375 | |
361 | 376 | // Didn't find a tag? Keep looping.... |
362 | 377 | if (!isset($match[1]) || $match[1] == '') |
@@ -367,11 +382,12 @@ discard block |
||
367 | 382 | $text_value = $this->_from_cdata($data); |
368 | 383 | $data = ''; |
369 | 384 | |
370 | - if ($text_value != '') |
|
371 | - $current[] = array( |
|
385 | + if ($text_value != '') { |
|
386 | + $current[] = array( |
|
372 | 387 | 'name' => '!', |
373 | 388 | 'value' => $text_value |
374 | 389 | ); |
390 | + } |
|
375 | 391 | } |
376 | 392 | // If the < isn't immediately next to the current position... more data. |
377 | 393 | elseif (strpos($data, '<') > 0) |
@@ -379,11 +395,12 @@ discard block |
||
379 | 395 | $text_value = $this->_from_cdata(substr($data, 0, strpos($data, '<'))); |
380 | 396 | $data = substr($data, strpos($data, '<')); |
381 | 397 | |
382 | - if ($text_value != '') |
|
383 | - $current[] = array( |
|
398 | + if ($text_value != '') { |
|
399 | + $current[] = array( |
|
384 | 400 | 'name' => '!', |
385 | 401 | 'value' => $text_value |
386 | 402 | ); |
403 | + } |
|
387 | 404 | } |
388 | 405 | // If we're looking at a </something> with no start, kill it. |
389 | 406 | elseif (strpos($data, '<') !== false && strpos($data, '<') == 0) |
@@ -393,22 +410,23 @@ discard block |
||
393 | 410 | $text_value = $this->_from_cdata(substr($data, 0, strpos($data, '<', 1))); |
394 | 411 | $data = substr($data, strpos($data, '<', 1)); |
395 | 412 | |
396 | - if ($text_value != '') |
|
397 | - $current[] = array( |
|
413 | + if ($text_value != '') { |
|
414 | + $current[] = array( |
|
398 | 415 | 'name' => '!', |
399 | 416 | 'value' => $text_value |
400 | 417 | ); |
401 | - } |
|
402 | - else |
|
418 | + } |
|
419 | + } else |
|
403 | 420 | { |
404 | 421 | $text_value = $this->_from_cdata($data); |
405 | 422 | $data = ''; |
406 | 423 | |
407 | - if ($text_value != '') |
|
408 | - $current[] = array( |
|
424 | + if ($text_value != '') { |
|
425 | + $current[] = array( |
|
409 | 426 | 'name' => '!', |
410 | 427 | 'value' => $text_value |
411 | 428 | ); |
429 | + } |
|
412 | 430 | } |
413 | 431 | } |
414 | 432 | |
@@ -425,8 +443,9 @@ discard block |
||
425 | 443 | { |
426 | 444 | // Because PHP 5.2.0+ seems to croak using regex, we'll have to do this the less fun way. |
427 | 445 | $last_tag_end = strpos($data, '</' . $match[1]. '>'); |
428 | - if ($last_tag_end === false) |
|
429 | - continue; |
|
446 | + if ($last_tag_end === false) { |
|
447 | + continue; |
|
448 | + } |
|
430 | 449 | |
431 | 450 | $offset = 0; |
432 | 451 | while (1 == 1) |
@@ -434,16 +453,17 @@ discard block |
||
434 | 453 | // Where is the next start tag? |
435 | 454 | $next_tag_start = strpos($data, '<' . $match[1], $offset); |
436 | 455 | // If the next start tag is after the last end tag then we've found the right close. |
437 | - if ($next_tag_start === false || $next_tag_start > $last_tag_end) |
|
438 | - break; |
|
456 | + if ($next_tag_start === false || $next_tag_start > $last_tag_end) { |
|
457 | + break; |
|
458 | + } |
|
439 | 459 | |
440 | 460 | // If not then find the next ending tag. |
441 | 461 | $next_tag_end = strpos($data, '</' . $match[1]. '>', $offset); |
442 | 462 | |
443 | 463 | // Didn't find one? Then just use the last and sod it. |
444 | - if ($next_tag_end === false) |
|
445 | - break; |
|
446 | - else |
|
464 | + if ($next_tag_end === false) { |
|
465 | + break; |
|
466 | + } else |
|
447 | 467 | { |
448 | 468 | $last_tag_end = $next_tag_end; |
449 | 469 | $offset = $next_tag_start + 1; |
@@ -457,16 +477,17 @@ discard block |
||
457 | 477 | if (!empty($inner_match)) |
458 | 478 | { |
459 | 479 | // Parse the inner data. |
460 | - if (strpos($inner_match, '<') !== false) |
|
461 | - $el += $this->_parse($inner_match); |
|
462 | - elseif (trim($inner_match) != '') |
|
480 | + if (strpos($inner_match, '<') !== false) { |
|
481 | + $el += $this->_parse($inner_match); |
|
482 | + } elseif (trim($inner_match) != '') |
|
463 | 483 | { |
464 | 484 | $text_value = $this->_from_cdata($inner_match); |
465 | - if ($text_value != '') |
|
466 | - $el[] = array( |
|
485 | + if ($text_value != '') { |
|
486 | + $el[] = array( |
|
467 | 487 | 'name' => '!', |
468 | 488 | 'value' => $text_value |
469 | 489 | ); |
490 | + } |
|
470 | 491 | } |
471 | 492 | } |
472 | 493 | } |
@@ -478,8 +499,9 @@ discard block |
||
478 | 499 | preg_match_all('/([\w:]+)="(.+?)"/', $match[2], $attr, PREG_SET_ORDER); |
479 | 500 | |
480 | 501 | // Set them as @attribute-name. |
481 | - foreach ($attr as $match_attr) |
|
482 | - $el['@' . $match_attr[1]] = $match_attr[2]; |
|
502 | + foreach ($attr as $match_attr) { |
|
503 | + $el['@' . $match_attr[1]] = $match_attr[2]; |
|
504 | + } |
|
483 | 505 | } |
484 | 506 | } |
485 | 507 | |
@@ -503,16 +525,18 @@ discard block |
||
503 | 525 | if (is_array($array) && !isset($array['name'])) |
504 | 526 | { |
505 | 527 | $temp = ''; |
506 | - foreach ($array as $val) |
|
507 | - $temp .= $this->_xml($val, $indent); |
|
528 | + foreach ($array as $val) { |
|
529 | + $temp .= $this->_xml($val, $indent); |
|
530 | + } |
|
508 | 531 | return $temp; |
509 | 532 | } |
510 | 533 | |
511 | 534 | // This is just text! |
512 | - if ($array['name'] == '!') |
|
513 | - return $indentation . '<![CDATA[' . $array['value'] . ']]>'; |
|
514 | - elseif (substr($array['name'], -2) == '[]') |
|
515 | - $array['name'] = substr($array['name'], 0, -2); |
|
535 | + if ($array['name'] == '!') { |
|
536 | + return $indentation . '<![CDATA[' . $array['value'] . ']]>'; |
|
537 | + } elseif (substr($array['name'], -2) == '[]') { |
|
538 | + $array['name'] = substr($array['name'], 0, -2); |
|
539 | + } |
|
516 | 540 | |
517 | 541 | // Start the element. |
518 | 542 | $output = $indentation . '<' . $array['name']; |
@@ -523,9 +547,9 @@ discard block |
||
523 | 547 | // Run through and recursively output all the elements or attrbutes inside this. |
524 | 548 | foreach ($array as $k => $v) |
525 | 549 | { |
526 | - if (substr($k, 0, 1) == '@') |
|
527 | - $output .= ' ' . substr($k, 1) . '="' . $v . '"'; |
|
528 | - elseif (is_array($v)) |
|
550 | + if (substr($k, 0, 1) == '@') { |
|
551 | + $output .= ' ' . substr($k, 1) . '="' . $v . '"'; |
|
552 | + } elseif (is_array($v)) |
|
529 | 553 | { |
530 | 554 | $output_el .= $this->_xml($v, $indent === null ? null : $indent + 1); |
531 | 555 | $inside_elements = true; |
@@ -533,10 +557,11 @@ discard block |
||
533 | 557 | } |
534 | 558 | |
535 | 559 | // Indent, if necessary.... then close the tag. |
536 | - if ($inside_elements) |
|
537 | - $output .= '>' . $output_el . $indentation . '</' . $array['name'] . '>'; |
|
538 | - else |
|
539 | - $output .= ' />'; |
|
560 | + if ($inside_elements) { |
|
561 | + $output .= '>' . $output_el . $indentation . '</' . $array['name'] . '>'; |
|
562 | + } else { |
|
563 | + $output .= ' />'; |
|
564 | + } |
|
540 | 565 | |
541 | 566 | return $output; |
542 | 567 | } |
@@ -553,19 +578,22 @@ discard block |
||
553 | 578 | $text = ''; |
554 | 579 | foreach ($array as $value) |
555 | 580 | { |
556 | - if (!is_array($value) || !isset($value['name'])) |
|
557 | - continue; |
|
581 | + if (!is_array($value) || !isset($value['name'])) { |
|
582 | + continue; |
|
583 | + } |
|
558 | 584 | |
559 | - if ($value['name'] == '!') |
|
560 | - $text .= $value['value']; |
|
561 | - else |
|
562 | - $return[$value['name']] = $this->_array($value); |
|
585 | + if ($value['name'] == '!') { |
|
586 | + $text .= $value['value']; |
|
587 | + } else { |
|
588 | + $return[$value['name']] = $this->_array($value); |
|
589 | + } |
|
563 | 590 | } |
564 | 591 | |
565 | - if (empty($return)) |
|
566 | - return $text; |
|
567 | - else |
|
568 | - return $return; |
|
592 | + if (empty($return)) { |
|
593 | + return $text; |
|
594 | + } else { |
|
595 | + return $return; |
|
596 | + } |
|
569 | 597 | } |
570 | 598 | |
571 | 599 | /** |
@@ -583,24 +611,28 @@ discard block |
||
583 | 611 | foreach ($parts as $part) |
584 | 612 | { |
585 | 613 | // Handle XML comments. |
586 | - if (!$inCdata && $part === '<!--') |
|
587 | - $inComment = true; |
|
588 | - if ($inComment && $part === '-->') |
|
589 | - $inComment = false; |
|
590 | - elseif ($inComment) |
|
591 | - continue; |
|
614 | + if (!$inCdata && $part === '<!--') { |
|
615 | + $inComment = true; |
|
616 | + } |
|
617 | + if ($inComment && $part === '-->') { |
|
618 | + $inComment = false; |
|
619 | + } elseif ($inComment) { |
|
620 | + continue; |
|
621 | + } |
|
592 | 622 | |
593 | 623 | // Handle Cdata blocks. |
594 | - elseif (!$inComment && $part === '<![CDATA[') |
|
595 | - $inCdata = true; |
|
596 | - elseif ($inCdata && $part === ']]>') |
|
597 | - $inCdata = false; |
|
598 | - elseif ($inCdata) |
|
599 | - $output .= htmlentities($part, ENT_QUOTES); |
|
624 | + elseif (!$inComment && $part === '<![CDATA[') { |
|
625 | + $inCdata = true; |
|
626 | + } elseif ($inCdata && $part === ']]>') { |
|
627 | + $inCdata = false; |
|
628 | + } elseif ($inCdata) { |
|
629 | + $output .= htmlentities($part, ENT_QUOTES); |
|
630 | + } |
|
600 | 631 | |
601 | 632 | // Everything else is kept as is. |
602 | - else |
|
603 | - $output .= $part; |
|
633 | + else { |
|
634 | + $output .= $part; |
|
635 | + } |
|
604 | 636 | } |
605 | 637 | |
606 | 638 | return $output; |
@@ -635,22 +667,26 @@ discard block |
||
635 | 667 | protected function _fetch($array) |
636 | 668 | { |
637 | 669 | // Don't return anything if this is just a string. |
638 | - if (is_string($array)) |
|
639 | - return ''; |
|
670 | + if (is_string($array)) { |
|
671 | + return ''; |
|
672 | + } |
|
640 | 673 | |
641 | 674 | $temp = ''; |
642 | 675 | foreach ($array as $text) |
643 | 676 | { |
644 | 677 | // This means it's most likely an attribute or the name itself. |
645 | - if (!isset($text['name'])) |
|
646 | - continue; |
|
678 | + if (!isset($text['name'])) { |
|
679 | + continue; |
|
680 | + } |
|
647 | 681 | |
648 | 682 | // This is text! |
649 | - if ($text['name'] == '!') |
|
650 | - $temp .= $text['value']; |
|
683 | + if ($text['name'] == '!') { |
|
684 | + $temp .= $text['value']; |
|
685 | + } |
|
651 | 686 | // Another element - dive in ;). |
652 | - else |
|
653 | - $temp .= $this->_fetch($text); |
|
687 | + else { |
|
688 | + $temp .= $this->_fetch($text); |
|
689 | + } |
|
654 | 690 | } |
655 | 691 | |
656 | 692 | // Return all the bits and pieces we've put together. |
@@ -669,12 +705,14 @@ discard block |
||
669 | 705 | protected function _path($array, $path, $level, $no_error = false) |
670 | 706 | { |
671 | 707 | // Is $array even an array? It might be false! |
672 | - if (!is_array($array)) |
|
673 | - return false; |
|
708 | + if (!is_array($array)) { |
|
709 | + return false; |
|
710 | + } |
|
674 | 711 | |
675 | 712 | // Asking for *no* path? |
676 | - if ($path == '' || $path == '.') |
|
677 | - return $array; |
|
713 | + if ($path == '' || $path == '.') { |
|
714 | + return $array; |
|
715 | + } |
|
678 | 716 | $paths = explode('|', $path); |
679 | 717 | |
680 | 718 | // A * means all elements of any name. |
@@ -685,16 +723,18 @@ discard block |
||
685 | 723 | // Check each element. |
686 | 724 | foreach ($array as $value) |
687 | 725 | { |
688 | - if (!is_array($value) || $value['name'] === '!') |
|
689 | - continue; |
|
726 | + if (!is_array($value) || $value['name'] === '!') { |
|
727 | + continue; |
|
728 | + } |
|
690 | 729 | |
691 | 730 | if ($show_all || in_array($value['name'], $paths)) |
692 | 731 | { |
693 | 732 | // Skip elements before "the one". |
694 | - if ($level !== null && $level > 0) |
|
695 | - $level--; |
|
696 | - else |
|
697 | - $results[] = $value; |
|
733 | + if ($level !== null && $level > 0) { |
|
734 | + $level--; |
|
735 | + } else { |
|
736 | + $results[] = $value; |
|
737 | + } |
|
698 | 738 | } |
699 | 739 | } |
700 | 740 | |
@@ -703,21 +743,25 @@ discard block |
||
703 | 743 | { |
704 | 744 | $trace = debug_backtrace(); |
705 | 745 | $i = 0; |
706 | - while ($i < count($trace) && isset($trace[$i]['class']) && $trace[$i]['class'] == get_class($this)) |
|
707 | - $i++; |
|
746 | + while ($i < count($trace) && isset($trace[$i]['class']) && $trace[$i]['class'] == get_class($this)) { |
|
747 | + $i++; |
|
748 | + } |
|
708 | 749 | $debug = ' from ' . $trace[$i - 1]['file'] . ' on line ' . $trace[$i - 1]['line']; |
709 | 750 | |
710 | 751 | // Cause an error. |
711 | - if ($this->debug_level & E_NOTICE && !$no_error) |
|
712 | - trigger_error('Undefined XML element: ' . $path . $debug, E_USER_NOTICE); |
|
752 | + if ($this->debug_level & E_NOTICE && !$no_error) { |
|
753 | + trigger_error('Undefined XML element: ' . $path . $debug, E_USER_NOTICE); |
|
754 | + } |
|
713 | 755 | return false; |
714 | 756 | } |
715 | 757 | // Only one result. |
716 | - elseif (count($results) == 1 || $level !== null) |
|
717 | - return $results[0]; |
|
758 | + elseif (count($results) == 1 || $level !== null) { |
|
759 | + return $results[0]; |
|
760 | + } |
|
718 | 761 | // Return the result set. |
719 | - else |
|
720 | - return $results + array('name' => $path . '[]'); |
|
762 | + else { |
|
763 | + return $results + array('name' => $path . '[]'); |
|
764 | + } |
|
721 | 765 | } |
722 | 766 | } |
723 | 767 | |
@@ -764,8 +808,9 @@ discard block |
||
764 | 808 | $this->error = false; |
765 | 809 | $this->pasv = array(); |
766 | 810 | |
767 | - if ($ftp_server !== null) |
|
768 | - $this->connect($ftp_server, $ftp_port, $ftp_user, $ftp_pass); |
|
811 | + if ($ftp_server !== null) { |
|
812 | + $this->connect($ftp_server, $ftp_port, $ftp_user, $ftp_pass); |
|
813 | + } |
|
769 | 814 | } |
770 | 815 | |
771 | 816 | /** |
@@ -778,14 +823,16 @@ discard block |
||
778 | 823 | */ |
779 | 824 | public function connect($ftp_server, $ftp_port = 21, $ftp_user = 'anonymous', $ftp_pass = '[email protected]') |
780 | 825 | { |
781 | - if (strpos($ftp_server, 'ftp://') === 0) |
|
782 | - $ftp_server = substr($ftp_server, 6); |
|
783 | - elseif (strpos($ftp_server, 'ftps://') === 0) |
|
784 | - $ftp_server = 'ssl://' . substr($ftp_server, 7); |
|
785 | - if (strpos($ftp_server, 'http://') === 0) |
|
786 | - $ftp_server = substr($ftp_server, 7); |
|
787 | - elseif (strpos($ftp_server, 'https://') === 0) |
|
788 | - $ftp_server = substr($ftp_server, 8); |
|
826 | + if (strpos($ftp_server, 'ftp://') === 0) { |
|
827 | + $ftp_server = substr($ftp_server, 6); |
|
828 | + } elseif (strpos($ftp_server, 'ftps://') === 0) { |
|
829 | + $ftp_server = 'ssl://' . substr($ftp_server, 7); |
|
830 | + } |
|
831 | + if (strpos($ftp_server, 'http://') === 0) { |
|
832 | + $ftp_server = substr($ftp_server, 7); |
|
833 | + } elseif (strpos($ftp_server, 'https://') === 0) { |
|
834 | + $ftp_server = substr($ftp_server, 8); |
|
835 | + } |
|
789 | 836 | $ftp_server = strtr($ftp_server, array('/' => '', ':' => '', '@' => '')); |
790 | 837 | |
791 | 838 | // Connect to the FTP server. |
@@ -834,12 +881,14 @@ discard block |
||
834 | 881 | */ |
835 | 882 | public function chdir($ftp_path) |
836 | 883 | { |
837 | - if (!is_resource($this->connection)) |
|
838 | - return false; |
|
884 | + if (!is_resource($this->connection)) { |
|
885 | + return false; |
|
886 | + } |
|
839 | 887 | |
840 | 888 | // No slash on the end, please... |
841 | - if ($ftp_path !== '/' && substr($ftp_path, -1) === '/') |
|
842 | - $ftp_path = substr($ftp_path, 0, -1); |
|
889 | + if ($ftp_path !== '/' && substr($ftp_path, -1) === '/') { |
|
890 | + $ftp_path = substr($ftp_path, 0, -1); |
|
891 | + } |
|
843 | 892 | |
844 | 893 | fwrite($this->connection, 'CWD ' . $ftp_path . "\r\n"); |
845 | 894 | if (!$this->check_response(250)) |
@@ -860,11 +909,13 @@ discard block |
||
860 | 909 | */ |
861 | 910 | public function chmod($ftp_file, $chmod) |
862 | 911 | { |
863 | - if (!is_resource($this->connection)) |
|
864 | - return false; |
|
912 | + if (!is_resource($this->connection)) { |
|
913 | + return false; |
|
914 | + } |
|
865 | 915 | |
866 | - if ($ftp_file == '') |
|
867 | - $ftp_file = '.'; |
|
916 | + if ($ftp_file == '') { |
|
917 | + $ftp_file = '.'; |
|
918 | + } |
|
868 | 919 | |
869 | 920 | // Do we have a file or a dir? |
870 | 921 | $is_dir = is_dir($ftp_file); |
@@ -880,9 +931,7 @@ discard block |
||
880 | 931 | { |
881 | 932 | $is_writable = true; |
882 | 933 | break; |
883 | - } |
|
884 | - |
|
885 | - else |
|
934 | + } else |
|
886 | 935 | { |
887 | 936 | // Convert the chmod value from octal (0777) to text ("777"). |
888 | 937 | fwrite($this->connection, 'SITE CHMOD ' . decoct($val) . ' ' . $ftp_file . "\r\n"); |
@@ -905,8 +954,9 @@ discard block |
||
905 | 954 | public function unlink($ftp_file) |
906 | 955 | { |
907 | 956 | // We are actually connected, right? |
908 | - if (!is_resource($this->connection)) |
|
909 | - return false; |
|
957 | + if (!is_resource($this->connection)) { |
|
958 | + return false; |
|
959 | + } |
|
910 | 960 | |
911 | 961 | // Delete file X. |
912 | 962 | fwrite($this->connection, 'DELE ' . $ftp_file . "\r\n"); |
@@ -935,9 +985,9 @@ discard block |
||
935 | 985 | { |
936 | 986 | // Wait for a response that isn't continued with -, but don't wait too long. |
937 | 987 | $time = time(); |
938 | - do |
|
939 | - $this->last_message = fgets($this->connection, 1024); |
|
940 | - while ((strlen($this->last_message) < 4 || strpos($this->last_message, ' ') === 0 || strpos($this->last_message, ' ', 3) !== 3) && time() - $time < 5); |
|
988 | + do { |
|
989 | + $this->last_message = fgets($this->connection, 1024); |
|
990 | + } while ((strlen($this->last_message) < 4 || strpos($this->last_message, ' ') === 0 || strpos($this->last_message, ' ', 3) !== 3) && time() - $time < 5); |
|
941 | 991 | |
942 | 992 | // Was the desired response returned? |
943 | 993 | return is_array($desired) ? in_array(substr($this->last_message, 0, 3), $desired) : substr($this->last_message, 0, 3) == $desired; |
@@ -951,15 +1001,16 @@ discard block |
||
951 | 1001 | public function passive() |
952 | 1002 | { |
953 | 1003 | // We can't create a passive data connection without a primary one first being there. |
954 | - if (!is_resource($this->connection)) |
|
955 | - return false; |
|
1004 | + if (!is_resource($this->connection)) { |
|
1005 | + return false; |
|
1006 | + } |
|
956 | 1007 | |
957 | 1008 | // Request a passive connection - this means, we'll talk to you, you don't talk to us. |
958 | 1009 | @fwrite($this->connection, 'PASV' . "\r\n"); |
959 | 1010 | $time = time(); |
960 | - do |
|
961 | - $response = fgets($this->connection, 1024); |
|
962 | - while (strpos($response, ' ', 3) !== 3 && time() - $time < 5); |
|
1011 | + do { |
|
1012 | + $response = fgets($this->connection, 1024); |
|
1013 | + } while (strpos($response, ' ', 3) !== 3 && time() - $time < 5); |
|
963 | 1014 | |
964 | 1015 | // If it's not 227, we weren't given an IP and port, which means it failed. |
965 | 1016 | if (strpos($response, '227 ') !== 0) |
@@ -990,12 +1041,14 @@ discard block |
||
990 | 1041 | public function create_file($ftp_file) |
991 | 1042 | { |
992 | 1043 | // First, we have to be connected... very important. |
993 | - if (!is_resource($this->connection)) |
|
994 | - return false; |
|
1044 | + if (!is_resource($this->connection)) { |
|
1045 | + return false; |
|
1046 | + } |
|
995 | 1047 | |
996 | 1048 | // I'd like one passive mode, please! |
997 | - if (!$this->passive()) |
|
998 | - return false; |
|
1049 | + if (!$this->passive()) { |
|
1050 | + return false; |
|
1051 | + } |
|
999 | 1052 | |
1000 | 1053 | // Seems logical enough, so far... |
1001 | 1054 | fwrite($this->connection, 'STOR ' . $ftp_file . "\r\n"); |
@@ -1030,12 +1083,14 @@ discard block |
||
1030 | 1083 | public function list_dir($ftp_path = '', $search = false) |
1031 | 1084 | { |
1032 | 1085 | // Are we even connected...? |
1033 | - if (!is_resource($this->connection)) |
|
1034 | - return false; |
|
1086 | + if (!is_resource($this->connection)) { |
|
1087 | + return false; |
|
1088 | + } |
|
1035 | 1089 | |
1036 | 1090 | // Passive... non-agressive... |
1037 | - if (!$this->passive()) |
|
1038 | - return false; |
|
1091 | + if (!$this->passive()) { |
|
1092 | + return false; |
|
1093 | + } |
|
1039 | 1094 | |
1040 | 1095 | // Get the listing! |
1041 | 1096 | fwrite($this->connection, 'LIST -1' . ($search ? 'R' : '') . ($ftp_path == '' ? '' : ' ' . $ftp_path) . "\r\n"); |
@@ -1051,8 +1106,9 @@ discard block |
||
1051 | 1106 | |
1052 | 1107 | // Read in the file listing. |
1053 | 1108 | $data = ''; |
1054 | - while (!feof($fp)) |
|
1055 | - $data .= fread($fp, 4096); |
|
1109 | + while (!feof($fp)) { |
|
1110 | + $data .= fread($fp, 4096); |
|
1111 | + } |
|
1056 | 1112 | fclose($fp); |
1057 | 1113 | |
1058 | 1114 | // Everything go okay? |
@@ -1074,21 +1130,23 @@ discard block |
||
1074 | 1130 | */ |
1075 | 1131 | public function locate($file, $listing = null) |
1076 | 1132 | { |
1077 | - if ($listing === null) |
|
1078 | - $listing = $this->list_dir('', true); |
|
1133 | + if ($listing === null) { |
|
1134 | + $listing = $this->list_dir('', true); |
|
1135 | + } |
|
1079 | 1136 | $listing = explode("\n", $listing); |
1080 | 1137 | |
1081 | 1138 | @fwrite($this->connection, 'PWD' . "\r\n"); |
1082 | 1139 | $time = time(); |
1083 | - do |
|
1084 | - $response = fgets($this->connection, 1024); |
|
1085 | - while ($response[3] != ' ' && time() - $time < 5); |
|
1140 | + do { |
|
1141 | + $response = fgets($this->connection, 1024); |
|
1142 | + } while ($response[3] != ' ' && time() - $time < 5); |
|
1086 | 1143 | |
1087 | 1144 | // Check for 257! |
1088 | - if (preg_match('~^257 "(.+?)" ~', $response, $match) != 0) |
|
1089 | - $current_dir = strtr($match[1], array('""' => '"')); |
|
1090 | - else |
|
1091 | - $current_dir = ''; |
|
1145 | + if (preg_match('~^257 "(.+?)" ~', $response, $match) != 0) { |
|
1146 | + $current_dir = strtr($match[1], array('""' => '"')); |
|
1147 | + } else { |
|
1148 | + $current_dir = ''; |
|
1149 | + } |
|
1092 | 1150 | |
1093 | 1151 | for ($i = 0, $n = count($listing); $i < $n; $i++) |
1094 | 1152 | { |
@@ -1101,12 +1159,15 @@ discard block |
||
1101 | 1159 | // Okay, this file's name is: |
1102 | 1160 | $listing[$i] = $current_dir . '/' . trim(strlen($listing[$i]) > 30 ? strrchr($listing[$i], ' ') : $listing[$i]); |
1103 | 1161 | |
1104 | - if ($file[0] == '*' && substr($listing[$i], -(strlen($file) - 1)) == substr($file, 1)) |
|
1105 | - return $listing[$i]; |
|
1106 | - if (substr($file, -1) == '*' && substr($listing[$i], 0, strlen($file) - 1) == substr($file, 0, -1)) |
|
1107 | - return $listing[$i]; |
|
1108 | - if (basename($listing[$i]) == $file || $listing[$i] == $file) |
|
1109 | - return $listing[$i]; |
|
1162 | + if ($file[0] == '*' && substr($listing[$i], -(strlen($file) - 1)) == substr($file, 1)) { |
|
1163 | + return $listing[$i]; |
|
1164 | + } |
|
1165 | + if (substr($file, -1) == '*' && substr($listing[$i], 0, strlen($file) - 1) == substr($file, 0, -1)) { |
|
1166 | + return $listing[$i]; |
|
1167 | + } |
|
1168 | + if (basename($listing[$i]) == $file || $listing[$i] == $file) { |
|
1169 | + return $listing[$i]; |
|
1170 | + } |
|
1110 | 1171 | } |
1111 | 1172 | |
1112 | 1173 | return false; |
@@ -1121,8 +1182,9 @@ discard block |
||
1121 | 1182 | public function create_dir($ftp_dir) |
1122 | 1183 | { |
1123 | 1184 | // We must be connected to the server to do something. |
1124 | - if (!is_resource($this->connection)) |
|
1125 | - return false; |
|
1185 | + if (!is_resource($this->connection)) { |
|
1186 | + return false; |
|
1187 | + } |
|
1126 | 1188 | |
1127 | 1189 | // Make this new beautiful directory! |
1128 | 1190 | fwrite($this->connection, 'MKD ' . $ftp_dir . "\r\n"); |
@@ -1154,35 +1216,40 @@ discard block |
||
1154 | 1216 | |
1155 | 1217 | $path = strtr($_SERVER['DOCUMENT_ROOT'], array('/home/' . $match[1] . '/' => '', '/home2/' . $match[1] . '/' => '')); |
1156 | 1218 | |
1157 | - if (substr($path, -1) == '/') |
|
1158 | - $path = substr($path, 0, -1); |
|
1219 | + if (substr($path, -1) == '/') { |
|
1220 | + $path = substr($path, 0, -1); |
|
1221 | + } |
|
1159 | 1222 | |
1160 | - if (strlen(dirname($_SERVER['PHP_SELF'])) > 1) |
|
1161 | - $path .= dirname($_SERVER['PHP_SELF']); |
|
1223 | + if (strlen(dirname($_SERVER['PHP_SELF'])) > 1) { |
|
1224 | + $path .= dirname($_SERVER['PHP_SELF']); |
|
1225 | + } |
|
1226 | + } elseif (strpos($filesystem_path, '/var/www/') === 0) { |
|
1227 | + $path = substr($filesystem_path, 8); |
|
1228 | + } else { |
|
1229 | + $path = strtr(strtr($filesystem_path, array('\\' => '/')), array($_SERVER['DOCUMENT_ROOT'] => '')); |
|
1162 | 1230 | } |
1163 | - elseif (strpos($filesystem_path, '/var/www/') === 0) |
|
1164 | - $path = substr($filesystem_path, 8); |
|
1165 | - else |
|
1166 | - $path = strtr(strtr($filesystem_path, array('\\' => '/')), array($_SERVER['DOCUMENT_ROOT'] => '')); |
|
1231 | + } else { |
|
1232 | + $path = ''; |
|
1167 | 1233 | } |
1168 | - else |
|
1169 | - $path = ''; |
|
1170 | 1234 | |
1171 | 1235 | if (is_resource($this->connection) && $this->list_dir($path) == '') |
1172 | 1236 | { |
1173 | 1237 | $data = $this->list_dir('', true); |
1174 | 1238 | |
1175 | - if ($lookup_file === null) |
|
1176 | - $lookup_file = $_SERVER['PHP_SELF']; |
|
1239 | + if ($lookup_file === null) { |
|
1240 | + $lookup_file = $_SERVER['PHP_SELF']; |
|
1241 | + } |
|
1177 | 1242 | |
1178 | 1243 | $found_path = dirname($this->locate('*' . basename(dirname($lookup_file)) . '/' . basename($lookup_file), $data)); |
1179 | - if ($found_path == false) |
|
1180 | - $found_path = dirname($this->locate(basename($lookup_file))); |
|
1181 | - if ($found_path != false) |
|
1182 | - $path = $found_path; |
|
1244 | + if ($found_path == false) { |
|
1245 | + $found_path = dirname($this->locate(basename($lookup_file))); |
|
1246 | + } |
|
1247 | + if ($found_path != false) { |
|
1248 | + $path = $found_path; |
|
1249 | + } |
|
1250 | + } elseif (is_resource($this->connection)) { |
|
1251 | + $found_path = true; |
|
1183 | 1252 | } |
1184 | - elseif (is_resource($this->connection)) |
|
1185 | - $found_path = true; |
|
1186 | 1253 | |
1187 | 1254 | return array($username, $path, isset($found_path)); |
1188 | 1255 | } |
@@ -56,6 +56,7 @@ discard block |
||
56 | 56 | * @param array $wordsSearch Search words |
57 | 57 | * @param array $wordsExclude Words to exclude |
58 | 58 | * @param bool $isExcluded Whether the specfied word should be excluded |
59 | + * @return void |
|
59 | 60 | */ |
60 | 61 | public function prepareIndexes($word, array &$wordsSearch, array &$wordsExclude, $isExcluded); |
61 | 62 | |
@@ -130,7 +131,7 @@ discard block |
||
130 | 131 | * @param array $excludedIndexWords Indexed words that should be excluded |
131 | 132 | * @param array $participants |
132 | 133 | * @param array $searchArray |
133 | - * @return mixed |
|
134 | + * @return integer |
|
134 | 135 | */ |
135 | 136 | public function searchQuery(array $query_params, array $searchWords, array $excludedIndexWords, array &$participants, array &$searchArray); |
136 | 137 | } |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | /** |
280 | 280 | * Generate the timestamp for the calculation |
281 | 281 | * |
282 | - * @return integer Timestamp |
|
282 | + * @return double Timestamp |
|
283 | 283 | */ |
284 | 284 | public function generateTimestamp() |
285 | 285 | { |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | * Truncate the given hash down to just what we need |
291 | 291 | * |
292 | 292 | * @param string $hash Hash to truncate |
293 | - * @return string Truncated hash value |
|
293 | + * @return integer Truncated hash value |
|
294 | 294 | */ |
295 | 295 | public function truncateHash($hash) |
296 | 296 | { |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | */ |
115 | 115 | public function setInitKey($key) |
116 | 116 | { |
117 | - if (preg_match('/^['.implode('', array_keys($this->getLookup())).']+$/', $key) == false) { |
|
117 | + if (preg_match('/^[' . implode('', array_keys($this->getLookup())) . ']+$/', $key) == false) { |
|
118 | 118 | throw new \InvalidArgumentException('Invalid base32 hash!'); |
119 | 119 | } |
120 | 120 | $this->initKey = $key; |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | $initKey = ($initKey == null) ? $this->getInitKey() : $initKey; |
248 | 248 | $timestamp = ($timestamp == null) ? $this->generateTimestamp() : $timestamp; |
249 | 249 | |
250 | - $hash = hash_hmac ( |
|
250 | + $hash = hash_hmac( |
|
251 | 251 | 'sha1', |
252 | 252 | pack('N*', 0) . pack('N*', $timestamp), |
253 | 253 | $initKey, |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | $code = ''; |
271 | 271 | |
272 | 272 | for ($i = 0; $i < $length; $i++) { |
273 | - $code .= $lookup[mt_rand(0, strlen($lookup)-1)]; |
|
273 | + $code .= $lookup[mt_rand(0, strlen($lookup) - 1)]; |
|
274 | 274 | } |
275 | 275 | |
276 | 276 | return $code; |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | */ |
284 | 284 | public function generateTimestamp() |
285 | 285 | { |
286 | - return floor(microtime(true)/$this->getRefresh()); |
|
286 | + return floor(microtime(true) / $this->getRefresh()); |
|
287 | 287 | } |
288 | 288 | |
289 | 289 | /** |
@@ -297,10 +297,10 @@ discard block |
||
297 | 297 | $offset = ord($hash[19]) & 0xf; |
298 | 298 | |
299 | 299 | return ( |
300 | - ((ord($hash[$offset+0]) & 0x7f) << 24 ) | |
|
301 | - ((ord($hash[$offset+1]) & 0xff) << 16 ) | |
|
302 | - ((ord($hash[$offset+2]) & 0xff) << 8 ) | |
|
303 | - (ord($hash[$offset+3]) & 0xff) |
|
300 | + ((ord($hash[$offset + 0]) & 0x7f) << 24) | |
|
301 | + ((ord($hash[$offset + 1]) & 0xff) << 16) | |
|
302 | + ((ord($hash[$offset + 2]) & 0xff) << 8) | |
|
303 | + (ord($hash[$offset + 3]) & 0xff) |
|
304 | 304 | ) % pow(10, $this->getCodeLength()); |
305 | 305 | } |
306 | 306 | |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | { |
316 | 316 | $lookup = $this->getLookup(); |
317 | 317 | |
318 | - if (preg_match('/^['.implode('', array_keys($lookup)).']+$/', $hash) == false) { |
|
318 | + if (preg_match('/^[' . implode('', array_keys($lookup)) . ']+$/', $hash) == false) { |
|
319 | 319 | throw new \InvalidArgumentException('Invalid base32 hash!'); |
320 | 320 | } |
321 | 321 |
@@ -382,7 +382,7 @@ |
||
382 | 382 | * @param array $parameters Not used? |
383 | 383 | * @param string $if_exists What to do if the index exists. If 'update', the definition will be updated. |
384 | 384 | * @param string $error |
385 | - * @return boolean Whether or not the operation was successful |
|
385 | + * @return false|null Whether or not the operation was successful |
|
386 | 386 | */ |
387 | 387 | function smf_db_add_index($table_name, $index_info, $parameters = array(), $if_exists = 'update', $error = 'fatal') |
388 | 388 | { |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | // Righty - let's do the damn thing! |
126 | 126 | $table_query = 'CREATE TABLE ' . $table_name . "\n" . '('; |
127 | 127 | foreach ($columns as $column) |
128 | - $table_query .= "\n\t" . smf_db_create_query_column($column) . ','; |
|
128 | + $table_query .= "\n\t" . smf_db_create_query_column($column) . ','; |
|
129 | 129 | |
130 | 130 | // Loop through the indexes next... |
131 | 131 | foreach ($indexes as $index) |
@@ -744,7 +744,7 @@ discard block |
||
744 | 744 | $type = $type . '(' . $size . ')'; |
745 | 745 | |
746 | 746 | // Now just put it together! |
747 | - return '`' .$column['name'] . '` ' . $type . ' ' . (!empty($unsigned) ? $unsigned : '') . (!empty($column['null']) ? '' : 'NOT NULL') . ' ' . $default; |
|
747 | + return '`' . $column['name'] . '` ' . $type . ' ' . (!empty($unsigned) ? $unsigned : '') . (!empty($column['null']) ? '' : 'NOT NULL') . ' ' . $default; |
|
748 | 748 | } |
749 | 749 | |
750 | 750 | ?> |
751 | 751 | \ No newline at end of file |
@@ -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 | * Add the file functions to the $smcFunc array. |
@@ -52,8 +53,9 @@ discard block |
||
52 | 53 | 'messages', 'moderators', 'package_servers', 'permission_profiles', 'permissions', 'personal_messages', |
53 | 54 | 'pm_recipients', 'poll_choices', 'polls', 'scheduled_tasks', 'sessions', 'settings', 'smileys', |
54 | 55 | 'themes', 'topics'); |
55 | - foreach ($reservedTables as $k => $table_name) |
|
56 | - $reservedTables[$k] = strtolower($db_prefix . $table_name); |
|
56 | + foreach ($reservedTables as $k => $table_name) { |
|
57 | + $reservedTables[$k] = strtolower($db_prefix . $table_name); |
|
58 | + } |
|
57 | 59 | |
58 | 60 | // We in turn may need the extra stuff. |
59 | 61 | db_extend('extra'); |
@@ -105,8 +107,9 @@ discard block |
||
105 | 107 | $table_name = str_replace('{db_prefix}', $db_prefix, $table_name); |
106 | 108 | |
107 | 109 | // First - no way do we touch SMF tables. |
108 | - if (in_array(strtolower($table_name), $reservedTables)) |
|
109 | - return false; |
|
110 | + if (in_array(strtolower($table_name), $reservedTables)) { |
|
111 | + return false; |
|
112 | + } |
|
110 | 113 | |
111 | 114 | // Log that we'll want to remove this on uninstall. |
112 | 115 | $db_package_log[] = array('remove_table', $table_name); |
@@ -116,16 +119,18 @@ discard block |
||
116 | 119 | if (in_array($full_table_name, $tables)) |
117 | 120 | { |
118 | 121 | // This is a sad day... drop the table? If not, return false (error) by default. |
119 | - if ($if_exists == 'overwrite') |
|
120 | - $smcFunc['db_drop_table']($table_name); |
|
121 | - else |
|
122 | - return $if_exists == 'ignore'; |
|
122 | + if ($if_exists == 'overwrite') { |
|
123 | + $smcFunc['db_drop_table']($table_name); |
|
124 | + } else { |
|
125 | + return $if_exists == 'ignore'; |
|
126 | + } |
|
123 | 127 | } |
124 | 128 | |
125 | 129 | // Righty - let's do the damn thing! |
126 | 130 | $table_query = 'CREATE TABLE ' . $table_name . "\n" . '('; |
127 | - foreach ($columns as $column) |
|
128 | - $table_query .= "\n\t" . smf_db_create_query_column($column) . ','; |
|
131 | + foreach ($columns as $column) { |
|
132 | + $table_query .= "\n\t" . smf_db_create_query_column($column) . ','; |
|
133 | + } |
|
129 | 134 | |
130 | 135 | // Loop through the indexes next... |
131 | 136 | foreach ($indexes as $index) |
@@ -133,19 +138,21 @@ discard block |
||
133 | 138 | $columns = implode(',', $index['columns']); |
134 | 139 | |
135 | 140 | // Is it the primary? |
136 | - if (isset($index['type']) && $index['type'] == 'primary') |
|
137 | - $table_query .= "\n\t" . 'PRIMARY KEY (' . implode(',', $index['columns']) . '),'; |
|
138 | - else |
|
141 | + if (isset($index['type']) && $index['type'] == 'primary') { |
|
142 | + $table_query .= "\n\t" . 'PRIMARY KEY (' . implode(',', $index['columns']) . '),'; |
|
143 | + } else |
|
139 | 144 | { |
140 | - if (empty($index['name'])) |
|
141 | - $index['name'] = implode('_', $index['columns']); |
|
145 | + if (empty($index['name'])) { |
|
146 | + $index['name'] = implode('_', $index['columns']); |
|
147 | + } |
|
142 | 148 | $table_query .= "\n\t" . (isset($index['type']) && $index['type'] == 'unique' ? 'UNIQUE' : 'KEY') . ' ' . $index['name'] . ' (' . $columns . '),'; |
143 | 149 | } |
144 | 150 | } |
145 | 151 | |
146 | 152 | // No trailing commas! |
147 | - if (substr($table_query, -1) == ',') |
|
148 | - $table_query = substr($table_query, 0, -1); |
|
153 | + if (substr($table_query, -1) == ',') { |
|
154 | + $table_query = substr($table_query, 0, -1); |
|
155 | + } |
|
149 | 156 | |
150 | 157 | // Which engine do we want here? |
151 | 158 | if (empty($engines)) |
@@ -155,8 +162,9 @@ discard block |
||
155 | 162 | |
156 | 163 | while ($row = $smcFunc['db_fetch_assoc']($get_engines)) |
157 | 164 | { |
158 | - if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') |
|
159 | - $engines[] = $row['Engine']; |
|
165 | + if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') { |
|
166 | + $engines[] = $row['Engine']; |
|
167 | + } |
|
160 | 168 | } |
161 | 169 | |
162 | 170 | $smcFunc['db_free_result']($get_engines); |
@@ -170,8 +178,9 @@ discard block |
||
170 | 178 | } |
171 | 179 | |
172 | 180 | $table_query .= ') ENGINE=' . $parameters['engine']; |
173 | - if (!empty($db_character_set) && $db_character_set == 'utf8') |
|
174 | - $table_query .= ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci'; |
|
181 | + if (!empty($db_character_set) && $db_character_set == 'utf8') { |
|
182 | + $table_query .= ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci'; |
|
183 | + } |
|
175 | 184 | |
176 | 185 | // Create the table! |
177 | 186 | $smcFunc['db_query']('', $table_query, |
@@ -203,8 +212,9 @@ discard block |
||
203 | 212 | $table_name = str_replace('{db_prefix}', $db_prefix, $table_name); |
204 | 213 | |
205 | 214 | // God no - dropping one of these = bad. |
206 | - if (in_array(strtolower($table_name), $reservedTables)) |
|
207 | - return false; |
|
215 | + if (in_array(strtolower($table_name), $reservedTables)) { |
|
216 | + return false; |
|
217 | + } |
|
208 | 218 | |
209 | 219 | // Does it exist? |
210 | 220 | if (in_array($full_table_name, $smcFunc['db_list_tables']())) |
@@ -245,14 +255,16 @@ discard block |
||
245 | 255 | |
246 | 256 | // Does it exist - if so don't add it again! |
247 | 257 | $columns = $smcFunc['db_list_columns']($table_name, false); |
248 | - foreach ($columns as $column) |
|
249 | - if ($column == $column_info['name']) |
|
258 | + foreach ($columns as $column) { |
|
259 | + if ($column == $column_info['name']) |
|
250 | 260 | { |
251 | 261 | // If we're going to overwrite then use change column. |
252 | 262 | if ($if_exists == 'update') |
253 | 263 | return $smcFunc['db_change_column']($table_name, $column_info['name'], $column_info); |
254 | - else |
|
255 | - return false; |
|
264 | + } |
|
265 | + else { |
|
266 | + return false; |
|
267 | + } |
|
256 | 268 | } |
257 | 269 | |
258 | 270 | // Get the specifics... |
@@ -262,8 +274,9 @@ discard block |
||
262 | 274 | // Allow unsigned integers (mysql only) |
263 | 275 | $unsigned = in_array($type, array('int', 'tinyint', 'smallint', 'mediumint', 'bigint')) && !empty($column_info['unsigned']) ? 'unsigned ' : ''; |
264 | 276 | |
265 | - if ($size !== null) |
|
266 | - $type = $type . '(' . $size . ')'; |
|
277 | + if ($size !== null) { |
|
278 | + $type = $type . '(' . $size . ')'; |
|
279 | + } |
|
267 | 280 | |
268 | 281 | // Now add the thing! |
269 | 282 | $query = ' |
@@ -295,8 +308,8 @@ discard block |
||
295 | 308 | |
296 | 309 | // Does it exist? |
297 | 310 | $columns = $smcFunc['db_list_columns']($table_name, true); |
298 | - foreach ($columns as $column) |
|
299 | - if ($column['name'] == $column_name) |
|
311 | + foreach ($columns as $column) { |
|
312 | + if ($column['name'] == $column_name) |
|
300 | 313 | { |
301 | 314 | $smcFunc['db_query']('', ' |
302 | 315 | ALTER TABLE ' . $table_name . ' |
@@ -305,6 +318,7 @@ discard block |
||
305 | 318 | 'security_override' => true, |
306 | 319 | ) |
307 | 320 | ); |
321 | + } |
|
308 | 322 | |
309 | 323 | return true; |
310 | 324 | } |
@@ -331,37 +345,47 @@ discard block |
||
331 | 345 | // Check it does exist! |
332 | 346 | $columns = $smcFunc['db_list_columns']($table_name, true); |
333 | 347 | $old_info = null; |
334 | - foreach ($columns as $column) |
|
335 | - if ($column['name'] == $old_column) |
|
348 | + foreach ($columns as $column) { |
|
349 | + if ($column['name'] == $old_column) |
|
336 | 350 | $old_info = $column; |
351 | + } |
|
337 | 352 | |
338 | 353 | // Nothing? |
339 | - if ($old_info == null) |
|
340 | - return false; |
|
354 | + if ($old_info == null) { |
|
355 | + return false; |
|
356 | + } |
|
341 | 357 | |
342 | 358 | // Get the right bits. |
343 | - if (!isset($column_info['name'])) |
|
344 | - $column_info['name'] = $old_column; |
|
345 | - if (!isset($column_info['default'])) |
|
346 | - $column_info['default'] = $old_info['default']; |
|
347 | - if (!isset($column_info['null'])) |
|
348 | - $column_info['null'] = $old_info['null']; |
|
349 | - if (!isset($column_info['auto'])) |
|
350 | - $column_info['auto'] = $old_info['auto']; |
|
351 | - if (!isset($column_info['type'])) |
|
352 | - $column_info['type'] = $old_info['type']; |
|
353 | - if (!isset($column_info['size']) || !is_numeric($column_info['size'])) |
|
354 | - $column_info['size'] = $old_info['size']; |
|
355 | - if (!isset($column_info['unsigned']) || !in_array($column_info['type'], array('int', 'tinyint', 'smallint', 'mediumint', 'bigint'))) |
|
356 | - $column_info['unsigned'] = ''; |
|
359 | + if (!isset($column_info['name'])) { |
|
360 | + $column_info['name'] = $old_column; |
|
361 | + } |
|
362 | + if (!isset($column_info['default'])) { |
|
363 | + $column_info['default'] = $old_info['default']; |
|
364 | + } |
|
365 | + if (!isset($column_info['null'])) { |
|
366 | + $column_info['null'] = $old_info['null']; |
|
367 | + } |
|
368 | + if (!isset($column_info['auto'])) { |
|
369 | + $column_info['auto'] = $old_info['auto']; |
|
370 | + } |
|
371 | + if (!isset($column_info['type'])) { |
|
372 | + $column_info['type'] = $old_info['type']; |
|
373 | + } |
|
374 | + if (!isset($column_info['size']) || !is_numeric($column_info['size'])) { |
|
375 | + $column_info['size'] = $old_info['size']; |
|
376 | + } |
|
377 | + if (!isset($column_info['unsigned']) || !in_array($column_info['type'], array('int', 'tinyint', 'smallint', 'mediumint', 'bigint'))) { |
|
378 | + $column_info['unsigned'] = ''; |
|
379 | + } |
|
357 | 380 | |
358 | 381 | list ($type, $size) = $smcFunc['db_calculate_type']($column_info['type'], $column_info['size']); |
359 | 382 | |
360 | 383 | // Allow for unsigned integers (mysql only) |
361 | 384 | $unsigned = in_array($type, array('int', 'tinyint', 'smallint', 'mediumint', 'bigint')) && !empty($column_info['unsigned']) ? 'unsigned ' : ''; |
362 | 385 | |
363 | - if ($size !== null) |
|
364 | - $type = $type . '(' . $size . ')'; |
|
386 | + if ($size !== null) { |
|
387 | + $type = $type . '(' . $size . ')'; |
|
388 | + } |
|
365 | 389 | |
366 | 390 | $smcFunc['db_query']('', ' |
367 | 391 | ALTER TABLE ' . $table_name . ' |
@@ -391,21 +415,23 @@ discard block |
||
391 | 415 | $table_name = str_replace('{db_prefix}', $db_prefix, $table_name); |
392 | 416 | |
393 | 417 | // No columns = no index. |
394 | - if (empty($index_info['columns'])) |
|
395 | - return false; |
|
418 | + if (empty($index_info['columns'])) { |
|
419 | + return false; |
|
420 | + } |
|
396 | 421 | $columns = implode(',', $index_info['columns']); |
397 | 422 | |
398 | 423 | // No name - make it up! |
399 | 424 | if (empty($index_info['name'])) |
400 | 425 | { |
401 | 426 | // No need for primary. |
402 | - if (isset($index_info['type']) && $index_info['type'] == 'primary') |
|
403 | - $index_info['name'] = ''; |
|
404 | - else |
|
405 | - $index_info['name'] = implode('_', $index_info['columns']); |
|
427 | + if (isset($index_info['type']) && $index_info['type'] == 'primary') { |
|
428 | + $index_info['name'] = ''; |
|
429 | + } else { |
|
430 | + $index_info['name'] = implode('_', $index_info['columns']); |
|
431 | + } |
|
432 | + } else { |
|
433 | + $index_info['name'] = $index_info['name']; |
|
406 | 434 | } |
407 | - else |
|
408 | - $index_info['name'] = $index_info['name']; |
|
409 | 435 | |
410 | 436 | // Log that we are going to want to remove this! |
411 | 437 | $db_package_log[] = array('remove_index', $table_name, $index_info['name']); |
@@ -418,10 +444,11 @@ discard block |
||
418 | 444 | if ($index['name'] == $index_info['name'] || ($index['type'] == 'primary' && isset($index_info['type']) && $index_info['type'] == 'primary')) |
419 | 445 | { |
420 | 446 | // If we want to overwrite simply remove the current one then continue. |
421 | - if ($if_exists != 'update' || $index['type'] == 'primary') |
|
422 | - return false; |
|
423 | - else |
|
424 | - $smcFunc['db_remove_index']($table_name, $index_info['name']); |
|
447 | + if ($if_exists != 'update' || $index['type'] == 'primary') { |
|
448 | + return false; |
|
449 | + } else { |
|
450 | + $smcFunc['db_remove_index']($table_name, $index_info['name']); |
|
451 | + } |
|
425 | 452 | } |
426 | 453 | } |
427 | 454 | |
@@ -435,8 +462,7 @@ discard block |
||
435 | 462 | 'security_override' => true, |
436 | 463 | ) |
437 | 464 | ); |
438 | - } |
|
439 | - else |
|
465 | + } else |
|
440 | 466 | { |
441 | 467 | $smcFunc['db_query']('', ' |
442 | 468 | ALTER TABLE ' . $table_name . ' |
@@ -520,8 +546,7 @@ discard block |
||
520 | 546 | $types = array( |
521 | 547 | 'inet' => 'varbinary', |
522 | 548 | ); |
523 | - } |
|
524 | - else |
|
549 | + } else |
|
525 | 550 | { |
526 | 551 | $types = array( |
527 | 552 | 'varbinary' => 'inet', |
@@ -535,16 +560,15 @@ discard block |
||
535 | 560 | { |
536 | 561 | $type_size = 16; |
537 | 562 | $type_name = 'varbinary'; |
538 | - } |
|
539 | - elseif ($type_name == 'varbinary' && $reverse && $type_size == 16) |
|
563 | + } elseif ($type_name == 'varbinary' && $reverse && $type_size == 16) |
|
540 | 564 | { |
541 | 565 | $type_name = 'inet'; |
542 | 566 | $type_size = null; |
567 | + } elseif ($type_name == 'varbinary') { |
|
568 | + $type_name = 'varbinary'; |
|
569 | + } else { |
|
570 | + $type_name = $types[$type_name]; |
|
543 | 571 | } |
544 | - elseif ($type_name == 'varbinary') |
|
545 | - $type_name = 'varbinary'; |
|
546 | - else |
|
547 | - $type_name = $types[$type_name]; |
|
548 | 572 | } |
549 | 573 | |
550 | 574 | return array($type_name, $type_size); |
@@ -612,8 +636,7 @@ discard block |
||
612 | 636 | if (!$detail) |
613 | 637 | { |
614 | 638 | $columns[] = $row['Field']; |
615 | - } |
|
616 | - else |
|
639 | + } else |
|
617 | 640 | { |
618 | 641 | // Is there an auto_increment? |
619 | 642 | $auto = strpos($row['Extra'], 'auto_increment') !== false ? true : false; |
@@ -623,10 +646,10 @@ discard block |
||
623 | 646 | { |
624 | 647 | $type = $matches[1]; |
625 | 648 | $size = $matches[2]; |
626 | - if (!empty($matches[3]) && $matches[3] == 'unsigned') |
|
627 | - $unsigned = true; |
|
628 | - } |
|
629 | - else |
|
649 | + if (!empty($matches[3]) && $matches[3] == 'unsigned') { |
|
650 | + $unsigned = true; |
|
651 | + } |
|
652 | + } else |
|
630 | 653 | { |
631 | 654 | $type = $row['Type']; |
632 | 655 | $size = null; |
@@ -677,19 +700,20 @@ discard block |
||
677 | 700 | $indexes = array(); |
678 | 701 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
679 | 702 | { |
680 | - if (!$detail) |
|
681 | - $indexes[] = $row['Key_name']; |
|
682 | - else |
|
703 | + if (!$detail) { |
|
704 | + $indexes[] = $row['Key_name']; |
|
705 | + } else |
|
683 | 706 | { |
684 | 707 | // What is the type? |
685 | - if ($row['Key_name'] == 'PRIMARY') |
|
686 | - $type = 'primary'; |
|
687 | - elseif (empty($row['Non_unique'])) |
|
688 | - $type = 'unique'; |
|
689 | - elseif (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT') |
|
690 | - $type = 'fulltext'; |
|
691 | - else |
|
692 | - $type = 'index'; |
|
708 | + if ($row['Key_name'] == 'PRIMARY') { |
|
709 | + $type = 'primary'; |
|
710 | + } elseif (empty($row['Non_unique'])) { |
|
711 | + $type = 'unique'; |
|
712 | + } elseif (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT') { |
|
713 | + $type = 'fulltext'; |
|
714 | + } else { |
|
715 | + $type = 'index'; |
|
716 | + } |
|
693 | 717 | |
694 | 718 | // This is the first column we've seen? |
695 | 719 | if (empty($indexes[$row['Key_name']])) |
@@ -702,10 +726,11 @@ discard block |
||
702 | 726 | } |
703 | 727 | |
704 | 728 | // Is it a partial index? |
705 | - if (!empty($row['Sub_part'])) |
|
706 | - $indexes[$row['Key_name']]['columns'][] = $row['Column_name'] . '(' . $row['Sub_part'] . ')'; |
|
707 | - else |
|
708 | - $indexes[$row['Key_name']]['columns'][] = $row['Column_name']; |
|
729 | + if (!empty($row['Sub_part'])) { |
|
730 | + $indexes[$row['Key_name']]['columns'][] = $row['Column_name'] . '(' . $row['Sub_part'] . ')'; |
|
731 | + } else { |
|
732 | + $indexes[$row['Key_name']]['columns'][] = $row['Column_name']; |
|
733 | + } |
|
709 | 734 | } |
710 | 735 | } |
711 | 736 | $smcFunc['db_free_result']($result); |
@@ -727,11 +752,11 @@ discard block |
||
727 | 752 | if (!empty($column['auto'])) |
728 | 753 | { |
729 | 754 | $default = 'auto_increment'; |
755 | + } elseif (isset($column['default']) && $column['default'] !== null) { |
|
756 | + $default = 'default \'' . $smcFunc['db_escape_string']($column['default']) . '\''; |
|
757 | + } else { |
|
758 | + $default = ''; |
|
730 | 759 | } |
731 | - elseif (isset($column['default']) && $column['default'] !== null) |
|
732 | - $default = 'default \'' . $smcFunc['db_escape_string']($column['default']) . '\''; |
|
733 | - else |
|
734 | - $default = ''; |
|
735 | 760 | |
736 | 761 | // Sort out the size... and stuff... |
737 | 762 | $column['size'] = isset($column['size']) && is_numeric($column['size']) ? $column['size'] : null; |
@@ -740,8 +765,9 @@ discard block |
||
740 | 765 | // Allow unsigned integers (mysql only) |
741 | 766 | $unsigned = in_array($type, array('int', 'tinyint', 'smallint', 'mediumint', 'bigint')) && !empty($column['unsigned']) ? 'unsigned ' : ''; |
742 | 767 | |
743 | - if ($size !== null) |
|
744 | - $type = $type . '(' . $size . ')'; |
|
768 | + if ($size !== null) { |
|
769 | + $type = $type . '(' . $size . ')'; |
|
770 | + } |
|
745 | 771 | |
746 | 772 | // Now just put it together! |
747 | 773 | return '`' .$column['name'] . '` ' . $type . ' ' . (!empty($unsigned) ? $unsigned : '') . (!empty($column['null']) ? '' : 'NOT NULL') . ' ' . $default; |
@@ -518,7 +518,7 @@ |
||
518 | 518 | * @param array $parameters Not used? |
519 | 519 | * @param string $if_exists What to do if the index exists. If 'update', the definition will be updated. |
520 | 520 | * @param string $error |
521 | - * @return boolean Whether or not the operation was successful |
|
521 | + * @return false|null Whether or not the operation was successful |
|
522 | 522 | */ |
523 | 523 | function smf_db_add_index($table_name, $index_info, $parameters = array(), $if_exists = 'update', $error = 'fatal') |
524 | 524 | { |
@@ -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 | * Add the file functions to the $smcFunc array. |
@@ -52,8 +53,9 @@ discard block |
||
52 | 53 | 'messages', 'moderators', 'package_servers', 'permission_profiles', 'permissions', 'personal_messages', |
53 | 54 | 'pm_recipients', 'poll_choices', 'polls', 'scheduled_tasks', 'sessions', 'settings', 'smileys', |
54 | 55 | 'themes', 'topics'); |
55 | - foreach ($reservedTables as $k => $table_name) |
|
56 | - $reservedTables[$k] = strtolower($db_prefix . $table_name); |
|
56 | + foreach ($reservedTables as $k => $table_name) { |
|
57 | + $reservedTables[$k] = strtolower($db_prefix . $table_name); |
|
58 | + } |
|
57 | 59 | |
58 | 60 | // We in turn may need the extra stuff. |
59 | 61 | db_extend('extra'); |
@@ -102,8 +104,9 @@ discard block |
||
102 | 104 | $table_name = str_replace('{db_prefix}', $db_prefix, $table_name); |
103 | 105 | |
104 | 106 | // First - no way do we touch SMF tables. |
105 | - if (in_array(strtolower($table_name), $reservedTables)) |
|
106 | - return false; |
|
107 | + if (in_array(strtolower($table_name), $reservedTables)) { |
|
108 | + return false; |
|
109 | + } |
|
107 | 110 | |
108 | 111 | // Log that we'll want to remove this on uninstall. |
109 | 112 | $db_package_log[] = array('remove_table', $table_name); |
@@ -113,10 +116,11 @@ discard block |
||
113 | 116 | if (in_array($full_table_name, $tables)) |
114 | 117 | { |
115 | 118 | // This is a sad day... drop the table? If not, return false (error) by default. |
116 | - if ($if_exists == 'overwrite') |
|
117 | - $smcFunc['db_drop_table']($table_name); |
|
118 | - else |
|
119 | - return $if_exists == 'ignore'; |
|
119 | + if ($if_exists == 'overwrite') { |
|
120 | + $smcFunc['db_drop_table']($table_name); |
|
121 | + } else { |
|
122 | + return $if_exists == 'ignore'; |
|
123 | + } |
|
120 | 124 | } |
121 | 125 | |
122 | 126 | // If we've got this far - good news - no table exists. We can build our own! |
@@ -134,17 +138,18 @@ discard block |
||
134 | 138 | ) |
135 | 139 | ); |
136 | 140 | $default = 'default nextval(\'' . $table_name . '_seq\')'; |
141 | + } elseif (isset($column['default']) && $column['default'] !== null) { |
|
142 | + $default = 'default \'' . $smcFunc['db_escape_string']($column['default']) . '\''; |
|
143 | + } else { |
|
144 | + $default = ''; |
|
137 | 145 | } |
138 | - elseif (isset($column['default']) && $column['default'] !== null) |
|
139 | - $default = 'default \'' . $smcFunc['db_escape_string']($column['default']) . '\''; |
|
140 | - else |
|
141 | - $default = ''; |
|
142 | 146 | |
143 | 147 | // Sort out the size... |
144 | 148 | $column['size'] = isset($column['size']) && is_numeric($column['size']) ? $column['size'] : null; |
145 | 149 | list ($type, $size) = $smcFunc['db_calculate_type']($column['type'], $column['size']); |
146 | - if ($size !== null) |
|
147 | - $type = $type . '(' . $size . ')'; |
|
150 | + if ($size !== null) { |
|
151 | + $type = $type . '(' . $size . ')'; |
|
152 | + } |
|
148 | 153 | |
149 | 154 | // Now just put it together! |
150 | 155 | $table_query .= "\n\t\"" . $column['name'] . '" ' . $type . ' ' . (!empty($column['null']) ? '' : 'NOT NULL') . ' ' . $default . ','; |
@@ -157,19 +162,21 @@ discard block |
||
157 | 162 | $columns = implode(',', $index['columns']); |
158 | 163 | |
159 | 164 | // Primary goes in the table... |
160 | - if (isset($index['type']) && $index['type'] == 'primary') |
|
161 | - $table_query .= "\n\t" . 'PRIMARY KEY (' . implode(',', $index['columns']) . '),'; |
|
162 | - else |
|
165 | + if (isset($index['type']) && $index['type'] == 'primary') { |
|
166 | + $table_query .= "\n\t" . 'PRIMARY KEY (' . implode(',', $index['columns']) . '),'; |
|
167 | + } else |
|
163 | 168 | { |
164 | - if (empty($index['name'])) |
|
165 | - $index['name'] = implode('_', $index['columns']); |
|
169 | + if (empty($index['name'])) { |
|
170 | + $index['name'] = implode('_', $index['columns']); |
|
171 | + } |
|
166 | 172 | $index_queries[] = 'CREATE ' . (isset($index['type']) && $index['type'] == 'unique' ? 'UNIQUE' : '') . ' INDEX ' . $table_name . '_' . $index['name'] . ' ON ' . $table_name . ' (' . $columns . ')'; |
167 | 173 | } |
168 | 174 | } |
169 | 175 | |
170 | 176 | // No trailing commas! |
171 | - if (substr($table_query, -1) == ',') |
|
172 | - $table_query = substr($table_query, 0, -1); |
|
177 | + if (substr($table_query, -1) == ',') { |
|
178 | + $table_query = substr($table_query, 0, -1); |
|
179 | + } |
|
173 | 180 | |
174 | 181 | $table_query .= ')'; |
175 | 182 | |
@@ -180,12 +187,13 @@ discard block |
||
180 | 187 | ) |
181 | 188 | ); |
182 | 189 | // And the indexes... |
183 | - foreach ($index_queries as $query) |
|
184 | - $smcFunc['db_query']('', $query, |
|
190 | + foreach ($index_queries as $query) { |
|
191 | + $smcFunc['db_query']('', $query, |
|
185 | 192 | array( |
186 | 193 | 'security_override' => true, |
187 | 194 | ) |
188 | 195 | ); |
196 | + } |
|
189 | 197 | |
190 | 198 | // Go, go power rangers! |
191 | 199 | $smcFunc['db_transaction']('commit'); |
@@ -213,8 +221,9 @@ discard block |
||
213 | 221 | $table_name = str_replace('{db_prefix}', $db_prefix, $table_name); |
214 | 222 | |
215 | 223 | // God no - dropping one of these = bad. |
216 | - if (in_array(strtolower($table_name), $reservedTables)) |
|
217 | - return false; |
|
224 | + if (in_array(strtolower($table_name), $reservedTables)) { |
|
225 | + return false; |
|
226 | + } |
|
218 | 227 | |
219 | 228 | // Does it exist? |
220 | 229 | if (in_array($full_table_name, $smcFunc['db_list_tables']())) |
@@ -272,21 +281,24 @@ discard block |
||
272 | 281 | |
273 | 282 | // Does it exist - if so don't add it again! |
274 | 283 | $columns = $smcFunc['db_list_columns']($table_name, false); |
275 | - foreach ($columns as $column) |
|
276 | - if ($column == $column_info['name']) |
|
284 | + foreach ($columns as $column) { |
|
285 | + if ($column == $column_info['name']) |
|
277 | 286 | { |
278 | 287 | // If we're going to overwrite then use change column. |
279 | 288 | if ($if_exists == 'update') |
280 | 289 | return $smcFunc['db_change_column']($table_name, $column_info['name'], $column_info); |
281 | - else |
|
282 | - return false; |
|
290 | + } |
|
291 | + else { |
|
292 | + return false; |
|
293 | + } |
|
283 | 294 | } |
284 | 295 | |
285 | 296 | // Get the specifics... |
286 | 297 | $column_info['size'] = isset($column_info['size']) && is_numeric($column_info['size']) ? $column_info['size'] : null; |
287 | 298 | list ($type, $size) = $smcFunc['db_calculate_type']($column_info['type'], $column_info['size']); |
288 | - if ($size !== null) |
|
289 | - $type = $type . '(' . $size . ')'; |
|
299 | + if ($size !== null) { |
|
300 | + $type = $type . '(' . $size . ')'; |
|
301 | + } |
|
290 | 302 | |
291 | 303 | // Now add the thing! |
292 | 304 | $query = ' |
@@ -301,11 +313,12 @@ discard block |
||
301 | 313 | // If there's more attributes they need to be done via a change on PostgreSQL. |
302 | 314 | unset($column_info['type'], $column_info['size']); |
303 | 315 | |
304 | - if (count($column_info) != 1) |
|
305 | - return $smcFunc['db_change_column']($table_name, $column_info['name'], $column_info); |
|
306 | - else |
|
307 | - return true; |
|
308 | -} |
|
316 | + if (count($column_info) != 1) { |
|
317 | + return $smcFunc['db_change_column']($table_name, $column_info['name'], $column_info); |
|
318 | + } else { |
|
319 | + return true; |
|
320 | + } |
|
321 | + } |
|
309 | 322 | |
310 | 323 | /** |
311 | 324 | * Removes a column. |
@@ -324,8 +337,8 @@ discard block |
||
324 | 337 | |
325 | 338 | // Does it exist? |
326 | 339 | $columns = $smcFunc['db_list_columns']($table_name, true); |
327 | - foreach ($columns as $column) |
|
328 | - if ($column['name'] == $column_name) |
|
340 | + foreach ($columns as $column) { |
|
341 | + if ($column['name'] == $column_name) |
|
329 | 342 | { |
330 | 343 | // If there is an auto we need remove it! |
331 | 344 | if ($column['auto']) |
@@ -335,6 +348,7 @@ discard block |
||
335 | 348 | 'security_override' => true, |
336 | 349 | ) |
337 | 350 | ); |
351 | + } |
|
338 | 352 | |
339 | 353 | $smcFunc['db_query']('', ' |
340 | 354 | ALTER TABLE ' . $table_name . ' |
@@ -369,13 +383,15 @@ discard block |
||
369 | 383 | // Check it does exist! |
370 | 384 | $columns = $smcFunc['db_list_columns']($table_name, true); |
371 | 385 | $old_info = null; |
372 | - foreach ($columns as $column) |
|
373 | - if ($column['name'] == $old_column) |
|
386 | + foreach ($columns as $column) { |
|
387 | + if ($column['name'] == $old_column) |
|
374 | 388 | $old_info = $column; |
389 | + } |
|
375 | 390 | |
376 | 391 | // Nothing? |
377 | - if ($old_info == null) |
|
378 | - return false; |
|
392 | + if ($old_info == null) { |
|
393 | + return false; |
|
394 | + } |
|
379 | 395 | |
380 | 396 | // Now we check each bit individually and ALTER as required. |
381 | 397 | if (isset($column_info['name']) && $column_info['name'] != $old_column) |
@@ -432,8 +448,9 @@ discard block |
||
432 | 448 | { |
433 | 449 | $column_info['size'] = isset($column_info['size']) && is_numeric($column_info['size']) ? $column_info['size'] : null; |
434 | 450 | list ($type, $size) = $smcFunc['db_calculate_type']($column_info['type'], $column_info['size']); |
435 | - if ($size !== null) |
|
436 | - $type = $type . '(' . $size . ')'; |
|
451 | + if ($size !== null) { |
|
452 | + $type = $type . '(' . $size . ')'; |
|
453 | + } |
|
437 | 454 | |
438 | 455 | // The alter is a pain. |
439 | 456 | $smcFunc['db_transaction']('begin'); |
@@ -527,21 +544,23 @@ discard block |
||
527 | 544 | $table_name = str_replace('{db_prefix}', $db_prefix, $table_name); |
528 | 545 | |
529 | 546 | // No columns = no index. |
530 | - if (empty($index_info['columns'])) |
|
531 | - return false; |
|
547 | + if (empty($index_info['columns'])) { |
|
548 | + return false; |
|
549 | + } |
|
532 | 550 | $columns = implode(',', $index_info['columns']); |
533 | 551 | |
534 | 552 | // No name - make it up! |
535 | 553 | if (empty($index_info['name'])) |
536 | 554 | { |
537 | 555 | // No need for primary. |
538 | - if (isset($index_info['type']) && $index_info['type'] == 'primary') |
|
539 | - $index_info['name'] = ''; |
|
540 | - else |
|
541 | - $index_info['name'] = $table_name . implode('_', $index_info['columns']); |
|
556 | + if (isset($index_info['type']) && $index_info['type'] == 'primary') { |
|
557 | + $index_info['name'] = ''; |
|
558 | + } else { |
|
559 | + $index_info['name'] = $table_name . implode('_', $index_info['columns']); |
|
560 | + } |
|
561 | + } else { |
|
562 | + $index_info['name'] = $table_name . $index_info['name']; |
|
542 | 563 | } |
543 | - else |
|
544 | - $index_info['name'] = $table_name . $index_info['name']; |
|
545 | 564 | |
546 | 565 | // Log that we are going to want to remove this! |
547 | 566 | $db_package_log[] = array('remove_index', $table_name, $index_info['name']); |
@@ -554,10 +573,11 @@ discard block |
||
554 | 573 | if ($index['name'] == $index_info['name'] || ($index['type'] == 'primary' && isset($index_info['type']) && $index_info['type'] == 'primary')) |
555 | 574 | { |
556 | 575 | // If we want to overwrite simply remove the current one then continue. |
557 | - if ($if_exists != 'update' || $index['type'] == 'primary') |
|
558 | - return false; |
|
559 | - else |
|
560 | - $smcFunc['db_remove_index']($table_name, $index_info['name']); |
|
576 | + if ($if_exists != 'update' || $index['type'] == 'primary') { |
|
577 | + return false; |
|
578 | + } else { |
|
579 | + $smcFunc['db_remove_index']($table_name, $index_info['name']); |
|
580 | + } |
|
561 | 581 | } |
562 | 582 | } |
563 | 583 | |
@@ -571,8 +591,7 @@ discard block |
||
571 | 591 | 'security_override' => true, |
572 | 592 | ) |
573 | 593 | ); |
574 | - } |
|
575 | - else |
|
594 | + } else |
|
576 | 595 | { |
577 | 596 | $smcFunc['db_query']('', ' |
578 | 597 | CREATE ' . (isset($index_info['type']) && $index_info['type'] == 'unique' ? 'UNIQUE' : '') . ' INDEX ' . $index_info['name'] . ' ON ' . $table_name . ' (' . $columns . ')', |
@@ -600,8 +619,9 @@ discard block |
||
600 | 619 | |
601 | 620 | // Better exist! |
602 | 621 | $indexes = $smcFunc['db_list_indexes']($table_name, true); |
603 | - if ($index_name != 'primary') |
|
604 | - $index_name = $table_name . '_' . $index_name; |
|
622 | + if ($index_name != 'primary') { |
|
623 | + $index_name = $table_name . '_' . $index_name; |
|
624 | + } |
|
605 | 625 | |
606 | 626 | foreach ($indexes as $index) |
607 | 627 | { |
@@ -665,8 +685,7 @@ discard block |
||
665 | 685 | 'datetime' => 'timestamp without time zone', |
666 | 686 | 'timestamp' => 'timestamp without time zone', |
667 | 687 | ); |
668 | - } |
|
669 | - else |
|
688 | + } else |
|
670 | 689 | { |
671 | 690 | $types = array( |
672 | 691 | 'character varying' => 'varchar', |
@@ -682,14 +701,16 @@ discard block |
||
682 | 701 | // Got it? Change it! |
683 | 702 | if (isset($types[$type_name])) |
684 | 703 | { |
685 | - if ($type_name == 'tinytext') |
|
686 | - $type_size = 255; |
|
704 | + if ($type_name == 'tinytext') { |
|
705 | + $type_size = 255; |
|
706 | + } |
|
687 | 707 | $type_name = $types[$type_name]; |
688 | 708 | } |
689 | 709 | |
690 | 710 | // Only char fields got size |
691 | - if (strpos($type_name, 'char') === false) |
|
692 | - $type_size = null; |
|
711 | + if (strpos($type_name, 'char') === false) { |
|
712 | + $type_size = null; |
|
713 | + } |
|
693 | 714 | |
694 | 715 | |
695 | 716 | return array($type_name, $type_size); |
@@ -744,8 +765,7 @@ discard block |
||
744 | 765 | if (!$detail) |
745 | 766 | { |
746 | 767 | $columns[] = $row['column_name']; |
747 | - } |
|
748 | - else |
|
768 | + } else |
|
749 | 769 | { |
750 | 770 | $auto = false; |
751 | 771 | // What is the default? |
@@ -753,11 +773,11 @@ discard block |
||
753 | 773 | { |
754 | 774 | $default = null; |
755 | 775 | $auto = true; |
776 | + } elseif (trim($row['column_default']) != '') { |
|
777 | + $default = strpos($row['column_default'], '::') === false ? $row['column_default'] : substr($row['column_default'], 0, strpos($row['column_default'], '::')); |
|
778 | + } else { |
|
779 | + $default = null; |
|
756 | 780 | } |
757 | - elseif (trim($row['column_default']) != '') |
|
758 | - $default = strpos($row['column_default'], '::') === false ? $row['column_default'] : substr($row['column_default'], 0, strpos($row['column_default'], '::')); |
|
759 | - else |
|
760 | - $default = null; |
|
761 | 781 | |
762 | 782 | // Make the type generic. |
763 | 783 | list ($type, $size) = $smcFunc['db_calculate_type']($row['data_type'], $row['character_maximum_length'], true); |
@@ -808,26 +828,30 @@ discard block |
||
808 | 828 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
809 | 829 | { |
810 | 830 | // Try get the columns that make it up. |
811 | - if (preg_match('~\(([^\)]+?)\)~i', $row['inddef'], $matches) == 0) |
|
812 | - continue; |
|
831 | + if (preg_match('~\(([^\)]+?)\)~i', $row['inddef'], $matches) == 0) { |
|
832 | + continue; |
|
833 | + } |
|
813 | 834 | |
814 | 835 | $columns = explode(',', $matches[1]); |
815 | 836 | |
816 | - if (empty($columns)) |
|
817 | - continue; |
|
837 | + if (empty($columns)) { |
|
838 | + continue; |
|
839 | + } |
|
818 | 840 | |
819 | - foreach ($columns as $k => $v) |
|
820 | - $columns[$k] = trim($v); |
|
841 | + foreach ($columns as $k => $v) { |
|
842 | + $columns[$k] = trim($v); |
|
843 | + } |
|
821 | 844 | |
822 | 845 | // Fix up the name to be consistent cross databases |
823 | - if (substr($row['name'], -5) == '_pkey' && $row['is_primary'] == 1) |
|
824 | - $row['name'] = 'PRIMARY'; |
|
825 | - else |
|
826 | - $row['name'] = str_replace($table_name . '_', '', $row['name']); |
|
846 | + if (substr($row['name'], -5) == '_pkey' && $row['is_primary'] == 1) { |
|
847 | + $row['name'] = 'PRIMARY'; |
|
848 | + } else { |
|
849 | + $row['name'] = str_replace($table_name . '_', '', $row['name']); |
|
850 | + } |
|
827 | 851 | |
828 | - if (!$detail) |
|
829 | - $indexes[] = $row['name']; |
|
830 | - else |
|
852 | + if (!$detail) { |
|
853 | + $indexes[] = $row['name']; |
|
854 | + } else |
|
831 | 855 | { |
832 | 856 | $indexes[$row['name']] = array( |
833 | 857 | 'name' => $row['name'], |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | * |
176 | 176 | * @param string $post_errors A string of info about errors encountered trying to save this draft |
177 | 177 | * @param array $recipientList An array of data about who this PM is being sent to |
178 | - * @return boolean false if you can't save the draft, true if we're doing this via XML more than 5 seconds after the last save, nothing otherwise |
|
178 | + * @return boolean|null false if you can't save the draft, true if we're doing this via XML more than 5 seconds after the last save, nothing otherwise |
|
179 | 179 | */ |
180 | 180 | function SavePMDraft(&$post_errors, $recipientList) |
181 | 181 | { |
@@ -392,7 +392,7 @@ discard block |
||
392 | 392 | * |
393 | 393 | * @param int $id_draft The ID of the draft to delete |
394 | 394 | * @param boolean $check Whether or not to check that the draft belongs to the current user |
395 | - * @return boolean False if it couldn't be deleted (doesn't return anything otherwise) |
|
395 | + * @return false|null False if it couldn't be deleted (doesn't return anything otherwise) |
|
396 | 396 | */ |
397 | 397 | function DeleteDraft($id_draft, $check = true) |
398 | 398 | { |
@@ -426,7 +426,7 @@ discard block |
||
426 | 426 | * @param int $member_id ID of the member to show drafts for |
427 | 427 | * @param boolean|integer If $type is 1, this can be set to only load drafts for posts in the specific topic |
428 | 428 | * @param int $draft_type The type of drafts to show - 0 for post drafts, 1 for PM drafts |
429 | - * @return boolean False if the drafts couldn't be loaded, nothing otherwise |
|
429 | + * @return false|null False if the drafts couldn't be loaded, nothing otherwise |
|
430 | 430 | */ |
431 | 431 | function ShowDrafts($member_id, $topic = false, $draft_type = 0) |
432 | 432 | { |
@@ -510,7 +510,7 @@ discard block |
||
510 | 510 | * Allows for the deleting and loading/editing of drafts |
511 | 511 | * |
512 | 512 | * @param type $memID |
513 | - * @param type $draft_type |
|
513 | + * @param integer $draft_type |
|
514 | 514 | */ |
515 | 515 | function showProfileDrafts($memID, $draft_type = 0) |
516 | 516 | { |
@@ -663,7 +663,7 @@ discard block |
||
663 | 663 | * Uses the showpmdraft template |
664 | 664 | * Allows for the deleting and loading/editing of drafts |
665 | 665 | * |
666 | - * @param type $memID |
|
666 | + * @param integer $memID |
|
667 | 667 | */ |
668 | 668 | function showPMDrafts($memID = -1) |
669 | 669 | { |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | locked = {int:locked}, |
86 | 86 | is_sticky = {int:is_sticky} |
87 | 87 | WHERE id_draft = {int:id_draft}', |
88 | - array ( |
|
88 | + array( |
|
89 | 89 | 'id_topic' => $topic_id, |
90 | 90 | 'id_board' => $board, |
91 | 91 | 'poster_time' => time(), |
@@ -410,7 +410,7 @@ discard block |
||
410 | 410 | DELETE FROM {db_prefix}user_drafts |
411 | 411 | WHERE id_draft IN ({array_int:id_draft})' . ($check ? ' |
412 | 412 | AND id_member = {int:id_member}' : ''), |
413 | - array ( |
|
413 | + array( |
|
414 | 414 | 'id_draft' => $id_draft, |
415 | 415 | 'id_member' => empty($user_info['id']) ? -1 : $user_info['id'], |
416 | 416 | ) |
@@ -471,7 +471,7 @@ discard block |
||
471 | 471 | $context['drafts'][] = array( |
472 | 472 | 'subject' => censorText(shorten_subject(stripslashes($row['subject']), 24)), |
473 | 473 | 'poster_time' => timeformat($row['poster_time']), |
474 | - 'link' => '<a href="' . $scripturl . '?action=post;board=' . $row['id_board'] . ';' . (!empty($row['id_topic']) ? 'topic='. $row['id_topic'] .'.0;' : '') . 'id_draft=' . $row['id_draft'] . '">' . $row['subject'] . '</a>', |
|
474 | + 'link' => '<a href="' . $scripturl . '?action=post;board=' . $row['id_board'] . ';' . (!empty($row['id_topic']) ? 'topic=' . $row['id_topic'] . '.0;' : '') . 'id_draft=' . $row['id_draft'] . '">' . $row['subject'] . '</a>', |
|
475 | 475 | ); |
476 | 476 | // PM drafts |
477 | 477 | elseif ($draft_type === 1) |
@@ -14,8 +14,9 @@ discard block |
||
14 | 14 | * @version 2.1 Beta 3 |
15 | 15 | */ |
16 | 16 | |
17 | -if (!defined('SMF')) |
|
17 | +if (!defined('SMF')) { |
|
18 | 18 | die('No direct access...'); |
19 | +} |
|
19 | 20 | |
20 | 21 | loadLanguage('Drafts'); |
21 | 22 | |
@@ -33,8 +34,9 @@ discard block |
||
33 | 34 | global $context, $user_info, $smcFunc, $modSettings, $board; |
34 | 35 | |
35 | 36 | // can you be, should you be ... here? |
36 | - if (empty($modSettings['drafts_post_enabled']) || !allowedTo('post_draft') || !isset($_POST['save_draft']) || !isset($_POST['id_draft'])) |
|
37 | - return false; |
|
37 | + if (empty($modSettings['drafts_post_enabled']) || !allowedTo('post_draft') || !isset($_POST['save_draft']) || !isset($_POST['id_draft'])) { |
|
38 | + return false; |
|
39 | + } |
|
38 | 40 | |
39 | 41 | // read in what they sent us, if anything |
40 | 42 | $id_draft = (int) $_POST['id_draft']; |
@@ -46,14 +48,16 @@ discard block |
||
46 | 48 | $context['draft_saved_on'] = $draft_info['poster_time']; |
47 | 49 | |
48 | 50 | // since we were called from the autosave function, send something back |
49 | - if (!empty($id_draft)) |
|
50 | - XmlDraft($id_draft); |
|
51 | + if (!empty($id_draft)) { |
|
52 | + XmlDraft($id_draft); |
|
53 | + } |
|
51 | 54 | |
52 | 55 | return true; |
53 | 56 | } |
54 | 57 | |
55 | - if (!isset($_POST['message'])) |
|
56 | - $_POST['message'] = isset($_POST['quickReply']) ? $_POST['quickReply'] : ''; |
|
58 | + if (!isset($_POST['message'])) { |
|
59 | + $_POST['message'] = isset($_POST['quickReply']) ? $_POST['quickReply'] : ''; |
|
60 | + } |
|
57 | 61 | |
58 | 62 | // prepare any data from the form |
59 | 63 | $topic_id = empty($_REQUEST['topic']) ? 0 : (int) $_REQUEST['topic']; |
@@ -66,8 +70,9 @@ discard block |
||
66 | 70 | |
67 | 71 | // message and subject still need a bit more work |
68 | 72 | preparsecode($draft['body']); |
69 | - if ($smcFunc['strlen']($draft['subject']) > 100) |
|
70 | - $draft['subject'] = $smcFunc['substr']($draft['subject'], 0, 100); |
|
73 | + if ($smcFunc['strlen']($draft['subject']) > 100) { |
|
74 | + $draft['subject'] = $smcFunc['substr']($draft['subject'], 0, 100); |
|
75 | + } |
|
71 | 76 | |
72 | 77 | // Modifying an existing draft, like hitting the save draft button or autosave enabled? |
73 | 78 | if (!empty($id_draft) && !empty($draft_info) && $draft_info['id_member'] == $user_info['id']) |
@@ -150,9 +155,9 @@ discard block |
||
150 | 155 | { |
151 | 156 | $context['draft_saved'] = true; |
152 | 157 | $context['id_draft'] = $id_draft; |
158 | + } else { |
|
159 | + $post_errors[] = 'draft_not_saved'; |
|
153 | 160 | } |
154 | - else |
|
155 | - $post_errors[] = 'draft_not_saved'; |
|
156 | 161 | |
157 | 162 | // cleanup |
158 | 163 | unset($_POST['save_draft']); |
@@ -182,8 +187,9 @@ discard block |
||
182 | 187 | global $context, $user_info, $smcFunc, $modSettings; |
183 | 188 | |
184 | 189 | // PM survey says ... can you stay or must you go |
185 | - if (empty($modSettings['drafts_pm_enabled']) || !allowedTo('pm_draft') || !isset($_POST['save_draft'])) |
|
186 | - return false; |
|
190 | + if (empty($modSettings['drafts_pm_enabled']) || !allowedTo('pm_draft') || !isset($_POST['save_draft'])) { |
|
191 | + return false; |
|
192 | + } |
|
187 | 193 | |
188 | 194 | // read in what you sent us |
189 | 195 | $id_pm_draft = (int) $_POST['id_pm_draft']; |
@@ -195,8 +201,9 @@ discard block |
||
195 | 201 | $context['draft_saved_on'] = $draft_info['poster_time']; |
196 | 202 | |
197 | 203 | // Send something back to the javascript caller |
198 | - if (!empty($id_draft)) |
|
199 | - XmlDraft($id_draft); |
|
204 | + if (!empty($id_draft)) { |
|
205 | + XmlDraft($id_draft); |
|
206 | + } |
|
200 | 207 | |
201 | 208 | return true; |
202 | 209 | } |
@@ -206,9 +213,9 @@ discard block |
||
206 | 213 | { |
207 | 214 | $recipientList['to'] = isset($_POST['recipient_to']) ? explode(',', $_POST['recipient_to']) : array(); |
208 | 215 | $recipientList['bcc'] = isset($_POST['recipient_bcc']) ? explode(',', $_POST['recipient_bcc']) : array(); |
216 | + } elseif (!empty($draft_info['to_list']) && empty($recipientList)) { |
|
217 | + $recipientList = smf_json_decode($draft_info['to_list'], true); |
|
209 | 218 | } |
210 | - elseif (!empty($draft_info['to_list']) && empty($recipientList)) |
|
211 | - $recipientList = smf_json_decode($draft_info['to_list'], true); |
|
212 | 219 | |
213 | 220 | // prepare the data we got from the form |
214 | 221 | $reply_id = empty($_POST['replied_to']) ? 0 : (int) $_POST['replied_to']; |
@@ -217,8 +224,9 @@ discard block |
||
217 | 224 | |
218 | 225 | // message and subject always need a bit more work |
219 | 226 | preparsecode($draft['body']); |
220 | - if ($smcFunc['strlen']($draft['subject']) > 100) |
|
221 | - $draft['subject'] = $smcFunc['substr']($draft['subject'], 0, 100); |
|
227 | + if ($smcFunc['strlen']($draft['subject']) > 100) { |
|
228 | + $draft['subject'] = $smcFunc['substr']($draft['subject'], 0, 100); |
|
229 | + } |
|
222 | 230 | |
223 | 231 | // Modifying an existing PM draft? |
224 | 232 | if (!empty($id_pm_draft) && !empty($draft_info) && $draft_info['id_member'] == $user_info['id']) |
@@ -284,9 +292,9 @@ discard block |
||
284 | 292 | { |
285 | 293 | $context['draft_saved'] = true; |
286 | 294 | $context['id_pm_draft'] = $id_pm_draft; |
295 | + } else { |
|
296 | + $post_errors[] = 'draft_not_saved'; |
|
287 | 297 | } |
288 | - else |
|
289 | - $post_errors[] = 'draft_not_saved'; |
|
290 | 298 | } |
291 | 299 | |
292 | 300 | // if we were called from the autosave function, send something back |
@@ -319,8 +327,9 @@ discard block |
||
319 | 327 | $type = (int) $type; |
320 | 328 | |
321 | 329 | // nothing to read, nothing to do |
322 | - if (empty($id_draft)) |
|
323 | - return false; |
|
330 | + if (empty($id_draft)) { |
|
331 | + return false; |
|
332 | + } |
|
324 | 333 | |
325 | 334 | // load in this draft from the DB |
326 | 335 | $request = $smcFunc['db_query']('', ' |
@@ -340,8 +349,9 @@ discard block |
||
340 | 349 | ); |
341 | 350 | |
342 | 351 | // no results? |
343 | - if (!$smcFunc['db_num_rows']($request)) |
|
344 | - return false; |
|
352 | + if (!$smcFunc['db_num_rows']($request)) { |
|
353 | + return false; |
|
354 | + } |
|
345 | 355 | |
346 | 356 | // load up the data |
347 | 357 | $draft_info = $smcFunc['db_fetch_assoc']($request); |
@@ -362,8 +372,7 @@ discard block |
||
362 | 372 | $context['subject'] = !empty($draft_info['subject']) ? stripslashes($draft_info['subject']) : ''; |
363 | 373 | $context['board'] = !empty($draft_info['board_id']) ? $draft_info['id_board'] : ''; |
364 | 374 | $context['id_draft'] = !empty($draft_info['id_draft']) ? $draft_info['id_draft'] : 0; |
365 | - } |
|
366 | - elseif ($type === 1) |
|
375 | + } elseif ($type === 1) |
|
367 | 376 | { |
368 | 377 | // one of those pm drafts? then set it up like we have an error |
369 | 378 | $_REQUEST['subject'] = !empty($draft_info['subject']) ? stripslashes($draft_info['subject']) : ''; |
@@ -399,12 +408,14 @@ discard block |
||
399 | 408 | global $user_info, $smcFunc; |
400 | 409 | |
401 | 410 | // Only a single draft. |
402 | - if (is_numeric($id_draft)) |
|
403 | - $id_draft = array($id_draft); |
|
411 | + if (is_numeric($id_draft)) { |
|
412 | + $id_draft = array($id_draft); |
|
413 | + } |
|
404 | 414 | |
405 | 415 | // can't delete nothing |
406 | - if (empty($id_draft) || ($check && empty($user_info['id']))) |
|
407 | - return false; |
|
416 | + if (empty($id_draft) || ($check && empty($user_info['id']))) { |
|
417 | + return false; |
|
418 | + } |
|
408 | 419 | |
409 | 420 | $smcFunc['db_query']('', ' |
410 | 421 | DELETE FROM {db_prefix}user_drafts |
@@ -433,14 +444,16 @@ discard block |
||
433 | 444 | global $smcFunc, $scripturl, $context, $txt, $modSettings; |
434 | 445 | |
435 | 446 | // Permissions |
436 | - if (($draft_type === 0 && empty($context['drafts_save'])) || ($draft_type === 1 && empty($context['drafts_pm_save'])) || empty($member_id)) |
|
437 | - return false; |
|
447 | + if (($draft_type === 0 && empty($context['drafts_save'])) || ($draft_type === 1 && empty($context['drafts_pm_save'])) || empty($member_id)) { |
|
448 | + return false; |
|
449 | + } |
|
438 | 450 | |
439 | 451 | $context['drafts'] = array(); |
440 | 452 | |
441 | 453 | // has a specific draft has been selected? Load it up if there is not a message already in the editor |
442 | - if (isset($_REQUEST['id_draft']) && empty($_POST['subject']) && empty($_POST['message'])) |
|
443 | - ReadDraft((int) $_REQUEST['id_draft'], $draft_type, true, true); |
|
454 | + if (isset($_REQUEST['id_draft']) && empty($_POST['subject']) && empty($_POST['message'])) { |
|
455 | + ReadDraft((int) $_REQUEST['id_draft'], $draft_type, true, true); |
|
456 | + } |
|
444 | 457 | |
445 | 458 | // load the drafts this user has available |
446 | 459 | $request = $smcFunc['db_query']('', ' |
@@ -463,23 +476,26 @@ discard block |
||
463 | 476 | // add them to the draft array for display |
464 | 477 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
465 | 478 | { |
466 | - if (empty($row['subject'])) |
|
467 | - $row['subject'] = $txt['no_subject']; |
|
479 | + if (empty($row['subject'])) { |
|
480 | + $row['subject'] = $txt['no_subject']; |
|
481 | + } |
|
468 | 482 | |
469 | 483 | // Post drafts |
470 | - if ($draft_type === 0) |
|
471 | - $context['drafts'][] = array( |
|
484 | + if ($draft_type === 0) { |
|
485 | + $context['drafts'][] = array( |
|
472 | 486 | 'subject' => censorText(shorten_subject(stripslashes($row['subject']), 24)), |
473 | 487 | 'poster_time' => timeformat($row['poster_time']), |
474 | 488 | 'link' => '<a href="' . $scripturl . '?action=post;board=' . $row['id_board'] . ';' . (!empty($row['id_topic']) ? 'topic='. $row['id_topic'] .'.0;' : '') . 'id_draft=' . $row['id_draft'] . '">' . $row['subject'] . '</a>', |
475 | 489 | ); |
490 | + } |
|
476 | 491 | // PM drafts |
477 | - elseif ($draft_type === 1) |
|
478 | - $context['drafts'][] = array( |
|
492 | + elseif ($draft_type === 1) { |
|
493 | + $context['drafts'][] = array( |
|
479 | 494 | 'subject' => censorText(shorten_subject(stripslashes($row['subject']), 24)), |
480 | 495 | 'poster_time' => timeformat($row['poster_time']), |
481 | 496 | 'link' => '<a href="' . $scripturl . '?action=pm;sa=send;id_draft=' . $row['id_draft'] . '">' . (!empty($row['subject']) ? $row['subject'] : $txt['drafts_none']) . '</a>', |
482 | 497 | ); |
498 | + } |
|
483 | 499 | } |
484 | 500 | $smcFunc['db_free_result']($request); |
485 | 501 | } |
@@ -543,8 +559,9 @@ discard block |
||
543 | 559 | } |
544 | 560 | |
545 | 561 | // Default to 10. |
546 | - if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) |
|
547 | - $_REQUEST['viewscount'] = 10; |
|
562 | + if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) { |
|
563 | + $_REQUEST['viewscount'] = 10; |
|
564 | + } |
|
548 | 565 | |
549 | 566 | // Get the count of applicable drafts on the boards they can (still) see ... |
550 | 567 | // @todo .. should we just let them see their drafts even if they have lost board access ? |
@@ -609,12 +626,14 @@ discard block |
||
609 | 626 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
610 | 627 | { |
611 | 628 | // Censor.... |
612 | - if (empty($row['body'])) |
|
613 | - $row['body'] = ''; |
|
629 | + if (empty($row['body'])) { |
|
630 | + $row['body'] = ''; |
|
631 | + } |
|
614 | 632 | |
615 | 633 | $row['subject'] = $smcFunc['htmltrim']($row['subject']); |
616 | - if (empty($row['subject'])) |
|
617 | - $row['subject'] = $txt['no_subject']; |
|
634 | + if (empty($row['subject'])) { |
|
635 | + $row['subject'] = $txt['no_subject']; |
|
636 | + } |
|
618 | 637 | |
619 | 638 | censorText($row['body']); |
620 | 639 | censorText($row['subject']); |
@@ -646,8 +665,9 @@ discard block |
||
646 | 665 | $smcFunc['db_free_result']($request); |
647 | 666 | |
648 | 667 | // If the drafts were retrieved in reverse order, get them right again. |
649 | - if ($reverse) |
|
650 | - $context['drafts'] = array_reverse($context['drafts'], true); |
|
668 | + if ($reverse) { |
|
669 | + $context['drafts'] = array_reverse($context['drafts'], true); |
|
670 | + } |
|
651 | 671 | |
652 | 672 | // Menu tab |
653 | 673 | $context[$context['profile_menu_name']]['tab_data'] = array( |
@@ -705,8 +725,9 @@ discard block |
||
705 | 725 | } |
706 | 726 | |
707 | 727 | // Default to 10. |
708 | - if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) |
|
709 | - $_REQUEST['viewscount'] = 10; |
|
728 | + if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) { |
|
729 | + $_REQUEST['viewscount'] = 10; |
|
730 | + } |
|
710 | 731 | |
711 | 732 | // Get the count of applicable drafts |
712 | 733 | $request = $smcFunc['db_query']('', ' |
@@ -765,12 +786,14 @@ discard block |
||
765 | 786 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
766 | 787 | { |
767 | 788 | // Censor.... |
768 | - if (empty($row['body'])) |
|
769 | - $row['body'] = ''; |
|
789 | + if (empty($row['body'])) { |
|
790 | + $row['body'] = ''; |
|
791 | + } |
|
770 | 792 | |
771 | 793 | $row['subject'] = $smcFunc['htmltrim']($row['subject']); |
772 | - if (empty($row['subject'])) |
|
773 | - $row['subject'] = $txt['no_subject']; |
|
794 | + if (empty($row['subject'])) { |
|
795 | + $row['subject'] = $txt['no_subject']; |
|
796 | + } |
|
774 | 797 | |
775 | 798 | censorText($row['body']); |
776 | 799 | censorText($row['subject']); |
@@ -825,8 +848,9 @@ discard block |
||
825 | 848 | $smcFunc['db_free_result']($request); |
826 | 849 | |
827 | 850 | // if the drafts were retrieved in reverse order, then put them in the right order again. |
828 | - if ($reverse) |
|
829 | - $context['drafts'] = array_reverse($context['drafts'], true); |
|
851 | + if ($reverse) { |
|
852 | + $context['drafts'] = array_reverse($context['drafts'], true); |
|
853 | + } |
|
830 | 854 | |
831 | 855 | // off to the template we go |
832 | 856 | $context['page_title'] = $txt['drafts']; |