@@ -11,8 +11,9 @@ discard block |
||
| 11 | 11 | * @version 2.1 Beta 4 |
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | -if (!defined('SMF')) |
|
| 14 | +if (!defined('SMF')) { |
|
| 15 | 15 | die('Hacking attempt...'); |
| 16 | +} |
|
| 16 | 17 | |
| 17 | 18 | /** |
| 18 | 19 | * Our Cache API class |
@@ -44,8 +45,9 @@ discard block |
||
| 44 | 45 | { |
| 45 | 46 | $supported = function_exists('xcache_get') && function_exists('xcache_set') && ini_get('xcache.var_size') > 0; |
| 46 | 47 | |
| 47 | - if ($test) |
|
| 48 | - return $supported; |
|
| 48 | + if ($test) { |
|
| 49 | + return $supported; |
|
| 50 | + } |
|
| 49 | 51 | return parent::isSupported() && $supported; |
| 50 | 52 | } |
| 51 | 53 | |
@@ -66,10 +68,11 @@ discard block |
||
| 66 | 68 | { |
| 67 | 69 | $key = $this->prefix . strtr($key, ':/', '-_'); |
| 68 | 70 | |
| 69 | - if ($value === null) |
|
| 70 | - return xcache_unset($key); |
|
| 71 | - else |
|
| 72 | - return xcache_set($key, $value, $ttl); |
|
| 71 | + if ($value === null) { |
|
| 72 | + return xcache_unset($key); |
|
| 73 | + } else { |
|
| 74 | + return xcache_set($key, $value, $ttl); |
|
| 75 | + } |
|
| 73 | 76 | } |
| 74 | 77 | |
| 75 | 78 | /** |
@@ -88,10 +91,12 @@ discard block |
||
| 88 | 91 | } |
| 89 | 92 | |
| 90 | 93 | // if passed a type, clear that type out |
| 91 | - if ($type === '' || $type === 'user') |
|
| 92 | - xcache_clear_cache(XC_TYPE_VAR, 0); |
|
| 93 | - if ($type === '' || $type === 'data') |
|
| 94 | - xcache_clear_cache(XC_TYPE_PHP, 0); |
|
| 94 | + if ($type === '' || $type === 'user') { |
|
| 95 | + xcache_clear_cache(XC_TYPE_VAR, 0); |
|
| 96 | + } |
|
| 97 | + if ($type === '' || $type === 'data') { |
|
| 98 | + xcache_clear_cache(XC_TYPE_PHP, 0); |
|
| 99 | + } |
|
| 95 | 100 | |
| 96 | 101 | $this->invalidateCache(); |
| 97 | 102 | return true; |
@@ -110,8 +115,9 @@ discard block |
||
| 110 | 115 | // While we could md5 this when saving, this could be tricky to be sure it doesn't get corrupted on additional saves. |
| 111 | 116 | $config_vars[] = array('xcache_adminpass', $txt['cache_xcache_adminpass'], 'db', 'text', 0); |
| 112 | 117 | |
| 113 | - if (!isset($context['settings_post_javascript'])) |
|
| 114 | - $context['settings_post_javascript'] = ''; |
|
| 118 | + if (!isset($context['settings_post_javascript'])) { |
|
| 119 | + $context['settings_post_javascript'] = ''; |
|
| 120 | + } |
|
| 115 | 121 | |
| 116 | 122 | $context['settings_post_javascript'] .= ' |
| 117 | 123 | $("#cache_accelerator").change(function (e) { |
@@ -14,8 +14,9 @@ discard block |
||
| 14 | 14 | * @version 2.1 Beta 4 |
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | -if (!defined('SMF')) |
|
| 17 | +if (!defined('SMF')) { |
|
| 18 | 18 | die('No direct access...'); |
| 19 | +} |
|
| 19 | 20 | |
| 20 | 21 | /** |
| 21 | 22 | * Check if the user is who he/she says he is |
@@ -42,12 +43,14 @@ discard block |
||
| 42 | 43 | $refreshTime = isset($_GET['xml']) ? 4200 : 3600; |
| 43 | 44 | |
| 44 | 45 | // Is the security option off? |
| 45 | - if (!empty($modSettings['securityDisable' . ($type != 'admin' ? '_' . $type : '')])) |
|
| 46 | - return; |
|
| 46 | + if (!empty($modSettings['securityDisable' . ($type != 'admin' ? '_' . $type : '')])) { |
|
| 47 | + return; |
|
| 48 | + } |
|
| 47 | 49 | |
| 48 | 50 | // Or are they already logged in?, Moderator or admin session is need for this area |
| 49 | - if ((!empty($_SESSION[$type . '_time']) && $_SESSION[$type . '_time'] + $refreshTime >= time()) || (!empty($_SESSION['admin_time']) && $_SESSION['admin_time'] + $refreshTime >= time())) |
|
| 50 | - return; |
|
| 51 | + if ((!empty($_SESSION[$type . '_time']) && $_SESSION[$type . '_time'] + $refreshTime >= time()) || (!empty($_SESSION['admin_time']) && $_SESSION['admin_time'] + $refreshTime >= time())) { |
|
| 52 | + return; |
|
| 53 | + } |
|
| 51 | 54 | |
| 52 | 55 | require_once($sourcedir . '/Subs-Auth.php'); |
| 53 | 56 | |
@@ -55,8 +58,9 @@ discard block |
||
| 55 | 58 | if (isset($_POST[$type . '_pass'])) |
| 56 | 59 | { |
| 57 | 60 | // Check to ensure we're forcing SSL for authentication |
| 58 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) |
|
| 59 | - fatal_lang_error('login_ssl_required'); |
|
| 61 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) { |
|
| 62 | + fatal_lang_error('login_ssl_required'); |
|
| 63 | + } |
|
| 60 | 64 | |
| 61 | 65 | checkSession(); |
| 62 | 66 | |
@@ -72,17 +76,19 @@ discard block |
||
| 72 | 76 | } |
| 73 | 77 | |
| 74 | 78 | // Better be sure to remember the real referer |
| 75 | - if (empty($_SESSION['request_referer'])) |
|
| 76 | - $_SESSION['request_referer'] = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array(); |
|
| 77 | - elseif (empty($_POST)) |
|
| 78 | - unset($_SESSION['request_referer']); |
|
| 79 | + if (empty($_SESSION['request_referer'])) { |
|
| 80 | + $_SESSION['request_referer'] = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array(); |
|
| 81 | + } elseif (empty($_POST)) { |
|
| 82 | + unset($_SESSION['request_referer']); |
|
| 83 | + } |
|
| 79 | 84 | |
| 80 | 85 | // Need to type in a password for that, man. |
| 81 | - if (!isset($_GET['xml'])) |
|
| 82 | - adminLogin($type); |
|
| 83 | - else |
|
| 84 | - return 'session_verify_fail'; |
|
| 85 | -} |
|
| 86 | + if (!isset($_GET['xml'])) { |
|
| 87 | + adminLogin($type); |
|
| 88 | + } else { |
|
| 89 | + return 'session_verify_fail'; |
|
| 90 | + } |
|
| 91 | + } |
|
| 86 | 92 | |
| 87 | 93 | /** |
| 88 | 94 | * Require a user who is logged in. (not a guest.) |
@@ -96,25 +102,30 @@ discard block |
||
| 96 | 102 | global $user_info, $txt, $context, $scripturl, $modSettings; |
| 97 | 103 | |
| 98 | 104 | // Luckily, this person isn't a guest. |
| 99 | - if (!$user_info['is_guest']) |
|
| 100 | - return; |
|
| 105 | + if (!$user_info['is_guest']) { |
|
| 106 | + return; |
|
| 107 | + } |
|
| 101 | 108 | |
| 102 | 109 | // Log what they were trying to do didn't work) |
| 103 | - if (!empty($modSettings['who_enabled'])) |
|
| 104 | - $_GET['error'] = 'guest_login'; |
|
| 110 | + if (!empty($modSettings['who_enabled'])) { |
|
| 111 | + $_GET['error'] = 'guest_login'; |
|
| 112 | + } |
|
| 105 | 113 | writeLog(true); |
| 106 | 114 | |
| 107 | 115 | // Just die. |
| 108 | - if (isset($_REQUEST['xml'])) |
|
| 109 | - obExit(false); |
|
| 116 | + if (isset($_REQUEST['xml'])) { |
|
| 117 | + obExit(false); |
|
| 118 | + } |
|
| 110 | 119 | |
| 111 | 120 | // Attempt to detect if they came from dlattach. |
| 112 | - if (SMF != 'SSI' && empty($context['theme_loaded'])) |
|
| 113 | - loadTheme(); |
|
| 121 | + if (SMF != 'SSI' && empty($context['theme_loaded'])) { |
|
| 122 | + loadTheme(); |
|
| 123 | + } |
|
| 114 | 124 | |
| 115 | 125 | // Never redirect to an attachment |
| 116 | - if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) |
|
| 117 | - $_SESSION['login_url'] = $_SERVER['REQUEST_URL']; |
|
| 126 | + if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) { |
|
| 127 | + $_SESSION['login_url'] = $_SERVER['REQUEST_URL']; |
|
| 128 | + } |
|
| 118 | 129 | |
| 119 | 130 | // Load the Login template and language file. |
| 120 | 131 | loadLanguage('Login'); |
@@ -124,8 +135,7 @@ discard block |
||
| 124 | 135 | { |
| 125 | 136 | $_SESSION['login_url'] = $scripturl . '?' . $_SERVER['QUERY_STRING']; |
| 126 | 137 | redirectexit('action=login'); |
| 127 | - } |
|
| 128 | - else |
|
| 138 | + } else |
|
| 129 | 139 | { |
| 130 | 140 | loadTemplate('Login'); |
| 131 | 141 | $context['sub_template'] = 'kick_guest'; |
@@ -155,8 +165,9 @@ discard block |
||
| 155 | 165 | global $sourcedir, $cookiename, $user_settings, $smcFunc; |
| 156 | 166 | |
| 157 | 167 | // You cannot be banned if you are an admin - doesn't help if you log out. |
| 158 | - if ($user_info['is_admin']) |
|
| 159 | - return; |
|
| 168 | + if ($user_info['is_admin']) { |
|
| 169 | + return; |
|
| 170 | + } |
|
| 160 | 171 | |
| 161 | 172 | // Only check the ban every so often. (to reduce load.) |
| 162 | 173 | if ($forceCheck || !isset($_SESSION['ban']) || empty($modSettings['banLastUpdated']) || ($_SESSION['ban']['last_checked'] < $modSettings['banLastUpdated']) || $_SESSION['ban']['id_member'] != $user_info['id'] || $_SESSION['ban']['ip'] != $user_info['ip'] || $_SESSION['ban']['ip2'] != $user_info['ip2'] || (isset($user_info['email'], $_SESSION['ban']['email']) && $_SESSION['ban']['email'] != $user_info['email'])) |
@@ -177,8 +188,9 @@ discard block |
||
| 177 | 188 | // Check both IP addresses. |
| 178 | 189 | foreach (array('ip', 'ip2') as $ip_number) |
| 179 | 190 | { |
| 180 | - if ($ip_number == 'ip2' && $user_info['ip2'] == $user_info['ip']) |
|
| 181 | - continue; |
|
| 191 | + if ($ip_number == 'ip2' && $user_info['ip2'] == $user_info['ip']) { |
|
| 192 | + continue; |
|
| 193 | + } |
|
| 182 | 194 | $ban_query[] = ' {inet:' . $ip_number . '} BETWEEN bi.ip_low and bi.ip_high'; |
| 183 | 195 | $ban_query_vars[$ip_number] = $user_info[$ip_number]; |
| 184 | 196 | // IP was valid, maybe there's also a hostname... |
@@ -228,24 +240,28 @@ discard block |
||
| 228 | 240 | // Store every type of ban that applies to you in your session. |
| 229 | 241 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 230 | 242 | { |
| 231 | - foreach ($restrictions as $restriction) |
|
| 232 | - if (!empty($row[$restriction])) |
|
| 243 | + foreach ($restrictions as $restriction) { |
|
| 244 | + if (!empty($row[$restriction])) |
|
| 233 | 245 | { |
| 234 | 246 | $_SESSION['ban'][$restriction]['reason'] = $row['reason']; |
| 247 | + } |
|
| 235 | 248 | $_SESSION['ban'][$restriction]['ids'][] = $row['id_ban']; |
| 236 | - if (!isset($_SESSION['ban']['expire_time']) || ($_SESSION['ban']['expire_time'] != 0 && ($row['expire_time'] == 0 || $row['expire_time'] > $_SESSION['ban']['expire_time']))) |
|
| 237 | - $_SESSION['ban']['expire_time'] = $row['expire_time']; |
|
| 249 | + if (!isset($_SESSION['ban']['expire_time']) || ($_SESSION['ban']['expire_time'] != 0 && ($row['expire_time'] == 0 || $row['expire_time'] > $_SESSION['ban']['expire_time']))) { |
|
| 250 | + $_SESSION['ban']['expire_time'] = $row['expire_time']; |
|
| 251 | + } |
|
| 238 | 252 | |
| 239 | - if (!$user_info['is_guest'] && $restriction == 'cannot_access' && ($row['id_member'] == $user_info['id'] || $row['email_address'] == $user_info['email'])) |
|
| 240 | - $flag_is_activated = true; |
|
| 253 | + if (!$user_info['is_guest'] && $restriction == 'cannot_access' && ($row['id_member'] == $user_info['id'] || $row['email_address'] == $user_info['email'])) { |
|
| 254 | + $flag_is_activated = true; |
|
| 255 | + } |
|
| 241 | 256 | } |
| 242 | 257 | } |
| 243 | 258 | $smcFunc['db_free_result']($request); |
| 244 | 259 | } |
| 245 | 260 | |
| 246 | 261 | // Mark the cannot_access and cannot_post bans as being 'hit'. |
| 247 | - if (isset($_SESSION['ban']['cannot_access']) || isset($_SESSION['ban']['cannot_post']) || isset($_SESSION['ban']['cannot_login'])) |
|
| 248 | - log_ban(array_merge(isset($_SESSION['ban']['cannot_access']) ? $_SESSION['ban']['cannot_access']['ids'] : array(), isset($_SESSION['ban']['cannot_post']) ? $_SESSION['ban']['cannot_post']['ids'] : array(), isset($_SESSION['ban']['cannot_login']) ? $_SESSION['ban']['cannot_login']['ids'] : array())); |
|
| 262 | + if (isset($_SESSION['ban']['cannot_access']) || isset($_SESSION['ban']['cannot_post']) || isset($_SESSION['ban']['cannot_login'])) { |
|
| 263 | + log_ban(array_merge(isset($_SESSION['ban']['cannot_access']) ? $_SESSION['ban']['cannot_access']['ids'] : array(), isset($_SESSION['ban']['cannot_post']) ? $_SESSION['ban']['cannot_post']['ids'] : array(), isset($_SESSION['ban']['cannot_login']) ? $_SESSION['ban']['cannot_login']['ids'] : array())); |
|
| 264 | + } |
|
| 249 | 265 | |
| 250 | 266 | // If for whatever reason the is_activated flag seems wrong, do a little work to clear it up. |
| 251 | 267 | if ($user_info['id'] && (($user_settings['is_activated'] >= 10 && !$flag_is_activated) |
@@ -260,8 +276,9 @@ discard block |
||
| 260 | 276 | if (!isset($_SESSION['ban']['cannot_access']) && !empty($_COOKIE[$cookiename . '_'])) |
| 261 | 277 | { |
| 262 | 278 | $bans = explode(',', $_COOKIE[$cookiename . '_']); |
| 263 | - foreach ($bans as $key => $value) |
|
| 264 | - $bans[$key] = (int) $value; |
|
| 279 | + foreach ($bans as $key => $value) { |
|
| 280 | + $bans[$key] = (int) $value; |
|
| 281 | + } |
|
| 265 | 282 | $request = $smcFunc['db_query']('', ' |
| 266 | 283 | SELECT bi.id_ban, bg.reason |
| 267 | 284 | FROM {db_prefix}ban_items AS bi |
@@ -297,14 +314,15 @@ discard block |
||
| 297 | 314 | if (isset($_SESSION['ban']['cannot_access'])) |
| 298 | 315 | { |
| 299 | 316 | // We don't wanna see you! |
| 300 | - if (!$user_info['is_guest']) |
|
| 301 | - $smcFunc['db_query']('', ' |
|
| 317 | + if (!$user_info['is_guest']) { |
|
| 318 | + $smcFunc['db_query']('', ' |
|
| 302 | 319 | DELETE FROM {db_prefix}log_online |
| 303 | 320 | WHERE id_member = {int:current_member}', |
| 304 | 321 | array( |
| 305 | 322 | 'current_member' => $user_info['id'], |
| 306 | 323 | ) |
| 307 | 324 | ); |
| 325 | + } |
|
| 308 | 326 | |
| 309 | 327 | // 'Log' the user out. Can't have any funny business... (save the name!) |
| 310 | 328 | $old_name = isset($user_info['name']) && $user_info['name'] != '' ? $user_info['name'] : $txt['guest_title']; |
@@ -390,9 +408,10 @@ discard block |
||
| 390 | 408 | } |
| 391 | 409 | |
| 392 | 410 | // Fix up the banning permissions. |
| 393 | - if (isset($user_info['permissions'])) |
|
| 394 | - banPermissions(); |
|
| 395 | -} |
|
| 411 | + if (isset($user_info['permissions'])) { |
|
| 412 | + banPermissions(); |
|
| 413 | + } |
|
| 414 | + } |
|
| 396 | 415 | |
| 397 | 416 | /** |
| 398 | 417 | * Fix permissions according to ban status. |
@@ -403,8 +422,9 @@ discard block |
||
| 403 | 422 | global $user_info, $sourcedir, $modSettings, $context; |
| 404 | 423 | |
| 405 | 424 | // Somehow they got here, at least take away all permissions... |
| 406 | - if (isset($_SESSION['ban']['cannot_access'])) |
|
| 407 | - $user_info['permissions'] = array(); |
|
| 425 | + if (isset($_SESSION['ban']['cannot_access'])) { |
|
| 426 | + $user_info['permissions'] = array(); |
|
| 427 | + } |
|
| 408 | 428 | // Okay, well, you can watch, but don't touch a thing. |
| 409 | 429 | elseif (isset($_SESSION['ban']['cannot_post']) || (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $user_info['warning'])) |
| 410 | 430 | { |
@@ -446,19 +466,20 @@ discard block |
||
| 446 | 466 | call_integration_hook('integrate_warn_permissions', array(&$permission_change)); |
| 447 | 467 | foreach ($permission_change as $old => $new) |
| 448 | 468 | { |
| 449 | - if (!in_array($old, $user_info['permissions'])) |
|
| 450 | - unset($permission_change[$old]); |
|
| 451 | - else |
|
| 452 | - $user_info['permissions'][] = $new; |
|
| 469 | + if (!in_array($old, $user_info['permissions'])) { |
|
| 470 | + unset($permission_change[$old]); |
|
| 471 | + } else { |
|
| 472 | + $user_info['permissions'][] = $new; |
|
| 473 | + } |
|
| 453 | 474 | } |
| 454 | 475 | $user_info['permissions'] = array_diff($user_info['permissions'], array_keys($permission_change)); |
| 455 | 476 | } |
| 456 | 477 | |
| 457 | 478 | // @todo Find a better place to call this? Needs to be after permissions loaded! |
| 458 | 479 | // Finally, some bits we cache in the session because it saves queries. |
| 459 | - if (isset($_SESSION['mc']) && $_SESSION['mc']['time'] > $modSettings['settings_updated'] && $_SESSION['mc']['id'] == $user_info['id']) |
|
| 460 | - $user_info['mod_cache'] = $_SESSION['mc']; |
|
| 461 | - else |
|
| 480 | + if (isset($_SESSION['mc']) && $_SESSION['mc']['time'] > $modSettings['settings_updated'] && $_SESSION['mc']['id'] == $user_info['id']) { |
|
| 481 | + $user_info['mod_cache'] = $_SESSION['mc']; |
|
| 482 | + } else |
|
| 462 | 483 | { |
| 463 | 484 | require_once($sourcedir . '/Subs-Auth.php'); |
| 464 | 485 | rebuildModCache(); |
@@ -469,14 +490,12 @@ discard block |
||
| 469 | 490 | { |
| 470 | 491 | $context['open_mod_reports'] = $_SESSION['rc']['reports']; |
| 471 | 492 | $context['open_member_reports'] = $_SESSION['rc']['member_reports']; |
| 472 | - } |
|
| 473 | - elseif ($_SESSION['mc']['bq'] != '0=1') |
|
| 493 | + } elseif ($_SESSION['mc']['bq'] != '0=1') |
|
| 474 | 494 | { |
| 475 | 495 | require_once($sourcedir . '/Subs-ReportedContent.php'); |
| 476 | 496 | $context['open_mod_reports'] = recountOpenReports('posts'); |
| 477 | 497 | $context['open_member_reports'] = recountOpenReports('members'); |
| 478 | - } |
|
| 479 | - else |
|
| 498 | + } else |
|
| 480 | 499 | { |
| 481 | 500 | $context['open_mod_reports'] = 0; |
| 482 | 501 | $context['open_member_reports'] = 0; |
@@ -496,8 +515,9 @@ discard block |
||
| 496 | 515 | global $user_info, $smcFunc; |
| 497 | 516 | |
| 498 | 517 | // Don't log web accelerators, it's very confusing... |
| 499 | - if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') |
|
| 500 | - return; |
|
| 518 | + if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') { |
|
| 519 | + return; |
|
| 520 | + } |
|
| 501 | 521 | |
| 502 | 522 | $smcFunc['db_insert']('', |
| 503 | 523 | '{db_prefix}log_banned', |
@@ -507,8 +527,8 @@ discard block |
||
| 507 | 527 | ); |
| 508 | 528 | |
| 509 | 529 | // One extra point for these bans. |
| 510 | - if (!empty($ban_ids)) |
|
| 511 | - $smcFunc['db_query']('', ' |
|
| 530 | + if (!empty($ban_ids)) { |
|
| 531 | + $smcFunc['db_query']('', ' |
|
| 512 | 532 | UPDATE {db_prefix}ban_items |
| 513 | 533 | SET hits = hits + 1 |
| 514 | 534 | WHERE id_ban IN ({array_int:ban_ids})', |
@@ -516,7 +536,8 @@ discard block |
||
| 516 | 536 | 'ban_ids' => $ban_ids, |
| 517 | 537 | ) |
| 518 | 538 | ); |
| 519 | -} |
|
| 539 | + } |
|
| 540 | + } |
|
| 520 | 541 | |
| 521 | 542 | /** |
| 522 | 543 | * Checks if a given email address might be banned. |
@@ -532,8 +553,9 @@ discard block |
||
| 532 | 553 | global $txt, $smcFunc; |
| 533 | 554 | |
| 534 | 555 | // Can't ban an empty email |
| 535 | - if (empty($email) || trim($email) == '') |
|
| 536 | - return; |
|
| 556 | + if (empty($email) || trim($email) == '') { |
|
| 557 | + return; |
|
| 558 | + } |
|
| 537 | 559 | |
| 538 | 560 | // Let's start with the bans based on your IP/hostname/memberID... |
| 539 | 561 | $ban_ids = isset($_SESSION['ban'][$restriction]) ? $_SESSION['ban'][$restriction]['ids'] : array(); |
@@ -606,16 +628,18 @@ discard block |
||
| 606 | 628 | if ($type == 'post') |
| 607 | 629 | { |
| 608 | 630 | $check = isset($_POST[$_SESSION['session_var']]) ? $_POST[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_POST['sc']) ? $_POST['sc'] : null); |
| 609 | - if ($check !== $sc) |
|
| 610 | - $error = 'session_timeout'; |
|
| 631 | + if ($check !== $sc) { |
|
| 632 | + $error = 'session_timeout'; |
|
| 633 | + } |
|
| 611 | 634 | } |
| 612 | 635 | |
| 613 | 636 | // How about $_GET['sesc']? |
| 614 | 637 | elseif ($type == 'get') |
| 615 | 638 | { |
| 616 | 639 | $check = isset($_GET[$_SESSION['session_var']]) ? $_GET[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_GET['sesc']) ? $_GET['sesc'] : null); |
| 617 | - if ($check !== $sc) |
|
| 618 | - $error = 'session_verify_fail'; |
|
| 640 | + if ($check !== $sc) { |
|
| 641 | + $error = 'session_verify_fail'; |
|
| 642 | + } |
|
| 619 | 643 | } |
| 620 | 644 | |
| 621 | 645 | // Or can it be in either? |
@@ -623,13 +647,15 @@ discard block |
||
| 623 | 647 | { |
| 624 | 648 | $check = isset($_GET[$_SESSION['session_var']]) ? $_GET[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_GET['sesc']) ? $_GET['sesc'] : (isset($_POST[$_SESSION['session_var']]) ? $_POST[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_POST['sc']) ? $_POST['sc'] : null))); |
| 625 | 649 | |
| 626 | - if ($check !== $sc) |
|
| 627 | - $error = 'session_verify_fail'; |
|
| 650 | + if ($check !== $sc) { |
|
| 651 | + $error = 'session_verify_fail'; |
|
| 652 | + } |
|
| 628 | 653 | } |
| 629 | 654 | |
| 630 | 655 | // Verify that they aren't changing user agents on us - that could be bad. |
| 631 | - if ((!isset($_SESSION['USER_AGENT']) || $_SESSION['USER_AGENT'] != $_SERVER['HTTP_USER_AGENT']) && empty($modSettings['disableCheckUA'])) |
|
| 632 | - $error = 'session_verify_fail'; |
|
| 656 | + if ((!isset($_SESSION['USER_AGENT']) || $_SESSION['USER_AGENT'] != $_SERVER['HTTP_USER_AGENT']) && empty($modSettings['disableCheckUA'])) { |
|
| 657 | + $error = 'session_verify_fail'; |
|
| 658 | + } |
|
| 633 | 659 | |
| 634 | 660 | // Make sure a page with session check requirement is not being prefetched. |
| 635 | 661 | if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') |
@@ -640,30 +666,35 @@ discard block |
||
| 640 | 666 | } |
| 641 | 667 | |
| 642 | 668 | // Check the referring site - it should be the same server at least! |
| 643 | - if (isset($_SESSION['request_referer'])) |
|
| 644 | - $referrer = $_SESSION['request_referer']; |
|
| 645 | - else |
|
| 646 | - $referrer = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array(); |
|
| 669 | + if (isset($_SESSION['request_referer'])) { |
|
| 670 | + $referrer = $_SESSION['request_referer']; |
|
| 671 | + } else { |
|
| 672 | + $referrer = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array(); |
|
| 673 | + } |
|
| 647 | 674 | if (!empty($referrer['host'])) |
| 648 | 675 | { |
| 649 | - if (strpos($_SERVER['HTTP_HOST'], ':') !== false) |
|
| 650 | - $real_host = substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], ':')); |
|
| 651 | - else |
|
| 652 | - $real_host = $_SERVER['HTTP_HOST']; |
|
| 676 | + if (strpos($_SERVER['HTTP_HOST'], ':') !== false) { |
|
| 677 | + $real_host = substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], ':')); |
|
| 678 | + } else { |
|
| 679 | + $real_host = $_SERVER['HTTP_HOST']; |
|
| 680 | + } |
|
| 653 | 681 | |
| 654 | 682 | $parsed_url = parse_url($boardurl); |
| 655 | 683 | |
| 656 | 684 | // Are global cookies on? If so, let's check them ;). |
| 657 | 685 | if (!empty($modSettings['globalCookies'])) |
| 658 | 686 | { |
| 659 | - if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $parsed_url['host'], $parts) == 1) |
|
| 660 | - $parsed_url['host'] = $parts[1]; |
|
| 687 | + if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $parsed_url['host'], $parts) == 1) { |
|
| 688 | + $parsed_url['host'] = $parts[1]; |
|
| 689 | + } |
|
| 661 | 690 | |
| 662 | - if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $referrer['host'], $parts) == 1) |
|
| 663 | - $referrer['host'] = $parts[1]; |
|
| 691 | + if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $referrer['host'], $parts) == 1) { |
|
| 692 | + $referrer['host'] = $parts[1]; |
|
| 693 | + } |
|
| 664 | 694 | |
| 665 | - if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $real_host, $parts) == 1) |
|
| 666 | - $real_host = $parts[1]; |
|
| 695 | + if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $real_host, $parts) == 1) { |
|
| 696 | + $real_host = $parts[1]; |
|
| 697 | + } |
|
| 667 | 698 | } |
| 668 | 699 | |
| 669 | 700 | // Okay: referrer must either match parsed_url or real_host. |
@@ -681,12 +712,14 @@ discard block |
||
| 681 | 712 | $log_error = true; |
| 682 | 713 | } |
| 683 | 714 | |
| 684 | - if (strtolower($_SERVER['HTTP_USER_AGENT']) == 'hacker') |
|
| 685 | - fatal_error('Sound the alarm! It\'s a hacker! Close the castle gates!!', false); |
|
| 715 | + if (strtolower($_SERVER['HTTP_USER_AGENT']) == 'hacker') { |
|
| 716 | + fatal_error('Sound the alarm! It\'s a hacker! Close the castle gates!!', false); |
|
| 717 | + } |
|
| 686 | 718 | |
| 687 | 719 | // Everything is ok, return an empty string. |
| 688 | - if (!isset($error)) |
|
| 689 | - return ''; |
|
| 720 | + if (!isset($error)) { |
|
| 721 | + return ''; |
|
| 722 | + } |
|
| 690 | 723 | // A session error occurred, show the error. |
| 691 | 724 | elseif ($is_fatal) |
| 692 | 725 | { |
@@ -695,13 +728,14 @@ discard block |
||
| 695 | 728 | ob_end_clean(); |
| 696 | 729 | header('HTTP/1.1 403 Forbidden - Session timeout'); |
| 697 | 730 | die; |
| 731 | + } else { |
|
| 732 | + fatal_lang_error($error, isset($log_error) ? 'user' : false); |
|
| 698 | 733 | } |
| 699 | - else |
|
| 700 | - fatal_lang_error($error, isset($log_error) ? 'user' : false); |
|
| 701 | 734 | } |
| 702 | 735 | // A session error occurred, return the error to the calling function. |
| 703 | - else |
|
| 704 | - return $error; |
|
| 736 | + else { |
|
| 737 | + return $error; |
|
| 738 | + } |
|
| 705 | 739 | |
| 706 | 740 | // We really should never fall through here, for very important reasons. Let's make sure. |
| 707 | 741 | trigger_error('Hacking attempt...', E_USER_ERROR); |
@@ -717,10 +751,9 @@ discard block |
||
| 717 | 751 | { |
| 718 | 752 | global $modSettings; |
| 719 | 753 | |
| 720 | - if (isset($_GET['confirm']) && isset($_SESSION['confirm_' . $action]) && md5($_GET['confirm'] . $_SERVER['HTTP_USER_AGENT']) == $_SESSION['confirm_' . $action]) |
|
| 721 | - return true; |
|
| 722 | - |
|
| 723 | - else |
|
| 754 | + if (isset($_GET['confirm']) && isset($_SESSION['confirm_' . $action]) && md5($_GET['confirm'] . $_SERVER['HTTP_USER_AGENT']) == $_SESSION['confirm_' . $action]) { |
|
| 755 | + return true; |
|
| 756 | + } else |
|
| 724 | 757 | { |
| 725 | 758 | $token = md5(mt_rand() . session_id() . (string) microtime() . $modSettings['rand_seed']); |
| 726 | 759 | $_SESSION['confirm_' . $action] = md5($token . $_SERVER['HTTP_USER_AGENT']); |
@@ -771,9 +804,9 @@ discard block |
||
| 771 | 804 | $return = $_SESSION['token'][$type . '-' . $action][3]; |
| 772 | 805 | unset($_SESSION['token'][$type . '-' . $action]); |
| 773 | 806 | return $return; |
| 807 | + } else { |
|
| 808 | + return ''; |
|
| 774 | 809 | } |
| 775 | - else |
|
| 776 | - return ''; |
|
| 777 | 810 | } |
| 778 | 811 | |
| 779 | 812 | // This nasty piece of code validates a token. |
@@ -804,12 +837,14 @@ discard block |
||
| 804 | 837 | fatal_lang_error('token_verify_fail', false); |
| 805 | 838 | } |
| 806 | 839 | // Remove this token as its useless |
| 807 | - else |
|
| 808 | - unset($_SESSION['token'][$type . '-' . $action]); |
|
| 840 | + else { |
|
| 841 | + unset($_SESSION['token'][$type . '-' . $action]); |
|
| 842 | + } |
|
| 809 | 843 | |
| 810 | 844 | // Randomly check if we should remove some older tokens. |
| 811 | - if (mt_rand(0, 138) == 23) |
|
| 812 | - cleanTokens(); |
|
| 845 | + if (mt_rand(0, 138) == 23) { |
|
| 846 | + cleanTokens(); |
|
| 847 | + } |
|
| 813 | 848 | |
| 814 | 849 | return false; |
| 815 | 850 | } |
@@ -824,14 +859,16 @@ discard block |
||
| 824 | 859 | function cleanTokens($complete = false) |
| 825 | 860 | { |
| 826 | 861 | // We appreciate cleaning up after yourselves. |
| 827 | - if (!isset($_SESSION['token'])) |
|
| 828 | - return; |
|
| 862 | + if (!isset($_SESSION['token'])) { |
|
| 863 | + return; |
|
| 864 | + } |
|
| 829 | 865 | |
| 830 | 866 | // Clean up tokens, trying to give enough time still. |
| 831 | - foreach ($_SESSION['token'] as $key => $data) |
|
| 832 | - if ($data[2] + 10800 < time() || $complete) |
|
| 867 | + foreach ($_SESSION['token'] as $key => $data) { |
|
| 868 | + if ($data[2] + 10800 < time() || $complete) |
|
| 833 | 869 | unset($_SESSION['token'][$key]); |
| 834 | -} |
|
| 870 | + } |
|
| 871 | + } |
|
| 835 | 872 | |
| 836 | 873 | /** |
| 837 | 874 | * Check whether a form has been submitted twice. |
@@ -849,37 +886,40 @@ discard block |
||
| 849 | 886 | { |
| 850 | 887 | global $context; |
| 851 | 888 | |
| 852 | - if (!isset($_SESSION['forms'])) |
|
| 853 | - $_SESSION['forms'] = array(); |
|
| 889 | + if (!isset($_SESSION['forms'])) { |
|
| 890 | + $_SESSION['forms'] = array(); |
|
| 891 | + } |
|
| 854 | 892 | |
| 855 | 893 | // Register a form number and store it in the session stack. (use this on the page that has the form.) |
| 856 | 894 | if ($action == 'register') |
| 857 | 895 | { |
| 858 | 896 | $context['form_sequence_number'] = 0; |
| 859 | - while (empty($context['form_sequence_number']) || in_array($context['form_sequence_number'], $_SESSION['forms'])) |
|
| 860 | - $context['form_sequence_number'] = mt_rand(1, 16000000); |
|
| 897 | + while (empty($context['form_sequence_number']) || in_array($context['form_sequence_number'], $_SESSION['forms'])) { |
|
| 898 | + $context['form_sequence_number'] = mt_rand(1, 16000000); |
|
| 899 | + } |
|
| 861 | 900 | } |
| 862 | 901 | // Check whether the submitted number can be found in the session. |
| 863 | 902 | elseif ($action == 'check') |
| 864 | 903 | { |
| 865 | - if (!isset($_REQUEST['seqnum'])) |
|
| 866 | - return true; |
|
| 867 | - elseif (!in_array($_REQUEST['seqnum'], $_SESSION['forms'])) |
|
| 904 | + if (!isset($_REQUEST['seqnum'])) { |
|
| 905 | + return true; |
|
| 906 | + } elseif (!in_array($_REQUEST['seqnum'], $_SESSION['forms'])) |
|
| 868 | 907 | { |
| 869 | 908 | $_SESSION['forms'][] = (int) $_REQUEST['seqnum']; |
| 870 | 909 | return true; |
| 910 | + } elseif ($is_fatal) { |
|
| 911 | + fatal_lang_error('error_form_already_submitted', false); |
|
| 912 | + } else { |
|
| 913 | + return false; |
|
| 871 | 914 | } |
| 872 | - elseif ($is_fatal) |
|
| 873 | - fatal_lang_error('error_form_already_submitted', false); |
|
| 874 | - else |
|
| 875 | - return false; |
|
| 876 | 915 | } |
| 877 | 916 | // Don't check, just free the stack number. |
| 878 | - elseif ($action == 'free' && isset($_REQUEST['seqnum']) && in_array($_REQUEST['seqnum'], $_SESSION['forms'])) |
|
| 879 | - $_SESSION['forms'] = array_diff($_SESSION['forms'], array($_REQUEST['seqnum'])); |
|
| 880 | - elseif ($action != 'free') |
|
| 881 | - trigger_error('checkSubmitOnce(): Invalid action \'' . $action . '\'', E_USER_WARNING); |
|
| 882 | -} |
|
| 917 | + elseif ($action == 'free' && isset($_REQUEST['seqnum']) && in_array($_REQUEST['seqnum'], $_SESSION['forms'])) { |
|
| 918 | + $_SESSION['forms'] = array_diff($_SESSION['forms'], array($_REQUEST['seqnum'])); |
|
| 919 | + } elseif ($action != 'free') { |
|
| 920 | + trigger_error('checkSubmitOnce(): Invalid action \'' . $action . '\'', E_USER_WARNING); |
|
| 921 | + } |
|
| 922 | + } |
|
| 883 | 923 | |
| 884 | 924 | /** |
| 885 | 925 | * Check the user's permissions. |
@@ -896,16 +936,19 @@ discard block |
||
| 896 | 936 | global $user_info, $smcFunc; |
| 897 | 937 | |
| 898 | 938 | // You're always allowed to do nothing. (unless you're a working man, MR. LAZY :P!) |
| 899 | - if (empty($permission)) |
|
| 900 | - return true; |
|
| 939 | + if (empty($permission)) { |
|
| 940 | + return true; |
|
| 941 | + } |
|
| 901 | 942 | |
| 902 | 943 | // You're never allowed to do something if your data hasn't been loaded yet! |
| 903 | - if (empty($user_info)) |
|
| 904 | - return false; |
|
| 944 | + if (empty($user_info)) { |
|
| 945 | + return false; |
|
| 946 | + } |
|
| 905 | 947 | |
| 906 | 948 | // Administrators are supermen :P. |
| 907 | - if ($user_info['is_admin']) |
|
| 908 | - return true; |
|
| 949 | + if ($user_info['is_admin']) { |
|
| 950 | + return true; |
|
| 951 | + } |
|
| 909 | 952 | |
| 910 | 953 | // Let's ensure this is an array. |
| 911 | 954 | $permission = (array) $permission; |
@@ -913,14 +956,16 @@ discard block |
||
| 913 | 956 | // Are we checking the _current_ board, or some other boards? |
| 914 | 957 | if ($boards === null) |
| 915 | 958 | { |
| 916 | - if (count(array_intersect($permission, $user_info['permissions'])) != 0) |
|
| 917 | - return true; |
|
| 959 | + if (count(array_intersect($permission, $user_info['permissions'])) != 0) { |
|
| 960 | + return true; |
|
| 961 | + } |
|
| 918 | 962 | // You aren't allowed, by default. |
| 919 | - else |
|
| 920 | - return false; |
|
| 963 | + else { |
|
| 964 | + return false; |
|
| 965 | + } |
|
| 966 | + } elseif (!is_array($boards)) { |
|
| 967 | + $boards = array($boards); |
|
| 921 | 968 | } |
| 922 | - elseif (!is_array($boards)) |
|
| 923 | - $boards = array($boards); |
|
| 924 | 969 | |
| 925 | 970 | $request = $smcFunc['db_query']('', ' |
| 926 | 971 | SELECT MIN(bp.add_deny) AS add_deny |
@@ -943,12 +988,14 @@ discard block |
||
| 943 | 988 | ); |
| 944 | 989 | |
| 945 | 990 | // Make sure they can do it on all of the boards. |
| 946 | - if ($smcFunc['db_num_rows']($request) != count($boards)) |
|
| 947 | - return false; |
|
| 991 | + if ($smcFunc['db_num_rows']($request) != count($boards)) { |
|
| 992 | + return false; |
|
| 993 | + } |
|
| 948 | 994 | |
| 949 | 995 | $result = true; |
| 950 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 951 | - $result &= !empty($row['add_deny']); |
|
| 996 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 997 | + $result &= !empty($row['add_deny']); |
|
| 998 | + } |
|
| 952 | 999 | $smcFunc['db_free_result']($request); |
| 953 | 1000 | |
| 954 | 1001 | // If the query returned 1, they can do it... otherwise, they can't. |
@@ -1013,9 +1060,10 @@ discard block |
||
| 1013 | 1060 | |
| 1014 | 1061 | // If you're doing something on behalf of some "heavy" permissions, validate your session. |
| 1015 | 1062 | // (take out the heavy permissions, and if you can't do anything but those, you need a validated session.) |
| 1016 | - if (!allowedTo(array_diff($permission, $heavy_permissions), $boards)) |
|
| 1017 | - validateSession(); |
|
| 1018 | -} |
|
| 1063 | + if (!allowedTo(array_diff($permission, $heavy_permissions), $boards)) { |
|
| 1064 | + validateSession(); |
|
| 1065 | + } |
|
| 1066 | + } |
|
| 1019 | 1067 | |
| 1020 | 1068 | /** |
| 1021 | 1069 | * Return the boards a user has a certain (board) permission on. (array(0) if all.) |
@@ -1034,8 +1082,9 @@ discard block |
||
| 1034 | 1082 | global $user_info, $smcFunc; |
| 1035 | 1083 | |
| 1036 | 1084 | // Arrays are nice, most of the time. |
| 1037 | - if (!is_array($permissions)) |
|
| 1038 | - $permissions = array($permissions); |
|
| 1085 | + if (!is_array($permissions)) { |
|
| 1086 | + $permissions = array($permissions); |
|
| 1087 | + } |
|
| 1039 | 1088 | |
| 1040 | 1089 | /* |
| 1041 | 1090 | * Set $simple to true to use this function as it were in SMF 2.0.x. |
@@ -1047,13 +1096,14 @@ discard block |
||
| 1047 | 1096 | // Administrators are all powerful, sorry. |
| 1048 | 1097 | if ($user_info['is_admin']) |
| 1049 | 1098 | { |
| 1050 | - if ($simple) |
|
| 1051 | - return array(0); |
|
| 1052 | - else |
|
| 1099 | + if ($simple) { |
|
| 1100 | + return array(0); |
|
| 1101 | + } else |
|
| 1053 | 1102 | { |
| 1054 | 1103 | $boards = array(); |
| 1055 | - foreach ($permissions as $permission) |
|
| 1056 | - $boards[$permission] = array(0); |
|
| 1104 | + foreach ($permissions as $permission) { |
|
| 1105 | + $boards[$permission] = array(0); |
|
| 1106 | + } |
|
| 1057 | 1107 | |
| 1058 | 1108 | return $boards; |
| 1059 | 1109 | } |
@@ -1085,31 +1135,32 @@ discard block |
||
| 1085 | 1135 | { |
| 1086 | 1136 | if ($simple) |
| 1087 | 1137 | { |
| 1088 | - if (empty($row['add_deny'])) |
|
| 1089 | - $deny_boards[] = $row['id_board']; |
|
| 1090 | - else |
|
| 1091 | - $boards[] = $row['id_board']; |
|
| 1092 | - } |
|
| 1093 | - else |
|
| 1138 | + if (empty($row['add_deny'])) { |
|
| 1139 | + $deny_boards[] = $row['id_board']; |
|
| 1140 | + } else { |
|
| 1141 | + $boards[] = $row['id_board']; |
|
| 1142 | + } |
|
| 1143 | + } else |
|
| 1094 | 1144 | { |
| 1095 | - if (empty($row['add_deny'])) |
|
| 1096 | - $deny_boards[$row['permission']][] = $row['id_board']; |
|
| 1097 | - else |
|
| 1098 | - $boards[$row['permission']][] = $row['id_board']; |
|
| 1145 | + if (empty($row['add_deny'])) { |
|
| 1146 | + $deny_boards[$row['permission']][] = $row['id_board']; |
|
| 1147 | + } else { |
|
| 1148 | + $boards[$row['permission']][] = $row['id_board']; |
|
| 1149 | + } |
|
| 1099 | 1150 | } |
| 1100 | 1151 | } |
| 1101 | 1152 | $smcFunc['db_free_result']($request); |
| 1102 | 1153 | |
| 1103 | - if ($simple) |
|
| 1104 | - $boards = array_unique(array_values(array_diff($boards, $deny_boards))); |
|
| 1105 | - else |
|
| 1154 | + if ($simple) { |
|
| 1155 | + $boards = array_unique(array_values(array_diff($boards, $deny_boards))); |
|
| 1156 | + } else |
|
| 1106 | 1157 | { |
| 1107 | 1158 | foreach ($permissions as $permission) |
| 1108 | 1159 | { |
| 1109 | 1160 | // never had it to start with |
| 1110 | - if (empty($boards[$permission])) |
|
| 1111 | - $boards[$permission] = array(); |
|
| 1112 | - else |
|
| 1161 | + if (empty($boards[$permission])) { |
|
| 1162 | + $boards[$permission] = array(); |
|
| 1163 | + } else |
|
| 1113 | 1164 | { |
| 1114 | 1165 | // Or it may have been removed |
| 1115 | 1166 | $deny_boards[$permission] = isset($deny_boards[$permission]) ? $deny_boards[$permission] : array(); |
@@ -1145,10 +1196,11 @@ discard block |
||
| 1145 | 1196 | |
| 1146 | 1197 | |
| 1147 | 1198 | // Moderators are free... |
| 1148 | - if (!allowedTo('moderate_board')) |
|
| 1149 | - $timeLimit = isset($timeOverrides[$error_type]) ? $timeOverrides[$error_type] : $modSettings['spamWaitTime']; |
|
| 1150 | - else |
|
| 1151 | - $timeLimit = 2; |
|
| 1199 | + if (!allowedTo('moderate_board')) { |
|
| 1200 | + $timeLimit = isset($timeOverrides[$error_type]) ? $timeOverrides[$error_type] : $modSettings['spamWaitTime']; |
|
| 1201 | + } else { |
|
| 1202 | + $timeLimit = 2; |
|
| 1203 | + } |
|
| 1152 | 1204 | |
| 1153 | 1205 | call_integration_hook('integrate_spam_protection', array(&$timeOverrides, &$timeLimit)); |
| 1154 | 1206 | |
@@ -1175,8 +1227,9 @@ discard block |
||
| 1175 | 1227 | if ($smcFunc['db_affected_rows']() != 1) |
| 1176 | 1228 | { |
| 1177 | 1229 | // Spammer! You only have to wait a *few* seconds! |
| 1178 | - if (!$only_return_result) |
|
| 1179 | - fatal_lang_error($error_type . '_WaitTime_broken', false, array($timeLimit)); |
|
| 1230 | + if (!$only_return_result) { |
|
| 1231 | + fatal_lang_error($error_type . '_WaitTime_broken', false, array($timeLimit)); |
|
| 1232 | + } |
|
| 1180 | 1233 | |
| 1181 | 1234 | return true; |
| 1182 | 1235 | } |
@@ -1194,11 +1247,13 @@ discard block |
||
| 1194 | 1247 | */ |
| 1195 | 1248 | function secureDirectory($path, $attachments = false) |
| 1196 | 1249 | { |
| 1197 | - if (empty($path)) |
|
| 1198 | - return 'empty_path'; |
|
| 1250 | + if (empty($path)) { |
|
| 1251 | + return 'empty_path'; |
|
| 1252 | + } |
|
| 1199 | 1253 | |
| 1200 | - if (!is_writable($path)) |
|
| 1201 | - return 'path_not_writable'; |
|
| 1254 | + if (!is_writable($path)) { |
|
| 1255 | + return 'path_not_writable'; |
|
| 1256 | + } |
|
| 1202 | 1257 | |
| 1203 | 1258 | $directoryname = basename($path); |
| 1204 | 1259 | |
@@ -1210,9 +1265,9 @@ discard block |
||
| 1210 | 1265 | |
| 1211 | 1266 | RemoveHandler .php .php3 .phtml .cgi .fcgi .pl .fpl .shtml'; |
| 1212 | 1267 | |
| 1213 | - if (file_exists($path . '/.htaccess')) |
|
| 1214 | - $errors[] = 'htaccess_exists'; |
|
| 1215 | - else |
|
| 1268 | + if (file_exists($path . '/.htaccess')) { |
|
| 1269 | + $errors[] = 'htaccess_exists'; |
|
| 1270 | + } else |
|
| 1216 | 1271 | { |
| 1217 | 1272 | $fh = @fopen($path . '/.htaccess', 'w'); |
| 1218 | 1273 | if ($fh) { |
@@ -1224,9 +1279,9 @@ discard block |
||
| 1224 | 1279 | $errors[] = 'htaccess_cannot_create_file'; |
| 1225 | 1280 | } |
| 1226 | 1281 | |
| 1227 | - if (file_exists($path . '/index.php')) |
|
| 1228 | - $errors[] = 'index-php_exists'; |
|
| 1229 | - else |
|
| 1282 | + if (file_exists($path . '/index.php')) { |
|
| 1283 | + $errors[] = 'index-php_exists'; |
|
| 1284 | + } else |
|
| 1230 | 1285 | { |
| 1231 | 1286 | $fh = @fopen($path . '/index.php', 'w'); |
| 1232 | 1287 | if ($fh) { |
@@ -1253,11 +1308,12 @@ discard block |
||
| 1253 | 1308 | $errors[] = 'index-php_cannot_create_file'; |
| 1254 | 1309 | } |
| 1255 | 1310 | |
| 1256 | - if (!empty($errors)) |
|
| 1257 | - return $errors; |
|
| 1258 | - else |
|
| 1259 | - return true; |
|
| 1260 | -} |
|
| 1311 | + if (!empty($errors)) { |
|
| 1312 | + return $errors; |
|
| 1313 | + } else { |
|
| 1314 | + return true; |
|
| 1315 | + } |
|
| 1316 | + } |
|
| 1261 | 1317 | |
| 1262 | 1318 | /** |
| 1263 | 1319 | * This sets the X-Frame-Options header. |
@@ -1270,14 +1326,16 @@ discard block |
||
| 1270 | 1326 | global $modSettings; |
| 1271 | 1327 | |
| 1272 | 1328 | $option = 'SAMEORIGIN'; |
| 1273 | - if (is_null($override) && !empty($modSettings['frame_security'])) |
|
| 1274 | - $option = $modSettings['frame_security']; |
|
| 1275 | - elseif (in_array($override, array('SAMEORIGIN', 'DENY'))) |
|
| 1276 | - $option = $override; |
|
| 1329 | + if (is_null($override) && !empty($modSettings['frame_security'])) { |
|
| 1330 | + $option = $modSettings['frame_security']; |
|
| 1331 | + } elseif (in_array($override, array('SAMEORIGIN', 'DENY'))) { |
|
| 1332 | + $option = $override; |
|
| 1333 | + } |
|
| 1277 | 1334 | |
| 1278 | 1335 | // Don't bother setting the header if we have disabled it. |
| 1279 | - if ($option == 'DISABLE') |
|
| 1280 | - return; |
|
| 1336 | + if ($option == 'DISABLE') { |
|
| 1337 | + return; |
|
| 1338 | + } |
|
| 1281 | 1339 | |
| 1282 | 1340 | // Finally set it. |
| 1283 | 1341 | header('X-Frame-Options: ' . $option); |
@@ -16,8 +16,9 @@ discard block |
||
| 16 | 16 | * @version 2.1 Beta 4 |
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | -if (!defined('SMF')) |
|
| 19 | +if (!defined('SMF')) { |
|
| 20 | 20 | die('No direct access...'); |
| 21 | +} |
|
| 21 | 22 | |
| 22 | 23 | /** |
| 23 | 24 | * Reads a .tar.gz file, filename, in and extracts file(s) from it. |
@@ -67,47 +68,53 @@ discard block |
||
| 67 | 68 | loadLanguage('Packages'); |
| 68 | 69 | |
| 69 | 70 | // This function sorta needs gzinflate! |
| 70 | - if (!function_exists('gzinflate')) |
|
| 71 | - fatal_lang_error('package_no_zlib', 'critical'); |
|
| 71 | + if (!function_exists('gzinflate')) { |
|
| 72 | + fatal_lang_error('package_no_zlib', 'critical'); |
|
| 73 | + } |
|
| 72 | 74 | |
| 73 | 75 | if (substr($gzfilename, 0, 7) == 'http://' || substr($gzfilename, 0, 8) == 'https://') |
| 74 | 76 | { |
| 75 | 77 | $data = fetch_web_data($gzfilename); |
| 76 | 78 | |
| 77 | - if ($data === false) |
|
| 78 | - return false; |
|
| 79 | - } |
|
| 80 | - else |
|
| 79 | + if ($data === false) { |
|
| 80 | + return false; |
|
| 81 | + } |
|
| 82 | + } else |
|
| 81 | 83 | { |
| 82 | 84 | $data = @file_get_contents($gzfilename); |
| 83 | 85 | |
| 84 | - if ($data === false) |
|
| 85 | - return false; |
|
| 86 | + if ($data === false) { |
|
| 87 | + return false; |
|
| 88 | + } |
|
| 86 | 89 | } |
| 87 | 90 | |
| 88 | 91 | umask(0); |
| 89 | - if (!$single_file && $destination !== null && !file_exists($destination)) |
|
| 90 | - mktree($destination, 0777); |
|
| 92 | + if (!$single_file && $destination !== null && !file_exists($destination)) { |
|
| 93 | + mktree($destination, 0777); |
|
| 94 | + } |
|
| 91 | 95 | |
| 92 | 96 | // No signature? |
| 93 | - if (strlen($data) < 2) |
|
| 94 | - return false; |
|
| 97 | + if (strlen($data) < 2) { |
|
| 98 | + return false; |
|
| 99 | + } |
|
| 95 | 100 | |
| 96 | 101 | $id = unpack('H2a/H2b', substr($data, 0, 2)); |
| 97 | 102 | if (strtolower($id['a'] . $id['b']) != '1f8b') |
| 98 | 103 | { |
| 99 | 104 | // Okay, this ain't no tar.gz, but maybe it's a zip file. |
| 100 | - if (substr($data, 0, 2) == 'PK') |
|
| 101 | - return read_zip_file($gzfilename, $destination, $single_file, $overwrite, $files_to_extract); |
|
| 102 | - else |
|
| 103 | - return false; |
|
| 105 | + if (substr($data, 0, 2) == 'PK') { |
|
| 106 | + return read_zip_file($gzfilename, $destination, $single_file, $overwrite, $files_to_extract); |
|
| 107 | + } else { |
|
| 108 | + return false; |
|
| 109 | + } |
|
| 104 | 110 | } |
| 105 | 111 | |
| 106 | 112 | $flags = unpack('Ct/Cf', substr($data, 2, 2)); |
| 107 | 113 | |
| 108 | 114 | // Not deflate! |
| 109 | - if ($flags['t'] != 8) |
|
| 110 | - return false; |
|
| 115 | + if ($flags['t'] != 8) { |
|
| 116 | + return false; |
|
| 117 | + } |
|
| 111 | 118 | $flags = $flags['f']; |
| 112 | 119 | |
| 113 | 120 | $offset = 10; |
@@ -117,18 +124,21 @@ discard block |
||
| 117 | 124 | // @todo Might be mussed. |
| 118 | 125 | if ($flags & 12) |
| 119 | 126 | { |
| 120 | - while ($flags & 8 && $data{$offset++} != "\0") |
|
| 121 | - continue; |
|
| 122 | - while ($flags & 4 && $data{$offset++} != "\0") |
|
| 123 | - continue; |
|
| 127 | + while ($flags & 8 && $data{$offset++} != "\0") { |
|
| 128 | + continue; |
|
| 129 | + } |
|
| 130 | + while ($flags & 4 && $data{$offset++} != "\0") { |
|
| 131 | + continue; |
|
| 132 | + } |
|
| 124 | 133 | } |
| 125 | 134 | |
| 126 | 135 | $crc = unpack('Vcrc32/Visize', substr($data, strlen($data) - 8, 8)); |
| 127 | 136 | $data = @gzinflate(substr($data, $offset, strlen($data) - 8 - $offset)); |
| 128 | 137 | |
| 129 | 138 | // smf_crc32 and crc32 may not return the same results, so we accept either. |
| 130 | - if ($crc['crc32'] != smf_crc32($data) && $crc['crc32'] != crc32($data)) |
|
| 131 | - return false; |
|
| 139 | + if ($crc['crc32'] != smf_crc32($data) && $crc['crc32'] != crc32($data)) { |
|
| 140 | + return false; |
|
| 141 | + } |
|
| 132 | 142 | |
| 133 | 143 | $blocks = strlen($data) / 512 - 1; |
| 134 | 144 | $offset = 0; |
@@ -149,83 +159,98 @@ discard block |
||
| 149 | 159 | |
| 150 | 160 | foreach ($current as $k => $v) |
| 151 | 161 | { |
| 152 | - if (in_array($k, $octdec)) |
|
| 153 | - $current[$k] = octdec(trim($v)); |
|
| 154 | - else |
|
| 155 | - $current[$k] = trim($v); |
|
| 162 | + if (in_array($k, $octdec)) { |
|
| 163 | + $current[$k] = octdec(trim($v)); |
|
| 164 | + } else { |
|
| 165 | + $current[$k] = trim($v); |
|
| 166 | + } |
|
| 156 | 167 | } |
| 157 | 168 | |
| 158 | - if ($current['type'] == 5 && substr($current['filename'], -1) != '/') |
|
| 159 | - $current['filename'] .= '/'; |
|
| 169 | + if ($current['type'] == 5 && substr($current['filename'], -1) != '/') { |
|
| 170 | + $current['filename'] .= '/'; |
|
| 171 | + } |
|
| 160 | 172 | |
| 161 | 173 | $checksum = 256; |
| 162 | - for ($i = 0; $i < 148; $i++) |
|
| 163 | - $checksum += ord($header{$i}); |
|
| 164 | - for ($i = 156; $i < 512; $i++) |
|
| 165 | - $checksum += ord($header{$i}); |
|
| 174 | + for ($i = 0; $i < 148; $i++) { |
|
| 175 | + $checksum += ord($header{$i}); |
|
| 176 | + } |
|
| 177 | + for ($i = 156; $i < 512; $i++) { |
|
| 178 | + $checksum += ord($header{$i}); |
|
| 179 | + } |
|
| 166 | 180 | |
| 167 | - if ($current['checksum'] != $checksum) |
|
| 168 | - break; |
|
| 181 | + if ($current['checksum'] != $checksum) { |
|
| 182 | + break; |
|
| 183 | + } |
|
| 169 | 184 | |
| 170 | 185 | $size = ceil($current['size'] / 512); |
| 171 | 186 | $current['data'] = substr($data, ++$offset << 9, $current['size']); |
| 172 | 187 | $offset += $size; |
| 173 | 188 | |
| 174 | 189 | // Not a directory and doesn't exist already... |
| 175 | - if (substr($current['filename'], -1, 1) != '/' && !file_exists($destination . '/' . $current['filename'])) |
|
| 176 | - $write_this = true; |
|
| 190 | + if (substr($current['filename'], -1, 1) != '/' && !file_exists($destination . '/' . $current['filename'])) { |
|
| 191 | + $write_this = true; |
|
| 192 | + } |
|
| 177 | 193 | // File exists... check if it is newer. |
| 178 | - elseif (substr($current['filename'], -1, 1) != '/') |
|
| 179 | - $write_this = $overwrite || filemtime($destination . '/' . $current['filename']) < $current['mtime']; |
|
| 194 | + elseif (substr($current['filename'], -1, 1) != '/') { |
|
| 195 | + $write_this = $overwrite || filemtime($destination . '/' . $current['filename']) < $current['mtime']; |
|
| 196 | + } |
|
| 180 | 197 | // Folder... create. |
| 181 | 198 | elseif ($destination !== null && !$single_file) |
| 182 | 199 | { |
| 183 | 200 | // Protect from accidental parent directory writing... |
| 184 | 201 | $current['filename'] = strtr($current['filename'], array('../' => '', '/..' => '')); |
| 185 | 202 | |
| 186 | - if (!file_exists($destination . '/' . $current['filename'])) |
|
| 187 | - mktree($destination . '/' . $current['filename'], 0777); |
|
| 203 | + if (!file_exists($destination . '/' . $current['filename'])) { |
|
| 204 | + mktree($destination . '/' . $current['filename'], 0777); |
|
| 205 | + } |
|
| 188 | 206 | $write_this = false; |
| 207 | + } else { |
|
| 208 | + $write_this = false; |
|
| 189 | 209 | } |
| 190 | - else |
|
| 191 | - $write_this = false; |
|
| 192 | 210 | |
| 193 | 211 | if ($write_this && $destination !== null) |
| 194 | 212 | { |
| 195 | - if (strpos($current['filename'], '/') !== false && !$single_file) |
|
| 196 | - mktree($destination . '/' . dirname($current['filename']), 0777); |
|
| 213 | + if (strpos($current['filename'], '/') !== false && !$single_file) { |
|
| 214 | + mktree($destination . '/' . dirname($current['filename']), 0777); |
|
| 215 | + } |
|
| 197 | 216 | |
| 198 | 217 | // Is this the file we're looking for? |
| 199 | - if ($single_file && ($destination == $current['filename'] || $destination == '*/' . basename($current['filename']))) |
|
| 200 | - return $current['data']; |
|
| 218 | + if ($single_file && ($destination == $current['filename'] || $destination == '*/' . basename($current['filename']))) { |
|
| 219 | + return $current['data']; |
|
| 220 | + } |
|
| 201 | 221 | // If we're looking for another file, keep going. |
| 202 | - elseif ($single_file) |
|
| 203 | - continue; |
|
| 222 | + elseif ($single_file) { |
|
| 223 | + continue; |
|
| 224 | + } |
|
| 204 | 225 | // Looking for restricted files? |
| 205 | - elseif ($files_to_extract !== null && !in_array($current['filename'], $files_to_extract)) |
|
| 206 | - continue; |
|
| 226 | + elseif ($files_to_extract !== null && !in_array($current['filename'], $files_to_extract)) { |
|
| 227 | + continue; |
|
| 228 | + } |
|
| 207 | 229 | |
| 208 | 230 | package_put_contents($destination . '/' . $current['filename'], $current['data']); |
| 209 | 231 | } |
| 210 | 232 | |
| 211 | - if (substr($current['filename'], -1, 1) != '/') |
|
| 212 | - $return[] = array( |
|
| 233 | + if (substr($current['filename'], -1, 1) != '/') { |
|
| 234 | + $return[] = array( |
|
| 213 | 235 | 'filename' => $current['filename'], |
| 214 | 236 | 'md5' => md5($current['data']), |
| 215 | 237 | 'preview' => substr($current['data'], 0, 100), |
| 216 | 238 | 'size' => $current['size'], |
| 217 | 239 | 'skipped' => false |
| 218 | 240 | ); |
| 241 | + } |
|
| 219 | 242 | } |
| 220 | 243 | |
| 221 | - if ($destination !== null && !$single_file) |
|
| 222 | - package_flush_cache(); |
|
| 244 | + if ($destination !== null && !$single_file) { |
|
| 245 | + package_flush_cache(); |
|
| 246 | + } |
|
| 223 | 247 | |
| 224 | - if ($single_file) |
|
| 225 | - return false; |
|
| 226 | - else |
|
| 227 | - return $return; |
|
| 228 | -} |
|
| 248 | + if ($single_file) { |
|
| 249 | + return false; |
|
| 250 | + } else { |
|
| 251 | + return $return; |
|
| 252 | + } |
|
| 253 | + } |
|
| 229 | 254 | |
| 230 | 255 | /** |
| 231 | 256 | * Extract zip data. A functional copy of {@list read_zip_data()}. |
@@ -254,65 +279,74 @@ discard block |
||
| 254 | 279 | { |
| 255 | 280 | $i = $iterator->getSubPathname(); |
| 256 | 281 | // If this is a file, and it doesn't exist.... happy days! |
| 257 | - if (substr($i, -1) != '/' && !file_exists($destination . '/' . $i)) |
|
| 258 | - $write_this = true; |
|
| 282 | + if (substr($i, -1) != '/' && !file_exists($destination . '/' . $i)) { |
|
| 283 | + $write_this = true; |
|
| 284 | + } |
|
| 259 | 285 | // If the file exists, we may not want to overwrite it. |
| 260 | - elseif (substr($i, -1) != '/') |
|
| 261 | - $write_this = $overwrite; |
|
| 262 | - else |
|
| 263 | - $write_this = false; |
|
| 286 | + elseif (substr($i, -1) != '/') { |
|
| 287 | + $write_this = $overwrite; |
|
| 288 | + } else { |
|
| 289 | + $write_this = false; |
|
| 290 | + } |
|
| 264 | 291 | |
| 265 | 292 | // Get the actual compressed data. |
| 266 | - if (!$file_info->isDir()) |
|
| 267 | - $file_data = file_get_contents($file_info); |
|
| 268 | - elseif ($destination !== null && !$single_file) |
|
| 293 | + if (!$file_info->isDir()) { |
|
| 294 | + $file_data = file_get_contents($file_info); |
|
| 295 | + } elseif ($destination !== null && !$single_file) |
|
| 269 | 296 | { |
| 270 | 297 | // Folder... create. |
| 271 | - if (!file_exists($destination . '/' . $i)) |
|
| 272 | - mktree($destination . '/' . $i, 0777); |
|
| 298 | + if (!file_exists($destination . '/' . $i)) { |
|
| 299 | + mktree($destination . '/' . $i, 0777); |
|
| 300 | + } |
|
| 273 | 301 | $file_data = null; |
| 302 | + } else { |
|
| 303 | + $file_data = null; |
|
| 274 | 304 | } |
| 275 | - else |
|
| 276 | - $file_data = null; |
|
| 277 | 305 | |
| 278 | 306 | // Okay! We can write this file, looks good from here... |
| 279 | 307 | if ($write_this && $destination !== null) |
| 280 | 308 | { |
| 281 | - if (!$single_file && !is_dir($destination . '/' . dirname($i))) |
|
| 282 | - mktree($destination . '/' . dirname($i), 0777); |
|
| 309 | + if (!$single_file && !is_dir($destination . '/' . dirname($i))) { |
|
| 310 | + mktree($destination . '/' . dirname($i), 0777); |
|
| 311 | + } |
|
| 283 | 312 | |
| 284 | 313 | // If we're looking for a specific file, and this is it... ka-bam, baby. |
| 285 | - if ($single_file && ($destination == $i || $destination == '*/' . basename($i))) |
|
| 286 | - return $file_data; |
|
| 314 | + if ($single_file && ($destination == $i || $destination == '*/' . basename($i))) { |
|
| 315 | + return $file_data; |
|
| 316 | + } |
|
| 287 | 317 | // Oh? Another file. Fine. You don't like this file, do you? I know how it is. Yeah... just go away. No, don't apologize. I know this file's just not *good enough* for you. |
| 288 | - elseif ($single_file) |
|
| 289 | - continue; |
|
| 318 | + elseif ($single_file) { |
|
| 319 | + continue; |
|
| 320 | + } |
|
| 290 | 321 | // Don't really want this? |
| 291 | - elseif ($files_to_extract !== null && !in_array($i, $files_to_extract)) |
|
| 292 | - continue; |
|
| 322 | + elseif ($files_to_extract !== null && !in_array($i, $files_to_extract)) { |
|
| 323 | + continue; |
|
| 324 | + } |
|
| 293 | 325 | |
| 294 | 326 | package_put_contents($destination . '/' . $i, $file_data); |
| 295 | 327 | } |
| 296 | 328 | |
| 297 | - if (substr($i, -1, 1) != '/') |
|
| 298 | - $return[] = array( |
|
| 329 | + if (substr($i, -1, 1) != '/') { |
|
| 330 | + $return[] = array( |
|
| 299 | 331 | 'filename' => $i, |
| 300 | 332 | 'md5' => md5($file_data), |
| 301 | 333 | 'preview' => substr($file_data, 0, 100), |
| 302 | 334 | 'size' => strlen($file_data), |
| 303 | 335 | 'skipped' => false |
| 304 | 336 | ); |
| 337 | + } |
|
| 305 | 338 | } |
| 306 | 339 | |
| 307 | - if ($destination !== null && !$single_file) |
|
| 308 | - package_flush_cache(); |
|
| 340 | + if ($destination !== null && !$single_file) { |
|
| 341 | + package_flush_cache(); |
|
| 342 | + } |
|
| 309 | 343 | |
| 310 | - if ($single_file) |
|
| 311 | - return false; |
|
| 312 | - else |
|
| 313 | - return $return; |
|
| 314 | - } |
|
| 315 | - catch (Exception $e) |
|
| 344 | + if ($single_file) { |
|
| 345 | + return false; |
|
| 346 | + } else { |
|
| 347 | + return $return; |
|
| 348 | + } |
|
| 349 | + } catch (Exception $e) |
|
| 316 | 350 | { |
| 317 | 351 | return false; |
| 318 | 352 | } |
@@ -334,13 +368,15 @@ discard block |
||
| 334 | 368 | function read_zip_data($data, $destination, $single_file = false, $overwrite = false, $files_to_extract = null) |
| 335 | 369 | { |
| 336 | 370 | umask(0); |
| 337 | - if ($destination !== null && !file_exists($destination) && !$single_file) |
|
| 338 | - mktree($destination, 0777); |
|
| 371 | + if ($destination !== null && !file_exists($destination) && !$single_file) { |
|
| 372 | + mktree($destination, 0777); |
|
| 373 | + } |
|
| 339 | 374 | |
| 340 | 375 | // Look for the end of directory signature 0x06054b50 |
| 341 | 376 | $data_ecr = explode("\x50\x4b\x05\x06", $data); |
| 342 | - if (!isset($data_ecr[1])) |
|
| 343 | - return false; |
|
| 377 | + if (!isset($data_ecr[1])) { |
|
| 378 | + return false; |
|
| 379 | + } |
|
| 344 | 380 | |
| 345 | 381 | $return = array(); |
| 346 | 382 | |
@@ -355,8 +391,9 @@ discard block |
||
| 355 | 391 | array_shift($file_sections); |
| 356 | 392 | |
| 357 | 393 | // sections and count from the signature must match or the zip file is bad |
| 358 | - if (count($file_sections) != $zip_info['files']) |
|
| 359 | - return false; |
|
| 394 | + if (count($file_sections) != $zip_info['files']) { |
|
| 395 | + return false; |
|
| 396 | + } |
|
| 360 | 397 | |
| 361 | 398 | // go though each file in the archive |
| 362 | 399 | foreach ($file_sections as $data) |
@@ -378,68 +415,79 @@ discard block |
||
| 378 | 415 | } |
| 379 | 416 | |
| 380 | 417 | // If this is a file, and it doesn't exist.... happy days! |
| 381 | - if (substr($file_info['filename'], -1) != '/' && !file_exists($destination . '/' . $file_info['filename'])) |
|
| 382 | - $write_this = true; |
|
| 418 | + if (substr($file_info['filename'], -1) != '/' && !file_exists($destination . '/' . $file_info['filename'])) { |
|
| 419 | + $write_this = true; |
|
| 420 | + } |
|
| 383 | 421 | // If the file exists, we may not want to overwrite it. |
| 384 | - elseif (substr($file_info['filename'], -1) != '/') |
|
| 385 | - $write_this = $overwrite; |
|
| 422 | + elseif (substr($file_info['filename'], -1) != '/') { |
|
| 423 | + $write_this = $overwrite; |
|
| 424 | + } |
|
| 386 | 425 | // This is a directory, so we're gonna want to create it. (probably...) |
| 387 | 426 | elseif ($destination !== null && !$single_file) |
| 388 | 427 | { |
| 389 | 428 | // Just a little accident prevention, don't mind me. |
| 390 | 429 | $file_info['filename'] = strtr($file_info['filename'], array('../' => '', '/..' => '')); |
| 391 | 430 | |
| 392 | - if (!file_exists($destination . '/' . $file_info['filename'])) |
|
| 393 | - mktree($destination . '/' . $file_info['filename'], 0777); |
|
| 431 | + if (!file_exists($destination . '/' . $file_info['filename'])) { |
|
| 432 | + mktree($destination . '/' . $file_info['filename'], 0777); |
|
| 433 | + } |
|
| 394 | 434 | $write_this = false; |
| 435 | + } else { |
|
| 436 | + $write_this = false; |
|
| 395 | 437 | } |
| 396 | - else |
|
| 397 | - $write_this = false; |
|
| 398 | 438 | |
| 399 | 439 | // Get the actual compressed data. |
| 400 | 440 | $file_info['data'] = substr($data, 26 + $file_info['filename_length'] + $file_info['extrafield_length']); |
| 401 | 441 | |
| 402 | 442 | // Only inflate it if we need to ;) |
| 403 | - if (!empty($file_info['compress_method']) || ($file_info['compressed_size'] != $file_info['size'])) |
|
| 404 | - $file_info['data'] = gzinflate($file_info['data']); |
|
| 443 | + if (!empty($file_info['compress_method']) || ($file_info['compressed_size'] != $file_info['size'])) { |
|
| 444 | + $file_info['data'] = gzinflate($file_info['data']); |
|
| 445 | + } |
|
| 405 | 446 | |
| 406 | 447 | // Okay! We can write this file, looks good from here... |
| 407 | 448 | if ($write_this && $destination !== null) |
| 408 | 449 | { |
| 409 | - if ((strpos($file_info['filename'], '/') !== false && !$single_file) || (!$single_file && !is_dir($file_info['dir']))) |
|
| 410 | - mktree($file_info['dir'], 0777); |
|
| 450 | + if ((strpos($file_info['filename'], '/') !== false && !$single_file) || (!$single_file && !is_dir($file_info['dir']))) { |
|
| 451 | + mktree($file_info['dir'], 0777); |
|
| 452 | + } |
|
| 411 | 453 | |
| 412 | 454 | // If we're looking for a specific file, and this is it... ka-bam, baby. |
| 413 | - if ($single_file && ($destination == $file_info['filename'] || $destination == '*/' . basename($file_info['filename']))) |
|
| 414 | - return $file_info['data']; |
|
| 455 | + if ($single_file && ($destination == $file_info['filename'] || $destination == '*/' . basename($file_info['filename']))) { |
|
| 456 | + return $file_info['data']; |
|
| 457 | + } |
|
| 415 | 458 | // Oh? Another file. Fine. You don't like this file, do you? I know how it is. Yeah... just go away. No, don't apologize. I know this file's just not *good enough* for you. |
| 416 | - elseif ($single_file) |
|
| 417 | - continue; |
|
| 459 | + elseif ($single_file) { |
|
| 460 | + continue; |
|
| 461 | + } |
|
| 418 | 462 | // Don't really want this? |
| 419 | - elseif ($files_to_extract !== null && !in_array($file_info['filename'], $files_to_extract)) |
|
| 420 | - continue; |
|
| 463 | + elseif ($files_to_extract !== null && !in_array($file_info['filename'], $files_to_extract)) { |
|
| 464 | + continue; |
|
| 465 | + } |
|
| 421 | 466 | |
| 422 | 467 | package_put_contents($destination . '/' . $file_info['filename'], $file_info['data']); |
| 423 | 468 | } |
| 424 | 469 | |
| 425 | - if (substr($file_info['filename'], -1, 1) != '/') |
|
| 426 | - $return[] = array( |
|
| 470 | + if (substr($file_info['filename'], -1, 1) != '/') { |
|
| 471 | + $return[] = array( |
|
| 427 | 472 | 'filename' => $file_info['filename'], |
| 428 | 473 | 'md5' => md5($file_info['data']), |
| 429 | 474 | 'preview' => substr($file_info['data'], 0, 100), |
| 430 | 475 | 'size' => $file_info['size'], |
| 431 | 476 | 'skipped' => false |
| 432 | 477 | ); |
| 478 | + } |
|
| 433 | 479 | } |
| 434 | 480 | |
| 435 | - if ($destination !== null && !$single_file) |
|
| 436 | - package_flush_cache(); |
|
| 481 | + if ($destination !== null && !$single_file) { |
|
| 482 | + package_flush_cache(); |
|
| 483 | + } |
|
| 437 | 484 | |
| 438 | - if ($single_file) |
|
| 439 | - return false; |
|
| 440 | - else |
|
| 441 | - return $return; |
|
| 442 | -} |
|
| 485 | + if ($single_file) { |
|
| 486 | + return false; |
|
| 487 | + } else { |
|
| 488 | + return $return; |
|
| 489 | + } |
|
| 490 | + } |
|
| 443 | 491 | |
| 444 | 492 | /** |
| 445 | 493 | * Checks the existence of a remote file since file_exists() does not do remote. |
@@ -451,14 +499,16 @@ discard block |
||
| 451 | 499 | { |
| 452 | 500 | $a_url = parse_url($url); |
| 453 | 501 | |
| 454 | - if (!isset($a_url['scheme'])) |
|
| 455 | - return false; |
|
| 502 | + if (!isset($a_url['scheme'])) { |
|
| 503 | + return false; |
|
| 504 | + } |
|
| 456 | 505 | |
| 457 | 506 | // Attempt to connect... |
| 458 | 507 | $temp = ''; |
| 459 | 508 | $fid = fsockopen($a_url['host'], !isset($a_url['port']) ? 80 : $a_url['port'], $temp, $temp, 8); |
| 460 | - if (!$fid) |
|
| 461 | - return false; |
|
| 509 | + if (!$fid) { |
|
| 510 | + return false; |
|
| 511 | + } |
|
| 462 | 512 | |
| 463 | 513 | fputs($fid, 'HEAD ' . $a_url['path'] . ' HTTP/1.0' . "\r\n" . 'Host: ' . $a_url['host'] . "\r\n\r\n"); |
| 464 | 514 | $head = fread($fid, 1024); |
@@ -493,8 +543,9 @@ discard block |
||
| 493 | 543 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 494 | 544 | { |
| 495 | 545 | // Already found this? If so don't add it twice! |
| 496 | - if (in_array($row['package_id'], $found)) |
|
| 497 | - continue; |
|
| 546 | + if (in_array($row['package_id'], $found)) { |
|
| 547 | + continue; |
|
| 548 | + } |
|
| 498 | 549 | |
| 499 | 550 | $found[] = $row['package_id']; |
| 500 | 551 | |
@@ -529,19 +580,21 @@ discard block |
||
| 529 | 580 | global $sourcedir, $packagesdir; |
| 530 | 581 | |
| 531 | 582 | // Extract package-info.xml from downloaded file. (*/ is used because it could be in any directory.) |
| 532 | - if (strpos($gzfilename, 'http://') !== false || strpos($gzfilename, 'https://') !== false) |
|
| 533 | - $packageInfo = read_tgz_data($gzfilename, 'package-info.xml', true); |
|
| 534 | - else |
|
| 583 | + if (strpos($gzfilename, 'http://') !== false || strpos($gzfilename, 'https://') !== false) { |
|
| 584 | + $packageInfo = read_tgz_data($gzfilename, 'package-info.xml', true); |
|
| 585 | + } else |
|
| 535 | 586 | { |
| 536 | - if (!file_exists($packagesdir . '/' . $gzfilename)) |
|
| 537 | - return 'package_get_error_not_found'; |
|
| 587 | + if (!file_exists($packagesdir . '/' . $gzfilename)) { |
|
| 588 | + return 'package_get_error_not_found'; |
|
| 589 | + } |
|
| 538 | 590 | |
| 539 | - if (is_file($packagesdir . '/' . $gzfilename)) |
|
| 540 | - $packageInfo = read_tgz_file($packagesdir . '/' . $gzfilename, '*/package-info.xml', true); |
|
| 541 | - elseif (file_exists($packagesdir . '/' . $gzfilename . '/package-info.xml')) |
|
| 542 | - $packageInfo = file_get_contents($packagesdir . '/' . $gzfilename . '/package-info.xml'); |
|
| 543 | - else |
|
| 544 | - return 'package_get_error_missing_xml'; |
|
| 591 | + if (is_file($packagesdir . '/' . $gzfilename)) { |
|
| 592 | + $packageInfo = read_tgz_file($packagesdir . '/' . $gzfilename, '*/package-info.xml', true); |
|
| 593 | + } elseif (file_exists($packagesdir . '/' . $gzfilename . '/package-info.xml')) { |
|
| 594 | + $packageInfo = file_get_contents($packagesdir . '/' . $gzfilename . '/package-info.xml'); |
|
| 595 | + } else { |
|
| 596 | + return 'package_get_error_missing_xml'; |
|
| 597 | + } |
|
| 545 | 598 | } |
| 546 | 599 | |
| 547 | 600 | // Nothing? |
@@ -549,10 +602,11 @@ discard block |
||
| 549 | 602 | { |
| 550 | 603 | // Perhaps they are trying to install a theme, lets tell them nicely this is the wrong function |
| 551 | 604 | $packageInfo = read_tgz_file($packagesdir . '/' . $gzfilename, '*/theme_info.xml', true); |
| 552 | - if (!empty($packageInfo)) |
|
| 553 | - return 'package_get_error_is_theme'; |
|
| 554 | - else |
|
| 555 | - return 'package_get_error_is_zero'; |
|
| 605 | + if (!empty($packageInfo)) { |
|
| 606 | + return 'package_get_error_is_theme'; |
|
| 607 | + } else { |
|
| 608 | + return 'package_get_error_is_zero'; |
|
| 609 | + } |
|
| 556 | 610 | } |
| 557 | 611 | |
| 558 | 612 | // Parse package-info.xml into an xmlArray. |
@@ -560,8 +614,9 @@ discard block |
||
| 560 | 614 | $packageInfo = new xmlArray($packageInfo); |
| 561 | 615 | |
| 562 | 616 | // @todo Error message of some sort? |
| 563 | - if (!$packageInfo->exists('package-info[0]')) |
|
| 564 | - return 'package_get_error_packageinfo_corrupt'; |
|
| 617 | + if (!$packageInfo->exists('package-info[0]')) { |
|
| 618 | + return 'package_get_error_packageinfo_corrupt'; |
|
| 619 | + } |
|
| 565 | 620 | |
| 566 | 621 | $packageInfo = $packageInfo->path('package-info[0]'); |
| 567 | 622 | |
@@ -580,8 +635,9 @@ discard block |
||
| 580 | 635 | } |
| 581 | 636 | } |
| 582 | 637 | |
| 583 | - if (!isset($package['type'])) |
|
| 584 | - $package['type'] = 'modification'; |
|
| 638 | + if (!isset($package['type'])) { |
|
| 639 | + $package['type'] = 'modification'; |
|
| 640 | + } |
|
| 585 | 641 | |
| 586 | 642 | return $package; |
| 587 | 643 | } |
@@ -634,15 +690,14 @@ discard block |
||
| 634 | 690 | { |
| 635 | 691 | $ftp_file = strtr($file, array($_SESSION['pack_ftp']['root'] => '')); |
| 636 | 692 | $package_ftp->chmod($ftp_file, $perms); |
| 693 | + } else { |
|
| 694 | + smf_chmod($file, $perms); |
|
| 637 | 695 | } |
| 638 | - else |
|
| 639 | - smf_chmod($file, $perms); |
|
| 640 | 696 | |
| 641 | 697 | $new_permissions = @fileperms($file); |
| 642 | 698 | $result = $new_permissions == $perms ? 'success' : 'failure'; |
| 643 | 699 | unset($_SESSION['pack_ftp']['original_perms'][$file]); |
| 644 | - } |
|
| 645 | - elseif ($do_change) |
|
| 700 | + } elseif ($do_change) |
|
| 646 | 701 | { |
| 647 | 702 | $new_permissions = ''; |
| 648 | 703 | $result = 'skipped'; |
@@ -758,8 +813,7 @@ discard block |
||
| 758 | 813 | |
| 759 | 814 | $context['sub_template'] = 'show_list'; |
| 760 | 815 | $context['default_list'] = 'restore_file_permissions'; |
| 761 | - } |
|
| 762 | - else |
|
| 816 | + } else |
|
| 763 | 817 | { |
| 764 | 818 | unset($listOptions['columns']['result']); |
| 765 | 819 | } |
@@ -769,12 +823,14 @@ discard block |
||
| 769 | 823 | createList($listOptions); |
| 770 | 824 | |
| 771 | 825 | // If we just restored permissions then whereever we are, we are now done and dusted. |
| 772 | - if (!empty($_POST['restore_perms'])) |
|
| 773 | - obExit(); |
|
| 826 | + if (!empty($_POST['restore_perms'])) { |
|
| 827 | + obExit(); |
|
| 828 | + } |
|
| 774 | 829 | } |
| 775 | 830 | // Otherwise, it's entirely irrelevant? |
| 776 | - elseif ($restore_write_status) |
|
| 777 | - return true; |
|
| 831 | + elseif ($restore_write_status) { |
|
| 832 | + return true; |
|
| 833 | + } |
|
| 778 | 834 | |
| 779 | 835 | // This is where we report what we got up to. |
| 780 | 836 | $return_data = array( |
@@ -812,11 +868,12 @@ discard block |
||
| 812 | 868 | if (!in_array($_POST['ftp_path'], array('', '/'))) |
| 813 | 869 | { |
| 814 | 870 | $ftp_root = strtr($boarddir, array($_POST['ftp_path'] => '')); |
| 815 | - if (substr($ftp_root, -1) == '/' && ($_POST['ftp_path'] == '' || substr($_POST['ftp_path'], 0, 1) == '/')) |
|
| 816 | - $ftp_root = substr($ftp_root, 0, -1); |
|
| 871 | + if (substr($ftp_root, -1) == '/' && ($_POST['ftp_path'] == '' || substr($_POST['ftp_path'], 0, 1) == '/')) { |
|
| 872 | + $ftp_root = substr($ftp_root, 0, -1); |
|
| 873 | + } |
|
| 874 | + } else { |
|
| 875 | + $ftp_root = $boarddir; |
|
| 817 | 876 | } |
| 818 | - else |
|
| 819 | - $ftp_root = $boarddir; |
|
| 820 | 877 | |
| 821 | 878 | $_SESSION['pack_ftp'] = array( |
| 822 | 879 | 'server' => $_POST['ftp_server'], |
@@ -828,8 +885,9 @@ discard block |
||
| 828 | 885 | 'connected' => true, |
| 829 | 886 | ); |
| 830 | 887 | |
| 831 | - if (!isset($modSettings['package_path']) || $modSettings['package_path'] != $_POST['ftp_path']) |
|
| 832 | - updateSettings(array('package_path' => $_POST['ftp_path'])); |
|
| 888 | + if (!isset($modSettings['package_path']) || $modSettings['package_path'] != $_POST['ftp_path']) { |
|
| 889 | + updateSettings(array('package_path' => $_POST['ftp_path'])); |
|
| 890 | + } |
|
| 833 | 891 | |
| 834 | 892 | // This is now the primary connection. |
| 835 | 893 | $package_ftp = $ftp; |
@@ -842,12 +900,13 @@ discard block |
||
| 842 | 900 | foreach ($chmodFiles as $k => $file) |
| 843 | 901 | { |
| 844 | 902 | // Sometimes this can somehow happen maybe? |
| 845 | - if (empty($file)) |
|
| 846 | - unset($chmodFiles[$k]); |
|
| 903 | + if (empty($file)) { |
|
| 904 | + unset($chmodFiles[$k]); |
|
| 905 | + } |
|
| 847 | 906 | // Already writable? |
| 848 | - elseif (@is_writable($file)) |
|
| 849 | - $return_data['files']['writable'][] = $file; |
|
| 850 | - else |
|
| 907 | + elseif (@is_writable($file)) { |
|
| 908 | + $return_data['files']['writable'][] = $file; |
|
| 909 | + } else |
|
| 851 | 910 | { |
| 852 | 911 | // Now try to change that. |
| 853 | 912 | $return_data['files'][package_chmod($file, 'writable', true) ? 'writable' : 'notwritable'][] = $file; |
@@ -864,19 +923,21 @@ discard block |
||
| 864 | 923 | { |
| 865 | 924 | require_once($sourcedir . '/Class-Package.php'); |
| 866 | 925 | $ftp = new ftp_connection(null); |
| 926 | + } elseif ($ftp->error !== false && !isset($ftp_error)) { |
|
| 927 | + $ftp_error = $ftp->last_message === null ? '' : $ftp->last_message; |
|
| 867 | 928 | } |
| 868 | - elseif ($ftp->error !== false && !isset($ftp_error)) |
|
| 869 | - $ftp_error = $ftp->last_message === null ? '' : $ftp->last_message; |
|
| 870 | 929 | |
| 871 | 930 | list ($username, $detect_path, $found_path) = $ftp->detect_path($boarddir); |
| 872 | 931 | |
| 873 | - if ($found_path) |
|
| 874 | - $_POST['ftp_path'] = $detect_path; |
|
| 875 | - elseif (!isset($_POST['ftp_path'])) |
|
| 876 | - $_POST['ftp_path'] = isset($modSettings['package_path']) ? $modSettings['package_path'] : $detect_path; |
|
| 932 | + if ($found_path) { |
|
| 933 | + $_POST['ftp_path'] = $detect_path; |
|
| 934 | + } elseif (!isset($_POST['ftp_path'])) { |
|
| 935 | + $_POST['ftp_path'] = isset($modSettings['package_path']) ? $modSettings['package_path'] : $detect_path; |
|
| 936 | + } |
|
| 877 | 937 | |
| 878 | - if (!isset($_POST['ftp_username'])) |
|
| 879 | - $_POST['ftp_username'] = $username; |
|
| 938 | + if (!isset($_POST['ftp_username'])) { |
|
| 939 | + $_POST['ftp_username'] = $username; |
|
| 940 | + } |
|
| 880 | 941 | } |
| 881 | 942 | |
| 882 | 943 | $context['package_ftp'] = array( |
@@ -889,8 +950,9 @@ discard block |
||
| 889 | 950 | ); |
| 890 | 951 | |
| 891 | 952 | // Which files failed? |
| 892 | - if (!isset($context['notwritable_files'])) |
|
| 893 | - $context['notwritable_files'] = array(); |
|
| 953 | + if (!isset($context['notwritable_files'])) { |
|
| 954 | + $context['notwritable_files'] = array(); |
|
| 955 | + } |
|
| 894 | 956 | $context['notwritable_files'] = array_merge($context['notwritable_files'], $return_data['files']['notwritable']); |
| 895 | 957 | |
| 896 | 958 | // Sent here to die? |
@@ -923,40 +985,48 @@ discard block |
||
| 923 | 985 | foreach ($files as $k => $file) |
| 924 | 986 | { |
| 925 | 987 | // If this file doesn't exist, then we actually want to look at the directory, no? |
| 926 | - if (!file_exists($file)) |
|
| 927 | - $file = dirname($file); |
|
| 988 | + if (!file_exists($file)) { |
|
| 989 | + $file = dirname($file); |
|
| 990 | + } |
|
| 928 | 991 | |
| 929 | 992 | // This looks odd, but it's an attempt to work around PHP suExec. |
| 930 | - if (!@is_writable($file)) |
|
| 931 | - smf_chmod($file, 0755); |
|
| 932 | - if (!@is_writable($file)) |
|
| 933 | - smf_chmod($file, 0777); |
|
| 934 | - if (!@is_writable(dirname($file))) |
|
| 935 | - smf_chmod($file, 0755); |
|
| 936 | - if (!@is_writable(dirname($file))) |
|
| 937 | - smf_chmod($file, 0777); |
|
| 993 | + if (!@is_writable($file)) { |
|
| 994 | + smf_chmod($file, 0755); |
|
| 995 | + } |
|
| 996 | + if (!@is_writable($file)) { |
|
| 997 | + smf_chmod($file, 0777); |
|
| 998 | + } |
|
| 999 | + if (!@is_writable(dirname($file))) { |
|
| 1000 | + smf_chmod($file, 0755); |
|
| 1001 | + } |
|
| 1002 | + if (!@is_writable(dirname($file))) { |
|
| 1003 | + smf_chmod($file, 0777); |
|
| 1004 | + } |
|
| 938 | 1005 | |
| 939 | 1006 | $fp = is_dir($file) ? @opendir($file) : @fopen($file, 'rb'); |
| 940 | 1007 | if (@is_writable($file) && $fp) |
| 941 | 1008 | { |
| 942 | 1009 | unset($files[$k]); |
| 943 | - if (!is_dir($file)) |
|
| 944 | - fclose($fp); |
|
| 945 | - else |
|
| 946 | - closedir($fp); |
|
| 1010 | + if (!is_dir($file)) { |
|
| 1011 | + fclose($fp); |
|
| 1012 | + } else { |
|
| 1013 | + closedir($fp); |
|
| 1014 | + } |
|
| 947 | 1015 | } |
| 948 | 1016 | } |
| 949 | 1017 | |
| 950 | 1018 | // No FTP required! |
| 951 | - if (empty($files)) |
|
| 952 | - return array(); |
|
| 1019 | + if (empty($files)) { |
|
| 1020 | + return array(); |
|
| 1021 | + } |
|
| 953 | 1022 | } |
| 954 | 1023 | |
| 955 | 1024 | // They've opted to not use FTP, and try anyway. |
| 956 | 1025 | if (isset($_SESSION['pack_ftp']) && $_SESSION['pack_ftp'] == false) |
| 957 | 1026 | { |
| 958 | - if ($files === null) |
|
| 959 | - return array(); |
|
| 1027 | + if ($files === null) { |
|
| 1028 | + return array(); |
|
| 1029 | + } |
|
| 960 | 1030 | |
| 961 | 1031 | foreach ($files as $k => $file) |
| 962 | 1032 | { |
@@ -968,26 +1038,29 @@ discard block |
||
| 968 | 1038 | smf_chmod($file, 0755); |
| 969 | 1039 | } |
| 970 | 1040 | |
| 971 | - if (!@is_writable($file)) |
|
| 972 | - smf_chmod($file, 0777); |
|
| 973 | - if (!@is_writable(dirname($file))) |
|
| 974 | - smf_chmod(dirname($file), 0777); |
|
| 1041 | + if (!@is_writable($file)) { |
|
| 1042 | + smf_chmod($file, 0777); |
|
| 1043 | + } |
|
| 1044 | + if (!@is_writable(dirname($file))) { |
|
| 1045 | + smf_chmod(dirname($file), 0777); |
|
| 1046 | + } |
|
| 975 | 1047 | |
| 976 | - if (@is_writable($file)) |
|
| 977 | - unset($files[$k]); |
|
| 1048 | + if (@is_writable($file)) { |
|
| 1049 | + unset($files[$k]); |
|
| 1050 | + } |
|
| 978 | 1051 | } |
| 979 | 1052 | |
| 980 | 1053 | return $files; |
| 981 | - } |
|
| 982 | - elseif (isset($_SESSION['pack_ftp'])) |
|
| 1054 | + } elseif (isset($_SESSION['pack_ftp'])) |
|
| 983 | 1055 | { |
| 984 | 1056 | // Load the file containing the ftp_connection class. |
| 985 | 1057 | require_once($sourcedir . '/Class-Package.php'); |
| 986 | 1058 | |
| 987 | 1059 | $package_ftp = new ftp_connection($_SESSION['pack_ftp']['server'], $_SESSION['pack_ftp']['port'], $_SESSION['pack_ftp']['username'], package_crypt($_SESSION['pack_ftp']['password'])); |
| 988 | 1060 | |
| 989 | - if ($files === null) |
|
| 990 | - return array(); |
|
| 1061 | + if ($files === null) { |
|
| 1062 | + return array(); |
|
| 1063 | + } |
|
| 991 | 1064 | |
| 992 | 1065 | foreach ($files as $k => $file) |
| 993 | 1066 | { |
@@ -1001,13 +1074,16 @@ discard block |
||
| 1001 | 1074 | $package_ftp->chmod($ftp_file, 0755); |
| 1002 | 1075 | } |
| 1003 | 1076 | |
| 1004 | - if (!@is_writable($file)) |
|
| 1005 | - $package_ftp->chmod($ftp_file, 0777); |
|
| 1006 | - if (!@is_writable(dirname($file))) |
|
| 1007 | - $package_ftp->chmod(dirname($ftp_file), 0777); |
|
| 1077 | + if (!@is_writable($file)) { |
|
| 1078 | + $package_ftp->chmod($ftp_file, 0777); |
|
| 1079 | + } |
|
| 1080 | + if (!@is_writable(dirname($file))) { |
|
| 1081 | + $package_ftp->chmod(dirname($ftp_file), 0777); |
|
| 1082 | + } |
|
| 1008 | 1083 | |
| 1009 | - if (@is_writable($file)) |
|
| 1010 | - unset($files[$k]); |
|
| 1084 | + if (@is_writable($file)) { |
|
| 1085 | + unset($files[$k]); |
|
| 1086 | + } |
|
| 1011 | 1087 | } |
| 1012 | 1088 | |
| 1013 | 1089 | return $files; |
@@ -1019,8 +1095,7 @@ discard block |
||
| 1019 | 1095 | |
| 1020 | 1096 | $files = packageRequireFTP($destination_url, $files, $return); |
| 1021 | 1097 | return $files; |
| 1022 | - } |
|
| 1023 | - elseif (isset($_POST['ftp_username'])) |
|
| 1098 | + } elseif (isset($_POST['ftp_username'])) |
|
| 1024 | 1099 | { |
| 1025 | 1100 | require_once($sourcedir . '/Class-Package.php'); |
| 1026 | 1101 | $ftp = new ftp_connection($_POST['ftp_server'], $_POST['ftp_port'], $_POST['ftp_username'], $_POST['ftp_password']); |
@@ -1042,19 +1117,21 @@ discard block |
||
| 1042 | 1117 | { |
| 1043 | 1118 | require_once($sourcedir . '/Class-Package.php'); |
| 1044 | 1119 | $ftp = new ftp_connection(null); |
| 1120 | + } elseif ($ftp->error !== false && !isset($ftp_error)) { |
|
| 1121 | + $ftp_error = $ftp->last_message === null ? '' : $ftp->last_message; |
|
| 1045 | 1122 | } |
| 1046 | - elseif ($ftp->error !== false && !isset($ftp_error)) |
|
| 1047 | - $ftp_error = $ftp->last_message === null ? '' : $ftp->last_message; |
|
| 1048 | 1123 | |
| 1049 | 1124 | list ($username, $detect_path, $found_path) = $ftp->detect_path($boarddir); |
| 1050 | 1125 | |
| 1051 | - if ($found_path) |
|
| 1052 | - $_POST['ftp_path'] = $detect_path; |
|
| 1053 | - elseif (!isset($_POST['ftp_path'])) |
|
| 1054 | - $_POST['ftp_path'] = isset($modSettings['package_path']) ? $modSettings['package_path'] : $detect_path; |
|
| 1126 | + if ($found_path) { |
|
| 1127 | + $_POST['ftp_path'] = $detect_path; |
|
| 1128 | + } elseif (!isset($_POST['ftp_path'])) { |
|
| 1129 | + $_POST['ftp_path'] = isset($modSettings['package_path']) ? $modSettings['package_path'] : $detect_path; |
|
| 1130 | + } |
|
| 1055 | 1131 | |
| 1056 | - if (!isset($_POST['ftp_username'])) |
|
| 1057 | - $_POST['ftp_username'] = $username; |
|
| 1132 | + if (!isset($_POST['ftp_username'])) { |
|
| 1133 | + $_POST['ftp_username'] = $username; |
|
| 1134 | + } |
|
| 1058 | 1135 | |
| 1059 | 1136 | $context['package_ftp'] = array( |
| 1060 | 1137 | 'server' => isset($_POST['ftp_server']) ? $_POST['ftp_server'] : (isset($modSettings['package_server']) ? $modSettings['package_server'] : 'localhost'), |
@@ -1066,23 +1143,24 @@ discard block |
||
| 1066 | 1143 | ); |
| 1067 | 1144 | |
| 1068 | 1145 | // If we're returning dump out here. |
| 1069 | - if ($return) |
|
| 1070 | - return $files; |
|
| 1146 | + if ($return) { |
|
| 1147 | + return $files; |
|
| 1148 | + } |
|
| 1071 | 1149 | |
| 1072 | 1150 | $context['page_title'] = $txt['package_ftp_necessary']; |
| 1073 | 1151 | $context['sub_template'] = 'ftp_required'; |
| 1074 | 1152 | obExit(); |
| 1075 | - } |
|
| 1076 | - else |
|
| 1153 | + } else |
|
| 1077 | 1154 | { |
| 1078 | 1155 | if (!in_array($_POST['ftp_path'], array('', '/'))) |
| 1079 | 1156 | { |
| 1080 | 1157 | $ftp_root = strtr($boarddir, array($_POST['ftp_path'] => '')); |
| 1081 | - if (substr($ftp_root, -1) == '/' && ($_POST['ftp_path'] == '' || $_POST['ftp_path'][0] == '/')) |
|
| 1082 | - $ftp_root = substr($ftp_root, 0, -1); |
|
| 1158 | + if (substr($ftp_root, -1) == '/' && ($_POST['ftp_path'] == '' || $_POST['ftp_path'][0] == '/')) { |
|
| 1159 | + $ftp_root = substr($ftp_root, 0, -1); |
|
| 1160 | + } |
|
| 1161 | + } else { |
|
| 1162 | + $ftp_root = $boarddir; |
|
| 1083 | 1163 | } |
| 1084 | - else |
|
| 1085 | - $ftp_root = $boarddir; |
|
| 1086 | 1164 | |
| 1087 | 1165 | $_SESSION['pack_ftp'] = array( |
| 1088 | 1166 | 'server' => $_POST['ftp_server'], |
@@ -1093,8 +1171,9 @@ discard block |
||
| 1093 | 1171 | 'root' => $ftp_root, |
| 1094 | 1172 | ); |
| 1095 | 1173 | |
| 1096 | - if (!isset($modSettings['package_path']) || $modSettings['package_path'] != $_POST['ftp_path']) |
|
| 1097 | - updateSettings(array('package_path' => $_POST['ftp_path'])); |
|
| 1174 | + if (!isset($modSettings['package_path']) || $modSettings['package_path'] != $_POST['ftp_path']) { |
|
| 1175 | + updateSettings(array('package_path' => $_POST['ftp_path'])); |
|
| 1176 | + } |
|
| 1098 | 1177 | |
| 1099 | 1178 | $files = packageRequireFTP($destination_url, $files, $return); |
| 1100 | 1179 | } |
@@ -1122,16 +1201,18 @@ discard block |
||
| 1122 | 1201 | global $packagesdir, $forum_version, $context, $temp_path, $language, $smcFunc; |
| 1123 | 1202 | |
| 1124 | 1203 | // Mayday! That action doesn't exist!! |
| 1125 | - if (empty($packageXML) || !$packageXML->exists($method)) |
|
| 1126 | - return array(); |
|
| 1204 | + if (empty($packageXML) || !$packageXML->exists($method)) { |
|
| 1205 | + return array(); |
|
| 1206 | + } |
|
| 1127 | 1207 | |
| 1128 | 1208 | // We haven't found the package script yet... |
| 1129 | 1209 | $script = false; |
| 1130 | 1210 | $the_version = strtr($forum_version, array('SMF ' => '')); |
| 1131 | 1211 | |
| 1132 | 1212 | // Emulation support... |
| 1133 | - if (!empty($_SESSION['version_emulate'])) |
|
| 1134 | - $the_version = $_SESSION['version_emulate']; |
|
| 1213 | + if (!empty($_SESSION['version_emulate'])) { |
|
| 1214 | + $the_version = $_SESSION['version_emulate']; |
|
| 1215 | + } |
|
| 1135 | 1216 | |
| 1136 | 1217 | // Single package emulation |
| 1137 | 1218 | if (!empty($_REQUEST['ve']) && !empty($_REQUEST['package'])) |
@@ -1139,8 +1220,9 @@ discard block |
||
| 1139 | 1220 | $the_version = $_REQUEST['ve']; |
| 1140 | 1221 | $_SESSION['single_version_emulate'][$_REQUEST['package']] = $the_version; |
| 1141 | 1222 | } |
| 1142 | - if (!empty($_REQUEST['package']) && (!empty($_SESSION['single_version_emulate'][$_REQUEST['package']]))) |
|
| 1143 | - $the_version = $_SESSION['single_version_emulate'][$_REQUEST['package']]; |
|
| 1223 | + if (!empty($_REQUEST['package']) && (!empty($_SESSION['single_version_emulate'][$_REQUEST['package']]))) { |
|
| 1224 | + $the_version = $_SESSION['single_version_emulate'][$_REQUEST['package']]; |
|
| 1225 | + } |
|
| 1144 | 1226 | |
| 1145 | 1227 | // Get all the versions of this method and find the right one. |
| 1146 | 1228 | $these_methods = $packageXML->set($method); |
@@ -1150,16 +1232,18 @@ discard block |
||
| 1150 | 1232 | if ($this_method->exists('@for')) |
| 1151 | 1233 | { |
| 1152 | 1234 | // Don't keep going if this won't work for this version of SMF. |
| 1153 | - if (!matchPackageVersion($the_version, $this_method->fetch('@for'))) |
|
| 1154 | - continue; |
|
| 1235 | + if (!matchPackageVersion($the_version, $this_method->fetch('@for'))) { |
|
| 1236 | + continue; |
|
| 1237 | + } |
|
| 1155 | 1238 | } |
| 1156 | 1239 | |
| 1157 | 1240 | // Upgrades may go from a certain old version of the mod. |
| 1158 | 1241 | if ($method == 'upgrade' && $this_method->exists('@from')) |
| 1159 | 1242 | { |
| 1160 | 1243 | // Well, this is for the wrong old version... |
| 1161 | - if (!matchPackageVersion($previous_version, $this_method->fetch('@from'))) |
|
| 1162 | - continue; |
|
| 1244 | + if (!matchPackageVersion($previous_version, $this_method->fetch('@from'))) { |
|
| 1245 | + continue; |
|
| 1246 | + } |
|
| 1163 | 1247 | } |
| 1164 | 1248 | |
| 1165 | 1249 | // We've found it! |
@@ -1168,8 +1252,9 @@ discard block |
||
| 1168 | 1252 | } |
| 1169 | 1253 | |
| 1170 | 1254 | // Bad news, a matching script wasn't found! |
| 1171 | - if (!($script instanceof xmlArray)) |
|
| 1172 | - return array(); |
|
| 1255 | + if (!($script instanceof xmlArray)) { |
|
| 1256 | + return array(); |
|
| 1257 | + } |
|
| 1173 | 1258 | |
| 1174 | 1259 | // Find all the actions in this method - in theory, these should only be allowed actions. (* means all.) |
| 1175 | 1260 | $actions = $script->set('*'); |
@@ -1198,12 +1283,12 @@ discard block |
||
| 1198 | 1283 | if ((isset($_REQUEST['readme']) && $action->fetch('@lang') == $_REQUEST['readme']) || (isset($_REQUEST['license']) && $action->fetch('@lang') == $_REQUEST['license']) || (!isset($_REQUEST['readme']) && $action->fetch('@lang') == $language) || (!isset($_REQUEST['license']) && $action->fetch('@lang') == $language)) |
| 1199 | 1284 | { |
| 1200 | 1285 | // In case the user put the blocks in the wrong order. |
| 1201 | - if (isset($context[$type]['selected']) && $context[$type]['selected'] == 'default') |
|
| 1202 | - $context[$type][] = 'default'; |
|
| 1286 | + if (isset($context[$type]['selected']) && $context[$type]['selected'] == 'default') { |
|
| 1287 | + $context[$type][] = 'default'; |
|
| 1288 | + } |
|
| 1203 | 1289 | |
| 1204 | 1290 | $context[$type]['selected'] = $smcFunc['htmlspecialchars']($action->fetch('@lang')); |
| 1205 | - } |
|
| 1206 | - else |
|
| 1291 | + } else |
|
| 1207 | 1292 | { |
| 1208 | 1293 | // We don't want this now, but we'll allow the user to select to read it. |
| 1209 | 1294 | $context[$type][] = $smcFunc['htmlspecialchars']($action->fetch('@lang')); |
@@ -1218,9 +1303,9 @@ discard block |
||
| 1218 | 1303 | { |
| 1219 | 1304 | $context[$type][] = 'default'; |
| 1220 | 1305 | continue; |
| 1306 | + } else { |
|
| 1307 | + $context[$type]['selected'] = 'default'; |
|
| 1221 | 1308 | } |
| 1222 | - else |
|
| 1223 | - $context[$type]['selected'] = 'default'; |
|
| 1224 | 1309 | } |
| 1225 | 1310 | } |
| 1226 | 1311 | |
@@ -1230,9 +1315,9 @@ discard block |
||
| 1230 | 1315 | $filename = $temp_path . '$auto_' . $temp_auto++ . (in_array($actionType, array('readme', 'redirect', 'license')) ? '.txt' : ($actionType == 'code' || $actionType == 'database' ? '.php' : '.mod')); |
| 1231 | 1316 | package_put_contents($filename, $action->fetch('.')); |
| 1232 | 1317 | $filename = strtr($filename, array($temp_path => '')); |
| 1318 | + } else { |
|
| 1319 | + $filename = $action->fetch('.'); |
|
| 1233 | 1320 | } |
| 1234 | - else |
|
| 1235 | - $filename = $action->fetch('.'); |
|
| 1236 | 1321 | |
| 1237 | 1322 | $return[] = array( |
| 1238 | 1323 | 'type' => $actionType, |
@@ -1247,8 +1332,7 @@ discard block |
||
| 1247 | 1332 | ); |
| 1248 | 1333 | |
| 1249 | 1334 | continue; |
| 1250 | - } |
|
| 1251 | - elseif ($actionType == 'hook') |
|
| 1335 | + } elseif ($actionType == 'hook') |
|
| 1252 | 1336 | { |
| 1253 | 1337 | $return[] = array( |
| 1254 | 1338 | 'type' => $actionType, |
@@ -1260,16 +1344,16 @@ discard block |
||
| 1260 | 1344 | 'description' => '', |
| 1261 | 1345 | ); |
| 1262 | 1346 | continue; |
| 1263 | - } |
|
| 1264 | - elseif ($actionType == 'credits') |
|
| 1347 | + } elseif ($actionType == 'credits') |
|
| 1265 | 1348 | { |
| 1266 | 1349 | // quick check of any supplied url |
| 1267 | 1350 | $url = $action->exists('@url') ? $action->fetch('@url') : ''; |
| 1268 | 1351 | if (strlen(trim($url)) > 0 && substr($url, 0, 7) !== 'http://' && substr($url, 0, 8) !== 'https://') |
| 1269 | 1352 | { |
| 1270 | 1353 | $url = 'http://' . $url; |
| 1271 | - if (strlen($url) < 8 || (substr($url, 0, 7) !== 'http://' && substr($url, 0, 8) !== 'https://')) |
|
| 1272 | - $url = ''; |
|
| 1354 | + if (strlen($url) < 8 || (substr($url, 0, 7) !== 'http://' && substr($url, 0, 8) !== 'https://')) { |
|
| 1355 | + $url = ''; |
|
| 1356 | + } |
|
| 1273 | 1357 | } |
| 1274 | 1358 | |
| 1275 | 1359 | $return[] = array( |
@@ -1281,8 +1365,7 @@ discard block |
||
| 1281 | 1365 | 'title' => $action->fetch('.'), |
| 1282 | 1366 | ); |
| 1283 | 1367 | continue; |
| 1284 | - } |
|
| 1285 | - elseif ($actionType == 'requires') |
|
| 1368 | + } elseif ($actionType == 'requires') |
|
| 1286 | 1369 | { |
| 1287 | 1370 | $return[] = array( |
| 1288 | 1371 | 'type' => $actionType, |
@@ -1291,14 +1374,12 @@ discard block |
||
| 1291 | 1374 | 'description' => '', |
| 1292 | 1375 | ); |
| 1293 | 1376 | continue; |
| 1294 | - } |
|
| 1295 | - elseif ($actionType == 'error') |
|
| 1377 | + } elseif ($actionType == 'error') |
|
| 1296 | 1378 | { |
| 1297 | 1379 | $return[] = array( |
| 1298 | 1380 | 'type' => 'error', |
| 1299 | 1381 | ); |
| 1300 | - } |
|
| 1301 | - elseif (in_array($actionType, array('require-file', 'remove-file', 'require-dir', 'remove-dir', 'move-file', 'move-dir', 'create-file', 'create-dir'))) |
|
| 1382 | + } elseif (in_array($actionType, array('require-file', 'remove-file', 'require-dir', 'remove-dir', 'move-file', 'move-dir', 'create-file', 'create-dir'))) |
|
| 1302 | 1383 | { |
| 1303 | 1384 | $this_action = &$return[]; |
| 1304 | 1385 | $this_action = array( |
@@ -1312,8 +1393,7 @@ discard block |
||
| 1312 | 1393 | { |
| 1313 | 1394 | $this_action['unparsed_destination'] = $action->fetch('@destination'); |
| 1314 | 1395 | $this_action['destination'] = parse_path($action->fetch('@destination')) . '/' . basename($this_action['filename']); |
| 1315 | - } |
|
| 1316 | - else |
|
| 1396 | + } else |
|
| 1317 | 1397 | { |
| 1318 | 1398 | $this_action['unparsed_filename'] = $this_action['filename']; |
| 1319 | 1399 | $this_action['filename'] = parse_path($this_action['filename']); |
@@ -1322,10 +1402,11 @@ discard block |
||
| 1322 | 1402 | // If we're moving or requiring (copying) a file. |
| 1323 | 1403 | if (substr($actionType, 0, 4) == 'move' || substr($actionType, 0, 7) == 'require') |
| 1324 | 1404 | { |
| 1325 | - if ($action->exists('@from')) |
|
| 1326 | - $this_action['source'] = parse_path($action->fetch('@from')); |
|
| 1327 | - else |
|
| 1328 | - $this_action['source'] = $temp_path . $this_action['filename']; |
|
| 1405 | + if ($action->exists('@from')) { |
|
| 1406 | + $this_action['source'] = parse_path($action->fetch('@from')); |
|
| 1407 | + } else { |
|
| 1408 | + $this_action['source'] = $temp_path . $this_action['filename']; |
|
| 1409 | + } |
|
| 1329 | 1410 | } |
| 1330 | 1411 | |
| 1331 | 1412 | // Check if these things can be done. (chmod's etc.) |
@@ -1334,22 +1415,23 @@ discard block |
||
| 1334 | 1415 | if (!mktree($this_action['destination'], false)) |
| 1335 | 1416 | { |
| 1336 | 1417 | $temp = $this_action['destination']; |
| 1337 | - while (!file_exists($temp) && strlen($temp) > 1) |
|
| 1338 | - $temp = dirname($temp); |
|
| 1418 | + while (!file_exists($temp) && strlen($temp) > 1) { |
|
| 1419 | + $temp = dirname($temp); |
|
| 1420 | + } |
|
| 1339 | 1421 | |
| 1340 | 1422 | $return[] = array( |
| 1341 | 1423 | 'type' => 'chmod', |
| 1342 | 1424 | 'filename' => $temp |
| 1343 | 1425 | ); |
| 1344 | 1426 | } |
| 1345 | - } |
|
| 1346 | - elseif ($actionType == 'create-file') |
|
| 1427 | + } elseif ($actionType == 'create-file') |
|
| 1347 | 1428 | { |
| 1348 | 1429 | if (!mktree(dirname($this_action['destination']), false)) |
| 1349 | 1430 | { |
| 1350 | 1431 | $temp = dirname($this_action['destination']); |
| 1351 | - while (!file_exists($temp) && strlen($temp) > 1) |
|
| 1352 | - $temp = dirname($temp); |
|
| 1432 | + while (!file_exists($temp) && strlen($temp) > 1) { |
|
| 1433 | + $temp = dirname($temp); |
|
| 1434 | + } |
|
| 1353 | 1435 | |
| 1354 | 1436 | $return[] = array( |
| 1355 | 1437 | 'type' => 'chmod', |
@@ -1357,36 +1439,38 @@ discard block |
||
| 1357 | 1439 | ); |
| 1358 | 1440 | } |
| 1359 | 1441 | |
| 1360 | - if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination'])))) |
|
| 1361 | - $return[] = array( |
|
| 1442 | + if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination'])))) { |
|
| 1443 | + $return[] = array( |
|
| 1362 | 1444 | 'type' => 'chmod', |
| 1363 | 1445 | 'filename' => $this_action['destination'] |
| 1364 | 1446 | ); |
| 1365 | - } |
|
| 1366 | - elseif ($actionType == 'require-dir') |
|
| 1447 | + } |
|
| 1448 | + } elseif ($actionType == 'require-dir') |
|
| 1367 | 1449 | { |
| 1368 | 1450 | if (!mktree($this_action['destination'], false)) |
| 1369 | 1451 | { |
| 1370 | 1452 | $temp = $this_action['destination']; |
| 1371 | - while (!file_exists($temp) && strlen($temp) > 1) |
|
| 1372 | - $temp = dirname($temp); |
|
| 1453 | + while (!file_exists($temp) && strlen($temp) > 1) { |
|
| 1454 | + $temp = dirname($temp); |
|
| 1455 | + } |
|
| 1373 | 1456 | |
| 1374 | 1457 | $return[] = array( |
| 1375 | 1458 | 'type' => 'chmod', |
| 1376 | 1459 | 'filename' => $temp |
| 1377 | 1460 | ); |
| 1378 | 1461 | } |
| 1379 | - } |
|
| 1380 | - elseif ($actionType == 'require-file') |
|
| 1462 | + } elseif ($actionType == 'require-file') |
|
| 1381 | 1463 | { |
| 1382 | - if ($action->exists('@theme')) |
|
| 1383 | - $this_action['theme_action'] = $action->fetch('@theme'); |
|
| 1464 | + if ($action->exists('@theme')) { |
|
| 1465 | + $this_action['theme_action'] = $action->fetch('@theme'); |
|
| 1466 | + } |
|
| 1384 | 1467 | |
| 1385 | 1468 | if (!mktree(dirname($this_action['destination']), false)) |
| 1386 | 1469 | { |
| 1387 | 1470 | $temp = dirname($this_action['destination']); |
| 1388 | - while (!file_exists($temp) && strlen($temp) > 1) |
|
| 1389 | - $temp = dirname($temp); |
|
| 1471 | + while (!file_exists($temp) && strlen($temp) > 1) { |
|
| 1472 | + $temp = dirname($temp); |
|
| 1473 | + } |
|
| 1390 | 1474 | |
| 1391 | 1475 | $return[] = array( |
| 1392 | 1476 | 'type' => 'chmod', |
@@ -1394,19 +1478,20 @@ discard block |
||
| 1394 | 1478 | ); |
| 1395 | 1479 | } |
| 1396 | 1480 | |
| 1397 | - if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination'])))) |
|
| 1398 | - $return[] = array( |
|
| 1481 | + if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination'])))) { |
|
| 1482 | + $return[] = array( |
|
| 1399 | 1483 | 'type' => 'chmod', |
| 1400 | 1484 | 'filename' => $this_action['destination'] |
| 1401 | 1485 | ); |
| 1402 | - } |
|
| 1403 | - elseif ($actionType == 'move-dir' || $actionType == 'move-file') |
|
| 1486 | + } |
|
| 1487 | + } elseif ($actionType == 'move-dir' || $actionType == 'move-file') |
|
| 1404 | 1488 | { |
| 1405 | 1489 | if (!mktree(dirname($this_action['destination']), false)) |
| 1406 | 1490 | { |
| 1407 | 1491 | $temp = dirname($this_action['destination']); |
| 1408 | - while (!file_exists($temp) && strlen($temp) > 1) |
|
| 1409 | - $temp = dirname($temp); |
|
| 1492 | + while (!file_exists($temp) && strlen($temp) > 1) { |
|
| 1493 | + $temp = dirname($temp); |
|
| 1494 | + } |
|
| 1410 | 1495 | |
| 1411 | 1496 | $return[] = array( |
| 1412 | 1497 | 'type' => 'chmod', |
@@ -1414,30 +1499,30 @@ discard block |
||
| 1414 | 1499 | ); |
| 1415 | 1500 | } |
| 1416 | 1501 | |
| 1417 | - if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination'])))) |
|
| 1418 | - $return[] = array( |
|
| 1502 | + if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination'])))) { |
|
| 1503 | + $return[] = array( |
|
| 1419 | 1504 | 'type' => 'chmod', |
| 1420 | 1505 | 'filename' => $this_action['destination'] |
| 1421 | 1506 | ); |
| 1422 | - } |
|
| 1423 | - elseif ($actionType == 'remove-dir') |
|
| 1507 | + } |
|
| 1508 | + } elseif ($actionType == 'remove-dir') |
|
| 1424 | 1509 | { |
| 1425 | - if (!is_writable($this_action['filename']) && file_exists($this_action['filename'])) |
|
| 1426 | - $return[] = array( |
|
| 1510 | + if (!is_writable($this_action['filename']) && file_exists($this_action['filename'])) { |
|
| 1511 | + $return[] = array( |
|
| 1427 | 1512 | 'type' => 'chmod', |
| 1428 | 1513 | 'filename' => $this_action['filename'] |
| 1429 | 1514 | ); |
| 1430 | - } |
|
| 1431 | - elseif ($actionType == 'remove-file') |
|
| 1515 | + } |
|
| 1516 | + } elseif ($actionType == 'remove-file') |
|
| 1432 | 1517 | { |
| 1433 | - if (!is_writable($this_action['filename']) && file_exists($this_action['filename'])) |
|
| 1434 | - $return[] = array( |
|
| 1518 | + if (!is_writable($this_action['filename']) && file_exists($this_action['filename'])) { |
|
| 1519 | + $return[] = array( |
|
| 1435 | 1520 | 'type' => 'chmod', |
| 1436 | 1521 | 'filename' => $this_action['filename'] |
| 1437 | 1522 | ); |
| 1523 | + } |
|
| 1438 | 1524 | } |
| 1439 | - } |
|
| 1440 | - else |
|
| 1525 | + } else |
|
| 1441 | 1526 | { |
| 1442 | 1527 | $return[] = array( |
| 1443 | 1528 | 'type' => 'error', |
@@ -1448,8 +1533,9 @@ discard block |
||
| 1448 | 1533 | } |
| 1449 | 1534 | |
| 1450 | 1535 | // Only testing - just return a list of things to be done. |
| 1451 | - if ($testing_only) |
|
| 1452 | - return $return; |
|
| 1536 | + if ($testing_only) { |
|
| 1537 | + return $return; |
|
| 1538 | + } |
|
| 1453 | 1539 | |
| 1454 | 1540 | umask(0); |
| 1455 | 1541 | |
@@ -1457,78 +1543,81 @@ discard block |
||
| 1457 | 1543 | $not_done = array(array('type' => '!')); |
| 1458 | 1544 | foreach ($return as $action) |
| 1459 | 1545 | { |
| 1460 | - if (in_array($action['type'], array('modification', 'code', 'database', 'redirect', 'hook', 'credits'))) |
|
| 1461 | - $not_done[] = $action; |
|
| 1546 | + if (in_array($action['type'], array('modification', 'code', 'database', 'redirect', 'hook', 'credits'))) { |
|
| 1547 | + $not_done[] = $action; |
|
| 1548 | + } |
|
| 1462 | 1549 | |
| 1463 | 1550 | if ($action['type'] == 'create-dir') |
| 1464 | 1551 | { |
| 1465 | - if (!mktree($action['destination'], 0755) || !is_writable($action['destination'])) |
|
| 1466 | - $failure |= !mktree($action['destination'], 0777); |
|
| 1467 | - } |
|
| 1468 | - elseif ($action['type'] == 'create-file') |
|
| 1552 | + if (!mktree($action['destination'], 0755) || !is_writable($action['destination'])) { |
|
| 1553 | + $failure |= !mktree($action['destination'], 0777); |
|
| 1554 | + } |
|
| 1555 | + } elseif ($action['type'] == 'create-file') |
|
| 1469 | 1556 | { |
| 1470 | - if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination']))) |
|
| 1471 | - $failure |= !mktree(dirname($action['destination']), 0777); |
|
| 1557 | + if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination']))) { |
|
| 1558 | + $failure |= !mktree(dirname($action['destination']), 0777); |
|
| 1559 | + } |
|
| 1472 | 1560 | |
| 1473 | 1561 | // Create an empty file. |
| 1474 | 1562 | package_put_contents($action['destination'], package_get_contents($action['source']), $testing_only); |
| 1475 | 1563 | |
| 1476 | - if (!file_exists($action['destination'])) |
|
| 1477 | - $failure = true; |
|
| 1478 | - } |
|
| 1479 | - elseif ($action['type'] == 'require-dir') |
|
| 1564 | + if (!file_exists($action['destination'])) { |
|
| 1565 | + $failure = true; |
|
| 1566 | + } |
|
| 1567 | + } elseif ($action['type'] == 'require-dir') |
|
| 1480 | 1568 | { |
| 1481 | 1569 | copytree($action['source'], $action['destination']); |
| 1482 | 1570 | // Any other theme folders? |
| 1483 | - if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['destination']])) |
|
| 1484 | - foreach ($context['theme_copies'][$action['type']][$action['destination']] as $theme_destination) |
|
| 1571 | + if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['destination']])) { |
|
| 1572 | + foreach ($context['theme_copies'][$action['type']][$action['destination']] as $theme_destination) |
|
| 1485 | 1573 | copytree($action['source'], $theme_destination); |
| 1486 | - } |
|
| 1487 | - elseif ($action['type'] == 'require-file') |
|
| 1574 | + } |
|
| 1575 | + } elseif ($action['type'] == 'require-file') |
|
| 1488 | 1576 | { |
| 1489 | - if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination']))) |
|
| 1490 | - $failure |= !mktree(dirname($action['destination']), 0777); |
|
| 1577 | + if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination']))) { |
|
| 1578 | + $failure |= !mktree(dirname($action['destination']), 0777); |
|
| 1579 | + } |
|
| 1491 | 1580 | |
| 1492 | 1581 | package_put_contents($action['destination'], package_get_contents($action['source']), $testing_only); |
| 1493 | 1582 | |
| 1494 | 1583 | $failure |= !copy($action['source'], $action['destination']); |
| 1495 | 1584 | |
| 1496 | 1585 | // Any other theme files? |
| 1497 | - if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['destination']])) |
|
| 1498 | - foreach ($context['theme_copies'][$action['type']][$action['destination']] as $theme_destination) |
|
| 1586 | + if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['destination']])) { |
|
| 1587 | + foreach ($context['theme_copies'][$action['type']][$action['destination']] as $theme_destination) |
|
| 1499 | 1588 | { |
| 1500 | 1589 | if (!mktree(dirname($theme_destination), 0755) || !is_writable(dirname($theme_destination))) |
| 1501 | 1590 | $failure |= !mktree(dirname($theme_destination), 0777); |
| 1591 | + } |
|
| 1502 | 1592 | |
| 1503 | 1593 | package_put_contents($theme_destination, package_get_contents($action['source']), $testing_only); |
| 1504 | 1594 | |
| 1505 | 1595 | $failure |= !copy($action['source'], $theme_destination); |
| 1506 | 1596 | } |
| 1507 | - } |
|
| 1508 | - elseif ($action['type'] == 'move-file') |
|
| 1597 | + } elseif ($action['type'] == 'move-file') |
|
| 1509 | 1598 | { |
| 1510 | - if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination']))) |
|
| 1511 | - $failure |= !mktree(dirname($action['destination']), 0777); |
|
| 1599 | + if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination']))) { |
|
| 1600 | + $failure |= !mktree(dirname($action['destination']), 0777); |
|
| 1601 | + } |
|
| 1512 | 1602 | |
| 1513 | 1603 | $failure |= !rename($action['source'], $action['destination']); |
| 1514 | - } |
|
| 1515 | - elseif ($action['type'] == 'move-dir') |
|
| 1604 | + } elseif ($action['type'] == 'move-dir') |
|
| 1516 | 1605 | { |
| 1517 | - if (!mktree($action['destination'], 0755) || !is_writable($action['destination'])) |
|
| 1518 | - $failure |= !mktree($action['destination'], 0777); |
|
| 1606 | + if (!mktree($action['destination'], 0755) || !is_writable($action['destination'])) { |
|
| 1607 | + $failure |= !mktree($action['destination'], 0777); |
|
| 1608 | + } |
|
| 1519 | 1609 | |
| 1520 | 1610 | $failure |= !rename($action['source'], $action['destination']); |
| 1521 | - } |
|
| 1522 | - elseif ($action['type'] == 'remove-dir') |
|
| 1611 | + } elseif ($action['type'] == 'remove-dir') |
|
| 1523 | 1612 | { |
| 1524 | 1613 | deltree($action['filename']); |
| 1525 | 1614 | |
| 1526 | 1615 | // Any other theme folders? |
| 1527 | - if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['filename']])) |
|
| 1528 | - foreach ($context['theme_copies'][$action['type']][$action['filename']] as $theme_destination) |
|
| 1616 | + if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['filename']])) { |
|
| 1617 | + foreach ($context['theme_copies'][$action['type']][$action['filename']] as $theme_destination) |
|
| 1529 | 1618 | deltree($theme_destination); |
| 1530 | - } |
|
| 1531 | - elseif ($action['type'] == 'remove-file') |
|
| 1619 | + } |
|
| 1620 | + } elseif ($action['type'] == 'remove-file') |
|
| 1532 | 1621 | { |
| 1533 | 1622 | // Make sure the file exists before deleting it. |
| 1534 | 1623 | if (file_exists($action['filename'])) |
@@ -1537,16 +1626,18 @@ discard block |
||
| 1537 | 1626 | $failure |= !unlink($action['filename']); |
| 1538 | 1627 | } |
| 1539 | 1628 | // The file that was supposed to be deleted couldn't be found. |
| 1540 | - else |
|
| 1541 | - $failure = true; |
|
| 1629 | + else { |
|
| 1630 | + $failure = true; |
|
| 1631 | + } |
|
| 1542 | 1632 | |
| 1543 | 1633 | // Any other theme folders? |
| 1544 | - if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['filename']])) |
|
| 1545 | - foreach ($context['theme_copies'][$action['type']][$action['filename']] as $theme_destination) |
|
| 1634 | + if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['filename']])) { |
|
| 1635 | + foreach ($context['theme_copies'][$action['type']][$action['filename']] as $theme_destination) |
|
| 1546 | 1636 | if (file_exists($theme_destination)) |
| 1547 | 1637 | $failure |= !unlink($theme_destination); |
| 1548 | - else |
|
| 1549 | - $failure = true; |
|
| 1638 | + } else { |
|
| 1639 | + $failure = true; |
|
| 1640 | + } |
|
| 1550 | 1641 | } |
| 1551 | 1642 | } |
| 1552 | 1643 | |
@@ -1568,8 +1659,9 @@ discard block |
||
| 1568 | 1659 | { |
| 1569 | 1660 | static $near_version = 0; |
| 1570 | 1661 | |
| 1571 | - if ($reset) |
|
| 1572 | - $near_version = 0; |
|
| 1662 | + if ($reset) { |
|
| 1663 | + $near_version = 0; |
|
| 1664 | + } |
|
| 1573 | 1665 | |
| 1574 | 1666 | // Normalize the $versions while we remove our previous Doh! |
| 1575 | 1667 | $versions = explode(',', str_replace(array(' ', '2.0rc1-1'), array('', '2.0rc1.1'), strtolower($versions))); |
@@ -1578,16 +1670,19 @@ discard block |
||
| 1578 | 1670 | foreach ($versions as $for) |
| 1579 | 1671 | { |
| 1580 | 1672 | // Adjust for those wild cards |
| 1581 | - if (strpos($for, '*') !== false) |
|
| 1582 | - $for = str_replace('*', '0dev0', $for) . '-' . str_replace('*', '999', $for); |
|
| 1673 | + if (strpos($for, '*') !== false) { |
|
| 1674 | + $for = str_replace('*', '0dev0', $for) . '-' . str_replace('*', '999', $for); |
|
| 1675 | + } |
|
| 1583 | 1676 | |
| 1584 | 1677 | // If we have a range, grab the lower value, done this way so it looks normal-er to the user e.g. 2.0 vs 2.0.99 |
| 1585 | - if (strpos($for, '-') !== false) |
|
| 1586 | - list ($for, $higher) = explode('-', $for); |
|
| 1678 | + if (strpos($for, '-') !== false) { |
|
| 1679 | + list ($for, $higher) = explode('-', $for); |
|
| 1680 | + } |
|
| 1587 | 1681 | |
| 1588 | 1682 | // Do the compare, if the for is greater, than what we have but not greater than what we are running ..... |
| 1589 | - if (compareVersions($near_version, $for) === -1 && compareVersions($for, $the_version) !== 1) |
|
| 1590 | - $near_version = $for; |
|
| 1683 | + if (compareVersions($near_version, $for) === -1 && compareVersions($for, $the_version) !== 1) { |
|
| 1684 | + $near_version = $for; |
|
| 1685 | + } |
|
| 1591 | 1686 | } |
| 1592 | 1687 | |
| 1593 | 1688 | return !empty($near_version) ? $near_version : false; |
@@ -1610,15 +1705,17 @@ discard block |
||
| 1610 | 1705 | $versions = explode(',', str_replace(array(' ', '2.0rc1-1'), array('', '2.0rc1.1'), strtolower($versions))); |
| 1611 | 1706 | |
| 1612 | 1707 | // Perhaps we do accept anything? |
| 1613 | - if (in_array('all', $versions)) |
|
| 1614 | - return true; |
|
| 1708 | + if (in_array('all', $versions)) { |
|
| 1709 | + return true; |
|
| 1710 | + } |
|
| 1615 | 1711 | |
| 1616 | 1712 | // Loop through each version. |
| 1617 | 1713 | foreach ($versions as $for) |
| 1618 | 1714 | { |
| 1619 | 1715 | // Wild card spotted? |
| 1620 | - if (strpos($for, '*') !== false) |
|
| 1621 | - $for = str_replace('*', '0dev0', $for) . '-' . str_replace('*', '999', $for); |
|
| 1716 | + if (strpos($for, '*') !== false) { |
|
| 1717 | + $for = str_replace('*', '0dev0', $for) . '-' . str_replace('*', '999', $for); |
|
| 1718 | + } |
|
| 1622 | 1719 | |
| 1623 | 1720 | // Do we have a range? |
| 1624 | 1721 | if (strpos($for, '-') !== false) |
@@ -1626,12 +1723,14 @@ discard block |
||
| 1626 | 1723 | list ($lower, $upper) = explode('-', $for); |
| 1627 | 1724 | |
| 1628 | 1725 | // Compare the version against lower and upper bounds. |
| 1629 | - if (compareVersions($version, $lower) > -1 && compareVersions($version, $upper) < 1) |
|
| 1630 | - return true; |
|
| 1726 | + if (compareVersions($version, $lower) > -1 && compareVersions($version, $upper) < 1) { |
|
| 1727 | + return true; |
|
| 1728 | + } |
|
| 1631 | 1729 | } |
| 1632 | 1730 | // Otherwise check if they are equal... |
| 1633 | - elseif (compareVersions($version, $for) === 0) |
|
| 1634 | - return true; |
|
| 1731 | + elseif (compareVersions($version, $for) === 0) { |
|
| 1732 | + return true; |
|
| 1733 | + } |
|
| 1635 | 1734 | } |
| 1636 | 1735 | |
| 1637 | 1736 | return false; |
@@ -1671,12 +1770,14 @@ discard block |
||
| 1671 | 1770 | } |
| 1672 | 1771 | |
| 1673 | 1772 | // Are they the same, perhaps? |
| 1674 | - if ($versions[1] === $versions[2]) |
|
| 1675 | - return 0; |
|
| 1773 | + if ($versions[1] === $versions[2]) { |
|
| 1774 | + return 0; |
|
| 1775 | + } |
|
| 1676 | 1776 | |
| 1677 | 1777 | // Get version numbering categories... |
| 1678 | - if (!isset($categories)) |
|
| 1679 | - $categories = array_keys($versions[1]); |
|
| 1778 | + if (!isset($categories)) { |
|
| 1779 | + $categories = array_keys($versions[1]); |
|
| 1780 | + } |
|
| 1680 | 1781 | |
| 1681 | 1782 | // Loop through each category. |
| 1682 | 1783 | foreach ($categories as $category) |
@@ -1686,13 +1787,15 @@ discard block |
||
| 1686 | 1787 | { |
| 1687 | 1788 | // Dev builds are a problematic exception. |
| 1688 | 1789 | // (stable) dev < (stable) but (unstable) dev = (unstable) |
| 1689 | - if ($category == 'type') |
|
| 1690 | - return $versions[1][$category] > $versions[2][$category] ? ($versions[1]['dev'] ? -1 : 1) : ($versions[2]['dev'] ? 1 : -1); |
|
| 1691 | - elseif ($category == 'dev') |
|
| 1692 | - return $versions[1]['dev'] ? ($versions[2]['type'] == 'stable' ? -1 : 0) : ($versions[1]['type'] == 'stable' ? 1 : 0); |
|
| 1790 | + if ($category == 'type') { |
|
| 1791 | + return $versions[1][$category] > $versions[2][$category] ? ($versions[1]['dev'] ? -1 : 1) : ($versions[2]['dev'] ? 1 : -1); |
|
| 1792 | + } elseif ($category == 'dev') { |
|
| 1793 | + return $versions[1]['dev'] ? ($versions[2]['type'] == 'stable' ? -1 : 0) : ($versions[1]['type'] == 'stable' ? 1 : 0); |
|
| 1794 | + } |
|
| 1693 | 1795 | // Otherwise a simple comparison. |
| 1694 | - else |
|
| 1695 | - return $versions[1][$category] > $versions[2][$category] ? 1 : -1; |
|
| 1796 | + else { |
|
| 1797 | + return $versions[1][$category] > $versions[2][$category] ? 1 : -1; |
|
| 1798 | + } |
|
| 1696 | 1799 | } |
| 1697 | 1800 | } |
| 1698 | 1801 | |
@@ -1726,11 +1829,13 @@ discard block |
||
| 1726 | 1829 | ); |
| 1727 | 1830 | |
| 1728 | 1831 | // do we parse in a package directory? |
| 1729 | - if (!empty($temp_path)) |
|
| 1730 | - $dirs['$package'] = $temp_path; |
|
| 1832 | + if (!empty($temp_path)) { |
|
| 1833 | + $dirs['$package'] = $temp_path; |
|
| 1834 | + } |
|
| 1731 | 1835 | |
| 1732 | - if (strlen($path) == 0) |
|
| 1733 | - trigger_error('parse_path(): There should never be an empty filename', E_USER_ERROR); |
|
| 1836 | + if (strlen($path) == 0) { |
|
| 1837 | + trigger_error('parse_path(): There should never be an empty filename', E_USER_ERROR); |
|
| 1838 | + } |
|
| 1734 | 1839 | |
| 1735 | 1840 | return strtr($path, $dirs); |
| 1736 | 1841 | } |
@@ -1747,8 +1852,9 @@ discard block |
||
| 1747 | 1852 | /** @var ftp_connection $package_ftp */ |
| 1748 | 1853 | global $package_ftp; |
| 1749 | 1854 | |
| 1750 | - if (!file_exists($dir)) |
|
| 1751 | - return; |
|
| 1855 | + if (!file_exists($dir)) { |
|
| 1856 | + return; |
|
| 1857 | + } |
|
| 1752 | 1858 | |
| 1753 | 1859 | $current_dir = @opendir($dir); |
| 1754 | 1860 | if ($current_dir == false) |
@@ -1756,8 +1862,9 @@ discard block |
||
| 1756 | 1862 | if ($delete_dir && isset($package_ftp)) |
| 1757 | 1863 | { |
| 1758 | 1864 | $ftp_file = strtr($dir, array($_SESSION['pack_ftp']['root'] => '')); |
| 1759 | - if (!is_dir($dir)) |
|
| 1760 | - $package_ftp->chmod($ftp_file, 0777); |
|
| 1865 | + if (!is_dir($dir)) { |
|
| 1866 | + $package_ftp->chmod($ftp_file, 0777); |
|
| 1867 | + } |
|
| 1761 | 1868 | $package_ftp->unlink($ftp_file); |
| 1762 | 1869 | } |
| 1763 | 1870 | |
@@ -1766,26 +1873,28 @@ discard block |
||
| 1766 | 1873 | |
| 1767 | 1874 | while ($entryname = readdir($current_dir)) |
| 1768 | 1875 | { |
| 1769 | - if (in_array($entryname, array('.', '..'))) |
|
| 1770 | - continue; |
|
| 1876 | + if (in_array($entryname, array('.', '..'))) { |
|
| 1877 | + continue; |
|
| 1878 | + } |
|
| 1771 | 1879 | |
| 1772 | - if (is_dir($dir . '/' . $entryname)) |
|
| 1773 | - deltree($dir . '/' . $entryname); |
|
| 1774 | - else |
|
| 1880 | + if (is_dir($dir . '/' . $entryname)) { |
|
| 1881 | + deltree($dir . '/' . $entryname); |
|
| 1882 | + } else |
|
| 1775 | 1883 | { |
| 1776 | 1884 | // Here, 755 doesn't really matter since we're deleting it anyway. |
| 1777 | 1885 | if (isset($package_ftp)) |
| 1778 | 1886 | { |
| 1779 | 1887 | $ftp_file = strtr($dir . '/' . $entryname, array($_SESSION['pack_ftp']['root'] => '')); |
| 1780 | 1888 | |
| 1781 | - if (!is_writable($dir . '/' . $entryname)) |
|
| 1782 | - $package_ftp->chmod($ftp_file, 0777); |
|
| 1889 | + if (!is_writable($dir . '/' . $entryname)) { |
|
| 1890 | + $package_ftp->chmod($ftp_file, 0777); |
|
| 1891 | + } |
|
| 1783 | 1892 | $package_ftp->unlink($ftp_file); |
| 1784 | - } |
|
| 1785 | - else |
|
| 1893 | + } else |
|
| 1786 | 1894 | { |
| 1787 | - if (!is_writable($dir . '/' . $entryname)) |
|
| 1788 | - smf_chmod($dir . '/' . $entryname, 0777); |
|
| 1895 | + if (!is_writable($dir . '/' . $entryname)) { |
|
| 1896 | + smf_chmod($dir . '/' . $entryname, 0777); |
|
| 1897 | + } |
|
| 1789 | 1898 | unlink($dir . '/' . $entryname); |
| 1790 | 1899 | } |
| 1791 | 1900 | } |
@@ -1798,14 +1907,15 @@ discard block |
||
| 1798 | 1907 | if (isset($package_ftp)) |
| 1799 | 1908 | { |
| 1800 | 1909 | $ftp_file = strtr($dir, array($_SESSION['pack_ftp']['root'] => '')); |
| 1801 | - if (!is_writable($dir . '/' . $entryname)) |
|
| 1802 | - $package_ftp->chmod($ftp_file, 0777); |
|
| 1910 | + if (!is_writable($dir . '/' . $entryname)) { |
|
| 1911 | + $package_ftp->chmod($ftp_file, 0777); |
|
| 1912 | + } |
|
| 1803 | 1913 | $package_ftp->unlink($ftp_file); |
| 1804 | - } |
|
| 1805 | - else |
|
| 1914 | + } else |
|
| 1806 | 1915 | { |
| 1807 | - if (!is_writable($dir)) |
|
| 1808 | - smf_chmod($dir, 0777); |
|
| 1916 | + if (!is_writable($dir)) { |
|
| 1917 | + smf_chmod($dir, 0777); |
|
| 1918 | + } |
|
| 1809 | 1919 | @rmdir($dir); |
| 1810 | 1920 | } |
| 1811 | 1921 | } |
@@ -1828,10 +1938,11 @@ discard block |
||
| 1828 | 1938 | { |
| 1829 | 1939 | if (!is_writable($strPath) && $mode !== false) |
| 1830 | 1940 | { |
| 1831 | - if (isset($package_ftp)) |
|
| 1832 | - $package_ftp->chmod(strtr($strPath, array($_SESSION['pack_ftp']['root'] => '')), $mode); |
|
| 1833 | - else |
|
| 1834 | - smf_chmod($strPath, $mode); |
|
| 1941 | + if (isset($package_ftp)) { |
|
| 1942 | + $package_ftp->chmod(strtr($strPath, array($_SESSION['pack_ftp']['root'] => '')), $mode); |
|
| 1943 | + } else { |
|
| 1944 | + smf_chmod($strPath, $mode); |
|
| 1945 | + } |
|
| 1835 | 1946 | } |
| 1836 | 1947 | |
| 1837 | 1948 | $test = @opendir($strPath); |
@@ -1839,36 +1950,37 @@ discard block |
||
| 1839 | 1950 | { |
| 1840 | 1951 | closedir($test); |
| 1841 | 1952 | return is_writable($strPath); |
| 1953 | + } else { |
|
| 1954 | + return false; |
|
| 1842 | 1955 | } |
| 1843 | - else |
|
| 1844 | - return false; |
|
| 1845 | 1956 | } |
| 1846 | 1957 | // Is this an invalid path and/or we can't make the directory? |
| 1847 | - if ($strPath == dirname($strPath) || !mktree(dirname($strPath), $mode)) |
|
| 1848 | - return false; |
|
| 1958 | + if ($strPath == dirname($strPath) || !mktree(dirname($strPath), $mode)) { |
|
| 1959 | + return false; |
|
| 1960 | + } |
|
| 1849 | 1961 | |
| 1850 | 1962 | if (!is_writable(dirname($strPath)) && $mode !== false) |
| 1851 | 1963 | { |
| 1852 | - if (isset($package_ftp)) |
|
| 1853 | - $package_ftp->chmod(dirname(strtr($strPath, array($_SESSION['pack_ftp']['root'] => ''))), $mode); |
|
| 1854 | - else |
|
| 1855 | - smf_chmod(dirname($strPath), $mode); |
|
| 1964 | + if (isset($package_ftp)) { |
|
| 1965 | + $package_ftp->chmod(dirname(strtr($strPath, array($_SESSION['pack_ftp']['root'] => ''))), $mode); |
|
| 1966 | + } else { |
|
| 1967 | + smf_chmod(dirname($strPath), $mode); |
|
| 1968 | + } |
|
| 1856 | 1969 | } |
| 1857 | 1970 | |
| 1858 | - if ($mode !== false && isset($package_ftp)) |
|
| 1859 | - return $package_ftp->create_dir(strtr($strPath, array($_SESSION['pack_ftp']['root'] => ''))); |
|
| 1860 | - elseif ($mode === false) |
|
| 1971 | + if ($mode !== false && isset($package_ftp)) { |
|
| 1972 | + return $package_ftp->create_dir(strtr($strPath, array($_SESSION['pack_ftp']['root'] => ''))); |
|
| 1973 | + } elseif ($mode === false) |
|
| 1861 | 1974 | { |
| 1862 | 1975 | $test = @opendir(dirname($strPath)); |
| 1863 | 1976 | if ($test) |
| 1864 | 1977 | { |
| 1865 | 1978 | closedir($test); |
| 1866 | 1979 | return true; |
| 1980 | + } else { |
|
| 1981 | + return false; |
|
| 1867 | 1982 | } |
| 1868 | - else |
|
| 1869 | - return false; |
|
| 1870 | - } |
|
| 1871 | - else |
|
| 1983 | + } else |
|
| 1872 | 1984 | { |
| 1873 | 1985 | @mkdir($strPath, $mode); |
| 1874 | 1986 | $test = @opendir($strPath); |
@@ -1876,9 +1988,9 @@ discard block |
||
| 1876 | 1988 | { |
| 1877 | 1989 | closedir($test); |
| 1878 | 1990 | return true; |
| 1991 | + } else { |
|
| 1992 | + return false; |
|
| 1879 | 1993 | } |
| 1880 | - else |
|
| 1881 | - return false; |
|
| 1882 | 1994 | } |
| 1883 | 1995 | } |
| 1884 | 1996 | |
@@ -1894,39 +2006,46 @@ discard block |
||
| 1894 | 2006 | /** @var ftp_connection $package_ftp */ |
| 1895 | 2007 | global $package_ftp; |
| 1896 | 2008 | |
| 1897 | - if (!file_exists($destination) || !is_writable($destination)) |
|
| 1898 | - mktree($destination, 0755); |
|
| 1899 | - if (!is_writable($destination)) |
|
| 1900 | - mktree($destination, 0777); |
|
| 2009 | + if (!file_exists($destination) || !is_writable($destination)) { |
|
| 2010 | + mktree($destination, 0755); |
|
| 2011 | + } |
|
| 2012 | + if (!is_writable($destination)) { |
|
| 2013 | + mktree($destination, 0777); |
|
| 2014 | + } |
|
| 1901 | 2015 | |
| 1902 | 2016 | $current_dir = opendir($source); |
| 1903 | - if ($current_dir == false) |
|
| 1904 | - return; |
|
| 2017 | + if ($current_dir == false) { |
|
| 2018 | + return; |
|
| 2019 | + } |
|
| 1905 | 2020 | |
| 1906 | 2021 | while ($entryname = readdir($current_dir)) |
| 1907 | 2022 | { |
| 1908 | - if (in_array($entryname, array('.', '..'))) |
|
| 1909 | - continue; |
|
| 2023 | + if (in_array($entryname, array('.', '..'))) { |
|
| 2024 | + continue; |
|
| 2025 | + } |
|
| 1910 | 2026 | |
| 1911 | - if (isset($package_ftp)) |
|
| 1912 | - $ftp_file = strtr($destination . '/' . $entryname, array($_SESSION['pack_ftp']['root'] => '')); |
|
| 2027 | + if (isset($package_ftp)) { |
|
| 2028 | + $ftp_file = strtr($destination . '/' . $entryname, array($_SESSION['pack_ftp']['root'] => '')); |
|
| 2029 | + } |
|
| 1913 | 2030 | |
| 1914 | 2031 | if (is_file($source . '/' . $entryname)) |
| 1915 | 2032 | { |
| 1916 | - if (isset($package_ftp) && !file_exists($destination . '/' . $entryname)) |
|
| 1917 | - $package_ftp->create_file($ftp_file); |
|
| 1918 | - elseif (!file_exists($destination . '/' . $entryname)) |
|
| 1919 | - @touch($destination . '/' . $entryname); |
|
| 2033 | + if (isset($package_ftp) && !file_exists($destination . '/' . $entryname)) { |
|
| 2034 | + $package_ftp->create_file($ftp_file); |
|
| 2035 | + } elseif (!file_exists($destination . '/' . $entryname)) { |
|
| 2036 | + @touch($destination . '/' . $entryname); |
|
| 2037 | + } |
|
| 1920 | 2038 | } |
| 1921 | 2039 | |
| 1922 | 2040 | package_chmod($destination . '/' . $entryname); |
| 1923 | 2041 | |
| 1924 | - if (is_dir($source . '/' . $entryname)) |
|
| 1925 | - copytree($source . '/' . $entryname, $destination . '/' . $entryname); |
|
| 1926 | - elseif (file_exists($destination . '/' . $entryname)) |
|
| 1927 | - package_put_contents($destination . '/' . $entryname, package_get_contents($source . '/' . $entryname)); |
|
| 1928 | - else |
|
| 1929 | - copy($source . '/' . $entryname, $destination . '/' . $entryname); |
|
| 2042 | + if (is_dir($source . '/' . $entryname)) { |
|
| 2043 | + copytree($source . '/' . $entryname, $destination . '/' . $entryname); |
|
| 2044 | + } elseif (file_exists($destination . '/' . $entryname)) { |
|
| 2045 | + package_put_contents($destination . '/' . $entryname, package_get_contents($source . '/' . $entryname)); |
|
| 2046 | + } else { |
|
| 2047 | + copy($source . '/' . $entryname, $destination . '/' . $entryname); |
|
| 2048 | + } |
|
| 1930 | 2049 | } |
| 1931 | 2050 | |
| 1932 | 2051 | closedir($current_dir); |
@@ -1944,21 +2063,24 @@ discard block |
||
| 1944 | 2063 | $data = array(); |
| 1945 | 2064 | |
| 1946 | 2065 | $dir = @dir($path . $sub_path); |
| 1947 | - if (!$dir) |
|
| 1948 | - return array(); |
|
| 2066 | + if (!$dir) { |
|
| 2067 | + return array(); |
|
| 2068 | + } |
|
| 1949 | 2069 | while ($entry = $dir->read()) |
| 1950 | 2070 | { |
| 1951 | - if ($entry == '.' || $entry == '..') |
|
| 1952 | - continue; |
|
| 2071 | + if ($entry == '.' || $entry == '..') { |
|
| 2072 | + continue; |
|
| 2073 | + } |
|
| 1953 | 2074 | |
| 1954 | - if (is_dir($path . $sub_path . '/' . $entry)) |
|
| 1955 | - $data = array_merge($data, listtree($path, $sub_path . '/' . $entry)); |
|
| 1956 | - else |
|
| 1957 | - $data[] = array( |
|
| 2075 | + if (is_dir($path . $sub_path . '/' . $entry)) { |
|
| 2076 | + $data = array_merge($data, listtree($path, $sub_path . '/' . $entry)); |
|
| 2077 | + } else { |
|
| 2078 | + $data[] = array( |
|
| 1958 | 2079 | 'filename' => $sub_path == '' ? $entry : $sub_path . '/' . $entry, |
| 1959 | 2080 | 'size' => filesize($path . $sub_path . '/' . $entry), |
| 1960 | 2081 | 'skipped' => false, |
| 1961 | 2082 | ); |
| 2083 | + } |
|
| 1962 | 2084 | } |
| 1963 | 2085 | $dir->close(); |
| 1964 | 2086 | |
@@ -2013,8 +2135,9 @@ discard block |
||
| 2013 | 2135 | { |
| 2014 | 2136 | // If this filename is relative, if so take a guess at what it should be. |
| 2015 | 2137 | $real_filename = $filename; |
| 2016 | - if (strpos($filename, 'Themes') === 0) |
|
| 2017 | - $real_filename = $boarddir . '/' . $filename; |
|
| 2138 | + if (strpos($filename, 'Themes') === 0) { |
|
| 2139 | + $real_filename = $boarddir . '/' . $filename; |
|
| 2140 | + } |
|
| 2018 | 2141 | |
| 2019 | 2142 | if (strpos($real_filename, $theme['theme_dir']) === 0) |
| 2020 | 2143 | { |
@@ -2033,8 +2156,9 @@ discard block |
||
| 2033 | 2156 | foreach ($theme_paths as $id => $theme) |
| 2034 | 2157 | { |
| 2035 | 2158 | // Default is getting done anyway, so no need for involvement here. |
| 2036 | - if ($id == 1) |
|
| 2037 | - continue; |
|
| 2159 | + if ($id == 1) { |
|
| 2160 | + continue; |
|
| 2161 | + } |
|
| 2038 | 2162 | |
| 2039 | 2163 | // For every template, do we want it? Yea, no, maybe? |
| 2040 | 2164 | foreach ($template_changes[1] as $index => $template_file) |
@@ -2057,8 +2181,9 @@ discard block |
||
| 2057 | 2181 | ); |
| 2058 | 2182 | |
| 2059 | 2183 | // Sometimes though, we have some additional files for other themes, if we have add them to the mix. |
| 2060 | - if (isset($custom_themes_add[$files_to_change[1]])) |
|
| 2061 | - $files_to_change += $custom_themes_add[$files_to_change[1]]; |
|
| 2184 | + if (isset($custom_themes_add[$files_to_change[1]])) { |
|
| 2185 | + $files_to_change += $custom_themes_add[$files_to_change[1]]; |
|
| 2186 | + } |
|
| 2062 | 2187 | |
| 2063 | 2188 | // Now, loop through all the files we're changing, and, well, change them ;) |
| 2064 | 2189 | foreach ($files_to_change as $theme => $working_file) |
@@ -2092,11 +2217,13 @@ discard block |
||
| 2092 | 2217 | continue; |
| 2093 | 2218 | } |
| 2094 | 2219 | // Okay, we're creating this file then...? |
| 2095 | - elseif (!file_exists($working_file)) |
|
| 2096 | - $working_data = ''; |
|
| 2220 | + elseif (!file_exists($working_file)) { |
|
| 2221 | + $working_data = ''; |
|
| 2222 | + } |
|
| 2097 | 2223 | // Phew, it exists! Load 'er up! |
| 2098 | - else |
|
| 2099 | - $working_data = str_replace("\r", '', package_get_contents($working_file)); |
|
| 2224 | + else { |
|
| 2225 | + $working_data = str_replace("\r", '', package_get_contents($working_file)); |
|
| 2226 | + } |
|
| 2100 | 2227 | |
| 2101 | 2228 | $actions[] = array( |
| 2102 | 2229 | 'type' => 'opened', |
@@ -2117,8 +2244,8 @@ discard block |
||
| 2117 | 2244 | |
| 2118 | 2245 | // Grab all search items of this operation (in most cases just 1). |
| 2119 | 2246 | $searches = $operation->set('search'); |
| 2120 | - foreach ($searches as $i => $search) |
|
| 2121 | - $actual_operation['searches'][] = array( |
|
| 2247 | + foreach ($searches as $i => $search) { |
|
| 2248 | + $actual_operation['searches'][] = array( |
|
| 2122 | 2249 | 'position' => $search->exists('@position') && in_array(trim($search->fetch('@position')), array('before', 'after', 'replace', 'end')) ? trim($search->fetch('@position')) : 'replace', |
| 2123 | 2250 | 'is_reg_exp' => $search->exists('@regexp') && trim($search->fetch('@regexp')) === 'true', |
| 2124 | 2251 | 'loose_whitespace' => $search->exists('@whitespace') && trim($search->fetch('@whitespace')) === 'loose', |
@@ -2127,6 +2254,7 @@ discard block |
||
| 2127 | 2254 | 'preg_search' => '', |
| 2128 | 2255 | 'preg_replace' => '', |
| 2129 | 2256 | ); |
| 2257 | + } |
|
| 2130 | 2258 | |
| 2131 | 2259 | // At least one search should be defined. |
| 2132 | 2260 | if (empty($actual_operation['searches'])) |
@@ -2151,30 +2279,32 @@ discard block |
||
| 2151 | 2279 | // Reverse modification of regular expressions are not allowed. |
| 2152 | 2280 | if ($search['is_reg_exp']) |
| 2153 | 2281 | { |
| 2154 | - if ($actual_operation['error'] === 'fatal') |
|
| 2155 | - $actions[] = array( |
|
| 2282 | + if ($actual_operation['error'] === 'fatal') { |
|
| 2283 | + $actions[] = array( |
|
| 2156 | 2284 | 'type' => 'failure', |
| 2157 | 2285 | 'filename' => $working_file, |
| 2158 | 2286 | 'search' => $search['search'], |
| 2159 | 2287 | 'is_custom' => $theme > 1 ? $theme : 0, |
| 2160 | 2288 | ); |
| 2289 | + } |
|
| 2161 | 2290 | |
| 2162 | 2291 | // Continue to the next operation. |
| 2163 | 2292 | continue 2; |
| 2164 | 2293 | } |
| 2165 | 2294 | |
| 2166 | 2295 | // The replacement is now the search subject... |
| 2167 | - if ($search['position'] === 'replace' || $search['position'] === 'end') |
|
| 2168 | - $actual_operation['searches'][$i]['search'] = $search['add']; |
|
| 2169 | - else |
|
| 2296 | + if ($search['position'] === 'replace' || $search['position'] === 'end') { |
|
| 2297 | + $actual_operation['searches'][$i]['search'] = $search['add']; |
|
| 2298 | + } else |
|
| 2170 | 2299 | { |
| 2171 | 2300 | // Reversing a before/after modification becomes a replacement. |
| 2172 | 2301 | $actual_operation['searches'][$i]['position'] = 'replace'; |
| 2173 | 2302 | |
| 2174 | - if ($search['position'] === 'before') |
|
| 2175 | - $actual_operation['searches'][$i]['search'] .= $search['add']; |
|
| 2176 | - elseif ($search['position'] === 'after') |
|
| 2177 | - $actual_operation['searches'][$i]['search'] = $search['add'] . $search['search']; |
|
| 2303 | + if ($search['position'] === 'before') { |
|
| 2304 | + $actual_operation['searches'][$i]['search'] .= $search['add']; |
|
| 2305 | + } elseif ($search['position'] === 'after') { |
|
| 2306 | + $actual_operation['searches'][$i]['search'] = $search['add'] . $search['search']; |
|
| 2307 | + } |
|
| 2178 | 2308 | } |
| 2179 | 2309 | |
| 2180 | 2310 | // ...and the search subject is now the replacement. |
@@ -2202,16 +2332,17 @@ discard block |
||
| 2202 | 2332 | foreach ($actual_operation['searches'] as $i => $search) |
| 2203 | 2333 | { |
| 2204 | 2334 | // Not much needed if the search subject is already a regexp. |
| 2205 | - if ($search['is_reg_exp']) |
|
| 2206 | - $actual_operation['searches'][$i]['preg_search'] = $search['search']; |
|
| 2207 | - else |
|
| 2335 | + if ($search['is_reg_exp']) { |
|
| 2336 | + $actual_operation['searches'][$i]['preg_search'] = $search['search']; |
|
| 2337 | + } else |
|
| 2208 | 2338 | { |
| 2209 | 2339 | // Make the search subject fit into a regular expression. |
| 2210 | 2340 | $actual_operation['searches'][$i]['preg_search'] = preg_quote($search['search'], '~'); |
| 2211 | 2341 | |
| 2212 | 2342 | // Using 'loose', a random amount of tabs and spaces may be used. |
| 2213 | - if ($search['loose_whitespace']) |
|
| 2214 | - $actual_operation['searches'][$i]['preg_search'] = preg_replace('~[ \t]+~', '[ \t]+', $actual_operation['searches'][$i]['preg_search']); |
|
| 2343 | + if ($search['loose_whitespace']) { |
|
| 2344 | + $actual_operation['searches'][$i]['preg_search'] = preg_replace('~[ \t]+~', '[ \t]+', $actual_operation['searches'][$i]['preg_search']); |
|
| 2345 | + } |
|
| 2215 | 2346 | } |
| 2216 | 2347 | |
| 2217 | 2348 | // Shuzzup. This is done so we can safely use a regular expression. ($0 is bad!!) |
@@ -2237,8 +2368,7 @@ discard block |
||
| 2237 | 2368 | if ($undo) |
| 2238 | 2369 | { |
| 2239 | 2370 | $actual_operation['searches'][$i]['preg_replace'] = ''; |
| 2240 | - } |
|
| 2241 | - else |
|
| 2371 | + } else |
|
| 2242 | 2372 | { |
| 2243 | 2373 | $actual_operation['searches'][$i]['preg_search'] = '(\\n\\?\\>)?$'; |
| 2244 | 2374 | $actual_operation['searches'][$i]['preg_replace'] .= '$1'; |
@@ -2285,8 +2415,9 @@ discard block |
||
| 2285 | 2415 | } |
| 2286 | 2416 | |
| 2287 | 2417 | // Replace it into nothing? That's not an option...unless it's an undoing end. |
| 2288 | - if ($search['add'] === '' && ($search['position'] !== 'end' || !$undo)) |
|
| 2289 | - continue; |
|
| 2418 | + if ($search['add'] === '' && ($search['position'] !== 'end' || !$undo)) { |
|
| 2419 | + continue; |
|
| 2420 | + } |
|
| 2290 | 2421 | |
| 2291 | 2422 | // Finally, we're doing some replacements. |
| 2292 | 2423 | $working_data = preg_replace('~' . $actual_operation['searches'][$i]['preg_search'] . '~s', $actual_operation['searches'][$i]['preg_replace'], $working_data, 1); |
@@ -2311,22 +2442,25 @@ discard block |
||
| 2311 | 2442 | |
| 2312 | 2443 | package_chmod($working_file); |
| 2313 | 2444 | |
| 2314 | - if ((file_exists($working_file) && !is_writable($working_file)) || (!file_exists($working_file) && !is_writable(dirname($working_file)))) |
|
| 2315 | - $actions[] = array( |
|
| 2445 | + if ((file_exists($working_file) && !is_writable($working_file)) || (!file_exists($working_file) && !is_writable(dirname($working_file)))) { |
|
| 2446 | + $actions[] = array( |
|
| 2316 | 2447 | 'type' => 'chmod', |
| 2317 | 2448 | 'filename' => $working_file |
| 2318 | 2449 | ); |
| 2450 | + } |
|
| 2319 | 2451 | |
| 2320 | - if (basename($working_file) == 'Settings_bak.php') |
|
| 2321 | - continue; |
|
| 2452 | + if (basename($working_file) == 'Settings_bak.php') { |
|
| 2453 | + continue; |
|
| 2454 | + } |
|
| 2322 | 2455 | |
| 2323 | 2456 | if (!$testing && !empty($modSettings['package_make_backups']) && file_exists($working_file)) |
| 2324 | 2457 | { |
| 2325 | 2458 | // No, no, not Settings.php! |
| 2326 | - if (basename($working_file) == 'Settings.php') |
|
| 2327 | - @copy($working_file, dirname($working_file) . '/Settings_bak.php'); |
|
| 2328 | - else |
|
| 2329 | - @copy($working_file, $working_file . '~'); |
|
| 2459 | + if (basename($working_file) == 'Settings.php') { |
|
| 2460 | + @copy($working_file, dirname($working_file) . '/Settings_bak.php'); |
|
| 2461 | + } else { |
|
| 2462 | + @copy($working_file, $working_file . '~'); |
|
| 2463 | + } |
|
| 2330 | 2464 | } |
| 2331 | 2465 | |
| 2332 | 2466 | // Always call this, even if in testing, because it won't really be written in testing mode. |
@@ -2393,8 +2527,9 @@ discard block |
||
| 2393 | 2527 | if ($code_match[1] != 'edit file' && $code_match[1] != 'file') |
| 2394 | 2528 | { |
| 2395 | 2529 | // It's a step, let's add that to the current steps. |
| 2396 | - if (isset($temp_changes[$step_counter])) |
|
| 2397 | - $temp_changes[$step_counter]['changes'][] = $code_match[0]; |
|
| 2530 | + if (isset($temp_changes[$step_counter])) { |
|
| 2531 | + $temp_changes[$step_counter]['changes'][] = $code_match[0]; |
|
| 2532 | + } |
|
| 2398 | 2533 | continue; |
| 2399 | 2534 | } |
| 2400 | 2535 | |
@@ -2411,11 +2546,13 @@ discard block |
||
| 2411 | 2546 | foreach ($theme_paths as $id => $theme) |
| 2412 | 2547 | { |
| 2413 | 2548 | // If this filename is relative, if so take a guess at what it should be. |
| 2414 | - if (strpos($filename, 'Themes') === 0) |
|
| 2415 | - $filename = $boarddir . '/' . $filename; |
|
| 2549 | + if (strpos($filename, 'Themes') === 0) { |
|
| 2550 | + $filename = $boarddir . '/' . $filename; |
|
| 2551 | + } |
|
| 2416 | 2552 | |
| 2417 | - if (strpos($filename, $theme['theme_dir']) === 0) |
|
| 2418 | - $template_changes[$id][$counter] = substr($filename, strlen($theme['theme_dir']) + 1); |
|
| 2553 | + if (strpos($filename, $theme['theme_dir']) === 0) { |
|
| 2554 | + $template_changes[$id][$counter] = substr($filename, strlen($theme['theme_dir']) + 1); |
|
| 2555 | + } |
|
| 2419 | 2556 | } |
| 2420 | 2557 | } |
| 2421 | 2558 | |
@@ -2428,8 +2565,9 @@ discard block |
||
| 2428 | 2565 | foreach ($theme_paths as $id => $theme) |
| 2429 | 2566 | { |
| 2430 | 2567 | // Don't do default, it means nothing to me. |
| 2431 | - if ($id == 1) |
|
| 2432 | - continue; |
|
| 2568 | + if ($id == 1) { |
|
| 2569 | + continue; |
|
| 2570 | + } |
|
| 2433 | 2571 | |
| 2434 | 2572 | // Now, for each file do we need to edit it? |
| 2435 | 2573 | foreach ($template_changes[1] as $pos => $template_file) |
@@ -2465,32 +2603,36 @@ discard block |
||
| 2465 | 2603 | package_chmod($working_file); |
| 2466 | 2604 | |
| 2467 | 2605 | // Don't even dare. |
| 2468 | - if (basename($working_file) == 'Settings_bak.php') |
|
| 2469 | - continue; |
|
| 2606 | + if (basename($working_file) == 'Settings_bak.php') { |
|
| 2607 | + continue; |
|
| 2608 | + } |
|
| 2470 | 2609 | |
| 2471 | - if (!is_writable($working_file)) |
|
| 2472 | - $actions[] = array( |
|
| 2610 | + if (!is_writable($working_file)) { |
|
| 2611 | + $actions[] = array( |
|
| 2473 | 2612 | 'type' => 'chmod', |
| 2474 | 2613 | 'filename' => $working_file |
| 2475 | 2614 | ); |
| 2615 | + } |
|
| 2476 | 2616 | |
| 2477 | 2617 | if (!$testing && !empty($modSettings['package_make_backups']) && file_exists($working_file)) |
| 2478 | 2618 | { |
| 2479 | - if (basename($working_file) == 'Settings.php') |
|
| 2480 | - @copy($working_file, dirname($working_file) . '/Settings_bak.php'); |
|
| 2481 | - else |
|
| 2482 | - @copy($working_file, $working_file . '~'); |
|
| 2619 | + if (basename($working_file) == 'Settings.php') { |
|
| 2620 | + @copy($working_file, dirname($working_file) . '/Settings_bak.php'); |
|
| 2621 | + } else { |
|
| 2622 | + @copy($working_file, $working_file . '~'); |
|
| 2623 | + } |
|
| 2483 | 2624 | } |
| 2484 | 2625 | |
| 2485 | 2626 | package_put_contents($working_file, $working_data, $testing); |
| 2486 | 2627 | } |
| 2487 | 2628 | |
| 2488 | - if ($working_file !== null) |
|
| 2489 | - $actions[] = array( |
|
| 2629 | + if ($working_file !== null) { |
|
| 2630 | + $actions[] = array( |
|
| 2490 | 2631 | 'type' => 'saved', |
| 2491 | 2632 | 'filename' => $working_file, |
| 2492 | 2633 | 'is_custom' => $is_custom, |
| 2493 | 2634 | ); |
| 2635 | + } |
|
| 2494 | 2636 | |
| 2495 | 2637 | // Is this "now working on" file a theme specific one? |
| 2496 | 2638 | $is_custom = isset($theme_id_ref[$counter - 1]) ? $theme_id_ref[$counter - 1] : 0; |
@@ -2509,10 +2651,11 @@ discard block |
||
| 2509 | 2651 | { |
| 2510 | 2652 | $places_to_check = array($boarddir, $sourcedir, $settings['default_theme_dir'], $settings['default_theme_dir'] . '/languages'); |
| 2511 | 2653 | |
| 2512 | - foreach ($places_to_check as $place) |
|
| 2513 | - if (file_exists($place . '/' . $working_file)) |
|
| 2654 | + foreach ($places_to_check as $place) { |
|
| 2655 | + if (file_exists($place . '/' . $working_file)) |
|
| 2514 | 2656 | { |
| 2515 | 2657 | $working_file = $place . '/' . $working_file; |
| 2658 | + } |
|
| 2516 | 2659 | break; |
| 2517 | 2660 | } |
| 2518 | 2661 | } |
@@ -2526,8 +2669,7 @@ discard block |
||
| 2526 | 2669 | 'type' => 'opened', |
| 2527 | 2670 | 'filename' => $working_file |
| 2528 | 2671 | ); |
| 2529 | - } |
|
| 2530 | - else |
|
| 2672 | + } else |
|
| 2531 | 2673 | { |
| 2532 | 2674 | $actions[] = array( |
| 2533 | 2675 | 'type' => 'missing', |
@@ -2563,11 +2705,13 @@ discard block |
||
| 2563 | 2705 | $replace_with = $code_match[2]; |
| 2564 | 2706 | |
| 2565 | 2707 | // Add this afterward... |
| 2566 | - if ($code_match[1] == 'add' || $code_match[1] == 'add after') |
|
| 2567 | - $replace_with = $working_search . "\n" . $replace_with; |
|
| 2708 | + if ($code_match[1] == 'add' || $code_match[1] == 'add after') { |
|
| 2709 | + $replace_with = $working_search . "\n" . $replace_with; |
|
| 2710 | + } |
|
| 2568 | 2711 | // Add this beforehand. |
| 2569 | - elseif ($code_match[1] == 'before' || $code_match[1] == 'add before' || $code_match[1] == 'above' || $code_match[1] == 'add above') |
|
| 2570 | - $replace_with .= "\n" . $working_search; |
|
| 2712 | + elseif ($code_match[1] == 'before' || $code_match[1] == 'add before' || $code_match[1] == 'above' || $code_match[1] == 'add above') { |
|
| 2713 | + $replace_with .= "\n" . $working_search; |
|
| 2714 | + } |
|
| 2571 | 2715 | // Otherwise.. replace with $replace_with ;). |
| 2572 | 2716 | } |
| 2573 | 2717 | |
@@ -2630,29 +2774,32 @@ discard block |
||
| 2630 | 2774 | { |
| 2631 | 2775 | package_chmod($working_file); |
| 2632 | 2776 | |
| 2633 | - if (!is_writable($working_file)) |
|
| 2634 | - $actions[] = array( |
|
| 2777 | + if (!is_writable($working_file)) { |
|
| 2778 | + $actions[] = array( |
|
| 2635 | 2779 | 'type' => 'chmod', |
| 2636 | 2780 | 'filename' => $working_file |
| 2637 | 2781 | ); |
| 2782 | + } |
|
| 2638 | 2783 | |
| 2639 | 2784 | if (!$testing && !empty($modSettings['package_make_backups']) && file_exists($working_file)) |
| 2640 | 2785 | { |
| 2641 | - if (basename($working_file) == 'Settings.php') |
|
| 2642 | - @copy($working_file, dirname($working_file) . '/Settings_bak.php'); |
|
| 2643 | - else |
|
| 2644 | - @copy($working_file, $working_file . '~'); |
|
| 2786 | + if (basename($working_file) == 'Settings.php') { |
|
| 2787 | + @copy($working_file, dirname($working_file) . '/Settings_bak.php'); |
|
| 2788 | + } else { |
|
| 2789 | + @copy($working_file, $working_file . '~'); |
|
| 2790 | + } |
|
| 2645 | 2791 | } |
| 2646 | 2792 | |
| 2647 | 2793 | package_put_contents($working_file, $working_data, $testing); |
| 2648 | 2794 | } |
| 2649 | 2795 | |
| 2650 | - if ($working_file !== null) |
|
| 2651 | - $actions[] = array( |
|
| 2796 | + if ($working_file !== null) { |
|
| 2797 | + $actions[] = array( |
|
| 2652 | 2798 | 'type' => 'saved', |
| 2653 | 2799 | 'filename' => $working_file, |
| 2654 | 2800 | 'is_custom' => $is_custom, |
| 2655 | 2801 | ); |
| 2802 | + } |
|
| 2656 | 2803 | |
| 2657 | 2804 | $actions[] = array( |
| 2658 | 2805 | 'type' => 'result', |
@@ -2678,17 +2825,19 @@ discard block |
||
| 2678 | 2825 | $mem_check = setMemoryLimit('128M'); |
| 2679 | 2826 | |
| 2680 | 2827 | // Windows doesn't seem to care about the memory_limit. |
| 2681 | - if (!empty($modSettings['package_disable_cache']) || $mem_check || stripos(PHP_OS, 'win') !== false) |
|
| 2682 | - $package_cache = array(); |
|
| 2683 | - else |
|
| 2684 | - $package_cache = false; |
|
| 2828 | + if (!empty($modSettings['package_disable_cache']) || $mem_check || stripos(PHP_OS, 'win') !== false) { |
|
| 2829 | + $package_cache = array(); |
|
| 2830 | + } else { |
|
| 2831 | + $package_cache = false; |
|
| 2832 | + } |
|
| 2685 | 2833 | } |
| 2686 | 2834 | |
| 2687 | - if (strpos($filename, 'Packages/') !== false || $package_cache === false || !isset($package_cache[$filename])) |
|
| 2688 | - return file_get_contents($filename); |
|
| 2689 | - else |
|
| 2690 | - return $package_cache[$filename]; |
|
| 2691 | -} |
|
| 2835 | + if (strpos($filename, 'Packages/') !== false || $package_cache === false || !isset($package_cache[$filename])) { |
|
| 2836 | + return file_get_contents($filename); |
|
| 2837 | + } else { |
|
| 2838 | + return $package_cache[$filename]; |
|
| 2839 | + } |
|
| 2840 | + } |
|
| 2692 | 2841 | |
| 2693 | 2842 | /** |
| 2694 | 2843 | * Writes data to a file, almost exactly like the file_put_contents() function. |
@@ -2712,19 +2861,22 @@ discard block |
||
| 2712 | 2861 | // Try to increase the memory limit - we don't want to run out of ram! |
| 2713 | 2862 | $mem_check = setMemoryLimit('128M'); |
| 2714 | 2863 | |
| 2715 | - if (!empty($modSettings['package_disable_cache']) || $mem_check || stripos(PHP_OS, 'win') !== false) |
|
| 2716 | - $package_cache = array(); |
|
| 2717 | - else |
|
| 2718 | - $package_cache = false; |
|
| 2864 | + if (!empty($modSettings['package_disable_cache']) || $mem_check || stripos(PHP_OS, 'win') !== false) { |
|
| 2865 | + $package_cache = array(); |
|
| 2866 | + } else { |
|
| 2867 | + $package_cache = false; |
|
| 2868 | + } |
|
| 2719 | 2869 | } |
| 2720 | 2870 | |
| 2721 | - if (isset($package_ftp)) |
|
| 2722 | - $ftp_file = strtr($filename, array($_SESSION['pack_ftp']['root'] => '')); |
|
| 2871 | + if (isset($package_ftp)) { |
|
| 2872 | + $ftp_file = strtr($filename, array($_SESSION['pack_ftp']['root'] => '')); |
|
| 2873 | + } |
|
| 2723 | 2874 | |
| 2724 | - if (!file_exists($filename) && isset($package_ftp)) |
|
| 2725 | - $package_ftp->create_file($ftp_file); |
|
| 2726 | - elseif (!file_exists($filename)) |
|
| 2727 | - @touch($filename); |
|
| 2875 | + if (!file_exists($filename) && isset($package_ftp)) { |
|
| 2876 | + $package_ftp->create_file($ftp_file); |
|
| 2877 | + } elseif (!file_exists($filename)) { |
|
| 2878 | + @touch($filename); |
|
| 2879 | + } |
|
| 2728 | 2880 | |
| 2729 | 2881 | package_chmod($filename); |
| 2730 | 2882 | |
@@ -2733,22 +2885,23 @@ discard block |
||
| 2733 | 2885 | $fp = @fopen($filename, in_array(substr($filename, -3), $text_filetypes) ? 'w' : 'wb'); |
| 2734 | 2886 | |
| 2735 | 2887 | // We should show an error message or attempt a rollback, no? |
| 2736 | - if (!$fp) |
|
| 2737 | - return false; |
|
| 2888 | + if (!$fp) { |
|
| 2889 | + return false; |
|
| 2890 | + } |
|
| 2738 | 2891 | |
| 2739 | 2892 | fwrite($fp, $data); |
| 2740 | 2893 | fclose($fp); |
| 2741 | - } |
|
| 2742 | - elseif (strpos($filename, 'Packages/') !== false || $package_cache === false) |
|
| 2743 | - return strlen($data); |
|
| 2744 | - else |
|
| 2894 | + } elseif (strpos($filename, 'Packages/') !== false || $package_cache === false) { |
|
| 2895 | + return strlen($data); |
|
| 2896 | + } else |
|
| 2745 | 2897 | { |
| 2746 | 2898 | $package_cache[$filename] = $data; |
| 2747 | 2899 | |
| 2748 | 2900 | // Permission denied, eh? |
| 2749 | 2901 | $fp = @fopen($filename, 'r+'); |
| 2750 | - if (!$fp) |
|
| 2751 | - return false; |
|
| 2902 | + if (!$fp) { |
|
| 2903 | + return false; |
|
| 2904 | + } |
|
| 2752 | 2905 | fclose($fp); |
| 2753 | 2906 | } |
| 2754 | 2907 | |
@@ -2766,19 +2919,22 @@ discard block |
||
| 2766 | 2919 | global $package_ftp, $package_cache; |
| 2767 | 2920 | static $text_filetypes = array('php', 'txt', '.js', 'css', 'vbs', 'tml', 'htm'); |
| 2768 | 2921 | |
| 2769 | - if (empty($package_cache)) |
|
| 2770 | - return; |
|
| 2922 | + if (empty($package_cache)) { |
|
| 2923 | + return; |
|
| 2924 | + } |
|
| 2771 | 2925 | |
| 2772 | 2926 | // First, let's check permissions! |
| 2773 | 2927 | foreach ($package_cache as $filename => $data) |
| 2774 | 2928 | { |
| 2775 | - if (isset($package_ftp)) |
|
| 2776 | - $ftp_file = strtr($filename, array($_SESSION['pack_ftp']['root'] => '')); |
|
| 2929 | + if (isset($package_ftp)) { |
|
| 2930 | + $ftp_file = strtr($filename, array($_SESSION['pack_ftp']['root'] => '')); |
|
| 2931 | + } |
|
| 2777 | 2932 | |
| 2778 | - if (!file_exists($filename) && isset($package_ftp)) |
|
| 2779 | - $package_ftp->create_file($ftp_file); |
|
| 2780 | - elseif (!file_exists($filename)) |
|
| 2781 | - @touch($filename); |
|
| 2933 | + if (!file_exists($filename) && isset($package_ftp)) { |
|
| 2934 | + $package_ftp->create_file($ftp_file); |
|
| 2935 | + } elseif (!file_exists($filename)) { |
|
| 2936 | + @touch($filename); |
|
| 2937 | + } |
|
| 2782 | 2938 | |
| 2783 | 2939 | $result = package_chmod($filename); |
| 2784 | 2940 | |
@@ -2832,8 +2988,9 @@ discard block |
||
| 2832 | 2988 | /** @var ftp_connection $package_ftp */ |
| 2833 | 2989 | global $package_ftp; |
| 2834 | 2990 | |
| 2835 | - if (file_exists($filename) && is_writable($filename) && $perm_state == 'writable') |
|
| 2836 | - return true; |
|
| 2991 | + if (file_exists($filename) && is_writable($filename) && $perm_state == 'writable') { |
|
| 2992 | + return true; |
|
| 2993 | + } |
|
| 2837 | 2994 | |
| 2838 | 2995 | // Start off checking without FTP. |
| 2839 | 2996 | if (!isset($package_ftp) || $package_ftp === false) |
@@ -2855,8 +3012,7 @@ discard block |
||
| 2855 | 3012 | |
| 2856 | 3013 | // Keep track of the writable status here. |
| 2857 | 3014 | $file_permissions = @fileperms($chmod_file); |
| 2858 | - } |
|
| 2859 | - else |
|
| 3015 | + } else |
|
| 2860 | 3016 | { |
| 2861 | 3017 | // This looks odd, but it's an attempt to work around PHP suExec. |
| 2862 | 3018 | if (!file_exists($chmod_file) && $perm_state == 'writable') |
@@ -2866,24 +3022,28 @@ discard block |
||
| 2866 | 3022 | mktree(dirname($chmod_file), 0755); |
| 2867 | 3023 | @touch($chmod_file); |
| 2868 | 3024 | smf_chmod($chmod_file, 0755); |
| 3025 | + } else { |
|
| 3026 | + $file_permissions = @fileperms($chmod_file); |
|
| 2869 | 3027 | } |
| 2870 | - else |
|
| 2871 | - $file_permissions = @fileperms($chmod_file); |
|
| 2872 | 3028 | } |
| 2873 | 3029 | |
| 2874 | 3030 | // This looks odd, but it's another attempt to work around PHP suExec. |
| 2875 | - if ($perm_state != 'writable') |
|
| 2876 | - smf_chmod($chmod_file, $perm_state == 'execute' ? 0755 : 0644); |
|
| 2877 | - else |
|
| 3031 | + if ($perm_state != 'writable') { |
|
| 3032 | + smf_chmod($chmod_file, $perm_state == 'execute' ? 0755 : 0644); |
|
| 3033 | + } else |
|
| 2878 | 3034 | { |
| 2879 | - if (!@is_writable($chmod_file)) |
|
| 2880 | - smf_chmod($chmod_file, 0755); |
|
| 2881 | - if (!@is_writable($chmod_file)) |
|
| 2882 | - smf_chmod($chmod_file, 0777); |
|
| 2883 | - if (!@is_writable(dirname($chmod_file))) |
|
| 2884 | - smf_chmod($chmod_file, 0755); |
|
| 2885 | - if (!@is_writable(dirname($chmod_file))) |
|
| 2886 | - smf_chmod($chmod_file, 0777); |
|
| 3035 | + if (!@is_writable($chmod_file)) { |
|
| 3036 | + smf_chmod($chmod_file, 0755); |
|
| 3037 | + } |
|
| 3038 | + if (!@is_writable($chmod_file)) { |
|
| 3039 | + smf_chmod($chmod_file, 0777); |
|
| 3040 | + } |
|
| 3041 | + if (!@is_writable(dirname($chmod_file))) { |
|
| 3042 | + smf_chmod($chmod_file, 0755); |
|
| 3043 | + } |
|
| 3044 | + if (!@is_writable(dirname($chmod_file))) { |
|
| 3045 | + smf_chmod($chmod_file, 0777); |
|
| 3046 | + } |
|
| 2887 | 3047 | } |
| 2888 | 3048 | |
| 2889 | 3049 | // The ultimate writable test. |
@@ -2892,20 +3052,22 @@ discard block |
||
| 2892 | 3052 | $fp = is_dir($chmod_file) ? @opendir($chmod_file) : @fopen($chmod_file, 'rb'); |
| 2893 | 3053 | if (@is_writable($chmod_file) && $fp) |
| 2894 | 3054 | { |
| 2895 | - if (!is_dir($chmod_file)) |
|
| 2896 | - fclose($fp); |
|
| 2897 | - else |
|
| 2898 | - closedir($fp); |
|
| 3055 | + if (!is_dir($chmod_file)) { |
|
| 3056 | + fclose($fp); |
|
| 3057 | + } else { |
|
| 3058 | + closedir($fp); |
|
| 3059 | + } |
|
| 2899 | 3060 | |
| 2900 | 3061 | // It worked! |
| 2901 | - if ($track_change) |
|
| 2902 | - $_SESSION['pack_ftp']['original_perms'][$chmod_file] = $file_permissions; |
|
| 3062 | + if ($track_change) { |
|
| 3063 | + $_SESSION['pack_ftp']['original_perms'][$chmod_file] = $file_permissions; |
|
| 3064 | + } |
|
| 2903 | 3065 | |
| 2904 | 3066 | return true; |
| 2905 | 3067 | } |
| 3068 | + } elseif ($perm_state != 'writable' && isset($_SESSION['pack_ftp']['original_perms'][$chmod_file])) { |
|
| 3069 | + unset($_SESSION['pack_ftp']['original_perms'][$chmod_file]); |
|
| 2906 | 3070 | } |
| 2907 | - elseif ($perm_state != 'writable' && isset($_SESSION['pack_ftp']['original_perms'][$chmod_file])) |
|
| 2908 | - unset($_SESSION['pack_ftp']['original_perms'][$chmod_file]); |
|
| 2909 | 3071 | } |
| 2910 | 3072 | |
| 2911 | 3073 | // If we're here we're a failure. |
@@ -2924,31 +3086,33 @@ discard block |
||
| 2924 | 3086 | mktree(dirname($filename), 0755); |
| 2925 | 3087 | $package_ftp->create_file($ftp_file); |
| 2926 | 3088 | $package_ftp->chmod($ftp_file, 0755); |
| 3089 | + } else { |
|
| 3090 | + $file_permissions = @fileperms($filename); |
|
| 2927 | 3091 | } |
| 2928 | - else |
|
| 2929 | - $file_permissions = @fileperms($filename); |
|
| 2930 | 3092 | |
| 2931 | 3093 | if ($perm_state != 'writable') |
| 2932 | 3094 | { |
| 2933 | 3095 | $package_ftp->chmod($ftp_file, $perm_state == 'execute' ? 0755 : 0644); |
| 2934 | - } |
|
| 2935 | - else |
|
| 3096 | + } else |
|
| 2936 | 3097 | { |
| 2937 | - if (!@is_writable($filename)) |
|
| 2938 | - $package_ftp->chmod($ftp_file, 0777); |
|
| 2939 | - if (!@is_writable(dirname($filename))) |
|
| 2940 | - $package_ftp->chmod(dirname($ftp_file), 0777); |
|
| 3098 | + if (!@is_writable($filename)) { |
|
| 3099 | + $package_ftp->chmod($ftp_file, 0777); |
|
| 3100 | + } |
|
| 3101 | + if (!@is_writable(dirname($filename))) { |
|
| 3102 | + $package_ftp->chmod(dirname($ftp_file), 0777); |
|
| 3103 | + } |
|
| 2941 | 3104 | } |
| 2942 | 3105 | |
| 2943 | 3106 | if (@is_writable($filename)) |
| 2944 | 3107 | { |
| 2945 | - if ($track_change) |
|
| 2946 | - $_SESSION['pack_ftp']['original_perms'][$filename] = $file_permissions; |
|
| 3108 | + if ($track_change) { |
|
| 3109 | + $_SESSION['pack_ftp']['original_perms'][$filename] = $file_permissions; |
|
| 3110 | + } |
|
| 2947 | 3111 | |
| 2948 | 3112 | return true; |
| 3113 | + } elseif ($perm_state != 'writable' && isset($_SESSION['pack_ftp']['original_perms'][$filename])) { |
|
| 3114 | + unset($_SESSION['pack_ftp']['original_perms'][$filename]); |
|
| 2949 | 3115 | } |
| 2950 | - elseif ($perm_state != 'writable' && isset($_SESSION['pack_ftp']['original_perms'][$filename])) |
|
| 2951 | - unset($_SESSION['pack_ftp']['original_perms'][$filename]); |
|
| 2952 | 3116 | } |
| 2953 | 3117 | |
| 2954 | 3118 | // Oh dear, we failed if we get here. |
@@ -2966,11 +3130,13 @@ discard block |
||
| 2966 | 3130 | $n = strlen($pass); |
| 2967 | 3131 | |
| 2968 | 3132 | $salt = session_id(); |
| 2969 | - while (strlen($salt) < $n) |
|
| 2970 | - $salt .= session_id(); |
|
| 3133 | + while (strlen($salt) < $n) { |
|
| 3134 | + $salt .= session_id(); |
|
| 3135 | + } |
|
| 2971 | 3136 | |
| 2972 | - for ($i = 0; $i < $n; $i++) |
|
| 2973 | - $pass{$i} = chr(ord($pass{$i}) ^ (ord($salt{$i}) - 32)); |
|
| 3137 | + for ($i = 0; $i < $n; $i++) { |
|
| 3138 | + $pass{$i} = chr(ord($pass{$i}) ^ (ord($salt{$i}) - 32)); |
|
| 3139 | + } |
|
| 2974 | 3140 | |
| 2975 | 3141 | return $pass; |
| 2976 | 3142 | } |
@@ -2989,8 +3155,9 @@ discard block |
||
| 2989 | 3155 | $base_files = array('index.php', 'SSI.php', 'agreement.txt', 'cron.php', 'ssi_examples.php', 'ssi_examples.shtml', 'subscriptions.php'); |
| 2990 | 3156 | foreach ($base_files as $file) |
| 2991 | 3157 | { |
| 2992 | - if (file_exists($boarddir . '/' . $file)) |
|
| 2993 | - $files[empty($_REQUEST['use_full_paths']) ? $file : $boarddir . '/' . $file] = $boarddir . '/' . $file; |
|
| 3158 | + if (file_exists($boarddir . '/' . $file)) { |
|
| 3159 | + $files[empty($_REQUEST['use_full_paths']) ? $file : $boarddir . '/' . $file] = $boarddir . '/' . $file; |
|
| 3160 | + } |
|
| 2994 | 3161 | } |
| 2995 | 3162 | |
| 2996 | 3163 | $dirs = array( |
@@ -3007,8 +3174,9 @@ discard block |
||
| 3007 | 3174 | 'theme_dir' => 'theme_dir', |
| 3008 | 3175 | ) |
| 3009 | 3176 | ); |
| 3010 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 3011 | - $dirs[$row['value']] = empty($_REQUEST['use_full_paths']) ? 'Themes/' . basename($row['value']) . '/' : strtr($row['value'] . '/', '\\', '/'); |
|
| 3177 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 3178 | + $dirs[$row['value']] = empty($_REQUEST['use_full_paths']) ? 'Themes/' . basename($row['value']) . '/' : strtr($row['value'] . '/', '\\', '/'); |
|
| 3179 | + } |
|
| 3012 | 3180 | $smcFunc['db_free_result']($request); |
| 3013 | 3181 | |
| 3014 | 3182 | try |
@@ -3023,11 +3191,13 @@ discard block |
||
| 3023 | 3191 | |
| 3024 | 3192 | foreach ($iter as $entry => $dir) |
| 3025 | 3193 | { |
| 3026 | - if ($dir->isDir()) |
|
| 3027 | - continue; |
|
| 3194 | + if ($dir->isDir()) { |
|
| 3195 | + continue; |
|
| 3196 | + } |
|
| 3028 | 3197 | |
| 3029 | - if (preg_match('~^(\.{1,2}|CVS|backup.*|help|images|.*\~)$~', $entry) != 0) |
|
| 3030 | - continue; |
|
| 3198 | + if (preg_match('~^(\.{1,2}|CVS|backup.*|help|images|.*\~)$~', $entry) != 0) { |
|
| 3199 | + continue; |
|
| 3200 | + } |
|
| 3031 | 3201 | |
| 3032 | 3202 | $files[empty($_REQUEST['use_full_paths']) ? str_replace(realpath($boarddir), '', $entry) : $entry] = $entry; |
| 3033 | 3203 | } |
@@ -3035,10 +3205,12 @@ discard block |
||
| 3035 | 3205 | $obj = new ArrayObject($files); |
| 3036 | 3206 | $iterator = $obj->getIterator(); |
| 3037 | 3207 | |
| 3038 | - if (!file_exists($packagesdir . '/backups')) |
|
| 3039 | - mktree($packagesdir . '/backups', 0777); |
|
| 3040 | - if (!is_writable($packagesdir . '/backups')) |
|
| 3041 | - package_chmod($packagesdir . '/backups'); |
|
| 3208 | + if (!file_exists($packagesdir . '/backups')) { |
|
| 3209 | + mktree($packagesdir . '/backups', 0777); |
|
| 3210 | + } |
|
| 3211 | + if (!is_writable($packagesdir . '/backups')) { |
|
| 3212 | + package_chmod($packagesdir . '/backups'); |
|
| 3213 | + } |
|
| 3042 | 3214 | $output_file = $packagesdir . '/backups/' . strftime('%Y-%m-%d_') . preg_replace('~[$\\\\/:<>|?*"\']~', '', $id); |
| 3043 | 3215 | $output_ext = '.tar'; |
| 3044 | 3216 | $output_ext_target = '.tar.gz'; |
@@ -3046,16 +3218,18 @@ discard block |
||
| 3046 | 3218 | if (file_exists($output_file . $output_ext_target)) |
| 3047 | 3219 | { |
| 3048 | 3220 | $i = 2; |
| 3049 | - while (file_exists($output_file . '_' . $i . $output_ext_target)) |
|
| 3050 | - $i++; |
|
| 3221 | + while (file_exists($output_file . '_' . $i . $output_ext_target)) { |
|
| 3222 | + $i++; |
|
| 3223 | + } |
|
| 3051 | 3224 | $output_file = $output_file . '_' . $i . $output_ext; |
| 3225 | + } else { |
|
| 3226 | + $output_file .= $output_ext; |
|
| 3052 | 3227 | } |
| 3053 | - else |
|
| 3054 | - $output_file .= $output_ext; |
|
| 3055 | 3228 | |
| 3056 | 3229 | @set_time_limit(300); |
| 3057 | - if (function_exists('apache_reset_timeout')) |
|
| 3058 | - @apache_reset_timeout(); |
|
| 3230 | + if (function_exists('apache_reset_timeout')) { |
|
| 3231 | + @apache_reset_timeout(); |
|
| 3232 | + } |
|
| 3059 | 3233 | |
| 3060 | 3234 | $a = new PharData($output_file); |
| 3061 | 3235 | $a->buildFromIterator($iterator); |
@@ -3067,8 +3241,7 @@ discard block |
||
| 3067 | 3241 | */ |
| 3068 | 3242 | unset($a); |
| 3069 | 3243 | unlink($output_file); |
| 3070 | - } |
|
| 3071 | - catch (Exception $e) |
|
| 3244 | + } catch (Exception $e) |
|
| 3072 | 3245 | { |
| 3073 | 3246 | log_error($e->getMessage(), 'backup'); |
| 3074 | 3247 | |
@@ -3100,32 +3273,35 @@ discard block |
||
| 3100 | 3273 | preg_match('~^(http|ftp)(s)?://([^/:]+)(:(\d+))?(.+)$~', $url, $match); |
| 3101 | 3274 | |
| 3102 | 3275 | // An FTP url. We should try connecting and RETRieving it... |
| 3103 | - if (empty($match[1])) |
|
| 3104 | - return false; |
|
| 3105 | - elseif ($match[1] == 'ftp') |
|
| 3276 | + if (empty($match[1])) { |
|
| 3277 | + return false; |
|
| 3278 | + } elseif ($match[1] == 'ftp') |
|
| 3106 | 3279 | { |
| 3107 | 3280 | // Include the file containing the ftp_connection class. |
| 3108 | 3281 | require_once($sourcedir . '/Class-Package.php'); |
| 3109 | 3282 | |
| 3110 | 3283 | // Establish a connection and attempt to enable passive mode. |
| 3111 | 3284 | $ftp = new ftp_connection(($match[2] ? 'ssl://' : '') . $match[3], empty($match[5]) ? 21 : $match[5], 'anonymous', $webmaster_email); |
| 3112 | - if ($ftp->error !== false || !$ftp->passive()) |
|
| 3113 | - return false; |
|
| 3285 | + if ($ftp->error !== false || !$ftp->passive()) { |
|
| 3286 | + return false; |
|
| 3287 | + } |
|
| 3114 | 3288 | |
| 3115 | 3289 | // I want that one *points*! |
| 3116 | 3290 | fwrite($ftp->connection, 'RETR ' . $match[6] . "\r\n"); |
| 3117 | 3291 | |
| 3118 | 3292 | // Since passive mode worked (or we would have returned already!) open the connection. |
| 3119 | 3293 | $fp = @fsockopen($ftp->pasv['ip'], $ftp->pasv['port'], $err, $err, 5); |
| 3120 | - if (!$fp) |
|
| 3121 | - return false; |
|
| 3294 | + if (!$fp) { |
|
| 3295 | + return false; |
|
| 3296 | + } |
|
| 3122 | 3297 | |
| 3123 | 3298 | // The server should now say something in acknowledgement. |
| 3124 | 3299 | $ftp->check_response(150); |
| 3125 | 3300 | |
| 3126 | 3301 | $data = ''; |
| 3127 | - while (!feof($fp)) |
|
| 3128 | - $data .= fread($fp, 4096); |
|
| 3302 | + while (!feof($fp)) { |
|
| 3303 | + $data .= fread($fp, 4096); |
|
| 3304 | + } |
|
| 3129 | 3305 | fclose($fp); |
| 3130 | 3306 | |
| 3131 | 3307 | // All done, right? Good. |
@@ -3142,22 +3318,25 @@ discard block |
||
| 3142 | 3318 | $fetch_data->get_url_data($url, $post_data); |
| 3143 | 3319 | |
| 3144 | 3320 | // no errors and a 200 result, then we have a good dataset, well we at least have data ;) |
| 3145 | - if ($fetch_data->result('code') == 200 && !$fetch_data->result('error')) |
|
| 3146 | - $data = $fetch_data->result('body'); |
|
| 3147 | - else |
|
| 3148 | - return false; |
|
| 3321 | + if ($fetch_data->result('code') == 200 && !$fetch_data->result('error')) { |
|
| 3322 | + $data = $fetch_data->result('body'); |
|
| 3323 | + } else { |
|
| 3324 | + return false; |
|
| 3325 | + } |
|
| 3149 | 3326 | } |
| 3150 | 3327 | // This is more likely; a standard HTTP URL. |
| 3151 | 3328 | elseif (isset($match[1]) && $match[1] == 'http') |
| 3152 | 3329 | { |
| 3153 | - if ($keep_alive && $match[3] == $keep_alive_dom) |
|
| 3154 | - $fp = $keep_alive_fp; |
|
| 3330 | + if ($keep_alive && $match[3] == $keep_alive_dom) { |
|
| 3331 | + $fp = $keep_alive_fp; |
|
| 3332 | + } |
|
| 3155 | 3333 | if (empty($fp)) |
| 3156 | 3334 | { |
| 3157 | 3335 | // Open the socket on the port we want... |
| 3158 | 3336 | $fp = @fsockopen(($match[2] ? 'ssl://' : '') . $match[3], empty($match[5]) ? ($match[2] ? 443 : 80) : $match[5], $err, $err, 5); |
| 3159 | - if (!$fp) |
|
| 3160 | - return false; |
|
| 3337 | + if (!$fp) { |
|
| 3338 | + return false; |
|
| 3339 | + } |
|
| 3161 | 3340 | } |
| 3162 | 3341 | |
| 3163 | 3342 | if ($keep_alive) |
@@ -3172,20 +3351,21 @@ discard block |
||
| 3172 | 3351 | fwrite($fp, 'GET ' . ($match[6] !== '/' ? str_replace(' ', '%20', $match[6]) : '') . ' HTTP/1.0' . "\r\n"); |
| 3173 | 3352 | fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n"); |
| 3174 | 3353 | fwrite($fp, 'User-Agent: PHP/SMF' . "\r\n"); |
| 3175 | - if ($keep_alive) |
|
| 3176 | - fwrite($fp, 'Connection: Keep-Alive' . "\r\n\r\n"); |
|
| 3177 | - else |
|
| 3178 | - fwrite($fp, 'Connection: close' . "\r\n\r\n"); |
|
| 3179 | - } |
|
| 3180 | - else |
|
| 3354 | + if ($keep_alive) { |
|
| 3355 | + fwrite($fp, 'Connection: Keep-Alive' . "\r\n\r\n"); |
|
| 3356 | + } else { |
|
| 3357 | + fwrite($fp, 'Connection: close' . "\r\n\r\n"); |
|
| 3358 | + } |
|
| 3359 | + } else |
|
| 3181 | 3360 | { |
| 3182 | 3361 | fwrite($fp, 'POST ' . ($match[6] !== '/' ? $match[6] : '') . ' HTTP/1.0' . "\r\n"); |
| 3183 | 3362 | fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n"); |
| 3184 | 3363 | fwrite($fp, 'User-Agent: PHP/SMF' . "\r\n"); |
| 3185 | - if ($keep_alive) |
|
| 3186 | - fwrite($fp, 'Connection: Keep-Alive' . "\r\n"); |
|
| 3187 | - else |
|
| 3188 | - fwrite($fp, 'Connection: close' . "\r\n"); |
|
| 3364 | + if ($keep_alive) { |
|
| 3365 | + fwrite($fp, 'Connection: Keep-Alive' . "\r\n"); |
|
| 3366 | + } else { |
|
| 3367 | + fwrite($fp, 'Connection: close' . "\r\n"); |
|
| 3368 | + } |
|
| 3189 | 3369 | fwrite($fp, 'Content-Type: application/x-www-form-urlencoded' . "\r\n"); |
| 3190 | 3370 | fwrite($fp, 'Content-Length: ' . strlen($post_data) . "\r\n\r\n"); |
| 3191 | 3371 | fwrite($fp, $post_data); |
@@ -3198,30 +3378,33 @@ discard block |
||
| 3198 | 3378 | { |
| 3199 | 3379 | $header = ''; |
| 3200 | 3380 | $location = ''; |
| 3201 | - while (!feof($fp) && trim($header = fgets($fp, 4096)) != '') |
|
| 3202 | - if (strpos($header, 'Location:') !== false) |
|
| 3381 | + while (!feof($fp) && trim($header = fgets($fp, 4096)) != '') { |
|
| 3382 | + if (strpos($header, 'Location:') !== false) |
|
| 3203 | 3383 | $location = trim(substr($header, strpos($header, ':') + 1)); |
| 3384 | + } |
|
| 3204 | 3385 | |
| 3205 | - if (empty($location)) |
|
| 3206 | - return false; |
|
| 3207 | - else |
|
| 3386 | + if (empty($location)) { |
|
| 3387 | + return false; |
|
| 3388 | + } else |
|
| 3208 | 3389 | { |
| 3209 | - if (!$keep_alive) |
|
| 3210 | - fclose($fp); |
|
| 3390 | + if (!$keep_alive) { |
|
| 3391 | + fclose($fp); |
|
| 3392 | + } |
|
| 3211 | 3393 | return fetch_web_data($location, $post_data, $keep_alive, $redirection_level + 1); |
| 3212 | 3394 | } |
| 3213 | 3395 | } |
| 3214 | 3396 | |
| 3215 | 3397 | // Make sure we get a 200 OK. |
| 3216 | - elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0) |
|
| 3217 | - return false; |
|
| 3398 | + elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0) { |
|
| 3399 | + return false; |
|
| 3400 | + } |
|
| 3218 | 3401 | |
| 3219 | 3402 | // Skip the headers... |
| 3220 | 3403 | while (!feof($fp) && trim($header = fgets($fp, 4096)) != '') |
| 3221 | 3404 | { |
| 3222 | - if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0) |
|
| 3223 | - $content_length = $match[1]; |
|
| 3224 | - elseif (preg_match('~connection:\s*close~i', $header) != 0) |
|
| 3405 | + if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0) { |
|
| 3406 | + $content_length = $match[1]; |
|
| 3407 | + } elseif (preg_match('~connection:\s*close~i', $header) != 0) |
|
| 3225 | 3408 | { |
| 3226 | 3409 | $keep_alive_dom = null; |
| 3227 | 3410 | $keep_alive = false; |
@@ -3233,19 +3416,20 @@ discard block |
||
| 3233 | 3416 | $data = ''; |
| 3234 | 3417 | if (isset($content_length)) |
| 3235 | 3418 | { |
| 3236 | - while (!feof($fp) && strlen($data) < $content_length) |
|
| 3237 | - $data .= fread($fp, $content_length - strlen($data)); |
|
| 3238 | - } |
|
| 3239 | - else |
|
| 3419 | + while (!feof($fp) && strlen($data) < $content_length) { |
|
| 3420 | + $data .= fread($fp, $content_length - strlen($data)); |
|
| 3421 | + } |
|
| 3422 | + } else |
|
| 3240 | 3423 | { |
| 3241 | - while (!feof($fp)) |
|
| 3242 | - $data .= fread($fp, 4096); |
|
| 3424 | + while (!feof($fp)) { |
|
| 3425 | + $data .= fread($fp, 4096); |
|
| 3426 | + } |
|
| 3243 | 3427 | } |
| 3244 | 3428 | |
| 3245 | - if (!$keep_alive) |
|
| 3246 | - fclose($fp); |
|
| 3247 | - } |
|
| 3248 | - else |
|
| 3429 | + if (!$keep_alive) { |
|
| 3430 | + fclose($fp); |
|
| 3431 | + } |
|
| 3432 | + } else |
|
| 3249 | 3433 | { |
| 3250 | 3434 | // Umm, this shouldn't happen? |
| 3251 | 3435 | trigger_error('fetch_web_data(): Bad URL', E_USER_NOTICE); |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 4 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * Redirect to the user help ;). |
@@ -95,12 +96,13 @@ discard block |
||
| 95 | 96 | ); |
| 96 | 97 | |
| 97 | 98 | // Have we got a localized one? |
| 98 | - if (file_exists($boarddir . '/agreement.' . $user_info['language'] . '.txt')) |
|
| 99 | - $context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.' . $user_info['language'] . '.txt'), true, 'agreement_' . $user_info['language']); |
|
| 100 | - elseif (file_exists($boarddir . '/agreement.txt')) |
|
| 101 | - $context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.txt'), true, 'agreement'); |
|
| 102 | - else |
|
| 103 | - $context['agreement'] = ''; |
|
| 99 | + if (file_exists($boarddir . '/agreement.' . $user_info['language'] . '.txt')) { |
|
| 100 | + $context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.' . $user_info['language'] . '.txt'), true, 'agreement_' . $user_info['language']); |
|
| 101 | + } elseif (file_exists($boarddir . '/agreement.txt')) { |
|
| 102 | + $context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.txt'), true, 'agreement'); |
|
| 103 | + } else { |
|
| 104 | + $context['agreement'] = ''; |
|
| 105 | + } |
|
| 104 | 106 | |
| 105 | 107 | // Nothing to show, so let's get out of here |
| 106 | 108 | if (empty($context['agreement'])) |
@@ -128,18 +130,21 @@ discard block |
||
| 128 | 130 | { |
| 129 | 131 | global $txt, $helptxt, $context, $scripturl; |
| 130 | 132 | |
| 131 | - if (!isset($_GET['help']) || !is_string($_GET['help'])) |
|
| 132 | - fatal_lang_error('no_access', false); |
|
| 133 | + if (!isset($_GET['help']) || !is_string($_GET['help'])) { |
|
| 134 | + fatal_lang_error('no_access', false); |
|
| 135 | + } |
|
| 133 | 136 | |
| 134 | - if (!isset($helptxt)) |
|
| 135 | - $helptxt = array(); |
|
| 137 | + if (!isset($helptxt)) { |
|
| 138 | + $helptxt = array(); |
|
| 139 | + } |
|
| 136 | 140 | |
| 137 | 141 | // Load the admin help language file and template. |
| 138 | 142 | loadLanguage('Help'); |
| 139 | 143 | |
| 140 | 144 | // Permission specific help? |
| 141 | - if (isset($_GET['help']) && substr($_GET['help'], 0, 14) == 'permissionhelp') |
|
| 142 | - loadLanguage('ManagePermissions'); |
|
| 145 | + if (isset($_GET['help']) && substr($_GET['help'], 0, 14) == 'permissionhelp') { |
|
| 146 | + loadLanguage('ManagePermissions'); |
|
| 147 | + } |
|
| 143 | 148 | |
| 144 | 149 | loadTemplate('Help'); |
| 145 | 150 | |
@@ -154,16 +159,18 @@ discard block |
||
| 154 | 159 | $context['sub_template'] = 'popup'; |
| 155 | 160 | |
| 156 | 161 | // What help string should be used? |
| 157 | - if (isset($helptxt[$_GET['help']])) |
|
| 158 | - $context['help_text'] = $helptxt[$_GET['help']]; |
|
| 159 | - elseif (isset($txt[$_GET['help']])) |
|
| 160 | - $context['help_text'] = $txt[$_GET['help']]; |
|
| 161 | - else |
|
| 162 | - $context['help_text'] = $_GET['help']; |
|
| 162 | + if (isset($helptxt[$_GET['help']])) { |
|
| 163 | + $context['help_text'] = $helptxt[$_GET['help']]; |
|
| 164 | + } elseif (isset($txt[$_GET['help']])) { |
|
| 165 | + $context['help_text'] = $txt[$_GET['help']]; |
|
| 166 | + } else { |
|
| 167 | + $context['help_text'] = $_GET['help']; |
|
| 168 | + } |
|
| 163 | 169 | |
| 164 | 170 | // Does this text contain a link that we should fill in? |
| 165 | - if (preg_match('~%([0-9]+\$)?s\?~', $context['help_text'], $match)) |
|
| 166 | - $context['help_text'] = sprintf($context['help_text'], $scripturl, $context['session_id'], $context['session_var']); |
|
| 167 | -} |
|
| 171 | + if (preg_match('~%([0-9]+\$)?s\?~', $context['help_text'], $match)) { |
|
| 172 | + $context['help_text'] = sprintf($context['help_text'], $scripturl, $context['session_id'], $context['session_var']); |
|
| 173 | + } |
|
| 174 | + } |
|
| 168 | 175 | |
| 169 | 176 | ?> |
| 170 | 177 | \ No newline at end of file |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 4 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * Edit the position and properties of a category. |
@@ -42,8 +43,9 @@ discard block |
||
| 42 | 43 | $cat_order = array(); |
| 43 | 44 | |
| 44 | 45 | // Setting 'move_after' to '0' moves the category to the top. |
| 45 | - if ($catOptions['move_after'] == 0) |
|
| 46 | - $cats[] = $category_id; |
|
| 46 | + if ($catOptions['move_after'] == 0) { |
|
| 47 | + $cats[] = $category_id; |
|
| 48 | + } |
|
| 47 | 49 | |
| 48 | 50 | // Grab the categories sorted by cat_order. |
| 49 | 51 | $request = $smcFunc['db_query']('', ' |
@@ -55,17 +57,19 @@ discard block |
||
| 55 | 57 | ); |
| 56 | 58 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 57 | 59 | { |
| 58 | - if ($row['id_cat'] != $category_id) |
|
| 59 | - $cats[] = $row['id_cat']; |
|
| 60 | - if ($row['id_cat'] == $catOptions['move_after']) |
|
| 61 | - $cats[] = $category_id; |
|
| 60 | + if ($row['id_cat'] != $category_id) { |
|
| 61 | + $cats[] = $row['id_cat']; |
|
| 62 | + } |
|
| 63 | + if ($row['id_cat'] == $catOptions['move_after']) { |
|
| 64 | + $cats[] = $category_id; |
|
| 65 | + } |
|
| 62 | 66 | $cat_order[$row['id_cat']] = $row['cat_order']; |
| 63 | 67 | } |
| 64 | 68 | $smcFunc['db_free_result']($request); |
| 65 | 69 | |
| 66 | 70 | // Set the new order for the categories. |
| 67 | - foreach ($cats as $index => $cat) |
|
| 68 | - if ($index != $cat_order[$cat]) |
|
| 71 | + foreach ($cats as $index => $cat) { |
|
| 72 | + if ($index != $cat_order[$cat]) |
|
| 69 | 73 | $smcFunc['db_query']('', ' |
| 70 | 74 | UPDATE {db_prefix}categories |
| 71 | 75 | SET cat_order = {int:new_order} |
@@ -75,6 +79,7 @@ discard block |
||
| 75 | 79 | 'current_category' => $cat, |
| 76 | 80 | ) |
| 77 | 81 | ); |
| 82 | + } |
|
| 78 | 83 | |
| 79 | 84 | // If the category order changed, so did the board order. |
| 80 | 85 | require_once($sourcedir . '/Subs-Boards.php'); |
@@ -117,8 +122,9 @@ discard block |
||
| 117 | 122 | )) |
| 118 | 123 | ); |
| 119 | 124 | |
| 120 | - if (empty($catOptions['dont_log'])) |
|
| 121 | - logAction('edit_cat', array('catname' => isset($catOptions['cat_name']) ? $catOptions['cat_name'] : $category_id), 'admin'); |
|
| 125 | + if (empty($catOptions['dont_log'])) { |
|
| 126 | + logAction('edit_cat', array('catname' => isset($catOptions['cat_name']) ? $catOptions['cat_name'] : $category_id), 'admin'); |
|
| 127 | + } |
|
| 122 | 128 | } |
| 123 | 129 | } |
| 124 | 130 | |
@@ -135,16 +141,20 @@ discard block |
||
| 135 | 141 | global $smcFunc; |
| 136 | 142 | |
| 137 | 143 | // Check required values. |
| 138 | - if (!isset($catOptions['cat_name']) || trim($catOptions['cat_name']) == '') |
|
| 139 | - trigger_error('createCategory(): A category name is required', E_USER_ERROR); |
|
| 144 | + if (!isset($catOptions['cat_name']) || trim($catOptions['cat_name']) == '') { |
|
| 145 | + trigger_error('createCategory(): A category name is required', E_USER_ERROR); |
|
| 146 | + } |
|
| 140 | 147 | |
| 141 | 148 | // Set default values. |
| 142 | - if (!isset($catOptions['cat_desc'])) |
|
| 143 | - $catOptions['cat_desc'] = ''; |
|
| 144 | - if (!isset($catOptions['move_after'])) |
|
| 145 | - $catOptions['move_after'] = 0; |
|
| 146 | - if (!isset($catOptions['is_collapsible'])) |
|
| 147 | - $catOptions['is_collapsible'] = true; |
|
| 149 | + if (!isset($catOptions['cat_desc'])) { |
|
| 150 | + $catOptions['cat_desc'] = ''; |
|
| 151 | + } |
|
| 152 | + if (!isset($catOptions['move_after'])) { |
|
| 153 | + $catOptions['move_after'] = 0; |
|
| 154 | + } |
|
| 155 | + if (!isset($catOptions['is_collapsible'])) { |
|
| 156 | + $catOptions['is_collapsible'] = true; |
|
| 157 | + } |
|
| 148 | 158 | // Don't log an edit right after. |
| 149 | 159 | $catOptions['dont_log'] = true; |
| 150 | 160 | |
@@ -210,21 +220,24 @@ discard block |
||
| 210 | 220 | ) |
| 211 | 221 | ); |
| 212 | 222 | $boards_inside = array(); |
| 213 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 214 | - $boards_inside[] = $row['id_board']; |
|
| 223 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 224 | + $boards_inside[] = $row['id_board']; |
|
| 225 | + } |
|
| 215 | 226 | $smcFunc['db_free_result']($request); |
| 216 | 227 | |
| 217 | - if (!empty($boards_inside)) |
|
| 218 | - deleteBoards($boards_inside, null); |
|
| 228 | + if (!empty($boards_inside)) { |
|
| 229 | + deleteBoards($boards_inside, null); |
|
| 230 | + } |
|
| 219 | 231 | } |
| 220 | 232 | |
| 221 | 233 | // Make sure the safe category is really safe. |
| 222 | - elseif (in_array($moveBoardsTo, $categories)) |
|
| 223 | - trigger_error('deleteCategories(): You cannot move the boards to a category that\'s being deleted', E_USER_ERROR); |
|
| 234 | + elseif (in_array($moveBoardsTo, $categories)) { |
|
| 235 | + trigger_error('deleteCategories(): You cannot move the boards to a category that\'s being deleted', E_USER_ERROR); |
|
| 236 | + } |
|
| 224 | 237 | |
| 225 | 238 | // Move the boards inside the categories to a safe category. |
| 226 | - else |
|
| 227 | - $smcFunc['db_query']('', ' |
|
| 239 | + else { |
|
| 240 | + $smcFunc['db_query']('', ' |
|
| 228 | 241 | UPDATE {db_prefix}boards |
| 229 | 242 | SET id_cat = {int:new_parent_cat} |
| 230 | 243 | WHERE id_cat IN ({array_int:category_list})', |
@@ -233,6 +246,7 @@ discard block |
||
| 233 | 246 | 'new_parent_cat' => $moveBoardsTo, |
| 234 | 247 | ) |
| 235 | 248 | ); |
| 249 | + } |
|
| 236 | 250 | |
| 237 | 251 | // Do the deletion of the category itself |
| 238 | 252 | $smcFunc['db_query']('', ' |
@@ -244,8 +258,9 @@ discard block |
||
| 244 | 258 | ); |
| 245 | 259 | |
| 246 | 260 | // Log what we've done. |
| 247 | - foreach ($categories as $category) |
|
| 248 | - logAction('delete_cat', array('catname' => $cat_tree[$category]['node']['name']), 'admin'); |
|
| 261 | + foreach ($categories as $category) { |
|
| 262 | + logAction('delete_cat', array('catname' => $cat_tree[$category]['node']['name']), 'admin'); |
|
| 263 | + } |
|
| 249 | 264 | |
| 250 | 265 | // Get all boards back into the right order. |
| 251 | 266 | reorderBoards(); |
@@ -19,8 +19,9 @@ discard block |
||
| 19 | 19 | * @version 2.1 Beta 4 |
| 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,21 +453,24 @@ 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 | $datLen += $len; |
| 452 | 470 | |
| 453 | - if ($this->m_gih->m_bInterlace) |
|
| 454 | - $this->deInterlace(); |
|
| 471 | + if ($this->m_gih->m_bInterlace) { |
|
| 472 | + $this->deInterlace(); |
|
| 473 | + } |
|
| 455 | 474 | |
| 456 | 475 | return true; |
| 457 | 476 | |
@@ -571,17 +590,20 @@ discard block |
||
| 571 | 590 | |
| 572 | 591 | public function loadFile($filename, $iIndex) |
| 573 | 592 | { |
| 574 | - if ($iIndex < 0) |
|
| 575 | - return false; |
|
| 593 | + if ($iIndex < 0) { |
|
| 594 | + return false; |
|
| 595 | + } |
|
| 576 | 596 | |
| 577 | 597 | $this->data = @file_get_contents($filename); |
| 578 | - if ($this->data === false) |
|
| 579 | - return false; |
|
| 598 | + if ($this->data === false) { |
|
| 599 | + return false; |
|
| 600 | + } |
|
| 580 | 601 | |
| 581 | 602 | // Tell the header to load up.... |
| 582 | 603 | $len = 0; |
| 583 | - if (!$this->header->load($this->data, $len)) |
|
| 584 | - return false; |
|
| 604 | + if (!$this->header->load($this->data, $len)) { |
|
| 605 | + return false; |
|
| 606 | + } |
|
| 585 | 607 | |
| 586 | 608 | $this->data = substr($this->data, $len); |
| 587 | 609 | |
@@ -589,8 +611,9 @@ discard block |
||
| 589 | 611 | for ($j = 0; $j <= $iIndex; $j++) |
| 590 | 612 | { |
| 591 | 613 | $imgLen = 0; |
| 592 | - if (!$this->image->load($this->data, $imgLen)) |
|
| 593 | - return false; |
|
| 614 | + if (!$this->image->load($this->data, $imgLen)) { |
|
| 615 | + return false; |
|
| 616 | + } |
|
| 594 | 617 | |
| 595 | 618 | $this->data = substr($this->data, $imgLen); |
| 596 | 619 | } |
@@ -601,8 +624,9 @@ discard block |
||
| 601 | 624 | |
| 602 | 625 | public function get_png_data($background_color) |
| 603 | 626 | { |
| 604 | - if (!$this->loaded) |
|
| 605 | - return false; |
|
| 627 | + if (!$this->loaded) { |
|
| 628 | + return false; |
|
| 629 | + } |
|
| 606 | 630 | |
| 607 | 631 | // Prepare the color table. |
| 608 | 632 | if ($this->image->m_gih->m_bLocalClr) |
@@ -610,25 +634,26 @@ discard block |
||
| 610 | 634 | $colors = $this->image->m_gih->m_nTableSize; |
| 611 | 635 | $pal = $this->image->m_gih->m_colorTable->toString(); |
| 612 | 636 | |
| 613 | - if ($background_color != -1) |
|
| 614 | - $background_color = $this->image->m_gih->m_colorTable->colorIndex($background_color); |
|
| 615 | - } |
|
| 616 | - elseif ($this->header->m_bGlobalClr) |
|
| 637 | + if ($background_color != -1) { |
|
| 638 | + $background_color = $this->image->m_gih->m_colorTable->colorIndex($background_color); |
|
| 639 | + } |
|
| 640 | + } elseif ($this->header->m_bGlobalClr) |
|
| 617 | 641 | { |
| 618 | 642 | $colors = $this->header->m_nTableSize; |
| 619 | 643 | $pal = $this->header->m_colorTable->toString(); |
| 620 | 644 | |
| 621 | - if ($background_color != -1) |
|
| 622 | - $background_color = $this->header->m_colorTable->colorIndex($background_color); |
|
| 623 | - } |
|
| 624 | - else |
|
| 645 | + if ($background_color != -1) { |
|
| 646 | + $background_color = $this->header->m_colorTable->colorIndex($background_color); |
|
| 647 | + } |
|
| 648 | + } else |
|
| 625 | 649 | { |
| 626 | 650 | $colors = 0; |
| 627 | 651 | $background_color = -1; |
| 628 | 652 | } |
| 629 | 653 | |
| 630 | - if ($background_color == -1) |
|
| 631 | - $background_color = $this->header->m_nBgColor; |
|
| 654 | + if ($background_color == -1) { |
|
| 655 | + $background_color = $this->header->m_nBgColor; |
|
| 656 | + } |
|
| 632 | 657 | |
| 633 | 658 | $data = &$this->image->m_data; |
| 634 | 659 | $header = &$this->image->m_gih; |
@@ -644,11 +669,13 @@ discard block |
||
| 644 | 669 | for ($x = 0; $x < $this->header->m_nWidth; $x++, $i++) |
| 645 | 670 | { |
| 646 | 671 | // Is this in the proper range? If so, get the specific pixel data... |
| 647 | - if ($x >= $header->m_nLeft && $y >= $header->m_nTop && $x < ($header->m_nLeft + $header->m_nWidth) && $y < ($header->m_nTop + $header->m_nHeight)) |
|
| 648 | - $bmp .= $data{$i}; |
|
| 672 | + if ($x >= $header->m_nLeft && $y >= $header->m_nTop && $x < ($header->m_nLeft + $header->m_nWidth) && $y < ($header->m_nTop + $header->m_nHeight)) { |
|
| 673 | + $bmp .= $data{$i}; |
|
| 674 | + } |
|
| 649 | 675 | // Otherwise, this is background... |
| 650 | - else |
|
| 651 | - $bmp .= chr($background_color); |
|
| 676 | + else { |
|
| 677 | + $bmp .= chr($background_color); |
|
| 678 | + } |
|
| 652 | 679 | } |
| 653 | 680 | } |
| 654 | 681 | |
@@ -677,8 +704,9 @@ discard block |
||
| 677 | 704 | $tmp = 'tRNS'; |
| 678 | 705 | |
| 679 | 706 | // Stick each color on - full transparency or none. |
| 680 | - for ($i = 0; $i < $colors; $i++) |
|
| 681 | - $tmp .= $i == $this->image->m_nTrans ? "\x00" : "\xFF"; |
|
| 707 | + for ($i = 0; $i < $colors; $i++) { |
|
| 708 | + $tmp .= $i == $this->image->m_nTrans ? "\x00" : "\xFF"; |
|
| 709 | + } |
|
| 682 | 710 | |
| 683 | 711 | $out .= $tmp . pack('N', smf_crc32($tmp)); |
| 684 | 712 | } |
@@ -14,8 +14,9 @@ discard block |
||
| 14 | 14 | * @version 2.1 Beta 4 |
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | -if (!defined('SMF')) |
|
| 17 | +if (!defined('SMF')) { |
|
| 18 | 18 | die('No direct access...'); |
| 19 | +} |
|
| 19 | 20 | |
| 20 | 21 | /** |
| 21 | 22 | * Locks a topic... either by way of a moderator or the topic starter. |
@@ -32,8 +33,9 @@ discard block |
||
| 32 | 33 | global $topic, $user_info, $sourcedir, $board, $smcFunc; |
| 33 | 34 | |
| 34 | 35 | // Just quit if there's no topic to lock. |
| 35 | - if (empty($topic)) |
|
| 36 | - fatal_lang_error('not_a_topic', false); |
|
| 36 | + if (empty($topic)) { |
|
| 37 | + fatal_lang_error('not_a_topic', false); |
|
| 38 | + } |
|
| 37 | 39 | |
| 38 | 40 | checkSession('get'); |
| 39 | 41 | |
@@ -55,23 +57,28 @@ discard block |
||
| 55 | 57 | |
| 56 | 58 | // Can you lock topics here, mister? |
| 57 | 59 | $user_lock = !allowedTo('lock_any'); |
| 58 | - if ($user_lock && $starter == $user_info['id']) |
|
| 59 | - isAllowedTo('lock_own'); |
|
| 60 | - else |
|
| 61 | - isAllowedTo('lock_any'); |
|
| 60 | + if ($user_lock && $starter == $user_info['id']) { |
|
| 61 | + isAllowedTo('lock_own'); |
|
| 62 | + } else { |
|
| 63 | + isAllowedTo('lock_any'); |
|
| 64 | + } |
|
| 62 | 65 | |
| 63 | 66 | // Locking with high privileges. |
| 64 | - if ($locked == '0' && !$user_lock) |
|
| 65 | - $locked = '1'; |
|
| 67 | + if ($locked == '0' && !$user_lock) { |
|
| 68 | + $locked = '1'; |
|
| 69 | + } |
|
| 66 | 70 | // Locking with low privileges. |
| 67 | - elseif ($locked == '0') |
|
| 68 | - $locked = '2'; |
|
| 71 | + elseif ($locked == '0') { |
|
| 72 | + $locked = '2'; |
|
| 73 | + } |
|
| 69 | 74 | // Unlocking - make sure you don't unlock what you can't. |
| 70 | - elseif ($locked == '2' || ($locked == '1' && !$user_lock)) |
|
| 71 | - $locked = '0'; |
|
| 75 | + elseif ($locked == '2' || ($locked == '1' && !$user_lock)) { |
|
| 76 | + $locked = '0'; |
|
| 77 | + } |
|
| 72 | 78 | // You cannot unlock this! |
| 73 | - else |
|
| 74 | - fatal_lang_error('locked_by_admin', 'user'); |
|
| 79 | + else { |
|
| 80 | + fatal_lang_error('locked_by_admin', 'user'); |
|
| 81 | + } |
|
| 75 | 82 | |
| 76 | 83 | // Actually lock the topic in the database with the new value. |
| 77 | 84 | $smcFunc['db_query']('', ' |
@@ -85,8 +92,9 @@ discard block |
||
| 85 | 92 | ); |
| 86 | 93 | |
| 87 | 94 | // If they are allowed a "moderator" permission, log it in the moderator log. |
| 88 | - if (!$user_lock) |
|
| 89 | - logAction($locked ? 'lock' : 'unlock', array('topic' => $topic, 'board' => $board)); |
|
| 95 | + if (!$user_lock) { |
|
| 96 | + logAction($locked ? 'lock' : 'unlock', array('topic' => $topic, 'board' => $board)); |
|
| 97 | + } |
|
| 90 | 98 | // Notify people that this topic has been locked? |
| 91 | 99 | sendNotifications($topic, empty($locked) ? 'unlock' : 'lock'); |
| 92 | 100 | |
@@ -112,8 +120,9 @@ discard block |
||
| 112 | 120 | isAllowedTo('make_sticky'); |
| 113 | 121 | |
| 114 | 122 | // You can't sticky a board or something! |
| 115 | - if (empty($topic)) |
|
| 116 | - fatal_lang_error('not_a_topic', false); |
|
| 123 | + if (empty($topic)) { |
|
| 124 | + fatal_lang_error('not_a_topic', false); |
|
| 125 | + } |
|
| 117 | 126 | |
| 118 | 127 | checkSession('get'); |
| 119 | 128 | |
@@ -147,8 +156,9 @@ discard block |
||
| 147 | 156 | // Log this sticky action - always a moderator thing. |
| 148 | 157 | logAction(empty($is_sticky) ? 'sticky' : 'unsticky', array('topic' => $topic, 'board' => $board)); |
| 149 | 158 | // Notify people that this topic has been stickied? |
| 150 | - if (empty($is_sticky)) |
|
| 151 | - sendNotifications($topic, 'sticky'); |
|
| 159 | + if (empty($is_sticky)) { |
|
| 160 | + sendNotifications($topic, 'sticky'); |
|
| 161 | + } |
|
| 152 | 162 | |
| 153 | 163 | // Take them back to the now stickied topic. |
| 154 | 164 | redirectexit('topic=' . $topic . '.' . $_REQUEST['start'] . ';moderate'); |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 4 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * Browse the list of package servers, add servers... |
@@ -43,13 +44,15 @@ discard block |
||
| 43 | 44 | ); |
| 44 | 45 | |
| 45 | 46 | // Now let's decide where we are taking this... |
| 46 | - if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) |
|
| 47 | - $context['sub_action'] = $_REQUEST['sa']; |
|
| 47 | + if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) { |
|
| 48 | + $context['sub_action'] = $_REQUEST['sa']; |
|
| 49 | + } |
|
| 48 | 50 | // We need to support possible old javascript links... |
| 49 | - elseif (isset($_GET['pgdownload'])) |
|
| 50 | - $context['sub_action'] = 'download'; |
|
| 51 | - else |
|
| 52 | - $context['sub_action'] = 'servers'; |
|
| 51 | + elseif (isset($_GET['pgdownload'])) { |
|
| 52 | + $context['sub_action'] = 'download'; |
|
| 53 | + } else { |
|
| 54 | + $context['sub_action'] = 'servers'; |
|
| 55 | + } |
|
| 53 | 56 | |
| 54 | 57 | // We need to force the "Download" tab as selected. |
| 55 | 58 | $context['menu_data_' . $context['admin_menu_id']]['current_subsection'] = 'packageget'; |
@@ -141,17 +144,19 @@ discard block |
||
| 141 | 144 | { |
| 142 | 145 | require_once($sourcedir . '/Class-Package.php'); |
| 143 | 146 | $ftp = new ftp_connection(null); |
| 147 | + } elseif ($ftp->error !== false && !isset($ftp_error)) { |
|
| 148 | + $ftp_error = $ftp->last_message === null ? '' : $ftp->last_message; |
|
| 144 | 149 | } |
| 145 | - elseif ($ftp->error !== false && !isset($ftp_error)) |
|
| 146 | - $ftp_error = $ftp->last_message === null ? '' : $ftp->last_message; |
|
| 147 | 150 | |
| 148 | 151 | list ($username, $detect_path, $found_path) = $ftp->detect_path($packagesdir); |
| 149 | 152 | |
| 150 | - if ($found_path || !isset($_POST['ftp_path'])) |
|
| 151 | - $_POST['ftp_path'] = $detect_path; |
|
| 153 | + if ($found_path || !isset($_POST['ftp_path'])) { |
|
| 154 | + $_POST['ftp_path'] = $detect_path; |
|
| 155 | + } |
|
| 152 | 156 | |
| 153 | - if (!isset($_POST['ftp_username'])) |
|
| 154 | - $_POST['ftp_username'] = $username; |
|
| 157 | + if (!isset($_POST['ftp_username'])) { |
|
| 158 | + $_POST['ftp_username'] = $username; |
|
| 159 | + } |
|
| 155 | 160 | |
| 156 | 161 | $context['package_ftp'] = array( |
| 157 | 162 | 'server' => isset($_POST['ftp_server']) ? $_POST['ftp_server'] : (isset($modSettings['package_server']) ? $modSettings['package_server'] : 'localhost'), |
@@ -160,8 +165,7 @@ discard block |
||
| 160 | 165 | 'path' => $_POST['ftp_path'], |
| 161 | 166 | 'error' => empty($ftp_error) ? null : $ftp_error, |
| 162 | 167 | ); |
| 163 | - } |
|
| 164 | - else |
|
| 168 | + } else |
|
| 165 | 169 | { |
| 166 | 170 | $context['package_download_broken'] = false; |
| 167 | 171 | |
@@ -203,8 +207,9 @@ discard block |
||
| 203 | 207 | |
| 204 | 208 | if (isset($_GET['server'])) |
| 205 | 209 | { |
| 206 | - if ($_GET['server'] == '') |
|
| 207 | - redirectexit('action=admin;area=packages;get'); |
|
| 210 | + if ($_GET['server'] == '') { |
|
| 211 | + redirectexit('action=admin;area=packages;get'); |
|
| 212 | + } |
|
| 208 | 213 | |
| 209 | 214 | $server = (int) $_GET['server']; |
| 210 | 215 | |
@@ -222,17 +227,18 @@ discard block |
||
| 222 | 227 | $smcFunc['db_free_result']($request); |
| 223 | 228 | |
| 224 | 229 | // If the server does not exist, dump out. |
| 225 | - if (empty($url)) |
|
| 226 | - fatal_lang_error('couldnt_connect', false); |
|
| 230 | + if (empty($url)) { |
|
| 231 | + fatal_lang_error('couldnt_connect', false); |
|
| 232 | + } |
|
| 227 | 233 | |
| 228 | 234 | // If there is a relative link, append to the stored server url. |
| 229 | - if (isset($_GET['relative'])) |
|
| 230 | - $url = $url . (substr($url, -1) == '/' ? '' : '/') . $_GET['relative']; |
|
| 235 | + if (isset($_GET['relative'])) { |
|
| 236 | + $url = $url . (substr($url, -1) == '/' ? '' : '/') . $_GET['relative']; |
|
| 237 | + } |
|
| 231 | 238 | |
| 232 | 239 | // Clear any "absolute" URL. Since "server" is present, "absolute" is garbage. |
| 233 | 240 | unset($_GET['absolute']); |
| 234 | - } |
|
| 235 | - elseif (isset($_GET['absolute']) && $_GET['absolute'] != '') |
|
| 241 | + } elseif (isset($_GET['absolute']) && $_GET['absolute'] != '') |
|
| 236 | 242 | { |
| 237 | 243 | // Initialize the requried variables. |
| 238 | 244 | $server = ''; |
@@ -256,16 +262,19 @@ discard block |
||
| 256 | 262 | } |
| 257 | 263 | } |
| 258 | 264 | // Minimum required parameter did not exist so dump out. |
| 259 | - else |
|
| 260 | - fatal_lang_error('couldnt_connect', false); |
|
| 265 | + else { |
|
| 266 | + fatal_lang_error('couldnt_connect', false); |
|
| 267 | + } |
|
| 261 | 268 | |
| 262 | 269 | // Attempt to connect. If unsuccessful... try the URL. |
| 263 | - if (!isset($_GET['package']) || file_exists($_GET['package'])) |
|
| 264 | - $_GET['package'] = $url . '/packages.xml?language=' . $context['user']['language']; |
|
| 270 | + if (!isset($_GET['package']) || file_exists($_GET['package'])) { |
|
| 271 | + $_GET['package'] = $url . '/packages.xml?language=' . $context['user']['language']; |
|
| 272 | + } |
|
| 265 | 273 | |
| 266 | 274 | // Check to be sure the packages.xml file actually exists where it is should be... or dump out. |
| 267 | - if ((isset($_GET['absolute']) || isset($_GET['relative'])) && !url_exists($_GET['package'])) |
|
| 268 | - fatal_lang_error('packageget_unable', false, array($url . '/index.php')); |
|
| 275 | + if ((isset($_GET['absolute']) || isset($_GET['relative'])) && !url_exists($_GET['package'])) { |
|
| 276 | + fatal_lang_error('packageget_unable', false, array($url . '/index.php')); |
|
| 277 | + } |
|
| 269 | 278 | |
| 270 | 279 | // Might take some time. |
| 271 | 280 | @set_time_limit(600); |
@@ -275,8 +284,9 @@ discard block |
||
| 275 | 284 | $listing = new xmlArray(fetch_web_data($_GET['package']), true); |
| 276 | 285 | |
| 277 | 286 | // Errm.... empty file? Try the URL.... |
| 278 | - if (!$listing->exists('package-list')) |
|
| 279 | - fatal_lang_error('packageget_unable', false, array($url . '/index.php')); |
|
| 287 | + if (!$listing->exists('package-list')) { |
|
| 288 | + fatal_lang_error('packageget_unable', false, array($url . '/index.php')); |
|
| 289 | + } |
|
| 280 | 290 | |
| 281 | 291 | // List out the packages... |
| 282 | 292 | $context['package_list'] = array(); |
@@ -284,8 +294,9 @@ discard block |
||
| 284 | 294 | $listing = $listing->path('package-list[0]'); |
| 285 | 295 | |
| 286 | 296 | // Use the package list's name if it exists. |
| 287 | - if ($listing->exists('list-title')) |
|
| 288 | - $name = $smcFunc['htmlspecialchars']($listing->fetch('list-title')); |
|
| 297 | + if ($listing->exists('list-title')) { |
|
| 298 | + $name = $smcFunc['htmlspecialchars']($listing->fetch('list-title')); |
|
| 299 | + } |
|
| 289 | 300 | |
| 290 | 301 | // Pick the correct template. |
| 291 | 302 | $context['sub_template'] = 'package_list'; |
@@ -300,28 +311,32 @@ discard block |
||
| 300 | 311 | |
| 301 | 312 | $installed_mods = array(); |
| 302 | 313 | // Look through the list of installed mods... |
| 303 | - foreach ($instmods as $installed_mod) |
|
| 304 | - $installed_mods[$installed_mod['package_id']] = $installed_mod['version']; |
|
| 314 | + foreach ($instmods as $installed_mod) { |
|
| 315 | + $installed_mods[$installed_mod['package_id']] = $installed_mod['version']; |
|
| 316 | + } |
|
| 305 | 317 | |
| 306 | 318 | // Get default author and email if they exist. |
| 307 | 319 | if ($listing->exists('default-author')) |
| 308 | 320 | { |
| 309 | 321 | $default_author = $smcFunc['htmlspecialchars']($listing->fetch('default-author')); |
| 310 | - if ($listing->exists('default-author/@email') && filter_var($listing->fetch('default-author/@email'), FILTER_VALIDATE_EMAIL)) |
|
| 311 | - $default_email = $smcFunc['htmlspecialchars']($listing->fetch('default-author/@email')); |
|
| 322 | + if ($listing->exists('default-author/@email') && filter_var($listing->fetch('default-author/@email'), FILTER_VALIDATE_EMAIL)) { |
|
| 323 | + $default_email = $smcFunc['htmlspecialchars']($listing->fetch('default-author/@email')); |
|
| 324 | + } |
|
| 312 | 325 | } |
| 313 | 326 | |
| 314 | 327 | // Get default web site if it exists. |
| 315 | 328 | if ($listing->exists('default-website')) |
| 316 | 329 | { |
| 317 | 330 | $default_website = $smcFunc['htmlspecialchars']($listing->fetch('default-website')); |
| 318 | - if ($listing->exists('default-website/@title')) |
|
| 319 | - $default_title = $smcFunc['htmlspecialchars']($listing->fetch('default-website/@title')); |
|
| 331 | + if ($listing->exists('default-website/@title')) { |
|
| 332 | + $default_title = $smcFunc['htmlspecialchars']($listing->fetch('default-website/@title')); |
|
| 333 | + } |
|
| 320 | 334 | } |
| 321 | 335 | |
| 322 | 336 | $the_version = strtr($forum_version, array('SMF ' => '')); |
| 323 | - if (!empty($_SESSION['version_emulate'])) |
|
| 324 | - $the_version = $_SESSION['version_emulate']; |
|
| 337 | + if (!empty($_SESSION['version_emulate'])) { |
|
| 338 | + $the_version = $_SESSION['version_emulate']; |
|
| 339 | + } |
|
| 325 | 340 | |
| 326 | 341 | $packageNum = 0; |
| 327 | 342 | $packageSection = 0; |
@@ -342,11 +357,13 @@ discard block |
||
| 342 | 357 | 'type' => $thisPackage->name(), |
| 343 | 358 | ); |
| 344 | 359 | |
| 345 | - if (in_array($package['type'], array('title', 'text'))) |
|
| 346 | - $context['package_list'][$packageSection][$package['type']] = $smcFunc['htmlspecialchars']($thisPackage->fetch('.')); |
|
| 360 | + if (in_array($package['type'], array('title', 'text'))) { |
|
| 361 | + $context['package_list'][$packageSection][$package['type']] = $smcFunc['htmlspecialchars']($thisPackage->fetch('.')); |
|
| 362 | + } |
|
| 347 | 363 | // It's a Title, Heading, Rule or Text. |
| 348 | - elseif (in_array($package['type'], array('heading', 'rule'))) |
|
| 349 | - $package['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('.')); |
|
| 364 | + elseif (in_array($package['type'], array('heading', 'rule'))) { |
|
| 365 | + $package['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('.')); |
|
| 366 | + } |
|
| 350 | 367 | // It's a Remote link. |
| 351 | 368 | elseif ($package['type'] == 'remote') |
| 352 | 369 | { |
@@ -354,20 +371,21 @@ discard block |
||
| 354 | 371 | |
| 355 | 372 | if ($remote_type == 'relative' && substr($thisPackage->fetch('@href'), 0, 7) != 'http://' && substr($thisPackage->fetch('@href'), 0, 8) != 'https://') |
| 356 | 373 | { |
| 357 | - if (isset($_GET['absolute'])) |
|
| 358 | - $current_url = $_GET['absolute'] . '/'; |
|
| 359 | - elseif (isset($_GET['relative'])) |
|
| 360 | - $current_url = $_GET['relative'] . '/'; |
|
| 361 | - else |
|
| 362 | - $current_url = ''; |
|
| 374 | + if (isset($_GET['absolute'])) { |
|
| 375 | + $current_url = $_GET['absolute'] . '/'; |
|
| 376 | + } elseif (isset($_GET['relative'])) { |
|
| 377 | + $current_url = $_GET['relative'] . '/'; |
|
| 378 | + } else { |
|
| 379 | + $current_url = ''; |
|
| 380 | + } |
|
| 363 | 381 | |
| 364 | 382 | $current_url .= $thisPackage->fetch('@href'); |
| 365 | - if (isset($_GET['absolute'])) |
|
| 366 | - $package['href'] = $scripturl . '?action=admin;area=packages;get;sa=browse;absolute=' . $current_url; |
|
| 367 | - else |
|
| 368 | - $package['href'] = $scripturl . '?action=admin;area=packages;get;sa=browse;server=' . $context['package_server'] . ';relative=' . $current_url; |
|
| 369 | - } |
|
| 370 | - else |
|
| 383 | + if (isset($_GET['absolute'])) { |
|
| 384 | + $package['href'] = $scripturl . '?action=admin;area=packages;get;sa=browse;absolute=' . $current_url; |
|
| 385 | + } else { |
|
| 386 | + $package['href'] = $scripturl . '?action=admin;area=packages;get;sa=browse;server=' . $context['package_server'] . ';relative=' . $current_url; |
|
| 387 | + } |
|
| 388 | + } else |
|
| 371 | 389 | { |
| 372 | 390 | $current_url = $thisPackage->fetch('@href'); |
| 373 | 391 | $package['href'] = $scripturl . '?action=admin;area=packages;get;sa=browse;absolute=' . $current_url; |
@@ -379,25 +397,28 @@ discard block |
||
| 379 | 397 | // It's a package... |
| 380 | 398 | else |
| 381 | 399 | { |
| 382 | - if (isset($_GET['absolute'])) |
|
| 383 | - $current_url = $_GET['absolute'] . '/'; |
|
| 384 | - elseif (isset($_GET['relative'])) |
|
| 385 | - $current_url = $_GET['relative'] . '/'; |
|
| 386 | - else |
|
| 387 | - $current_url = ''; |
|
| 400 | + if (isset($_GET['absolute'])) { |
|
| 401 | + $current_url = $_GET['absolute'] . '/'; |
|
| 402 | + } elseif (isset($_GET['relative'])) { |
|
| 403 | + $current_url = $_GET['relative'] . '/'; |
|
| 404 | + } else { |
|
| 405 | + $current_url = ''; |
|
| 406 | + } |
|
| 388 | 407 | |
| 389 | 408 | $server_att = $server != '' ? ';server=' . $server : ''; |
| 390 | 409 | |
| 391 | 410 | $package += $thisPackage->to_array(); |
| 392 | 411 | |
| 393 | - if (isset($package['website'])) |
|
| 394 | - unset($package['website']); |
|
| 412 | + if (isset($package['website'])) { |
|
| 413 | + unset($package['website']); |
|
| 414 | + } |
|
| 395 | 415 | $package['author'] = array(); |
| 396 | 416 | |
| 397 | - if ($package['description'] == '') |
|
| 398 | - $package['description'] = $txt['package_no_description']; |
|
| 399 | - else |
|
| 400 | - $package['description'] = parse_bbc(preg_replace('~\[[/]?html\]~i', '', $smcFunc['htmlspecialchars']($package['description']))); |
|
| 417 | + if ($package['description'] == '') { |
|
| 418 | + $package['description'] = $txt['package_no_description']; |
|
| 419 | + } else { |
|
| 420 | + $package['description'] = parse_bbc(preg_replace('~\[[/]?html\]~i', '', $smcFunc['htmlspecialchars']($package['description']))); |
|
| 421 | + } |
|
| 401 | 422 | |
| 402 | 423 | $package['is_installed'] = isset($installed_mods[$package['id']]); |
| 403 | 424 | $package['is_current'] = $package['is_installed'] && ($installed_mods[$package['id']] == $package['version']); |
@@ -406,12 +427,14 @@ discard block |
||
| 406 | 427 | // This package is either not installed, or installed but old. Is it supported on this version of SMF? |
| 407 | 428 | if (!$package['is_installed'] || (!$package['is_current'] && !$package['is_newer'])) |
| 408 | 429 | { |
| 409 | - if ($thisPackage->exists('version/@for')) |
|
| 410 | - $package['can_install'] = matchPackageVersion($the_version, $thisPackage->fetch('version/@for')); |
|
| 430 | + if ($thisPackage->exists('version/@for')) { |
|
| 431 | + $package['can_install'] = matchPackageVersion($the_version, $thisPackage->fetch('version/@for')); |
|
| 432 | + } |
|
| 411 | 433 | } |
| 412 | 434 | // Okay, it's already installed AND up to date. |
| 413 | - else |
|
| 414 | - $package['can_install'] = false; |
|
| 435 | + else { |
|
| 436 | + $package['can_install'] = false; |
|
| 437 | + } |
|
| 415 | 438 | |
| 416 | 439 | $already_exists = getPackageInfo(basename($package['filename'])); |
| 417 | 440 | $package['download_conflict'] = is_array($already_exists) && $already_exists['id'] == $package['id'] && $already_exists['version'] != $package['version']; |
@@ -423,40 +446,44 @@ discard block |
||
| 423 | 446 | |
| 424 | 447 | if ($thisPackage->exists('author') || isset($default_author)) |
| 425 | 448 | { |
| 426 | - if ($thisPackage->exists('author/@email') && filter_var($thisPackage->fetch('author/@email'), FILTER_VALIDATE_EMAIL)) |
|
| 427 | - $package['author']['email'] = $thisPackage->fetch('author/@email'); |
|
| 428 | - elseif (isset($default_email)) |
|
| 429 | - $package['author']['email'] = $default_email; |
|
| 430 | - |
|
| 431 | - if ($thisPackage->exists('author') && $thisPackage->fetch('author') != '') |
|
| 432 | - $package['author']['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('author')); |
|
| 433 | - else |
|
| 434 | - $package['author']['name'] = $default_author; |
|
| 435 | - |
|
| 436 | - if (!empty($package['author']['email'])) |
|
| 437 | - $package['author']['link'] = '<a href="mailto:' . $package['author']['email'] . '">' . $package['author']['name'] . '</a>'; |
|
| 449 | + if ($thisPackage->exists('author/@email') && filter_var($thisPackage->fetch('author/@email'), FILTER_VALIDATE_EMAIL)) { |
|
| 450 | + $package['author']['email'] = $thisPackage->fetch('author/@email'); |
|
| 451 | + } elseif (isset($default_email)) { |
|
| 452 | + $package['author']['email'] = $default_email; |
|
| 453 | + } |
|
| 454 | + |
|
| 455 | + if ($thisPackage->exists('author') && $thisPackage->fetch('author') != '') { |
|
| 456 | + $package['author']['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('author')); |
|
| 457 | + } else { |
|
| 458 | + $package['author']['name'] = $default_author; |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + if (!empty($package['author']['email'])) { |
|
| 462 | + $package['author']['link'] = '<a href="mailto:' . $package['author']['email'] . '">' . $package['author']['name'] . '</a>'; |
|
| 463 | + } |
|
| 438 | 464 | } |
| 439 | 465 | |
| 440 | 466 | if ($thisPackage->exists('website') || isset($default_website)) |
| 441 | 467 | { |
| 442 | - if ($thisPackage->exists('website') && $thisPackage->exists('website/@title')) |
|
| 443 | - $package['author']['website']['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('website/@title')); |
|
| 444 | - elseif (isset($default_title)) |
|
| 445 | - $package['author']['website']['name'] = $default_title; |
|
| 446 | - elseif ($thisPackage->exists('website')) |
|
| 447 | - $package['author']['website']['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('website')); |
|
| 448 | - else |
|
| 449 | - $package['author']['website']['name'] = $default_website; |
|
| 450 | - |
|
| 451 | - if ($thisPackage->exists('website') && $thisPackage->fetch('website') != '') |
|
| 452 | - $authorhompage = $smcFunc['htmlspecialchars']($thisPackage->fetch('website')); |
|
| 453 | - else |
|
| 454 | - $authorhompage = $default_website; |
|
| 468 | + if ($thisPackage->exists('website') && $thisPackage->exists('website/@title')) { |
|
| 469 | + $package['author']['website']['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('website/@title')); |
|
| 470 | + } elseif (isset($default_title)) { |
|
| 471 | + $package['author']['website']['name'] = $default_title; |
|
| 472 | + } elseif ($thisPackage->exists('website')) { |
|
| 473 | + $package['author']['website']['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('website')); |
|
| 474 | + } else { |
|
| 475 | + $package['author']['website']['name'] = $default_website; |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + if ($thisPackage->exists('website') && $thisPackage->fetch('website') != '') { |
|
| 479 | + $authorhompage = $smcFunc['htmlspecialchars']($thisPackage->fetch('website')); |
|
| 480 | + } else { |
|
| 481 | + $authorhompage = $default_website; |
|
| 482 | + } |
|
| 455 | 483 | |
| 456 | 484 | $package['author']['website']['href'] = $authorhompage; |
| 457 | 485 | $package['author']['website']['link'] = '<a href="' . $authorhompage . '">' . $package['author']['website']['name'] . '</a>'; |
| 458 | - } |
|
| 459 | - else |
|
| 486 | + } else |
|
| 460 | 487 | { |
| 461 | 488 | $package['author']['website']['href'] = ''; |
| 462 | 489 | $package['author']['website']['link'] = ''; |
@@ -472,11 +499,13 @@ discard block |
||
| 472 | 499 | $packageNum = in_array($package['type'], array('title', 'heading', 'text', 'remote', 'rule')) ? 0 : $packageNum + 1; |
| 473 | 500 | $package['count'] = $packageNum; |
| 474 | 501 | |
| 475 | - if (!in_array($package['type'], array('title', 'text'))) |
|
| 476 | - $context['package_list'][$packageSection]['items'][] = $package; |
|
| 502 | + if (!in_array($package['type'], array('title', 'text'))) { |
|
| 503 | + $context['package_list'][$packageSection]['items'][] = $package; |
|
| 504 | + } |
|
| 477 | 505 | |
| 478 | - if ($package['count'] > 1) |
|
| 479 | - $context['list_type'] = 'ol'; |
|
| 506 | + if ($package['count'] > 1) { |
|
| 507 | + $context['list_type'] = 'ol'; |
|
| 508 | + } |
|
| 480 | 509 | } |
| 481 | 510 | |
| 482 | 511 | $packageSection++; |
@@ -489,8 +518,9 @@ discard block |
||
| 489 | 518 | { |
| 490 | 519 | foreach ($packageSection['items'] as $i => $package) |
| 491 | 520 | { |
| 492 | - if ($package['count'] == 0 || isset($package['can_install'])) |
|
| 493 | - continue; |
|
| 521 | + if ($package['count'] == 0 || isset($package['can_install'])) { |
|
| 522 | + continue; |
|
| 523 | + } |
|
| 494 | 524 | |
| 495 | 525 | $context['package_list'][$ps_id]['items'][$i]['can_install'] = false; |
| 496 | 526 | |
@@ -539,8 +569,9 @@ discard block |
||
| 539 | 569 | checkSession('get'); |
| 540 | 570 | |
| 541 | 571 | // To download something, we need a valid server or url. |
| 542 | - if (empty($_GET['server']) && (!empty($_GET['get']) && !empty($_REQUEST['package']))) |
|
| 543 | - fatal_lang_error('package_get_error_is_zero', false); |
|
| 572 | + if (empty($_GET['server']) && (!empty($_GET['get']) && !empty($_REQUEST['package']))) { |
|
| 573 | + fatal_lang_error('package_get_error_is_zero', false); |
|
| 574 | + } |
|
| 544 | 575 | |
| 545 | 576 | if (isset($_GET['server'])) |
| 546 | 577 | { |
@@ -560,22 +591,23 @@ discard block |
||
| 560 | 591 | $smcFunc['db_free_result']($request); |
| 561 | 592 | |
| 562 | 593 | // If server does not exist then dump out. |
| 563 | - if (empty($url)) |
|
| 564 | - fatal_lang_error('couldnt_connect', false); |
|
| 594 | + if (empty($url)) { |
|
| 595 | + fatal_lang_error('couldnt_connect', false); |
|
| 596 | + } |
|
| 565 | 597 | |
| 566 | 598 | $url = $url . '/'; |
| 567 | - } |
|
| 568 | - else |
|
| 599 | + } else |
|
| 569 | 600 | { |
| 570 | 601 | // Initialize the requried variables. |
| 571 | 602 | $server = ''; |
| 572 | 603 | $url = ''; |
| 573 | 604 | } |
| 574 | 605 | |
| 575 | - if (isset($_REQUEST['byurl']) && !empty($_POST['filename'])) |
|
| 576 | - $package_name = basename($_REQUEST['filename']); |
|
| 577 | - else |
|
| 578 | - $package_name = basename($_REQUEST['package']); |
|
| 606 | + if (isset($_REQUEST['byurl']) && !empty($_POST['filename'])) { |
|
| 607 | + $package_name = basename($_REQUEST['filename']); |
|
| 608 | + } else { |
|
| 609 | + $package_name = basename($_REQUEST['package']); |
|
| 610 | + } |
|
| 579 | 611 | |
| 580 | 612 | if (isset($_REQUEST['conflict']) || (isset($_REQUEST['auto']) && file_exists($packagesdir . '/' . $package_name))) |
| 581 | 613 | { |
@@ -584,14 +616,15 @@ discard block |
||
| 584 | 616 | { |
| 585 | 617 | $ext = substr($package_name, strrpos(substr($package_name, 0, -3), '.')); |
| 586 | 618 | $package_name = substr($package_name, 0, strrpos(substr($package_name, 0, -3), '.')) . '_'; |
| 619 | + } else { |
|
| 620 | + $ext = ''; |
|
| 587 | 621 | } |
| 588 | - else |
|
| 589 | - $ext = ''; |
|
| 590 | 622 | |
| 591 | 623 | // Find the first available. |
| 592 | 624 | $i = 1; |
| 593 | - while (file_exists($packagesdir . '/' . $package_name . $i . $ext)) |
|
| 594 | - $i++; |
|
| 625 | + while (file_exists($packagesdir . '/' . $package_name . $i . $ext)) { |
|
| 626 | + $i++; |
|
| 627 | + } |
|
| 595 | 628 | |
| 596 | 629 | $package_name = $package_name . $i . $ext; |
| 597 | 630 | } |
@@ -602,25 +635,28 @@ discard block |
||
| 602 | 635 | |
| 603 | 636 | // Done! Did we get this package automatically? |
| 604 | 637 | // @ TODO: These are usually update packages. Allowing both for now until more testing has been done. |
| 605 | - if (preg_match('~^https?://[\w_\-]+\.simplemachines\.org/~', $_REQUEST['package']) == 1 && strpos($_REQUEST['package'], 'dlattach') === false && isset($_REQUEST['auto'])) |
|
| 606 | - redirectexit('action=admin;area=packages;sa=install;package=' . $package_name); |
|
| 638 | + if (preg_match('~^https?://[\w_\-]+\.simplemachines\.org/~', $_REQUEST['package']) == 1 && strpos($_REQUEST['package'], 'dlattach') === false && isset($_REQUEST['auto'])) { |
|
| 639 | + redirectexit('action=admin;area=packages;sa=install;package=' . $package_name); |
|
| 640 | + } |
|
| 607 | 641 | |
| 608 | 642 | // You just downloaded a mod from SERVER_NAME_GOES_HERE. |
| 609 | 643 | $context['package_server'] = $server; |
| 610 | 644 | |
| 611 | 645 | $context['package'] = getPackageInfo($package_name); |
| 612 | 646 | |
| 613 | - if (!is_array($context['package'])) |
|
| 614 | - fatal_lang_error('package_cant_download', false); |
|
| 647 | + if (!is_array($context['package'])) { |
|
| 648 | + fatal_lang_error('package_cant_download', false); |
|
| 649 | + } |
|
| 615 | 650 | |
| 616 | - if ($context['package']['type'] == 'modification') |
|
| 617 | - $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['install_mod'] . ' ]</a>'; |
|
| 618 | - elseif ($context['package']['type'] == 'avatar') |
|
| 619 | - $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['use_avatars'] . ' ]</a>'; |
|
| 620 | - elseif ($context['package']['type'] == 'language') |
|
| 621 | - $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['add_languages'] . ' ]</a>'; |
|
| 622 | - else |
|
| 623 | - $context['package']['install']['link'] = ''; |
|
| 651 | + if ($context['package']['type'] == 'modification') { |
|
| 652 | + $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['install_mod'] . ' ]</a>'; |
|
| 653 | + } elseif ($context['package']['type'] == 'avatar') { |
|
| 654 | + $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['use_avatars'] . ' ]</a>'; |
|
| 655 | + } elseif ($context['package']['type'] == 'language') { |
|
| 656 | + $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['add_languages'] . ' ]</a>'; |
|
| 657 | + } else { |
|
| 658 | + $context['package']['install']['link'] = ''; |
|
| 659 | + } |
|
| 624 | 660 | |
| 625 | 661 | // Does a 3rd party hook want to do some additional changes? |
| 626 | 662 | call_integration_hook('integrate_package_download'); |
@@ -646,10 +682,11 @@ discard block |
||
| 646 | 682 | // @todo Use FTP if the Packages directory is not writable. |
| 647 | 683 | |
| 648 | 684 | // Check the file was even sent! |
| 649 | - if (!isset($_FILES['package']['name']) || $_FILES['package']['name'] == '') |
|
| 650 | - fatal_lang_error('package_upload_error_nofile'); |
|
| 651 | - elseif (!is_uploaded_file($_FILES['package']['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['package']['tmp_name']))) |
|
| 652 | - fatal_lang_error('package_upload_error_failed'); |
|
| 685 | + if (!isset($_FILES['package']['name']) || $_FILES['package']['name'] == '') { |
|
| 686 | + fatal_lang_error('package_upload_error_nofile'); |
|
| 687 | + } elseif (!is_uploaded_file($_FILES['package']['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['package']['tmp_name']))) { |
|
| 688 | + fatal_lang_error('package_upload_error_failed'); |
|
| 689 | + } |
|
| 653 | 690 | |
| 654 | 691 | // Make sure it has a sane filename. |
| 655 | 692 | $_FILES['package']['name'] = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $_FILES['package']['name']); |
@@ -666,8 +703,9 @@ discard block |
||
| 666 | 703 | // Setup the destination and throw an error if the file is already there! |
| 667 | 704 | $destination = $packagesdir . '/' . $packageName; |
| 668 | 705 | // @todo Maybe just roll it like we do for downloads? |
| 669 | - if (file_exists($destination)) |
|
| 670 | - fatal_lang_error('package_upload_error_exists'); |
|
| 706 | + if (file_exists($destination)) { |
|
| 707 | + fatal_lang_error('package_upload_error_exists'); |
|
| 708 | + } |
|
| 671 | 709 | |
| 672 | 710 | // Now move the file. |
| 673 | 711 | move_uploaded_file($_FILES['package']['tmp_name'], $destination); |
@@ -690,12 +728,14 @@ discard block |
||
| 690 | 728 | { |
| 691 | 729 | while ($package = readdir($dir)) |
| 692 | 730 | { |
| 693 | - if ($package == '.' || $package == '..' || $package == 'temp' || $package == $packageName || (!(is_dir($packagesdir . '/' . $package) && file_exists($packagesdir . '/' . $package . '/package-info.xml')) && substr(strtolower($package), -7) != '.tar.gz' && substr(strtolower($package), -4) != '.tgz' && substr(strtolower($package), -4) != '.zip')) |
|
| 694 | - continue; |
|
| 731 | + if ($package == '.' || $package == '..' || $package == 'temp' || $package == $packageName || (!(is_dir($packagesdir . '/' . $package) && file_exists($packagesdir . '/' . $package . '/package-info.xml')) && substr(strtolower($package), -7) != '.tar.gz' && substr(strtolower($package), -4) != '.tgz' && substr(strtolower($package), -4) != '.zip')) { |
|
| 732 | + continue; |
|
| 733 | + } |
|
| 695 | 734 | |
| 696 | 735 | $packageInfo = getPackageInfo($package); |
| 697 | - if (!is_array($packageInfo)) |
|
| 698 | - continue; |
|
| 736 | + if (!is_array($packageInfo)) { |
|
| 737 | + continue; |
|
| 738 | + } |
|
| 699 | 739 | |
| 700 | 740 | if ($packageInfo['id'] == $context['package']['id'] && $packageInfo['version'] == $context['package']['version']) |
| 701 | 741 | { |
@@ -707,14 +747,15 @@ discard block |
||
| 707 | 747 | closedir($dir); |
| 708 | 748 | } |
| 709 | 749 | |
| 710 | - if ($context['package']['type'] == 'modification') |
|
| 711 | - $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['install_mod'] . ' ]</a>'; |
|
| 712 | - elseif ($context['package']['type'] == 'avatar') |
|
| 713 | - $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['use_avatars'] . ' ]</a>'; |
|
| 714 | - elseif ($context['package']['type'] == 'language') |
|
| 715 | - $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['add_languages'] . ' ]</a>'; |
|
| 716 | - else |
|
| 717 | - $context['package']['install']['link'] = ''; |
|
| 750 | + if ($context['package']['type'] == 'modification') { |
|
| 751 | + $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['install_mod'] . ' ]</a>'; |
|
| 752 | + } elseif ($context['package']['type'] == 'avatar') { |
|
| 753 | + $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['use_avatars'] . ' ]</a>'; |
|
| 754 | + } elseif ($context['package']['type'] == 'language') { |
|
| 755 | + $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['add_languages'] . ' ]</a>'; |
|
| 756 | + } else { |
|
| 757 | + $context['package']['install']['link'] = ''; |
|
| 758 | + } |
|
| 718 | 759 | |
| 719 | 760 | // Does a 3rd party hook want to do some additional changes? |
| 720 | 761 | call_integration_hook('integrate_package_upload'); |
@@ -737,16 +778,18 @@ discard block |
||
| 737 | 778 | checkSession(); |
| 738 | 779 | |
| 739 | 780 | // If they put a slash on the end, get rid of it. |
| 740 | - if (substr($_POST['serverurl'], -1) == '/') |
|
| 741 | - $_POST['serverurl'] = substr($_POST['serverurl'], 0, -1); |
|
| 781 | + if (substr($_POST['serverurl'], -1) == '/') { |
|
| 782 | + $_POST['serverurl'] = substr($_POST['serverurl'], 0, -1); |
|
| 783 | + } |
|
| 742 | 784 | |
| 743 | 785 | // Are they both nice and clean? |
| 744 | 786 | $servername = trim($smcFunc['htmlspecialchars']($_POST['servername'])); |
| 745 | 787 | $serverurl = trim($smcFunc['htmlspecialchars']($_POST['serverurl'])); |
| 746 | 788 | |
| 747 | 789 | // Make sure the URL has the correct prefix. |
| 748 | - if (strpos($serverurl, 'http://') !== 0 && strpos($serverurl, 'https://') !== 0) |
|
| 749 | - $serverurl = 'http://' . $serverurl; |
|
| 790 | + if (strpos($serverurl, 'http://') !== 0 && strpos($serverurl, 'https://') !== 0) { |
|
| 791 | + $serverurl = 'http://' . $serverurl; |
|
| 792 | + } |
|
| 750 | 793 | |
| 751 | 794 | $smcFunc['db_insert']('', |
| 752 | 795 | '{db_prefix}package_servers', |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 4 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * Show the database queries for debugging |
@@ -30,8 +31,9 @@ discard block |
||
| 30 | 31 | global $scripturl, $settings, $context, $db_connection, $boarddir, $smcFunc, $txt, $db_show_debug; |
| 31 | 32 | |
| 32 | 33 | // We should have debug mode enabled, as well as something to display! |
| 33 | - if (!isset($db_show_debug) || $db_show_debug !== true || !isset($_SESSION['debug'])) |
|
| 34 | - fatal_lang_error('no_access', false); |
|
| 34 | + if (!isset($db_show_debug) || $db_show_debug !== true || !isset($_SESSION['debug'])) { |
|
| 35 | + fatal_lang_error('no_access', false); |
|
| 36 | + } |
|
| 35 | 37 | |
| 36 | 38 | // Don't allow except for administrators. |
| 37 | 39 | isAllowedTo('admin_forum'); |
@@ -41,10 +43,11 @@ discard block |
||
| 41 | 43 | { |
| 42 | 44 | $_SESSION['view_queries'] = $_SESSION['view_queries'] == 1 ? 0 : 1; |
| 43 | 45 | |
| 44 | - if (strpos($_SESSION['old_url'], 'action=viewquery') !== false) |
|
| 45 | - redirectexit(); |
|
| 46 | - else |
|
| 47 | - redirectexit($_SESSION['old_url']); |
|
| 46 | + if (strpos($_SESSION['old_url'], 'action=viewquery') !== false) { |
|
| 47 | + redirectexit(); |
|
| 48 | + } else { |
|
| 49 | + redirectexit($_SESSION['old_url']); |
|
| 50 | + } |
|
| 48 | 51 | } |
| 49 | 52 | |
| 50 | 53 | call_integration_hook('integrate_egg_nog'); |
@@ -83,26 +86,28 @@ discard block |
||
| 83 | 86 | foreach ($query as $line) |
| 84 | 87 | { |
| 85 | 88 | preg_match('/^(\t*)/', $line, $temp); |
| 86 | - if (strlen($temp[0]) < $min_indent || $min_indent == 0) |
|
| 87 | - $min_indent = strlen($temp[0]); |
|
| 89 | + if (strlen($temp[0]) < $min_indent || $min_indent == 0) { |
|
| 90 | + $min_indent = strlen($temp[0]); |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + foreach ($query as $l => $dummy) { |
|
| 94 | + $query[$l] = substr($dummy, $min_indent); |
|
| 88 | 95 | } |
| 89 | - foreach ($query as $l => $dummy) |
|
| 90 | - $query[$l] = substr($dummy, $min_indent); |
|
| 91 | 96 | $query_data['q'] = implode("\n", $query); |
| 92 | 97 | |
| 93 | 98 | // Make the filenames look a bit better. |
| 94 | - if (isset($query_data['f'])) |
|
| 95 | - $query_data['f'] = preg_replace('~^' . preg_quote($boarddir, '~') . '~', '...', $query_data['f']); |
|
| 99 | + if (isset($query_data['f'])) { |
|
| 100 | + $query_data['f'] = preg_replace('~^' . preg_quote($boarddir, '~') . '~', '...', $query_data['f']); |
|
| 101 | + } |
|
| 96 | 102 | |
| 97 | 103 | $is_select_query = substr(trim($query_data['q']), 0, 6) == 'SELECT'; |
| 98 | - if ($is_select_query) |
|
| 99 | - $select = $query_data['q']; |
|
| 100 | - elseif (preg_match('~^INSERT(?: IGNORE)? INTO \w+(?:\s+\([^)]+\))?\s+(SELECT .+)$~s', trim($query_data['q']), $matches) != 0) |
|
| 104 | + if ($is_select_query) { |
|
| 105 | + $select = $query_data['q']; |
|
| 106 | + } elseif (preg_match('~^INSERT(?: IGNORE)? INTO \w+(?:\s+\([^)]+\))?\s+(SELECT .+)$~s', trim($query_data['q']), $matches) != 0) |
|
| 101 | 107 | { |
| 102 | 108 | $is_select_query = true; |
| 103 | 109 | $select = $matches[1]; |
| 104 | - } |
|
| 105 | - elseif (preg_match('~^CREATE TEMPORARY TABLE .+?(SELECT .+)$~s', trim($query_data['q']), $matches) != 0) |
|
| 110 | + } elseif (preg_match('~^CREATE TEMPORARY TABLE .+?(SELECT .+)$~s', trim($query_data['q']), $matches) != 0) |
|
| 106 | 111 | { |
| 107 | 112 | $is_select_query = true; |
| 108 | 113 | $select = $matches[1]; |
@@ -110,10 +115,11 @@ discard block |
||
| 110 | 115 | // Temporary tables created in earlier queries are not explainable. |
| 111 | 116 | if ($is_select_query) |
| 112 | 117 | { |
| 113 | - foreach (array('log_topics_unread', 'topics_posted_in', 'tmp_log_search_topics', 'tmp_log_search_messages') as $tmp) |
|
| 114 | - if (strpos($select, $tmp) !== false) |
|
| 118 | + foreach (array('log_topics_unread', 'topics_posted_in', 'tmp_log_search_topics', 'tmp_log_search_messages') as $tmp) { |
|
| 119 | + if (strpos($select, $tmp) !== false) |
|
| 115 | 120 | { |
| 116 | 121 | $is_select_query = false; |
| 122 | + } |
|
| 117 | 123 | break; |
| 118 | 124 | } |
| 119 | 125 | } |
@@ -124,13 +130,15 @@ discard block |
||
| 124 | 130 | ', nl2br(str_replace("\t", ' ', $smcFunc['htmlspecialchars']($query_data['q']))), ' |
| 125 | 131 | </a><br>'; |
| 126 | 132 | |
| 127 | - if (!empty($query_data['f']) && !empty($query_data['l'])) |
|
| 128 | - echo sprintf($txt['debug_query_in_line'], $query_data['f'], $query_data['l']); |
|
| 133 | + if (!empty($query_data['f']) && !empty($query_data['l'])) { |
|
| 134 | + echo sprintf($txt['debug_query_in_line'], $query_data['f'], $query_data['l']); |
|
| 135 | + } |
|
| 129 | 136 | |
| 130 | - if (isset($query_data['s'], $query_data['t']) && isset($txt['debug_query_which_took_at'])) |
|
| 131 | - echo sprintf($txt['debug_query_which_took_at'], round($query_data['t'], 8), round($query_data['s'], 8)); |
|
| 132 | - else |
|
| 133 | - echo sprintf($txt['debug_query_which_took'], round($query_data['t'], 8)); |
|
| 137 | + if (isset($query_data['s'], $query_data['t']) && isset($txt['debug_query_which_took_at'])) { |
|
| 138 | + echo sprintf($txt['debug_query_which_took_at'], round($query_data['t'], 8), round($query_data['s'], 8)); |
|
| 139 | + } else { |
|
| 140 | + echo sprintf($txt['debug_query_which_took'], round($query_data['t'], 8)); |
|
| 141 | + } |
|
| 134 | 142 | |
| 135 | 143 | echo ' |
| 136 | 144 | </div>'; |